Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export class BRIGController {
private parserWorker?: Worker;
private alignmentWorkers: Worker[] = [];
private progressCallback?: (update: ProgressUpdate) => void;
private alignmentCache: Map<string, AlignmentResult> = new Map();
private alignmentCache: Map<string, { result: AlignmentResult; rawOutput: string }> = new Map();

async initialize(): Promise<void> {
console.log('[Controller] Starting initialization...');
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand Down
21 changes: 21 additions & 0 deletions tests/e2e/brigx.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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`))
Expand Down