Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

GrokAcpCliProbe.test.ts

130 lines5.4 KB

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("session/new advertises typed SessionModelState with at least one model", () =>
44 Effect.gen(function* () {
45 const runtime = yield* makeProbeRuntime;
46 const started = yield* runtime.start();
47 const result = started.sessionSetupResult;
48​
49 expect(typeof started.sessionId).toBe("string");
50​
51 // Modern grok-shell advertises models through the typed
52 // `SessionModelState` field, not via a `configOptions` entry.
53 // If this assertion fails the upstream surface has regressed.
54 const models = result.models;
55 expect(models).toBeDefined();
56 expect(typeof models?.currentModelId).toBe("string");
57 expect(models?.availableModels.length ?? 0).toBeGreaterThan(0);
58 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
59 );
60​
61 it.effect("session/set_model accepts a no-op switch to the current model", () =>
62 Effect.gen(function* () {
63 const runtime = yield* makeProbeRuntime;
64 const started = yield* runtime.start();
65 const currentModelId = started.sessionSetupResult.models?.currentModelId?.trim();
66 expect(currentModelId).toBeDefined();
67 if (!currentModelId) return;
68​
69 // No-op switch — selecting the model the session already runs on must
70 // succeed against every Grok build that implements `session/set_model`.
71 yield* runtime.setSessionModel(currentModelId);
72 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
73 );
74​
75 it.effect("session/set_model accepts advertised reasoning effort metadata", () =>
76 Effect.gen(function* () {
77 const runtime = yield* makeProbeRuntime;
78 const started = yield* runtime.start();
79 const modelState = started.sessionSetupResult.models;
80 const currentModelId = modelState?.currentModelId.trim();
81 expect(currentModelId).toBeDefined();
82 if (!currentModelId) return;
83​
84 const currentModel = modelState?.availableModels.find(
85 (model) => model.modelId.trim() === currentModelId,
86 );
87 const reasoningEffort = currentModel?._meta?.reasoningEffort;
88 expect(typeof reasoningEffort).toBe("string");
89 if (typeof reasoningEffort !== "string") return;
90​
91 yield* runtime.setSessionModel(currentModelId, { reasoningEffort });
92 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
93 );
94​
95 it.effect.skipIf(process.env.T3_GROK_LIVE_TURN !== "1")(
96 "finishes a real Grok turn and streams its answer",
97 () =>
98 Effect.gen(function* () {
99 const fileSystem = yield* FileSystem.FileSystem;
100 const cwd = yield* fileSystem.makeTempDirectoryScoped();
101 const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
102 const runtime = yield* makeGrokAcpRuntime({
103 grokSettings: { binaryPath: "grok" },
104 environment: process.env,
105 childProcessSpawner,
106 cwd,
107 runtimeMode: "approval-required",
108 clientInfo: { name: "t3-grok-probe", version: "0.0.0" },
109 });
110 yield* runtime.start();
111 const chunks: string[] = [];
112 const events = yield* Stream.runForEach(runtime.getEvents(), (event) => {
113 if (event._tag === "EventStreamBarrier") {
114 return Deferred.succeed(event.acknowledge, undefined);
115 }
116 if (event._tag === "ContentDelta") {
117 chunks.push(event.text);
118 }
119 return Effect.void;
120 }).pipe(Effect.forkChild);
121 const result = yield* runtime.prompt({
122 prompt: [{ type: "text", text: "Reply exactly GROK_T3_OK. Do not use any tools." }],
123 });
124 yield* runtime.drainEvents;
125 expect(result.stopReason).toBe("end_turn");
126 expect(chunks.join("")).toContain("GROK_T3_OK");
127 yield* Fiber.interrupt(events);
128 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
129 );
130});