The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | import { EnvironmentId, ThreadId } from "@t3tools/contracts"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import { AtomRegistry } from "effect/reactivity"; |
| 5 | |
| 6 | import { reviewTurnDiffsBySectionId } from "../features/review/reviewModel"; |
| 7 | import { lastReviewTurnDiffsAtom, recordReviewTurnDiffAnswer } from "./reviewTurnDiffs"; |
| 8 | |
| 9 | const environmentId = EnvironmentId.make("env-1"); |
| 10 | const threadId = ThreadId.make("thread-1"); |
| 11 | |
| 12 | const answer = ( |
| 13 | registry: AtomRegistry.AtomRegistry, |
| 14 | range: { fromTurnCount: number; toTurnCount: number; diff: string }, |
| 15 | ignoreWhitespace = false, |
| 16 | ) => |
| 17 | recordReviewTurnDiffAnswer( |
| 18 | { environmentId, input: { ignoreWhitespace } }, |
| 19 | { threadId, ...range }, |
| 20 | registry, |
| 21 | ); |
| 22 | |
| 23 | describe("recordReviewTurnDiffAnswer", () => { |
| 24 | it.effect("keeps loaded turn diffs for review after their queries are gone", () => |
| 25 | Effect.gen(function* () { |
| 26 | const registry = AtomRegistry.make(); |
| 27 | yield* answer(registry, { fromTurnCount: 0, toTurnCount: 1, diff: "turn one" }); |
| 28 | yield* answer(registry, { fromTurnCount: 1, toTurnCount: 2, diff: "turn two" }); |
| 29 | |
| 30 | // A disconnected sheet mounts no turn query; every loaded turn still has its diff. |
| 31 | const cached = registry.get(lastReviewTurnDiffsAtom(environmentId, threadId)); |
| 32 | expect( |
| 33 | reviewTurnDiffsBySectionId( |
| 34 | [{ checkpointTurnCount: 1 }, { checkpointTurnCount: 2 }, { checkpointTurnCount: 3 }], |
| 35 | cached, |
| 36 | ), |
| 37 | ).toEqual({ "turn:1": "turn one", "turn:2": "turn two", "turn:3": undefined }); |
| 38 | registry.dispose(); |
| 39 | }), |
| 40 | ); |
| 41 | |
| 42 | it.effect("ignores ranges and whitespace-ignoring reads, which no review section shows", () => |
| 43 | Effect.gen(function* () { |
| 44 | const registry = AtomRegistry.make(); |
| 45 | yield* answer(registry, { fromTurnCount: 0, toTurnCount: 3, diff: "whole thread" }); |
| 46 | yield* answer(registry, { fromTurnCount: 1, toTurnCount: 2, diff: "no whitespace" }, true); |
| 47 | |
| 48 | expect(registry.get(lastReviewTurnDiffsAtom(environmentId, threadId))).toEqual({}); |
| 49 | registry.dispose(); |
| 50 | }), |
| 51 | ); |
| 52 | }); |