Skip to content

docs: correct FE1 and agent guidance on Storybook and Vitest roles - #29016

Merged
DanielleMaywood merged 3 commits into
mainfrom
fix-storybook-fe1-guidance
Sep 9, 2026
Merged

docs: correct FE1 and agent guidance on Storybook and Vitest roles#29016
DanielleMaywood merged 3 commits into
mainfrom
fix-storybook-fe1-guidance

Conversation

@DanielleMaywood

@DanielleMaywood DanielleMaywood commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Storybook in this repository is visual regression only. The storybook CI job runs pixel-storybook, which loads each story, runs its play function, waits for the DOM to settle, and screenshots it.

FE1 stated the opposite: it demanded interaction coverage in play functions and called RTL interaction tests a violation, so agents kept producing assertion-heavy play functions that duplicate what Pixel already captures.

The corrected contract, in every document that restates it:

  • Visual regression is Pixel's job. What the DOM renders, shows, or hides is verified by the story's screenshot, not by an assertion. That applies in both places: a play function must not assert at all (it only drives state setup the screenshot needs), and a Vitest test must not use toBeVisible/toBeInTheDocument/geometry as its outcome assertion.
  • Vitest is the behavior check. A test drives the real interaction with userEvent, uses semantic queries to locate the element it interacts with, and asserts the non-visual outcome: the callback payload, the API request, the attribute value, the state change.

Files updated:

  • .claude/docs/FRONTEND_PATTERNS.md: FE1 rewritten with both incorrect examples (assertions in a play function, and visibility as a test's outcome) plus a correct example asserting onValueChange's payload.
  • site/AGENTS.md: FE1 one-line summary and the Testing section.
  • AGENTS.md: the frontend repository guardrail.
  • .claude/skills/frontend-review/SKILL.md: the FE1 checklist now flags visibility/presence outcome assertions in tests as a FAIL, alongside assertions in play functions.

Follow-ups in this stack remove the assertion-only play functions and duplicate stories that the old guidance produced.

Generated by Coder Agents on behalf of @DanielleMaywood.

Comment thread .claude/docs/FRONTEND_PATTERNS.md Outdated
Comment thread .claude/skills/frontend-review/SKILL.md Outdated
Comment thread .claude/docs/FRONTEND_PATTERNS.md Outdated
Storybook in this repository is visual regression only. The storybook CI
job runs pixel-storybook, which loads each story, runs its play function,
waits for the DOM to settle, and screenshots it. Vitest is where behavior
and interaction assertions belong.

The old FE1 inverted this: it demanded interaction coverage in play
functions and called RTL interaction tests a violation. Update FE1, its
one-line summary, the repository guardrail, and the frontend-review
checklist so agents stop producing assertion-heavy play functions.
@DanielleMaywood
DanielleMaywood force-pushed the fix-storybook-fe1-guidance branch from 41b0835 to 74d21c3 Compare September 8, 2026 15:26
Comment thread .claude/docs/FRONTEND_PATTERNS.md Outdated
item that must not change.
## FE1: Vitest covers behavior, Storybook covers visual states

Every frontend change needs a Vitest/RTL test for the behavior, and/or

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think demanding "every change be tested" it part of the problem. agents love to interpret that as "a new test must be written" even if coverage is already present. they get desperate looking for ways to expand test coverage and write bullshit negative-value tests as a result.

long way of saying: we need to loosen this language. it's too strict sounding as is.

also wth is rtl?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Has the agent loosen the language a bit

Comment thread .claude/docs/FRONTEND_PATTERNS.md Outdated

Every frontend change needs a Vitest/RTL test for the behavior, and/or
a Storybook story for every visual state the change can render. CI runs
Pixel, our internal visual regression tool for Storybook, over the build:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Pixel, our internal visual regression tool for Storybook, over the build:
Pixel for visual regression testing using Storybook:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Had the agent apply this

Comment thread .claude/docs/FRONTEND_PATTERNS.md Outdated
check: what the DOM renders, shows, or hides. The test is the behavior
check: what the component did.

- Write the behavior test in a `.test.tsx` file using RTL and `userEvent`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oh, react testing library? I don't like this acronym. it's not common enough to be obvious.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair, to be fair I momentarily read it as right to left 🤣

Comment thread .claude/docs/FRONTEND_PATTERNS.md Outdated
check: what the DOM renders, shows, or hides. The test is the behavior
check: what the component did.

- Write the behavior test in a `.test.tsx` file using RTL and `userEvent`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
- Write the behavior test in a `.test.tsx` file using RTL and `userEvent`.
- Behavior tests should use Vitest, React Testing Library and `userEvent`.

I think this is another case of language that is too suggestive of "you must write more tests". it's too prescriptive. saying "write the test" implies that a test must be written.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good shout

Comment thread .claude/docs/FRONTEND_PATTERNS.md Outdated

- Write the behavior test in a `.test.tsx` file using RTL and `userEvent`.
Drive the real interaction, then assert the non-visual outcome: the
callback payload, the API request, the attribute value, the state change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think tests that assert attribute presence are negative-value and should be avoided.

Comment thread .claude/docs/FRONTEND_PATTERNS.md Outdated
Comment on lines +33 to +35
you interact with, not as the assertion. An outcome assertion such as
`expect(el).toBeVisible()` or `toBeInTheDocument()` reports what the DOM
renders, which is exactly what the story's screenshot already captures.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

whereas this actually should be said louder, and more strictly. do not assert .toBeInTheDocument(). hard stop.

Comment on lines +36 to +39
- A story's `play` function exists only for state setup the screenshot needs:
open the menu, toggle the switch, type the text, focus the trigger. Do not
put assertions in a play function. Pixel fails the capture only if the
setup throws.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

and call out more clearly that the alternative here is to do it in Vitest instead if it's actually valuable.

Comment thread site/AGENTS.md Outdated
## Frontend contract

- **FE1:** UI behavior changes ship with Storybook stories whose `play` function exercises the real interaction. Vitest or RTL is for pure logic only.
- **FE1:** UI behavior changes ship with a Vitest/RTL test for the behavior and a Storybook story for each visual state. Pixel screenshots every story in CI, so a story's `play` function may drive the component into the state being captured (open the menu, type text) but must not assert behavior. Tests drive the interaction and assert the non-visual outcome (callback, request, attribute, state); assertions on what the DOM renders, such as visibility or presence, are the screenshot's job.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

RTL again. just say the full name here.

@DanielleMaywood

Copy link
Copy Markdown
Contributor Author

@aslilac my agent has made the changes, I've checked them and I think it covers everything you've asked for. Lemme know if I missed anything or anything else we should cover.

@DanielleMaywood
DanielleMaywood marked this pull request as ready for review September 8, 2026 22:50
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-08T22:55:15.859252Z e336f46 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e336f463ec

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +33 to +37
- Use semantic queries (`getByRole`, `getByLabelText`) to locate the elements
you interact with, not as the assertion. Do not assert `.toBeInTheDocument()`,
`.toBeVisible()`, DOM geometry, or attribute presence. Hard stop: they
report what the DOM renders, which is exactly what the story's screenshot
already captures.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Permit assertions for DOM-only outcomes

When the contract is semantic DOM state, such as the absence of an incorrect tablist role or the presence of an accessible error message, there may be no callback or request to assert, and a pixel screenshot cannot detect the accessibility regression. The hard ban would reject tests such as site/src/components/Tabs/Tabs.test.tsx:31-46, removing the only check for semantics that remain visually identical. Limit the prohibition to assertions that merely duplicate visual coverage, while allowing rendered or semantic assertions when they are themselves the behavior under test.

AGENTS.md reference: AGENTS.md:L31-L31

Useful? React with 👍 / 👎.

Comment thread site/AGENTS.md
Comment thread .claude/skills/frontend-review/SKILL.md Outdated
new Vitest test, and the new visual states by Storybook stories. Behavior
tests should use Vitest, React Testing Library and `userEvent`. A `play`
function may only drive state setup the screenshot needs (open the menu,
type the text); assertions in a `play` function are a FAIL, as is behavior

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"assertions are a fail" what does that mean? it makes it sound like pixel is supposed to enforce that you don't use assertions, but that's not how it works

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oh, this is in the review skill?

Comment thread .claude/skills/frontend-review/SKILL.md Outdated
`toBeInTheDocument`, geometry, attribute presence) is a FAIL, hard stop:
the story's screenshot already covers it. Flag tests written only to
expand coverage when equivalent coverage already exists. Flag stories marked
`parameters.pixel.exclude: true` that have no equivalent test, since an

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

and require an explanation for excluded stories. why does the story exist if it's not worth snapshotting?

@DanielleMaywood

Copy link
Copy Markdown
Contributor Author

Merging now because I'm still getting PRs loaded with sloppy tests @aslilac . If there is anything else to fix I'll do a follow-up PR

@DanielleMaywood
DanielleMaywood merged commit 5d04899 into main Sep 9, 2026
26 checks passed
@DanielleMaywood
DanielleMaywood deleted the fix-storybook-fe1-guidance branch September 9, 2026 08:19
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants