// SPDX-FileCopyrightText: 2026 Scientific Computing Studio, LLC // SPDX-License-Identifier: Apache-2.0 // A phone-width screen shows one part of a workspace at a time (styles.css, src/ui/shell.ts setNarrow); a wider one // must not see any of it: AGENTS.md rule 7 keeps the workspace's parts where they are on a normal screen. import test from 'node:test'; import assert from 'node:assert/strict'; import { readFileSync } from 'node:fs'; const css = readFileSync(new URL('../styles.css', import.meta.url), 'utf8').replace(/\/\*[\s\S]*?\*\//g, ''); /** The top-level blocks of a stylesheet: [prelude, body] pairs. */ function blocks(text) { const out = []; let depth = 0, start = 0, prelude = ''; for (let i = 0; i < text.length; i++) { if (text[i] === '{') { if (depth === 0) { prelude = text.slice(start, i).trim(); start = i + 1; } depth++; } else if (text[i] === '}') { depth--; if (depth === 0) { out.push([prelude, text.slice(start, i)]); start = i + 1; } } } return out; } test('every narrow-screen rule is inside the 700px media query, and the bar is hidden outside it', () => { const top = blocks(css); const outside = top.filter(([p]) => !p.startsWith('@media')).map(([p, b]) => `${p}{${b}}`); assert.ok(outside.some((r) => /^\.narrow-bar\{\s*display: none;\s*\}$/.test(r.replace(/\s*\{\s*/, '{').trim())), '.narrow-bar is display: none on a normal screen'); for (const r of outside) assert.doesNotMatch(r, /data-narrow/, `a rule outside the media query reads data-narrow: ${r.slice(0, 80)}`); for (const [p, b] of top.filter(([p]) => p.startsWith('@media') && !/max-width: 700px/.test(p))) assert.doesNotMatch(b, /data-narrow|narrow-bar/, `${p} reads the narrow layout`); const narrow = top.filter(([p]) => /^@media \(max-width: 700px\)$/.test(p)).map(([, b]) => b).join('\n'); for (const part of ['code', 'side', 'dock']) assert.match(narrow, new RegExp(`data-narrow="${part}"`), part); }); test('the shell offers the parts, and Run, Compile & run and a diagnostic\'s line show the part they open', () => { const shell = readFileSync(new URL('../src/ui/shell.ts', import.meta.url), 'utf8'); assert.match(shell, /\[\['code', 'Code'\], \['side', 'Board'\]\] : \[\['code', 'Code'\], \['side', 'Run and views'\], \['dock', 'Setup and output'\]\]/); assert.match(shell, /this\.stepper\?\.goto\(this\.session\.trace\(\)\?\.count \?\? 0\); this\.setNarrow\('side'\);/, 'Run shows the Run view'); assert.match(shell, /if \(open\) this\.setNarrow\('dock'\);/, 'opening the dock (Compile & run) shows it'); assert.match(shell, /reveal: \(lang, line\) => \{\n\s*this\.setNarrow\('code'\);/, 'a line in the code shows the code'); }); test('a phone-width toolbar is three rows: the classes its rules order are the ones the shell gives', () => { // the mark, the area, help and the theme; the problem, its versions and Reset; the actions. A wide screen keeps the // toolbar's one row, so every one of these rules is inside the 700px query and none applies to an embed's toolbar. const shell = readFileSync(new URL('../src/ui/shell.ts', import.meta.url), 'utf8'); const narrow = blocks(css).filter(([p]) => /^@media \(max-width: 700px\)$/.test(p)).map(([, b]) => b).join('\n'); for (const cls of ['tool-help', 'tool-reset', 'brand-name', 'icon-btn', 'versions']) { assert.match(shell, new RegExp(`['\` ]${cls}['\` $]`), `the shell no longer gives .${cls}`); assert.match(narrow, new RegExp(`\\.shell:not\\(\\.shell-embed\\) > \\.toolbar[^{]*\\.${cls}\\b`), `no narrow rule for .${cls}`); } assert.match(shell, /class: 'shell' \+ \(this\.embed \? ' shell-embed' : ''\)/, 'an embedded workspace is marked, so its toolbar keeps its own order'); assert.match(narrow, /\.toolbar::before, \.shell:not\(\.shell-embed\) > \.toolbar::after \{[^}]*flex-basis: 100%/, 'the two line breaks between the rows'); // the short label of the Best practices switch is for a small phone only assert.match(shell, /class: 'tool-wide' \}, 'Best practices'\), el\('span', \{ class: 'tool-tight' \}, 'Practices'\)/); const outside = blocks(css).filter(([p]) => !p.startsWith('@media')).map(([p, b]) => `${p}{${b}}`.replace(/\s+/g, ' ')); assert.ok(outside.some((r) => /^\.tool-tight\s*\{ display: none; \}$/.test(r)), '.tool-tight is hidden on a normal screen'); });