Coverage for src/governed_harness/validators/base.py: 100%
32 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-12 16:06 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-12 16:06 +0000
1from __future__ import annotations
3from dataclasses import dataclass
4from pathlib import Path
5from typing import Protocol
7from governed_harness.configuration.models import ValidatorDefinition
8from governed_harness.domain.enums import ResultStatus
9from governed_harness.domain.models import (
10 CapabilityGrant,
11 ChangeSet,
12 Finding,
13 Provenance,
14 Task,
15 ToolInvocation,
16 ValidationResult,
17)
18from governed_harness.evidence.artifact_store import LocalArtifactStore
19from governed_harness.runtime.cancellation import CancellationToken
20from governed_harness.runtime.process_runner import SafeProcessRunner
23@dataclass(frozen=True)
24class ValidationContext:
25 execution_id: str
26 workspace: Path
27 task: Task
28 change_set: ChangeSet
29 definition: ValidatorDefinition
30 grants: list[CapabilityGrant]
31 artifact_store: LocalArtifactStore
32 process_runner: SafeProcessRunner
33 provenance: Provenance
34 cancellation: CancellationToken
35 max_output_bytes: int
36 # Unredacted diff exists only in memory for security checks. It must never be
37 # persisted as an artifact or event payload.
38 raw_diff: str | None = None
39 # Status of an unavailable mandatory validator (governance.applyProfilePolicies):
40 # missingTestCommand for a missing executable or Python module, missingTestScript for a
41 # missing package script. None keeps BLOCKED.
42 missing_command_status: ResultStatus | None = None
43 missing_script_status: ResultStatus | None = None
44 # verification.outputParsers: parse the output of a failing command validator into one
45 # located finding per reported problem (validators.parsers).
46 parse_output: bool = False
49@dataclass(frozen=True)
50class ValidatorOutput:
51 result: ValidationResult
52 findings: tuple[Finding, ...] = ()
53 tool_invocations: tuple[ToolInvocation, ...] = ()
56class Validator(Protocol):
57 validator_id: str
59 def execute(self, context: ValidationContext) -> ValidatorOutput:
60 """Run the validator on ``context`` and return its output."""