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.4 KB
Raw Blame
/**
 * Opt-in screenshot capture for the Puppeteer suites.
 *
 * Screenshots are a debugging aid for a human (or a model) eyeballing the
 * migrated UI — a page can return HTTP 200 with a correct body and still
 * render as a collapsed layout, a blank panel, or an error card, and no
 * assertion in the suite catches that.
 *
 * They are deliberately OFF unless `LDR_UI_SCREENSHOTS` is set, so:
 *   - CI never spends time or disk on them, and never uploads artifacts;
 *   - a normal `node test_*.js` run behaves exactly as before.
 *
 * Enable locally with:
 *     LDR_UI_SCREENSHOTS=1 CI=true node test_navigation_and_theme_ci.js
 *
 * Output goes to `tests/ui_tests/screenshots/` (or $LDR_UI_SCREENSHOT_DIR),
 * which .gitignore already blocks three times over — `*.png`,
 * `screenshots/`, and `tests/screenshots/` — so captures can never be
 * committed by accident.
 */

const fs = require('fs');
const path = require('path');

const ENABLED = Boolean(process.env.LDR_UI_SCREENSHOTS);
const OUT_DIR =
    process.env.LDR_UI_SCREENSHOT_DIR || path.join(__dirname, 'screenshots');

let dirReady = false;

function ensureDir() {
    if (!dirReady) {
        fs.mkdirSync(OUT_DIR, { recursive: true });
        dirReady = true;
    }
    return OUT_DIR;
}

/** Whether capture is enabled for this run. */
function screenshotsEnabled() {
    return ENABLED;
}

/**
 * Capture `page` as `<prefix>-<name>.png`, if enabled.
 *
 * Never throws: a screenshot failing must not fail the test that asked
 * for it — the assertion is the test, this is only an aid. Returns the
 * written path, or null when disabled or on error.
 */
async function capture(page, prefix, name, { fullPage = false } = {}) {
    if (!ENABLED || !page) return null;
    try {
        const safe = String(name).replace(/[^\w.-]+/g, '_');
        const file = path.join(ensureDir(), `${prefix}-${safe}.png`);
        await page.screenshot({ path: file, fullPage });
        return file;
    } catch (err) {
        console.log(`   (screenshot "${name}" skipped: ${err.message})`);
        return null;
    }
}

/**
 * Capture only when `condition` is false — i.e. grab evidence at the
 * moment an assertion fails, which is when a picture is worth most.
 */
async function captureOnFailure(page, prefix, name, condition) {
    if (condition) return null;
    return capture(page, prefix, `FAIL-${name}`);
}

module.exports = { capture, captureOnFailure, screenshotsEnabled, OUT_DIR };