diff --git a/e2e/README.md b/e2e/README.md index 773502038..05a30baf6 100644 --- a/e2e/README.md +++ b/e2e/README.md @@ -48,6 +48,13 @@ The first run needs `pnpm install --dir e2e` and `pnpm --dir e2e exec playwright install chromium`. The cloud environment ships Chromium and Playwright preinstalled; run with `NODE_PATH=$(pnpm root -g)`. +## Mocked settings review + +With the dashboard running on local Vite and the browser dependencies installed, +run `node e2e/settings-save.cjs http://127.0.0.1:5173`. Playwright intercepts the +API in the browser; this check needs neither sign-in nor a running backend. +Set `CHROME_BIN` to use an installed Chromium instead of Playwright's browser. + ## Single-binary smoke check Point this check at an already running, disposable `archie` instance with its diff --git a/e2e/checks/catalogue-preview-modal.cjs b/e2e/checks/catalogue-preview-modal.cjs new file mode 100644 index 000000000..ca488b415 --- /dev/null +++ b/e2e/checks/catalogue-preview-modal.cjs @@ -0,0 +1,49 @@ +const assert = require('node:assert/strict'); + +module.exports = async ({ page, go, shot }) => { + // An isolated catalogue entry keeps the check independent of the live source. + await page.route('**/api/extensions/catalogue', route => route.fulfill({ json: [{ + name: 'preview-extension', display_name: 'Preview extension', description: 'An extension to preview.', + contract: 'workflow', group: 'platform', latest: '1.0.0', default_version: '1.0.0', + versions: [{ version: '1.0.0', digest: 'preview-digest', registered: true, settings: [] }], + }] })); + await page.setViewportSize({ width: 390, height: 600 }); + await go('/settings/extensions?tab=marketplace'); + const opener = page.getByRole('button', { name: 'Details for Preview extension' }); + const preview = page.getByRole('dialog', { name: 'Preview extension' }); + const version = preview.getByRole('combobox', { name: 'Version' }); + const close = preview.getByRole('button', { name: 'Close' }); + + await opener.click(); + await page.keyboard.press('Tab'); + await page.keyboard.press('Shift+Tab'); + assert.ok(await version.evaluate(el => el === document.activeElement)); + await shot('version-focus'); + const { clearance, ring } = await version.evaluate(el => { + let scroll = el.parentElement; + while (getComputedStyle(scroll).overflowY !== 'auto') scroll = scroll.parentElement; + const bounds = scroll.getBoundingClientRect(); + const field = el.getBoundingClientRect(); + const css = getComputedStyle(el); + return { + clearance: Math.min(field.left - bounds.left, bounds.left + scroll.clientWidth - field.right), + ring: Math.max(3, parseFloat(css.outlineWidth) + parseFloat(css.outlineOffset)), + }; + }); + assert.ok(clearance + 0.1 >= ring, `Version focus ring: ${clearance}px clearance for ${ring}px ring`); + + await page.keyboard.press('Space'); + const options = page.getByRole('listbox'); + await options.waitFor(); + await page.keyboard.press('Escape'); + await options.waitFor({ state: 'hidden' }); + await preview.waitFor(); + await page.keyboard.press('Escape'); + await preview.waitFor({ state: 'detached' }); + assert.ok(await opener.evaluate(el => el === document.activeElement)); + + await opener.click(); + await close.click(); + await preview.waitFor({ state: 'detached' }); + assert.ok(await opener.evaluate(el => el === document.activeElement)); +}; diff --git a/e2e/checks/linked-user-identities.cjs b/e2e/checks/linked-user-identities.cjs new file mode 100644 index 000000000..04d922614 --- /dev/null +++ b/e2e/checks/linked-user-identities.cjs @@ -0,0 +1,100 @@ +const assert = require('node:assert/strict'); + +const org = { id: 'example-org', name: 'Example', version: 1 }; +const user = { id: '11111111-1111-4111-8111-111111111111', name: 'Alex Rivera', kind: 'user' }; +const other = { id: '22222222-2222-4222-8222-222222222222', name: user.name, kind: 'user' }; +const bot = { id: '33333333-3333-4333-8333-333333333333', name: 'Nightly bot', kind: 'bot' }; +const missing = { id: '44444444-4444-4444-8444-444444444444' }; +const target = { id: '55555555-5555-4555-8555-555555555555', name: 'Riley Singh', kind: 'user' }; + +const member = (actor) => ({ + identity_id: actor.id, display_name: actor.name, kind: actor.kind, role: 'viewer', status: 'active', +}); + +// An audit actor link must resolve the exact user, not another member with the same name. +module.exports = async ({ page, go, shot }) => { + const at = new Date().toISOString(); + const records = [user, bot, missing].map((actor, i) => ({ + id: `audit-${i}`, at, category: 'runtime', kind: 'task', action: 'task.retry', severity: 'info', outcome: 'success', + actor, summary: `Task audit ${i}`, + target: i === 1 ? { kind: 'identity', id: target.id, label: target.name } : { kind: 'task', id: String(i + 1) }, + })); + await page.route('**/api/**', async (route) => { + const { pathname: path, searchParams } = new URL(route.request().url()); + const version = Number(searchParams.get('version')) || 2; + const fixtures = { + '/api/auth/status': { user: { id: 'operator', display_name: 'Operator' }, setup_required: false }, + '/api/capabilities': { sections: { settings: false } }, + '/api/orgs': { current: org.id, orgs: [org] }, + [`/api/orgs/${org.id}/members`]: { members: [member(user), { ...member(other), status: 'suspended' }, member(target)] }, + [`/api/orgs/${org.id}/member-candidates`]: { identities: [] }, + [`/api/orgs/${org.id}/history`]: { events: [{ id: 'history', kind: 'org', old_name: 'Previous', new_name: org.name, at, actor_id: user.id, actor_name: user.name }] }, + '/api/audit': { records }, + '/api/access/decisions': { decisions: [{ at, principal: user.id, outcome: 'allowed', action: 'read', kind: 'task', resource: '1', level: 'org', policies: [], count: 1 }] }, + '/api/alerts': { alerts: [] }, + '/api/proposals/example': { id: 'example', title: 'Example proposal', kind: 'policy', state: 'rejected', proposed_by_id: bot.id, answered_by_id: user.id, actions: [], created_at: at }, + '/api/runs/example': { + run: { id: 'example', workflow: 'Example run', state: 'succeeded', created_at: at, finished_at: at }, stages: [], + actions: [{ decision: { id: 'decision', level: 'ask', action: { connector: 'example', name: 'act' }, at, refused_by: 'policy-rule' }, approval: { state: 'approved', answered_by: user.name, answered_by_id: user.id, answered_via: 'web' } }], + }, + '/api/approvals': [], + '/api/policies/hard-rules': { version, body: '// example', created_at: at, created_by: user.id, versions: [{ version: 2 }, { version: 1 }] }, + '/api/policies/change-request': { version: 1, body: '', created_at: at }, + '/api/workflows': [{ id: 'workflow', name: 'Example workflow', version: 1, body: 'steps: []', created_by: user.id, created_at: at, enabled: true }], + '/api/workflow-drafts': [], + '/api/workflow-stats': [], + '/api/triggers': [], + }; + if (path === '/api/stream') return route.fulfill({ status: 200, contentType: 'text/event-stream', body: ': ready\n\n' }); + await route.fulfill({ json: fixtures[path] ?? {} }); + }); + await go('/org/audit'); + await page.getByText(user.name, { exact: true }).filter({ visible: true }).waitFor(); + const link = page.getByRole('link', { name: user.name, exact: true }); + assert.equal(await link.count(), 1, 'the visible audit user name should be a link'); + assert.equal(await page.getByRole('link', { name: bot.name, exact: true }).count(), 0); + assert.equal(await page.getByRole('link', { name: missing.id, exact: true }).count(), 0); + const targetLink = page.getByRole('link', { name: target.name, exact: true }); + const targetHref = await targetLink.getAttribute('href', { timeout: 1500 }).catch(() => null); + assert.equal(targetHref && new URL(targetHref, page.url()).searchParams.get('member'), target.id, 'an audit identity target should link to its user'); + await shot('audit-actor'); + await link.click(); + await page.waitForURL((url) => url.pathname === '/org/members' && url.searchParams.get('member') === user.id); + await page.getByRole('heading', { name: 'Members' }).waitFor(); + const row = page.getByRole('row').filter({ hasText: user.name }); + await row.first().waitFor(); + assert.equal(await row.count(), 1); + assert.match(await row.innerText(), /\bactive\b/); + await shot('target-member'); + await page.getByRole('link', { name: 'All members' }).click(); + await page.getByRole('button', { name: `Suspend ${user.name}` }).waitFor(); + assert.equal(await row.count(), 2); + await go(`/org/members?org=${org.id}&member=${missing.id}`); + await page.getByText('Member not found in this organisation', { exact: true }).waitFor(); + + const unresolved = []; + for (const [path, ready] of [ + ['/proposals/example', () => page.getByText('Rejected by', { exact: true }).waitFor()], + ['/runs/example', () => page.getByText('Refused by policy-rule', { exact: true }).waitFor()], + ['/controls', () => page.getByRole('textbox', { name: 'Hard rules', exact: true }).waitFor()], + ['/org', () => page.getByRole('heading', { name: 'Name changes' }).waitFor()], + ['/org/decisions', () => page.getByRole('cell', { name: 'Allowed' }).waitFor()], + ['/workflows', () => page.getByRole('link', { name: 'Example workflow', exact: true }).waitFor()], + ]) { + await go(path); + await ready(); + const credit = page.getByRole('link', { name: user.name, exact: true }); + const href = await credit.getAttribute('href', { timeout: 1500 }).catch(() => null); + if (!href || new URL(href, page.url()).searchParams.get('member') !== user.id) unresolved.push(path); + assert.equal(await page.getByRole('link', { name: bot.id, exact: true }).count(), 0); + assert.equal(await page.getByRole('link', { name: 'policy-rule', exact: true }).count(), 0); + if (path === '/controls') { + await page.getByRole('combobox', { name: 'Hard rules version' }).click(); + await page.getByRole('option', { name: 'Version 1' }).click(); + await page.getByRole('textbox', { name: 'Hard rules, version 1' }).waitFor(); + const oldHref = await credit.getAttribute('href', { timeout: 1500 }).catch(() => null); + if (!oldHref || new URL(oldHref, page.url()).searchParams.get('member') !== user.id) unresolved.push('/controls (previous version)'); + } + } + assert.deepEqual(unresolved, [], 'attribution should display the user name linked by ID'); +}; diff --git a/e2e/checks/policy-editor-modal.cjs b/e2e/checks/policy-editor-modal.cjs new file mode 100644 index 000000000..29e9b12ca --- /dev/null +++ b/e2e/checks/policy-editor-modal.cjs @@ -0,0 +1,80 @@ +const assert = require('node:assert/strict'); + +module.exports = async ({ page, go, fail, shot }) => { + const opener = page.getByRole('button', { name: 'New policy', exact: true }); + const editor = page.getByRole('dialog', { name: /New policy|draft-policy/ }); + const confirm = page.getByRole('alertdialog', { name: 'Discard unsaved changes?' }); + const id = editor.getByRole('textbox', { name: 'Policy id' }); + const cedar = editor.getByRole('textbox', { name: 'Cedar policy' }); + const dismissals = { + Close: () => editor.getByRole('button', { name: 'Close', exact: true }).click({ timeout: 2000 }), + Cancel: () => editor.getByRole('button', { name: 'Cancel', exact: true }).click({ timeout: 2000 }), + Escape: () => page.keyboard.press('Escape'), + Backdrop: () => page.mouse.click(8, 8), + }; + const focused = (field) => field.evaluate(el => el === document.activeElement); + const closed = async () => { + await page.locator('[role="alertdialog"]').waitFor({ state: 'detached', timeout: 2000 }); + await page.locator('[role="dialog"]').waitFor({ state: 'detached', timeout: 2000 }); + assert.ok(await focused(opener), 'focus did not return to New policy'); + }; + const cases = async (scenario, rows, run) => { + for (const row of rows) { + // A failed modal must not block the next independently tested path. + await go('/org/policies'); + try { await run(row); } catch (error) { fail(`${scenario} ${row}: ${error.message}`); } + } + }; + + await cases('Mobile', ['focus clearance'], async () => { + await page.setViewportSize({ width: 390, height: 600 }); + await opener.click(); + for (const field of [id, cedar]) { + // Opening focuses the ID; Tab past the level selector to reach Cedar. + if (field === cedar) { + await page.keyboard.press('Tab'); + await page.keyboard.press('Tab'); + } + assert.ok(await focused(field), 'keyboard focus did not reach the policy field'); + const { name, clearance, ring } = await field.evaluate(el => { + const form = el.closest('form'); + const bounds = form.getBoundingClientRect(); + const field = el.getBoundingClientRect(); + const css = getComputedStyle(el); + return { + name: el.getAttribute('aria-label'), + clearance: Math.min(field.left - bounds.left, field.top - bounds.top, + bounds.left + form.clientWidth - field.right, bounds.top + form.clientHeight - field.bottom), + ring: Math.max(3, parseFloat(css.outlineWidth) + parseFloat(css.outlineOffset)), + }; + }); + if (clearance + 0.1 < ring) fail(`${name} focus ring: ${clearance}px clearance for ${ring}px ring`); + await shot(name); + } + }); + await page.setViewportSize({ width: 1440, height: 900 }); + + await cases('Clean', Object.keys(dismissals), async (action) => { + await opener.click(); + await dismissals[action](); + await closed(); + }); + + await cases('Dirty', Object.keys(dismissals), async (action) => { + await opener.click(); + await id.pressSequentially('draft-policy'); + await dismissals[action](); + const keep = confirm.getByRole('button', { name: 'Keep editing' }); + await keep.waitFor({ timeout: 2000 }); + if (action === 'Escape') await page.keyboard.press('Escape'); + else await keep.click({ timeout: 2000 }); + await page.locator('[role="alertdialog"]').waitFor({ state: 'detached', timeout: 2000 }); + assert.equal(await id.inputValue(), 'draft-policy'); + assert.ok(await editor.evaluate(el => el.contains(document.activeElement)), 'focus did not return to the editor'); + await dismissals[action](); + await confirm.getByRole('button', { name: 'Discard changes' }).click({ timeout: 2000 }); + await closed(); + await opener.click(); + assert.equal(await id.inputValue(), '', 'discarded policy reappeared on reopen'); + }); +}; diff --git a/e2e/checks/proposals-refresh.cjs b/e2e/checks/proposals-refresh.cjs new file mode 100644 index 000000000..9b53e0827 --- /dev/null +++ b/e2e/checks/proposals-refresh.cjs @@ -0,0 +1,112 @@ +const assert = require('node:assert/strict'); + +const waiting = { + id: '00000000-0000-4000-8000-000000000001', + title: 'Correct the workflow', + kind: 'workflow_change', + state: 'pending', + needs: 'owner', + actions: [], + created_at: '2026-01-01T00:00:00Z', +}; + +// Keep the last successful result and protect its tab from competing reads. +module.exports = async ({ page, go, shot, tolerate }) => { + const now = new Date(); + await page.clock.install({ time: now }); + await page.clock.pauseAt(new Date(now.getTime() + 60_000)); + tolerate(/503.*\/api\/proposals/); + + const pendingURL = '**/api/proposals?state=pending'; + let current = waiting; + let failNext; + await page.route(pendingURL, async route => { + if (failNext) { + const failing = failNext; + failNext = undefined; + await failing; + await route.fulfill({ status: 503, contentType: 'application/problem+json', json: { detail: 'Could not refresh proposals' } }); + return; + } + await route.fulfill({ json: [current] }); + }); + + await go('/proposals'); + const proposal = page.getByRole('link', { name: waiting.title, exact: true }); + const sort = page.getByRole('columnheader', { name: 'Proposal', exact: true }); + await proposal.waitFor(); + await sort.getByRole('button').press('Enter'); + await proposal.focus(); + + const failure = Promise.withResolvers(); + failNext = failure.promise; + const refresh = page.waitForRequest(pendingURL); + await page.clock.runFor(5000); + await refresh; + assert.equal(await proposal.isVisible(), true, 'the row should stay visible during a refresh'); + failure.resolve(); + + const error = page.getByRole('alert').filter({ hasText: 'Could not refresh proposals' }); + await error.waitFor(); + assert.equal(await proposal.isVisible(), true, 'a failed refresh must not replace the table'); + assert.equal(await sort.getAttribute('aria-sort'), 'ascending', 'the table should keep the operator’s sort'); + assert.equal(await proposal.evaluate(link => link === document.activeElement), true, 'the row should keep keyboard focus'); + await shot('failed-refresh-retains-table'); + + current = { ...waiting, title: 'Workflow correction updated' }; + await error.getByRole('button', { name: 'Retry' }).click(); + await page.getByRole('link', { name: current.title, exact: true }).waitFor(); + await error.waitFor({ state: 'hidden' }); + assert.equal(await sort.getAttribute('aria-sort'), 'ascending'); + + // A failed read belongs to its filter, not to the newly selected tab. + failNext = Promise.resolve(); + await page.clock.runFor(5000); + await error.waitFor(); + const published = Promise.withResolvers(); + await page.route('**/api/proposals?state=published', async route => { + await published.promise; + await route.fulfill({ json: [] }); + }); + const publishedTab = page.getByRole('tab', { name: 'Published' }); + await publishedTab.click(); + const loading = page.getByRole('status', { name: 'Loading proposals' }); + assert.equal(await loading.isVisible(), true, 'a new tab must not inherit the previous tab’s error'); + assert.equal(await error.isVisible(), false); + assert.equal(await page.getByRole('table').count(), 0, 'rows from the previous tab must not appear'); + published.resolve(); + const empty = page.getByText('No proposals', { exact: true }); + await empty.waitFor(); + + // A slow read must still take effect after a background poll ticks. + const slow = Promise.withResolvers(); + const stale = Promise.withResolvers(); + let first = true; + await page.route(pendingURL, async route => { + const read = first ? slow : stale; + first = false; + await read.promise; + await route.fulfill({ json: [waiting] }); + }); + const switched = page.waitForRequest(pendingURL); + await page.getByRole('tab', { name: 'Waiting' }).click(); + await switched; + await page.clock.runFor(5000); + slow.resolve(); + await proposal.waitFor({ timeout: 3000 }).catch(() => { + assert.fail('a slow read must render its result even after a background poll ticks'); + }); + + // A late response for Waiting cannot replace the Published result. + const nextPoll = page.waitForRequest(pendingURL); + await page.clock.runFor(5000); + await nextPoll; + await publishedTab.click(); + await empty.waitFor(); + const response = page.waitForResponse(pendingURL); + stale.resolve(); + await (await response).finished(); + await page.clock.runFor(50); + assert.equal(await proposal.isVisible(), false, 'a response for the previous tab must not replace the current one'); + assert.equal(await empty.isVisible(), true); +}; diff --git a/e2e/settings-save.cjs b/e2e/settings-save.cjs new file mode 100644 index 000000000..7d1c03e3a --- /dev/null +++ b/e2e/settings-save.cjs @@ -0,0 +1,141 @@ +// Run against local Vite only: node e2e/settings-save.cjs [http://127.0.0.1:5173] +// Every API request is intercepted; no real settings can be changed. +const assert = require('node:assert/strict'); +const { test } = require('node:test'); +const { chromium } = require('playwright'); + +const base = new URL(process.argv[2] ?? 'http://127.0.0.1:5173'); +assert.equal(base.hostname, '127.0.0.1', 'use a local Vite server'); +const id = '11111111-1111-4111-8111-111111111111'; + +async function scenario(t, path) { + const browser = await chromium.launch({ executablePath: process.env.CHROME_BIN }); + t.after(() => browser.close()); + const page = await browser.newPage(); + page.setDefaultTimeout(5000); + const provider = { id, name: 'Example', class: 'openai', base_url: 'https://provider.example' }; + const saved = { + '/api/settings/agent-models': { default: { provider_id: id, model: 'original' } }, + '/api/settings/model-providers': [provider], + '/api/settings/model-classes': [{ class: 'openai' }], + '/api/settings/model-policy': { workflow_aliases: null, chat_aliases: null }, + '/api/settings/instructions': { text: 'Original instructions' }, + }; + const moduleWrites = { + '/api/settings/agent-model': (body) => (saved['/api/settings/agent-models'].default = body), + [`/api/settings/model-providers/${id}`]: (body) => Object.assign(provider, body), + '/api/settings/model-policy': (body) => (saved['/api/settings/model-policy'] = body), + '/api/settings/instructions': (body) => (saved['/api/settings/instructions'] = { text: body.text.trim() }), + '/api/settings/agent-model/test': (body) => ({ model: body.model, answer: 'Ready' }), + }; + const writes = []; + const failed = new Set(); + const legacy = []; + await page.route('**/*', async (r) => { + const request = r.request(); + const url = new URL(request.url()); + if (url.origin !== base.origin) return r.abort(); + const path = url.pathname; + if (!path.startsWith('/api/')) return r.continue(); + if (path.startsWith('/api/control-plane/')) legacy.push(path); + if (request.method() !== 'GET') { + const body = request.postDataJSON(); + writes.push([request.method(), path, body]); + if (failed.delete(path)) { + return r.fulfill({ status: 503, contentType: 'application/problem+json', body: '{"detail":"Save temporarily unavailable"}' }); + } + if (moduleWrites[path]) return r.fulfill({ json: moduleWrites[path](body) }); + return r.fulfill({ status: 404 }); + } + const context = { + '/api/auth/status': { setup_required: false, user: { id: 'u', display_name: 'Operator', kind: 'operator' }, instance: 'archie' }, + '/api/authentication': { public_url: base.origin, oidc_issuer: '', oidc_client_id: '', oidc_audience: '', trusted_proxies: [] }, + '/api/capabilities': { sections: { chat: false } }, + '/api/orgs': { orgs: [{ id: 'test', name: 'Test', role: 'owner', version: 1 }], current: 'test', instance_admin: true }, + '/api/alerts': { alerts: [] }, + '/api/credentials': [], + }; + return r.fulfill({ json: saved[path] ?? context[path] ?? {} }); + }); + await page.goto(new URL(path, base).href); + return { page, writes, failed, saved, legacy }; +} + +async function review(page) { + await page.getByRole('button', { name: 'Review and save', exact: true }).click({ timeout: 3500 }); + return page.getByRole('dialog'); +} + +test('Models reviews only staged edits and retries only the unfinished writes', async (t) => { + const { page, writes, failed, legacy } = await scenario(t, '/settings/models'); + const alias = page.locator('#model-default'); + await alias.fill('new-model'); + await page.getByRole('button', { name: /Example/ }).click(); + await page.getByLabel('Name for Example').fill('Renamed'); + await page.getByLabel('Aliases workflows may use').fill('default'); + await page.getByLabel('Aliases chat may use').fill('default'); + const nav = page.getByRole('navigation', { name: 'Instance', exact: true }); + await nav.getByRole('link', { name: 'Authentication', exact: true }).click(); + await nav.getByRole('link', { name: 'Models', exact: true }).click(); + assert.equal(await alias.inputValue(), 'new-model'); + const dialog = await review(page); + await dialog.getByText('new-model', { exact: false }).waitFor(); + await dialog.getByText('Renamed', { exact: false }).waitFor(); + await dialog.getByRole('button', { name: 'Revert chat', exact: true }).click(); + assert.deepEqual(writes, [], 'editing and opening the review must not write'); + + const providerPath = `/api/settings/model-providers/${id}`; + failed.add(providerPath); + const confirm = dialog.getByRole('button', { name: 'Save', exact: true }); + await confirm.click(); + await dialog.getByText('Save temporarily unavailable').waitFor(); + const aliasWrite = ['PUT', '/api/settings/agent-model', { provider_id: id, model: 'new-model' }]; + const providerWrite = ['PUT', providerPath, { name: 'Renamed', class: 'openai', base_url: 'https://provider.example' }]; + const policyWrite = ['PUT', '/api/settings/model-policy', { workflow_aliases: ['default'], chat_aliases: null }]; + assert.deepEqual(writes, [aliasWrite, providerWrite], 'stop after the rejected write'); + assert.equal(await dialog.getByText('new-model', { exact: false }).count(), 0, 'successful alias is no longer staged'); + await confirm.click(); + await dialog.waitFor({ state: 'hidden' }); + assert.deepEqual(writes, [aliasWrite, providerWrite, providerWrite, policyWrite]); + assert.deepEqual(legacy, []); +}); + +test('Testing a model runs immediately without saving its draft', async (t) => { + const { page, writes } = await scenario(t, '/settings/models'); + await page.locator('#model-default').fill('try-this'); + await page.getByRole('button', { name: 'Test', exact: true }).click(); + await page.getByText('try-this answered “Ready”').waitFor(); + const dialog = await review(page); + await dialog.getByText('After: try-this').waitFor(); + assert.deepEqual(writes, [['POST', '/api/settings/agent-model/test', { provider_id: id, model: 'try-this' }]]); +}); + +test('Instructions can be discarded or retried from the review', async (t) => { + const { page, writes, saved, failed, legacy } = await scenario(t, '/org/instructions'); + const text = page.getByRole('textbox', { name: 'Instructions' }); + await text.fill('Discard me'); + let dialog = await review(page); + await dialog.getByText('Discard me', { exact: false }).waitFor(); + await dialog.getByRole('button', { name: 'Discard all' }).click(); + assert.equal(await text.inputValue(), 'Original instructions'); + await text.fill('New instructions'); + dialog = await review(page); + const path = '/api/settings/instructions'; + assert.deepEqual(writes, [], 'discard and review do not write'); + const confirm = dialog.getByRole('button', { name: 'Save', exact: true }); + saved[path].text = 'Changed in another tab'; + await confirm.click(); + await dialog.getByText('Changed elsewhere. Latest values loaded.').waitFor(); + await dialog.getByText('Changed in another tab').waitFor(); + assert.deepEqual(writes, [], 'a newer value needs another review before it is overwritten'); + failed.add(path); + await confirm.click(); + await dialog.getByText('Save temporarily unavailable').waitFor(); + const command = ['PUT', path, { text: 'New instructions' }]; + assert.deepEqual(writes, [command]); + await confirm.click(); + await dialog.waitFor({ state: 'hidden' }); + assert.deepEqual(writes, [command, command]); + assert.equal(saved[path].text, 'New instructions'); + assert.deepEqual(legacy, []); +}); diff --git a/ui/src/audit/AuditDetail.vue b/ui/src/audit/AuditDetail.vue index 753deab9a..1fd84cb3e 100644 --- a/ui/src/audit/AuditDetail.vue +++ b/ui/src/audit/AuditDetail.vue @@ -5,6 +5,7 @@ import { Undo2 } from "@lucide/vue"; import ChangeList from "@/components/ChangeList.vue"; import { Button } from "@/components/ui/button"; import { MetadataList } from "@/components/ui/metadata-list"; +import UserReference from "@/org/UserReference.vue"; import { changesFromFields, metadataRows, @@ -25,8 +26,9 @@ const href = computed(() => targetHref(props.record.target));