From f7465a34481eb5aaaf6cdad1c2bd2202dd92e68b Mon Sep 17 00:00:00 2001 From: Artjoms Stukans Date: Mon, 16 Nov 2026 01:40:01 +0100 Subject: [PATCH 1/4] Ask before every destructive action in the dashboard The first production install found that the People tab's trash icons removed a sign-in application or unlinked an operator at once. An audit of every destructive action found five that did not ask: - Settings > People: remove a sign-in application, unlink an operator - Account allowed people and repository /fix overrides: Remove - Factory tab, allowed people on a work source: Remove - Prompts: Reset to default (deletes the saved custom text) Each now opens ConfirmDialog, which names what goes and what that means. A refused request stays in the dialog, so it can be retried or cancelled. The drift banner's "Take the new default" stays one click: it already shows both texts side by side. The OAuth application form and the operator links table move to their own files so the screens stay small. Tests cover, for each action, that the first click does not call the API, Confirm does and Cancel does not. Part of #391 --- spire-ui/src/components/ActorPicker.test.tsx | 39 ++++- spire-ui/src/components/ActorPicker.tsx | 24 +++- .../src/components/OperatorLinksTable.tsx | 105 ++++++++++++++ .../components/PromptDetail.reset.test.tsx | 79 ++++++++++ spire-ui/src/components/PromptDetail.tsx | 7 +- spire-ui/src/components/ResetPromptButton.tsx | 35 +++++ .../src/components/ScmConnections.test.tsx | 51 ++++++- spire-ui/src/components/ScmConnections.tsx | 136 ++++-------------- spire-ui/src/components/ScmOAuthAppForm.tsx | 101 +++++++++++++ .../src/components/SettingsOperators.test.tsx | 46 ++++++ spire-ui/src/components/SettingsOperators.tsx | 78 +--------- .../repositories/factory/PeopleStep.tsx | 19 ++- .../factory/RepositoryFactory.test.tsx | 18 ++- 13 files changed, 536 insertions(+), 202 deletions(-) create mode 100644 spire-ui/src/components/OperatorLinksTable.tsx create mode 100644 spire-ui/src/components/PromptDetail.reset.test.tsx create mode 100644 spire-ui/src/components/ResetPromptButton.tsx create mode 100644 spire-ui/src/components/ScmOAuthAppForm.tsx diff --git a/spire-ui/src/components/ActorPicker.test.tsx b/spire-ui/src/components/ActorPicker.test.tsx index 620f5cc37..e12c13855 100644 --- a/spire-ui/src/components/ActorPicker.test.tsx +++ b/spire-ui/src/components/ActorPicker.test.tsx @@ -1,4 +1,4 @@ -import { act, fireEvent, screen, within } from '@testing-library/react'; +import { act, fireEvent, screen, waitFor, within } from '@testing-library/react'; import { beforeEach, expect, test, vi } from 'vitest'; import ActorPicker from './ActorPicker'; @@ -116,3 +116,40 @@ test('edits a repository deny with the stored version', async () => { handle: '@TEST-person', providerUserId: '900123', effect: 'DENY', revision: 2, }); }); + +// Removing a person changes who may command the bot, so the row's Remove only asks. +async function askToRemove(repositoryId?: string) { + vi.mocked(api.fetchActors).mockResolvedValue({ revision: 1, actors: [stored] }); + vi.mocked(api.deleteActor).mockResolvedValue(undefined as never); + renderWithQuery(); + const row = await screen.findByRole('button', { name: 'Remove @TEST-person' }); + await waitFor(() => expect(row).toBeEnabled()); + await user.click(row); + return screen.getByRole('dialog'); +} + +test('asks before removing an allowed person, naming what it means', async () => { + const dialog = await askToRemove(); + expect(dialog).toHaveTextContent('Remove @TEST-person from the allowed people? Their review commands and conversations are no longer accepted until they are added again.'); + expect(api.deleteActor).not.toHaveBeenCalled(); +}); + +test('asks before removing a fix override, naming what it means', async () => { + const dialog = await askToRemove('TEST-repo'); + expect(dialog).toHaveTextContent('Remove the override for @TEST-person? Whether they may use /fix on this repository is decided by their push access again.'); + expect(api.deleteActor).not.toHaveBeenCalled(); +}); + +test('removes the person once the dialog is confirmed', async () => { + const dialog = await askToRemove(); + await user.click(within(dialog).getByRole('button', { name: 'Remove' })); + expect(api.deleteActor).toHaveBeenCalledWith('/api/providers/TEST-account/actors', stored, 1); + await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()); +}); + +test('keeps the person when the dialog is cancelled', async () => { + const dialog = await askToRemove(); + await user.click(within(dialog).getByRole('button', { name: 'Cancel' })); + expect(screen.queryByRole('dialog')).toBeNull(); + expect(api.deleteActor).not.toHaveBeenCalled(); +}); diff --git a/spire-ui/src/components/ActorPicker.tsx b/spire-ui/src/components/ActorPicker.tsx index b5ea58ab0..0dd6a822a 100644 --- a/spire-ui/src/components/ActorPicker.tsx +++ b/spire-ui/src/components/ActorPicker.tsx @@ -1,8 +1,9 @@ import { useEffect, useMemo, useState } from 'react'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import { invalidateLive, writeLive } from '../liveCache'; -import { actorLabel, actorPath, actorsKey, deleteActor, fetchActors, resolveActor, saveActor, type Actor, type ActorPolicy } from './actorsApi'; +import { actorLabel, actorPath, actorsKey, deleteActor, fetchActors, resolveActor, saveActor, type Actor, type ActorDisplay, type ActorPolicy } from './actorsApi'; import { fetchRepositories, repositoriesKey } from './repositories/repositoriesApi'; +import ConfirmDialog from './ConfirmDialog'; interface Props { accountId: string; @@ -36,6 +37,8 @@ export default function ActorPicker({ accountId, accountType, repositoryId }: Pr ?? (read.error ? String(read.error) : null) ?? (scopeAsked && repositoriesRead.error ? String(repositoriesRead.error) : null); const [busy, setBusy] = useState(false); + // Removing a person changes who may command the bot, so it waits for a yes. + const [removing, setRemoving] = useState(null); async function load(refresh = false) { if (!refresh) { await invalidateLive(client, actorsKey(path)); return; } @@ -65,6 +68,13 @@ export default function ActorPicker({ accountId, accountType, repositoryId }: Pr } catch (failure) { setError(String(failure)); } finally { setBusy(false); } } + // A failed remove stays in the dialog, so it can be tried again or cancelled. + async function remove(actor: ActorDisplay) { + if (!policy) return; + setError(null); + await deleteActor(path, actor, repositoryId ? actor.revision : policy.revision); + await load(); + } function chooseScope() { // Each click asks again, as it always did; the cached list fills the select meanwhile. if (scopeAsked) void invalidateLive(client, repositoriesKey); @@ -95,12 +105,14 @@ export default function ActorPicker({ accountId, accountType, repositoryId }: Pr {error &&

{error}

} {policy ?
    {policy.actors.map(actor =>
  • {actorLabel(actor)} — {actor.effect === 'DENY' ? 'Denied' : 'Allowed'}{actor.stale && · stale display; refresh by ID} - +
  • )}
:

People have not loaded.

} + {removing && remove(removing)} onClose={() => setRemoving(null)} />} ; } diff --git a/spire-ui/src/components/OperatorLinksTable.tsx b/spire-ui/src/components/OperatorLinksTable.tsx new file mode 100644 index 000000000..eeaf0ee11 --- /dev/null +++ b/spire-ui/src/components/OperatorLinksTable.tsx @@ -0,0 +1,105 @@ +import { useState } from 'react'; +import { Trash2 } from 'lucide-react'; +import { ObservedAuthor, OperatorIdentityLink, SeenOperator, unlinkOperatorIdentity } from '../api'; +import ConfirmDialog from './ConfirmDialog'; +import { NameWithId } from './NameWithId'; + +interface Props { + links: OperatorIdentityLink[]; + operators: SeenOperator[]; + candidates: ObservedAuthor[]; + onUnlinked: () => void; +} + +/** + * The operator-to-account links, each with an Unlink that waits for a yes: an unlinked operator stops seeing their own + * numbers for that account until somebody links it again. + */ +export function OperatorLinksTable({ links, operators, candidates, onUnlinked }: Props) { + const [unlinking, setUnlinking] = useState(null); + + // A failed unlink stays in the dialog, so it can be tried again or cancelled. + const unlink = async (link: OperatorIdentityLink) => { + await unlinkOperatorIdentity(link.oidcSubject, link.providerType); + onUnlinked(); + }; + + return ( + <> + + + + + + + + + + {links.map((link) => ( + + + + + + + ))} + +
OperatorPlatformSCM account +
+ + {link.providerType} + + + +
+ + {unlinking && ( + unlink(unlinking)} + onClose={() => setUnlinking(null)} + /> + )} + + ); +} + +/** + * Name first, username second, and the opaque subject only when there is nothing else to show. + * + * The username is empty when the identity provider's login is an email address (it is never stored), + * so the name stands alone then. + */ +export function labelFor(operator: SeenOperator): string { + if (operator.displayName && operator.username && operator.displayName !== operator.username) { + return `${operator.displayName} · ${operator.username}`; + } + return operator.displayName || operator.username || operator.subject; +} + +function operatorName(operators: SeenOperator[], subject: string): string { + const match = operators.find((o) => o.subject === subject); + return match ? labelFor(match) : subject; +} + +/** + * The login the operator proved by signing in, else the name the reviews recorded, else the id + * (a link made by hand for an author no review has seen). + */ +function nameFor(candidates: ObservedAuthor[], link: OperatorIdentityLink): string { + if (link.authorHandle) return link.authorHandle; + const match = candidates.find( + (c) => c.providerType === link.providerType && c.authorId === link.authorId, + ); + return match ? match.displayName : link.authorId; +} diff --git a/spire-ui/src/components/PromptDetail.reset.test.tsx b/spire-ui/src/components/PromptDetail.reset.test.tsx new file mode 100644 index 000000000..6f4914faf --- /dev/null +++ b/spire-ui/src/components/PromptDetail.reset.test.tsx @@ -0,0 +1,79 @@ +import { describe, it, expect, vi } from 'vitest'; +import { fireEvent, screen, waitFor, within } from '@testing-library/react'; +import { MemoryRouter, Route, Routes } from 'react-router'; +import PromptDetail from './PromptDetail'; +import * as api from '../api'; +import { renderWithQuery } from '../test/queryWrapper'; + +/** + * Reset to default deletes the custom text saved for the scope, and nothing keeps a copy, so the + * button only asks; the prompt is reset when the dialog's Reset is pressed. + */ + +function customizedView(): api.PromptView { + return { + kind: 'review', + scope: '*', + inheritedFrom: 'global', + customized: true, + system: 'TEST persona', + body: 'Diff:\n{{diff}}', + updatedAt: '2026-08-20T10:00:00Z', + palette: [], + lockedSuffixPreview: 'TEST suffix', + baseKnown: true, + defaultDrifted: false, + currentDefaultSystem: 'TEST default persona', + currentDefaultBody: 'Diff:\n{{diff}}', + baseSystem: 'TEST default persona', + baseBody: 'Diff:\n{{diff}}', + }; +} + +function renderPrompt() { + vi.spyOn(api, 'fetchPrompt').mockResolvedValue(customizedView()); + renderWithQuery( + + + } /> + + , + ); +} + +describe('reset to default', () => { + it('asks first, naming the prompt and what is lost', async () => { + const reset = vi.spyOn(api, 'resetPrompt').mockResolvedValue(); + renderPrompt(); + + fireEvent.click(await screen.findByRole('button', { name: /reset to default/i })); + + expect(screen.getByRole('dialog')).toHaveTextContent( + 'Reset Review to its default? The custom text saved for this scope is deleted and cannot be restored.', + ); + expect(reset).not.toHaveBeenCalled(); + }); + + it('resets once the dialog is confirmed', async () => { + const reset = vi.spyOn(api, 'resetPrompt').mockResolvedValue(); + renderPrompt(); + + fireEvent.click(await screen.findByRole('button', { name: /reset to default/i })); + fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Reset' })); + + await waitFor(() => expect(reset).toHaveBeenCalledWith('review', '*')); + await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()); + }); + + it('keeps the custom text when the dialog is cancelled', async () => { + const reset = vi.spyOn(api, 'resetPrompt').mockResolvedValue(); + renderPrompt(); + + fireEvent.click(await screen.findByRole('button', { name: /reset to default/i })); + fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Cancel' })); + + expect(screen.queryByRole('dialog')).toBeNull(); + expect(reset).not.toHaveBeenCalled(); + expect(screen.getByDisplayValue('TEST persona')).toBeInTheDocument(); + }); +}); diff --git a/spire-ui/src/components/PromptDetail.tsx b/spire-ui/src/components/PromptDetail.tsx index aa17d40af..bb0625adb 100644 --- a/spire-ui/src/components/PromptDetail.tsx +++ b/spire-ui/src/components/PromptDetail.tsx @@ -1,13 +1,14 @@ import { useEffect, useRef, useState } from 'react'; import { hashKey, useQuery, useQueryClient } from '@tanstack/react-query'; import { useNavigate, useParams, useSearchParams } from 'react-router'; -import { AlertTriangle, ArrowLeft, FileText, RotateCcw } from 'lucide-react'; +import { AlertTriangle, ArrowLeft, FileText } from 'lucide-react'; import { acceptPromptDefault, fetchPrompt, GLOBAL_SCOPE, promptKey, promptsKey, resetPrompt, savePrompt, type PromptView } from '../api'; import { updateLive, writeLive } from '../liveCache'; import AutoTextarea from './AutoTextarea'; import PromptDriftBanner, { type PromptDrift } from './PromptDriftBanner'; import ProvenanceLine from './PromptProvenance'; import PromptSamplePicker from './PromptSamplePicker'; +import ResetPromptButton from './ResetPromptButton'; import { KIND_LABELS } from './promptKinds'; function driftOf(v: PromptView): PromptDrift { @@ -277,9 +278,7 @@ function PromptEditor({ initial }: { initial: PromptView }) { )}
- + + {asking && ( + setAsking(false)} + /> + )} + + ); +} diff --git a/spire-ui/src/components/ScmConnections.test.tsx b/spire-ui/src/components/ScmConnections.test.tsx index 3b8113bc8..7a96f15f5 100644 --- a/spire-ui/src/components/ScmConnections.test.tsx +++ b/spire-ui/src/components/ScmConnections.test.tsx @@ -1,5 +1,5 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'; -import { render, screen, waitFor, fireEvent } from '@testing-library/react'; +import { render, screen, waitFor, fireEvent, within } from '@testing-library/react'; import { ScmConnections } from './ScmConnections'; import * as api from '../api'; import { queryWrapper } from '../test/queryWrapper'; @@ -191,4 +191,53 @@ describe('ScmConnections', () => { await waitFor(() => expect(screen.getByRole('alert').textContent).toMatch(/TEST-REJECTED/)); }); + + /** + * Removing an application stops every operator proving their account on that platform, so the + * trash icon only asks; nothing is deleted until the dialog's Remove is pressed. + */ + it('asks before removing a sign-in application, naming what it means', async () => { + const remove = vi.spyOn(api, 'deleteScmOAuthApp').mockResolvedValue(undefined); + render(, { wrapper: queryWrapper() }); + + fireEvent.click(await screen.findByRole('button', { name: 'Remove the github sign-in application' })); + + const dialog = screen.getByRole('dialog'); + expect(dialog).toHaveTextContent( + 'Remove the GitHub sign-in application? Operators can no longer prove their GitHub account until it is set up again.', + ); + expect(remove).not.toHaveBeenCalled(); + }); + + it('removes the application once the dialog is confirmed', async () => { + const remove = vi.spyOn(api, 'deleteScmOAuthApp').mockResolvedValue(undefined); + render(, { wrapper: queryWrapper() }); + + fireEvent.click(await screen.findByRole('button', { name: 'Remove the github sign-in application' })); + fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Remove' })); + + await waitFor(() => expect(remove).toHaveBeenCalledWith('github')); + await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()); + }); + + it('keeps the application when the dialog is cancelled', async () => { + const remove = vi.spyOn(api, 'deleteScmOAuthApp').mockResolvedValue(undefined); + render(, { wrapper: queryWrapper() }); + + fireEvent.click(await screen.findByRole('button', { name: 'Remove the github sign-in application' })); + fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Cancel' })); + + expect(screen.queryByRole('dialog')).toBeNull(); + expect(remove).not.toHaveBeenCalled(); + }); + + it('keeps the dialog open with the reason when the removal is refused', async () => { + vi.spyOn(api, 'deleteScmOAuthApp').mockRejectedValue(new Error('TEST-REFUSED')); + render(, { wrapper: queryWrapper() }); + + fireEvent.click(await screen.findByRole('button', { name: 'Remove the github sign-in application' })); + fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Remove' })); + + expect(await within(screen.getByRole('dialog')).findByText('TEST-REFUSED')).toBeTruthy(); + }); }); diff --git a/spire-ui/src/components/ScmConnections.tsx b/spire-ui/src/components/ScmConnections.tsx index 1c557c627..534eaa929 100644 --- a/spire-ui/src/components/ScmConnections.tsx +++ b/spire-ui/src/components/ScmConnections.tsx @@ -1,12 +1,14 @@ -import { FormEvent, useState } from 'react'; +import { useState } from 'react'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import { KeyRound, Trash2 } from 'lucide-react'; -import { ScmOAuthApp, deleteScmOAuthApp, fetchScmOAuthApps, saveScmOAuthApp, scmOAuthAppsKey } from '../api'; +import { ScmOAuthApp, deleteScmOAuthApp, fetchScmOAuthApps, scmOAuthAppsKey } from '../api'; import { invalidateLive } from '../liveCache'; +import ConfirmDialog from './ConfirmDialog'; +import CopyField from './CopyField'; +import { oauthSetupGuide } from './oauthAppSetup'; +import { ScmOAuthAppForm } from './ScmOAuthAppForm'; const NO_APPS: ScmOAuthApp[] = []; -import CopyField from './CopyField'; -import { baseUrlHint, oauthSetupGuide } from './oauthAppSetup'; /** * The OAuth applications operators sign into to prove which SCM account is theirs. @@ -33,17 +35,16 @@ export function ScmConnections() { const [actionError, setError] = useState(null); const error = actionError ?? (read.error ? (read.error instanceof Error ? read.error.message : String(read.error)) : null); const [open, setOpen] = useState(null); + // Removing an application stops every operator proving their account on that platform, so it waits for a yes. + const [removing, setRemoving] = useState(null); const reload = () => invalidateLive(client, scmOAuthAppsKey); + // A failed delete stays in the dialog; a failed re-read shows through the read's own error. const remove = async (providerType: string) => { setError(null); - try { - await deleteScmOAuthApp(providerType); - await reload(); - } catch (e: unknown) { - setError(e instanceof Error ? e.message : String(e)); - } + await deleteScmOAuthApp(providerType); + void reload(); }; return ( @@ -103,10 +104,22 @@ export function ScmConnections() { setRereading(true); void reload().finally(() => setRereading(false)); }} - onDelete={() => void remove(app.providerType)} + onDelete={() => setRemoving(app)} onError={setError} /> ))} + + {removing && ( + remove(removing.providerType)} + onClose={() => setRemoving(null)} + /> + )}
); } @@ -164,89 +177,16 @@ function AppRow({ {guide && } - + )} ); } -/** - * The form of one platform. Mounted only while its row is open, so its fields start from the row as last read, not as - * it was when the page first drew it. - */ -function AppForm({ app, onSaved, onError }: { app: ScmOAuthApp; onSaved: () => void; onError: (message: string) => void }) { - const [clientId, setClientId] = useState(app.clientId); - const [clientSecret, setClientSecret] = useState(''); - const [webBaseUrl, setWebBaseUrl] = useState(app.webBaseUrl ?? ''); - const [apiBaseUrl, setApiBaseUrl] = useState(app.apiBaseUrl ?? ''); - const [saving, setSaving] = useState(false); - - const submit = async (event: FormEvent) => { - event.preventDefault(); - setSaving(true); - try { - // clientSecret is sent as typed, and blank means KEEP. Sending '' would wipe a working - // credential the moment somebody edited only a base URL. - await saveScmOAuthApp({ providerType: app.providerType, webBaseUrl, apiBaseUrl, clientId, clientSecret }); - setClientSecret(''); - onSaved(); - } catch (e: unknown) { - onError(e instanceof Error ? e.message : String(e)); - } finally { - setSaving(false); - } - }; - - return ( -
- - - - - -
- ); +/** The platform as it names itself, the way the row shows it. */ +function platformName(providerType: string): string { + return oauthSetupGuide(providerType)?.providerLabel ?? providerType; } /** The platform's own portal, step by step — the same shape Settings → Repositories uses. */ @@ -282,23 +222,3 @@ function SetupChecklist({ providerType }: { providerType: string }) { ); } - -/** - * What the client id looks like on each platform. - * - *

Only a shape, never a value that could be mistaken for a real credential — the placeholders are - * the platform's own field name rather than a plausible-looking id. - */ -function placeholderFor(providerType: string, field: 'id'): string { - if (field !== 'id') { - return ''; - } - switch (providerType) { - case 'bitbucket-cloud': - return 'the consumer’s Key'; - case 'gitlab': - return 'the Application ID'; - default: - return 'the Client ID'; - } -} diff --git a/spire-ui/src/components/ScmOAuthAppForm.tsx b/spire-ui/src/components/ScmOAuthAppForm.tsx new file mode 100644 index 000000000..5f9e4f855 --- /dev/null +++ b/spire-ui/src/components/ScmOAuthAppForm.tsx @@ -0,0 +1,101 @@ +import { FormEvent, useState } from 'react'; +import { ScmOAuthApp, saveScmOAuthApp } from '../api'; +import { baseUrlHint } from './oauthAppSetup'; + +/** + * The form of one platform. Mounted only while its row is open, so its fields start from the row as last read, not as + * it was when the page first drew it. + */ +export function ScmOAuthAppForm({ app, onSaved, onError }: { app: ScmOAuthApp; onSaved: () => void; onError: (message: string) => void }) { + const [clientId, setClientId] = useState(app.clientId); + const [clientSecret, setClientSecret] = useState(''); + const [webBaseUrl, setWebBaseUrl] = useState(app.webBaseUrl ?? ''); + const [apiBaseUrl, setApiBaseUrl] = useState(app.apiBaseUrl ?? ''); + const [saving, setSaving] = useState(false); + + const submit = async (event: FormEvent) => { + event.preventDefault(); + setSaving(true); + try { + // clientSecret is sent as typed, and blank means KEEP. Sending '' would wipe a working + // credential the moment somebody edited only a base URL. + await saveScmOAuthApp({ providerType: app.providerType, webBaseUrl, apiBaseUrl, clientId, clientSecret }); + setClientSecret(''); + onSaved(); + } catch (e: unknown) { + onError(e instanceof Error ? e.message : String(e)); + } finally { + setSaving(false); + } + }; + + return ( +

+ + + + + +
+ ); +} + +/** + * What the client id looks like on each platform. + * + *

Only a shape, never a value that could be mistaken for a real credential — the placeholders are + * the platform's own field name rather than a plausible-looking id. + */ +function placeholderFor(providerType: string, field: 'id'): string { + if (field !== 'id') { + return ''; + } + switch (providerType) { + case 'bitbucket-cloud': + return 'the consumer’s Key'; + case 'gitlab': + return 'the Application ID'; + default: + return 'the Client ID'; + } +} diff --git a/spire-ui/src/components/SettingsOperators.test.tsx b/spire-ui/src/components/SettingsOperators.test.tsx index 91a697f9a..b1773e59a 100644 --- a/spire-ui/src/components/SettingsOperators.test.tsx +++ b/spire-ui/src/components/SettingsOperators.test.tsx @@ -227,4 +227,50 @@ describe('SettingsOperators', () => { await waitFor(() => expect(screen.getByRole('alert').textContent).toMatch(/TEST-REJECTED/)); }); + + /** + * Unlinking stops an operator seeing their own numbers for that account, so the trash icon only + * asks; nothing is unlinked until the dialog's Unlink is pressed. + */ + describe('unlinking', () => { + beforeEach(() => { + vi.spyOn(api, 'fetchOperatorIdentities').mockResolvedValue([ + { oidcSubject: 'TEST-SUBJECT-1', providerType: 'github', authorId: '3218389', authorHandle: 'TEST-handle' }, + ]); + }); + + it('asks first, naming the operator and the account', async () => { + const unlink = vi.spyOn(api, 'unlinkOperatorIdentity').mockResolvedValue(undefined); + render(, { wrapper: queryWrapper() }); + + fireEvent.click(await screen.findByRole('button', { name: 'Unlink TEST-SUBJECT-1 on github' })); + + expect(screen.getByRole('dialog')).toHaveTextContent( + 'Unlink TEST Operator One · test-user-one from github · TEST-handle?', + ); + expect(unlink).not.toHaveBeenCalled(); + }); + + it('unlinks once the dialog is confirmed', async () => { + const unlink = vi.spyOn(api, 'unlinkOperatorIdentity').mockResolvedValue(undefined); + render(, { wrapper: queryWrapper() }); + + fireEvent.click(await screen.findByRole('button', { name: 'Unlink TEST-SUBJECT-1 on github' })); + fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Unlink' })); + + await waitFor(() => expect(unlink).toHaveBeenCalledWith('TEST-SUBJECT-1', 'github')); + await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()); + }); + + it('keeps the link when the dialog is cancelled', async () => { + const unlink = vi.spyOn(api, 'unlinkOperatorIdentity').mockResolvedValue(undefined); + render(, { wrapper: queryWrapper() }); + + fireEvent.click(await screen.findByRole('button', { name: 'Unlink TEST-SUBJECT-1 on github' })); + fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Cancel' })); + + expect(screen.queryByRole('dialog')).toBeNull(); + expect(unlink).not.toHaveBeenCalled(); + }); + }); }); diff --git a/spire-ui/src/components/SettingsOperators.tsx b/spire-ui/src/components/SettingsOperators.tsx index a672c64dd..0ba373122 100644 --- a/spire-ui/src/components/SettingsOperators.tsx +++ b/spire-ui/src/components/SettingsOperators.tsx @@ -1,6 +1,6 @@ import { FormEvent, useState } from 'react'; import { useQuery, useQueryClient } from '@tanstack/react-query'; -import { Trash2, UsersRound } from 'lucide-react'; +import { UsersRound } from 'lucide-react'; import { ObservedAuthor, OperatorIdentityLink, @@ -10,11 +10,10 @@ import { fetchSeenOperators, operatorsKey, linkOperatorIdentity, - unlinkOperatorIdentity, } from '../api'; import { invalidateLive } from '../liveCache'; import AccountsTabs from './AccountsTabs'; -import { NameWithId } from './NameWithId'; +import { OperatorLinksTable, labelFor } from './OperatorLinksTable'; import { ScmConnections } from './ScmConnections'; /** @@ -84,16 +83,6 @@ export function SettingsOperators() { } }; - const remove = async (link: OperatorIdentityLink) => { - setError(null); - try { - await unlinkOperatorIdentity(link.oidcSubject, link.providerType); - await reload(); - } catch (e: unknown) { - setError(e instanceof Error ? e.message : String(e)); - } - }; - const nothingToPick = operators.length === 0 || candidates.length === 0; return ( @@ -168,38 +157,7 @@ export function SettingsOperators() { )} {links !== null && links.length > 0 && ( - - - - - - - - - - {links.map((link) => ( - - - - - - - ))} - -
OperatorPlatformSCM account -
- - {link.providerType} - - - -
+ void reload()} /> )} @@ -217,33 +175,3 @@ export function SettingsOperators() { function keyOf(author: ObservedAuthor): string { return `${author.providerType}|${author.authorId}`; } - -/** - * Name first, username second, and the opaque subject only when there is nothing else to show. - * - * The username is empty when the identity provider's login is an email address (it is never stored), - * so the name stands alone then. - */ -function labelFor(operator: SeenOperator): string { - if (operator.displayName && operator.username && operator.displayName !== operator.username) { - return `${operator.displayName} · ${operator.username}`; - } - return operator.displayName || operator.username || operator.subject; -} - -function operatorName(operators: SeenOperator[], subject: string): string { - const match = operators.find((o) => o.subject === subject); - return match ? labelFor(match) : subject; -} - -/** - * The login the operator proved by signing in, else the name the reviews recorded, else the id - * (a link made by hand for an author no review has seen). - */ -function nameFor(candidates: ObservedAuthor[], link: OperatorIdentityLink): string { - if (link.authorHandle) return link.authorHandle; - const match = candidates.find( - (c) => c.providerType === link.providerType && c.authorId === link.authorId, - ); - return match ? match.displayName : link.authorId; -} diff --git a/spire-ui/src/components/repositories/factory/PeopleStep.tsx b/spire-ui/src/components/repositories/factory/PeopleStep.tsx index a90cc72ef..ffeaeca70 100644 --- a/spire-ui/src/components/repositories/factory/PeopleStep.tsx +++ b/spire-ui/src/components/repositories/factory/PeopleStep.tsx @@ -1,6 +1,7 @@ import { useEffect, useRef, useState } from 'react'; import { actorLabel, type ActorResult } from '../../actorsApi'; import * as api from '../../work-items/workSourcesApi'; +import ConfirmDialog from '../../ConfirmDialog'; import SettingField from '../../SettingField'; import FactoryStep from './FactoryStep'; @@ -63,12 +64,15 @@ function AllowPerson({ source, cancelled, changed }: { source: api.WorkSource; c export default function PeopleStep({ sources, open, setOpen, changed }: Props) { // Holds the person being removed, so only that row reports work — not every row at once. - const [busy, setBusy] = useState(null), [error, setError] = useState(''); + const [busy, setBusy] = useState(null); + // Removing a person stops their labels starting work, so it waits for a yes. + const [removing, setRemoving] = useState<{ source: api.WorkSource; id: string; label: string } | null>(null); const counted = sources.some(source => source.enabled && source.allowedPeople.length > 0); - async function remove(source: api.WorkSource, id: string, label: string) { - setBusy(id); setError(''); + // A failed remove stays in the dialog, so it can be tried again or cancelled. + async function remove({ source, id, label }: { source: api.WorkSource; id: string; label: string }) { + setBusy(id); try { await api.removeWorkActor(source, id); changed(`Removed ${label} from ${source.name}.`); } - catch (failure) { setError(String(failure)); } finally { setBusy(null); } + finally { setBusy(null); } } return {source.allowedPeople.map(person =>

  • {actorLabel(person)}{person.providerUserId}
  • )} {open === `people:${source.id}` ? setOpen(null)} changed={changed} /> : } )} - {error &&

    {error}

    } + {removing && remove(removing)} onClose={() => setRemoving(null)} />} ; } diff --git a/spire-ui/src/components/repositories/factory/RepositoryFactory.test.tsx b/spire-ui/src/components/repositories/factory/RepositoryFactory.test.tsx index b9ea0a856..d9e153b59 100644 --- a/spire-ui/src/components/repositories/factory/RepositoryFactory.test.tsx +++ b/spire-ui/src/components/repositories/factory/RepositoryFactory.test.tsx @@ -53,8 +53,24 @@ describe('people', () => { const people = within(await step(2)); expect(people.getByText('@TEST-person')).toBeInTheDocument(); expect(people.getByText('900123')).toHaveClass('prov-sub'); - fireEvent.click(people.getByRole('button', { name: 'Remove @TEST-person' })); + }); + // Removing a person stops their labels starting work, so the button only asks; the dialog's Remove does it. + it('removes an allowed person only after the dialog is confirmed', async () => { + renderFactory(); + fireEvent.click(within(await step(2)).getByRole('button', { name: 'Remove @TEST-person' })); + const dialog = screen.getByRole('dialog'); + expect(dialog).toHaveTextContent('Remove @TEST-person from TEST-source name? Labels they add no longer start work.'); + expect(sources.removeWorkActor).not.toHaveBeenCalled(); + fireEvent.click(within(dialog).getByRole('button', { name: 'Remove' })); await waitFor(() => expect(sources.removeWorkActor).toHaveBeenCalledWith(source(), '900123')); + await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()); + }); + it('keeps an allowed person when the dialog is cancelled', async () => { + renderFactory(); + fireEvent.click(within(await step(2)).getByRole('button', { name: 'Remove @TEST-person' })); + fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Cancel' })); + expect(screen.queryByRole('dialog')).toBeNull(); + expect(sources.removeWorkActor).not.toHaveBeenCalled(); }); it('allows the one person a lookup finds, naming them on the button, with the source revision', async () => { vi.spyOn(sources, 'resolveWorkActor').mockResolvedValue({ status: 'FOUND', actors: [{ providerUserId: '900456', handle: 'TEST-new', displayName: 'TEST-new' }], detail: null }); From 8c537284da12b3929e5a0514b2970a991764546c Mon Sep 17 00:00:00 2001 From: Artjoms Stukans Date: Mon, 16 Nov 2026 01:40:01 +0100 Subject: [PATCH 2/4] Document proxy manager settings from the first install nginx proxy manager is a second nginx in front of the dashboard's own, so it needs the same limits. Without the header buffers the sign-in callback, which sets the session as several large cookies, answered 502 "upstream sent too big header" on the first production install (2026-11-15). The timeouts keep the idle WebSockets open and the body size lets a large webhook through. Adds the symptom to the troubleshooting table and a HISTORY entry for the confirmations. Part of #391 --- docs/HISTORY.md | 10 ++++++++++ docs/TLS.md | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/docs/HISTORY.md b/docs/HISTORY.md index 73a620925..d3703eec5 100644 --- a/docs/HISTORY.md +++ b/docs/HISTORY.md @@ -2528,3 +2528,13 @@ lives in `docs/`, the locked decisions in `docs/DECISIONS.md`, and claims no tes login the forge reported (`Author.username`, never the email, dropped if it looks like one), the identity list returns it, and the People table and the My activity chips show it with the id as fallback; a link made by hand keeps null, and a hand relink of the same account keeps the observed login. A name equal to its id is shown once. + +- **Destructive actions ask first (2026-11-16, Part of #391).** The first production install found that the trash + icons on the People tab acted at once. An audit of every destructive action in the dashboard found five that did + not ask: removing a sign-in application, unlinking an operator's SCM account, removing a person from an account's + allowed people or a repository's /fix overrides, removing an allowed person from a work source, and Reset to + default on a prompt. Each now opens `ConfirmDialog`, which names what goes and what that means; a refused request + stays in the dialog. The drift banner's "Take the new default" stays one click, as it already shows both texts. + `ScmOAuthAppForm` and `OperatorLinksTable` moved out of their screens to keep the files small. docs/TLS.md now gives + nginx proxy manager's advanced settings from that install: without the header buffers the sign-in callback + answered 502 "upstream sent too big header". diff --git a/docs/TLS.md b/docs/TLS.md index 6df6fe346..08b44e931 100644 --- a/docs/TLS.md +++ b/docs/TLS.md @@ -227,6 +227,30 @@ Configured through its UI rather than a file, so as a settings list: | SSL certificate | Let's Encrypt, or your own | | Force SSL | on | | HTTP/2 Support | optional | +| Advanced → Custom Nginx Configuration | **required** — the six lines below | + +```nginx +proxy_buffer_size 16k; +proxy_buffers 8 16k; +large_client_header_buffers 4 32k; +proxy_read_timeout 3600s; +proxy_send_timeout 3600s; +client_max_body_size 25m; +``` + +These match the dashboard's own proxy (`spire-ui/nginx/default.conf.template`), and proxy manager +needs them for the same reasons, because it is a second nginx in front of that one: + +- **The buffers.** The sign-in callback answers with the operator session as several large + `Set-Cookie` headers, and the browser sends them back as one large `Cookie` header. At nginx's + 4k/8k defaults the callback fails with a bare 502 and `upstream sent too big header` in proxy + manager's log, while every Code Spire service logs nothing, because each one answered correctly. + Proven on the first production install (2026-11-15): sign-in returned 502 until these three lines + were added. +- **The timeouts.** The WebSockets are idle between events; at the 60-second default they reconnect + every minute (see [Long-lived connections](#long-lived-connections)). +- **The body size.** An SCM webhook for a large pull request exceeds proxy manager's 1 MB default, + and the SCM records a failed delivery. Proxy manager sends `X-Forwarded-Proto` and preserves `Host` by default, satisfying requirements 1 and 2 with no custom configuration. Give the identity provider its own proxy host under requirement 5. @@ -348,6 +372,7 @@ Each of these is silent in at least one component, which is why the symptom is t | Login completes, then bounces back to the login screen | The browser is discarding a `Secure` cookie over a non-trustworthy origin. You are on plain HTTP somewhere other than a loopback address. | | Identity provider rejects the redirect | Either `redirect_uri` is `http://` (requirement 1 or 4), or it is correct and simply not registered for the client (requirement 5). Check which before changing proxy settings — with the bundled realm, an unregistered callback is the likelier cause. | | Login redirects to an address the browser cannot resolve | The IdP is advertising a hostname only the containers can reach — requirement 5, point 1. | +| Sign-in callback answers 502, the terminator logs `upstream sent too big header` | The terminator's header buffers are at nginx's defaults and the session cookies do not fit. Raise them as in [nginx proxy manager](#nginx-proxy-manager). | | Login round-trip lands on a backend port | `Host` was rewritten — requirement 2. | | Services refuse to start | `SPIRE_TRUSTED_PROXIES` is unset — requirement 4. This one is loud, by design. | | Everything starts, but `redirect_uri` is `http://` anyway | `SPIRE_TRUSTED_PROXIES` is *set but wrong* — it does not cover the dashboard's actual address, so the headers are distrusted. A Docker range carried into Kubernetes does this. | From 757d8a1cb94799a87e184aa8fe59a720ce3a17e5 Mon Sep 17 00:00:00 2001 From: Artjoms Stukans Date: Mon, 16 Nov 2026 01:48:58 +0100 Subject: [PATCH 3/4] Move the legacy entry from ScmConnections to its extracted form The sign-in application form moved out of ScmConnections.tsx unchanged, taking its settings-convention debt with it. The contract test's legacy list now names the file that holds the form, so it neither flags the moved form as new debt nor keeps a screen that no longer owes anything. Part of #391 --- spire-ui/src/settingsTables.contract.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spire-ui/src/settingsTables.contract.test.ts b/spire-ui/src/settingsTables.contract.test.ts index bb380772d..d3a95d9ca 100644 --- a/spire-ui/src/settingsTables.contract.test.ts +++ b/spire-ui/src/settingsTables.contract.test.ts @@ -78,7 +78,9 @@ const fieldComponent = (file: string) => FIELD_COMPONENTS.some(name => file.ends * means a new screen repeated a mistake these rules exist to stop. Recorded 2026-09-14. */ const LEGACY_SCREENS = [ - 'ProviderFormModal.tsx', 'SettingsOperators.tsx', 'ScmConnections.tsx', 'SettingsWebhookRepos.tsx', + // ScmOAuthAppForm.tsx is ScmConnections.tsx's legacy form, moved out unchanged (2026-11-16) so the + // screen fits its size limit; the debt moved with it, it did not grow. + 'ProviderFormModal.tsx', 'SettingsOperators.tsx', 'ScmOAuthAppForm.tsx', 'SettingsWebhookRepos.tsx', 'SettingsLlmProviders.tsx', 'SettingsLlmModelForm.tsx', 'SettingsContextProviders.tsx', // Field groups of the legacy forms above. They were always in the same debt; the field rule only // saw them once it stopped being limited to screens (2026-09-15). They leave with their forms. From b9b92f5d3cd3f899468155a91594d86a9f294236 Mon Sep 17 00:00:00 2001 From: Artjoms Stukans Date: Mon, 16 Nov 2026 02:00:23 +0100 Subject: [PATCH 4/4] Move the confirmation tests into their own files Review of #429 found the unlink and remove-person cases pushed SettingsOperators.test.tsx and RepositoryFactory.test.tsx past the file-size limit. They now live in OperatorLinksTable.test.tsx, next to the component that owns the dialog, and PeopleStepConfirm.test.tsx, which reuses the factory test setup. Both older files are back below their previous length. TLS.md no longer says proxy manager needs no custom configuration at all: only requirements 1 and 2 need none; the Advanced lines cover the buffers, timeouts and body size. Part of #391 --- docs/TLS.md | 4 +- .../components/OperatorLinksTable.test.tsx | 51 +++++++++++++++++++ .../src/components/SettingsOperators.test.tsx | 46 ----------------- .../factory/PeopleStepConfirm.test.tsx | 33 ++++++++++++ .../factory/RepositoryFactory.test.tsx | 18 ------- 5 files changed, 86 insertions(+), 66 deletions(-) create mode 100644 spire-ui/src/components/OperatorLinksTable.test.tsx create mode 100644 spire-ui/src/components/repositories/factory/PeopleStepConfirm.test.tsx diff --git a/docs/TLS.md b/docs/TLS.md index 08b44e931..2a81a9a8e 100644 --- a/docs/TLS.md +++ b/docs/TLS.md @@ -252,8 +252,8 @@ needs them for the same reasons, because it is a second nginx in front of that o - **The body size.** An SCM webhook for a large pull request exceeds proxy manager's 1 MB default, and the SCM records a failed delivery. -Proxy manager sends `X-Forwarded-Proto` and preserves `Host` by default, satisfying requirements 1 -and 2 with no custom configuration. Give the identity provider its own proxy host under requirement 5. +Proxy manager sends `X-Forwarded-Proto` and preserves `Host` by default, so requirements 1 and 2 +need no custom configuration; the Advanced lines above are for the buffers, timeouts and body size. Give the identity provider its own proxy host under requirement 5. **Websockets Support is not optional.** With it off, the dashboard loads and REST works, so the deployment looks healthy — but the timeline, the review detail, the attention panel and the gateway's diff --git a/spire-ui/src/components/OperatorLinksTable.test.tsx b/spire-ui/src/components/OperatorLinksTable.test.tsx new file mode 100644 index 000000000..87956d2b3 --- /dev/null +++ b/spire-ui/src/components/OperatorLinksTable.test.tsx @@ -0,0 +1,51 @@ +import { describe, it, expect, vi } from 'vitest'; +import { render, screen, waitFor, fireEvent, within } from '@testing-library/react'; +import { OperatorLinksTable } from './OperatorLinksTable'; +import * as api from '../api'; + +/** + * Unlinking stops an operator seeing their own numbers for that account, so the trash icon only + * asks; nothing is unlinked until the dialog's Unlink is pressed. + */ + +const LINKS: api.OperatorIdentityLink[] = [ + { oidcSubject: 'TEST-SUBJECT-1', providerType: 'github', authorId: '3218389', authorHandle: 'TEST-handle' }, +]; +const OPERATORS: api.SeenOperator[] = [ + { subject: 'TEST-SUBJECT-1', username: 'test-user-one', displayName: 'TEST Operator One' }, +]; + +function renderTable(onUnlinked = vi.fn()) { + render(); + fireEvent.click(screen.getByRole('button', { name: 'Unlink TEST-SUBJECT-1 on github' })); + return screen.getByRole('dialog'); +} + +describe('OperatorLinksTable unlinking', () => { + it('asks first, naming the operator and the account', () => { + const unlink = vi.spyOn(api, 'unlinkOperatorIdentity').mockResolvedValue(undefined); + + expect(renderTable()).toHaveTextContent('Unlink TEST Operator One · test-user-one from github · TEST-handle?'); + expect(unlink).not.toHaveBeenCalled(); + }); + + it('unlinks once the dialog is confirmed', async () => { + const unlink = vi.spyOn(api, 'unlinkOperatorIdentity').mockResolvedValue(undefined); + const onUnlinked = vi.fn(); + + fireEvent.click(within(renderTable(onUnlinked)).getByRole('button', { name: 'Unlink' })); + + await waitFor(() => expect(unlink).toHaveBeenCalledWith('TEST-SUBJECT-1', 'github')); + await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()); + expect(onUnlinked).toHaveBeenCalled(); + }); + + it('keeps the link when the dialog is cancelled', () => { + const unlink = vi.spyOn(api, 'unlinkOperatorIdentity').mockResolvedValue(undefined); + + fireEvent.click(within(renderTable()).getByRole('button', { name: 'Cancel' })); + + expect(screen.queryByRole('dialog')).toBeNull(); + expect(unlink).not.toHaveBeenCalled(); + }); +}); diff --git a/spire-ui/src/components/SettingsOperators.test.tsx b/spire-ui/src/components/SettingsOperators.test.tsx index b1773e59a..91a697f9a 100644 --- a/spire-ui/src/components/SettingsOperators.test.tsx +++ b/spire-ui/src/components/SettingsOperators.test.tsx @@ -227,50 +227,4 @@ describe('SettingsOperators', () => { await waitFor(() => expect(screen.getByRole('alert').textContent).toMatch(/TEST-REJECTED/)); }); - - /** - * Unlinking stops an operator seeing their own numbers for that account, so the trash icon only - * asks; nothing is unlinked until the dialog's Unlink is pressed. - */ - describe('unlinking', () => { - beforeEach(() => { - vi.spyOn(api, 'fetchOperatorIdentities').mockResolvedValue([ - { oidcSubject: 'TEST-SUBJECT-1', providerType: 'github', authorId: '3218389', authorHandle: 'TEST-handle' }, - ]); - }); - - it('asks first, naming the operator and the account', async () => { - const unlink = vi.spyOn(api, 'unlinkOperatorIdentity').mockResolvedValue(undefined); - render(, { wrapper: queryWrapper() }); - - fireEvent.click(await screen.findByRole('button', { name: 'Unlink TEST-SUBJECT-1 on github' })); - - expect(screen.getByRole('dialog')).toHaveTextContent( - 'Unlink TEST Operator One · test-user-one from github · TEST-handle?', - ); - expect(unlink).not.toHaveBeenCalled(); - }); - - it('unlinks once the dialog is confirmed', async () => { - const unlink = vi.spyOn(api, 'unlinkOperatorIdentity').mockResolvedValue(undefined); - render(, { wrapper: queryWrapper() }); - - fireEvent.click(await screen.findByRole('button', { name: 'Unlink TEST-SUBJECT-1 on github' })); - fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Unlink' })); - - await waitFor(() => expect(unlink).toHaveBeenCalledWith('TEST-SUBJECT-1', 'github')); - await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()); - }); - - it('keeps the link when the dialog is cancelled', async () => { - const unlink = vi.spyOn(api, 'unlinkOperatorIdentity').mockResolvedValue(undefined); - render(, { wrapper: queryWrapper() }); - - fireEvent.click(await screen.findByRole('button', { name: 'Unlink TEST-SUBJECT-1 on github' })); - fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Cancel' })); - - expect(screen.queryByRole('dialog')).toBeNull(); - expect(unlink).not.toHaveBeenCalled(); - }); - }); }); diff --git a/spire-ui/src/components/repositories/factory/PeopleStepConfirm.test.tsx b/spire-ui/src/components/repositories/factory/PeopleStepConfirm.test.tsx new file mode 100644 index 000000000..2f7dbe2a6 --- /dev/null +++ b/spire-ui/src/components/repositories/factory/PeopleStepConfirm.test.tsx @@ -0,0 +1,33 @@ +import { fireEvent, screen, waitFor, within } from '@testing-library/react'; +import { beforeEach, describe, expect, it } from 'vitest'; +import * as sources from '../../work-items/workSourcesApi'; +import { source } from './factoryFixtures'; +import { renderFactory, step, stubFactoryApis } from './factoryTestSetup'; + +beforeEach(stubFactoryApis); + +// Removing a person stops their labels starting work, so the button only asks; the dialog's Remove does it. +describe('removing an allowed person', () => { + async function askToRemove() { + renderFactory(); + fireEvent.click(within(await step(2)).getByRole('button', { name: 'Remove @TEST-person' })); + return screen.getByRole('dialog'); + } + + it('asks first, naming the person, the source and what it means', async () => { + expect(await askToRemove()).toHaveTextContent('Remove @TEST-person from TEST-source name? Labels they add no longer start work.'); + expect(sources.removeWorkActor).not.toHaveBeenCalled(); + }); + + it('removes the person once the dialog is confirmed', async () => { + fireEvent.click(within(await askToRemove()).getByRole('button', { name: 'Remove' })); + await waitFor(() => expect(sources.removeWorkActor).toHaveBeenCalledWith(source(), '900123')); + await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()); + }); + + it('keeps the person when the dialog is cancelled', async () => { + fireEvent.click(within(await askToRemove()).getByRole('button', { name: 'Cancel' })); + expect(screen.queryByRole('dialog')).toBeNull(); + expect(sources.removeWorkActor).not.toHaveBeenCalled(); + }); +}); diff --git a/spire-ui/src/components/repositories/factory/RepositoryFactory.test.tsx b/spire-ui/src/components/repositories/factory/RepositoryFactory.test.tsx index d9e153b59..71afc46b9 100644 --- a/spire-ui/src/components/repositories/factory/RepositoryFactory.test.tsx +++ b/spire-ui/src/components/repositories/factory/RepositoryFactory.test.tsx @@ -54,24 +54,6 @@ describe('people', () => { expect(people.getByText('@TEST-person')).toBeInTheDocument(); expect(people.getByText('900123')).toHaveClass('prov-sub'); }); - // Removing a person stops their labels starting work, so the button only asks; the dialog's Remove does it. - it('removes an allowed person only after the dialog is confirmed', async () => { - renderFactory(); - fireEvent.click(within(await step(2)).getByRole('button', { name: 'Remove @TEST-person' })); - const dialog = screen.getByRole('dialog'); - expect(dialog).toHaveTextContent('Remove @TEST-person from TEST-source name? Labels they add no longer start work.'); - expect(sources.removeWorkActor).not.toHaveBeenCalled(); - fireEvent.click(within(dialog).getByRole('button', { name: 'Remove' })); - await waitFor(() => expect(sources.removeWorkActor).toHaveBeenCalledWith(source(), '900123')); - await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull()); - }); - it('keeps an allowed person when the dialog is cancelled', async () => { - renderFactory(); - fireEvent.click(within(await step(2)).getByRole('button', { name: 'Remove @TEST-person' })); - fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: 'Cancel' })); - expect(screen.queryByRole('dialog')).toBeNull(); - expect(sources.removeWorkActor).not.toHaveBeenCalled(); - }); it('allows the one person a lookup finds, naming them on the button, with the source revision', async () => { vi.spyOn(sources, 'resolveWorkActor').mockResolvedValue({ status: 'FOUND', actors: [{ providerUserId: '900456', handle: 'TEST-new', displayName: 'TEST-new' }], detail: null }); const form = await openPeople();