The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Queue from "effect/Queue"; |
| 4 | import * as Stream from "effect/Stream"; |
| 5 | import * as TestClock from "effect/testing/TestClock"; |
| 6 | |
| 7 | import * as KeepAwake from "./KeepAwake.ts"; |
| 8 | |
| 9 | describe("KeepAwake.holdWhileWanted", () => { |
| 10 | it.effect("keeps one hold across a gap shorter than the grace and releases after it", () => |
| 11 | Effect.gen(function* () { |
| 12 | const wanted = yield* Queue.unbounded<boolean>(); |
| 13 | const transitions = yield* Queue.unbounded<"held" | "released">(); |
| 14 | const hold = Effect.acquireRelease(Queue.offer(transitions, "held"), () => |
| 15 | Queue.offer(transitions, "released"), |
| 16 | ).pipe(Effect.andThen(Effect.never), Effect.scoped); |
| 17 | yield* KeepAwake.holdWhileWanted(Stream.fromQueue(wanted), hold, "60 seconds").pipe( |
| 18 | Effect.forkScoped, |
| 19 | ); |
| 20 | |
| 21 | yield* Queue.offer(wanted, true); |
| 22 | expect(yield* Queue.take(transitions)).toBe("held"); |
| 23 | |
| 24 | yield* Queue.offer(wanted, false); |
| 25 | yield* TestClock.adjust("30 seconds"); |
| 26 | yield* Queue.offer(wanted, true); |
| 27 | yield* TestClock.adjust("120 seconds"); |
| 28 | expect(yield* Queue.size(transitions)).toBe(0); |
| 29 | |
| 30 | yield* Queue.offer(wanted, false); |
| 31 | yield* TestClock.adjust("120 seconds"); |
| 32 | expect(yield* Queue.take(transitions)).toBe("released"); |
| 33 | expect(yield* Queue.size(transitions)).toBe(0); |
| 34 | }), |
| 35 | ); |
| 36 | }); |