Skip to content

ESD-1650: Polish WASM output composition and HTTP transport fidelity#534

Open
Phil-Browne wants to merge 4 commits into
mainfrom
worktree-esd-1650-wasm-output-transport-polish
Open

ESD-1650: Polish WASM output composition and HTTP transport fidelity#534
Phil-Browne wants to merge 4 commits into
mainfrom
worktree-esd-1650-wasm-output-transport-polish

Conversation

@Phil-Browne

Copy link
Copy Markdown
Contributor

Three fidelity gaps in the WASM build. The command tree stays alive across invocations in a browser session, so repeated --help calls kept re-coloring and re-suffixing the same help text. Structured output (JSON/CSV/XML/table) was overwritten on every print call, so a command emitting more than one document only kept the last. And the WASM HTTP transport dropped every header value but the first and sent bodies as Go strings, which would mangle a binary body.

  • Cache each command's pristine help text so repeated --help always renders from a clean base.
  • Accumulate structured output buffers across calls within one command, clearing only between invocations.
  • Join multi-value headers instead of dropping all but the first, and send request bodies as raw bytes via a Uint8Array.
  • Roll back a structured buffer to its pre-call length if an encode fails partway through, so a failed call can't leak partial output into a later successful one.

Tests added for the help-text regression, buffer accumulation (including a first-ever XML output test), and the transport header/body fixes.

Copilot AI review requested due to automatic review settings July 10, 2026 19:50
@Phil-Browne Phil-Browne requested a review from a team as a code owner July 10, 2026 19:50
@Phil-Browne Phil-Browne requested a review from mola-dev July 10, 2026 19:50
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.29%. Comparing base (dee5b8d) to head (4cb5846).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #534   +/-   ##
=======================================
  Coverage   79.29%   79.29%           
=======================================
  Files         193      193           
  Lines       18683    18685    +2     
=======================================
+ Hits        14814    14816    +2     
  Misses       2820     2820           
  Partials     1049     1049           
Files with missing lines Coverage Δ
internal/base/output/common.go 77.70% <100.00%> (+0.14%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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 addresses statefulness and fidelity issues specific to the js/wasm build, where the Cobra command tree and WASM output/transport layers persist across browser-session invocations. It prevents repeated help rendering from re-mutating the same cmd.Long, ensures structured output buffers (JSON/CSV/XML/table) accumulate within a single invocation but reset between invocations, and improves HTTP request transport fidelity for multi-value headers and binary request bodies.

Changes:

  • Cache each command’s pristine Long help text in WASM so repeated --help renders from an unmodified baseline.
  • Change WASM structured output writers to append per PrintOutput call (with rollback-on-encode-failure) and reset those buffers between WASM invocations via output.ResetState().
  • Fix WASM fetch option composition to (1) join multi-value request headers and (2) send request bodies as raw bytes via Uint8Array instead of UTF-8 strings; add tests for these behaviors.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/wasm/wasmhttp/transport.go Joins multi-value request headers and sends request bodies as Uint8Array to avoid binary mangling.
internal/wasm/wasmhttp/transport_test.go Adds tests for multi-value header joining and binary body round-tripping through fetch options.
internal/base/output/table_wasm.go Appends table output across calls (per invocation) and prints only the newly-rendered segment.
internal/base/output/table_wasm_test.go Adds a regression test ensuring multiple table renders are accumulated.
internal/base/output/output_wasm.go Appends JSON/CSV/XML output across calls with rollback-on-error; wires a WASM reset hook to clear buffers between invocations.
internal/base/output/output_wasm_test.go Adds accumulation tests for JSON/CSV/XML plus a first XML WASM capture test and ResetState buffer-clear test.
internal/base/output/common.go Extends ResetState() to also clear WASM structured buffers via an overridable hook.
cmd/megaport/megaport_wasm.go Caches original per-command Long help text to prevent repeated --help from re-coloring/re-suffixing already-mutated content.
cmd/megaport/help_wasm_test.go New WASM tests asserting repeated --help invocations produce byte-identical output for root and a subcommand.

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

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@penzeliz-megaport penzeliz-megaport left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed for correctness; no findings. LGTM.

Repeated --help calls were re-coloring and re-suffixing the same help
text because the command tree persists across WASM invocations. Cache
each command's pristine Long text so help always renders from a clean
base.

Structured output (JSON/CSV/XML/table) was overwritten on every
PrintOutput call, so a command emitting more than one document only
kept the last. Buffers now accumulate across calls within an
invocation and are cleared only between invocations.

The WASM HTTP transport dropped every header value but the first and
sent request bodies as Go strings, which would mangle binary bodies.
Multi-value headers are now joined per HTTP semantics and bodies are
passed as raw bytes via a Uint8Array.
printJSON/printCSV/printXML/printTable no longer reset per call, so a
partial write from a failed encode could persist and get prepended to
a later successful call within the same invocation. Roll the buffer
back to its pre-call length whenever the call returns an error.

Also note the Cookie-header exception to the multi-value header join.
@Phil-Browne Phil-Browne force-pushed the worktree-esd-1650-wasm-output-transport-polish branch from 324b363 to b66b4de Compare July 13, 2026 13:58
@Phil-Browne

Copy link
Copy Markdown
Contributor Author

Merge conflicts resolved @penzeliz-megaport

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.

3 participants