feat(process): record global capture event order
This commit is contained in:
@@ -110,6 +110,35 @@ export interface ProtocolEvent {
|
||||
| "limit_exhausted";
|
||||
}
|
||||
|
||||
/** Capture collection whose members participate in global observation order. */
|
||||
export const PROCESS_CAPTURE_EVENT_COLLECTIONS = [
|
||||
"frames",
|
||||
"rendered_frames",
|
||||
"interaction_events",
|
||||
"lifecycle",
|
||||
"process_samples",
|
||||
"filesystem_checkpoints",
|
||||
"shim_events",
|
||||
"protocol_events",
|
||||
"replay_transitions",
|
||||
] as const;
|
||||
|
||||
export type ProcessCaptureEventCollection =
|
||||
(typeof PROCESS_CAPTURE_EVENT_COLLECTIONS)[number];
|
||||
|
||||
/** One reference from global observation order into a capture collection. */
|
||||
export interface ProcessCaptureEventJournalEntry {
|
||||
readonly capture_order: number;
|
||||
readonly collection: ProcessCaptureEventCollection;
|
||||
readonly index: number;
|
||||
}
|
||||
|
||||
/** Shared observation callback used by every process-capture producer. */
|
||||
export type RecordProcessCaptureEvent = (
|
||||
collection: ProcessCaptureEventCollection,
|
||||
index: number,
|
||||
) => void;
|
||||
|
||||
/**
|
||||
* Process Capture v4 observation set.
|
||||
*
|
||||
@@ -156,6 +185,12 @@ export interface ProcessCapture {
|
||||
readonly shim_events: readonly ShimEvent[];
|
||||
readonly protocol_events: readonly ProtocolEvent[];
|
||||
readonly replay_transitions: readonly ReplayTransitionRecord[];
|
||||
/**
|
||||
* Global observation order across independently recorded collections.
|
||||
*
|
||||
* Absence is accepted for captures written before this journal existed.
|
||||
*/
|
||||
readonly event_journal?: readonly ProcessCaptureEventJournalEntry[];
|
||||
readonly files_before: readonly FileState[];
|
||||
readonly files_after: readonly FileState[];
|
||||
readonly filesystem_effects: readonly FileEffect[];
|
||||
@@ -328,6 +363,15 @@ export const processCaptureSchema: z.ZodType<ProcessCapture> = z.object({
|
||||
}),
|
||||
)
|
||||
.default([]),
|
||||
event_journal: z
|
||||
.array(
|
||||
z.object({
|
||||
capture_order: z.number().int().nonnegative(),
|
||||
collection: z.enum(PROCESS_CAPTURE_EVENT_COLLECTIONS),
|
||||
index: z.number().int().nonnegative(),
|
||||
}),
|
||||
)
|
||||
.default([]),
|
||||
files_before: z.array(fileStateSchema),
|
||||
files_after: z.array(fileStateSchema),
|
||||
filesystem_effects: z.array(fileEffectSchema),
|
||||
@@ -383,3 +427,9 @@ export {
|
||||
PROCESS_COMPARISON_DIMENSIONS,
|
||||
processCaptureComparisonSchema,
|
||||
} from "./processComparison.js";
|
||||
export {
|
||||
compareProcessTraces,
|
||||
processTraceComparisonResultSchema,
|
||||
processTraceSourceSchema,
|
||||
processTraceSpecificationSchema,
|
||||
} from "./processTraceComparison.js";
|
||||
|
||||
@@ -72,6 +72,54 @@ const validateOrdering = (
|
||||
require(orderedTimestamps(values), name, "timestamps must be ordered");
|
||||
};
|
||||
|
||||
const journalCollectionSizes = (
|
||||
capture: ProcessCapture,
|
||||
): Readonly<
|
||||
Record<
|
||||
NonNullable<ProcessCapture["event_journal"]>[number]["collection"],
|
||||
number
|
||||
>
|
||||
> => ({
|
||||
frames: capture.frames.length,
|
||||
rendered_frames: capture.rendered_frames.length,
|
||||
interaction_events: capture.interaction_events.length,
|
||||
lifecycle: 2,
|
||||
process_samples: capture.process_samples.length,
|
||||
filesystem_checkpoints: capture.filesystem_checkpoints.length,
|
||||
shim_events: capture.shim_events.length,
|
||||
protocol_events: capture.protocol_events.length,
|
||||
replay_transitions: capture.replay_transitions.length,
|
||||
});
|
||||
|
||||
const validateEventJournal = (
|
||||
capture: ProcessCapture,
|
||||
require: RequireInvariant,
|
||||
): void => {
|
||||
const journal = capture.event_journal ?? [];
|
||||
if (journal.length === 0) return;
|
||||
const sizes = journalCollectionSizes(capture);
|
||||
const references = new Set<string>();
|
||||
for (const [position, entry] of journal.entries()) {
|
||||
require(entry.capture_order ===
|
||||
position, `event_journal.${String(position)}.capture_order`, "capture order must be contiguous from zero");
|
||||
require(entry.index <
|
||||
sizes[
|
||||
entry.collection
|
||||
], `event_journal.${String(position)}.index`, "journal reference is outside its capture collection");
|
||||
const reference = `${entry.collection}:${String(entry.index)}`;
|
||||
require(!references.has(
|
||||
reference,
|
||||
), `event_journal.${String(position)}`, "journal references must be unique");
|
||||
references.add(reference);
|
||||
}
|
||||
const expectedSize = Object.values(sizes).reduce(
|
||||
(total, size) => total + size,
|
||||
0,
|
||||
);
|
||||
require(journal.length ===
|
||||
expectedSize, "event_journal", "nonempty journal must reference every captured observation");
|
||||
};
|
||||
|
||||
const validateLifecycle = (
|
||||
capture: ProcessCapture,
|
||||
require: RequireInvariant,
|
||||
@@ -262,6 +310,7 @@ export const validateProcessCapture = (
|
||||
};
|
||||
validateCommitments(capture, require);
|
||||
validateOrdering(capture, require);
|
||||
validateEventJournal(capture, require);
|
||||
validateLifecycle(capture, require);
|
||||
validateShimEvents(capture, require);
|
||||
validateReplayEvents(capture, require);
|
||||
|
||||
Reference in New Issue
Block a user