Skip to content

fix(cli): repair --from-json crash, empty-2xx parse, login identity & hang - #1

Merged
akoso merged 1 commit into
mainfrom
fix/cli-from-json-and-login-bugs
Jun 13, 2026
Merged

akoso merged 1 commit into
mainfrom
fix/cli-from-json-and-login-bugs

Conversation

@akoso

@akoso akoso commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

Fixes four user-reported bugs in the shipped (node-target) binary.

C1 — --from-json crashed with "Bun is not defined" · High

readJsonBody read files via Bun.file(), which is undefined in the node binary, so every --from-json call died before sending a request. The bug existed in 7 commands, not just options (goals, events, collections add/edit too).
Fix: shared readJsonObject() using node:fs/promises, replacing the 7 duplicated copies.

C2 — successful create reported as failure → silent duplicates · High

Option creation returns 201 with no body; openapi-fetch's JSON parser threw "Failed to parse JSON", which bypassed the error check and surfaced a server-side success as a CLI failure. Retrying created duplicates.
Fix: the client middleware normalizes empty 2xx bodies to undefined data.

C3 — whoami showed <unknown@local> · Low

Login never fetched identity. Both login flows now call GET /v1/me via a shared fetchIdentity() helper.

C4 — mna login hung after browser approval

A keep-alive socket kept the loopback server (and event loop) alive. Now sends Connection: close and calls closeAllConnections() so the CLI exits on its own.

Tests

Adds coverage for the JSON util (incl. the no-Bun path) and the empty-201 client behavior. typecheck + lint + 22 tests green.

🤖 Generated with Claude Code

… hang

Four user-reported bugs in the shipped (node-target) binary:

- C1: --from-json read files via Bun.file(), undefined in the node binary,
  crashing every call with "Bun is not defined". Extracted a shared
  readJsonObject() using node:fs/promises and removed the 7 duplicated copies
  across options/goals/events/collections add & edit.
- C2: option-creation returns 201 with no body; openapi-fetch's JSON parser
  threw "Failed to parse JSON", which bypassed the error check and reported a
  server-side success as failure -> silent duplicates on retry. The client
  middleware now normalizes empty 2xx bodies to undefined data.
- C3: whoami showed <unknown@local> because login never fetched identity. Both
  login flows now call GET /v1/me via a shared fetchIdentity() helper.
- C4: `mna login` hung after browser approval because a keep-alive socket kept
  the loopback server (and event loop) alive. Send Connection: close and call
  closeAllConnections() so the CLI exits on its own.

Adds tests for the JSON util and the empty-201 client behavior.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@akoso
akoso merged commit 9a43adc into main Jun 13, 2026
1 check passed
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