|
| 1 | +// Teardown must close fixture-owned databases before restoring the parent state env. |
| 2 | +import fs from "node:fs/promises"; |
| 3 | +import path from "node:path"; |
| 4 | +import { openOpenClawAgentDatabase } from "openclaw/plugin-sdk/sqlite-runtime-testing"; |
| 5 | +import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/temp-path"; |
| 6 | +import { describe, expect, it } from "vitest"; |
| 7 | +import { withZalouserIngressTestQueue } from "./ingress.test-support.js"; |
| 8 | + |
| 9 | +describe("withZalouserIngressTestQueue", () => { |
| 10 | + it("does not write through the parent state environment during teardown", async () => { |
| 11 | + const parentDir = await fs.realpath( |
| 12 | + await fs.mkdtemp(path.join(resolvePreferredOpenClawTmpDir(), "openclaw-zalouser-parent-")), |
| 13 | + ); |
| 14 | + const previousStateDir = process.env.OPENCLAW_STATE_DIR; |
| 15 | + process.env.OPENCLAW_STATE_DIR = parentDir; |
| 16 | + try { |
| 17 | + await withZalouserIngressTestQueue(async () => { |
| 18 | + // A processed inbound message opens the per-agent DB under the child state |
| 19 | + // dir; releasing its lease after env restoration would open a shared-state |
| 20 | + // write transaction against this parent dir instead (PR #119809 review). |
| 21 | + openOpenClawAgentDatabase({ agentId: "main" }); |
| 22 | + }); |
| 23 | + // With the correct close-before-restore order the parent state dir stays |
| 24 | + // untouched; the old order created openclaw.sqlite* files here. |
| 25 | + expect(await fs.readdir(parentDir)).toEqual([]); |
| 26 | + } finally { |
| 27 | + if (previousStateDir === undefined) { |
| 28 | + delete process.env.OPENCLAW_STATE_DIR; |
| 29 | + } else { |
| 30 | + process.env.OPENCLAW_STATE_DIR = previousStateDir; |
| 31 | + } |
| 32 | + await fs.rm(parentDir, { recursive: true, force: true }); |
| 33 | + } |
| 34 | + }); |
| 35 | +}); |
0 commit comments