Skip to content
Source
Sign inSign up
pingdotgg/t3code

test: drop Effect.scoped wrappers that @effect/vitest already applies #35993

Mergedjuliusmarmingemerged 1 commit intomain fromrefs/pull/35993/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

@effect/vitest already scopes every test body. In the vendored source, it.effect is flow(Effect.scoped, Effect.provide(TestEnv)) and it.live is Effect.scoped (.repos/effect/packages/vitest/src/internal/internal.ts:490-491). it.layer(...)'s it.effect wraps the body in provide(Effect.scoped(effect)) too (line 353). So when a test body is wholly Effect.scoped(X), or X.pipe(..., Effect.scoped) with Effect.scoped as the last step, the wrapper does nothing.

This PR removes 1,247 of those wrappers across 171 test files, along with their extra indentation.

How

An AST codemod (oxc-parser + magic-string, no regex) ran over every tracked *.test.ts / *.test.tsx in apps/* and packages/*. .repos/ and node_modules were excluded. vp fmt then fixed the indentation. With whitespace ignored, the diff contains only removed wrappers and formatter reflow. Forms removed:

  • () => Effect.scoped(body), including block bodies that end in return Effect.scoped(...), for it.effect / it.live and .each / .skipIf / .runIf / .only, the effectIt alias, and it.layer blocks;
  • body.pipe(..., Effect.scoped) where Effect.scoped is the last step;
  • body.pipe(Effect.scoped, Effect.provideService(...)), because provideService holds no resources;
  • 11 helpers whose only job is to pass a body straight to the test: withStore, runNode, run (FirefoxCookies, Sources), withClientSettings, withSavedEnvironments, withTempDir, withEnvironmentThemes, stopEarlierBackgroundWork, runCleanupTest, withTerminals. Each of these is used only as a whole test body. Removing Effect.scoped after an Effect.provide(layer) inside them is safe because Effect.provide builds the layer in its own scopedWith scope (internal/layer.ts:15).

Kept on purpose

  • About 620 body.pipe(Effect.scoped, Effect.provide(layer)) and Effect.scoped(body).pipe(Effect.provide(layer)) forms. In these the body's scoped resources close before the provided layer's resources. Removing the wrapper would reverse that order, so they stay. Many are probably harmless, but checking each one by hand was out of scope.
  • Effect.scoped around part of a test. These close resources partway through, often so the test can assert that teardown ran.
  • Helpers also used partway through a test: withManager (Manager.test.ts), withSettings (DesktopAppSettings.test.ts) and withHarness (DesktopServerExposure.test.ts), each used inside a test body at least once.
  • Effect.scoped in non-test code, hooks, and layer construction.

No lint rule was added.

Verification

  • vp run check:changed: format, lint, knip, typecheck (36 packages) and vp test over the 172 changed test files all pass (4,070 passed, 6 skipped). Server tests ran inside unshare -U --map-current-user -p -f --mount-proc with TMPDIR under $HOME.
  • After rebasing onto #35868, the 4 conflicting files were reset to main's version and the codemod was re-run on them, which picked up one new wrapper in pullRequests.test.ts. Re-ran 13 server files: ServerBrowserStream, ClaudeTaskOutputTail, UsageService, storageCleanup, environmentTheme, VcsStatusBroadcaster, ProviderInstanceRegistry, BackgroundWorkStop and five it.layer-based CLI files (409 passed). Also re-ran DrainableWorker, KeyedCoalescingWorker and pullRequests (75 passed), plus vp run typecheck (41/41).

Done by Claude Opus 5.5 in Claude Code.

🤖 Generated with Claude Code

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. Approvability

      Verdict: Approved at ec3257f

      Macroscope's review found this PR approvable — The changes are confined to paths excluded by the repository’s review configuration, so their contents were not reconstructed. Within that prescribed scope, no concrete material risk requiring human judgment is established.

      Notes:

      • No code objects were reviewed. Approvability was decided on eligibility alone.
      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. Thread transfer impact

      ✅ Thread transfer remains within every enforced ceiling.

      ProviderMetricMain baselineThis PRImpactPR ceiling
      CodexTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      CodexThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      CodexLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      CodexLive turn WebSocket decoded21.5 KiB21.5 KiB0 B (0.0%)24.4 KiB✅
      CodexLive turn messages110 (0.0%)8✅
      ClaudeTotal thread wire5.0 KiB5.0 KiB0 B (0.0%)6.8 KiB✅
      ClaudeThread snapshot wire3.8 KiB3.8 KiB0 B (0.0%)4.9 KiB✅
      ClaudeLive turn WebSocket wire1.2 KiB1.2 KiB0 B (0.0%)2.0 KiB✅
      ClaudeLive turn WebSocket decoded21.9 KiB21.9 KiB0 B (0.0%)24.4 KiB✅
      ClaudeLive turn messages110 (0.0%)8✅

      Other scenarios

      All 64 scenario measurements match main.

      All 64 scenario measurements
      ProviderScenarioMetricMain baselineThis PRImpactPR ceiling
      Codexshort turn resumeWebSocket decoded10.5 KiB10.5 KiB0 B (0.0%)12.7 KiB✅
      Codexshort turn resumeWebSocket messages220 (0.0%)2✅
      Codexlong turn running, cold openHTTP decoded281.7 KiB281.7 KiB0 B (0.0%)302.7 KiB✅
      Codexlong turn running, cold openrows75750 (0.0%)75✅
      Codexlong turn running, history pageHTTP decoded92.4 KiB92.4 KiB0 B (0.0%)107.4 KiB✅
      Codexlong turn running, history pagerows75750 (0.0%)75✅
      Codexlong turn finished, cold openHTTP decoded381.5 KiB381.5 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, socket cold openWebSocket decoded381.6 KiB381.6 KiB0 B (0.0%)410.2 KiB✅
      Codexlong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Codexlong turn finished, socket cold openrows1511510 (0.0%)151✅
      Codexlong turn finished, work pageHTTP decoded186.2 KiB186.2 KiB0 B (0.0%)200.2 KiB✅
      Codexlong turn finished, work pagerows1501500 (0.0%)150✅
      Codexidle thread resumeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexidle thread resumeWebSocket messages110 (0.0%)1✅
      Codexfleet shell snapshotHTTP decoded42.4 KiB42.4 KiB0 B (0.0%)53.7 KiB✅
      Codexfleet shell snapshotrows27270 (0.0%)27✅
      Codexfleet shell subscribeWebSocket decoded65 B65 B0 B (0.0%)200 B✅
      Codexfleet shell subscribeWebSocket messages110 (0.0%)1✅
      Codexfleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Codexfleet shell resume checkrows0000✅
      Codexstale shell reloadHTTP decoded42.4 KiB42.4 KiB0 B (0.0%)53.7 KiB✅
      Codexstale shell reloadrows27270 (0.0%)27✅
      Codexstale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Codexstale shell resumeWebSocket messages220 (0.0%)2✅
      Codexstale todo list cold openHTTP decoded72.4 KiB72.4 KiB0 B (0.0%)83.0 KiB✅
      Codexstale todo list cold openrows75750 (0.0%)75✅
      Codexstale todo list cold opennodes220 (0.0%)4✅
      Codexstale todo list cold opensubagents220 (0.0%)4✅
      Codexstale todo list cold openplans110 (0.0%)2✅
      Codexstale todo list cold openproviderTurns110 (0.0%)2✅
      Codexstale todo list cold opencheckpoints110 (0.0%)2✅
      Claudeshort turn resumeWebSocket decoded10.6 KiB10.6 KiB0 B (0.0%)12.7 KiB✅
      Claudeshort turn resumeWebSocket messages220 (0.0%)2✅
      Claudelong turn running, cold openHTTP decoded283.3 KiB283.3 KiB0 B (0.0%)302.7 KiB✅
      Claudelong turn running, cold openrows75750 (0.0%)75✅
      Claudelong turn running, history pageHTTP decoded93.4 KiB93.4 KiB0 B (0.0%)107.4 KiB✅
      Claudelong turn running, history pagerows75750 (0.0%)75✅
      Claudelong turn finished, cold openHTTP decoded384.2 KiB384.2 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, socket cold openWebSocket decoded384.3 KiB384.3 KiB0 B (0.0%)410.2 KiB✅
      Claudelong turn finished, socket cold openWebSocket messages220 (0.0%)2✅
      Claudelong turn finished, socket cold openrows1511510 (0.0%)151✅
      Claudelong turn finished, work pageHTTP decoded188.1 KiB188.1 KiB0 B (0.0%)200.2 KiB✅
      Claudelong turn finished, work pagerows1501500 (0.0%)150✅
      Claudeidle thread resumeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudeidle thread resumeWebSocket messages110 (0.0%)1✅
      Claudefleet shell snapshotHTTP decoded43.0 KiB43.0 KiB0 B (0.0%)53.7 KiB✅
      Claudefleet shell snapshotrows27270 (0.0%)27✅
      Claudefleet shell subscribeWebSocket decoded66 B66 B0 B (0.0%)200 B✅
      Claudefleet shell subscribeWebSocket messages110 (0.0%)1✅
      Claudefleet shell resume checkHTTP decoded18 B18 B0 B (0.0%)100 B✅
      Claudefleet shell resume checkrows0000✅
      Claudestale shell reloadHTTP decoded43.0 KiB43.0 KiB0 B (0.0%)53.7 KiB✅
      Claudestale shell reloadrows27270 (0.0%)27✅
      Claudestale shell resumeWebSocket decoded140 B140 B0 B (0.0%)400 B✅
      Claudestale shell resumeWebSocket messages220 (0.0%)2✅
      Claudestale todo list cold openHTTP decoded73.4 KiB73.4 KiB0 B (0.0%)83.0 KiB✅
      Claudestale todo list cold openrows75750 (0.0%)75✅
      Claudestale todo list cold opennodes220 (0.0%)4✅
      Claudestale todo list cold opensubagents220 (0.0%)4✅
      Claudestale todo list cold openplans110 (0.0%)2✅
      Claudestale todo list cold openproviderTurns110 (0.0%)2✅
      Claudestale todo list cold opencheckpoints110 (0.0%)2✅

      Baseline: 43ce395 · PR result: ec3257f · Source CI: success

      Scenario and decoded snapshot size

      10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

      • Codex decoded thread snapshot: 108.5 KiB
      • Claude decoded thread snapshot: 108.8 KiB

      Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

    4. juliusmarminge merged thisee64555

    5. juliusmarminge closed this

Sign in to join this conversation.