Skip to content

Phase 9: Flip CLI default API URL to api.nemar.org - #352

Merged
neuromechanist merged 3 commits into
devfrom
feature/issue-330-phase9-cli-default-url
Apr 25, 2026
Merged

neuromechanist merged 3 commits into
devfrom
feature/issue-330-phase9-cli-default-url

Conversation

@neuromechanist

Copy link
Copy Markdown
Contributor

Summary

  • Flip DEFAULT_API_URL in src/lib/api.ts, src/lib/config.ts, src/commands/auth.ts from https://api.osc.earth/nemar to https://api.nemar.org
  • Add migrateApiUrl() to src/lib/config.ts: silently rewrites stored apiUrl entries on existing user configs that still point at the legacy URL. Untouched: workers.dev URLs, self-hosted custom URLs, anything that's not an exact match
  • Update CI dev-build URL injection to pivot off the new prod URL and target the SCCN dev worker (nemar-api-dev.sccn-org.workers.dev)
  • Update generated API-reference docs and test setup default
  • Bump CLI version to 0.8.0-dev (release minor bump happens on dev branch after merge)

This is Phase 9 of the SCCN migration epic (#314). The personal api.osc.earth/nemar worker stays in MAINTENANCE_MODE=read-only as a buffer for users on older CLIs, until Phase 11 retires it.

Why a migration shim

  • Stored configs at ~/.config/nemar/config.json snapshot the active apiUrl on login (auth.ts:146); without the migration, users would keep hitting api.osc.earth/nemar even after upgrading.
  • The shim is exact-match and silent: only the literal legacy default gets rewritten. Dev builds, workers.dev fallbacks, and anyone on a custom backend are left alone.

Test plan

  • New unit test test/config-migrate-api-url.test.ts exercises legacy rewrite, idempotent rewrite, and pass-through cases against a real temp config dir (no mocks).
  • bun test test/api.test.ts 61/61 pass.
  • bun run build produces a dist/index.js containing 3 api.nemar.org instances + 1 api.osc.earth/nemar (the LEGACY_DEFAULT_API_URL constant for the migration check). Verified.
  • IS_DEV_BUILD detection still works: prod default has no workers.dev substring, dev-injected URL does.
  • Pre-existing failure test/datalad-commands.test.ts > clone fails for non-existent dataset reproduces on dev before this PR — not a Phase 9 regression.
  • Post-merge: bump version to 0.8.0 on dev branch via ./scripts/bump-version.sh minor, then PR dev -> main for the npm release.

Sed pattern note

The CI dev-URL injection in npm-publish.yml literally sed-replaces the prod URL string in the bundled dist/index.js. After this PR the source URL is api.nemar.org; without updating the sed, dev npm publishes would silently keep pointing at the prod URL. Updated to source-from api.nemar.org and target nemar-api-dev.sccn-org.workers.dev.

Refs

Source changes:
- src/lib/api.ts, src/lib/config.ts, src/commands/auth.ts: DEFAULT_API_URL
  is now https://api.nemar.org. IS_DEV_BUILD detection (workers.dev
  substring) is unchanged and still flips for CI-injected dev builds.
- src/lib/config.ts: new migrateApiUrl() runs on module load and silently
  rewrites stored apiUrl entries that match the legacy default. Custom URLs
  (workers.dev, self-hosted) are untouched. The legacy redirect on the
  personal Cloudflare worker keeps stale configs working through Phase 11.

Test:
- test/config-migrate-api-url.test.ts: real integration test against a temp
  config dir, covers legacy rewrite, idempotent rewrite of already-new URL,
  and pass-through of dev/custom URLs.
- test/setup.ts default updated to api.nemar.org.

CI:
- .github/workflows/npm-publish.yml: dev-branch sed pattern updated to
  source from api.nemar.org and target nemar-api-dev.sccn-org.workers.dev
  (SCCN dev worker, not the personal one). Without this dev npm publishes
  would silently keep pointing at api.nemar.org.

Docs:
- scripts/generate-docs.ts: API reference base URL updated.

Refs #330
- Export DEFAULT_API_URL from src/lib/config and use it in auth.ts
  (was: duplicate hardcoded literal). Eliminates drift risk on the
  next URL change. Build dedupes the literal too.
- Add idempotency note on migrateApiUrl() per reviewer ask.
- Test: cover account with no apiUrl field (legacy-flat migration
  result) to guard the optional-chaining guard.

Refs #330
@neuromechanist

Copy link
Copy Markdown
Contributor Author

Review pass: addressed

Three findings actioned in commit 591fab2:

  • code-reviewer suggestion 1 (drift risk): auth.ts:146 was duplicating the literal URL. Now exports DEFAULT_API_URL from src/lib/config and imports it. Build minifier dedupes too — bundle drops from 3 → 2 api.nemar.org instances.
  • code-reviewer suggestion 2 (idempotency note): One-line comment added on migrateApiUrl() documenting the exact-match guard + atomic Conf write semantics.
  • test-analyzer Important (untested branch): Added a partial fixture account with no apiUrl field. Asserts migrateApiUrl doesn't crash on the optional-chaining branch and doesn't invent a value. Test now has 6 expectations.

Deferred per agent ratings ≤ 3:

  • IS_DEV_BUILD unit test (build-time grep -c in npm-publish.yml already proves substitution).
  • Empty / null / malformed JSON edge cases (Conf parse-error, Zod-rejected).
  • The pre-existing datalad-commands.test.ts clone-fail brittleness (orthogonal, reproduces on dev before this PR).

Reviews:

  • code-reviewer: 'Approve. Standards met.'
  • pr-test-analyzer: critical/important coverage hit; suggestions skipped per their rating.

@github-actions

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR352

Version: 0.8.0-PR352.591fab2
Commit: 591fab2


🤖 Updated on each push.

@neuromechanist
neuromechanist merged commit dc42f4d into dev Apr 25, 2026
8 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-330-phase9-cli-default-url branch April 25, 2026 21:56

This branch was previously deployed

1 inactive deployment
npm — 591fab27 Deployed Apr 25, 2026 by neuromechanist via publish #612
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