feat: add engine and store snapshot/restore for restart resilience
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user