import assert from 'node:assert/strict'; import fs from 'node:fs'; import path from 'node:path'; import test from 'node:test'; import { fileURLToPath } from 'node:url'; const currentDirectory = path.dirname(fileURLToPath(import.meta.url)); const webRoot = path.resolve(currentDirectory, '../..'); function readSource(relativePath) { return fs.readFileSync(path.join(webRoot, relativePath), 'utf8'); } const kbFormSource = readSource( 'src/app/home/knowledge/components/kb-form/KBForm.tsx', ); const selectSource = readSource( 'src/app/home/knowledge/components/kb-form/KnowledgeEngineSelect.tsx', ); const agentRunnerSelectSource = readSource( 'src/app/home/agents/components/AgentRunnerSelect.tsx', ); const agentFormSource = readSource( 'src/app/home/agents/components/AgentFormComponent.tsx', ); const pipelineFormSource = readSource( 'src/app/home/pipelines/components/pipeline-form/PipelineFormComponent.tsx', ); const agentRunnerMarketplaceSource = readSource( 'src/app/home/agents/agent-runner-marketplace.ts', ); const marketplaceInstallButtonSource = readSource( 'src/app/home/components/MarketplaceInstallButton.tsx', ); const marketplaceSource = readSource( 'src/app/home/knowledge/components/kb-form/knowledge-engine-marketplace.ts', ); const taskContextSource = readSource( 'src/app/home/plugins/components/plugin-install-task/PluginInstallTaskContext.tsx', ); const progressDialogSource = readSource( 'src/app/home/plugins/components/plugin-install-task/PluginInstallProgressDialog.tsx', ); const installedPluginsSource = readSource( 'src/app/home/plugins/components/plugin-installed/PluginInstalledComponent.tsx', ); const homeSidebarSource = readSource( 'src/app/home/components/home-sidebar/HomeSidebar.tsx', ); test('keeps the knowledge-base fields visible without an installed engine', () => { assert.match(kbFormSource, / { assert.match( marketplaceSource, /KNOWLEDGE_ENGINE_COMPONENT_FILTER = 'KnowledgeEngine'/, ); assert.match(marketplaceSource, /installPluginFromMarketplace\(/); assert.match(marketplaceSource, /getKnowledgeEngines\(\)/); assert.match(marketplaceSource, /sessionStorage\.setItem\(/); assert.match(selectSource, /resumePendingKnowledgeEngineInstall\(/); assert.match(selectSource, /onInstalled\(installed\)/); assert.match(selectSource, /component=KnowledgeEngine/); }); test('tracks plugin upgrades as recoverable multistep async tasks', () => { assert.match(taskContextSource, /name\.startsWith\('plugin-upgrade-'\)/); assert.match(taskContextSource, /operation: PluginTaskOperation/); assert.match(taskContextSource, /progress_percent/); assert.match(progressDialogSource, /InstallStage\.CHECKING/); assert.match(progressDialogSource, /InstallStage\.VALIDATING/); assert.match(progressDialogSource, /InstallStage\.ACTIVATING/); assert.match(progressDialogSource, /plugins\.installProgress\.updateTitle/); for (const source of [installedPluginsSource, homeSidebarSource]) { assert.match( source, /upgradePlugin\([\s\S]*?add(?:Plugin)?Task\([\s\S]*?operation: 'upgrade'/, ); assert.match( source, /pluginTaskKey\(res\.task_id, 'marketplace', 'upgrade'\)/, ); } }); test('keeps marketplace install actions on one fixed vertical column', () => { for (const source of [selectSource, agentRunnerSelectSource]) { assert.match(source, /grid-cols-\[1\.75rem_minmax\(0,1fr\)_4rem\]/); assert.match(source, / { assert.match(selectSource, /function SelectedEngineContent/); assert.match( selectSource, /selectedEngine \? \([\s\S]*? { for (const source of [selectSource, agentRunnerSelectSource]) { assert.match(source, /const handleInstall = useCallback/); assert.match(source, /installing=\{activePluginId === pluginId\}/); assert.match(source, /progress=\{installProgress\}/); assert.doesNotMatch(source, /MARKETPLACE_VALUE_PREFIX/); } assert.match(marketplaceInstallButtonSource, / { assert.match(agentRunnerMarketplaceSource, /installedPluginDescriptions/); assert.match(agentRunnerMarketplaceSource, /metadata\.description/); assert.match(agentRunnerSelectSource, /installedRunnerDescription\(/); assert.match( agentRunnerSelectSource, /function InstalledRunnerOptionContent/, ); assert.match(agentRunnerSelectSource, /marketplacePlugin\?\.description/); assert.match( agentRunnerSelectSource, /grid-cols-\[1\.75rem_minmax\(0,1fr\)\]/, ); assert.doesNotMatch(agentRunnerSelectSource, /description=\{option\.name\}/); });