Gate Matrix profile updates for non-owner message tool runs (#62662)

Merged via squash.

Prepared head SHA: 602b16a676
Co-authored-by: eleqtrizit <31522568+eleqtrizit@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
This commit is contained in:
Agustin Rivera
2026-04-10 09:56:17 -07:00
committed by GitHub
parent 1c1fe8a405
commit fe0f686c92
38 changed files with 619 additions and 175 deletions

View File

@@ -2,15 +2,21 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { beforeEach, describe, expect, it, vi } from "vitest";
import {
clearActiveMcpLoopbackRuntime,
setActiveMcpLoopbackRuntime,
} from "../gateway/mcp-http.loopback-runtime.js";
import { onAgentEvent, resetAgentEventsForTest } from "../infra/agent-events.js";
import {
makeBootstrapWarn as realMakeBootstrapWarn,
resolveBootstrapContextForRun as realResolveBootstrapContextForRun,
} from "./bootstrap-files.js";
import { runClaudeCliAgent } from "./cli-runner.js";
import {
createManagedRun,
mockSuccessfulCliRun,
restoreCliRunnerPrepareTestDeps,
setupCliRunnerTestRegistry,
supervisorSpawnMock,
} from "./cli-runner.test-support.js";
import { buildCliEnvAuthLog, executePreparedCliRun } from "./cli-runner/execute.js";
@@ -97,6 +103,19 @@ function buildPreparedCliRunContext(params: {
};
}
function createClaudeSuccessRun(sessionId: string) {
return createManagedRun({
reason: "exit",
exitCode: 0,
exitSignal: null,
durationMs: 50,
stdout: JSON.stringify({ message: "ok", session_id: sessionId }),
stderr: "",
timedOut: false,
noOutputTimedOut: false,
});
}
describe("runCliAgent spawn path", () => {
it("does not inject hardcoded 'Tools are disabled' text into CLI arguments", async () => {
supervisorSpawnMock.mockResolvedValueOnce(
@@ -367,6 +386,55 @@ describe("runCliAgent spawn path", () => {
}
});
it("ignores legacy claudeSessionId on the compat wrapper", async () => {
setupCliRunnerTestRegistry();
supervisorSpawnMock.mockResolvedValueOnce(createClaudeSuccessRun("sid-wrapper"));
await runClaudeCliAgent({
sessionId: "openclaw-session",
sessionFile: "/tmp/session.jsonl",
workspaceDir: "/tmp",
prompt: "hi",
model: "opus",
timeoutMs: 1_000,
runId: "run-claude-legacy-wrapper",
claudeSessionId: "c9d7b831-1c31-4d22-80b9-1e50ca207d4b",
});
const input = supervisorSpawnMock.mock.calls[0]?.[0] as { argv?: string[]; input?: string };
expect(input.argv).not.toContain("--resume");
expect(input.argv).not.toContain("c9d7b831-1c31-4d22-80b9-1e50ca207d4b");
expect(input.argv).toContain("--session-id");
expect(input.input).toContain("hi");
});
it("forwards senderIsOwner through the compat wrapper into bundle MCP env", async () => {
setupCliRunnerTestRegistry();
setActiveMcpLoopbackRuntime({ port: 23119, token: "loopback-token-123" });
try {
supervisorSpawnMock.mockResolvedValueOnce(createClaudeSuccessRun("sid-owner"));
await runClaudeCliAgent({
sessionId: "openclaw-session",
sessionKey: "agent:main:matrix:room:123",
sessionFile: "/tmp/session.jsonl",
workspaceDir: "/tmp",
prompt: "hi",
model: "opus",
timeoutMs: 1_000,
runId: "run-claude-owner-wrapper",
senderIsOwner: false,
});
const input = supervisorSpawnMock.mock.calls[0]?.[0] as {
env?: Record<string, string | undefined>;
};
expect(input.env?.OPENCLAW_MCP_SENDER_IS_OWNER).toBe("false");
} finally {
clearActiveMcpLoopbackRuntime("loopback-token-123");
}
});
it("runs CLI through supervisor and returns payload", async () => {
supervisorSpawnMock.mockResolvedValueOnce(
createManagedRun({