fix: harden workspace diagnostics probes
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { expect, test, vi } from "vitest";
|
||||
import {
|
||||
createProductionWorkspaceDiagnoser,
|
||||
createWorkspaceDiagnoser,
|
||||
type DiagnosticAdapters,
|
||||
} from "../src/workspaces/diagnostics.js";
|
||||
@@ -233,3 +234,31 @@ test("requires a matching embedding model vector and removes its unique write pr
|
||||
id: expect.stringMatching(/^diagnostic:/),
|
||||
}));
|
||||
});
|
||||
|
||||
test("constructs the production diagnoser with the configured timeout and injected adapters", async () => {
|
||||
const adapters = successfulAdapters();
|
||||
|
||||
const result = await createProductionWorkspaceDiagnoser(1234, adapters)(workspace, bindings, {
|
||||
writeProbe: false,
|
||||
});
|
||||
|
||||
expect(result.activatable).toBe(true);
|
||||
expect(adapters.probeConnector).toHaveBeenCalledWith(expect.objectContaining({ timeoutMs: 1234 }));
|
||||
expect(adapters.probeEmbedding).toHaveBeenCalledWith(expect.objectContaining({ timeoutMs: 1234 }));
|
||||
});
|
||||
|
||||
test("retries bounded cleanup after a write-probe removal times out", async () => {
|
||||
const adapters = successfulAdapters({
|
||||
removeDiagnosticRecord: vi.fn(() => new Promise<void>(() => undefined)),
|
||||
});
|
||||
const diagnoseWithShortTimeout = createWorkspaceDiagnoser(adapters, { timeoutMs: 10 });
|
||||
|
||||
const startedAt = Date.now();
|
||||
const result = await diagnoseWithShortTimeout(workspace, bindings, { writeProbe: true });
|
||||
|
||||
expect(Date.now() - startedAt).toBeLessThan(250);
|
||||
expect(adapters.writeDiagnosticRecord).toHaveBeenCalledTimes(1);
|
||||
expect(adapters.removeDiagnosticRecord).toHaveBeenCalledTimes(2);
|
||||
expect(result).toMatchObject({ activatable: false });
|
||||
expect(JSON.stringify(result)).not.toContain("timeout");
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user