mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 18:55:22 +00:00
feat: 移除 Codex Fast mode 与 AutoReview 后台分析,模型改为配置驱动
移除 pi-extension-codex-fast-mode:
- 删除整个扩展目录;同步清理根 package.json 的 files / pi.extensions /
dependencies 条目、package-lock.json、tests/extension-load.test.ts 断言
与文档章节。
- pi-minimal-footer 的 Fast on 渲染是该扩展的唯一消费者。扩展移除后 accent
分支不再有生产者,collectFooterStatusItems 简化为直接返回非空状态字符串,
去掉 FooterStatusItem 与 accent 标志,避免留下死代码。
移除 500 次裁决后的后台分析体系:
- 删除 analysis-agent.ts(192 行)与 ledger.ts(296 行),以及对应的
auto-review-runtime / auto-review-ledger 测试。
- runtime.ts 由 177 行收敛到 85 行:安装选项缩为 { service, config };删除
handleAgentSettled 与 agent_settled 注册;保留 session_start / turn_start
(denial circuit breaker 属安全语义)/ session_shutdown。
- 删除 analysis 配置键:config、extension-config、config-schema、生成的
permissions.schema.json 与种子配置。
- 删除 reviewer 的 onDecision 回调(唯一消费者是 ledger)。
- 删除迁移机制 scripts/migrate-permission-policy.mjs、其测试与 update.sh 中
46 行 migrate_permission_policy 接线。种子部署保持“目标缺失才写入”,已存在
的 policy.jsonc 永不被覆盖。
AutoReview 模型改为纯配置驱动:
- 删除 DEFAULT_PROVIDER / DEFAULT_MODEL 常量与 findCodexTemplate 合成逻辑;
model.ts 由 65 行收敛到 48 行。
- provider / model 任一缺失时返回新增失败类别 model-unconfigured 并 defer 到
人工审批;provider 未注册或模型未发布同样 defer。
- reasoning 不再有默认常量,完全由配置决定。
- session_start 在 auto-review 已列入 authorizerChain 且 provider/model 未配齐
时 ui.notify 提示一次,避免不使用 AutoReview 的用户被打扰。
- 种子 autoReview 只保留 enabled,provider/model/reasoning 由用户按本机实际
可用的模型填写。
破坏性变更:analysis 键已从 strictObject schema 删除,任何仍带该键的
policy.jsonc 会使整份配置被拒(fail-closed 到全 ask)。这是刻意的变更,已由
config-loader 测试固定,防止将来无声放宽。
测试:
- 新增 auto-review-model.test.ts(7 例),覆盖此前完全缺失的模型解析:真实
命中、未配置、provider 未知、模型未发布,以及不再合成替代模型。
- 重写 auto-review-runtime.test.ts(6 例):authorizer 注册、未配置时提示
一次、已配置 / disabled / 无 UI / 不在 chain 时静默。
- config-loader.test.ts 新增 2 例:带 analysis 的旧配置被拒且 fail-closed、
autoReview 逐字段合并。
- composition-root.test.ts 的 EXPECTED_HANDLERS 移除 agent_settled。
文档:AGENTS.md、README.md、pi-permission-system 的 README / CHANGELOG /
configuration.md / architecture.md / auto-review UPSTREAM.md。
验证:pi-permission-system 的 typecheck、2577 个测试与 build 全部通过;根 50
个测试通过;schema 重新生成无漂移;新种子通过 schema 校验;5 个脚本 sh -n
通过;git diff --check 无空白问题。未安装 shellcheck;未执行真实 pi install /
update(属外部写操作)。
This commit is contained in:
@@ -1,141 +0,0 @@
|
||||
import { mkdtempSync, readFileSync, rmSync, statSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
DEFAULT_AUTO_REVIEW_ANALYSIS_CONFIG,
|
||||
DEFAULT_AUTO_REVIEW_CONFIG,
|
||||
} from "#src/auto-review/config";
|
||||
import { AutoReviewLedger } from "#src/auto-review/ledger";
|
||||
import type { PromptPermissionDetails } from "#src/service";
|
||||
|
||||
const roots: string[] = [];
|
||||
|
||||
afterEach(() => {
|
||||
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
function details(requestId: string): PromptPermissionDetails {
|
||||
return {
|
||||
requestId,
|
||||
source: "tool",
|
||||
surface: "bash",
|
||||
toolName: "bash",
|
||||
command: "npm install example",
|
||||
agentName: "main",
|
||||
} as unknown as PromptPermissionDetails;
|
||||
}
|
||||
|
||||
describe("AutoReviewLedger", () => {
|
||||
it("marks analysis pending only after the configured number of completed verdicts", () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "auto-review-ledger-"));
|
||||
roots.push(root);
|
||||
const ledger = new AutoReviewLedger(root);
|
||||
const analysis = { ...DEFAULT_AUTO_REVIEW_ANALYSIS_CONFIG, threshold: 2 };
|
||||
const assessment = {
|
||||
outcome: "allow" as const,
|
||||
riskLevel: "low" as const,
|
||||
userAuthorization: "high" as const,
|
||||
rationale: "directly authorized",
|
||||
};
|
||||
|
||||
ledger.recordDecision({
|
||||
details: details("request-1"),
|
||||
assessment,
|
||||
policyRevision: "policy-a",
|
||||
config: DEFAULT_AUTO_REVIEW_CONFIG,
|
||||
analysis,
|
||||
});
|
||||
expect(ledger.hasPendingAnalysis()).toBe(false);
|
||||
expect(ledger.prepareBatch(analysis)).toBeUndefined();
|
||||
|
||||
ledger.recordDecision({
|
||||
details: details("request-2"),
|
||||
assessment,
|
||||
policyRevision: "policy-a",
|
||||
config: DEFAULT_AUTO_REVIEW_CONFIG,
|
||||
analysis,
|
||||
});
|
||||
expect(ledger.hasPendingAnalysis()).toBe(true);
|
||||
const batch = ledger.prepareBatch(analysis);
|
||||
expect(batch?.fromSequence).toBe(1);
|
||||
expect(batch?.toSequence).toBe(2);
|
||||
expect(batch?.records).toHaveLength(2);
|
||||
expect(batch?.records[0]).not.toHaveProperty("rationale");
|
||||
expect(batch?.records[0].normalizedPattern).toBe("npm install *");
|
||||
});
|
||||
|
||||
it("persists owner-only state and resumes a pending batch", () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "auto-review-ledger-"));
|
||||
roots.push(root);
|
||||
const analysis = { ...DEFAULT_AUTO_REVIEW_ANALYSIS_CONFIG, threshold: 1 };
|
||||
const ledger = new AutoReviewLedger(root);
|
||||
ledger.recordDecision({
|
||||
details: details("request-1"),
|
||||
assessment: {
|
||||
outcome: "deny",
|
||||
riskLevel: "high",
|
||||
userAuthorization: "unknown",
|
||||
rationale: "unsafe",
|
||||
},
|
||||
policyRevision: "policy-b",
|
||||
config: DEFAULT_AUTO_REVIEW_CONFIG,
|
||||
analysis,
|
||||
});
|
||||
|
||||
const resumed = new AutoReviewLedger(root);
|
||||
expect(resumed.hasPendingAnalysis()).toBe(true);
|
||||
expect(resumed.prepareBatch(analysis)?.records[0].outcome).toBe("deny");
|
||||
expect(statSync(join(root, "state.json")).mode & 0o777).toBe(0o600);
|
||||
expect(readFileSync(join(root, "ledger", "decisions.jsonl"), "utf8")).not.toContain("unsafe");
|
||||
});
|
||||
|
||||
it("does not retain command arguments, secret path segments, or rationale", () => {
|
||||
const root = mkdtempSync(join(tmpdir(), "auto-review-ledger-"));
|
||||
roots.push(root);
|
||||
const ledger = new AutoReviewLedger(root);
|
||||
const analysis = { ...DEFAULT_AUTO_REVIEW_ANALYSIS_CONFIG, threshold: 10 };
|
||||
const assessment = {
|
||||
outcome: "allow" as const,
|
||||
riskLevel: "medium" as const,
|
||||
userAuthorization: "high" as const,
|
||||
rationale: "secret-rationale",
|
||||
};
|
||||
const commandRecord = ledger.recordDecision({
|
||||
details: {
|
||||
requestId: "request-command",
|
||||
source: "tool",
|
||||
agentName: "main",
|
||||
surface: "bash",
|
||||
toolName: "bash",
|
||||
command: "curl https://token.example/?api_key=secret-value",
|
||||
} as unknown as PromptPermissionDetails,
|
||||
assessment,
|
||||
policyRevision: "policy-c",
|
||||
config: DEFAULT_AUTO_REVIEW_CONFIG,
|
||||
analysis,
|
||||
});
|
||||
const pathRecord = ledger.recordDecision({
|
||||
details: {
|
||||
requestId: "request-path",
|
||||
source: "tool",
|
||||
agentName: "main",
|
||||
surface: "path",
|
||||
toolName: "read",
|
||||
path: "clients/acme-secret/token.txt",
|
||||
} as unknown as PromptPermissionDetails,
|
||||
assessment,
|
||||
policyRevision: "policy-c",
|
||||
config: DEFAULT_AUTO_REVIEW_CONFIG,
|
||||
analysis,
|
||||
});
|
||||
|
||||
expect(commandRecord.normalizedPattern).toBe("curl *");
|
||||
expect(pathRecord.normalizedPattern).toBe("<relative>/*");
|
||||
const persisted = readFileSync(join(root, "ledger", "decisions.jsonl"), "utf8");
|
||||
expect(persisted).not.toContain("secret-value");
|
||||
expect(persisted).not.toContain("acme-secret");
|
||||
expect(persisted).not.toContain("secret-rationale");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,94 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import type { Api, Model, Provider } from "@earendil-works/pi-ai";
|
||||
import { resolveReviewModel, type ReviewModelRegistry } from "#src/auto-review/model";
|
||||
import { DEFAULT_AUTO_REVIEW_CONFIG, type AutoReviewConfig } from "#src/auto-review/config";
|
||||
|
||||
const model: Model<Api> = {
|
||||
id: "reviewer-model",
|
||||
name: "Reviewer Model",
|
||||
api: "openai-completions",
|
||||
provider: "vendor",
|
||||
baseUrl: "https://example.invalid",
|
||||
reasoning: true,
|
||||
input: ["text"],
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||
contextWindow: 1000,
|
||||
maxTokens: 100,
|
||||
};
|
||||
|
||||
function registryWith(providerId: string | undefined): ReviewModelRegistry {
|
||||
const provider = { id: providerId ?? "vendor", getModels: () => [model] } as unknown as Provider<Api>;
|
||||
return {
|
||||
find: (candidateProvider, modelId) =>
|
||||
candidateProvider === providerId && modelId === model.id ? model : undefined,
|
||||
getAll: () => [model],
|
||||
getProvider: (candidate) => (candidate === providerId ? provider : undefined),
|
||||
getApiKeyAndHeaders: async () => ({ ok: true, apiKey: "key" }),
|
||||
};
|
||||
}
|
||||
|
||||
function config(overrides: Partial<AutoReviewConfig>): AutoReviewConfig {
|
||||
return { ...DEFAULT_AUTO_REVIEW_CONFIG, ...overrides };
|
||||
}
|
||||
|
||||
describe("resolveReviewModel", () => {
|
||||
it("resolves the operator-named model from the registry", () => {
|
||||
const result = resolveReviewModel(
|
||||
registryWith("vendor"),
|
||||
config({ provider: "vendor", model: "reviewer-model" }),
|
||||
);
|
||||
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) throw new Error("expected success");
|
||||
expect(result.value.model.id).toBe("reviewer-model");
|
||||
expect(result.value.provider.id).toBe("vendor");
|
||||
});
|
||||
|
||||
it("reports model-unconfigured when no provider is named", () => {
|
||||
const result = resolveReviewModel(registryWith("vendor"), config({ model: "reviewer-model" }));
|
||||
|
||||
expect(result).toEqual({ ok: false, category: "model-unconfigured" });
|
||||
});
|
||||
|
||||
it("reports model-unconfigured when no model is named", () => {
|
||||
const result = resolveReviewModel(registryWith("vendor"), config({ provider: "vendor" }));
|
||||
|
||||
expect(result).toEqual({ ok: false, category: "model-unconfigured" });
|
||||
});
|
||||
|
||||
it("reports model-unconfigured for the default config with no named pair", () => {
|
||||
const result = resolveReviewModel(registryWith("vendor"), DEFAULT_AUTO_REVIEW_CONFIG);
|
||||
|
||||
expect(result).toEqual({ ok: false, category: "model-unconfigured" });
|
||||
});
|
||||
|
||||
it("reports provider-unresolved for an unknown provider", () => {
|
||||
const result = resolveReviewModel(
|
||||
registryWith("vendor"),
|
||||
config({ provider: "missing", model: "reviewer-model" }),
|
||||
);
|
||||
|
||||
expect(result).toEqual({ ok: false, category: "provider-unresolved" });
|
||||
});
|
||||
|
||||
it("reports model-unresolved for a model the provider does not publish", () => {
|
||||
const result = resolveReviewModel(
|
||||
registryWith("vendor"),
|
||||
config({ provider: "vendor", model: "missing-model" }),
|
||||
);
|
||||
|
||||
expect(result).toEqual({ ok: false, category: "model-unresolved" });
|
||||
});
|
||||
|
||||
it("never synthesizes a model the provider does not publish", () => {
|
||||
// The reviewer used to fall back to a synthesized Codex stand-in. It must
|
||||
// now refuse instead, so the ask defers to the human prompt.
|
||||
const result = resolveReviewModel(
|
||||
registryWith("vendor"),
|
||||
config({ provider: "vendor", model: "codex-auto-review" }),
|
||||
);
|
||||
|
||||
expect(result.ok).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,61 +1,15 @@
|
||||
import { mkdtempSync, rmSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type { ExtensionAPI, ModelRegistry, SessionManager } from "@earendil-works/pi-coding-agent";
|
||||
import {
|
||||
DEFAULT_AUTO_REVIEW_ANALYSIS_CONFIG,
|
||||
DEFAULT_AUTO_REVIEW_CONFIG,
|
||||
} from "#src/auto-review/config";
|
||||
import { AutoReviewLedger } from "#src/auto-review/ledger";
|
||||
import type { ExtensionContext, ModelRegistry, SessionManager } from "@earendil-works/pi-coding-agent";
|
||||
import { DEFAULT_AUTO_REVIEW_CONFIG, type AutoReviewConfig } from "#src/auto-review/config";
|
||||
import { installBuiltinAutoReview } from "#src/auto-review/runtime";
|
||||
import { getAnalysisStateDir } from "#src/config-paths";
|
||||
import type { ConfigReader } from "#src/config-store";
|
||||
import type { PermissionsService, PromptPermissionDetails } from "#src/service";
|
||||
import type { ReviewLogger } from "#src/session-logger";
|
||||
import type { PermissionsService } from "#src/service";
|
||||
|
||||
type AnalysisRunner = NonNullable<
|
||||
Parameters<typeof installBuiltinAutoReview>[0]["runAnalysis"]
|
||||
>;
|
||||
|
||||
const roots: string[] = [];
|
||||
|
||||
afterEach(() => {
|
||||
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
function seedPending(agentDir: string) {
|
||||
const analysis = { ...DEFAULT_AUTO_REVIEW_ANALYSIS_CONFIG, threshold: 1 };
|
||||
const ledger = new AutoReviewLedger(getAnalysisStateDir(agentDir));
|
||||
ledger.recordDecision({
|
||||
details: {
|
||||
requestId: "request-1",
|
||||
source: "tool",
|
||||
agentName: "main",
|
||||
surface: "bash",
|
||||
toolName: "bash",
|
||||
command: "npm install example",
|
||||
} as unknown as PromptPermissionDetails,
|
||||
assessment: {
|
||||
outcome: "allow",
|
||||
riskLevel: "low",
|
||||
userAuthorization: "high",
|
||||
rationale: "directly authorized",
|
||||
},
|
||||
policyRevision: "policy-a",
|
||||
config: DEFAULT_AUTO_REVIEW_CONFIG,
|
||||
analysis,
|
||||
});
|
||||
return { analysis, ledger };
|
||||
}
|
||||
|
||||
function harness(agentDir: string, analysis: typeof DEFAULT_AUTO_REVIEW_ANALYSIS_CONFIG, runAnalysis: Parameters<typeof installBuiltinAutoReview>[0]["runAnalysis"]) {
|
||||
const sendMessage = vi.fn();
|
||||
function harness(autoReview: AutoReviewConfig, hasUI = true) {
|
||||
const notify = vi.fn();
|
||||
const registerAuthorizer = vi.fn(() => () => {});
|
||||
const review = vi.fn();
|
||||
const controller = installBuiltinAutoReview({
|
||||
pi: { sendMessage } as unknown as ExtensionAPI,
|
||||
service: { registerAuthorizer } as unknown as PermissionsService,
|
||||
config: {
|
||||
current: () => ({
|
||||
@@ -63,118 +17,75 @@ function harness(agentDir: string, analysis: typeof DEFAULT_AUTO_REVIEW_ANALYSIS
|
||||
permissionReviewLog: true,
|
||||
yoloMode: false,
|
||||
doublePressToConfirm: true,
|
||||
autoReview: DEFAULT_AUTO_REVIEW_CONFIG,
|
||||
analysis,
|
||||
authorizerChain: ["auto-review"],
|
||||
autoReview,
|
||||
}),
|
||||
} as ConfigReader,
|
||||
logger: { review } as unknown as ReviewLogger,
|
||||
agentDir,
|
||||
runAnalysis,
|
||||
});
|
||||
controller.handleSessionStart({
|
||||
const ctx = {
|
||||
hasUI,
|
||||
ui: { notify },
|
||||
modelRegistry: {} as ModelRegistry,
|
||||
sessionManager: { getBranch: () => [] } as unknown as Pick<SessionManager, "getBranch">,
|
||||
});
|
||||
return { controller, sendMessage, registerAuthorizer, review };
|
||||
} as unknown as ExtensionContext;
|
||||
|
||||
controller.handleSessionStart(ctx);
|
||||
return { controller, notify, registerAuthorizer };
|
||||
}
|
||||
|
||||
describe("built-in AutoReview lifecycle", () => {
|
||||
it("analyzes a persisted pending checkpoint at agent_settled and follows up in the same session", async () => {
|
||||
const agentDir = mkdtempSync(join(tmpdir(), "auto-review-runtime-"));
|
||||
roots.push(agentDir);
|
||||
const { analysis } = seedPending(agentDir);
|
||||
const runAnalysis = vi.fn<AnalysisRunner>(async () => ({
|
||||
summary: "No unconditional policy changes recommended.",
|
||||
allowCandidates: [],
|
||||
denyCandidates: [],
|
||||
keepReview: [],
|
||||
hardGuardCandidates: [],
|
||||
}));
|
||||
const { controller, sendMessage, registerAuthorizer } = harness(agentDir, analysis, runAnalysis);
|
||||
|
||||
await controller.handleAgentSettled();
|
||||
it("registers the auto-review authorizer", () => {
|
||||
const { registerAuthorizer } = harness({ ...DEFAULT_AUTO_REVIEW_CONFIG });
|
||||
|
||||
expect(registerAuthorizer).toHaveBeenCalledWith("auto-review", expect.any(Function));
|
||||
expect(runAnalysis).toHaveBeenCalledTimes(1);
|
||||
expect(runAnalysis.mock.calls[0]?.[0].batch).toMatchObject({ fromSequence: 1, toSequence: 1 });
|
||||
expect(sendMessage).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ customType: "permission-policy-analysis-ready", display: true }),
|
||||
{ deliverAs: "followUp", triggerTurn: true },
|
||||
);
|
||||
expect(new AutoReviewLedger(getAnalysisStateDir(agentDir)).hasPendingAnalysis()).toBe(false);
|
||||
|
||||
await controller.handleAgentSettled();
|
||||
expect(runAnalysis).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("keeps the checkpoint pending when background analysis fails", async () => {
|
||||
const agentDir = mkdtempSync(join(tmpdir(), "auto-review-runtime-"));
|
||||
roots.push(agentDir);
|
||||
const { analysis } = seedPending(agentDir);
|
||||
const runAnalysis = vi.fn<AnalysisRunner>(async () => {
|
||||
throw new Error("analysis unavailable");
|
||||
it("warns once at session start when provider and model are unset", () => {
|
||||
const { notify } = harness({ ...DEFAULT_AUTO_REVIEW_CONFIG });
|
||||
|
||||
expect(notify).toHaveBeenCalledTimes(1);
|
||||
expect(notify.mock.calls[0]?.[1]).toBe("warning");
|
||||
expect(notify.mock.calls[0]?.[0]).toMatch(/provider.*model/iu);
|
||||
});
|
||||
|
||||
it("stays silent when both provider and model are configured", () => {
|
||||
const { notify } = harness({ ...DEFAULT_AUTO_REVIEW_CONFIG, provider: "vendor", model: "m" });
|
||||
|
||||
expect(notify).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("stays silent when AutoReview is disabled", () => {
|
||||
const { notify } = harness({ ...DEFAULT_AUTO_REVIEW_CONFIG, enabled: false });
|
||||
|
||||
expect(notify).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not notify without a UI", () => {
|
||||
const { notify } = harness({ ...DEFAULT_AUTO_REVIEW_CONFIG }, false);
|
||||
|
||||
expect(notify).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("stays silent when auto-review is not in the authorizer chain", () => {
|
||||
const notify = vi.fn();
|
||||
const controller = installBuiltinAutoReview({
|
||||
service: { registerAuthorizer: vi.fn(() => () => {}) } as unknown as PermissionsService,
|
||||
config: {
|
||||
current: () => ({
|
||||
debugLog: false,
|
||||
permissionReviewLog: true,
|
||||
yoloMode: false,
|
||||
doublePressToConfirm: true,
|
||||
authorizerChain: [],
|
||||
autoReview: { ...DEFAULT_AUTO_REVIEW_CONFIG },
|
||||
}),
|
||||
} as ConfigReader,
|
||||
});
|
||||
const { controller, sendMessage, review } = harness(agentDir, analysis, runAnalysis);
|
||||
|
||||
await controller.handleAgentSettled();
|
||||
|
||||
expect(sendMessage).not.toHaveBeenCalled();
|
||||
expect(review).toHaveBeenCalledWith("auto_review.analysis_failed", { error: "analysis unavailable" });
|
||||
expect(new AutoReviewLedger(getAnalysisStateDir(agentDir)).hasPendingAnalysis()).toBe(true);
|
||||
});
|
||||
|
||||
it("discards a stale result after session replacement without advancing the checkpoint", async () => {
|
||||
const agentDir = mkdtempSync(join(tmpdir(), "auto-review-runtime-"));
|
||||
roots.push(agentDir);
|
||||
const { analysis } = seedPending(agentDir);
|
||||
let resolveAnalysis!: (proposal: Awaited<ReturnType<AnalysisRunner>>) => void;
|
||||
const runAnalysis = vi.fn<AnalysisRunner>(() => new Promise((resolve) => {
|
||||
resolveAnalysis = resolve;
|
||||
}));
|
||||
const { controller, sendMessage, review } = harness(agentDir, analysis, runAnalysis);
|
||||
|
||||
const pending = controller.handleAgentSettled();
|
||||
expect(runAnalysis).toHaveBeenCalledTimes(1);
|
||||
controller.handleSessionShutdown();
|
||||
controller.handleSessionStart({
|
||||
modelRegistry: {} as ModelRegistry,
|
||||
sessionManager: { getBranch: () => [] } as unknown as Pick<SessionManager, "getBranch">,
|
||||
});
|
||||
resolveAnalysis({
|
||||
summary: "stale proposal",
|
||||
allowCandidates: [],
|
||||
denyCandidates: [],
|
||||
keepReview: [],
|
||||
hardGuardCandidates: [],
|
||||
});
|
||||
await pending;
|
||||
hasUI: true,
|
||||
ui: { notify },
|
||||
} as unknown as ExtensionContext);
|
||||
|
||||
expect(sendMessage).not.toHaveBeenCalled();
|
||||
expect(review).not.toHaveBeenCalledWith("auto_review.analysis_completed", expect.anything());
|
||||
expect(new AutoReviewLedger(getAnalysisStateDir(agentDir)).hasPendingAnalysis()).toBe(true);
|
||||
});
|
||||
|
||||
it("does not advance the checkpoint when same-session delivery fails", async () => {
|
||||
const agentDir = mkdtempSync(join(tmpdir(), "auto-review-runtime-"));
|
||||
roots.push(agentDir);
|
||||
const { analysis } = seedPending(agentDir);
|
||||
const runAnalysis = vi.fn<AnalysisRunner>(async () => ({
|
||||
summary: "proposal",
|
||||
allowCandidates: [],
|
||||
denyCandidates: [],
|
||||
keepReview: [],
|
||||
hardGuardCandidates: [],
|
||||
}));
|
||||
const { controller, sendMessage, review } = harness(agentDir, analysis, runAnalysis);
|
||||
sendMessage.mockImplementation(() => {
|
||||
throw new Error("session delivery unavailable");
|
||||
});
|
||||
|
||||
await controller.handleAgentSettled();
|
||||
|
||||
expect(review).toHaveBeenCalledWith("auto_review.analysis_failed", {
|
||||
error: "session delivery unavailable",
|
||||
});
|
||||
expect(new AutoReviewLedger(getAnalysisStateDir(agentDir)).hasPendingAnalysis()).toBe(true);
|
||||
expect(notify).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -45,7 +45,6 @@ const SERVING_REGISTRY_KEY = Symbol.for(
|
||||
|
||||
/** Events the factory must register a handler for. */
|
||||
const EXPECTED_HANDLERS = [
|
||||
"agent_settled",
|
||||
"before_agent_start",
|
||||
"input",
|
||||
"resources_discover",
|
||||
|
||||
@@ -131,6 +131,34 @@ describe("loadUnifiedConfig", () => {
|
||||
});
|
||||
});
|
||||
|
||||
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(
|
||||
|
||||
Reference in New Issue
Block a user