|
| 1 | +/** |
| 2 | + * Full SessionPrompt Effect layer stack with real LLM (not TestLLM). |
| 3 | + * |
| 4 | + * Use this when tests need to exercise the complete prompt pipeline |
| 5 | + * (resolveTools, tool execution, processor event handling) through |
| 6 | + * the real AI SDK streamText against a fake HTTP server. |
| 7 | + * |
| 8 | + * Service stubs (MCP, LSP, FileTime) are no-ops — they satisfy the |
| 9 | + * layer graph without requiring real servers. |
| 10 | + * |
| 11 | + * Usage: |
| 12 | + * import { env } from "../fixture/prompt-layers" |
| 13 | + * const it = testEffect(env) |
| 14 | + */ |
| 15 | + |
| 16 | +import { NodeFileSystem } from "@effect/platform-node" |
| 17 | +import { Effect, Layer } from "effect" |
| 18 | +import { Agent as AgentSvc } from "../../src/agent/agent" |
| 19 | +import { Bus } from "../../src/bus" |
| 20 | +import { Command } from "../../src/command" |
| 21 | +import { Config } from "../../src/config/config" |
| 22 | +import { FileTime } from "../../src/file/time" |
| 23 | +import { AppFileSystem } from "../../src/filesystem" |
| 24 | +import { LSP } from "../../src/lsp" |
| 25 | +import { MCP } from "../../src/mcp" |
| 26 | +import { Permission } from "../../src/permission" |
| 27 | +import { Plugin } from "../../src/plugin" |
| 28 | +import { Session } from "../../src/session" |
| 29 | +import { LLM } from "../../src/session/llm" |
| 30 | +import { SessionCompaction } from "../../src/session/compaction" |
| 31 | +import { SessionProcessor } from "../../src/session/processor" |
| 32 | +import { SessionPrompt } from "../../src/session/prompt" |
| 33 | +import { SessionStatus } from "../../src/session/status" |
| 34 | +import { Snapshot } from "../../src/snapshot" |
| 35 | +import { ToolRegistry } from "../../src/tool/registry" |
| 36 | +import { Truncate } from "../../src/tool/truncate" |
| 37 | +import * as CrossSpawnSpawner from "../../src/effect/cross-spawn-spawner" |
| 38 | + |
| 39 | +// --- Service stubs --- |
| 40 | + |
| 41 | +const mcp = Layer.succeed( |
| 42 | + MCP.Service, |
| 43 | + MCP.Service.of({ |
| 44 | + status: () => Effect.succeed({}), |
| 45 | + clients: () => Effect.succeed({}), |
| 46 | + tools: () => Effect.succeed({}), |
| 47 | + prompts: () => Effect.succeed({}), |
| 48 | + resources: () => Effect.succeed({}), |
| 49 | + add: () => Effect.succeed({ status: { status: "disabled" as const } }), |
| 50 | + connect: () => Effect.void, |
| 51 | + disconnect: () => Effect.void, |
| 52 | + getPrompt: () => Effect.succeed(undefined), |
| 53 | + readResource: () => Effect.succeed(undefined), |
| 54 | + startAuth: () => Effect.die("unexpected MCP auth"), |
| 55 | + authenticate: () => Effect.die("unexpected MCP auth"), |
| 56 | + finishAuth: () => Effect.die("unexpected MCP auth"), |
| 57 | + removeAuth: () => Effect.void, |
| 58 | + supportsOAuth: () => Effect.succeed(false), |
| 59 | + hasStoredTokens: () => Effect.succeed(false), |
| 60 | + getAuthStatus: () => Effect.succeed("not_authenticated" as const), |
| 61 | + }), |
| 62 | +) |
| 63 | + |
| 64 | +const lsp = Layer.succeed( |
| 65 | + LSP.Service, |
| 66 | + LSP.Service.of({ |
| 67 | + init: () => Effect.void, |
| 68 | + status: () => Effect.succeed([]), |
| 69 | + hasClients: () => Effect.succeed(false), |
| 70 | + touchFile: () => Effect.void, |
| 71 | + diagnostics: () => Effect.succeed({}), |
| 72 | + hover: () => Effect.succeed(undefined), |
| 73 | + definition: () => Effect.succeed([]), |
| 74 | + references: () => Effect.succeed([]), |
| 75 | + implementation: () => Effect.succeed([]), |
| 76 | + documentSymbol: () => Effect.succeed([]), |
| 77 | + workspaceSymbol: () => Effect.succeed([]), |
| 78 | + prepareCallHierarchy: () => Effect.succeed([]), |
| 79 | + incomingCalls: () => Effect.succeed([]), |
| 80 | + outgoingCalls: () => Effect.succeed([]), |
| 81 | + }), |
| 82 | +) |
| 83 | + |
| 84 | +const filetime = Layer.succeed( |
| 85 | + FileTime.Service, |
| 86 | + FileTime.Service.of({ |
| 87 | + read: () => Effect.void, |
| 88 | + get: () => Effect.succeed(undefined), |
| 89 | + assert: () => Effect.void, |
| 90 | + withLock: (_filepath, fn) => Effect.promise(fn), |
| 91 | + }), |
| 92 | +) |
| 93 | + |
| 94 | +// --- Layer composition --- |
| 95 | + |
| 96 | +const status = SessionStatus.layer.pipe(Layer.provideMerge(Bus.layer)) |
| 97 | +const infra = Layer.mergeAll(NodeFileSystem.layer, CrossSpawnSpawner.defaultLayer) |
| 98 | +const deps = Layer.mergeAll( |
| 99 | + Session.defaultLayer, |
| 100 | + Snapshot.defaultLayer, |
| 101 | + AgentSvc.defaultLayer, |
| 102 | + Command.defaultLayer, |
| 103 | + Permission.layer, |
| 104 | + Plugin.defaultLayer, |
| 105 | + Config.defaultLayer, |
| 106 | + filetime, |
| 107 | + lsp, |
| 108 | + mcp, |
| 109 | + AppFileSystem.defaultLayer, |
| 110 | + status, |
| 111 | + LLM.defaultLayer, |
| 112 | +).pipe(Layer.provideMerge(infra)) |
| 113 | +const registry = ToolRegistry.layer.pipe(Layer.provideMerge(deps)) |
| 114 | +const trunc = Truncate.layer.pipe(Layer.provideMerge(deps)) |
| 115 | +const proc = SessionProcessor.layer.pipe(Layer.provideMerge(deps)) |
| 116 | +const compact = SessionCompaction.layer.pipe(Layer.provideMerge(proc), Layer.provideMerge(deps)) |
| 117 | + |
| 118 | +/** Full SessionPrompt layer with real LLM and no-op stubs for MCP/LSP/FileTime */ |
| 119 | +export const env = SessionPrompt.layer.pipe( |
| 120 | + Layer.provideMerge(compact), |
| 121 | + Layer.provideMerge(proc), |
| 122 | + Layer.provideMerge(registry), |
| 123 | + Layer.provideMerge(trunc), |
| 124 | + Layer.provideMerge(deps), |
| 125 | +) |
0 commit comments