Skip to content

Run Playwright specs that use a local fixtures file under playwright test, and let a repo send chosen tests to its own runner - #4347

Closed
vilano93 wants to merge 2 commits into
garrytan:mainfrom
vilano93:fix/pregate-playwright-fixtures
Closed

vilano93 wants to merge 2 commits into
garrytan:mainfrom
vilano93:fix/pregate-playwright-fixtures

Conversation

@vilano93

Copy link
Copy Markdown
Contributor

Why (in your own words)

My app repo has vitest unit tests and Playwright specs in one package. Every spec takes test from its own fixtures file (export const test = base.extend(…), then import { expect, test } from './fixture'), which is Playwright's documented fixtures pattern. pregate only marks a spec as Playwright when the spec itself imports @playwright/test (#3741). So a diff that touches only a spec, even one comment line, sends it to vitest run <spec>. Vitest finds no test files, the lane fails, and /ship cannot publish a record. This PR follows the modules a test takes test from. A unit test that imports some other Playwright-based helper keeps its unit runner.

Detection alone does not get my specs to pass. My harness has to build the native engine and the bundle before a spec can start, and the repo's entry point pnpm run e2e -- <spec> does that build, while a bare playwright test deliberately never builds. A repo can declare only one runner for every file today, so I add runners to .gstack/pregate.json. A rule is { when: [globs], runner, cwd? }, and the selected files it matches go to that command ahead of runner and detection, first match wins. Every other file keeps today's plan. gstack-checks treats each rule as a command that needs consent, like runner.

Live evidence

Same branch, where one commit changes one comment line in app/e2e/smoke.spec.ts (later editing-flag.spec.ts). Command: gstack-pregate run --stage tests --allow-repo-commands --base <base>.

Installed 1.99.2.0, the spec goes to vitest:

    lanes: ran: (cd 'app' && pnpm exec vitest run 'e2e/smoke.spec.ts')
    lanes:   No test files found, exiting with code 1
    lanes:   include: src/**/*.test.{ts,tsx}, e2e/lib/**/*.test.ts
tests      lanes     fail               1823 ms  local lane exited 1 (? failed of ? ran; 1 files; pipefail) (PREGATE_LANE_FAILED)

This branch, no runners rule: the spec is now seen as Playwright. My harness then refuses to start on a stale bundle, which is why the second part exists:

    lanes: ran: (cd 'app' && pnpm exec playwright test --reporter=list '(?:^|/)e2e/smoke\.spec\.ts$')
    lanes:       Error: Harness kann nicht starten:
    lanes:       - Bundle nicht frisch (main älter als app/src, …) — `pnpm run e2e:rauch` baut es
tests      lanes     fail               6576 ms  local lane exited 1 (1 failed of 1 ran; 1 files; pipefail) (PREGATE_LANE_FAILED)

This branch, base policy with "runners": [{ "when": ["app/e2e/*.spec.ts"], "runner": "pnpm run e2e -- {files}", "cwd": "app/e2e" }]: the spec runs through the repo's entry point, which builds and then runs it:

PREGATE_TEST: 1/1 editing-flag.spec.ts pass 30.7
tests      lanes     requires-remote   31246 ms  1 tests ran in 1 file(s), exit 0; 2 requires-remote obligation(s)
    lanes: ran: (cd 'app/e2e' && pnpm run e2e -- 'editing-flag.spec.ts')
    lanes:     ✓  1 [e2e] › e2e/editing-flag.spec.ts:16:7 › … (14.2s)
    lanes:     ✓  2 [e2e] › e2e/editing-flag.spec.ts:45:7 › … (12.3s)
    lanes:     2 passed (26.8s)

The two requires-remote obligations are the repo's Linux CI lanes, unchanged by this PR.

The four new tests were red before the fix:

(fail) … > a spec importing test from a local fixtures module that extends @playwright/test runs through playwright test
(fail) … > a runners rule sends its files to its command from its directory; the rest keep their plan
(fail) … > config: runners entries need globs, a {files} command and a contained directory
(fail) gstack-checks on a fixture repo > consent covers the runners rules

The first one was red because the specs went into the vitest group (e2e/smoke.spec.ts, e2e/deep.spec.ts under pnpm exec vitest run). The consent test was red because a rule added on the base ran with exit 0 and no new consent.

To confirm the tests can fail, I broke the code on purpose:

Sabotage Test that went red
Spec detection back to the direct import only the fixtures-module test
runners ignored (planRuns skips the rules) the runners-rule test
cwd validation removed the config test

Scope

  • Changed:
    • lib/pregate/checks/lanes.ts:
      • playwrightSpec follows the modules a test takes test from, through import { test }, aliases, export { test } from, index modules and .js specifiers that name .ts sources, up to 8 hops and only inside the repo.
      • planRuns applies runners rules first. A matched file outside the rule's cwd is unclaimed, so the lane reads incomplete.
    • lib/pregate/config.ts: the runners key, with validation (non-empty globs, a {files} command, a contained cwd, no unknown keys, at most 32 rules) and the --explain line.
    • lib/pregate/head-policy.ts: runners is frozen under --policy-from head, like runner.
    • lib/checks.ts, bin/gstack-checks:
      • The rules are part of the trusted command set and the grant log.
      • detect and the consent refusal list each rule.
    • docs/pregate.md: the runner row gets the fixtures detection, and there is a new runners row.
    • test/pregate-selection.test.ts, test/gstack-checks.test.ts: the four tests above.
    • changelog.d/fix-pregate-playwright-fixtures.md: the changelog fragment.
  • Verified live by: the three runs above on macOS 26 (Apple Silicon, Bun 1.4.4), on a real repo. bun run typecheck is clean, and bun run typecheck:test reports none new.
  • Did NOT test:
    • Linux or Windows.
    • The remote gate and test_backend: they still receive the whole selection, and the docs say so.
    • The full free suite. Locally, test:quick fails in qa-functional-observer-atomic, relink-disabled-router, render-sections-provenance and transcript-consent. pregate-head-policy fails twice and pregate-guards once. All of these fail the same way on an untouched upstream/main checkout on this machine, so CI is the judge here.
    • The paid evals. This change adds no prompt text.
  • Known limit: a runners command that wraps Playwright gets the generic summary parser. My entry point prints a fixture project's 1 passed before the spec's 2 passed, so the lane says "1 tests ran" for two tests. The verdict comes from the exit code and stays right. Picking the Playwright parser for any output with Playwright's Running N tests using header would fix the count. I left that out to keep this PR to one concern.
  • Behaviour change to weigh: a spec that takes test from a local module built on @playwright/test moves from the unit runner to playwright test. Before, a diff that also touched a unit test made vitest drop the spec silently, so the spec now really runs, and a stale harness can turn the lane red for the first time. runners is the way out for such a repo.

Liveness proof (required for external contributors)

Checklist

  • Liveness screenshot attached (GSTACK PR typed live into a real surface) or PR author is @garrytan (owner exemption)
  • This is not a generated-file-only diff (I edited the source/template and regenerated)
  • No ETHOS.md edits, and no changes to voice / founder perspective / YC references
  • New public command / external service / host adapter has an accepted issue linked (or N/A)
  • Linked issue or reproduction: reproduction above

🤖 Generated with Claude Code

vilano93 and others added 2 commits November 13, 2026 21:37
…test, and let a repo name its own runner per path

pregate marked a spec as Playwright only when the spec itself imported
@playwright/test. Specs that take `test` from a local fixtures module
(`export const test = base.extend(...)`) went to the package's vitest,
which found no test files and failed the lane. pregate now follows the
modules a test takes `test` from.

A spec whose harness must build first cannot run under a bare
`playwright test`, so `.gstack/pregate.json` gains `runners`:
`{ when: [globs], runner, cwd? }` rules that send matching selected
files to the repo's own command, ahead of `runner` and detection.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A runners rule is a command like runner. Adding or editing one on the
base now changes the trusted command set, so nothing runs until the user
agrees again, and detect and the consent refusal name each rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trunk-io

trunk-io Bot commented Nov 13, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@capy-ai

capy-ai Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Thanks for this, and for the live runs and the sabotage table. The detection half (a spec that takes test from a local fixtures file going to vitest) is a clear bug with a real cost, so we're picking it up: a crew lane will rewrite it on current main and credit you as co-author. Pregate changes are paused until November 21, so it will wait until then. The runners rules are new configuration that runs repo commands, so that part goes through our planning step first rather than landing with the fix.

@capy-ai

capy-ai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Thank you for this. We're picking up the idea. A maintainer agent working through a batch of fixes (our tracking thread GSTA-805) will first reproduce the problem on current main. If it reproduces, the agent rebuilds the fix on main with you credited as co-author, because we don't merge outside branches directly, and we'll close this PR with a link when it lands. If it no longer reproduces, we'll close this and say what changed. The rebuild will likely take only the detection half. Other work on the same pregate files has to land first, so this may take a few days.

capy-ai Bot added a commit that referenced this pull request Nov 22, 2026
…xture specs run under Playwright (#4702)

Deleting or renaming a test now runs the tests of files that still list
it even when another test already covers it, and Playwright specs that
take `test` from a local fixtures file run under `playwright test`.

Why: a deleted test could pass the local checks while a stale curation
list failed after merge (#3536), and fixture-based Playwright specs went
to the unit runner and failed (#4347).

Nothing to do. A repo whose specs import `@playwright/test` directly
sees no change.

Co-authored-by: Yuan S. <[email protected]>
Co-authored-by: marcode <[email protected]>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: review-p1/specialist-batched#1 reader=specialist-batched
Review-Finding: review-p1/specialist-batched#2 reader=specialist-batched
Review-Finding: review-p1/red-team#1 reader=red-team
Review-Finding: review-v1/outside-voice#1 reader=outside-voice
Review-Finding: review-v1/outside-voice#2 reader=outside-voice
Review-Finding: review-v1/outside-voice#3 reader=outside-voice
Review-Finding: review-v1/outside-voice#4 reader=outside-voice
Review-Finding: review-p2/specialist-batched#1 reader=specialist-batched
Review-Finding: review-p2/red-team#1 reader=red-team
@capy-ai

capy-ai Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Thank you @vilano93. The detection half of this landed in #4702, rebuilt on current main with you credited as co-author: a spec that takes test from a local Playwright fixtures module (base.extend(…), mergeTests(…), re-exports and index files) now runs under playwright test. The runners setting is new configuration rather than a fix, so we're not taking it for now. Closing this; thanks for the clear report and the patch.

@capy-ai capy-ai Bot closed this Nov 22, 2026
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.

1 participant