@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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
import { canConnectAs, type UnavailableChoice } from './connect-as';
|
|
3
|
+
import type { AgentChoice } from './services/agent-choices.api';
|
|
4
|
+
|
|
5
|
+
/** What the agents on offer answered: the list, or that they could not be loaded. */
|
|
6
|
+
export interface AgentChoicesAnswer {
|
|
7
|
+
agents: readonly AgentChoice[];
|
|
8
|
+
/** The agents could not be listed: `agents` is then empty for that reason, not because there are none. */
|
|
9
|
+
failed?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The "Connect as" state a connection is made with — the one shape both
|
|
14
|
+
* forms (the OAuth consent step, the connection-key form) hold, so the
|
|
15
|
+
* agents module owns the consent state and each page only says when its
|
|
16
|
+
* agents answered and what it does with the choice.
|
|
17
|
+
*/
|
|
18
|
+
export interface ConnectAsChoiceState {
|
|
19
|
+
/** The agents on offer; Everything is always offered first. */
|
|
20
|
+
agents: readonly AgentChoice[];
|
|
21
|
+
/** The chosen agent's path, or null for Everything. */
|
|
22
|
+
value: string | null;
|
|
23
|
+
setValue: (agentPath: string | null) => void;
|
|
24
|
+
/** Set when the agents could not be loaded: Everything waits for the person to confirm it. */
|
|
25
|
+
unavailable: UnavailableChoice | undefined;
|
|
26
|
+
/** Whether a connection may be made with the choice as it stands (see {@link canConnectAs}). */
|
|
27
|
+
mayConnect: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The agents on offer have answered. `requestKey` names the request they
|
|
30
|
+
* answered for, when the page waits on one in particular (the consent
|
|
31
|
+
* step's authorization state): until that request's own answer is in,
|
|
32
|
+
* Everything is not yet a choice anyone made.
|
|
33
|
+
*/
|
|
34
|
+
settle: (answer: AgentChoicesAnswer, requestKey?: string) => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The "Connect as" choice: Everything (null) unless the person picks an
|
|
39
|
+
* agent, settled once the agents on offer answer. A remembered choice that is
|
|
40
|
+
* no longer on offer falls back to Everything. With `expect`, the state is
|
|
41
|
+
* settled only when the answer named that request; without it, by any answer.
|
|
42
|
+
*/
|
|
43
|
+
export function useConnectAsChoice(opts: { initial?: string | null | (() => string | null); expect?: string | null } = {}): ConnectAsChoiceState {
|
|
44
|
+
const [agents, setAgents] = useState<readonly AgentChoice[]>([]);
|
|
45
|
+
const [value, setValue] = useState<string | null>(opts.initial ?? null);
|
|
46
|
+
const [failed, setFailed] = useState(false);
|
|
47
|
+
const [settledFor, setSettledFor] = useState<string | null>(null);
|
|
48
|
+
const [everythingConfirmed, setEverythingConfirmed] = useState(false);
|
|
49
|
+
|
|
50
|
+
const settle = useCallback((answer: AgentChoicesAnswer, requestKey = '') => {
|
|
51
|
+
setAgents(answer.agents);
|
|
52
|
+
setFailed(answer.failed === true);
|
|
53
|
+
// A remembered choice that is no longer on offer falls back to Everything.
|
|
54
|
+
setValue((current) => (current && answer.agents.some((a) => a.path === current) ? current : null));
|
|
55
|
+
setSettledFor(requestKey);
|
|
56
|
+
}, []);
|
|
57
|
+
|
|
58
|
+
const unavailable = useMemo<UnavailableChoice | undefined>(
|
|
59
|
+
() => (failed ? { confirmed: everythingConfirmed, onConfirm: setEverythingConfirmed } : undefined),
|
|
60
|
+
[failed, everythingConfirmed],
|
|
61
|
+
);
|
|
62
|
+
const settled = opts.expect === undefined ? settledFor !== null : opts.expect != null && settledFor === opts.expect;
|
|
63
|
+
const mayConnect = canConnectAs({ settled, unavailable });
|
|
64
|
+
|
|
65
|
+
return { agents, value, setValue, unavailable, mayConnect, settle };
|
|
66
|
+
}
|
|
@@ -177,6 +177,19 @@ describe('AuditLogPage', () => {
|
|
|
177
177
|
expect(screen.queryByRole('button', { name: /Revoke key for Old script/ })).not.toBeInTheDocument();
|
|
178
178
|
});
|
|
179
179
|
|
|
180
|
+
it('shows what each connection and key connects as: Everything, or the agent file it was made as', async () => {
|
|
181
|
+
vi.mocked(listPrincipals).mockResolvedValue([
|
|
182
|
+
{ ...ALICE_CLAUDE, agentPath: 'Agents/delivery-mechanic.agent' },
|
|
183
|
+
{ ...ALICE_CI, agentPath: null },
|
|
184
|
+
]);
|
|
185
|
+
renderPage({ isAdmin: true });
|
|
186
|
+
await waitFor(() => expect(screen.getByText('CI pipeline')).toBeInTheDocument());
|
|
187
|
+
const rowOf = (label: string) => screen.getByText(label).closest('li') as HTMLElement;
|
|
188
|
+
expect(rowOf('Claude')).toHaveTextContent('As delivery-mechanic');
|
|
189
|
+
expect(within(rowOf('Claude')).getByTitle('Agents/delivery-mechanic.agent')).toBeInTheDocument();
|
|
190
|
+
expect(rowOf('CI pipeline')).toHaveTextContent('As Everything');
|
|
191
|
+
});
|
|
192
|
+
|
|
180
193
|
it('shows an admin a key its owner deleted for good, marked as such, with its history intact', async () => {
|
|
181
194
|
vi.mocked(listPrincipals).mockResolvedValue([{ ...BOB_OLD, deletedAt: NOW - 10 * DAY, eventCount: 18 }]);
|
|
182
195
|
renderPage({ isAdmin: true });
|
|
@@ -2,7 +2,7 @@ import { Fragment, useCallback, useEffect, useId, useMemo, useRef, useState } fr
|
|
|
2
2
|
import { Link } from 'react-router-dom';
|
|
3
3
|
import { Badge, Banner, Button } from '../../../shared/components';
|
|
4
4
|
import { cn } from '../../../lib/utils';
|
|
5
|
-
import {
|
|
5
|
+
import { pathForTool, pathForSkill } from '../../library';
|
|
6
6
|
import {
|
|
7
7
|
listEvents,
|
|
8
8
|
type AgentEvent,
|
|
@@ -5,9 +5,10 @@ import { Dialog } from '../../../shared/components/Dialog';
|
|
|
5
5
|
import { Badge, Banner, Button } from '../../../shared/components';
|
|
6
6
|
import { cn, formatRelativeTime } from '../../../lib/utils';
|
|
7
7
|
import { GITHUB_LINK_KIND } from '../../../shared/marketplace-url';
|
|
8
|
-
import { useAdmin } from '../../admin
|
|
9
|
-
import { useAuth } from '../../auth
|
|
8
|
+
import { useAdmin } from '../../admin';
|
|
9
|
+
import { useAuth } from '../../auth';
|
|
10
10
|
import { listPrincipals, revokeAgent, revokeKey, type AuditPrincipal } from '../services/audit.api';
|
|
11
|
+
import { connectedAsLabel } from '../../agents';
|
|
11
12
|
import { groupByAccount, principalKey } from './principal-grouping';
|
|
12
13
|
import { AuditEventsPanel } from './AuditEventsPanel';
|
|
13
14
|
|
|
@@ -276,6 +277,14 @@ export function AuditLogPage() {
|
|
|
276
277
|
{p.deletedAt != null && <Badge tone="outline">Deleted by owner</Badge>}
|
|
277
278
|
</span>
|
|
278
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' && (
|
|
283
|
+
<>
|
|
284
|
+
<span title={p.agentPath ?? undefined}>As {connectedAsLabel(p.agentPath)}</span>
|
|
285
|
+
{' · '}
|
|
286
|
+
</>
|
|
287
|
+
)}
|
|
279
288
|
<span title={formatAbsolute(p.createdAt)}>
|
|
280
289
|
{p.kind === 'agent' ? 'Connected' : p.kind === 'page' ? 'First call' : 'Created'}{' '}
|
|
281
290
|
{formatRelative(p.createdAt)}
|
|
@@ -29,6 +29,11 @@ export interface AuditPrincipal {
|
|
|
29
29
|
/** Events on record for it. */
|
|
30
30
|
eventCount: number;
|
|
31
31
|
user: { id: string; email: string; name: string };
|
|
32
|
+
/**
|
|
33
|
+
* For a key or an agent: the agent configuration it connects as (a knowledge-base
|
|
34
|
+
* path), or null for Everything. Absent for a page.
|
|
35
|
+
*/
|
|
36
|
+
agentPath?: string | null;
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
export type AgentEventKind = 'capability' | 'tool' | 'skill';
|
|
@@ -75,6 +75,27 @@ describe('AccountPage', () => {
|
|
|
75
75
|
await userEvent.click(screen.getByRole('button', { name: 'Change password' }));
|
|
76
76
|
expect(await screen.findByRole('alert')).toHaveTextContent('Current password is incorrect');
|
|
77
77
|
});
|
|
78
|
+
|
|
79
|
+
it('disables the submit while a change is in flight, and sends one change for a double click', async () => {
|
|
80
|
+
let finish!: () => void;
|
|
81
|
+
vi.mocked(changePassword).mockImplementation(
|
|
82
|
+
() => new Promise<void>((resolve) => (finish = resolve)),
|
|
83
|
+
);
|
|
84
|
+
renderPage();
|
|
85
|
+
await userEvent.type(screen.getByLabelText(/Current password/), 'old-password');
|
|
86
|
+
await userEvent.type(screen.getByLabelText(/New password/), 'new-password-1');
|
|
87
|
+
await userEvent.type(screen.getByLabelText(/Confirm new password/), 'new-password-1');
|
|
88
|
+
await userEvent.dblClick(screen.getByRole('button', { name: 'Change password' }));
|
|
89
|
+
// A second submit straight from the form, as a click landing before the
|
|
90
|
+
// disabled button rendered would be.
|
|
91
|
+
screen.getByRole('button', { name: 'Saving…' }).closest('form')!.requestSubmit();
|
|
92
|
+
expect(screen.getByRole('button', { name: 'Saving…' })).toBeDisabled();
|
|
93
|
+
expect(changePassword).toHaveBeenCalledTimes(1);
|
|
94
|
+
|
|
95
|
+
finish();
|
|
96
|
+
expect(await screen.findByRole('status')).toHaveTextContent('Password changed.');
|
|
97
|
+
expect(screen.getByRole('button', { name: 'Change password' })).toBeEnabled();
|
|
98
|
+
});
|
|
78
99
|
});
|
|
79
100
|
|
|
80
101
|
/**
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
+
import { changePassword } from '../services/account.api';
|
|
3
|
+
import { authFetch, getToken, setToken } from '../../../lib/api';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A password change ends every session opened before it, the changer's old
|
|
7
|
+
* token included, so the page keeps working only if the token the change
|
|
8
|
+
* hands back is what the NEXT request carries. Only `fetch` is stubbed: the
|
|
9
|
+
* real `changePassword` and `authFetch` read and write the stored token.
|
|
10
|
+
*/
|
|
11
|
+
describe('changePassword and the token it hands back', () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
localStorage.clear();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
vi.restoreAllMocks();
|
|
18
|
+
localStorage.clear();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('authenticates the next request with the replacement token', async () => {
|
|
22
|
+
setToken('token-before-the-change');
|
|
23
|
+
const fetchMock = vi
|
|
24
|
+
.spyOn(globalThis, 'fetch')
|
|
25
|
+
.mockResolvedValueOnce(new Response(JSON.stringify({ ok: true, token: 'token-after-the-change' }), { status: 200 }))
|
|
26
|
+
.mockResolvedValueOnce(new Response(JSON.stringify({ user: {} }), { status: 200 }));
|
|
27
|
+
|
|
28
|
+
await changePassword('old-password-1', 'new-password-1');
|
|
29
|
+
await authFetch('/api/auth/me');
|
|
30
|
+
|
|
31
|
+
const authorization = (call: number) =>
|
|
32
|
+
new Headers((fetchMock.mock.calls[call][1] as RequestInit).headers).get('Authorization');
|
|
33
|
+
expect(authorization(0)).toBe('Bearer token-before-the-change');
|
|
34
|
+
expect(authorization(1)).toBe('Bearer token-after-the-change');
|
|
35
|
+
expect(getToken()).toBe('token-after-the-change');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('keeps a sign-in another tab made while the change was in flight, rather than overwriting it', async () => {
|
|
39
|
+
setToken('token-before-the-change');
|
|
40
|
+
vi.spyOn(globalThis, 'fetch').mockImplementationOnce(async () => {
|
|
41
|
+
// The other tab signs in as someone else before this response arrives.
|
|
42
|
+
setToken('other-account-token');
|
|
43
|
+
return new Response(JSON.stringify({ ok: true, token: 'token-after-the-change' }), { status: 200 });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
await changePassword('old-password-1', 'new-password-1');
|
|
47
|
+
expect(getToken()).toBe('other-account-token');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('keeps the stored token when a success answer carries no token, rather than storing "undefined"', async () => {
|
|
51
|
+
setToken('token-before-the-change');
|
|
52
|
+
vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(new Response(JSON.stringify({ ok: true }), { status: 200 }));
|
|
53
|
+
|
|
54
|
+
await changePassword('old-password-1', 'new-password-1');
|
|
55
|
+
expect(getToken()).toBe('token-before-the-change');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('keeps the stored token when the change is refused', async () => {
|
|
59
|
+
setToken('token-before-the-change');
|
|
60
|
+
vi.spyOn(globalThis, 'fetch').mockResolvedValueOnce(
|
|
61
|
+
new Response(JSON.stringify({ error: 'Your password was changed from another session; nothing was changed.' }), {
|
|
62
|
+
status: 409,
|
|
63
|
+
}),
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
await expect(changePassword('old-password-1', 'new-password-1')).rejects.toThrow(/another session/);
|
|
67
|
+
expect(getToken()).toBe('token-before-the-change');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState, type FormEvent } from 'react';
|
|
1
|
+
import { useRef, useState, type FormEvent } from 'react';
|
|
2
2
|
import { PageShell } from '../../../shared/components/PageShell';
|
|
3
3
|
import { useAuth } from '../state/auth.context';
|
|
4
4
|
import { changePassword } from '../services/account.api';
|
|
@@ -25,15 +25,20 @@ export function AccountPage() {
|
|
|
25
25
|
const [error, setError] = useState<string | null>(null);
|
|
26
26
|
const [saved, setSaved] = useState(false);
|
|
27
27
|
const [submitting, setSubmitting] = useState(false);
|
|
28
|
+
// Set synchronously, so a second click landing before the disabled button
|
|
29
|
+
// renders is dropped too: one change at a time, never two racing.
|
|
30
|
+
const inFlight = useRef(false);
|
|
28
31
|
|
|
29
32
|
async function handleSubmit(e: FormEvent<HTMLFormElement>) {
|
|
30
33
|
e.preventDefault();
|
|
34
|
+
if (inFlight.current) return;
|
|
31
35
|
setError(null);
|
|
32
36
|
setSaved(false);
|
|
33
37
|
if (newPassword !== confirmPassword) {
|
|
34
38
|
setError('New passwords do not match');
|
|
35
39
|
return;
|
|
36
40
|
}
|
|
41
|
+
inFlight.current = true;
|
|
37
42
|
setSubmitting(true);
|
|
38
43
|
try {
|
|
39
44
|
await changePassword(currentPassword || undefined, newPassword);
|
|
@@ -44,6 +49,7 @@ export function AccountPage() {
|
|
|
44
49
|
} catch (err) {
|
|
45
50
|
setError(err instanceof Error ? err.message : 'Could not change password');
|
|
46
51
|
} finally {
|
|
52
|
+
inFlight.current = false;
|
|
47
53
|
setSubmitting(false);
|
|
48
54
|
}
|
|
49
55
|
}
|
|
@@ -113,7 +119,7 @@ export function AccountPage() {
|
|
|
113
119
|
)}
|
|
114
120
|
{saved && (
|
|
115
121
|
<div className="text-sm text-emerald-700" role="status">
|
|
116
|
-
Password changed.
|
|
122
|
+
Password changed. Every other session has been signed out.
|
|
117
123
|
</div>
|
|
118
124
|
)}
|
|
119
125
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the auth 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 { useAuthState } from './hooks/useAuthState';
|
|
7
|
+
export { createAccount, deactivateAccount, deleteAccount, getAccountReferences, listAccounts, reactivateAccount } from './services/account.api';
|
|
8
|
+
export type { AccountReferences, AccountSummary } from './services/account.api';
|
|
9
|
+
export { takePostLoginRedirect } from './services/sso';
|
|
10
|
+
export type { LoginProviders } from './services/sso';
|
|
11
|
+
export { AuthContext, useAuth } from './state/auth.context';
|
|
12
|
+
export { useSignInMethods } from './state/use-sign-in-methods';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { authFetch } from '../../../lib/api';
|
|
1
|
+
import { authFetch, getToken, setToken } from '../../../lib/api';
|
|
2
2
|
|
|
3
3
|
/** One row of the admin Accounts list (`GET /api/admin/accounts`). */
|
|
4
4
|
export interface AccountSummary {
|
|
@@ -48,17 +48,33 @@ async function readError(res: Response, fallback: string): Promise<string> {
|
|
|
48
48
|
return (body as { error?: string }).error || fallback;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Self-service password change. `currentPassword` is required once one is set.
|
|
53
|
+
* The change ends every session opened before it, this one's included, so the
|
|
54
|
+
* fresh token the server hands back replaces the stored one — but only the
|
|
55
|
+
* one this request sent: the stored token is one key shared by every tab, and
|
|
56
|
+
* a tab that signed in as someone else while this request was in flight has
|
|
57
|
+
* replaced it already. That sign-in is kept; this change's token belongs to
|
|
58
|
+
* a session that tab no longer has.
|
|
59
|
+
*/
|
|
52
60
|
export async function changePassword(
|
|
53
61
|
currentPassword: string | undefined,
|
|
54
62
|
newPassword: string,
|
|
55
63
|
): Promise<void> {
|
|
64
|
+
const sent = getToken();
|
|
56
65
|
const res = await authFetch('/api/auth/change-password', {
|
|
57
66
|
method: 'POST',
|
|
58
67
|
headers: { 'Content-Type': 'application/json' },
|
|
59
68
|
body: JSON.stringify({ currentPassword, newPassword }),
|
|
60
69
|
});
|
|
61
70
|
if (!res.ok) throw new Error(await readError(res, 'Could not change password'));
|
|
71
|
+
const body = (await res.json().catch(() => ({}))) as { token?: unknown };
|
|
72
|
+
// The change is written by now. Only a token the server actually handed
|
|
73
|
+
// back replaces the stored one: an answer without one (a replica from
|
|
74
|
+
// before the change handed tokens back, mid-deploy) must not turn the
|
|
75
|
+
// stored token into the string "undefined" and sign the person out.
|
|
76
|
+
const token = typeof body.token === 'string' && body.token ? body.token : null;
|
|
77
|
+
if (token && getToken() === sent) setToken(token);
|
|
62
78
|
}
|
|
63
79
|
|
|
64
80
|
export async function listAccounts(): Promise<AccountSummary[]> {
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
+
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
3
|
+
import type { PullRequestSummary } from '@bevel-software/platform-shared';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Editing a request's title and description from its dialog: offered to the
|
|
7
|
+
* people the server says may (`viewerCanEdit` — the author, or anyone who may
|
|
8
|
+
* merge it), saved through the PATCH route, and shown at once — in the dialog
|
|
9
|
+
* from a fresh read, and in every list through the stale signal.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const detailMock = vi.hoisted(() => ({ fetchPrDetail: vi.fn() }));
|
|
13
|
+
vi.mock('../../pr/services/pr-detail.api', () => ({ fetchPrDetail: detailMock.fetchPrDetail }));
|
|
14
|
+
vi.mock('../services/change-requests.api', () => ({
|
|
15
|
+
readFileOnBranch: vi.fn(async () => 'branch copy'),
|
|
16
|
+
}));
|
|
17
|
+
vi.mock('../../pr/services/pr-approvals.api', () => ({
|
|
18
|
+
approvePrFile: vi.fn(),
|
|
19
|
+
revertPrFile: vi.fn(),
|
|
20
|
+
unapprovePrFile: vi.fn(),
|
|
21
|
+
}));
|
|
22
|
+
vi.mock('../../pr/services/pr-merge.api', () => ({
|
|
23
|
+
mergePullRequest: vi.fn(),
|
|
24
|
+
refreshChangeRequestFromTarget: vi.fn(),
|
|
25
|
+
}));
|
|
26
|
+
vi.mock('../../pr/services/pr-cancel.api', () => ({
|
|
27
|
+
cancelPullRequest: vi.fn(),
|
|
28
|
+
deleteChangeRequest: vi.fn(),
|
|
29
|
+
}));
|
|
30
|
+
const editApi = vi.hoisted(() => ({ updateChangeRequest: vi.fn() }));
|
|
31
|
+
vi.mock('../../pr/services/pr-edit.api', async (importOriginal) => ({
|
|
32
|
+
...(await importOriginal<typeof import('../../pr/services/pr-edit.api')>()),
|
|
33
|
+
updateChangeRequest: editApi.updateChangeRequest,
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
import { ChangeRequestDialog } from '../components/ChangeRequestDialog';
|
|
37
|
+
import { PR_STALE_EVENT } from '../../../core/events';
|
|
38
|
+
import { GitApiError } from '../../git/services/git.api';
|
|
39
|
+
|
|
40
|
+
const CR: PullRequestSummary = {
|
|
41
|
+
number: 12,
|
|
42
|
+
title: 'Old title',
|
|
43
|
+
authorId: 'abc',
|
|
44
|
+
author: { login: 'user-abc', name: 'Ali' },
|
|
45
|
+
appAuthor: { name: 'Ali' },
|
|
46
|
+
branch: 'ali.raza/draft',
|
|
47
|
+
base: 'main',
|
|
48
|
+
state: 'open',
|
|
49
|
+
createdAt: '2026-08-07T00:00:00.000Z',
|
|
50
|
+
touchedNodePaths: [],
|
|
51
|
+
review: { approvals: 0, changesRequested: 0, pendingLogins: [] },
|
|
52
|
+
url: '/change-requests/12',
|
|
53
|
+
} as unknown as PullRequestSummary;
|
|
54
|
+
|
|
55
|
+
function detail(over: Record<string, unknown> = {}) {
|
|
56
|
+
return {
|
|
57
|
+
...CR,
|
|
58
|
+
body: 'Old reason.\n\n## My own section\n\nDetails.',
|
|
59
|
+
headSha: 'h',
|
|
60
|
+
baseSha: 'b',
|
|
61
|
+
files: [],
|
|
62
|
+
approvals: [],
|
|
63
|
+
mergeableInBevel: false,
|
|
64
|
+
mergeBlockedReasons: [],
|
|
65
|
+
mergeWarnings: [],
|
|
66
|
+
viewerCanBypassMerge: false,
|
|
67
|
+
viewerCanCancel: true,
|
|
68
|
+
viewerCanDelete: false,
|
|
69
|
+
viewerCanEdit: true,
|
|
70
|
+
...over,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
beforeEach(() => {
|
|
75
|
+
detailMock.fetchPrDetail.mockReset();
|
|
76
|
+
editApi.updateChangeRequest.mockReset();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('ChangeRequestDialog: editing the title and description', () => {
|
|
80
|
+
it('offers no Edit control to someone who may not edit', async () => {
|
|
81
|
+
detailMock.fetchPrDetail.mockResolvedValue(detail({ viewerCanEdit: false }));
|
|
82
|
+
render(<ChangeRequestDialog cr={CR} onClose={() => {}} onResolved={() => {}} />);
|
|
83
|
+
expect(await screen.findByText(/Old reason./)).toBeInTheDocument();
|
|
84
|
+
expect(screen.queryByRole('button', { name: 'Edit' })).not.toBeInTheDocument();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('offers the body whole — own headings included; it is the description and nothing else', async () => {
|
|
88
|
+
detailMock.fetchPrDetail.mockResolvedValue(detail());
|
|
89
|
+
render(<ChangeRequestDialog cr={CR} onClose={() => {}} onResolved={() => {}} />);
|
|
90
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Edit' }));
|
|
91
|
+
expect(screen.getByRole('textbox', { name: 'Title' })).toHaveValue('Old title');
|
|
92
|
+
expect(screen.getByRole('textbox', { name: 'Description' })).toHaveValue(
|
|
93
|
+
'Old reason.\n\n## My own section\n\nDetails.',
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('saves only what changed, then shows the new text and refreshes every list', async () => {
|
|
98
|
+
detailMock.fetchPrDetail.mockResolvedValueOnce(detail());
|
|
99
|
+
editApi.updateChangeRequest.mockResolvedValue({ ...CR, title: 'New title' });
|
|
100
|
+
detailMock.fetchPrDetail.mockResolvedValueOnce(
|
|
101
|
+
detail({
|
|
102
|
+
title: 'New title',
|
|
103
|
+
body: 'P2 - Planned\n\nNew reason.',
|
|
104
|
+
}),
|
|
105
|
+
);
|
|
106
|
+
const stale = vi.fn();
|
|
107
|
+
window.addEventListener(PR_STALE_EVENT, stale);
|
|
108
|
+
render(<ChangeRequestDialog cr={CR} onClose={() => {}} onResolved={() => {}} />);
|
|
109
|
+
|
|
110
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Edit' }));
|
|
111
|
+
fireEvent.change(screen.getByRole('textbox', { name: 'Description' }), {
|
|
112
|
+
target: { value: 'P2 - Planned\n\nNew reason.' },
|
|
113
|
+
});
|
|
114
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
|
|
115
|
+
|
|
116
|
+
await waitFor(() =>
|
|
117
|
+
expect(editApi.updateChangeRequest).toHaveBeenCalledWith(12, { description: 'P2 - Planned\n\nNew reason.' }),
|
|
118
|
+
);
|
|
119
|
+
expect(await screen.findByRole('heading', { name: 'New title' })).toBeInTheDocument();
|
|
120
|
+
expect(screen.getByText(/New reason\./)).toBeInTheDocument();
|
|
121
|
+
expect(screen.queryByRole('textbox', { name: 'Description' })).not.toBeInTheDocument();
|
|
122
|
+
expect(detailMock.fetchPrDetail).toHaveBeenLastCalledWith(12, { fresh: true });
|
|
123
|
+
expect(stale).toHaveBeenCalled();
|
|
124
|
+
window.removeEventListener(PR_STALE_EVENT, stale);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('a saved edit stays saved when the follow-up read fails — no error, and every list still refreshes', async () => {
|
|
128
|
+
detailMock.fetchPrDetail.mockResolvedValueOnce(detail());
|
|
129
|
+
editApi.updateChangeRequest.mockResolvedValue({ ...CR, title: 'New title' });
|
|
130
|
+
detailMock.fetchPrDetail.mockRejectedValueOnce(new Error('network down'));
|
|
131
|
+
const stale = vi.fn();
|
|
132
|
+
window.addEventListener(PR_STALE_EVENT, stale);
|
|
133
|
+
render(<ChangeRequestDialog cr={CR} onClose={() => {}} onResolved={() => {}} />);
|
|
134
|
+
|
|
135
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Edit' }));
|
|
136
|
+
fireEvent.change(screen.getByRole('textbox', { name: 'Title' }), { target: { value: 'New title' } });
|
|
137
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
|
|
138
|
+
|
|
139
|
+
await waitFor(() => expect(screen.queryByRole('textbox', { name: 'Title' })).not.toBeInTheDocument());
|
|
140
|
+
expect(stale).toHaveBeenCalled();
|
|
141
|
+
expect(screen.queryByText(/Couldn't save/)).not.toBeInTheDocument();
|
|
142
|
+
expect(screen.queryByText(/network down/)).not.toBeInTheDocument();
|
|
143
|
+
window.removeEventListener(PR_STALE_EVENT, stale);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("shows the server's refusal in its words and keeps the draft", async () => {
|
|
147
|
+
detailMock.fetchPrDetail.mockResolvedValue(detail());
|
|
148
|
+
editApi.updateChangeRequest.mockRejectedValue(
|
|
149
|
+
new GitApiError(409, 'This change request has already been applied; its title and description can no longer be changed.', {}),
|
|
150
|
+
);
|
|
151
|
+
render(<ChangeRequestDialog cr={CR} onClose={() => {}} onResolved={() => {}} />);
|
|
152
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Edit' }));
|
|
153
|
+
fireEvent.change(screen.getByRole('textbox', { name: 'Title' }), { target: { value: 'Newer' } });
|
|
154
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
|
|
155
|
+
expect(await screen.findByRole('alert')).toHaveTextContent('already been applied');
|
|
156
|
+
expect(screen.getByRole('textbox', { name: 'Title' })).toHaveValue('Newer');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('will not save an empty title', async () => {
|
|
160
|
+
detailMock.fetchPrDetail.mockResolvedValue(detail());
|
|
161
|
+
render(<ChangeRequestDialog cr={CR} onClose={() => {}} onResolved={() => {}} />);
|
|
162
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Edit' }));
|
|
163
|
+
fireEvent.change(screen.getByRole('textbox', { name: 'Title' }), { target: { value: ' ' } });
|
|
164
|
+
expect(screen.getByRole('button', { name: 'Save' })).toBeDisabled();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -65,7 +65,6 @@ const DETAIL = {
|
|
|
65
65
|
headSha: 'h',
|
|
66
66
|
baseSha: 'b',
|
|
67
67
|
files: [{ path: 'Docs/a.md', status: 'modified', additions: 1, deletions: 0, isBinary: false, sha: '', rawUrl: '' }],
|
|
68
|
-
comments: [],
|
|
69
68
|
approvals: [APPROVAL],
|
|
70
69
|
mergeableInBevel: true,
|
|
71
70
|
mergeBlockedReasons: [],
|
|
@@ -70,7 +70,6 @@ describe('ChangeRequestDialog: a request with no remaining changes', () => {
|
|
|
70
70
|
headSha: 'h',
|
|
71
71
|
baseSha: 'b',
|
|
72
72
|
files: [],
|
|
73
|
-
comments: [],
|
|
74
73
|
approvals: [],
|
|
75
74
|
mergeableInBevel: true,
|
|
76
75
|
mergeBlockedReasons: [],
|
|
@@ -121,7 +120,6 @@ function detailWith(approvals: FileApprovalState[]) {
|
|
|
121
120
|
sha: '',
|
|
122
121
|
rawUrl: '',
|
|
123
122
|
})),
|
|
124
|
-
comments: [],
|
|
125
123
|
approvals,
|
|
126
124
|
mergeableInBevel: true,
|
|
127
125
|
mergeBlockedReasons: [],
|