Route tests for /api/v1/agents/models merge/degradation contract · Issue #3322 · chmonitor/chmonitor · GitHub
Skip to content

Route tests for /api/v1/agents/models merge/degradation contract #3322

Description

@duyetbot

Plan 127: Route tests for /api/v1/agents/models merge/degradation contract

Executor instructions: Follow this plan step by step. Run every
verification command and confirm the expected result before moving to the
next step. If anything in the "STOP conditions" section occurs, stop and
report — do not improvise.

Drift check (run first): git diff --stat 34113ac..HEAD -- apps/dashboard/src/routes/api/v1/agents/models.ts
On mismatch, re-read live files.

Status

  • Priority: P3
  • Effort: S
  • Risk: LOW
  • Depends on: none
  • Category: tests
  • Planned at: commit 34113ac, 2026-08-26
  • Issue: (filled after publish)

Why this matters

/api/v1/agents/models (~315 lines, 3 commits since July — tied-highest churn
of untested routes) merges FOUR upstream model catalogs with per-step fail-soft
degradation and feeds the model picker for paying cloud users. Leaf modules are
tested; the route's own contract is not: outage degradation ordering,
last-wins preset merging, the "sole configured-authority" filter, and auth
wiring. A regression either empties the picker or exposes unconfigured
providers.

Current state

apps/dashboard/src/routes/api/v1/agents/models.ts — loaders for registry /
OpenRouter dynamic models / AnyRouter presets / providers; per-step try/catch;
filterByConfiguredProviders; authorizeAgentApiRequest. Mock exemplar:
mv-designer.test.ts:11–29 (mock.module style).

Commands you will need

Purpose Command Expected
New tests cd apps/dashboard && bun test src/routes/api/v1/agents --isolate pass
Full unit pnpm run test:unit pass

Scope

In scope: NEW test file beside the route (models.test.ts or
__tests__/models.test.ts matching siblings).

Out of scope: any source change.

Git workflow

  • Branch: advisor/127-agents-models-tests
  • Commit: test(agents): cover models route merge and degradation

Steps

  1. Mock all four loader modules + auth. Assert:
    • OpenRouter loader throws → response still contains registry + AnyRouter entries (200).
    • Presets conflict → last-wins per current code (characterize actual order).
    • A provider unconfigured locally has its catalog entries stripped even when its loader succeeds.
    • Auth rejection → 401 before any loader runs (assert loader mocks untouched).
  2. Battery green.

Done criteria

  • Test file green, ≥6 branch assertions
  • Zero source diffs outside the new test

STOP conditions

  • Route internals not mock-seamable without refactor → characterize through the route export only as far as possible, report gaps.

Maintenance notes

  • Update when model-catalog sources change.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions