@bevel-software/platform-core-frontend 0.19.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/package.json +2 -2
  2. package/src/core/CoreAppShell.tsx +6 -2
  3. package/src/modules/access/hooks/useFileAccess.ts +2 -2
  4. package/src/modules/audit/__tests__/AuditLogPage.test.tsx +312 -0
  5. package/src/modules/audit/components/AuditEventsPanel.tsx +319 -0
  6. package/src/modules/audit/components/AuditLogPage.tsx +373 -0
  7. package/src/modules/audit/components/principal-grouping.ts +49 -0
  8. package/src/modules/audit/services/audit.api.ts +98 -0
  9. package/src/modules/auth/components/LoginScreen.tsx +1 -0
  10. package/src/modules/git/components/BranchSwitcher.tsx +9 -3
  11. package/src/modules/git/components/FileComparisonPanel.tsx +10 -4
  12. package/src/modules/git/components/PullNeededBanner.tsx +2 -2
  13. package/src/modules/git/services/error-messages.ts +2 -2
  14. package/src/modules/layout/__tests__/HeaderAlignment.test.tsx +110 -9
  15. package/src/modules/layout/components/SidebarFrame.tsx +26 -9
  16. package/src/modules/library/__tests__/DeleteToolDialog.test.tsx +11 -0
  17. package/src/modules/library/__tests__/LibraryRoutes.test.tsx +3 -0
  18. package/src/modules/library/__tests__/PluginIndexRow.test.tsx +146 -0
  19. package/src/modules/library/__tests__/PluginPage.test.tsx +110 -3
  20. package/src/modules/library/__tests__/ToolPage.test.tsx +20 -0
  21. package/src/modules/library/__tests__/name-with-badges.test.tsx +16 -3
  22. package/src/modules/library/__tests__/title-row-actions.ts +43 -0
  23. package/src/modules/library/components/PluginIndexRow.tsx +37 -20
  24. package/src/modules/library/components/PluginPage.tsx +115 -3
  25. package/src/modules/library/components/tool-page/ToolPage.tsx +25 -17
  26. package/src/modules/library/routes/library-paths.ts +9 -2
  27. package/src/modules/library/services/plugins.api.ts +45 -0
  28. package/src/modules/library/utils/plugin-summary.ts +7 -2
  29. package/src/modules/onboarding/__tests__/onboarding.test.tsx +43 -0
  30. package/src/modules/onboarding/components/ConnectAgentPill.tsx +13 -2
  31. package/src/modules/pr/components/OpenChangeRequestDialog.tsx +3 -2
  32. package/src/modules/review/components/ReviewPanel.tsx +2 -2
  33. package/src/modules/settings/components/__tests__/SettingsLayout.test.tsx +2 -1
  34. package/src/modules/settings/settings-nav-items.tsx +11 -9
  35. package/src/modules/setup/components/SetupScreen.tsx +11 -0
  36. package/src/modules/setup/services/setup.api.ts +1 -1
  37. package/src/modules/toolbar/services/external-api-keys.api.ts +2 -0
  38. package/src/modules/workspace/components/FileExplorer.tsx +4 -2
  39. package/src/modules/workspace/components/FileViewer.tsx +14 -4
  40. package/src/modules/workspace/components/KbDocumentShell.tsx +50 -8
  41. package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +60 -0
  42. package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +99 -0
  43. package/src/modules/workspace/components/__tests__/KbDocumentShell.test.tsx +49 -1
  44. package/src/modules/workspace/hooks/useWorkspaceState.ts +7 -2
  45. package/src/modules/workspace/services/__tests__/workspace.api.test.ts +78 -1
  46. package/src/modules/workspace/utils/fileTree.ts +2 -1
  47. package/src/modules/workspace/utils/treeConfirm.ts +7 -3
  48. package/src/shared/theme/measure.ts +23 -2
  49. package/src/modules/admin/__tests__/ConnectionKeysPage.test.tsx +0 -266
  50. package/src/modules/admin/components/ConnectionKeysPage.tsx +0 -269
  51. package/src/modules/admin/components/connection-keys-grouping.ts +0 -43
  52. package/src/modules/admin/services/connection-keys.api.ts +0 -47
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bevel-software/platform-core-frontend",
3
- "version": "0.19.0",
3
+ "version": "0.21.0",
4
4
  "description": "Open-source core UI of the Bevel platform (raw TS/TSX source): workspace explorer/viewer, branches & change requests, Library, secrets, tools, access control.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -45,7 +45,7 @@
45
45
  "tailwind-merge": "^3.5.0",
46
46
  "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
47
47
  "yaml": "^2.9.0",
48
- "@bevel-software/platform-shared": "0.19.0"
48
+ "@bevel-software/platform-shared": "0.21.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@testing-library/jest-dom": "^6.9.1",
@@ -46,7 +46,7 @@ import { ExternalAgentAccessPage } from '../modules/toolbar/components/ExternalA
46
46
  import { AdminRolesPage } from '../modules/admin/components/AdminRolesPage';
47
47
  import { UserAccountsPage } from '../modules/admin/components/UserAccountsPage';
48
48
  import { DirectoryGroupsPage } from '../modules/admin/components/DirectoryGroupsPage';
49
- import { ConnectionKeysPage } from '../modules/admin/components/ConnectionKeysPage';
49
+ import { AuditLogPage } from '../modules/audit/components/AuditLogPage';
50
50
  import { ToolsExplorerPage } from '../modules/tools/ToolsExplorerPage';
51
51
  import { LibraryRoutes } from '../modules/library/routes/LibraryRoutes';
52
52
  import { RootLanding } from '../modules/onboarding/components/RootLanding';
@@ -421,7 +421,11 @@ export function ShellRoutes({ apps }: { apps: AppDef[] }) {
421
421
  <Route path="/deployment" element={<DeploymentPage />} />
422
422
  <Route path="/user-accounts" element={<UserAccountsPage />} />
423
423
  <Route path="/directory-groups" element={<DirectoryGroupsPage />} />
424
- <Route path="/connection-keys" element={<ConnectionKeysPage />} />
424
+ <Route path="/audit-log" element={<AuditLogPage />} />
425
+ {/* The Audit log replaced the admin Connection keys overview; links
426
+ to the old address (bookmarks, the enterprise shell's older rows)
427
+ land on it. */}
428
+ <Route path="/connection-keys" element={<Navigate to="/audit-log" replace />} />
425
429
  <Route path="/tools" element={<ToolsExplorerPage />} />
426
430
  </Route>
427
431
  {/* `/` consults the onboarding: a brand-new account's FIRST visit lands
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useState } from 'react';
2
- import { isProtectedBranch } from '@bevel-software/platform-shared';
2
+ import { currentBranchModel, isProtectedBranch } from '@bevel-software/platform-shared';
3
3
  import { useWorkspace } from '../../workspace/state/workspace.context';
4
4
  import { fetchFileAccess, type AccessEligible } from '../api';
5
5
 
@@ -98,7 +98,7 @@ export function useFileAccess(
98
98
  setState({ canWrite: null, canDownload: null, eligible: EMPTY_ELIGIBLE, owners: EMPTY_ELIGIBLE, loading: false, error: null });
99
99
  return;
100
100
  }
101
- if (!isProtectedBranch(branch)) {
101
+ if (!isProtectedBranch(currentBranchModel(), branch)) {
102
102
  // `canDownload: null` — NOT true. The write short-circuits are this
103
103
  // hook's own policy, and they match the backend's write gates; the raw
104
104
  // endpoint gates EVERY download regardless of branch or path, so
@@ -0,0 +1,312 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { render, screen, waitFor, within } from '@testing-library/react';
3
+ import userEvent from '@testing-library/user-event';
4
+ import { MemoryRouter } from 'react-router-dom';
5
+ import { AuditLogPage } from '../components/AuditLogPage';
6
+ import { groupByAccount } from '../components/principal-grouping';
7
+ import { AdminContext } from '../../admin/state/admin.context';
8
+ import { AuthContext } from '../../auth/state/auth.context';
9
+ import {
10
+ listPrincipals,
11
+ listEvents,
12
+ revokeAgent,
13
+ revokeKey,
14
+ type AgentEvent,
15
+ type AuditPrincipal,
16
+ } from '../services/audit.api';
17
+
18
+ vi.mock('../services/audit.api', () => ({
19
+ listPrincipals: vi.fn(),
20
+ listEvents: vi.fn(),
21
+ revokeAgent: vi.fn(),
22
+ revokeKey: vi.fn(),
23
+ }));
24
+
25
+ const ALICE = { id: 'u-alice', email: 'alice@example.com', name: 'Alice' };
26
+ const BOB = { id: 'u-bob', email: 'bob@example.com', name: 'Bob' };
27
+
28
+ const DAY = 24 * 60 * 60 * 1000;
29
+ const NOW = Date.now();
30
+
31
+ const ALICE_CLAUDE: AuditPrincipal = {
32
+ kind: 'agent',
33
+ id: 'c-claude',
34
+ label: 'Claude',
35
+ createdAt: NOW - 12 * DAY,
36
+ lastUsedAt: NOW - 4 * 60 * 1000,
37
+ revokedAt: null,
38
+ revokedBy: null,
39
+ eventCount: 3,
40
+ user: ALICE,
41
+ };
42
+ const ALICE_CI: AuditPrincipal = {
43
+ kind: 'key',
44
+ id: 'k-ci',
45
+ label: 'CI pipeline',
46
+ keyKind: 'key',
47
+ createdAt: NOW - 10 * DAY,
48
+ lastUsedAt: NOW - 2 * 60 * 60 * 1000,
49
+ revokedAt: null,
50
+ revokedBy: null,
51
+ eventCount: 0,
52
+ user: ALICE,
53
+ };
54
+ const BOB_OLD: AuditPrincipal = {
55
+ kind: 'key',
56
+ id: 'k-old',
57
+ label: 'Old script',
58
+ keyKind: 'key',
59
+ createdAt: NOW - 40 * DAY,
60
+ lastUsedAt: NOW - 30 * DAY,
61
+ revokedAt: NOW - 20 * DAY,
62
+ revokedBy: 'admin',
63
+ eventCount: 18,
64
+ user: BOB,
65
+ };
66
+ const BOB_LINK: AuditPrincipal = {
67
+ kind: 'key',
68
+ id: 'k-link',
69
+ label: 'Claude',
70
+ keyKind: 'github-link',
71
+ createdAt: NOW - DAY,
72
+ lastUsedAt: NOW - 60 * 1000,
73
+ revokedAt: null,
74
+ revokedBy: null,
75
+ eventCount: 63,
76
+ user: BOB,
77
+ };
78
+
79
+ const EVENTS: AgentEvent[] = [
80
+ { id: 'e1', kind: 'capability', manual: null, name: 'grep', outcome: 'ok', at: NOW - 1000 },
81
+ { id: 'e2', kind: 'tool', manual: 'notion', name: 'notion-search', outcome: 'error', at: NOW - 2000 },
82
+ { id: 'e3', kind: 'skill', manual: 'Plugins/Sales/rfi', name: 'rfi', outcome: 'ok', at: NOW - 3000 },
83
+ { id: 'e4', kind: 'tool', manual: 'slack', name: 'post_message', outcome: 'denied', at: NOW - 4000 },
84
+ ];
85
+
86
+ function renderPage(opts: { isAdmin?: boolean; me?: typeof ALICE } = {}) {
87
+ const me = opts.me ?? ALICE;
88
+ return render(
89
+ <MemoryRouter>
90
+ <AuthContext.Provider
91
+ value={{
92
+ user: { id: me.id, email: me.email, name: me.name },
93
+ token: 'jwt',
94
+ isLoading: false,
95
+ login: async () => {},
96
+ logout: () => {},
97
+ }}
98
+ >
99
+ <AdminContext.Provider
100
+ value={{
101
+ isAdmin: opts.isAdmin ?? false,
102
+ isAdminLoading: false,
103
+ unreadCount: 0,
104
+ lastSeen: null,
105
+ markSeen: () => {},
106
+ refresh: () => {},
107
+ rolesConfigCorrupted: false,
108
+ rolesConfigErrors: [],
109
+ runRolesRecovery: async () => {},
110
+ }}
111
+ >
112
+ <AuditLogPage />
113
+ </AdminContext.Provider>
114
+ </AuthContext.Provider>
115
+ </MemoryRouter>,
116
+ );
117
+ }
118
+
119
+ beforeEach(() => {
120
+ vi.mocked(listPrincipals).mockReset().mockResolvedValue([ALICE_CLAUDE, ALICE_CI, BOB_LINK, BOB_OLD]);
121
+ vi.mocked(listEvents).mockReset().mockResolvedValue({ events: EVENTS, total: 4, nextCursor: null });
122
+ vi.mocked(revokeAgent).mockReset().mockResolvedValue(undefined);
123
+ vi.mocked(revokeKey).mockReset().mockResolvedValue(undefined);
124
+ });
125
+
126
+ describe('groupByAccount', () => {
127
+ it('groups in server order and drops revoked rows (and accounts left empty) when they are hidden', () => {
128
+ const groups = groupByAccount([ALICE_CLAUDE, ALICE_CI, BOB_OLD], { includeRevoked: false });
129
+ expect(groups.map((g) => g.user.id)).toEqual(['u-alice']);
130
+ expect(groups[0].principals.map((p) => p.id)).toEqual(['c-claude', 'k-ci']);
131
+ expect(groupByAccount([ALICE_CLAUDE, BOB_OLD], { includeRevoked: true }).map((g) => g.user.id)).toEqual(['u-alice', 'u-bob']);
132
+ });
133
+
134
+ it('narrows by person or by row label', () => {
135
+ const all = [ALICE_CLAUDE, ALICE_CI, BOB_LINK];
136
+ expect(groupByAccount(all, { includeRevoked: true, query: 'bob' }).map((g) => g.user.id)).toEqual(['u-bob']);
137
+ const byLabel = groupByAccount(all, { includeRevoked: true, query: 'CI' });
138
+ expect(byLabel).toHaveLength(1);
139
+ expect(byLabel[0].principals.map((p) => p.id)).toEqual(['k-ci']);
140
+ });
141
+ });
142
+
143
+ describe('AuditLogPage', () => {
144
+ it("asks for the member's own rows and lists them without account headers", async () => {
145
+ vi.mocked(listPrincipals).mockResolvedValue([ALICE_CLAUDE, ALICE_CI]);
146
+ renderPage({ isAdmin: false });
147
+ await waitFor(() => expect(screen.getByText('CI pipeline')).toBeInTheDocument());
148
+
149
+ expect(listPrincipals).toHaveBeenCalledWith('me');
150
+ expect(screen.getByText('Claude')).toBeInTheDocument();
151
+ expect(screen.getByText('Agent · OAuth')).toBeInTheDocument();
152
+ expect(screen.getByText('Connection key')).toBeInTheDocument();
153
+ expect(screen.getByText(/Connected 1w ago/)).toBeInTheDocument();
154
+ expect(screen.getByText(/3 events/)).toBeInTheDocument();
155
+ expect(screen.getByText(/No events yet/)).toBeInTheDocument();
156
+ // A member sees no per-account header: the page is theirs alone.
157
+ expect(screen.queryByText('alice@example.com')).not.toBeInTheDocument();
158
+ expect(screen.getByText(/2 live/)).toBeInTheDocument();
159
+ });
160
+
161
+ it('asks for every account for an admin, grouped per person, hiding revoked rows by default', async () => {
162
+ renderPage({ isAdmin: true });
163
+ await waitFor(() => expect(screen.getByText('CI pipeline')).toBeInTheDocument());
164
+
165
+ expect(listPrincipals).toHaveBeenCalledWith('all');
166
+ const alice = screen.getByRole('region', { name: 'Agents and keys for alice@example.com' });
167
+ expect(within(alice).getByText('Alice')).toBeInTheDocument();
168
+ expect(within(alice).getByText('CI pipeline')).toBeInTheDocument();
169
+ const bob = screen.getByRole('region', { name: 'Agents and keys for bob@example.com' });
170
+ expect(within(bob).getByText('Claude link')).toBeInTheDocument();
171
+ expect(within(bob).queryByText('Old script')).not.toBeInTheDocument();
172
+ expect(screen.getByText(/2 accounts · 3 live · 1 revoked/)).toBeInTheDocument();
173
+
174
+ await userEvent.click(screen.getByRole('checkbox', { name: 'Show revoked' }));
175
+ expect(within(bob).getByText('Old script')).toBeInTheDocument();
176
+ expect(within(bob).getByText('Revoked by an admin')).toBeInTheDocument();
177
+ expect(screen.queryByRole('button', { name: /Revoke key for Old script/ })).not.toBeInTheDocument();
178
+ });
179
+
180
+ it('shows an admin a key its owner deleted for good, marked as such, with its history intact', async () => {
181
+ vi.mocked(listPrincipals).mockResolvedValue([{ ...BOB_OLD, deletedAt: NOW - 10 * DAY, eventCount: 18 }]);
182
+ renderPage({ isAdmin: true });
183
+ await waitFor(() => expect(screen.getByText(/1 revoked/)).toBeInTheDocument());
184
+ await userEvent.click(screen.getByRole('checkbox', { name: 'Show revoked' }));
185
+ expect(screen.getByText('Old script')).toBeInTheDocument();
186
+ expect(screen.getByText('Deleted by owner')).toBeInTheDocument();
187
+ expect(screen.getByText(/18 events/)).toBeInTheDocument();
188
+ });
189
+
190
+ it('expands a row to its events once, keeps them across a collapse, and filters them', async () => {
191
+ vi.mocked(listPrincipals).mockResolvedValue([ALICE_CLAUDE]);
192
+ renderPage();
193
+ const row = await screen.findByRole('button', { name: /Claude/, expanded: false });
194
+
195
+ await userEvent.click(row);
196
+ await waitFor(() => expect(screen.getByText('grep')).toBeInTheDocument());
197
+ expect(listEvents).toHaveBeenCalledWith('agent', 'c-claude', { limit: 50 });
198
+ expect(row).toHaveAttribute('aria-expanded', 'true');
199
+
200
+ // Skills and tools link to their pages; a capability is plain text.
201
+ expect(screen.getByRole('link', { name: 'rfi' })).toHaveAttribute('href', '/skills-and-tools/skills/rfi');
202
+ expect(screen.getByRole('link', { name: /notion-search/ })).toHaveAttribute('href', '/skills-and-tools/tools/notion');
203
+ expect(screen.queryByRole('link', { name: 'grep' })).not.toBeInTheDocument();
204
+ expect(screen.getByText('needs sign-in')).toBeInTheDocument();
205
+ expect(screen.getByText(/Showing 4 of 4 events/)).toBeInTheDocument();
206
+
207
+ // Errors only: the ok rows go, the error and the denied one stay.
208
+ await userEvent.click(screen.getByRole('checkbox', { name: 'Errors only' }));
209
+ expect(screen.queryByText('grep')).not.toBeInTheDocument();
210
+ expect(screen.getByRole('link', { name: /notion-search/ })).toBeInTheDocument();
211
+ expect(screen.getByRole('link', { name: /post_message/ })).toBeInTheDocument();
212
+ await userEvent.click(screen.getByRole('checkbox', { name: 'Errors only' }));
213
+
214
+ // Type chips narrow to one kind.
215
+ await userEvent.click(screen.getByRole('button', { name: 'Skill', pressed: false }));
216
+ expect(screen.getByRole('link', { name: 'rfi' })).toBeInTheDocument();
217
+ expect(screen.queryByText('grep')).not.toBeInTheDocument();
218
+
219
+ // Collapse and re-expand: no second request.
220
+ await userEvent.click(row);
221
+ expect(row).toHaveAttribute('aria-expanded', 'false');
222
+ await userEvent.click(row);
223
+ expect(row).toHaveAttribute('aria-expanded', 'true');
224
+ expect(listEvents).toHaveBeenCalledTimes(1);
225
+ });
226
+
227
+ it('offers to try again when the first load fails, and names its panel only once it exists', async () => {
228
+ vi.mocked(listPrincipals).mockResolvedValue([ALICE_CLAUDE]);
229
+ vi.mocked(listEvents)
230
+ .mockRejectedValueOnce(new Error('Could not load events'))
231
+ .mockResolvedValueOnce({ events: EVENTS, total: 4, nextCursor: null });
232
+ renderPage();
233
+ const row = await screen.findByRole('button', { name: /Claude/, expanded: false });
234
+ // Nothing to control yet: the panel is mounted on the first open.
235
+ expect(row).not.toHaveAttribute('aria-controls');
236
+
237
+ await userEvent.click(row);
238
+ expect(row).toHaveAttribute('aria-controls', expect.stringContaining('c-claude'));
239
+ await waitFor(() => expect(screen.getByRole('alert')).toHaveTextContent('Could not load events'));
240
+
241
+ // A collapse keeps the panel, so the failure would otherwise be permanent.
242
+ await userEvent.click(row);
243
+ await userEvent.click(row);
244
+ await userEvent.click(screen.getByRole('button', { name: 'Try again' }));
245
+ await waitFor(() => expect(screen.getByText('grep')).toBeInTheDocument());
246
+ expect(listEvents).toHaveBeenCalledTimes(2);
247
+ });
248
+
249
+ it('loads older events through the cursor', async () => {
250
+ vi.mocked(listPrincipals).mockResolvedValue([ALICE_CLAUDE]);
251
+ vi.mocked(listEvents)
252
+ .mockResolvedValueOnce({ events: EVENTS.slice(0, 2), total: 4, nextCursor: 'cur-2' })
253
+ .mockResolvedValueOnce({ events: EVENTS.slice(2), total: 4, nextCursor: null });
254
+ renderPage();
255
+ await userEvent.click(await screen.findByRole('button', { name: /Claude/, expanded: false }));
256
+ await waitFor(() => expect(screen.getByText(/Showing 2 of 4 events/)).toBeInTheDocument());
257
+
258
+ await userEvent.click(screen.getByRole('button', { name: 'Load older events' }));
259
+ await waitFor(() => expect(screen.getByText(/Showing 4 of 4 events/)).toBeInTheDocument());
260
+ expect(listEvents).toHaveBeenLastCalledWith('agent', 'c-claude', { before: 'cur-2', limit: 50 });
261
+ expect(screen.queryByRole('button', { name: 'Load older events' })).not.toBeInTheDocument();
262
+ });
263
+
264
+ it('revokes an agent after confirmation and marks the row at once', async () => {
265
+ vi.mocked(listPrincipals).mockResolvedValue([ALICE_CLAUDE]);
266
+ renderPage();
267
+ await userEvent.click(await screen.findByRole('button', { name: 'Revoke access for Claude (alice@example.com)' }));
268
+
269
+ const dialog = screen.getByRole('dialog');
270
+ expect(within(dialog).getByText(/Every token it holds stops working now/)).toBeInTheDocument();
271
+ // The reload after the revoke sees the server's view of it.
272
+ vi.mocked(listPrincipals).mockResolvedValue([{ ...ALICE_CLAUDE, revokedAt: NOW, revokedBy: 'owner' }]);
273
+ await userEvent.click(within(dialog).getByRole('button', { name: 'Revoke access' }));
274
+
275
+ await waitFor(() => expect(revokeAgent).toHaveBeenCalledWith('c-claude'));
276
+ expect(revokeKey).not.toHaveBeenCalled();
277
+ // Revoked rows hide by default; the toggle now offers them.
278
+ await userEvent.click(await screen.findByRole('checkbox', { name: 'Show revoked' }));
279
+ expect(screen.getByText('Disconnected by owner')).toBeInTheDocument();
280
+ expect(screen.queryByRole('button', { name: /Revoke access for Claude/ })).not.toBeInTheDocument();
281
+ });
282
+
283
+ it("revokes someone else's key as an admin, marked as an admin's doing", async () => {
284
+ vi.mocked(listPrincipals).mockResolvedValue([BOB_LINK]);
285
+ renderPage({ isAdmin: true });
286
+ await userEvent.click(await screen.findByRole('button', { name: 'Revoke key for Claude (bob@example.com)' }));
287
+ vi.mocked(listPrincipals).mockResolvedValue([{ ...BOB_LINK, revokedAt: NOW, revokedBy: 'admin' }]);
288
+ await userEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Revoke key' }));
289
+
290
+ await waitFor(() => expect(revokeKey).toHaveBeenCalledWith('k-link'));
291
+ await userEvent.click(await screen.findByRole('checkbox', { name: 'Show revoked' }));
292
+ expect(screen.getByText('Revoked by an admin')).toBeInTheDocument();
293
+ });
294
+
295
+ it('keeps the rows and shows the error when a revoke fails', async () => {
296
+ vi.mocked(listPrincipals).mockResolvedValue([ALICE_CI]);
297
+ vi.mocked(revokeKey).mockRejectedValue(new Error('Could not revoke this key'));
298
+ renderPage();
299
+ await userEvent.click(await screen.findByRole('button', { name: 'Revoke key for CI pipeline (alice@example.com)' }));
300
+ await userEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Revoke key' }));
301
+
302
+ await waitFor(() => expect(screen.getByRole('alert')).toHaveTextContent('Could not revoke this key'));
303
+ expect(screen.getByRole('button', { name: 'Revoke key for CI pipeline (alice@example.com)' })).toBeInTheDocument();
304
+ });
305
+
306
+ it('shows the load error instead of an empty log when the list cannot be fetched', async () => {
307
+ vi.mocked(listPrincipals).mockRejectedValue(new Error('Could not load the audit log'));
308
+ renderPage();
309
+ await waitFor(() => expect(screen.getByRole('alert')).toHaveTextContent('Could not load the audit log'));
310
+ expect(screen.queryByText(/Nothing connected/)).not.toBeInTheDocument();
311
+ });
312
+ });