analyze-codebase
Analyze Codebase
When to use
- At the start of a Playwright testing session (before ingest-spec or plan-tests)
- When running as part of
run-testing-sessionpipeline (Stage 1) - When project context is stale and needs refresh
Important: Always Prompt, Never Skip
When invoked as part of the run-testing-session orchestrator (Stage 0):
- If
project-context.mddoes NOT exist: Show user "No global project context found. Run analyze-codebase? (required to proceed)" → User must choose Yes or the orchestrator cancels - If
project-context.mdEXISTS: Show user these options:- A) Use existing context (skip analyze-codebase)
- B) Re-run analyze-codebase (project has grown or changed)
- C) Cancel session
This ensures the user always controls when the codebase analysis happens, especially important when the repository has grown and context needs refresh.
When run standalone (outside the orchestrator): analyze-codebase always writes to docs/playwright-spec-testing/project-context.md without prompting. Users can run it manually anytime.
Inputs
- Project root directory path
What it does
Scan the project at the project root and produce a shared context document that all subsequent pipeline stages depend on. You are read-only — do not run the app or open a browser.
Phase 1: Playwright setup
Search the project root and common config locations for:
playwright.config.tsorplaywright.config.js— note:testDir,baseURL,use.browserName, reporterpackage.json— note the test script and any@playwright/testversion- Existing test files matching
**/*.spec.ts,**/*.spec.js,**/*.test.ts,**/*.test.js
If no Playwright config exists, note this clearly.
Phase 2: Routing structure
Look for:
app/orpages/directory → Next.js App Router or Pages Routersrc/routes/→ SvelteKit or React Router file-based routingrouter.tsorroutes.ts→ programmatic routing- Top-level
index.html→ single-page app without file-based routing
List the top-level routes you find with their paths and likely purpose.
Phase 3: Existing specs
Search for:
**/*.featurefiles — Gherkin specs- Any file in
specs/,test-cases/, ortest-docs/directories - Any Markdown or text file whose name contains "test", "spec", "scenario", or "acceptance"
Phase 4: Tech stack
From package.json dependencies, identify:
- UI framework: React, Vue, Svelte, Angular, or vanilla
- Component library: shadcn/ui, MUI, Ant Design, Chakra, Radix, etc.
- CSS approach: Tailwind, CSS Modules, styled-components
Phase 5: Write context document
Save findings to docs/playwright-spec-testing/project-context.md (create directory if needed).
Use this exact structure:
# Project Context
_Generated by analyze-codebase on [DATE]_
## Playwright Config
- Config file: [path or "not found"]
- testDir: [value]
- baseURL: [value]
- Default browser: [value]
## Test File Conventions
- Existing test files: [list with paths]
- Naming pattern: [e.g., "*.spec.ts in tests/"]
- Output directory for new tests: [inferred from testDir, or "not yet determined — plan-tests will ask"]
## Routing Structure
- Framework: [Next.js App Router / Pages Router / React Router / SvelteKit / other]
- Top-level routes: [list]
## Existing Specs
- [path] — [Gherkin / plain English]
## Tech Stack
- UI framework: [name]
- Component library: [name or "none detected"]
- CSS approach: [name]
## Notes
[Any issues, warnings, or things to know]
Phase 6: Scan for reusable test infrastructure
After writing the main project-context.md, scan the project for reusable test infrastructure and append a new section to the same file.
What to scan for:
- Custom fixture files (
fixtures/,*.fixtures.ts, any file containingtest.extend()`) - Page objects (
page-objects/,pages/, any class whose constructor accepts a PlaywrightPageparameter) - Auth helpers (functions named
login*,auth*,signIn*) - Shared
beforeEachpatterns in existing spec files
Append to project-context.md:
## Reusable Test Infrastructure
### Fixtures
- `tests/fixtures/auth.fixture.ts` — exports `authenticatedPage` (pre-logged-in page)
- `tests/fixtures/index.ts` — re-exports all fixtures via custom `test` object
### Page Objects
- `tests/pages/LoginPage.ts` — methods: `fill()`, `submit()`, `expectError()`
- `tests/pages/SettingsPage.ts` — methods: `openLicensesTab()`, `clickAssignUsers()`
### Auth Helpers
- `tests/helpers/login.ts` — `loginAs(page, role)` fills credentials and submits
### Notes
[None detected] OR [any caveats about partial coverage]
If nothing is found in any subcategory, omit that subsection and write instead:
### Notes — No reusable infrastructure detected
Global Output (Never Workspace-Scoped)
The output file docs/playwright-spec-testing/project-context.md is ALWAYS at the global root level, never inside a workspace directory. This file is shared across all sessions in the project. If running as part of a workspace session (from run-testing-session), the workspace will generate its own workspace-context.md from this global context, but analyze-codebase only writes the global file.
Key Rules
- Never invent information. If not found, write "not found" or "not detected."
- Do not run the app or open a browser.
- If Playwright is not installed, report BLOCKED.
Output
docs/playwright-spec-testing/project-context.md (includes ## Reusable Test Infrastructure section)
Report when done:
- Status: DONE | DONE_WITH_CONCERNS | BLOCKED | NEEDS_CONTEXT
- Summary of what was found
- Path to output file
- Any concerns or missing information
More from lautaroleonhardt/pst
plan-tests
Use after explore-app to synthesize an exhaustive, human-reviewable test plan from exploration reports and project context. Reads all exploration/<slug>.md files, parsed-spec.md, and project-context.md. Outputs test-plan.md with full steps, assertions, and assigned test file paths.
9ingest-spec
Use when you have a Gherkin .feature file or plain-English test cases to parse into structured scenarios. Writes output to docs/playwright-spec-testing/parsed-spec.md.
9generate-tests
Use after plan-tests to write a Playwright test for one scenario by mechanically translating test-plan.md into Playwright API calls. Requires docs/playwright-spec-testing/test-plan.md. Writes the test file at the path assigned in the plan.
9debug-test
Use when a Playwright test is failing. Diagnoses the root cause and applies a minimal fix. Requires the failing test file path and the full error output.
9explore-app
Use after ingest-spec to walk through one scenario in the live app and capture real selectors and URLs. Requires a running app and a scenario from docs/playwright-spec-testing/parsed-spec.md. Writes output to docs/playwright-spec-testing/exploration/<scenario-slug>.md.
9run-testing-session
Use to run the full Playwright testing pipeline (analyze → ingest → plan → explore → generate → debug) with isolated subagent context per stage. Each stage is reviewed and fixed automatically. Requires a running target app and a spec input.
9