项目文件夹

文件
wehub-resource-sync 7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

194 行
7.4 KiB
JavaScript

此文件含有模棱两可的 Unicode 字符
此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。
/**
* Simple Research Test
* Minimal test to check if research can start
*/
const puppeteer = require('puppeteer');
const AuthHelper = require('./auth_helper');
const { getPuppeteerLaunchOptions } = require('./puppeteer_config');
const { setupDefaultModel } = require('./model_helper');
// NAVIGATION NOTE: Using 'domcontentloaded' instead of 'networkidle2' for page.goto()
// because networkidle2 waits for no network activity for 500ms, but WebSocket
// connections and background polling keep the network active, causing infinite hangs.
// See: test_login_validation.js and auth_helper.js for detailed explanation.
async function testSimpleResearch() {
const browser = await puppeteer.launch(getPuppeteerLaunchOptions());
const page = await browser.newPage();
const baseUrl = 'http://127.0.0.1:5000';
const authHelper = new AuthHelper(page, baseUrl);
let testPassed = false;
console.log('🔬 Simple Research Test\n');
// Monitor key API calls
page.on('response', async response => {
if (response.url().includes('/api/start_research') ||
response.url().includes('/research/start')) {
console.log(`\n📥 Research API Response:`);
console.log(` URL: ${response.url()}`);
console.log(` Status: ${response.status()} ${response.statusText()}`);
try {
const body = await response.text();
console.log(` Body: ${body.substring(0, 200)}...`);
} catch {
console.log(` Body: <unable to read>`);
}
}
});
try {
// Login
console.log('🔐 Logging in...');
await authHelper.ensureAuthenticatedWithTimeout();
console.log('✅ Logged in\n');
// Go to home
await page.goto(baseUrl, {
waitUntil: 'domcontentloaded',
timeout: 30000
});
// Check if we can find the form
console.log('📋 Checking form elements...');
const formCheck = await page.evaluate(() => {
return {
query: !!document.querySelector('#query'),
submit: !!document.querySelector('button[type="submit"]'),
form: !!document.querySelector('#research-form, form'),
provider: document.querySelector('#model_provider')?.value || 'not found',
model: document.querySelector('#model, input[name="model"]')?.value || 'not found'
};
});
console.log('Form elements found:');
console.log(` Query input: ${formCheck.query ? '✅' : '❌'}`);
console.log(` Submit button: ${formCheck.submit ? '✅' : '❌'}`);
console.log(` Form: ${formCheck.form ? '✅' : '❌'}`);
console.log(` Provider: ${formCheck.provider}`);
console.log(` Model: ${formCheck.model}`);
if (!formCheck.query || !formCheck.submit) {
throw new Error('Essential form elements not found');
}
// Set up model configuration before submitting
console.log('\n🔧 Configuring model...');
const modelConfigured = await setupDefaultModel(page);
if (!modelConfigured) {
throw new Error('Failed to configure model');
}
// Fill and submit
console.log('\n📝 Submitting research...');
await page.type('#query', 'What is 2+2?');
// Try different ways to submit - look for submit button within the form first
console.log('Looking for submit button...');
// First try to find submit button within the form specifically
const submitButton = await page.evaluate(() => {
const form = document.querySelector('#research-form, form');
if (form) {
const btn = form.querySelector('button[type="submit"], #start-research-btn, button:not([type="button"])');
if (btn) {
btn.click();
return true;
}
}
// Fallback: try any submit button on the page
const anySubmit = document.querySelector('#start-research-btn') ||
document.querySelector('button[type="submit"]') ||
Array.from(document.querySelectorAll('button')).find(b =>
b.textContent.includes('Start Research') ||
b.textContent.includes('Submit'));
if (anySubmit) {
anySubmit.click();
return true;
}
return false;
});
if (submitButton) {
console.log('✅ Submit button clicked');
// Wait for response or navigation
await Promise.race([
page.waitForNavigation({ waitUntil: 'domcontentloaded', timeout: 10000 }).catch(() => null),
page.waitForResponse(response =>
response.url().includes('research') || response.url().includes('api'),
{ timeout: 10000 }
).catch(() => null),
new Promise(resolve => setTimeout(resolve, 5000))
]);
console.log('Navigation or response received');
} else {
console.log('❌ Submit button not found, trying Enter key...');
await page.focus('#query');
await page.keyboard.press('Enter');
await new Promise(resolve => setTimeout(resolve, 3000));
}
// Wait a bit more
await new Promise(resolve => setTimeout(resolve, 3000));
// Check final state
const finalState = await page.evaluate(() => {
const alerts = Array.from(document.querySelectorAll('.alert')).map(a => ({
type: a.className.includes('danger') ? 'error' :
a.className.includes('success') ? 'success' : 'info',
text: a.textContent.trim()
}));
return {
url: window.location.href,
alerts,
queryValue: document.querySelector('#query')?.value || ''
};
});
console.log('\n📊 Final state:');
console.log(` URL: ${finalState.url}`);
console.log(` Query still in input: ${finalState.queryValue ? 'Yes' : 'No'}`);
if (finalState.alerts.length > 0) {
console.log(` Alerts:`);
finalState.alerts.forEach(alert => {
const icon = alert.type === 'error' ? '❌' :
alert.type === 'success' ? '✅' : '️';
console.log(` ${icon} ${alert.text}`);
});
}
// Check if we were redirected to a research page
if (finalState.url.includes('/research/') || finalState.url.includes('/progress')) {
console.log('\n✅ Research started successfully!');
console.log(` Research ID: ${finalState.url.split('/').pop()}`);
testPassed = true;
} else if (finalState.alerts.some(a => a.type === 'error')) {
console.log('\n❌ Research failed to start - error shown');
} else {
console.log('\n⚠️ Research status unclear - still on home page');
}
} catch (error) {
console.error('\n❌ Test error:', error.message);
}
await browser.close();
console.log('\n🏁 Test completed');
process.exit(testPassed ? 0 : 1);
}
// Run the test
testSimpleResearch().catch(error => {
console.error('Fatal error:', error);
process.exit(1);
});