mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-09 02:43:29 +08:00
test: add 3 tests for typeof guard, empty package.json, and learned_skills_path override (round 86)
- loadAliases resets to defaults when aliases field is a truthy non-object (string) - detectFromPackageJson returns null for empty (0-byte) package.json - evaluate-session uses learned_skills_path config override with ~ expansion
This commit is contained in:
@@ -1350,6 +1350,19 @@ function runTests() {
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
// ── Round 86: detectFromPackageJson with empty (0-byte) package.json ──
|
||||
console.log('\nRound 86: detectFromPackageJson (empty package.json):');
|
||||
|
||||
if (test('detectFromPackageJson returns null for empty (0-byte) package.json', () => {
|
||||
// package-manager.js line 109-111: readFile returns "" for empty file.
|
||||
// "" is falsy → if (content) is false → skips JSON.parse → returns null.
|
||||
const testDir = createTestDir();
|
||||
fs.writeFileSync(path.join(testDir, 'package.json'), '');
|
||||
const result = pm.detectFromPackageJson(testDir);
|
||||
assert.strictEqual(result, null, 'Empty package.json should return null (content="" is falsy)');
|
||||
cleanupTestDir(testDir);
|
||||
})) passed++; else failed++;
|
||||
|
||||
// Summary
|
||||
console.log('\n=== Test Results ===');
|
||||
console.log(`Passed: ${passed}`);
|
||||
|
||||
@@ -1202,6 +1202,27 @@ function runTests() {
|
||||
'Entries with invalid/missing dates should sort to the end');
|
||||
})) passed++; else failed++;
|
||||
|
||||
// ── Round 86: loadAliases with truthy non-object aliases field ──
|
||||
console.log('\nRound 86: loadAliases (truthy non-object aliases field):');
|
||||
|
||||
if (test('loadAliases resets to defaults when aliases field is a string (typeof !== object)', () => {
|
||||
// session-aliases.js line 58: if (!data.aliases || typeof data.aliases !== 'object')
|
||||
// Previous tests covered !data.aliases (undefined) via { noAliasesKey: true }.
|
||||
// This exercises the SECOND half: aliases is truthy but typeof !== 'object'.
|
||||
const aliasesPath = aliases.getAliasesPath();
|
||||
fs.writeFileSync(aliasesPath, JSON.stringify({
|
||||
version: '1.0',
|
||||
aliases: 'this-is-a-string-not-an-object',
|
||||
metadata: { totalCount: 0 }
|
||||
}));
|
||||
const data = aliases.loadAliases();
|
||||
assert.strictEqual(typeof data.aliases, 'object', 'Should reset aliases to object');
|
||||
assert.ok(!Array.isArray(data.aliases), 'Should be a plain object, not array');
|
||||
assert.strictEqual(Object.keys(data.aliases).length, 0, 'Should have no aliases');
|
||||
assert.strictEqual(data.version, '1.0', 'Should have version');
|
||||
resetAliases();
|
||||
})) passed++; else failed++;
|
||||
|
||||
// Summary
|
||||
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
||||
process.exit(failed > 0 ? 1 : 0);
|
||||
|
||||
Reference in New Issue
Block a user