Skip to content

test(plugins): comprehensive plugin system tests and improvements - #19

Merged
echobt merged 4 commits into
mainfrom
feature/plugin-system-improvements-and-tests
Feb 3, 2026
Merged

test(plugins): comprehensive plugin system tests and improvements#19
echobt merged 4 commits into
mainfrom
feature/plugin-system-improvements-and-tests

Conversation

@echobt

@echobtechobt commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR adds comprehensive tests for the Cortex plugin system to ensure everything works correctly and catches edge cases.

Changes

New Test Files

  • src/cortex-cli/src/plugin_cmd.rs: 1204 lines of tests for CLI commands
  • src/cortex-plugins/tests/edge_case_tests.rs: 1537 lines of edge case tests
  • src/cortex-plugins/tests/lifecycle_tests.rs: 1712 lines of lifecycle tests
  • src/cortex-plugins/tests/integration_tests.rs: 850 lines of integration tests

Test Coverage Areas

  1. CLI Command Tests (plugin_cmd.rs)

    • Plugin subcommand argument parsing (new, dev, build, validate, publish)
    • Validation functions (generate_manifest, generate_rust_code, generate_cargo_toml)
    • ValidationResult/ValidationIssue serialization
    • validate_capabilities and validate_permissions functions
  2. Edge Case Tests (edge_case_tests.rs)

    • Manifest edge cases (empty IDs, invalid semver, invalid characters, TOML syntax)
    • Registry SSRF protection (IPv4-mapped IPv6, cloud metadata endpoints, dangerous ports)
    • Directory traversal protection
    • Hook priority and execution order
    • Configuration edge cases
    • Error handling
  3. Lifecycle Tests (lifecycle_tests.rs)

    • Plugin discovery in various scenarios
    • Loading valid/invalid plugins
    • Initialization and shutdown
    • Hook registration and dispatch
    • Command registry
    • WASM runtime tests
  4. Integration Tests (integration_tests.rs)

    • SDK code generation
    • Hook system integration
    • Command registry operations
    • Plugin signing and verification
    • Manifest parsing

Security Audit Results

Security scans found no critical issues:

  • ✅ No hardcoded secrets or API keys
  • ✅ SSRF protection properly implemented
  • ✅ Directory traversal protection working
  • ✅ Proper certificate validation (default TLS settings)
  • ✅ All unsafe blocks have proper SAFETY comments
  • ✅ Input validation consistently applied

Minor Recommendations (non-blocking)

  • Consider adding blocklist for dangerous commands with wildcard permissions
  • Consider adding audit logging for security-sensitive operations

Test Results

All 274 tests pass:

  • 108 unit tests
  • 59 edge case tests
  • 78 lifecycle tests
  • 29 integration tests
cargo test -p cortex-plugins
running 108 tests ... ok
running 59 tests ... ok
running 78 tests ... ok
running 29 tests ... ok
test result: ok. 274 passed; 0 failed

Clippy

No warnings or errors.

Add tests covering:
- Malformed manifests (empty ID, invalid semver, bad TOML syntax)
- Invalid characters in plugin ID
- Permission and hook execution edge cases
- Hook priority ordering and abort/skip/continue behavior
- Registry SSRF protection (private IPs, metadata endpoints)
- Directory traversal protection
- Plugin registration/unregistration lifecycle
- Configuration edge cases (enable/disable, whitelist mode)
- Error handling and display messages
- Plugin state transitions
- Remote registry management
- Signing and checksum verification
59 tests pass covering error handling and boundary conditions.
- Add comprehensive lifecycle tests covering plugin discover → load → init → hook → shutdown flow
- Add tests for PluginManager creation, discovery, loading, and lifecycle management
- Add tests for WasmRuntime and WasmPlugin
- Add tests for PluginConfig settings
- Add tests for HookRegistry and HookDispatcher
- Add tests for EventBus and event subscription
- Add tests for PluginCommand and command registry
- Fix clippy warning: replace vec![] with array for constant case list
@greptile-apps

Copy link
Copy Markdown

Greptile Overview

Greptile Summary

Added comprehensive test coverage for the Cortex plugin system with 217+ new tests across three files covering the complete plugin lifecycle, edge cases, and CLI commands.

Key Changes

  • lifecycle_tests.rs (78 tests): Full lifecycle testing from discovery through shutdown, including plugin manager operations, registry functions, hook system with priority ordering, command registry, WASM runtime validation, and configuration management
  • edge_case_tests.rs (59 tests): Thorough edge case coverage including malformed manifest handling, invalid plugin ID validation, SSRF protection for cloud metadata endpoints and private IPs, directory traversal prevention, hook priority boundaries, error type conversions, and plugin signing
  • plugin_cmd.rs (80+ tests): CLI argument parsing validation for all plugin commands (new, dev, build, validate, publish), template generation verification, and validation result serialization

Test Quality

The tests follow consistent patterns with:

  • Mock implementations for isolated unit testing
  • Async test support using tokio::test
  • Comprehensive error condition testing
  • Security boundary validation (SSRF, path traversal)
  • Edge cases for system-reserved priorities and malformed inputs

All tests pass according to the PR description and use appropriate test helpers to avoid requiring actual WASM compilation.

Confidence Score: 5/5

  • Safe to merge - comprehensive test additions with no production code changes
  • All three files are new test files or test additions with no changes to production code. The tests are well-structured, follow existing patterns, cover critical security boundaries, and all pass according to the PR description. No runtime risks.
  • No files require special attention

Important Files Changed

FilenameOverview
src/cortex-plugins/tests/lifecycle_tests.rsNew comprehensive test file covering full plugin lifecycle (discover, load, init, hook, shutdown) with 78 tests for discovery, manager, registry, hooks, commands, errors, WASM runtime, and config
src/cortex-plugins/tests/edge_case_tests.rsNew edge case test file with 59 tests covering malformed manifests, invalid IDs, SSRF protection, directory traversal, hook priorities, error conversions, and plugin signing validation
src/cortex-cli/src/plugin_cmd.rsAdded 80+ tests for CLI argument parsing covering PluginNewArgs, PluginDevArgs, PluginBuildArgs, PluginValidateArgs, PluginPublishArgs, template generation, and validation serialization

Sequence Diagram

sequenceDiagram
participant User
participant PluginManager
participant PluginRegistry
participant Plugin
participant HookDispatcher
participant CommandRegistry
Note over User,CommandRegistry: Plugin Lifecycle: Discover → Load → Init → Hook → Shutdown
User->>PluginManager: discover()
PluginManager->>PluginManager: Search plugin directories
PluginManager->>PluginManager: Read plugin.toml manifests
PluginManager-->>User: List of discovered plugins
User->>PluginManager: discover_and_load()
PluginManager->>PluginManager: discover()
loop For each discovered plugin
PluginManager->>Plugin: new(manifest, path)
Plugin-->>PluginManager: Plugin instance
PluginManager->>PluginRegistry: register(plugin)
PluginRegistry-->>PluginManager: Registration result
end
PluginManager-->>User: Loaded plugins
User->>PluginManager: init_all()
PluginManager->>PluginRegistry: init_all()
loop For each registered plugin
PluginRegistry->>Plugin: init()
Plugin->>Plugin: Change state: Loaded → Active
Plugin-->>PluginRegistry: Init result
opt Plugin has hooks
Plugin->>HookDispatcher: Register hooks
end
opt Plugin has commands
Plugin->>CommandRegistry: Register commands
end
end
PluginRegistry-->>PluginManager: Init results
PluginManager-->>User: All plugins initialized
Note over User,CommandRegistry: Runtime: Hook Execution & Command Dispatch
User->>HookDispatcher: trigger_tool_execute_before(input)
HookDispatcher->>HookDispatcher: Sort hooks by priority
loop For each matching hook
HookDispatcher->>Plugin: execute_hook(input, output)
Plugin-->>HookDispatcher: HookResult (Continue/Abort/Skip/Replace)
alt HookResult is Abort or Skip
HookDispatcher-->>User: Early return
end
end
HookDispatcher-->>User: Final output
User->>CommandRegistry: execute(cmd_name, args)
CommandRegistry->>CommandRegistry: Lookup command
CommandRegistry->>Plugin: execute_command(name, args, ctx)
Plugin-->>CommandRegistry: Command result
CommandRegistry-->>User: Execution result
Note over User,CommandRegistry: Cleanup: Shutdown
User->>PluginManager: shutdown_all()
PluginManager->>PluginRegistry: shutdown_all()
loop For each active plugin
PluginRegistry->>Plugin: shutdown()
Plugin->>Plugin: Change state: Active → Unloaded
Plugin->>HookDispatcher: Unregister hooks
Plugin->>CommandRegistry: Unregister commands
Plugin-->>PluginRegistry: Shutdown result
end
PluginRegistry-->>PluginManager: Shutdown results
PluginManager-->>User: All plugins shutdown
Loading

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@echobtechobt changed the title test: Add comprehensive plugin system testsfeat(plugins): comprehensive plugin system tests and improvementsFeb 3, 2026
…system
- Add integration tests for SDK code generation (manifest, Rust, Cargo.toml, TypeScript)
- Add hook system integration tests (priority ordering, abort behavior, session hooks)
- Add command registry tests (categories, aliases, execution with args)
- Add plugin signing/checksum verification tests
- Add plugin context builder tests
- Add manifest parsing tests with all capabilities, WASM settings, dependencies, and hooks
- Add error handling tests for all error variants
- Add registry integration tests for plugin lifecycle
Total test count: 274 tests (108 unit + 59 edge case + 78 lifecycle + 29 integration)
@echobt
echobtforce-pushed the feature/plugin-system-improvements-and-tests branch from 8c6acb6 to 66e0e33CompareFebruary 3, 2026 19:56
@echobtechobt changed the title feat(plugins): comprehensive plugin system tests and improvementstest(plugins): comprehensive plugin system tests and improvementsFeb 3, 2026
@echobt
echobt merged commit d544e8a into mainFeb 3, 2026
31 of 38 checks passed
lahcenelhadi2001-a11y pushed a commit to lahcenelhadi2001-a11y/cortex that referenced this pull request Mar 9, 2026
fix: guard against non-iterable extensions in settings panel (fixesBaseIntelligence/bounty-challenge#21906)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@echobt