harden state durability and disable destructive snapshot sync

This commit is contained in:
Codex
2026-02-18 15:24:49 +00:00
parent 331b66506a
commit 4814342156
6 changed files with 123 additions and 35 deletions

View File

@@ -11,6 +11,7 @@ const {
function createRuntimeConfig() {
return {
nodeEnv: "test",
port: 3000,
logLevel: "info",
appBaseUrl: "http://localhost:3000",
@@ -60,6 +61,7 @@ function createRuntimeConfig() {
stepCredits: 1,
maxCharsPerArticle: 120000,
},
allowInMemoryStateFallback: true,
};
}
@@ -153,3 +155,39 @@ test("createRuntime falls back to in-memory state when initial load fails", asyn
assert.equal(response.status, 303);
await runtime.persister.flush();
});
test("createRuntime fails startup when fallback is disabled", async () => {
const runtimeConfig = createRuntimeConfig();
runtimeConfig.allowInMemoryStateFallback = false;
await assert.rejects(
createRuntime({
runtimeConfig,
logger: { info() {}, warn() {}, error() {} },
stateStore: {
async load() {
throw new Error("state_load_failed");
},
async save() {},
},
}),
/state_store_unavailable_without_fallback/,
);
});
test("createMutationPersister surfaces save errors", async () => {
const persister = createMutationPersister({
stateStore: {
async save() {
throw new Error("persist_failed");
},
},
logger: { error() {} },
});
await assert.rejects(
persister.enqueue({}),
/persist_failed/,
);
assert.equal(persister.getLastError()?.message, "persist_failed");
});