feat(process): coordinate reactive capture effects

This commit is contained in:
morluto
2026-07-23 01:32:58 +00:00
parent 42f3b9c2ec
commit db9a83190b
7 changed files with 1147 additions and 4 deletions
+21 -1
View File
@@ -37,6 +37,7 @@ import {
processCaptureSchema,
validateProcessCapture,
type ProcessCapture,
type ProcessCaptureEventJournalEntry,
type ProcessExecutionPolicy,
} from "../src/domain/processCapture.js";
@@ -493,12 +494,31 @@ describe("process capture domain", () => {
it("accepts old captures without a journal and validates complete journals", () => {
const journal = createProcessCaptureJournal();
const observed: ProcessCaptureEventJournalEntry[] = [];
const unsubscribe = journal.subscribe((entry) => observed.push(entry));
journal.recordEvent("lifecycle", 0);
journal.recordEvent("lifecycle", 1);
const settlementEntry = journal.record("lifecycle", 1);
unsubscribe();
journal.recordEvent("frames", 0);
expect(journal.entries).toEqual([
{ capture_order: 0, collection: "lifecycle", index: 0 },
{ capture_order: 1, collection: "lifecycle", index: 1 },
{ capture_order: 2, collection: "frames", index: 0 },
]);
expect(observed).toEqual(journal.entries.slice(0, 2));
expect(settlementEntry).toEqual(journal.entries[1]);
const nestedJournal = createProcessCaptureJournal();
const notifications: string[] = [];
nestedJournal.subscribe((entry) => {
notifications.push(`a:${String(entry.capture_order)}`);
if (entry.capture_order === 0) nestedJournal.record("frames", 1);
});
nestedJournal.subscribe((entry) =>
notifications.push(`b:${String(entry.capture_order)}`),
);
nestedJournal.record("frames", 0);
expect(notifications).toEqual(["a:0", "b:0", "a:1", "b:1"]);
const capture = emptyCapture();
const { event_journal: _eventJournal, ...oldCapture } = capture;