test: cover heartbeat doctor and include migration paths

This commit is contained in:
Gustavo Madeira Santana
2026-03-03 19:39:51 -05:00
parent e842ec39fc
commit 9173a4ba73
2 changed files with 67 additions and 0 deletions

View File

@@ -600,6 +600,36 @@ describe("doctor config flow", () => {
expectGoogleChatDmAllowFromRepaired(result.cfg);
});
it("migrates top-level heartbeat into agents.defaults.heartbeat on repair", async () => {
const result = await runDoctorConfigWithInput({
repair: true,
config: {
heartbeat: {
model: "anthropic/claude-3-5-haiku-20241022",
every: "30m",
},
},
run: loadAndMaybeMigrateDoctorConfig,
});
const cfg = result.cfg as {
heartbeat?: unknown;
agents?: {
defaults?: {
heartbeat?: {
model?: string;
every?: string;
};
};
};
};
expect(cfg.heartbeat).toBeUndefined();
expect(cfg.agents?.defaults?.heartbeat).toMatchObject({
model: "anthropic/claude-3-5-haiku-20241022",
every: "30m",
});
});
it("repairs googlechat account dm.policy open by setting dm.allowFrom on repair", async () => {
const result = await runDoctorConfigWithInput({
repair: true,

View File

@@ -43,4 +43,41 @@ describe("gateway startup legacy migration fallback", () => {
);
expect(message).not.toContain("Legacy config entries detected but auto-migration failed.");
});
test("keeps detailed validation errors when heartbeat comes from include-resolved config", async () => {
testState.legacyIssues = [
{
path: "heartbeat",
message:
"top-level heartbeat is not a valid config path; use agents.defaults.heartbeat instead.",
},
];
// Simulate a parsed source that only contains include directives, while
// legacy heartbeat is surfaced from the resolved config.
testState.legacyParsed = {
$include: ["heartbeat.defaults.json"],
};
testState.migrationConfig = null;
testState.migrationChanges = [];
let server: Awaited<ReturnType<typeof startGatewayServer>> | undefined;
let thrown: unknown;
try {
server = await startGatewayServer(await getFreePort());
} catch (err) {
thrown = err;
}
if (server) {
await server.close();
}
expect(thrown).toBeInstanceOf(Error);
const message = String((thrown as Error).message);
expect(message).toContain("Invalid config at");
expect(message).toContain(
"heartbeat: top-level heartbeat is not a valid config path; use agents.defaults.heartbeat instead.",
);
expect(message).not.toContain("Legacy config entries detected but auto-migration failed.");
});
});