|
5 | 5 | EnvironmentId, |
6 | 6 | MessageId, |
7 | 7 | NodeId, |
| 8 | + type OrchestratorMcpCapabilitiesResult, |
8 | 9 | OrchestratorMcpTarget, |
9 | 10 | type OrchestrationV2ThreadShell, |
10 | 11 | type ScheduledTask, |
@@ -1156,6 +1157,176 @@ describe("OrchestratorMcpService provider resolution", () => { |
1156 | 1157 | }), |
1157 | 1158 | ); |
1158 | 1159 |
|
| 1160 | + describe("listed models", () => { |
| 1161 | + const opencodeInstanceId = ProviderInstanceId.make("opencode"); |
| 1162 | + const model = (slug: string, extra: Partial<ServerProvider["models"][number]> = {}) => ({ |
| 1163 | + slug, |
| 1164 | + name: slug, |
| 1165 | + isCustom: false, |
| 1166 | + capabilities: null, |
| 1167 | + ...extra, |
| 1168 | + }); |
| 1169 | + const opencodeSlugs = Array.from( |
| 1170 | + { length: 12 }, |
| 1171 | + (_, index) => `oc/m${String(index + 1).padStart(2, "0")}`, |
| 1172 | + ); |
| 1173 | + const catalog: ReadonlyArray<ServerProvider> = [ |
| 1174 | + { |
| 1175 | + ...providerSnapshot({ |
| 1176 | + instanceId: codexInstanceId, |
| 1177 | + driver: ProviderDriverKind.make("codex"), |
| 1178 | + }), |
| 1179 | + models: [ |
| 1180 | + model("gpt-6", { |
| 1181 | + name: "Sol", |
| 1182 | + capabilities: { |
| 1183 | + optionDescriptors: [ |
| 1184 | + { |
| 1185 | + id: "effort", |
| 1186 | + label: "Reasoning", |
| 1187 | + description: "How hard the model thinks.", |
| 1188 | + type: "select", |
| 1189 | + options: [ |
| 1190 | + { id: "low", label: "Low", description: "Fast." }, |
| 1191 | + { id: "high", label: "High", isDefault: true }, |
| 1192 | + ], |
| 1193 | + promptInjectedValues: ["high"], |
| 1194 | + }, |
| 1195 | + { id: "fastMode", label: "Fast", type: "boolean" }, |
| 1196 | + { |
| 1197 | + id: "agent", |
| 1198 | + label: "Agent", |
| 1199 | + type: "select", |
| 1200 | + options: [{ id: "build", label: "Build" }], |
| 1201 | + currentValue: "build", |
| 1202 | + }, |
| 1203 | + ], |
| 1204 | + }, |
| 1205 | + }), |
| 1206 | + model("gpt-5", { isLegacy: true }), |
| 1207 | + model("gpt-4", { isLegacy: true }), |
| 1208 | + model("gpt-3", { name: "GPT-3", isLegacy: true }), |
| 1209 | + model("my-alpha", { isCustom: true }), |
| 1210 | + ], |
| 1211 | + }, |
| 1212 | + { |
| 1213 | + ...providerSnapshot({ |
| 1214 | + instanceId: opencodeInstanceId, |
| 1215 | + driver: ProviderDriverKind.make("opencode"), |
| 1216 | + }), |
| 1217 | + models: [ |
| 1218 | + ...opencodeSlugs.map((slug) => model(slug, { isLegacy: slug === "oc/m03" })), |
| 1219 | + model("oc-custom", { isCustom: true }), |
| 1220 | + ], |
| 1221 | + }, |
| 1222 | + ]; |
| 1223 | + |
| 1224 | + const capabilitiesWith = (search?: string) => |
| 1225 | + Effect.gen(function* () { |
| 1226 | + const service = yield* OrchestratorMcpService.OrchestratorMcpService; |
| 1227 | + return yield* service.capabilities(scope, search === undefined ? {} : { search }); |
| 1228 | + }).pipe( |
| 1229 | + Effect.provide( |
| 1230 | + layerOrchestratorService.pipe( |
| 1231 | + Layer.provide( |
| 1232 | + Layer.mergeAll( |
| 1233 | + NodeServices.layer, |
| 1234 | + Layer.mock(ThreadManagementService.ThreadManagementService)({ |
| 1235 | + getThreadRecords: () => |
| 1236 | + Effect.succeed( |
| 1237 | + parentProjection([], { instanceId: codexInstanceId, model: "gpt-3" }), |
| 1238 | + ), |
| 1239 | + }), |
| 1240 | + ServerSettings.layerTest({ |
| 1241 | + favorites: [ |
| 1242 | + { provider: codexInstanceId, model: "gpt-4" }, |
| 1243 | + { provider: opencodeInstanceId, model: "oc/m10" }, |
| 1244 | + ], |
| 1245 | + providerModelPreferences: { |
| 1246 | + [opencodeInstanceId]: { hiddenModels: ["oc/m02"], modelOrder: ["oc/m12"] }, |
| 1247 | + }, |
| 1248 | + }), |
| 1249 | + providerRegistryLayer(catalog), |
| 1250 | + adapterRegistryLayer([codexInstanceId, opencodeInstanceId]), |
| 1251 | + Layer.mock(ProjectService.ProjectService)({}), |
| 1252 | + Layer.mock(SecretRequests.SecretRequests)({}), |
| 1253 | + Layer.mock(ScheduledTaskService.ScheduledTaskService)({}), |
| 1254 | + ), |
| 1255 | + ), |
| 1256 | + ), |
| 1257 | + ), |
| 1258 | + ); |
| 1259 | + |
| 1260 | + const listing = (capabilities: OrchestratorMcpCapabilitiesResult) => |
| 1261 | + capabilities.providers.map((provider) => ({ |
| 1262 | + id: provider.providerInstanceId, |
| 1263 | + models: provider.models.map((entry) => entry.id), |
| 1264 | + omitted: provider.omittedModels ?? 0, |
| 1265 | + })); |
| 1266 | + |
| 1267 | + it.effect( |
| 1268 | + "skips legacy models, lists the first 8 of large catalogs, and keeps pinned models", |
| 1269 | + () => |
| 1270 | + Effect.gen(function* () { |
| 1271 | + assert.deepEqual(listing(yield* capabilitiesWith()), [ |
| 1272 | + // gpt-4 is a favorite and gpt-3 is the caller's model; legacy gpt-5 is left out. |
| 1273 | + { id: codexInstanceId, models: ["gpt-6", "gpt-4", "gpt-3", "my-alpha"], omitted: 1 }, |
| 1274 | + { |
| 1275 | + id: opencodeInstanceId, |
| 1276 | + models: [ |
| 1277 | + "oc/m12", |
| 1278 | + "oc/m01", |
| 1279 | + "oc/m04", |
| 1280 | + "oc/m05", |
| 1281 | + "oc/m06", |
| 1282 | + "oc/m07", |
| 1283 | + "oc/m08", |
| 1284 | + "oc/m09", |
| 1285 | + "oc/m10", |
| 1286 | + "oc-custom", |
| 1287 | + ], |
| 1288 | + omitted: 2, |
| 1289 | + }, |
| 1290 | + ]); |
| 1291 | + }), |
| 1292 | + ); |
| 1293 | + |
| 1294 | + it.effect("search matches every word and caps each provider's matches", () => |
| 1295 | + Effect.gen(function* () { |
| 1296 | + assert.deepEqual(listing(yield* capabilitiesWith("GPT 5")), [ |
| 1297 | + { id: codexInstanceId, models: ["gpt-5"], omitted: 0 }, |
| 1298 | + { id: opencodeInstanceId, models: [], omitted: 0 }, |
| 1299 | + ]); |
| 1300 | + const opencode = listing(yield* capabilitiesWith("oc/m"))[1]; |
| 1301 | + assert.deepEqual(opencode, { |
| 1302 | + id: opencodeInstanceId, |
| 1303 | + models: ["oc/m12", "oc/m01", "oc/m03", "oc/m04", "oc/m05", "oc/m06", "oc/m07", "oc/m08"], |
| 1304 | + omitted: 3, |
| 1305 | + }); |
| 1306 | + }), |
| 1307 | + ); |
| 1308 | + |
| 1309 | + it.effect("describes models by id, distinct label, and option values", () => |
| 1310 | + Effect.gen(function* () { |
| 1311 | + const codex = (yield* capabilitiesWith()).providers[0]; |
| 1312 | + assert.deepEqual(codex?.models.slice(0, 4), [ |
| 1313 | + { |
| 1314 | + id: "gpt-6", |
| 1315 | + label: "Sol", |
| 1316 | + options: [ |
| 1317 | + { id: "effort", values: ["low", "high"], default: "high" }, |
| 1318 | + { id: "fastMode", values: [false, true] }, |
| 1319 | + { id: "agent", values: ["build"], default: "build" }, |
| 1320 | + ], |
| 1321 | + }, |
| 1322 | + { id: "gpt-4" }, |
| 1323 | + { id: "gpt-3" }, |
| 1324 | + { id: "my-alpha" }, |
| 1325 | + ]); |
| 1326 | + }), |
| 1327 | + ); |
| 1328 | + }); |
| 1329 | + |
1159 | 1330 | it.effect("rejects delegation to a provider without a registered adapter", () => |
1160 | 1331 | Effect.gen(function* () { |
1161 | 1332 | const forkOnlyInstanceId = ProviderInstanceId.make("forkOnly"); |
@@ -2315,3 +2486,79 @@ describe("OrchestratorMcpService provider resolution", () => { |
2315 | 2486 | ); |
2316 | 2487 | }); |
2317 | 2488 | }); |
| 2489 | + |
| 2490 | +describe("OrchestratorMcpService thread lookup", () => { |
| 2491 | + const bareId = ThreadId.make("5d0b4a3e-8c1f-4a52-9d37-2f6c7e1b9a04"); |
| 2492 | + const launched = liveThreadShell(ThreadId.make(`mcp:${bareId}`)); |
| 2493 | + const deletedLaunched = { ...launched, deletedAt: DateTime.makeUnsafe("2026-10-05T00:00:00Z") }; |
| 2494 | + const client: McpInvocationScope = { |
| 2495 | + environmentId: EnvironmentId.make("environment:thread-lookup"), |
| 2496 | + requestNamespace: "client:thread-lookup", |
| 2497 | + thread: undefined, |
| 2498 | + client: { sessionId: "thread-lookup", label: "Claude Code", access: "full-access" }, |
| 2499 | + capabilities: new Set(["orchestration"]), |
| 2500 | + issuedAt: 1, |
| 2501 | + }; |
| 2502 | + const service = (shells: ReadonlyArray<OrchestrationV2ThreadShell>, sent: Ref.Ref<number>) => |
| 2503 | + layerOrchestratorService.pipe( |
| 2504 | + Layer.provide( |
| 2505 | + Layer.mergeAll( |
| 2506 | + NodeServices.layer, |
| 2507 | + Layer.mock(ThreadManagementService.ThreadManagementService)({ |
| 2508 | + getThreadShell: (threadId) => |
| 2509 | + Effect.succeed(shells.find((shell) => shell.id === threadId) ?? null), |
| 2510 | + sendToThread: () => Ref.update(sent, (count) => count + 1).pipe(Effect.as({} as never)), |
| 2511 | + }), |
| 2512 | + ServerSettings.layerTest(), |
| 2513 | + Layer.mock(ProviderRegistry.ProviderRegistry)({ getProviders: Effect.succeed([]) }), |
| 2514 | + Layer.mock(ProviderAdapterRegistry.ProviderAdapterRegistryV2)({ |
| 2515 | + list: () => Effect.succeed([]), |
| 2516 | + }), |
| 2517 | + Layer.mock(ProjectService.ProjectService)({}), |
| 2518 | + Layer.mock(SecretRequests.SecretRequests)({}), |
| 2519 | + Layer.mock(ScheduledTaskService.ScheduledTaskService)({}), |
| 2520 | + ), |
| 2521 | + ), |
| 2522 | + ); |
| 2523 | + const failuresFor = (shells: ReadonlyArray<OrchestrationV2ThreadShell>) => |
| 2524 | + Effect.gen(function* () { |
| 2525 | + const sent = yield* Ref.make(0); |
| 2526 | + return yield* Effect.gen(function* () { |
| 2527 | + const mcp = yield* OrchestratorMcpService.OrchestratorMcpService; |
| 2528 | + const read = yield* mcp.readThread(client, { threadId: bareId }).pipe(Effect.flip); |
| 2529 | + const send = yield* mcp |
| 2530 | + .sendToThread(client, { threadId: bareId, message: "hello" }) |
| 2531 | + .pipe(Effect.flip); |
| 2532 | + return { read, send, sends: yield* Ref.get(sent) }; |
| 2533 | + }).pipe(Effect.provide(service(shells, sent))); |
| 2534 | + }); |
| 2535 | + |
| 2536 | + it.effect("points a bare uuid at the mcp: thread it belongs to", () => |
| 2537 | + Effect.gen(function* () { |
| 2538 | + const { read, send, sends } = yield* failuresFor([launched]); |
| 2539 | + for (const error of [read, send]) { |
| 2540 | + assert.equal(error.code, "thread_not_found"); |
| 2541 | + assert.include(error.message, `mcp:${bareId}`); |
| 2542 | + } |
| 2543 | + assert.equal(sends, 0); |
| 2544 | + }), |
| 2545 | + ); |
| 2546 | + |
| 2547 | + it.effect("keeps the plain message for an id that matches nothing", () => |
| 2548 | + Effect.gen(function* () { |
| 2549 | + const { read, send } = yield* failuresFor([]); |
| 2550 | + assert.equal(read.code, "thread_not_found"); |
| 2551 | + assert.equal(read.message, `Thread ${bareId} is no longer available.`); |
| 2552 | + assert.equal(send.code, "thread_not_found"); |
| 2553 | + assert.equal(send.message, `Thread ${bareId} was not found.`); |
| 2554 | + }), |
| 2555 | + ); |
| 2556 | + |
| 2557 | + it.effect("does not name an mcp: thread that was deleted", () => |
| 2558 | + Effect.gen(function* () { |
| 2559 | + const { read, send } = yield* failuresFor([deletedLaunched]); |
| 2560 | + assert.equal(read.message, `Thread ${bareId} is no longer available.`); |
| 2561 | + assert.equal(send.message, `Thread ${bareId} was not found.`); |
| 2562 | + }), |
| 2563 | + ); |
| 2564 | +}); |
0 commit comments