diff --git a/app/tool/chat_sessions_probe.mjs b/app/tool/chat_sessions_probe.mjs index 362473c5..6d299f0e 100644 --- a/app/tool/chat_sessions_probe.mjs +++ b/app/tool/chat_sessions_probe.mjs @@ -98,6 +98,22 @@ try { const click = async (label, what = label) => { if (!await clickLabel(label)) throw new Error(`Could not click ${what}`); }; + const clickCreateConfirm = async () => { + const point = await evaluate(`(() => { + const dialog = [...document.querySelectorAll('[role="dialog"], [role="alertdialog"]')] + .find(node => node.innerText.includes('Start a chat')); + if (!dialog) return null; + const confirm = [...dialog.querySelectorAll('flt-semantics')] + .find(node => (node.getAttribute('aria-label') || node.innerText || '') === 'New chat'); + if (!confirm) return null; + const rect = confirm.getBoundingClientRect(); + return {x: rect.x + rect.width / 2, y: rect.y + rect.height / 2}; + })()`); + if (!point) throw new Error('Could not find New chat confirm inside the Start a chat dialog'); + await send('Input.dispatchMouseEvent', { type: 'mousePressed', x: point.x, y: point.y, button: 'left', clickCount: 1 }, session); + await send('Input.dispatchMouseEvent', { type: 'mouseReleased', x: point.x, y: point.y, button: 'left', clickCount: 1 }, session); + await delay(500); + }; const clickFirst = async label => { const point = await evaluate(`(() => { const needle = ${JSON.stringify(label)}; const e=[...document.querySelectorAll('flt-semantics')].find(x => (x.getAttribute('aria-label') || x.innerText || '') === needle); if (!e) return null; e.scrollIntoView({block:'center'}); const r=e.getBoundingClientRect(); return {x:r.x+r.width/2,y:r.y+r.height/2}; })()`); if (!point) throw new Error(`Could not find ${label}`); @@ -176,7 +192,8 @@ try { // Dialog chrome at the smallest size the list supports (320 CSS px, 2x DPR). await click('New chat', 'the New chat action'); - await waitText('Server directory', 'the create dialog at 320'); + await waitText('Start a chat', 'the create dialog at 320'); + await waitText('Where should this chat live?', 'the directory picker at 320'); await shot('create-320-2x', 320, 640, 2); await click('Cancel', 'Cancel the create dialog'); await resize(390, 844); @@ -203,10 +220,9 @@ try { // A create reply without `chat_session` uses the web's exact sentence. await click('New chat', 'the New chat action'); - await waitText('Server directory', 'the create dialog'); - await focusInput(); - await type('No session title'); - await click('Create', 'the create dialog confirm'); + await waitText('Start a chat', 'the create dialog'); + await waitText('Where should this chat live?', 'the directory picker'); + await clickCreateConfirm(); await waitText( 'The server did not return the new chat session.', 'the missing-session wording', @@ -219,25 +235,24 @@ try { // Create: the dialog sends once and the accepted row arrives from a list read. await click('New chat', 'the New chat action'); - await waitText('Create', 'the create dialog'); - await focusInput(); - await type('Probe created'); - await click('Create', 'the create dialog confirm'); + await waitText('Start a chat', 'the create dialog'); + await waitText('Where should this chat live?', 'the directory picker'); + await clickCreateConfirm(); if (process.env.PROBE_DEBUG) console.log(JSON.stringify({ afterCreate: await bodyText(), labels: await semantics() }, null, 2)); - await waitText('Probe created', 'the created row'); + await waitText('New chat', 'the created row'); if ((await visibleText()).includes('no chat harness')) throw new Error('Create did not reach the fixture'); await shot('created-list', 390, 844); - // Rename: seeded with the current title, then the row reads the accepted name. - await click('Chat actions for Probe created', 'the created row actions'); + // Rename: the server-assigned fixed title is changed and read back. + await click('Chat actions for New chat', 'the created row actions'); await click('Rename…', 'Rename…'); await waitText('Rename chat', 'the rename dialog'); const seeded = await focusInput(); - if (seeded !== 'Probe created') throw new Error(`Rename was seeded with ${JSON.stringify(seeded)}`); + if (seeded !== 'New chat') throw new Error(`Rename was seeded with ${JSON.stringify(seeded)}`); await type('Probe renamed'); await click('Save', 'the rename Save'); await waitText('Probe renamed', 'the renamed row'); - if ((await visibleText()).includes('Probe created')) throw new Error('The old title survived the accepted rename'); + if ((await visibleText()).includes('Probe created') || (await visibleText()).includes('New chat')) throw new Error('The old title survived the accepted rename'); await shot('renamed-list', 390, 844); // Star the renamed row (the first unstarred row in server order). diff --git a/app/tool/chat_sessions_probe_entry.dart b/app/tool/chat_sessions_probe_entry.dart index 042d6c96..6b9bcd85 100644 --- a/app/tool/chat_sessions_probe_entry.dart +++ b/app/tool/chat_sessions_probe_entry.dart @@ -8,9 +8,9 @@ import 'package:pipelines_app/features/chat/session_screen.dart'; /// Stateful chat-session fixture for the real-browser probe: every accepted /// mutation changes the list the next `chat_sessions` read returns, so the /// screen must refresh from the server rather than guess. A title of -/// `Refused title` is refused with the server's words; `No session title` -/// returns a create reply without `chat_session`; `?unseen=1` reports newer -/// recency after the first read so the `New` marker can be observed. +/// `Refused title` is refused with the server's words; the first create returns +/// a reply without `chat_session`; `?unseen=1` reports newer recency after the +/// first read so the `New` marker can be observed. class _FixtureGateway implements ApiGateway { _FixtureGateway({this.bumpAfterFirstRead = false}); @@ -18,6 +18,7 @@ class _FixtureGateway implements ApiGateway { /// reads report newer activity, so the browser can prove the `New` marker. final bool bumpAfterFirstRead; int _reads = 0; + int _creates = 0; final _sessions = [ { @@ -66,8 +67,9 @@ class _FixtureGateway implements ApiGateway { }; case 'chat_create': final body = fields['chat_create']! as JsonMap; - // The web's exact refusal for a reply without a created session. - if ('${body['title']}' == 'No session title') return const {}; + // Exercise the missing-session refusal independently of the fixed + // title the create dialog now submits. + if (_creates++ == 0) return const {}; final session = { 'id': 'probe-new-${_nextId++}', 'title': body['title'],