Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

quickshell/nuguland/features/system/fixtures/suite.mjs

Raw
// `just ui-test system`: the registry system feature in the real Bar inside nested
// niri, driven by real pointer and keyboard against the feature's Resources double:
// the bar chip's attention, current problems leading the live card and its process
// line, then incident history, then the collapsed machine disclosure and its retained
// expansion, issue and agent actions with pending,
// failure and retry, the agent-dispatched close, sparklines waiting for history,
// grouped crash and oom history in plain words with a retained details disclosure,
// keyboard reveal of rows below the viewport, stale and unavailable history with its
// fix and retry, the all ok line leading an all-clear popup, initial focus in
// reading order, and the polling gate across close and reopen. `fixtures/production.mjs` then proves
// the production service's journal, prompt and terminal boundaries.
// The suite contract (snapshot shape, helpers) is documented in .system/RULES.md.
export default async function systemSuite({ assert, snapshot, open, check, click, key, screenshot, within, call }) {
    const system = value => value.features.system;
    const service = value => system(value).service;
    const control = (value, name) => system(value).controls[name];
    const item = (value, name) => system(value).items[name];
    const hasText = (value, text) => system(value).texts.includes(text);
    const names = {
        action: 'open fixture service failed',
        agent: 'fix with agent: fixture service failed',
        crashAgent: 'assess crashes: fixture editor',
        crashOpen: 'open latest crash for fixture editor',
        batteryAgent: 'fix with agent: battery wear',
        updatesAgent: 'fix with agent: 3 updates available',
        updatesOpen: 'open 3 updates available',
    };
    const rect = (value, name) => control(value, names[name])?.rect;
    const oomOpen = 'open record for fixture worker with a very long process name <b>literal markup</b> and additional identifying text';
    // The hashed unit name reads as the app it runs.
    const crashFacts = pid => `latest crash · signal sigsegv · pid ${pid} · uid 1000 · /usr/bin/fixture-editor · editor`;
    const focusedName = value => Object.entries(system(value).controls).find(([, entry]) => entry.focused)?.[0];
    const visibleIn = (value, rect) => {
        const panel = system(value).surface;
        return rect && rect.y >= panel.y && rect.y + rect.height <= panel.y + panel.height;
    };
    // Section tops in layout order, each strictly below the previous one.
    const ordered = (value, names) => names.map(name => item(value, name)?.rect ?? control(value, name)?.rect).every((rect, index, rects) => rect && (index === 0 || rect.y >= rects[index - 1].y + rects[index - 1].height));
    // Real Tab traversal, one observed focus move per key, until `name` holds focus.
    async function tabTo(name) {
        for (let moves = 0; moves < 12 && focusedName(snapshot()) !== name; moves++) {
            const before = focusedName(snapshot());
            key('Tab');
            await check(`Tab moves focus on from ${before}`, value => focusedName(value) !== before);
        }
        return check(`keyboard reaches ${name}`, value => focusedName(value) === name);
    }
    const opened = () => open('system', value => rect(value, 'action'));

    let state = snapshot();
    assert.equal(state.chips.system.label, 'system', 'registry bar label');
    const chip = value => value.chips.system;
    assert(chip(state).active && chip(state).strong && chip(state).role === 'warning', 'a current failed service makes the closed chip strong in the warning role');
    await screenshot('system-chip-strong');
    assert.equal(service(state).popupOpen, false, 'closed popup holds the polling gate shut');

    state = await opened();
    state = await check('opening focuses the first problem action', value => control(value, names.action)?.focused);
    assert.equal(service(state).opens, 1);
    assert(!hasText(state, 'fixture-host'), 'machine identity waits behind its disclosure');
    assert(control(state, 'expand machine'), 'the machine disclosure is collapsed');
    assert(hasText(state, 'fixture service failed') && hasText(state, 'needs attention') && !hasText(state, 'all ok'));
    assert(hasText(state, 'fixture-worker · 25%'));
    await check('needs attention leads, then the live card with its process line, then incident history, then the machine disclosure', value => {
        const issues = item(value, 'currentIssues')?.rect;
        const panel = system(value).surface;
        return issues && issues.y - panel.y < 40 && visibleIn(value, item(value, 'issue fixture-unit')?.rect) && visibleIn(value, control(value, 'fixture-worker · 25%')?.rect)
            && ordered(value, ['currentIssues', 'liveMetrics', 'incidentHistory', 'expand machine']) && ordered(value, ['issue fixture-unit', 'fixture-worker · 25%']);
    });
    await check('three samples of history leave every sparkline hidden', value => ['cpu', 'memory', 'temperature', 'network', 'disk'].every(name => !item(value, `spark ${name}`)));
    assert(hasText(state, 'load') && hasText(state, '13% busy') && !system(state).texts.some(text => text.includes('0.50')), 'load reads as one plain busy figure, its averages wait in the hint');
    await screenshot('system-populated');
    click(rect(state, 'action'));
    state = await check('resource issue action routes once with the issue id', value => service(value).actions === 1 && service(value).lastAction === 'fixture-unit');
    key('Tab');
    await check('Tab reaches the agent action after open', value => control(value, names.agent)?.focused);
    key('shift+Tab');
    key('Tab');
    key('Return');
    state = await check('Enter dispatches one agent request and disables duplicates', value => service(value).agentPending && service(value).agentActions === 1 && service(value).agentIssueId === 'fixture-unit');
    click(rect(state, 'agent'));
    await check('pending pointer does not dispatch twice', value => service(value).agentActions === 1);
    call('system', 'agentResult', false);
    state = await check('missing executable is named with its fix beside the retry', value => !service(value).agentPending && hasText(value, 'pi not found · install pi or add it to the session path, then retry') && control(value, names.agent)?.enabled);
    await screenshot('system-agent-unavailable');
    click(rect(state, 'agent'));
    await check('pointer retries the agent request once', value => service(value).agentActions === 2 && service(value).agentPending);
    // The panel turns the service's dispatch into its host close request.
    call('system', 'agentResult', true);
    state = await check('agent dispatch closes the popup and releases polling', value => !value.popup.open && !service(value).popupOpen && value.popup.lastCloseReason === 'agent-dispatched');

    state = await opened();
    await tabTo('expand machine');
    state = await check('keyboard reveals the machine disclosure at the end', value => visibleIn(value, control(value, 'expand machine')?.rect));
    click(control(state, 'expand machine').rect);
    state = await check('pointer expands the machine details into view', value => hasText(value, 'fixture-host') && hasText(value, 'battery 72% · on battery · health 94%') && control(value, 'collapse machine') && visibleIn(value, item(value, 'machineDetails')?.rect));
    call('system', 'fillHistory');
    await check('two minutes of history show every sparkline', value => ['cpu', 'memory', 'temperature', 'network', 'disk'].every(name => item(value, `spark ${name}`)) && !item(value, 'spark swap'));
    await screenshot('system-machine');
    call('system', 'showIncidents');
    state = await check('battery and updates omit agent actions while crash retains one', value => !!rect(value, 'crashAgent') && !rect(value, 'batteryAgent') && !rect(value, 'updatesAgent') && !!rect(value, 'updatesOpen'));
    await check('crash and oom history is neutral while current failures retain severity', value => {
        const historyIds = [service(value).crashGroupId, 'fixture-oom'];
        const history = historyIds.map(id => item(value, `issue ${id}`));
        const current = item(value, 'issue fixture-unit');
        const battery = item(value, 'issue battery-health');
        // Each historical row shows the clock glyph (\uF017) instead of its severity icon.
        const clock = id => item(value, `issue glyph ${id}`)?.text === '\uF017';
        return hasText(value, 'incident history') && hasText(value, 'current boot · last 24 hours · latest 100') && historyIds.every(clock) && !clock('fixture-unit') && !clock('battery-health') && history.every(row => row && !row.attention && !row.destructive && !row.highlighted) && current?.destructive && battery?.attention;
    });
    // The expanded machine details scrolled the leading problems above the viewport.
    // Reach them through real keyboard traversal and focus reveal.
    await tabTo(names.updatesOpen);
    state = await check('keyboard reveals the update action above the viewport', value => control(value, names.updatesOpen)?.focused && visibleIn(value, control(value, names.updatesOpen).rect));
    click(rect(state, 'updatesOpen'));
    await check('updates retain their existing open action', value => service(value).actions === 2 && service(value).lastAction === 'updates');
    await screenshot('system-agent-eligibility');
    // Tab skips non-actionable battery wear; then the crash group's open and agent actions.
    key('Tab');
    key('Tab');
    key('space');
    state = await check('Space targets one crash group, summarized in plain words', value => service(value).agentPending && service(value).agentIssueId === service(value).crashGroupId && hasText(value, 'crashed 3 times') && hasText(value, 'stopped · out of memory') && !system(value).texts.some(text => /pid|sigsegv|oom/.test(text)) && hasText(value, '4 recorded'));
    const crashGroupId = service(state).crashGroupId;
    call('system', 'agentResult', false);
    await screenshot('system-grouped-crashes');
    await tabTo('show details for fixture editor');
    key('Return');
    await check('Enter discloses the technical identifiers of the latest crash', value => hasText(value, crashFacts(123)) && control(value, 'hide details for fixture editor')?.focused);
    await screenshot('system-incident-details');
    key('shift+Tab');
    await check('Shift+Tab returns to the crash agent action', value => control(value, names.crashAgent)?.focused);
    key('Return');
    state = await check('Enter retries the eligible historical agent action', value => service(value).agentPending && service(value).agentIssueId === crashGroupId);
    call('system', 'addCrash');
    state = await check('new occurrence updates count and latest time without changing group or pending state', value => service(value).agentPending && service(value).agentIssueId === crashGroupId && service(value).crashGroupId === crashGroupId && hasText(value, 'crashed 4 times') && hasText(value, crashFacts(200)) && hasText(value, '5 recorded') && system(value).texts.some(text => text.startsWith('latest · just now')));
    const groupRequests = service(state).agentActions;
    click(rect(state, 'crashAgent'));
    await check('updated pending group still suppresses duplicate pointer dispatch', value => service(value).agentActions === groupRequests);
    call('system', 'agentResult', false);
    click(rect(state, 'crashOpen'));
    await check('group open routes the stable id to its latest event', value => service(value).actions === 3 && service(value).lastAction === crashGroupId);
    click(rect(state, 'crashAgent'));
    await check('pointer retries the updated crash group', value => service(value).agentActions === groupRequests + 1 && service(value).agentIssueId === crashGroupId);
    call('system', 'agentResult', false);
    await screenshot('system-incidents');
    await tabTo(oomOpen);
    await screenshot('system-long-incident');
    call('system', 'setIncidentStatus', 'unavailable');
    await check('unreadable journal marks retained incidents stale', value => !!rect(value, 'crashAgent') && hasText(value, 'showing last readable history · journal unreadable') && hasText(value, '5 recorded'));
    call('system', 'clear');
    state = await check('unreadable empty history says so without a count', value => hasText(value, 'crash history unavailable · journal unreadable') && !system(value).texts.some(text => text.endsWith(' recorded')));
    await screenshot('system-history-unavailable');
    key('Escape');
    await check('Escape closes unreadable history', value => !value.popup.open && !service(value).popupOpen);
    state = await open('system', value => control(value, 'retry crash history')?.rect);
    state = await check('unreadable history names the fix and opening focuses its retry', value => hasText(value, 'join the systemd-journal group and sign in again, then retry') && control(value, 'retry crash history')?.focused && hasText(value, 'all ok'));
    click(control(state, 'retry crash history').rect);
    await check('retry reads the journal again and shows it pending', value => service(value).incidentRetries === 1 && hasText(value, 'reading crash history') && !control(value, 'retry crash history'));
    await screenshot('system-history-retrying');
    call('system', 'setIncidentStatus', 'ready');
    state = await check('external empty issues and processes render all-clear', value => hasText(value, 'all ok') && !hasText(value, 'needs attention') && hasText(value, 'no crashes or out-of-memory stops recorded') && hasText(value, '0 recorded') && !hasText(value, 'fixture service failed') && !hasText(value, 'fixture-worker · 25%') && !rect(value, 'action') && service(value).actions === 3);
    await screenshot('system-all-clear');
    key('Escape');
    state = await check('Escape closes system and releases the polling gate', value => !value.popup.open && !service(value).popupOpen && value.popup.lastCloseReason === 'escape-key');
    assert.equal(service(state).opens, service(state).closes);
    state = await open('system', value => control(value, 'collapse machine')?.rect);
    assert(hasText(state, 'fixture-host'), 'the machine details stay expanded across close and reopen');
    assert.equal(system(state).retained.expandedIncident, crashGroupId, 'the incident details disclosure is retained across close and reopen');
    await check('reopening starts at the all ok line and focuses the machine disclosure', value => control(value, 'collapse machine')?.focused && visibleIn(value, item(value, 'allOk')?.rect) && visibleIn(value, control(value, 'collapse machine').rect));
    key('Escape');
    state = await check('Escape closes the reopened popup', value => !value.popup.open && !service(value).popupOpen);
    assert.equal(service(state).opens, service(state).closes);
    assert(!chip(state).active && !chip(state).strong && chip(state).role === 'ui.accent', 'all-clear leaves the chip quiet');
    call('system', 'showWarning');
    await check('a current warning shows the warning dot without strong emphasis', value => chip(value).active && !chip(value).strong && chip(value).role === 'warning' && !service(value).popupOpen);
    await screenshot('system-chip-dot');
    call('system', 'showHistoryOnly');
    await check('incident history alone leaves the chip quiet', value => !chip(value).active && !chip(value).strong && service(value).crashGroupId.length > 0);
    state = await open('system', value => control(value, names.crashOpen)?.rect);
    await check('one all ok line leads recorded history, and opening focuses the latest crash', value => control(value, names.crashOpen)?.focused && visibleIn(value, item(value, 'allOk')?.rect) && ordered(value, ['allOk', 'liveMetrics', 'incidentHistory']) && !hasText(value, 'needs attention'));
    await screenshot('system-history-only');
    key('Escape');
    state = await check('Escape closes history-only system', value => !value.popup.open && !service(value).popupOpen);
    assert.equal(service(state).opens, service(state).closes);
}