diff --git a/lib/controller.ts b/lib/controller.ts index cd3c946..2022774 100644 --- a/lib/controller.ts +++ b/lib/controller.ts @@ -66,7 +66,7 @@ export class BRIGController { private parserWorker?: Worker; private alignmentWorkers: Worker[] = []; private progressCallback?: (update: ProgressUpdate) => void; - private alignmentCache: Map = new Map(); + private alignmentCache: Map = new Map(); async initialize(): Promise { console.log('[Controller] Starting initialization...'); @@ -532,8 +532,7 @@ export class BRIGController { if (!params.forceAlignment && this.alignmentCache.has(cacheKey)) { console.log(`[Controller] Using cached alignment for ${query.name}`); - const cachedResult = this.alignmentCache.get(cacheKey)!; - result = { result: cachedResult, rawOutput: '' }; + result = this.alignmentCache.get(cacheKey)!; } else { console.log(`[Controller] Aligning ${query.name} (${query.length} bp)`); try { @@ -550,7 +549,7 @@ export class BRIGController { const message = error instanceof Error ? error.message : String(error); throw new Error(`Alignment failed for ${query.name}: ${message}`); } - this.alignmentCache.set(cacheKey, result.result); + this.alignmentCache.set(cacheKey, result); } alignmentResults[ringIndex] = result; diff --git a/tests/e2e/brigx.spec.ts b/tests/e2e/brigx.spec.ts index 2534e07..76189aa 100644 --- a/tests/e2e/brigx.spec.ts +++ b/tests/e2e/brigx.spec.ts @@ -411,7 +411,9 @@ test.describe('BRIGX e2e — circular genome plot', () => { }) const pageErrors: Error[] = [] + const consoleMessages: string[] = [] page.on('pageerror', error => pageErrors.push(error)) + page.on('console', message => consoleMessages.push(message.text())) await page.goto('/app') await page.getByLabel('Reference genome file').setInputFiles(REFERENCE) @@ -439,6 +441,25 @@ test.describe('BRIGX e2e — circular genome plot', () => { await page.getByRole('button', { name: 'Run Alignments' }).click() await Promise.all(assetResponses) await expect(page.getByText('Alignments completed successfully!')).toBeVisible({ timeout: 30_000 }) + + const downloadAlignment = async () => { + const downloadPromise = page.waitForEvent('download') + await page.getByRole('button', { name: 'Download', exact: true }).click() + const download = await downloadPromise + const downloadPath = await download.path() + expect(downloadPath).not.toBeNull() + return fs.readFile(downloadPath!, 'utf8') + } + await expect(page.getByRole('button', { name: 'Download', exact: true })).toHaveCount(1) + const freshAlignment = await downloadAlignment() + expect(freshAlignment).toContain('#query\tsubject\t%identity') + + await page.getByRole('button', { name: 'Run Alignments' }).click() + await expect.poll(() => consoleMessages.some(message => message.includes('Using cached alignment'))).toBe(true) + await expect(page.getByRole('button', { name: 'Download', exact: true })).toHaveCount(1) + const cachedAlignment = await downloadAlignment() + expect(cachedAlignment).toBe(freshAlignment) + for (const moduleName of ['formatdb', 'blastall']) { const jsRequests = requestedAssets.filter(pathname => pathname.endsWith(`/wasm/blast/${moduleName}.js`)) const wasmRequests = requestedAssets.filter(pathname => pathname.endsWith(`/wasm/blast/${moduleName}.wasm`))