






















@@ -56,9 +56,32 @@ type MemoryTranscriptUpdateSubscriber = (
5656const MEMORY_CORE_TRANSCRIPT_UPDATE_SUBSCRIBER_KEY = Symbol.for(
5757"openclaw.memoryCore.sessionTranscriptUpdateSubscriber",
5858);
59+const originalStartupStateDir = process.env.OPENCLAW_STATE_DIR;
60+const originalStartupConfigPath = process.env.OPENCLAW_CONFIG_PATH;
59616062type SourceStateRow = { path: string; hash: string; mtime: number; size: number };
616364+function setStartupStateDir(stateDir: string): void {
65+Reflect.set(process.env, "OPENCLAW_STATE_DIR", stateDir);
66+}
67+68+function setStartupConfigPath(configPath: string): void {
69+Reflect.set(process.env, "OPENCLAW_CONFIG_PATH", configPath);
70+}
71+72+function restoreStartupEnv(): void {
73+if (originalStartupStateDir === undefined) {
74+Reflect.deleteProperty(process.env, "OPENCLAW_STATE_DIR");
75+} else {
76+Reflect.set(process.env, "OPENCLAW_STATE_DIR", originalStartupStateDir);
77+}
78+if (originalStartupConfigPath === undefined) {
79+Reflect.deleteProperty(process.env, "OPENCLAW_CONFIG_PATH");
80+} else {
81+Reflect.set(process.env, "OPENCLAW_CONFIG_PATH", originalStartupConfigPath);
82+}
83+}
84+6285class SessionStartupCatchupHarness extends MemoryManagerSyncOps {
6386protected readonly cfg = {} as OpenClawConfig;
6487protected readonly agentId = "main";
@@ -230,13 +253,13 @@ describe("session startup catch-up", () => {
230253231254beforeEach(async () => {
232255stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-session-startup-"));
233-vi.stubEnv("OPENCLAW_STATE_DIR", stateDir);
256+setStartupStateDir(stateDir);
234257});
235258236259afterEach(async () => {
237260vi.clearAllTimers();
238261vi.useRealTimers();
239-vi.unstubAllEnvs();
262+restoreStartupEnv();
240263clearRuntimeConfigSnapshot();
241264clearConfigCache();
242265await fs.rm(stateDir, { recursive: true, force: true });
@@ -458,7 +481,7 @@ describe("session startup catch-up", () => {
458481"utf-8",
459482);
460483await fs.writeFile(configPath, JSON.stringify({ session: { store: storePath } }), "utf-8");
461-vi.stubEnv("OPENCLAW_CONFIG_PATH", configPath);
484+setStartupConfigPath(configPath);
462485clearRuntimeConfigSnapshot();
463486clearConfigCache();
464487const harness = new SessionStartupCatchupHarness([]);
@@ -505,7 +528,7 @@ describe("session startup catch-up", () => {
505528"utf-8",
506529);
507530await fs.writeFile(configPath, JSON.stringify({ session: { store: storePath } }), "utf-8");
508-vi.stubEnv("OPENCLAW_CONFIG_PATH", configPath);
531+setStartupConfigPath(configPath);
509532clearRuntimeConfigSnapshot();
510533clearConfigCache();
511534const harness = new SessionStartupCatchupHarness([]);
@@ -553,7 +576,7 @@ describe("session startup catch-up", () => {
553576"utf-8",
554577);
555578await fs.writeFile(configPath, JSON.stringify({ session: { store: storePath } }), "utf-8");
556-vi.stubEnv("OPENCLAW_CONFIG_PATH", configPath);
579+setStartupConfigPath(configPath);
557580clearRuntimeConfigSnapshot();
558581clearConfigCache();
559582const harness = new SessionStartupCatchupHarness([]);
@@ -660,7 +683,7 @@ describe("session startup catch-up", () => {
660683"utf-8",
661684);
662685await fs.writeFile(configPath, JSON.stringify({ session: { store: storePath } }), "utf-8");
663-vi.stubEnv("OPENCLAW_CONFIG_PATH", configPath);
686+setStartupConfigPath(configPath);
664687clearRuntimeConfigSnapshot();
665688clearConfigCache();
666689const harness = new SessionStartupCatchupHarness([]);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。