mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 13:11:10 +00:00
refactor: dedupe agent and browser cli helpers
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user