fix(process): preserve numeric output and original PTY evidence

This commit is contained in:
N0zoM1z0
2026-10-09 17:55:28 +08:00
parent aa5750c263
commit 00d8e44cbf
10 changed files with 168 additions and 7 deletions
@@ -5,6 +5,28 @@ import {
emptyProcessCapture as emptyCapture,
} from "./processCapture.fixture.js";
it("compares normalized terminal facts while retaining different source text for audit", () => {
const capture = emptyCapture();
const frame = { sequence: 0, at_ms: 0, data: "listen:<port> score=20" };
const left = {
...capture,
frames: [{ ...frame, raw_data: "listen:8080 score=20" }],
};
const right = {
...capture,
frames: [{ ...frame, raw_data: "listen:9090 score=20" }],
};
expect(compareProcessCaptures(left, right)).toMatchObject({
terminal: "unchanged",
});
expect(
compareProcessCaptures(left, {
...right,
frames: [{ ...frame, data: "listen:<port> score=21" }],
}),
).toMatchObject({ terminal: "changed" });
});
it("distinguishes added evidence from unknown observations", () => {
const capture = emptyCapture();
const added = compareProcessCaptures(capture, {
+3
View File
@@ -11,6 +11,8 @@ export interface TerminalFrame {
readonly sequence: number;
readonly at_ms: number;
readonly data: string;
/** Original PTY text when normalization changed it; older captures may omit it. */
readonly raw_data?: string | undefined;
}
/** Serialized terminal state after interpreting control and resize sequences. */
@@ -402,6 +404,7 @@ const processCaptureShapeSchema = z.strictObject({
sequence: z.number().int().nonnegative(),
at_ms: z.number().int().nonnegative(),
data: z.string(),
raw_data: z.string().optional(),
}),
),
rendered_frames: z.array(
+5 -1
View File
@@ -2,6 +2,7 @@ import canonicalize from "canonicalize";
import { z } from "zod";
import type { ProcessCapture } from "./processCapture.js";
import { comparableTerminalFrame } from "./processObservation.js";
import { AnalysisInputError } from "../analysisErrorCore.js";
import { jsonValueSchema } from "../jsonValue.js";
import {
@@ -100,7 +101,10 @@ export type ProcessCaptureComparison = z.infer<
const terminalObservations = (capture: ProcessCapture): readonly unknown[] =>
[
...capture.frames.map((frame) => ({ kind: "raw" as const, ...frame })),
...capture.frames.map((frame) => ({
kind: "raw" as const,
...comparableTerminalFrame(frame),
})),
...capture.rendered_frames.map((frame) => ({
kind: "rendered" as const,
...frame,
+16 -3
View File
@@ -1,7 +1,17 @@
import { z } from "zod";
import { jsonValueSchema, type JsonValue } from "../jsonValue.js";
import type { UnverifiedProcessCapture } from "./processCapture.js";
import type {
TerminalFrame,
UnverifiedProcessCapture,
} from "./processCapture.js";
/** Project normalized PTY facts without source text used only for audit. */
export const comparableTerminalFrame = (frame: TerminalFrame) => ({
sequence: frame.sequence,
at_ms: frame.at_ms,
data: frame.data,
});
/** Process-capture observation families shared by live drivers and trace assertions. */
export const processObservationSourceSchema = z.enum([
@@ -126,11 +136,14 @@ const projectedRecord = (
): ProjectedRecord | null => {
const projected = (() => {
switch (location.collection) {
case "frames":
case "frames": {
const frame = capture.frames[location.index];
return {
source: "terminal_raw" as const,
value: capture.frames[location.index],
value:
frame === undefined ? undefined : comparableTerminalFrame(frame),
};
}
case "rendered_frames":
return {
source: "terminal_rendered" as const,
+3
View File
@@ -84,6 +84,9 @@ export const processComparisonContract = (
settle_ms: scenario.settle_ms,
limits: scenario.limits,
normalization: scenario.normalization,
...(scenario.normalization.ports
? { port_normalization_version: "contextual-endpoints-v1" }
: {}),
});
/**