@@ -121,6 +121,19 @@ const {
|
121 | 121 | |
122 | 122 | const CHOKIDAR_FACTORY_KEY = Symbol.for("openclaw.test.memoryWatchFactory"); |
123 | 123 | const NATIVE_FACTORY_KEY = Symbol.for("openclaw.test.memoryNativeWatchFactory"); |
| 124 | +const originalWatcherStateDir = process.env.OPENCLAW_STATE_DIR; |
| 125 | + |
| 126 | +function setWatcherStateDir(stateDir: string): void { |
| 127 | +Reflect.set(process.env, "OPENCLAW_STATE_DIR", stateDir); |
| 128 | +} |
| 129 | + |
| 130 | +function restoreWatcherStateDir(): void { |
| 131 | +if (originalWatcherStateDir === undefined) { |
| 132 | +Reflect.deleteProperty(process.env, "OPENCLAW_STATE_DIR"); |
| 133 | +} else { |
| 134 | +Reflect.set(process.env, "OPENCLAW_STATE_DIR", originalWatcherStateDir); |
| 135 | +} |
| 136 | +} |
124 | 137 | |
125 | 138 | vi.mock("openclaw/plugin-sdk/memory-core-host-engine-foundation", async (importOriginal) => { |
126 | 139 | const actual = |
@@ -194,7 +207,7 @@ describe("memory watcher config", () => {
|
194 | 207 | } |
195 | 208 | await closeAllMemorySearchManagers(); |
196 | 209 | clearRegistry(); |
197 | | -vi.unstubAllEnvs(); |
| 210 | +restoreWatcherStateDir(); |
198 | 211 | if (workspaceDir) { |
199 | 212 | await fs.rm(workspaceDir, { recursive: true, force: true }); |
200 | 213 | workspaceDir = ""; |
@@ -204,7 +217,7 @@ describe("memory watcher config", () => {
|
204 | 217 | |
205 | 218 | async function setupWatcherWorkspace(seedFile: { name: string; contents: string }) { |
206 | 219 | workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-memory-watch-")); |
207 | | -vi.stubEnv("OPENCLAW_STATE_DIR", path.join(workspaceDir, "state")); |
| 220 | +setWatcherStateDir(path.join(workspaceDir, "state")); |
208 | 221 | extraDir = path.join(workspaceDir, "extra"); |
209 | 222 | await fs.mkdir(path.join(workspaceDir, "memory"), { recursive: true }); |
210 | 223 | await fs.mkdir(extraDir, { recursive: true }); |
|