test: add runServiceStart config pre-flight tests (#35862)

Address Greptile review: add test coverage for runServiceStart path.
The error message copy-paste issue was already fixed in the DRY refactor
(uses params.serviceNoun instead of hardcoded 'restart').
This commit is contained in:
merlin 2026-03-06 00:36:05 +08:00 committed by Peter Steinberger
parent 6740cdf160
commit 335223af32
1 changed files with 61 additions and 0 deletions

View File

@ -143,3 +143,64 @@ describe("runServiceRestart config pre-flight (#35862)", () => {
expect(service.restart).toHaveBeenCalledTimes(1);
});
});
describe("runServiceStart config pre-flight (#35862)", () => {
let runServiceStart: typeof import("./lifecycle-core.js").runServiceStart;
beforeAll(async () => {
({ runServiceStart } = await import("./lifecycle-core.js"));
});
beforeEach(() => {
runtimeLogs.length = 0;
readConfigFileSnapshotMock.mockReset();
readConfigFileSnapshotMock.mockResolvedValue({
exists: true,
valid: true,
config: {},
issues: [],
});
service.isLoaded.mockClear();
service.restart.mockClear();
service.isLoaded.mockResolvedValue(true);
service.restart.mockResolvedValue(undefined);
});
it("aborts start when config is invalid", async () => {
readConfigFileSnapshotMock.mockResolvedValue({
exists: true,
valid: false,
config: {},
issues: [{ path: "agents.defaults.pdfModel", message: "Unrecognized key" }],
});
await expect(
runServiceStart({
serviceNoun: "Gateway",
service,
renderStartHints: () => [],
opts: { json: true },
}),
).rejects.toThrow("__exit__:1");
expect(service.restart).not.toHaveBeenCalled();
});
it("proceeds with start when config is valid", async () => {
readConfigFileSnapshotMock.mockResolvedValue({
exists: true,
valid: true,
config: {},
issues: [],
});
await runServiceStart({
serviceNoun: "Gateway",
service,
renderStartHints: () => [],
opts: { json: true },
});
expect(service.restart).toHaveBeenCalledTimes(1);
});
});