2026-04-27 11:59:46 +00:00
|
|
|
/**
|
|
|
|
|
* Architecture guard tests — verify source code structure invariants
|
|
|
|
|
* that cannot be expressed via TypeScript types or lint rules.
|
|
|
|
|
*/
|
2026-04-25 11:44:39 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
|
const path = require('path');
|
2026-04-29 05:53:19 +00:00
|
|
|
const { assert } = require('./test-setup');
|
2026-04-27 11:59:46 +00:00
|
|
|
|
2026-04-25 11:44:39 +00:00
|
|
|
const mainSource = fs.readFileSync(path.join(__dirname, '..', 'main.ts'), 'utf8');
|
2026-04-25 15:40:56 +00:00
|
|
|
const viewSource = fs.readFileSync(path.join(__dirname, '..', 'src', 'view.ts'), 'utf8');
|
2026-04-27 11:59:46 +00:00
|
|
|
|
|
|
|
|
// View lifecycle guards
|
2026-04-25 15:40:56 +00:00
|
|
|
assert.ok(!/\basync\s+onOpen\s*\(/.test(viewSource), 'ParallelReaderView.onOpen should not be async without await');
|
|
|
|
|
assert.ok(!/\basync\s+onClose\s*\(\)\s*\{\s*\}/.test(viewSource), 'empty onClose should not be async');
|
|
|
|
|
assert.ok(/focusSummaryPane\s*\(\)/.test(viewSource), 'summary pane should expose a focus helper');
|
2026-04-27 11:53:35 +00:00
|
|
|
assert.ok(
|
|
|
|
|
/\.focus\(\{\s*preventScroll:\s*true\s*\}\)/.test(viewSource),
|
|
|
|
|
'summary pane focus should not scroll the page',
|
|
|
|
|
);
|
2026-04-25 15:40:56 +00:00
|
|
|
assert.ok(/moveActiveSection[\s\S]*focusSummaryPane/.test(viewSource), 'card navigation should focus the summary pane');
|
2026-04-27 11:59:46 +00:00
|
|
|
|
|
|
|
|
// Cache debounce guards
|
2026-04-25 11:44:39 +00:00
|
|
|
assert.ok(/scheduleCacheSave\s*\(/.test(mainSource), 'cache touch should use a debounced cache save path');
|
|
|
|
|
assert.ok(/flushCacheSave\s*\(/.test(mainSource), 'pending cache touches should be flushable');
|
|
|
|
|
assert.ok(/onunload[\s\S]*flushCacheSave/.test(mainSource), 'plugin unload should flush pending cache touches');
|
|
|
|
|
assert.ok(/cacheTouch[\s\S]*scheduleCacheSave/.test(mainSource), 'cacheTouch should schedule a cache save');
|
2026-04-27 11:53:35 +00:00
|
|
|
assert.ok(
|
|
|
|
|
!/cacheTouch[\s\S]{0,220}await this\.saveCache/.test(mainSource),
|
|
|
|
|
'cacheTouch should not synchronously write cache.json',
|
|
|
|
|
);
|
2026-04-26 10:05:38 +00:00
|
|
|
assert.ok(/handleFileRename[\s\S]*cacheManager\.move/.test(mainSource), 'file rename should delegate cache moves');
|
2026-04-27 11:53:35 +00:00
|
|
|
assert.ok(
|
|
|
|
|
!/handleFileRename[\s\S]*cacheManager\.cache\[/.test(mainSource),
|
|
|
|
|
'file rename should not mutate cache directly',
|
|
|
|
|
);
|
2026-04-27 11:59:46 +00:00
|
|
|
|
|
|
|
|
// Module extraction guards
|
2026-04-25 13:32:32 +00:00
|
|
|
assert.ok(!/function addIconButton/.test(mainSource), 'UI icon helper should live outside main.ts');
|
|
|
|
|
assert.ok(!/function addTextButton/.test(mainSource), 'UI text-button helper should live outside main.ts');
|
|
|
|
|
assert.ok(!/function copyToClipboard/.test(mainSource), 'clipboard helper should live outside main.ts');
|
2026-04-25 06:12:17 +00:00
|
|
|
|
2026-04-29 05:53:19 +00:00
|
|
|
console.log('architecture tests passed');
|