Skip to content

Fix saved-prompts API contract tests failing against backend #396

@hsteude

Description

@hsteude

Context

Running bun test with the OpenCode backend on port 4096 causes 4 failures in api-contract.test.ts. The saved-prompts extended API endpoints (/api/ext/saved-prompts) are served by our dev/production server (dev.ts / serve-ui.ts), not by the OpenCode backend directly. The API contract tests hit http://127.0.0.1:4096 (the backend), so the backend returns HTML (its built-in SPA fallback) instead of JSON.

Failing tests

  1. GET /api/ext/saved-prompts returns prompt arrays — gets text/html instead of application/json
  2. GET /api/ext/saved-prompts supports directory param — JSON parse error (HTML response)
  3. PUT /api/ext/saved-prompts rejects project prompts without directory — gets 200 instead of 400
  4. PUT /api/ext/saved-prompts rejects outside directory — gets 200 instead of 400/403

Root cause

The api-contract.test.ts file tests against OPENCODE_URL (default http://127.0.0.1:4096), but extended endpoints are only available through our proxy server. These tests need to either:

  1. Skip when targeting the backend directly — detect that extended endpoints aren't available and skip gracefully, OR
  2. Run against the dev server — add a separate test target for extended API tests against http://localhost:3000

Files to modify

  • app-prefixable/tests/api-contract.test.ts:247-348 — Extended API test section

Acceptance criteria

  • bun test passes with only the OpenCode backend running (no dev server)
  • Extended API tests still run and pass when the dev server is available
  • No false positives from HTML fallback responses

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingin-progressCurrently being worked onpriority:highImportant feature or significant bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions