Skip to content

refactor(meta): deduplicate extension internals, pin failure paths with tests - #25

Merged
BlockedPath merged 2 commits into
mainfrom
claude/fervent-goodall-b171f3
Oct 2, 2026
Merged

BlockedPath merged 2 commits into
mainfrom
claude/fervent-goodall-b171f3

Conversation

@BlockedPath

@BlockedPath BlockedPath commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

Static Badge

What

A behavior-preserving cleanup of extensions/meta.ts (789 → 761 lines), preceded by a new test file that pins the paths being restructured.

Commit 1: test(meta). Adds tests/meta-failures.test.ts (49 tests). It covers behavior the existing suites didn't: slow_down back-off, denied/expired/unknown device-login errors, default interval and expiry, request shapes and progress messages, exact mint-failure messages, catalog refresh fallbacks (offline, no key, HTTP error, empty catalog, abort, failed persistence), the bundled model table, and MODEL_API_KEY/META_API_KEY mirroring. All of these pass against the unmodified extension.

Commit 2: refactor(meta).

  • Five near-identical bundled-model literals → one museFallbackModel() factory plus shared cost constants.
  • The ": ${detail}" suffix was copy-pasted in five places → detailedError().
  • loginMeta (80 lines) split into startDeviceAuthorization and pollForIdentityToken.
  • The "cached or fallback" tail repeated four times in refreshMetaModels → cachedOrFallbackModels(); credentialApiKey and fetchMetaCatalog extracted.
  • Thinking-level maps built in a loop; shared Muse compat and default limits; toProviderModels gates the one fallback it needs instead of the whole list per catalog entry.
  • responseBody is generic and reuses asRecord (duplicate removed); env mirroring extracted to mirrorApiKeyEnv().
  • AGENTS.md: one line noting the new test file.

Why

meta.ts had a lot of copy-paste (model literals, error formatting, fallback handling) that made each change touch many places. The existing tests didn't cover the failure paths being restructured, so the safety net came first.

Reviewer notes

  • Verification: bun run typecheck is clean. bun test gives 86 pass, 3 skip, 0 fail. The skips are the optional live probes. I ran with live credentials blanked and HOME redirected, because the live probes make real billable requests when a credential resolves.
  • Mutation check: I injected 12 deliberate bugs into the refactored code. Nine were caught by the tests; the other three are equivalent mutations (e.g. swapping which env key wins in ??=, which can't change behavior).
  • Removed export: metaFallbackCost is gone. Its only caller was the media module dropped in v0.6.0 and nothing here references it, but it was technically a public export.
  • Still one file: I did not split meta.ts into modules. tests/package.test.ts and the branch contract in AGENTS.md require extensions/ to contain only meta.ts.
  • Contract names preserved: gateMuseMaxEffort(), applyMetaResponsesCacheHints(), MUSE_USER_AGENT_MODEL_IDS, and the Pi 0.83/0.84 refresh-context handling.
  • No CHANGELOG entry, since there is no user-visible change; that's left to the release commit.

🤖 Generated with Claude Code

BlockedPath and others added 2 commits October 2, 2026 15:07
Add characterization tests for behavior the happy-path suites did not
cover: slow_down back-off, denied/expired/unknown device-login errors,
default interval and expiry, request shapes and progress messages, mint
failure messages, catalog refresh fallbacks (offline, no key, HTTP error,
empty catalog, abort, failed persistence), the bundled model table, and
the MODEL_API_KEY/META_API_KEY env mirroring.

These pass against the unmodified extension.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…og fallbacks

Behavior-preserving cleanup of extensions/meta.ts:

- Build the five bundled models with one museFallbackModel() factory and
  shared cost constants instead of five near-identical literals.
- Route every "<message>: <detail>" error through detailedError().
- Split loginMeta into startDeviceAuthorization and pollForIdentityToken.
- Collapse the repeated cached-or-fallback tail of refreshMetaModels into
  cachedOrFallbackModels(); extract credentialApiKey and fetchMetaCatalog.
- Build thinking-level maps in a loop, share the Muse compat/default
  limits, and gate a single fallback model instead of the whole list per
  catalog entry.
- Make responseBody generic and reuse asRecord; extract mirrorApiKeyEnv().
- Remove metaFallbackCost, whose only caller (the media module) was
  dropped in v0.6.0.

Public exports otherwise unchanged. The package still ships a single
extensions/meta.ts per the branch contract.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 2, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: b7e8c9a8-a67a-4ba0-a0db-dae996815c47

  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@BlockedPath
BlockedPath merged commit 96b4e02 into main Oct 2, 2026
6 checks 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