const { test } = require('node:test'); const assert = require('node:assert/strict'); const fs = require('node:fs'); const path = require('node:path'); const ROOT = path.join(__dirname, '..', '..'); const PLUGIN_LOADER_JS = path.join(ROOT, 'static', 'js', 'plugin-loader.js'); const MANIFEST = path.join(ROOT, 'plugins', 'capability_inspector', 'plugin.json'); const SCREEN_HTML = path.join(ROOT, 'plugins', 'capability_inspector', 'screen.html'); const SETTINGS_HTML = path.join(ROOT, 'plugins', 'capability_inspector', 'settings.html'); function source(file) { return fs.readFileSync(file, 'utf8'); } function region(src, needle, length = 1800) { const start = src.indexOf(needle); assert.ok(start !== -1, `missing source needle: ${needle}`); return src.slice(start, start + length); } test('capability inspector manifest ships settings but no default nav entry', () => { const manifest = JSON.parse(source(MANIFEST)); assert.equal(manifest.id, 'capability_inspector'); assert.equal(manifest.nav, undefined); assert.equal(manifest.settings.html, 'settings.html'); }); test('capability inspector plugins menu entry is localStorage opt-in', () => { const src = source(PLUGIN_LOADER_JS); const helper = region(src, "const CAPABILITY_INSPECTOR_NAV_SETTING = 'capability_inspector.showInPluginsMenu'", 1400); const menu = region(src, 'const navPlugins = plugins.map', 1000); const contributions = region(src, 'async function _registerLegacyPluginUiContributions(plugin)', 1400); assert.match(helper, /localStorage\.getItem\(CAPABILITY_INSPECTOR_NAV_SETTING\)\s*===\s*['"]1['"]/); assert.match(helper, /if \(plugin\.id === ['"]capability_inspector['"]\)/); assert.match(helper, /return null/); assert.match(helper, /label:\s*['"]Capabilities['"]/); assert.match(menu, /_pluginNav\(plugin\)/); assert.match(contributions, /const nav = _pluginNav\(plugin\)/); assert.doesNotMatch(contributions, /if \(plugin\.nav\)/); }); test('capability inspector settings toggles the plugins menu setting', () => { const html = source(SETTINGS_HTML); assert.match(html, /id="capability-inspector-show-nav"/); assert.match(html, /capability_inspector\.showInPluginsMenu/); assert.match(html, /localStorage\.setItem\(key, '1'\)/); assert.match(html, /localStorage\.removeItem\(key\)/); assert.match(html, /window\.loadPlugins\(\)/); assert.match(html, /window\.showScreen\('plugin-capability_inspector'\)/); }); test('capability inspector screen ships scoped graph lane CSS', () => { const html = source(SCREEN_HTML); assert.match(html, /