Skip to content

Commit b697629

Browse files
committed
fix(cli): escape standing-grant ledger fields visibly; register grants methods in inventory tests
The grant ledger's revokedBy (client display name), automation label, and agent-authored command now go through escapeApprovalTextForTerminal like the pending-approvals table, so hostile control characters render as visible \u{...} escapes instead of being silently stripped by the table renderer. Regression test fails pre-fix. Also lists exec.approval.grants.list/revoke in the 2026.8 release-train roster, classifies the approvals grants command group for JSON output, and fixes the stubGrants mock typing.
1 parent 288b72f commit b697629

5 files changed

Lines changed: 40 additions & 4 deletions

File tree

‎src/cli/exec-approvals-cli.pending-resolve.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,4 +527,33 @@ describe("exec approvals pending and resolve CLI", () => {
527527
);
528528
expect(callGatewayFromCli).toHaveBeenCalledTimes(1);
529529
});
530+
531+
it("escapes hostile grant fields visibly in the standing-grant ledger", async () => {
532+
const now = Date.now();
533+
callGatewayFromCli.mockResolvedValueOnce({
534+
grants: [
535+
{
536+
grantId: "grant-1",
537+
cronJobId: "job-1",
538+
cronJobName: "night\u001B[2Jly",
539+
command: "echo hi \u001B]52;c;steal\u0007",
540+
cwd: null,
541+
createdAtMs: now - 60_000,
542+
expiresAtMs: null,
543+
revokedAtMs: now - 1_000,
544+
revokedBy: "ops\u001B[1;31madmin",
545+
lastUsedAtMs: null,
546+
useCount: 3,
547+
},
548+
],
549+
});
550+
551+
await runApprovalsCommand(["approvals", "grants", "list"]);
552+
553+
const output = runtimeOutput();
554+
expect(output).not.toContain("\u001B");
555+
expect(output).toContain("revoked by ops\\u{1B}");
556+
expect(output).toContain("night\\u{1B}");
557+
expect(output).toContain("\\u{1B}]52;c;steal");
558+
});
530559
});

‎src/cli/exec-approvals-cli.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,9 @@ type StandingGrantCliEntry = {
558558

559559
function describeGrantState(grant: StandingGrantCliEntry, nowMs: number): string {
560560
if (grant.revokedAtMs !== null) {
561-
return `revoked${grant.revokedBy ? ` by ${grant.revokedBy}` : ""}`;
561+
// revokedBy carries the revoking client's self-reported display name;
562+
// escape it visibly rather than relying on the table's silent strip.
563+
return `revoked${grant.revokedBy ? ` by ${escapeApprovalTextForTerminal(grant.revokedBy)}` : ""}`;
562564
}
563565
if (grant.expiresAtMs !== null && grant.expiresAtMs <= nowMs) {
564566
return "expired";
@@ -589,8 +591,8 @@ function renderStandingGrants(grants: StandingGrantCliEntry[]): void {
589591
],
590592
rows: grants.map((grant) => ({
591593
ID: grant.grantId,
592-
Automation: grant.cronJobName ?? grant.cronJobId,
593-
Command: grant.command,
594+
Automation: escapeApprovalTextForTerminal(grant.cronJobName ?? grant.cronJobId),
595+
Command: escapeApprovalTextForTerminal(grant.command),
594596
Uses: String(grant.useCount),
595597
State: describeGrantState(grant, now),
596598
})),

‎src/cli/program/root-command-descriptions.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ const JSON_NOT_APPLICABLE = {
6262
"infer embedding",
6363
"approvals",
6464
"approvals allowlist",
65+
"approvals grants",
6566
"exec-policy",
6667
"nodes",
6768
"nodes camera",

‎src/gateway/methods/core-descriptors.since.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ const CURRENT_TRAIN_METHODS = [
8484
"diagnostics.lanes",
8585
"plugins.inspect",
8686
"device.pair.setupStatus",
87+
"exec.approval.grants.list",
88+
"exec.approval.grants.revoke",
8789
"sessions.patchMany",
8890
"sessions.groups.update",
8991
"sessions.groups.defaults",

‎ui/src/pages/approvals/approvals-page.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ afterEach(() => {
9898
vi.restoreAllMocks();
9999
});
100100

101-
function stubGrants(history: ReturnType<typeof vi.fn>): GatewayBrowserClient["request"] {
101+
function stubGrants(
102+
history: (method: string, params?: unknown) => unknown,
103+
): GatewayBrowserClient["request"] {
102104
// The page also loads the standing-grant ledger; answer it out of band so
103105
// history tests keep their ordered mock queues and call counts.
104106
return ((method: string, params?: unknown) =>

0 commit comments

Comments
 (0)