feat: add engine and store snapshot/restore for restart resilience

This commit is contained in:
Codex
2026-02-18 12:57:25 +00:00
parent 76f673fe4c
commit 9b3cdbff1a
6 changed files with 117 additions and 15 deletions

View File

@@ -154,3 +154,29 @@ test("lists jobs for user newest first and provides summary", () => {
assert.equal(summary.totalCreditsSpent, 2);
assert.equal(summary.balance, 8);
});
test("round-trips state snapshot across engine restart", () => {
const engine1 = createEngine();
engine1.topUpCredits("u1", 5, "topup-snapshot");
const created = engine1.processMention({
mentionPostId: "m-snapshot",
callerUserId: "u1",
parentPost: {
id: "p-snapshot",
authorId: "author-snapshot",
article: { id: "a-snapshot", title: "Snap", body: "hello world" },
},
});
const snapshot = engine1.exportState();
const engine2 = new XArtAudioEngine({
creditConfig: engine1.creditConfig,
initialState: snapshot,
});
assert.equal(engine2.getWalletBalance("u1"), 4);
assert.equal(engine2.getJob(created.job.id).article.title, "Snap");
assert.equal(engine2.getAsset(created.job.assetId).articleTitle, "Snap");
assert.equal(engine2.checkAudioAccess(created.job.assetId, "u1").allowed, true);
});