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, 03:37 UTC
| 1 | import { assert, it } from "@effect/vitest"; |
| 2 | import { |
| 3 | CommandId, |
| 4 | EventId, |
| 5 | ProjectId, |
| 6 | ProviderInstanceId, |
| 7 | RunId, |
| 8 | ThreadId, |
| 9 | type OrchestrationV2AppThread, |
| 10 | } from "@t3tools/contracts"; |
| 11 | import * as DateTime from "effect/DateTime"; |
| 12 | import * as Effect from "effect/Effect"; |
| 13 | import * as Layer from "effect/Layer"; |
| 14 | |
| 15 | import * as Sqlite from "../persistence/Sqlite.ts"; |
| 16 | import * as EventSink from "./EventSink.ts"; |
| 17 | import * as EventStore from "./EventStore.ts"; |
| 18 | import * as ProjectionStore from "./ProjectionStore.ts"; |
| 19 | |
| 20 | const layer = EventSink.layer.pipe( |
| 21 | Layer.provideMerge(Layer.merge(EventStore.layer, ProjectionStore.layer)), |
| 22 | Layer.provide(Sqlite.layerMemory), |
| 23 | ); |
| 24 | |
| 25 | it.effect("rejects a planned fork whose source was deleted before it committed", () => |
| 26 | Effect.gen(function* () { |
| 27 | const sink = yield* EventSink.EventSinkV2; |
| 28 | const projections = yield* ProjectionStore.ProjectionStoreV2; |
| 29 | const now = yield* DateTime.now; |
| 30 | const sourceId = ThreadId.make("fork-source"); |
| 31 | const targetId = ThreadId.make("fork-target"); |
| 32 | const providerInstanceId = ProviderInstanceId.make("codex"); |
| 33 | const source: OrchestrationV2AppThread = { |
| 34 | id: sourceId, |
| 35 | projectId: ProjectId.make("project"), |
| 36 | title: "Source", |
| 37 | createdBy: "user", |
| 38 | creationSource: "web", |
| 39 | providerInstanceId, |
| 40 | modelSelection: { instanceId: providerInstanceId, model: "gpt-5" }, |
| 41 | runtimeMode: "full-access", |
| 42 | interactionMode: "default", |
| 43 | branch: null, |
| 44 | worktreePath: null, |
| 45 | activeProviderThreadId: null, |
| 46 | lineage: { rootThreadId: sourceId, parentThreadId: null, relationshipToParent: null }, |
| 47 | forkedFrom: null, |
| 48 | createdAt: now, |
| 49 | updatedAt: now, |
| 50 | archivedAt: null, |
| 51 | deletedAt: null, |
| 52 | settledOverride: null, |
| 53 | settledAt: null, |
| 54 | snoozedUntil: null, |
| 55 | snoozedAt: null, |
| 56 | lastVisitedAt: null, |
| 57 | }; |
| 58 | yield* sink.write({ |
| 59 | events: [ |
| 60 | { |
| 61 | id: EventId.make("source-created"), |
| 62 | type: "thread.created", |
| 63 | threadId: sourceId, |
| 64 | occurredAt: now, |
| 65 | payload: source, |
| 66 | }, |
| 67 | ], |
| 68 | }); |
| 69 | const plannedFork = { |
| 70 | commandId: CommandId.make("fork"), |
| 71 | commandType: "thread.fork", |
| 72 | threadId: targetId, |
| 73 | acceptedAt: now, |
| 74 | effects: [], |
| 75 | events: [ |
| 76 | { |
| 77 | id: EventId.make("fork-created"), |
| 78 | type: "thread.created" as const, |
| 79 | threadId: targetId, |
| 80 | occurredAt: now, |
| 81 | payload: { |
| 82 | ...source, |
| 83 | id: targetId, |
| 84 | forkedFrom: { type: "run" as const, threadId: sourceId, runId: RunId.make("run") }, |
| 85 | }, |
| 86 | }, |
| 87 | ], |
| 88 | }; |
| 89 | yield* sink.write({ |
| 90 | events: [ |
| 91 | { |
| 92 | id: EventId.make("source-deleted"), |
| 93 | type: "thread.deleted", |
| 94 | threadId: sourceId, |
| 95 | occurredAt: now, |
| 96 | payload: { ...source, deletedAt: now }, |
| 97 | }, |
| 98 | ], |
| 99 | }); |
| 100 | const rejected = yield* sink.commitCommand(plannedFork); |
| 101 | assert.equal(rejected.receipt.status, "rejected"); |
| 102 | assert.isFalse(rejected.committed); |
| 103 | const replayed = yield* sink.commitCommand(plannedFork); |
| 104 | assert.deepEqual(replayed.receipt, rejected.receipt); |
| 105 | assert.isFalse(replayed.committed); |
| 106 | const missing = yield* projections.getThread(targetId).pipe(Effect.flip); |
| 107 | assert.instanceOf(missing, ProjectionStore.ProjectionStoreThreadNotFoundError); |
| 108 | }).pipe(Effect.provide(layer)), |
| 109 | ); |