mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 19:18:26 +00:00
test(doctor): tighten legacy migration e2e timeout budgets
This commit is contained in:
@@ -15,32 +15,38 @@ import {
|
|||||||
writeConfigFile,
|
writeConfigFile,
|
||||||
} from "./doctor.e2e-harness.js";
|
} from "./doctor.e2e-harness.js";
|
||||||
|
|
||||||
|
const DOCTOR_MIGRATION_TIMEOUT_MS = 20_000;
|
||||||
|
|
||||||
describe("doctor command", () => {
|
describe("doctor command", () => {
|
||||||
it("migrates routing.allowFrom to channels.whatsapp.allowFrom", { timeout: 60_000 }, async () => {
|
it(
|
||||||
mockDoctorConfigSnapshot({
|
"migrates routing.allowFrom to channels.whatsapp.allowFrom",
|
||||||
parsed: { routing: { allowFrom: ["+15555550123"] } },
|
{ timeout: DOCTOR_MIGRATION_TIMEOUT_MS },
|
||||||
valid: false,
|
async () => {
|
||||||
issues: [{ path: "routing.allowFrom", message: "legacy" }],
|
mockDoctorConfigSnapshot({
|
||||||
legacyIssues: [{ path: "routing.allowFrom", message: "legacy" }],
|
parsed: { routing: { allowFrom: ["+15555550123"] } },
|
||||||
});
|
valid: false,
|
||||||
|
issues: [{ path: "routing.allowFrom", message: "legacy" }],
|
||||||
|
legacyIssues: [{ path: "routing.allowFrom", message: "legacy" }],
|
||||||
|
});
|
||||||
|
|
||||||
const { doctorCommand } = await import("./doctor.js");
|
const { doctorCommand } = await import("./doctor.js");
|
||||||
const runtime = createDoctorRuntime();
|
const runtime = createDoctorRuntime();
|
||||||
|
|
||||||
migrateLegacyConfig.mockReturnValue({
|
migrateLegacyConfig.mockReturnValue({
|
||||||
config: { channels: { whatsapp: { allowFrom: ["+15555550123"] } } },
|
config: { channels: { whatsapp: { allowFrom: ["+15555550123"] } } },
|
||||||
changes: ["Moved routing.allowFrom → channels.whatsapp.allowFrom."],
|
changes: ["Moved routing.allowFrom → channels.whatsapp.allowFrom."],
|
||||||
});
|
});
|
||||||
|
|
||||||
await doctorCommand(runtime, { nonInteractive: true, repair: true });
|
await doctorCommand(runtime, { nonInteractive: true, repair: true });
|
||||||
|
|
||||||
expect(writeConfigFile).toHaveBeenCalledTimes(1);
|
expect(writeConfigFile).toHaveBeenCalledTimes(1);
|
||||||
const written = writeConfigFile.mock.calls[0]?.[0] as Record<string, unknown>;
|
const written = writeConfigFile.mock.calls[0]?.[0] as Record<string, unknown>;
|
||||||
expect((written.channels as Record<string, unknown>)?.whatsapp).toEqual({
|
expect((written.channels as Record<string, unknown>)?.whatsapp).toEqual({
|
||||||
allowFrom: ["+15555550123"],
|
allowFrom: ["+15555550123"],
|
||||||
});
|
});
|
||||||
expect(written.routing).toBeUndefined();
|
expect(written.routing).toBeUndefined();
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
it("does not add a new gateway auth token while fixing legacy issues on invalid config", async () => {
|
it("does not add a new gateway auth token while fixing legacy issues on invalid config", async () => {
|
||||||
mockDoctorConfigSnapshot({
|
mockDoctorConfigSnapshot({
|
||||||
@@ -80,25 +86,29 @@ describe("doctor command", () => {
|
|||||||
expect(auth).toBeUndefined();
|
expect(auth).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("skips legacy gateway services migration", { timeout: 60_000 }, async () => {
|
it(
|
||||||
mockDoctorConfigSnapshot();
|
"skips legacy gateway services migration",
|
||||||
|
{ timeout: DOCTOR_MIGRATION_TIMEOUT_MS },
|
||||||
|
async () => {
|
||||||
|
mockDoctorConfigSnapshot();
|
||||||
|
|
||||||
findLegacyGatewayServices.mockResolvedValueOnce([
|
findLegacyGatewayServices.mockResolvedValueOnce([
|
||||||
{
|
{
|
||||||
platform: "darwin",
|
platform: "darwin",
|
||||||
label: "com.steipete.openclaw.gateway",
|
label: "com.steipete.openclaw.gateway",
|
||||||
detail: "loaded",
|
detail: "loaded",
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
serviceIsLoaded.mockResolvedValueOnce(false);
|
serviceIsLoaded.mockResolvedValueOnce(false);
|
||||||
serviceInstall.mockClear();
|
serviceInstall.mockClear();
|
||||||
|
|
||||||
const { doctorCommand } = await import("./doctor.js");
|
const { doctorCommand } = await import("./doctor.js");
|
||||||
await doctorCommand(createDoctorRuntime());
|
await doctorCommand(createDoctorRuntime());
|
||||||
|
|
||||||
expect(uninstallLegacyGatewayServices).not.toHaveBeenCalled();
|
expect(uninstallLegacyGatewayServices).not.toHaveBeenCalled();
|
||||||
expect(serviceInstall).not.toHaveBeenCalled();
|
expect(serviceInstall).not.toHaveBeenCalled();
|
||||||
});
|
},
|
||||||
|
);
|
||||||
|
|
||||||
it("offers to update first for git checkouts", async () => {
|
it("offers to update first for git checkouts", async () => {
|
||||||
delete process.env.OPENCLAW_UPDATE_IN_PROGRESS;
|
delete process.env.OPENCLAW_UPDATE_IN_PROGRESS;
|
||||||
|
|||||||
@@ -1,48 +1,54 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
import { readConfigFileSnapshot, writeConfigFile } from "./doctor.e2e-harness.js";
|
import { readConfigFileSnapshot, writeConfigFile } from "./doctor.e2e-harness.js";
|
||||||
|
|
||||||
|
const DOCTOR_MIGRATION_TIMEOUT_MS = 20_000;
|
||||||
|
|
||||||
describe("doctor command", () => {
|
describe("doctor command", () => {
|
||||||
it("migrates Slack/Discord dm.policy keys to dmPolicy aliases", { timeout: 60_000 }, async () => {
|
it(
|
||||||
readConfigFileSnapshot.mockResolvedValue({
|
"migrates Slack/Discord dm.policy keys to dmPolicy aliases",
|
||||||
path: "/tmp/openclaw.json",
|
{ timeout: DOCTOR_MIGRATION_TIMEOUT_MS },
|
||||||
exists: true,
|
async () => {
|
||||||
raw: "{}",
|
readConfigFileSnapshot.mockResolvedValue({
|
||||||
parsed: {
|
path: "/tmp/openclaw.json",
|
||||||
channels: {
|
exists: true,
|
||||||
slack: { dm: { enabled: true, policy: "open", allowFrom: ["*"] } },
|
raw: "{}",
|
||||||
discord: {
|
parsed: {
|
||||||
dm: { enabled: true, policy: "allowlist", allowFrom: ["123"] },
|
channels: {
|
||||||
|
slack: { dm: { enabled: true, policy: "open", allowFrom: ["*"] } },
|
||||||
|
discord: {
|
||||||
|
dm: { enabled: true, policy: "allowlist", allowFrom: ["123"] },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
valid: true,
|
||||||
valid: true,
|
config: {
|
||||||
config: {
|
channels: {
|
||||||
channels: {
|
slack: { dm: { enabled: true, policy: "open", allowFrom: ["*"] } },
|
||||||
slack: { dm: { enabled: true, policy: "open", allowFrom: ["*"] } },
|
discord: { dm: { enabled: true, policy: "allowlist", allowFrom: ["123"] } },
|
||||||
discord: { dm: { enabled: true, policy: "allowlist", allowFrom: ["123"] } },
|
},
|
||||||
},
|
},
|
||||||
},
|
issues: [],
|
||||||
issues: [],
|
legacyIssues: [],
|
||||||
legacyIssues: [],
|
});
|
||||||
});
|
|
||||||
|
|
||||||
const { doctorCommand } = await import("./doctor.js");
|
const { doctorCommand } = await import("./doctor.js");
|
||||||
const runtime = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
|
const runtime = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
|
||||||
|
|
||||||
await doctorCommand(runtime, { nonInteractive: true, repair: true });
|
await doctorCommand(runtime, { nonInteractive: true, repair: true });
|
||||||
|
|
||||||
expect(writeConfigFile).toHaveBeenCalledTimes(1);
|
expect(writeConfigFile).toHaveBeenCalledTimes(1);
|
||||||
const written = writeConfigFile.mock.calls[0]?.[0] as Record<string, unknown>;
|
const written = writeConfigFile.mock.calls[0]?.[0] as Record<string, unknown>;
|
||||||
const channels = (written.channels ?? {}) as Record<string, unknown>;
|
const channels = (written.channels ?? {}) as Record<string, unknown>;
|
||||||
const slack = (channels.slack ?? {}) as Record<string, unknown>;
|
const slack = (channels.slack ?? {}) as Record<string, unknown>;
|
||||||
const discord = (channels.discord ?? {}) as Record<string, unknown>;
|
const discord = (channels.discord ?? {}) as Record<string, unknown>;
|
||||||
|
|
||||||
expect(slack.dmPolicy).toBe("open");
|
expect(slack.dmPolicy).toBe("open");
|
||||||
expect(slack.allowFrom).toEqual(["*"]);
|
expect(slack.allowFrom).toEqual(["*"]);
|
||||||
expect(slack.dm).toEqual({ enabled: true });
|
expect(slack.dm).toEqual({ enabled: true });
|
||||||
|
|
||||||
expect(discord.dmPolicy).toBe("allowlist");
|
expect(discord.dmPolicy).toBe("allowlist");
|
||||||
expect(discord.allowFrom).toEqual(["123"]);
|
expect(discord.allowFrom).toEqual(["123"]);
|
||||||
expect(discord.dm).toEqual({ enabled: true });
|
expect(discord.dm).toEqual({ enabled: true });
|
||||||
});
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user