Some grok tests looked Grok Build up as the plugin does and ran what they
found (`grok --version`, `grok models`). On a machine with Grok Build
installed that ran the real CLI, which can reach xAI.
packages/grok/nocli.mjs is imported first by every grok test file, and
each calls noRealGrok() before reading its environment. It sets every
place executable() looks:
- PATH: /usr/bin and /bin only (the fakes' scripts run cat, rm, sleep),
each left out if it holds a grok; empty on Windows.
- GROK_BIN_DIR: a folder that doesn't exist; GROK_HOME: an empty folder.
- HOME and USERPROFILE: an empty folder, for ~/.grok/bin and
~/.local/bin. Bun's os.homedir() keeps the HOME the process started
with (checked: setting process.env.HOME doesn't change it), so the
helper mock.module()s node:os with a homedir that reads HOME
(USERPROFILE) at call time, as Node's does, before index.mjs loads.
Other packages in the same run see Node's behaviour: the started HOME
unless a test changed it.
A test that wants a CLI still puts its fake in GROK_BIN_DIR.
Marker proof: a fake grok (under a .grok folder, so it counts as Grok
Build) that appends its argv to a marker file, placed on the outer PATH,
in ~/.local/bin and ~/.grok/bin under the test HOME. Run as
TMPDIR=$H HOME=$H/home PATH=$H/outer:$PATH bun test:
- old tests (92d5557), packages/grok: marker written, 5 runs (1 `grok
--version`, 4 `grok models`, from ~/.grok/bin under the test HOME),
78 pass 4 fail
- new tests, packages/grok: no marker, 82 pass 0 fail
- new tests with the mock.module line commented out: marker written
again (same 5 runs), 78 pass 4 fail
- new tests, whole repo: no marker, 2166 pass 0 fail across 189 files
- bun scripts/check.mjs: ok (no version bump: test-only change)
Not tried: Windows; a run with the real HOME (the marker run covers the
same folders under a test HOME); the real grok was never run.
Closes #325
52 lines
2.5 KiB
JavaScript
52 lines
2.5 KiB
JavaScript
import { noRealGrok } from "./nocli.mjs"
|
|
import { expect, test } from "bun:test"
|
|
import { _internal } from "./index.mjs"
|
|
|
|
noRealGrok()
|
|
|
|
test("a plain Codex task reaches Grok as a user message without requiring tools", () => {
|
|
const task = {
|
|
type: "agent_message", author: "/root", recipient: "/root/research",
|
|
content: [{ type: "input_text", text: "Message Type: NEW_TASK\nPayload:\nresearch the failure" }],
|
|
}
|
|
const sent = JSON.parse(_internal.rewrite(JSON.stringify({ input: [task] })))
|
|
expect(sent.input).toEqual([{
|
|
type: "message", role: "user",
|
|
content: [{ type: "input_text", text: "From /root to /root/research\n\n" }, ...task.content],
|
|
}])
|
|
})
|
|
|
|
test("a subagent's reply keeps its sender, recipient, position and multimodal parts", () => {
|
|
const before = { type: "function_call", call_id: "call_1", name: "send_message", arguments: "{}" }
|
|
const after = { type: "function_call_output", call_id: "call_1", output: "sent" }
|
|
const reply = { type: "agent_message", author: "/root/research", recipient: "/root", content: [
|
|
{ type: "input_text", text: "Message Type: FINAL_ANSWER\nPayload:\nfound the cause" },
|
|
{ type: "input_image", image_url: "data:image/png;base64,fixture" },
|
|
] }
|
|
const sent = JSON.parse(_internal.rewrite(JSON.stringify({ tools: [], input: [before, reply, after] })))
|
|
expect(sent.input).toEqual([before, {
|
|
type: "message", role: "user",
|
|
content: [{ type: "input_text", text: "From /root/research to /root\n\n" }, ...reply.content],
|
|
}, after])
|
|
})
|
|
|
|
test("a sealed or malformed agent message is never converted or dropped", () => {
|
|
for (const item of [
|
|
{ type: "agent_message", content: [{ type: "encrypted_content", encrypted_content: "sealed fixture" }] },
|
|
{ type: "agent_message", content: [{ type: "input_text", text: "header" }, { type: "encrypted_content", encrypted_content: "sealed fixture" }] },
|
|
{ type: "agent_message", content: [{ type: "input_text", encrypted_content: "sealed fixture" }] },
|
|
{ type: "agent_message", encrypted_content: "sealed fixture", content: [{ type: "input_text", text: "header" }] },
|
|
{ type: "agent_message", content: [{ type: "future_content", payload: "keep me" }] },
|
|
{ type: "agent_message", content: [] },
|
|
{ type: "agent_message", content: null },
|
|
]) {
|
|
const body = JSON.stringify({ input: [item] })
|
|
expect(_internal.rewrite(body)).toBe(body)
|
|
}
|
|
})
|
|
|
|
test("ordinary Responses histories stay byte-for-byte unchanged", () => {
|
|
const body = '{ "input": [{"type":"message","role":"user","content":"hello"}] }'
|
|
expect(_internal.rewrite(body)).toBe(body)
|
|
})
|