mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 18:55:22 +00:00
AutoReview: - 审查器回到 Codex Guardian 风格的对话式审查,默认跟随会话当前主模型 (每次审查实时读取 ctx.model);provider/model 必须同时设置才固定审查 模型,只设其一视为配置错误并转人工。 - 结论只通过 approve / reject 两个工具给出,参数仅 reason;不强制 toolChoice,正文文本(即使是合法 JSON)一律忽略。 - approve 自动放行;reject 转人工并在弹窗显示理由(标注模型生成)。 超时、Provider 错误、截断、未调用工具、多次调用、参数无效等异常同样 转人工,并附固定的系统说明;用户按 Esc 中止时直接拒绝。 - 模型调用改为 modelRegistry.streamSimple(...).result():Pi 1.3.0 面向 扩展的 ModelRegistry 没有 completeSimple,原写法在真实环境中每次都会 转人工。 - 对话记录保留可信度标注;工具结果在有更短的 pi-compaction 摘要时替换 为摘要;token 估算改为非 ASCII 字符按 1 token 计;预算可配置。 - 同一条用户消息内完全相同的请求只缓存 approve 结论。 - 默认 reasoning low、总超时 30 秒、最多 2 次尝试、maxOutputTokens 4000。 删除: - 未发布过的 TypeSafe Jev 分类器实现、DenialCircuitBreaker。 - 整个 annotator 机制(model-explanation、注册表、registerAnnotator、 provider-timeout);annotators 配置键保留为已弃用并忽略,避免旧配置 被拒绝。 测试: - 新增 reviewer / transcript / 弹窗说明 / 默认配置测试;清理重复、恒真 或只测实现细节的旧测试。 - 使用 deepseek-v4.1-flash 实测 5 个场景各 5 次,25 次结论全部符合预期。 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
175 lines
5.9 KiB
TypeScript
175 lines
5.9 KiB
TypeScript
import { homedir } from "node:os";
|
|
import { describe, expect, it } from "vitest";
|
|
import {
|
|
resolveNodeText,
|
|
SKIP_SUBTREE_TYPES,
|
|
} from "#src/access-intent/bash/node-text";
|
|
import { makeTSNode } from "#test/helpers/fake-ts-node";
|
|
|
|
describe("SKIP_SUBTREE_TYPES", () => {
|
|
it("does not contain common argument node types", () => {
|
|
expect(SKIP_SUBTREE_TYPES.has("word")).toBe(false);
|
|
expect(SKIP_SUBTREE_TYPES.has("string")).toBe(false);
|
|
expect(SKIP_SUBTREE_TYPES.has("raw_string")).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("resolveNodeText", () => {
|
|
describe("word nodes", () => {
|
|
it("returns the node text unchanged", () => {
|
|
expect(resolveNodeText(makeTSNode("word", "hello"))).toBe("hello");
|
|
});
|
|
});
|
|
|
|
describe("raw_string nodes (single-quoted)", () => {
|
|
it("strips surrounding single quotes", () => {
|
|
expect(resolveNodeText(makeTSNode("raw_string", "'content'"))).toBe(
|
|
"content",
|
|
);
|
|
});
|
|
|
|
it("strips single quotes around a path", () => {
|
|
expect(resolveNodeText(makeTSNode("raw_string", "'/etc/hosts'"))).toBe(
|
|
"/etc/hosts",
|
|
);
|
|
});
|
|
|
|
it("returns text as-is when not fully single-quoted", () => {
|
|
// A raw_string node without enclosing quotes (defensive fallback)
|
|
expect(resolveNodeText(makeTSNode("raw_string", "noquotes"))).toBe(
|
|
"noquotes",
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("string nodes (double-quoted)", () => {
|
|
it("concatenates inner word children, skipping quote delimiters", () => {
|
|
const quoteOpen = makeTSNode('"', '"');
|
|
const content = makeTSNode("string_content", "hello world");
|
|
const quoteClose = makeTSNode('"', '"');
|
|
const node = makeTSNode("string", '"hello world"', [
|
|
quoteOpen,
|
|
content,
|
|
quoteClose,
|
|
]);
|
|
expect(resolveNodeText(node)).toBe("hello world");
|
|
});
|
|
|
|
it("concatenates multiple inner children", () => {
|
|
const quoteOpen = makeTSNode('"', '"');
|
|
const part1 = makeTSNode("string_content", "foo");
|
|
const part2 = makeTSNode("simple_expansion", "$BAR");
|
|
const quoteClose = makeTSNode('"', '"');
|
|
const node = makeTSNode("string", '"foo$BAR"', [
|
|
quoteOpen,
|
|
part1,
|
|
part2,
|
|
quoteClose,
|
|
]);
|
|
expect(resolveNodeText(node)).toBe("foo$BAR");
|
|
});
|
|
|
|
it("returns empty string for an empty double-quoted string", () => {
|
|
const quoteOpen = makeTSNode('"', '"');
|
|
const quoteClose = makeTSNode('"', '"');
|
|
const node = makeTSNode("string", '""', [quoteOpen, quoteClose]);
|
|
expect(resolveNodeText(node)).toBe("");
|
|
});
|
|
});
|
|
|
|
describe("string_content, simple_expansion, and expansion nodes", () => {
|
|
it("returns text as-is for string_content", () => {
|
|
expect(resolveNodeText(makeTSNode("string_content", "plain text"))).toBe(
|
|
"plain text",
|
|
);
|
|
});
|
|
|
|
it("resolves a plain $HOME reference to the home directory", () => {
|
|
// The children matter: the resolver discriminates a plain reference from
|
|
// an operator-bearing expansion structurally, not by text prefix (#694).
|
|
const node = makeTSNode("simple_expansion", "$HOME", [
|
|
makeTSNode("$", "$"),
|
|
makeTSNode("variable_name", "HOME"),
|
|
]);
|
|
expect(resolveNodeText(node)).toBe(homedir());
|
|
});
|
|
|
|
it("resolves a plain ${HOME} reference to the home directory", () => {
|
|
const node = makeTSNode("expansion", "${HOME}", [
|
|
makeTSNode("${", "${"),
|
|
makeTSNode("variable_name", "HOME"),
|
|
makeTSNode("}", "}"),
|
|
]);
|
|
expect(resolveNodeText(node)).toBe(homedir());
|
|
});
|
|
|
|
it("returns text as-is for a variable outside the resolvable set", () => {
|
|
const node = makeTSNode("expansion", "${VAR}", [
|
|
makeTSNode("${", "${"),
|
|
makeTSNode("variable_name", "VAR"),
|
|
makeTSNode("}", "}"),
|
|
]);
|
|
expect(resolveNodeText(node)).toBe("${VAR}");
|
|
});
|
|
|
|
it("returns text as-is for an expansion carrying an operator", () => {
|
|
const node = makeTSNode("expansion", "${HOME:-/tmp}", [
|
|
makeTSNode("${", "${"),
|
|
makeTSNode("variable_name", "HOME"),
|
|
makeTSNode(":-", ":-"),
|
|
makeTSNode("word", "/tmp"),
|
|
makeTSNode("}", "}"),
|
|
]);
|
|
expect(resolveNodeText(node)).toBe("${HOME:-/tmp}");
|
|
});
|
|
});
|
|
|
|
describe("concatenation nodes", () => {
|
|
it("concatenates resolved children", () => {
|
|
const word = makeTSNode("word", "/etc/");
|
|
const expansion = makeTSNode("simple_expansion", "$FILE", [
|
|
makeTSNode("$", "$"),
|
|
makeTSNode("variable_name", "FILE"),
|
|
]);
|
|
const node = makeTSNode("concatenation", "/etc/$FILE", [word, expansion]);
|
|
expect(resolveNodeText(node)).toBe("/etc/$FILE");
|
|
});
|
|
|
|
it("concatenates a resolved $HOME reference with its suffix", () => {
|
|
const expansion = makeTSNode("simple_expansion", "$HOME", [
|
|
makeTSNode("$", "$"),
|
|
makeTSNode("variable_name", "HOME"),
|
|
]);
|
|
const suffix = makeTSNode("word", "/sub");
|
|
const node = makeTSNode("concatenation", "$HOME/sub", [
|
|
expansion,
|
|
suffix,
|
|
]);
|
|
expect(resolveNodeText(node)).toBe(`${homedir()}/sub`);
|
|
});
|
|
|
|
it("handles nested concatenation-of-string", () => {
|
|
// A concatenation whose child is a double-quoted string
|
|
const quoteOpen = makeTSNode('"', '"');
|
|
const content = makeTSNode("string_content", "bar");
|
|
const quoteClose = makeTSNode('"', '"');
|
|
const inner = makeTSNode("string", '"bar"', [
|
|
quoteOpen,
|
|
content,
|
|
quoteClose,
|
|
]);
|
|
const prefix = makeTSNode("word", "foo");
|
|
const node = makeTSNode("concatenation", 'foo"bar"', [prefix, inner]);
|
|
expect(resolveNodeText(node)).toBe("foobar");
|
|
});
|
|
});
|
|
|
|
describe("default fallback", () => {
|
|
it("returns the raw text for unknown node types", () => {
|
|
expect(resolveNodeText(makeTSNode("unknown_type", "rawtext"))).toBe(
|
|
"rawtext",
|
|
);
|
|
});
|
|
});
|
|
});
|