Skip to content

Commit 2195f94

Browse files
author
Peter Steinberger
committed
test(agents): reuse worktree state database fixture
1 parent 48d3f2e commit 2195f94

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎src/agents/worktrees/service.test.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ import { promisify } from "node:util";
77
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
88
import { closeOpenClawStateDatabaseForTest } from "../../state/openclaw-state-db.js";
99
import {
10+
deleteRegistryWorktree,
11+
finalizeWorktreeRemovalRows,
1012
getRegistryWorktree,
1113
getRegistryWorktreeProvisionedChunk,
1214
getRegistryWorktreeProvisionedPaths,
1315
getRegistryWorktreeProvisionedState,
16+
listRegistryWorktrees,
1417
} from "./registry.js";
1518
import {
1619
IDLE_GC_MS,
@@ -70,6 +73,7 @@ describe("ManagedWorktreeService", () => {
7073
let templateRoot: string;
7174
let templateRepo: string;
7275
let gitTemplate: string;
76+
let stateDir: string;
7377
let root: string;
7478
let repo: string;
7579
let env: NodeJS.ProcessEnv;
@@ -80,13 +84,15 @@ describe("ManagedWorktreeService", () => {
8084
const tempRoot = await fs.realpath(os.tmpdir());
8185
templateRoot = await fs.mkdtemp(path.join(tempRoot, "openclaw-managed-worktrees-template-"));
8286
gitTemplate = path.join(templateRoot, "git-template");
87+
stateDir = path.join(templateRoot, "state");
8388
// Keep the hooks directory expected by hook-safety coverage without copying
8489
// the host's sample hooks into every per-test repository.
8590
await fs.mkdir(path.join(gitTemplate, "hooks"), { recursive: true });
8691
templateRepo = await initializeRepository(templateRoot, gitTemplate);
8792
});
8893

8994
afterAll(async () => {
95+
closeOpenClawStateDatabaseForTest();
9096
await fs.rm(templateRoot, { recursive: true, force: true });
9197
});
9298

@@ -99,13 +105,17 @@ describe("ManagedWorktreeService", () => {
99105
recursive: true,
100106
});
101107
repo = await fs.realpath(repo);
102-
env = { ...process.env, OPENCLAW_STATE_DIR: path.join(root, "openclaw-state") };
108+
env = { ...process.env, OPENCLAW_STATE_DIR: stateDir };
103109
now = 1_700_000_000_000;
104110
service = new ManagedWorktreeService({ env, now: () => now });
105111
});
106112

107113
afterEach(async () => {
108-
closeOpenClawStateDatabaseForTest();
114+
for (const record of listRegistryWorktrees(env)) {
115+
finalizeWorktreeRemovalRows(env, record.id);
116+
deleteRegistryWorktree(env, record.id);
117+
}
118+
await fs.rm(path.join(stateDir, "worktrees"), { recursive: true, force: true });
109119
await fs.rm(root, { recursive: true, force: true });
110120
});
111121

0 commit comments

Comments
 (0)