mirror of
https://github.com/catlog22/Claude-Code-Workflow.git
synced 2026-03-12 17:21:19 +08:00
Add comprehensive tests for CLI functionality and CodexLens compatibility
- Introduced tests for stale running fallback in CLI watch functionality to ensure proper handling of saved conversations. - Added compatibility tests for CodexLens CLI to verify index initialization despite compatibility conflicts. - Implemented tests for Smart Search MCP usage to validate default settings and path handling. - Created tests for UV Manager to ensure Python preference handling works as expected. - Added a detailed guide for CCW/Codex commands and skills, covering core commands, execution modes, and templates.
This commit is contained in:
@@ -199,6 +199,202 @@ describe('cli routes integration', async () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('GET /api/cli/execution prefers newer saved conversation over stale active running state', async () => {
|
||||
const broadcasts: any[] = [];
|
||||
const { server, baseUrl } = await createServer(PROJECT_ROOT, broadcasts);
|
||||
const historyStoreUrl = new URL('../../dist/tools/cli-history-store.js', import.meta.url);
|
||||
const historyStoreMod: any = await import(historyStoreUrl.href);
|
||||
const executionId = `EXEC-STALE-DETAIL-${Date.now()}`;
|
||||
const now = 1_741_392_000_000;
|
||||
|
||||
try {
|
||||
const store = new historyStoreMod.CliHistoryStore(PROJECT_ROOT);
|
||||
store.saveConversation({
|
||||
id: executionId,
|
||||
created_at: new Date(now - 10_000).toISOString(),
|
||||
updated_at: new Date(now - 5_000).toISOString(),
|
||||
tool: 'codex',
|
||||
model: 'default',
|
||||
mode: 'analysis',
|
||||
category: 'user',
|
||||
total_duration_ms: 2300,
|
||||
turn_count: 1,
|
||||
latest_status: 'success',
|
||||
turns: [{
|
||||
turn: 1,
|
||||
timestamp: new Date(now - 5_000).toISOString(),
|
||||
prompt: 'SAVED DETAIL SHOULD WIN',
|
||||
duration_ms: 2300,
|
||||
status: 'success',
|
||||
exit_code: 0,
|
||||
output: {
|
||||
stdout: 'saved output',
|
||||
stderr: '',
|
||||
truncated: false,
|
||||
cached: false,
|
||||
}
|
||||
}]
|
||||
});
|
||||
store.close();
|
||||
|
||||
mock.method(Date, 'now', () => now - 60_000);
|
||||
mod.updateActiveExecution({
|
||||
type: 'started',
|
||||
executionId,
|
||||
tool: 'codex',
|
||||
mode: 'analysis',
|
||||
prompt: 'STALE ACTIVE DETAIL'
|
||||
});
|
||||
mock.restoreAll();
|
||||
mock.method(console, 'log', () => {});
|
||||
mock.method(console, 'error', () => {});
|
||||
|
||||
const res = await requestJson(
|
||||
baseUrl,
|
||||
'GET',
|
||||
`/api/cli/execution?path=${encodeURIComponent(PROJECT_ROOT)}&id=${encodeURIComponent(executionId)}`,
|
||||
);
|
||||
|
||||
assert.equal(res.status, 200);
|
||||
assert.equal(res.json?._active, undefined);
|
||||
assert.equal(res.json?.turns?.[0]?.prompt, 'SAVED DETAIL SHOULD WIN');
|
||||
assert.equal(res.json?.latest_status, 'success');
|
||||
} finally {
|
||||
await new Promise<void>((resolve) => server.close(() => resolve()));
|
||||
}
|
||||
});
|
||||
|
||||
it('GET /api/cli/active filters stale running state when saved conversation is newer', async () => {
|
||||
const broadcasts: any[] = [];
|
||||
const { server, baseUrl } = await createServer(PROJECT_ROOT, broadcasts);
|
||||
const historyStoreUrl = new URL('../../dist/tools/cli-history-store.js', import.meta.url);
|
||||
const historyStoreMod: any = await import(historyStoreUrl.href);
|
||||
const executionId = `EXEC-STALE-ACTIVE-${Date.now()}`;
|
||||
const now = 1_741_392_500_000;
|
||||
|
||||
try {
|
||||
const store = new historyStoreMod.CliHistoryStore(PROJECT_ROOT);
|
||||
store.saveConversation({
|
||||
id: executionId,
|
||||
created_at: new Date(now - 12_000).toISOString(),
|
||||
updated_at: new Date(now - 4_000).toISOString(),
|
||||
tool: 'codex',
|
||||
model: 'default',
|
||||
mode: 'analysis',
|
||||
category: 'user',
|
||||
total_duration_ms: 3200,
|
||||
turn_count: 1,
|
||||
latest_status: 'success',
|
||||
turns: [{
|
||||
turn: 1,
|
||||
timestamp: new Date(now - 4_000).toISOString(),
|
||||
prompt: 'SAVED ACTIVE SHOULD WIN',
|
||||
duration_ms: 3200,
|
||||
status: 'success',
|
||||
exit_code: 0,
|
||||
output: {
|
||||
stdout: 'saved output',
|
||||
stderr: '',
|
||||
truncated: false,
|
||||
cached: false,
|
||||
}
|
||||
}]
|
||||
});
|
||||
store.close();
|
||||
|
||||
mock.method(Date, 'now', () => now - 60_000);
|
||||
mod.updateActiveExecution({
|
||||
type: 'started',
|
||||
executionId,
|
||||
tool: 'codex',
|
||||
mode: 'analysis',
|
||||
prompt: 'STALE ACTIVE SHOULD DISAPPEAR'
|
||||
});
|
||||
mock.restoreAll();
|
||||
mock.method(console, 'log', () => {});
|
||||
mock.method(console, 'error', () => {});
|
||||
|
||||
const res = await requestJson(
|
||||
baseUrl,
|
||||
'GET',
|
||||
`/api/cli/active?path=${encodeURIComponent(PROJECT_ROOT)}`,
|
||||
);
|
||||
|
||||
assert.equal(res.status, 200);
|
||||
assert.equal(Array.isArray(res.json?.executions), true);
|
||||
assert.equal(res.json.executions.some((exec: any) => exec.id === executionId), false);
|
||||
} finally {
|
||||
await new Promise<void>((resolve) => server.close(() => resolve()));
|
||||
}
|
||||
});
|
||||
|
||||
it('GET /api/cli/active keeps running state when saved conversation is older', async () => {
|
||||
const broadcasts: any[] = [];
|
||||
const { server, baseUrl } = await createServer(PROJECT_ROOT, broadcasts);
|
||||
const historyStoreUrl = new URL('../../dist/tools/cli-history-store.js', import.meta.url);
|
||||
const historyStoreMod: any = await import(historyStoreUrl.href);
|
||||
const executionId = `EXEC-ACTIVE-RESUME-${Date.now()}`;
|
||||
const now = 1_741_393_000_000;
|
||||
|
||||
try {
|
||||
const store = new historyStoreMod.CliHistoryStore(PROJECT_ROOT);
|
||||
store.saveConversation({
|
||||
id: executionId,
|
||||
created_at: new Date(now - 120_000).toISOString(),
|
||||
updated_at: new Date(now - 110_000).toISOString(),
|
||||
tool: 'codex',
|
||||
model: 'default',
|
||||
mode: 'analysis',
|
||||
category: 'user',
|
||||
total_duration_ms: 1200,
|
||||
turn_count: 1,
|
||||
latest_status: 'success',
|
||||
turns: [{
|
||||
turn: 1,
|
||||
timestamp: new Date(now - 110_000).toISOString(),
|
||||
prompt: 'OLDER SAVED TURN',
|
||||
duration_ms: 1200,
|
||||
status: 'success',
|
||||
exit_code: 0,
|
||||
output: {
|
||||
stdout: 'older output',
|
||||
stderr: '',
|
||||
truncated: false,
|
||||
cached: false,
|
||||
}
|
||||
}]
|
||||
});
|
||||
store.close();
|
||||
|
||||
mock.method(Date, 'now', () => now - 20_000);
|
||||
mod.updateActiveExecution({
|
||||
type: 'started',
|
||||
executionId,
|
||||
tool: 'codex',
|
||||
mode: 'analysis',
|
||||
prompt: 'NEWER ACTIVE SHOULD STAY'
|
||||
});
|
||||
mock.restoreAll();
|
||||
mock.method(console, 'log', () => {});
|
||||
mock.method(console, 'error', () => {});
|
||||
|
||||
const res = await requestJson(
|
||||
baseUrl,
|
||||
'GET',
|
||||
`/api/cli/active?path=${encodeURIComponent(PROJECT_ROOT)}`,
|
||||
);
|
||||
|
||||
assert.equal(res.status, 200);
|
||||
assert.equal(Array.isArray(res.json?.executions), true);
|
||||
const activeExecution = res.json.executions.find((exec: any) => exec.id === executionId);
|
||||
assert.ok(activeExecution);
|
||||
assert.equal(activeExecution.status, 'running');
|
||||
assert.equal(activeExecution.prompt, 'NEWER ACTIVE SHOULD STAY');
|
||||
} finally {
|
||||
await new Promise<void>((resolve) => server.close(() => resolve()));
|
||||
}
|
||||
});
|
||||
|
||||
it('PUT /api/cli/config/gemini updates config and broadcasts event', async () => {
|
||||
const broadcasts: any[] = [];
|
||||
const { server, baseUrl } = await createServer(PROJECT_ROOT, broadcasts);
|
||||
|
||||
Reference in New Issue
Block a user