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

GrokAcpCliProbe.test.ts

69 lines2.8 KB

1/**
2 * Optional integration check against a real `grok agent stdio` install.
3 * Enable with: T3_GROK_ACP_PROBE=1 bun run test GrokAcpCliProbe
4 *
5 * The probe assumes either `XAI_API_KEY` is set in the environment or
6 * the user has previously run `grok login`. Without credentials the
7 * agent's `authenticate` request will fail and the test will surface
8 * the error.
9 */
10import * as NodeServices from "@effect/platform-node/NodeServices";
11import { it } from "@effect/vitest";
12import * as Effect from "effect/Effect";
13import { ChildProcessSpawner } from "effect/unstable/process";
14import { describe, expect } from "vite-plus/test";
15​
16import { makeGrokAcpRuntime } from "./GrokAcpSupport.ts";
17​
18const makeProbeRuntime = Effect.gen(function* () {
19 const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
20 return yield* makeGrokAcpRuntime({
21 grokSettings: { binaryPath: "grok" },
22 environment: process.env,
23 childProcessSpawner,
24 cwd: process.cwd(),
25 clientInfo: { name: "t3-grok-probe", version: "0.0.0" },
26 });
27});
28​
29describe.runIf(process.env.T3_GROK_ACP_PROBE === "1")("Grok ACP CLI probe", () => {
30 it.effect("initialize and authenticate against real grok agent stdio", () =>
31 Effect.gen(function* () {
32 const runtime = yield* makeProbeRuntime;
33 const started = yield* runtime.start();
34 expect(started.initializeResult).toBeDefined();
35 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
36 );
37​
38 it.effect("session/new advertises typed SessionModelState with at least one model", () =>
39 Effect.gen(function* () {
40 const runtime = yield* makeProbeRuntime;
41 const started = yield* runtime.start();
42 const result = started.sessionSetupResult;
43​
44 expect(typeof started.sessionId).toBe("string");
45​
46 // Modern grok-shell advertises models through the typed
47 // `SessionModelState` field, not via a `configOptions` entry.
48 // If this assertion fails the upstream surface has regressed.
49 const models = result.models;
50 expect(models).toBeDefined();
51 expect(typeof models?.currentModelId).toBe("string");
52 expect(models?.availableModels.length ?? 0).toBeGreaterThan(0);
53 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
54 );
55​
56 it.effect("session/set_model accepts a no-op switch to the current model", () =>
57 Effect.gen(function* () {
58 const runtime = yield* makeProbeRuntime;
59 const started = yield* runtime.start();
60 const currentModelId = started.sessionSetupResult.models?.currentModelId?.trim();
61 expect(currentModelId).toBeDefined();
62 if (!currentModelId) return;
63​
64 // No-op switch — selecting the model the session already runs on must
65 // succeed against every Grok build that implements `session/set_model`.
66 yield* runtime.setSessionModel(currentModelId);
67 }).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
68 );
69});