Skip to content

Commit 1e6cb7e

Browse files
authored
Release v0.4.0: Dynamic Plugin Support, OAuth/PKCE Authentication, Enhanced Validation & Test Coverage (#20) (#21)
* feat: add authentication scope management for API and provisioning keys * feat: refactor authentication scope management to use property accessors * feat: enhance API key and provisioning key validation with improved error handling and UI feedback * feat: update authentication handling to unify API and provisioning key fields with improved loading feedback * feat: implement UI updates and event listeners for authentication scope changes and proxy settings * feat: improve null safety and error handling in activity data processing and UI components * feat: implement PKCE authentication flow with code exchange for API key * feat: add OAuth app name constant for improved authorization flow clarity * test: add comprehensive authentication tests for OpenRouterService - Add PKCE auth code exchange tests - Add API key validation tests - Add provisioning key validation tests - Add network error handling tests - Use MockWebServer for realistic HTTP testing These tests verify the authentication flow and error handling that was refactored into helper classes. refactor: integrate helper classes into SetupWizardDialog - Replace inline PKCE logic with PkceAuthHandler (156 lines removed) - Replace inline error handling with SetupWizardErrorHandler - Replace PluginLogger calls with SetupWizardLogger - Replace magic numbers with SetupWizardConfig constants - Add proper cleanup in dispose() method This integration reduces SetupWizardDialog from 1,194 to 1,048 lines while improving maintainability and testability. refactor: extract PKCE, error handling, logging, and config from SetupWizardDialog - Extract PkceAuthHandler: 199-line dedicated OAuth/PKCE flow handler - Extract SetupWizardConfig: centralize magic numbers and configuration - Extract SetupWizardErrorHandler: standardize error handling with user-friendly messages - Extract SetupWizardLogger: provide controlled logging with different levels - Make OpenRouterService open and add baseUrlOverride for testability This refactoring reduces complexity and improves maintainability while maintaining all existing functionality. The original SetupWizardDialog will be updated to use these helpers in a follow-up commit. * feat: refactor endpoint methods in OpenRouterService for dynamic URL generation * feat: add key validation for current auth scope and centralized error messages * refactor: remove deprecated key validation methods and update endpoint logging * feat: update auth scope to REGULAR and enhance logging for PKCE exchange process * feat: synchronize authentication settings in OpenRouterSettingsPanel and enhance welcome notification formatting * feat: release version 0.4.0 with OAuth/PKCE authentication flow, enhanced key validation, and UI improvements * feat: implement settings migration for provisioning keys and update version to 0.4.0 * feat: implement dynamic plugin support with resource cleanup and lifecycle management feat: add dynamic plugin support with resource cleanup and lifecycle management * feat: refactor activity cost calculation and improve tooltip formatting in status bar * feat: enhance dynamic plugin support tests with mocked dependencies and improved cleanup verification
1 parent 2db9859 commit 1e6cb7e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+3816
-577
lines changed

CHANGELOG.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,97 @@ All notable changes to the OpenRouter IntelliJ Plugin will be documented in this
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.4.0] - 2025-12-22
9+
10+
### New Features
11+
12+
#### 🔄 Dynamic Plugin Support (NEW!)
13+
- **No Restart Required** - Install, update, and uninstall plugin without restarting IDE
14+
- **Disposable Services** - All 4 core services (ProxyService, OpenRouterService, SettingsService, GenerationTrackingService) implement Disposable
15+
- **PluginLifecycleListener** - Tracks plugin load/unload events with detailed logging
16+
- **Resource Cleanup** - Graceful shutdown of Jetty server (10s timeout), HTTP client connection pool, and async tasks
17+
- **State Persistence** - Settings and generation tracking data saved before plugin unload
18+
- **Memory Leak Prevention** - Proper cleanup prevents memory leaks and allows safe plugin reload
19+
- **IntelliJ Compliance** - Meets all dynamic plugin requirements and restrictions
20+
21+
#### 🔐 OAuth/PKCE Authentication Flow
22+
- **PKCE Authentication** - Implemented full PKCE (Proof Key for Code Exchange) authentication flow for secure API key generation
23+
- **OAuth Code Exchange** - Secure OAuth code exchange mechanism for API key creation
24+
- **PkceAuthHandler** - Dedicated 208-line OAuth/PKCE flow handler for improved security and maintainability
25+
- **OAuth App Integration** - Added OAuth app name constant for improved authorization flow clarity
26+
27+
#### 🔑 Authentication Scope Management
28+
- **Unified Authentication** - Unified API and provisioning key fields with improved loading feedback
29+
- **Scope Management** - Added authentication scope management for API and provisioning keys
30+
- **Property Accessors** - Refactored authentication scope management to use property accessors for better encapsulation
31+
- **Synchronized Settings** - Synchronized authentication settings across UI components for consistency
32+
33+
#### ✅ Enhanced Key Validation
34+
- **Comprehensive Validation** - Enhanced API key and provisioning key validation with improved error handling
35+
- **Scope-Aware Validation** - Added key validation for current authentication scope
36+
- **KeyValidator Utility** - Created 96-line KeyValidator utility for centralized validation logic
37+
- **Centralized Error Messages** - Created 145-line ErrorMessages utility for consistent user feedback
38+
39+
### Code Quality & Architecture
40+
41+
#### Setup Wizard Refactoring
42+
- **Extracted PkceAuthHandler** - 208-line dedicated OAuth/PKCE flow handler
43+
- **Extracted SetupWizardConfig** - 44-line centralized configuration constants
44+
- **Extracted SetupWizardErrorHandler** - 88-line standardized error handling with user-friendly messages
45+
- **Extracted SetupWizardLogger** - 79-line controlled logging with different levels
46+
- **Reduced Complexity** - Reduced SetupWizardDialog from 1,194 to 1,048 lines (146 lines removed)
47+
- **Improved Testability** - Made OpenRouterService open with baseUrlOverride for better testing
48+
49+
#### Service Layer Improvements
50+
- **Dynamic URL Generation** - Refactored endpoint methods in OpenRouterService for dynamic URL generation
51+
- **Enhanced Logging** - Updated auth scope to REGULAR and enhanced logging for PKCE exchange process
52+
- **Deprecated Method Removal** - Removed deprecated key validation methods and updated endpoint logging
53+
54+
#### UI/UX Enhancements
55+
- **Event Listeners** - Implemented UI updates and event listeners for authentication scope changes
56+
- **Null Safety** - Improved null safety and error handling in activity data processing and UI components
57+
- **Welcome Notification** - Enhanced welcome notification formatting for better user experience
58+
- **Proxy Settings** - Better proxy settings management and UI feedback
59+
60+
### Testing & Quality
61+
62+
#### Comprehensive Test Coverage
63+
- **Authentication Tests** - Added comprehensive authentication tests for OpenRouterService (312 lines)
64+
- **PKCE Tests** - PKCE auth code exchange tests with MockWebServer for realistic HTTP testing
65+
- **Validation Tests** - API key and provisioning key validation tests
66+
- **Network Error Tests** - Network error handling tests for robust error recovery
67+
- **Integration Tests** - Added OpenRouterConfigurableIntegrationTest (161 lines)
68+
- **Settings Panel Tests** - Enhanced OpenRouterSettingsPanelIntegrationTest and OpenRouterSettingsPanelUITest (243 lines)
69+
70+
### Technical Improvements
71+
72+
#### New Utility Classes
73+
- **OpenRouterConstants** - 140-line constants file for OpenRouter API configuration
74+
- **UIConstants** - 125-line constants file for UI configuration and magic numbers
75+
- **ErrorMessages** - 145-line centralized error message management
76+
- **KeyValidator** - 96-line validation utility for API and provisioning keys
77+
- **OkHttpExtensions** - Enhanced HTTP client extensions for better request handling
78+
- **OpenRouterRequestBuilder** - Improved request builder with better error handling
79+
80+
#### New Dynamic Plugin Support Files
81+
- **PluginLifecycleListener** - 72-line listener for plugin load/unload events
82+
- **DynamicPluginSupportTest** - 150-line test suite for dynamic plugin functionality
83+
- **DYNAMIC_PLUGIN_SUPPORT.md** - 150-line comprehensive documentation with troubleshooting guide
84+
85+
#### Refactoring & Cleanup
86+
- **Constants Extraction** - Replaced magic numbers with proper constants throughout codebase
87+
- **Helper Classes** - Extracted helper classes from SetupWizardDialog for better separation of concerns
88+
- **Improved Maintainability** - Better code organization and reduced method complexity
89+
- **Enhanced Error Handling** - Standardized error handling across all components
90+
- **Disposable Implementation** - All services properly implement Disposable for resource cleanup
91+
92+
### Statistics
93+
- **38+ files changed**
94+
- **3,800+ insertions(+), 550+ deletions(-)**
95+
- **Net change: +3,250+ lines**
96+
- **13 new files** - Utilities, handlers, listeners, tests, and documentation
97+
- **10 new files created** (utilities, handlers, tests)
98+
899
## [0.3.0] - 2025-12-05
9100

10101
### New Features

README.md

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# OpenRouter IntelliJ Plugin
22

33
[![JetBrains Plugin](https://img.shields.io/badge/JetBrains-Plugin-orange.svg)](https://plugins.jetbrains.com/plugin/28520)
4-
[![Version](https://img.shields.io/badge/version-0.3.0-blue.svg)](https://github.com/DimazzzZ/openrouter-intellij-plugin/releases)
4+
[![Version](https://img.shields.io/badge/version-0.4.0-blue.svg)](https://github.com/DimazzzZ/openrouter-intellij-plugin/releases)
55
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
66

77
An IntelliJ IDEA plugin for integrating with [OpenRouter.ai](https://openrouter.ai), providing access to 400+ AI models with usage monitoring, quota tracking, and seamless JetBrains AI Assistant integration.
@@ -10,14 +10,14 @@ An IntelliJ IDEA plugin for integrating with [OpenRouter.ai](https://openrouter.
1010

1111
- **🤖 AI Assistant Proxy** - Configurable local proxy server (ports 8880-8899 by default) with auto-start control and flexible port selection
1212
- **📊 Status Bar Widget** - Real-time usage display with comprehensive popup menu
13-
- **🔑 API Key Management** - Secure provisioning key support with automatic API key creation
13+
- **🔑 Flexible Authentication** - OAuth/PKCE or Provisioning Key support with secure credential storage
1414
- **📈 Usage Analytics** - Track token consumption, costs, and model performance
1515
- **🔴 Real-time Monitoring** - Live connection status with color-coded indicators
1616
- **📋 Statistics Popup** - Detailed usage analytics in modal dialog
1717
- **⚙️ Settings Panel** - Configuration with validation and testing
1818
- **🌐 OpenAI Compatibility** - Full OpenAI API compatibility layer for custom integrations
1919
- **🔒 Security** - Encrypted API key storage with localhost-only proxy access
20-
- **🧪 Comprehensive Testing** - 207+ tests covering unit, integration, and E2E scenarios
20+
- **🧪 Comprehensive Testing** - 475+ tests covering unit, integration, and E2E scenarios
2121
- **🛠️ Developer-Friendly** - Extensive documentation and debugging capabilities
2222
- **⭐ Favorite Models** - Quick access to your preferred AI models with advanced filtering:
2323
- Filter by provider (OpenAI, Anthropic, Google, Meta, etc.)
@@ -48,28 +48,23 @@ An IntelliJ IDEA plugin for integrating with [OpenRouter.ai](https://openrouter.
4848
When you first install the plugin, a **welcome notification** will appear with a "Quick Setup" button. This launches a step-by-step wizard that guides you through:
4949

5050
1. **Welcome** - Introduction to OpenRouter and what you'll need
51-
2. **Provisioning Key** - Add and automatically validate your key from [OpenRouter](https://openrouter.ai/settings/provisioning-keys)
51+
2. **Authentication** - Choose your authentication method:
52+
- **Regular API Key** - OAuth/PKCE flow (one-click browser authorization)
53+
- **Provisioning Key** - Extended mode with full monitoring capabilities
5254
3. **Favorite Models** - Select your preferred models with embedded search and filtering
5355
4. **Completion** - Copy proxy server URL and configure AI Assistant
5456

55-
**New in v0.2.0+:**
56-
- ✅ Automatic provisioning key validation with visual feedback
57-
- ✅ Embedded model selection UI with real-time search
58-
- ✅ Smart button states (Next/Finish only enabled when ready)
59-
- ✅ Polished layout with proper spacing and typography
60-
- ✅ Back button navigation between steps
61-
6257
The wizard makes setup quick and easy, especially for first-time users!
6358

6459
### Manual Setup
6560

66-
1. **Get Provisioning Key**: Visit [OpenRouter Provisioning Keys](https://openrouter.ai/settings/provisioning-keys)
67-
2. **Configure**: `Settings``Tools``OpenRouter` → Enter Provisioning Key
61+
1. **Open Settings**: `Settings``Tools``OpenRouter`
62+
2. **Choose Authentication Method**:
63+
- **Regular API Key**: Click "Connect to OpenRouter" for OAuth/PKCE browser authorization
64+
- **Provisioning Key**: Get from [OpenRouter Provisioning Keys](https://openrouter.ai/settings/provisioning-keys) and paste
6865
3. **Select Models**: `Settings``Tools``OpenRouter``Favorite Models` → Choose your models
6966
4. **Start Using**: Click status bar widget to access features
7067

71-
The plugin automatically creates and configures an API key when you provide a provisioning key.
72-
7368
## 🤖 AI Assistant Integration
7469

7570
**NEW**: Connect JetBrains AI Assistant to OpenRouter's 400+ AI models using the plugin's local proxy server!
@@ -79,19 +74,20 @@ The plugin automatically creates and configures an API key when you provide a pr
7974
2. **Configure Proxy Server**: Auto-start is disabled by default - manually start via Settings or enable auto-start
8075
3. **Configure AI Assistant**: Settings → Tools → AI Assistant → Models → Add custom model
8176
- **Provider**: Custom
82-
- **Server URL**: Copy from OpenRouter settings (e.g., `http://127.0.0.1:8080`)
77+
- **Server URL**: Copy from OpenRouter settings (e.g., `http://127.0.0.1:8880`)
8378
- **API Key**: Any text (not validated by proxy)
8479
- **Model**: Choose from OpenRouter's model catalog
8580
4. **Start Using**: Access 400+ models through AI Assistant
8681

8782
📖 **[Complete Setup Guide](docs/AI_ASSISTANT_SETUP.md)** - Step-by-step instructions with screenshot placeholders
8883

8984
### Supported Models
90-
- **OpenAI**: GPT-4, GPT-4 Turbo, GPT-3.5 Turbo
91-
- **Anthropic**: Claude 3 Opus, Claude 3 Sonnet, Claude 3 Haiku
92-
- **Meta**: Llama 2 70B, Code Llama
93-
- **Google**: Gemini Pro, PaLM 2
94-
- **Mistral**: Mistral 7B, Mixtral 8x7B
85+
- **OpenAI**: GPT-4o, GPT-4 Turbo, o1, o3-mini
86+
- **Anthropic**: Claude 3.5 Sonnet, Claude 3 Opus, Claude 3 Haiku
87+
- **Meta**: Llama 3.3, Llama 3.1, Code Llama
88+
- **Google**: Gemini 2.0 Flash, Gemini 1.5 Pro
89+
- **Mistral**: Mistral Large, Mixtral 8x22B
90+
- **DeepSeek**: DeepSeek V3, DeepSeek R1
9591
- **And 390+ more models from 40+ providers!**
9692

9793
### Benefits
@@ -142,23 +138,18 @@ proxyPortRangeEnd = 8899 // Range end for auto-selection
142138
- **Settings Management** - Encrypted credential storage with validation
143139
- **Status Bar Integration** - Real-time monitoring with minimal UI footprint
144140

145-
### API Key Handling
146-
The plugin uses a sophisticated API key management system:
147-
- **Provisioning Keys** - Primary authentication for quota/usage data
148-
- **API Keys** - Automatically created for chat completions
141+
### Authentication Methods
142+
The plugin supports two authentication methods:
143+
- **Regular API Key** (OAuth/PKCE) - One-click browser authorization, minimal permissions, no usage monitoring
144+
- **Provisioning Key** (Extended) - Full functionality with quota tracking, usage monitoring, and API key management
149145
- **Security** - All keys encrypted using IntelliJ's credential store
150146
- **Validation** - Real-time key testing and status verification
151147

152-
### Recent Fixes
153-
- **401 Error Resolution** - Fixed API key handling to use settings instead of Authorization headers
154-
- **Model Name Compatibility** - Updated to use full OpenRouter model names (e.g., `openai/gpt-4-turbo`)
155-
- **Security Cleanup** - Removed all real API keys from codebase and documentation
156-
157148
## Compatibility
158149

159150
**Supported IDEs**: IntelliJ IDEA, WebStorm, PyCharm, PhpStorm, RubyMine, CLion, Android Studio, GoLand, Rider
160-
**IDE Versions**: 2023.2+ to 2025.3+
161-
**Requirements**: OpenRouter.ai account with Provisioning Key
151+
**IDE Versions**: 2024.1+ to 2025.3+
152+
**Requirements**: OpenRouter.ai account (free or paid)
162153

163154
## Development
164155

@@ -173,7 +164,7 @@ cd openrouter-intellij-plugin
173164

174165
### Testing
175166
```bash
176-
# Run all tests (207+ tests)
167+
# Run all tests (475+ tests)
177168
./gradlew test
178169

179170
# Run core functionality tests only
@@ -183,13 +174,36 @@ cd openrouter-intellij-plugin
183174
./gradlew runIde --no-daemon
184175
```
185176

186-
**Test Coverage**:
187-
- **Unit Tests** - 109 tests covering data models, settings, and business logic
188-
- **Integration Tests** - 50+ tests for API key handling and proxy server functionality
189-
- **Request Builder Tests** - 12 tests validating refactored HTTP request construction
190-
- **Favorite Models Tests** - 11 tests for favorite models management
191-
- **Security Tests** - Comprehensive validation of API key handling and encryption
192-
- **Total** - 207+ tests with 100% pass rate
177+
### Testing Dynamic Plugin Support
178+
179+
The plugin supports installation, updates, and uninstallation **without IDE restart** (dynamic plugin).
180+
181+
**Quick Test** (Enable/Disable):
182+
```bash
183+
# Start development IDE and test enable/disable
184+
./scripts/test-enable-disable.sh
185+
186+
# In the IDE: Settings → Plugins → Toggle OpenRouter OFF/ON
187+
# Should work without restart ✅
188+
```
189+
190+
**Full Test** (Multiple Versions):
191+
```bash
192+
# Build 3 test versions (0.4.0, 0.4.1, 0.4.2)
193+
./scripts/build-test-versions.sh
194+
195+
# Install v0.4.0 (may require restart on first install)
196+
# Update to v0.4.1 (should NOT require restart)
197+
# Update to v0.4.2 (should NOT require restart)
198+
```
199+
200+
See [LOCAL_DYNAMIC_PLUGIN_TESTING.md](docs/LOCAL_DYNAMIC_PLUGIN_TESTING.md) for detailed testing instructions.
201+
202+
**Test Coverage**: 475+ tests with 100% pass rate
203+
- Unit tests for data models, settings, and business logic
204+
- Integration tests for API key handling and proxy server functionality
205+
- Authentication tests with MockWebServer for realistic HTTP testing
206+
- Security tests for API key handling and encryption
193207

194208
For detailed testing information, see [TESTING.md](TESTING.md).
195209

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ tasks {
114114
systemProperty("java.awt.headless", "true")
115115
jvmArgs = listOf(
116116
"-Dnet.bytebuddy.experimental=true", // For Mockito Java 21+ compatibility
117-
"--add-opens=java.base/java.lang=ALL-UNNAMED", // For Java 25 compatibility
117+
"--add-opens=java.base/java.lang=ALL-UNNAMED",
118118
"--add-opens=java.base/java.util=ALL-UNNAMED"
119119
)
120120
testLogging {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
pluginGroup = org.zhavoronkov
44
pluginName = OpenRouter
55
pluginRepositoryUrl = https://github.com/DimazzzZ/openrouter-intellij-plugin
6-
pluginVersion = 0.3.0
6+
pluginVersion = 0.4.0
77

88
# Plugin metadata
99
pluginId = org.zhavoronkov.openrouter

0 commit comments

Comments
 (0)