mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 10:45: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>
119 lines
4.0 KiB
TypeScript
119 lines
4.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { prefix, stripBashCommentLines } from "#src/bash-arity";
|
|
|
|
describe("prefix", () => {
|
|
it("returns empty array for empty input", () => {
|
|
expect(prefix([])).toEqual([]);
|
|
});
|
|
|
|
it("returns single-element array for a bare known command", () => {
|
|
// 'git' alone has arity 2 but only 1 token is available — clamp.
|
|
expect(prefix(["git"])).toEqual(["git"]);
|
|
});
|
|
|
|
it("returns arity-2 prefix for git subcommands", () => {
|
|
expect(prefix(["git", "checkout", "main"])).toEqual(["git", "checkout"]);
|
|
});
|
|
|
|
it("returns arity-2 prefix for git status with flags", () => {
|
|
expect(prefix(["git", "status", "--short"])).toEqual(["git", "status"]);
|
|
});
|
|
|
|
it("returns arity-3 prefix for npm run (longest match wins over npm arity-2)", () => {
|
|
expect(prefix(["npm", "run", "dev"])).toEqual(["npm", "run", "dev"]);
|
|
});
|
|
|
|
it("returns arity-2 prefix for npm install (npm fallback, npm run does not match)", () => {
|
|
expect(prefix(["npm", "install", "lodash"])).toEqual(["npm", "install"]);
|
|
});
|
|
|
|
it("returns arity-3 prefix for docker compose subcommands", () => {
|
|
expect(prefix(["docker", "compose", "up", "--build"])).toEqual([
|
|
"docker",
|
|
"compose",
|
|
"up",
|
|
]);
|
|
});
|
|
|
|
it("returns arity-2 prefix for docker pull (docker fallback)", () => {
|
|
expect(prefix(["docker", "pull", "ubuntu"])).toEqual(["docker", "pull"]);
|
|
});
|
|
|
|
it("returns arity-1 prefix for unknown commands", () => {
|
|
expect(prefix(["unknown-tool", "--flag"])).toEqual(["unknown-tool"]);
|
|
});
|
|
|
|
it("returns arity-1 prefix for rm (args are targets, not subcommands)", () => {
|
|
expect(prefix(["rm", "-rf", "node_modules"])).toEqual(["rm"]);
|
|
});
|
|
|
|
it("returns arity-1 prefix for cat", () => {
|
|
expect(prefix(["cat", "file.txt"])).toEqual(["cat"]);
|
|
});
|
|
|
|
it("is case-insensitive: 'Git' looks up as 'git'", () => {
|
|
// Tokens are preserved as-is; only the lookup key is lowercased.
|
|
expect(prefix(["Git", "checkout", "main"])).toEqual(["Git", "checkout"]);
|
|
});
|
|
|
|
it("clamps arity to available token count when command is shorter than arity", () => {
|
|
// npm run has arity 3; only ["npm", "run"] provided → return both.
|
|
expect(prefix(["npm", "run"])).toEqual(["npm", "run"]);
|
|
});
|
|
|
|
it("returns arity-2 prefix for pnpm run (longest match wins over pnpm)", () => {
|
|
// pnpm run <script> — arity 3 means include the script name.
|
|
expect(prefix(["pnpm", "run", "build"])).toEqual(["pnpm", "run", "build"]);
|
|
});
|
|
|
|
it("returns arity-2 prefix for cargo subcommands", () => {
|
|
expect(prefix(["cargo", "build", "--release"])).toEqual(["cargo", "build"]);
|
|
});
|
|
|
|
it("returns arity-2 prefix for kubectl subcommands", () => {
|
|
expect(prefix(["kubectl", "get", "pods"])).toEqual(["kubectl", "get"]);
|
|
});
|
|
|
|
it("returns arity-1 for bare 'ls' (args are paths)", () => {
|
|
expect(prefix(["ls", "-la", "/tmp"])).toEqual(["ls"]);
|
|
});
|
|
});
|
|
|
|
describe("stripBashCommentLines", () => {
|
|
it("removes a single leading comment line", () => {
|
|
expect(
|
|
stripBashCommentLines("# Check debug logs\nfind /home -type f"),
|
|
).toBe("find /home -type f");
|
|
});
|
|
|
|
it("removes multiple leading comment lines", () => {
|
|
expect(
|
|
stripBashCommentLines("# Step 1\n# Step 2\ngit status --short"),
|
|
).toBe("git status --short");
|
|
});
|
|
|
|
it("returns empty string when all lines are comments", () => {
|
|
expect(stripBashCommentLines("# just a comment")).toBe("");
|
|
});
|
|
|
|
it("returns empty string for blank input", () => {
|
|
expect(stripBashCommentLines("")).toBe("");
|
|
});
|
|
|
|
it("returns the command unchanged when no comment lines are present", () => {
|
|
expect(stripBashCommentLines("grep -rn foo src/")).toBe(
|
|
"grep -rn foo src/",
|
|
);
|
|
});
|
|
|
|
it("trims surrounding whitespace from the result", () => {
|
|
expect(stripBashCommentLines("\n\n ls -la \n")).toBe("ls -la");
|
|
});
|
|
|
|
it("treats indented comment lines as comments", () => {
|
|
expect(stripBashCommentLines(" # indented comment\necho hi")).toBe(
|
|
"echo hi",
|
|
);
|
|
});
|
|
});
|