Skip to content

fix(cli): read the remote manifest body once, and cover loadManifest - #13

Merged
Oyinkans0la12 merged 2 commits into
mainfrom
fix/manifest-remote-fetch
Sep 14, 2026
Merged

Oyinkans0la12 merged 2 commits into
mainfrom
fix/manifest-remote-fetch

Conversation

@Oyinkans0la12

Copy link
Copy Markdown
Collaborator

Fixes #2. Part of #8.

The bug

loadManifest consumed the same Response twice:

return { manifest: parseOrExplain(await response.text(), url), source: url, json: await response.text() };

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 remote
path — 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.ts is new: loadManifest had no coverage at
all, 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 candidate
path 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 real fetch, which is what
turns the fix into a regression test. Confirmed by reverting the source fix:

Test Files  1 failed (1)
     Tests  2 failed | 11 passed (13)   # "Body is unusable: Body has already been read"

and green again with it (13 passed).

Verification

npm run typecheck   # clean, both workspaces
npm test            # 90 SDK tests + 90 CLI tests passing (was 77 CLI tests)

Two commits, one logical unit each (fix, then tests), per CONTRIBUTING.md.

`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.
@Oyinkans0la12
Oyinkans0la12 merged commit 7cda63e into main Sep 14, 2026
1 check passed
@Oyinkans0la12
Oyinkans0la12 deleted the fix/manifest-remote-fetch branch September 15, 2026 14:49
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.

loadManifest reads the fetch body twice, so every remote --repo manifest load fails

1 participant