@os-eco/overstory-cli 0.7.2 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/agents/hooks-deployer.test.ts +6 -5
- package/src/agents/identity.test.ts +3 -2
- package/src/agents/manifest.test.ts +4 -3
- package/src/agents/overlay.test.ts +3 -2
- package/src/commands/agents.test.ts +5 -4
- package/src/commands/completions.test.ts +8 -5
- package/src/commands/completions.ts +37 -1
- package/src/commands/costs.test.ts +4 -3
- package/src/commands/dashboard.test.ts +265 -6
- package/src/commands/dashboard.ts +367 -64
- package/src/commands/doctor.test.ts +3 -2
- package/src/commands/errors.test.ts +3 -2
- package/src/commands/feed.test.ts +3 -2
- package/src/commands/feed.ts +2 -29
- package/src/commands/inspect.test.ts +3 -2
- package/src/commands/log.test.ts +248 -8
- package/src/commands/log.ts +193 -110
- package/src/commands/logs.test.ts +3 -2
- package/src/commands/mail.test.ts +3 -2
- package/src/commands/metrics.test.ts +4 -3
- package/src/commands/nudge.test.ts +3 -2
- package/src/commands/prime.test.ts +2 -2
- package/src/commands/replay.test.ts +3 -2
- package/src/commands/run.test.ts +2 -1
- package/src/commands/sling.test.ts +127 -0
- package/src/commands/sling.ts +101 -3
- package/src/commands/status.test.ts +8 -8
- package/src/commands/trace.test.ts +3 -2
- package/src/commands/watch.test.ts +3 -2
- package/src/config.test.ts +3 -3
- package/src/doctor/agents.test.ts +3 -2
- package/src/doctor/logs.test.ts +3 -2
- package/src/doctor/structure.test.ts +3 -2
- package/src/index.ts +3 -1
- package/src/logging/color.ts +1 -1
- package/src/logging/format.test.ts +110 -0
- package/src/logging/format.ts +42 -1
- package/src/logging/logger.test.ts +3 -2
- package/src/mail/client.test.ts +3 -2
- package/src/mail/store.test.ts +3 -2
- package/src/merge/queue.test.ts +3 -2
- package/src/merge/resolver.test.ts +39 -0
- package/src/merge/resolver.ts +1 -1
- package/src/mulch/client.test.ts +63 -2
- package/src/mulch/client.ts +62 -1
- package/src/runtimes/claude.test.ts +4 -3
- package/src/runtimes/pi-guards.test.ts +26 -2
- package/src/runtimes/pi-guards.ts +3 -3
- package/src/schema-consistency.test.ts +4 -2
- package/src/sessions/compat.test.ts +3 -2
- package/src/sessions/store.test.ts +3 -2
- package/src/test-helpers.ts +20 -1
- package/src/watchdog/daemon.test.ts +4 -3
- package/src/watchdog/triage.test.ts +3 -2
|
@@ -203,6 +203,9 @@ function createMockMulchClient(
|
|
|
203
203
|
action: "analyze",
|
|
204
204
|
};
|
|
205
205
|
},
|
|
206
|
+
async appendOutcome() {
|
|
207
|
+
// No-op stub: resolver tests don't exercise outcome appending
|
|
208
|
+
},
|
|
206
209
|
};
|
|
207
210
|
}
|
|
208
211
|
|
|
@@ -1440,6 +1443,42 @@ describe("createMergeResolver", () => {
|
|
|
1440
1443
|
});
|
|
1441
1444
|
});
|
|
1442
1445
|
|
|
1446
|
+
describe("queryConflictHistory uses sortByScore", () => {
|
|
1447
|
+
test("passes sortByScore: true to mulch search when querying conflict history", async () => {
|
|
1448
|
+
const repoDir = await createTempGitRepo();
|
|
1449
|
+
try {
|
|
1450
|
+
const defaultBranch = await getDefaultBranch(repoDir);
|
|
1451
|
+
await setupContentConflict(repoDir, defaultBranch);
|
|
1452
|
+
|
|
1453
|
+
const entry = makeTestEntry({
|
|
1454
|
+
branchName: "feature-branch",
|
|
1455
|
+
filesModified: ["src/test.ts"],
|
|
1456
|
+
});
|
|
1457
|
+
|
|
1458
|
+
// Capture search call options
|
|
1459
|
+
let capturedSearchOptions: unknown;
|
|
1460
|
+
const mockMulchClient = createMockMulchClient();
|
|
1461
|
+
mockMulchClient.search = async (_query, options) => {
|
|
1462
|
+
capturedSearchOptions = options;
|
|
1463
|
+
return "";
|
|
1464
|
+
};
|
|
1465
|
+
|
|
1466
|
+
const resolver = createMergeResolver({
|
|
1467
|
+
aiResolveEnabled: false,
|
|
1468
|
+
reimagineEnabled: false,
|
|
1469
|
+
mulchClient: mockMulchClient,
|
|
1470
|
+
});
|
|
1471
|
+
|
|
1472
|
+
await resolver.resolve(entry, defaultBranch, repoDir);
|
|
1473
|
+
|
|
1474
|
+
// Verify sortByScore was passed to search
|
|
1475
|
+
expect(capturedSearchOptions).toMatchObject({ sortByScore: true });
|
|
1476
|
+
} finally {
|
|
1477
|
+
await cleanupTempDir(repoDir);
|
|
1478
|
+
}
|
|
1479
|
+
});
|
|
1480
|
+
});
|
|
1481
|
+
|
|
1443
1482
|
describe("AI-resolve with history context", () => {
|
|
1444
1483
|
test("includes historical context in AI prompt when available", async () => {
|
|
1445
1484
|
const repoDir = await createTempGitRepo();
|
package/src/merge/resolver.ts
CHANGED
|
@@ -514,7 +514,7 @@ async function queryConflictHistory(
|
|
|
514
514
|
entry: MergeEntry,
|
|
515
515
|
): Promise<ConflictHistory> {
|
|
516
516
|
try {
|
|
517
|
-
const searchOutput = await mulchClient.search("merge-conflict");
|
|
517
|
+
const searchOutput = await mulchClient.search("merge-conflict", { sortByScore: true });
|
|
518
518
|
const patterns = parseConflictPatterns(searchOutput);
|
|
519
519
|
return buildConflictHistory(patterns, entry.filesModified);
|
|
520
520
|
} catch {
|
package/src/mulch/client.test.ts
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
9
|
-
import { mkdtemp
|
|
9
|
+
import { mkdtemp } from "node:fs/promises";
|
|
10
10
|
import { tmpdir } from "node:os";
|
|
11
11
|
import { join } from "node:path";
|
|
12
12
|
import { AgentError } from "../errors.ts";
|
|
13
|
+
import { cleanupTempDir } from "../test-helpers.ts";
|
|
13
14
|
import { createMulchClient } from "./client.ts";
|
|
14
15
|
|
|
15
16
|
// Check if mulch is available
|
|
@@ -30,7 +31,7 @@ describe("createMulchClient", () => {
|
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
afterEach(async () => {
|
|
33
|
-
await
|
|
34
|
+
await cleanupTempDir(tempDir);
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
/**
|
|
@@ -162,6 +163,33 @@ describe("createMulchClient", () => {
|
|
|
162
163
|
});
|
|
163
164
|
expect(typeof result).toBe("string");
|
|
164
165
|
});
|
|
166
|
+
|
|
167
|
+
test.skipIf(!hasMulch)("passes --sort-by-score flag in prime options", async () => {
|
|
168
|
+
await initMulch();
|
|
169
|
+
const client = createMulchClient(tempDir);
|
|
170
|
+
// mulch prime --sort-by-score may not be supported in older mulch versions;
|
|
171
|
+
// the interface and impl are forward-looking — test accepts both outcomes.
|
|
172
|
+
try {
|
|
173
|
+
const result = await client.prime([], "markdown", { sortByScore: true });
|
|
174
|
+
expect(typeof result).toBe("string");
|
|
175
|
+
} catch (error) {
|
|
176
|
+
expect(error).toBeInstanceOf(AgentError);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
test.skipIf(!hasMulch)("passes --sort-by-score with --files together", async () => {
|
|
181
|
+
await initMulch();
|
|
182
|
+
const client = createMulchClient(tempDir);
|
|
183
|
+
try {
|
|
184
|
+
const result = await client.prime([], "markdown", {
|
|
185
|
+
files: ["src/config.ts"],
|
|
186
|
+
sortByScore: true,
|
|
187
|
+
});
|
|
188
|
+
expect(typeof result).toBe("string");
|
|
189
|
+
} catch (error) {
|
|
190
|
+
expect(error).toBeInstanceOf(AgentError);
|
|
191
|
+
}
|
|
192
|
+
});
|
|
165
193
|
});
|
|
166
194
|
|
|
167
195
|
describe("status", () => {
|
|
@@ -452,6 +480,39 @@ describe("createMulchClient", () => {
|
|
|
452
480
|
expect(typeof result).toBe("string");
|
|
453
481
|
});
|
|
454
482
|
|
|
483
|
+
test.skipIf(!hasMulch)("passes --classification flag when provided", async () => {
|
|
484
|
+
await initMulch();
|
|
485
|
+
const client = createMulchClient(tempDir);
|
|
486
|
+
const result = await client.search("test", { classification: "foundational" });
|
|
487
|
+
expect(typeof result).toBe("string");
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
test.skipIf(!hasMulch)("passes --outcome-status flag when provided (success)", async () => {
|
|
491
|
+
await initMulch();
|
|
492
|
+
const client = createMulchClient(tempDir);
|
|
493
|
+
const result = await client.search("test", { outcomeStatus: "success" });
|
|
494
|
+
expect(typeof result).toBe("string");
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
test.skipIf(!hasMulch)("passes --outcome-status flag when provided (failure)", async () => {
|
|
498
|
+
await initMulch();
|
|
499
|
+
const client = createMulchClient(tempDir);
|
|
500
|
+
const result = await client.search("test", { outcomeStatus: "failure" });
|
|
501
|
+
expect(typeof result).toBe("string");
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
test.skipIf(!hasMulch)("passes all search filters together", async () => {
|
|
505
|
+
await initMulch();
|
|
506
|
+
const client = createMulchClient(tempDir);
|
|
507
|
+
const result = await client.search("test", {
|
|
508
|
+
classification: "tactical",
|
|
509
|
+
outcomeStatus: "success",
|
|
510
|
+
sortByScore: true,
|
|
511
|
+
file: "src/config.ts",
|
|
512
|
+
});
|
|
513
|
+
expect(typeof result).toBe("string");
|
|
514
|
+
});
|
|
515
|
+
|
|
455
516
|
test.skipIf(!hasMulch)("roundtrip: record via API then search and find it", async () => {
|
|
456
517
|
await initMulch();
|
|
457
518
|
const addProc = Bun.spawn(["ml", "add", "roundtrip"], {
|
package/src/mulch/client.ts
CHANGED
|
@@ -28,9 +28,22 @@ export interface MulchClient {
|
|
|
28
28
|
options?: {
|
|
29
29
|
files?: string[];
|
|
30
30
|
excludeDomain?: string[];
|
|
31
|
+
sortByScore?: boolean;
|
|
31
32
|
},
|
|
32
33
|
): Promise<string>;
|
|
33
34
|
|
|
35
|
+
/** Append an outcome entry to an existing record by ID in the given domain. */
|
|
36
|
+
appendOutcome(
|
|
37
|
+
domain: string,
|
|
38
|
+
id: string,
|
|
39
|
+
outcome: {
|
|
40
|
+
status: "success" | "failure" | "partial";
|
|
41
|
+
agent?: string;
|
|
42
|
+
notes?: string;
|
|
43
|
+
duration?: number;
|
|
44
|
+
},
|
|
45
|
+
): Promise<void>;
|
|
46
|
+
|
|
34
47
|
/** Show domain statistics. */
|
|
35
48
|
status(): Promise<MulchStatus>;
|
|
36
49
|
|
|
@@ -58,7 +71,15 @@ export interface MulchClient {
|
|
|
58
71
|
query(domain?: string): Promise<string>;
|
|
59
72
|
|
|
60
73
|
/** Search records across all domains. */
|
|
61
|
-
search(
|
|
74
|
+
search(
|
|
75
|
+
query: string,
|
|
76
|
+
options?: {
|
|
77
|
+
file?: string;
|
|
78
|
+
sortByScore?: boolean;
|
|
79
|
+
classification?: string;
|
|
80
|
+
outcomeStatus?: "success" | "failure";
|
|
81
|
+
},
|
|
82
|
+
): Promise<string>;
|
|
62
83
|
|
|
63
84
|
/** Show expertise record changes since a git ref. */
|
|
64
85
|
diff(options?: { since?: string }): Promise<MulchDiffResult>;
|
|
@@ -214,6 +235,8 @@ interface MulchProgrammaticApi {
|
|
|
214
235
|
type?: string;
|
|
215
236
|
tag?: string;
|
|
216
237
|
classification?: string;
|
|
238
|
+
outcomeStatus?: "success" | "failure";
|
|
239
|
+
sortByScore?: boolean;
|
|
217
240
|
file?: string;
|
|
218
241
|
cwd?: string;
|
|
219
242
|
},
|
|
@@ -222,6 +245,22 @@ interface MulchProgrammaticApi {
|
|
|
222
245
|
domain: string,
|
|
223
246
|
options?: { type?: string; classification?: string; file?: string; cwd?: string },
|
|
224
247
|
): Promise<MulchExpertiseRecord[]>;
|
|
248
|
+
appendOutcome(
|
|
249
|
+
domain: string,
|
|
250
|
+
id: string,
|
|
251
|
+
outcome: {
|
|
252
|
+
status: "success" | "failure" | "partial";
|
|
253
|
+
agent?: string;
|
|
254
|
+
notes?: string;
|
|
255
|
+
duration?: number;
|
|
256
|
+
recorded_at?: string;
|
|
257
|
+
},
|
|
258
|
+
options?: { cwd?: string },
|
|
259
|
+
): Promise<{
|
|
260
|
+
record: MulchExpertiseRecord;
|
|
261
|
+
outcome: { status: string; agent?: string; notes?: string; recorded_at?: string };
|
|
262
|
+
total_outcomes: number;
|
|
263
|
+
}>;
|
|
225
264
|
}
|
|
226
265
|
|
|
227
266
|
const MULCH_PKG = "@os-eco/mulch-cli";
|
|
@@ -406,6 +445,9 @@ export function createMulchClient(cwd: string): MulchClient {
|
|
|
406
445
|
if (options?.excludeDomain && options.excludeDomain.length > 0) {
|
|
407
446
|
args.push("--exclude-domain", ...options.excludeDomain);
|
|
408
447
|
}
|
|
448
|
+
if (options?.sortByScore) {
|
|
449
|
+
args.push("--sort-by-score");
|
|
450
|
+
}
|
|
409
451
|
const { stdout } = await runMulch(args, "prime");
|
|
410
452
|
return stdout;
|
|
411
453
|
},
|
|
@@ -472,6 +514,9 @@ export function createMulchClient(cwd: string): MulchClient {
|
|
|
472
514
|
const api = await loadMulchApi();
|
|
473
515
|
const results = await api.searchExpertise(query, {
|
|
474
516
|
file: options?.file,
|
|
517
|
+
classification: options?.classification,
|
|
518
|
+
outcomeStatus: options?.outcomeStatus,
|
|
519
|
+
sortByScore: options?.sortByScore,
|
|
475
520
|
cwd,
|
|
476
521
|
});
|
|
477
522
|
return formatSearchResults(results);
|
|
@@ -595,5 +640,21 @@ export function createMulchClient(cwd: string): MulchClient {
|
|
|
595
640
|
throw new AgentError(`Failed to parse JSON from mulch compact: ${trimmed.slice(0, 200)}`);
|
|
596
641
|
}
|
|
597
642
|
},
|
|
643
|
+
|
|
644
|
+
async appendOutcome(domain, id, outcome) {
|
|
645
|
+
const api = await loadMulchApi();
|
|
646
|
+
try {
|
|
647
|
+
await api.appendOutcome(
|
|
648
|
+
domain,
|
|
649
|
+
id,
|
|
650
|
+
{ ...outcome, recorded_at: new Date().toISOString() },
|
|
651
|
+
{ cwd },
|
|
652
|
+
);
|
|
653
|
+
} catch (error) {
|
|
654
|
+
throw new AgentError(
|
|
655
|
+
`mulch appendOutcome ${domain}/${id} failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
},
|
|
598
659
|
};
|
|
599
660
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
-
import { mkdtemp
|
|
2
|
+
import { mkdtemp } from "node:fs/promises";
|
|
3
3
|
import { tmpdir } from "node:os";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
+
import { cleanupTempDir } from "../test-helpers.ts";
|
|
5
6
|
import type { ResolvedModel } from "../types.ts";
|
|
6
7
|
import { ClaudeRuntime } from "./claude.ts";
|
|
7
8
|
import type { SpawnOpts } from "./types.ts";
|
|
@@ -239,7 +240,7 @@ describe("ClaudeRuntime", () => {
|
|
|
239
240
|
});
|
|
240
241
|
|
|
241
242
|
afterEach(async () => {
|
|
242
|
-
await
|
|
243
|
+
await cleanupTempDir(tempDir);
|
|
243
244
|
});
|
|
244
245
|
|
|
245
246
|
test("writes overlay to .claude/CLAUDE.md when overlay is provided", async () => {
|
|
@@ -373,7 +374,7 @@ describe("ClaudeRuntime", () => {
|
|
|
373
374
|
});
|
|
374
375
|
|
|
375
376
|
afterEach(async () => {
|
|
376
|
-
await
|
|
377
|
+
await cleanupTempDir(tempDir);
|
|
377
378
|
});
|
|
378
379
|
|
|
379
380
|
test("returns null for non-existent file", async () => {
|
|
@@ -349,7 +349,9 @@ describe("generatePiGuardExtension", () => {
|
|
|
349
349
|
|
|
350
350
|
test("generated code contains pi.exec ov log tool-start in tool_call handler", () => {
|
|
351
351
|
const generated = generatePiGuardExtension(builderHooks());
|
|
352
|
-
expect(generated).toContain(
|
|
352
|
+
expect(generated).toContain(
|
|
353
|
+
'pi.exec("ov", ["log", "tool-start", "--agent", AGENT_NAME, "--tool-name", event.toolName])',
|
|
354
|
+
);
|
|
353
355
|
});
|
|
354
356
|
|
|
355
357
|
test('generated code contains pi.on("tool_execution_end", ...)', () => {
|
|
@@ -359,7 +361,9 @@ describe("generatePiGuardExtension", () => {
|
|
|
359
361
|
|
|
360
362
|
test("generated code contains pi.exec ov log tool-end in tool_execution_end handler", () => {
|
|
361
363
|
const generated = generatePiGuardExtension(builderHooks());
|
|
362
|
-
expect(generated).toContain(
|
|
364
|
+
expect(generated).toContain(
|
|
365
|
+
'pi.exec("ov", ["log", "tool-end", "--agent", AGENT_NAME, "--tool-name", event.toolName])',
|
|
366
|
+
);
|
|
363
367
|
});
|
|
364
368
|
|
|
365
369
|
test('generated code contains pi.on("session_shutdown", ...)', () => {
|
|
@@ -373,6 +377,26 @@ describe("generatePiGuardExtension", () => {
|
|
|
373
377
|
'await pi.exec("ov", ["log", "session-end", "--agent", AGENT_NAME])',
|
|
374
378
|
);
|
|
375
379
|
});
|
|
380
|
+
|
|
381
|
+
test("tool_call handler passes --tool-name event.toolName to tool-start", () => {
|
|
382
|
+
const generated = generatePiGuardExtension(builderHooks());
|
|
383
|
+
expect(generated).toContain(
|
|
384
|
+
'pi.exec("ov", ["log", "tool-start", "--agent", AGENT_NAME, "--tool-name", event.toolName])',
|
|
385
|
+
);
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
test("tool_execution_end handler passes --tool-name event.toolName to tool-end", () => {
|
|
389
|
+
const generated = generatePiGuardExtension(builderHooks());
|
|
390
|
+
expect(generated).toContain(
|
|
391
|
+
'pi.exec("ov", ["log", "tool-end", "--agent", AGENT_NAME, "--tool-name", event.toolName])',
|
|
392
|
+
);
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
test("tool_execution_end handler uses named event parameter (not _event)", () => {
|
|
396
|
+
const generated = generatePiGuardExtension(builderHooks());
|
|
397
|
+
expect(generated).toContain('pi.on("tool_execution_end", async (event) => {');
|
|
398
|
+
expect(generated).not.toContain('pi.on("tool_execution_end", async (_event) => {');
|
|
399
|
+
});
|
|
376
400
|
});
|
|
377
401
|
|
|
378
402
|
describe("PiRuntime integration", () => {
|
|
@@ -241,7 +241,7 @@ export function generatePiGuardExtension(hooks: HooksDef): string {
|
|
|
241
241
|
`\tpi.on("tool_call", async (event) => {`,
|
|
242
242
|
`\t\t// Activity tracking: update lastActivity so watchdog knows agent is alive.`,
|
|
243
243
|
`\t\t// Fire-and-forget — do not await (avoids latency on every tool call).`,
|
|
244
|
-
`\t\tpi.exec("ov", ["log", "tool-start", "--agent", AGENT_NAME]).catch(() => {});`,
|
|
244
|
+
`\t\tpi.exec("ov", ["log", "tool-start", "--agent", AGENT_NAME, "--tool-name", event.toolName]).catch(() => {});`,
|
|
245
245
|
``,
|
|
246
246
|
`\t\t// 1. Block native team/task tools (all agents).`,
|
|
247
247
|
`\t\tif (TEAM_BLOCKED.has(event.toolName)) {`,
|
|
@@ -326,8 +326,8 @@ export function generatePiGuardExtension(hooks: HooksDef): string {
|
|
|
326
326
|
`\t * Tool execution end: fire-and-forget "ov log tool-end" for event tracking.`,
|
|
327
327
|
`\t * Paired with tool_call's tool-start fire for proper begin/end event logging.`,
|
|
328
328
|
`\t */`,
|
|
329
|
-
`\tpi.on("tool_execution_end", async (
|
|
330
|
-
`\t\tpi.exec("ov", ["log", "tool-end", "--agent", AGENT_NAME]).catch(() => {});`,
|
|
329
|
+
`\tpi.on("tool_execution_end", async (event) => {`,
|
|
330
|
+
`\t\tpi.exec("ov", ["log", "tool-end", "--agent", AGENT_NAME, "--tool-name", event.toolName]).catch(() => {});`,
|
|
331
331
|
`\t});`,
|
|
332
332
|
``,
|
|
333
333
|
`\t/**`,
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import { Database } from "bun:sqlite";
|
|
14
14
|
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
15
|
-
import { mkdtemp
|
|
15
|
+
import { mkdtemp } from "node:fs/promises";
|
|
16
16
|
import { tmpdir } from "node:os";
|
|
17
17
|
import { join } from "node:path";
|
|
18
18
|
import { createEventStore } from "./events/store.ts";
|
|
@@ -21,6 +21,8 @@ import { createMergeQueue } from "./merge/queue.ts";
|
|
|
21
21
|
import { createMetricsStore } from "./metrics/store.ts";
|
|
22
22
|
import { createSessionStore } from "./sessions/store.ts";
|
|
23
23
|
|
|
24
|
+
import { cleanupTempDir } from "./test-helpers.ts";
|
|
25
|
+
|
|
24
26
|
/** Extract sorted column names from a table via PRAGMA table_info(). */
|
|
25
27
|
function getTableColumns(db: Database, tableName: string): string[] {
|
|
26
28
|
const rows = db.prepare(`PRAGMA table_info(${tableName})`).all() as Array<{ name: string }>;
|
|
@@ -35,7 +37,7 @@ describe("SQL schema consistency", () => {
|
|
|
35
37
|
});
|
|
36
38
|
|
|
37
39
|
afterEach(async () => {
|
|
38
|
-
await
|
|
40
|
+
await cleanupTempDir(tmpDir);
|
|
39
41
|
});
|
|
40
42
|
|
|
41
43
|
describe("SessionStore", () => {
|
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
9
|
-
import { mkdtemp,
|
|
9
|
+
import { mkdtemp, writeFile } from "node:fs/promises";
|
|
10
10
|
import { tmpdir } from "node:os";
|
|
11
11
|
import { join } from "node:path";
|
|
12
|
+
import { cleanupTempDir } from "../test-helpers.ts";
|
|
12
13
|
import { openSessionStore } from "./compat.ts";
|
|
13
14
|
|
|
14
15
|
let tempDir: string;
|
|
@@ -22,7 +23,7 @@ beforeEach(async () => {
|
|
|
22
23
|
});
|
|
23
24
|
|
|
24
25
|
afterEach(async () => {
|
|
25
|
-
await
|
|
26
|
+
await cleanupTempDir(tempDir);
|
|
26
27
|
});
|
|
27
28
|
|
|
28
29
|
/** Create a sessions.json with the given entries. */
|
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
9
|
-
import { mkdtemp
|
|
9
|
+
import { mkdtemp } from "node:fs/promises";
|
|
10
10
|
import { tmpdir } from "node:os";
|
|
11
11
|
import { join } from "node:path";
|
|
12
|
+
import { cleanupTempDir } from "../test-helpers.ts";
|
|
12
13
|
import type { AgentSession, AgentState, InsertRun, Run, RunStore } from "../types.ts";
|
|
13
14
|
import { createRunStore, createSessionStore, type SessionStore } from "./store.ts";
|
|
14
15
|
|
|
@@ -24,7 +25,7 @@ beforeEach(async () => {
|
|
|
24
25
|
|
|
25
26
|
afterEach(async () => {
|
|
26
27
|
store.close();
|
|
27
|
-
await
|
|
28
|
+
await cleanupTempDir(tempDir);
|
|
28
29
|
});
|
|
29
30
|
|
|
30
31
|
/** Helper to create an AgentSession with optional overrides. */
|
package/src/test-helpers.ts
CHANGED
|
@@ -95,9 +95,28 @@ export async function getDefaultBranch(repoDir: string): Promise<string> {
|
|
|
95
95
|
|
|
96
96
|
/**
|
|
97
97
|
* Remove a temp directory. Safe to call even if the directory doesn't exist.
|
|
98
|
+
*
|
|
99
|
+
* On Windows, SQLite WAL/SHM file handles may linger briefly after db.close(),
|
|
100
|
+
* causing EBUSY errors on immediate rm(). Retries with exponential backoff
|
|
101
|
+
* (up to ~1.5s total) to handle this OS-level timing issue.
|
|
98
102
|
*/
|
|
99
103
|
export async function cleanupTempDir(dir: string): Promise<void> {
|
|
100
|
-
|
|
104
|
+
const maxRetries = process.platform === "win32" ? 5 : 0;
|
|
105
|
+
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
106
|
+
try {
|
|
107
|
+
await rm(dir, { recursive: true, force: true });
|
|
108
|
+
return;
|
|
109
|
+
} catch (err: unknown) {
|
|
110
|
+
const code = (err as NodeJS.ErrnoException).code;
|
|
111
|
+
if (code === "EBUSY" && attempt < maxRetries) {
|
|
112
|
+
// Exponential backoff: 50, 100, 200, 400, 800ms
|
|
113
|
+
await Bun.sleep(50 * 2 ** attempt);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
// Non-EBUSY or final attempt: swallow (temp dirs are cleaned by OS anyway)
|
|
117
|
+
if (code !== "ENOENT") return;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
101
120
|
}
|
|
102
121
|
|
|
103
122
|
/**
|
|
@@ -15,11 +15,12 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
18
|
-
import { mkdir, mkdtemp
|
|
18
|
+
import { mkdir, mkdtemp } from "node:fs/promises";
|
|
19
19
|
import { tmpdir } from "node:os";
|
|
20
20
|
import { join } from "node:path";
|
|
21
21
|
import { createEventStore } from "../events/store.ts";
|
|
22
22
|
import { createSessionStore } from "../sessions/store.ts";
|
|
23
|
+
import { cleanupTempDir } from "../test-helpers.ts";
|
|
23
24
|
import type { AgentSession, HealthCheck, StoredEvent } from "../types.ts";
|
|
24
25
|
import { buildCompletionMessage, runDaemonTick } from "./daemon.ts";
|
|
25
26
|
|
|
@@ -163,7 +164,7 @@ beforeEach(async () => {
|
|
|
163
164
|
});
|
|
164
165
|
|
|
165
166
|
afterEach(async () => {
|
|
166
|
-
await
|
|
167
|
+
await cleanupTempDir(tempRoot);
|
|
167
168
|
});
|
|
168
169
|
|
|
169
170
|
describe("daemon tick", () => {
|
|
@@ -1100,7 +1101,7 @@ describe("daemon mulch failure recording", () => {
|
|
|
1100
1101
|
});
|
|
1101
1102
|
|
|
1102
1103
|
afterEach(async () => {
|
|
1103
|
-
await
|
|
1104
|
+
await cleanupTempDir(tempRoot);
|
|
1104
1105
|
});
|
|
1105
1106
|
|
|
1106
1107
|
/** Track calls to the recordFailure mock. */
|
|
@@ -7,9 +7,10 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
|
10
|
-
import { mkdir, mkdtemp
|
|
10
|
+
import { mkdir, mkdtemp } from "node:fs/promises";
|
|
11
11
|
import { tmpdir } from "node:os";
|
|
12
12
|
import { join } from "node:path";
|
|
13
|
+
import { cleanupTempDir } from "../test-helpers.ts";
|
|
13
14
|
import { buildTriagePrompt, classifyResponse, triageAgent } from "./triage.ts";
|
|
14
15
|
|
|
15
16
|
describe("classifyResponse", () => {
|
|
@@ -97,7 +98,7 @@ describe("triageAgent", () => {
|
|
|
97
98
|
});
|
|
98
99
|
|
|
99
100
|
afterEach(async () => {
|
|
100
|
-
await
|
|
101
|
+
await cleanupTempDir(tempRoot);
|
|
101
102
|
});
|
|
102
103
|
|
|
103
104
|
test("returns 'extend' when no logs directory exists", async () => {
|