34 lines
1.1 KiB
JavaScript
34 lines
1.1 KiB
JavaScript
|
|
import assert from "node:assert/strict";
|
||
|
|
import test from "node:test";
|
||
|
|
import { DeepSeekJsonClient, extractJson } from "./model-client.mjs";
|
||
|
|
|
||
|
|
test("extractJson accepts strict JSON and fenced JSON", () => {
|
||
|
|
assert.deepEqual(extractJson('{"ok":true}'), { ok: true });
|
||
|
|
assert.deepEqual(extractJson('```json\n{"ok":true}\n```'), { ok: true });
|
||
|
|
});
|
||
|
|
|
||
|
|
test("DeepSeek client sends the secret only as authorization and returns JSON", async () => {
|
||
|
|
let observed;
|
||
|
|
const client = new DeepSeekJsonClient({
|
||
|
|
apiKey: "test-secret",
|
||
|
|
apiUrl: "https://model.invalid/v1",
|
||
|
|
model: "fixture-model",
|
||
|
|
fetchImpl: async (url, options) => {
|
||
|
|
observed = { url, options };
|
||
|
|
return {
|
||
|
|
ok: true,
|
||
|
|
async json() {
|
||
|
|
return { choices: [{ message: { content: '{"decision":"ok"}' } }] };
|
||
|
|
},
|
||
|
|
};
|
||
|
|
},
|
||
|
|
});
|
||
|
|
const result = await client.generate({
|
||
|
|
role: "fixture",
|
||
|
|
instruction: "return json",
|
||
|
|
input: { event: "test" },
|
||
|
|
});
|
||
|
|
assert.deepEqual(result, { decision: "ok" });
|
||
|
|
assert.equal(observed.options.headers.authorization, "Bearer test-secret");
|
||
|
|
assert.equal(observed.options.body.includes("test-secret"), false);
|
||
|
|
});
|