fix(editor): ask only the top refusing layer, safe retry notes

This commit is contained in:
bchanot committed 2026-11-14 23:17:54 +01:00
1 parent f8be0ad01a
commit ee86a3a659
5 files changed
+92 -15

No files matched your search

+19 -5
View File
@@ -57,6 +57,18 @@ export async function passwordToken(account: SandboxAccount): Promise<string> {
return body.access_token
}
/**
* Records a retry on the running test; outside a test (the global setup) it goes to the
* console, where `test.info()` would throw.
*/
function noteRetry(type: string, description: string): void {
try {
test.info().annotations.push({ type, description })
} catch {
console.log(`${type}: ${description}`)
}
}
/**
* A verified TOTP factor enrolled by the account itself through the GoTrue
* API (as its authenticator app would be set up); resolves with its secret.
@@ -70,8 +82,10 @@ export async function enrolVerifiedFactor(
if (!enrolment.factor) throw new Error(`sandbox enrol: ${refusal(enrolment)}`)
let verified = await verifyTotp(token, enrolment.factor)
// The HTTP 500 of the sweep (see `STEP_UP_ATTEMPTS`) is tried once more.
if (verified.status >= 500)
if (verified.status >= 500) {
noteRetry('verify retried', `HTTP ${verified.status} from GoTrue verify`)
verified = await verifyTotp(token, enrolment.factor)
}
if (verified.status !== 200)
throw new Error(`sandbox verify: ${refusal(verified)}`)
return enrolment.factor.secret
@@ -151,10 +165,10 @@ export async function stepUpAdmin(page: Page, dict: Dict, secret: string) {
for (let attempt = 1; ; attempt += 1) {
const unavailable = await sendStepUpCode(page, dict, secret)
if (!unavailable || attempt === STEP_UP_ATTEMPTS) break
test.info().annotations.push({
type: 'step-up retried',
description: `attempt ${attempt}: GoTrue verify failed on the server`,
})
noteRetry(
'step-up retried',
`attempt ${attempt}: GoTrue verify failed on the server`,
)
await page.reload()
}
await expect(stepUpHeading(page, dict)).toBeHidden()
+3 -2
View File
@@ -9,8 +9,9 @@ import { FINGERPRINT_PATTERN, fingerprintOf, randomHex } from './fingerprint'
* entries and the left-draft flag carry instead of the account id. It is kept in this
* tab's sessionStorage with a fingerprint of the account id salted with the tag, reused
* only for the account whose fingerprint it holds, and rotated on sign-out and on any
* other account (the flags of the old tag cleared). Resolved at once, on any origin (http included). A storage
* that refuses keeps it in memory only: a reload then restores nothing.
* other account (the flags of the old tag cleared). Resolved at once, on any origin
* (http included). A storage that refuses keeps it in memory only: a reload then
* restores nothing.
*/
const STORAGE_KEY = 'faunosteo:editor:session-tag'
const TAG_PATTERN = /^[0-9a-f]{32}$/
@@ -233,8 +233,8 @@ function leavingLayers(from: EditorView, to: EditorView): LayerName[] {
/**
* Whether a POP must not be followed, and which layer refused it: a modal that is no
* layer is open (its place-scoped state is not in the history, every layer is asked), or
* a dirty layer would be removed. Only the layers the POP removes are asked, top down, so
* a dirty form shows its own confirmation and a layer the POP keeps is never asked.
* a dirty layer would be removed. Only the layers the POP removes are asked, top down, and
* the first to refuse stops the walk: a lower dirty layer's question is never left pending.
*/
function refusal(
ctx: PopContext,
@@ -246,9 +246,7 @@ function refusal(
return 'modal'
}
const leaving = leavingLayers(view, entry?.view ?? ctx.defaultView)
const answers = leaving.map((layer) => nav.guards.ask(layer, false).allowed)
const index = answers.indexOf(false)
return index < 0 ? null : leaving[index]
return leaving.find((layer) => !nav.guards.ask(layer, false).allowed) ?? null
}
/** The view under the finding dialog's sheet: what lies over it is clean, it goes. */
+4 -2
View File
@@ -86,8 +86,10 @@ export function stepHistory(
const state = api.get()
const preview = editablePreview(state)
if (typeof preview === 'string') return blocked(preview)
const move = direction === 'undo' ? stepBack : stepForward
const step = move(historyOf(state), state.documentText)
const step = (direction === 'undo' ? stepBack : stepForward)(
historyOf(state),
state.documentText,
)
if (!step) return blocked('empty')
const replaced = preview.replaceDocument(step.text)
if (!replaced.ok) return replaced
@@ -1066,7 +1066,7 @@ describe('the citations sheet over a dirty edit form (final review rev 4, item 1
draftKept()
})
it('after the cascade keeps the form, one Back reopens the sheet (docs, limit 6)', async () => {
it('after the cascade keeps the form, one Back reopens the sheet (docs, limit 5)', async () => {
const user = await sheetOverDirtyForm()
const sheet = within(panelOpen()!)
const head = sheet.getByRole('button', { name: /^Alpha/ })
@@ -1099,6 +1099,68 @@ describe('the citations sheet over a dirty edit form (final review rev 4, item 1
draftKept()
})
/** The reference Alpha's edit dialog opened from the sheet; `dirty` types in it. */
async function referenceOverSheet(user: User, dirty: boolean) {
const sheet = within(panelOpen()!)
const head = sheet.getByRole('button', { name: /^Alpha/ })
if (head.getAttribute('aria-expanded') === 'false') await user.click(head)
const tile = within(head.closest('li')!)
await user.click(tile.getByRole('button', { name: 'Modifier' }))
await waitFor(() => expect(refForm()).toBeDefined())
if (dirty)
await user.type(within(refForm()!).getByLabelText('Citation'), ' x')
}
it('a jump of three entries asks the dirty reference only, nothing stays pending under it', async () => {
const user = await sheetOverDirtyForm()
await referenceOverSheet(user, true)
await act(async () => navigate(-3))
await waitFor(() => expect(screen.queryAllByText(question)).toHaveLength(1))
expect(refForm()!.contains(screen.getByText(question))).toBe(true)
await user.click(
within(refForm()!).getByRole('button', { name: 'Abandonner' }),
)
await waitFor(() => expect(refForm()).toBeUndefined())
// The refused jump is dropped: the sheet stays, and no question comes up unasked.
expect(panelOpen()).not.toBeNull()
expect(screen.queryByText(question)).toBeNull()
draftKept()
})
it('a clean reference over the sheet over a dirty form: a Back asks the form in view', async () => {
const user = await sheetOverDirtyForm()
await referenceOverSheet(user, false)
await act(async () => navigate(-3))
await waitFor(() => expect(panelOpen()).toBeNull())
await waitFor(() => expect(refForm()).toBeUndefined())
expect(inDialog().getByText(question)).toBeVisible()
await waitFor(() =>
expect(findingDialog()!.contains(document.activeElement)).toBe(true),
)
draftKept()
})
it('a clean reference over the sheet over a dirty form: a leave out asks the form in view', async () => {
const user = await sheetOverDirtyForm()
await referenceOverSheet(user, false)
const url = new URL('/app/admin/sheets', window.location.origin).href
const event = Object.assign(new Event('navigate', { cancelable: true }), {
navigationType: 'traverse',
destination: { url, key: 'list', sameDocument: true },
})
act(() => {
api.dispatchEvent(event)
})
expect(event.defaultPrevented).toBe(true)
await waitFor(() => expect(panelOpen()).toBeNull())
await waitFor(() => expect(refForm()).toBeUndefined())
expect(inDialog().getByText(question)).toBeVisible()
await waitFor(() =>
expect(findingDialog()!.contains(document.activeElement)).toBe(true),
)
draftKept()
})
it('a jump out of the editor closes the sheet, then the form asks in view', async () => {
await sheetOverDirtyForm()
const url = new URL('/app/admin/sheets', window.location.origin).href