Files
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

225 lines
6.9 KiB
JavaScript

/**
* Jest unit tests for Re-run Research configuration handling.
*
* Tests the logic for:
* 1. Building rerun config from research items (history.js handleRerun)
* 2. Parsing and applying rerun config (research.js checkAndApplyRerunConfig)
*
* Note: Re-run only stores query and mode. All other settings (model, provider,
* search engine, etc.) come from the user's current defaults via the settings manager.
*
* Run with: npx jest tests/infrastructure_tests/test_rerun_config.test.js
*/
// Mock sessionStorage
const mockSessionStorage = {
store: {},
getItem: jest.fn((key) => mockSessionStorage.store[key] || null),
setItem: jest.fn((key, value) => { mockSessionStorage.store[key] = value; }),
removeItem: jest.fn((key) => { delete mockSessionStorage.store[key]; }),
clear: jest.fn(() => { mockSessionStorage.store = {}; })
};
// Mock URLValidator
const mockURLValidator = {
safeAssign: jest.fn()
};
// Setup globals
global.sessionStorage = mockSessionStorage;
global.URLValidator = mockURLValidator;
global.window = {
location: { href: '' }
};
// ============================================================================
// handleRerun Logic Tests (from history.js)
// ============================================================================
describe('handleRerun Configuration Building', () => {
beforeEach(() => {
jest.clearAllMocks();
mockSessionStorage.clear();
});
/**
* Simulates the handleRerun function logic.
* Only stores query and mode - no advanced settings.
*/
function buildRerunConfig(item) {
return {
query: item.query,
mode: item.mode
};
}
describe('Basic Config Building', () => {
test('should include query and mode from item', () => {
const item = {
query: 'What is quantum computing?',
mode: 'detailed'
};
const config = buildRerunConfig(item);
expect(config.query).toBe('What is quantum computing?');
expect(config.mode).toBe('detailed');
});
test('should handle missing mode gracefully', () => {
const item = {
query: 'Test query'
// mode is undefined
};
const config = buildRerunConfig(item);
expect(config.query).toBe('Test query');
expect(config.mode).toBeUndefined();
});
test('should handle empty query', () => {
const item = {
query: '',
mode: 'quick'
};
const config = buildRerunConfig(item);
expect(config.query).toBe('');
expect(config.mode).toBe('quick');
});
});
describe('Advanced settings are NOT included', () => {
test('should not include submission params even when present', () => {
const item = {
query: 'Test query',
mode: 'detailed',
metadata: {
submission: {
model_provider: 'OLLAMA',
model: 'llama3',
search_engine: 'duckduckgo',
iterations: 5,
questions_per_iteration: 3,
strategy: 'focused-iteration'
}
}
};
const config = buildRerunConfig(item);
expect(config.query).toBe('Test query');
expect(config.mode).toBe('detailed');
expect(config.model_provider).toBeUndefined();
expect(config.model).toBeUndefined();
expect(config.search_engine).toBeUndefined();
expect(config.iterations).toBeUndefined();
expect(config.questions_per_iteration).toBeUndefined();
expect(config.strategy).toBeUndefined();
});
test('should only have query and mode keys', () => {
const item = {
query: 'Test query',
mode: 'quick',
metadata: { submission: { model_provider: 'OPENAI' } }
};
const config = buildRerunConfig(item);
const keys = Object.keys(config);
expect(keys).toEqual(['query', 'mode']);
});
});
});
// ============================================================================
// checkAndApplyRerunConfig Logic Tests (from research.js)
// ============================================================================
describe('checkAndApplyRerunConfig Parsing', () => {
beforeEach(() => {
jest.clearAllMocks();
mockSessionStorage.clear();
});
/**
* Simulates the config parsing logic from checkAndApplyRerunConfig
*/
function parseRerunConfig() {
const rerunConfigStr = sessionStorage.getItem('rerunConfig');
if (!rerunConfigStr) return null;
try {
const config = JSON.parse(rerunConfigStr);
sessionStorage.removeItem('rerunConfig');
return config;
} catch {
sessionStorage.removeItem('rerunConfig');
return null;
}
}
describe('Valid Config Parsing', () => {
test('should parse valid JSON config', () => {
const config = { query: 'Test', mode: 'quick' };
sessionStorage.setItem('rerunConfig', JSON.stringify(config));
const parsed = parseRerunConfig();
expect(parsed).toEqual(config);
expect(sessionStorage.getItem('rerunConfig')).toBeNull();
});
test('should parse config with query and mode', () => {
const config = {
query: 'Full config test',
mode: 'detailed'
};
sessionStorage.setItem('rerunConfig', JSON.stringify(config));
const parsed = parseRerunConfig();
expect(parsed).toEqual(config);
});
});
describe('Invalid Config Handling', () => {
test('should return null for invalid JSON', () => {
sessionStorage.setItem('rerunConfig', 'not valid json {{{');
const parsed = parseRerunConfig();
expect(parsed).toBeNull();
expect(sessionStorage.getItem('rerunConfig')).toBeNull();
});
test('should return null for empty string', () => {
sessionStorage.setItem('rerunConfig', '');
const parsed = parseRerunConfig();
expect(parsed).toBeNull();
});
test('should return null when no config exists', () => {
const parsed = parseRerunConfig();
expect(parsed).toBeNull();
});
test('should handle truncated JSON', () => {
sessionStorage.setItem('rerunConfig', '{"query": "test"');
const parsed = parseRerunConfig();
expect(parsed).toBeNull();
expect(sessionStorage.getItem('rerunConfig')).toBeNull();
});
});
});