fix: resolve TypeScript errors in test files

- claude-import-tui.test.ts: add proper mock for ExtensionCommandContext
  with all required properties using type assertions
- marketplace-discovery.test.ts: add explicit check for result.error
  before accessing it to satisfy strict null checking
This commit is contained in:
Jamie McGregor Nelson 2026-03-16 14:43:52 -04:00
parent c6e06f344b
commit d85f7b8d82
2 changed files with 48 additions and 14 deletions

View file

@ -14,6 +14,7 @@ import assert from 'node:assert';
import { existsSync, mkdtempSync, rmSync, writeFileSync, readFileSync, mkdirSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import type { ExtensionCommandContext } from '@gsd/pi-coding-agent';
import { runClaudeImportFlow, getClaudeSearchRoots, discoverClaudeSkills, discoverClaudePlugins } from '../claude-import.js';
import { getMarketplaceFixtures } from './marketplace-test-fixtures.js';
@ -40,14 +41,7 @@ interface MockUISelectCall {
}
function createMockContext(selections: string[]): {
ctx: {
ui: {
select: ReturnType<typeof mock.fn>;
notify: ReturnType<typeof mock.fn>;
};
waitForIdle: ReturnType<typeof mock.fn>;
reload: ReturnType<typeof mock.fn>;
};
ctx: ExtensionCommandContext;
selectCalls: MockUISelectCall[];
} {
const selectCalls: MockUISelectCall[] = [];
@ -64,16 +58,55 @@ function createMockContext(selections: string[]): {
const notifyMock = mock.fn();
// Create a mock that satisfies ExtensionCommandContext
// Using type assertion since we only use select, notify, waitForIdle, reload in the tests
const ctx = {
ui: {
select: selectMock,
notify: notifyMock,
confirm: async () => false,
input: async () => undefined,
onTerminalInput: () => () => {},
setStatus: () => {},
setWorkingMessage: () => {},
setWidget: () => {},
setFooter: () => {},
setHeader: () => {},
setTitle: () => {},
custom: async () => { throw new Error('Not implemented'); },
pasteToEditor: () => {},
setEditorText: () => {},
getEditorText: () => '',
editor: async () => undefined,
setEditorComponent: () => {},
theme: {},
getAllThemes: () => [],
getTheme: () => undefined,
setTheme: () => ({ success: false }),
getToolsExpanded: () => true,
setToolsExpanded: () => {},
},
hasUI: true,
cwd: process.cwd(),
sessionManager: {} as unknown,
modelRegistry: {} as unknown,
model: undefined,
isIdle: () => true,
abort: () => {},
hasPendingMessages: () => false,
shutdown: () => {},
getContextUsage: () => undefined,
compact: () => {},
getSystemPrompt: () => '',
waitForIdle: mock.fn(async () => {}),
newSession: async () => ({ cancelled: false }),
fork: async () => ({ cancelled: false }),
navigateTree: async () => ({ cancelled: false }),
switchSession: async () => ({ cancelled: false }),
reload: mock.fn(async () => {}),
};
} as unknown as ExtensionCommandContext;
return { ctx: ctx as unknown as Parameters<typeof runClaudeImportFlow>[0], selectCalls };
return { ctx, selectCalls };
}
// ============================================================================
@ -262,7 +295,7 @@ describe(
});
// Verify notification was called
const notifyCalls = (ctx.ui.notify as ReturnType<typeof mock.fn>).mock.calls;
const notifyCalls = (ctx.ui.notify as unknown as ReturnType<typeof mock.fn>).mock.calls;
assert.ok(notifyCalls.length > 0, 'Should have shown notification');
console.log('\nNotifications shown:');

View file

@ -15,7 +15,7 @@ import {
inspectPlugin,
discoverMarketplace,
resolvePluginRoot
} from '../marketplace-discovery';
} from '../marketplace-discovery.js';
import { getMarketplaceFixtures } from './marketplace-test-fixtures.js';
const fixtureSetup = getMarketplaceFixtures(import.meta.dirname);
@ -110,6 +110,7 @@ describe('inspectPlugin', { skip: skipReason }, () => {
it('should return error for non-existent plugin directory', () => {
const result = inspectPlugin('/tmp/nonexistent-plugin');
assert.strictEqual(result.status, 'error');
assert.ok(result.error !== undefined, 'error should be defined');
assert.ok(result.error.includes('not found'));
});
});
@ -121,7 +122,7 @@ describe('discoverMarketplace', { skip: skipReason }, () => {
assert.strictEqual(result.status, 'ok');
assert.strictEqual(result.pluginFormat, 'jamie-style');
assert.ok(result.plugins.length > 0);
assert.ok(result.plugins.every(p => p.status === 'ok'));
assert.ok(result.plugins.every((p: { status: string }) => p.status === 'ok'));
assert.strictEqual(result.summary.total, result.plugins.length);
assert.strictEqual(result.summary.ok, result.plugins.length);
@ -148,7 +149,7 @@ describe('discoverMarketplace', { skip: skipReason }, () => {
it('should inventory skills, agents, commands correctly', () => {
const result = discoverMarketplace(CLAUDE_SKILLS_PATH!);
const pythonPlugin = result.plugins.find(p => p.name === 'python3-development');
const pythonPlugin = result.plugins.find((p: { name: string }) => p.name === 'python3-development');
assert.ok(pythonPlugin !== undefined);
if (pythonPlugin) {