Skip to content

Latest commit

 

History

History
62 lines (44 loc) · 6.71 KB

AGENTS.md

File metadata and controls

62 lines (44 loc) · 6.71 KB

Agent Guide: Design System React

Instructions for AI coding agents (and a quick-start for humans) working in this repo. For conventions and rationale, read docs/codebase-overview.md — start at Creating a New Component before writing component code. Human contributor setup is in CONTRIBUTING.md.

Commands

Setup: Node >= 24 (.nvmrc), npm install, then npx playwright install chromium for the browser test project.

Never run bare npm test — it starts Vitest in watch mode and will not exit.

Command Purpose
npm run typecheck tsc --noEmit
npm run lint ESLint; 0 errors and no more warnings than --max-warnings in package.json
npm test -- --run All tests: jsdom unit project, real-browser browser project, and snapshots
npm test -- --run -u Same, and regenerate story HTML snapshots
npm run build Type-check, library build, .d.ts, entry shims
npm run test:snapshots Story HTML snapshot suite only (~3s)
npm run test:ci Everything CI runs: typecheck, test, build, lint

Run npm run test:ci before requesting review. A husky pre-push hook runs test:snapshots and blocks the push if snapshots are stale.

Things that are easy to miss

  • Stories are test fixtures, not just demos. Every story in components/**/__docs__/*.stories.{jsx,tsx} (except portal-rendered ones, which need component tests instead) is rendered into components/__tests__/__snapshots__/story-snapshots.test.jsx.snap. If you add, remove, or change a story, or change a component's rendered markup, run npm test -- --run -u, review the snapshot diff, and commit it in the same PR.
  • A filtered test run does not run the snapshot suite. npm test -- --run components/combobox skips components/__tests__/story-snapshots.test.jsx. Always finish with an unfiltered run.
  • Local runs write new snapshots silently. Outside CI, a plain npm test -- --run passes and writes snapshots for new stories without failing; CI then fails if they aren't committed. test:ci and test:snapshots pass --update=none to behave like CI. Check git status for .snap changes before pushing.
  • Stories must use the component's real prop API. Cross-check against components/<name>/__examples__ and types.ts; stories written against an assumed API are a common source of "component looks broken" reports.
  • Unexpected console output has a budget of 0. Any test that writes console.error/console.warn is listed after the run (and, on a PR, annotated on the test file and in the job summary); the run fails past maxWarnings in scripts/vitest-console-reporter.ts. Fix the cause, or assert an expected warning with vi.spyOn(console, '<method>'). Lint warnings are annotated on the PR the same way. Build warnings are printed and never fail.
  • jsdom vs. browser tests. Tests that need a real browser (focus traversal, layout/measurement) go in *.browser.test.jsx; everything else is jsdom.
  • New scripts in scripts/ are TypeScript. Write .ts and run it with tsx (as release.ts is); npm run typecheck covers them via tsconfig.scripts.json. The remaining .mjs/.js scripts predate this rule; convert one when you substantially change it. Tests in scripts/__tests__/ stay *.test.mjs, the pattern the scripts Vitest project picks up.
  • Types are the contract. Runtime PropTypes were removed in the TypeScript migration; the generated .d.ts files are what consumers get.
  • Restoring or mirroring existing behavior (stories lost in a rewrite, parity with another implementation): build the inventory from git (git show <old-ref>:<path>, git log --follow), not from memory, and list the before/after set in the PR description.

Git and pull requests

  • Maintainers: push branches to salesforce/design-system-react, not a personal fork. Chromatic runs on push, so fork PRs get no visual review. External contributors fork as described in CONTRIBUTING.md.
  • Conventional commits are enforced by commitlint (fix:, feat:, docs:, chore:, test:, style:, …). Public API removals or renames are breaking: use ! and a BREAKING CHANGE: footer.
  • Keep lint/format-only changes in their own commit (style:), separate from the fix:/feat: commit, so the functional diff is reviewable.
  • Rebase on master and resolve conflicts before requesting review.
  • Fill in docs/PULL_REQUEST_TEMPLATE.md. For bug fixes, state the root cause, not just the symptom, and add a regression test.

Releasing

Maintainers: npm run release-pr -- next (or an explicit version such as 11.0.0-alpha.4) bumps package.json on chore/release-<version> cut from origin/master, commits, pushes, and opens the PR (add --dry-run to preview). Once it merges, create the GitHub Release with gh release create v<version> --target master --generate-notes (add --prerelease for alpha/beta/rc), which triggers .github/workflows/npm-publish.yml to publish to npm. See scripts/release.ts for details.

For a maintenance line, add --base <branch>: npm run release-pr -- next --base 0.10.x cuts chore/release-0.10.66 from origin/0.10.x (next patch-bumps a stable version there) and opens the PR against that branch. After it merges, gh release create v<version> --target 0.10.x --generate-notes runs that branch's own publish workflow. A stable maintenance release publishes under npm's latest dist-tag, which is right while the current major is in prerelease.

Scratch files

Agent-generated notes, plans, and analyses go in .planning/ (gitignored). Don't commit them.

Reference

Sections of docs/codebase-overview.md to check when a decision is ambiguous: