Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

feat(view): a sidebar lists every project and what needs you [N26]

Corey Olsonc6f40e35ddc4
diff --git a/src/cockpit.js b/src/cockpit.js
index 8c7fb263..8fe2608d 100644
--- a/src/cockpit.js
+++ b/src/cockpit.js
@@ -1,9 +1,11 @@
/**
* The page `pullboard view` serves (N26): one self-contained file, no assets from anywhere, that
- * reads the board through the server's JSON and refreshes itself. It keeps the hosted board's layout:
- * a top bar with the project switcher and tabs, and two panes, a list and the selected thing's
- * detail. Forms post actions that the server runs as CLI commands (N27), so the page never decides a
- * rule itself, and every field a person types in sits outside what the refresh rebuilds.
+ * reads the board through the server's JSON and refreshes itself. The layout is the one the person
+ * asked for: a sidebar listing every project on the machine with what needs them there, and a main
+ * column with the tabs over two panes, a list and the selected thing's detail. Under 900px wide the
+ * sidebar folds into a top bar. Forms post actions that the server runs as CLI commands (N27), so the
+ * page never decides a rule itself, and every field a person types in sits outside what the refresh
+ * rebuilds.
*
* @returns {string}
*/
@@ -24,9 +26,10 @@ export function cockpitPage() {
--shadow: 0 1px 2px rgba(18,26,23,.05), 0 12px 34px -18px rgba(18,26,23,.28);
--sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
--mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
- --top: 56px; --detail-w: 424px; --agents-w: 306px;
+ --top: 56px; --side-w: 236px; --agents-w: clamp(240px, 30%, 306px);
color-scheme: light;
}
+@media (max-width: 1100px) { :root { --side-w: 208px; } }
@media (prefers-color-scheme: dark) { :root {
--ground: #0c110f; --surface: #121815; --surface-2: #171f1b; --line: #232e29; --line-strong: #34423b;
--ink: #e7ece9; --ink-muted: #9caba3; --ink-faint: #6a776f;
@@ -40,31 +43,52 @@ button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
-.top { position: sticky; top: 0; z-index: 10; height: var(--top); display: flex; align-items: center; gap: 18px; padding: 0 18px; background: var(--surface); border-bottom: 1px solid var(--line); }
+.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
+.side { position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 0 10px 16px; background: var(--surface); border-right: 1px solid var(--line); }
+.side-top { display: flex; align-items: center; gap: 10px; height: var(--top); margin: 0 -10px 6px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; white-space: nowrap; }
-.brand svg { width: 22px; height: 22px; }
-.switch { position: relative; }
-.switch-btn { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-weight: 600; max-width: 260px; }
+.brand svg { width: 22px; height: 22px; flex: none; }
+.switch-btn { display: none; align-items: center; gap: 8px; min-width: 0; border: 1px solid var(--line); background: var(--surface-2); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-weight: 600; }
.switch-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.switch-btn small { color: var(--ink-faint); font-weight: 400; }
-.menu { position: absolute; top: calc(100% + 6px); left: 0; width: 340px; max-width: calc(100vw - 24px); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 12px; box-shadow: var(--shadow); padding: 10px; display: grid; gap: 8px; }
-.label { font: 600 11px/1 var(--mono); letter-spacing: .07em; text-transform: uppercase; color: var(--ink-faint); padding: 4px 6px; }
-.proj { text-align: left; border: 1px solid transparent; background: none; border-radius: 8px; padding: 7px 9px; cursor: pointer; display: grid; gap: 2px; width: 100%; }
+.side-body { display: grid; gap: 2px; align-content: start; }
+.label { font: 600 11px/1 var(--mono); letter-spacing: .07em; text-transform: uppercase; color: var(--ink-faint); padding: 8px 8px 6px; }
+.proj { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1px 8px; align-items: center; width: 100%; text-align: left; border: 1px solid transparent; background: none; border-radius: 8px; padding: 7px 8px; cursor: pointer; }
.proj:hover { background: var(--surface-2); }
-.proj.on { background: var(--accent-soft); border-color: var(--accent); }
-.proj small { color: var(--ink-faint); font-size: 12px; }
-.proj .bad { color: var(--reject); }
-.tabs { display: flex; gap: 2px; height: 100%; overflow-x: auto; }
+.proj.on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
+.proj .pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+.proj small { grid-column: 1 / -1; color: var(--ink-faint); font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; }
+.proj small.bad { color: var(--reject); }
+.need { min-width: 20px; padding: 1px 6px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); font: 700 11.5px/1.5 var(--mono); text-align: center; }
+.start { margin: 12px 4px 0; padding: 10px 4px 0; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-muted); }
+.start summary { cursor: pointer; }
+.start form { margin-top: 10px; }
+.body { min-width: 0; }
+.top { position: sticky; top: 0; z-index: 10; min-height: var(--top); display: flex; align-items: stretch; gap: 12px; padding: 0 18px; background: var(--surface); border-bottom: 1px solid var(--line); }
+.tabs { display: flex; flex-wrap: wrap; gap: 2px; }
.tab { border: 0; background: none; padding: 0 12px; cursor: pointer; color: var(--ink-muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tab b { font: 600 11px var(--mono); color: var(--ink-faint); margin-left: 4px; }
-.live { margin-left: auto; font-size: 12px; color: var(--ink-faint); white-space: nowrap; }
-@media (max-width: 760px) { .live { display: none; } .top { gap: 10px; padding: 0 10px; } .brand span { display: none; } }
+.live { margin-left: auto; align-self: center; font-size: 12px; color: var(--ink-faint); white-space: nowrap; }
+.switching main { opacity: .45; transition: opacity .12s; }
main { padding: 16px 18px 28px; }
-.two { display: grid; grid-template-columns: minmax(0, 1fr) var(--detail-w); gap: 16px; align-items: start; }
+.two { display: grid; grid-template-columns: minmax(0, 1fr) clamp(300px, 42%, 600px); gap: 16px; align-items: start; }
.two.narrow { grid-template-columns: minmax(0, 1fr) var(--agents-w); }
-@media (max-width: 1040px) { .two, .two.narrow { grid-template-columns: minmax(0, 1fr); } }
+@media (max-width: 900px) {
+ .shell { display: block; }
+ .side { position: static; height: auto; overflow: visible; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
+ .side-top { height: auto; margin: 0; padding: 0; border: 0; }
+ .brand span { display: none; }
+ .switch-btn { display: flex; }
+ .side-body { display: none; padding-top: 6px; }
+ .side.open .side-body { display: grid; }
+ .top { padding: 0 6px; }
+ .tab { padding: 11px 6px; }
+ .live { display: none; }
+ main { padding: 12px 10px 24px; }
+ .two, .two.narrow { grid-template-columns: minmax(0, 1fr); }
+}
.primary { display: grid; gap: 12px; min-width: 0; }
.card-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px; }
@@ -84,7 +108,7 @@ input, select { border: 1px solid var(--line-strong); background: var(--surface)
.ny em { font-style: normal; color: var(--warn); font-size: 12px; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 2px; }
-.chips button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 11px; cursor: pointer; }
+.chips button { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 3px 9px; cursor: pointer; font-size: 13px; }
.chips button.on { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.chips button b { font: 600 11px var(--mono); color: var(--ink-faint); margin-left: 4px; }
@@ -105,7 +129,7 @@ input, select { border: 1px solid var(--line-strong); background: var(--surface)
.empty { color: var(--ink-faint); padding: 14px 10px; }
.detail { position: sticky; top: calc(var(--top) + 16px); max-height: calc(100vh - var(--top) - 32px); overflow-y: auto; padding: 16px; display: grid; gap: 14px; align-content: start; }
-@media (max-width: 1040px) { .detail { position: static; max-height: none; } }
+@media (max-width: 900px) { .detail { position: static; max-height: none; } }
.detail h2 { margin: 0; font-size: 18px; line-height: 1.3; overflow-wrap: anywhere; }
.detail h2 span { color: var(--ink-faint); font: 600 13px var(--mono); margin-right: 6px; }
.detail h3 { margin: 0 0 6px; font: 600 11px/1 var(--mono); letter-spacing: .07em; text-transform: uppercase; color: var(--ink-faint); }
@@ -155,17 +179,20 @@ input, select { border: 1px solid var(--line-strong); background: var(--surface)
</style>
</head>
<body>
-<header class="top">
- <div class="brand"><svg viewBox="0 0 64 64" aria-hidden="true"><path fill="currentColor" d="M8 7h35a6 6 0 0 1 6 6v7H8a5 5 0 0 1-5-5v-3a5 5 0 0 1 5-5Z"/><rect width="56" height="14" x="3" y="25" fill="var(--accent)" rx="5"/><path fill="currentColor" d="M8 43h35a6 6 0 0 1 6 6v8H8a5 5 0 0 1-5-5v-4a5 5 0 0 1 5-5Z"/></svg><span>Pullboard</span></div>
- <div class="switch">
- <button class="switch-btn" id="proj-switch" type="button" aria-haspopup="true"><span id="proj-name">Projects</span><small>▾</small></button>
- <div class="menu" id="proj-menu" hidden>
- <div class="label">Projects on this machine</div>
- <div id="proj-list"></div>
- <div class="label">Start a board</div>
- <form id="init-form" class="inline" style="padding:0 4px 4px"><label>Folder of a git repo<input id="init-path" required placeholder="/path/to/repo"></label><button class="go" type="submit">Init</button></form>
- </div>
+<div class="shell">
+<aside class="side" id="side" aria-label="Projects">
+ <div class="side-top">
+ <div class="brand"><svg viewBox="0 0 64 64" aria-hidden="true"><path fill="currentColor" d="M8 7h35a6 6 0 0 1 6 6v7H8a5 5 0 0 1-5-5v-3a5 5 0 0 1 5-5Z"/><rect width="56" height="14" x="3" y="25" fill="var(--accent)" rx="5"/><path fill="currentColor" d="M8 43h35a6 6 0 0 1 6 6v8H8a5 5 0 0 1-5-5v-4a5 5 0 0 1 5-5Z"/></svg><span>Pullboard</span></div>
+ <button class="switch-btn" id="proj-switch" type="button" aria-expanded="false" aria-controls="side-body"><span id="proj-name">Projects</span><b class="need" id="proj-elsewhere" title="Needs you in other projects" hidden></b><small>▾</small></button>
</div>
+ <div class="side-body" id="side-body">
+ <div class="label">Projects</div>
+ <nav id="proj-list" aria-label="Projects on this machine"></nav>
+ <details class="start"><summary>Start a board</summary><form id="init-form" class="panel-form"><label>Folder of a git repo<input id="init-path" required placeholder="/path/to/repo"></label><button class="go" type="submit">Init</button></form></details>
+ </div>
+</aside>
+<div class="body">
+<header class="top">
<nav class="tabs" id="tabs" aria-label="Board">
<button class="tab" data-tab="items" type="button">Items<b id="count-items"></b></button>
<button class="tab" data-tab="shouts" type="button">Shouts<b id="count-shouts"></b></button>
@@ -219,6 +246,8 @@ input, select { border: 1px solid var(--line-strong); background: var(--surface)
<div class="card-panel feed" id="activity"></div>
</section>
</main>
+</div>
+</div>
<div class="console" id="console" title="Click to close" hidden></div>
<script>
const key = new URLSearchParams(location.search).get('k') || '';
@@ -234,6 +263,11 @@ const stateOf = (i) => i.status === 'claimed' ? 'building' : i.status === 'submi
const STATES = { building: ['building', 'busy'], verify: ['to verify', 'warn'], back: ['sent back', 'no'], verified: ['verified', 'ok'], open: ['open', ''], withdrawn: ['withdrawn', ''] };
const chip = (s) => '<span class="chip ' + STATES[s][1] + '">' + STATES[s][0] + '</span>';
const tone = (s) => s === 'approved' ? 'ok' : s === 'pending' ? 'no' : s === 'draft' ? 'warn' : '';
+const count = (n, one, many = one) => n + ' ' + (n === 1 ? one : many);
+// What needs the person in a project, as its Needs-you list counts it: work sent back or waiting for a
+// verdict, open questions, held lanes.
+const needCount = (x) => x.ok ? x.sentBack + x.awaiting + x.pending + x.holds : 0;
+const doing = (x) => [x.sentBack && count(x.sentBack, 'sent back'), x.awaiting && count(x.awaiting, 'to verify'), x.pending && count(x.pending, 'question', 'questions'), x.holds && count(x.holds, 'lane held', 'lanes held'), x.building && count(x.building, 'building')].filter(Boolean).join(' · ') || (x.open ? count(x.open, 'item open', 'items open') : 'nothing open');
async function api(path, body) {
const res = await fetch(path, { method: body ? 'POST' : 'GET', headers: { 'x-pullboard-key': key, ...(body ? { 'content-type': 'application/json' } : {}) }, body: body ? JSON.stringify(body) : undefined });
@@ -243,7 +277,10 @@ async function api(path, body) {
}
async function refresh() {
- const next = await api('/api/state' + (view.root ? '?root=' + encodeURIComponent(view.root) : ''));
+ const root = view.root;
+ const next = await api('/api/state' + (root ? '?root=' + encodeURIComponent(root) : ''));
+ // The person switched projects while this answer was on its way: the switch's own refresh shows it.
+ if (root !== view.root) return;
if (!next.project && next.projects.some((p) => p.ok)) {
view.root = next.projects.find((p) => p.ok).root;
keep('pb.project', view.root);
@@ -261,9 +298,16 @@ async function refresh() {
function render() {
const p = data.project;
- $('proj-list').innerHTML = data.projects.length ? data.projects.map((x) => '<button class="proj' + (x.root === view.root ? ' on' : '') + '" data-root="' + esc(x.root) + '" type="button"><b>' + esc(x.name) + '</b>' + (x.ok ? '<small>' + x.building + ' building · ' + x.awaiting + ' to verify · ' + x.verified + ' verified' + (x.pending ? ' · ' + x.pending + ' questions' : '') + '</small>' : '<small class="bad">' + esc(x.error) + '</small>') + '</button>').join('') : '<div class="empty">No projects yet: run pullboard init in a repo, or start one below.</div>';
+ // Every project stays in view with what needs the person there, so one look covers them all.
+ $('proj-list').innerHTML = data.projects.length ? data.projects.map((x) => {
+ const on = x.root === view.root;
+ return '<button class="proj' + (on ? ' on' : '') + '"' + (on ? ' aria-current="true"' : '') + ' data-root="' + esc(x.root) + '" title="' + esc(x.root) + '" type="button"><span class="pname">' + esc(x.name) + '</span>' + (needCount(x) ? '<b class="need" title="needs you">' + needCount(x) + '</b>' : '') + (x.ok ? '<small>' + esc(doing(x)) : '<small class="bad">' + esc(x.error)) + '</small></button>';
+ }).join('') : '<div class="empty">No projects yet: run pullboard init in a repo, or start one below.</div>';
+ const elsewhere = data.projects.filter((x) => x.root !== view.root).reduce((n, x) => n + needCount(x), 0);
+ $('proj-elsewhere').textContent = elsewhere ? elsewhere + ' elsewhere' : '';
+ $('proj-elsewhere').hidden = !elsewhere;
if (!p) { $('proj-name').textContent = 'No project'; return; }
- $('proj-name').textContent = p.root.split('/').pop();
+ $('proj-name').textContent = (data.projects.find((x) => x.root === view.root) || { name: p.root.split('/').pop() }).name;
const items = p.items.filter((i) => i.status !== 'withdrawn');
const by = (s) => items.filter((i) => stateOf(i) === s);
const active = items.filter((i) => stateOf(i) !== 'verified');
@@ -387,12 +431,31 @@ async function act(command, args, root = view.root) {
}
}
+/** Open or close the project list where the sidebar is folded into a top bar (under 900px). */
+function fold(open) {
+ $('side').classList.toggle('open', open);
+ $('proj-switch').setAttribute('aria-expanded', String(open));
+}
+
+/** Show another project: mark it at once, dim the old one's panes until its board arrives. */
+function switchTo(root) {
+ view.root = root;
+ view.item = null;
+ view.adding = false;
+ keep('pb.project', root);
+ fold(false);
+ if (data) render();
+ document.body.classList.add('switching');
+ refresh().catch(() => { $('live').textContent = 'offline: is pullboard view still running?'; }).finally(() => document.body.classList.remove('switching'));
+}
+
document.addEventListener('click', (event) => {
const t = event.target.closest('[data-root],[data-tab],[data-go],[data-item],[data-state],[data-rows],[data-row],[data-release],[data-shout],[data-new],#proj-switch,#console');
- if (!t) { if (!event.target.closest('.switch')) $('proj-menu').hidden = true; return; }
- if (t.id === 'proj-switch') { $('proj-menu').hidden = !$('proj-menu').hidden; return; }
+ if (!event.target.closest('.side')) fold(false);
+ if (!t) return;
+ if (t.id === 'proj-switch') { fold(!$('side').classList.contains('open')); return; }
if (t.id === 'console') { t.hidden = true; return; }
- if (t.dataset.root) { view.root = t.dataset.root; view.item = null; keep('pb.project', view.root); $('proj-menu').hidden = true; refresh(); }
+ if (t.dataset.root) switchTo(t.dataset.root);
else if (t.dataset.tab) { view.tab = t.dataset.tab; keep('pb.tab', view.tab); showTab(); }
else if (t.dataset.go) go(t.dataset.go);
else if (t.dataset.item) { view.item = Number(t.dataset.item); view.adding = false; render(); }
diff --git a/test/cockpit.test.js b/test/cockpit.test.js
new file mode 100644
index 00000000..20053f88
--- /dev/null
+++ b/test/cockpit.test.js
@@ -0,0 +1,308 @@
+/**
+ * The view's page as the person sees it (N26, N27). Each test sets up real projects with the real
+ * CLI, starts `pullboard view` over them, and runs the page it serves in a vm with just enough of a
+ * document for its script: every element the page names by id records what the script writes into
+ * it, and the script's requests go to that view. Nothing is stood in for but the browser.
+ */
+import assert from 'node:assert/strict';
+import { execFileSync, spawn, spawnSync } from 'node:child_process';
+import { chmodSync, mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join, resolve } from 'node:path';
+import { after, test } from 'node:test';
+import vm from 'node:vm';
+
+const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');
+const scratch = [];
+
+after(() => {
+ for (const dir of scratch) rmSync(dir, { recursive: true, force: true });
+});
+
+const SPEC = `# Demo spec
+
+## G · Goals
+- G1 [approved, must] The page renders. | gate: web test
+- G2 [approved, must] The page says goodbye. | gate: web test
+`;
+
+/**
+ * A scratch machine: its own project registry, a `pullboard` shim on the PATH so the hooks find the
+ * CLI, and git kept apart from this machine's config. run() fails the test on any refusal.
+ */
+function machine() {
+ const dir = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-cockpit-')));
+ scratch.push(dir);
+ mkdirSync(join(dir, 'bin'));
+ writeFileSync(join(dir, 'bin', 'pullboard'), `#!/bin/sh\nexec "${process.execPath}" "${BIN}" "$@"\n`);
+ chmodSync(join(dir, 'bin', 'pullboard'), 0o755);
+ const env = {
+ ...process.env,
+ PATH: `${join(dir, 'bin')}:${process.env.PATH}`,
+ GIT_CONFIG_GLOBAL: '/dev/null',
+ GIT_CONFIG_NOSYSTEM: '1',
+ GIT_AUTHOR_NAME: 'Test Agent',
+ GIT_AUTHOR_EMAIL: '[email protected]',
+ GIT_COMMITTER_NAME: 'Test Agent',
+ GIT_COMMITTER_EMAIL: '[email protected]',
+ PULLBOARD_HOME: join(dir, 'home'),
+ };
+ const git = (cwd, ...args) => execFileSync('git', args, { cwd, env, encoding: 'utf8', stdio: 'pipe' }).trim();
+ const run = (cwd, ...args) => {
+ const result = spawnSync(process.execPath, [BIN, ...args], { cwd, env, encoding: 'utf8' });
+ assert.equal(result.status, 0, `pullboard ${args.join(' ')}: ${result.stderr}`);
+ return result.stdout;
+ };
+ return { dir, env, git, run };
+}
+
+/**
+ * A project registered on the machine: a repo set up by `pullboard init`, one web lane, and a
+ * worktree joined to it as web-1.
+ */
+function project(box, name, spec = SPEC) {
+ const repo = join(box.dir, name);
+ mkdirSync(repo);
+ box.git(repo, 'init', '-q', '-b', 'main');
+ box.run(repo, 'init');
+ const config = { gate: 'true', spec: 'SPEC.md', verify: 'any', lease: '2h', lanes: { web: { owns: ['web/'], specs: ['G'] } }, shared: [] };
+ writeFileSync(join(repo, 'pullboard.json'), JSON.stringify(config, null, 2));
+ writeFileSync(join(repo, 'SPEC.md'), spec);
+ box.git(repo, 'add', '-A');
+ box.git(repo, 'commit', '-q', '-m', 'chore: set up pullboard');
+ const branch = `web/${name.replace(/[^a-z]/g, '')}`;
+ const web = join(box.dir, `${name}-web`);
+ box.git(repo, 'worktree', 'add', '-q', web, '-b', branch);
+ box.run(web, 'join', 'web');
+ return { repo, web, branch };
+}
+
+/**
+ * web-1 builds an item: claims it, commits a file in its lane through the hooks, and submits it.
+ */
+function build(box, p, id, file) {
+ box.run(p.web, 'claim', String(id));
+ mkdirSync(join(p.web, 'web'), { recursive: true });
+ writeFileSync(join(p.web, 'web', file), `${file}\n`);
+ box.git(p.web, 'add', '-A');
+ box.git(p.web, 'commit', '-q', '-m', `feat(web): ${file} [G1]`);
+ box.run(p.web, 'submit', String(id));
+}
+
+/**
+ * The coordinator sends an item back from a checkout of its submitted commit, as a verifier does.
+ */
+function sendBack(box, p, id, note) {
+ box.git(p.repo, 'switch', '-q', '--detach', p.branch);
+ box.run(p.repo, 'verify', String(id), 'reject', '--reason', 'BEHAVIOR_MISMATCH', '--note', note, '--as', 'coordinator');
+ box.git(p.repo, 'switch', '-q', 'main');
+}
+
+/**
+ * Start `pullboard view` on the machine and read the link it prints; stop() ends it.
+ */
+async function startView(box) {
+ const child = spawn(process.execPath, [BIN, 'view', '--no-open'], { cwd: box.dir, env: box.env });
+ const link = await new Promise((found, fail) => {
+ let out = '';
+ child.stdout.on('data', (chunk) => {
+ out += chunk;
+ const match = /Pullboard view: (http:\/\/127\.0\.0\.1:\d+\/\?k=\S+)/.exec(out);
+ if (match) found(new URL(match[1]));
+ });
+ child.on('exit', (code) => fail(new Error(`view exited ${code}: ${out}`)));
+ });
+ const stop = () => new Promise((done) => {
+ if (child.exitCode !== null || child.signalCode !== null) return done();
+ child.once('exit', done);
+ child.kill('SIGTERM');
+ });
+ return { link, key: link.searchParams.get('k'), base: `http://127.0.0.1:${link.port}`, stop };
+}
+
+/**
+ * An element as the page's script uses one: what it writes, its classes and attributes, the
+ * listeners it adds, and how often it was scrolled into view.
+ */
+function element(id) {
+ const classes = new Set();
+ let html = '';
+ let text = '';
+ return {
+ id,
+ // A browser keeps both as strings, whatever the script assigns.
+ get innerHTML() { return html; },
+ set innerHTML(value) { html = String(value ?? ''); },
+ get textContent() { return text; },
+ set textContent(value) { text = String(value ?? ''); },
+ value: '',
+ hidden: false,
+ dataset: {},
+ style: {},
+ attributes: {},
+ listeners: {},
+ scrolled: 0,
+ classList: {
+ add: (name) => classes.add(name),
+ remove: (name) => classes.delete(name),
+ contains: (name) => classes.has(name),
+ toggle: (name, force = !classes.has(name)) => {
+ if (force) classes.add(name);
+ else classes.delete(name);
+ return force;
+ },
+ },
+ setAttribute(name, value) { this.attributes[name] = String(value); },
+ getAttribute(name) { return this.attributes[name] ?? null; },
+ addEventListener(type, listener) { (this.listeners[type] ??= []).push(listener); },
+ focus() {},
+ scrollIntoView() { this.scrolled += 1; },
+ getBoundingClientRect: () => ({ top: 0, bottom: 0, left: 0, right: 0, width: 0, height: 0 }),
+ querySelectorAll: () => [],
+ };
+}
+
+/**
+ * What a click lands on: an element with these data attributes, this id, and these classes on it
+ * or its ancestors, as the page's closest() calls find it.
+ */
+function target({ id = '', classes = '', ...data }) {
+ const matches = (selector) => {
+ if (selector.startsWith('#')) return selector.slice(1) === id;
+ if (selector.startsWith('.')) return classes.split(' ').includes(selector.slice(1));
+ const attribute = /^\[data-([a-z-]+)\]$/.exec(selector);
+ return attribute ? attribute[1].replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()) in data : false;
+ };
+ const self = { id, dataset: data, closest: (selectors) => (selectors.split(',').some((selector) => matches(selector.trim())) ? self : null) };
+ return self;
+}
+
+/**
+ * Wait until the page has no request out and its answers have been rendered.
+ */
+async function settle(inflight) {
+ for (let quiet = 0; quiet < 3; quiet = inflight.size ? 0 : quiet + 1) {
+ if (inflight.size) await Promise.allSettled([...inflight]);
+ await new Promise((done) => setImmediate(done));
+ }
+}
+
+/**
+ * Open the page a view serves, at a window width, and wait for its first board. show(id) is what
+ * that region holds; click() and type() act as the person would.
+ */
+async function openPage(view, { width = 1280 } = {}) {
+ const html = await (await fetch(view.link)).text();
+ const script = html.slice(html.indexOf('<script>') + '<script>'.length, html.lastIndexOf('</script>'));
+ const known = new Set([...html.matchAll(/\bid="([^"]+)"/g)].map((match) => match[1]));
+ const elements = new Map();
+ const node = (id) => {
+ if (!elements.has(id)) elements.set(id, element(id));
+ return elements.get(id);
+ };
+ const clicks = [];
+ const inflight = new Set();
+ const document = {
+ body: element('body'),
+ hidden: false,
+ getElementById: (id) => (known.has(id) ? node(id) : null),
+ querySelectorAll: () => [],
+ addEventListener: (type, listener) => { if (type === 'click') clicks.push(listener); },
+ };
+ const context = vm.createContext({
+ document,
+ location: { search: `?k=${view.key}` },
+ URLSearchParams,
+ innerWidth: width,
+ innerHeight: 800,
+ matchMedia: (query) => ({ matches: width <= Number(/max-width:\s*(\d+)px/.exec(query)?.[1] ?? Infinity) }),
+ setInterval: () => 0,
+ setTimeout,
+ clearTimeout,
+ fetch: (path, init) => {
+ const answer = fetch(`${view.base}${path}`, init).then(async (res) => {
+ const body = await res.json();
+ return { ok: res.ok, status: res.status, json: async () => body };
+ });
+ inflight.add(answer);
+ const done = () => inflight.delete(answer);
+ answer.then(done, done);
+ return answer;
+ },
+ });
+ vm.runInContext(script, context);
+ await settle(inflight);
+ return {
+ html,
+ show: (id) => node(id).innerHTML,
+ element: node,
+ async click(on) {
+ const event = { target: target(on) };
+ for (const listener of clicks) listener(event);
+ await settle(inflight);
+ },
+ async type(id, text) {
+ node(id).value = text;
+ for (const listener of node(id).listeners.input ?? []) listener({ target: node(id) });
+ await settle(inflight);
+ },
+ };
+}
+
+/**
+ * The project rows the sidebar shows: name, needs count, the line under it, and which is current.
+ */
+function projectRows(html) {
+ return html.split('<button').slice(1).map((row) => ({
+ root: /data-root="([^"]*)"/.exec(row)?.[1],
+ name: /class="pname">([^<]*)</.exec(row)?.[1],
+ needs: /class="need"[^>]*>([^<]*)</.exec(row)?.[1] ?? '',
+ line: /<small[^>]*>([^<]*)</.exec(row)?.[1],
+ current: /aria-current="true"/.test(row),
+ }));
+}
+
+test('the sidebar lists every project and what needs the person [N26]', async () => {
+ const box = machine();
+ const alpha = project(box, 'alpha');
+ box.run(alpha.repo, 'add', 'web', 'Greeting', '--specs', 'G1', '--criterion', 'greets');
+ box.run(alpha.repo, 'add', 'web', 'Farewell', '--specs', 'G2', '--criterion', 'says goodbye');
+ build(box, alpha, 1, 'greeting.html');
+ sendBack(box, alpha, 1, 'no greeting on the page');
+ build(box, alpha, 2, 'farewell.html');
+ const beta = project(box, 'beta', `${SPEC}- G3 [pending] Should the page greet in French?\n`);
+ box.run(beta.repo, 'hold', 'web', '--reason', 'G3 is open');
+ const gamma = project(box, 'gam<i>ma');
+ box.run(gamma.repo, 'add', 'web', 'Gamma page', '--specs', 'G1', '--criterion', 'renders');
+ const view = await startView(box);
+ try {
+ const page = await openPage(view);
+ const side = page.html.slice(page.html.indexOf('<aside class="side"'), page.html.indexOf('</aside>'));
+ assert.match(side, /<nav id="proj-list"/, 'the project rows sit in the sidebar');
+ for (const opening of side.match(/<(aside|div|nav)\b[^>]*>/g)) assert.doesNotMatch(opening, /\bhidden\b/, `${opening} shows without opening anything`);
+ assert.match(page.html, /\.shell \{ display: grid; grid-template-columns: var\(--side-w\) minmax\(0, 1fr\);/, 'a sidebar column beside the main one');
+ assert.match(page.html, /@media \(max-width: 900px\) \{[^@]*\.side-body \{ display: none;[^@]*\.side\.open \.side-body \{ display: grid; \}/, 'under 900px the list folds behind the project button');
+
+ assert.deepEqual(projectRows(page.show('proj-list')), [
+ { root: alpha.repo, name: 'alpha', needs: '2', line: '1 sent back · 1 to verify', current: true },
+ { root: beta.repo, name: 'beta', needs: '2', line: '1 question · 1 lane held', current: false },
+ { root: gamma.repo.replace('<', '&lt;').replace('>', '&gt;'), name: 'gam&lt;i&gt;ma', needs: '', line: '1 item open', current: false },
+ ]);
+ assert.match(page.show('chain'), /Greeting/);
+
+ await page.click({ root: gamma.repo, classes: 'proj side' });
+ assert.deepEqual(projectRows(page.show('proj-list')).map((row) => [row.name, row.current]), [['alpha', false], ['beta', false], ['gam&lt;i&gt;ma', true]]);
+ assert.match(page.show('chain'), /Gamma page/, 'the main column shows the project picked');
+ assert.doesNotMatch(page.show('chain'), /Greeting/);
+ assert.equal(page.element('proj-name').textContent, 'gam<i>ma');
+ assert.equal(page.element('proj-elsewhere').textContent, '4 elsewhere', 'the folded button counts what needs the person elsewhere');
+
+ await page.click({ id: 'proj-switch', classes: 'switch-btn side' });
+ assert.ok(page.element('side').classList.contains('open'), 'the project button opens the list');
+ assert.equal(page.element('proj-switch').getAttribute('aria-expanded'), 'true');
+ await page.click({ classes: 'row' });
+ assert.ok(!page.element('side').classList.contains('open'), 'a click outside the sidebar folds it again');
+ } finally {
+ await view.stop();
+ }
+});