feat(llm): propagate cancellation through reconstruction providers
This commit is contained in:
@@ -128,6 +128,38 @@ describe("OllamaLlmProvider chat capability detection", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("forwards caller cancellation to the Ollama capability probe without starting inference", async () => {
|
||||
const originalBaseUrl = process.env.OLLAMA_BASE_URL;
|
||||
const controller = new AbortController();
|
||||
const fetchSpy = vi.fn().mockImplementation((_, options) => new Promise((_, reject) => {
|
||||
options.signal.addEventListener("abort", () => {
|
||||
const error = new Error("aborted");
|
||||
error.name = "AbortError";
|
||||
reject(error);
|
||||
}, { once: true });
|
||||
}));
|
||||
vi.stubGlobal("fetch", fetchSpy);
|
||||
process.env.OLLAMA_BASE_URL = "http://ollama.test";
|
||||
|
||||
try {
|
||||
__resetChatSupportForTests();
|
||||
const request = getProvider().generateReconstruction(
|
||||
"prompt",
|
||||
"configured-model",
|
||||
undefined,
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
controller.abort();
|
||||
await expect(request).rejects.toMatchObject({ name: "AbortError" });
|
||||
expect(fetchSpy).toHaveBeenCalledTimes(1);
|
||||
expect(fetchSpy.mock.calls[0][1].signal).toBe(controller.signal);
|
||||
} finally {
|
||||
vi.unstubAllGlobals();
|
||||
if (originalBaseUrl === undefined) delete process.env.OLLAMA_BASE_URL;
|
||||
else process.env.OLLAMA_BASE_URL = originalBaseUrl;
|
||||
}
|
||||
});
|
||||
|
||||
it("reports chat-skipped generate fallback execution", async () => {
|
||||
const originalBaseUrl = process.env.OLLAMA_BASE_URL;
|
||||
const fetchSpy = vi.fn()
|
||||
@@ -393,6 +425,29 @@ describe("OpenAI reconstruction provider experiment seam", () => {
|
||||
assertStrictObjectInvariant(reparsedSchema);
|
||||
});
|
||||
|
||||
it("forwards caller cancellation to the OpenAI response request", async () => {
|
||||
const controller = new AbortController();
|
||||
const fetchSpy = vi.fn().mockImplementation((_, options) => new Promise((_, reject) => {
|
||||
options.signal.addEventListener("abort", () => {
|
||||
const error = new Error("aborted");
|
||||
error.name = "AbortError";
|
||||
reject(error);
|
||||
}, { once: true });
|
||||
}));
|
||||
const provider = createOpenAIReconstructionProvider({ apiKey: "test-key", fetchImpl: fetchSpy });
|
||||
|
||||
const request = provider.generateReconstruction(
|
||||
"focused prompt",
|
||||
"gpt-5.6-terra",
|
||||
focusedDeconstructJsonSchema,
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
controller.abort();
|
||||
|
||||
await expect(request).rejects.toMatchObject({ name: "AbortError" });
|
||||
expect(fetchSpy.mock.calls[0][1].signal).toBe(controller.signal);
|
||||
});
|
||||
|
||||
it("emits one safe final-schema trace only when explicitly enabled", async () => {
|
||||
const previousTraceFlag = process.env.CONFIDENCE_ENGINE_EXPERIMENT_TRACE_OPENAI_SCHEMA;
|
||||
const infoSpy = vi.spyOn(console, "info").mockImplementation(() => {});
|
||||
|
||||
Reference in New Issue
Block a user