mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-06 17:23:28 +08:00
fix: stabilize windows hook tests
This commit is contained in:
@@ -2356,17 +2356,25 @@ async function runTests() {
|
|||||||
assert.strictEqual(code, 0, `detect-project should source cleanly, stderr: ${stderr}`);
|
assert.strictEqual(code, 0, `detect-project should source cleanly, stderr: ${stderr}`);
|
||||||
|
|
||||||
const [projectId, projectDir] = stdout.trim().split(/\r?\n/);
|
const [projectId, projectDir] = stdout.trim().split(/\r?\n/);
|
||||||
const nativeProjectDir = fromBashPath(projectDir);
|
|
||||||
const registryPath = path.join(homeDir, '.claude', 'homunculus', 'projects.json');
|
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(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(registryPath), 'projects.json should be created');
|
||||||
assert.ok(fs.existsSync(projectMetadataPath), 'project.json should be written in the project directory');
|
assert.ok(fs.existsSync(projectMetadataPath), 'project.json should be written in the project directory');
|
||||||
|
|
||||||
const registry = JSON.parse(fs.readFileSync(registryPath, 'utf8'));
|
const registry = JSON.parse(fs.readFileSync(registryPath, 'utf8'));
|
||||||
const metadata = JSON.parse(fs.readFileSync(projectMetadataPath, 'utf8'));
|
const metadata = JSON.parse(fs.readFileSync(projectMetadataPath, 'utf8'));
|
||||||
const nativeMetadataRoot = fromBashPath(metadata.root);
|
const nativeMetadataRoot = fromBashPath(metadata.root);
|
||||||
|
const nativeProjectDir = fromBashPath(projectDir);
|
||||||
|
|
||||||
assert.ok(registry[projectId], 'registry should contain the detected project');
|
assert.ok(registry[projectId], 'registry should contain the detected project');
|
||||||
assert.strictEqual(metadata.id, projectId, 'project.json should include the detected id');
|
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.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.created_at, 'project.json should include created_at');
|
||||||
assert.ok(metadata.last_seen, 'project.json should include last_seen');
|
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 {
|
} finally {
|
||||||
cleanupTestDir(testRoot);
|
cleanupTestDir(testRoot);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,6 +171,16 @@ function cleanupTestDir(testDir) {
|
|||||||
fs.rmSync(testDir, { recursive: true, force: true });
|
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
|
// Test suite
|
||||||
async function runTests() {
|
async function runTests() {
|
||||||
console.log('\n=== Hook Integration Tests ===\n');
|
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 () => {
|
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
|
// 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, {
|
const result = await runHookCommand(hookCommand, {
|
||||||
tool_input: { command: 'npm run dev' }
|
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 () => {
|
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.)
|
// 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, {
|
const result = await runHookCommand(hookCommand, {
|
||||||
tool_input: { command: 'yarn dev' }
|
tool_input: { command: 'yarn dev' }
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user