-
Notifications
You must be signed in to change notification settings - Fork 3
feat: Implement shared IDE extension core module #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
packages/extension-core/__tests__/command-registry.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /** | ||
| * Command registry tests | ||
| * @fileoverview Tests for the command registry functionality | ||
| */ | ||
|
|
||
| import { CommandRegistryImpl } from "../src/core/command-registry"; | ||
| import { ExtensionEventEmitter } from "../src/events/event-emitter"; | ||
| import type { CommandDefinition } from "../src/types/index"; | ||
|
|
||
| describe("CommandRegistry", () => { | ||
| let commandRegistry: CommandRegistryImpl; | ||
| let eventEmitter: ExtensionEventEmitter; | ||
|
|
||
| beforeEach(() => { | ||
| eventEmitter = new ExtensionEventEmitter(); | ||
| commandRegistry = new CommandRegistryImpl(eventEmitter); | ||
| }); | ||
|
|
||
| describe("command registration", () => { | ||
| it("should register a command successfully", () => { | ||
| const command: CommandDefinition = { | ||
| id: "test.command", | ||
| title: "Test Command", | ||
| handler: jest.fn(), | ||
| }; | ||
|
|
||
| commandRegistry.registerCommand(command); | ||
|
|
||
| expect(commandRegistry.hasCommand("test.command")).toBe(true); | ||
| expect(commandRegistry.getCommands()).toHaveLength(1); | ||
| }); | ||
|
|
||
| it("should throw error for invalid command definition", () => { | ||
| const invalidCommand = { | ||
| title: "Invalid Command", | ||
| handler: jest.fn(), | ||
| } as CommandDefinition; | ||
|
|
||
| expect(() => commandRegistry.registerCommand(invalidCommand)).toThrow(); | ||
| }); | ||
|
|
||
| it("should unregister a command", () => { | ||
| const command: CommandDefinition = { | ||
| id: "test.command", | ||
| title: "Test Command", | ||
| handler: jest.fn(), | ||
| }; | ||
|
|
||
| commandRegistry.registerCommand(command); | ||
| expect(commandRegistry.hasCommand("test.command")).toBe(true); | ||
|
|
||
| commandRegistry.unregisterCommand("test.command"); | ||
| expect(commandRegistry.hasCommand("test.command")).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("command execution", () => { | ||
| it("should execute a registered command", async () => { | ||
| const mockHandler = jest.fn().mockResolvedValue("success"); | ||
| const command: CommandDefinition = { | ||
| id: "test.command", | ||
| title: "Test Command", | ||
| handler: mockHandler, | ||
| }; | ||
|
|
||
| commandRegistry.registerCommand(command); | ||
|
|
||
| const result = await commandRegistry.executeCommand("test.command", "arg1", "arg2"); | ||
|
|
||
| expect(mockHandler).toHaveBeenCalledWith("arg1", "arg2"); | ||
| expect(result).toBe("success"); | ||
| }); | ||
|
|
||
| it("should throw error for unregistered command", async () => { | ||
| await expect(commandRegistry.executeCommand("nonexistent.command")).rejects.toThrow( | ||
| "Command nonexistent.command is not registered", | ||
| ); | ||
| }); | ||
|
|
||
| it("should throw error for disabled command", async () => { | ||
| const command: CommandDefinition = { | ||
| id: "test.command", | ||
| title: "Test Command", | ||
| handler: jest.fn(), | ||
| enabled: false, | ||
| }; | ||
|
|
||
| commandRegistry.registerCommand(command); | ||
|
|
||
| await expect(commandRegistry.executeCommand("test.command")).rejects.toThrow( | ||
| "Command test.command is disabled", | ||
| ); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /** | ||
| * Extension core tests | ||
| * @fileoverview Tests for the main extension core functionality | ||
| */ | ||
|
|
||
| import { ExtensionCoreImpl, createExtensionCore } from "../src/core/extension-core"; | ||
|
|
||
| describe("ExtensionCore", () => { | ||
| let extensionCore: ExtensionCoreImpl; | ||
|
|
||
| beforeEach(() => { | ||
| extensionCore = new ExtensionCoreImpl(); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| if (extensionCore.isInitialized()) { | ||
| await extensionCore.dispose(); | ||
| } | ||
| }); | ||
|
|
||
| describe("initialization", () => { | ||
| it("should initialize successfully", async () => { | ||
| expect(extensionCore.isInitialized()).toBe(false); | ||
|
|
||
| await extensionCore.initialize(); | ||
|
|
||
| expect(extensionCore.isInitialized()).toBe(true); | ||
| }); | ||
|
|
||
| it("should not initialize twice", async () => { | ||
| await extensionCore.initialize(); | ||
|
|
||
| // Second initialization should not throw | ||
| await expect(extensionCore.initialize()).resolves.toBeUndefined(); | ||
| expect(extensionCore.isInitialized()).toBe(true); | ||
| }); | ||
|
|
||
| it("should provide access to all components", async () => { | ||
| await extensionCore.initialize(); | ||
|
|
||
| expect(extensionCore.getCommandRegistry()).toBeDefined(); | ||
| expect(extensionCore.getWorkspaceContextProvider()).toBeDefined(); | ||
| expect(extensionCore.getAICommandHandler()).toBeDefined(); | ||
| expect(extensionCore.getProgressStreamer()).toBeDefined(); | ||
| expect(extensionCore.getConfigurationManager()).toBeDefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("disposal", () => { | ||
| it("should dispose successfully", async () => { | ||
| await extensionCore.initialize(); | ||
| expect(extensionCore.isInitialized()).toBe(true); | ||
|
|
||
| await extensionCore.dispose(); | ||
| expect(extensionCore.isInitialized()).toBe(false); | ||
| }); | ||
|
|
||
| it("should handle disposal when not initialized", async () => { | ||
| expect(extensionCore.isInitialized()).toBe(false); | ||
|
|
||
| await expect(extensionCore.dispose()).resolves.toBeUndefined(); | ||
| }); | ||
| }); | ||
|
|
||
| describe("factory function", () => { | ||
| it("should create extension core instance", () => { | ||
| const core = createExtensionCore(); | ||
| expect(core).toBeInstanceOf(ExtensionCoreImpl); | ||
| expect(core.isInitialized()).toBe(false); | ||
| }); | ||
| }); | ||
| }); | ||
105 changes: 105 additions & 0 deletions
105
packages/extension-core/__tests__/progress-streamer.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /** | ||
| * Progress streamer tests | ||
| * @fileoverview Tests for the progress streaming functionality | ||
| */ | ||
|
|
||
| import { ProgressStreamerImpl } from "../src/core/progress-streamer"; | ||
| import { ExtensionEventEmitter } from "../src/events/event-emitter"; | ||
|
|
||
| describe("ProgressStreamer", () => { | ||
| let progressStreamer: ProgressStreamerImpl; | ||
| let eventEmitter: ExtensionEventEmitter; | ||
|
|
||
| beforeEach(() => { | ||
| eventEmitter = new ExtensionEventEmitter(); | ||
| progressStreamer = new ProgressStreamerImpl(eventEmitter); | ||
| }); | ||
|
|
||
| describe("progress stream management", () => { | ||
| it("should start a progress stream", () => { | ||
| const stream = progressStreamer.startProgress("test-op", "Test Operation"); | ||
|
|
||
| expect(stream.operationId).toBe("test-op"); | ||
| expect(stream.title).toBe("Test Operation"); | ||
| expect(stream.isActive()).toBe(true); | ||
| expect(progressStreamer.getProgress("test-op")).toBe(stream); | ||
| }); | ||
|
|
||
| it("should update progress", () => { | ||
| const stream = progressStreamer.startProgress("test-op", "Test Operation"); | ||
|
|
||
| stream.update({ | ||
| progress: 50, | ||
| message: "Half way done", | ||
| }); | ||
|
|
||
| const currentProgress = stream.getCurrentProgress(); | ||
| expect(currentProgress.progress).toBe(50); | ||
| expect(currentProgress.message).toBe("Half way done"); | ||
| }); | ||
|
|
||
| it("should complete progress", () => { | ||
| const stream = progressStreamer.startProgress("test-op", "Test Operation"); | ||
|
|
||
| stream.complete({ result: "success" }); | ||
|
|
||
| expect(stream.isActive()).toBe(false); | ||
| const currentProgress = stream.getCurrentProgress(); | ||
| expect(currentProgress.completed).toBe(true); | ||
| expect(currentProgress.result).toEqual({ result: "success" }); | ||
| }); | ||
|
|
||
| it("should fail progress", () => { | ||
| const stream = progressStreamer.startProgress("test-op", "Test Operation"); | ||
| const error = new Error("Test error"); | ||
|
|
||
| stream.fail(error); | ||
|
|
||
| expect(stream.isActive()).toBe(false); | ||
| const currentProgress = stream.getCurrentProgress(); | ||
| expect(currentProgress.completed).toBe(true); | ||
| expect(currentProgress.error).toBe("Test error"); | ||
| }); | ||
|
|
||
| it("should cancel progress", () => { | ||
| const stream = progressStreamer.startProgress("test-op", "Test Operation"); | ||
|
|
||
| stream.cancel(); | ||
|
|
||
| expect(stream.isActive()).toBe(false); | ||
| const currentProgress = stream.getCurrentProgress(); | ||
| expect(currentProgress.cancelled).toBe(true); | ||
| }); | ||
| }); | ||
|
|
||
| describe("stream collection management", () => { | ||
| it("should get active streams", () => { | ||
| const stream1 = progressStreamer.startProgress("op1", "Operation 1"); | ||
| const stream2 = progressStreamer.startProgress("op2", "Operation 2"); | ||
|
|
||
| expect(progressStreamer.getActiveStreams()).toHaveLength(2); | ||
|
|
||
| stream1.complete(); | ||
| expect(progressStreamer.getActiveStreams()).toHaveLength(1); | ||
| }); | ||
|
|
||
| it("should stop progress stream", () => { | ||
| const stream = progressStreamer.startProgress("test-op", "Test Operation"); | ||
| expect(stream.isActive()).toBe(true); | ||
|
|
||
| progressStreamer.stopProgress("test-op"); | ||
| expect(stream.isActive()).toBe(false); | ||
| expect(progressStreamer.getProgress("test-op")).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("should clear all streams", () => { | ||
| progressStreamer.startProgress("op1", "Operation 1"); | ||
| progressStreamer.startProgress("op2", "Operation 2"); | ||
|
|
||
| expect(progressStreamer.getActiveStreams()).toHaveLength(2); | ||
|
|
||
| progressStreamer.clearAllStreams(); | ||
| expect(progressStreamer.getActiveStreams()).toHaveLength(0); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import baseConfig from "../../eslint.config.mjs"; | ||
|
|
||
| export default [ | ||
| ...baseConfig, | ||
| { | ||
| files: ["**/*.ts"], | ||
| rules: { | ||
| // Extension-specific rules can be added here | ||
| }, | ||
| }, | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /** @type {import('jest').Config} */ | ||
| module.exports = { | ||
| preset: "ts-jest", | ||
| testEnvironment: "node", | ||
| roots: ["<rootDir>/src", "<rootDir>/__tests__"], | ||
| testMatch: ["**/__tests__/**/*.test.ts", "**/*.test.ts"], | ||
| collectCoverageFrom: ["src/**/*.ts", "!src/**/*.d.ts", "!src/index.ts"], | ||
| coverageDirectory: "coverage", | ||
| coverageReporters: ["text", "lcov", "html"], | ||
| setupFilesAfterEnv: ["../../jest.setup.js"], | ||
| moduleNameMapper: { | ||
| "^(\\.{1,2}/.*)\\.js$": "$1", | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "name": "@lighthouse-tooling/extension-core", | ||
| "version": "0.1.0", | ||
| "description": "Shared IDE extension core module for Lighthouse AI integration", | ||
| "main": "dist/index.js", | ||
| "types": "dist/index.d.ts", | ||
| "scripts": { | ||
| "build": "tsc -p tsconfig.build.json", | ||
| "test": "jest", | ||
| "test:watch": "jest --watch", | ||
| "test:coverage": "jest --coverage", | ||
| "lint": "eslint .", | ||
| "lint:fix": "eslint . --fix", | ||
| "format": "prettier --write .", | ||
| "format:check": "prettier --check .", | ||
| "clean": "rm -rf dist" | ||
| }, | ||
| "devDependencies": { | ||
| "jest": "^29.7.0", | ||
| "ts-jest": "^29.1.1", | ||
| "@types/jest": "^29.5.5", | ||
| "typescript": "^5.0.0" | ||
| }, | ||
| "dependencies": { | ||
| "@lighthouse-tooling/types": "workspace:*", | ||
| "@lighthouse-tooling/shared": "workspace:*", | ||
| "@lighthouse-tooling/sdk-wrapper": "workspace:*" | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Missing tests for error scenarios during initialization and disposal.
Add tests that cover error handling during ExtensionCore initialization and disposal, ensuring proper logging and propagation.