Skip to content

Expand test suite with unit and integration tests for core modules #12

Description

@dollfins

Description

The test suite (src/test/suite/extension.test.ts) currently contains only two basic tests:

  1. Extension loads and activates
  2. Commands are registered

There are no tests for the core diagnostic functionality, code actions, or report panel. This makes refactoring risky.

Required Test Coverage

Unit Tests for diagnostics.ts

  • Mock the Soroban Guard CLI and verify:
    • JSON output is parsed correctly into GuardResults
    • Findings are mapped to VS Code Diagnostic objects with correct severity
    • Severity mapping works for all levels (critical, high, medium, low, info)
    • CLI errors are handled gracefully
    • shouldScan() correctly filters files based on exclude patterns

Unit Tests for codeActions.ts

  • Mock diagnostics with various rule IDs
  • Verify correct code action is returned for each rule ID (A-01, A-04, O-01, R-01)
  • Verify workspace edits are constructed correctly

Unit Tests for statusBar.ts

  • Verify state transitions produce correct text and colors
  • Verify score display formatting

Integration Tests

  • Full end-to-end flow: activate extension → scan file → receive diagnostics → apply fix
  • Use a small Soroban contract fixture with known vulnerabilities

Implementation Notes

  • Use VS Code's mock APIs from @vscode/test-electron
  • Create test fixtures in src/test/fixtures/ directory
  • Use ts-mocha or ts-node for running TypeScript tests directly
  • Add a test:coverage script if possible

Acceptance Criteria

  • All diagnostic severity levels are tested
  • All code action rule IDs are tested
  • CLI error handling is tested
  • Exclude pattern logic is tested
  • Tests run as part of CI
  • Test coverage is at least 60% for core modules

Complexity

Medium — requires mocking VS Code APIs and CLI processes.

Points

150

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions