Skip to content

test: simulate opencode's request instead of running its CLI - #131

Merged
solderzzc merged 2 commits into
mainfrom
claude/opencode-simulate-query
Aug 8, 2026
Merged

solderzzc merged 2 commits into
mainfrom
claude/opencode-simulate-query

Conversation

@solderzzc

Copy link
Copy Markdown
Member

The opencode job has been red on every PR for weeks, and its failure never said anything about SwiftLM.

What was happening

Test 2 ran npm install opencode-ai then npx opencode run. The runner OOM-kills the CLI:

✅ PASS: OpenAI SDK parsed the stream successfully
…
Killed: 9    | npx --yes opencode run

The server had already answered correctly. The job was measuring the npm CLI's memory footprint on a CI runner, and it was waived with continue-on-error — a permanently red job nobody can act on, which is a job people stop reading.

What it does now

Issues the request shape opencode actually sends, through the OpenAI SDK already installed for Test 1:

  • coding-agent system prompt + a tool catalogue (bash, read)
  • stream: true
  • reassembles the response the way a strict client must — tool-call deltas keyed by index

and asserts: the stream parses, it reports a finish_reason, every tool call carries a function name, and the accumulated arguments are valid JSON. No npm, no CLI, no OOM.

Result

Local run against the same model CI uses:

✅ PASS: OpenAI SDK parsed the stream successfully
✅ PASS: opencode-shaped request handled — Success: 28 chunks, finish_reason=tool_calls, tool_calls=1
Results: 2 passed, 0 failed, 2 total

tool_calls=1 matters: the model really did emit a tool call, so the index-keyed reassembly path is exercised rather than vacuously skipped. That is a stronger assertion than "the CLI did not crash" — it would catch the missing index field regression that OpenAI-compat clients depend on.

continue-on-error is removed. The job can pass now, so a failure means SwiftLM misbehaved and should block.

Refs #128.

🤖 Generated with Claude Code

solderzzc and others added 2 commits August 7, 2026 21:34
The opencode job has been red on every PR for weeks. Its Test 2 installed
opencode-ai from npm and ran `npx opencode run`, which the runner OOM-kills
(`Killed: 9`) — after the server had already answered correctly. The failure
said nothing about SwiftLM, and a permanently red job that nobody can act on
is a job people stop reading.

What is worth testing is the request shape opencode sends, so Test 2 now
issues it directly through the OpenAI SDK: a coding-agent system prompt, a
tool catalogue, streaming on. It then reassembles the response the way a
strict client must — tool-call deltas keyed by index — and asserts the stream
parses, reports a finish_reason, every tool call carries a function name, and
the accumulated arguments are valid JSON. No npm, no CLI, no OOM.

Because the job can now pass, it is no longer continue-on-error: a failure
here means SwiftLM misbehaved and should block the merge.

Local run against the same model CI uses: 2 passed, 0 failed —
28 chunks, finish_reason=tool_calls, tool_calls=1, so the tool-call
reassembly path is genuinely exercised rather than skipped.

Refs #128.

Co-Authored-By: Claude Opus 5 <[email protected]>
- release.yml's comment asserted the opposite of the new behaviour: it said
  opencode is continue-on-error so its failures do not block releases. This PR
  removed that waiver, and #127 gates releases on CI success, so an opencode
  failure now stops the release. That coupling is intentional but was
  documented nowhere else.
- The simulation omitted stream_options: {include_usage: true}, which
  opencode's networking layer injects into every streaming request. It makes
  SwiftLM append a terminal chunk with an empty `choices` array — exactly the
  shape a strict SSE client can trip on, and previously covered only by
  curl+grep, never by an SDK parser and never alongside tools.
- A run where the model emits no tool call still passes, by design, so the job
  cannot flake. But it could then go quietly vacuous — green forever while the
  reassembly path stops being exercised — so that case now prints a loud
  WARNING.

Local run: 2 passed, 0 failed, 31 chunks, finish_reason=tool_calls,
tool_calls=1 with the usage chunk present.

Co-Authored-By: Claude Opus 5 <[email protected]>
@solderzzc
solderzzc merged commit 70b60c2 into main Aug 8, 2026
13 checks passed
@solderzzc
solderzzc deleted the claude/opencode-simulate-query branch August 8, 2026 06:42
solderzzc added a commit that referenced this pull request Aug 8, 2026
Removing the opencode CLI in #131 was right — the runner OOM-killed it after
the server had already answered, and its assertions were a two-string grep —
but it left every SSE assertion in CI going through Python httpx.

That matters because SwiftLM frames SSE with \r\n\r\n rather than the spec's
\n\n. httpx tolerates it; whether a different parser does is exactly what a
second implementation establishes, and there was no longer one.

tests/test-sse-node.js uses Node's built-in fetch and a manual event split —
no npm install, node is preinstalled on macos-15, so it reintroduces none of
the memory pressure that motivated #131. It asserts the framing is parseable,
there is exactly one [DONE] terminator, every payload is valid JSON with a
choices array, a finish_reason is reported, content accumulates, and the
terminal usage chunk with an empty choices array does not break accumulation.

Run from test-contract.sh against the already-running server, and skipped
rather than failed where node is absent.

Local run: 7 passed, 0 failed. It confirms empirically that the server emits
\r\n\r\n, which was previously only an implementation detail nothing asserted.

Fixes #134.

Co-authored-by: Claude Opus 5 <[email protected]>
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.

1 participant