mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-26 02:45:13 +00:00
refactor: isolate exec approval followup handoff
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
consumeExecApprovalFollowupElevatedDefaults,
|
||||
resetExecApprovalFollowupElevatedDefaultsForTests,
|
||||
consumeExecApprovalFollowupRuntimeHandoff,
|
||||
resetExecApprovalFollowupRuntimeHandoffsForTests,
|
||||
} from "./bash-tools.exec-approval-followup-state.js";
|
||||
import {
|
||||
buildExecApprovalPendingToolResult,
|
||||
@@ -63,7 +63,7 @@ describe("sendExecApprovalFollowupResult", () => {
|
||||
allowlist: [],
|
||||
file: { version: 1, agents: {} },
|
||||
});
|
||||
resetExecApprovalFollowupElevatedDefaultsForTests();
|
||||
resetExecApprovalFollowupRuntimeHandoffsForTests();
|
||||
});
|
||||
|
||||
it("logs repeated followup dispatch failures once per approval id and error message", async () => {
|
||||
@@ -132,22 +132,65 @@ describe("sendExecApprovalFollowupResult", () => {
|
||||
);
|
||||
|
||||
const call = sendExecApprovalFollowup.mock.calls[0]?.[0] as
|
||||
| { execApprovalFollowupToken?: string; bashElevated?: unknown }
|
||||
| {
|
||||
internalRuntimeHandoffId?: string;
|
||||
idempotencyKey?: string;
|
||||
execApprovalFollowupToken?: string;
|
||||
bashElevated?: unknown;
|
||||
}
|
||||
| undefined;
|
||||
expect(call?.execApprovalFollowupToken).toEqual(expect.any(String));
|
||||
expect(call?.internalRuntimeHandoffId).toEqual(expect.any(String));
|
||||
expect(call?.idempotencyKey).toMatch(/^exec-approval-followup:approval-elevated-75832:nonce:/);
|
||||
expect(call?.idempotencyKey).not.toContain(call?.internalRuntimeHandoffId ?? "");
|
||||
expect(call).not.toHaveProperty("bashElevated");
|
||||
expect(call).not.toHaveProperty("execApprovalFollowupToken");
|
||||
expect(
|
||||
consumeExecApprovalFollowupElevatedDefaults({
|
||||
token: call?.execApprovalFollowupToken ?? "",
|
||||
consumeExecApprovalFollowupRuntimeHandoff({
|
||||
handoffId: call?.internalRuntimeHandoffId ?? "",
|
||||
approvalId: "approval-elevated-75832",
|
||||
idempotencyKey: call?.idempotencyKey ?? "",
|
||||
sessionKey: "agent:main:telegram:direct:wrong",
|
||||
}),
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
consumeExecApprovalFollowupElevatedDefaults({
|
||||
token: call?.execApprovalFollowupToken ?? "",
|
||||
consumeExecApprovalFollowupRuntimeHandoff({
|
||||
handoffId: call?.internalRuntimeHandoffId ?? "",
|
||||
approvalId: "approval-elevated-75832",
|
||||
idempotencyKey: call?.idempotencyKey ?? "",
|
||||
sessionKey: "agent:main:telegram:direct:123",
|
||||
}),
|
||||
).toEqual(bashElevated);
|
||||
).toEqual({
|
||||
kind: "exec-approval-followup",
|
||||
approvalId: "approval-elevated-75832",
|
||||
sessionKey: "agent:main:telegram:direct:123",
|
||||
idempotencyKey: call?.idempotencyKey,
|
||||
bashElevated,
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps non-elevated agent followups on the deterministic idempotency path", async () => {
|
||||
sendExecApprovalFollowup.mockResolvedValue(true);
|
||||
|
||||
await sendExecApprovalFollowupResult(
|
||||
{
|
||||
approvalId: "approval-normal-75832",
|
||||
sessionKey: "agent:main:telegram:direct:123",
|
||||
turnSourceChannel: "telegram",
|
||||
},
|
||||
"Exec finished",
|
||||
{ sendExecApprovalFollowup, logWarn },
|
||||
);
|
||||
|
||||
const call = sendExecApprovalFollowup.mock.calls[0]?.[0] as
|
||||
| {
|
||||
internalRuntimeHandoffId?: string;
|
||||
idempotencyKey?: string;
|
||||
bashElevated?: unknown;
|
||||
}
|
||||
| undefined;
|
||||
expect(call).not.toHaveProperty("internalRuntimeHandoffId");
|
||||
expect(call).not.toHaveProperty("idempotencyKey");
|
||||
expect(call).not.toHaveProperty("bashElevated");
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user