@bevel-software/platform-core-frontend 0.33.0 → 0.35.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.
- package/package.json +2 -2
- package/src/lib/__tests__/api.test.ts +28 -1
- package/src/lib/api.ts +4 -2
- package/src/modules/access/__tests__/ManageAccessDialog.add-row-picking.test.tsx +53 -1
- package/src/modules/access/api.ts +27 -8
- package/src/modules/access/components/ManageAccessDialog.tsx +7 -7
- package/src/modules/access/index.ts +1 -1
- package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +51 -0
- package/src/modules/admin/components/DirectoryGroupsPage.tsx +42 -5
- package/src/modules/admin/index.ts +1 -1
- package/src/modules/admin/services/groups.api.ts +11 -1
- package/src/modules/agents/__tests__/useConnectAsChoice.test.ts +56 -0
- package/src/modules/agents/components/ConnectAsChoice.tsx +88 -0
- package/src/modules/agents/connect-as.ts +15 -0
- package/src/modules/agents/index.ts +5 -0
- package/src/modules/agents/services/agent-choices.api.ts +39 -0
- package/src/modules/agents/useConnectAsChoice.ts +66 -0
- package/src/modules/audit/__tests__/AuditLogPage.test.tsx +16 -2
- package/src/modules/audit/components/AuditLogPage.tsx +11 -0
- package/src/modules/audit/services/audit.api.ts +5 -0
- package/src/modules/auth/__tests__/AccountPage.test.tsx +21 -0
- package/src/modules/auth/__tests__/account.api.test.ts +69 -0
- package/src/modules/auth/components/AccountPage.tsx +8 -2
- package/src/modules/auth/index.ts +1 -1
- package/src/modules/auth/services/account.api.ts +18 -2
- package/src/modules/git/__tests__/BranchSwitcher.test.tsx +0 -14
- package/src/modules/git/__tests__/git.api.test.ts +2 -2
- package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +1 -1
- package/src/modules/library/__tests__/SkillPage.test.tsx +229 -24
- package/src/modules/library/__tests__/ToolVarRow.test.tsx +51 -5
- package/src/modules/library/components/skill-page/SkillFilePane.tsx +57 -9
- package/src/modules/library/components/skill-page/SkillPage.tsx +65 -25
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +22 -14
- package/src/modules/review/components/MarkdownDiffViewer.tsx +23 -1
- package/src/modules/review/components/ReviewPanel.tsx +8 -2
- package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +31 -0
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +79 -16
- package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +122 -2
- package/src/modules/secrets-vault/services/connect.api.ts +20 -5
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +45 -4
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +127 -12
- package/src/modules/toolbar/services/external-api-keys.api.ts +5 -2
- package/src/modules/workspace/components/FileViewer.tsx +1 -1
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +58 -8
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +40 -7
- package/src/modules/workspace/components/renderers/KbAppLink.tsx +56 -0
- package/src/modules/workspace/components/renderers/KbMarkdownView.tsx +30 -10
- package/src/modules/workspace/components/renderers/MarkdownRenderer.tsx +37 -40
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.links.test.tsx +185 -0
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.sectionReclick.test.tsx +88 -0
- package/src/modules/workspace/components/renderers/__tests__/MarkdownRenderer.test.tsx +199 -29
- package/src/modules/workspace/components/renderers/__tests__/bridgeHarness.ts +37 -4
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +59 -0
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +15 -1
- package/src/modules/workspace/components/renderers/__tests__/liveDataReferencePage.test.ts +397 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +48 -15
- package/src/modules/workspace/components/renderers/htmlToolBridge.ts +19 -0
- package/src/modules/workspace/components/renderers/kbMarkdownPipeline.tsx +35 -28
- package/src/modules/workspace/components/renderers/scrollToHeading.ts +35 -0
- package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +6 -0
- package/src/modules/workspace/hooks/useLinksOut.ts +12 -6
- package/src/modules/workspace/index.ts +21 -2
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +262 -25
- package/src/modules/workspace/routing/kb-routes.ts +221 -53
- package/src/modules/workspace/utils/__tests__/treeConfirm.test.ts +32 -48
- package/src/modules/workspace/utils/fileTree.ts +1 -1
- package/src/modules/workspace/utils/treeConfirm.ts +24 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bevel-software/platform-core-frontend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.35.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.
|
|
48
|
+
"@bevel-software/platform-shared": "0.35.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@modelcontextprotocol/client": "^2.3.1",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
2
|
|
|
3
|
-
import { authFetch, API_UNREACHABLE_EVENT } from '../api';
|
|
3
|
+
import { authFetch, API_UNREACHABLE_EVENT, getToken, setToken } from '../api';
|
|
4
4
|
|
|
5
5
|
/** Counts API_UNREACHABLE_EVENT dispatches for the span of one test. */
|
|
6
6
|
function watchUnreachable(): { seen: () => number; stop: () => void } {
|
|
@@ -131,3 +131,30 @@ describe('authFetch application-level responses', () => {
|
|
|
131
131
|
expect(watcher.seen()).toBe(1);
|
|
132
132
|
});
|
|
133
133
|
});
|
|
134
|
+
|
|
135
|
+
describe('authFetch on a 401', () => {
|
|
136
|
+
beforeEach(() => {
|
|
137
|
+
vi.restoreAllMocks();
|
|
138
|
+
localStorage.clear();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('clears the token the request carried', async () => {
|
|
142
|
+
setToken('old');
|
|
143
|
+
vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(new Response('', { status: 401 }));
|
|
144
|
+
await authFetch('/api/me');
|
|
145
|
+
expect(getToken()).toBeNull();
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('keeps a replacement stored while the refused request was in flight', async () => {
|
|
149
|
+
// A password change hands back a new token while requests sent with the
|
|
150
|
+
// old one are still out; their 401s arrive after it is stored.
|
|
151
|
+
setToken('old');
|
|
152
|
+
let answer: (r: Response) => void = () => {};
|
|
153
|
+
vi.spyOn(globalThis, 'fetch').mockReturnValueOnce(new Promise<Response>((resolve) => { answer = resolve; }));
|
|
154
|
+
const inFlight = authFetch('/api/me');
|
|
155
|
+
setToken('replacement');
|
|
156
|
+
answer(new Response('', { status: 401 }));
|
|
157
|
+
await inFlight;
|
|
158
|
+
expect(getToken()).toBe('replacement');
|
|
159
|
+
});
|
|
160
|
+
});
|
package/src/lib/api.ts
CHANGED
|
@@ -114,7 +114,9 @@ export interface AuthFetchOptions {
|
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
116
|
* Fetch wrapper that injects the Authorization header from localStorage.
|
|
117
|
-
* On 401 responses, clears the stored token
|
|
117
|
+
* On 401 responses, clears the stored token — but only if it is still the one
|
|
118
|
+
* this request carried: a password change stores a replacement while older
|
|
119
|
+
* requests are in flight, and their 401s must not sign the changer out.
|
|
118
120
|
*/
|
|
119
121
|
export async function authFetch(
|
|
120
122
|
input: RequestInfo | URL,
|
|
@@ -141,7 +143,7 @@ export async function authFetch(
|
|
|
141
143
|
signalUnreachable();
|
|
142
144
|
}
|
|
143
145
|
|
|
144
|
-
if (response.status === 401) {
|
|
146
|
+
if (response.status === 401 && getToken() === token) {
|
|
145
147
|
clearToken();
|
|
146
148
|
}
|
|
147
149
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import { render, screen, within } from '@testing-library/react';
|
|
2
|
+
import { render, screen, waitFor, within } from '@testing-library/react';
|
|
3
3
|
import userEvent from '@testing-library/user-event';
|
|
4
4
|
import type { FileTreeEntry } from '@bevel-software/platform-shared';
|
|
5
5
|
import type { AccessResponse } from '../api';
|
|
@@ -139,3 +139,55 @@ describe('ManageAccessDialog add row: picking several in a row', () => {
|
|
|
139
139
|
expect(screen.getAllByRole('button', { name: /GTM Team/ })).toHaveLength(1); // the chip's Remove
|
|
140
140
|
});
|
|
141
141
|
});
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A TYPED NAME SHARED BY A ROLE AND A GROUP. A bare name in an access rule
|
|
145
|
+
* means the role when one exists, so Enter on an exact typed match picks the
|
|
146
|
+
* role; the group of the same name is still reachable from its own row.
|
|
147
|
+
*/
|
|
148
|
+
describe('ManageAccessDialog add row: Enter on a name shared by a role and a group', () => {
|
|
149
|
+
async function typeAndShare(name: string): Promise<void> {
|
|
150
|
+
const user = userEvent.setup();
|
|
151
|
+
render(<ManageAccessDialog entry={ENTRY} onClose={() => {}} />);
|
|
152
|
+
const field = await screen.findByPlaceholderText(FIELD);
|
|
153
|
+
await user.type(field, name.toLowerCase());
|
|
154
|
+
// Enter resolves against the loaded suggestions — wait for them.
|
|
155
|
+
await screen.findAllByRole('button', { name: new RegExp(name) });
|
|
156
|
+
await user.keyboard('{Enter}');
|
|
157
|
+
expect(screen.getByRole('button', { name: `Remove ${name}` })).toBeInTheDocument();
|
|
158
|
+
await user.click(screen.getByRole('button', { name: /^share$/i }));
|
|
159
|
+
await waitFor(() => expect(api.grantAccess).toHaveBeenCalled());
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
it('picks the ROLE when both a role and a group are named Admin', async () => {
|
|
163
|
+
api.suggestPrincipals.mockResolvedValue({
|
|
164
|
+
roles: ['Admin'],
|
|
165
|
+
groups: ['Admin'],
|
|
166
|
+
people: [],
|
|
167
|
+
peopleWithheld: false,
|
|
168
|
+
});
|
|
169
|
+
await typeAndShare('Admin');
|
|
170
|
+
expect(api.grantAccess).toHaveBeenCalledWith(
|
|
171
|
+
'ws-1',
|
|
172
|
+
expect.objectContaining({ principal: { kind: 'role', role: 'Admin' } }),
|
|
173
|
+
);
|
|
174
|
+
expect(api.grantAccess).not.toHaveBeenCalledWith(
|
|
175
|
+
'ws-1',
|
|
176
|
+
expect.objectContaining({ principal: { kind: 'group', group: 'Admin' } }),
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('picks the GROUP when no role shares its name', async () => {
|
|
181
|
+
api.suggestPrincipals.mockResolvedValue({
|
|
182
|
+
roles: [],
|
|
183
|
+
groups: ['Admin'],
|
|
184
|
+
people: [],
|
|
185
|
+
peopleWithheld: false,
|
|
186
|
+
});
|
|
187
|
+
await typeAndShare('Admin');
|
|
188
|
+
expect(api.grantAccess).toHaveBeenCalledWith(
|
|
189
|
+
'ws-1',
|
|
190
|
+
expect.objectContaining({ principal: { kind: 'group', group: 'Admin' } }),
|
|
191
|
+
);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
@@ -209,10 +209,9 @@ export function asInheritedError(err: unknown): InheritedRevokeError | null {
|
|
|
209
209
|
/**
|
|
210
210
|
* A grantable principal — a person (by email), a role (an app-defined
|
|
211
211
|
* capability from the registry, or a legacy roles.yaml role), or a group (a
|
|
212
|
-
* people-set from the active group source — IdP-synced or manual).
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
* just sends `kind: 'role'`. The separate kinds exist so the backend
|
|
212
|
+
* people-set from the active group source — IdP-synced or manual). The backend
|
|
213
|
+
* writes groups as explicit `group/<Name>` tokens and roles as `role/<Name>`
|
|
214
|
+
* tokens itself, never a bare name — the dialog just sends the kind. The separate kinds exist so the backend
|
|
216
215
|
* validates each against the right namespace.
|
|
217
216
|
*/
|
|
218
217
|
export type Principal =
|
|
@@ -393,19 +392,39 @@ export interface PathPrincipals {
|
|
|
393
392
|
write: AccessPrincipalRef[];
|
|
394
393
|
}
|
|
395
394
|
|
|
396
|
-
/** One
|
|
395
|
+
/** One principal that loses or gains one verb in a move; a person with no display name is named by their address. */
|
|
396
|
+
export interface HolderChangeRef extends AccessPrincipalRef {
|
|
397
|
+
verb: 'read' | 'write';
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Who loses and who gains opening or editing a file or folder in a move, as
|
|
402
|
+
* the resolver judges each of them on both sides — the one answer the move
|
|
403
|
+
* dialog and the agent's `move_file` both show. Not a diff of the two holder
|
|
404
|
+
* lists: those name grants, so they miss a person the destination denies by
|
|
405
|
+
* name and show a writer leaving a folder everyone reads as losing `read`.
|
|
406
|
+
*/
|
|
407
|
+
export interface HolderChanges {
|
|
408
|
+
lose: HolderChangeRef[];
|
|
409
|
+
gain: HolderChangeRef[];
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/** One file's or folder's holders where it is now and where a move would put it, and who the move costs and serves. */
|
|
397
413
|
export interface ProspectiveAccess {
|
|
398
414
|
before: PathPrincipals;
|
|
399
415
|
after: PathPrincipals;
|
|
416
|
+
changes: HolderChanges;
|
|
400
417
|
}
|
|
401
418
|
|
|
402
419
|
/**
|
|
403
420
|
* Resolve who holds read and write on `relativePath` today and who would hold
|
|
404
421
|
* them once it sits in `toDir` — the destination's folder rules with what the
|
|
405
422
|
* move carries layered on top: a file's own frontmatter, or the `access.md`
|
|
406
|
-
* files inside a folder, counted at the paths they land on
|
|
407
|
-
*
|
|
408
|
-
* the repo root.
|
|
423
|
+
* files inside a folder, counted at the paths they land on — and who loses
|
|
424
|
+
* and who gains in between (`changes`). Both paths are repo-relative
|
|
425
|
+
* (`Knowledge/Foo.md`, `Knowledge/Sales`); `toDir` is `''` for the repo root.
|
|
426
|
+
* The route answers 403 when the caller may not read the file or the
|
|
427
|
+
* destination folder: the dialog then says it could not work the change out.
|
|
409
428
|
*
|
|
410
429
|
* `signal` lets the move dialog give up on it: the answer decorates the
|
|
411
430
|
* confirmation and must never hold it open.
|
|
@@ -373,7 +373,7 @@ function NoAccountNote({ help = NO_ACCOUNT_HELP }: { help?: string }) {
|
|
|
373
373
|
|
|
374
374
|
/**
|
|
375
375
|
* A principal's row/chip identity. Kind is PART of it: a group and a role
|
|
376
|
-
* sharing a name are DIFFERENT principals server-side (
|
|
376
|
+
* sharing a name are DIFFERENT principals server-side (`group/<name>` vs
|
|
377
377
|
* `role/<name>`), so they key — and chip — separately (`g:` vs `r:`). One
|
|
378
378
|
* name picked as both is two chips, and each grants its own kind.
|
|
379
379
|
*/
|
|
@@ -739,7 +739,7 @@ function buildRows(data: AccessResponse | null, myEmail: string): PrincipalRow[]
|
|
|
739
739
|
list.principals ?? list.roles.map((name) => ({ name, kind: 'role' as const }));
|
|
740
740
|
const touchCollective = (c: ResolvedPrincipal): PrincipalRow => {
|
|
741
741
|
// Rows are keyed by KIND + name (`g:`/`r:`/`p:`) — the backend treats a
|
|
742
|
-
//
|
|
742
|
+
// `group/Product` (group) and `role/Product` (role) as DIFFERENT
|
|
743
743
|
// principals, so a group and a role sharing a name are two rows, each
|
|
744
744
|
// mutating its own grant. Collapsing them to one row silently pointed
|
|
745
745
|
// every edit at the group and hid the role's grant entirely. A plugin
|
|
@@ -1258,16 +1258,16 @@ export function ManageAccessDialog({
|
|
|
1258
1258
|
|
|
1259
1259
|
// Resolve the CURRENT typed query into a principal to append as a chip: an
|
|
1260
1260
|
// exact group/role match or a free-typed email. (Suggestion clicks append
|
|
1261
|
-
// directly.)
|
|
1262
|
-
// shared by both
|
|
1263
|
-
// via its own suggestion row.
|
|
1261
|
+
// directly.) Role first — a bare name in an access rule means the role when
|
|
1262
|
+
// one exists, so a typed name shared by both picks what that name means; the
|
|
1263
|
+
// group stays reachable via its own suggestion row.
|
|
1264
1264
|
const addPending: Principal | null = useMemo(() => {
|
|
1265
1265
|
const q = query.trim();
|
|
1266
1266
|
if (!q) return null;
|
|
1267
|
-
const groupHit = suggest?.groups?.find((g) => g.toLowerCase() === q.toLowerCase());
|
|
1268
|
-
if (groupHit) return { kind: 'group', group: groupHit };
|
|
1269
1267
|
const roleHit = suggest?.roles?.find((g) => g.toLowerCase() === q.toLowerCase());
|
|
1270
1268
|
if (roleHit) return { kind: 'role', role: roleHit };
|
|
1269
|
+
const groupHit = suggest?.groups?.find((g) => g.toLowerCase() === q.toLowerCase());
|
|
1270
|
+
if (groupHit) return { kind: 'group', group: groupHit };
|
|
1271
1271
|
if (EMAIL_RE.test(q)) return { kind: 'user', email: q, displayName: q.split('@')[0] };
|
|
1272
1272
|
return null;
|
|
1273
1273
|
}, [query, suggest]);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* layout and free to move. Export what another module needs; nothing more.
|
|
5
5
|
*/
|
|
6
6
|
export { fetchAdmins, fetchFileAccess, fetchFileAccessBatch, fetchProspectiveAccess, parsePluginPrincipalToken, pluginPrincipalLabel, suggestPrincipals } from './api';
|
|
7
|
-
export type { AccessEligible, AccessPrincipalRef, AccessResponse, AdminContact, GrantSources, PathPrincipals, ProspectiveAccess } from './api';
|
|
7
|
+
export type { AccessEligible, AccessPrincipalRef, AccessResponse, AdminContact, GrantSources, HolderChangeRef, HolderChanges, PathPrincipals, ProspectiveAccess } from './api';
|
|
8
8
|
export { useAccessRequests } from './hooks/useAccessRequests';
|
|
9
9
|
export type { AccessRequestsState } from './hooks/useAccessRequests';
|
|
10
10
|
export { formatEligible, useFileAccess } from './hooks/useFileAccess';
|
|
@@ -266,6 +266,26 @@ describe('DirectoryGroupsPage', () => {
|
|
|
266
266
|
await waitFor(() => expect(deleteGroup).toHaveBeenCalledWith('product'));
|
|
267
267
|
});
|
|
268
268
|
|
|
269
|
+
it('the delete confirm counts and names only the rules the roster lists, with no hidden-content line', async () => {
|
|
270
|
+
renderPage();
|
|
271
|
+
await userEvent.click(await screen.findByRole('button', { name: 'Delete Product' }));
|
|
272
|
+
|
|
273
|
+
const dialog = within(screen.getByRole('dialog'));
|
|
274
|
+
expect(dialog.getByText(/1 access rule\b/)).toBeInTheDocument();
|
|
275
|
+
expect(dialog.getByText(/docs\/roadmap\.md/)).toBeInTheDocument();
|
|
276
|
+
expect(dialog.queryByText(/cannot read/)).not.toBeInTheDocument();
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('the delete confirm with no listed rules does not claim nothing is shared — unreadable rules may exist', async () => {
|
|
280
|
+
renderPage();
|
|
281
|
+
await userEvent.click(await screen.findByRole('button', { name: 'Delete Design' }));
|
|
282
|
+
|
|
283
|
+
const dialog = within(screen.getByRole('dialog'));
|
|
284
|
+
expect(dialog.getByText('No access rule you can read references this group.')).toBeInTheDocument();
|
|
285
|
+
expect(dialog.queryByText(/Nothing is shared/)).not.toBeInTheDocument();
|
|
286
|
+
expect(dialog.queryByText(/lose nothing/)).not.toBeInTheDocument();
|
|
287
|
+
});
|
|
288
|
+
|
|
269
289
|
it('idp mode: read-only roster, no mutation controls, membership note shown', async () => {
|
|
270
290
|
vi.mocked(getGroupsRoster).mockResolvedValue(IDP_ROSTER);
|
|
271
291
|
renderPage();
|
|
@@ -346,6 +366,37 @@ describe('DirectoryGroupsPage', () => {
|
|
|
346
366
|
expect(screen.queryByText('Loading…')).not.toBeInTheDocument();
|
|
347
367
|
});
|
|
348
368
|
|
|
369
|
+
it('names every rule whose bare group name resolves to a same-named role, with the group/ spelling', async () => {
|
|
370
|
+
vi.mocked(getGroupsRoster).mockResolvedValue({
|
|
371
|
+
mode: 'idp',
|
|
372
|
+
groups: [
|
|
373
|
+
{
|
|
374
|
+
canonical: 'admin',
|
|
375
|
+
displayName: 'Admin',
|
|
376
|
+
members: ['mallory@example.com'],
|
|
377
|
+
referencedBy: [],
|
|
378
|
+
assignedToRoles: [],
|
|
379
|
+
bareNameResolvesToRole: [{ path: 'Knowledge/Board/access.md', verb: 'read' }],
|
|
380
|
+
},
|
|
381
|
+
...IDP_ROSTER.groups,
|
|
382
|
+
],
|
|
383
|
+
groupsHealth: { ok: true },
|
|
384
|
+
});
|
|
385
|
+
renderPage();
|
|
386
|
+
const report = await screen.findByRole('status');
|
|
387
|
+
expect(report).toHaveTextContent(/name a group the way a role is named/i);
|
|
388
|
+
expect(report).toHaveTextContent('Knowledge/Board/access.md');
|
|
389
|
+
expect(report).toHaveTextContent('read: Admin');
|
|
390
|
+
expect(report).toHaveTextContent('group/Admin');
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
it('shows no bare-name report when no group shares a role name', async () => {
|
|
394
|
+
vi.mocked(getGroupsRoster).mockResolvedValue(MANUAL_ROSTER);
|
|
395
|
+
renderPage();
|
|
396
|
+
await screen.findByText('Product');
|
|
397
|
+
expect(screen.queryByText(/name a group the way a role is named/i)).not.toBeInTheDocument();
|
|
398
|
+
});
|
|
399
|
+
|
|
349
400
|
it('a roster whose groupsHealth is broken banners loudly: file, reason, "not being applied"', async () => {
|
|
350
401
|
// Broken IdP-synced file: the roster still answers 200 (mode stays idp,
|
|
351
402
|
// groups empty) but carries the health marker — resolution is degraded
|
|
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef, useState } from 'react';
|
|
|
2
2
|
import { useSearchParams } from 'react-router-dom';
|
|
3
3
|
import { Check, Loader2, Pencil, Plus, Trash2, X } from 'lucide-react';
|
|
4
4
|
import { PageShell } from '../../../shared/components/PageShell';
|
|
5
|
+
import { Banner } from '../../../shared/components/Banner';
|
|
5
6
|
import { Dialog } from '../../../shared/components/Dialog';
|
|
6
7
|
import { useAdmin } from '../state/admin.context';
|
|
7
8
|
import { useAppRegistry } from '../../../core/registry';
|
|
@@ -60,6 +61,11 @@ export function DirectoryGroupsPage() {
|
|
|
60
61
|
const [working, setWorking] = useState(false);
|
|
61
62
|
// Group pending delete confirmation (manual mode).
|
|
62
63
|
const [deleteTarget, setDeleteTarget] = useState<GroupRosterEntry | null>(null);
|
|
64
|
+
// Only rules in files the admin can read: the roster leaves the rest out
|
|
65
|
+
// entirely (Admin status does not grant read, not even a count). So the
|
|
66
|
+
// copy below always says "you can read" and never claims there are no
|
|
67
|
+
// other rules — it reads the same whether or not unreadable ones exist.
|
|
68
|
+
const deleteRuleCount = deleteTarget?.referencedBy.length ?? 0;
|
|
63
69
|
// The overlay panel's "a directory connection exists" signal — true between
|
|
64
70
|
// connecting and the first push, when the roster still reads 'manual' but
|
|
65
71
|
// manual edits would go dormant. See GroupsDirectoryPanelProps.
|
|
@@ -150,6 +156,12 @@ export function DirectoryGroupsPage() {
|
|
|
150
156
|
const health = roster?.groupsHealth;
|
|
151
157
|
const broken =
|
|
152
158
|
brokenGroups ?? (health && !health.ok ? { file: health.file, reason: health.reason } : null);
|
|
159
|
+
// Groups that share a role's name, with the rules that spell them bare —
|
|
160
|
+
// those rules grant the ROLE, so an Admin must rewrite them if the group
|
|
161
|
+
// was meant.
|
|
162
|
+
const bareCollisions = (roster?.groups ?? []).filter(
|
|
163
|
+
(g) => (g.bareNameResolvesToRole?.length ?? 0) > 0,
|
|
164
|
+
);
|
|
153
165
|
|
|
154
166
|
return (
|
|
155
167
|
<>
|
|
@@ -171,6 +183,31 @@ export function DirectoryGroupsPage() {
|
|
|
171
183
|
</div>
|
|
172
184
|
)}
|
|
173
185
|
|
|
186
|
+
{bareCollisions.length > 0 && (
|
|
187
|
+
<Banner tone="wait" role="status" className="text-xs">
|
|
188
|
+
<div className="font-semibold">
|
|
189
|
+
Some access rules name a group the way a role is named.
|
|
190
|
+
</div>
|
|
191
|
+
<div>
|
|
192
|
+
A bare name in an access rule means the role when one of that name exists. These
|
|
193
|
+
rules resolve to the role, not the group — if the group was meant, write it as{' '}
|
|
194
|
+
<code>group/<Name></code> (a denial as <code>deny group/<Name></code>):
|
|
195
|
+
</div>
|
|
196
|
+
{/* A row is a verb and a file: whether the rule there grants or denies is
|
|
197
|
+
not in the roster, so the spelling is given for both. */}
|
|
198
|
+
<ul className="mt-1 list-disc pl-4">
|
|
199
|
+
{bareCollisions.flatMap((g) =>
|
|
200
|
+
g.bareNameResolvesToRole!.map((ref, index) => (
|
|
201
|
+
<li key={`${g.canonical}:${ref.path}:${ref.verb}:${index}`}>
|
|
202
|
+
<code>{ref.path}</code> — {ref.verb}: {g.displayName} (write{' '}
|
|
203
|
+
<code>group/{g.displayName}</code>, or <code>deny group/{g.displayName}</code> for a denial)
|
|
204
|
+
</li>
|
|
205
|
+
)),
|
|
206
|
+
)}
|
|
207
|
+
</ul>
|
|
208
|
+
</Banner>
|
|
209
|
+
)}
|
|
210
|
+
|
|
174
211
|
{error && (
|
|
175
212
|
<div
|
|
176
213
|
className="text-xs text-danger bg-danger-soft border border-danger/30 rounded-sm px-2 py-1.5"
|
|
@@ -259,12 +296,12 @@ export function DirectoryGroupsPage() {
|
|
|
259
296
|
>
|
|
260
297
|
{deleteTarget && (
|
|
261
298
|
<div className="space-y-2">
|
|
262
|
-
{
|
|
299
|
+
{deleteRuleCount > 0 ? (
|
|
263
300
|
<>
|
|
264
301
|
<p className="text-xs text-ink leading-snug">
|
|
265
|
-
{
|
|
266
|
-
{
|
|
267
|
-
{
|
|
302
|
+
{deleteRuleCount} access rule
|
|
303
|
+
{deleteRuleCount === 1 ? '' : 's'} you can read reference
|
|
304
|
+
{deleteRuleCount === 1 ? 's' : ''} this group and will stop
|
|
268
305
|
matching anyone after deletion:
|
|
269
306
|
</p>
|
|
270
307
|
<ul className="max-h-40 overflow-auto text-xs text-ink-muted space-y-0.5">
|
|
@@ -277,7 +314,7 @@ export function DirectoryGroupsPage() {
|
|
|
277
314
|
</>
|
|
278
315
|
) : (deleteTarget.assignedToRoles?.length ?? 0) === 0 ? (
|
|
279
316
|
<p className="text-xs text-ink leading-snug">
|
|
280
|
-
|
|
317
|
+
No access rule you can read references this group.
|
|
281
318
|
</p>
|
|
282
319
|
) : null}
|
|
283
320
|
{/* Role assignments are unassigned atomically with the delete —
|
|
@@ -4,4 +4,4 @@
|
|
|
4
4
|
* layout and free to move. Export what another module needs; nothing more.
|
|
5
5
|
*/
|
|
6
6
|
export { addMember, fetchRoles } from './services/roles.api';
|
|
7
|
-
export { AdminContext, useAdmin } from './state/admin.context';
|
|
7
|
+
export { AdminContext, useAdmin, type AdminContextValue } from './state/admin.context';
|
|
@@ -18,7 +18,10 @@ export interface GroupRosterEntry {
|
|
|
18
18
|
canonical: string;
|
|
19
19
|
displayName: string;
|
|
20
20
|
members: string[];
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Every access rule referencing this group in a file the viewer can read —
|
|
23
|
+
* drives the delete warning.
|
|
24
|
+
*/
|
|
22
25
|
referencedBy: { path: string; verb: string }[];
|
|
23
26
|
/**
|
|
24
27
|
* Canonical names of roles carrying an assignment to this group — deleting
|
|
@@ -27,6 +30,13 @@ export interface GroupRosterEntry {
|
|
|
27
30
|
* defensively: a skewed server may omit it, and rendering must not throw.
|
|
28
31
|
*/
|
|
29
32
|
assignedToRoles?: string[];
|
|
33
|
+
/**
|
|
34
|
+
* Access rules naming this group's name BARE while a role of the same name
|
|
35
|
+
* exists — a bare name means the role, so these grant the role, not this
|
|
36
|
+
* group. Rewritten as `group/<Name>` if the group was meant. Optional
|
|
37
|
+
* defensively, like `assignedToRoles`.
|
|
38
|
+
*/
|
|
39
|
+
bareNameResolvesToRole?: { path: string; verb: string }[];
|
|
30
40
|
}
|
|
31
41
|
|
|
32
42
|
/**
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { act, renderHook } from '@testing-library/react';
|
|
3
|
+
import { useConnectAsChoice } from '../useConnectAsChoice';
|
|
4
|
+
|
|
5
|
+
const AGENT = { path: 'Agents/release-helper.agent', name: 'release-helper', description: 'Reads; never writes.' };
|
|
6
|
+
|
|
7
|
+
describe('useConnectAsChoice', () => {
|
|
8
|
+
it('starts at Everything and lets nothing connect until the agents answer', () => {
|
|
9
|
+
const { result } = renderHook(() => useConnectAsChoice());
|
|
10
|
+
expect(result.current.value).toBeNull();
|
|
11
|
+
expect(result.current.mayConnect).toBe(false);
|
|
12
|
+
act(() => result.current.settle({ agents: [AGENT] }));
|
|
13
|
+
expect(result.current.agents).toEqual([AGENT]);
|
|
14
|
+
expect(result.current.mayConnect).toBe(true);
|
|
15
|
+
act(() => result.current.setValue(AGENT.path));
|
|
16
|
+
expect(result.current.value).toBe(AGENT.path);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('drops a remembered choice the answer no longer offers, back to Everything', () => {
|
|
20
|
+
const { result } = renderHook(() => useConnectAsChoice({ initial: 'Agents/gone.agent' }));
|
|
21
|
+
expect(result.current.value).toBe('Agents/gone.agent');
|
|
22
|
+
act(() => result.current.settle({ agents: [AGENT] }));
|
|
23
|
+
expect(result.current.value).toBeNull();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('keeps a remembered choice the answer still offers', () => {
|
|
27
|
+
const { result } = renderHook(() => useConnectAsChoice({ initial: AGENT.path }));
|
|
28
|
+
act(() => result.current.settle({ agents: [AGENT] }));
|
|
29
|
+
expect(result.current.value).toBe(AGENT.path);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('waits for Everything to be confirmed when the agents could not be loaded', () => {
|
|
33
|
+
const { result } = renderHook(() => useConnectAsChoice());
|
|
34
|
+
act(() => result.current.settle({ agents: [], failed: true }));
|
|
35
|
+
expect(result.current.unavailable).toBeDefined();
|
|
36
|
+
expect(result.current.mayConnect).toBe(false);
|
|
37
|
+
act(() => result.current.unavailable!.onConfirm(true));
|
|
38
|
+
expect(result.current.mayConnect).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('with an expected request, is settled only by that request’s answer', () => {
|
|
42
|
+
const { result, rerender } = renderHook(({ expect: key }) => useConnectAsChoice({ expect: key }), {
|
|
43
|
+
initialProps: { expect: 'state-1' as string | null },
|
|
44
|
+
});
|
|
45
|
+
act(() => result.current.settle({ agents: [] }, 'state-0'));
|
|
46
|
+
expect(result.current.mayConnect).toBe(false);
|
|
47
|
+
act(() => result.current.settle({ agents: [] }, 'state-1'));
|
|
48
|
+
expect(result.current.mayConnect).toBe(true);
|
|
49
|
+
// A new request arrives: its own answer is awaited again.
|
|
50
|
+
rerender({ expect: 'state-2' });
|
|
51
|
+
expect(result.current.mayConnect).toBe(false);
|
|
52
|
+
// And without any request there is nothing to connect.
|
|
53
|
+
rerender({ expect: null });
|
|
54
|
+
expect(result.current.mayConnect).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { useId } from 'react';
|
|
2
|
+
import { cn } from '../../../lib/utils';
|
|
3
|
+
import type { AgentChoice } from '../services/agent-choices.api';
|
|
4
|
+
import type { UnavailableChoice } from '../connect-as';
|
|
5
|
+
|
|
6
|
+
export interface ConnectAsChoiceProps {
|
|
7
|
+
/** The agents the person may connect as; Everything is always offered first. */
|
|
8
|
+
agents: readonly AgentChoice[];
|
|
9
|
+
/** The chosen agent's path, or null for Everything. */
|
|
10
|
+
value: string | null;
|
|
11
|
+
onChange: (agentPath: string | null) => void;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
/** One line under the heading, saying what the choice is for here. */
|
|
14
|
+
hint?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Set when the agents could not be loaded: the list is not "you have
|
|
17
|
+
* none", so the choice says it failed and asks the person to confirm
|
|
18
|
+
* Everything before the connection is made (see {@link canConnectAs}).
|
|
19
|
+
*/
|
|
20
|
+
unavailable?: UnavailableChoice;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* "Connect as": Everything (selected by default) or one agent configuration, by
|
|
25
|
+
* name with its description. Used where a connection is made — the OAuth
|
|
26
|
+
* consent step and the connection-key form — so both offer the same choice
|
|
27
|
+
* the same way.
|
|
28
|
+
*
|
|
29
|
+
* With no agent on offer there is no choice to make, and nothing is shown:
|
|
30
|
+
* the connection is Everything's, as every connection was before agents
|
|
31
|
+
* existed, and a page with one radio button would only ask what it cannot
|
|
32
|
+
* be asked. The one exception is a listing that FAILED — then the person is
|
|
33
|
+
* told, and confirms Everything, since the agents may well exist.
|
|
34
|
+
*/
|
|
35
|
+
export function ConnectAsChoice({ agents, value, onChange, disabled, hint, unavailable }: ConnectAsChoiceProps) {
|
|
36
|
+
const name = useId();
|
|
37
|
+
if (agents.length === 0 && !unavailable) return null;
|
|
38
|
+
const options: { path: string | null; title: string; detail: string }[] = [
|
|
39
|
+
{
|
|
40
|
+
path: null,
|
|
41
|
+
title: 'Everything',
|
|
42
|
+
detail: 'Every tool, skill and plugin you may read.',
|
|
43
|
+
},
|
|
44
|
+
...agents.map((a) => ({ path: a.path, title: a.name, detail: a.description || a.path })),
|
|
45
|
+
];
|
|
46
|
+
return (
|
|
47
|
+
<fieldset className="space-y-1.5" disabled={disabled}>
|
|
48
|
+
<legend className="text-xs font-medium text-ink">Connect as</legend>
|
|
49
|
+
{hint && <p className="text-meta text-ink-muted leading-snug">{hint}</p>}
|
|
50
|
+
<div className="divide-y divide-line border border-line rounded-md">
|
|
51
|
+
{options.map((o) => {
|
|
52
|
+
const checked = value === o.path;
|
|
53
|
+
return (
|
|
54
|
+
<label
|
|
55
|
+
key={o.path ?? ''}
|
|
56
|
+
className={cn('flex items-start gap-2 px-3 py-2 cursor-pointer', checked && 'bg-sunken')}
|
|
57
|
+
>
|
|
58
|
+
<input
|
|
59
|
+
type="radio"
|
|
60
|
+
name={name}
|
|
61
|
+
className="mt-0.5"
|
|
62
|
+
checked={checked}
|
|
63
|
+
onChange={() => onChange(o.path)}
|
|
64
|
+
/>
|
|
65
|
+
<span className="min-w-0">
|
|
66
|
+
<span className="block text-sm font-medium text-ink truncate">{o.title}</span>
|
|
67
|
+
<span className="block text-meta text-ink-muted leading-snug">{o.detail}</span>
|
|
68
|
+
</span>
|
|
69
|
+
</label>
|
|
70
|
+
);
|
|
71
|
+
})}
|
|
72
|
+
</div>
|
|
73
|
+
{unavailable && (
|
|
74
|
+
<div role="alert" className="text-xs text-danger bg-danger-soft border border-danger rounded-md px-2 py-1.5 space-y-1">
|
|
75
|
+
<p>Your agents couldn't be loaded, so only Everything can be chosen right now.</p>
|
|
76
|
+
<label className="flex items-center gap-1.5 cursor-pointer">
|
|
77
|
+
<input
|
|
78
|
+
type="checkbox"
|
|
79
|
+
checked={unavailable.confirmed}
|
|
80
|
+
onChange={(e) => unavailable.onConfirm(e.target.checked)}
|
|
81
|
+
/>
|
|
82
|
+
Connect as Everything anyway
|
|
83
|
+
</label>
|
|
84
|
+
</div>
|
|
85
|
+
)}
|
|
86
|
+
</fieldset>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** The agents could not be loaded; Everything waits for the person to confirm it. */
|
|
2
|
+
export interface UnavailableChoice {
|
|
3
|
+
confirmed: boolean;
|
|
4
|
+
onConfirm: (confirmed: boolean) => void;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Whether a connection may be made with the "Connect as" choice as it
|
|
9
|
+
* stands: once the agents on offer have answered — before that, the default
|
|
10
|
+
* Everything is not yet a choice anyone made — and then always, unless they
|
|
11
|
+
* failed to load and Everything is not yet confirmed.
|
|
12
|
+
*/
|
|
13
|
+
export function canConnectAs(choices: { settled: boolean; unavailable: UnavailableChoice | undefined }): boolean {
|
|
14
|
+
return choices.settled && (!choices.unavailable || choices.unavailable.confirmed);
|
|
15
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { canConnectAs, type UnavailableChoice } from './connect-as';
|
|
2
|
+
export { listAgentChoices, connectedAsLabel, type AgentChoice } from './services/agent-choices.api';
|
|
3
|
+
// The "Connect as" state both forms hold: the consent step and the key form
|
|
4
|
+
// settle it with the agents they loaded and read the choice back from it.
|
|
5
|
+
export { useConnectAsChoice, type AgentChoicesAnswer, type ConnectAsChoiceState } from './useConnectAsChoice';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { authFetch } from '../../../lib/api';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Connecting as an agent: an MCP connection or a connection key is made as
|
|
5
|
+
* Everything (all the person may read) or as one agent configuration of the
|
|
6
|
+
* knowledge base, whose lists narrow what the connection loads. What a
|
|
7
|
+
* configuration is — the file kind, what it says — is the distribution's;
|
|
8
|
+
* this mirrors the backend's `modules/agent-scope` contract, which only
|
|
9
|
+
* names the configuration by its path.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/** One agent configuration the signed-in person may connect as. */
|
|
13
|
+
export interface AgentChoice {
|
|
14
|
+
/** Repo-relative path of the configuration — what the connection records. */
|
|
15
|
+
path: string;
|
|
16
|
+
/** Its name, as the choice shows it. */
|
|
17
|
+
name: string;
|
|
18
|
+
/** Its description, one line; empty when it has none. */
|
|
19
|
+
description: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The agents a connection key may be minted as (the OAuth consent step gets the same list with its request). */
|
|
23
|
+
export async function listAgentChoices(): Promise<AgentChoice[]> {
|
|
24
|
+
const res = await authFetch('/api/mcp/agent-choices');
|
|
25
|
+
if (!res.ok) throw new Error("Couldn't load the agents you can connect as.");
|
|
26
|
+
const body = (await res.json()) as { agents?: AgentChoice[] };
|
|
27
|
+
return Array.isArray(body.agents) ? body.agents : [];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* How a connection's choice reads beside it: "Everything" for none, else the
|
|
32
|
+
* configuration's file name without its extension (the stored record is the
|
|
33
|
+
* path; the name its definition carries is the distribution's to show).
|
|
34
|
+
*/
|
|
35
|
+
export function connectedAsLabel(agentPath: string | null | undefined): string {
|
|
36
|
+
if (!agentPath) return 'Everything';
|
|
37
|
+
const base = agentPath.slice(agentPath.lastIndexOf('/') + 1);
|
|
38
|
+
return base.replace(/\.[a-z0-9]+$/i, '') || agentPath;
|
|
39
|
+
}
|