Open History to see the last commit
1import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
2import { expect, it } from "@effect/vitest";
3import { EnvironmentId, ProviderInstanceId, ThreadId } from "@t3tools/contracts";
4import * as Effect from "effect/Effect";
5import * as Layer from "effect/Layer";
6
7import { OrchestratorProjectionError } from "../orchestration-v2/Orchestrator.ts";
8import * as ThreadManagement from "../orchestration-v2/ThreadManagementService.ts";
9import type * as McpInvocationContext from "./McpInvocationContext.ts";
10import * as ThreadMetadataMcp from "./ThreadMetadataMcpService.ts";
11
12const threadId = ThreadId.make("thread:metadata-caller");
13const scope: McpInvocationContext.McpInvocationScope = {
14 environmentId: EnvironmentId.make("environment:metadata-test"),
15 threadId,
16 providerSessionId: "provider-session:metadata-test",
17 providerInstanceId: ProviderInstanceId.make("codex"),
18 capabilities: new Set(["orchestration"]),
19 issuedAt: 1,
20};
21
22function serviceLayer(
23 getThreadShell: ThreadManagement.ThreadManagementService["Service"]["getThreadShell"],
24) {
25 return ThreadMetadataMcp.layer.pipe(
26 Layer.provide(
27 Layer.merge(
28 Layer.mock(ThreadManagement.ThreadManagementService)({
29 getThreadShell,
30 getThreadRecords: () => Effect.die("projection must not load after shell failure"),
31 } satisfies Partial<ThreadManagement.ThreadManagementService["Service"]>),
32 NodeCrypto.layer,
33 ),
34 ),
35 );
36}
37
38const updateCallingThread = Effect.gen(function* () {
39 const service = yield* ThreadMetadataMcp.ThreadMetadataMcpService;
40 return yield* service.update(scope, {
41 action: "rename",
42 title: "Renamed thread",
43 clientRequestId: "metadata-caller-classification",
44 });
45});
46
47it.effect("reports an absent calling thread as thread_not_found", () =>
48 Effect.gen(function* () {
49 const error = yield* updateCallingThread.pipe(
50 Effect.provide(serviceLayer(() => Effect.succeed(null))),
51 Effect.flip,
52 );
53
54 expect(error.code).toBe("thread_not_found");
55 }),
56);
57
58it.effect("keeps calling-thread storage failures as orchestration errors", () =>
59 Effect.gen(function* () {
60 const error = yield* updateCallingThread.pipe(
61 Effect.provide(
62 serviceLayer(() =>
63 Effect.fail(
64 new OrchestratorProjectionError({
65 threadId,
66 cause: new Error("storage unavailable"),
67 }),
68 ),
69 ),
70 ),
71 Effect.flip,
72 );
73
74 expect(error.code).toBe("orchestration_error");
75 }),
76);