Skip to content

feat: add optional viewport field to plan files + --viewport CLI flag for responsive/mobile testing - #306

Open
waterWang wants to merge 1 commit into
TestSprite:mainfrom
waterWang:feat/viewport-override
Open

feat: add optional viewport field to plan files + --viewport CLI flag for responsive/mobile testing#306
waterWang wants to merge 1 commit into
TestSprite:mainfrom
waterWang:feat/viewport-override

Conversation

@waterWang

@waterWang waterWang commented Aug 11, 2026

Copy link
Copy Markdown

Summary

Adds an optional viewport field to the plan file schema (<width>x<height>, e.g. "390x844") and a --viewport <WxH> CLI flag to test create --plan-from. This lets users test responsive/mobile-only UI (e.g. md:hidden bottom nav) by telling the frontend browser runner what viewport to use before executing plan steps.

Closes #174

Changes

src/commands/test.ts

  • CliPlanInput — added optional viewport?: string field
  • assertPlanShape — validates viewport format (^\d+x\d+$)
  • collectPlanIssues — same viewport format check for test lint
  • runCreateFromPlan — passes viewport through to POST /tests body; also supports --viewport CLI flag as an override of the plan file's viewport
  • test create command — added --viewport <WxH> flag
  • CreateFromPlanOptions — added viewport?: string for the override path
  • CreateFlagOpts — added viewport?: string for the flag parsing

schemas/plan.schema.json

  • Added viewport property (string, pattern ^[1-9]\d*x[1-9]\d*$)

DOCUMENTATION.md

  • Added viewport to the plan file field table

src/lib/plan-schema.spec.ts

  • Added test: validates valid viewport ("390x844") and rejects invalid ("abc")
  • Added test: plan with viewport + all optional fields

Testing

  • src/lib/plan-schema.spec.ts — 17 tests pass (2 new): schema + validator both accept valid viewport, reject invalid
  • src/commands/test.test.ts — 324 tests pass
  • src/commands/test.run.spec.ts — 92 tests pass

Usage

Plan file (JSON):

{
  "projectId": "prj_abc123",
  "type": "frontend",
  "name": "Mobile bottom-nav test",
  "viewport": "390x844",
  "planSteps": [
    { "type": "action", "description": "Navigate to dashboard" },
    { "type": "assertion", "description": "Verify the mobile bottom navigation bar is visible" }
  ]
}

CLI flag override:

testsprite test create --plan-from plan.json --viewport 390x844

When --viewport is supplied alongside --plan-from, it overrides the plan file's viewport value — useful for running the same plan at different breakpoints (e.g. mobile smoke pass on a desktop-authored plan).

Summary by CodeRabbit

  • New Features

    • Frontend test plans can now specify a browser viewport using WIDTHxHEIGHT format.
    • Added a --viewport option when creating tests from plans.
    • Command-line viewport values override the value defined in the plan.
  • Bug Fixes

    • Added validation to reject invalid viewport dimensions and provide consistent plan validation results.
  • Documentation

    • Documented viewport configuration and the desktop default used when no viewport is specified.

Adds an optional viewport field to the plan file schema
(<width>x<height> format, e.g. "390x844") and a --viewport <WxH>
CLI flag to test create --plan-from. This allows users to test
responsive/mobile-only UI by telling the frontend browser runner
what viewport size to use.

- CliPlanInput: add viewport?: string
- plan.schema.json: add viewport property (pattern: ^[1-9]\d*x[1-9]\d*$)
- assertPlanShape / collectPlanIssues: validate viewport format
- runCreateFromPlan: pass viewport in POST /tests body
- test create: add --viewport <WxH> flag (overrides plan JSON value)
- DOCUMENTATION.md: add viewport to plan field table
- Tests: 2 new viewport tests (valid + invalid)

Closes TestSprite#174
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Changes

Frontend viewport support

Layer / File(s) Summary
Viewport schema and validation
schemas/plan.schema.json, DOCUMENTATION.md, src/commands/test.ts, src/lib/plan-schema.spec.ts
Plans accept optional positive viewport dimensions in <width>x<height> format. Runtime validation and schema tests cover valid, invalid, and complete plan values.
CLI override and request forwarding
src/commands/test.ts
test create --viewport <WxH> overrides the plan value. The resolved viewport is validated and included in the create request.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: ruili-testsprite

Sequence Diagram(s)

sequenceDiagram
  participant TestCreateCommand
  participant runCreateFromPlan
  participant PlanValidator
  participant CreateRequest
  TestCreateCommand->>runCreateFromPlan: pass --viewport value
  runCreateFromPlan->>PlanValidator: validate plan and viewport
  PlanValidator-->>runCreateFromPlan: return validated viewport
  runCreateFromPlan->>CreateRequest: include resolved viewport
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: optional plan-file viewport support and the --viewport CLI flag.
Linked Issues check ✅ Passed The changes implement configurable viewport dimensions through plan files and a CLI override, addressing issue #174.
Out of Scope Changes check ✅ Passed All changes support viewport configuration, validation, request forwarding, documentation, or related tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
DOCUMENTATION.md (1)

169-169: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the CLI override precedence.

This row documents the plan value, but it does not state that test create --plan-from --viewport &lt;WxH&gt; overrides the JSON value. Add this rule to the note or link the command reference.

Suggested documentation update
-| `viewport`   | no       | string | Browser viewport for the frontend runner, in `<width>x<height>` form. Forwarded to the backend. Absent means the runner's desktop default. |
+| `viewport`   | no       | string | Browser viewport for the frontend runner, in `<width>x<height>` form. Forwarded to the backend. A `--viewport <WxH>` value on `test create --plan-from` overrides this field. Absent means the runner's desktop default. |

As per path instructions, test create --plan-from supports a CLI --viewport &lt;WxH&gt; override, and the CLI value should take precedence over the plan value.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@DOCUMENTATION.md` at line 169, Update the viewport documentation row in
DOCUMENTATION.md to state that the test create --plan-from --viewport <WxH> CLI
value overrides the viewport specified in the JSON plan, or link to the command
reference documenting this precedence.

Source: Path instructions

src/lib/plan-schema.spec.ts (1)

137-145: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add boundary cases for positive viewport dimensions.

The test rejects "abc" but does not cover 0x844, 390x0, or 0390x0844. Add these cases and assert that both validate and passesRealValidator reject them. This protects the schema and runtime validator contract.

As per path instructions, plan validation and test lint are local/offline and should reject invalid plans before network requests.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lib/plan-schema.spec.ts` around lines 137 - 145, Extend the viewport
validation test around validate and passesRealValidator to cover zero dimensions
and leading-zero dimensions: reject 0x844, 390x0, and 0390x0844 with both
validators. Keep the existing valid 390x844 and invalid abc assertions, and
ensure these cases remain local validation checks before any network-dependent
path.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/commands/test.ts`:
- Around line 9601-9605: Handle the shared test create command’s viewport option
in both execution paths: if viewport is supported only with --plan-from, reject
its use before runCreate via localValidationError so the command returns
VALIDATION_ERROR with exit code 5; otherwise pass viewport through runCreate and
include it in the request body. Update the --plan-from forwarding at the
existing action branch while preserving the thin client’s existing error
handling.
- Around line 2449-2458: Define a shared VIEWPORT_PATTERN matching positive,
non-zero dimensions without leading zeroes, then replace the duplicated viewport
regex checks in the CLI override, assertPlanShape, and collectPlanIssues. Ensure
all local validation paths, including test create --plan-from and test lint,
reject values such as 0x844, 390x0, and 0390x0844 consistently with
schemas/plan.schema.json.

---

Nitpick comments:
In `@DOCUMENTATION.md`:
- Line 169: Update the viewport documentation row in DOCUMENTATION.md to state
that the test create --plan-from --viewport <WxH> CLI value overrides the
viewport specified in the JSON plan, or link to the command reference
documenting this precedence.

In `@src/lib/plan-schema.spec.ts`:
- Around line 137-145: Extend the viewport validation test around validate and
passesRealValidator to cover zero dimensions and leading-zero dimensions: reject
0x844, 390x0, and 0390x0844 with both validators. Keep the existing valid
390x844 and invalid abc assertions, and ensure these cases remain local
validation checks before any network-dependent path.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d13ea3cf-b63e-41e4-ae2e-76d4663e6c2d

📥 Commits

Reviewing files that changed from the base of the PR and between b35dbae and fc11edf.

📒 Files selected for processing (4)
  • DOCUMENTATION.md
  • schemas/plan.schema.json
  • src/commands/test.ts
  • src/lib/plan-schema.spec.ts

Comment thread src/commands/test.ts
Comment on lines +2449 to +2458
if (opts.viewport !== undefined) {
if (!/^\d+x\d+$/.test(opts.viewport)) {
throw localValidationError(
'viewport',
'must be a string in `<width>x<height>` format (e.g. "390x844")',
undefined,
'flag',
);
}
plan.viewport = opts.viewport;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Use one positive-dimension validator for every viewport input.

schemas/plan.schema.json requires each dimension to match [1-9]\d*, but these runtime checks use \d+. Therefore 0x844, 390x0, and 0390x0844 pass --viewport, assertPlanShape, and test lint, even though the schema rejects them. test create --plan-from can send a value that local validation should reject.

Define one VIEWPORT_PATTERN and use it in the CLI override, assertPlanShape, and collectPlanIssues.

Proposed fix
+const VIEWPORT_PATTERN = /^[1-9]\d*x[1-9]\d*$/;

-    if (!/^\d+x\d+$/.test(opts.viewport)) {
+    if (!VIEWPORT_PATTERN.test(opts.viewport)) {

-    if (typeof obj.viewport !== 'string' || !/^\d+x\d+$/.test(obj.viewport)) {
+    if (typeof obj.viewport !== 'string' || !VIEWPORT_PATTERN.test(obj.viewport)) {

As per path instructions, plan validation and test lint are local/offline and should reject invalid plans before network requests.

Also applies to: 2763-2772, 2854-2858

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/commands/test.ts` around lines 2449 - 2458, Define a shared
VIEWPORT_PATTERN matching positive, non-zero dimensions without leading zeroes,
then replace the duplicated viewport regex checks in the CLI override,
assertPlanShape, and collectPlanIssues. Ensure all local validation paths,
including test create --plan-from and test lint, reject values such as 0x844,
390x0, and 0390x0844 consistently with schemas/plan.schema.json.

Source: Path instructions

Comment thread src/commands/test.ts
Comment on lines +9601 to +9605
.option(
'--viewport <WxH>',
'optional browser viewport for the frontend runner (e.g. "390x844" for mobile). ' +
'With --plan-from, overrides the viewport in the plan JSON.',
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not silently ignore --viewport outside --plan-from.

The option is registered on the shared test create command. The action forwards it only in the --plan-from branch at Line [9708]. The regular runCreate call at Lines [9722-9748] does not receive it. A valid code-file invocation can therefore succeed without applying the requested viewport.

If viewport is plan-only, reject the flag before runCreate with localValidationError so the command returns VALIDATION_ERROR with exit code 5. Otherwise, thread viewport through runCreate and its request body.

As per path instructions, this thin client must preserve correctness and clear error handling.

Also applies to: 9708-9708

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/commands/test.ts` around lines 9601 - 9605, Handle the shared test create
command’s viewport option in both execution paths: if viewport is supported only
with --plan-from, reject its use before runCreate via localValidationError so
the command returns VALIDATION_ERROR with exit code 5; otherwise pass viewport
through runCreate and include it in the request body. Update the --plan-from
forwarding at the existing action branch while preserving the thin client’s
existing error handling.

Source: Path instructions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Hackathon] Frontend runner uses a fixed desktop viewport - cannot test mobile/responsive layouts

1 participant