mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-09 19:03:28 +08:00
test: add Round 103 edge-case tests (countInFile bool, grepFile numeric, loadAliases array)
- countInFile(file, false): boolean falls to else-return-0 type guard (utils.js:443) - grepFile(file, 0): numeric pattern implicitly coerced via RegExp constructor, contrasting with countInFile which explicitly rejects non-string non-RegExp - loadAliases with array aliases: typeof [] === 'object' bypasses validation at session-aliases.js:58, returning array instead of plain object Total tests: 869 (all passing)
This commit is contained in:
@@ -1327,6 +1327,34 @@ function runTests() {
|
||||
'Persisted title should be null after round-trip through saveAliases/loadAliases');
|
||||
})) passed++; else failed++;
|
||||
|
||||
// ── Round 103: loadAliases with array aliases in JSON (typeof [] === 'object' bypass) ──
|
||||
console.log('\nRound 103: loadAliases (array aliases — typeof bypass):');
|
||||
if (test('loadAliases accepts array aliases because typeof [] === "object" passes validation', () => {
|
||||
// session-aliases.js line 58: `typeof data.aliases !== 'object'` is the guard.
|
||||
// Arrays are typeof 'object' in JavaScript, so {"aliases": [1,2,3]} passes
|
||||
// validation. The returned data.aliases is an array, not a plain object.
|
||||
// Downstream code (Object.keys, Object.entries, bracket access) behaves
|
||||
// differently on arrays vs objects but doesn't crash — it just produces
|
||||
// unexpected results like numeric string keys "0", "1", "2".
|
||||
resetAliases();
|
||||
const aliasesPath = aliases.getAliasesPath();
|
||||
fs.writeFileSync(aliasesPath, JSON.stringify({
|
||||
version: '1.0',
|
||||
aliases: ['item0', 'item1', 'item2'],
|
||||
metadata: { totalCount: 3, lastUpdated: new Date().toISOString() }
|
||||
}));
|
||||
const data = aliases.loadAliases();
|
||||
// The array passes the typeof 'object' check and is returned as-is
|
||||
assert.ok(Array.isArray(data.aliases),
|
||||
'data.aliases should be an array (typeof [] === "object" bypasses guard)');
|
||||
assert.strictEqual(data.aliases.length, 3,
|
||||
'Array should have 3 elements');
|
||||
// Object.keys on an array returns ["0", "1", "2"] — numeric index strings
|
||||
const keys = Object.keys(data.aliases);
|
||||
assert.deepStrictEqual(keys, ['0', '1', '2'],
|
||||
'Object.keys of array returns numeric string indices, not named alias keys');
|
||||
})) passed++; else failed++;
|
||||
|
||||
// Summary
|
||||
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
||||
process.exit(failed > 0 ? 1 : 0);
|
||||
|
||||
Reference in New Issue
Block a user