Skip to content

Tech debt: Improve test coverage to 90%+ #85

@andreasronge

Description

@andreasronge

Summary

Improve test coverage from 85.18% to 90%+ by adding edge case tests for Parser, Validator, and Context modules. This ensures better confidence in error paths and edge case handling.

Context

Architecture reference: docs/architecture.md - Error Messages for LLM Consumption
Dependencies: None
Related issues: None

Current State

Verified via mix test --cover:

  • Overall coverage: 85.18% (target: 90%)
  • Parser: 66.67% - Missing edge case tests for malformed input
  • Validator: 80.22% - Some validation paths untested
  • Context: 66.67% - Simple module, some paths untested

Other modules are well-covered:

  • PtcRunner: 100%
  • Schema: 94.12%
  • Sandbox: 87.50%
  • Interpreter: 84.62%
  • Operations: ~90%

Acceptance Criteria

  • Overall test coverage reaches 90%+
  • Parser module reaches 85%+ coverage
  • Validator module reaches 90%+ coverage
  • Context module reaches 85%+ coverage
  • All new tests catch real bugs (not just coverage padding)
  • Existing tests pass
  • No test duplication - tests should cover distinct scenarios

Implementation Hints

Files to modify:

  • test/ptc_runner/parser_test.exs - Add edge case tests (create if needed)
  • test/ptc_runner/validator_test.exs - Add validation path tests (create if needed)
  • test/ptc_runner/context_test.exs - Add context edge cases (create if needed)

Parser edge cases to test:

  • Non-string, non-map input (integer, list, nil)
  • Empty string input
  • Valid JSON but not a valid program structure
  • JSON with unexpected top-level keys

Validator edge cases to test:

  • Unknown operation with no close match (no typo suggestion)
  • Nested validation errors (error in nested expression)
  • Field type mismatches for each field type
  • Missing required fields for each operation type
  • Extra unexpected fields in operations

Context edge cases to test:

  • Get non-existent variable
  • Put and get with special characters in name
  • Tools map edge cases

Patterns to follow:

  • Existing tests in test/ptc_runner_test.exs for assertion style
  • Use descriptive test names that explain the scenario
  • Group related tests in describe blocks

Test Plan

Unit tests (the deliverable):

  • Parser: 5-8 new edge case tests
  • Validator: 8-12 new validation path tests
  • Context: 3-5 new edge case tests

Verification:

  • Run mix test --cover and verify 90%+ coverage
  • Ensure no test is trivial (each should catch a real potential bug)

Out of Scope

  • Refactoring existing tests
  • Adding tests for well-covered modules (Operations, Schema)
  • Performance testing
  • Integration or E2E tests

Notes from Review

  • Parser has no nesting limit, so "deeply nested JSON at max depth boundary" is not applicable
  • Some Validator type paths are dead code (custom validators bypass generic validation), but testing them is still valuable for completeness
  • Context new/2 default argument "miss" is an Elixir coverage quirk, not a real missed path

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-implementationIssue is approved and ready to implementtech-debtTechnical debt or refactoring

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions