test: replace hanging pair approve poc coverage

This commit is contained in:
Peter Steinberger
2026-04-04 16:42:46 +09:00
parent 2c0f096688
commit 9bbedf3caa
2 changed files with 44 additions and 8 deletions

View File

@@ -221,8 +221,8 @@ vi.mock("../../channels/plugins/pairing.js", async () => {
vi.mock("../../agents/model-catalog.js", () => ({
loadModelCatalog: vi.fn(async () => [
{ provider: "anthropic", id: "claude-opus-4-6", name: "Claude Opus" },
{ provider: "anthropic", id: "claude-sonnet-4-6", name: "Claude Sonnet" },
{ provider: "anthropic", id: "claude-opus-4-5", name: "Claude Opus" },
{ provider: "anthropic", id: "claude-sonnet-4-5", name: "Claude Sonnet" },
{ provider: "openai", id: "gpt-4.1", name: "GPT-4.1" },
{ provider: "openai", id: "gpt-4.1-mini", name: "GPT-4.1 Mini" },
{ provider: "google", id: "gemini-2.0-flash", name: "Gemini Flash" },
@@ -2443,7 +2443,7 @@ describe("handleCommands /allowlist", () => {
describe("/models command", () => {
const cfg = {
commands: { text: true },
agents: { defaults: { model: { primary: "anthropic/claude-opus-4-6" } } },
agents: { defaults: { model: { primary: "anthropic/claude-opus-4-5" } } },
} as unknown as OpenClawConfig;
it.each(["discord", "whatsapp"])("lists providers on %s (text)", async (surface) => {
@@ -2487,7 +2487,7 @@ describe("/models command", () => {
includes: [
"Models (anthropic",
"page 1/",
"anthropic/claude-opus-4-6",
"anthropic/claude-opus-4-5",
"Switch: /model <provider/model>",
"All: /models anthropic all",
],
@@ -2496,7 +2496,7 @@ describe("/models command", () => {
{
name: "ignores page argument when all flag is present",
command: "/models anthropic 3 all",
includes: ["Models (anthropic", "page 1/1", "anthropic/claude-opus-4-6"],
includes: ["Models (anthropic", "page 1/1", "anthropic/claude-opus-4-5"],
excludes: ["Page out of range"],
},
{
@@ -2538,7 +2538,7 @@ describe("/models command", () => {
defaults: {
model: {
primary: "localai/ultra-chat",
fallbacks: ["anthropic/claude-opus-4-6"],
fallbacks: ["anthropic/claude-opus-4-5"],
},
imageModel: "visionpro/studio-v1",
},
@@ -2565,7 +2565,7 @@ describe("/models command", () => {
const scopedCfg = {
commands: { text: true },
agents: {
defaults: { model: { primary: "anthropic/claude-opus-4-6" } },
defaults: { model: { primary: "anthropic/claude-opus-4-5" } },
list: [{ id: "support", model: "localai/ultra-chat" }],
},
} as unknown as OpenClawConfig;
@@ -2589,6 +2589,7 @@ describe("handleCommands plugin commands", () => {
clearPluginCommands();
let receivedCtx:
| {
gatewayClientScopes?: string[];
sessionKey?: string;
sessionId?: string;
}
@@ -2607,7 +2608,9 @@ describe("handleCommands plugin commands", () => {
commands: { text: true },
channels: { whatsapp: { allowFrom: ["*"] } },
} as OpenClawConfig;
const params = buildParams("/card", cfg);
const params = buildParams("/card", cfg, {
GatewayClientScopes: ["operator.write", "operator.pairing"],
});
params.sessionKey = "agent:main:whatsapp:direct:test-user";
params.sessionEntry = {
sessionId: "session-plugin-command",
@@ -2618,6 +2621,7 @@ describe("handleCommands plugin commands", () => {
expect(commandResult.shouldContinue).toBe(false);
expect(commandResult.reply?.text).toBe("from plugin");
expect(receivedCtx).toMatchObject({
gatewayClientScopes: ["operator.write", "operator.pairing"],
sessionKey: "agent:main:whatsapp:direct:test-user",
sessionId: "session-plugin-command",
});

View File

@@ -1397,6 +1397,38 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
expect(mockState.lastDispatchCtx?.CommandBody).toBe("ops update");
});
it("forwards gateway caller scopes into the dispatch context", async () => {
createTranscriptFixture("openclaw-chat-send-gateway-client-scopes-");
mockState.finalText = "ok";
const respond = vi.fn();
const context = createChatContext();
await runNonStreamingChatSend({
context,
respond,
idempotencyKey: "idem-gateway-client-scopes",
message: "/scopecheck",
client: {
connect: {
scopes: ["operator.write", "operator.pairing"],
client: {
id: "openclaw-cli",
mode: "cli",
displayName: "openclaw-cli",
version: "1.0.0",
},
},
},
expectBroadcast: false,
});
expect(mockState.lastDispatchCtx?.GatewayClientScopes).toEqual([
"operator.write",
"operator.pairing",
]);
expect(mockState.lastDispatchCtx?.CommandBody).toBe("/scopecheck");
});
it("injects ACP system provenance into the agent-visible body", async () => {
createTranscriptFixture("openclaw-chat-send-system-provenance-acp-");
mockState.finalText = "ok";