test: dedupe and optimize test suites

This commit is contained in:
Peter Steinberger
2026-02-19 15:18:50 +00:00
parent b0e55283d5
commit a1cb700a05
80 changed files with 2627 additions and 2962 deletions

View File

@@ -29,22 +29,30 @@ function makeRuntime() {
}
describe("ensureConfigReady", () => {
async function runEnsureConfigReady(commandPath: string[]) {
vi.resetModules();
const { ensureConfigReady } = await import("./config-guard.js");
await ensureConfigReady({ runtime: makeRuntime() as never, commandPath });
}
beforeEach(() => {
vi.clearAllMocks();
readConfigFileSnapshotMock.mockResolvedValue(makeSnapshot());
});
it("skips doctor flow for read-only fast path commands", async () => {
vi.resetModules();
const { ensureConfigReady } = await import("./config-guard.js");
await ensureConfigReady({ runtime: makeRuntime() as never, commandPath: ["status"] });
expect(loadAndMaybeMigrateDoctorConfigMock).not.toHaveBeenCalled();
});
it("runs doctor flow for commands that may mutate state", async () => {
vi.resetModules();
const { ensureConfigReady } = await import("./config-guard.js");
await ensureConfigReady({ runtime: makeRuntime() as never, commandPath: ["message"] });
expect(loadAndMaybeMigrateDoctorConfigMock).toHaveBeenCalledTimes(1);
it.each([
{
name: "skips doctor flow for read-only fast path commands",
commandPath: ["status"],
expectedDoctorCalls: 0,
},
{
name: "runs doctor flow for commands that may mutate state",
commandPath: ["message"],
expectedDoctorCalls: 1,
},
])("$name", async ({ commandPath, expectedDoctorCalls }) => {
await runEnsureConfigReady(commandPath);
expect(loadAndMaybeMigrateDoctorConfigMock).toHaveBeenCalledTimes(expectedDoctorCalls);
});
});