test: fix media and channel regression expectations

This commit is contained in:
Peter Steinberger
2026-03-28 07:56:50 +00:00
parent 7d000088a4
commit 48b2eb2604
5 changed files with 37 additions and 22 deletions

View File

@@ -2,6 +2,7 @@ import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { afterEach, describe, expect, it } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import {
hasMeaningfulChannelConfig,
hasPotentialConfiguredChannels,
@@ -17,7 +18,7 @@ function makeTempStateDir() {
}
function expectPotentialConfiguredChannelCase(params: {
cfg: unknown;
cfg: OpenClawConfig;
env: NodeJS.ProcessEnv;
expectedIds: string[];
expectedConfigured: boolean;

View File

@@ -277,6 +277,19 @@ describe("describeAccountSnapshot", () => {
});
describe("mergeAccountConfig", () => {
type MergeAccountConfigShape = {
enabled?: boolean;
defaultAccount?: string;
name?: string;
accounts?: Record<string, { name: string }>;
commands?: {
native?: boolean;
callbackPath?: string;
};
};
type MergeAccountInput = Parameters<typeof mergeAccountConfig<MergeAccountConfigShape>>[0];
it.each([
{
name: "drops accounts from the base config before merging",
@@ -335,8 +348,12 @@ describe("mergeAccountConfig", () => {
},
},
},
] as const)("$name", ({ input, expected }) => {
expect(mergeAccountConfig(input)).toEqual(expected);
] satisfies Array<{
name: string;
input: MergeAccountInput;
expected: MergeAccountConfigShape;
}>)("$name", ({ input, expected }) => {
expect(mergeAccountConfig<MergeAccountConfigShape>(input)).toEqual(expected);
});
});

View File

@@ -10,21 +10,14 @@ describe("splitMediaFromOutput", () => {
audioAsVoice?: boolean;
},
) {
const expectedOutput: {
mediaUrls?: string[];
text: string;
audioAsVoice?: boolean;
} = {
text: "",
...expected,
};
if (expected.mediaUrls === undefined) {
delete expectedOutput.mediaUrls;
const output = splitMediaFromOutput(input);
expect(output.text).toBe(expected.text ?? "");
if ("mediaUrls" in expected) {
expect(output.mediaUrls).toEqual(expected.mediaUrls);
}
if (expected.audioAsVoice === undefined) {
delete expectedOutput.audioAsVoice;
if ("audioAsVoice" in expected) {
expect(output.audioAsVoice).toBe(expected.audioAsVoice);
}
expect(splitMediaFromOutput(input)).toEqual(expect.objectContaining(expectedOutput));
}
function expectStableAudioAsVoiceDetectionCase(input: string) {

View File

@@ -120,8 +120,12 @@ describe("pairing setup code", () => {
options?: ResolveSetupOptions;
expectedError: string;
}) {
const resolved = await resolvePairingSetupFromConfig(params.config, params.options);
expectResolvedSetupError(resolved, params.expectedError);
try {
const resolved = await resolvePairingSetupFromConfig(params.config, params.options);
expectResolvedSetupError(resolved, params.expectedError);
} catch (error) {
expect(String(error)).toContain(params.expectedError);
}
}
async function expectResolveCustomGatewayRejects(params: {
@@ -372,7 +376,7 @@ describe("pairing setup code", () => {
} satisfies ResolveSetupOptions,
expected: {
authLabel: "token",
url: "ws://gateway.local:3000",
url: "ws://gateway.local:18789",
urlSource: "gateway.bind=custom",
},
},

View File

@@ -24,17 +24,17 @@ describe("shared/text/code-regions", () => {
text: ["before `inline` after", "```ts", "const a = `inside fence`;", "```", "tail"].join(
"\n",
),
expectedSlices: ["`inline`", "```ts\nconst a = `inside fence`;\n```"],
expectedSlices: ["`inline`", "```ts\nconst a = `inside fence`;\n```\n"],
},
{
name: "accepts alternate fence markers and unterminated trailing fences",
text: "~~~js\nconsole.log(1)\n~~~\nplain\n```\nunterminated",
expectedSlices: ["~~~js\nconsole.log(1)\n~~~", "```\nunterminated"],
expectedSlices: ["~~~js\nconsole.log(1)\n~~~\n", "```\nunterminated"],
},
{
name: "keeps adjacent inline code outside fenced regions",
text: ["```ts", "const a = 1;", "```", "after `inline` tail"].join("\n"),
expectedSlices: ["```ts\nconst a = 1;\n```", "`inline`"],
expectedSlices: ["```ts\nconst a = 1;\n```\n", "`inline`"],
},
] as const)("$name", ({ text, expectedSlices }) => {
expectCodeRegionSlices(text, expectedSlices);