Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/browser/PlaywrightBrowserScenarioProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ import type {
ProviderIdentity,
} from "../application/AnalysisProvider.js";
import type { BrowserScenario } from "../domain/browserScenario.js";
import type { BrowserScenarioAction } from "../domain/browserScenarioValues.js";
import {
BROWSER_SCENARIO_START_STEP_ID,
type BrowserScenarioAction,
} from "../domain/browserScenarioValues.js";
import {
browserScenarioCaptureSchema,
type BrowserScenarioCapture,
Expand Down Expand Up @@ -143,7 +146,7 @@ const initialStep = async (input: {
);
return createStep({
stepIndex: 0,
stepId: "scenario_start",
stepId: BROWSER_SCENARIO_START_STEP_ID,
action: "goto_start",
status: "completed",
elapsedMs,
Expand Down
22 changes: 22 additions & 0 deletions src/domain/browserScenario.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,28 @@ it("accepts caller-selected viewport sizes and click counts without ceilings", (
expect(parsed.actions[0]).toMatchObject({ click_count: 4 });
});

it("refuses an action step id that the provider reserves for the initial state", () => {
const scenario = (secondStepId: string) => ({
browser: { mode: "launch", executable_path: "/opt/chromium" },
start_url: { url: "https://app.example.test/" },
actions: [
{ step_id: "open", action: "wait_for_timeout", duration_ms: 10 },
{ step_id: secondStepId, action: "wait_for_timeout", duration_ms: 10 },
],
});

expect(() => browserScenarioSchema.parse(scenario("scenario_start"))).toThrow(
/reserved/u,
);
const rejected = browserScenarioSchema.safeParse(scenario("scenario_start"));
expect(rejected.success).toBe(false);
expect(rejected.error?.issues[0]?.path).toEqual(["actions", 1, "step_id"]);
// Only the exact identity is reserved; a similar caller id stays valid.
expect(
browserScenarioSchema.parse(scenario("scenario_start_2")).actions,
).toHaveLength(2);
});

it.each([
{
field: "duration_ms",
Expand Down
10 changes: 10 additions & 0 deletions src/domain/browserScenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { z } from "zod";

import {
browserScenarioActionSchema,
BROWSER_SCENARIO_START_STEP_ID,
browserScenarioBrowserSchema,
browserScenarioCaptureSchema,
browserScenarioEnvironmentSchema,
Expand Down Expand Up @@ -111,6 +112,15 @@ const validateBrowserScenario = (
"Action step IDs",
context,
);
const reservedIndex = scenario.actions.findIndex(
({ step_id: id }) => id === BROWSER_SCENARIO_START_STEP_ID,
);
if (reservedIndex !== -1)
addIssue(
context,
["actions", reservedIndex, "step_id"],
"Action step IDs must not reuse the reserved initial step identity",
);
assertUnique(
scenario.secrets.map(({ secret_id: id }) => id),
["secrets"],
Expand Down
6 changes: 6 additions & 0 deletions src/domain/browserScenarioValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ import {

export const scenarioIdentifierSchema = z.string().regex(IDENTIFIER_PATTERN);

/**
* Step identity the provider owns for the initial-state step. Callers cannot
* claim it, because two capture steps with one identity cannot be aligned.
*/
export const BROWSER_SCENARIO_START_STEP_ID = "scenario_start";

const browserScenarioBaseUrlSchema = z
.string()
.min(1)
Expand Down
Loading