Skip to content

Commit caf9cac

Browse files
committed
test(plugin-state): cover newer read-only schemas
1 parent 25949c5 commit caf9cac

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

‎src/plugin-state/plugin-state-store.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Plugin state store tests cover per-plugin persisted state reads and writes.
22
import { chmodSync, existsSync, rmSync, statSync } from "node:fs";
33
import path from "node:path";
4+
import { DatabaseSync } from "node:sqlite";
45
import { MAX_DATE_TIMESTAMP_MS } from "@openclaw/normalization-core/number-coercion";
56
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
67
import {
@@ -9,6 +10,7 @@ import {
910
} from "../state/openclaw-quarantine-store.js";
1011
import {
1112
clearOpenClawStateDatabaseOpenFailure,
13+
OPENCLAW_STATE_SCHEMA_VERSION,
1214
openOpenClawStateDatabase,
1315
recordOpenClawStateDatabaseOpenFailure,
1416
} from "../state/openclaw-state-db.js";
@@ -938,6 +940,35 @@ describe("plugin state keyed store", () => {
938940
});
939941
});
940942

943+
it("fails closed for a newer shared-state schema", async () => {
944+
await withPluginStateTestState(async () => {
945+
const store = createPluginStateKeyedStore("discord", {
946+
namespace: "newer-schema",
947+
maxEntries: 10,
948+
});
949+
await store.register("k", { ok: true });
950+
const databasePath = resolveOpenClawStateSqlitePath(testState?.env);
951+
openOpenClawStateDatabase().db.exec(
952+
`PRAGMA user_version = ${OPENCLAW_STATE_SCHEMA_VERSION + 1};`,
953+
);
954+
closePluginStateDatabase();
955+
956+
try {
957+
await expect(store.lookup("k")).rejects.toMatchObject({
958+
code: "PLUGIN_STATE_OPEN_FAILED",
959+
path: databasePath,
960+
});
961+
} finally {
962+
const database = new DatabaseSync(databasePath);
963+
try {
964+
database.exec(`PRAGMA user_version = ${OPENCLAW_STATE_SCHEMA_VERSION};`);
965+
} finally {
966+
database.close();
967+
}
968+
}
969+
});
970+
});
971+
941972
it.runIf(process.platform !== "win32")(
942973
"reports inaccessible explicit state directories instead of treating them as empty",
943974
async () => {

0 commit comments

Comments
 (0)