feat(coding-agent): allow project trust extensions to defer

This commit is contained in:
Mario Zechner
2026-06-08 13:38:29 +02:00
parent 085a08582f
commit d8aef0feff
10 changed files with 72 additions and 19 deletions

View File

@@ -7,8 +7,8 @@ import * as os from "node:os";
import * as path from "node:path";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { AuthStorage } from "../src/core/auth-storage.ts";
import { createExtensionRuntime, discoverAndLoadExtensions } from "../src/core/extensions/loader.ts";
import { ExtensionRunner } from "../src/core/extensions/runner.ts";
import { createExtensionRuntime, discoverAndLoadExtensions, loadExtensions } from "../src/core/extensions/loader.ts";
import { ExtensionRunner, emitProjectTrustEvent } from "../src/core/extensions/runner.ts";
import type {
ExtensionActions,
ExtensionContextActions,
@@ -85,6 +85,45 @@ describe("ExtensionRunner", () => {
getSystemPrompt: () => "",
};
describe("project_trust", () => {
it("continues past undecided handlers and returns the first yes/no decision", async () => {
const undecidedPath = path.join(extensionsDir, "undecided.ts");
const decidedPath = path.join(extensionsDir, "decided.ts");
fs.writeFileSync(
undecidedPath,
`export default function(pi) {
pi.on("project_trust", () => ({ trusted: "undecided", remember: true }));
}`,
);
fs.writeFileSync(
decidedPath,
`export default function(pi) {
pi.on("project_trust", () => ({ trusted: "no", remember: true }));
}`,
);
const extensionsResult = await loadExtensions([undecidedPath, decidedPath], tempDir);
const result = await emitProjectTrustEvent(
extensionsResult,
{ type: "project_trust", cwd: tempDir },
{
cwd: tempDir,
mode: "tui",
hasUI: false,
ui: {
select: async () => undefined,
confirm: async () => false,
input: async () => undefined,
notify: () => {},
},
},
);
expect(result.result).toEqual({ trusted: "no", remember: true });
expect(result.errors).toEqual([]);
});
});
describe("shortcut conflicts", () => {
it("warns when extension shortcut conflicts with built-in", async () => {
const extCode = `

View File

@@ -199,7 +199,7 @@ Project skill`,
join(userExtDir, "user.ts"),
`globalThis[${JSON.stringify(loadCountKey)}] = (globalThis[${JSON.stringify(loadCountKey)}] ?? 0) + 1;
export default function(pi) {
pi.on("project_trust", () => ({ trusted: true }));
pi.on("project_trust", () => ({ trusted: "yes" }));
pi.registerCommand("user-trust", {
description: "user trust",
handler: async () => {},