const test = require('node:test'); const assert = require('node:assert/strict'); const Module = require('node:module'); function createStatus(overrides = {}) { return { installed: true, executable: 'openclaude', launchCommand: 'openclaude --project-aware', terminalName: 'OpenClaude', shimEnabled: false, workspaceFolder: '/workspace/openclaude/very/long/path/example-project', workspaceSourceLabel: 'active editor workspace', launchCwd: '/workspace/openclaude/very/long/path/example-project', launchCwdLabel: '/workspace/openclaude/very/long/path/example-project', canLaunchInWorkspaceRoot: true, profileStatusLabel: 'Found', profileStatusHint: '/workspace/openclaude/very/long/path/example-project/.openclaude-profile.json', workspaceProfilePath: '/workspace/openclaude/very/long/path/example-project/.openclaude-profile.json', providerState: { label: 'Codex', detail: 'gpt-5.4', source: 'profile', }, providerSourceLabel: 'saved profile', ...overrides, }; } function loadExtension() { const extensionPath = require.resolve('./extension'); delete require.cache[extensionPath]; const originalLoad = Module._load; Module._load = function patchedLoad(request, parent, isMain) { if (request === 'vscode') { return { workspace: {}, window: {}, env: {}, commands: {}, Uri: { parse: value => value, file: value => value }, }; } return originalLoad.call(this, request, parent, isMain); }; try { return require('./extension'); } finally { Module._load = originalLoad; } } test('renderControlCenterHtml uses the OpenClaude wordmark, status rail, and warm action hierarchy', () => { const { renderControlCenterHtml } = loadExtension(); const html = renderControlCenterHtml(createStatus(), { nonce: 'test-nonce', platform: 'win32' }); assert.match(html, /OpenClaude<\/span>/); assert.match(html, /class="status-rail"/); assert.match(html, /\.sunset-gradient\s*\{/); assert.match(html, /class="action-button primary" id="launch"/); assert.match(html, /class="action-button secondary" id="launchRoot"/); assert.match( html, /title="\/workspace\/openclaude\/very\/long\/path\/example-project"[^>]*>\/workspace\/openclaude\/very\/long\/path\/example-project<\//, ); }); test('renderControlCenterHtml shows explicit disabled and empty states when workspace data is missing', () => { const { renderControlCenterHtml } = loadExtension(); const html = renderControlCenterHtml( createStatus({ workspaceFolder: null, workspaceSourceLabel: 'no workspace open', launchCwd: null, launchCwdLabel: 'VS Code default terminal cwd', canLaunchInWorkspaceRoot: false, profileStatusLabel: 'No workspace', profileStatusHint: 'Open a workspace folder to detect a saved profile', workspaceProfilePath: null, }), { nonce: 'test-nonce', platform: 'linux' }, ); assert.match( html, /class="action-button secondary" id="launchRoot"[^>]*disabled[^>]*>[\s\S]*Open a workspace folder to enable workspace-root launch/, ); assert.match(html, /No workspace profile yet/); assert.match(html, /Open a workspace folder to detect a saved profile/); assert.doesNotMatch(html, /id="openProfile"/); }); test('OpenClaudeControlCenterProvider.getHtml supplies a nonce to the redesigned renderer', () => { const { OpenClaudeControlCenterProvider } = loadExtension(); const provider = new OpenClaudeControlCenterProvider(); assert.doesNotThrow(() => provider.getHtml(createStatus())); const html = provider.getHtml(createStatus()); assert.match(html, /script-src 'nonce-[^']+'/); assert.match(html, /', workspaceSourceLabel: 'active workspace', launchCwdLabel: '">', profileStatusHint: '', workspaceProfilePath: '"/>', providerState: { label: 'Provider ">', detail: '', source: 'profile', }, }), { nonce: 'test-nonce', platform: 'linux' }, ); assert.match(html, /<img src=x onerror="boom\(\)">/); assert.match(html, /"\/><script>workspace\(\)<\/script>/); assert.match(html, /active <b>workspace<\/b>/); assert.match(html, /<svg onload="profile\(\)">/); assert.match(html, /Provider "><img src=x onerror="label\(\)">/); assert.match(html, /<script>provider-detail\(\)<\/script> · saved profile/); assert.doesNotMatch(html, /