Skip to content

test: migrate prompt tests to HTTP mock LLM server - #20304

Merged
kitlangton merged 14 commits into
devfrom
refactor/llm-server-effect
Mar 31, 2026
Merged

test: migrate prompt tests to HTTP mock LLM server#20304
kitlangton merged 14 commits into
devfrom
refactor/llm-server-effect

Conversation

@kitlangton

@kitlangton kitlangton commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • replace the Bun-based mock LLM with an Effect HTTP mock server and migrate the prompt/session tests to run against the HTTP-backed provider path
  • add it.live(...) support to the shared Effect test helper, consolidate the prompt provider coverage into prompt-effect.test.ts, and add regression coverage around InstanceState context behavior
  • propagate InstanceRef through Effect-backed runtime boundaries and deferred database callbacks so prompt/session flows keep the correct instance context after async escapes
  • break the db -> installation -> run-service -> instance -> project -> db cycle by extracting installation metadata into a leaf module used by db.ts
  • make scoped test tempdir cleanup more robust on Windows by using the retrying cleanup path already used by the async tmpdir fixture

Verification

  • bun typecheck
  • bun test test/session/prompt-effect.test.ts test/effect/instance-state.test.ts
  • bun run build (from packages/sdk/js)
  • PR CI
@kitlangton
kitlangton force-pushed the refactor/llm-server-effect branch 2 times, most recently from dbc9bae to 0c5e66a Compare March 31, 2026 18:30
Comment thread packages/opencode/src/effect/instance-state.ts Outdated
Comment thread packages/opencode/src/effect/instance-bind.ts Outdated
Comment thread packages/opencode/src/effect/instance-state.ts Outdated
Comment thread packages/opencode/src/effect/instance-state.ts Outdated
Comment thread packages/opencode/src/effect/instance-state.ts
Comment thread packages/opencode/src/effect/run-service.ts Outdated
Comment thread packages/opencode/src/installation/index.ts
Comment thread packages/opencode/src/session/index.ts Outdated
Comment thread packages/opencode/src/session/prompt.ts
Comment thread packages/opencode/test/session/prompt-provider.test.ts Outdated
@kitlangton
kitlangton marked this pull request as ready for review March 31, 2026 20:37
- Replace Bun.serve with Effect HTTP server using NodeHttpServer
- Add TestLLMServer service for mock LLM testing with SSE responses
- Update prompt-provider.test.ts to use testEffect pattern with provideTmpdirInstance
- Remove redundant test/fixture/effect.ts (using existing test/lib/effect.ts instead)
Default the shared effect test helper to support both test-clock and live execution, and switch the current opencode effect tests to the live path for real integration behavior.
Switch the basic assistant reply prompt-effect test to the HTTP-backed mock LLM server while keeping the more stream-sensitive cases on the in-process fake for now.
Add fixture support for tmpdir-backed mock server tests, extend the mock LLM server DSL for failure and hanging cases, and migrate the next prompt tests to the HTTP-backed path.
Migrate the next prompt-effect cases to the HTTP-backed mock server path, keep the shell handoff cases on short live timeouts, and leave the stream-failure case on the in-process fake until the server DSL matches it.
…ceRef

Add a ServiceMap.Reference that carries InstanceContext through the
Effect service graph so child fibers retain instance context even when
resumed by external I/O events outside the ALS boundary.

- Add InstanceRef to instance-state.ts; InstanceState.get/has/invalidate
  try the Reference first, fall back to ALS
- makeRuntime automatically captures ALS into InstanceRef at the boundary
- provideInstance (test fixture) sets InstanceRef for Effect.runPromiseWith
- Remove all redundant provideInstance(dir) wrappers from prompt tests
- Fix test/lib/effect.ts type params (drop unnecessary S/T generics)
Migrate 16 direct Instance.directory/worktree/project reads inside
Effect code to use InstanceState.directory/context helpers that check
the InstanceRef first and fall back to ALS.

- Export InstanceState.directory and InstanceState.context helpers
- bus/index.ts: GlobalBus.emit uses InstanceState.directory
- session/prompt.ts: 5 callsites migrated to InstanceState.context
- session/index.ts: 4 callsites migrated
- session/compaction.ts: 1 callsite migrated
- config/config.ts: 1 callsite migrated
- format/index.ts: 1 callsite migrated
- worktree/index.ts: 5 callsites migrated
- storage/db.ts: Database.effect preserves Instance ALS via Instance.bind
- test/lib/llm-server.ts: add wait/hold/fail SSE stream support
- Remove most provideInstance(dir) wrappers from prompt tests
  (5 remain due to Instance.state sync ALS dependency)
- makeRuntime.provide reads InstanceRef from current Effect fiber when
  ALS is unavailable, bridging static function calls (like Bus.publish)
  that create new fibers from inside Effect code
- Database.transaction preserves Instance ALS via Instance.bind on the
  bun:sqlite transaction callback (native fn loses ALS)
- Instance.restore helper for bridging Effect→sync code with ALS
- InstanceState.withALS bridges InstanceRef back to ALS for sync callers
- prompt.ts: InstructionPrompt.clear wrapped with withALS
- Remove ALL provideInstance(dir) wrappers from prompt-effect tests
@kitlangton
kitlangton force-pushed the refactor/llm-server-effect branch from 362dab6 to 90469bb Compare March 31, 2026 20:42
@kitlangton
kitlangton merged commit 0c03a3e into dev Mar 31, 2026
8 checks passed
@kitlangton
kitlangton deleted the refactor/llm-server-effect branch March 31, 2026 23:14
jeromelau pushed a commit to jeromelau/opencode that referenced this pull request Apr 2, 2026
vicary pushed a commit to vicary/opencode that referenced this pull request Apr 6, 2026
balcsida pushed a commit to balcsida/opencode that referenced this pull request Apr 8, 2026
byeonghwankwak1 added a commit to team-monolith-product/enk-opencode that referenced this pull request Apr 10, 2026
Effect.promise(setTimeout) 기반 waitMs는 Effect 스케줄러와 협조하지
않아 CI에서 forked fiber가 50ms 안에 진행되지 못해 race가 발생.
upstream PR anomalyco#20304 과 동일하게 모든 waitMs(N)을
Effect.sleep(N)으로 변환하고 헬퍼 정의 삭제.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
byeonghwankwak1 added a commit to team-monolith-product/enk-opencode that referenced this pull request Apr 10, 2026
Effect.promise(setTimeout) 기반 waitMs는 Effect 스케줄러와 협조하지
않아 CI에서 forked fiber가 50ms 안에 진행되지 못해 race가 발생.
upstream PR anomalyco#20304 과 동일하게 모든 waitMs(N)을
Effect.sleep(N)으로 변환하고 헬퍼 정의 삭제.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
xywsxp pushed a commit to xywsxp/opencode that referenced this pull request Apr 24, 2026
Rwanbt pushed a commit to Rwanbt/unifia that referenced this pull request May 5, 2026
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
AIALRA-0 pushed a commit to AIALRA-0/opencode-turn-engine that referenced this pull request Jun 10, 2026
avion23 pushed a commit to avion23/opencode that referenced this pull request Jun 10, 2026
Rwanbt pushed a commit to Rwanbt/unifia that referenced this pull request Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment