feat: emit app state snapshots on all mutating workflows

This commit is contained in:
Codex
2026-02-18 12:59:15 +00:00
parent 0c2124e4cf
commit c714c2eaec
2 changed files with 56 additions and 2 deletions

View File

@@ -5,7 +5,7 @@ const assert = require("node:assert/strict");
const { buildApp } = require("../src/app");
const { hmacSHA256Hex } = require("../src/lib/signature");
function createApp() {
function createApp(options = {}) {
return buildApp({
config: {
xWebhookSecret: "x-secret",
@@ -18,6 +18,7 @@ function createApp() {
maxCharsPerArticle: 120000,
},
},
...options,
});
}
@@ -194,3 +195,32 @@ test("X webhook valid flow processes article", () => {
assert.equal(body.status, "completed");
assert.equal(body.creditsCharged, 1);
});
test("emits persistence snapshots on mutating actions", () => {
const snapshots = [];
const app = createApp({
onMutation(state) {
snapshots.push(state);
},
});
call(app, {
method: "POST",
path: "/app/actions/topup",
headers: { cookie: "xartaudio_user=alice" },
body: "amount=5",
});
call(app, {
method: "POST",
path: "/app/actions/simulate-mention",
headers: { cookie: "xartaudio_user=alice" },
body: "title=Persisted&body=hello",
});
assert.equal(snapshots.length >= 2, true);
const latest = snapshots[snapshots.length - 1];
assert.equal(latest.version, 1);
assert.equal(typeof latest.updatedAt, "string");
assert.equal(typeof latest.engine, "object");
});