Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

quickshell/nuguland/features/config/fixtures/production.mjs

Raw
import assert from 'node:assert/strict';
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';

// Actual Config Process -> installed-artifact runtime -> private gsettings.
// Remaining integrations stay doubled; Nugu sources are not mounted.
export default async function configProduction({ env, start, stop, waitFor, ipc, screenshot, snapshot, setFixture, click }) {
    assert.equal(process.env.NUGULAND_UI_SANDBOX, '1');
    assert(!existsSync('/nugu') && !existsSync('/project/../../nugu'));
    const bin = '/tmp/config-production-bin';
    mkdirSync(bin);
    writeFileSync(bin + '/gsettings', `#!/bin/sh
sleep 0.3
if [ -f /tmp/config-interrupt ]; then
    # The runtime itself, not the timeout that wraps this publisher.
    kill -TERM "$(cut -d' ' -f4 "/proc/$PPID/stat")"
    exit 1
fi
if [ -f /tmp/config-publication-stop ]; then
    printf 'publisher unavailable\\n' >&2
    exit 1
fi
exec /usr/bin/gsettings "$@"
`, { mode: 0o700 });
    const fixture = '/project/config-production.qml';
    const bar = readFileSync('/project/bar-ui-test.qml', 'utf8');
    const marker = '        target: "uiTest"';
    assert.equal(bar.split(marker).length, 2);
    writeFileSync(fixture, bar.replace(marker, marker + `
        function selectMode(value: string): void { featureRegistry.config.selectMode(value); }
        function appearance(): string {
            return JSON.stringify({mode: featureRegistry.config.mode, busy: featureRegistry.config.busy, error: featureRegistry.config.error});
        }
`));
    const child = start('qs', ['--no-color', '-p', fixture], 'config-production', {
        ...env, PATH: bin + ':' + env.PATH, GSETTINGS_BACKEND: 'keyfile', GIO_USE_VFS: 'local'
    });
    setFixture(fixture, '/evidence/config-production.log', child);
    const state = () => JSON.parse(ipc('appearance'));
    const modeFile = env.XDG_STATE_HOME + '/nugu/mode';
    try {
        await waitFor('production Config loads', () => readFileSync('/evidence/config-production.log', 'utf8').includes('Configuration Loaded'));
        await waitFor('production Config reads authority', () => state().mode === 'dark' && !state().busy);
        ipc('external', 'feature:config:requestSection:["appearance"]');
        await waitFor('production Config renders registry appearance declaration', () =>
            snapshot().popup.name === 'config' && snapshot().features.config.controls['dark mode']?.checked);
        // Real pointer selects orientation through production declarations and service.
        async function chooseOrientation(name, expected) {
            let previous = '';
            await waitFor('production orientation target settles', () => {
                const value = snapshot(), target = value.features.config.controls[name];
                if (!value.popup.windowActive || !target?.enabled) return false;
                const geometry = JSON.stringify([value.popup.card, target.rect]);
                const settled = geometry === previous;
                previous = geometry;
                return settled;
            });
            click(snapshot().features.config.controls[name].rect);
            await waitFor('production Config changes actual Bar geometry', () => {
                const value = snapshot();
                return value.orientation === expected && value.features.config.controls[name]?.checked &&
                    (expected === 'vertical' ? value.barWidth === value.barThickness : value.barWidth === value.width);
            });
        }
        await chooseOrientation('vertical bar', 'vertical');
        await screenshot('config-native-orientation');
        await chooseOrientation('horizontal bar', 'horizontal');
        // Pre-selection refusal cannot claim the chosen mode was committed.
        writeFileSync(env.HOME + '/.nugu-runtime', 'unrelated');
        ipc('selectMode', 'light');
        await waitFor('production Config exposes unchanged selection on preflight refusal', () =>
            !state().busy && state().mode === 'dark' && state().error === 'appearance interrupted; retry selected mode');
        rmSync(env.HOME + '/.nugu-runtime');
        writeFileSync('/tmp/config-publication-stop', '');
        ipc('selectMode', 'light');
        await waitFor('production Config exposes pending runtime write', () => state().busy);
        await waitFor('production partial failure retains persisted selected intent', () =>
            !state().busy && state().mode === 'light' && state().error === 'desktop preference incomplete; retry selected mode');
        assert.equal(readFileSync(modeFile, 'utf8'), 'light\n');
        await screenshot('config-native-partial');
        rmSync('/tmp/config-publication-stop');
        ipc('selectMode', 'light');
        await waitFor('same-mode runtime retry succeeds', () => !state().busy && state().mode === 'light' && !state().error);
        assert.equal(readFileSync(env.XDG_CONFIG_HOME + '/glib-2.0/settings/keyfile', 'utf8').includes("color-scheme='prefer-light'"), true);
        assert.deepEqual(readFileSync(env.XDG_STATE_HOME + '/nugu/niri.kdl'), readFileSync(env.XDG_CONFIG_HOME + '/niri/themes/nugu-light.kdl'));
        await screenshot('config-native-light');
        writeFileSync(modeFile, 'dark\n');
        await waitFor('production Config observes external authority changes without writeback', () =>
            state().mode === 'dark' && snapshot().features.config.controls['dark mode']?.checked);
        await screenshot('config-native-dark');
        writeFileSync('/tmp/config-interrupt', '');
        ipc('selectMode', 'light');
        await waitFor('abnormal runtime termination keeps committed authority and exposes retry', () =>
            !state().busy && state().mode === 'light' && state().error === 'appearance interrupted; retry selected mode');
        assert.equal(readFileSync(modeFile, 'utf8'), 'light\n');
        rmSync('/tmp/config-interrupt');
        ipc('selectMode', 'light');
        await waitFor('interrupted publication reconciles on same-mode retry', () =>
            !state().busy && state().mode === 'light' && !state().error);
    } finally {
        await stop(child);
    }
}