40 lines
2.4 KiB
JavaScript
40 lines
2.4 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { getReasoningCapabilities, loadReasoningPreferences, normalizeReasoningEffort, reasoningPreferenceKey, saveReasoningPreferences } from "../src/lib/reasoning-effort.ts";
|
|
|
|
const capabilities = { efforts: ["none", "low", "medium", "high", "xhigh"], defaultEffort: "none" };
|
|
const catalog = { openai: { reasoningCapabilities: { "gpt-5.2": capabilities } } };
|
|
|
|
test("capabilities come only from the selected provider/model and a valid catalog entry", () => {
|
|
assert.deepEqual(getReasoningCapabilities(catalog, "openai", " gpt-5.2 "), capabilities);
|
|
for (const [data, provider, model] of [[{}, "openai", "gpt-5.2"], [catalog, "xai", "gpt-5.2"], [catalog, "openai", "gpt-5.2-new"]]) {
|
|
assert.equal(getReasoningCapabilities(data, provider, model), null);
|
|
}
|
|
for (const entry of [{}, { efforts: [] }, { efforts: ["future"], defaultEffort: "future" }, { efforts: ["high"], defaultEffort: "none" }]) {
|
|
assert.equal(getReasoningCapabilities({ openai: { reasoningCapabilities: { model: entry } } }, "openai", "model"), null);
|
|
}
|
|
assert.equal(normalizeReasoningEffort(capabilities, "xhigh"), "xhigh");
|
|
assert.equal(normalizeReasoningEffort(capabilities, "max"), null);
|
|
assert.equal(normalizeReasoningEffort(null, "high"), null);
|
|
assert.equal(normalizeReasoningEffort(capabilities, null), null);
|
|
});
|
|
|
|
test("browser memory is per provider/model and survives corrupt or unavailable storage", (t) => {
|
|
const original = globalThis.window;
|
|
t.after(() => { globalThis.window = original; });
|
|
let stored = "{}";
|
|
globalThis.window = { localStorage: { getItem: () => stored, setItem: (_, value) => { stored = value; } } };
|
|
const key = reasoningPreferenceKey("openai", "gpt-5.2");
|
|
assert.notEqual(key, reasoningPreferenceKey("xai", "gpt-5.2"));
|
|
assert.notEqual(key, reasoningPreferenceKey("openai", "gpt-5.1"));
|
|
assert.equal(saveReasoningPreferences({ [key]: "high" }), true);
|
|
assert.deepEqual(loadReasoningPreferences(), { [key]: "high" });
|
|
stored = JSON.stringify({ [key]: "future", other: null });
|
|
assert.deepEqual(loadReasoningPreferences(), { other: null });
|
|
stored = "broken JSON";
|
|
assert.deepEqual(loadReasoningPreferences(), {});
|
|
globalThis.window = { get localStorage() { throw new Error("blocked"); } };
|
|
assert.deepEqual(loadReasoningPreferences(), {});
|
|
assert.equal(saveReasoningPreferences({ [key]: "high" }), false);
|
|
});
|