Skip to content

feat(quickjs): insomnia.test()/pm.test() lifecycle + real chai parity - #10410

Open
jackkav wants to merge 4 commits into
developfrom
claude/quickjs-test-lifecycle
Open

feat(quickjs): insomnia.test()/pm.test() lifecycle + real chai parity#10410
jackkav wants to merge 4 commits into
developfrom
claude/quickjs-test-lifecycle

Conversation

@jackkav

@jackkav jackkav commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

Stacked on #10392 — PR 3 of the hidden-window → QuickJS rollout plan.

Summary

  • Vendors chai@4.5.0 through the existing M3 npm-vendoring pipeline (sandbox-vendored-libs-list.tschai.generated.ts) and binds its .expect as insomnia.expect, so pm.test() assertion messages match the hidden-window path byte-for-byte (verified against the real vendored bundle inside an actual QuickJS context — e.g. "expected 199 to deeply equal 200") instead of a hand-rolled reimplementation.
  • insomnia.test()/insomnia.test.skip() run entirely inside the VM, building requestTestResults in the same {testCase, status, executionTime, errorMessage, category} shape run-script.ts produces. A pm.test() the script doesn't await is still waited on before the run ends (mirrors waitForAllTestsDone()).
  • Generalizes the sendRequest bridge's teardown handling into a BridgeCalls registry that drains outstanding calls after the task settles (bounded by the script deadline) — landing feat(quickjs): insomnia.sendRequest() bridge for the QuickJS script sandbox #10392's deferred item so a fire-and-forget insomnia.sendRequest(url, callback) actually gets its callback called instead of being silently dropped, with anything still open at the deadline cancelled and rejected with a real, observable error.

Test plan

  • npx tsc --noEmit clean
  • npx eslint clean on changed files
  • npx vitest run src/scripting/ — 227/227 passing (run from packages/insomnia, not the repo root)
  • e2e smoke test row for the test lifecycle (tracked as follow-up per the rollout plan)

Base automatically changed from claude/quickjs-sendrequest-bridge-wip to develop August 17, 2026 09:51
Vendors chai@4.5.0 through the existing M3 npm-vendoring pipeline
(sandbox-vendored-libs-list.ts -> chai.generated.ts) and binds its
.expect as insomnia.expect, so pm.test() assertion messages match the
hidden-window path byte-for-byte instead of a hand-rolled
reimplementation. insomnia.test()/insomnia.test.skip() run entirely
inside the VM, building requestTestResults in the same shape
run-script.ts produces; a pm.test() the script doesn't await is still
waited on before the run ends.

Also generalizes the sendRequest bridge's teardown fix into a
BridgeCalls registry that drains outstanding calls after the task
settles (bounded by the script deadline) -- landing PR2's deferred
item so a fire-and-forget insomnia.sendRequest(url, callback) actually
gets its callback called instead of being silently dropped, with
anything still open at the deadline cancelled and rejected with a
real, observable error.
@jackkav
jackkav force-pushed the claude/quickjs-test-lifecycle branch from cf74b09 to 797c000 Compare August 17, 2026 10:08
A background formatter in this environment stripped the leading
/* eslint-disable */ from the vendored chai bundle before it was
committed, which the sandbox:vendored:ci guardrail in CI correctly
flagged as drift from a fresh regeneration.
Copilot AI lite review requested due to automatic review settings August 17, 2026 10:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR advances the QuickJS scripting sandbox rollout by adding in-VM insomnia.test() lifecycle handling and switching assertions to real vendored chai to better match the existing (hidden-window) scripting path, while also improving the insomnia.sendRequest() bridge teardown/drain behavior.

Changes:

  • Vendor chai@4.5.0 via the existing sandbox vendoring pipeline and expose insomnia.expect backed by that bundle.
  • Implement insomnia.test() / insomnia.test.skip() inside the QuickJS VM and export requestTestResults in the same shape as the existing scripting environment.
  • Generalize sendRequest teardown into a BridgeCalls registry and drain pending calls after the task settles (bounded by deadline), cancelling leftovers at teardown.

Reviewed changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/insomnia/src/templating/sandbox/vendored/uuid.generated.ts Regenerated vendored uuid bundle metadata/header.
packages/insomnia/src/templating/sandbox/vendored/pkg/package.json Add chai as an exact-pinned vendored dependency and update description to cover scripting sandbox too.
packages/insomnia/src/templating/sandbox/vendored/pkg/package-lock.json Lockfile updates for vendored chai and its transitive dependencies.
packages/insomnia/src/templating/sandbox/vendored/chai.generated.ts New generated vendored chai bundle source/version export.
packages/insomnia/src/templating/sandbox/vendored/ajv.generated.ts Regenerated vendored ajv bundle metadata/header.
packages/insomnia/src/scripting/quickjs-script-engine.ts Bind vendored chai into the VM, implement in-VM tests/results, and add BridgeCalls registry + drain/teardown semantics.
packages/insomnia/src/scripting/quickjs-script-engine.test.ts Add coverage for QuickJS insomnia.test() behavior and new bridge drain/cancellation behaviors.
packages/insomnia/scripts/sandbox-vendored-libs-list.ts Add chai to the vendored libs list (also used by QuickJS scripting engine).
Files not reviewed (1)
  • packages/insomnia/src/templating/sandbox/vendored/pkg/package-lock.json: Generated file

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/insomnia/src/scripting/quickjs-script-engine.ts
Comment thread packages/insomnia/src/scripting/quickjs-script-engine.ts Outdated
Clarify doc comments: there is no globalThis.pm alias in the QuickJS
sandbox, matching the hidden-window sandbox, which has none either
(only `insomnia` and the `$` Postman-compat alias exist in both).

Drop the `e &&` guard around e.actual/e.expected in the failed-test
errorMessage so it matches insomnia-scripting-environment/src/objects/
test.ts's template exactly -- the guard changed the rendered value for
a falsy thrown primitive (e.g. `throw 0`) instead of just avoiding a
crash, which property access on a primitive never causes anyway.
Without this, ESLint's default reportUnusedDisableDirectives flags
these checked-in, machine-generated files' blanket
`/* eslint-disable */` as unused (the minified bundle happens to trip
no rule under this config), and `--fix` deletes it -- which then
perpetually conflicts with scripts/generate-sandbox-vendored.ts always
re-adding it and with CI's sandbox:vendored:generate diff check.
Same category as the existing **/*.min.js/**/dist/* ignores.

Also restores the comment in the three vendored files, stripped by
this exact autofix before it landed on this branch.
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.

2 participants