feat(coding-agent): add extension project trust decisions
This commit is contained in:
@@ -187,6 +187,53 @@ Project skill`,
|
||||
expect(extensionsResult.extensions[0].path).toBe(join(cwd, ".pi", "extensions", "shared.ts"));
|
||||
});
|
||||
|
||||
it("should load user extensions before trust and reuse them after trust resolves", async () => {
|
||||
const userExtDir = join(agentDir, "extensions");
|
||||
const projectExtDir = join(cwd, ".pi", "extensions");
|
||||
mkdirSync(userExtDir, { recursive: true });
|
||||
mkdirSync(projectExtDir, { recursive: true });
|
||||
const loadCountKey = `__piTrustPreloadCount_${Date.now()}_${Math.random().toString(36).slice(2)}`;
|
||||
const globalState = globalThis as typeof globalThis & Record<string, number | undefined>;
|
||||
|
||||
writeFileSync(
|
||||
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.registerCommand("user-trust", {
|
||||
description: "user trust",
|
||||
handler: async () => {},
|
||||
});
|
||||
}`,
|
||||
);
|
||||
writeFileSync(
|
||||
join(projectExtDir, "project.ts"),
|
||||
`export default function(pi) {
|
||||
pi.registerCommand("project-trusted", {
|
||||
description: "project trusted",
|
||||
handler: async () => {},
|
||||
});
|
||||
}`,
|
||||
);
|
||||
|
||||
const loader = new DefaultResourceLoader({ cwd, agentDir });
|
||||
await loader.reload({
|
||||
resolveProjectTrust: async ({ extensionsResult }) => {
|
||||
expect(extensionsResult.extensions.map((extension) => extension.path)).toEqual([
|
||||
join(userExtDir, "user.ts"),
|
||||
]);
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
const extensionsResult = loader.getExtensions();
|
||||
expect(extensionsResult.extensions.map((extension) => extension.path)).toEqual([
|
||||
join(cwd, ".pi", "extensions", "project.ts"),
|
||||
join(userExtDir, "user.ts"),
|
||||
]);
|
||||
expect(globalState[loadCountKey]).toBe(1);
|
||||
});
|
||||
|
||||
it("should keep both extensions loaded when command names collide", async () => {
|
||||
const userExtDir = join(agentDir, "extensions");
|
||||
const projectExtDir = join(cwd, ".pi", "extensions");
|
||||
|
||||
Reference in New Issue
Block a user