Files
pi-perplexity/test/config-command.test.ts
T
97aab3e9b9 refactor(search): always send searches as incognito (#14)
Hardcode is_incognito: true in the Perplexity request and remove the
toggle surface: the incognito tool parameter, PI_PERPLEXITY_INCOGNITO
env var, config file field, /perplexity-config prompt, and TUI status
indicators. Config and resolveDefaultModel are now model-only.

Supersedes the incognito portion of PR #4.

Co-authored-by: Ivan Pereira <183991+ivanrvpereira@users.noreply.github.com>
2026-07-16 15:28:02 +01:00

99 lines
3.0 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, test } from "./test-helpers.js";
import { mkdtemp, readFile, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { registerPerplexityConfigCommand } from "../src/commands/config.js";
let loadConfig: (configPath?: string) => Promise<import("../src/config.js").PerplexityConfig>;
let saveConfig: (config: import("../src/config.js").PerplexityConfig, configPath?: string) => Promise<void>;
let tempDir: string;
let configPath: string;
beforeEach(async () => {
tempDir = await mkdtemp(join(tmpdir(), "pi-perplexity-command-test-"));
configPath = join(tempDir, "config.json");
const mod = await import(`../src/config.js?t=${Date.now()}`);
loadConfig = mod.loadConfig;
saveConfig = mod.saveConfig;
});
afterEach(async () => {
await rm(tempDir, { recursive: true, force: true });
});
describe("perplexity-config command", () => {
test("marks the configured model as current in the select options", async () => {
let handler: ((args: string, ctx: any) => Promise<void>) | undefined;
await saveConfig({ model: "gpt54" }, configPath);
registerPerplexityConfigCommand(
{
registerCommand(name: string, command: { handler: (args: string, ctx: any) => Promise<void> }) {
expect(name).toBe("perplexity-config");
handler = command.handler;
},
} as any,
{
getConfigPath: () => configPath,
loadConfig: () => loadConfig(configPath),
saveConfig: (config) => saveConfig(config, configPath),
},
);
expect(handler).toBeDefined();
let options: string[] = [];
await handler!("", {
ui: {
select: async (_label: string, receivedOptions: string[]) => {
options = receivedOptions;
return "GPT-5.4 [current]";
},
notify: () => undefined,
},
});
expect(options).toContain("GPT-5.4 [current]");
});
test("writes selected config to disk", async () => {
let handler: ((args: string, ctx: any) => Promise<void>) | undefined;
registerPerplexityConfigCommand(
{
registerCommand(name: string, command: { handler: (args: string, ctx: any) => Promise<void> }) {
expect(name).toBe("perplexity-config");
handler = command.handler;
},
} as any,
{
getConfigPath: () => configPath,
loadConfig: () => loadConfig(configPath),
saveConfig: (config) => saveConfig(config, configPath),
},
);
expect(handler).toBeDefined();
const notifications: Array<{ message: string; level: string }> = [];
await handler!("", {
ui: {
select: async () => "GPT-5.4",
notify: (message: string, level: string) => notifications.push({ message, level }),
},
});
const raw = await readFile(configPath, "utf8");
expect(JSON.parse(raw)).toEqual({ model: "gpt54" });
expect(notifications).toContainEqual({
message: "Perplexity config saved:\nModel: gpt54 (GPT-5.4)",
level: "info",
});
});
});