@bevel-software/platform-core-frontend 0.32.0 → 0.34.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/core/CoreAppShell.tsx +1 -1
- 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 +4 -5
- package/src/modules/access/components/ManageAccessDialog.tsx +11 -12
- package/src/modules/access/hooks/useAccessRequests.ts +1 -1
- package/src/modules/access/hooks/useFileAccess.ts +1 -1
- package/src/modules/access/index.ts +11 -0
- package/src/modules/access/requests.api.ts +1 -1
- package/src/modules/admin/__tests__/DirectoryGroupsPage.test.tsx +51 -0
- package/src/modules/admin/components/AddMemberInput.tsx +1 -1
- package/src/modules/admin/components/DirectoryGroupsPage.tsx +42 -5
- package/src/modules/admin/components/UserAccountsPage.tsx +3 -3
- package/src/modules/admin/index.ts +7 -0
- package/src/modules/admin/services/groups.api.ts +11 -1
- package/src/modules/admin/state/admin.context.tsx +1 -1
- package/src/modules/agents/__tests__/useConnectAsChoice.test.ts +56 -0
- package/src/modules/agents/components/ConnectAsChoice.tsx +81 -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 +13 -0
- package/src/modules/audit/components/AuditEventsPanel.tsx +1 -1
- package/src/modules/audit/components/AuditLogPage.tsx +11 -2
- 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 +12 -0
- package/src/modules/auth/services/account.api.ts +18 -2
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.access-rules.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.binary.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.brings-itself-up-to-date.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.edit.test.tsx +166 -0
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.fork-point.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.initial-file.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.moved.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.sync-banner.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.test.tsx +0 -2
- package/src/modules/change-requests/__tests__/ChangeRequestDialog.unreadable.test.tsx +0 -1
- package/src/modules/change-requests/__tests__/apply-outcome-for-every-viewer.test.tsx +0 -1
- package/src/modules/change-requests/components/BranchFilePreview.tsx +4 -12
- package/src/modules/change-requests/components/ChangeRequestDialog.tsx +138 -30
- package/src/modules/change-requests/components/ChangeRequestLink.tsx +2 -3
- package/src/modules/change-requests/components/CrFileTree.tsx +1 -1
- package/src/modules/change-requests/components/FileChangeBoxes.tsx +2 -3
- package/src/modules/change-requests/hooks/useApplyChangeRequest.ts +3 -5
- package/src/modules/change-requests/hooks/useCrFileDiffs.ts +1 -1
- package/src/modules/change-requests/index.ts +14 -0
- package/src/modules/change-requests/services/change-requests.api.ts +2 -2
- package/src/modules/change-requests/services/denied-file.api.ts +2 -2
- package/src/modules/change-requests/services/propose.api.ts +3 -4
- package/src/modules/change-requests/utils/diff.ts +1 -1
- package/src/modules/change-requests/utils/readFailure.ts +1 -1
- package/src/modules/embed/__tests__/EmbedView.test.tsx +19 -2
- package/src/modules/embed/components/EmbedLinkPage.tsx +1 -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/components/BranchSwitcher.tsx +3 -4
- package/src/modules/git/components/FileHistoryPanel.tsx +2 -2
- package/src/modules/git/components/GitSyncFailedBanner.tsx +2 -4
- package/src/modules/git/components/HistoryVersionPreview.tsx +4 -15
- package/src/modules/git/components/PullNeededBanner.tsx +1 -1
- package/src/modules/git/hooks/__tests__/useGitState.deleteBranch.test.tsx +1 -1
- package/src/modules/git/hooks/useAutoPullUpdates.ts +1 -1
- package/src/modules/git/index.ts +11 -0
- package/src/modules/layout/components/MobileChatLayout.tsx +1 -1
- package/src/modules/layout/index.ts +9 -0
- package/src/modules/library/__tests__/SkillPage.test.tsx +268 -24
- package/src/modules/library/__tests__/propose-change.test.ts +75 -0
- package/src/modules/library/components/AddToPluginDialog.tsx +1 -1
- package/src/modules/library/components/ChangeRequestDock.tsx +1 -1
- package/src/modules/library/components/LibraryLayout.tsx +2 -2
- package/src/modules/library/components/LibraryPage.tsx +3 -3
- package/src/modules/library/components/ManagedPluginRequests.tsx +1 -1
- package/src/modules/library/components/NewSkillPanel.tsx +2 -2
- package/src/modules/library/components/PersonalAddDialog.tsx +1 -1
- package/src/modules/library/components/PersonalPluginPage.tsx +1 -1
- package/src/modules/library/components/PluginExtras.tsx +1 -4
- package/src/modules/library/components/PluginPage.tsx +1 -1
- package/src/modules/library/components/PluginRows.tsx +1 -1
- package/src/modules/library/components/SkillsTree.tsx +1 -4
- package/src/modules/library/components/plugin-page-parts.tsx +1 -1
- package/src/modules/library/components/skill-page/SkillFilePane.tsx +74 -14
- package/src/modules/library/components/skill-page/SkillPage.tsx +80 -47
- package/src/modules/library/components/tool-page/ToolConnectionSection.tsx +2 -4
- package/src/modules/library/components/tool-page/ToolVarRow.tsx +2 -2
- package/src/modules/library/hooks/useJoinRequests.ts +1 -1
- package/src/modules/library/hooks/useLibraryData.ts +3 -3
- package/src/modules/library/hooks/useToolPage.ts +1 -1
- package/src/modules/library/hooks/useToolSource.ts +1 -1
- package/src/modules/library/index.ts +12 -0
- package/src/modules/library/routes/LibraryRoutes.tsx +1 -1
- package/src/modules/library/routes/WorkspaceItemRoute.tsx +1 -3
- package/src/modules/library/routes/library-paths.ts +1 -1
- package/src/modules/library/services/library.api.ts +10 -8
- package/src/modules/library/services/plugins.api.ts +1 -1
- package/src/modules/library/services/teams.api.ts +1 -1
- package/src/modules/library/utils/status.ts +2 -2
- package/src/modules/onboarding/components/ConnectAgentPill.tsx +1 -1
- package/src/modules/onboarding/components/CreatorWelcomePage.tsx +2 -3
- package/src/modules/onboarding/components/GetStartedColumn.tsx +6 -13
- package/src/modules/onboarding/components/InviteButton.tsx +2 -2
- package/src/modules/onboarding/components/InviteDialog.tsx +4 -6
- package/src/modules/onboarding/components/RootLanding.tsx +2 -2
- package/src/modules/onboarding/components/StarterPackCard.tsx +1 -1
- package/src/modules/onboarding/components/WelcomePage.tsx +2 -5
- package/src/modules/onboarding/index.ts +10 -0
- package/src/modules/onboarding/paths.ts +1 -1
- package/src/modules/onboarding/state/agent-connection.ts +2 -2
- package/src/modules/onboarding/state/onboarding.ts +1 -1
- package/src/modules/onboarding/state/starter-packs.ts +1 -1
- package/src/modules/pr/components/OpenChangeRequestDialog.tsx +1 -1
- package/src/modules/pr/index.ts +14 -0
- package/src/modules/pr/services/pr-approvals.api.ts +1 -1
- package/src/modules/pr/services/pr-cancel.api.ts +1 -1
- package/src/modules/pr/services/pr-detail.api.ts +2 -2
- package/src/modules/pr/services/pr-edit.api.ts +22 -0
- package/src/modules/pr/services/pr-merge.api.ts +1 -1
- package/src/modules/pr/services/pr-open.api.ts +1 -1
- package/src/modules/review/components/DiffViewer.tsx +1 -1
- package/src/modules/review/components/MarkdownDiffViewer.tsx +24 -3
- package/src/modules/review/components/ReviewPanel.tsx +10 -5
- package/src/modules/review/components/__tests__/MarkdownDiffViewer.test.tsx +31 -0
- package/src/modules/review/state/ReviewProvider.tsx +2 -2
- package/src/modules/secrets-vault/components/ConnectToolsPage.tsx +79 -16
- package/src/modules/secrets-vault/components/__tests__/ConnectToolsPage.test.tsx +112 -2
- package/src/modules/secrets-vault/index.ts +6 -0
- package/src/modules/secrets-vault/services/connect.api.ts +20 -5
- package/src/modules/settings/components/DeploymentPage.tsx +2 -2
- package/src/modules/settings/components/SettingsLayout.tsx +2 -2
- package/src/modules/settings/index.ts +8 -0
- package/src/modules/setup/components/FirstRunStorage.tsx +1 -1
- package/src/modules/setup/index.ts +6 -0
- package/src/modules/toolbar/commands/actions.tsx +3 -3
- package/src/modules/toolbar/commands/useCommandActions.ts +5 -9
- package/src/modules/toolbar/components/AgentInstructionsCard.tsx +2 -2
- package/src/modules/toolbar/components/AppSwitcher.tsx +1 -2
- package/src/modules/toolbar/components/CoworkSetupSteps.tsx +1 -1
- package/src/modules/toolbar/components/ExternalAgentAccessPage.tsx +39 -5
- package/src/modules/toolbar/components/ProfileMenu.tsx +3 -3
- package/src/modules/toolbar/components/SearchPalette.tsx +4 -8
- package/src/modules/toolbar/components/Toolbar.tsx +2 -5
- package/src/modules/toolbar/components/__tests__/ExternalAgentAccessPage.test.tsx +91 -2
- package/src/modules/toolbar/index.ts +6 -0
- package/src/modules/toolbar/search/sources.ts +4 -7
- package/src/modules/toolbar/services/agent-instructions.api.ts +1 -1
- package/src/modules/toolbar/services/external-api-keys.api.ts +5 -2
- package/src/modules/tools/ToolsExplorerPage.tsx +217 -18
- package/src/modules/tools/__tests__/ToolsExplorerPage.read-only.test.tsx +220 -0
- package/src/modules/tools/tool-hints.api.ts +44 -0
- package/src/modules/workflow/index.ts +7 -0
- package/src/modules/workflow/state/ChangeRequestStaleBinder.tsx +1 -0
- package/src/modules/workflow/state/EventBusFocusBinder.tsx +1 -1
- package/src/modules/workspace/components/FileExplorer.tsx +35 -8
- package/src/modules/workspace/components/FilePaneCard.tsx +37 -12
- package/src/modules/workspace/components/FileRoute.tsx +10 -3
- package/src/modules/workspace/components/FileViewer.tsx +169 -25
- package/src/modules/workspace/components/FullScreenView.tsx +93 -0
- package/src/modules/workspace/components/KbFileRail.tsx +1 -1
- package/src/modules/workspace/components/KbPageHeader.tsx +9 -0
- package/src/modules/workspace/components/__tests__/FileExplorer.test.tsx +163 -0
- package/src/modules/workspace/components/__tests__/FileRoute.test.tsx +11 -0
- package/src/modules/workspace/components/__tests__/FileViewer.test.tsx +487 -3
- package/src/modules/workspace/components/readingCarry.ts +59 -0
- package/src/modules/workspace/components/renderers/HtmlRenderer.tsx +74 -180
- 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/ToolRenderer.tsx +1 -1
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.links.test.tsx +185 -0
- package/src/modules/workspace/components/renderers/__tests__/HtmlRenderer.tools.test.tsx +168 -42
- 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 +57 -7
- package/src/modules/workspace/components/renderers/__tests__/htmlSandbox.test.ts +122 -4
- package/src/modules/workspace/components/renderers/__tests__/htmlToolBridge.test.ts +235 -1
- package/src/modules/workspace/components/renderers/__tests__/htmlViewsGuide.test.ts +29 -4
- package/src/modules/workspace/components/renderers/__tests__/liveDataReferencePage.test.ts +397 -0
- package/src/modules/workspace/components/renderers/__tests__/pageToolsHarness.ts +79 -0
- package/src/modules/workspace/components/renderers/__tests__/useHtmlToolBridge.test.tsx +316 -0
- package/src/modules/workspace/components/renderers/htmlSandbox.ts +123 -28
- package/src/modules/workspace/components/renderers/htmlToolBridge.ts +215 -25
- package/src/modules/workspace/components/renderers/index.ts +10 -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/components/renderers/useHtmlToolBridge.tsx +253 -0
- package/src/modules/workspace/hooks/__tests__/useLinksOut.test.ts +6 -0
- package/src/modules/workspace/hooks/useFullScreenView.ts +52 -0
- package/src/modules/workspace/hooks/useImageRevision.ts +1 -1
- package/src/modules/workspace/hooks/useKnowledgeWriteTarget.ts +1 -1
- package/src/modules/workspace/hooks/useLastCommit.ts +1 -1
- package/src/modules/workspace/hooks/useLinksOut.ts +12 -6
- package/src/modules/workspace/hooks/useWorkspaceState.ts +4 -4
- package/src/modules/workspace/index.ts +50 -2
- package/src/modules/workspace/routing/__tests__/kb-routes.test.tsx +262 -25
- package/src/modules/workspace/routing/kb-routes.ts +222 -54
- package/src/modules/workspace/state/__tests__/applied-request-clears-pending.test.tsx +0 -1
- package/src/modules/workspace/state/open-change-requests.tsx +1 -1
- package/src/modules/workspace/utils/fileTree.ts +1 -1
- package/src/modules/workspace/utils/frameEscape.ts +15 -0
- package/src/modules/workspace/utils/treeConfirm.ts +1 -1
- package/src/shared/theme/measure.ts +7 -0
- package/src/modules/pr/services/pr-comments.api.ts +0 -45
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bevel-software/platform-core-frontend",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.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.34.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@modelcontextprotocol/client": "^2.3.1",
|
|
@@ -18,7 +18,7 @@ import { GitContext } from '../modules/git/state/git.context';
|
|
|
18
18
|
import { AutoUpdateContext } from '../modules/git/state/auto-update.context';
|
|
19
19
|
import { useGitState } from '../modules/git/hooks/useGitState';
|
|
20
20
|
import { useAutoPullUpdates } from '../modules/git/hooks/useAutoPullUpdates';
|
|
21
|
-
import { EventBusProvider } from '../modules/workflow
|
|
21
|
+
import { EventBusProvider } from '../modules/workflow';
|
|
22
22
|
import { EventBusFocusBinder } from '../modules/workflow/state/EventBusFocusBinder';
|
|
23
23
|
import { ChangeRequestStaleBinder } from '../modules/workflow/state/ChangeRequestStaleBinder';
|
|
24
24
|
import { Toolbar } from '../modules/toolbar/components/Toolbar';
|
|
@@ -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
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Verb } from '@bevel-software/platform-shared';
|
|
2
2
|
import { authFetch } from '../../lib/api';
|
|
3
|
-
import { GitApiError, handleApiResponse } from '../git
|
|
3
|
+
import { GitApiError, handleApiResponse } from '../git';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* A collective grantee with WHAT it is — role (capability), group (audience),
|
|
@@ -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 =
|
|
@@ -33,11 +33,10 @@ import {
|
|
|
33
33
|
MenuPanel,
|
|
34
34
|
useDismissableMenu,
|
|
35
35
|
} from '../../../shared/components';
|
|
36
|
-
import { useWorkspace } from '../../workspace
|
|
37
|
-
import { useAuth } from '../../auth
|
|
38
|
-
import {
|
|
39
|
-
import {
|
|
40
|
-
import { useInviteDialog } from '../../onboarding/state/invite-dialog.context';
|
|
36
|
+
import { useWorkspace } from '../../workspace';
|
|
37
|
+
import { useAuth, useSignInMethods } from '../../auth';
|
|
38
|
+
import { AdminContext } from '../../admin';
|
|
39
|
+
import { useInviteDialog } from '../../onboarding';
|
|
41
40
|
import {
|
|
42
41
|
fetchFileAccess,
|
|
43
42
|
grantAccess,
|
|
@@ -374,7 +373,7 @@ function NoAccountNote({ help = NO_ACCOUNT_HELP }: { help?: string }) {
|
|
|
374
373
|
|
|
375
374
|
/**
|
|
376
375
|
* A principal's row/chip identity. Kind is PART of it: a group and a role
|
|
377
|
-
* sharing a name are DIFFERENT principals server-side (
|
|
376
|
+
* sharing a name are DIFFERENT principals server-side (`group/<name>` vs
|
|
378
377
|
* `role/<name>`), so they key — and chip — separately (`g:` vs `r:`). One
|
|
379
378
|
* name picked as both is two chips, and each grants its own kind.
|
|
380
379
|
*/
|
|
@@ -740,7 +739,7 @@ function buildRows(data: AccessResponse | null, myEmail: string): PrincipalRow[]
|
|
|
740
739
|
list.principals ?? list.roles.map((name) => ({ name, kind: 'role' as const }));
|
|
741
740
|
const touchCollective = (c: ResolvedPrincipal): PrincipalRow => {
|
|
742
741
|
// Rows are keyed by KIND + name (`g:`/`r:`/`p:`) — the backend treats a
|
|
743
|
-
//
|
|
742
|
+
// `group/Product` (group) and `role/Product` (role) as DIFFERENT
|
|
744
743
|
// principals, so a group and a role sharing a name are two rows, each
|
|
745
744
|
// mutating its own grant. Collapsing them to one row silently pointed
|
|
746
745
|
// every edit at the group and hid the role's grant entirely. A plugin
|
|
@@ -1259,16 +1258,16 @@ export function ManageAccessDialog({
|
|
|
1259
1258
|
|
|
1260
1259
|
// Resolve the CURRENT typed query into a principal to append as a chip: an
|
|
1261
1260
|
// exact group/role match or a free-typed email. (Suggestion clicks append
|
|
1262
|
-
// directly.)
|
|
1263
|
-
// shared by both
|
|
1264
|
-
// 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.
|
|
1265
1264
|
const addPending: Principal | null = useMemo(() => {
|
|
1266
1265
|
const q = query.trim();
|
|
1267
1266
|
if (!q) return null;
|
|
1268
|
-
const groupHit = suggest?.groups?.find((g) => g.toLowerCase() === q.toLowerCase());
|
|
1269
|
-
if (groupHit) return { kind: 'group', group: groupHit };
|
|
1270
1267
|
const roleHit = suggest?.roles?.find((g) => g.toLowerCase() === q.toLowerCase());
|
|
1271
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 };
|
|
1272
1271
|
if (EMAIL_RE.test(q)) return { kind: 'user', email: q, displayName: q.split('@')[0] };
|
|
1273
1272
|
return null;
|
|
1274
1273
|
}, [query, suggest]);
|
|
@@ -2,7 +2,7 @@ import { useCallback, useEffect, useState } from 'react';
|
|
|
2
2
|
import { DEFAULT_BRANCH } from '@bevel-software/platform-shared';
|
|
3
3
|
import { useLatestRef } from '../../../shared/components';
|
|
4
4
|
import { grantAccess } from '../api';
|
|
5
|
-
import { cancelPullRequest } from '../../pr
|
|
5
|
+
import { cancelPullRequest } from '../../pr';
|
|
6
6
|
import type { AccessProposal, AccessRequestRow } from '../requests.api';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
import { currentBranchModel, isProtectedBranch } from '@bevel-software/platform-shared';
|
|
3
|
-
import { useWorkspace } from '../../workspace
|
|
3
|
+
import { useWorkspace } from '../../workspace';
|
|
4
4
|
import { fetchFileAccess, type AccessEligible } from '../api';
|
|
5
5
|
|
|
6
6
|
export interface FileAccessState {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the access module offers the other modules. A consumer outside the
|
|
3
|
+
* module imports from here, never from the files: they are the module's own
|
|
4
|
+
* layout and free to move. Export what another module needs; nothing more.
|
|
5
|
+
*/
|
|
6
|
+
export { fetchAdmins, fetchFileAccess, fetchFileAccessBatch, fetchProspectiveAccess, parsePluginPrincipalToken, pluginPrincipalLabel, suggestPrincipals } from './api';
|
|
7
|
+
export type { AccessEligible, AccessPrincipalRef, AccessResponse, AdminContact, GrantSources, PathPrincipals, ProspectiveAccess } from './api';
|
|
8
|
+
export { useAccessRequests } from './hooks/useAccessRequests';
|
|
9
|
+
export type { AccessRequestsState } from './hooks/useAccessRequests';
|
|
10
|
+
export { formatEligible, useFileAccess } from './hooks/useFileAccess';
|
|
11
|
+
export { offersManageAccess } from './manage-access-affordance';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { authFetch } from '../../lib/api';
|
|
2
|
-
import { handleApiResponse } from '../git
|
|
2
|
+
import { handleApiResponse } from '../git';
|
|
3
3
|
|
|
4
4
|
/** The two levels the Manage access dialog can ask for. Owner covers Can edit. */
|
|
5
5
|
export type RequestLevel = 'write' | 'owner';
|
|
@@ -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
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect, useId, useRef, useState, type Ref } from 'react';
|
|
2
2
|
import { Loader2 } from 'lucide-react';
|
|
3
3
|
import { DEFAULT_BRANCH } from '@bevel-software/platform-shared';
|
|
4
|
-
import { suggestPrincipals } from '../../access
|
|
4
|
+
import { suggestPrincipals } from '../../access';
|
|
5
5
|
import { initials } from '../../../lib/email';
|
|
6
6
|
|
|
7
7
|
/** A person offered by the suggest endpoint — name and email, nothing more. */
|
|
@@ -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 —
|
|
@@ -3,8 +3,8 @@ import { Users } from 'lucide-react';
|
|
|
3
3
|
import { PageShell } from '../../../shared/components/PageShell';
|
|
4
4
|
import { Dialog } from '../../../shared/components/Dialog';
|
|
5
5
|
import { useAdmin } from '../state/admin.context';
|
|
6
|
-
import { useAuth } from '../../auth
|
|
7
|
-
import { useInviteDialog } from '../../onboarding
|
|
6
|
+
import { useAuth } from '../../auth';
|
|
7
|
+
import { useInviteDialog } from '../../onboarding';
|
|
8
8
|
import { useLatestRequest } from '../../../lib/latest-request';
|
|
9
9
|
import {
|
|
10
10
|
createAccount,
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
reactivateAccount,
|
|
16
16
|
type AccountReferences,
|
|
17
17
|
type AccountSummary,
|
|
18
|
-
} from '../../auth
|
|
18
|
+
} from '../../auth';
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* How an account signs in, in the words this page uses everywhere (the row and
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the admin module offers the other modules. A consumer outside the
|
|
3
|
+
* module imports from here, never from the files: they are the module's own
|
|
4
|
+
* layout and free to move. Export what another module needs; nothing more.
|
|
5
|
+
*/
|
|
6
|
+
export { addMember, fetchRoles } from './services/roles.api';
|
|
7
|
+
export { AdminContext, useAdmin } 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
|
/**
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
useState,
|
|
9
9
|
type ReactNode,
|
|
10
10
|
} from 'react';
|
|
11
|
-
import { useAuth } from '../../auth
|
|
11
|
+
import { useAuth } from '../../auth';
|
|
12
12
|
import { fetchAdminAccess } from '../services/admin.api';
|
|
13
13
|
import { useAppRegistry } from '../../../core/registry';
|
|
14
14
|
import { getRolesHealth, recoverRoles } from '../services/roles.api';
|
|
@@ -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,81 @@
|
|
|
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
|
+
export function ConnectAsChoice({ agents, value, onChange, disabled, hint, unavailable }: ConnectAsChoiceProps) {
|
|
30
|
+
const name = useId();
|
|
31
|
+
const options: { path: string | null; title: string; detail: string }[] = [
|
|
32
|
+
{
|
|
33
|
+
path: null,
|
|
34
|
+
title: 'Everything',
|
|
35
|
+
detail: 'Every tool, skill and plugin you may read.',
|
|
36
|
+
},
|
|
37
|
+
...agents.map((a) => ({ path: a.path, title: a.name, detail: a.description || a.path })),
|
|
38
|
+
];
|
|
39
|
+
return (
|
|
40
|
+
<fieldset className="space-y-1.5" disabled={disabled}>
|
|
41
|
+
<legend className="text-xs font-medium text-ink">Connect as</legend>
|
|
42
|
+
{hint && <p className="text-meta text-ink-muted leading-snug">{hint}</p>}
|
|
43
|
+
<div className="divide-y divide-line border border-line rounded-md">
|
|
44
|
+
{options.map((o) => {
|
|
45
|
+
const checked = value === o.path;
|
|
46
|
+
return (
|
|
47
|
+
<label
|
|
48
|
+
key={o.path ?? ''}
|
|
49
|
+
className={cn('flex items-start gap-2 px-3 py-2 cursor-pointer', checked && 'bg-sunken')}
|
|
50
|
+
>
|
|
51
|
+
<input
|
|
52
|
+
type="radio"
|
|
53
|
+
name={name}
|
|
54
|
+
className="mt-0.5"
|
|
55
|
+
checked={checked}
|
|
56
|
+
onChange={() => onChange(o.path)}
|
|
57
|
+
/>
|
|
58
|
+
<span className="min-w-0">
|
|
59
|
+
<span className="block text-sm font-medium text-ink truncate">{o.title}</span>
|
|
60
|
+
<span className="block text-meta text-ink-muted leading-snug">{o.detail}</span>
|
|
61
|
+
</span>
|
|
62
|
+
</label>
|
|
63
|
+
);
|
|
64
|
+
})}
|
|
65
|
+
</div>
|
|
66
|
+
{unavailable && (
|
|
67
|
+
<div role="alert" className="text-xs text-danger bg-danger-soft border border-danger rounded-md px-2 py-1.5 space-y-1">
|
|
68
|
+
<p>Your agents couldn't be loaded, so only Everything can be chosen right now.</p>
|
|
69
|
+
<label className="flex items-center gap-1.5 cursor-pointer">
|
|
70
|
+
<input
|
|
71
|
+
type="checkbox"
|
|
72
|
+
checked={unavailable.confirmed}
|
|
73
|
+
onChange={(e) => unavailable.onConfirm(e.target.checked)}
|
|
74
|
+
/>
|
|
75
|
+
Connect as Everything anyway
|
|
76
|
+
</label>
|
|
77
|
+
</div>
|
|
78
|
+
)}
|
|
79
|
+
</fieldset>
|
|
80
|
+
);
|
|
81
|
+
}
|