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, created_by: '00000000-0000-5000-8000-000000000001' }, '/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.getByText('System', { exact: true }).waitFor(); assert.equal(await page.getByText('00000000-0000-5000-8000-000000000001', { exact: true }).count(), 0); assert.equal(await page.getByRole('link', { name: 'System', exact: true }).count(), 0); 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'); };