Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Note SPBoucher AI8 * File : tests/e2e/model-picker.mjs9 * Module : tests10 * Repository : https://git.spboucher.ai/note-spboucher-ai11 * Project Website : https://note.spboucher.ai12 * Created : 2026-11-1913 * Last Modified : 2026-11-1914 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243// Manual check of the model selector in a real browser (scratch instance): opens it, searches, navigates with the keyboard, selects.44import { chromium } from "@playwright/test";45import fs from "node:fs";46const token = fs.readFileSync(process.env.HOME + "/dev/note-next-ai-data/.session", "utf8").trim();47const out = process.env.HOME + "/dev/note-next-ai-data/live";48const browser = await chromium.launch();49for (const [name, viewport, scheme] of [["desktop", { width: 1280, height: 800 }, "light"], ["phone", { width: 390, height: 844 }, "dark"]]) {50 const ctx = await browser.newContext({ viewport, colorScheme: scheme, extraHTTPHeaders: { cookie: `__Host-note_session=${token}` } });51 const page = await ctx.newPage(); const errors = []; page.on("pageerror", (e) => errors.push(String(e))); page.on("console", (m) => { if (m.type() === "error") errors.push(m.text()); });52 await page.goto("http://localhost:8484/", { waitUntil: "networkidle" });53 let btn = page.locator('button[aria-label="Model"]').first();54 if (!(await btn.count()) || !(await btn.isVisible().catch(() => false))) { const open = page.locator('button[aria-label*="ssistant" i], button[aria-label*="AI" ]').first(); if (await open.count()) await open.click().catch(() => {}); btn = page.locator('button[aria-label="Model"]').first(); }55 await btn.scrollIntoViewIfNeeded(); const before = (await btn.innerText()).trim();56 await btn.click(); await page.waitForSelector('[role="listbox"]');57 const options = await page.locator('[role="option"]').count(); const groups = await page.locator('[role="group"]').evaluateAll((els) => els.map((e) => e.getAttribute("aria-label")));58 await page.waitForTimeout(350); await page.screenshot({ path: `${out}/picker-${name}-open.png` });59 await page.keyboard.type("haiku"); await page.waitForTimeout(150);60 const filtered = await page.locator('[role="option"]').evaluateAll((els) => els.map((e) => e.innerText.replace(/\s+/g, " ").trim()));61 const activeId = await page.locator('input[role="combobox"]').getAttribute("aria-activedescendant");62 await page.keyboard.press("ArrowDown"); await page.keyboard.press("ArrowUp"); await page.screenshot({ path: `${out}/picker-${name}-search.png` });63 await page.keyboard.press("Enter"); await page.waitForTimeout(200);64 const after = (await btn.innerText()).replace(/\s+/g, " ").trim(); const closed = (await page.locator('[role="listbox"]').count()) === 0;65 // reopen, show unavailable, Escape closes66 await btn.click(); await page.waitForSelector('[role="listbox"]'); const show = page.getByRole("button", { name: "Show" }); let withUnavailable = null, disabled = null;67 if (await show.count()) { await show.click(); await page.waitForFunction(() => document.querySelectorAll('[role="option"][aria-disabled="true"]').length > 0, null, { timeout: 15000 }).catch(() => {}); withUnavailable = await page.locator('[role="option"]').count(); disabled = await page.locator('[role="option"][aria-disabled="true"]').count(); await page.keyboard.type("claude sonnet"); await page.waitForTimeout(200); await page.screenshot({ path: `${out}/picker-${name}-unavailable.png` }); }68 await page.keyboard.press("Escape"); await page.waitForTimeout(150); const escClosed = (await page.locator('[role="listbox"]').count()) === 0;69 const logo = await page.evaluate(async () => (await fetch("/model-logos/anthropic.svg")).status);70 console.log(JSON.stringify({ name, before, options, groups, filtered, activeId: Boolean(activeId), after, closed, withUnavailable, disabled, escClosed, logo, errors: errors.slice(0, 5) }));71 await ctx.close();72}73await browser.close();74