refactor(browser): remove arbitrary capture ceilings
This commit is contained in:
@@ -165,3 +165,36 @@ it("accepts complete browser inputs beyond former string length caps", () => {
|
||||
: undefined,
|
||||
).toBe(longToken);
|
||||
});
|
||||
|
||||
it("accepts caller-selected viewport sizes and click counts without ceilings", () => {
|
||||
const input = {
|
||||
browser: {
|
||||
mode: "launch",
|
||||
executable_path: "/opt/chromium",
|
||||
headless: true,
|
||||
user_data: "temporary-owned",
|
||||
cleanup: "close-and-delete-profile",
|
||||
},
|
||||
start_url: { url: "https://app.example.test/" },
|
||||
allowed_origins: ["https://app.example.test"],
|
||||
environment: {
|
||||
viewport: { width: 20_000, height: 10_000, device_scale_factor: 8 },
|
||||
},
|
||||
actions: [
|
||||
{
|
||||
step_id: "many-clicks",
|
||||
action: "click",
|
||||
locator: { kind: "css", selector: "#item" },
|
||||
click_count: 4,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const parsed = browserScenarioSchema.parse(input);
|
||||
expect(parsed.environment.viewport).toEqual({
|
||||
width: 20_000,
|
||||
height: 10_000,
|
||||
device_scale_factor: 8,
|
||||
});
|
||||
expect(parsed.actions[0]).toMatchObject({ click_count: 4 });
|
||||
});
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
browserScenarioEventSchema,
|
||||
browserStepArtifactsSchema,
|
||||
} from "./browserScenarioCaptureValues.js";
|
||||
import { browserScenarioCaptureSchema } from "./browserScenarioCapture.js";
|
||||
|
||||
const networkEvent = {
|
||||
sequence: 1,
|
||||
@@ -140,6 +141,69 @@ it("accepts complete storage, history, and text artifacts beyond former caps", (
|
||||
expect(parsed.success).toBe(true);
|
||||
});
|
||||
|
||||
it("accepts complete scenario output beyond former string and origin caps", () => {
|
||||
const longText = "detail".repeat(1_000);
|
||||
const origins = Array.from(
|
||||
{ length: 33 },
|
||||
(_, index) => `https://site-${index}.example.test`,
|
||||
);
|
||||
const step = (index: number) => ({
|
||||
step_index: index,
|
||||
step_id: longText,
|
||||
action: longText,
|
||||
elapsed_ms: 0,
|
||||
before_url: sanitizeBrowserUrl("https://example.test/"),
|
||||
after_url: sanitizeBrowserUrl("https://example.test/"),
|
||||
event_sequence_start: 1,
|
||||
event_sequence_end: 0,
|
||||
artifacts: {
|
||||
screenshot: { state: "not_requested" },
|
||||
dom: { state: "not_requested" },
|
||||
accessibility: { state: "not_requested" },
|
||||
url: { state: "not_requested" },
|
||||
history: { state: "not_requested" },
|
||||
storage: { state: "not_requested" },
|
||||
},
|
||||
completeness: {
|
||||
status: "complete",
|
||||
equality_eligible: true,
|
||||
missing_sections: [],
|
||||
truncated_sections: [],
|
||||
},
|
||||
status: "completed",
|
||||
error: null,
|
||||
});
|
||||
const parsed = browserScenarioCaptureSchema.parse({
|
||||
browser: {
|
||||
mode: "launch",
|
||||
process_ownership: "provider-owned",
|
||||
cleanup: "terminated-owned-process",
|
||||
product: longText,
|
||||
version: longText,
|
||||
},
|
||||
scenario: {
|
||||
start_origin: longText,
|
||||
allowed_origins: origins,
|
||||
action_count: 1,
|
||||
secret_references: [longText],
|
||||
},
|
||||
duration_ms: 0,
|
||||
steps: [step(0), step(1)],
|
||||
events: { retained: 0, dropped: 0, items: [] },
|
||||
completeness: {
|
||||
status: "complete",
|
||||
equality_eligible: true,
|
||||
missing_sections: [],
|
||||
truncated_sections: [],
|
||||
},
|
||||
limitations: Array.from({ length: 65 }, () => longText),
|
||||
});
|
||||
|
||||
expect(parsed.scenario.allowed_origins).toHaveLength(33);
|
||||
expect(parsed.steps[0]?.step_id).toBe(longText);
|
||||
expect(parsed.limitations).toHaveLength(65);
|
||||
});
|
||||
|
||||
it("derives equality eligibility from exact completeness state", () => {
|
||||
expect(
|
||||
browserScenarioCompletenessSchema.safeParse({
|
||||
|
||||
@@ -21,21 +21,21 @@ export {
|
||||
type BrowserStepArtifacts,
|
||||
} from "./browserScenarioCaptureValues.js";
|
||||
|
||||
/** Step-indexed, explicitly bounded browser scenario observation. */
|
||||
/** 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).max(1_024),
|
||||
version: z.string().min(1).max(256),
|
||||
product: z.string().min(1),
|
||||
version: z.string().min(1),
|
||||
}),
|
||||
scenario: z.strictObject({
|
||||
start_origin: z.string().min(1).max(2_048),
|
||||
allowed_origins: z.array(z.string().min(1).max(2_048)).min(1).max(32),
|
||||
start_origin: z.string().min(1),
|
||||
allowed_origins: z.array(z.string().min(1)).min(1),
|
||||
action_count: z.number().int().min(1),
|
||||
secret_references: z.array(z.string().min(1).max(64)),
|
||||
secret_references: z.array(z.string().min(1)),
|
||||
}),
|
||||
duration_ms: z.number().int().min(0),
|
||||
steps: z.array(browserScenarioStepSchema).min(1),
|
||||
@@ -45,7 +45,7 @@ export const browserScenarioCaptureSchema = z
|
||||
items: z.array(browserScenarioEventSchema),
|
||||
}),
|
||||
completeness: browserScenarioCompletenessSchema,
|
||||
limitations: z.array(z.string().min(1).max(2_048)).max(64),
|
||||
limitations: z.array(z.string().min(1)),
|
||||
})
|
||||
.superRefine((capture, context) => {
|
||||
if (capture.events.retained !== capture.events.items.length)
|
||||
|
||||
@@ -30,13 +30,13 @@ export const captureStateSchema = <Schema extends z.ZodType>(value: Schema) =>
|
||||
}),
|
||||
z.strictObject({
|
||||
state: z.literal("missing"),
|
||||
reason: z.string().min(1).max(1_024),
|
||||
reason: z.string().min(1),
|
||||
}),
|
||||
z.strictObject({
|
||||
state: z.literal("truncated"),
|
||||
observed: z.number().int().min(0),
|
||||
retained: z.number().int().min(0),
|
||||
reason: z.string().min(1).max(1_024),
|
||||
reason: z.string().min(1),
|
||||
}),
|
||||
]);
|
||||
|
||||
@@ -281,8 +281,8 @@ export const classifyBrowserScenarioCompleteness = (
|
||||
|
||||
const browserScenarioStepShape = {
|
||||
step_index: z.number().int().min(0),
|
||||
step_id: z.string().min(1).max(64),
|
||||
action: z.string().min(1).max(64),
|
||||
step_id: z.string().min(1),
|
||||
action: z.string().min(1),
|
||||
elapsed_ms: z.number().int().min(0),
|
||||
before_url: sanitizedBrowserUrlSchema,
|
||||
after_url: sanitizedBrowserUrlSchema,
|
||||
|
||||
@@ -95,9 +95,9 @@ export const browserScenarioEnvironmentSchema = z
|
||||
.strictObject({
|
||||
viewport: z
|
||||
.strictObject({
|
||||
width: z.number().int().min(320).max(7_680).default(1_280),
|
||||
height: z.number().int().min(240).max(4_320).default(720),
|
||||
device_scale_factor: z.number().min(0.5).max(4).default(1),
|
||||
width: z.number().int().positive().default(1_280),
|
||||
height: z.number().int().positive().default(720),
|
||||
device_scale_factor: z.number().positive().default(1),
|
||||
})
|
||||
.default({ width: 1_280, height: 720, device_scale_factor: 1 }),
|
||||
locale: z
|
||||
@@ -182,7 +182,7 @@ export const browserScenarioActionSchema = z.discriminatedUnion("action", [
|
||||
action: z.literal("click"),
|
||||
locator: locatorSchema,
|
||||
button: z.enum(["left", "middle", "right"]).default("left"),
|
||||
click_count: z.number().int().min(1).max(3).default(1),
|
||||
click_count: z.number().int().positive().default(1),
|
||||
}),
|
||||
z.strictObject({
|
||||
...stepBase,
|
||||
@@ -382,8 +382,8 @@ const snapshotKindSchema = z.enum([
|
||||
|
||||
export const browserScenarioCaptureSchema = z
|
||||
.strictObject({
|
||||
after_each_step: z.array(snapshotKindSchema).max(6).default([]),
|
||||
at_end: z.array(snapshotKindSchema).max(6).default(["url"]),
|
||||
after_each_step: z.array(snapshotKindSchema).default([]),
|
||||
at_end: z.array(snapshotKindSchema).default(["url"]),
|
||||
events: z
|
||||
.array(
|
||||
z.enum([
|
||||
|
||||
@@ -51,6 +51,6 @@ export const createElectronActiveObservationFixtureResult = (
|
||||
observed: 1,
|
||||
},
|
||||
limitations: [
|
||||
"IPC payloads are represented only by bounded value shapes; values are never retained.",
|
||||
"IPC payloads are represented by value shapes; payload values are never retained.",
|
||||
],
|
||||
});
|
||||
|
||||
@@ -35,4 +35,15 @@ describe("inline web screenshots", () => {
|
||||
}).success,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("accepts a caller-supplied target ID without a length ceiling", () => {
|
||||
const targetId = "target-".repeat(100);
|
||||
expect(
|
||||
captureWebScreenshotInputSchema.parse({
|
||||
cdp_endpoint: "http://127.0.0.1:9222",
|
||||
allowed_origins: ["https://app.example.test"],
|
||||
target_id: targetId,
|
||||
}).target_id,
|
||||
).toBe(targetId);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -35,7 +35,7 @@ export type WebScreenshotArtifact = z.infer<typeof webScreenshotArtifactSchema>;
|
||||
export const captureWebScreenshotInputSchema = z.strictObject({
|
||||
cdp_endpoint: browserEndpointSchema,
|
||||
allowed_origins: browserAllowedOriginsSchema,
|
||||
target_id: z.string().trim().min(1).max(256),
|
||||
target_id: z.string().trim().min(1),
|
||||
});
|
||||
export type CaptureWebScreenshotInput = z.infer<
|
||||
typeof captureWebScreenshotInputSchema
|
||||
|
||||
Reference in New Issue
Block a user