| 1 | import { assert, it } from "@effect/vitest"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as Schema from "effect/Schema"; |
| 4 | |
| 5 | import { |
| 6 | OrchestrationGetFullThreadDiffInput, |
| 7 | OrchestrationGetTurnDiffInput, |
| 8 | ThreadTurnDiff, |
| 9 | } from "./checkpointDiff.ts"; |
| 10 | |
| 11 | const decodeTurnDiffInput = Schema.decodeUnknownEffect(OrchestrationGetTurnDiffInput); |
| 12 | const decodeFullThreadDiffInput = Schema.decodeUnknownEffect(OrchestrationGetFullThreadDiffInput); |
| 13 | const decodeThreadTurnDiff = Schema.decodeUnknownEffect(ThreadTurnDiff); |
| 14 | |
| 15 | it.effect("parses turn diff input when fromTurnCount <= toTurnCount", () => |
| 16 | Effect.gen(function* () { |
| 17 | const parsed = yield* decodeTurnDiffInput({ |
| 18 | threadId: "thread-1", |
| 19 | fromTurnCount: 1, |
| 20 | toTurnCount: 2, |
| 21 | }); |
| 22 | assert.strictEqual(parsed.fromTurnCount, 1); |
| 23 | assert.strictEqual(parsed.toTurnCount, 2); |
| 24 | }), |
| 25 | ); |
| 26 | |
| 27 | it.effect("parses turn diff input with whitespace ignoring enabled", () => |
| 28 | Effect.gen(function* () { |
| 29 | const parsed = yield* decodeTurnDiffInput({ |
| 30 | threadId: "thread-1", |
| 31 | fromTurnCount: 1, |
| 32 | toTurnCount: 2, |
| 33 | ignoreWhitespace: true, |
| 34 | }); |
| 35 | assert.strictEqual(parsed.ignoreWhitespace, true); |
| 36 | }), |
| 37 | ); |
| 38 | |
| 39 | it.effect("parses full thread diff input with whitespace ignoring enabled", () => |
| 40 | Effect.gen(function* () { |
| 41 | const parsed = yield* decodeFullThreadDiffInput({ |
| 42 | threadId: "thread-1", |
| 43 | toTurnCount: 2, |
| 44 | ignoreWhitespace: true, |
| 45 | }); |
| 46 | assert.strictEqual(parsed.ignoreWhitespace, true); |
| 47 | }), |
| 48 | ); |
| 49 | |
| 50 | it.effect("rejects turn diff input when fromTurnCount > toTurnCount", () => |
| 51 | Effect.gen(function* () { |
| 52 | const result = yield* Effect.exit( |
| 53 | decodeTurnDiffInput({ |
| 54 | threadId: "thread-1", |
| 55 | fromTurnCount: 3, |
| 56 | toTurnCount: 2, |
| 57 | }), |
| 58 | ); |
| 59 | assert.strictEqual(result._tag, "Failure"); |
| 60 | }), |
| 61 | ); |
| 62 | |
| 63 | it.effect("rejects thread turn diff when fromTurnCount > toTurnCount", () => |
| 64 | Effect.gen(function* () { |
| 65 | const result = yield* Effect.exit( |
| 66 | decodeThreadTurnDiff({ |
| 67 | threadId: "thread-1", |
| 68 | fromTurnCount: 3, |
| 69 | toTurnCount: 2, |
| 70 | diff: "patch", |
| 71 | }), |
| 72 | ); |
| 73 | assert.strictEqual(result._tag, "Failure"); |
| 74 | }), |
| 75 | ); |