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.0 KB
Raw Blame
/**
 * Tests for pages/note-detail.js — renderGradeFailure.
 *
 * When the research COMPLETED but grading failed, renderGradeFailure keeps the
 * completed research and offers a "Retry grading" affordance (re-grade without
 * re-running the research). A 502 (report temporarily unavailable) is softened;
 * other errors show the server message (or a generic fallback).
 *
 * Driven via the production-inert window.__noteDetailTest hook.
 */

let hook;

beforeAll(async () => {
    window.__VITEST_TEST__ = true;
    globalThis.safeFetch = vi.fn(() =>
        Promise.resolve({ ok: true, json: () => Promise.resolve({ success: true }) })
    );
    globalThis.escapeHtml = (s) => String(s ?? '');
    await import('@js/pages/note-detail.js');
    hook = window.__noteDetailTest;
});

afterAll(() => {
    delete window.__VITEST_TEST__;
});

beforeEach(() => {
    document.body.innerHTML =
        '<div id="ldr-ai-results-panel"><span id="ldr-ai-results-title"></span>' +
        '<div id="ldr-ai-results-content"></div></div>';
});

const content = () => document.getElementById('ldr-ai-results-content').innerHTML;

describe('renderGradeFailure', () => {
    it('offers a retry affordance carrying the research id, plus a report link', () => {
        hook.renderGradeFailure('res-1', ['c'], 'hard error', 500);

        const html = content();
        expect(html).toContain('hard error');
        expect(html).toContain('Retry grading');
        expect(html).toContain('data-research-id="res-1"');
        expect(html).toContain('/results/res-1'); // view full report link
    });

    it('softens the 502 (report temporarily unavailable) copy', () => {
        hook.renderGradeFailure('res-1', ['c'], 'Bad Gateway', 502);

        const html = content().toLowerCase();
        expect(html).toContain('temporarily unavailable');
        expect(html).not.toContain('bad gateway');
    });

    it('falls back to a generic message when none is given', () => {
        hook.renderGradeFailure('res-1', ['c'], undefined, 500);
        expect(content()).toContain('Grading failed.');
    });
});