refactor: dedupe agent and browser cli helpers

This commit is contained in:
Peter Steinberger
2026-03-03 00:14:48 +00:00
parent fe14be2352
commit fd3ca8a34c
46 changed files with 1051 additions and 1117 deletions

View File

@@ -115,6 +115,16 @@ describe("subagent registry persistence", () => {
return registryPath;
};
const readPersistedRun = async <T>(
registryPath: string,
runId: string,
): Promise<T | undefined> => {
const parsed = JSON.parse(await fs.readFile(registryPath, "utf8")) as {
runs?: Record<string, unknown>;
};
return parsed.runs?.[runId] as T | undefined;
};
const createPersistedEndedRun = (params: {
runId: string;
childSessionKey: string;
@@ -316,11 +326,12 @@ describe("subagent registry persistence", () => {
await restartRegistryAndFlush();
expect(announceSpy).toHaveBeenCalledTimes(1);
const afterFirst = JSON.parse(await fs.readFile(registryPath, "utf8")) as {
runs: Record<string, { cleanupHandled?: boolean; cleanupCompletedAt?: number }>;
};
expect(afterFirst.runs["run-3"].cleanupHandled).toBe(false);
expect(afterFirst.runs["run-3"].cleanupCompletedAt).toBeUndefined();
const afterFirst = await readPersistedRun<{
cleanupHandled?: boolean;
cleanupCompletedAt?: number;
}>(registryPath, "run-3");
expect(afterFirst?.cleanupHandled).toBe(false);
expect(afterFirst?.cleanupCompletedAt).toBeUndefined();
announceSpy.mockResolvedValueOnce(true);
await restartRegistryAndFlush();
@@ -345,10 +356,8 @@ describe("subagent registry persistence", () => {
await restartRegistryAndFlush();
expect(announceSpy).toHaveBeenCalledTimes(1);
const afterFirst = JSON.parse(await fs.readFile(registryPath, "utf8")) as {
runs: Record<string, { cleanupHandled?: boolean }>;
};
expect(afterFirst.runs["run-4"]?.cleanupHandled).toBe(false);
const afterFirst = await readPersistedRun<{ cleanupHandled?: boolean }>(registryPath, "run-4");
expect(afterFirst?.cleanupHandled).toBe(false);
announceSpy.mockResolvedValueOnce(true);
await restartRegistryAndFlush();