The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { expect, it } from "@effect/vitest"; |
| 2 | import { |
| 3 | EnvironmentId, |
| 4 | type EnvironmentThemeFile, |
| 5 | ProviderInstanceId, |
| 6 | ThreadId, |
| 7 | } from "@t3tools/contracts"; |
| 8 | import * as Effect from "effect/Effect"; |
| 9 | import * as Layer from "effect/Layer"; |
| 10 | import * as Stream from "effect/Stream"; |
| 11 | |
| 12 | import { |
| 13 | EnvironmentThemeRefusedError, |
| 14 | EnvironmentThemeService, |
| 15 | } from "../../../environmentTheme.ts"; |
| 16 | import * as ThreadCommandExecutor from "../../../orchestration-v2/ThreadCommandExecutor.ts"; |
| 17 | import * as ThreadManagement from "../../../orchestration-v2/ThreadManagementService.ts"; |
| 18 | import * as McpInvocationContext from "../../McpInvocationContext.ts"; |
| 19 | import * as McpToolAccess from "../../McpToolAccess.ts"; |
| 20 | import { liveThreadShell } from "../../McpToolAccess.testkit.ts"; |
| 21 | import * as ThemeHandlers from "./handlers.ts"; |
| 22 | import { ThemeToolkit } from "./tools.ts"; |
| 23 | |
| 24 | const environmentId = EnvironmentId.make("environment:theme"); |
| 25 | const threadId = ThreadId.make("thread:theme"); |
| 26 | const AGENT_THEME = { |
| 27 | name: "Agent Look", |
| 28 | appearance: "dark", |
| 29 | canvas: "#101010", |
| 30 | accent: "#7aa2f7", |
| 31 | css: "[data-chat-header] { border-bottom: 1px solid red; }", |
| 32 | } satisfies EnvironmentThemeFile; |
| 33 | |
| 34 | it.effect("applies the theme through the service and reports a refusal as an invalid request", () => |
| 35 | Effect.gen(function* () { |
| 36 | const layerDependencies = Layer.mergeAll( |
| 37 | ThreadCommandExecutor.layer, |
| 38 | Layer.succeed(McpInvocationContext.McpInvocationContext, { |
| 39 | environmentId, |
| 40 | requestNamespace: "provider:theme", |
| 41 | thread: { |
| 42 | threadId, |
| 43 | providerSessionId: "provider:theme", |
| 44 | providerInstanceId: ProviderInstanceId.make("codex"), |
| 45 | }, |
| 46 | client: undefined, |
| 47 | capabilities: new Set(["orchestration" as const]), |
| 48 | issuedAt: 0, |
| 49 | }), |
| 50 | Layer.mock(ThreadManagement.ThreadManagementService)({ |
| 51 | getThreadShell: () => Effect.succeed(liveThreadShell(threadId)), |
| 52 | }), |
| 53 | Layer.mock(EnvironmentThemeService)({ |
| 54 | apply: (input) => |
| 55 | "themeId" in input && input.themeId === "missing" |
| 56 | ? Effect.fail( |
| 57 | new EnvironmentThemeRefusedError({ |
| 58 | themeId: input.themeId, |
| 59 | problem: "is not a built-in or published theme.", |
| 60 | }), |
| 61 | ) |
| 62 | : Effect.void, |
| 63 | }), |
| 64 | ); |
| 65 | yield* Effect.gen(function* () { |
| 66 | const toolkit = yield* ThemeToolkit; |
| 67 | const call = (params: Parameters<typeof toolkit.handle<"t3_theme_set">>[1]) => |
| 68 | toolkit.handle("t3_theme_set", params).pipe( |
| 69 | Stream.unwrap, |
| 70 | Stream.runCollect, |
| 71 | Effect.map((parts) => parts.at(-1)?.result), |
| 72 | ); |
| 73 | |
| 74 | expect(yield* call({ themeId: "agent-look", theme: AGENT_THEME })).toEqual({ |
| 75 | themeId: "agent-look", |
| 76 | published: true, |
| 77 | }); |
| 78 | expect(yield* call({ themeId: "grove" })).toEqual({ themeId: "grove", published: false }); |
| 79 | expect(yield* call({ appearance: "dark" })).toEqual({ |
| 80 | appearance: "dark", |
| 81 | published: false, |
| 82 | }); |
| 83 | expect(yield* call({ theme: AGENT_THEME })).toMatchObject({ code: "invalid_request" }); |
| 84 | expect(yield* call({})).toMatchObject({ code: "invalid_request" }); |
| 85 | expect(yield* call({ themeId: "missing" })).toMatchObject({ |
| 86 | code: "invalid_request", |
| 87 | message: 'Theme "missing" is not a built-in or published theme.', |
| 88 | }); |
| 89 | }).pipe( |
| 90 | Effect.provide( |
| 91 | McpToolAccess.HandlersLayer.layer(ThemeHandlers.layer).pipe( |
| 92 | Layer.provideMerge(layerDependencies), |
| 93 | ), |
| 94 | ), |
| 95 | ); |
| 96 | }), |
| 97 | ); |