Skip to content

test: extract shared fixtures for clearer test code#168

Merged
benvinegar merged 1 commit intomainfrom
test/extract-shared-test-helpers
Apr 6, 2026
Merged

test: extract shared fixtures for clearer test code#168
benvinegar merged 1 commit intomainfrom
test/extract-shared-test-helpers

Conversation

@benvinegar
Copy link
Copy Markdown
Member

Summary

  • extract repeated test setup into shared helpers under test/helpers/
  • rename shared helpers so test-only fixture code is explicit (createTest*)
  • update AGENTS.md to document the test-helper naming rule

Testing

  • bun run typecheck
  • bun test

Extract repeated test setup into shared helpers and name those helpers with explicit Test prefixes so fixture code is clearly distinct from app code.
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 6, 2026

Greptile Summary

This PR extracts repeated test setup code into three shared helper modules under test/helpers/app-bootstrap.ts, diff-helpers.ts, and mcp-fixtures.ts — and renames all shared helpers to follow the createTest* naming convention required by both CLAUDE.md and AGENTS.md. AGENTS.md is also updated to document the naming rule explicitly.

Key changes:

  • New test/helpers/app-bootstrap.ts: Exports createTestGitAppBootstrap, replacing per-file duplicates of AppBootstrap fixture construction across all AppHost test files.
  • New test/helpers/diff-helpers.ts: Exports createTestDiffFile, createTestHeaderOnlyDiffFile, createTestAgentFileContext, and lines, replacing locally defined variants across core and UI test files.
  • New test/helpers/mcp-fixtures.ts: Exports a full suite of createTestSession* factories covering the MCP session type hierarchy, removing boilerplate from daemonState, client, server, and commands tests.
  • 13 test files updated to consume shared helpers. Two files (commands.test.ts and AppHost.interactions.test.tsx) use buildTest* aliasing where a local positional-argument wrapper shadows the shared import — a functional but slightly non-obvious pattern worth being aware of.
  • No test logic was changed — this is a pure extraction refactoring.

Confidence Score: 5/5

Safe to merge — pure test infrastructure refactoring with no changes to production code or test logic.

All 16 changed files are test infrastructure only. The three new helper modules cleanly consolidate duplicated fixture code and follow the established createTest* naming convention documented in CLAUDE.md and now AGENTS.md. No production behavior is affected, no test assertions were changed, and no logic was altered — only import paths and fixture extraction. No P0 or P1 issues found.

No files require special attention. The buildTest* aliasing pattern in src/session/commands.test.ts, src/ui/AppHost.interactions.test.tsx, and src/ui/components/ui-components.test.tsx is intentional and functional.

Important Files Changed

Filename Overview
AGENTS.md Testing section updated to document the createTest* naming rule and test/helpers/ placement convention
test/helpers/app-bootstrap.ts New shared helper exporting createTestGitAppBootstrap for AppBootstrap test fixtures with configurable defaults
test/helpers/diff-helpers.ts New shared helpers: createTestDiffFile, createTestHeaderOnlyDiffFile, createTestAgentFileContext, and lines
test/helpers/mcp-fixtures.ts New shared helpers for MCP session fixtures: six createTestSession*/createTestSelectedSessionContext factories
src/core/liveComments.test.ts Updated to import createTestDiffFile and lines from test/helpers/diff-helpers; no logic change
src/core/loaders.ordering.test.ts Updated to import createTestDiffFile from test/helpers/diff-helpers; no logic change
src/mcp/client.test.ts Updated to import createTestSessionFileSummary, createTestSessionRegistration, createTestSessionSnapshot from shared helpers
src/mcp/daemonState.registration.test.ts Updated to import createTestSessionRegistration and createTestSessionSnapshot from shared helpers
src/mcp/daemonState.test.ts Updated to import all four MCP fixtures from shared helpers; thin local wrappers remain for test-specific overrides
src/mcp/server.test.ts Updated to use shared MCP fixtures directly in openRegisteredSession WebSocket payload
src/session/commands.test.ts Imports createTestListedSession as buildTestListedSession to avoid naming collision with local positional-arg wrapper
src/ui/AppHost.interactions.test.tsx Imports createTestDiffFile as buildTestDiffFile and createTestGitAppBootstrap from shared helpers
src/ui/AppHost.responsive.test.tsx Updated to use shared createTestDiffFile and createTestGitAppBootstrap directly
src/ui/AppHost.scroll-regression.test.tsx Updated to use shared createTestDiffFile and createTestGitAppBootstrap directly
src/ui/components/ui-components.test.tsx Imports createTestDiffFile as buildTestDiffFile to avoid collision with local positional-arg wrapper
src/ui/lib/diffSectionGeometry.test.ts Updated to import createTestDiffFile, createTestHeaderOnlyDiffFile, and lines from shared helpers

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["test/helpers/app-bootstrap.ts\ncreateTestGitAppBootstrap"] --> B["AppHost.interactions.test.tsx"]
    A --> C["AppHost.responsive.test.tsx"]
    A --> D["AppHost.scroll-regression.test.tsx"]
    A --> E["ui-components.test.tsx"]

    F["test/helpers/diff-helpers.ts\ncreateTestDiffFile\ncreateTestHeaderOnlyDiffFile\nlines"] --> B
    F --> C
    F --> D
    F --> E
    F --> G["liveComments.test.ts"]
    F --> H["loaders.ordering.test.ts"]
    F --> I["diffSectionGeometry.test.ts"]

    J["test/helpers/mcp-fixtures.ts\ncreateTestSession*\ncreateTestSelectedSessionContext"] --> K["client.test.ts"]
    J --> L["daemonState.test.ts"]
    J --> M["daemonState.registration.test.ts"]
    J --> N["server.test.ts"]
    J --> O["commands.test.ts"]
Loading

Reviews (1): Last reviewed commit: "test: make shared fixtures easier to spo..." | Re-trigger Greptile

@benvinegar benvinegar merged commit 383c348 into main Apr 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant