Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions packages/opencode/test/effect/runner.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect } from "bun:test"
import { Cause, Deferred, Effect, Exit, Fiber, Latch, Ref, Scope } from "effect"
import { Runner } from "@/effect/runner"
import { TestClock } from "effect/testing"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: TestClock is imported from the wrong module path. The codebase uses effect/testing/TestClock (see test/lib/effect.ts and test/session/reasoning-watchdog.test.ts), not effect/testing. This likely fails to compile because TestClock.adjust is not exported from effect/testing.

Suggested change
import { TestClock } from "effect/testing"
import * as TestClock from "effect/testing/TestClock"

import { it } from "../lib/effect"

const waitForState = <A, E>(runner: Runner.Runner<A, E>, tag: Runner.State<A, E>["_tag"]) =>
Expand Down Expand Up @@ -331,9 +332,9 @@ describe("Runner", () => {
}),
)

// Pure fiber/latch handoff: use TestClock rather than a wall-clock readiness race.
// Advance the readiness deadline so a missing ready signal fails without a live-clock race.
it.effect(
"cancel does not mask shell defects",
"cancel preserves a shell finalizer defect",
Effect.gen(function* () {
const s = yield* Scope.Scope
const runner = Runner.make<string>(s, { onInterrupt: Effect.succeed("interrupted") })
Expand All @@ -348,7 +349,10 @@ describe("Runner", () => {
ready,
)
.pipe(Effect.forkChild)
yield* ready.await.pipe(Effect.timeout("250 millis"))
const readiness = yield* ready.await.pipe(Effect.timeout("250 millis"), Effect.forkChild)
yield* Effect.yieldNow
yield* TestClock.adjust("250 millis")
yield* Fiber.join(readiness)

yield* runner.cancel
const exit = yield* Fiber.await(sh)
Expand All @@ -357,6 +361,52 @@ describe("Runner", () => {
}),
)

it.effect(
"cancel preserves a mixed interrupt and shell defect cause",
Effect.gen(function* () {
const s = yield* Scope.Scope
const runner = Runner.make<string>(s, { onInterrupt: Effect.succeed("interrupted") })
const ready = yield* Latch.make()
const cause = Cause.combine(Cause.interrupt(), Cause.die("mixed boom"))
const sh = yield* runner
.startShell(ready.open.pipe(Effect.andThen(Effect.never), Effect.onExit(() => Effect.failCause(cause))), ready)
.pipe(Effect.forkChild)
const readiness = yield* ready.await.pipe(Effect.timeout("250 millis"), Effect.forkChild)
yield* Effect.yieldNow
yield* TestClock.adjust("250 millis")
yield* Fiber.join(readiness)
yield* runner.cancel
const exit = yield* Fiber.await(sh)
expect(Exit.isFailure(exit)).toBe(true)
if (Exit.isFailure(exit)) {
expect(Cause.hasInterrupts(exit.cause)).toBe(true)
expect(Cause.hasDies(exit.cause)).toBe(true)
expect(Cause.squash(exit.cause)).toBe("mixed boom")
}
}),
)

it.effect(
"cancel maps a mixed interrupt and typed shell failure to the fallback",
Effect.gen(function* () {
const s = yield* Scope.Scope
const runner = Runner.make<string, string>(s, { onInterrupt: Effect.succeed("interrupted") })
const ready = yield* Latch.make()
const cause = Cause.combine(Cause.interrupt(), Cause.fail("shell failure"))
const sh = yield* runner
.startShell(ready.open.pipe(Effect.andThen(Effect.never), Effect.onExit(() => Effect.failCause(cause))), ready)
.pipe(Effect.forkChild)
const readiness = yield* ready.await.pipe(Effect.timeout("250 millis"), Effect.forkChild)
yield* Effect.yieldNow
yield* TestClock.adjust("250 millis")
yield* Fiber.join(readiness)
yield* runner.cancel
const exit = yield* Fiber.await(sh)
expect(Exit.isSuccess(exit)).toBe(true)
if (Exit.isSuccess(exit)) expect(exit.value).toBe("interrupted")
}),
)

// --- shell→run handoff ---

it.live(
Expand Down
Loading