|
| 1 | +import * as NodeFS from "node:fs"; |
1 | 2 | import * as ServerSecretStore from "../auth/ServerSecretStore.ts"; |
2 | 3 | import * as SourceControlProviderRegistry from "../sourceControl/SourceControlProviderRegistry.ts"; |
3 | 4 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
@@ -35,6 +36,7 @@ import * as OpenCodeServerLedger from "@t3tools/provider-opencode/server/OpenCod |
35 | 36 | import * as ServerSettings from "../serverSettings.ts"; |
36 | 37 | import * as VcsDriverRegistry from "../vcs/VcsDriverRegistry.ts"; |
37 | 38 | import * as VcsProcess from "../vcs/VcsProcess.ts"; |
| 39 | +import * as EffectWorker from "./EffectWorker.ts"; |
38 | 40 | import * as Orchestrator from "./Orchestrator.ts"; |
39 | 41 | import * as ProviderTurnStartServiceTestkit from "./ProviderTurnStartService.testkit.ts"; |
40 | 42 | import * as RuntimeLayer from "./runtimeLayer.ts"; |
@@ -238,4 +240,97 @@ describe.runIf(process.env.T3_GROK_LIVE_ORCHESTRATOR === "1")("Grok V2 live orch |
238 | 240 | }).pipe(Effect.provide(layerLive), Effect.scoped), |
239 | 241 | 360_000, |
240 | 242 | ); |
| 243 | + |
| 244 | + it.live( |
| 245 | + "closes a background shell inside the server orchestrator", |
| 246 | + () => |
| 247 | + Effect.gen(function* () { |
| 248 | + const orchestrator = yield* Orchestrator.OrchestratorV2; |
| 249 | + yield* EffectWorker.runDaemonWithOptions({ concurrency: 2 }).pipe(Effect.forkScoped); |
| 250 | + const worktreePath = "/tmp/t3-grok-live-background-shell"; |
| 251 | + NodeFS.mkdirSync(worktreePath, { recursive: true }); |
| 252 | + const projectId = ProjectId.make("project:grok-live-background-shell"); |
| 253 | + const threadId = ThreadId.make("thread:grok-live-background-shell"); |
| 254 | + const marker = `LIVE_SHELL_${Date.now().toString(36)}`; |
| 255 | + yield* orchestrator.dispatch({ |
| 256 | + type: "thread.create", |
| 257 | + createdBy: "user", |
| 258 | + creationSource: "web", |
| 259 | + commandId: CommandId.make("command:grok-live-background-shell:create"), |
| 260 | + threadId, |
| 261 | + projectId, |
| 262 | + title: "Grok live background shell", |
| 263 | + modelSelection: GROK_MODEL_SELECTION, |
| 264 | + runtimeMode: "full-access", |
| 265 | + interactionMode: "default", |
| 266 | + branch: null, |
| 267 | + worktreePath, |
| 268 | + }); |
| 269 | + yield* Console.log("Grok live background shell thread created; dispatching prompt."); |
| 270 | + yield* orchestrator.dispatch({ |
| 271 | + type: "message.dispatch", |
| 272 | + createdBy: "user", |
| 273 | + creationSource: "web", |
| 274 | + commandId: CommandId.make("command:grok-live-background-shell:prompt"), |
| 275 | + threadId, |
| 276 | + messageId: MessageId.make("message:grok-live-background-shell"), |
| 277 | + text: [ |
| 278 | + "Use your shell tool for this and nothing else.", |
| 279 | + `Run: sleep 12 && echo ${marker}`, |
| 280 | + "Start it in the background instead of holding the tool call open.", |
| 281 | + "Poll that background task until it exits.", |
| 282 | + `Then reply with exactly ${marker} and stop.`, |
| 283 | + ].join(" "), |
| 284 | + attachments: [], |
| 285 | + modelSelection: GROK_MODEL_SELECTION, |
| 286 | + dispatchMode: { type: "start_immediately" }, |
| 287 | + }); |
| 288 | + yield* Console.log("Grok live background shell prompt dispatched; waiting for completion."); |
| 289 | + const projection = yield* waitForIdle(threadId); |
| 290 | + const commands = projection.turnItems.flatMap((item) => |
| 291 | + item.type === "command_execution" |
| 292 | + ? [ |
| 293 | + { |
| 294 | + status: item.status, |
| 295 | + input: item.input.slice(0, 180), |
| 296 | + output: (item.output ?? "").slice(0, 240), |
| 297 | + exitCode: item.exitCode ?? null, |
| 298 | + }, |
| 299 | + ] |
| 300 | + : [], |
| 301 | + ); |
| 302 | + const assistant = projection.messages |
| 303 | + .filter((message) => message.role === "assistant") |
| 304 | + .map((message) => message.text) |
| 305 | + .join("\n"); |
| 306 | + yield* Console.log( |
| 307 | + JSON.stringify( |
| 308 | + { |
| 309 | + marker, |
| 310 | + runs: projection.runs.map((run) => run.status), |
| 311 | + commands, |
| 312 | + assistant: assistant.slice(-400), |
| 313 | + }, |
| 314 | + null, |
| 315 | + 2, |
| 316 | + ), |
| 317 | + ); |
| 318 | + const sleepCommand = commands.find((command) => command.input.includes("sleep")); |
| 319 | + assert.deepEqual( |
| 320 | + projection.runs.map((run) => run.status), |
| 321 | + ["completed"], |
| 322 | + ); |
| 323 | + assert.isDefined(sleepCommand); |
| 324 | + assert.equal( |
| 325 | + sleepCommand !== undefined && |
| 326 | + !["idle", "pending", "running", "waiting"].includes(sleepCommand.status), |
| 327 | + true, |
| 328 | + ); |
| 329 | + assert.include( |
| 330 | + `${assistant}\n${commands.map((command) => command.output).join("\n")}`, |
| 331 | + marker, |
| 332 | + ); |
| 333 | + }).pipe(Effect.provide(layerLive), Effect.scoped), |
| 334 | + 360_000, |
| 335 | + ); |
241 | 336 | }); |
0 commit comments