Skip to content

livery.workshop._scope

livery.workshop._scope

Local check-leg scope marker and proved-branch lookup for coverage union.

Each check leg leaves its scope in fm-gate.json beside its trace (full, affected, nothing, or verified) so the leg's entries after the gate, and its timing row, know which suites ran. verified_branch reads the pull request branch whose proved rows cover the checked-out tree on main, so the coverage extension can carry over that branch's parts before Phase B6 moves coverage beside the proved row itself.

Classes:

Name Description
LegScope

What the gate ran on one check leg, as the marker the leg left says.

VerifiedBranch

The branch whose proved rows cover a tree, or why the record could not say.

Functions:

Name Description
write_marker

Leave the leg's scope, suites, label, and proving branch beside its trace.

leg_scope

Read what the gate ran on this leg from the marker it left at root.

verified_branch

Read which pull request branch's proved rows cover the checkout at root.

Attributes:

Name Type Description
MARKER
FULL
AFFECTED
NOTHING
VERIFIED
KNOWN

MARKER module-attribute

MARKER = 'fm-gate.json'

FULL module-attribute

FULL = 'full'

AFFECTED module-attribute

AFFECTED = 'affected'

NOTHING module-attribute

NOTHING = 'nothing'

VERIFIED module-attribute

VERIFIED = 'verified'

KNOWN module-attribute

LegScope dataclass

LegScope(scope: str, packages: tuple[str, ...] = (), leg: str = '', base_tree: str = '', branch: str = '')

What the gate ran on one check leg, as the marker the leg left says.

Attributes:

Name Type Description
scope str

What the gate ran: full, affected, nothing, verified, or unknown when no marker exists or it does not parse.

packages tuple[str, ...]

The paths of the suites a narrowed gate ran; empty for every other scope.

leg str

The label the leg's rows are keyed by (check-ubuntu-latest-3.14); empty when absent.

base_tree str

The tree a narrowed gate measured from; empty when absent.

branch str

The pull request branch whose proved rows satisfied a main push leg, when known; empty otherwise.

scope instance-attribute

scope: str

packages class-attribute instance-attribute

packages: tuple[str, ...] = ()

leg class-attribute instance-attribute

leg: str = ''

base_tree class-attribute instance-attribute

base_tree: str = ''

branch class-attribute instance-attribute

branch: str = ''

VerifiedBranch dataclass

VerifiedBranch(branch: str, reason: str = '')

The branch whose proved rows cover a tree, or why the record could not say.

Attributes:

Name Type Description
branch str

The pull request branch whose run proved the tree; empty when no branch proved it or the record could not be read.

reason str

Why the record decided nothing; empty when the record was read.

branch instance-attribute

branch: str

reason class-attribute instance-attribute

reason: str = ''

write_marker

write_marker(root: Path, scope: str, packages: tuple[str, ...] = (), *, leg: str = '', base_tree: str = '', branch: str = '') -> None

Leave the leg's scope, suites, label, and proving branch beside its trace.

Source code in packages/workshop/src/livery/workshop/_scope.py
def write_marker(
    root: Path,
    scope: str,
    packages: tuple[str, ...] = (),
    *,
    leg: str = "",
    base_tree: str = "",
    branch: str = "",
) -> None:
    """Leave the leg's scope, suites, label, and proving branch beside its trace."""
    payload: dict[str, object] = {
        "scope": scope,
        "packages": list(packages),
        "leg": leg,
        "base_tree": base_tree,
    }
    if branch:
        payload["branch"] = branch
    (root / MARKER).write_text(
        json.dumps(payload, sort_keys=True),
        encoding="utf-8",
    )

leg_scope

leg_scope(root: Path) -> LegScope

Read what the gate ran on this leg from the marker it left at root.

Source code in packages/workshop/src/livery/workshop/_scope.py
def leg_scope(root: Path) -> LegScope:
    """Read what the gate ran on this leg from the marker it left at *root*."""
    unknown = LegScope("unknown")
    path = root / MARKER
    if not path.is_file():
        return unknown
    try:
        loaded = json.loads(path.read_text("utf-8"))
    except (OSError, ValueError):
        return unknown
    if not isinstance(loaded, dict):
        return unknown
    return LegScope(
        scope=str(loaded.get("scope", "unknown")),
        packages=tuple(str(p) for p in loaded.get("packages", []) or []),
        leg=str(loaded.get("leg", "") or ""),
        base_tree=str(loaded.get("base_tree", "") or ""),
        branch=str(loaded.get("branch", "") or ""),
    )

verified_branch

verified_branch(root: Path) -> VerifiedBranch

Read which pull request branch's proved rows cover the checkout at root.

Source code in packages/workshop/src/livery/workshop/_scope.py
def verified_branch(root: Path) -> VerifiedBranch:
    """Read which pull request branch's proved rows cover the checkout at *root*."""
    from livery.workshop._proved import proving_branch

    marker = leg_scope(root)
    if marker.branch:
        return VerifiedBranch(marker.branch)
    branch, why = proving_branch(root)
    if why:
        return VerifiedBranch("", why)
    return VerifiedBranch(branch)