11// Plugin state store tests cover per-plugin persisted state reads and writes.
22import { chmodSync , existsSync , rmSync , statSync } from "node:fs" ;
33import path from "node:path" ;
4+ import { DatabaseSync } from "node:sqlite" ;
45import { MAX_DATE_TIMESTAMP_MS } from "@openclaw/normalization-core/number-coercion" ;
56import { afterAll , afterEach , beforeAll , beforeEach , describe , expect , it , vi } from "vitest" ;
67import {
@@ -9,6 +10,7 @@ import {
910} from "../state/openclaw-quarantine-store.js" ;
1011import {
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