ESD-1650: Polish WASM output composition and HTTP transport fidelity#534
ESD-1650: Polish WASM output composition and HTTP transport fidelity#534Phil-Browne wants to merge 4 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
Longhelp text in WASM so repeated--helprenders 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
Uint8Arrayinstead 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. |
penzeliz-megaport
left a comment
There was a problem hiding this comment.
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.
324b363 to
b66b4de
Compare
|
Merge conflicts resolved @penzeliz-megaport |
…m-output-transport-polish
…m-output-transport-polish
Three fidelity gaps in the WASM build. The command tree stays alive across invocations in a browser session, so repeated
--helpcalls 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.--helpalways renders from a clean base.Tests added for the help-text regression, buffer accumulation (including a first-ever XML output test), and the transport header/body fixes.