Open History to see the last commit
1/**
2 * Optional integration check against a real `grok agent stdio` install.
3 * Enable with: T3_GROK_ACP_PROBE=1 vp test run GrokAcpCliProbe
4 * Set T3_GROK_LIVE_TURN=1 to also send a small prompt to the real model.
5 *
6 * The probe assumes either `XAI_API_KEY` is set in the environment or
7 * the user has previously run `grok login`. Without credentials the
8 * agent's `authenticate` request will fail and the test will surface
9 * the error.
10 */
11import * as NodeServices from "@effect/platform-node/NodeServices";
12import { it } from "@effect/vitest";
13import * as Effect from "effect/Effect";
14import * as Deferred from "effect/Deferred";
15import * as Fiber from "effect/Fiber";
16import * as FileSystem from "effect/FileSystem";
17import * as Stream from "effect/Stream";
18import { ChildProcessSpawner } from "effect/unstable/process";
19import { describe, expect } from "vite-plus/test";
20
21import { makeGrokAcpRuntime } from "./GrokAcpSupport.ts";
22
23const makeProbeRuntime = Effect.gen(function* () {
24 const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
25 return yield* makeGrokAcpRuntime({
26 grokSettings: { binaryPath: "grok" },
27 environment: process.env,
28 childProcessSpawner,
29 cwd: process.cwd(),
30 clientInfo: { name: "t3-grok-probe", version: "0.0.0" },
31 });
32});
33
34describe.runIf(process.env.T3_GROK_ACP_PROBE === "1")("Grok ACP CLI probe", () => {
35 it.effect("initialize and authenticate against real grok agent stdio", () =>
36 Effect.gen(function* () {
37 const runtime = yield* makeProbeRuntime;
38 const started = yield* runtime.start();
39 expect(started.initializeResult).toBeDefined();
40 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
41 );
42
43 it.effect("completes a prompt on the agent's default model", () =>
44 Effect.gen(function* () {
45 const runtime = yield* makeProbeRuntime;
46 const started = yield* runtime.start();
47 expect(typeof started.sessionId).toBe("string");
48
49 const result = yield* runtime
50 .prompt({ prompt: [{ type: "text", text: "Respond with exactly: grok switch ok" }] })
51 .pipe(Effect.timeout("60 seconds"));
52 expect(result.stopReason).toBe("end_turn");
53 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
54 );
55 it.effect("session/set_model accepts advertised reasoning effort metadata", () =>
56 Effect.gen(function* () {
57 const runtime = yield* makeProbeRuntime;
58 const started = yield* runtime.start();
59 const modelState = started.sessionSetupResult.models;
60 const currentModelId = modelState?.currentModelId.trim();
61 expect(currentModelId).toBeDefined();
62 if (!currentModelId) return;
63
64 const currentModel = modelState?.availableModels.find(
65 (model) => model.modelId.trim() === currentModelId,
66 );
67 const reasoningEffort = currentModel?._meta?.reasoningEffort;
68 expect(typeof reasoningEffort).toBe("string");
69 if (typeof reasoningEffort !== "string") return;
70
71 yield* runtime.setSessionModel(currentModelId, { reasoningEffort });
72 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
73 );
74
75 it.effect.skipIf(process.env.T3_GROK_LIVE_TURN !== "1")(
76 "finishes a real Grok turn and streams its answer",
77 () =>
78 Effect.gen(function* () {
79 const fileSystem = yield* FileSystem.FileSystem;
80 const cwd = yield* fileSystem.makeTempDirectoryScoped();
81 const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
82 const runtime = yield* makeGrokAcpRuntime({
83 grokSettings: { binaryPath: "grok" },
84 environment: process.env,
85 childProcessSpawner,
86 cwd,
87 runtimeMode: "approval-required",
88 clientInfo: { name: "t3-grok-probe", version: "0.0.0" },
89 });
90 yield* runtime.start();
91 const chunks: string[] = [];
92 const events = yield* Stream.runForEach(runtime.getEvents(), (event) => {
93 if (event._tag === "EventStreamBarrier") {
94 return Deferred.succeed(event.acknowledge, undefined);
95 }
96 if (event._tag === "ContentDelta") {
97 chunks.push(event.text);
98 }
99 return Effect.void;
100 }).pipe(Effect.forkChild);
101 const result = yield* runtime.prompt({
102 prompt: [{ type: "text", text: "Reply exactly GROK_T3_OK. Do not use any tools." }],
103 });
104 yield* runtime.drainEvents;
105 expect(result.stopReason).toBe("end_turn");
106 expect(chunks.join("")).toContain("GROK_T3_OK");
107 yield* Fiber.interrupt(events);
108 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
109 );
110});