test: drop unused session store path scaffolding

This commit is contained in:
Peter Steinberger
2026-05-08 09:20:15 +01:00
parent c74b2197f6
commit 0a2245c18c
4 changed files with 43 additions and 35 deletions

View File

@@ -2,7 +2,8 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { loadSessionStore, saveSessionStore, type SessionEntry } from "../../config/sessions.js";
import type { SessionEntry } from "../../config/sessions.js";
import { listSessionEntries, upsertSessionEntry } from "../../config/sessions/store.js";
import { appendSessionTranscriptMessage } from "../../config/sessions/transcript-append.js";
import { loadSqliteSessionTranscriptEvents } from "../../config/sessions/transcript-store.sqlite.js";
import type { OpenClawConfig } from "../../config/types.openclaw.js";
@@ -91,11 +92,9 @@ async function readSessionFileEntries(sessionFile: string) {
describe("CLI attempt execution", () => {
let tmpDir: string;
let storePath: string;
beforeEach(async () => {
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-cli-attempt-"));
storePath = path.join(tmpDir, "agents", "main", "sessions", "sessions.json");
vi.stubEnv("OPENCLAW_STATE_DIR", tmpDir);
runCliAgentMock.mockReset();
runEmbeddedPiAgentMock.mockReset();
@@ -113,7 +112,15 @@ describe("CLI attempt execution", () => {
});
async function writeStore(store: Record<string, SessionEntry>) {
await saveSessionStore(storePath, store);
for (const [sessionKey, entry] of Object.entries(store)) {
upsertSessionEntry({ agentId: "main", sessionKey, entry });
}
}
function readStore(): Record<string, SessionEntry> {
return Object.fromEntries(
listSessionEntries({ agentId: "main" }).map(({ sessionKey, entry }) => [sessionKey, entry]),
);
}
async function runClaudeCliAttempt(params: {
@@ -149,7 +156,6 @@ describe("CLI attempt execution", () => {
onAgentEvent: vi.fn(),
authProfileProvider: "claude-cli",
sessionStore: params.sessionStore,
storePath,
sessionHasHistory: false,
});
}
@@ -214,7 +220,6 @@ describe("CLI attempt execution", () => {
onAgentEvent: vi.fn(),
authProfileProvider: "claude-cli",
sessionStore,
storePath,
sessionHasHistory: false,
});
@@ -224,7 +229,7 @@ describe("CLI attempt execution", () => {
expect(sessionStore[sessionKey]?.cliSessionIds?.["claude-cli"]).toBeUndefined();
expect(sessionStore[sessionKey]?.claudeCliSessionId).toBeUndefined();
const persisted = loadSessionStore(storePath);
const persisted = readStore();
expect(persisted[sessionKey]?.cliSessionIds?.["claude-cli"]).toBeUndefined();
expect(persisted[sessionKey]?.claudeCliSessionId).toBeUndefined();
});
@@ -264,7 +269,7 @@ describe("CLI attempt execution", () => {
expect(sessionStore[sessionKey]?.cliSessionIds?.["claude-cli"]).toBeUndefined();
expect(sessionStore[sessionKey]?.claudeCliSessionId).toBeUndefined();
const persisted = loadSessionStore(storePath);
const persisted = readStore();
expect(persisted[sessionKey]?.cliSessionBindings?.["claude-cli"]).toBeUndefined();
expect(persisted[sessionKey]?.cliSessionIds?.["claude-cli"]).toBeUndefined();
expect(persisted[sessionKey]?.claudeCliSessionId).toBeUndefined();
@@ -360,7 +365,6 @@ describe("CLI attempt execution", () => {
onAgentEvent: vi.fn(),
authProfileProvider: "openai-codex",
sessionStore,
storePath,
sessionHasHistory: false,
});
@@ -384,7 +388,6 @@ describe("CLI attempt execution", () => {
sessionKey,
sessionEntry,
sessionStore,
storePath,
sessionAgentId: "main",
sessionCwd: tmpDir,
config: {},
@@ -445,7 +448,6 @@ describe("CLI attempt execution", () => {
sessionKey,
sessionEntry,
sessionStore,
storePath,
sessionAgentId: "main",
sessionCwd: tmpDir,
config: {},
@@ -466,7 +468,6 @@ describe("CLI attempt execution", () => {
sessionKey,
sessionEntry: updatedFirst,
sessionStore,
storePath,
sessionAgentId: "main",
sessionCwd: tmpDir,
config: {},
@@ -501,7 +502,6 @@ describe("CLI attempt execution", () => {
sessionKey,
sessionEntry,
sessionStore,
storePath,
sessionAgentId: "main",
sessionCwd: tmpDir,
config: {},
@@ -534,7 +534,6 @@ describe("CLI attempt execution", () => {
sessionKey,
sessionEntry: updatedFirst,
sessionStore,
storePath,
sessionAgentId: "main",
sessionCwd: tmpDir,
config: {},
@@ -572,7 +571,6 @@ describe("CLI attempt execution", () => {
sessionKey,
sessionEntry,
sessionStore,
storePath,
sessionAgentId: "main",
sessionCwd: tmpDir,
config: {},
@@ -624,7 +622,6 @@ describe("CLI attempt execution", () => {
onAgentEvent: vi.fn(),
authProfileProvider: "claude-cli",
sessionStore,
storePath,
sessionHasHistory: false,
});
@@ -733,7 +730,6 @@ describe("CLI attempt execution", () => {
onAgentEvent: vi.fn(),
authProfileProvider: "anthropic",
sessionStore,
storePath,
sessionHasHistory: false,
});
@@ -790,7 +786,6 @@ describe("CLI attempt execution", () => {
onAgentEvent: vi.fn(),
authProfileProvider: "openai",
sessionStore,
storePath,
sessionHasHistory: false,
});
@@ -857,7 +852,6 @@ describe("CLI attempt execution", () => {
onAgentEvent: vi.fn(),
authProfileProvider: "anthropic",
sessionStore,
storePath,
sessionHasHistory: true,
});
@@ -920,7 +914,6 @@ describe("CLI attempt execution", () => {
onAgentEvent: vi.fn(),
authProfileProvider: "claude-cli",
sessionStore,
storePath,
sessionHasHistory: false,
});

View File

@@ -4,7 +4,8 @@ import { createServer } from "node:http";
import { tmpdir } from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
import { updateSessionStore, type SessionEntry } from "../../config/sessions.js";
import type { SessionEntry } from "../../config/sessions.js";
import { upsertSessionEntry } from "../../config/sessions/store.js";
import {
initializeGlobalHookRunner,
resetGlobalHookRunner,
@@ -639,8 +640,8 @@ describe("native hook relay registry", () => {
it("passes config to trusted policies for native pre-tool session extension reads", async () => {
const stateDir = await fs.mkdtemp(path.join(tmpdir(), "openclaw-native-relay-policy-"));
const storePath = path.join(stateDir, "sessions.json");
const config = { session: { store: storePath } };
const config = { session: {} };
const previousStateDir = process.env.OPENCLAW_STATE_DIR;
const seen: unknown[] = [];
const registry = createEmptyPluginRegistry();
registry.sessionExtensions = [
@@ -675,11 +676,14 @@ describe("native hook relay registry", () => {
];
setActivePluginRegistry(registry);
try {
await updateSessionStore(storePath, (store) => {
store["agent:main:session-1"] = {
process.env.OPENCLAW_STATE_DIR = stateDir;
upsertSessionEntry({
agentId: "main",
sessionKey: "agent:main:session-1",
entry: {
sessionId: "session-1",
updatedAt: Date.now(),
} as SessionEntry;
} satisfies SessionEntry,
});
await expect(
patchPluginSessionExtension({
@@ -722,6 +726,11 @@ describe("native hook relay registry", () => {
});
expect(seen).toEqual([{ block: true }]);
} finally {
if (previousStateDir === undefined) {
delete process.env.OPENCLAW_STATE_DIR;
} else {
process.env.OPENCLAW_STATE_DIR = previousStateDir;
}
await fs.rm(stateDir, { recursive: true, force: true });
}
});

View File

@@ -2,7 +2,8 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { updateSessionStore, type SessionEntry } from "../config/sessions.js";
import type { SessionEntry } from "../config/sessions.js";
import { upsertSessionEntry } from "../config/sessions/store.js";
import { resetDiagnosticSessionStateForTest } from "../logging/diagnostic-session-state.js";
import {
initializeGlobalHookRunner,
@@ -457,8 +458,8 @@ describe("before_tool_call hook integration for client tools", () => {
it("lets trusted policies read session extensions for client tools when config is provided", async () => {
resetGlobalHookRunner();
const stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-client-tool-policy-"));
const storePath = path.join(stateDir, "sessions.json");
const config = { session: { store: storePath } };
const config = { session: {} };
const previousStateDir = process.env.OPENCLAW_STATE_DIR;
const seen: unknown[] = [];
const registry = createEmptyPluginRegistry();
registry.sessionExtensions = [
@@ -489,11 +490,14 @@ describe("before_tool_call hook integration for client tools", () => {
];
setActivePluginRegistry(registry);
try {
await updateSessionStore(storePath, (store) => {
store["agent:main:client"] = {
process.env.OPENCLAW_STATE_DIR = stateDir;
upsertSessionEntry({
agentId: "main",
sessionKey: "agent:main:client",
entry: {
sessionId: "session-client",
updatedAt: Date.now(),
} as SessionEntry;
} satisfies SessionEntry,
});
await expect(
patchPluginSessionExtension({
@@ -533,6 +537,11 @@ describe("before_tool_call hook integration for client tools", () => {
expect(seen).toEqual([{ gate: "client" }]);
} finally {
if (previousStateDir === undefined) {
delete process.env.OPENCLAW_STATE_DIR;
} else {
process.env.OPENCLAW_STATE_DIR = previousStateDir;
}
setActivePluginRegistry(createEmptyPluginRegistry());
await fs.rm(stateDir, { recursive: true, force: true });
}

View File

@@ -15,11 +15,9 @@ vi.mock("../../plugin-sdk/browser-maintenance.js", () => ({
describe("initSessionState - heartbeat should not trigger session reset", () => {
let tempDir: string;
let storePath: string;
beforeEach(async () => {
tempDir = await fs.mkdtemp("/tmp/openclaw-test-");
storePath = path.join(tempDir, "agents", "main", "sessions", "sessions.json");
});
afterEach(async () => {
@@ -74,7 +72,6 @@ describe("initSessionState - heartbeat should not trigger session reset", () =>
updatedAt: number,
overrides: Partial<SessionEntry> = {},
): Promise<void> => {
void storePath;
upsertSessionEntry({
agentId: "main",
sessionKey: "main:user123",