Repository navigation
feat(AUTO-1062): ask sandbox for variable mutations only and rebuild scopes on the host - #1568
Conversation
Pass variableMutationsOnly to host.execute so the sandbox sends back only mutations for environment, globals and collectionVariables. The full post-script scopes for the script trigger are rebuilt from the context sent to the sandbox (the masked clone when forbidden secrets apply) with the mutations applied. An older sandbox ignores the option and sends the full scopes, which are used as before. Co-Authored-By: Claude <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project check has failed because the head coverage (34.08%) is below the target coverage (35.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #1568 +/- ##
===========================================
+ Coverage 77.61% 77.65% +0.03%
===========================================
Files 51 51
Lines 4361 4368 +7
Branches 1234 1234
===========================================
+ Hits 3385 3392 +7
Misses 732 732
Partials 244 244
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Full-run results, for reviewers. This was a copy of the PPC Governor collection (AUTO-1062) through a local CLI build: 44 VUs, fixed load, 20 min, 6 GiB / 4 CPU. The run used a prototype that patched the sandbox the same way as this PR (only
Why it helps: the allocation profile of the host thread shows the uvm bridge making about 6 copies of the variables per script run ( Reviewer guide covering all the AUTO-1062 changes: https://claude.ai/artifact/S7vBMoFxTA9kjzQHhQTXpt |
Co-Authored-By: Claude <noreply@anthropic.com>
Read script.variableMutationsOnly from run options instead of always asking the sandbox for mutations only, so existing consumers keep the full-scope round trip unless they opt in. Co-Authored-By: Claude <noreply@anthropic.com>
| 'request', 'response'], | ||
|
|
||
| // variable scopes the sandbox sends back as mutations alone, see `variableMutationsOnly` | ||
| MUTATIONS_ONLY_SCOPES = ['environment', 'globals', 'collectionVariables'], |
There was a problem hiding this comment.
Why is _variables (local variable scope) not included?
There was a problem hiding this comment.
- include _variables in the scopes rebuilt from mutations - rebuild only when the run asked for mutations only - use const in applyScopeMutations - list the changelog entry under new features, trim the docs note - replace the sandbox-importing integration test with a standard one plus unit tests over a stubbed host Co-Authored-By: Claude <noreply@anthropic.com>
postman-sandbox v6.9.0 adds the `variableMutationsOnly` execute option (postmanlabs/postman-sandbox#1116) that `script.variableMutationsOnly` relies on. Co-Authored-By: Claude <noreply@anthropic.com>
Cover the two branches of applyScopeMutations that no test reached: a
scope the run holds as a plain object (item command falls back to `{}`
for a scope missing from its payload) and a scope the sandbox sends back
without mutations.
Co-Authored-By: Claude <noreply@anthropic.com>
Context
AUTO-1062 / AUTO-60. After each script the sandbox sends back the full local, environment, globals and collectionVariables scopes, and runtime mostly needs only their
mutations. With ~4 MB of variables that copy costs ~22 ms and ~22 MB per script. One sandbox thread serves all VUs, so it also caps throughput: in a 44-VU, 20-minute CLI run, a prototype cut the worker peak from 2.65 to 1.92 GB and raised throughput from 32 to 40 rps.Summary of the change
script.variableMutationsOnly(defaultfalse). When set,event.command.jspassesvariableMutationsOnly: truetohost.execute(needs feat(AUTO-1062): add variableMutationsOnly option to return only scope mutations postman-sandbox#1116). Consumers that don't set it keep today's full-scope round trip. The perf lib opts in._variables, environment, globals, collectionVariables) comes back with novalues, runtime rebuilds it withapplyScopeMutations: a copy ofcontextToUse[scope]with the mutations applied, and.mutationskept. Thescripttrigger still gets full scopes with mutations, which nested-request and consumers read.contextToUseis the masked clone when_forbiddenSecretKeysapply, so masked secrets stay masked in the script result. A sandbox-only prototype failed 9 tests here (8 vault masking, 1 pm.variables).result[scope].mutations→applyOn(payload.context[scope]), as before.Breaking changes
None. The option is off by default, so existing consumers see no change. With it on, an older sandbox ignores it and sends full scopes, which take the old path (detected by
values).Dependencies
postmanlabs/postman-sandbox#1116 (
variableMutationsOnly). No gain until runtime bumpspostman-sandbox. Until then this PR is behaviour-neutral.Test plan
Bench:
node copybench.js <runtimeDir> 7 100(1 request, prerequest + test script, 4.08 MB collection vars, 200 scripts):Opt-in commit (a2c60f2): new
test/integration/sanity/variable-mutations-only.test.jscovers default off, opt-in, and the host rebuild when the sandbox sends mutations only (stubbed, so it runs against any sandbox version). Its default-off case fails against the previous hardcodedtrue. test-integration: 1918 passing, 0 failing. test-unit: 571 passing. The one failure,version.test.js, is down to localnode_modulesnot matching the lockfile, not this change. Lint ok.Review round (27c2eca):
_variablesincluded, rebuild gated on the option, standard integration test plus unit tests over a stubbed host (test/unit/event-command-variable-mutations-only.test.js).version.test.js, localnode_modulesvs lockfile, not this changeAdditional notes
Draft to
develop. Hold it until the sandbox release, then add the dependency bump.Generated with Claude Code