test(server): use Layer.mock for partial Account service stub#26472
Merged
Conversation
7cd5653 to
cbdb2d9
Compare
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.
katosun2
pushed a commit
to katosun2/opencode
that referenced
this pull request
May 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two related test improvements for
httpapi-account-error-mapping.test.ts:Layer.mockfor partial service stubs. Replaces the hand-rolledLayer.succeed(Account.Service, Account.Service.of({ ... }))(which stubbed all 11Account.Servicemethods just to overrideorgsByAccount) withLayer.mock, which only requires the one method the test actually exercises. Unimplemented methods now defect withUnimplementedErrorif accidentally called, so the mock fails loudly instead of silently succeeding with placeholder values.testEffectconversion. Replaces thebun:testtest()+afterEachsetup withit.live(...)fromtest/lib/effect.ts. Flag toggling and database reset move into aLayer.effectDiscardfinalizer; per-testtmpdirbecomestmpdirScopedso the temp directory is owned by the Effect scope.Both endpoints still assert status 500 + a structured
InternalServerErrorbody with no stack-trace leak.Documents both patterns in
packages/opencode/test/AGENTS.mdso future tests reach forLayer.mockandtestEffectfirst.Test plan
bun run test test/server/httpapi-account-error-mapping.test.ts— both tests still pass.bun run typecheck— clean.