Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

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

Raw
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
import { readFileSync, writeFileSync } from 'node:fs';
import { setTimeout as delay } from 'node:timers/promises';

export default async function mediaProduction({ env, start, stop, waitFor, ipc, setFixture }) {
    assert.equal(process.env.NUGULAND_UI_SANDBOX, '1');
    const build = spawnSync('cc', ['-std=c17', '-Wall', '-Wextra', '-Werror', '/project/features/media/fixtures/mpris-standin.c', '-lsystemd', '-o', '/tmp/mpris-standin'], { env, encoding: 'utf8', timeout: 10000 });
    assert.equal(build.status, 0, build.stderr);
    const standin = start('/tmp/mpris-standin', [], 'media-mpris');
    await waitFor('private MPRIS stand-in', () => readFileSync('/evidence/media-mpris.log', 'utf8').includes('mpris fixture ready'));
    const fixture = '/project/media-native-probe.qml';
    writeFileSync(fixture, readFileSync('/project/features/media/fixtures/native-probe.qml', 'utf8').replaceAll('import "../../../features/', 'import "./features/'));
    const child = start('qs', ['--no-color', '-p', fixture], 'media-native-probe');
    setFixture(fixture, '/evidence/media-native-probe.log', child);
    try {
        await waitFor('media native probe loaded', () => readFileSync('/evidence/media-native-probe.log', 'utf8').includes('Configuration Loaded'));
        const state = () => JSON.parse(ipc('snapshot'));
        await waitFor('native player discovered', () => {
            const s = state();
            return s.player.title === 'fixture track' && s.player.playbackState === 'playing' && s.player.position >= 30;
        });
        // Let upstream's initial position requests settle before testing timer silence.
        await delay(1500);
        const closed = state();
        await delay(1200);
        assert.equal(state().signals, closed.signals, 'closed panel must not emit position notifications');
        ipc('open', 'true');
        const opened = state();
        const advanced = await waitFor('open playing position advances', () => {
            const s = state();
            return s.signals > opened.signals && s.player.position > opened.player.position ? s : null;
        });
        assert(advanced.player.progress > opened.player.progress);
        ipc('toggle');
        await waitFor('native player paused', () => state().player.playbackState === 'paused');
        await delay(500);
        const paused = state();
        await delay(1200);
        assert.equal(state().signals, paused.signals, 'paused player must not receive timer notifications');
        ipc('toggle');
        await waitFor('native player resumed', () => state().player.playbackState === 'playing');
        ipc('open', 'false');
        await delay(500);
        const reclosed = state();
        await delay(1200);
        assert.equal(state().signals, reclosed.signals, 'closing stops timer notifications');
        console.log('pass: private MPRIS progress and timer lifecycle');
    } finally {
        await stop(child);
        await stop(standin);
    }
}