Audit cleanup: dw.json atomicity, output discipline, timer leaks, ANSI palette#411
Draft
clavery wants to merge 1 commit into
Draft
Audit cleanup: dw.json atomicity, output discipline, timer leaks, ANSI palette#411clavery wants to merge 1 commit into
clavery wants to merge 1 commit into
Conversation
…I palette
Outcomes from a multi-package code review (CLI, SDK, MCP, mrt-utilities,
vs-extension). Fixes correctness and consistency issues; no new features.
Concurrency / data integrity (SDK)
- dw.json mutations (addInstance/removeInstance/setActiveInstance) now
serialize through a per-path async lock, and saveDwJson writes via
tmp-file + atomic rename with orphan cleanup.
- stateful-store.setStoredSession drops an exists-then-mkdir TOCTOU and
cleans up orphan tmp on rename failure.
Resource cleanup (SDK)
- code deploy/download progress intervals run inside a withProgress helper
that always tears down on exception.
- jobs/run.ts JobAlreadyRunning detection no longer silently swallows a
text() failure; an unreadable body falls through to the normal error
path with a debug log.
- code/download.ts replaces non-null assertions on Map.get() with explicit
guards.
Output discipline (CLI)
- 9 sandbox commands now route output through this.log; bare console.* in
src/commands/** is now banned by ESLint (the Prophet IDE template script
is exempt because it serializes JS source for an external runtime).
Shared CLI palette (SDK + CLI)
- New @salesforce/b2c-tooling-sdk/cli ANSI palette (LEVEL_COLORS,
colorLevel, colorDim, colorHighlight); utils/logs/format.ts and
utils/mrt-logs/format.ts now consume it instead of redefining.
Public-API hygiene (CLI)
- Dropped formatApiError re-export aliases in slas/client and
scapi/schemas; 7 call sites now import getApiErrorMessage from the SDK
directly. Removed redundant alias-passthrough test.
Other
- mrt-utilities configure-proxying onError guards res.headersSent before
writeHead to avoid masking the original error.
- vs-extension renderTemplate fixes a latent ordering bug where
${pageName}Data placeholders were left orphaned after the broader
${pageName} replacement ran.
- Trimmed a duplicated docstring in mrt-utilities ssr-proxying and
re-tagged the diff-with-instance comment in vs-extension as an
intentional stub rather than a stale TODO.
Verification
- pnpm run lint:agent: clean across all packages
- pnpm run typecheck:agent: clean
- pnpm run test:agent: SDK 1722 / CLI 1215 / MCP 720 / MRT 516 passing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Outcomes from a multi-package code review across
b2c-cli,b2c-tooling-sdk,b2c-dx-mcp,mrt-utilities, andb2c-vs-extension. Fixes correctness and consistency issues; no new features. Calibrated against source — items where the audit was overly cautious were intentionally left alone; the change set is the diff that's actually load-bearing.Driven by a four-wave plan (HIGH risk first → focused refactors → MEDIUM cleanup → LOW polish).
What changed
Concurrency / data integrity (SDK)
dw.jsonmutations (addInstance,removeInstance,setActiveInstance) now serialize through a per-path async lock.saveDwJsonwrites via tmp-file + atomic rename with orphan cleanup.stateful-store.setStoredSessionremoves an exists-then-mkdir TOCTOU; orphan tmp file is cleaned up if rename fails.Resource cleanup (SDK)
codedeploy/download progress intervals run inside awithProgresshelper that always tears down on exception.jobs/run.tsJobAlreadyRunningdetection no longer silently swallowstext()failure — falls through to normal error path with a debug log.code/download.tsreplacesMap.get(name)!non-null assertions with explicit guards.Output discipline (CLI)
this.logso--jsonmode and test stdout silencing work as documented.no-consoleESLint rule scoped tosrc/commands/**to prevent regression. Prophet IDE template exempt (it serializes JS source for an external runtime).Shared CLI palette (SDK + CLI)
@salesforce/b2c-tooling-sdk/cliANSI palette (LEVEL_COLORS,colorLevel,colorDim,colorHighlight).utils/logs/format.tsandutils/mrt-logs/format.tsconsume the shared palette instead of re-declaring it.Public-API hygiene (CLI)
formatApiErrorre-export aliases inutils/slas/client.tsandutils/scapi/schemas.ts; 7 call sites now importgetApiErrorMessagefrom the SDK directly.Other
mrt-utilitiesproxyonErrorguardsres.headersSentbeforewriteHeadso it doesn't mask the original error when upstream begins streaming before erroring.vs-extensionrenderTemplateordering bug:${pageName}Datawas being orphaned because the broader${pageName}replacement ran first and stripped the placeholder boundary.mrt-utilities/ssr-proxying.tsand re-tagged the diff-with-instance comment invs-extensionas an intentional stub rather than a stale TODO.What was deliberately not changed
The audit also flagged a number of issues that, on inspection of the source, were either false positives or contractually-correct behavior. Notable calibrations:
PENDING_TOKEN_REQUESTSsingleflight is already in place; residual check-then-delete ingetCachedOAuthTokenis single-thread safe.registry.tsduplicate-tool registration —registeredToolNamesSet already dedupes both toolset and--toolspaths.waitForHalt"lost wakeup" — waiter is pushed synchronously inside the Promise executor; no interleaving possible.mrt tail-logsheartbeat orphaning —open/error/closelisteners are attached synchronously;closealways clears the heartbeat.pollUntilextraction — deferred.waitForJobandwaitForSandboxhave distinct error types and stage-specific logging; net DRY gain is small relative to regression risk on well-tested polling paths.Changeset
Included:
.changeset/wave-review-cleanup.md— patch bumps for@salesforce/b2c-tooling-sdk,@salesforce/b2c-cli,@salesforce/mrt-utilities, andb2c-vs-extension.Test plan
pnpm run lint:agent— clean across all packagespnpm run typecheck:agent— cleanpnpm run test:agent— SDK 1722 / CLI 1215 / MCP 720 / MRT 516 passingb2c sandbox ips,b2c sandbox usage <id>,b2c sandbox settings <id>— verify human output and--jsonmodes both workb2c setup authand a subsequent stateful-auth command — confirm session file round-tripsb2c setup authinvocations against the samedw.json— confirm no entries are lost (the dw.json serializer is in-process; multi-process remains best-effort but writes themselves are atomic via rename)b2c code deployagainst a sandbox — confirm progress messages still appear at the expected cadence