From 04ad4737de61d3f44a4dfa71ca2007125df9e486 Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Fri, 20 Mar 2026 03:23:37 -0700 Subject: [PATCH] fix: stabilize windows hook tests --- tests/hooks/hooks.test.js | 16 ++++++++++++++-- tests/integration/hooks.test.js | 22 ++++++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/tests/hooks/hooks.test.js b/tests/hooks/hooks.test.js index e192af2c..bd3440f1 100644 --- a/tests/hooks/hooks.test.js +++ b/tests/hooks/hooks.test.js @@ -2356,17 +2356,25 @@ async function runTests() { assert.strictEqual(code, 0, `detect-project should source cleanly, stderr: ${stderr}`); const [projectId, projectDir] = stdout.trim().split(/\r?\n/); - const nativeProjectDir = fromBashPath(projectDir); const registryPath = path.join(homeDir, '.claude', 'homunculus', 'projects.json'); - const projectMetadataPath = path.join(nativeProjectDir, 'project.json'); + const expectedProjectDir = path.join( + homeDir, + '.claude', + 'homunculus', + 'projects', + projectId + ); + const projectMetadataPath = path.join(expectedProjectDir, 'project.json'); assert.ok(projectId, 'detect-project should emit a project id'); + assert.ok(projectDir, 'detect-project should emit a project directory'); assert.ok(fs.existsSync(registryPath), 'projects.json should be created'); assert.ok(fs.existsSync(projectMetadataPath), 'project.json should be written in the project directory'); const registry = JSON.parse(fs.readFileSync(registryPath, 'utf8')); const metadata = JSON.parse(fs.readFileSync(projectMetadataPath, 'utf8')); const nativeMetadataRoot = fromBashPath(metadata.root); + const nativeProjectDir = fromBashPath(projectDir); assert.ok(registry[projectId], 'registry should contain the detected project'); assert.strictEqual(metadata.id, projectId, 'project.json should include the detected id'); @@ -2375,6 +2383,10 @@ async function runTests() { assert.strictEqual(metadata.remote, 'https://github.com/example/ecc-test.git', 'project.json should include the sanitized remote'); assert.ok(metadata.created_at, 'project.json should include created_at'); assert.ok(metadata.last_seen, 'project.json should include last_seen'); + assert.ok( + nativeProjectDir.endsWith(path.join('projects', projectId)), + `PROJECT_DIR should point at the project storage directory, got: ${projectDir}` + ); } finally { cleanupTestDir(testRoot); } diff --git a/tests/integration/hooks.test.js b/tests/integration/hooks.test.js index 79a88bef..df47e213 100644 --- a/tests/integration/hooks.test.js +++ b/tests/integration/hooks.test.js @@ -171,6 +171,16 @@ function cleanupTestDir(testDir) { fs.rmSync(testDir, { recursive: true, force: true }); } +function getHookCommandByDescription(hooks, lifecycle, descriptionText) { + const hookGroup = hooks.hooks[lifecycle]?.find( + entry => entry.description && entry.description.includes(descriptionText) + ); + + assert.ok(hookGroup, `Expected ${lifecycle} hook matching "${descriptionText}"`); + assert.ok(hookGroup.hooks?.[0]?.command, `Expected ${lifecycle} hook command for "${descriptionText}"`); + return hookGroup.hooks[0].command; +} + // Test suite async function runTests() { console.log('\n=== Hook Integration Tests ===\n'); @@ -253,7 +263,11 @@ async function runTests() { if (await asyncTest('dev server hook transforms command to tmux session', async () => { // Test the auto-tmux dev hook — transforms dev commands to run in tmux - const hookCommand = hooks.hooks.PreToolUse[0].hooks[0].command; + const hookCommand = getHookCommandByDescription( + hooks, + 'PreToolUse', + 'Auto-start dev servers in tmux' + ); const result = await runHookCommand(hookCommand, { tool_input: { command: 'npm run dev' } }); @@ -280,7 +294,11 @@ async function runTests() { if (await asyncTest('dev server hook transforms yarn dev to tmux session', async () => { // The auto-tmux dev hook transforms dev commands (yarn dev, npm run dev, etc.) - const hookCommand = hooks.hooks.PreToolUse[0].hooks[0].command; + const hookCommand = getHookCommandByDescription( + hooks, + 'PreToolUse', + 'Auto-start dev servers in tmux' + ); const result = await runHookCommand(hookCommand, { tool_input: { command: 'yarn dev' } });