Files
AutoGPT/autogpt_platform/frontend/AGENTS.md
Ubbe a11199aa67 dx(frontend): set up React integration testing with Vitest + RTL + MSW (#12667)
## Summary
- Establish React integration tests (Vitest + RTL + MSW) as the primary
frontend testing strategy (~90% of tests)
- Update all contributor documentation (TESTING.md, CONTRIBUTING.md,
AGENTS.md) to reflect the integration-first convention
- Add `NuqsTestingAdapter` and `TooltipProvider` to the shared test
wrapper so page-level tests work out of the box
- Write 8 integration tests for the library page as a reference example
for the pattern

## Why
We had the testing infrastructure (Vitest, RTL, MSW, Orval-generated
handlers) but no established convention for page-level integration
tests. Most existing tests were for stores or small components. Since
our frontend is client-first, we need a documented, repeatable pattern
for testing full pages with mocked APIs.

## What
- **Docs**: Rewrote `TESTING.md` as a comprehensive guide. Updated
testing sections in `CONTRIBUTING.md`, `frontend/AGENTS.md`,
`platform/AGENTS.md`, and `autogpt_platform/AGENTS.md`
- **Test infra**: Added `NuqsTestingAdapter` (for `nuqs` query state
hooks) and `TooltipProvider` (for Radix tooltips) to `test-utils.tsx`
- **Reference tests**: `library/__tests__/main.test.tsx` with 8 tests
covering agent rendering, tabs, folders, search bar, and Jump Back In

## How
- Convention: tests live in `__tests__/` next to `page.tsx`, named
descriptively (`main.test.tsx`, `search.test.tsx`)
- Pattern: `setupHandlers()` → `render(<Page />)` → `findBy*` assertions
- MSW handlers from
`@/app/api/__generated__/endpoints/{tag}/{tag}.msw.ts` for API mocking
- Custom `render()` from `@/tests/integrations/test-utils` wraps all
required providers

## Test plan
- [x] All 422 unit/integration tests pass (`pnpm test:unit`)
- [x] `pnpm format` clean
- [x] `pnpm lint` clean (no new errors)
- [x] `pnpm types` — pre-existing onboarding type errors only, no new
errors

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Nicholas Tindle <nicholas.tindle@agpt.co>
Co-authored-by: Reinier van der Leer <pwuts@agpt.co>
2026-04-06 13:17:08 +00:00

4.6 KiB

Frontend

This file provides guidance to coding agents when working with the frontend.

Essential Commands

# Install dependencies
pnpm i

# Generate API client from OpenAPI spec
pnpm generate:api

# Start development server
pnpm dev

# Run E2E tests
pnpm test

# Run Storybook for component development
pnpm storybook

# Build production
pnpm build

# Format and lint
pnpm format

# Type checking
pnpm types

Pre-completion Checks (MANDATORY)

After making any code changes in the frontend, you MUST run the following commands in order before reporting work as done, creating commits, or opening PRs:

  1. pnpm format — auto-fix formatting issues
  2. pnpm lint — check for lint errors; fix any that appear
  3. pnpm types — check for type errors; fix any that appear

Do NOT skip these steps. If any command reports errors, fix them and re-run until clean. Only then may you consider the task complete. If typing keeps failing, stop and ask the user.

  1. pnpm test:unit — run integration tests; fix any failures

Code Style

  • Fully capitalize acronyms in symbols, e.g. graphID, useBackendAPI
  • Use function declarations (not arrow functions) for components/handlers
  • No dark: Tailwind classes — the design system handles dark mode
  • Use Next.js <Link> for internal navigation — never raw <a> tags
  • No any types unless the value genuinely can be anything
  • No linter suppressors (// @ts-ignore, // eslint-disable) — fix the actual issue
  • File length — keep files under ~200 lines; extract sub-components or hooks into their own files when a file grows beyond this
  • Function/component length — keep render functions and hooks under ~50 lines; extract named helpers or sub-components when they grow longer

Architecture

  • Framework: Next.js 15 App Router (client-first approach)
  • Data Fetching: Type-safe generated API hooks via Orval + React Query
  • State Management: React Query for server state, co-located UI state in components/hooks
  • Component Structure: Separate render logic (.tsx) from business logic (use*.ts hooks)
  • Workflow Builder: Visual graph editor using @xyflow/react
  • UI Components: shadcn/ui (Radix UI primitives) with Tailwind CSS styling
  • Icons: Phosphor Icons only
  • Feature Flags: LaunchDarkly integration
  • Error Handling: ErrorCard for render errors, toast for mutations, Sentry for exceptions
  • Testing: Vitest + React Testing Library + MSW for integration tests (primary), Playwright for E2E, Storybook for visual

Environment Configuration

.env.default (defaults) → .env (user overrides)

Feature Development

See @CONTRIBUTING.md for complete patterns. Quick reference:

  1. Pages: Create in src/app/(platform)/feature-name/page.tsx
    • Extract component logic into custom hooks grouped by concern, not by component. Each hook should represent a cohesive domain of functionality (e.g., useSearch, useFilters, usePagination) rather than bundling all state into one useComponentState hook.
      • Put each hook in its own .ts file
    • Put sub-components in local components/ folder
    • Component props should be type Props = { ... } (not exported) unless it needs to be used outside the component
  2. Components: Structure as ComponentName/ComponentName.tsx + useComponentName.ts + helpers.ts
    • Use design system components from src/components/ (atoms, molecules, organisms)
    • Never use src/components/__legacy__/*
  3. Data fetching: Use generated API hooks from @/app/api/__generated__/endpoints/
    • Regenerate with pnpm generate:api
    • Pattern: use{Method}{Version}{OperationName}
  4. Styling: Tailwind CSS only, use design tokens, Phosphor Icons only
  5. Testing: Integration tests are the default (~90%). See TESTING.md for full details.
    • New pages/features: Write integration tests in __tests__/ next to page.tsx using Vitest + RTL + MSW
    • API mocking: Use Orval-generated MSW handlers from @/app/api/__generated__/endpoints/{tag}/{tag}.msw.ts
    • Run: pnpm test:unit (integration/unit), pnpm test (Playwright E2E)
    • Storybook: For design system components in src/components/
    • TDD: Write a failing test first, implement, then verify
  6. Code conventions:
    • Use function declarations (not arrow functions) for components/handlers
    • Do not use useCallback or useMemo unless asked to optimise a given function
    • Do not type hook returns, let Typescript infer as much as possible
    • Never type with any unless a variable/attribute can ACTUALLY be of any type
    • avoid index and barrel files