Positron Vitest Test Authoring
Write tests for Positron source code, then have them independently reviewed.
Arguments
$ARGUMENTS may contain:
- A file path (e.g.,
src/vs/.../myComponent.tsx) -- write tests for this specific file --branch <branch-name>to analyze all changes on a branch- A PR number (e.g.,
#12242or12242) to analyze a pull request - A PR URL (e.g.,
https://github.com/posit-dev/positron/pull/12242)
Phase 1: Branch/PR Analysis
Skip this phase if the argument is a specific source file path -- go directly to Phase 2 Prepare.
Run this phase when the argument is a branch name, PR number, or PR URL, or the user asks "what tests should I write?" without naming a file. Spawn an analysis subagent to produce a structured test plan -- this keeps the analysis work out of the main agent's context.
Agent({
description: "Analyze PR for test recommendations",
prompt: "<analysis prompt below, with arguments filled in>"
})
Analysis subagent prompt
Analyze the changes from <PR number, branch, or "current branch"> and produce a test plan for the Positron IDE.
Step 1: Get the diff.
<if PR number>: gh pr diff <number> --name-only and gh pr diff <number> for full content.
<if branch>: git fetch origin <branch> && git diff main...origin/<branch> --name-only --diff-filter=ACMR
<if current>: git diff main...HEAD --name-only --diff-filter=ACMR
Step 2: Verify code exists on the current branch.
For each new symbol (method, class, interface member) in the diff:
grep -rq "<symbol>" <file>to confirm it exists in the working treegit log --oneline --grep="revert" -- <file>to check for post-merge reverts- Skip any file where changes no longer exist
Step 3: Read the testing guide.
Read the Testing section of CLAUDE.md (the "Where should I put my test?" decision table), .claude/rules/vitest-tests.md for core patterns, and the JSDoc on PositronTestContainerBuilder in src/vs/test/vitest/positronTestContainer.ts for presets. For React component work, also read .claude/rules/vitest-rtl.md.
Step 4: Classify each file.
Skip: test files, type-only files, configs, docs, action-only files, files with reverted changes.
For each Positron source file in src/vs/:
- Determine the test pattern using the CLAUDE.md decision table:
- Pure function/class, no services -> Plain test
- Service/class needing DI -> Builder (
createTestContainer()) - React component (
.tsx) with props only -> RTL prop-driven (setupRTLRenderer()) - React component using
usePositronReactServicesContext()-> RTL service-context (withReactServices()+setupRTLRenderer(() => ctx.reactServices))
- Check if a
.vitest.tsor.vitest.tsxalready exists - Determine the lowest builder preset that covers its dependencies
- Note any extra
.stub()calls needed beyond the preset - Check if the class is exported
- For upstream (Microsoft copyright) files, flag with warning
Step 5: Return the test plan as structured output.
Format your response as:
Tests to write:
For each: file path, pattern (plain/builder/RTL prop-driven/RTL service-context), preset + reasoning (why this is the lowest viable preset -- name the key dependencies that require it), extra stubs needed, what to test, whether class is exported
Tests to extend:
For each: existing test file path, current preset + why it's sufficient (or what changes are needed), what new cases are needed
Already covered: Brief list
Upstream warnings: Any modified upstream files
After analysis subagent returns
Present the test plan to the dev. Ask: "Want me to write/extend these tests?"
Wait for confirmation before proceeding to Phase 2.
Phase 2: Writing
Prepare
Gather the context you need before drafting the plan: