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.

3.5 KB
Raw Blame
/** Additional runtime coverage for FastAPI agent-phase progress frames. */

let progressComponent;

beforeAll(async () => {
    await import('@js/components/progress.js');
    progressComponent = window.progressComponent;
});

beforeEach(() => {
    document.body.innerHTML = `
        <section id="agent-thinking-panel" style="display: none">
            <div id="agent-thinking-content"></div>
        </section>
    `;
});

afterEach(() => {
    document.body.replaceChildren();
    delete window.__agentPhaseXss;
});

const phaseCases = [
    [
        { phase: 'react', iteration: 3, message: 'Planning the next cycle' },
        'ldr-info',
        'CYCLE 3',
        'Planning the next cycle',
    ],
    [
        { phase: 'thought', thought: 'Compare the primary sources' },
        'ldr-thought',
        '💭 THINKING',
        'Compare the primary sources',
    ],
    [
        { phase: 'error', error: 'Provider authentication failed' },
        'ldr-error',
        '❌ ERROR',
        'Provider authentication failed',
    ],
    [
        { phase: 'synthesis' },
        'ldr-info',
        '📝 SYNTHESIZING',
        'Synthesizing findings with citations...',
    ],
    [
        { phase: 'sub_research', message: 'Checking a disputed claim' },
        'ldr-action',
        '🔬 SUB-RESEARCH',
        'Checking a disputed claim',
    ],
    [
        { phase: 'init' },
        'ldr-info',
        '🚀 STARTING',
        'Initializing research...',
    ],
    [
        { phase: 'complete', message: 'Report assembled' },
        'ldr-info',
        '✅ COMPLETE',
        'Report assembled',
    ],
];

it.each(phaseCases)(
    'renders the $phase frame with its semantic label and content',
    (frame, expectedClass, expectedLabel, expectedContent) => {
        progressComponent.updateAgentThinking(frame);

        const panel = document.getElementById('agent-thinking-panel');
        const step = panel.querySelector('.ldr-agent-step');
        expect(panel.style.display).toBe('block');
        expect(step.classList).toContain(expectedClass);
        expect(step.querySelector('.ldr-agent-step-label').textContent)
            .toBe(expectedLabel);
        expect(step.querySelector('.ldr-agent-step-content').textContent)
            .toBe(expectedContent);
    },
);

it('serializes non-query tool arguments when the frame has no display message', () => {
    progressComponent.updateAgentThinking({
        phase: 'tool_call',
        tool: 'fetch_document',
        arguments: {
            document_id: 'doc-3299',
            include_metadata: true,
        },
    });

    expect(document.querySelector('.ldr-agent-step-content').textContent)
        .toBe(
            'Using fetch_document\nArgs: {\n'
            + '  "document_id": "doc-3299",\n'
            + '  "include_metadata": true\n}',
        );
});

it('keeps hostile phase content inert in the agent panel', () => {
    const payload = '</div><img src=x onerror="window.__agentPhaseXss=true">';

    progressComponent.updateAgentThinking({
        phase: 'thought',
        thought: payload,
    });

    const content = document.querySelector('.ldr-agent-step-content');
    expect(content.textContent).toBe(payload);
    expect(content.querySelector('img')).toBeNull();
    expect(window.__agentPhaseXss).toBeUndefined();
});

it('ignores an agent frame when the optional panel is absent', () => {
    document.body.replaceChildren();

    expect(() => progressComponent.updateAgentThinking({
        phase: 'init',
        message: 'No panel on this layout',
    })).not.toThrow();
});