mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-17 04:01:05 +00:00
test: trim config migration smoke coverage
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { CallGatewayOptions } from "../../gateway/call.js";
|
||||
import { setActivePluginRegistry } from "../../plugins/runtime.js";
|
||||
import { createSessionConversationTestRegistry } from "../../test-utils/session-conversation-registry.js";
|
||||
import { runSessionsSendA2AFlow, __testing } from "./sessions-send-tool.a2a.js";
|
||||
@@ -13,15 +14,17 @@ vi.mock("./agent-step.js", () => ({
|
||||
}));
|
||||
|
||||
describe("runSessionsSendA2AFlow announce delivery", () => {
|
||||
type CallGatewayDep = NonNullable<
|
||||
NonNullable<Parameters<typeof __testing.setDepsForTest>[0]>["callGateway"]
|
||||
>;
|
||||
let mockCallGateway: ReturnType<typeof vi.fn> & CallGatewayDep;
|
||||
let gatewayCalls: CallGatewayOptions[];
|
||||
|
||||
beforeEach(() => {
|
||||
setActivePluginRegistry(createSessionConversationTestRegistry());
|
||||
mockCallGateway = vi.fn().mockResolvedValue({}) as ReturnType<typeof vi.fn> & CallGatewayDep;
|
||||
__testing.setDepsForTest({ callGateway: mockCallGateway });
|
||||
gatewayCalls = [];
|
||||
__testing.setDepsForTest({
|
||||
callGateway: async <T = Record<string, unknown>>(opts: CallGatewayOptions) => {
|
||||
gatewayCalls.push(opts);
|
||||
return {} as T;
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
@@ -40,11 +43,9 @@ describe("runSessionsSendA2AFlow announce delivery", () => {
|
||||
});
|
||||
|
||||
// Find the gateway send call (not the waitForAgentRun call)
|
||||
const sendCall = mockCallGateway.mock.calls.find(
|
||||
(call: unknown[]) => (call[0] as { method: string }).method === "send",
|
||||
);
|
||||
const sendCall = gatewayCalls.find((call) => call.method === "send");
|
||||
expect(sendCall).toBeDefined();
|
||||
const sendParams = (sendCall![0] as { params: Record<string, unknown> }).params;
|
||||
const sendParams = sendCall?.params as Record<string, unknown>;
|
||||
expect(sendParams.to).toBe("-100123");
|
||||
expect(sendParams.channel).toBe("telegram");
|
||||
expect(sendParams.threadId).toBe("554");
|
||||
@@ -60,11 +61,9 @@ describe("runSessionsSendA2AFlow announce delivery", () => {
|
||||
roundOneReply: "Worker completed successfully",
|
||||
});
|
||||
|
||||
const sendCall = mockCallGateway.mock.calls.find(
|
||||
(call: unknown[]) => (call[0] as { method: string }).method === "send",
|
||||
);
|
||||
const sendCall = gatewayCalls.find((call) => call.method === "send");
|
||||
expect(sendCall).toBeDefined();
|
||||
const sendParams = (sendCall![0] as { params: Record<string, unknown> }).params;
|
||||
const sendParams = sendCall?.params as Record<string, unknown>;
|
||||
expect(sendParams.channel).toBe("discord");
|
||||
expect(sendParams.threadId).toBeUndefined();
|
||||
});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { applyLegacyDoctorMigrations } from "../commands/doctor/shared/legacy-config-migrate.js";
|
||||
import { applyRuntimeLegacyConfigMigrations } from "../commands/doctor/shared/runtime-compat-api.js";
|
||||
import {
|
||||
getConfigValueAtPath,
|
||||
@@ -760,224 +759,6 @@ describe("config strict validation", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("accepts legacy channel streaming aliases via auto-migration and reports legacyIssues", () => {
|
||||
const raw = {
|
||||
channels: {
|
||||
discord: {
|
||||
accounts: {
|
||||
work: {
|
||||
streamMode: "block",
|
||||
draftChunk: {
|
||||
maxChars: 900,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const migrated = applyLegacyDoctorMigrations(raw);
|
||||
expect(migrated.next).not.toBeNull();
|
||||
|
||||
if (!migrated.next) {
|
||||
return;
|
||||
}
|
||||
const channels = (
|
||||
migrated.next as {
|
||||
channels?: {
|
||||
discord?: { accounts?: { work?: unknown } };
|
||||
};
|
||||
}
|
||||
).channels;
|
||||
expect(channels?.discord?.accounts?.work).toMatchObject({
|
||||
streaming: {
|
||||
mode: "block",
|
||||
preview: {
|
||||
chunk: {
|
||||
maxChars: 900,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("accepts legacy nested channel allow aliases via auto-migration and reports legacyIssues", () => {
|
||||
const raw = {
|
||||
channels: {
|
||||
slack: {
|
||||
channels: {
|
||||
ops: {
|
||||
allow: false,
|
||||
},
|
||||
},
|
||||
accounts: {
|
||||
work: {
|
||||
channels: {
|
||||
general: {
|
||||
allow: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
googlechat: {
|
||||
groups: {
|
||||
"spaces/aaa": {
|
||||
allow: false,
|
||||
},
|
||||
},
|
||||
accounts: {
|
||||
work: {
|
||||
groups: {
|
||||
"spaces/bbb": {
|
||||
allow: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
discord: {
|
||||
guilds: {
|
||||
"100": {
|
||||
channels: {
|
||||
general: {
|
||||
allow: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
accounts: {
|
||||
work: {
|
||||
guilds: {
|
||||
"200": {
|
||||
channels: {
|
||||
help: {
|
||||
allow: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const issues = findLegacyConfigIssues(raw);
|
||||
const migrated = applyRuntimeLegacyConfigMigrations(raw);
|
||||
|
||||
expect(issues.some((issue) => issue.path === "channels.slack")).toBe(true);
|
||||
expect(issues.some((issue) => issue.path === "channels.slack.accounts")).toBe(true);
|
||||
expect(issues.some((issue) => issue.path === "channels.googlechat")).toBe(true);
|
||||
expect(issues.some((issue) => issue.path === "channels.googlechat.accounts")).toBe(true);
|
||||
expect(issues.some((issue) => issue.path === "channels.discord")).toBe(true);
|
||||
expect(issues.some((issue) => issue.path === "channels.discord.accounts")).toBe(true);
|
||||
expect(migrated.next).not.toBeNull();
|
||||
|
||||
const next = migrated.next as {
|
||||
channels?: {
|
||||
slack?: {
|
||||
channels?: {
|
||||
ops?: {
|
||||
enabled?: boolean;
|
||||
allow?: unknown;
|
||||
};
|
||||
};
|
||||
};
|
||||
googlechat?: {
|
||||
groups?: {
|
||||
"spaces/aaa"?: {
|
||||
enabled?: boolean;
|
||||
allow?: unknown;
|
||||
};
|
||||
};
|
||||
};
|
||||
discord?: {
|
||||
guilds?: {
|
||||
"100"?: {
|
||||
channels?: {
|
||||
general?: {
|
||||
enabled?: boolean;
|
||||
allow?: unknown;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
} | null;
|
||||
expect(next?.channels?.slack?.channels?.ops).toMatchObject({
|
||||
enabled: false,
|
||||
});
|
||||
expect(next?.channels?.googlechat?.groups?.["spaces/aaa"]).toMatchObject({
|
||||
enabled: false,
|
||||
});
|
||||
expect(next?.channels?.discord?.guilds?.["100"]?.channels?.general).toMatchObject({
|
||||
enabled: false,
|
||||
});
|
||||
expect(next?.channels?.slack?.channels?.ops?.allow).toBeUndefined();
|
||||
expect(next?.channels?.googlechat?.groups?.["spaces/aaa"]?.allow).toBeUndefined();
|
||||
expect(next?.channels?.discord?.guilds?.["100"]?.channels?.general?.allow).toBeUndefined();
|
||||
});
|
||||
|
||||
it("accepts legacy discord voice tts provider keys via auto-migration and reports legacyIssues", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
await writeOpenClawConfig(home, {
|
||||
channels: {
|
||||
discord: {
|
||||
voice: {
|
||||
tts: {
|
||||
provider: "elevenlabs",
|
||||
elevenlabs: {
|
||||
voiceId: "voice-1",
|
||||
},
|
||||
},
|
||||
},
|
||||
accounts: {
|
||||
main: {
|
||||
voice: {
|
||||
tts: {
|
||||
edge: {
|
||||
voice: "en-US-AvaNeural",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const snap = await readConfigFileSnapshot();
|
||||
|
||||
expect(snap.valid).toBe(true);
|
||||
expect(snap.legacyIssues.some((issue) => issue.path === "channels.discord.voice.tts")).toBe(
|
||||
true,
|
||||
);
|
||||
expect(snap.legacyIssues.some((issue) => issue.path === "channels.discord.accounts")).toBe(
|
||||
true,
|
||||
);
|
||||
expect(snap.sourceConfig.channels?.discord?.voice?.tts?.providers?.elevenlabs).toEqual({
|
||||
voiceId: "voice-1",
|
||||
});
|
||||
expect(
|
||||
snap.sourceConfig.channels?.discord?.accounts?.main?.voice?.tts?.providers?.microsoft,
|
||||
).toEqual({
|
||||
voice: "en-US-AvaNeural",
|
||||
});
|
||||
expect(
|
||||
(snap.sourceConfig.channels?.discord?.voice?.tts as Record<string, unknown> | undefined)
|
||||
?.elevenlabs,
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
(
|
||||
snap.sourceConfig.channels?.discord?.accounts?.main?.voice?.tts as
|
||||
| Record<string, unknown>
|
||||
| undefined
|
||||
)?.edge,
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
it("does not treat resolved-only gateway.bind aliases as source-literal legacy or invalid", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
await writeOpenClawConfig(home, {
|
||||
|
||||
Reference in New Issue
Block a user