forked from Emanuele-web04/synara
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathComposerPendingApprovalPanel.browser.tsx
More file actions
141 lines (126 loc) · 4.32 KB
/
Copy pathComposerPendingApprovalPanel.browser.tsx
File metadata and controls
141 lines (126 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// FILE: ComposerPendingApprovalPanel.browser.tsx
// Purpose: Browser regression coverage for the detached approval decision card.
// Layer: Chat composer UI browser test
// Depends on: ComposerPendingApprovalPanel and vitest-browser-react.
import {
ApprovalRequestId,
type ProviderApprovalDecision,
type ProviderRequestKind,
} from "@synara/contracts";
import { page } from "vitest/browser";
import { describe, expect, it, vi } from "vitest";
import { render } from "vitest-browser-react";
import { type PendingApproval } from "../../session-logic";
import { ComposerPendingApprovalPanel } from "./ComposerPendingApprovalPanel";
const APPROVAL_REQUEST_ID = ApprovalRequestId.makeUnsafe("approval-test-1");
const LIFECYCLE_GENERATION = "generation-test-1";
function makeApproval(overrides: Partial<PendingApproval> = {}): PendingApproval {
return {
requestId: APPROVAL_REQUEST_ID,
lifecycleGeneration: LIFECYCLE_GENERATION,
requestKind: "command",
createdAt: "2026-07-03T01:00:00.000Z",
detail: 'Bash: {"command":"bun run test"}',
...overrides,
};
}
async function mountApprovalPanel(input?: { approval?: PendingApproval; isResponding?: boolean }) {
const onRespond = vi.fn(
async (
_requestId: ApprovalRequestId,
_decision: ProviderApprovalDecision,
_lifecycleGeneration?: string,
_requestKind?: ProviderRequestKind,
) => undefined,
);
const screen = await render(
<ComposerPendingApprovalPanel
approval={input?.approval ?? makeApproval()}
pendingCount={1}
isResponding={input?.isResponding ?? false}
onRespond={onRespond}
/>,
);
return {
onRespond,
cleanup: async () => {
await screen.unmount();
},
};
}
describe("ComposerPendingApprovalPanel", () => {
it.each([
["Approve once", "accept"],
["Always allow this session", "acceptForSession"],
["Decline", "decline"],
["Cancel turn", "cancel"],
] as const)("sends %s as an approval decision", async (label, decision) => {
const mounted = await mountApprovalPanel();
try {
await page.getByRole("button", { name: new RegExp(label, "u") }).click();
expect(mounted.onRespond).toHaveBeenCalledTimes(1);
expect(mounted.onRespond).toHaveBeenCalledWith(
APPROVAL_REQUEST_ID,
decision,
LIFECYCLE_GENERATION,
"command",
);
} finally {
await mounted.cleanup();
}
});
it("renders the request kind prompt and parsed command detail", async () => {
const requestKind: ProviderRequestKind = "command";
const mounted = await mountApprovalPanel({
approval: makeApproval({ requestKind }),
});
try {
await expect.element(page.getByText("Approve this command?")).toBeInTheDocument();
await expect.element(page.getByText("bun run test")).toBeInTheDocument();
} finally {
await mounted.cleanup();
}
});
it("renders license-changer parody copy for permission requests", async () => {
const mounted = await mountApprovalPanel({
approval: makeApproval({
requestKind: "permissions",
detail: "Request to adjust LICENSE terms",
permissionProfile: {
license: { file: "LICENSE", readable: true },
copyrightOwner: "forkara-team",
},
}),
});
try {
await expect
.element(page.getByText("License Changer check: confirm legal ownership before proceeding"))
.toBeInTheDocument();
await expect
.element(page.getByRole("link", { name: /Read current LICENSE/u }))
.toBeInTheDocument();
await expect
.element(
page.getByText(
"Changing license terms is not a cosmetic toggle. Verify ownership and repository policy before allowing",
),
)
.toBeInTheDocument();
} finally {
await mounted.cleanup();
}
});
it("hides session approval when the provider cannot persist it", async () => {
const mounted = await mountApprovalPanel({
approval: makeApproval({ sessionApprovalAvailable: false }),
});
try {
await expect.element(page.getByRole("button", { name: /Approve once/u })).toBeInTheDocument();
await expect
.element(page.getByRole("button", { name: /Always allow this session/u }))
.not.toBeInTheDocument();
} finally {
await mounted.cleanup();
}
});
});