|
1 | | -import { MessageId, RunId, TurnItemId, type OrchestrationV2TurnItem } from "@t3tools/contracts"; |
| 1 | +import { |
| 2 | + EnvironmentId, |
| 3 | + MessageId, |
| 4 | + RunId, |
| 5 | + TurnItemId, |
| 6 | + type OrchestrationV2TurnItem, |
| 7 | +} from "@t3tools/contracts"; |
2 | 8 | import { describe, expect, it } from "@effect/vitest"; |
3 | 9 | import * as DateTime from "effect/DateTime"; |
| 10 | +import * as Option from "effect/Option"; |
| 11 | +import { AsyncResult, Atom, AtomRegistry } from "effect/reactivity"; |
4 | 12 |
|
5 | 13 | import { v2Now, v2Projection, v2ThreadId } from "./orchestrationV2TestFixtures.ts"; |
6 | | -import { sameThreadStructure } from "./threadDetail.ts"; |
| 14 | +import { createEnvironmentThreadDetailAtoms, sameThreadStructure } from "./threadDetail.ts"; |
| 15 | +import { EMPTY_ENVIRONMENT_THREAD_STATE } from "./threadState.ts"; |
7 | 16 |
|
8 | 17 | const later = DateTime.makeUnsafe("2026-06-20T00:00:01.000Z"); |
9 | 18 |
|
@@ -82,3 +91,30 @@ describe("sameThreadStructure", () => { |
82 | 91 | expect(sameThreadStructure(before, { ...before, runs: [] })).toBe(false); |
83 | 92 | }); |
84 | 93 | }); |
| 94 | + |
| 95 | +describe("lastVisitedAtAtom", () => { |
| 96 | + it("follows a visit mark the quiet thread holds through", () => { |
| 97 | + const projection = withItem(assistant); |
| 98 | + const state = Atom.make( |
| 99 | + AsyncResult.success({ ...EMPTY_ENVIRONMENT_THREAD_STATE, data: Option.some(projection) }), |
| 100 | + ); |
| 101 | + const details = createEnvironmentThreadDetailAtoms(() => state); |
| 102 | + const ref = { environmentId: EnvironmentId.make("env"), threadId: v2ThreadId }; |
| 103 | + const registry = AtomRegistry.make(); |
| 104 | + const unmountQuiet = registry.mount(details.quietThreadAtom(ref)); |
| 105 | + const unmountVisit = registry.mount(details.lastVisitedAtAtom(ref)); |
| 106 | + const quietBefore = registry.get(details.quietThreadAtom(ref)); |
| 107 | + |
| 108 | + const visited = { ...projection, thread: { ...projection.thread, lastVisitedAt: later } }; |
| 109 | + registry.set( |
| 110 | + state, |
| 111 | + AsyncResult.success({ ...EMPTY_ENVIRONMENT_THREAD_STATE, data: Option.some(visited) }), |
| 112 | + ); |
| 113 | + |
| 114 | + expect(registry.get(details.quietThreadAtom(ref))).toBe(quietBefore); |
| 115 | + expect(registry.get(details.lastVisitedAtAtom(ref))).toBe(later); |
| 116 | + unmountQuiet(); |
| 117 | + unmountVisit(); |
| 118 | + registry.dispose(); |
| 119 | + }); |
| 120 | +}); |
0 commit comments