test: tighten outbound route assertions

This commit is contained in:
Peter Steinberger
2026-05-11 12:37:12 +01:00
parent 5569973d90
commit f57bcb0788
3 changed files with 19 additions and 10 deletions

View File

@@ -167,7 +167,9 @@ describe("agent delivery helpers", () => {
},
])("builds delivery plan for %j", ({ params, expected }) => {
const plan = expectDeliveryPlan(params);
expect(plan).toMatchObject(expected);
for (const [key, value] of Object.entries(expected)) {
expect((plan as Record<string, unknown>)[key]).toEqual(value);
}
});
it("resolves fallback targets when no explicit destination is provided", () => {

View File

@@ -188,7 +188,9 @@ describe("bound delivery router", () => {
failClosed,
});
expect(route).toMatchObject(expected);
for (const [key, value] of Object.entries(expected)) {
expect((route as Record<string, unknown>)[key]).toEqual(value);
}
if (expectedConversationId !== undefined) {
expect(route.binding?.conversation.conversationId).toBe(expectedConversationId);
}

View File

@@ -3,8 +3,13 @@ import type { OpenClawConfig } from "../../config/config.js";
import { ensureOutboundSessionEntry, resolveOutboundSessionRoute } from "./outbound-session.js";
import { setMinimalOutboundSessionPluginRegistryForTests } from "./outbound-session.test-helpers.js";
type InboundMetadataParams = {
sessionKey?: string;
storePath?: string;
};
const mocks = vi.hoisted(() => ({
recordSessionMetaFromInbound: vi.fn(async () => ({ ok: true })),
recordSessionMetaFromInbound: vi.fn(async (_params: InboundMetadataParams) => ({ ok: true })),
resolveStorePath: vi.fn(
(_store: unknown, params?: { agentId?: string }) => `/stores/${params?.agentId ?? "main"}.json`,
),
@@ -394,7 +399,9 @@ describe("resolveOutboundSessionRoute", () => {
resolvedTarget,
});
expect(route).toMatchObject(expected);
for (const [key, value] of Object.entries(expected)) {
expect((route as Record<string, unknown>)[key]).toEqual(value);
}
});
it("rejects bare numeric GuildChat targets when the caller has no kind hint", async () => {
@@ -436,11 +443,9 @@ describe("ensureOutboundSessionEntry", () => {
expect(mocks.resolveStorePath).toHaveBeenCalledWith("/stores/{agentId}.json", {
agentId: "main",
});
expect(mocks.recordSessionMetaFromInbound).toHaveBeenCalledWith(
expect.objectContaining({
storePath: "/stores/main.json",
sessionKey: "agent:main:workspace:channel:c1",
}),
);
expect(mocks.recordSessionMetaFromInbound).toHaveBeenCalledOnce();
const metadata = mocks.recordSessionMetaFromInbound.mock.calls[0]?.[0];
expect(metadata?.storePath).toBe("/stores/main.json");
expect(metadata?.sessionKey).toBe("agent:main:workspace:channel:c1");
});
});