Files
my-pi/pi-permission-system/test/config-loader.test.ts
T
云服务部-叶林立andDevin <158243242+devin-ai-integration[bot]@users.noreply.github.com> 2aa1be0b54 feat: 组合包配置以包内 config/ 为唯一来源,并新增受保护写入人工审批
配置统一:权限策略、硬防御、Tool Search、提示词封面以及新迁入的
RTK、pi-compaction、pi-worktree、pi-hermes-memory 配置全部由扩展
直接读取已安装组合包内的 config/,pi install / pi update 即完成部署;
删除 rebuild-bundle-config.mjs 与 bundle-manifest.json,my-pi/ 只保留
日志与缓存。update.sh 成功升级后将默认 git 来源的已安装副本
reset 回发布版本。AGENTS.md 新增「组合包配置原则」。

脚本整合:search_config.sh / ssh_config.sh 合并为 configure.sh
search|ssh;install.sh / update.sh 共享函数抽到 scripts/lib.sh,远程
安装器改为先下载到临时文件再执行,下载失败可被检测。

权限:hard-guards 新增 protectedWrites,写入 Pi 凭据/设置、已安装
组合包与扩展目录、pi-ssh 凭据库时一律人工确认(跳过 AutoReview、
yolo 与 Session grant,无 UI 时拒绝);放行 ls、LSP 查询、ctx 只读、
web_search、Chrome 只读与 git 只读命令,skill_manage 改为 ask。

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-10-20 01:05:31 -07:00

832 lines
26 KiB
TypeScript

import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import {
detectDeprecatedPreviewCaps,
loadAndMergeConfigs,
loadUnifiedConfig,
mergeUnifiedConfigs,
stripJsonComments,
} from "#src/config-loader";
describe("stripJsonComments", () => {
it("returns empty string for empty input", () => {
expect(stripJsonComments("")).toBe("");
});
it("passes through plain JSON unchanged", () => {
const input = '{"key": true}';
expect(stripJsonComments(input)).toBe(input);
});
it("drops a line comment body and preserves the trailing newline", () => {
// The space before // is emitted; the comment body is dropped; \n is kept.
expect(stripJsonComments('{ // comment\n"k": 1}')).toBe('{ \n"k": 1}');
});
it("drops a line comment that runs to EOF with no trailing newline", () => {
expect(stripJsonComments('{"k": 1} // trailing')).toBe('{"k": 1} ');
});
it("drops a block comment and nothing else", () => {
expect(stripJsonComments('{ /* block */ "k": 1}')).toBe('{ "k": 1}');
});
it("drops an unterminated block comment to EOF", () => {
expect(stripJsonComments("{ /* no close")).toBe("{ ");
});
it("preserves // inside a double-quoted string", () => {
expect(stripJsonComments('{"url": "http://example.com"}')).toBe(
'{"url": "http://example.com"}',
);
});
it("preserves block-comment markers inside a double-quoted string", () => {
expect(stripJsonComments('{"v": "a /* b */ c"}')).toBe(
'{"v": "a /* b */ c"}',
);
});
it("preserves // inside a single-quoted string", () => {
expect(stripJsonComments("{'url': 'http://x.com'}")).toBe(
"{'url': 'http://x.com'}",
);
});
it("preserves block-comment markers inside a single-quoted string", () => {
expect(stripJsonComments("{'v': 'a /* b */ c'}")).toBe(
"{'v': 'a /* b */ c'}",
);
});
it("honors a backslash-escaped quote so it does not close the string", () => {
// The string value is: a\"b (backslash-escaped double quote)
expect(stripJsonComments('{"k": "a\\"b"}')).toBe('{"k": "a\\"b"}');
});
it("emits an unterminated string to EOF verbatim", () => {
expect(stripJsonComments('{"k": "unterminated')).toBe(
'{"k": "unterminated',
);
});
it("preserves a lone slash that is not part of // or /*", () => {
expect(stripJsonComments('{"v": 1/2}')).toBe('{"v": 1/2}');
});
it("handles a combined JSONC document that round-trips to valid JSON", () => {
const jsonc = [
"{",
' "debugLog": true, // runtime knob',
' "permission": { /* the policy */ "*": "ask" }',
"}",
].join("\n");
const stripped = stripJsonComments(jsonc);
// Must parse without throwing
const parsed = JSON.parse(stripped) as Record<string, unknown>;
expect(parsed.debugLog).toBe(true);
expect(parsed.permission).toEqual({ "*": "ask" });
});
});
describe("loadUnifiedConfig", () => {
let tempDir: string;
beforeEach(() => {
tempDir = mkdtempSync(join(tmpdir(), "config-loader-test-"));
});
afterEach(() => {
rmSync(tempDir, { recursive: true, force: true });
});
it("parses a valid JSON file with runtime knobs and flat permission", () => {
const configPath = join(tempDir, "config.json");
writeFileSync(
configPath,
JSON.stringify({
debugLog: true,
permissionReviewLog: false,
yoloMode: true,
permission: {
"*": "ask",
read: "allow",
bash: { "git status": "allow" },
},
}),
);
const result = loadUnifiedConfig(configPath);
expect(result.issues).toEqual([]);
expect(result.config.debugLog).toBe(true);
expect(result.config.permissionReviewLog).toBe(false);
expect(result.config.yoloMode).toBe(true);
expect(result.config.permission).toEqual({
"*": "ask",
read: "allow",
bash: { "git status": "allow" },
});
});
it("rejects the removed analysis key so a stale config cannot silently widen", () => {
const configPath = join(tempDir, "config.json");
writeFileSync(
configPath,
JSON.stringify({ analysis: { threshold: 500 }, permission: { "*": "ask" } }),
);
const result = loadUnifiedConfig(configPath);
expect(result.issues.some((issue) => issue.includes("analysis"))).toBe(true);
// Fail-closed: the whole scope config is dropped, so `ask` is the effective
// default again rather than any rule the stale file meant to contribute.
expect(result.config).toEqual({});
});
it("merges the autoReview object field-by-field", () => {
const merged = mergeUnifiedConfigs(
{ autoReview: { enabled: true, provider: "vendor", model: "m" } },
{ autoReview: { reasoning: "low" } },
);
expect(merged.autoReview).toEqual({
enabled: true,
provider: "vendor",
model: "m",
reasoning: "low",
});
});
it("strips JSONC comments before parsing", () => {
const configPath = join(tempDir, "config.json");
writeFileSync(
configPath,
`{
// This is a comment
"debugLog": true,
/* block comment */
"permission": { "*": "ask" }
}`,
);
const result = loadUnifiedConfig(configPath);
expect(result.issues).toEqual([]);
expect(result.config.debugLog).toBe(true);
expect(result.config.permission).toEqual({ "*": "ask" });
});
it("rejects unknown keys with a clear issue and empty config", () => {
const configPath = join(tempDir, "config.json");
writeFileSync(
configPath,
JSON.stringify({
debugLog: false,
unknownField: "ignored",
anotherRandom: 42,
}),
);
const result = loadUnifiedConfig(configPath);
expect(result.issues.join("\n")).toContain("unknownField");
expect(result.issues.join("\n")).toContain("anotherRandom");
// Fail-closed: the whole scope is rejected, dropping the valid field too.
expect(result.config).toEqual({});
});
it("returns empty config and no issues when the file does not exist", () => {
const configPath = join(tempDir, "nonexistent.json");
const result = loadUnifiedConfig(configPath);
expect(result.issues).toEqual([]);
expect(result.config.debugLog).toBeUndefined();
expect(result.config.permission).toBeUndefined();
});
it("returns empty config and an issue when the file contains invalid JSON", () => {
const configPath = join(tempDir, "config.json");
writeFileSync(configPath, "not valid json {{{");
const result = loadUnifiedConfig(configPath);
expect(result.issues).toHaveLength(1);
expect(result.issues[0]).toContain(configPath);
});
it("rejects non-boolean runtime knobs with a clear issue", () => {
const configPath = join(tempDir, "config.json");
writeFileSync(
configPath,
JSON.stringify({
debugLog: "yes",
permissionReviewLog: 1,
yoloMode: null,
}),
);
const result = loadUnifiedConfig(configPath);
expect(result.config).toEqual({});
expect(result.issues.join("\n")).toContain("debugLog");
});
it("fails closed: an invalid field contributes no permission rules", () => {
const configPath = join(tempDir, "config.json");
writeFileSync(
configPath,
JSON.stringify({
permission: { "*": "allow", read: "allow" },
toolInputPreviewMaxLength: -5,
}),
);
const result = loadUnifiedConfig(configPath);
// Even though permission carried `allow` rules, the invalid knob rejects
// the whole scope so no `allow` leaks through — downstream falls to `ask`.
expect(result.config).toEqual({});
expect(result.config.permission).toBeUndefined();
expect(result.issues.length).toBeGreaterThan(0);
});
it("rejects an invalid PermissionState inside a permission map", () => {
const configPath = join(tempDir, "config.json");
writeFileSync(
configPath,
JSON.stringify({
permission: {
read: "allow",
write: "invalid",
bash: { "git *": "ask", "rm -rf": 42 },
},
}),
);
const result = loadUnifiedConfig(configPath);
expect(result.config).toEqual({});
expect(result.issues.length).toBeGreaterThan(0);
});
it("accepts permission as object with mixed string and object values", () => {
const configPath = join(tempDir, "config.json");
writeFileSync(
configPath,
JSON.stringify({
permission: {
"*": "ask",
read: "allow",
bash: { "*": "ask", "git *": "allow" },
},
}),
);
const result = loadUnifiedConfig(configPath);
expect(result.issues).toEqual([]);
expect(result.config.permission).toEqual({
"*": "ask",
read: "allow",
bash: { "*": "ask", "git *": "allow" },
});
});
it("preserves a deny-with-reason object inside a pattern map", () => {
const configPath = join(tempDir, "config.json");
writeFileSync(
configPath,
JSON.stringify({
permission: {
bash: {
"git *": "allow",
"npm *": { action: "deny", reason: "Use pnpm instead" },
},
},
}),
);
const result = loadUnifiedConfig(configPath);
expect(result.config.permission).toEqual({
bash: {
"git *": "allow",
"npm *": { action: "deny", reason: "Use pnpm instead" },
},
});
});
it("rejects a deny object with a non-string reason", () => {
const configPath = join(tempDir, "config.json");
writeFileSync(
configPath,
JSON.stringify({
permission: {
bash: {
"git *": "allow",
"npm *": { action: "deny", reason: 42 },
},
},
}),
);
const result = loadUnifiedConfig(configPath);
expect(result.config).toEqual({});
expect(result.issues.length).toBeGreaterThan(0);
});
it("returns no permission when the permission field is absent", () => {
const configPath = join(tempDir, "config.json");
writeFileSync(configPath, JSON.stringify({ debugLog: false }));
const result = loadUnifiedConfig(configPath);
expect(result.config.permission).toBeUndefined();
});
it("rejects a non-object permission field", () => {
const configPath = join(tempDir, "config.json");
writeFileSync(configPath, JSON.stringify({ permission: "allow" }));
const result = loadUnifiedConfig(configPath);
expect(result.config).toEqual({});
expect(result.issues.length).toBeGreaterThan(0);
});
it("parses the positive-integer scalar knobs", () => {
const configPath = join(tempDir, "config.json");
writeFileSync(
configPath,
JSON.stringify({
forwardingTimeoutMs: 120_000,
toolInputPreviewMaxLength: 1000,
toolTextSummaryMaxLength: 120,
}),
);
const result = loadUnifiedConfig(configPath);
expect(result.config.forwardingTimeoutMs).toBe(120_000);
expect(result.config.toolInputPreviewMaxLength).toBe(1000);
expect(result.config.toolTextSummaryMaxLength).toBe(120);
});
it("rejects a non-positive forwardingTimeoutMs", () => {
const configPath = join(tempDir, "config.json");
writeFileSync(configPath, JSON.stringify({ forwardingTimeoutMs: 0 }));
const result = loadUnifiedConfig(configPath);
expect(result.issues.length).toBeGreaterThan(0);
});
it("omits the scalar knobs when absent", () => {
const configPath = join(tempDir, "config.json");
writeFileSync(configPath, JSON.stringify({ debugLog: false }));
const result = loadUnifiedConfig(configPath);
expect(result.config).not.toHaveProperty("toolInputPreviewMaxLength");
expect(result.config).not.toHaveProperty("toolTextSummaryMaxLength");
expect(result.config).not.toHaveProperty("forwardingTimeoutMs");
});
it.each([
["zero", 0],
["negative", -1],
["float", 1.5],
["string", "200"],
["boolean", true],
] as const)("rejects invalid toolInputPreviewMaxLength: %s", (_label, value) => {
const configPath = join(tempDir, "config.json");
writeFileSync(
configPath,
JSON.stringify({ toolInputPreviewMaxLength: value }),
);
const result = loadUnifiedConfig(configPath);
expect(result.config).toEqual({});
expect(result.issues.length).toBeGreaterThan(0);
});
it.each([
["zero", 0],
["negative", -1],
["float", 1.5],
["string", "80"],
["boolean", false],
] as const)("rejects invalid toolTextSummaryMaxLength: %s", (_label, value) => {
const configPath = join(tempDir, "config.json");
writeFileSync(
configPath,
JSON.stringify({ toolTextSummaryMaxLength: value }),
);
const result = loadUnifiedConfig(configPath);
expect(result.config).toEqual({});
expect(result.issues.length).toBeGreaterThan(0);
});
it.each([
["string", "not-an-array"],
["number", 42],
["mixed-type array", ["a", 1]],
["object", { a: "b" }],
] as const)("rejects invalid piInfrastructureReadPaths: %s", (_label, value) => {
const configPath = join(tempDir, "config.json");
writeFileSync(
configPath,
JSON.stringify({ piInfrastructureReadPaths: value }),
);
const result = loadUnifiedConfig(configPath);
expect(result.config).toEqual({});
expect(result.issues.length).toBeGreaterThan(0);
});
});
describe("mergeUnifiedConfigs", () => {
it("deep-merges permission objects so the later config overrides per key", () => {
const merged = mergeUnifiedConfigs(
{
permission: {
"*": "ask",
read: "allow",
bash: { "git status": "allow" },
},
},
{
permission: {
"*": "allow",
bash: { "rm -rf *": "deny" },
},
},
);
expect(merged.permission).toEqual({
"*": "allow",
read: "allow",
bash: { "git status": "allow", "rm -rf *": "deny" },
});
});
it("string permission value in override replaces base string for same key", () => {
const merged = mergeUnifiedConfigs(
{ permission: { read: "ask" } },
{ permission: { read: "allow" } },
);
expect(merged.permission).toEqual({ read: "allow" });
});
it("object replaces string when override uses object for same surface", () => {
const merged = mergeUnifiedConfigs(
{ permission: { bash: "ask" } },
{ permission: { bash: { "*": "allow", "rm -rf *": "deny" } } },
);
expect(merged.permission).toEqual({
bash: { "*": "allow", "rm -rf *": "deny" },
});
});
it("string replaces object when override uses string for same surface", () => {
const merged = mergeUnifiedConfigs(
{ permission: { bash: { "git *": "allow" } } },
{ permission: { bash: "deny" } },
);
expect(merged.permission).toEqual({ bash: "deny" });
});
it("replaces scalar runtime knobs with later values", () => {
const merged = mergeUnifiedConfigs(
{
debugLog: true,
permissionReviewLog: true,
yoloMode: false,
doublePressToConfirm: true,
},
{ debugLog: false, yoloMode: true, doublePressToConfirm: false },
);
expect(merged.debugLog).toBe(false);
expect(merged.permissionReviewLog).toBe(true);
expect(merged.yoloMode).toBe(true);
expect(merged.doublePressToConfirm).toBe(false);
});
it("replaces prompt-budget scalars with later values", () => {
const merged = mergeUnifiedConfigs(
{ promptMaxRows: 24, promptFieldMaxWidth: 400 },
{ promptMaxRows: 10 },
);
expect(merged.promptMaxRows).toBe(10);
expect(merged.promptFieldMaxWidth).toBe(400);
});
it("replaces the review-log field width with a later value and keeps the base's otherwise", () => {
expect(
mergeUnifiedConfigs(
{ reviewLogFieldMaxWidth: 1000 },
{ reviewLogFieldMaxWidth: 200 },
).reviewLogFieldMaxWidth,
).toBe(200);
expect(
mergeUnifiedConfigs({ reviewLogFieldMaxWidth: 200 }, {})
.reviewLogFieldMaxWidth,
).toBe(200);
});
it("returns base unchanged when override is empty", () => {
const base = {
debugLog: true,
permission: { read: "allow" as const },
};
const merged = mergeUnifiedConfigs(base, {});
expect(merged.debugLog).toBe(true);
expect(merged.permission).toEqual({ read: "allow" });
});
it("returns override unchanged when base is empty", () => {
const override = {
yoloMode: true,
permission: { bash: { "rm -rf *": "deny" as const } },
};
const merged = mergeUnifiedConfigs({}, override);
expect(merged.yoloMode).toBe(true);
expect(merged.permission).toEqual({ bash: { "rm -rf *": "deny" } });
});
it("does not set undefined keys in the merged result", () => {
const merged = mergeUnifiedConfigs({ debugLog: true }, { yoloMode: false });
expect(merged.debugLog).toBe(true);
expect(merged.yoloMode).toBe(false);
expect(merged).not.toHaveProperty("permissionReviewLog");
expect(merged).not.toHaveProperty("permission");
});
it("override toolInputPreviewMaxLength replaces base value", () => {
const merged = mergeUnifiedConfigs(
{ toolInputPreviewMaxLength: 200 },
{ toolInputPreviewMaxLength: 1000 },
);
expect(merged.toolInputPreviewMaxLength).toBe(1000);
});
it("base toolInputPreviewMaxLength survives when override omits it", () => {
const merged = mergeUnifiedConfigs(
{ toolInputPreviewMaxLength: 500 },
{ debugLog: true },
);
expect(merged.toolInputPreviewMaxLength).toBe(500);
});
it("toolInputPreviewMaxLength is absent when both base and override omit it", () => {
const merged = mergeUnifiedConfigs({ debugLog: true }, { yoloMode: false });
expect(merged).not.toHaveProperty("toolInputPreviewMaxLength");
});
it("override toolTextSummaryMaxLength replaces base value", () => {
const merged = mergeUnifiedConfigs(
{ toolTextSummaryMaxLength: 80 },
{ toolTextSummaryMaxLength: 200 },
);
expect(merged.toolTextSummaryMaxLength).toBe(200);
});
it("base toolTextSummaryMaxLength survives when override omits it", () => {
const merged = mergeUnifiedConfigs(
{ toolTextSummaryMaxLength: 120 },
{ debugLog: false },
);
expect(merged.toolTextSummaryMaxLength).toBe(120);
});
it("toolTextSummaryMaxLength is absent when both base and override omit it", () => {
const merged = mergeUnifiedConfigs({}, { permissionReviewLog: true });
expect(merged).not.toHaveProperty("toolTextSummaryMaxLength");
});
it("override authorizerChain replaces base array", () => {
const merged = mergeUnifiedConfigs(
{ authorizerChain: ["base-judge"] },
{ authorizerChain: ["override-judge"] },
);
expect(merged.authorizerChain).toEqual(["override-judge"]);
});
it("base authorizerChain survives when override omits it", () => {
const merged = mergeUnifiedConfigs(
{ authorizerChain: ["kept-judge"] },
{ debugLog: true },
);
expect(merged.authorizerChain).toEqual(["kept-judge"]);
});
it("base shellTools survives when override omits it", () => {
const merged = mergeUnifiedConfigs(
{ shellTools: { exec_command: { commandArgument: "cmd" } } },
{},
);
expect(merged.shellTools).toEqual({
exec_command: { commandArgument: "cmd" },
});
});
it("override shellTools survives when base omits it", () => {
const merged = mergeUnifiedConfigs(
{},
{ shellTools: { exec_command: { commandArgument: "cmd" } } },
);
expect(merged.shellTools).toEqual({
exec_command: { commandArgument: "cmd" },
});
});
it("merges shellTools by tool name: override adds without dropping base", () => {
const merged = mergeUnifiedConfigs(
{ shellTools: { exec_command: { commandArgument: "cmd" } } },
{ shellTools: { run_shell: { commandArgument: "script" } } },
);
expect(merged.shellTools).toEqual({
exec_command: { commandArgument: "cmd" },
run_shell: { commandArgument: "script" },
});
});
it("field-merges a colliding shell alias and preserves its decision floor", () => {
const merged = mergeUnifiedConfigs(
{
shellTools: {
exec_command: {
commandArgument: "cmd",
workdirArgument: "workdir",
decisionFloor: "ask",
},
},
},
{ shellTools: { exec_command: { commandArgument: "command" } } },
);
expect(merged.shellTools).toEqual({
exec_command: {
commandArgument: "command",
workdirArgument: "workdir",
decisionFloor: "ask",
},
});
});
it("shellTools is absent when both base and override omit it", () => {
const merged = mergeUnifiedConfigs({ debugLog: true }, { yoloMode: false });
expect(merged).not.toHaveProperty("shellTools");
});
});
describe("loadAndMergeConfigs", () => {
let tempDir: string;
let agentDir: string;
let cwd: string;
let globalConfigPath: string;
beforeEach(() => {
tempDir = mkdtempSync(join(tmpdir(), "config-merge-test-"));
agentDir = join(tempDir, "agent");
cwd = join(tempDir, "project");
// Tests inject a temp policy path; the bundle config/ file is never touched.
globalConfigPath = join(tempDir, "config", "pi-permission-policy.jsonc");
});
afterEach(() => {
rmSync(tempDir, { recursive: true, force: true });
});
function writeGlobal(content: Record<string, unknown>): void {
mkdirSync(dirname(globalConfigPath), { recursive: true });
writeFileSync(globalConfigPath, JSON.stringify(content));
}
function writeProject(content: Record<string, unknown>): void {
const dir = join(cwd, ".pi", "extensions", "pi-permission-system");
mkdirSync(dir, { recursive: true });
writeFileSync(join(dir, "policy.jsonc"), JSON.stringify(content));
}
function writeLegacyGlobalPolicy(content: Record<string, unknown>): void {
mkdirSync(agentDir, { recursive: true });
writeFileSync(
join(agentDir, "pi-permissions.jsonc"),
JSON.stringify(content),
);
}
function writeLegacyProjectPolicy(content: Record<string, unknown>): void {
const dir = join(cwd, ".pi", "agent");
mkdirSync(dir, { recursive: true });
writeFileSync(join(dir, "pi-permissions.jsonc"), JSON.stringify(content));
}
it("ignores leftover files at legacy locations", () => {
writeLegacyGlobalPolicy({
defaultPolicy: { tools: "allow" },
tools: { read: "allow" },
});
writeGlobal({
permission: { "*": "deny" },
});
const result = loadAndMergeConfigs(globalConfigPath);
// The legacy file is simply ignored — never merged, never flagged.
expect(result.issues).toEqual([]);
expect(result.merged.permission).toEqual({ "*": "deny" });
});
it("emits no issues when no config file exists", () => {
const result = loadAndMergeConfigs(globalConfigPath);
expect(result.issues).toEqual([]);
expect(result.merged).toEqual({});
});
it("warns when the merged config leaves bash inheriting a permissive top-level '*'", () => {
writeGlobal({
permission: { "*": "allow", read: "allow" },
});
const result = loadAndMergeConfigs(globalConfigPath);
expect(result.issues.some((i) => i.includes("bash"))).toBe(true);
});
it("does not warn about bash fallback when bash is explicitly gated", () => {
writeGlobal({
permission: { "*": "allow", bash: { "*": "ask" } },
});
const result = loadAndMergeConfigs(globalConfigPath);
expect(result.issues).toEqual([]);
});
it("ignores new and legacy project policy files", () => {
writeGlobal({ permission: { "*": "ask", bash: "deny" } });
writeProject({ permission: { bash: "allow" } });
writeLegacyProjectPolicy({ permission: { "*": "allow" } });
const result = loadAndMergeConfigs(globalConfigPath);
expect(result.merged.permission).toEqual({ "*": "ask", bash: "deny" });
expect(result.issues).toEqual([]);
});
describe("deprecated tool-preview caps", () => {
it("notices a config that sets either cap", () => {
writeGlobal({
permission: { "*": "ask" },
toolInputPreviewMaxLength: 400,
});
const result = loadAndMergeConfigs(globalConfigPath);
expect(result.issues).toHaveLength(1);
expect(result.issues[0]).toContain("toolInputPreviewMaxLength");
});
it("keeps accepting the config rather than rejecting it fail-closed", () => {
writeGlobal({
permission: { "*": "ask", bash: "deny" },
toolTextSummaryMaxLength: 120,
});
const result = loadAndMergeConfigs(globalConfigPath);
expect(result.merged.permission).toEqual({ "*": "ask", bash: "deny" });
});
it("stays silent when neither cap is set", () => {
writeGlobal({ permission: { "*": "ask", bash: "deny" } });
const result = loadAndMergeConfigs(globalConfigPath);
expect(result.issues).toEqual([]);
});
});
});
// ── detectDeprecatedPreviewCaps ────────────────────────────────────────────
describe("detectDeprecatedPreviewCaps", () => {
it("names the input-preview cap when it alone is set", () => {
const notice = detectDeprecatedPreviewCaps({
toolInputPreviewMaxLength: 400,
});
expect(notice).toContain("toolInputPreviewMaxLength");
expect(notice).not.toContain("toolTextSummaryMaxLength");
});
it("names the text-summary cap when it alone is set", () => {
const notice = detectDeprecatedPreviewCaps({
toolTextSummaryMaxLength: 120,
});
expect(notice).toContain("toolTextSummaryMaxLength");
expect(notice).not.toContain("toolInputPreviewMaxLength");
});
it("names both caps when both are set", () => {
const notice = detectDeprecatedPreviewCaps({
toolInputPreviewMaxLength: 400,
toolTextSummaryMaxLength: 120,
});
expect(notice).toContain("toolInputPreviewMaxLength");
expect(notice).toContain("toolTextSummaryMaxLength");
});
it("returns undefined when neither cap is set", () => {
expect(detectDeprecatedPreviewCaps({})).toBeUndefined();
});
});