Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/GrokAdapterV2.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
import * as NodeServices from "@effect/platform-node/NodeServices";
import {
EnvironmentId,
ProjectId,
MessageId,
NodeId,
Expand Down Expand Up @@ -290,6 +291,52 @@ describe("Grok launch permission mode", () => {
...override,
});

it.effect("launches the agent with the env that names the thread it serves", () =>
Effect.gen(function* () {
const instanceId = ProviderInstanceId.make("grok-launch-test");
const threadId = ThreadId.make("grok-launch-thread-env");
const endpoint = "http://127.0.0.1:43123/mcp";
yield* (yield* McpProviderSessions.McpProviderSessions).set({
environmentId: EnvironmentId.make("environment-grok-launch-thread-env"),
threadId,
providerSessionId: "mcp-session-grok-launch-thread-env",
providerInstanceId: instanceId,
endpoint,
authorizationHeader: "Bearer grok-thread-env-token",
browserToolsAvailable: false,
});
const environments: Array<Record<string, unknown> | undefined> = [];
const childProcessSpawner = ChildProcessSpawner.make((command) => {
if (command._tag === "StandardCommand") environments.push(command.options.env);
return Effect.fail(
PlatformError.systemError({
_tag: "NotFound",
module: "grok-launch-test",
method: "spawn",
}),
);
});
const adapter = yield* makeGrokAdapterV2({
instanceId,
settings: LAUNCH_TEST_GROK_SETTINGS,
environment: {},
hostPlatform: "darwin",
selfInvocation: yield* resolveSelfInvocation(),
}).pipe(Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, childProcessSpawner));
yield* adapter
.openSession({
threadId,
providerSessionId: ProviderSessionId.make("grok-launch-thread-env"),
modelSelection: { instanceId, model: "grok-build" },
runtimePolicy: policy("full-access"),
})
.pipe(Effect.scoped, Effect.ignore);
assert.lengthOf(environments, 1);
assert.equal(environments[0]?.T3CODE_THREAD_ID, "grok-launch-thread-env");
assert.equal(environments[0]?.T3_ACP_MCP_ENDPOINT, endpoint);
}).pipe(Effect.provideService(HostProcess.Platform, "darwin"), Effect.provide(layerTest)),
);

it.effect.each(
(
[
Expand Down
4 changes: 2 additions & 2 deletions packages/provider-grok/src/server/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,12 @@ export function makeGrokAcpAdapterFlavor(
ownedModelOptionIds: [GROK_REASONING_EFFORT_OPTION_ID],
makeRuntime:
options.makeRuntime ??
(({ runtimePolicy, ...input }) =>
(({ runtimePolicy, processEnvironment, ...input }) =>
makeGrokAcpRuntime({
...input,
interruptPromptOnCancel: input.interruptPromptOnCancel ?? false,
grokSettings: options.settings,
environment: options.environment,
environment: { ...options.environment, ...processEnvironment },
runtimeMode: grokLaunchRuntimeMode(runtimePolicy),
})),
// Auto prompts represent classifier refusals and must reach the user.
Expand Down
Loading