@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
@@ -17,6 +17,7 @@
17
17
  * rule the browser would get is the rule this test gets.
18
18
  */
19
19
  import { describe, it, expect, beforeAll, beforeEach, afterAll } from 'vitest';
20
+ import type { ReactNode } from 'react';
20
21
  import { render, screen } from '@testing-library/react';
21
22
  import { readFileSync } from 'node:fs';
22
23
  import { createRequire } from 'node:module';
@@ -115,6 +116,31 @@ function flattenCascadeLayers(css: string): string {
115
116
  }
116
117
  }
117
118
 
119
+ /**
120
+ * Every class a tree actually renders, harvested off the DOM.
121
+ *
122
+ * The candidate list has to hold every utility these assertions depend on —
123
+ * Tailwind emits no rule for a class nobody names — and the band wears more
124
+ * than `HEADER_BAND`. The sidebar's row adds `empty:hidden`, which is
125
+ * `SidebarFrame`'s own and the whole of the "a header that draws nothing
126
+ * reserves no band" rule; a list that named it by hand would keep compiling it
127
+ * long after the frame stopped using it, and every assertion below it would
128
+ * pass against a stylesheet describing an app that no longer exists.
129
+ *
130
+ * So the list is READ off a render instead. Rendered here before the
131
+ * stylesheet is in the document, which is fine: this only wants the class
132
+ * attributes, and unmounts before any test runs.
133
+ */
134
+ function classesRendered(tree: ReactNode): string[] {
135
+ const { container, unmount } = render(tree);
136
+ const found = new Set<string>();
137
+ for (const element of container.querySelectorAll<HTMLElement>('*')) {
138
+ for (const cls of element.classList) found.add(cls);
139
+ }
140
+ unmount();
141
+ return [...found];
142
+ }
143
+
118
144
  /**
119
145
  * `--spacing-header` as the BUILD resolves it, read back out of the compiled
120
146
  * CSS. Not out of `tokens.css`: a value a test parses from source is a value
@@ -151,15 +177,27 @@ let stylesheet: HTMLStyleElement;
151
177
  beforeAll(async () => {
152
178
  // The candidates are the band's own classes, read off the constant the app
153
179
  // renders — `flex h-header flex-none items-center` today, whatever it says
154
- // tomorrow. `HEADER_COLUMN_TOP` rides along because the column's offset is
155
- // the other half of the seam.
156
- const css = await compileAppStylesheet(`${HEADER_BAND} ${HEADER_COLUMN_TOP}`.split(/\s+/));
180
+ // tomorrow — plus every class a real `SidebarFrame` puts on the row, which
181
+ // is where `empty:hidden` comes from. `HEADER_COLUMN_TOP` rides along
182
+ // because the column's offset is the other half of the seam.
183
+ const css = await compileAppStylesheet([
184
+ ...`${HEADER_BAND} ${HEADER_COLUMN_TOP}`.split(/\s+/),
185
+ ...classesRendered(
186
+ <SidebarFrame label="File explorer" header={<div>Connect your agent</div>}>
187
+ <nav>tree</nav>
188
+ </SidebarFrame>,
189
+ ),
190
+ ]);
157
191
 
158
192
  // The compiled output has to CONTAIN the height utility, or the rest of
159
193
  // this file is measuring an element with no rule behind it and every
160
194
  // `auto === auto` comparison passes. This is the assertion that catches a
161
195
  // Tailwind or configuration regression rather than a markup one.
162
196
  expect(css).toMatch(/\.h-header\s*\{[^}]*height:\s*var\(--spacing-header\)/);
197
+ // Same for the rule that TAKES the band away again. Without it, the
198
+ // empty-header case below would read an element with no display rule on it
199
+ // and call the band gone on the strength of a default.
200
+ expect(css).toMatch(/:empty\s*\{[^}]*display:\s*none/);
163
201
  headerHeight = tokenHeightIn(css);
164
202
 
165
203
  stylesheet = document.createElement('style');
@@ -242,6 +280,16 @@ const heightOf = (testId: string) =>
242
280
  /** The column a band opens — the element the band is the first row of. */
243
281
  const columnOf = (testId: string) => screen.getByTestId(testId).parentElement!;
244
282
 
283
+ /**
284
+ * A column's top-padding classes — what decides where its first row starts.
285
+ *
286
+ * Compared between the two columns rather than against a literal: the number
287
+ * lives in `HEADER_COLUMN_TOP` and moving it is allowed, moving it on one
288
+ * side only is the bug.
289
+ */
290
+ const offsetClassesOf = (column: Element) =>
291
+ [...column.classList].filter((cls) => cls.startsWith('pt-'));
292
+
245
293
  /**
246
294
  * Everything drawn above a band inside its own column.
247
295
  *
@@ -301,19 +349,72 @@ describe('the sidebar header row and the page title bar', () => {
301
349
  }
302
350
  });
303
351
 
304
- it('reserves the row for a header that draws nothing', () => {
352
+ it('spends the row on a header that draws', () => {
353
+ render(
354
+ <SidebarFrame label="File explorer" header={<div>Connect your agent</div>}>
355
+ <nav>tree</nav>
356
+ </SidebarFrame>,
357
+ );
358
+ const band = screen.getByTestId(SIDEBAR_HEADER_TESTID);
359
+ expect(band).not.toBeEmptyDOMElement();
360
+ expect(window.getComputedStyle(band).display).not.toBe('none');
361
+ expect(heightOf(SIDEBAR_HEADER_TESTID)).toBe(headerHeight);
362
+ });
363
+
364
+ it('reserves no row for a header that draws nothing', () => {
305
365
  // Knowledge and the Library both pass the connect-your-agent pill, which
306
- // renders NOTHING once onboarding is done. If the row collapsed with it,
307
- // the page's title bar would be left lined up against a nav that had
308
- // moved a band's height up — the seam would break for exactly the people
309
- // who have finished setting the product up.
366
+ // draws NOTHING once onboarding is done. The band used to stay anyway, on
367
+ // the theory that a row coming and going would break the seam — and what
368
+ // it actually did was open the nav a band's height BELOW the page title
369
+ // beside it, for everyone who had finished setting the product up.
370
+ //
371
+ // Measured against the real sheet, not read off the class list: what this
372
+ // has to be true of is the box the browser lays out, and a `hidden`
373
+ // variant that Tailwind stopped emitting would leave the class in place
374
+ // and the strip on the screen.
310
375
  const DismissedPill = () => null;
311
376
  render(
312
377
  <SidebarFrame label="File explorer" header={<DismissedPill />}>
313
378
  <nav>tree</nav>
314
379
  </SidebarFrame>,
315
380
  );
316
- expect(heightOf(SIDEBAR_HEADER_TESTID)).toBe(headerHeight);
381
+ const band = screen.getByTestId(SIDEBAR_HEADER_TESTID);
382
+ expect(band).toBeEmptyDOMElement();
383
+ expect(window.getComputedStyle(band).display).toBe('none');
384
+ });
385
+
386
+ it('opens the nav on the page title band once the header is done drawing', () => {
387
+ // The consequence, in the seam's own terms: with the band gone, the
388
+ // sidebar's first ROW is the first thing in the sidebar's column, and the
389
+ // page's title bar is the first thing in the page's. Both columns open on
390
+ // `HEADER_COLUMN_TOP`, so both start at the same offset — which is AC1's
391
+ // "their top edges align", as structurally as a DOM with no layout engine
392
+ // can put it.
393
+ const DismissedPill = () => null;
394
+ render(
395
+ <>
396
+ <SidebarFrame label="File explorer" header={<DismissedPill />}>
397
+ <nav>Company Context</nav>
398
+ </SidebarFrame>
399
+ <KbDocumentShell header={<PageHeader />}>
400
+ <p>The document</p>
401
+ </KbDocumentShell>
402
+ </>,
403
+ );
404
+ const nav = screen.getByText('Company Context');
405
+ const titleBar = screen.getByTestId(PAGE_HEADER_TESTID);
406
+ const offset = offsetClassesOf(nav.parentElement!);
407
+ // Non-empty first: two columns that have both lost their offset agree
408
+ // about nothing, and an `[] === []` pass is exactly how this assertion
409
+ // would stop noticing.
410
+ expect(offset).toEqual(HEADER_COLUMN_TOP.split(/\s+/));
411
+ expect(offsetClassesOf(titleBar.parentElement!)).toEqual(offset);
412
+ // And nothing between the sidebar column's top edge and that first row
413
+ // takes any height: the collapsed band is all there is, and it is gone.
414
+ for (let node = nav.previousElementSibling; node; node = node.previousElementSibling) {
415
+ expect(window.getComputedStyle(node).display).toBe('none');
416
+ }
417
+ expect(drawnAbove(PAGE_HEADER_TESTID)).toEqual([]);
317
418
  });
318
419
 
319
420
  it('renders no band for a surface that declares no header', () => {
@@ -365,16 +365,33 @@ export function SidebarFrame({
365
365
  the seam under the toolbar; the page's title bar is the right
366
366
  half.
367
367
 
368
- Keyed on whether the surface DECLARED a header, not on whether
369
- that header drew anything. Knowledge and the Library both pass
370
- the connect-your-agent pill, which renders nothing once
371
- onboarding is done; if the row went with it, finishing setup
372
- would pull the nav up by the band's height and leave the page's
373
- title bar aligned to nothing. Settings passes no header at all
374
- and gets no band, because it has no title bar on the other side
375
- of the seam to hold a line with. */}
368
+ The band is spent on a header that DRAWS, and on nothing else.
369
+ It used to be keyed on whether the surface DECLARED one, on the
370
+ theory that a row coming and going with the connect-your-agent
371
+ pill would pull the nav up by the band's height the moment
372
+ onboarding finished. It does pull it up — onto the page title's
373
+ own band, which is where the nav's first row belongs. What the
374
+ old rule actually bought was an empty 48px strip above "Company
375
+ Context" and above the "Everything" lens, for everyone who had
376
+ finished setting the product up.
377
+
378
+ Settings passes no header at all and gets no band, because it
379
+ has no title bar on the other side of the seam to hold a line
380
+ with. Knowledge and the Library pass a pill that empties itself,
381
+ and get the band back the day it has something to say.
382
+
383
+ `empty:hidden` rather than a check in React, for the same reason
384
+ the footer group below uses it: an element that renders null is
385
+ still an element, so "did this header draw anything" is a
386
+ question only the DOM can answer. Which makes it the header's
387
+ business to leave NOTHING here when it has nothing — see
388
+ `ConnectAgentPill`, whose dismissal receipt goes to the body
389
+ rather than into this row. */}
376
390
  {header !== undefined && (
377
- <div data-testid={SIDEBAR_HEADER_TESTID} className={cn(HEADER_BAND, 'w-full')}>
391
+ <div
392
+ data-testid={SIDEBAR_HEADER_TESTID}
393
+ className={cn(HEADER_BAND, 'w-full empty:hidden')}
394
+ >
378
395
  {header}
379
396
  </div>
380
397
  )}
@@ -80,6 +80,7 @@ vi.mock('../utils/navigate-external', () => ({ navigateExternal: vi.fn() }));
80
80
 
81
81
  import { ToolPage } from '../components/tool-page/ToolPage';
82
82
  import { DeleteToolDialog } from '../components/tool-page/DeleteToolDialog';
83
+ import { expectMenuAtTheEndOfTheTitleRow } from './title-row-actions';
83
84
 
84
85
  const TOOL: ToolSecrets = {
85
86
  slug: 'heyreach',
@@ -196,6 +197,16 @@ beforeEach(() => {
196
197
  });
197
198
 
198
199
  describe('who is offered Delete', () => {
200
+ /**
201
+ * The menu's PLACE does not depend on what is in it. The same assertion
202
+ * `ToolPage.test.tsx` makes for a reader, here for the one caller that
203
+ * really owns the plugin — the spec's "with and without Delete".
204
+ */
205
+ it('keeps the ⋯ at the right end of the title row for the owner too', async () => {
206
+ expect(await openMenu()).toBeInTheDocument();
207
+ expectMenuAtTheEndOfTheTitleRow();
208
+ });
209
+
199
210
  it('offers it to an owner of the plugin holding the tool', async () => {
200
211
  expect(await openMenu()).toBeInTheDocument();
201
212
  });
@@ -32,6 +32,9 @@ vi.mock('../services/plugins.api', () => ({
32
32
  listJoinRequests: pluginsMock.listJoinRequests,
33
33
  reconcileJoinRequest: vi.fn(),
34
34
  requestPluginAccess: vi.fn(),
35
+ // The plugin page repairs its links on open for a manager; these fixtures
36
+ // are members, so it never fires — but the module still has to export it.
37
+ repairPluginLinks: vi.fn().mockResolvedValue({ repaired: [], skipped: [] }),
35
38
  AlreadyReadableError: class AlreadyReadableError extends Error {},
36
39
  }));
37
40
 
@@ -0,0 +1,146 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { render, screen, within } from '@testing-library/react';
3
+ import { Badge } from '../../../shared/components';
4
+ import { PluginIndexRow } from '../components/PluginIndexRow';
5
+
6
+ /**
7
+ * A plugin row's RIGHT EDGE — everything that is not the name.
8
+ *
9
+ * The bug: the `Owner` chip travelled with the name, through
10
+ * `NameWithBadges`, and the counts travelled with `ListRow`'s `meta`. Two
11
+ * groups, two lines, two vertical alignments. On the plugins index every row
12
+ * with a description is two lines tall, so the chip sat up on the name's line
13
+ * on the LEFT while "2 skills · 0 tools" sat centred on the RIGHT, and neither
14
+ * lined up with the other or with the row.
15
+ *
16
+ * The rule now is one line at the edge: chips, counts, state. `ListRow`
17
+ * already owns the group that does it (`ml-auto flex flex-none items-center`),
18
+ * so what these assert is that everything trailing is IN that one group —
19
+ * which is what makes "on one line, right-aligned, centred against the row"
20
+ * true by construction rather than by three components agreeing.
21
+ */
22
+
23
+ /**
24
+ * The row's trailing group: the one element that holds everything at the
25
+ * edge. Found through the counts, which every plugin row has, rather than by
26
+ * a class — the group is `ListRow`'s and its class list is `ListRow`'s to
27
+ * change.
28
+ */
29
+ function trailingGroup(counts: string): HTMLElement {
30
+ return screen.getByText(counts).parentElement as HTMLElement;
31
+ }
32
+
33
+ describe('the trailing controls on a plugin row', () => {
34
+ const COUNTS = '2 skills · 0 tools';
35
+
36
+ it('puts the chip, the counts and the state in ONE group', () => {
37
+ render(
38
+ <PluginIndexRow
39
+ label="Company Handbook"
40
+ badge={<Badge>Owner</Badge>}
41
+ description="Run by Admin"
42
+ meta={COUNTS}
43
+ trailing={<Badge>Locked</Badge>}
44
+ onOpen={vi.fn()}
45
+ />,
46
+ );
47
+
48
+ const group = trailingGroup(COUNTS);
49
+ expect(within(group).getByText('Owner')).toBeInTheDocument();
50
+ expect(within(group).getByText('Locked')).toBeInTheDocument();
51
+ // In reading order: what the plugin is to you, how much is in it, where
52
+ // your access stands.
53
+ expect(
54
+ [...group.children].map((child) => child.textContent),
55
+ ).toEqual(['Owner', COUNTS, 'Locked']);
56
+ });
57
+
58
+ it('holds that group on one centred line, right-aligned', () => {
59
+ render(
60
+ <PluginIndexRow
61
+ label="Company Handbook"
62
+ badge={<Badge>Owner</Badge>}
63
+ description="Run by Admin"
64
+ meta={COUNTS}
65
+ onOpen={vi.fn()}
66
+ />,
67
+ );
68
+
69
+ const group = trailingGroup(COUNTS);
70
+ // `ml-auto` is the right-alignment, `items-center` the centring, and
71
+ // `flex-none` is what stops the group being squeezed into a second line
72
+ // by a long name. No `flex-wrap`: one line is the whole point.
73
+ expect(group.className).toContain('ml-auto');
74
+ expect(group.className).toContain('items-center');
75
+ expect(group.className).toContain('flex-none');
76
+ expect(group.className).not.toContain('flex-wrap');
77
+ // And the row centres it against ITSELF, so the height of the title
78
+ // block is not the group's business.
79
+ const row = group.parentElement as HTMLElement;
80
+ expect(row.className).toContain('items-center');
81
+ });
82
+
83
+ /**
84
+ * The reported case, exactly: "Company Handbook" over "Run by Admin" is a
85
+ * two-line title block, and the pill used to ride the first of those lines.
86
+ */
87
+ it('does not move when the title block is two lines tall', () => {
88
+ const { rerender } = render(
89
+ <PluginIndexRow
90
+ label="Company Handbook"
91
+ badge={<Badge>Owner</Badge>}
92
+ meta={COUNTS}
93
+ onOpen={vi.fn()}
94
+ />,
95
+ );
96
+ const oneLine = trailingGroup(COUNTS);
97
+ expect(within(oneLine).getByText('Owner')).toBeInTheDocument();
98
+ const shape = oneLine.className;
99
+
100
+ rerender(
101
+ <PluginIndexRow
102
+ label="Company Handbook"
103
+ badge={<Badge>Owner</Badge>}
104
+ description="Run by Admin, Olga Ivanova and Juan Perez"
105
+ meta={COUNTS}
106
+ onOpen={vi.fn()}
107
+ />,
108
+ );
109
+ const twoLines = trailingGroup(COUNTS);
110
+ // Same group, same classes, and the chip is still in it: the description
111
+ // grew the title block and changed nothing at the edge.
112
+ expect(twoLines.className).toBe(shape);
113
+ expect(within(twoLines).getByText('Owner')).toBeInTheDocument();
114
+ expect(screen.getByText('Run by Admin, Olga Ivanova and Juan Perez')).toBeInTheDocument();
115
+ });
116
+
117
+ it('keeps the trailing room clear for the menu that rides the same line', () => {
118
+ // The `…` is a SIBLING of the row button, positioned on the row's
119
+ // mid-line — the same line the group is centred on — but it is out of the
120
+ // flex flow, so the row reserves its width rather than letting it paint
121
+ // over the counts.
122
+ render(
123
+ <PluginIndexRow
124
+ label="Company Handbook"
125
+ badge={<Badge>Owner</Badge>}
126
+ meta={COUNTS}
127
+ actions={[{ label: 'Share', icon: null, onSelect: vi.fn() }]}
128
+ onOpen={vi.fn()}
129
+ />,
130
+ );
131
+ const row = trailingGroup(COUNTS).parentElement as HTMLElement;
132
+ expect(row.className).toContain('pr-10');
133
+ // Centred on the row's mid-line, which is the line the group is on.
134
+ const menu = screen.getByRole('button', { name: 'Actions for Company Handbook' });
135
+ expect(menu.className).toContain('top-1/2');
136
+ expect(menu.className).toContain('-translate-y-1/2');
137
+ // …and it really is outside the row, or reserving room for it would be
138
+ // reserving room twice.
139
+ expect(row).not.toContainElement(menu);
140
+ });
141
+
142
+ it('grows no trailing group at all on a row with nothing to put in one', () => {
143
+ render(<PluginIndexRow label="Company Handbook" onOpen={vi.fn()} />);
144
+ expect(screen.queryByText('Owner')).toBeNull();
145
+ });
146
+ });
@@ -12,6 +12,7 @@ import type { LibraryData } from '../hooks/useLibraryData';
12
12
  import type { ToolSecrets } from '../../secrets-vault/services/tool-secrets.api';
13
13
  import type { PluginSummary } from '../services/plugins.api';
14
14
  import { withAuth } from './auth-harness';
15
+ import { expectMenuAtTheEndOfTheTitleRow } from './title-row-actions';
15
16
 
16
17
  /**
17
18
  * The plugin page: which view a caller gets, what the page says about who runs
@@ -30,6 +31,7 @@ const pluginsMock = vi.hoisted(() => ({
30
31
  requestPluginAccess: vi.fn(),
31
32
  unlinkSkill: vi.fn(),
32
33
  renamePlugin: vi.fn(),
34
+ repairPluginLinks: vi.fn(),
33
35
  }));
34
36
  const libApiMock = vi.hoisted(() => ({ removeLibraryItem: vi.fn() }));
35
37
  vi.mock('../services/library.api', async (importOriginal) => ({
@@ -45,6 +47,7 @@ vi.mock('../services/plugins.api', () => ({
45
47
  requestPluginAccess: pluginsMock.requestPluginAccess,
46
48
  unlinkSkill: pluginsMock.unlinkSkill,
47
49
  renamePlugin: pluginsMock.renamePlugin,
50
+ repairPluginLinks: pluginsMock.repairPluginLinks,
48
51
  AlreadyReadableError: class AlreadyReadableError extends Error {},
49
52
  }));
50
53
 
@@ -234,6 +237,9 @@ describe('PluginPage', () => {
234
237
  pluginsMock.reconcileJoinRequest.mockResolvedValue(false);
235
238
  pluginsMock.requestPluginAccess.mockResolvedValue(undefined);
236
239
  pluginsMock.renamePlugin.mockReset();
240
+ // The page-open repair: nothing to do, unless a test says otherwise.
241
+ pluginsMock.repairPluginLinks.mockReset();
242
+ pluginsMock.repairPluginLinks.mockResolvedValue({ repaired: [], skipped: [] });
237
243
  });
238
244
 
239
245
  it('lets a plugin MANAGER remove a skill, behind a confirm that says who loses it', async () => {
@@ -327,6 +333,19 @@ describe('PluginPage', () => {
327
333
  expect(screen.getByTestId('library-card-skill-outreach')).toBeInTheDocument();
328
334
  });
329
335
 
336
+ /**
337
+ * The other half of the shared criterion — see `title-row-actions.ts`. This
338
+ * page is the reference the tool page was brought into line with, so it is
339
+ * the one that must not drift: if this fails, the helper is describing the
340
+ * plugin page's old shape and the tool page has been pinned to it.
341
+ */
342
+ it('carries its ⋯ at the right end of the title row', async () => {
343
+ pluginsMock.listPlugins.mockResolvedValue([gtm({ name: 'gtm', displayName: 'GTM' })]);
344
+ renderPlugin('gtm');
345
+ await screen.findByRole('heading', { name: 'GTM', level: 1 });
346
+ expectMenuAtTheEndOfTheTitleRow();
347
+ });
348
+
330
349
  it('offers Rename plugin to a MANAGER, and moves to the new identity once the rename lands', async () => {
331
350
  pluginsMock.listPlugins.mockResolvedValue([gtm({ name: 'gtm', displayName: 'GTM', canWrite: true })]);
332
351
  pluginsMock.renamePlugin.mockResolvedValue({ name: 'go-to-market', displayName: 'GTM', rewritten: [] });
@@ -554,18 +573,106 @@ describe('PluginPage', () => {
554
573
  });
555
574
 
556
575
  it("warns about a broken link even when the caller cannot read that skill — the server's count wins", async () => {
557
- // The manager the missing grant locks out: the skill is NOT in their
576
+ // The member the missing grant locks out: the skill is NOT in their
558
577
  // catalog, so nothing in `items` could say a link is broken. The summary
559
- // carries the index's own count.
578
+ // carries the index's own count. (A MANAGER never gets this far — their
579
+ // page repairs the links first; see the repair tests below.)
560
580
  dataMock.useLibraryData.mockReturnValue({ ...CATALOG, tools: [connectedTool()] });
561
- pluginsMock.listPlugins.mockResolvedValue([gtm({ canWrite: true, brokenLinks: 2 })]);
581
+ pluginsMock.listPlugins.mockResolvedValue([gtm({ canWrite: false, brokenLinks: 2 })]);
562
582
  renderPlugin('GTM');
563
583
  expect(
564
584
  await screen.findByText(/2 linked skills can't be read by GTM's members: their access rules no longer name them\. Repair the links from the skill pages\./),
565
585
  ).toBeInTheDocument();
586
+ expect(pluginsMock.repairPluginLinks).not.toHaveBeenCalled();
566
587
  expect(screen.queryByText(/integrations? needs? setup/)).not.toBeInTheDocument();
567
588
  });
568
589
 
590
+ it('repairs the plugin\'s links on open for a MANAGER — once, silently, and then reloads', async () => {
591
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, tools: [connectedTool()] });
592
+ pluginsMock.listPlugins.mockResolvedValue([gtm({ canWrite: true, brokenLinks: 1 })]);
593
+ pluginsMock.repairPluginLinks.mockResolvedValue({ repaired: ['Skills/Eng/deploy'], skipped: [] });
594
+ vi.mocked(CATALOG.reload).mockClear();
595
+ renderPlugin('GTM');
596
+
597
+ await waitFor(() => expect(pluginsMock.repairPluginLinks).toHaveBeenCalledWith('GTM'));
598
+ // Once per page open: the reload it asks for must not run it again.
599
+ await waitFor(() => expect(CATALOG.reload).toHaveBeenCalled());
600
+ expect(pluginsMock.repairPluginLinks).toHaveBeenCalledTimes(1);
601
+ // Nothing is said about a repaired link — not a banner, not a toast. The
602
+ // count the summary was serving was taken before the repair wrote.
603
+ expect(screen.queryByText(/can't be read by GTM's members/)).not.toBeInTheDocument();
604
+ });
605
+
606
+ it('names the skill and its editors for a link the manager cannot repair', async () => {
607
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, tools: [connectedTool()] });
608
+ pluginsMock.listPlugins.mockResolvedValue([gtm({ canWrite: true, brokenLinks: 1 })]);
609
+ pluginsMock.repairPluginLinks.mockResolvedValue({
610
+ repaired: [],
611
+ skipped: [
612
+ {
613
+ root: 'Skills/Eng/deploy',
614
+ reason: 'needs-skill-write',
615
+ skills: [{ path: 'Skills/Eng/deploy', name: 'deploy' }],
616
+ editors: { roles: ['Eng'], users: [{ name: 'Eve', email: 'eve@x.io' }] },
617
+ },
618
+ ],
619
+ });
620
+ vi.mocked(CATALOG.reload).mockClear();
621
+ renderPlugin('GTM');
622
+
623
+ const banner = await screen.findByText(
624
+ "deploy can't be read by GTM's members. Eng and Eve can repair the link from the skill page.",
625
+ );
626
+ expect(banner.closest('[role="status"]')).toHaveClass('bg-urgent-soft');
627
+ // The count-shaped sentence is gone: this one names what is actually left.
628
+ expect(screen.queryByText(/access rules no longer name them/)).not.toBeInTheDocument();
629
+ // Nothing was written, so nothing is reloaded.
630
+ expect(CATALOG.reload).not.toHaveBeenCalled();
631
+ });
632
+
633
+ it('says a denied link is denied, not merely unrepaired — Repair would write nothing', async () => {
634
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, tools: [connectedTool()] });
635
+ pluginsMock.listPlugins.mockResolvedValue([gtm({ canWrite: true, brokenLinks: 1 })]);
636
+ pluginsMock.repairPluginLinks.mockResolvedValue({
637
+ repaired: [],
638
+ skipped: [
639
+ {
640
+ root: 'Skills/Eng/deploy',
641
+ reason: 'denied',
642
+ skills: [{ path: 'Skills/Eng/deploy', name: 'deploy' }],
643
+ editors: { roles: [], users: [{ name: 'Mia', email: 'mia@x.io' }] },
644
+ },
645
+ ],
646
+ });
647
+ vi.mocked(CATALOG.reload).mockClear();
648
+ renderPlugin('GTM');
649
+
650
+ const banner = await screen.findByText(
651
+ "deploy is denied to GTM's members in its access rules. Mia can change that from the skill page.",
652
+ );
653
+ expect(banner.closest('[role="status"]')).toHaveClass('bg-urgent-soft');
654
+ expect(CATALOG.reload).not.toHaveBeenCalled();
655
+ });
656
+
657
+ it('asks for no repair on a plugin whose links live in an external format', async () => {
658
+ pluginsMock.listPlugins.mockResolvedValue([
659
+ gtm({ canWrite: true, linksAreManaged: false, brokenLinks: 0 }),
660
+ ]);
661
+ renderPlugin('GTM');
662
+ await screen.findByRole('heading', { name: 'GTM', level: 1 });
663
+ expect(pluginsMock.repairPluginLinks).not.toHaveBeenCalled();
664
+ });
665
+
666
+ it('falls back to the served count when the repair itself could not be asked for', async () => {
667
+ dataMock.useLibraryData.mockReturnValue({ ...CATALOG, tools: [connectedTool()] });
668
+ pluginsMock.listPlugins.mockResolvedValue([gtm({ canWrite: true, brokenLinks: 1 })]);
669
+ pluginsMock.repairPluginLinks.mockRejectedValue(new Error('offline'));
670
+ renderPlugin('GTM');
671
+ expect(
672
+ await screen.findByText(/1 linked skill can't be read by GTM's members/),
673
+ ).toBeInTheDocument();
674
+ });
675
+
569
676
  it('pluralises the attention banner', async () => {
570
677
  dataMock.useLibraryData.mockReturnValue({
571
678
  ...CATALOG,
@@ -61,6 +61,7 @@ vi.mock('../utils/navigate-external', () => ({ navigateExternal: vi.fn() }));
61
61
 
62
62
  import { ToolPage } from '../components/tool-page/ToolPage';
63
63
  import { NAME_MIN_WIDTH } from '../components/NameWithBadges';
64
+ import { expectMenuAtTheEndOfTheTitleRow } from './title-row-actions';
64
65
  import { TOOL_CREDENTIALS_STALE_EVENT } from '../../../core/events';
65
66
 
66
67
  const GITHUB: ToolSecrets = {
@@ -214,6 +215,25 @@ describe('ToolPage: frame', () => {
214
215
  expect(row.className).toContain('overflow-hidden');
215
216
  });
216
217
 
218
+ /**
219
+ * The `⋯` belongs at the right end of the title row, where the plugin page
220
+ * and the skill page put their trailing controls. It used to be the last
221
+ * child of this page's `<header>` — below the description, on a line of its
222
+ * own under the back link, left-aligned — so the one gesture the three item
223
+ * pages share was in a different place on one of them.
224
+ *
225
+ * Asserted through the shared helper, which `PluginPage.test.tsx` calls
226
+ * too: the criterion is a comparison, so it is written once.
227
+ */
228
+ // The owner's case — the same menu with `Delete tool` in it — is asserted
229
+ // in `DeleteToolDialog.test.tsx`, which is the file that can actually own
230
+ // the plugin holding this tool.
231
+ it('puts the ⋯ at the right end of the title row, where the plugin page has it', async () => {
232
+ renderPage();
233
+ await screen.findByRole('heading', { name: 'heyreach', level: 1 });
234
+ expectMenuAtTheEndOfTheTitleRow();
235
+ });
236
+
217
237
  it('shows no kicker for a legacy ungrouped path either', async () => {
218
238
  secretsMock.listToolSecrets.mockResolvedValue([
219
239
  { ...GITHUB, slug: 'slack', name: 'slack', path: 'Tools/slack.tool' },
@@ -226,7 +226,17 @@ describe('LibraryCard: the name keeps its width', () => {
226
226
  });
227
227
 
228
228
  describe('PluginIndexRow: the same rule, one line tall', () => {
229
- it('holds a long plugin name to the floor beside its chips', () => {
229
+ /**
230
+ * The row is the ONE caller that keeps the name and hands the badges back.
231
+ *
232
+ * A card's chips sit beside its name and drop under it when the two stop
233
+ * fitting, and `NAME_MIN_WIDTH` is the floor that decides when. An index
234
+ * row has somewhere better to put them — its own right edge, beside the
235
+ * counts — so the name never competes with a chip and is never given a
236
+ * floor to defend itself with. A floor here would be a claim on space with
237
+ * nothing left on the line to give it back.
238
+ */
239
+ it('gives the name the whole title line, chips or no chips', () => {
230
240
  render(
231
241
  <PluginIndexRow
232
242
  label={LONG_NAME}
@@ -238,8 +248,9 @@ describe('PluginIndexRow: the same rule, one line tall', () => {
238
248
 
239
249
  const name = screen.getByTitle(LONG_NAME);
240
250
  expect(name).toHaveTextContent(LONG_NAME);
241
- expect(name.className).toContain(NAME_MIN_WIDTH);
242
- expect(name.parentElement!.className).toContain('flex-wrap');
251
+ expect(name.className).not.toContain(NAME_MIN_WIDTH);
252
+ // And the chip is not on that line at all — it went to the row's edge.
253
+ expect(name.parentElement).not.toContainElement(screen.getByText('Owner'));
243
254
  });
244
255
 
245
256
  it('is laid out in a track that can actually run short', () => {
@@ -265,6 +276,8 @@ describe('PluginIndexRow: the same rule, one line tall', () => {
265
276
  it('says the whole name on a row that carries no chip at all', () => {
266
277
  // The row used to pass its label through as a bare string, so a plugin
267
278
  // whose name the row had to truncate had nowhere to finish saying it.
279
+ // `NameWithBadges` is still what gives it the `title`, which is the only
280
+ // reason the row still goes through it now that the chips have left.
268
281
  render(<PluginIndexRow label={LONG_NAME} meta="4 skills · 2 tools" onOpen={vi.fn()} />);
269
282
  const name = screen.getByTitle(LONG_NAME);
270
283
  expect(name).toHaveTextContent(LONG_NAME);