Skip to content

Commit 3a25fff

Browse files
committed
test: reroute state-db test imports to contract and cache modules
1 parent 8640e42 commit 3a25fff

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎src/agents/tools/transcripts-tool.auto-start.test.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import { createDeferred } from "../../../test/helpers/promise.js";
66
import { createTempDirTracker } from "../../../test/helpers/temp-dir.js";
77
import { createEmptyPluginRegistry } from "../../plugins/registry-empty.js";
88
import { withPluginRuntimeRegistryScope } from "../../plugins/runtime/gateway-request-scope.js";
9+
import { openClawStateDatabaseCache } from "../../state/openclaw-state-db-cache.js";
910
import {
1011
closeOpenClawStateDatabaseByPath,
1112
closeOpenClawStateDatabaseForTest,
12-
getOpenClawStateDatabaseIfOpen,
1313
} from "../../state/openclaw-state-db.js";
14+
import { resolveOpenClawStateSqlitePath } from "../../state/openclaw-state-db.paths.js";
1415
import type {
1516
TranscriptSourceProvider,
1617
TranscriptStartRequest,
@@ -52,6 +53,7 @@ describe("transcripts auto-start stop reporting", () => {
5253
])("$name preserves state and finishes siblings", async ({ blocked, outcome, manual }) => {
5354
const stateDir = await fs.realpath(tempDirs.make("openclaw-transcripts-auto-stop-"));
5455
const options = { env: { ...process.env, OPENCLAW_STATE_DIR: stateDir } };
56+
const databasePath = path.resolve(resolveOpenClawStateSqlitePath(options.env));
5557
const exportRoot = path.join(stateDir, "transcripts");
5658
const store = new TranscriptsStore(exportRoot, options);
5759
const requests = new Map<string, TranscriptStartRequest>();
@@ -150,7 +152,8 @@ describe("transcripts auto-start stop reporting", () => {
150152
expect(stop).toHaveBeenCalledTimes(2);
151153
expect(logger.warn.mock.calls.map(([message]) => message)).toEqual(warnings);
152154

153-
const database = getOpenClawStateDatabaseIfOpen(options)!;
155+
const database =
156+
openClawStateDatabaseCache.getOpenClawStateDatabaseIfOpenAtPath(databasePath)!;
154157
expect(database.db.isOpen).toBe(true);
155158
expect(closeOpenClawStateDatabaseByPath(database.path)).toBe(true);
156159
expect(database.db.isOpen).toBe(false);
@@ -178,7 +181,9 @@ describe("transcripts auto-start stop reporting", () => {
178181
).toContain(capturedText);
179182
}
180183
}
181-
expect(getOpenClawStateDatabaseIfOpen(options)).not.toBe(database);
184+
expect(
185+
openClawStateDatabaseCache.getOpenClawStateDatabaseIfOpenAtPath(databasePath),
186+
).not.toBe(database);
182187
await expect(execute("status")).resolves.toMatchObject({
183188
details: {
184189
active:

‎test/test-env.state-lifetime.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { pathToFileURL } from "node:url";
88
import { Worker } from "node:worker_threads";
99
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
1010
import { listOpenClawRegisteredAgentDatabases } from "../src/state/openclaw-agent-db-registry-listing.js";
11+
import { OPENCLAW_STATE_SCHEMA_VERSION } from "../src/state/openclaw-state-db-contract.js";
1112
import {
1213
closeOpenClawStateDatabaseByPath,
1314
openOpenClawStateDatabase,
14-
OPENCLAW_STATE_SCHEMA_VERSION,
1515
} from "../src/state/openclaw-state-db.js";
1616
import { resolveOpenClawStateSqlitePath } from "../src/state/openclaw-state-db.paths.js";
1717
import { captureFullEnv, setTestEnvValue, withPathResolutionEnv } from "../src/test-utils/env.js";

0 commit comments

Comments
 (0)