Finish backlog cleanup for Pi integration
This commit is contained in:
42
tests/pi-extension-loader-patch.test.ts
Normal file
42
tests/pi-extension-loader-patch.test.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
import { patchPiExtensionLoaderSource } from "../scripts/lib/pi-extension-loader-patch.mjs";
|
||||
|
||||
test("patchPiExtensionLoaderSource rewrites Windows extension imports to file URLs", () => {
|
||||
const input = [
|
||||
'import * as path from "node:path";',
|
||||
'import { fileURLToPath } from "node:url";',
|
||||
"async function loadExtensionModule(extensionPath) {",
|
||||
" const jiti = createJiti(import.meta.url);",
|
||||
' const module = await jiti.import(extensionPath, { default: true });',
|
||||
" return module;",
|
||||
"}",
|
||||
"",
|
||||
].join("\n");
|
||||
|
||||
const patched = patchPiExtensionLoaderSource(input);
|
||||
|
||||
assert.match(patched, /pathToFileURL/);
|
||||
assert.match(patched, /process\.platform === "win32"/);
|
||||
assert.match(patched, /path\.isAbsolute\(extensionPath\)/);
|
||||
assert.match(patched, /jiti\.import\(extensionSpecifier, \{ default: true \}\)/);
|
||||
});
|
||||
|
||||
test("patchPiExtensionLoaderSource is idempotent", () => {
|
||||
const input = [
|
||||
'import * as path from "node:path";',
|
||||
'import { fileURLToPath } from "node:url";',
|
||||
"async function loadExtensionModule(extensionPath) {",
|
||||
" const jiti = createJiti(import.meta.url);",
|
||||
' const module = await jiti.import(extensionPath, { default: true });',
|
||||
" return module;",
|
||||
"}",
|
||||
"",
|
||||
].join("\n");
|
||||
|
||||
const once = patchPiExtensionLoaderSource(input);
|
||||
const twice = patchPiExtensionLoaderSource(once);
|
||||
|
||||
assert.equal(twice, once);
|
||||
});
|
||||
@@ -19,6 +19,31 @@ test("loadPiWebAccessConfig returns empty config when Pi web config is missing",
|
||||
});
|
||||
|
||||
test("getPiWebAccessStatus reads Pi web-access config directly", () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "feynman-pi-web-"));
|
||||
const configPath = getPiWebSearchConfigPath(root);
|
||||
mkdirSync(join(root, ".feynman"), { recursive: true });
|
||||
writeFileSync(
|
||||
configPath,
|
||||
JSON.stringify({
|
||||
provider: "exa",
|
||||
searchProvider: "exa",
|
||||
exaApiKey: "exa_...",
|
||||
chromeProfile: "Profile 2",
|
||||
geminiApiKey: "AIza...",
|
||||
}),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
const status = getPiWebAccessStatus(loadPiWebAccessConfig(configPath), configPath);
|
||||
assert.equal(status.routeLabel, "Exa");
|
||||
assert.equal(status.requestProvider, "exa");
|
||||
assert.equal(status.exaConfigured, true);
|
||||
assert.equal(status.geminiApiConfigured, true);
|
||||
assert.equal(status.perplexityConfigured, false);
|
||||
assert.equal(status.chromeProfile, "Profile 2");
|
||||
});
|
||||
|
||||
test("getPiWebAccessStatus reads Gemini routes directly", () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "feynman-pi-web-"));
|
||||
const configPath = getPiWebSearchConfigPath(root);
|
||||
mkdirSync(join(root, ".feynman"), { recursive: true });
|
||||
@@ -36,6 +61,7 @@ test("getPiWebAccessStatus reads Pi web-access config directly", () => {
|
||||
const status = getPiWebAccessStatus(loadPiWebAccessConfig(configPath), configPath);
|
||||
assert.equal(status.routeLabel, "Gemini");
|
||||
assert.equal(status.requestProvider, "gemini");
|
||||
assert.equal(status.exaConfigured, false);
|
||||
assert.equal(status.geminiApiConfigured, true);
|
||||
assert.equal(status.perplexityConfigured, false);
|
||||
assert.equal(status.chromeProfile, "Profile 2");
|
||||
|
||||
41
tests/service-tier.test.ts
Normal file
41
tests/service-tier.test.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { mkdtempSync, readFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
|
||||
import {
|
||||
getConfiguredServiceTier,
|
||||
normalizeServiceTier,
|
||||
resolveProviderServiceTier,
|
||||
setConfiguredServiceTier,
|
||||
} from "../src/model/service-tier.js";
|
||||
|
||||
test("normalizeServiceTier accepts supported values only", () => {
|
||||
assert.equal(normalizeServiceTier("priority"), "priority");
|
||||
assert.equal(normalizeServiceTier("standard_only"), "standard_only");
|
||||
assert.equal(normalizeServiceTier("FAST"), undefined);
|
||||
assert.equal(normalizeServiceTier(undefined), undefined);
|
||||
});
|
||||
|
||||
test("setConfiguredServiceTier persists and clears settings.json values", () => {
|
||||
const dir = mkdtempSync(join(tmpdir(), "feynman-service-tier-"));
|
||||
const settingsPath = join(dir, "settings.json");
|
||||
|
||||
setConfiguredServiceTier(settingsPath, "priority");
|
||||
assert.equal(getConfiguredServiceTier(settingsPath), "priority");
|
||||
|
||||
const persisted = JSON.parse(readFileSync(settingsPath, "utf8")) as { serviceTier?: string };
|
||||
assert.equal(persisted.serviceTier, "priority");
|
||||
|
||||
setConfiguredServiceTier(settingsPath, undefined);
|
||||
assert.equal(getConfiguredServiceTier(settingsPath), undefined);
|
||||
});
|
||||
|
||||
test("resolveProviderServiceTier filters unsupported provider+tier pairs", () => {
|
||||
assert.equal(resolveProviderServiceTier("openai", "priority"), "priority");
|
||||
assert.equal(resolveProviderServiceTier("openai-codex", "flex"), "flex");
|
||||
assert.equal(resolveProviderServiceTier("anthropic", "standard_only"), "standard_only");
|
||||
assert.equal(resolveProviderServiceTier("anthropic", "priority"), undefined);
|
||||
assert.equal(resolveProviderServiceTier("google", "priority"), undefined);
|
||||
});
|
||||
Reference in New Issue
Block a user