mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-12 09:41:11 +00:00
fix: use target session for bash sandbox hints
This commit is contained in:
@@ -43,6 +43,24 @@ function buildParams(commandBody: string) {
|
||||
};
|
||||
}
|
||||
|
||||
function buildElevatedDeniedParams(commandBody: string) {
|
||||
const base = buildParams(commandBody);
|
||||
return {
|
||||
...base,
|
||||
ctx: {
|
||||
...base.ctx,
|
||||
SessionKey: "agent:main:telegram:slash-session",
|
||||
} as MsgContext,
|
||||
agentId: "main",
|
||||
sessionKey: "agent:target:telegram:direct:target-session",
|
||||
elevated: {
|
||||
enabled: true,
|
||||
allowed: false,
|
||||
failures: [],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function buildRunningSession(overrides?: Record<string, unknown>) {
|
||||
return {
|
||||
id: "session-1",
|
||||
@@ -116,4 +134,37 @@ describe("handleBashChatCommand stop", () => {
|
||||
expect(result.text).toContain("!poll session-1");
|
||||
expect(killProcessTreeMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("uses the canonical target session for elevated sandbox explanation", async () => {
|
||||
const sandboxRuntime = await import("../../agents/sandbox.js");
|
||||
const resolveSandboxRuntimeStatusSpy = vi
|
||||
.spyOn(sandboxRuntime, "resolveSandboxRuntimeStatus")
|
||||
.mockReturnValue({
|
||||
agentId: "target",
|
||||
sessionKey: "agent:target:telegram:direct:target-session",
|
||||
mainSessionKey: "agent:target:main",
|
||||
mode: "non-main",
|
||||
sandboxed: true,
|
||||
toolPolicy: {
|
||||
allowReadOutsideWorkspace: false,
|
||||
allowReadInsideWorkspace: true,
|
||||
allowWriteOutsideWorkspace: false,
|
||||
allowWriteInsideWorkspace: true,
|
||||
allowShell: true,
|
||||
},
|
||||
});
|
||||
|
||||
const result = await handleBashChatCommand(buildElevatedDeniedParams("/bash pwd"));
|
||||
|
||||
expect(resolveSandboxRuntimeStatusSpy).toHaveBeenCalledWith({
|
||||
cfg: expect.any(Object),
|
||||
sessionKey: "agent:target:telegram:direct:target-session",
|
||||
});
|
||||
expect(result.text).toContain(
|
||||
"openclaw sandbox explain --session agent:target:telegram:direct:target-session",
|
||||
);
|
||||
expect(result.text).not.toContain(
|
||||
"openclaw sandbox explain --session agent:main:telegram:slash-session",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -210,13 +210,13 @@ export async function handleBashChatCommand(params: {
|
||||
if (!params.elevated.enabled || !params.elevated.allowed) {
|
||||
const runtimeSandboxed = resolveSandboxRuntimeStatus({
|
||||
cfg: params.cfg,
|
||||
sessionKey: params.ctx.SessionKey,
|
||||
sessionKey: params.sessionKey,
|
||||
}).sandboxed;
|
||||
return {
|
||||
text: formatElevatedUnavailableMessage({
|
||||
runtimeSandboxed,
|
||||
failures: params.elevated.failures,
|
||||
sessionKey: params.ctx.SessionKey,
|
||||
sessionKey: params.sessionKey,
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user