test: exercise command json payloads

This commit is contained in:
Shakker
2026-05-11 20:28:28 +01:00
parent 0961d5c8a8
commit b6027cb40e
2 changed files with 63 additions and 26 deletions
+44 -8
View File
@@ -224,15 +224,51 @@ describe("gateway status output", () => {
ok?: unknown;
degraded?: unknown;
primaryTargetId?: unknown;
targets?: Array<{ connect?: { ok?: unknown; rpcOk?: unknown; error?: unknown } }>;
targets?: unknown;
warnings?: unknown;
}
| undefined;
expect(payload?.ok).toBe(true);
expect(payload?.degraded).toBe(true);
expect(payload?.primaryTargetId).toBe("detail-timeout");
expect(payload?.targets).toHaveLength(1);
expect(payload?.targets?.[0]?.connect?.ok).toBe(true);
expect(payload?.targets?.[0]?.connect?.rpcOk).toBe(false);
expect(payload?.targets?.[0]?.connect?.error).toBe("timeout");
expect(payload).toStrictEqual(
expect.objectContaining({
degraded: true,
ok: true,
primaryTargetId: "detail-timeout",
targets: [
expect.objectContaining({
active: true,
auth: {
capability: "read_only",
role: "operator",
scopes: ["operator.read"],
},
config: null,
connect: {
close: null,
error: "timeout",
latencyMs: 40,
ok: true,
rpcOk: false,
scopeLimited: false,
},
health: null,
id: "detail-timeout",
kind: "explicit",
presence: null,
self: null,
summary: null,
tunnel: null,
url: "ws://127.0.0.1:18789",
}),
],
warnings: [
{
code: "probe_detail_failed",
message:
"Gateway accepted the WebSocket connection, but follow-up read diagnostics failed: timeout",
targetIds: ["detail-timeout"],
},
],
}),
);
});
});
+19 -18
View File
@@ -94,25 +94,26 @@ describe("modelsAuthListCommand", () => {
cfg: {},
provider: "openai-codex",
});
expect(runtime.jsonPayloads).toHaveLength(1);
expect(runtime.jsonPayloads).toStrictEqual([
expect.objectContaining({
agentDir: "/tmp/openclaw/agents/coder",
agentId: "coder",
authStatePath: "/tmp/openclaw/agents/coder/auth-state.json",
profiles: [
{
cooldownUntil: "2027-01-15T08:00:10.000Z",
email: "user@example.com",
expiresAt: "2027-01-15T08:00:00.000Z",
id: "openai-codex:user@example.com",
label: "openai-codex:user@example.com",
provider: "openai-codex",
type: "oauth",
},
],
provider: "openai-codex",
}),
]);
expect(JSON.stringify(runtime.jsonPayloads[0])).not.toContain("secret");
const payload = runtime.jsonPayloads[0] as
| {
agentId?: unknown;
provider?: unknown;
profiles?: Array<Record<string, unknown>>;
}
| undefined;
expect(payload?.agentId).toBe("coder");
expect(payload?.provider).toBe("openai-codex");
expect(payload?.profiles).toHaveLength(1);
const [profile] = payload?.profiles ?? [];
expect(profile?.id).toBe("openai-codex:user@example.com");
expect(profile?.provider).toBe("openai-codex");
expect(profile?.type).toBe("oauth");
expect(profile?.email).toBe("user@example.com");
expect(profile?.expiresAt).toBe("2027-01-15T08:00:00.000Z");
expect(profile?.cooldownUntil).toBe("2027-01-15T08:00:10.000Z");
});
it("prints an empty profile list without failing", async () => {