'use strict'; // The one panel, without an editor and without a browser: the settings table against the manifest, // the page's text read as a tree (a small reader of its own, below — no DOM library), the // stylesheet's rules for lining up and for a narrow side bar, how one moves between the views, // what the views draw, what the page may say, and the sign-in as the Account view steps through // it. What this cannot show is how it looks: no layout is computed here. const test = require('node:test'); const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const settings = require('../src/settings'); const { SCHEMA, validate, serverAddress } = require('../src/messages'); const { Account } = require('../src/account'); const { Chat } = require('../src/chat'); const { chatHtml, TABS } = require('../src/webview'); const page = require('../media/chat.js'); const { tempDir } = require('./helpers'); const ROOT = path.join(__dirname, '..'); const pkg = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8')); const properties = pkg.contributes.configuration.properties; const fields = settings.fields(properties); const css = fs.readFileSync(path.join(ROOT, 'media', 'chat.css'), 'utf8').replace(/\/\*[\s\S]*?\*\//g, ''); const html = chatHtml({ cspSource: 'https://file.example', nonce: 'abc123', scriptUri: 'https://file.example/media/chat.js', styleUri: 'https://file.example/media/chat.css', logoUri: 'https://file.example/media/logo.png', fields, }); // ---- a reader of the page's text: elements, attributes, text; nothing is run ---------------- const VOID = new Set(['meta', 'link', 'input', 'img', 'br', 'path', 'hr']); class El { constructor(tag, attrs, parent) { this.tag = tag; this.attrs = attrs; this.parent = parent; this.children = []; this.own = ''; } get text() { const own = this.own.replace(/"/g, '"').replace(/'/g, "'").replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&'); return (own + this.children.map((c) => c.text).join(' ')).replace(/\s+/g, ' ').trim(); } all(out) { const list = out || []; for (const c of this.children) { list.push(c); c.all(list); } return list; } find(test_) { return this.all().filter(test_); } has(cls) { return String(this.attrs.class || '').split(/\s+/).includes(cls); } } function read(text) { const root = new El('#root', {}, null); let at = root; const re = /]*>|<(\/?)([A-Za-z][A-Za-z0-9]*)((?:\s+[A-Za-z_:][-A-Za-z0-9_:.]*(?:="[^"]*")?)*)\s*(\/?)>|([^<]+)/g; let pos = 0; for (let m; (m = re.exec(text)); ) { assert.equal(m.index, pos, 'nothing unreadable at ' + pos + ': ' + text.slice(pos, pos + 60)); pos = re.lastIndex; if (m[5] !== undefined) { at.own += m[5]; continue; } if (!m[2]) continue; const tag = m[2].toLowerCase(); if (m[1]) { assert.equal(at.tag, tag, ` closes <${at.tag}>`); at = at.parent; continue; } const attrs = {}; for (const a of m[3].matchAll(/([A-Za-z_:][-A-Za-z0-9_:.]*)(?:="([^"]*)")?/g)) { assert.ok(!(a[1] in attrs), `<${tag}> has ${a[1]} twice`); attrs[a[1]] = a[2] === undefined ? '' : a[2].replace(/"/g, '"').replace(/'/g, "'").replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&'); } const el = new El(tag, attrs, at); at.children.push(el); if (!VOID.has(tag) && !m[4]) at = el; } assert.equal(pos, text.length); assert.equal(at, root, 'every element is closed'); return root; } const dom = read(html); const byId = (id) => { const found = dom.find((e) => e.attrs.id === id); assert.equal(found.length, 1, `one element with the id ${id}`); return found[0]; }; // A document that can only make elements and text (as in tests/markdown.test.js): what the page's // own drawing is run against. class Node { constructor(tag, text) { this.tag = tag; this.text = text; this.children = []; this.attrs = {}; this.className = ''; this.listeners = {}; } appendChild(c) { this.children.push(c); return c; } setAttribute(k, v) { this.attrs[k] = String(v); } addEventListener(name, fn) { this.listeners[name] = fn; } set textContent(v) { this.children = [new Node('#text', String(v))]; } get textContent() { return this.tag === '#text' ? this.text : this.children.map((c) => c.textContent).join(''); } all(out) { const list = out || []; for (const c of this.children) { list.push(c); c.all(list); } return list; } buttons() { return this.all().filter((n) => n.tag === 'button'); } } const doc = { createElement: (tag) => new Node(tag), createTextNode: (text) => new Node('#text', text) }; // ---- the settings table ----------------------------------------------------------------------- test('every contributed setting is in the panel, with the control its type takes; none is in the table and not in the manifest', () => { const contributed = Object.keys(properties).map((k) => k.replace(/^llembas\./, '')); assert.ok(contributed.length >= 12); assert.deepEqual(Object.keys(settings.PRESENT).sort(), contributed.slice().sort(), 'the table and the manifest name the same settings: add a new one to src/settings.js'); assert.deepEqual(fields.map((f) => f.key).sort(), contributed.slice().sort()); for (const f of fields) { const def = properties['llembas.' + f.key]; assert.equal(f.type, def.type, f.key); assert.equal(settings.CONTROLS[f.control], def.type, `${f.key}: a ${f.control} for a ${def.type}`); assert.equal(f.control === 'select', Array.isArray(def.enum), `${f.key}: a list of choices is a select, and only that`); if (def.enum) { assert.deepEqual(f.choices, def.enum); assert.deepEqual(Object.keys(settings.PRESENT[f.key].choices), def.enum, `${f.key}: a label for every choice`); } assert.deepEqual([f.min, f.max], [def.minimum === undefined ? null : def.minimum, def.maximum === undefined ? null : def.maximum], f.key); assert.equal(f.machine, def.scope === 'machine', f.key); assert.ok(settings.VIEWS.includes(f.view) && f.label && f.hint && !/`/.test(f.hint), f.key); assert.deepEqual(f.default, def.default); if (def.type === 'number') assert.ok(Number.isInteger(def.default) && Number.isInteger(def.minimum) && Number.isInteger(def.maximum), `${f.key}: whole numbers with a range`); } // What starts or reaches a program is never a folder's to set. for (const key of ['command', 'login.caFile', 'chat.startMode']) assert.equal(fields.find((f) => f.key === key).machine, true, key); // The views the settings are spread over, and that each view has some. assert.deepEqual([...new Set(fields.map((f) => f.view))].sort(), ['account', 'autocomplete', 'settings']); assert.deepEqual(fields.filter((f) => f.view === 'autocomplete').map((f) => f.key), ['complete.auto', 'complete.length', 'complete.maxTokens', 'complete.debounce', 'complete.instructions'], 'everything llembas.complete.* holds'); }); test('a setting the table does not know still appears, under Settings, by its key and with its own type', () => { const more = settings.fields({ ...properties, 'llembas.new.thing': { type: 'number', default: 3, minimum: 1, maximum: 9, description: 'A `new` thing.' }, 'other.setting': { type: 'string' } }); const f = more[more.length - 1]; assert.deepEqual( { key: f.key, view: f.view, group: f.group, label: f.label, control: f.control, hint: f.hint, min: f.min, max: f.max, machine: f.machine }, { key: 'new.thing', view: 'settings', group: 'Other', label: 'llembas.new.thing', control: 'number', hint: 'A new thing.', min: 1, max: 9, machine: false }, ); assert.ok(!more.some((x) => x.key.includes('other')), "another extension's setting is none of the panel's"); const page_ = chatHtml({ cspSource: 'https://file.example', nonce: 'n', scriptUri: 'https://file.example/s', styleUri: 'https://file.example/c', fields: more }); assert.ok(page_.includes('data-setting="new.thing"')); // What the manifest says is written into the page escaped, whatever it holds. const hostile = settings.fields({ 'llembas.x': { type: 'string', default: '', description: ' "quoted" & more' } }); const out = chatHtml({ cspSource: 'https://file.example', nonce: 'n', scriptUri: 'https://file.example/s', styleUri: 'https://file.example/c', fields: hostile }); assert.ok(!out.includes(' { const ok = (w) => settings.checkWrite(fields, w); assert.deepEqual(ok({ key: 'complete.auto', value: false, target: 'user' }), { ok: true, key: 'complete.auto', value: false, target: 'user' }); assert.deepEqual(ok({ key: 'complete.maxTokens', value: 4096, target: 'workspace' }), { ok: true, key: 'complete.maxTokens', value: 4096, target: 'workspace' }); assert.deepEqual(ok({ key: 'complete.instructions', value: ' two\nlines ', target: 'user' }), { ok: true, key: 'complete.instructions', value: ' two\nlines ', target: 'user' }); assert.deepEqual(ok({ key: 'command', value: ' /opt/lembas/bin/lembas ', target: 'user' }), { ok: true, key: 'command', value: '/opt/lembas/bin/lembas', target: 'user' }); assert.deepEqual(ok({ key: 'command', target: 'user', reset: true }), { ok: true, key: 'command', value: undefined, target: 'user' }); for (const bad of [ null, 'x', {}, { key: 7 }, { key: 'nope', value: 1 }, { key: 'constructor', value: 1 }, { key: 'complete.auto', value: 1 }, { key: 'complete.auto', value: 'true' }, { key: 'complete.maxTokens', value: 4097 }, { key: 'complete.maxTokens', value: NaN }, { key: 'complete.maxTokens', value: Infinity }, { key: 'complete.maxTokens', value: 2.5 }, { key: 'media.maxMegabytes', value: 0 }, { key: 'complete.length', value: 'Auto' }, { key: 'complete.length', value: 3 }, { key: 'complete.instructions', value: 'x'.repeat(2001) }, { key: 'complete.instructions', value: 'a\u0000b' }, { key: 'chat.startMode', value: 'plan\nmode' }, { key: 'login.caFile', value: '/a', target: 'workspace' }, { key: 'command', value: 'x'.repeat(4097) }, { key: 'complete.auto', value: true, target: 'machine' }, { key: 'command', target: 'workspace', reset: true }, ]) { const r = ok(bad); assert.equal(r.ok, false, JSON.stringify(bad)); assert.ok(r.why && r.why.length < 200); } // Where a value comes from, as the page is told. const f = fields.find((x) => x.key === 'complete.debounce'); assert.deepEqual(settings.levelsOf(f, { defaultValue: 250 }, 250), { value: 250, from: 'default', user: false, workspace: false }); assert.deepEqual(settings.levelsOf(f, { globalValue: 100, workspaceValue: 300 }, 300), { value: 300, from: 'workspace', user: true, workspace: true }); assert.deepEqual(settings.levelsOf(f, { globalValue: 100, workspaceFolderValue: 5 }, 5), { value: 5, from: 'folder', user: true, workspace: false }); assert.deepEqual(settings.levelsOf(f, undefined, 'junk'), { value: 250, from: 'default', user: false, workspace: false }); }); // ---- the page, read as a tree ------------------------------------------------------------------- test('the page: one frame with a tab for every view, each a tab panel; ids are unique and every reference lands', () => { const ids = dom.find((e) => e.attrs.id !== undefined).map((e) => e.attrs.id); assert.equal(new Set(ids).size, ids.length, 'no id twice: ' + ids.filter((x, i) => ids.indexOf(x) !== i).join(', ')); const list = dom.find((e) => e.attrs.role === 'tablist'); assert.equal(list.length, 1); assert.equal(list[0].attrs['aria-orientation'], 'horizontal'); assert.ok(list[0].attrs['aria-label']); const tabs = list[0].children; assert.deepEqual(tabs.map((b) => b.attrs['data-view']), ['chat', 'sessions', 'models', 'autocomplete', 'settings', 'account', 'status']); assert.deepEqual(tabs.map((b) => b.attrs['data-view']), page.VIEWS, 'the page script and the page agree on the views'); assert.deepEqual(tabs.map((b) => b.attrs['data-view']), TABS.map((x) => x.id)); assert.match(css, new RegExp(`\\.tablist\\s*\\{[^}]*grid-template-columns:\\s*repeat\\(${tabs.length},\\s*minmax\\(0,\\s*1fr\\)\\)`), 'as many equal tracks as tabs: the strip cannot be wider than the frame'); for (const b of tabs) { assert.equal(b.tag, 'button'); assert.deepEqual([b.attrs.role, b.attrs.type], ['tab', 'button']); assert.equal(b.attrs.id, 'tab-' + b.attrs['data-view']); assert.ok(b.attrs.title && b.text === b.attrs.title, 'a name for a screen reader, and the same as a tooltip'); const panel = byId(b.attrs['aria-controls']); assert.equal(panel.attrs.role, 'tabpanel'); assert.equal(panel.attrs['aria-labelledby'], b.attrs.id); const icon = b.children.find((c) => c.tag === 'svg'); assert.deepEqual([icon.attrs['aria-hidden'], icon.attrs.focusable], ['true', 'false'], 'the drawing is not read'); } // One tab is selected and in the tab order: the arrow keys move between the rest (roving tabindex). assert.deepEqual(tabs.map((b) => b.attrs['aria-selected']), ['true', 'false', 'false', 'false', 'false', 'false', 'false']); assert.deepEqual(tabs.map((b) => b.attrs.tabindex), ['0', '-1', '-1', '-1', '-1', '-1', '-1']); // Every view but the conversation starts hidden, has a heading and a way back that names itself. const panes = dom.find((e) => e.has('pane')); assert.deepEqual(panes.map((p) => p.attrs['data-pane']), ['sessions', 'models', 'autocomplete', 'settings', 'account', 'status', 'files']); assert.deepEqual(panes.map((p) => p.attrs['data-pane']), page.BESIDE, 'every pane may stand beside the conversation'); for (const p of panes) { assert.ok('hidden' in p.attrs && p.attrs.tabindex === '-1', p.attrs.id); assert.equal(p.find((e) => e.tag === 'h2').length, 1); const close = p.find((e) => e.attrs['data-close'] !== undefined); assert.equal(close.length, 1); assert.match(close[0].attrs.title, /Esc/); } assert.equal(byId('view-files').attrs.role, 'region', 'a pane without a tab is a region with its heading for a name'); assert.equal(byId('view-files').attrs['aria-labelledby'], 'h-files'); assert.ok(!('hidden' in byId('view-chat').attrs)); // References: a label's control, what describes or names or is controlled by something. for (const e of dom.all()) { for (const name of ['for', 'aria-controls', 'aria-labelledby', 'aria-describedby']) if (e.attrs[name] !== undefined) byId(e.attrs[name]); } // Landmarks, and where a screen reader is told what changed. assert.equal(dom.find((e) => e.tag === 'nav').length, 1); assert.equal(dom.find((e) => e.tag === 'main').length, 1); for (const id of ['announce', 'sessions-status', 'models-status', 'account-who', 'account-flow', 'status-list', 'files-status']) assert.equal(byId(id).attrs['aria-live'], 'polite', id); }); test('the page: every control has a name and is a real control; nothing inline, nothing from elsewhere, no colour of its own', () => { const labelled = new Set(dom.find((e) => e.tag === 'label').map((l) => l.attrs.for)); for (const e of dom.find((x) => ['input', 'select', 'textarea'].includes(x.tag) && x.attrs.type !== 'hidden')) { assert.ok(labelled.has(e.attrs.id) || e.attrs['aria-label'], `a name for <${e.tag} id="${e.attrs.id}">`); } for (const b of dom.find((x) => x.tag === 'button')) { assert.equal(b.attrs.type, 'button', b.attrs.id || b.text); assert.ok(b.text || b.attrs['aria-label'], 'a button says what it does'); } assert.equal(dom.find((e) => e.tag === 'a' || e.tag === 'form' || e.tag === 'iframe' || e.tag === 'object').length, 0, 'nothing that navigates or embeds'); for (const e of dom.all()) { for (const name of Object.keys(e.attrs)) { assert.ok(!/^on/i.test(name), `no inline handler: ${name} on <${e.tag}>`); assert.notEqual(name, 'style', 'no inline style'); } } // Only the script, the stylesheet and the logo are loaded, each from the extension's own place. const loaded = dom.find((e) => e.attrs.src !== undefined || e.attrs.href !== undefined).map((e) => e.attrs.src || e.attrs.href); assert.deepEqual(loaded.sort(), ['https://file.example/media/chat.css', 'https://file.example/media/chat.js', 'https://file.example/media/logo.png', 'https://file.example/media/logo.png']); const csp = dom.find((e) => e.tag === 'meta' && e.attrs['http-equiv'] === 'Content-Security-Policy'); assert.equal(csp.length, 1); assert.equal(csp[0].attrs.content, "default-src 'none'; img-src https://file.example; style-src https://file.example; script-src 'nonce-abc123'; base-uri 'none'; form-action 'none'"); assert.equal(dom.find((e) => e.tag === 'script').length, 1); assert.equal(dom.find((e) => e.tag === 'script')[0].attrs.nonce, 'abc123'); // Colour: the drawings take the text's; nothing else in the page names one. assert.ok(!/#[0-9a-fA-F]{3,8}\b|\b(rgb|rgba|hsl|hsla)\(/.test(html.replace(/'/g, '')), 'no colour written into the page'); for (const e of dom.find((x) => x.attrs.fill !== undefined || x.attrs.stroke !== undefined)) { assert.ok(['none', 'currentColor'].includes(e.attrs.fill) && ['none', 'currentColor', undefined].includes(e.attrs.stroke), 'a drawing in the colour of the text'); } // Nothing predefined: no server, model or key is written into the page. assert.ok(!/https?:\/\/(?!file\.example)/.test(html), 'no address but the page\'s own files'); for (const e of dom.find((x) => x.tag === 'input' && x.attrs.type !== 'hidden')) assert.equal(e.attrs.value, undefined, `${e.attrs.id} starts empty`); }); /** The four slots of a field, in order. */ const SLOTS = ['f-label', 'f-control', 'f-hint', 'f-level']; test('forms: every field is label, control, hint and level — all four, in that order, even when one is empty', () => { const all = dom.find((e) => e.has('field')); assert.ok(all.length >= fields.length + 4); for (const f of all) { assert.ok(f.parent.has('form'), `the field ${f.attrs['data-field']} is a child of a form: the form's rows are what lines fields up`); assert.deepEqual(f.children.map((c) => String(c.attrs.class).split(' ')[0]), SLOTS, f.attrs['data-field']); const [label, control, hint] = f.children; assert.equal(label.tag, 'label'); assert.ok(label.text, 'a label says something'); const inputs = control.find((e) => ['input', 'select', 'textarea'].includes(e.tag)); assert.equal(control.children.length, 1, 'one control'); assert.equal(inputs.length, 1); assert.equal(label.attrs.for, inputs[0].attrs.id, 'the label is tied to its control'); assert.equal(inputs[0].attrs['aria-describedby'], hint.attrs.id, 'and the hint describes it'); assert.ok(hint.text, 'a hint says something'); } // A form holds fields and nothing else, so no stray child takes a row. for (const form of dom.find((e) => e.has('form'))) assert.ok(form.children.length > 0 && form.children.every((c) => c.has('field')), 'only fields in a form'); }); test('forms: a field for every setting, in its view, with its level — User and Workspace where a folder may hold it', () => { const controls = dom.find((e) => e.attrs['data-setting'] !== undefined); assert.deepEqual(controls.map((c) => c.attrs['data-setting']).sort(), fields.map((f) => f.key).sort(), 'each setting once'); for (const f of fields) { const c = controls.find((x) => x.attrs['data-setting'] === f.key); let pane = c; while (pane && !pane.has('pane')) pane = pane.parent; assert.equal(pane.attrs['data-pane'], f.view, `${f.key} is in the ${f.view} view`); const field = c.parent.parent; assert.ok(field.has('field')); assert.equal(field.children[0].text, f.label); assert.ok(field.children[2].text.includes('llembas.' + f.key), 'the hint names the setting as settings.json does'); // The control fits the type. if (f.control === 'toggle') assert.deepEqual([c.tag, c.attrs.type], ['input', 'checkbox']); else if (f.control === 'number') assert.deepEqual([c.tag, c.attrs.type, c.attrs.min, c.attrs.max, c.attrs.step], ['input', 'number', String(f.min), String(f.max), '1']); else if (f.control === 'select') assert.deepEqual(c.children.map((o) => o.attrs.value), f.choices); else if (f.control === 'longtext') assert.deepEqual([c.tag, c.attrs.maxlength], ['textarea', String(f.maxLength)]); else assert.deepEqual([c.tag, c.attrs.type, c.attrs.maxlength], ['input', 'text', String(f.maxLength)]); // The level: where the value comes from, where the next change goes, and a reset there. const level = field.children[3]; const origin = level.find((e) => e.has('f-origin')); const reset = level.find((e) => e.attrs['data-reset'] === f.key); assert.deepEqual([origin.length, reset.length], [1, 1], f.key); assert.match(reset[0].attrs['aria-label'], /^Reset “.+” at this level$/); const choose = level.find((e) => e.tag === 'select'); if (f.machine) { assert.equal(choose.length, 0, `${f.key}: no Workspace level to choose`); assert.equal(level.find((e) => e.has('f-fixed'))[0].text, 'User settings only: a folder cannot set this.'); } else { assert.deepEqual(choose[0].children.map((o) => [o.attrs.value, o.text]), [['user', 'User'], ['workspace', 'Workspace']]); assert.ok(choose[0].attrs['aria-label'].includes(f.label)); } } // The other forms: the models and the address, fields like any other. for (const id of ['m-session', 'm-main', 'm-autocomplete', 'account-address']) assert.ok(byId(id).parent.parent.has('field'), id); assert.deepEqual(byId('m-main-keep').children.map((o) => o.attrs.value), ['account', 'window']); // The way out to the editor's Settings page is a small link at the foot of Settings, after every field. const out = byId('open-settings-ui'); let p = out; while (!p.has('pane-body')) p = p.parent; assert.equal(p.parent.attrs['data-pane'], 'settings'); assert.equal(p.children[p.children.length - 1].find((e) => e === out).length, 1, 'the last thing in the view'); }); // ---- the stylesheet: lined up by construction, and narrow first ------------------------------------- /** The declarations of the first rule whose selector list is exactly `selector`. */ function rule(selector) { const escaped = selector.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); const m = new RegExp(`(?:^|\\})\\s*${escaped}\\s*\\{([^}]*)\\}`).exec(css); assert.ok(m, `a rule for ${selector}`); return Object.fromEntries(m[1].split(';').map((d) => d.trim()).filter(Boolean).map((d) => [d.slice(0, d.indexOf(':')).trim(), d.slice(d.indexOf(':') + 1).trim()])); } test('the stylesheet: fields share the form\'s rows (subgrid), and nothing is lined up by its bottom or its baseline', () => { const form = rule('.form'); assert.equal(form.display, 'grid'); assert.match(form['grid-template-columns'], /^repeat\(auto-fit, minmax\(min\(100%, \d+px\), 1fr\)\)$/, 'a track gives up its minimum before the frame scrolls sideways'); const field = rule('.field'); assert.equal(field.display, 'grid'); assert.equal(field['grid-template-rows'], 'subgrid'); assert.equal(field['grid-row'], `span ${SLOTS.length}`, 'as many rows as a field has slots'); // The rule this tree was given after a form whose longest hint pushed its own control up. for (const m of css.matchAll(/(align-items|align-self|align-content|justify-items)\s*:\s*([^;}]+)/g)) { assert.ok(!/\b(end|flex-end|baseline|last)\b/.test(m[2]), `${m[1]}: ${m[2].trim()} lines up by coincidence`); } assert.ok(!/vertical-align\s*:\s*(bottom|baseline)/.test(css)); }); test('the stylesheet: nothing has a width that a 240 px side bar cannot hold; wide things scroll in themselves', () => { // Every grid track with a pixel minimum gives it up below that width. for (const m of css.matchAll(/minmax\(([^()]*(?:\([^()]*\))?[^()]*),/g)) { const min = m[1].trim(); assert.ok(/^(0|min\(100%, \d+px\)|\d+(\.\d+)?em)$/.test(min), `a track that cannot shrink: minmax(${min}, …)`); const em = /^(\d+(\.\d+)?)em$/.exec(min); if (em) assert.ok(Number(em[1]) <= 10, min); } // No fixed track or box wider than a narrow side bar. for (const m of css.matchAll(/(?:^|[;{\s])((?:min-|max-)?width|flex-basis|grid-template-columns)\s*:\s*([^;}]+)/g)) { if (m[1] === 'max-width') continue; for (const px of m[2].matchAll(/(\d+)px/g)) { const inMin = new RegExp(`min\\(100%, ${px[1]}px\\)`).test(m[2]); assert.ok(inMin || Number(px[1]) <= 48, `${m[1]}: ${m[2].trim()}`); } } // The frame never scrolls sideways; what is wide has its own scroller. assert.equal(rule('.pane-body')['overflow-x'], 'hidden'); assert.equal(rule('#log')['overflow-x'], 'hidden'); assert.equal(rule('pre')['overflow-x'], 'auto'); assert.equal(rule('.table-wrap')['overflow-x'], 'auto'); assert.equal(rule('.stderr').overflow, 'auto'); // Long words in a label, a hint or a row break rather than push. for (const sel of ['.f-label', '.f-hint', '.pane-status', '.facts dd', '.task-title']) assert.equal(rule(sel)['overflow-wrap'], 'anywhere', sel); // Beside the conversation: below it in a narrow frame, next to it in a wide one. assert.equal(rule('.stage.split')['grid-template-rows'], 'minmax(0, 1fr) minmax(0, 1fr)'); assert.match(css, /@media \(min-width: 640px\)\s*\{\s*\.stage\.split\s*\{[^}]*grid-template-columns:\s*minmax\(0, 1fr\) minmax\(0, 1fr\)/); }); test('the stylesheet: what is pressed is 28 px high, focus is visible, high contrast and reduced motion are respected', () => { const px = (v) => Number(/^(\d+)px$/.exec(String(v))[1]); assert.ok(px(rule('button').height) >= 28); assert.ok(px(rule('select').height) >= 28); assert.ok(px(rule('button.tab').height) >= 28); assert.ok(px(rule('button.icon-btn').height) >= 28); assert.ok(px(rule('.f-control')['min-height']) >= 28); assert.ok(px(rule('.f-control input[type="checkbox"]').height) >= 28); assert.ok(px(rule('button.row-main')['min-height']) >= 28); assert.ok(px(rule('button.linkish')['min-height']) >= 28); // The two small buttons are drawn small and pressed large: 4 px more above and below. const reach = rule('button.mini::after, button.plain::after'); assert.deepEqual([reach.position, reach.top, reach.bottom], ['absolute', '-4px', '-4px']); assert.ok(px(rule('button.mini').height) + 8 >= 28 && px(rule('button.plain').height) + 8 >= 28); assert.equal(rule('button.mini').position, 'relative'); assert.equal(rule('button.plain').position, 'relative'); // Focus. assert.match(css, /button:focus-visible[^{]*\{[^}]*outline:\s*1px solid var\(--vscode-focusBorder\)/); assert.match(css, /button\.tab:focus-visible\s*\{[^}]*outline:\s*1px solid var\(--vscode-focusBorder\)/); assert.match(css, /input\[type="checkbox"\]:focus-visible\s*\{[^}]*outline/); // High contrast: the editor's own border colours where a background alone told things apart. assert.match(css, /\.vscode-high-contrast button\.tab\[aria-selected="true"\][^{]*\{[^}]*var\(--vscode-contrastActiveBorder\)/); assert.match(css, /var\(--vscode-contrastBorder/); // No motion where none is wanted. assert.match(css, /@media \(prefers-reduced-motion: reduce\)\s*\{[^}]*animation:\s*none !important;[^}]*transition:\s*none !important/); }); // ---- moving between the views ------------------------------------------------------------------- test('the rule of the panel: a tab opens its view whole; what is reached from the conversation opens beside it and closes back to it', () => { const { navReduce, checkNav, restoreNav, tabKey } = page; const start = { view: 'chat', split: '' }; assert.deepEqual(navReduce(start, { type: 'tab', view: 'settings' }), { view: 'settings', split: '' }); assert.deepEqual(navReduce(start, { type: 'beside', view: 'models' }), { view: 'chat', split: 'models' }); // Beside always means beside the conversation, wherever one was. assert.deepEqual(navReduce({ view: 'settings', split: '' }, { type: 'beside', view: 'sessions' }), { view: 'chat', split: 'sessions' }); assert.deepEqual(navReduce({ view: 'chat', split: 'models' }, { type: 'beside', view: 'account' }), { view: 'chat', split: 'account' }); assert.deepEqual(navReduce({ view: 'chat', split: 'models' }, { type: 'close' }), start); // A tab while something is beside: that view, whole. assert.deepEqual(navReduce({ view: 'chat', split: 'models' }, { type: 'tab', view: 'models' }), { view: 'models', split: '' }); assert.deepEqual(navReduce({ view: 'chat', split: 'models' }, { type: 'tab', view: 'chat' }), start); // The conversation is never beside itself; a pane without a tab is never the whole frame; nonsense is the conversation. assert.deepEqual(navReduce(start, { type: 'beside', view: 'chat' }), start); assert.deepEqual(navReduce(start, { type: 'tab', view: 'files' }), start); assert.deepEqual(navReduce(start, { type: 'beside', view: 'files' }), { view: 'chat', split: 'files' }); for (const junk of [null, 'x', {}, { type: 'tab' }, { type: 'tab', view: '