Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

2.9 KB
Raw Blame
const assert = require('node:assert/strict');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { after, test } = require('node:test');

const { runTest } = require('./run_all_tests');

const fixtureDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ldr-ui-runner-'));
after(() => fs.rmSync(fixtureDir, { recursive: true, force: true }));

function fixture(name, source) {
    const file = path.join(fixtureDir, name);
    fs.writeFileSync(file, source);
    return { name, file };
}

// runTest() prints the same "Running", "Test timeout", PASSED/FAILED and
// "TIMING:" lines for these fixtures as for real UI tests, and this file runs
// in the error-benchmark shard. Hold those lines back and print them only if a
// case fails, so a search of the shard log finds only real test results.
async function runFixture(t, child, timeoutMs, check) {
    const log = t.mock.method(console, 'log', () => {});
    let result;
    try {
        result = await runTest(child, timeoutMs);
    } finally {
        log.mock.restore();
    }
    try {
        check(result);
    } catch (error) {
        const lines = log.mock.calls.map((call) => call.arguments.join(' '));
        console.log(`runTest output for ${child.name}:\n${lines.join('\n')}`);
        throw error;
    }
}

test('a completed child passes', async (t) => {
    await runFixture(t, fixture('success.js', 'process.exit(0);'), 5000, (result) => {
        assert.equal(result.success, true);
    });
});

test('a timed-out child that exits zero on SIGTERM fails', async (t) => {
    const child = fixture(
        'clean-shutdown.js',
        'process.on("SIGTERM", () => process.exit(0)); setInterval(() => {}, 1000);'
    );
    // Allow a loaded CI host time to start Node before the SIGTERM handler is installed.
    await runFixture(t, child, 3000, (result) => {
        assert.equal(result.code, 0);
        assert.equal(result.success, false);
        assert.match(result.error, /Timed out/);
    });
});

// The child ignores SIGTERM and exits on its own after 20 s, so a runner that
// never escalates to SIGKILL fails this test instead of leaving the child alive.
test('a timed-out child that ignores SIGTERM is killed and fails', async (t) => {
    const child = fixture(
        'ignore-sigterm.js',
        'process.on("SIGTERM", () => {}); setTimeout(() => process.exit(0), 20000);'
    );
    // Same startup allowance as above; the runner sends SIGKILL 5 s after SIGTERM.
    await runFixture(t, child, 3000, (result) => {
        assert.equal(result.signal, 'SIGKILL');
        assert.equal(result.code, null);
        assert.equal(result.success, false);
        assert.match(result.error, /Timed out/);
    });
});

test('a child that exits nonzero fails', async (t) => {
    await runFixture(t, fixture('failure.js', 'process.exit(1);'), 5000, (result) => {
        assert.equal(result.success, false);
        assert.equal(result.code, 1);
    });
});