- Map fork and merge-back turns into stored handoffs and transfer resolutions - Add shell snapshot projection support plus coverage tests - Update replay fixtures and web contracts for the new turn flow
129 lines
3.7 KiB
TypeScript
129 lines
3.7 KiB
TypeScript
import { assert, it } from "@effect/vitest";
|
|
import { EventId, ProjectId, ThreadId } from "@t3tools/contracts";
|
|
import { DateTime, Effect, Layer } from "effect";
|
|
import * as SqlClient from "effect/unstable/sql/SqlClient";
|
|
|
|
import { SqlitePersistenceMemory } from "../persistence/Layers/Sqlite.ts";
|
|
import { ProjectionStoreV2, layer as projectionStoreLayer } from "./ProjectionStore.ts";
|
|
|
|
const TestLayer = Layer.mergeAll(
|
|
projectionStoreLayer.pipe(Layer.provideMerge(SqlitePersistenceMemory)),
|
|
SqlitePersistenceMemory,
|
|
);
|
|
|
|
it.layer(TestLayer)("ProjectionStoreV2", (it) => {
|
|
it.effect("builds shell snapshots without decoding full turn item payloads", () =>
|
|
Effect.gen(function* () {
|
|
const projectionStore = yield* ProjectionStoreV2;
|
|
const sql = yield* SqlClient.SqlClient;
|
|
const now = yield* DateTime.now;
|
|
const nowIso = DateTime.formatIso(now);
|
|
const threadId = ThreadId.make("thread:projection-shell-stale-item");
|
|
const projectId = ProjectId.make("project:projection-shell");
|
|
|
|
yield* projectionStore.apply({
|
|
id: EventId.make("event:projection-shell-thread-created"),
|
|
type: "thread.created",
|
|
threadId,
|
|
occurredAt: now,
|
|
payload: {
|
|
id: threadId,
|
|
projectId,
|
|
title: "Projection shell",
|
|
defaultProvider: "codex",
|
|
modelSelection: {
|
|
provider: "codex",
|
|
model: "gpt-5.4",
|
|
},
|
|
runtimeMode: "full-access",
|
|
interactionMode: "default",
|
|
branch: null,
|
|
worktreePath: null,
|
|
activeProviderThreadId: null,
|
|
lineage: {
|
|
parentThreadId: null,
|
|
relationshipToParent: null,
|
|
rootThreadId: threadId,
|
|
},
|
|
forkedFrom: null,
|
|
createdAt: now,
|
|
updatedAt: now,
|
|
archivedAt: null,
|
|
deletedAt: null,
|
|
},
|
|
});
|
|
|
|
yield* sql`
|
|
INSERT INTO orchestration_v2_projection_turn_items (
|
|
turn_item_id,
|
|
thread_id,
|
|
run_id,
|
|
node_id,
|
|
provider_thread_id,
|
|
provider_turn_id,
|
|
parent_item_id,
|
|
ordinal,
|
|
type,
|
|
status,
|
|
updated_at,
|
|
payload_json
|
|
)
|
|
VALUES (
|
|
${"turn-item:stale-user-message"},
|
|
${threadId},
|
|
${null},
|
|
${null},
|
|
${null},
|
|
${null},
|
|
${null},
|
|
${0},
|
|
${"user_message"},
|
|
${"completed"},
|
|
${nowIso},
|
|
${JSON.stringify({
|
|
id: "turn-item:stale-user-message",
|
|
threadId,
|
|
runId: null,
|
|
nodeId: null,
|
|
providerThreadId: null,
|
|
providerTurnId: null,
|
|
nativeItemRef: null,
|
|
parentItemId: null,
|
|
ordinal: 0,
|
|
status: "completed",
|
|
title: null,
|
|
startedAt: nowIso,
|
|
completedAt: nowIso,
|
|
updatedAt: nowIso,
|
|
type: "user_message",
|
|
messageId: "message:stale-user-message",
|
|
text: "stale user message",
|
|
attachments: [],
|
|
})}
|
|
)
|
|
`;
|
|
|
|
const shell = yield* projectionStore.getShellSnapshot();
|
|
const fullProjectionExit = yield* Effect.exit(projectionStore.getThreadProjection(threadId));
|
|
|
|
assert.deepEqual(
|
|
shell.threads.map((thread) => ({
|
|
id: thread.id,
|
|
itemCount: thread.itemCount,
|
|
visibleItemCount: thread.visibleItemCount,
|
|
status: thread.status,
|
|
})),
|
|
[
|
|
{
|
|
id: threadId,
|
|
itemCount: 1,
|
|
visibleItemCount: 1,
|
|
status: "idle",
|
|
},
|
|
],
|
|
);
|
|
assert.equal(fullProjectionExit._tag, "Failure");
|
|
}),
|
|
);
|
|
});
|