* feat(browser): capture correlated network content and lifecycle evidence Keep request identities and redirect relationships across ordered scenario events. Capture selected browser-exposed bytes and duplicate headers through modular readers, settle bounded reads before cleanup, and preserve unavailable states. Keep content-selection mismatches and legacy network coverage unknown during comparison. Verify real CLI/MCP, installed package, and browser lifecycle paths. Refs #774 Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * fix(browser): align capture defaults and redact encoded media metadata Correct the complete documented request and legacy default expectation caught by CI. Cover and redact encoded declared values in captured body media types. Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing) * test(browser): verify polling capture cutoff completeness Accept incomplete event coverage only when the continuously polling fixture has explicit unfinished requests; retain failures for other missing or truncated sections. Include actual completeness and unfinished transactions in diagnostics. Assisted-by: Yukari (gensokyo-skills:yukari-boundary-analysis) Assisted-by: Kogasa (gensokyo-skills:kogasa-surprise-testing)
111 lines
3.7 KiB
TypeScript
111 lines
3.7 KiB
TypeScript
import { z } from "zod";
|
|
import { browserNetworkContentSelectionValuesSchema } from "./browserNetworkEvidence.js";
|
|
|
|
import {
|
|
browserScenarioCompletenessSchema,
|
|
browserScenarioEventSchema,
|
|
browserScenarioStepSchema,
|
|
} from "./browserScenarioCaptureValues.js";
|
|
|
|
export {
|
|
classifyBrowserScenarioCompleteness,
|
|
browserScenarioEventSchema,
|
|
browserScenarioStepSchema,
|
|
browserStepArtifactsSchema,
|
|
type BrowserScenarioCompleteness,
|
|
type BrowserScenarioCompletenessSection,
|
|
type BrowserScenarioEvent,
|
|
type BrowserScenarioStep,
|
|
type BrowserScenarioStepOutcome,
|
|
type BrowserStepArtifacts,
|
|
} from "./browserScenarioCaptureValues.js";
|
|
|
|
/** Step-indexed browser scenario observation. */
|
|
export const browserScenarioCaptureSchema = z
|
|
.strictObject({
|
|
browser: z.strictObject({
|
|
mode: z.enum(["launch", "connect"]),
|
|
process_ownership: z.enum(["provider-owned", "external"]),
|
|
cleanup: z.enum(["terminated-owned-process", "disconnected-external"]),
|
|
product: z.string().min(1),
|
|
version: z.string().min(1),
|
|
}),
|
|
scenario: z.strictObject({
|
|
start_origin: z.string().min(1),
|
|
action_count: z.number().int().min(1),
|
|
secret_references: z.array(z.string().min(1)),
|
|
network_content: browserNetworkContentSelectionValuesSchema.optional(),
|
|
}),
|
|
duration_ms: z.number().int().min(0),
|
|
steps: z.array(browserScenarioStepSchema).min(1),
|
|
events: z.strictObject({
|
|
retained: z.number().int().min(0),
|
|
dropped: z.number().int().min(0),
|
|
items: z.array(browserScenarioEventSchema),
|
|
}),
|
|
completeness: browserScenarioCompletenessSchema,
|
|
limitations: z.array(z.string().min(1)),
|
|
})
|
|
.superRefine((capture, context) => {
|
|
const bySequence = new Map(
|
|
capture.events.items.map((event) => [event.sequence, event]),
|
|
);
|
|
if (bySequence.size !== capture.events.items.length)
|
|
context.addIssue({
|
|
code: "custom",
|
|
path: ["events", "items"],
|
|
message: "Event sequence numbers must be unique",
|
|
});
|
|
for (const [index, event] of capture.events.items.entries()) {
|
|
if (event.kind !== "network-content") continue;
|
|
const source = bySequence.get(event.source_event_sequence);
|
|
if (
|
|
source?.kind !== event.phase ||
|
|
source.transaction_id !== event.transaction_id ||
|
|
source.sequence >= event.sequence
|
|
)
|
|
context.addIssue({
|
|
code: "custom",
|
|
path: ["events", "items", index, "source_event_sequence"],
|
|
message:
|
|
"Network content must reference an earlier matching transaction phase",
|
|
});
|
|
}
|
|
if (capture.events.retained !== capture.events.items.length)
|
|
context.addIssue({
|
|
code: "custom",
|
|
path: ["events", "retained"],
|
|
message: "Retained event count must equal items length",
|
|
});
|
|
if (capture.steps.length !== capture.scenario.action_count + 1)
|
|
context.addIssue({
|
|
code: "custom",
|
|
path: ["steps"],
|
|
message: "Capture must include initial state and one entry per action",
|
|
});
|
|
const expectedIndices = capture.steps.map((_, index) => index);
|
|
if (
|
|
capture.steps.some(
|
|
({ step_index: index }, offset) => index !== expectedIndices[offset],
|
|
)
|
|
)
|
|
context.addIssue({
|
|
code: "custom",
|
|
path: ["steps"],
|
|
message: "Step indices must be contiguous from zero",
|
|
});
|
|
if (
|
|
capture.events.items.some(
|
|
({ step_index: index }) => index >= capture.steps.length,
|
|
)
|
|
)
|
|
context.addIssue({
|
|
code: "custom",
|
|
path: ["events", "items"],
|
|
message: "Event references an unknown step index",
|
|
});
|
|
});
|
|
export type BrowserScenarioCapture = z.infer<
|
|
typeof browserScenarioCaptureSchema
|
|
>;
|