Skip to content

test(server): use Layer.mock for partial Account service stub#26472

Merged
kitlangton merged 1 commit into
devfrom
kit/test-layer-mock-refactor
May 9, 2026
Merged

test(server): use Layer.mock for partial Account service stub#26472
kitlangton merged 1 commit into
devfrom
kit/test-layer-mock-refactor

Conversation

@kitlangton
Copy link
Copy Markdown
Contributor

@kitlangton kitlangton commented May 9, 2026

Summary

Two related test improvements for httpapi-account-error-mapping.test.ts:

  1. Layer.mock for partial service stubs. Replaces the hand-rolled Layer.succeed(Account.Service, Account.Service.of({ ... })) (which stubbed all 11 Account.Service methods just to override orgsByAccount) with Layer.mock, which only requires the one method the test actually exercises. Unimplemented methods now defect with UnimplementedError if accidentally called, so the mock fails loudly instead of silently succeeding with placeholder values.

  2. testEffect conversion. Replaces the bun:test test() + afterEach setup with it.live(...) from test/lib/effect.ts. Flag toggling and database reset move into a Layer.effectDiscard finalizer; per-test tmpdir becomes tmpdirScoped so the temp directory is owned by the Effect scope.

Both endpoints still assert status 500 + a structured InternalServerError body with no stack-trace leak.

Documents both patterns in packages/opencode/test/AGENTS.md so future tests reach for Layer.mock and testEffect first.

Test plan

  • bun run test test/server/httpapi-account-error-mapping.test.ts — both tests still pass.
  • bun run typecheck — clean.

@kitlangton kitlangton closed this May 9, 2026
@kitlangton kitlangton force-pushed the kit/test-layer-mock-refactor branch from 7cd5653 to cbdb2d9 Compare May 9, 2026 04:01
Replace the hand-rolled `Layer.succeed(Account.Service, Account.Service.of({...}))`
that stubbed all 11 methods with `Layer.mock`, which only requires the one
method the test exercises (`orgsByAccount`). Unimplemented methods now defect
with `UnimplementedError` if accidentally called, surfacing the misuse instead
of silently succeeding with a placeholder.

Document the pattern in `packages/opencode/test/AGENTS.md` so future tests
reach for `Layer.mock` first.
@kitlangton kitlangton reopened this May 9, 2026
@kitlangton kitlangton merged commit 7f3e514 into dev May 9, 2026
6 of 8 checks passed
@kitlangton kitlangton deleted the kit/test-layer-mock-refactor branch May 9, 2026 04:05
katosun2 pushed a commit to katosun2/opencode that referenced this pull request May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant