Skip to content

API Reference parrot.flows.dev_loop.test_scope.contract

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.flows.dev_loop.test_scope.contract

View source

## Validation Commands parsing and over-broad pytest detection (FEAT-563 M1/M9).

Attribute KNOWN_RUNNER_KINDS

Type: frozenset[str]

Alias RunnerContract

Re-exported from parrot.flows.dev_loop.test_scope.datatypes.RunnerContract.

Alias RunnerRegistry

Re-exported from parrot.flows.dev_loop.test_scope.runners.registry.RunnerRegistry.

Attribute SPEC_CONTRACT_HEADING

Type: str

Attribute TEST_CONTRACT_SCHEMA

Type: int

Alias TIERS

Re-exported from parrot.flows.dev_loop.test_scope.policy.TIERS.

Alias TestContract

Re-exported from parrot.flows.dev_loop.test_scope.datatypes.TestContract.

Attribute VALIDATION_HEADING

Type: str

Function contract_digest

Return a stable digest over the normalized schema-2 payload.

contract_digest(runners: Sequence[RunnerContract]) -> str

Parameter Type Default Description
runners Sequence[RunnerContract]

Returns: str

Function contract_from_index_header

Read the cached test_contract payload from an index header.

contract_from_index_header(header: Mapping[str, object], *, registry: 'RunnerRegistry | None' = None) -> TestContract | None

Parameter Type Default Description
header Mapping[str, object]
registry 'RunnerRegistry | None' None

Returns: TestContract | None

Raises:

  • ValueError — If a present payload has an invalid shape, schema, or digest.

Function contract_to_header

Always write schema 2 with normalized runner blocks.

contract_to_header(contract: TestContract) -> dict[str, object]

Parameter Type Default Description
contract TestContract

Returns: dict[str, object]

Function env_prefix_of

The leading POSIX simple-command NAME=value assignment tokens of argv, in order ([] if none).

env_prefix_of(argv: Sequence[str]) -> list[str]

Parameter Type Default Description
argv Sequence[str]

Returns: list[str]

Function is_broad_pytest

True for pytest with no path operand or an operand in {., tests, packages//tests} or a parent. Pass worktree so an absolute operand pointing at one of those same directories is also recognized (see _relativize).

is_broad_pytest(argv: Sequence[str], *, worktree: Path | None = None) -> bool

Parameter Type Default Description
argv Sequence[str]
worktree Path | None None

Returns: bool

Function is_pytest_invocation

True when argv is pytest ... / python[3] -m pytest ... (past env/uv run prefixes).

A declared ## Validation Commands entry that is NOT a pytest invocation at all (e.g. true or ruff check .) is silently invisible to plan_tests/is_broad_pytest — this lets a task (or a lint) tell the two apart from a command that IS pytest but simply narrow.

is_pytest_invocation(argv: Sequence[str]) -> bool

Parameter Type Default Description
argv Sequence[str]

Returns: bool

Function lift_schema1

Lift schema 1 to one pytest runner after validating its original digest.

lift_schema1(payload: Mapping[str, object]) -> TestContract

Parameter Type Default Description
payload Mapping[str, object]

Returns: TestContract

Function load_index_header

Read a per-spec index JSON and return it without its tasks member.

load_index_header(index_path: Path) -> dict[str, object]

Parameter Type Default Description
index_path Path

Returns: dict[str, object]

Raises:

  • ValueError — If the index cannot be read, decoded, or is not a JSON object.

Function normalize_pytest_argv

argv past any leading env-assignment and/or uv run [flags] launcher prefix.

normalize_pytest_argv(argv: Sequence[str]) -> list[str]

Parameter Type Default Description
argv Sequence[str]

Returns: list[str]

Function parse_spec_contract

Parse spec §4 ### Validation Contract.

parse_spec_contract(spec_md: str, *, registry: 'RunnerRegistry | None' = None) -> TestContract | None

Parameter Type Default Description
spec_md str
registry 'RunnerRegistry | None' None

Returns: TestContract | None — None for an explicit none — fallback contract.

Raises:

  • ValueError — If the subsection is missing or malformed.

Function parse_validation_commands

Backticked commands under '## Validation Commands' (bullets), shlex-split; [] when absent.

parse_validation_commands(task_md: str) -> list[list[str]]

Parameter Type Default Description
task_md str

Returns: list[list[str]]

Function strip_env_prefix

Drop leading POSIX simple-command NAME=value assignment tokens (e.g. PYTHONPATH=x pytest ...).

.claude/rules/worktree-management.md documents exactly this idiom for running pytest inside a worktree (PYTHONPATH=packages/ai-parrot/src pytest ...) — without this strip, the guard's argv[0]/seg[0] check never recognizes the command as pytest and silently allows it unscoped.

strip_env_prefix(argv: Sequence[str]) -> list[str]

Parameter Type Default Description
argv Sequence[str]

Returns: list[str]

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally