fix: stabilize windows hook tests

This commit is contained in:
Affaan Mustafa
2026-03-20 03:23:37 -07:00
parent 8ebb47bdd1
commit 04ad4737de
2 changed files with 34 additions and 4 deletions

View File

@@ -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);
}

View File

@@ -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' }
});