


























@@ -2,11 +2,18 @@ import { mkdtempSync, rmSync } from "node:fs";
22import os from "node:os";
33import path from "node:path";
44import { afterEach, describe, expect, it } from "vitest";
5-import { DebugProxyCaptureStore, persistEventPayload } from "./store.sqlite.js";
5+import {
6+acquireDebugProxyCaptureStore,
7+closeDebugProxyCaptureStore,
8+DebugProxyCaptureStore,
9+getDebugProxyCaptureStore,
10+persistEventPayload,
11+} from "./store.sqlite.js";
612713const cleanupDirs: string[] = [];
814915afterEach(() => {
16+closeDebugProxyCaptureStore();
1017while (cleanupDirs.length > 0) {
1118const dir = cleanupDirs.pop();
1219if (dir) {
@@ -22,6 +29,35 @@ function makeStore() {
2229}
23302431describe("DebugProxyCaptureStore", () => {
32+it("keeps the cached store open until the last lease releases", () => {
33+const root = mkdtempSync(path.join(os.tmpdir(), "openclaw-proxy-capture-lease-"));
34+cleanupDirs.push(root);
35+const dbPath = path.join(root, "capture.sqlite");
36+const blobDir = path.join(root, "blobs");
37+38+const first = acquireDebugProxyCaptureStore(dbPath, blobDir);
39+const second = acquireDebugProxyCaptureStore(dbPath, blobDir);
40+41+expect(second.store).toBe(first.store);
42+first.release();
43+expect(first.store.isClosed).toBe(false);
44+45+second.release();
46+expect(first.store.isClosed).toBe(true);
47+48+const reopened = getDebugProxyCaptureStore(dbPath, blobDir);
49+expect(Object.is(reopened, first.store)).toBe(false);
50+expect(reopened.isClosed).toBe(false);
51+});
52+53+it("ignores duplicate close calls", () => {
54+const store = makeStore();
55+56+store.close();
57+expect(() => store.close()).not.toThrow();
58+expect(store.isClosed).toBe(true);
59+});
60+2561it("stores sessions, blobs, and duplicate-send query results", () => {
2662const store = makeStore();
2763store.upsertSession({
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。