Skip to content

OUT-3986: MSW harness + error-shape reproduction#120

Open
SandipBajracharya wants to merge 5 commits into
OUT-3985from
OUT-3986
Open

OUT-3986: MSW harness + error-shape reproduction#120
SandipBajracharya wants to merge 5 commits into
OUT-3985from
OUT-3986

Conversation

@SandipBajracharya

Copy link
Copy Markdown
Collaborator

OUT-3986 — L0.2: MSW harness + error-shape reproduction

Fakes Dropbox (rpc + content) and Copilot (api.copilot.app) at the HTTP boundary with MSW, so integration tests drive the real SDK clients — and their real error-construction paths — without touching the network.

Stacked on OUT-3985 (Testcontainers harness). Base is OUT-3985, so this PR shows only the 3 OUT-3986 commits.

What's included

  • Server + lifecyclesetupServer with onUnhandledRequest: 'error', wired into the integration setup; per-test overrides reset between tests.
  • Base handlers — ambient Dropbox OAuth-refresh, empty list_folder/list_folder/continue, empty listFiles.
  • Override helpersmockDropboxRpc / mockDropboxContent / mockCopilot (correctly host/method-scoped).
  • Error-shape builders — return HTTP responses the real SDKs turn into the exact errors production branches on:
    • isCopilotApiError at 400 (body.message === 'Folder already exists') and 404
    • DropboxResponseError at 409 with error.error.path['.tag'] === 'not_found' and error_summary starting path_lookup/not_found
  • Pagination helpers — cursor (list_folder) and nextToken (listFiles).
  • Self-test (test/msw/msw-harness.integration.test.ts) — drives the real clients over both transports (node-fetch + undici) to prove every shape reproduces.

Supporting changes

  • DROPBOX_API_URL → content host (keeps the two Dropbox hosts distinct); COPILOT_ENV=local so the Copilot SDK trusts the placeholder apiKey; copilot-node-sdk inlined in Vitest to resolve its ESM directory import.
  • Import boundary — a scoped Biome noRestrictedImports rule forbids production src/ code from importing test files / the harness (test/**, **/__tests__/**, *.test.*). Test files are exempt.

Scope

Mechanism only — typed data factories/seeders (L0.3), clock control (L0.4), and CI wiring (L0.5) are separate issues.

Verification

  • Unit 124/124 · integration 18/18 · typecheck clean · lint clean.
  • Boundary rule verified: production→test import errors; test→harness allowed.

🤖 Generated with Claude Code

SandipBajracharya and others added 3 commits July 15, 2026 18:04
Mock Service Worker (2.x) fakes Dropbox + Copilot at the HTTP boundary
for the integration test suite. Dev-only; no production dependency.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…dary

Fake the Dropbox (rpc + content) and Copilot hosts with MSW so integration
tests drive the real SDK clients without network access:

- server + base handlers (ambient OAuth refresh, empty list_folder/listFiles)
- per-test override helpers (mockDropboxRpc / mockDropboxContent / mockCopilot)
- error-shape builders reproducing the errors production branches on
  (isCopilotApiError 400/404; DropboxResponseError 409 not_found) by returning
  HTTP responses the real SDKs turn into those errors
- cursor / nextToken pagination helpers
- a self-test driving the real clients to prove every shape reproduces

Wire the MSW lifecycle into the integration setup (onUnhandledRequest:
'error'), point DROPBOX_API_URL at the content host, set COPILOT_ENV=local so
the Copilot SDK trusts the placeholder apiKey, and inline copilot-node-sdk in
Vitest to resolve its ESM directory import.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add a scoped noRestrictedImports rule: files under src/ (excluding
co-located tests) may not import the test harness or test files
(test/**, **/__tests__/**, *.test.*). Keeps test-only code out of the
production bundle. Test files are exempt and keep full import freedom.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Jul 15, 2026

Copy link
Copy Markdown

OUT-3986

@vercel

vercel Bot commented Jul 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dropbox-integration Ready Ready Preview, Comment Jul 15, 2026 2:46pm

Request Review

@greptile-apps

greptile-apps Bot commented Jul 15, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds an MSW-based HTTP harness for Dropbox and Copilot integration tests. The main changes are:

  • MSW server lifecycle and base handlers for both SDKs.
  • Reusable error, override, and pagination helpers.
  • Integration coverage for SDK error shapes and paginated responses.
  • Test environment and Vitest resolution updates.
  • Production-to-test import boundary linting.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
test/msw/pagination.ts Adds Dropbox and Copilot pagination handlers with validation for page sizes.
test/integration/setup.ts Starts, resets, and closes the MSW server around integration tests.
biome.json Restricts production imports from test code while excluding source test files.
vitest.integration.config.ts Includes harness tests and resolves the Copilot SDK through Vite.

Reviews (2): Last reviewed commit: "fix(OUT-3986): treat *.spec files as tes..." | Re-trigger Greptile

Comment thread test/msw/pagination.ts
Comment thread test/msw/pagination.ts
Comment thread biome.json Outdated
A pageSize of 0 (or negative / non-integer) made slice return no entries,
so nextOffset never advanced while has_more stayed true — a consumer
following the cursor/nextToken would loop on the same page until timeout.
Both paginators now fail fast with a clear error, and a guard test covers it.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The unit config recognizes src/**/*.spec.ts as tests, but the
noRestrictedImports override only exempted *.test.ts/tsx — so a co-located
*.spec file importing a test/ helper was wrongly flagged as production.
Exempt *.spec.ts/tsx on the importer side and add *.spec.* to the banned
import targets, so .spec and .test are handled uniformly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@SandipBajracharya

Copy link
Copy Markdown
Collaborator Author

@greptileai review

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.

2 participants