Commit f1a4ac0
authored
Audit cleanup: concurrency, error handling, DRY pass (#407)
* Audit cleanup: concurrency, error handling, DRY pass
Cross-package code-review pass addressing high- and medium-severity
findings across the SDK, CLI, MCP server, VS extension, and mrt-utilities.
Concurrency / correctness:
- SDK: atomic write for the stateful auth-session file (temp + rename).
- SDK: single-flight refresh in OAuthStrategy.getAccessToken so concurrent
callers coalesce instead of stampeding the AM token endpoint.
- SDK: clean up debug-session keepalive/poll timers when connect()
fails after starting them.
- SDK: try/finally around progress timers in code download/deploy so
aborted requests can no longer leak intervals.
- CLI: long-running commands (code:watch, logs:tail, mrt:tail-logs)
deregister their SIGINT/SIGTERM handlers when finished.
- VS ext: guard webview postMessage against panel disposal in the
Swagger API Browser; drain pending uploads before tearing down code-
sync watchers; prevent sandbox-tree polling stop-checks from stacking
when the polling interval is shorter than the stabilization window.
- mrt-utilities: pipeToDestination now destroys the destination on
pipeline error so consumers fail fast instead of hanging.
- MCP: registerToolsets() throws clearly if invoked twice for the
same server; telemetry send failures are logged at debug.
Error handling:
- Replaced silent catch {} blocks in stateful-store unlinkSync,
job:run afterOperation hooks, logs:tail signal handler, and MCP
telemetry with debug-level logging.
- CIP commands now stream output through ux.stdout instead of
process.stdout, restoring --json and test capture; CIP tests use
runSilent.
DRY / dead code:
- New @salesforce/b2c-tooling-sdk/ux export hosts the canonical
confirm() prompt; CLI's prompts.ts is now a thin re-export.
- New auth/jwt-utils consolidates JWT exp/scope decoding previously
duplicated across three auth strategies.
- AM list commands share an amPageSizeFlag definition.
- formatApiError SLAS/SCAPI variants now alias the SDK's
getApiErrorMessage; ECDN gets a single requireScapiCoordinates
helper.
- Removed deprecated LocalSourceResult re-export.
Lint, typecheck, and the full test suite (4,075 tests) pass.
* Test-quality cleanup: tighten assertions, add expectError helper
Companion to the audit cleanup. Addresses every High and the highest-
leverage Medium items from TEST_AUDIT_PLAN.md so the test suite catches
real regressions instead of just confirming functions ran.
CLI:
- expectError(fn, match?) helper added to test/helpers/test-setup.ts;
replaces the verbose try { await x; expect.fail(...) } catch {}
pattern that could swallow the wrong error type.
- code/deploy: tighten .calledOnce checks to verify args (instance,
cartridges, code version) and afterOperation hook payload.
- code/activate: assert PATCH path/body and reload toggle order
(active → alternate → active) instead of just call counts.
- auth/token: assert returned JSON shape and that ux.stdout was called
with exactly the access token, not just .calledOnce.
- mrt/env/var/push: positively assert that listEnvVars ran when
asserting setBatchStub was *not* called.
- cip/query: drop echo tautologies (result.sql === input); assert that
the resolved SQL was passed to mockClient.query.
- Promote sinon.stub(odsClient) and makeCommandThrowOnError out of 12
duplicated copies in sandbox tests into the canonical helpers.
- Switch .to.equal(true|false) → .to.be.true|false where present.
SDK:
- logger.test.ts: drop 18 redundant `expect(logger).to.exist` lines
(the followup `.to.be.a('function')` was the real check).
MCP:
- registry: new smoke test invokes a registered handler
(sfnext_get_guidelines) end-to-end; previously only tool names were
asserted.
- theming-store: 25 weak `expect(guidance).to.exist` calls upgraded to
`expect(guidance, '...').to.not.be.undefined` so failures point at
the missing key.
- figma generate-component: replace 7 `array.some(d => …).to.equal(true)`
chains with `array.find(...)` + concrete property assertions so
failures show what actually went wrong.
mrt-utilities:
- create-lambda-adapter-compression.test.ts: replace 39 fixed
`setTimeout(50ms)` waits with the existing event-driven
`stream.waitForEnd()`. Suite runtime drops from ~3s to ~1s.
All 4,076 tests pass (+1 from the new MCP smoke test). Lint and
typecheck clean.1 parent b947888 commit f1a4ac0
76 files changed
Lines changed: 844 additions & 652 deletions
File tree
- .changeset
- packages
- b2c-cli
- src
- commands
- am
- clients
- roles
- users
- cip
- code
- job
- logs
- mrt
- setup/ide
- lib/scaffold
- utils
- am
- cip
- ecdn
- scapi
- slas
- test
- commands
- auth
- cip
- report
- code
- mrt/env/var
- sandbox
- helpers
- b2c-dx-mcp
- src
- test
- tools/storefrontnext
- figma/generate-component
- site-theming
- b2c-tooling-sdk
- src
- auth
- clients
- operations
- code
- debug
- ux
- test/logging
- b2c-vs-extension/src
- api-browser
- code-sync
- sandbox-tree
- mrt-utilities
- src/streaming
- test/streaming
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
| 79 | + | |
82 | 80 | | |
83 | 81 | | |
84 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
64 | 65 | | |
65 | 66 | | |
66 | 67 | | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
| 68 | + | |
71 | 69 | | |
72 | 70 | | |
73 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
| 93 | + | |
96 | 94 | | |
97 | 95 | | |
98 | 96 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
0 commit comments