@bevel-software/platform-core-frontend 0.34.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bevel-software/platform-core-frontend",
3
- "version": "0.34.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.34.0"
48
+ "@bevel-software/platform-shared": "0.35.0"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@modelcontextprotocol/client": "^2.3.1",
@@ -392,19 +392,39 @@ export interface PathPrincipals {
392
392
  write: AccessPrincipalRef[];
393
393
  }
394
394
 
395
- /** One file's or folder's holders where it is now and where a move would put it. */
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. */
396
413
  export interface ProspectiveAccess {
397
414
  before: PathPrincipals;
398
415
  after: PathPrincipals;
416
+ changes: HolderChanges;
399
417
  }
400
418
 
401
419
  /**
402
420
  * Resolve who holds read and write on `relativePath` today and who would hold
403
421
  * them once it sits in `toDir` — the destination's folder rules with what the
404
422
  * move carries layered on top: a file's own frontmatter, or the `access.md`
405
- * files inside a folder, counted at the paths they land on. Both paths are
406
- * repo-relative (`Knowledge/Foo.md`, `Knowledge/Sales`); `toDir` is `''` for
407
- * 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.
408
428
  *
409
429
  * `signal` lets the move dialog give up on it: the answer decorates the
410
430
  * confirmation and must never hold it open.
@@ -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';
@@ -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';
@@ -25,9 +25,16 @@ export interface ConnectAsChoiceProps {
25
25
  * name with its description. Used where a connection is made — the OAuth
26
26
  * consent step and the connection-key form — so both offer the same choice
27
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.
28
34
  */
29
35
  export function ConnectAsChoice({ agents, value, onChange, disabled, hint, unavailable }: ConnectAsChoiceProps) {
30
36
  const name = useId();
37
+ if (agents.length === 0 && !unavailable) return null;
31
38
  const options: { path: string | null; title: string; detail: string }[] = [
32
39
  {
33
40
  path: null,
@@ -4,8 +4,8 @@ import userEvent from '@testing-library/user-event';
4
4
  import { MemoryRouter } from 'react-router-dom';
5
5
  import { AuditLogPage } from '../components/AuditLogPage';
6
6
  import { groupByAccount } from '../components/principal-grouping';
7
- import { AdminContext } from '../../admin/state/admin.context';
8
- import { AuthContext } from '../../auth/state/auth.context';
7
+ import { AdminContext } from '../../admin';
8
+ import { AuthContext } from '../../auth';
9
9
  import {
10
10
  listPrincipals,
11
11
  listEvents,
@@ -187,7 +187,8 @@ describe('AuditLogPage', () => {
187
187
  const rowOf = (label: string) => screen.getByText(label).closest('li') as HTMLElement;
188
188
  expect(rowOf('Claude')).toHaveTextContent('As delivery-mechanic');
189
189
  expect(within(rowOf('Claude')).getByTitle('Agents/delivery-mechanic.agent')).toBeInTheDocument();
190
- expect(rowOf('CI pipeline')).toHaveTextContent('As Everything');
190
+ // Everything is what a connection is unless it says otherwise: no tag.
191
+ expect(rowOf('CI pipeline')).not.toHaveTextContent('As ');
191
192
  });
192
193
 
193
194
  it('shows an admin a key its owner deleted for good, marked as such, with its history intact', async () => {
@@ -277,11 +277,13 @@ export function AuditLogPage() {
277
277
  {p.deletedAt != null && <Badge tone="outline">Deleted by owner</Badge>}
278
278
  </span>
279
279
  <span className="block text-meta text-ink-muted">
280
- {/* What the connection loads: Everything, or the agent configuration it
281
- was made as. A page acts as its viewer, so it has none. */}
282
- {p.kind !== 'page' && (
280
+ {/* The agent configuration the connection was made as, when it was
281
+ made as one; a connection made as Everything, which is what a
282
+ connection is unless it says otherwise, carries no tag. A page
283
+ acts as its viewer, so it never has one. */}
284
+ {p.kind !== 'page' && p.agentPath && (
283
285
  <>
284
- <span title={p.agentPath ?? undefined}>As {connectedAsLabel(p.agentPath)}</span>
286
+ <span title={p.agentPath}>As {connectedAsLabel(p.agentPath)}</span>
285
287
  {' · '}
286
288
  </>
287
289
  )}
@@ -8,5 +8,5 @@ export { createAccount, deactivateAccount, deleteAccount, getAccountReferences,
8
8
  export type { AccountReferences, AccountSummary } from './services/account.api';
9
9
  export { takePostLoginRedirect } from './services/sso';
10
10
  export type { LoginProviders } from './services/sso';
11
- export { AuthContext, useAuth } from './state/auth.context';
11
+ export { AuthContext, useAuth, type AuthContextValue } from './state/auth.context';
12
12
  export { useSignInMethods } from './state/use-sign-in-methods';
@@ -1,6 +1,6 @@
1
1
  import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { render, screen, fireEvent, waitFor } from '@testing-library/react';
3
- import type { ToolVarStatus } from '../../secrets-vault/services/tool-secrets.api';
2
+ import { render, screen, fireEvent, waitFor, cleanup } from '@testing-library/react';
3
+ import type { ToolVarStatus } from '../../secrets-vault';
4
4
 
5
5
  /**
6
6
  * The per-variable state matrix, one case per row of the spec table.
@@ -12,16 +12,21 @@ import type { ToolVarStatus } from '../../secrets-vault/services/tool-secrets.ap
12
12
  * clobber the discovered provider).
13
13
  */
14
14
 
15
+ // The row reaches Secrets & connections through that module's entry, so the
16
+ // mock sits on the entry too — the same surface, with the rest of the module
17
+ // left as it is — never on the files behind it.
15
18
  const secretsMock = vi.hoisted(() => ({
16
19
  setAdminVar: vi.fn(),
17
20
  setUserVar: vi.fn(),
18
21
  deleteAdminVar: vi.fn(),
19
22
  setOAuthClientSecret: vi.fn(),
20
23
  }));
21
- vi.mock('../../secrets-vault/services/tool-secrets.api', () => secretsMock);
22
-
23
24
  const connectMock = vi.hoisted(() => ({ startToolOAuth: vi.fn() }));
24
- vi.mock('../../secrets-vault/services/connect.api', () => connectMock);
25
+ vi.mock('../../secrets-vault', async (importOriginal) => ({
26
+ ...(await importOriginal<typeof import('../../secrets-vault')>()),
27
+ ...secretsMock,
28
+ ...connectMock,
29
+ }));
25
30
 
26
31
  // External navigation behind a spy-able module — never assign
27
32
  // window.location.href in a test.
@@ -236,7 +241,48 @@ describe('ToolVarRow: oauth', () => {
236
241
  expect(screen.getByRole('button', { name: 'Replace client secret' })).toBeInTheDocument();
237
242
  });
238
243
 
244
+ it('offers a writer Replace client secret while not signed in, and it opens the client-secret editor', async () => {
245
+ const { onChanged } = renderRow(signin({ authorized: false }), { canWrite: true, setupKind: 'oauth-manual' });
246
+ expect(screen.getByRole('button', { name: 'Sign in' })).toBeInTheDocument();
247
+ expect(screen.queryByRole('button', { name: 'Set client secret' })).toBeNull();
248
+ fireEvent.click(screen.getByRole('button', { name: 'Replace client secret' }));
249
+
250
+ const input = screen.getByLabelText('Client secret for SIGNIN');
251
+ expect(input).toHaveAttribute('type', 'password');
252
+ fireEvent.change(input, { target: { value: 'cs_new' } });
253
+ fireEvent.click(screen.getByRole('button', { name: 'Save' }));
254
+ await waitFor(() =>
255
+ expect(secretsMock.setOAuthClientSecret).toHaveBeenCalledWith('github', 'SIGNIN', 'cs_new'),
256
+ );
257
+ await waitFor(() => expect(onChanged).toHaveBeenCalled());
258
+ });
259
+
260
+ it('offers a writer Replace client secret beside Sign in again', () => {
261
+ renderRow(signin({ authorized: true, needsReauth: true }), { canWrite: true, setupKind: 'oauth-manual' });
262
+ expect(screen.getByRole('button', { name: 'Sign in again' })).toBeInTheDocument();
263
+ expect(screen.getByRole('button', { name: 'Replace client secret' })).toBeInTheDocument();
264
+ });
265
+
266
+ it('shows a reader who cannot write the tool Sign in only, in every state', () => {
267
+ renderRow(signin({ authorized: false }), { canWrite: false, setupKind: 'oauth-manual' });
268
+ expect(screen.getByRole('button', { name: 'Sign in' })).toBeInTheDocument();
269
+ expect(screen.queryByRole('button', { name: /client secret/ })).toBeNull();
270
+ cleanup();
271
+ renderRow(signin({ authorized: true }), { canWrite: false, setupKind: 'oauth-manual' });
272
+ expect(screen.queryByRole('button', { name: /client secret/ })).toBeNull();
273
+ cleanup();
274
+ renderRow(signin({ authorized: true, needsReauth: true }), { canWrite: false, setupKind: 'oauth-manual' });
275
+ expect(screen.queryByRole('button', { name: /client secret/ })).toBeNull();
276
+ });
277
+
239
278
  it('never shows a client-secret affordance for oauth-auto, even to a writer', () => {
279
+ renderRow(signin({ authorized: false }), { canWrite: true, setupKind: 'oauth-auto' });
280
+ expect(screen.queryByRole('button', { name: /client secret/ })).toBeNull();
281
+ cleanup();
282
+ renderRow(signin({ authorized: true, needsReauth: true }), { canWrite: true, setupKind: 'oauth-auto' });
283
+ expect(screen.queryByRole('button', { name: /client secret/ })).toBeNull();
284
+ cleanup();
285
+
240
286
  renderRow(signin({ authorized: true }), { canWrite: true, setupKind: 'oauth-auto' });
241
287
  expect(screen.queryByRole('button', { name: 'Replace client secret' })).toBeNull();
242
288
 
@@ -26,6 +26,10 @@ import { navigateExternal } from '../../utils/navigate-external';
26
26
  * - `oauth-auto` NEVER gets a client-secret affordance. Its client was
27
27
  * auto-registered by PKCE dynamic registration and has no secret; saving one
28
28
  * would clobber the discovered provider row and break sign-in for everyone.
29
+ * - Every OTHER sign-in offers its owner the client secret in every state of
30
+ * the row: "Replace client secret" while one is stored, "Set client secret"
31
+ * while none is. The secret belongs to the tool, not to the caller's own
32
+ * sign-in, so whether the owner is signed in has no say in it.
29
33
  * - Whose problem is it? A user-scope gap is the caller's to fix and always
30
34
  * shows an action. An admin-scope gap is the OWNER's, so a non-writer sees a
31
35
  * chip that explains the state and no button they can't act on.
@@ -147,13 +151,6 @@ export function ToolVarRow({
147
151
  Signed in
148
152
  </Badge>,
149
153
  );
150
- if (mayEditClientSecret) {
151
- meta.push(
152
- <Button key="secret" size="sm" variant="quiet" onClick={() => open('client-secret')}>
153
- Replace client secret
154
- </Button>,
155
- );
156
- }
157
154
  } else if (variable.authorized) {
158
155
  description = 'Each person sets their own';
159
156
  meta.push(
@@ -172,13 +169,7 @@ export function ToolVarRow({
172
169
  // The owner hasn't declared the provider (or hasn't set its secret), so
173
170
  // there is nothing for anyone to sign in to yet.
174
171
  description = "The tool owner hasn't finished the sign-in setup yet.";
175
- if (mayEditClientSecret) {
176
- meta.push(
177
- <Button key="secret" size="sm" onClick={() => open('client-secret')}>
178
- Set client secret
179
- </Button>,
180
- );
181
- } else {
172
+ if (!mayEditClientSecret) {
182
173
  meta.push(
183
174
  <Badge key="chip" tone="neutral">
184
175
  Not set
@@ -186,6 +177,23 @@ export function ToolVarRow({
186
177
  );
187
178
  }
188
179
  }
180
+ // The client secret is the owner's, not the sign-in's: whatever state the
181
+ // caller's own sign-in is in, an owner who may edit it can replace a stored
182
+ // secret (or set a missing one) from this row. Tying it to the caller being
183
+ // signed in left an owner replacing a connector with no way to do it here.
184
+ if (mayEditClientSecret) {
185
+ meta.push(
186
+ variable.adminConfigured ? (
187
+ <Button key="secret" size="sm" variant="quiet" onClick={() => open('client-secret')}>
188
+ Replace client secret
189
+ </Button>
190
+ ) : (
191
+ <Button key="secret" size="sm" onClick={() => open('client-secret')}>
192
+ Set client secret
193
+ </Button>
194
+ ),
195
+ );
196
+ }
189
197
  } else if (variable.scope === 'admin') {
190
198
  if (variable.adminConfigured) {
191
199
  description = 'One value for the whole team. Already handled';
@@ -555,6 +555,16 @@ describe('ConnectToolsPage: inside Skills & Tools', () => {
555
555
  expect(await within(group).findByRole('radio', { name: /ops.*Watches the dashboards\./ })).not.toBeChecked();
556
556
  });
557
557
 
558
+ it('asks nothing when there is no agent to connect as: the connection is Everything’s, as it always was', async () => {
559
+ connectMock.getMcpOAuthRequest.mockResolvedValue({ clientName: 'Claude', scope: null, resource: null, agents: [] });
560
+ renderPage();
561
+ // Finish waits for the agents to answer, so once it went through, the choice had its chance to appear.
562
+ await finish();
563
+ expect(screen.queryByRole('group', { name: 'Connect as' })).toBeNull();
564
+ expect(screen.queryByText(/Connect as/)).toBeNull();
565
+ expect(connectMock.completeMcpOAuth).toHaveBeenCalledWith('signed-state', null);
566
+ });
567
+
558
568
  it('says when the agents could not be loaded, and approves Everything only once that is confirmed', async () => {
559
569
  connectMock.getMcpOAuthRequest.mockResolvedValue({
560
570
  clientName: 'Claude',
@@ -608,7 +608,14 @@ export function ExternalAgentAccessPage() {
608
608
  <div className="flex-1 min-w-0">
609
609
  <div className="font-medium truncate">{k.label}</div>
610
610
  <div className="text-[11px] text-ink-muted">
611
- <span title={k.agentPath ?? undefined}>As {connectedAsLabel(k.agentPath)}</span> · Created{' '}
611
+ {/* Only a key made as an agent says so; Everything is what a key
612
+ is unless it says otherwise, and needs no tag. */}
613
+ {k.agentPath && (
614
+ <>
615
+ <span title={k.agentPath}>As {connectedAsLabel(k.agentPath)}</span> ·{' '}
616
+ </>
617
+ )}
618
+ Created{' '}
612
619
  {formatRelative(k.createdAt)} · Last used {formatRelative(k.lastUsedAt)}
613
620
  {/* A key an admin took is not one you can reconnect — say so,
614
621
  or people try. Your own disconnect keeps its word. */}
@@ -34,25 +34,35 @@ const { listMock, createMock, instructionsMock, facadeMock, registrationMock, ad
34
34
  adminState: { isAdmin: false },
35
35
  }));
36
36
 
37
- // Only the hook is replaced. `AdminContext` itself stays real, because the
38
- // instructions card below reads the context directly rather than through the
39
- // hook; a whole-module mock left it undefined and every case here threw.
40
- vi.mock('../../../admin/state/admin.context', async (importOriginal) => ({
41
- ...(await importOriginal<typeof import('../../../admin/state/admin.context')>()),
37
+ // The other modules this page reaches, replaced at their entries: that is
38
+ // where the page imports them from, and the one surface a mock may stand in
39
+ // for. Only the hook is replaced on `admin`; `AdminContext` itself stays real,
40
+ // because the instructions card below reads the context directly rather than
41
+ // through the hook; a whole-module mock left it undefined and every case here
42
+ // threw.
43
+ vi.mock('../../../admin', async (importOriginal) => ({
44
+ ...(await importOriginal<typeof import('../../../admin')>()),
42
45
  useAdmin: () => ({ isAdmin: adminState.isAdmin }),
43
46
  }));
44
47
 
45
- // The registration state the Cowork drawer reads, and the admin credentials
46
- // endpoint this page must never call. Mocked, or the component reaches for
47
- // the real endpoints over the network.
48
- vi.mock('../../../settings/services/github-facade.api', () => ({
49
- fetchGitHubFacade: facadeMock,
48
+ // The registration state the Cowork drawer reads.
49
+ vi.mock('../../../settings', async (importOriginal) => ({
50
+ ...(await importOriginal<typeof import('../../../settings')>()),
50
51
  fetchMarketplaceRegistration: registrationMock,
51
52
  }));
52
53
 
54
+ // The admin credentials endpoint this page must never call. It is reached
55
+ // inside the settings module, by `ClaudeConnectionCard`, which the toolbar's
56
+ // registration steps import by file rather than through the entry, so the
57
+ // guard sits on the file too until that import moves.
58
+ vi.mock('../../../settings/services/github-facade.api', async (importOriginal) => ({
59
+ ...(await importOriginal<typeof import('../../../settings/services/github-facade.api')>()),
60
+ fetchGitHubFacade: facadeMock,
61
+ }));
62
+
53
63
  // The agents a key may be minted as ("Connect as").
54
- vi.mock('../../../agents/services/agent-choices.api', async (importOriginal) => ({
55
- ...(await importOriginal<typeof import('../../../agents/services/agent-choices.api')>()),
64
+ vi.mock('../../../agents', async (importOriginal) => ({
65
+ ...(await importOriginal<typeof import('../../../agents')>()),
56
66
  listAgentChoices: agentChoicesMock,
57
67
  }));
58
68
 
@@ -817,6 +827,21 @@ describe('minting a key as an agent ("Connect as")', () => {
817
827
  expect(ops).not.toBeChecked();
818
828
  });
819
829
 
830
+ it('asks nothing when there is no agent to mint as: the key is Everything’s, as it always was', async () => {
831
+ agentChoicesMock.mockResolvedValue([]);
832
+ const user = userEvent.setup();
833
+ mount(PUBLIC_URL);
834
+ await user.click(screen.getByRole('tab', { name: 'Autonomous agents' }));
835
+ await user.type(screen.getByRole('textbox', { name: /Create an external API key/ }), 'CI');
836
+ // Create key is enabled only once the agents answered, so the choice had its chance to appear.
837
+ const create = screen.getByRole('button', { name: 'Create key' });
838
+ expect(create).toBeEnabled();
839
+ expect(screen.queryByRole('group', { name: 'Connect as' })).toBeNull();
840
+ expect(screen.queryByText(/Connect as/)).toBeNull();
841
+ await user.click(create);
842
+ expect(createMock).toHaveBeenLastCalledWith('CI', null);
843
+ });
844
+
820
845
  it('mints as Everything unless an agent is picked, and as the agent when one is', async () => {
821
846
  agentChoicesMock.mockResolvedValue([OPS]);
822
847
  const user = userEvent.setup();
@@ -876,7 +901,8 @@ describe('minting a key as an agent ("Connect as")', () => {
876
901
  await user.click(screen.getByRole('tab', { name: 'Autonomous agents' }));
877
902
  await screen.findByText('Pipeline');
878
903
  const rowOf = (label: string) => screen.getByText(label).closest('li') as HTMLElement;
879
- expect(rowOf('Laptop')).toHaveTextContent('As Everything');
904
+ // Everything is what a key is unless it says otherwise: no tag.
905
+ expect(rowOf('Laptop')).not.toHaveTextContent('As ');
880
906
  expect(rowOf('Pipeline')).toHaveTextContent('As ops');
881
907
  });
882
908
  });
@@ -13,13 +13,13 @@ import { KbPageHeader } from './KbPageHeader';
13
13
  import { useOpenChangeRequests } from '../hooks/useOpenChangeRequests';
14
14
  import { Banner, Button, IconButton, Surface, useFocusHandoff } from '../../../shared/components';
15
15
  import { displayFileName, fileNameTooltip, isAccessRulesFile } from '../utils/display-file-name';
16
- import { ManageAccessDialog } from '../../access/components/ManageAccessDialog';
17
16
  import { useGit } from '../../git';
18
17
  import { LayoutContext } from '../../layout';
19
18
  import { useLocation, useNavigate, useParams } from 'react-router-dom';
20
19
  import { useCanonicalFileUrl, useFileNav } from '../routing/kb-routes';
21
20
  import { PullNeededBanner } from '../../git/components/PullNeededBanner';
22
21
  import { GitSyncFailedBanner } from '../../git/components/GitSyncFailedBanner';
22
+ import { ManageAccessDialog } from '../../access/components/ManageAccessDialog';
23
23
  import { useFileAccess, formatEligible } from '../../access';
24
24
  import { FileHistoryPanel } from '../../git/components/FileHistoryPanel';
25
25
  import { FileComparisonPanel } from '../../git/components/FileComparisonPanel';
@@ -13,10 +13,10 @@ import {
13
13
  type WorkspaceContextValue,
14
14
  } from '../../state/workspace.context';
15
15
  import { makeWorkspaceFixture } from '../../__tests__/testFixtures';
16
- import { GitContext, type GitContextValue } from '../../../git/state/git.context';
17
- import { AuthContext, type AuthContextValue } from '../../../auth/state/auth.context';
16
+ import { GitContext, type GitContextValue } from '../../../git';
17
+ import { AuthContext, type AuthContextValue } from '../../../auth';
18
18
  import { OpenChangeRequestsContext } from '../../state/open-change-requests.context';
19
- import { AdminContext, type AdminContextValue } from '../../../admin/state/admin.context';
19
+ import { AdminContext, type AdminContextValue } from '../../../admin';
20
20
  import { PR_STALE_EVENT } from '../../../../core/events';
21
21
  import { EventBusProvider } from '../../../workflow';
22
22
  import type { WorkflowEvent } from '@bevel-software/platform-shared';
@@ -44,10 +44,14 @@ const cancelMocks = vi.hoisted(() => ({
44
44
  cancelPullRequest: vi.fn(),
45
45
  deleteChangeRequest: vi.fn(),
46
46
  }));
47
- vi.mock('../../../pr/services/pr-cancel.api', () => cancelMocks);
47
+ vi.mock('../../../pr', async (importOriginal) => ({ ...(await importOriginal<typeof import('../../../pr')>()), ...cancelMocks }));
48
48
 
49
49
  // The sheet itself is covered by the access module's own tests; here only
50
50
  // WHICH workspace and proposal the tree hands it matters.
51
+ // A component is composed by importing its file, never through a module's
52
+ // index (the Module Map's one allowance for React components), so the
53
+ // component's file is the surface the tree reaches it through, and the one a
54
+ // mock stands in for.
51
55
  vi.mock('../../../access/components/ManageAccessDialog', () => ({
52
56
  ManageAccessDialog: (props: {
53
57
  entry: FileTreeEntry;
@@ -2056,16 +2060,36 @@ describe('FileExplorer: delete and move ask first', () => {
2056
2060
  const person = (name: string, email: string) => ({ kind: 'person', name, email });
2057
2061
 
2058
2062
  /**
2059
- * Answer the move dialog's access lookup with these before/after holders,
2060
- * and everything else (the destination-writable preflight) with a writable
2061
- * verdict — the warnings suite covers that one on its own.
2063
+ * Answer the move dialog's access lookup with these before/after holders —
2064
+ * and the `changes` the server derives from the resolver, which this stand-in
2065
+ * derives from the two sides, since no rule here denies anyone by name — and
2066
+ * everything else (the destination-writable preflight) with a writable
2067
+ * verdict; the warnings suite covers that one on its own.
2062
2068
  */
2063
2069
  function answerAccess(before: Side, after: Side, opts: { canWrite?: boolean } = {}) {
2064
2070
  const side = (s: Side) => ({ read: s.read ?? [], write: s.write ?? [] });
2071
+ const keyOf = (p: unknown) => {
2072
+ const { kind, name, email } = p as { kind: string; name: string; email?: string };
2073
+ return kind === 'person' ? `person:${(email ?? name).toLowerCase()}` : `${kind}:${name.toLowerCase()}`;
2074
+ };
2075
+ const changesOf = (b: Side, a: Side) => {
2076
+ const lose: unknown[] = [];
2077
+ const gain: unknown[] = [];
2078
+ for (const verb of ['read', 'write'] as const) {
2079
+ const had = new Set((b[verb] ?? []).map(keyOf));
2080
+ const has = new Set((a[verb] ?? []).map(keyOf));
2081
+ for (const p of b[verb] ?? []) if (!has.has(keyOf(p))) lose.push({ ...(p as object), verb });
2082
+ for (const p of a[verb] ?? []) if (!had.has(keyOf(p))) gain.push({ ...(p as object), verb });
2083
+ }
2084
+ return { lose, gain };
2085
+ };
2065
2086
  mockAuthFetch.mockImplementation(async (url: string) => {
2066
2087
  const u = String(url);
2067
2088
  if (u.includes('/access/prospective')) {
2068
- return { ok: true, json: async () => ({ before: side(before), after: side(after) }) };
2089
+ return {
2090
+ ok: true,
2091
+ json: async () => ({ before: side(before), after: side(after), changes: changesOf(before, after) }),
2092
+ };
2069
2093
  }
2070
2094
  if (u.includes('/access?')) {
2071
2095
  return { ok: true, json: async () => ({ canWrite: opts.canWrite ?? true }) };
@@ -1,6 +1,6 @@
1
1
  import { describe, it, expect, afterEach } from 'vitest';
2
2
  import { DEFAULT_KB_LAYOUT, configureKbLayout } from '@bevel-software/platform-shared';
3
- import type { AccessPrincipalRef, PathPrincipals } from '../../../access/api';
3
+ import type { AccessPrincipalRef, HolderChangeRef, HolderChanges } from '../../../access';
4
4
  import type { FileTreeEntry } from '@bevel-software/platform-shared';
5
5
  import {
6
6
  accessChangeLines,
@@ -45,29 +45,26 @@ describe('deleteSentence', () => {
45
45
  * What the move confirmation says about access. The tester who failed the
46
46
  * previous move warning asked for names — "these people would lose the
47
47
  * following access, these people would gain the following access" — so these
48
- * cases are the sentences, not the resolution: the resolver's before and after
49
- * lists go in, the lines the dialog reads go out.
48
+ * cases are the sentences, not the resolution: the resolver's own changes
49
+ * (the server's `prospectiveHolderChanges`, the same answer the agent's
50
+ * `move_file` gives) go in, the lines the dialog reads go out.
50
51
  */
51
52
 
52
53
  const group = (name: string): AccessPrincipalRef => ({ kind: 'group', name });
53
54
  const role = (name: string): AccessPrincipalRef => ({ kind: 'role', name });
54
55
  const person = (name: string, email: string): AccessPrincipalRef => ({ kind: 'person', name, email });
55
56
  const plugin = (token: string): AccessPrincipalRef => ({ kind: 'plugin', name: token });
57
+ const reads = (p: AccessPrincipalRef): HolderChangeRef => ({ ...p, verb: 'read' });
58
+ const edits = (p: AccessPrincipalRef): HolderChangeRef => ({ ...p, verb: 'write' });
56
59
 
57
60
  /** The layout is module state shared by the whole file; each test that names one puts the defaults back. */
58
61
  afterEach(() => configureKbLayout({ ...DEFAULT_KB_LAYOUT }));
59
62
 
60
- const side = (read: AccessPrincipalRef[], write: AccessPrincipalRef[] = []): PathPrincipals => ({
61
- read,
62
- write,
63
- });
63
+ const changes = (lose: HolderChangeRef[], gain: HolderChangeRef[] = []): HolderChanges => ({ lose, gain });
64
64
 
65
65
  describe('accessChangeLines', () => {
66
66
  it('names who loses access, by verb', () => {
67
- const change = accessChangeLines(
68
- side([group('Engineering')], [group('Engineering')]),
69
- side([], []),
70
- );
67
+ const change = accessChangeLines(changes([reads(group('Engineering')), edits(group('Engineering'))]));
71
68
 
72
69
  expect(change.lose).toEqual([
73
70
  'Engineering: can no longer open',
@@ -77,98 +74,85 @@ describe('accessChangeLines', () => {
77
74
  });
78
75
 
79
76
  it('names who gains access, by verb', () => {
80
- const change = accessChangeLines(side([], []), side([group('Product')], [group('Product')]));
77
+ const change = accessChangeLines(changes([], [reads(group('Product')), edits(group('Product'))]));
81
78
 
82
79
  expect(change.lose).toEqual([]);
83
80
  expect(change.gain).toEqual(['Product: can open', 'Product: can edit']);
84
81
  });
85
82
 
86
83
  it('lists both blocks when the move costs one group and serves another', () => {
87
- const change = accessChangeLines(side([group('Engineering')]), side([group('Product')]));
84
+ const change = accessChangeLines(changes([reads(group('Engineering'))], [reads(group('Product'))]));
88
85
 
89
86
  expect(change.lose).toEqual(['Engineering: can no longer open']);
90
87
  expect(change.gain).toEqual(['Product: can open']);
91
88
  });
92
89
 
93
- it('reports no change at all when both sides resolve the same', () => {
94
- const both = side([group('Engineering'), person('Ali Raza', 'ali@x.io')], [group('Engineering')]);
95
-
96
- expect(accessChangeLines(both, both)).toEqual({ lose: [], gain: [] });
97
- });
98
-
99
- it('is unmoved by the order the resolver happens to list principals in', () => {
100
- const before = side([group('Engineering'), group('Product')]);
101
- const after = side([group('Product'), group('Engineering')]);
102
-
103
- expect(accessChangeLines(before, after)).toEqual({ lose: [], gain: [] });
90
+ it('reports no change at all when the resolver found none', () => {
91
+ expect(accessChangeLines(changes([], []))).toEqual({ lose: [], gain: [] });
104
92
  });
105
93
 
106
94
  it('names a directly granted person, by the name on the grant', () => {
107
- const change = accessChangeLines(side([person('Ali Raza', 'ali@x.io')]), side([]));
95
+ const change = accessChangeLines(changes([reads(person('Ali Raza', 'ali@x.io'))]));
108
96
 
109
97
  expect(change.lose).toEqual(['Ali Raza: can no longer open']);
110
98
  });
111
99
 
112
- it('matches a person on their address, whatever name each side carries', () => {
100
+ it('is one person at one address, whatever name each change carries', () => {
101
+ // The resolver names a person by address; the label follows the first spelling.
113
102
  const change = accessChangeLines(
114
- side([person('Ali Raza', 'ali@x.io')]),
115
- side([person('ali@x.io', 'ALI@x.io')]),
103
+ changes([reads(person('Ali Raza', 'ali@x.io')), edits(person('ali@x.io', 'ALI@x.io'))]),
116
104
  );
117
105
 
118
- expect(change).toEqual({ lose: [], gain: [] });
106
+ expect(change.lose).toEqual(['Ali Raza: can no longer open', 'Ali Raza: can no longer edit']);
119
107
  });
120
108
 
121
109
  it('falls back to a nameless person’s address rather than an empty line', () => {
122
- const change = accessChangeLines(side([]), side([person('', 'ali@x.io')]));
110
+ const change = accessChangeLines(changes([], [reads(person('', 'ali@x.io'))]));
123
111
 
124
112
  expect(change.gain).toEqual(['ali@x.io: can open']);
125
113
  });
126
114
 
127
115
  it('keeps a group and a same-named role apart — they are different principals', () => {
128
- const change = accessChangeLines(side([group('Design')]), side([role('Design')]));
116
+ const change = accessChangeLines(changes([reads(group('Design'))], [reads(role('Design'))]));
129
117
 
130
118
  expect(change.lose).toEqual(['Design: can no longer open']);
131
119
  expect(change.gain).toEqual(['Design: can open']);
132
120
  });
133
121
 
134
122
  it('names a plugin principal as the share sheet does', () => {
135
- const change = accessChangeLines(side([]), side([plugin('plugin/GTM/read')]));
123
+ const change = accessChangeLines(changes([], [reads(plugin('plugin/GTM/read'))]));
136
124
 
137
125
  expect(change.gain).toEqual(['GTM · readers: can open']);
138
126
  });
139
127
 
140
128
  it('names the built-in everyone role Everyone', () => {
141
- const change = accessChangeLines(side([role('everyone')]), side([]));
129
+ const change = accessChangeLines(changes([reads(role('everyone'))]));
142
130
 
143
131
  expect(change.lose).toEqual(['Everyone: can no longer open']);
144
132
  });
145
133
 
146
- it('puts one principal’s two verbs together, opening before editing', () => {
134
+ it('puts one principal’s two verbs together, opening before editing, whatever order the changes came in', () => {
147
135
  const change = accessChangeLines(
148
- side([group('Engineering'), group('Ops')], [group('Ops')]),
149
- side([]),
136
+ changes([edits(group('Ops')), reads(group('Engineering')), reads(group('Ops'))]),
150
137
  );
151
138
 
152
139
  expect(change.lose).toEqual([
153
- 'Engineering: can no longer open',
154
140
  'Ops: can no longer open',
155
141
  'Ops: can no longer edit',
142
+ 'Engineering: can no longer open',
156
143
  ]);
157
144
  });
158
145
 
159
146
  it('lists a principal in both blocks when it trades one verb for another', () => {
160
- const change = accessChangeLines(
161
- side([group('Engineering')], [group('Engineering')]),
162
- side([group('Engineering')], []),
163
- );
147
+ const change = accessChangeLines(changes([edits(group('Engineering'))], [reads(group('Engineering'))]));
164
148
 
165
149
  expect(change.lose).toEqual(['Engineering: can no longer edit']);
166
- expect(change.gain).toEqual([]);
150
+ expect(change.gain).toEqual(['Engineering: can open']);
167
151
  });
168
152
 
169
153
  it('shows six lines and folds the rest into "and N more"', () => {
170
- const many = Array.from({ length: 9 }, (_, i) => group(`Team ${i + 1}`));
171
- const change = accessChangeLines(side(many), side([]));
154
+ const many = Array.from({ length: 9 }, (_, i) => reads(group(`Team ${i + 1}`)));
155
+ const change = accessChangeLines(changes(many));
172
156
 
173
157
  expect(change.lose).toHaveLength(7);
174
158
  expect(change.lose[5]).toBe('Team 6: can no longer open');
@@ -176,16 +160,16 @@ describe('accessChangeLines', () => {
176
160
  });
177
161
 
178
162
  it('caps at six without a count when there are exactly six', () => {
179
- const six = Array.from({ length: 6 }, (_, i) => group(`Team ${i + 1}`));
180
- const change = accessChangeLines(side([]), side(six));
163
+ const six = Array.from({ length: 6 }, (_, i) => reads(group(`Team ${i + 1}`)));
164
+ const change = accessChangeLines(changes([], six));
181
165
 
182
166
  expect(change.gain).toHaveLength(6);
183
167
  expect(change.gain.at(-1)).toBe('Team 6: can open');
184
168
  });
185
169
 
186
170
  it('caps each block on its own', () => {
187
- const losers = Array.from({ length: 8 }, (_, i) => group(`Old ${i + 1}`));
188
- const change = accessChangeLines(side(losers), side([group('Product')]));
171
+ const losers = Array.from({ length: 8 }, (_, i) => reads(group(`Old ${i + 1}`)));
172
+ const change = accessChangeLines(changes(losers, [reads(group('Product'))]));
189
173
 
190
174
  expect(change.lose.at(-1)).toBe('and 2 more');
191
175
  expect(change.gain).toEqual(['Product: can open']);
@@ -12,7 +12,8 @@ import {
12
12
  parsePluginPrincipalToken,
13
13
  pluginPrincipalLabel,
14
14
  type AccessPrincipalRef,
15
- type PathPrincipals,
15
+ type HolderChangeRef,
16
+ type HolderChanges,
16
17
  type ProspectiveAccess,
17
18
  } from '../../access';
18
19
  import { KB_ROOT_DIRS } from './fileTree';
@@ -238,44 +239,39 @@ function capped(lines: string[]): string[] {
238
239
  }
239
240
 
240
241
  /**
241
- * Who loses and who gains access in one move: per verb, the principals
242
- * present before and absent after, and absent before and present after.
242
+ * The lines of who loses and who gains access in one move, from the
243
+ * resolver's own verdicts (`changes`, the server's `prospectiveHolderChanges`
244
+ * — the same answer the agent's `move_file` gives). Nothing is derived here
245
+ * from the holder lists: those name grants, so a diff of them misses a
246
+ * person the destination denies by name and shows a writer leaving a folder
247
+ * everyone reads as losing `read`.
243
248
  *
244
- * Lines are grouped by principal in the order the lists name them — the
245
- * resolver's order, collectives before directly granted people — and within a
246
- * principal, opening before editing. A principal that loses one verb and
247
- * gains another appears in both blocks, which is what happened.
249
+ * Lines are grouped by principal in the order the changes name them — the
250
+ * resolver's order, collectives before people — and within a principal,
251
+ * opening before editing. A principal that loses one verb and gains another
252
+ * appears in both blocks, which is what happened.
248
253
  */
249
- export function accessChangeLines(before: PathPrincipals, after: PathPrincipals): AccessChange {
254
+ export function accessChangeLines(changes: HolderChanges): AccessChange {
250
255
  const lose: string[] = [];
251
256
  const gain: string[] = [];
252
- // First-seen order over every list, so a principal's lines sit together
257
+ // First-seen order over both lists, so a principal's lines sit together
253
258
  // wherever the verb that introduced it came from.
254
259
  const order: AccessPrincipalRef[] = [];
255
260
  const seen = new Set<string>();
256
- for (const side of [before, after]) {
257
- for (const verb of ACCESS_VERBS) {
258
- for (const principal of side[verb]) {
259
- const key = principalKey(principal);
260
- if (seen.has(key)) continue;
261
- seen.add(key);
262
- order.push(principal);
263
- }
264
- }
261
+ for (const change of [...changes.lose, ...changes.gain]) {
262
+ const key = principalKey(change);
263
+ if (seen.has(key)) continue;
264
+ seen.add(key);
265
+ order.push(change);
265
266
  }
266
- const keysOf = (list: AccessPrincipalRef[]) => new Set(list.map(principalKey));
267
- const sides = {
268
- before: { read: keysOf(before.read), write: keysOf(before.write) },
269
- after: { read: keysOf(after.read), write: keysOf(after.write) },
270
- };
267
+ const has = (list: HolderChangeRef[], key: string, verb: 'read' | 'write') =>
268
+ list.some((c) => c.verb === verb && principalKey(c) === key);
271
269
  for (const principal of order) {
272
270
  const key = principalKey(principal);
273
271
  const label = principalLabel(principal);
274
272
  for (const verb of ACCESS_VERBS) {
275
- const had = sides.before[verb].has(key);
276
- const has = sides.after[verb].has(key);
277
- if (had && !has) lose.push(`${label}: can no longer ${VERB_WORD[verb]}`);
278
- if (!had && has) gain.push(`${label}: can ${VERB_WORD[verb]}`);
273
+ if (has(changes.lose, key, verb)) lose.push(`${label}: can no longer ${VERB_WORD[verb]}`);
274
+ if (has(changes.gain, key, verb)) gain.push(`${label}: can ${VERB_WORD[verb]}`);
279
275
  }
280
276
  }
281
277
  return { lose: capped(lose), gain: capped(gain) };
@@ -283,7 +279,7 @@ export function accessChangeLines(before: PathPrincipals, after: PathPrincipals)
283
279
 
284
280
  /** {@link accessChangeLines} over a whole prospective-access answer. */
285
281
  export function accessChangeOf(access: ProspectiveAccess): AccessChange {
286
- return accessChangeLines(access.before, access.after);
282
+ return accessChangeLines(access.changes);
287
283
  }
288
284
 
289
285
  /**