|
| 1 | +import { assert, it } from "@effect/vitest"; |
| 2 | +import { ProviderDriverKind } from "@t3tools/contracts"; |
| 3 | +import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator"; |
| 4 | +import * as Effect from "effect/Effect"; |
| 5 | +import * as Layer from "effect/Layer"; |
| 6 | +import * as SqlClient from "effect/sql/SqlClient"; |
| 7 | + |
| 8 | +import * as SqlitePersistence from "../persistence/Sqlite.ts"; |
| 9 | +import { layerIdAllocator } from "./ProviderOrchestrationAdapterInfrastructure.ts"; |
| 10 | + |
| 11 | +it.effect("subagent threads stored under a legacy id keep it when re-derived", () => |
| 12 | + Effect.gen(function* () { |
| 13 | + const stored = { |
| 14 | + driver: ProviderDriverKind.make("claudeAgent"), |
| 15 | + nativeThreadId: "parent:task-1", |
| 16 | + }; |
| 17 | + const legacyId = IdAllocator.deriveThreadFromProviderThread(stored); |
| 18 | + const layerStored = Layer.effectDiscard( |
| 19 | + Effect.gen(function* () { |
| 20 | + const sql = yield* SqlClient.SqlClient; |
| 21 | + yield* sql` |
| 22 | + INSERT INTO orchestration_v2_projection_threads ( |
| 23 | + thread_id, project_id, title, default_provider, runtime_mode, interaction_mode, |
| 24 | + created_at, updated_at, payload_json |
| 25 | + ) VALUES ( |
| 26 | + ${legacyId}, 'project-1', 'Subagent', 'claudeAgent', 'full-access', 'default', |
| 27 | + '2026-01-01T00:00:00.000Z', '2026-01-01T00:00:00.000Z', '{}' |
| 28 | + ) |
| 29 | + `; |
| 30 | + }), |
| 31 | + ).pipe(Layer.provideMerge(SqlitePersistence.layerMemory)); |
| 32 | + const ids = yield* IdAllocator.IdAllocatorV2.pipe( |
| 33 | + Effect.provide(layerIdAllocator.pipe(Layer.provide(layerStored))), |
| 34 | + ); |
| 35 | + |
| 36 | + assert.strictEqual(ids.derive.subagentThread(stored), legacyId); |
| 37 | + assert.match( |
| 38 | + ids.derive.subagentThread({ ...stored, nativeThreadId: "parent:task-2" }), |
| 39 | + /^thread:subagent:[0-9a-f]{16}$/, |
| 40 | + ); |
| 41 | + }), |
| 42 | +); |
0 commit comments