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.

test(ui-tests): real assertions for followup research (dead-field audit) (#4673)

LearningCircuitf035cf6bee3c
diff --git a/src/local_deep_research/web/static/js/followup.js b/src/local_deep_research/web/static/js/followup.js
index d7a8e10dff..69bd4afd60 100644
--- a/src/local_deep_research/web/static/js/followup.js
+++ b/src/local_deep_research/web/static/js/followup.js
@@ -355,3 +355,9 @@ function toggleAdvancedOptions(event) {
// Exposed on window so vitest can exercise getResearchIdFromPage
// (and other future helpers) without spinning up the full followup modal.
window.FollowUpResearch = FollowUpResearch;
+// The singleton instance must also be on window because templates use it in
+// inline onclick handlers (e.g. results.html: `window.followUpResearch ? ...`).
+// A top-level `const` does NOT become a window property in classic scripts,
+// so without this assignment those handlers always fall through to the
+// "feature loading..." alert branch and the modal never opens.
+window.followUpResearch = followUpResearch;
diff --git a/tests/ui_tests/test_followup_research_ci.js b/tests/ui_tests/test_followup_research_ci.js
index 463da1aa19..5b14f935ca 100644
--- a/tests/ui_tests/test_followup_research_ci.js
+++ b/tests/ui_tests/test_followup_research_ci.js
@@ -27,6 +27,66 @@ async function navigateToWithRetry(page, url) {
}
}
+/**
+ * Deterministic results-page URL for follow-up modal tests.
+ *
+ * The /results/<id> route (research_routes.py: results_page) renders
+ * pages/results.html without any DB lookup of the research id — it only
+ * carries @login_required (satisfied here by setupTest({authenticate:true})),
+ * so a synthetic UUID still renders the page, the
+ * #ask-followup-btn, and loads followup.js. This lets the follow-up
+ * modal tests run on a no-LLM CI shard with a fresh DB (where no
+ * completed research exists to link to), instead of skipping the whole
+ * feature. followup.js derives parentResearchId from this URL path.
+ */
+const SYNTHETIC_RESULTS_ID = '00000000-0000-0000-0000-000000000123';
+
+/**
+ * Open the follow-up modal on a freshly-loaded results page and wait for
+ * it to be visible. Returns true once #followUpModal is shown.
+ *
+ * The modal markup is fetched client-side from
+ * /static/templates/followup_modal.html and injected by followup.js, then
+ * shown via Bootstrap (class "show", display !== none). We poll because
+ * the fetch + insert is async.
+ */
+async function openFollowupModal(page, baseUrl) {
+ // Force a genuinely fresh load of the results page on every call.
+ // navigateTo() skips page.goto when the path is unchanged, so without
+ // this reset a test that runs after another already on /results/<id>
+ // would re-use the modal left open by the earlier test instead of
+ // independently re-loading the page and re-opening the modal. Resetting
+ // to about:blank guarantees each test exercises the full
+ // navigate -> inject -> show path from a clean page.
+ await page.goto('about:blank', { timeout: 5000 });
+
+ await navigateToWithRetry(page, `${baseUrl}/results/${SYNTHETIC_RESULTS_ID}`);
+
+ // followup.js wires #ask-followup-btn.onclick on DOMContentLoaded.
+ // Wait for the button to exist and be enabled before clicking.
+ await page.waitForSelector('#ask-followup-btn:not([disabled])', { timeout: 10000 });
+
+ await page.evaluate(() => {
+ const btn = document.getElementById('ask-followup-btn');
+ if (window.followUpResearch) {
+ window.followUpResearch.showFollowUpModal();
+ } else if (btn) {
+ btn.click();
+ }
+ });
+
+ // Wait for the modal to be injected and shown.
+ try {
+ await page.waitForFunction(() => {
+ const m = document.getElementById('followUpModal');
+ return !!m && getComputedStyle(m).display !== 'none';
+ }, { timeout: 8000 });
+ return true;
+ } catch {
+ return false;
+ }
+}
+
// ============================================================================
// Follow-up Research Tests
// ============================================================================
@@ -137,121 +197,106 @@ const FollowupResearchTests = {
},
async followupQueryPrefilled(page, baseUrl) {
- await navigateToWithRetry(page, `${baseUrl}/history`);
-
- const researchId = await page.evaluate(() => {
- const link = document.querySelector('a[href*="/results/"]');
- const match = link?.href?.match(/\/results\/([a-zA-Z0-9-]+)/);
- return match ? match[1] : null;
- });
-
- if (!researchId) {
- return { passed: null, skipped: true, message: 'No research for prefilled query test' };
+ const opened = await openFollowupModal(page, baseUrl);
+ if (!opened) {
+ return { passed: false, message: 'Follow-up modal did not open on results page' };
}
- await navigateToWithRetry(page, `${baseUrl}/results/${researchId}`);
-
- // Click follow-up button
- await page.evaluate(() => {
- const buttons = Array.from(document.querySelectorAll('button, a.btn'));
- const followupBtn = buttons.find(b =>
- b.textContent?.toLowerCase().includes('follow') ||
- b.textContent?.toLowerCase().includes('deeper')
- );
- if (followupBtn) followupBtn.click();
- });
-
- await delay(500);
-
+ // The follow-up textarea is #followUpQuestion inside #followUpModal.
+ // It is NOT prefilled with a value (followup.js only ever reads
+ // .value, never writes it); it carries an example-prompt
+ // placeholder and is `required`. Assert that concrete structure
+ // scoped to the modal so a wrong page/modal would fail this test.
const result = await page.evaluate(() => {
- const queryInput = document.querySelector(
- 'input[name*="query"], ' +
- 'textarea[name*="query"], ' +
- '#followup-query, ' +
- '.followup-input'
- );
-
- if (!queryInput) return { hasInput: false };
+ const modal = document.getElementById('followUpModal');
+ if (!modal) return { hasModal: false };
- const value = queryInput.value || queryInput.textContent;
- const placeholder = queryInput.placeholder;
+ const input = modal.querySelector('textarea#followUpQuestion');
+ if (!input) return { hasModal: true, hasInput: false };
return {
+ hasModal: true,
hasInput: true,
- hasValue: value && value.length > 0,
- valueLength: value?.length || 0,
- hasPlaceholder: placeholder && placeholder.length > 0,
- previewText: value?.substring(0, 50) || placeholder?.substring(0, 50)
+ placeholder: input.placeholder || '',
+ placeholderLen: (input.placeholder || '').length,
+ required: input.hasAttribute('required'),
+ value: input.value || ''
};
});
+ if (!result.hasModal) {
+ return { passed: false, message: 'Wrong page loaded: #followUpModal missing' };
+ }
if (!result.hasInput) {
- return { passed: null, skipped: true, message: 'No query input found in follow-up form' };
+ return { passed: false, message: 'Follow-up modal opened but textarea#followUpQuestion not found' };
}
+ // Real assertion: the question field renders with a non-trivial
+ // example placeholder and is required. Empty value is expected
+ // (the field is not prefilled), so we do not require a value.
+ const passed = result.placeholderLen > 10 && result.required && result.value === '';
+
return {
- passed: result.hasValue || result.hasPlaceholder,
- message: result.hasValue
- ? `Query prefilled (${result.valueLength} chars): "${result.previewText}..."`
- : (result.hasPlaceholder ? `Placeholder set: "${result.previewText}..."` : 'Query not prefilled')
+ passed,
+ message: passed
+ ? `Follow-up question field ready (required, placeholder ${result.placeholderLen} chars, value empty as expected)`
+ : `Unexpected question field state: required=${result.required}, placeholderLen=${result.placeholderLen}, value="${result.value.slice(0, 30)}"`
};
},
async followupSubmitButton(page, baseUrl) {
- await navigateToWithRetry(page, `${baseUrl}/history`);
-
- const researchId = await page.evaluate(() => {
- const link = document.querySelector('a[href*="/results/"]');
- const match = link?.href?.match(/\/results\/([a-zA-Z0-9-]+)/);
- return match ? match[1] : null;
- });
-
- if (!researchId) {
- return { passed: null, skipped: true, message: 'No research for submit button test' };
+ const opened = await openFollowupModal(page, baseUrl);
+ if (!opened) {
+ return { passed: false, message: 'Follow-up modal did not open on results page' };
}
- await navigateToWithRetry(page, `${baseUrl}/results/${researchId}`);
-
- // Open follow-up form
- await page.evaluate(() => {
- const buttons = Array.from(document.querySelectorAll('button, a.btn'));
- const followupBtn = buttons.find(b =>
- b.textContent?.toLowerCase().includes('follow') ||
- b.textContent?.toLowerCase().includes('deeper')
- );
- if (followupBtn) followupBtn.click();
- });
-
- await delay(500);
-
+ // Assert the submit control SCOPED to #followUpModal — no global
+ // .btn-primary fallback (the results page chrome also has
+ // .btn-primary buttons like #ask-followup-btn). The modal's
+ // submit button is the primary button that triggers
+ // submitFollowUp() and is labelled "Start Follow-up Research".
const result = await page.evaluate(() => {
- const submitBtn = document.querySelector(
- 'button[type="submit"], ' +
- '.followup-submit, ' +
- '.btn-primary, ' +
- 'button.submit'
- );
-
- // Check within modal/form context
- const modal = document.querySelector('.modal, .dialog, [role="dialog"]');
- const modalSubmit = modal?.querySelector('button[type="submit"], .btn-primary');
-
- const btn = modalSubmit || submitBtn;
+ const modal = document.getElementById('followUpModal');
+ if (!modal) return { hasModal: false };
+
+ const footer = modal.querySelector('.modal-footer') || modal;
+ const candidates = Array.from(footer.querySelectorAll('button.btn-primary'));
+ const submitBtn = candidates.find(b =>
+ (b.getAttribute('onclick') || '').includes('submitFollowUp') ||
+ /follow-?up/i.test(b.textContent || '')
+ ) || candidates[0];
+
+ if (!submitBtn) {
+ return { hasModal: true, hasSubmitBtn: false };
+ }
return {
- hasSubmitBtn: !!btn,
- buttonText: btn?.textContent?.trim(),
- isDisabled: btn?.disabled
+ hasModal: true,
+ hasSubmitBtn: true,
+ buttonText: (submitBtn.textContent || '').trim(),
+ onclick: submitBtn.getAttribute('onclick') || '',
+ isDisabled: !!submitBtn.disabled
};
});
+ if (!result.hasModal) {
+ return { passed: false, message: 'Wrong page loaded: #followUpModal missing' };
+ }
if (!result.hasSubmitBtn) {
- return { passed: null, skipped: true, message: 'No submit button in follow-up form' };
+ return { passed: false, message: 'No .btn-primary submit button inside #followUpModal' };
}
+ // Real assertion: the scoped button is the follow-up submit
+ // control (wired to submitFollowUp and/or labelled accordingly).
+ const wired = result.onclick.includes('submitFollowUp');
+ const labelled = /follow-?up/i.test(result.buttonText);
+ const passed = wired || labelled;
+
return {
- passed: true,
- message: `Submit button found: "${result.buttonText}" (disabled: ${result.isDisabled})`
+ passed,
+ message: passed
+ ? `Follow-up submit button found in modal: "${result.buttonText}" (disabled: ${result.isDisabled})`
+ : `Found modal .btn-primary but it is not the follow-up submit: "${result.buttonText}" onclick="${result.onclick}"`
};
},
@@ -333,64 +378,60 @@ const FollowupResearchTests = {
},
async followupLinksToOriginal(page, baseUrl) {
- await navigateToWithRetry(page, `${baseUrl}/history`);
-
- const researchId = await page.evaluate(() => {
- const link = document.querySelector('a[href*="/results/"]');
- const match = link?.href?.match(/\/results\/([a-zA-Z0-9-]+)/);
- return match ? match[1] : null;
- });
-
- if (!researchId) {
- return { passed: null, skipped: true, message: 'No research for original link test' };
+ const opened = await openFollowupModal(page, baseUrl);
+ if (!opened) {
+ return { passed: false, message: 'Follow-up modal did not open on results page' };
}
- await navigateToWithRetry(page, `${baseUrl}/results/${researchId}`);
-
- // Open follow-up form
- await page.evaluate(() => {
- const buttons = Array.from(document.querySelectorAll('button, a.btn'));
- const followupBtn = buttons.find(b =>
- b.textContent?.toLowerCase().includes('follow') ||
- b.textContent?.toLowerCase().includes('deeper')
- );
- if (followupBtn) followupBtn.click();
- });
-
- await delay(500);
-
- const result = await page.evaluate((originalId) => {
- // Look for reference to original research
- const modal = document.querySelector('.modal, .dialog, [role="dialog"], .followup-form');
- const container = modal || document;
+ // The follow-up modal references the parent/original research via a
+ // dedicated #parentContext block (populated by /api/followup/prepare)
+ // plus visible copy stating the follow-up builds on the *previous
+ // research* context. There is no static hyperlink to the source id;
+ // the parent linkage is carried in JS (parentResearchId from the URL)
+ // and surfaced through #parentContext / #parentSummary / #parentSources.
+ // Assert that concrete structure SCOPED to the modal (not generic
+ // page text), so a wrong page would fail this test. We do not depend
+ // on #parentContext being *visible*: it is populated by the
+ // /api/followup/prepare DB lookup, which returns 404 for the synthetic
+ // id (no such research) and leaves the block hidden — so we assert only
+ // on the structural reference existing in the modal.
+ const result = await page.evaluate(() => {
+ const modal = document.getElementById('followUpModal');
+ if (!modal) return { hasModal: false };
- const originalLink = container.querySelector(`a[href*="${originalId}"], a[href*="original"]`);
- const originalRef = container.querySelector('[class*="original"], [class*="parent"], .source-research');
+ const parentCtx = modal.querySelector('#parentContext');
+ const parentSummary = modal.querySelector('#parentSummary');
+ const parentSources = modal.querySelector('#parentSources');
- // Check text content for reference
- const text = container.textContent?.toLowerCase() || '';
- const hasReference = text.includes('original') || text.includes('parent') ||
- text.includes('based on') || text.includes('continue from');
+ const visibleText = (modal.textContent || '').toLowerCase();
+ const mentionsPrevious = visibleText.includes('previous research');
return {
- hasLink: !!originalLink,
- hasRefElement: !!originalRef,
- hasReferenceText: hasReference,
- linkHref: originalLink?.href
+ hasModal: true,
+ hasParentContext: !!parentCtx,
+ hasParentSummary: !!parentSummary,
+ hasParentSources: !!parentSources,
+ mentionsPrevious
};
- }, researchId);
-
- const hasReference = result.hasLink || result.hasRefElement || result.hasReferenceText;
+ });
- if (!hasReference) {
- return { passed: null, skipped: true, message: 'No reference to original research found' };
+ if (!result.hasModal) {
+ return { passed: false, message: 'Wrong page loaded: #followUpModal missing' };
}
+ // Real assertion: the parent-research reference structure exists in
+ // the modal AND the modal copy explicitly mentions the previous
+ // research it builds on.
+ const passed = result.hasParentContext &&
+ result.hasParentSummary &&
+ result.hasParentSources &&
+ result.mentionsPrevious;
+
return {
- passed: true,
- message: result.hasLink
- ? `Link to original research found`
- : (result.hasRefElement ? 'Reference to original research shown' : 'Original research reference in text')
+ passed,
+ message: passed
+ ? 'Follow-up modal references parent research (#parentContext/#parentSummary/#parentSources + "previous research" copy)'
+ : `Parent-research reference incomplete: parentContext=${result.hasParentContext}, parentSummary=${result.hasParentSummary}, parentSources=${result.hasParentSources}, mentionsPrevious=${result.mentionsPrevious}`
};
}
};