Skip to content

perf(tests): mock the tool registry globally, drop the dead deps optimizer - #6117

Merged
waleedlatif1 merged 2 commits into
stagingfrom
perf/vitest-deps-optimizer
Jul 31, 2026
Merged

perf(tests): mock the tool registry globally, drop the dead deps optimizer#6117
waleedlatif1 merged 2 commits into
stagingfrom
perf/vitest-deps-optimizer

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

The test suite spent far more time importing modules than running them — import was 1,399s aggregate against 88s of actual tests. This cuts the full suite 45%, with zero coverage lost.

Lint and Test is currently the CI critical path (p50 189s vs Build App's 150s), and ~143s of it is the test run.

Where the cost was — measured per area

lib/core touches no registry and sets the floor at 0.09s/file. Everything that reaches the tool registry graph:

area files import per-file × floor
blocks 25 177.9s 7.12s 79×
providers 53 193.2s 3.65s 41×
executor 64 196.2s 3.07s 34×
tools 78 159.9s 2.05s 23×
app/api 204 214.7s 1.05s 12×
lib/core 50 4.6s 0.09s

The tool registry is 4,351 entries pulling ~5,907 modules, and almost nothing under test needs the real thing. @/blocks/registry was already globally mocked for exactly this reason — this extends the same pattern to @/tools/registry.

Result — full suite, same commit, same machine

baseline after
Duration 166.21s 91.56s −45%
import 1399.17s 617.08s −56%
transform 141.80s 61.98s −56%
setup 259.00s 203.61s −21%
Test Files 1 failed / 1252 passed 1 failed / 1252 passed identical
Tests 1 failed / 16873 passed 1 failed / 16873 passed identical

The single failure reproduces on unmodified stagingcloud-review-tools.test.ts can't find rg from its spawned python3 on macOS. CI installs ripgrep explicitly and it passes there.

No coverage was removed

Four files genuinely assert tool registration or tool params. They opt out with vi.unmock('@/tools/registry') rather than being weakened or deleted — outlook, azure_devops, and the two search-replace suites. Each carries a comment explaining why, so the pattern is discoverable for the next person who needs the real registry.

These are exactly the tests that catch blocks and tools drifting apart, which is the kind of breakage that ships silently. Deleting them to make the number work would have been trading correctness for speed.

deps.optimizer was dead config — measured, not assumed

It was set to web, which only applies to client environments (jsdom/happy-dom), while 985 of 1,219 files declare @vitest-environment node. Vitest's docs are explicit that node/edge use ssr.

I measured both ways rather than just "fixing" it to ssr:

config Duration import
baseline (web) 19.33s 135.30s
removed 19.23s 136.37s
switched to ssr + include list for openai / Anthropic / Google / Bedrock SDKs 19.19s 136.69s

All identical within noise. The cost is first-party module graph, which the optimizer doesn't touch — it only bundles node_modules. So the honest move is deleting it, not leaving config that reads as if it does something.

Also fixes a latent mock gap

Adds the missing getBlockRegistry accessor to the @/blocks/registry mock. #6083 renamed that export and the mock was never updated, so any test reaching those three consumers would have hit getBlockRegistry is not a function. Nothing exercises them today — this closes it before someone trips on it.

Rejected, with evidence

isolate: false is ~20% faster (import 136.6s → 110.4s on a 145-file set) but leaks state between files — it broke two doc-servable tests on the first run that pass under isolation. Correctness over speed.

Type of Change

  • Performance
  • Improvement (dead config removal, mock fidelity)

Testing

Full suite run both ways on the same machine (table above). tsc --noEmit exit 0. biome check clean. Each of the four opt-out files verified individually: outlook 21/21, azure-devops 28/28, indexer 58/58, replacements 32/32.

…mizer

The test suite spent far more time importing modules than running them: on
the full suite, `import` was 1,399s aggregate against 88s of actual tests.
Per-file import cost showed exactly where it came from — lib/core, which
touches no registry, runs at 0.09s/file, while every area that reaches the
tool registry runs 12x-79x that (blocks 7.12s/file, providers 3.65, executor
3.07, tools 2.05, app/api 1.05).

The tool registry is 4,351 entries pulling ~5,907 modules, and almost nothing
under test needs the real thing. `@/blocks/registry` was already globally
mocked for this reason; this does the same for `@/tools/registry`.

Full suite, same commit, same machine:

  baseline  Duration 166.21s  (transform 141.80s, import 1399.17s)
  after     Duration  91.56s  (transform  61.98s, import  617.08s)

45% faster, import -56%, transform -56%. Identical results either way:
1252 files / 16873 tests pass, plus one failure that reproduces on unmodified
staging (cloud-review-tools.test.ts cannot find `rg` from its spawned python3
locally; CI installs ripgrep and it passes there).

Four test files genuinely assert tool registration or tool params, so they
opt out with `vi.unmock('@/tools/registry')` rather than being weakened or
deleted — outlook, azure_devops, and the two search-replace suites. No
coverage is lost.

Also removes `deps.optimizer.web`, which was dead config: it only applies to
client environments (jsdom/happy-dom) and 985 of 1,219 files declare
`@vitest-environment node`. Measured both ways to be sure — removing it is a
no-op (19.33s -> 19.23s), and switching it to the correct `ssr` side with an
include list for the heavy provider SDKs was also a no-op (19.19s). The cost
is first-party module graph, which the optimizer does not touch, so the
honest move is to delete it rather than leave config that reads as if it
does something.

Adds the missing `getBlockRegistry` accessor to the existing
`@/blocks/registry` mock. #6083 renamed that export and the mock was never
updated, so any test reaching those three consumers would have hit
"getBlockRegistry is not a function". Nothing exercises them today.

Not done, deliberately: `isolate: false` is ~20% faster but leaks state
between files and broke two doc-servable tests on the first run.
@vercel

vercel Bot commented Jul 31, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 31, 2026 2:55am

Request Review

@cursor

cursor Bot commented Jul 31, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Test-only changes: global mocks with explicit opt-outs for registry contract tests; no production runtime impact.

Overview
Speeds up the Vitest suite by mocking @/tools/registry globally in vitest.setup.ts (empty tools object), matching the existing @/blocks/registry pattern so most files no longer pull the full ~4,351-entry registry graph on import.

Four test files that assert real registration or tool params opt out with vi.unmock('@/tools/registry') and comments: outlook.test.ts, azure-devops.test.ts, and the two workflow search-replace suites (transitive dependency on real subblock/tool param resolution).

Vitest config: removes the deps.optimizer.web block from vitest.config.ts (measured as no benefit for this node-heavy suite).

Blocks registry mock: adds getBlockRegistry to the @/blocks/registry mock so consumers that call it do not hit “not a function” after a prior export rename.

Reviewed by Cursor Bugbot for commit 27af851. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR reduces Vitest startup overhead while preserving tests that require real registry data.

  • Globally mocks the tool registry and expands the block registry mock with the renamed accessor.
  • Explicitly restores the real tool registry in Outlook, Azure DevOps, and search-replace suites that depend on registration metadata.
  • Removes an ineffective dependency-optimizer configuration.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/vitest.setup.ts Adds the global lightweight tool-registry mock and brings the block-registry mock in sync with its current accessor API.
apps/sim/vitest.config.ts Removes dependency-optimizer configuration that did not benefit the predominantly Node-based test suite.
apps/sim/lib/workflows/search-replace/indexer.test.ts Restores the real tool registry because tool-input indexing resolves parameter configuration through the registry.
apps/sim/lib/workflows/search-replace/replacements.test.ts Restores the real tool registry for replacement scenarios that first index registry-backed tool-input parameters.
apps/sim/blocks/blocks/outlook.test.ts Restores the real registry for assertions covering Outlook tool registration and parameters.
apps/sim/tools/azure_devops/azure-devops.test.ts Restores the real registry for Azure DevOps registration and parameter assertions.

Reviews (2): Last reviewed commit: "docs(tests): explain why the search-repl..." | Re-trigger Greptile

Comment thread apps/sim/lib/workflows/search-replace/indexer.test.ts
…d-bearing

Review read the missing direct import of @/tools/registry as evidence the
vi.unmock calls were no-ops. They are not: the dependency is transitive —
the search-replace planner resolves tool input params through real subblock
configs — and removing both opt-outs fails 8 tests across the two suites.
Comment now says that, so the next reader does not delete them.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 27af851. Configure here.

@waleedlatif1
waleedlatif1 merged commit c553de1 into staging Jul 31, 2026
27 checks passed
@waleedlatif1
waleedlatif1 deleted the perf/vitest-deps-optimizer branch July 31, 2026 02:59
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