mirror of
https://github.com/SikongJueluo/pi-extensions.git
synced 2026-10-05 11:52:55 +08:00
refactor(permission): consume structured bash payload
- require @gotgenes/pi-permission-system >=25.3.0 and read the complete local bash command from PromptPermissionDetails.payload instead of session-walking recovery - remove the @sikongjueluo/pi-permission-shared package - pass the triggering command unit to handlers via HandlerContext.unit in place of details.command - add shadow-only AI judge modules for evidence projection, structured verdict requests, and prompt building, with vitest coverage - record ADR 0004 and mark the ADR 0001 recovery mechanism superseded - exclude pi-permission-system 25.3.0 from the pnpm minimumReleaseAge guard
This commit is contained in:
@@ -0,0 +1,133 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { PromptPermissionDetails } from "@gotgenes/pi-permission-system";
|
||||
import { buildBashJudgmentEvidence } from "../src/evidence";
|
||||
|
||||
function details(
|
||||
unit: string,
|
||||
fullCommand = unit,
|
||||
): PromptPermissionDetails {
|
||||
return {
|
||||
requestId: "req-1",
|
||||
source: "tool_call",
|
||||
agentName: null,
|
||||
message: "bash ask",
|
||||
payload: {
|
||||
kind: "bash",
|
||||
request: {
|
||||
requester: {
|
||||
agentName: null,
|
||||
forwarded: false,
|
||||
sessionId: null,
|
||||
},
|
||||
surface: "bash",
|
||||
toolName: "bash",
|
||||
invokedToolName: null,
|
||||
value: unit,
|
||||
matchedPattern: null,
|
||||
commandContext: null,
|
||||
executedUnit: null,
|
||||
},
|
||||
evidence:
|
||||
fullCommand === unit
|
||||
? []
|
||||
: [
|
||||
{
|
||||
label: "full command",
|
||||
text: fullCommand,
|
||||
detail: null,
|
||||
},
|
||||
],
|
||||
annotations: [],
|
||||
},
|
||||
toolCallId: "call-1",
|
||||
toolName: "bash",
|
||||
command: unit,
|
||||
};
|
||||
}
|
||||
|
||||
describe("buildBashJudgmentEvidence", () => {
|
||||
it("uses request.value when the full command is equal and deduplicated", () => {
|
||||
expect(buildBashJudgmentEvidence(details("pnpm test"))).toEqual({
|
||||
fullCommand: "pnpm test",
|
||||
triggeringUnit: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it("uses the unique full-command evidence for a compound input", () => {
|
||||
expect(
|
||||
buildBashJudgmentEvidence(
|
||||
details(
|
||||
"git push origin main",
|
||||
"pnpm test && git push origin main",
|
||||
),
|
||||
),
|
||||
).toEqual({
|
||||
fullCommand: "pnpm test && git push origin main",
|
||||
triggeringUnit: "git push origin main",
|
||||
});
|
||||
});
|
||||
|
||||
it("defers on duplicate full-command evidence", () => {
|
||||
const ask = details("git push", "cd /repo && git push");
|
||||
const evidence = ask.payload.evidence[0]!;
|
||||
ask.payload = {
|
||||
...ask.payload,
|
||||
evidence: [evidence, evidence],
|
||||
};
|
||||
expect(buildBashJudgmentEvidence(ask)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("defers forwarded and shell-alias asks", () => {
|
||||
const forwarded = details("pnpm test");
|
||||
forwarded.forwarding = {
|
||||
requesterAgentName: "child",
|
||||
requesterSessionId: "s1",
|
||||
};
|
||||
expect(buildBashJudgmentEvidence(forwarded)).toBeUndefined();
|
||||
|
||||
const alias = details("pnpm test");
|
||||
alias.payload = {
|
||||
...alias.payload,
|
||||
request: {
|
||||
...alias.payload.request,
|
||||
invokedToolName: "exec_command",
|
||||
},
|
||||
};
|
||||
expect(buildBashJudgmentEvidence(alias)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("defers malformed forwarding and full-command fields", () => {
|
||||
const missingForwarded = details("pnpm test");
|
||||
missingForwarded.payload = {
|
||||
...missingForwarded.payload,
|
||||
request: {
|
||||
...missingForwarded.payload.request,
|
||||
requester: {
|
||||
agentName: null,
|
||||
forwarded: undefined as unknown as boolean,
|
||||
sessionId: null,
|
||||
},
|
||||
},
|
||||
};
|
||||
expect(buildBashJudgmentEvidence(missingForwarded)).toBeUndefined();
|
||||
|
||||
const nullText = details("git push", "cd /repo && git push");
|
||||
nullText.payload = {
|
||||
...nullText.payload,
|
||||
evidence: [
|
||||
{
|
||||
label: "full command",
|
||||
text: null as unknown as string,
|
||||
detail: null,
|
||||
},
|
||||
],
|
||||
};
|
||||
expect(buildBashJudgmentEvidence(nullText)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("defers when legacy and structured command units disagree", () => {
|
||||
const ask = details("pnpm test");
|
||||
ask.command = "git push";
|
||||
expect(buildBashJudgmentEvidence(ask)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user