Define the testing strategy for gh-attach to ensure all upload strategies, CLI commands, and MCP tools are thoroughly tested at unit, integration, and E2E levels. Quality and verifiability are top priorities.
The system SHALL maintain ≥90% line coverage across the core library.
- GIVEN the core library source files in
src/core/ - WHEN unit tests are run via
npm test - THEN line coverage SHALL be ≥90%
- AND branch coverage SHALL be ≥80%
- GIVEN any unit test
- THEN it SHALL NOT make real HTTP requests
- AND it SHALL NOT access the filesystem (except via mocked interfaces)
- AND it SHALL complete in <100ms
Each upload strategy SHALL have comprehensive unit tests.
- GIVEN the BrowserSessionStrategy class
- THEN tests SHALL cover:
- Successful 3-step upload flow (policy → S3 → confirm)
- CSRF token extraction from HTML
- Expired session handling
- Malformed HTML handling
- Network timeout handling
- GIVEN the ReleaseAssetStrategy class
- THEN tests SHALL cover:
- Creating a new draft release
- Reusing an existing release
- Filename collision handling
- Permission errors
- API rate limiting
- GIVEN the RepoBranchStrategy class
- THEN tests SHALL cover:
- Creating orphan branch
- Committing to existing branch
- URL generation using the GitHub raw URL format
- GIVEN the CookieExtractionStrategy class
- THEN tests SHALL cover:
- Chrome cookie reading (mocked)
- Firefox cookie reading (mocked)
- No browser available scenario
- Cross-platform path resolution
The system SHALL include integration tests using msw (Mock Service Worker) for HTTP interaction replay.
- GIVEN recorded HTTP interaction fixtures
- WHEN the integration test runs an upload through the core library
- THEN msw SHALL intercept all HTTP requests
- AND the test SHALL verify the complete request/response sequence
- AND the final URL SHALL be returned correctly
- GIVEN HTTP fixtures
- THEN they SHALL be stored in
test/fixtures/organized by strategy - AND each fixture SHALL document what it tests in a comment header
- GIVEN fixture files for error scenarios (401, 403, 422, 500)
- WHEN the integration test replays these
- THEN the appropriate error types SHALL be thrown with correct error codes
The system SHALL include CLI integration tests that test the full command pipeline.
- GIVEN the compiled CLI binary
- WHEN
gh-attach --helpis executed - THEN stdout SHALL contain the help text
- AND exit code SHALL be 0
- GIVEN a mocked upload strategy injected via dependency injection
- WHEN
gh-attach upload ./test.png --target owner/repo#1 --format jsonis executed - THEN stdout SHALL contain valid JSON with url, markdown, and strategy fields
- GIVEN a failing upload scenario
- WHEN the CLI runs
- THEN stderr SHALL contain a human-readable error message
- AND the exit code SHALL match the error type
The system SHALL include integration tests for the MCP server.
- GIVEN the MCP server running in-process
- WHEN a
tools/listrequest is sent - THEN the response SHALL include
upload_image,check_auth, andlist_strategiestools
- GIVEN the MCP server with a mocked upload strategy
- WHEN a
tools/callrequest forupload_imageis sent - THEN the response SHALL contain the upload result
The system SHALL include E2E tests that run against real GitHub infrastructure.
- GIVEN the
E2E_TESTSenvironment variable - WHEN it is not set or set to
false - THEN E2E tests SHALL be skipped with a clear message
- GIVEN
GITHUB_TOKENandE2E_TEST_REPOenvironment variables - WHEN the E2E test runs
- THEN it SHALL upload a small test image via the release-asset strategy
- AND verify the returned URL is accessible
- AND clean up the test asset afterward
- GIVEN the same environment variables
- WHEN the E2E test runs
- THEN it SHALL upload via the repo-branch strategy
- AND verify the raw URL returns the image
- AND clean up the test branch/commit
- GIVEN any E2E test
- THEN it SHALL use a dedicated test repository
- AND clean up all created resources (releases, branches, comments) after execution
- AND be safe to run in parallel
The system SHALL organize tests by type and module.
- GIVEN the project
- THEN test files SHALL be organized as:
test/unit/— unit tests (mirroringsrc/structure)test/integration/— integration tests with HTTP mockingtest/e2e/— end-to-end teststest/fixtures/— shared test fixtures and HTTP recordings
- GIVEN any test file
- THEN it SHALL be named
*.test.ts - AND describe blocks SHALL match the class/module under test
The system SHALL provide convenient npm scripts for running tests.
- GIVEN the
package.json - THEN it SHALL define:
test— run all unit + integration teststest:unit— run only unit teststest:integration— run only integration teststest:e2e— run E2E tests (requires env vars)test:coverage— run tests with coverage reporttest:watch— run tests in watch mode
The system SHALL use snapshot tests for CLI help text and output formatting.
- GIVEN the CLI help output
- WHEN the snapshot test runs
- THEN it SHALL compare against stored snapshots
- AND fail if the output has changed unexpectedly