Skip to content

test: add PermissionError coverage for flight-plan create command #78

@pofallon

Description

@pofallon

Context

The maverick flight-plan create command (added in #40) now handles PermissionError from both Path.mkdir() and Path.write_text() with a Rich-formatted error message and exit code 1. However, no unit test was written to verify this behaviour.

Missing coverage

tests/unit/cli/commands/flight_plan/test_create.py has no test for:

  • Writing to a read-only output directory → expect exit code 1 + error message
  • Writing to a path where the file itself is not writable → expect exit code 1 + error message

Suggested fix

Add parametrized tests that mock Path.mkdir and Path.write_text to raise PermissionError and assert:

  1. Exit code is 1
  2. The error output contains a user-friendly message (not a raw traceback)
from unittest.mock import patch

def test_create_permission_error_on_mkdir(cli_runner, tmp_path):
    with patch("maverick.cli.commands.flight_plan.create.Path.mkdir", side_effect=PermissionError("denied")):
        result = cli_runner.invoke(flight_plan, ["create", "my-plan", "--output-dir", str(tmp_path)])
    assert result.exit_code == 1
    assert "Permission denied" in result.output or "permission" in result.output.lower()

Origin

Flagged during code review of branch 040-flight-plan-cli (spec compliance review, severity MEDIUM).

Metadata

Metadata

Assignees

No one assigned

    Labels

    tech-debtTechnical debt to address

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions