7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
244 lines
9.2 KiB
JavaScript
244 lines
9.2 KiB
JavaScript
/**
|
|
* E2E Tests for Chat Mode "New Chat" Button
|
|
*
|
|
* Verifies the UI invariants of startNewChat() at chat.js:
|
|
* - URL resets from /chat/<session> back to /chat/
|
|
* - Welcome screen is shown again
|
|
* - Title resets to "New Chat"
|
|
* - Edit-title and Export buttons are hidden again
|
|
* - Send button is re-enabled when a fresh chat is started after one
|
|
* was in progress (sendBtn.disabled = false on chat.js)
|
|
*
|
|
* No LLM required. We seed the session by clicking a suggestion chip
|
|
* to get into the post-welcome state, then exercise the New Chat
|
|
* button.
|
|
*
|
|
* Prerequisites: Web server on http://127.0.0.1:5000 (override BASE_URL).
|
|
*/
|
|
|
|
const puppeteer = require('puppeteer');
|
|
const AuthHelper = require('../auth_helper');
|
|
const { getPuppeteerLaunchOptions } = require('../puppeteer_config');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const BASE_URL = process.env.BASE_URL || 'http://127.0.0.1:5000';
|
|
const isCI = !!process.env.CI;
|
|
|
|
const TIMEOUTS = {
|
|
navigation: isCI ? 60000 : 30000,
|
|
selector: isCI ? 30000 : 10000,
|
|
};
|
|
|
|
const SCREENSHOTS_DIR = path.join(__dirname, '..', 'screenshots');
|
|
|
|
async function snap(page, name) {
|
|
if (!fs.existsSync(SCREENSHOTS_DIR)) {
|
|
fs.mkdirSync(SCREENSHOTS_DIR, { recursive: true });
|
|
}
|
|
const file = path.join(SCREENSHOTS_DIR, `chat_newchat_${name}_${Date.now()}.png`);
|
|
try {
|
|
await page.screenshot({ path: file, fullPage: true });
|
|
} catch (_) {}
|
|
}
|
|
|
|
async function gotoChat(page) {
|
|
await page.goto(`${BASE_URL}/chat/`, {
|
|
waitUntil: 'domcontentloaded',
|
|
timeout: TIMEOUTS.navigation,
|
|
});
|
|
await page.waitForSelector('.ldr-chat-container', { timeout: TIMEOUTS.selector });
|
|
await page.waitForSelector('#new-chat-btn', { timeout: TIMEOUTS.selector });
|
|
// chat.js wires event listeners synchronously in init() and sets
|
|
// data-init-complete once init() (including the async most-recent
|
|
// session restore) has fully settled. window.chatComponent is
|
|
// assigned at script-eval time — BEFORE init runs — so it is not a
|
|
// reliable "listeners bound" signal; data-init-complete is. Then
|
|
// force a clean New Chat state so a bare /chat/ visit that
|
|
// auto-resumed a prior session doesn't leave the welcome chips
|
|
// hidden for startSessionByChip().
|
|
await page.waitForSelector('#chat-input[data-init-complete="true"]', { timeout: TIMEOUTS.selector });
|
|
await page.evaluate(() => window.chatComponent.startNewChat());
|
|
await page.waitForFunction(
|
|
() => {
|
|
const el = document.getElementById('chat-welcome');
|
|
return el && getComputedStyle(el).display !== 'none';
|
|
},
|
|
{ timeout: TIMEOUTS.selector }
|
|
);
|
|
}
|
|
|
|
async function startSessionByChip(page) {
|
|
await page.waitForSelector('.ldr-chat-suggestion', { timeout: TIMEOUTS.selector });
|
|
// evaluate().click() bypasses Puppeteer's interactability check —
|
|
// the chip is occasionally considered not-clickable in headless
|
|
// mode during the welcome-to-progress transition.
|
|
await page.evaluate(() => {
|
|
document.querySelector('.ldr-chat-suggestion').click();
|
|
});
|
|
// Welcome screen hides on first send
|
|
await page.waitForFunction(
|
|
() => {
|
|
const el = document.getElementById('chat-welcome');
|
|
return !el || getComputedStyle(el).display === 'none';
|
|
},
|
|
{ timeout: TIMEOUTS.selector }
|
|
);
|
|
// URL transitions to /chat/<session>
|
|
await page.waitForFunction(
|
|
() => /\/chat\/[\w-]+/.test(window.location.pathname),
|
|
{ timeout: TIMEOUTS.selector }
|
|
);
|
|
}
|
|
|
|
async function run() {
|
|
console.log(`Running chat "New Chat" button tests (CI mode: ${isCI})`);
|
|
|
|
const browser = await puppeteer.launch(getPuppeteerLaunchOptions());
|
|
const page = await browser.newPage();
|
|
await page.setViewport({ width: 1280, height: 800 });
|
|
if (isCI) {
|
|
page.setDefaultTimeout(60000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
}
|
|
|
|
page.on('pageerror', (e) => console.log('PAGE ERROR:', e.message));
|
|
page.on('console', (m) => {
|
|
if (m.type() === 'error') console.log('BROWSER ERROR:', m.text());
|
|
});
|
|
|
|
const auth = new AuthHelper(page, BASE_URL);
|
|
|
|
let passed = 0;
|
|
let failed = 0;
|
|
|
|
try {
|
|
await auth.ensureAuthenticated();
|
|
|
|
// Test 1: New Chat button visible on fresh page load
|
|
console.log('Test 1: New Chat button is present on fresh page');
|
|
try {
|
|
await gotoChat(page);
|
|
const visible = await page.$eval(
|
|
'#new-chat-btn',
|
|
(b) => getComputedStyle(b).display !== 'none' && !b.disabled
|
|
);
|
|
if (!visible) throw new Error('#new-chat-btn missing/hidden');
|
|
console.log('PASSED');
|
|
passed++;
|
|
} catch (e) {
|
|
console.log(`FAILED: ${e.message}`);
|
|
await snap(page, 'visible');
|
|
failed++;
|
|
}
|
|
|
|
// Test 2: After starting a session, clicking New Chat resets URL +
|
|
// re-shows welcome + clears title.
|
|
console.log('Test 2: Clicking New Chat resets the UI state');
|
|
try {
|
|
await gotoChat(page);
|
|
await startSessionByChip(page);
|
|
|
|
// Title should have moved off "New Chat" — server returns a
|
|
// session title from the initial query.
|
|
// We don't assert what the title became, only that we left
|
|
// the welcome state and then return to it after the reset.
|
|
await page.evaluate(() => {
|
|
document.getElementById('new-chat-btn').click();
|
|
});
|
|
|
|
// URL should be /chat/ again
|
|
await page.waitForFunction(
|
|
() =>
|
|
window.location.pathname === '/chat/' ||
|
|
window.location.pathname === '/chat',
|
|
{ timeout: TIMEOUTS.selector }
|
|
);
|
|
|
|
// Welcome screen visible again
|
|
await page.waitForFunction(
|
|
() => {
|
|
const el = document.getElementById('chat-welcome');
|
|
return el && getComputedStyle(el).display !== 'none';
|
|
},
|
|
{ timeout: TIMEOUTS.selector }
|
|
);
|
|
|
|
// Title resets to "New Chat" (updateTitle('New Chat'), chat.js)
|
|
const title = await page.$eval('#chat-title', (h) => (h.textContent || '').trim());
|
|
if (title !== 'New Chat') {
|
|
throw new Error(`Title did not reset; got "${title}"`);
|
|
}
|
|
|
|
// Edit/Export buttons hidden again (hideSessionButtons, chat.js)
|
|
const editHidden = await page.$eval('#edit-title-btn', (b) => b.style.display === 'none');
|
|
const exportHidden = await page.$eval('#export-chat-btn', (b) => b.style.display === 'none');
|
|
if (!editHidden || !exportHidden) {
|
|
throw new Error(
|
|
`Session buttons still visible: edit=${!editHidden} export=${!exportHidden}`
|
|
);
|
|
}
|
|
console.log('PASSED');
|
|
passed++;
|
|
} catch (e) {
|
|
console.log(`FAILED: ${e.message}`);
|
|
await snap(page, 'reset');
|
|
failed++;
|
|
}
|
|
|
|
// Test 3: After reset, typing in input still enables send button —
|
|
// proves isProcessing was cleared. Calls the exported
|
|
// startNewChat() directly to isolate state-reset semantics
|
|
// from the chip-click/research-spawn flake surface.
|
|
console.log('Test 3: Send button works again after New Chat reset');
|
|
try {
|
|
await gotoChat(page);
|
|
// Directly invoke the exported reset (no chip click, no
|
|
// research spawn) — we only care that the reset path leaves
|
|
// the input usable.
|
|
await page.evaluate(() => {
|
|
window.chatComponent.startNewChat();
|
|
});
|
|
|
|
await page.waitForFunction(
|
|
() => {
|
|
const el = document.getElementById('chat-welcome');
|
|
return el && getComputedStyle(el).display !== 'none';
|
|
},
|
|
{ timeout: TIMEOUTS.selector }
|
|
);
|
|
|
|
// Set value directly + dispatch the input event so the listener
|
|
// at chat.js fires.
|
|
await page.evaluate(() => {
|
|
const ta = document.getElementById('chat-input');
|
|
ta.value = 'after-reset probe';
|
|
ta.dispatchEvent(new Event('input', { bubbles: true }));
|
|
});
|
|
const disabled = await page.$eval('#send-btn', (b) => b.disabled);
|
|
if (disabled) throw new Error('Send button still disabled after reset+typing');
|
|
console.log('PASSED');
|
|
passed++;
|
|
} catch (e) {
|
|
console.log(`FAILED: ${e.message}`);
|
|
await snap(page, 'reusable');
|
|
failed++;
|
|
}
|
|
} catch (e) {
|
|
console.log(`Test suite error: ${e.message}`);
|
|
failed++;
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
|
|
console.log('-'.repeat(50));
|
|
console.log(`Chat New-Chat Button Tests — passed: ${passed}, failed: ${failed}`);
|
|
console.log('-'.repeat(50));
|
|
if (failed > 0) process.exit(1);
|
|
}
|
|
|
|
run().catch((e) => {
|
|
console.error('Test runner error:', e);
|
|
process.exit(1);
|
|
});
|