Skip to content

armgit / ECC

Public Imported from GitHub
0

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

test: add 3 tests for untested fallback/skip/failure paths (Round 70)

Affaan Mustafa44b5a4f9f0c8
diff --git a/tests/ci/validators.test.js b/tests/ci/validators.test.js
index 679fdd5cd..bf21c3998 100644
--- a/tests/ci/validators.test.js
+++ b/tests/ci/validators.test.js
@@ -1895,6 +1895,28 @@ function runTests() {
cleanupTestDir(testDir);
})) passed++; else failed++;
+ // ── Round 70: validate-commands.js "would create:" line skip ──
+ console.log('\nRound 70: validate-commands.js (would create: skip):');
+
+ if (test('skips command references on "would create:" lines', () => {
+ const testDir = createTestDir();
+ const agentsDir = createTestDir();
+ const skillsDir = createTestDir();
+ // "Would create:" is the alternate form checked by the regex at line 80:
+ // if (/creates:|would create:/i.test(line)) continue;
+ // Only "creates:" was previously tested (Round 20). "Would create:" exercises
+ // the second alternation in the regex.
+ fs.writeFileSync(path.join(testDir, 'gen-cmd.md'),
+ '# Generator Command\n\nWould create: `/phantom-cmd` in your project.\n\nThis is safe.');
+
+ const result = runValidatorWithDirs('validate-commands', {
+ COMMANDS_DIR: testDir, AGENTS_DIR: agentsDir, SKILLS_DIR: skillsDir
+ });
+ assert.strictEqual(result.code, 0, 'Should skip "would create:" lines');
+ assert.ok(!result.stderr.includes('phantom-cmd'), 'Should not flag ref on "would create:" line');
+ cleanupTestDir(testDir); cleanupTestDir(agentsDir); cleanupTestDir(skillsDir);
+ })) passed++; else failed++;
+
// Summary
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
process.exit(failed > 0 ? 1 : 0);
diff --git a/tests/hooks/hooks.test.js b/tests/hooks/hooks.test.js
index 3768b2878..c22110926 100644
--- a/tests/hooks/hooks.test.js
+++ b/tests/hooks/hooks.test.js
@@ -3075,6 +3075,48 @@ async function runTests() {
}
})) passed++; else failed++;
+ // ── Round 70: session-end.js entry.name / entry.input fallback in direct tool_use entries ──
+ console.log('\nRound 70: session-end.js (entry.name/entry.input fallback):');
+
+ if (await asyncTest('extracts tool name and file path from entry.name/entry.input (not tool_name/tool_input)', async () => {
+ const isoHome = path.join(os.tmpdir(), `ecc-r70-entryname-${Date.now()}`);
+ const sessionsDir = path.join(isoHome, '.claude', 'sessions');
+ fs.mkdirSync(sessionsDir, { recursive: true });
+ const transcriptPath = path.join(isoHome, 'transcript.jsonl');
+
+ // Use "name" and "input" fields instead of "tool_name" and "tool_input"
+ // This exercises the fallback at session-end.js lines 63 and 66:
+ // const toolName = entry.tool_name || entry.name || '';
+ // const filePath = entry.tool_input?.file_path || entry.input?.file_path || '';
+ const lines = [
+ '{"type":"user","content":"Use the alt format fields"}',
+ '{"type":"tool_use","name":"Edit","input":{"file_path":"/src/alt-format.ts"}}',
+ '{"type":"tool_use","name":"Read","input":{"file_path":"/src/other.ts"}}',
+ '{"type":"tool_use","name":"Write","input":{"file_path":"/src/written.ts"}}',
+ ];
+ fs.writeFileSync(transcriptPath, lines.join('\n'));
+
+ const stdinJson = JSON.stringify({ transcript_path: transcriptPath });
+ try {
+ const result = await runScript(path.join(scriptsDir, 'session-end.js'), stdinJson, {
+ HOME: isoHome, USERPROFILE: isoHome
+ });
+ assert.strictEqual(result.code, 0, 'Should exit 0');
+
+ const files = fs.readdirSync(sessionsDir).filter(f => f.endsWith('.tmp'));
+ assert.ok(files.length > 0, 'Should create session file');
+ const content = fs.readFileSync(path.join(sessionsDir, files[0]), 'utf8');
+ // Tools extracted via entry.name fallback
+ assert.ok(content.includes('Edit'), 'Should list Edit via entry.name fallback');
+ assert.ok(content.includes('Read'), 'Should list Read via entry.name fallback');
+ // Files modified via entry.input fallback (Edit and Write, not Read)
+ assert.ok(content.includes('/src/alt-format.ts'), 'Should list edited file via entry.input fallback');
+ assert.ok(content.includes('/src/written.ts'), 'Should list written file via entry.input fallback');
+ } finally {
+ fs.rmSync(isoHome, { recursive: true, force: true });
+ }
+ })) passed++; else failed++;
+
// Summary
console.log('\n=== Test Results ===');
console.log(`Passed: ${passed}`);
diff --git a/tests/lib/session-aliases.test.js b/tests/lib/session-aliases.test.js
index e19fb0e13..17b3712b4 100644
--- a/tests/lib/session-aliases.test.js
+++ b/tests/lib/session-aliases.test.js
@@ -983,6 +983,53 @@ function runTests() {
resetAliases();
})) passed++; else failed++;
+ // ── Round 70: updateAliasTitle save failure path ──
+ console.log('\nupdateAliasTitle save failure (Round 70):');
+
+ if (test('updateAliasTitle returns failure when saveAliases fails (read-only dir)', () => {
+ if (process.platform === 'win32' || process.getuid?.() === 0) {
+ console.log(' (skipped — chmod ineffective on Windows/root)');
+ return;
+ }
+ // Use a fresh isolated HOME to avoid .tmp/.bak leftovers from other tests.
+ // On macOS, overwriting an EXISTING file in a read-only dir succeeds,
+ // so we must start clean with ONLY the .json file present.
+ const isoHome = path.join(os.tmpdir(), `ecc-alias-r70-${Date.now()}`);
+ const isoClaudeDir = path.join(isoHome, '.claude');
+ fs.mkdirSync(isoClaudeDir, { recursive: true });
+ const savedHome = process.env.HOME;
+ const savedProfile = process.env.USERPROFILE;
+ try {
+ process.env.HOME = isoHome;
+ process.env.USERPROFILE = isoHome;
+ // Re-require to pick up new HOME
+ delete require.cache[require.resolve('../../scripts/lib/session-aliases')];
+ delete require.cache[require.resolve('../../scripts/lib/utils')];
+ const freshAliases = require('../../scripts/lib/session-aliases');
+
+ // Set up a valid alias
+ freshAliases.setAlias('title-save-fail', '/path/session', 'Original Title');
+ // Verify no leftover .tmp/.bak
+ const ap = freshAliases.getAliasesPath();
+ assert.ok(fs.existsSync(ap), 'Alias file should exist after setAlias');
+
+ // Make .claude dir read-only so saveAliases fails when creating .bak
+ fs.chmodSync(isoClaudeDir, 0o555);
+
+ const result = freshAliases.updateAliasTitle('title-save-fail', 'New Title');
+ assert.strictEqual(result.success, false, 'Should fail when save is blocked');
+ assert.ok(result.error.includes('Failed to update alias title'),
+ `Should return save failure error, got: ${result.error}`);
+ } finally {
+ try { fs.chmodSync(isoClaudeDir, 0o755); } catch { /* best-effort */ }
+ process.env.HOME = savedHome;
+ process.env.USERPROFILE = savedProfile;
+ delete require.cache[require.resolve('../../scripts/lib/session-aliases')];
+ delete require.cache[require.resolve('../../scripts/lib/utils')];
+ fs.rmSync(isoHome, { recursive: true, force: true });
+ }
+ })) passed++; else failed++;
+
// Summary
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
process.exit(failed > 0 ? 1 : 0);