Repository navigation
fix(cli): read the remote manifest body once, and cover loadManifest - #13
Merged
Merged
Conversation
`loadManifest` called `response.text()` twice, once for the parser and once for the `json` field. A fetch body can only be consumed once, so every remote manifest load - `--repo owner/name` on `status`, `claim` and `report` - failed with "Body is unusable: Body has already been read" instead of parsing the manifest it had just downloaded. Read the body into a local and hand the same text to both consumers.
`loadManifest` decides which manifest becomes a payout, and nothing tested it: the four-step preference order, the remote URL shape and the failure messages were all unverified. The fetch stub is deliberately strict - it rejects a second `text()` call, like real fetch does - which is what makes the double-read fix a regression test. Verified by reverting the fix: the two remote-body cases fail, both green again with it. Part of #8.
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.
Fixes #2. Part of #8.
The bug
loadManifestconsumed the sameResponsetwice:A fetch body can only be read once, so the second call rejects with
TypeError: Body is unusable: Body has already been read. Every documented remotepath —
splitstream status --repo owner/name,claim --repo … --ref …,report --repo …— failed while holding a perfectly good manifest in memory.The fix
Read the body once into a local and hand the same string to both consumers. One
line, no behaviour change beyond working.
Tests
packages/cli/test/manifest.test.tsis new:loadManifesthad no coverage atall, even though it is the single place where a wrong manifest becomes a wrong
payout. It covers the documented source preference (explicit path → local
checkout via
--repo→ remote at--ref→ working directory), the candidatepath order, the remote URL shape, and the failure messages (404, invalid JSON,
valid JSON that is not a manifest, transport error).
The fetch stub rejects a second
text()call, like realfetch, which is whatturns the fix into a regression test. Confirmed by reverting the source fix:
and green again with it (13 passed).
Verification
Two commits, one logical unit each (fix, then tests), per
CONTRIBUTING.md.