Commit 1f24b81
authored
perf(test): speed up CLI unit tests, silence stdout noise, fix flakey MCP tests (#260)
* perf(test): speed up CLI unit tests from ~8s to ~1.7s
Two key changes:
1. Fix sandbox reset test poll-interval (5s → 0s): The test used
poll-interval: 5 which caused a real 5-second sleep in waitForSandbox.
Other sandbox tests already use poll-interval: 0 to avoid this.
2. Replace runCommand with shared Config in cip/report and scapi/schemas
tests: runCommand from @oclif/test calls Config.load() on every
invocation (~1s cold, ~40ms warm). Instead, load Config once in a
before() hook and use config.runCommand() / Help.showHelp() directly.
Added getSharedFullConfig() helper to test-setup.ts for reuse.
* perf(test): silence stdout noise from AM command tests
stubCommandConfigAndLogger now automatically stubs command.log,
command.logToStderr, and ux.stdout so non-JSON command output
(tables, formatted details) doesn't leak to the console during tests.
* perf(test): speed up SDK unit tests from ~8.5s to ~2.7s
Several changes to eliminate unnecessary real delays in tests:
1. Telemetry tests: Use fake timers to skip the 300ms real sleep in
telemetry.stop(). Added stopTelemetryFast() helper that installs
sinon fake timers, advances clock, then restores. (9 calls × 300ms)
2. Logs integration tests: Reduce pollInterval (1000→100ms) and delays
(1500→200ms, 10000→5000ms timeout) since the test just verifies
stop/discover behavior, not sustained polling.
3. MRT env tests: Use fake timers with shouldAdvanceTime for timeout
and polling tests. Reduce pollInterval from 100→10ms.
4. Logs tail tests: Reduce pollInterval (100→10ms) and stop/wait
delays (200→50ms) since these use MSW mocks, not real network.
5. Code watch tests: Reduce filesystem watcher ready delays from
200-300ms to 50ms.
6. Job command test: Stub mockInstance.webdav.get to reject immediately
instead of timing out on a real network request.
7. CLI integration tests: Replace runCommand (which calls Config.load
per invocation) with a shared Config instance loaded once in
before() hook.
* fix(test): fix type errors in base-command integration test
Cast extraParams to Record<string, unknown> before accessing .query/.body
to satisfy tsc -p test stricter type checking used in CI.
* fix(test): revert mrt/env fake timers to avoid OOM in CI
The sinon.useFakeTimers({shouldAdvanceTime: true}) with pollInterval: 10
caused rapid-fire MSW HTTP requests (50+ polls in a tickAsync burst),
accumulating memory that led to OOM on CI runners with limited heap.
Reverted to real timers with pollInterval: 100 and this.timeout(5000),
which is still faster than the original tests and doesn't risk OOM.
* fix(test): restore runCommand for cip/report and scapi/schemas tests
Revert the shared Config + config.runCommand() optimization for these
tests. The change to showHelp() and config.runCommand() skipped the
oclif init hook and full run() pipeline, which reduced function coverage
below the 70% threshold.
The runCommand approach calls Config.load() per invocation but oclif
caches internally, so subsequent calls are ~40ms. The sandbox reset
poll-interval fix (5s→0s) remains the primary speed win.
Retains: sandbox reset poll-interval fix, stdout silencing in
stubCommandConfigAndLogger.
* fix(test): fix flaky MCP signal handler tests that hang on CI
The signal handler tests called command.run() which is async and sets up
stdinClosePromise, then used setTimeout-based polling to wait for
handlers to register. This was non-deterministic:
- run() is synchronous after the stubbed connect() resolves, so handlers
are registered immediately — no polling needed
- stdinClosePromise was left dangling with only runPromise.catch(() => {})
as cleanup, which doesn't await the flush() promise chain
- On CI (slower timing), the polling races and unresolved promises caused
mocha to hang until the 60s timeout, then exit with code 1 or 2
Fixed by:
- Awaiting command.run() directly (handlers register synchronously)
- Triggering signal handlers immediately after run()
- Awaiting stdinClosePromise to ensure flush() completes
- Removing all setTimeout-based polling and manual cleanup
* perf: cache ts-morph Project in page-designer-decorator analyzer
Reuse a single ts-morph Project instance across analyzeComponent calls
instead of creating a new one each time. The Project uses an in-memory
file system and is stateless — source files are added with overwrite:true
and removed in a finally block after analysis.
This eliminates repeated TypeScript compiler initialization (~40ms local,
~700ms CI per call × 57 test invocations). MCP test suite drops from
~2s to ~440ms locally, expected ~52s to ~10-15s on CI.
* ci: move docs build to separate workflow triggered only on docs/ changes
The docs build (vitepress + typedoc) was running on every CI run
regardless of what changed. Move it to a dedicated workflow with a
paths filter on docs/ so it only runs when documentation files change.
This removes a blocking step from the main CI pipeline for the vast
majority of PRs that don't touch docs.1 parent 1a15687 commit 1f24b81
17 files changed
Lines changed: 313 additions & 247 deletions
File tree
- .claude/skills/testing
- .github/workflows
- packages
- b2c-cli/test
- commands/sandbox
- helpers
- b2c-dx-mcp
- src/tools/storefrontnext/page-designer-decorator
- test/commands
- b2c-tooling-sdk/test
- cli
- operations
- code
- logs
- mrt
- telemetry
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
324 | 324 | | |
325 | 325 | | |
326 | 326 | | |
327 | | - | |
| 327 | + | |
328 | 328 | | |
329 | | - | |
| 329 | + | |
330 | 330 | | |
331 | | - | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
332 | 350 | | |
333 | 351 | | |
334 | 352 | | |
| |||
344 | 362 | | |
345 | 363 | | |
346 | 364 | | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | 365 | | |
353 | 366 | | |
354 | | - | |
| 367 | + | |
355 | 368 | | |
356 | 369 | | |
357 | 370 | | |
358 | 371 | | |
359 | 372 | | |
360 | 373 | | |
| 374 | + | |
361 | 375 | | |
362 | 376 | | |
363 | 377 | | |
364 | 378 | | |
| 379 | + | |
| 380 | + | |
365 | 381 | | |
366 | 382 | | |
367 | 383 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | 63 | | |
67 | 64 | | |
68 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| 164 | + | |
| 165 | + | |
164 | 166 | | |
165 | 167 | | |
166 | 168 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
119 | 128 | | |
120 | 129 | | |
121 | 130 | | |
| |||
Lines changed: 51 additions & 33 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
12 | 29 | | |
13 | 30 | | |
14 | 31 | | |
| |||
352 | 369 | | |
353 | 370 | | |
354 | 371 | | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
359 | 389 | | |
360 | | - | |
361 | | - | |
362 | | - | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
363 | 403 | | |
364 | | - | |
365 | 404 | | |
366 | 405 | | |
367 | | - | |
| 406 | + | |
368 | 407 | | |
369 | | - | |
| 408 | + | |
370 | 409 | | |
371 | 410 | | |
372 | 411 | | |
| 412 | + | |
| 413 | + | |
373 | 414 | | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
382 | | - | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | 415 | | |
398 | 416 | | |
399 | 417 | | |
| |||
0 commit comments