Skip to content

Commit 0d316a9

Browse files
committed
test: isolate shared /tmp session-store paths in runner and health suites
The agent-runner execution fixtures handed storePath "/tmp/sessions.json" to the real executeAgentTurn. Production resolution derives the agent database from the store's directory, so those turns created and migrated the machine-wide /tmp/openclaw-agent.sqlite. A stale copy of that file makes unrelated suites fail through the real session accessor the next time OPENCLAW_AGENT_SCHEMA_VERSION is bumped, which is the failure #132960 had to repair across 14 suites. Route the store paths through the existing test/helpers/temp-dir tracker: the auto-reply harness gains makeTestSessionStorePath() beside the tracked agentDir and workspace it already owns, and the two gateway health collector suites, whose resolveSessionStorePathCore mock made real target resolution inspect the same shared database read-only, get their own tracked directories. Production LOC unchanged.
1 parent 7504a3b commit 0d316a9

5 files changed

Lines changed: 48 additions & 10 deletions

‎src/auto-reply/reply/agent-runner-execution-cli-sessions.test.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import path from "node:path";
12
import { afterEach, describe, expect, it, vi } from "vitest";
23
import { buildPreparedCliRunContext } from "../../agents/cli-runner.test-helpers.js";
34
import { executeDeps } from "../../agents/cli-runner/execute-deps.js";
@@ -24,6 +25,7 @@ import {
2425
expectMockCallArgFields,
2526
initialFallbackAttemptOptions,
2627
createMinimalRunAgentTurnParams,
28+
makeTestSessionStorePath,
2729
} from "./agent-runner-execution.test-support.js";
2830
import type { FallbackRunnerParams } from "./agent-runner-execution.test-support.js";
2931

@@ -522,9 +524,10 @@ describe("executeAgentTurn: CLI session routing", () => {
522524
MediaTypes: ["image/png"],
523525
} as never;
524526
followupRun.userTurnTranscriptRecorder = createTestUserTurnRecorder(preparedUserTurnMessage);
527+
const storePath = makeTestSessionStorePath();
525528
const sessionEntry: SessionEntry = {
526529
sessionId: "session",
527-
sessionFile: "/tmp/session.jsonl",
530+
sessionFile: path.join(path.dirname(storePath), "session.jsonl"),
528531
updatedAt: 1,
529532
};
530533
const activeSessionStore = { main: sessionEntry };
@@ -534,7 +537,7 @@ describe("executeAgentTurn: CLI session routing", () => {
534537
commandBody: "runtime prompt",
535538
transcriptCommandBody: "display prompt",
536539
activeSessionStore,
537-
storePath: "/tmp/sessions.json",
540+
storePath,
538541
getActiveSessionEntry: () => activeSessionStore.main,
539542
});
540543

@@ -546,12 +549,12 @@ describe("executeAgentTurn: CLI session routing", () => {
546549
sessionId: "session",
547550
suppressNextUserMessagePersistence: false,
548551
persistAssistantTranscript: true,
549-
storePath: "/tmp/sessions.json",
552+
storePath,
550553
sessionTarget: {
551554
agentId: "main",
552555
sessionId: "session",
553556
sessionKey: "main",
554-
storePath: "/tmp/sessions.json",
557+
storePath,
555558
},
556559
});
557560
const call = requireMockCall(state.runCliAgentMock, 0, "CLI runtime");

‎src/auto-reply/reply/agent-runner-execution-context-failures.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
requireRecord,
1515
expectRecordFields,
1616
createMinimalRunAgentTurnParams,
17+
makeTestSessionStorePath,
1718
} from "./agent-runner-execution.test-support.js";
1819
import type { FallbackRunnerParams } from "./agent-runner-execution.test-support.js";
1920

@@ -49,7 +50,7 @@ describe("executeAgentTurn: context failures", () => {
4950
sessionKey: "agent:main:main",
5051
getActiveSessionEntry: () => activeSessionEntry,
5152
activeSessionStore,
52-
storePath: "/tmp/sessions.json",
53+
storePath: makeTestSessionStorePath(),
5354
});
5455

5556
expect(result.kind).toBe("final");
@@ -95,7 +96,7 @@ describe("executeAgentTurn: context failures", () => {
9596
sessionKey: "agent:main:main",
9697
getActiveSessionEntry: () => activeSessionEntry,
9798
activeSessionStore,
98-
storePath: "/tmp/sessions.json",
99+
storePath: makeTestSessionStorePath(),
99100
});
100101

101102
expect(result.kind).toBe("final");

‎src/auto-reply/reply/agent-runner-execution.test-support.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,18 @@ export function expectBlockReplyCall(
603603
expectMockCallArgFields(onBlockReply, index, "block reply payload", fields);
604604
}
605605

606+
/**
607+
* Session-store paths reach production resolution, which derives a real agent
608+
* SQLite file from the store's directory. A shared /tmp path would therefore
609+
* open the machine-wide agent database and make unrelated suites depend on it.
610+
*/
611+
export function makeTestSessionStorePath(): string {
612+
return path.join(
613+
useAutoCleanupTempDirTracker(onTestFinished).make("openclaw-agent-execution-store-"),
614+
"sessions.json",
615+
);
616+
}
617+
606618
export function createMinimalRunAgentTurnParams(overrides?: {
607619
followupRun?: FollowupRun;
608620
opts?: GetReplyOptions;

‎src/gateway/health/collector.deadline.test.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
1+
import path from "node:path";
2+
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
3+
import { createTempDirTracker } from "../../../test/helpers/temp-dir.js";
24
import type { ChannelPlugin } from "../../channels/plugins/types.plugin.js";
35
import type { OpenClawConfig } from "../../config/types.openclaw.js";
46

@@ -49,13 +51,22 @@ async function collectDeadlineSnapshot(params: {
4951
});
5052
}
5153

54+
const tempDirs = createTempDirTracker();
55+
56+
afterAll(() => {
57+
tempDirs.cleanup();
58+
});
59+
5260
describe("gateway health collection deadline", () => {
5361
beforeAll(async () => {
5462
vi.doMock("../../config/config.js", () => ({
5563
getRuntimeConfig: () => testConfig,
5664
}));
65+
// Store paths reach real SQLite target resolution, which inspects the agent
66+
// database beside them; a shared /tmp path would read machine-wide state.
67+
const storePath = path.join(tempDirs.make("openclaw-health-deadline-"), "sessions.json");
5768
vi.doMock("../../config/sessions/paths.js", () => ({
58-
resolveSessionStorePathCore: () => "/tmp/sessions.json",
69+
resolveSessionStorePathCore: () => storePath,
5970
}));
6071
vi.doMock("../../config/sessions/session-accessor.js", () => ({
6172
listSessionEntriesReadOnly: () => [],

‎src/gateway/health/collector.legacy-owner.test.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
1+
import path from "node:path";
2+
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
3+
import { createTempDirTracker } from "../../../test/helpers/temp-dir.js";
24
import type { ChannelPlugin } from "../../channels/plugins/types.public.js";
35
import { retainLegacyDefaultAgentId } from "../../config/legacy.default-agent-owner.js";
46
import type { OpenClawConfig } from "../../config/types.openclaw.js";
@@ -39,13 +41,22 @@ function createHealthPlugin(): ChannelPlugin {
3941
};
4042
}
4143

44+
const tempDirs = createTempDirTracker();
45+
46+
afterAll(() => {
47+
tempDirs.cleanup();
48+
});
49+
4250
describe("collectGatewayHealthSnapshot legacy owner projection", () => {
4351
beforeAll(async () => {
4452
vi.doMock("../../config/config.js", () => ({
4553
getRuntimeConfig: () => testConfig,
4654
}));
55+
// Store paths reach real SQLite target resolution, which inspects the agent
56+
// database beside them; a shared /tmp path would read machine-wide state.
57+
const storePath = path.join(tempDirs.make("openclaw-health-legacy-owner-"), "sessions.json");
4758
vi.doMock("../../config/sessions/paths.js", () => ({
48-
resolveSessionStorePathCore: () => "/tmp/sessions.json",
59+
resolveSessionStorePathCore: () => storePath,
4960
}));
5061
vi.doMock("../../config/sessions/session-accessor.js", () => ({
5162
listSessionEntriesReadOnly: () => [],

0 commit comments

Comments
 (0)