

























@@ -13,6 +13,10 @@ import {
1313} from "./session-store.js";
1414import { resolveSession } from "./session.js";
151516+const sessionStoreMocks = vi.hoisted(() => ({
17+updateSessionStore: vi.fn(),
18+}));
19+1620vi.mock("../model-selection.js", () => ({
1721isCliProvider: (provider: string, cfg?: OpenClawConfig) =>
1822Object.hasOwn(cfg?.agents?.defaults?.cliBackends ?? {}, provider),
@@ -80,19 +84,8 @@ vi.mock("../../config/sessions.js", async () => {
8084await fs.mkdir(path.dirname(storePath), { recursive: true });
8185await fs.writeFile(storePath, JSON.stringify(store, null, 2), "utf8");
8286};
83-return {
84-mergeSessionEntry: (existing: SessionEntry | undefined, patch: Partial<SessionEntry>) => ({
85- ...existing,
86- ...patch,
87-sessionId: patch.sessionId ?? existing?.sessionId ?? "mock-session",
88-updatedAt: Math.max(existing?.updatedAt ?? 0, patch.updatedAt ?? 0, Date.now()),
89-}),
90-setSessionRuntimeModel: (entry: SessionEntry, runtime: { provider: string; model: string }) => {
91-entry.modelProvider = runtime.provider;
92-entry.model = runtime.model;
93-return true;
94-},
95-updateSessionStore: async <T>(
87+sessionStoreMocks.updateSessionStore.mockImplementation(
88+async <T>(
9689storePath: string,
9790mutator: (store: Record<string, SessionEntry>) => Promise<T> | T,
9891) => {
@@ -115,6 +108,20 @@ vi.mock("../../config/sessions.js", async () => {
115108await writeStore(storePath, store);
116109return result;
117110},
111+);
112+return {
113+mergeSessionEntry: (existing: SessionEntry | undefined, patch: Partial<SessionEntry>) => ({
114+ ...existing,
115+ ...patch,
116+sessionId: patch.sessionId ?? existing?.sessionId ?? "mock-session",
117+updatedAt: Math.max(existing?.updatedAt ?? 0, patch.updatedAt ?? 0, Date.now()),
118+}),
119+setSessionRuntimeModel: (entry: SessionEntry, runtime: { provider: string; model: string }) => {
120+entry.modelProvider = runtime.provider;
121+entry.model = runtime.model;
122+return true;
123+},
124+updateSessionStore: sessionStoreMocks.updateSessionStore,
118125loadSessionStore: (storePath: string) => {
119126try {
120127return JSON.parse(fsSync.readFileSync(storePath, "utf8")) as Record<string, SessionEntry>;
@@ -157,6 +164,59 @@ async function withTempSessionStore<T>(
157164}
158165159166describe("updateSessionStoreAfterAgentRun", () => {
167+it("passes resolved maintenance config to the gateway turn store write", async () => {
168+sessionStoreMocks.updateSessionStore.mockClear();
169+await withTempSessionStore(async ({ storePath }) => {
170+const cfg = {
171+session: {
172+maintenance: {
173+mode: "enforce",
174+maxEntries: 42,
175+},
176+},
177+} as OpenClawConfig;
178+const sessionKey = "agent:main:explicit:test-maintenance-config";
179+const sessionId = "test-maintenance-config-session";
180+const sessionStore: Record<string, SessionEntry> = {
181+[sessionKey]: {
182+ sessionId,
183+updatedAt: 1,
184+},
185+};
186+await fs.writeFile(storePath, JSON.stringify(sessionStore, null, 2));
187+const result: EmbeddedAgentRunResult = {
188+meta: {
189+durationMs: 1,
190+agentMeta: {
191+ sessionId,
192+provider: "openai",
193+model: "gpt-5.5",
194+},
195+},
196+};
197+198+await updateSessionStoreAfterAgentRun({
199+ cfg,
200+ sessionId,
201+ sessionKey,
202+ storePath,
203+ sessionStore,
204+defaultProvider: "openai",
205+defaultModel: "gpt-5.5",
206+ result,
207+});
208+209+const updateOptions = sessionStoreMocks.updateSessionStore.mock.calls.at(-1)?.[2];
210+expect(updateOptions).toMatchObject({
211+takeCacheOwnership: true,
212+maintenanceConfig: {
213+mode: "enforce",
214+maxEntries: 42,
215+},
216+});
217+});
218+});
219+160220it("persists the selected embedded harness id on the session", async () => {
161221await withTempSessionStore(async ({ storePath }) => {
162222const cfg = {} as OpenClawConfig;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。