Skip to content

livery.extensions.coverage._leg

livery.extensions.coverage._leg

The check leg's half of coverage: each suite's parts, left for the leg's write.

A check leg's tests run measured. At the leg's end the coverage extension's entry, coverage.leg, first runs the suites no record can supply at their current closure, when the gate ran narrowed or skipped (top_up). Then it gathers the parts of every suite the leg ran (gather_leg): the parts a native suite's measurer left in the workspace, and the parts the listed reductions make of the data the run left, once for each suite, each holding the files of the suite's closure. It leaves them in the line format's stored form, with the fixed facts they name and the scope the leg measured, for the leg's one write, which puts them on the leg's per-run ref beside its timing row, and it prints each suite's size as a record stores it, what ran and its fixed facts, raw and gzipped, with the share of what ran that names the tests that reached each line.

Classes:

Name Description
CoverageUnit

One coverage record unit: either a package suite or a single test item.

Functions:

Name Description
expand_units

Expand selection = "on" suites into per-item units; keep others whole.

suites_of

The packages with a test directory: the units the record keys.

units_of

The recorded units: every package's suite, then the workspace's own tests.

own_tests

The workspace's own tests, as a unit a test step runs; none otherwise.

suites_that_ran

The units the leg ran, by its scope marker and its shard's record.

on_this_shard_units

units less those that did not run on this shard; all on one shard of one.

on_this_shard

units less those that did not run on this shard; all on one shard of one.

request

What a reduction is asked for unit: its tests' contexts and its closure.

request_for

What a reduction is asked for unit (package suite or single test item).

sizes

unit as a record stores it: its row's bytes, the tests' share, its facts'.

shown_sizes

unit's size as a line shows it: what ran, its fixed facts, the tests' share.

shown_size

count bytes as a line shows them: 1.3 MB, 412.0 KB.

gather_leg

Gather the parts of every suite the leg ran and leave them for its write.

unrecorded

Of units, those no record in bases can supply on this leg; each says why.

with_unstored_suites

subset plus every suite no record can supply for this leg.

top_up

Run the suites or items no record can supply on this leg; the measured scope.

Attributes:

Name Type Description
MEASURED

MEASURED module-attribute

MEASURED = 'measured'

CoverageUnit dataclass

CoverageUnit(path: str, owner: Package, item: bool = False, step: str = '')

One coverage record unit: either a package suite or a single test item.

Attributes:

Name Type Description
path str
owner Package
item bool
step str

path instance-attribute

path: str

owner instance-attribute

owner: Package

item class-attribute instance-attribute

item: bool = False

step class-attribute instance-attribute

step: str = ''

expand_units

expand_units(root: Path, units: Sequence[Package]) -> tuple[CoverageUnit, ...]

Expand selection = "on" suites into per-item units; keep others whole.

Source code in packages/extensions/coverage/src/livery/extensions/coverage/_leg.py
def expand_units(root: Path, units: Sequence[Package]) -> tuple[CoverageUnit, ...]:
    """Expand ``selection = "on"`` suites into per-item units; keep others whole."""
    from livery.extensions.coverage._parts import native
    from livery.workshop import TEST_ITEMS, answer

    needs_items = any(
        unit.test_selection == "on" and not native(unit) for unit in units
    )
    listers = answer(root, TEST_ITEMS) if needs_items else {}
    out: list[CoverageUnit] = []
    for unit in units:
        if unit.test_selection == "on" and not native(unit) and listers:
            expanded: list[CoverageUnit] = []
            seen: set[str] = set()
            for step_name, lister in sorted(listers.items()):
                for item in lister(unit):
                    if item not in seen:
                        seen.add(item)
                        expanded.append(
                            CoverageUnit(
                                path=item, owner=unit, item=True, step=step_name
                            )
                        )
            if expanded:
                out.extend(expanded)
                continue
        out.append(CoverageUnit(path=unit.path, owner=unit))
    return tuple(out)

suites_of

suites_of(packages: tuple[Package, ...]) -> tuple[Package, ...]

The packages with a test directory: the units the record keys.

Source code in packages/extensions/coverage/src/livery/extensions/coverage/_leg.py
def suites_of(packages: tuple[Package, ...]) -> tuple[Package, ...]:
    """The packages with a test directory: the units the record keys."""
    return tuple(
        package for package in packages if (package.directory / "tests").is_dir()
    )

units_of

units_of(root: Path, packages: tuple[Package, ...]) -> tuple[Package, ...]

The recorded units: every package's suite, then the workspace's own tests.

The workspace's own tests are a unit while a test step runs them (own_tests).

Source code in packages/extensions/coverage/src/livery/extensions/coverage/_leg.py
def units_of(root: Path, packages: tuple[Package, ...]) -> tuple[Package, ...]:
    """The recorded units: every package's suite, then the workspace's own tests.

    The workspace's own tests are a unit while a test step runs them
    (`own_tests`).
    """
    return suites_of(packages) + own_tests(root)

own_tests

own_tests(root: Path) -> tuple[Package, ...]

The workspace's own tests, as a unit a test step runs; none otherwise.

The unit (livery.workshop.workspace_suite) holds the root's set, and a test step runs it while that set holds an extension the step names (livery.workshop.tested), the rule the test step itself asks (livery.workshop.scoped_suite). A root whose set holds no such extension runs none of its own tests, so no leg leaves a part for them and no record holds them.

Source code in packages/extensions/coverage/src/livery/extensions/coverage/_leg.py
def own_tests(root: Path) -> tuple[Package, ...]:
    """The workspace's own tests, as a unit a test step runs; none otherwise.

    The unit ([livery.workshop.workspace_suite][]) holds the root's
    set, and a test step runs it while that set holds an extension the
    step names ([livery.workshop.tested][]), the rule the test step
    itself asks ([livery.workshop.scoped_suite][]). A root whose set
    holds no such extension runs none of its own tests, so no leg
    leaves a part for them and no record holds them.
    """
    from livery.workshop import tested, workspace_suite

    unit = workspace_suite(root)
    return tested((unit,)) if unit is not None else ()

suites_that_ran

suites_that_ran(marker: LegScope, root: Path, packages: tuple[Package, ...]) -> tuple[Package, ...]

The units the leg ran, by its scope marker and its shard's record.

Every suite after a full gate, the named packages' suites after a narrowed or a measured one, none after a skip; the workspace's own tests whenever any suite ran and a test step runs them (own_tests), since every leg that runs a suite runs them then. On a shard of a sharded leg, those among them with a test file in the shard's share (on_this_shard). The marker decides, never the data's contexts: a suite whose tests reach no line that collection had not already reached leaves no context of its own under a first-hit tracer, and still ran.

Source code in packages/extensions/coverage/src/livery/extensions/coverage/_leg.py
def suites_that_ran(
    marker: LegScope, root: Path, packages: tuple[Package, ...]
) -> tuple[Package, ...]:
    """The units the leg ran, by its scope marker and its shard's record.

    Every suite after a full gate, the named packages' suites after a
    narrowed or a measured one, none after a skip; the workspace's
    own tests whenever any suite ran and a test step runs them
    (`own_tests`), since every leg that runs a suite runs them then.
    On a shard of a sharded leg, those among them with a test file in
    the shard's share (`on_this_shard`). The marker decides, never the
    data's contexts: a suite whose tests reach no line that collection
    had not already reached leaves no context of its own under a
    first-hit tracer, and still ran.
    """
    scope = marker.scope
    if scope == "full":
        ran = suites_of(packages)
    elif scope in ("affected", MEASURED):
        named = set(marker.packages)
        ran = tuple(package for package in suites_of(packages) if package.path in named)
    else:
        return ()
    return on_this_shard(root, ran + own_tests(root))

on_this_shard_units

on_this_shard_units(root: Path, units: tuple[CoverageUnit, ...]) -> tuple[CoverageUnit, ...]

units less those that did not run on this shard; all on one shard of one.

Source code in packages/extensions/coverage/src/livery/extensions/coverage/_leg.py
def on_this_shard_units(
    root: Path, units: tuple[CoverageUnit, ...]
) -> tuple[CoverageUnit, ...]:
    """*units* less those that did not run on this shard; all on one shard of one."""
    from livery.workshop import read_shard

    record, why = read_shard(root)
    if why:
        fail(
            f"coverage: {why}; a sharded leg's parts are judged by the test files"
            " its shard ran, and this leg's record does not read"
        )
    if record is None or record.shard.count == 1:
        return units
    partitioned = set(record.suites)
    item_set = set(record.items)
    return tuple(
        unit
        for unit in units
        if (
            (
                unit.path in item_set
                if unit.item
                else any(_of_unit(unit.owner, name) for name in record.items)
            )
            if unit.owner.path in partitioned
            else record.shard.first
        )
    )

on_this_shard

on_this_shard(root: Path, units: tuple[Package, ...]) -> tuple[Package, ...]

units less those that did not run on this shard; all on one shard of one.

A sharded check leg's test step runs each suite's share of its test files and records them as the items it ran, with the suites it partitioned (livery.workshop.read_shard). A suite the record names ran here where a file of it is among the items; one with no file among them ran on another shard, whose parts the gate job folds in before the union reads. A suite the record does not name, a native suite with no python test file, ran whole on the first shard with every step that does not read the shard, so the first shard expects its parts and every other shard does not. Without a record, or on one shard of one, every unit ran whole here.

Raises:

Type Description
Failed

When the record does not read, naming why: a sharded leg's parts are judged by the files its shard ran.

Source code in packages/extensions/coverage/src/livery/extensions/coverage/_leg.py
def on_this_shard(root: Path, units: tuple[Package, ...]) -> tuple[Package, ...]:
    """*units* less those that did not run on this shard; all on one shard of one.

    A sharded check leg's test step runs each suite's share of its test
    files and records them as the items it ran, with the suites it
    partitioned ([livery.workshop.read_shard][]). A suite the record
    names ran here where a file of it is among the items; one with no
    file among them ran on another shard, whose parts the gate job
    folds in before the union reads. A suite the record does not name,
    a native suite with no python test file, ran whole on the first
    shard with every step that does not read the shard, so the first
    shard expects its parts and every other shard does not. Without a
    record, or on one shard of one, every unit ran whole here.

    Raises:
        Failed: When the record does not read, naming why: a sharded
            leg's parts are judged by the files its shard ran.
    """
    kept = on_this_shard_units(root, tuple(CoverageUnit(u.path, u) for u in units))
    return tuple(unit.owner for unit in kept)

request

request(packages: tuple[Package, ...], unit: Package) -> dict[str, Any]

What a reduction is asked for unit: its tests' contexts and its closure.

A package's own tests are the node ids under its tests/ directory, as the pytest extension's plugin names each test's context; the workspace's own tests are every node id under tests/, and their closure is every file.

Source code in packages/extensions/coverage/src/livery/extensions/coverage/_leg.py
def request(packages: tuple[Package, ...], unit: Package) -> dict[str, Any]:
    """What a reduction is asked for *unit*: its tests' contexts and its closure.

    A package's own tests are the node ids under its ``tests/``
    directory, as the pytest extension's plugin names each test's
    context; the workspace's own tests are every node id under
    ``tests/``, and their closure is every file.
    """
    from livery.extensions.coverage._record import closure

    if unit.path == WORKSPACE_TESTS:
        return {"unit": unit.path, "tests": f"{unit.path}/"}
    return {
        "unit": unit.path,
        "tests": f"{unit.path}/tests/",
        "within": [f"{member.path}/" for member in closure(packages, unit)],
    }

request_for

request_for(packages: tuple[Package, ...], unit: CoverageUnit) -> dict[str, Any]

What a reduction is asked for unit (package suite or single test item).

Source code in packages/extensions/coverage/src/livery/extensions/coverage/_leg.py
def request_for(packages: tuple[Package, ...], unit: CoverageUnit) -> dict[str, Any]:
    """What a reduction is asked for *unit* (package suite or single test item)."""
    if not unit.item:
        return request(packages, unit.owner)
    from livery.extensions.coverage._record import closure

    req: dict[str, Any] = {"unit": unit.path, "tests": f"{unit.path}::"}
    if unit.owner.path != WORKSPACE_TESTS:
        req["within"] = [f"{member.path}/" for member in closure(packages, unit.owner)]
    return req

sizes

sizes(unit: Unit) -> tuple[int, int, int, int, int, int]

unit as a record stores it: its row's bytes, the tests' share, its facts'.

Each raw, then gzipped at zlib's default level, the level git stores an object at: the row; what the tests that reached each line add to it, the row's size less its size without its parts' contexts and each file's reached; and the fixed facts, one file each as the record keeps them.

Source code in packages/extensions/coverage/src/livery/extensions/coverage/_leg.py
def sizes(unit: Unit) -> tuple[int, int, int, int, int, int]:
    """*unit* as a record stores it: its row's bytes, the tests' share, its facts'.

    Each raw, then gzipped at zlib's default level, the level git
    stores an object at: the row; what the tests that reached each
    line add to it, the row's size less its size without its parts'
    contexts and each file's ``reached``; and the fixed facts, one
    file each as the record keeps them.
    """
    row = json.dumps(list(unit.parts), sort_keys=True).encode("utf-8")
    bare = json.dumps(
        [_without_tests(part) for part in unit.parts], sort_keys=True
    ).encode("utf-8")
    packed = _gzipped(row)
    facts = [
        facts_text(unit.facts[name]).encode("utf-8")
        for name in unit.named
        if name in unit.facts
    ]
    return (
        len(row),
        packed,
        len(row) - len(bare),
        max(0, packed - _gzipped(bare)),
        sum(len(item) for item in facts),
        sum(_gzipped(item) for item in facts),
    )

shown_sizes

shown_sizes(unit: Unit) -> str

unit's size as a line shows it: what ran, its fixed facts, the tests' share.

Source code in packages/extensions/coverage/src/livery/extensions/coverage/_leg.py
def shown_sizes(unit: Unit) -> str:
    """*unit*'s size as a line shows it: what ran, its fixed facts, the tests' share."""
    row, packed, tests, tests_packed, facts, facts_packed = sizes(unit)
    share = (
        f"; the tests that reached each line take {shown_size(tests)} raw,"
        f" {shown_size(tests_packed)} gzipped of what ran"
        if tests
        else ""
    )
    return (
        f"{shown_size(row)} raw, {shown_size(packed)} gzipped, and its fixed facts"
        f" {shown_size(facts)} raw, {shown_size(facts_packed)} gzipped{share}"
    )

shown_size

shown_size(count: int) -> str

count bytes as a line shows them: 1.3 MB, 412.0 KB.

The unit is chosen on the rounded figure, so a size that rounds to a thousand kilobytes shows as 1.0 MB.

Source code in packages/extensions/coverage/src/livery/extensions/coverage/_leg.py
def shown_size(count: int) -> str:
    """*count* bytes as a line shows them: ``1.3 MB``, ``412.0 KB``.

    The unit is chosen on the rounded figure, so a size that rounds to
    a thousand kilobytes shows as ``1.0 MB``.
    """
    kilobytes = f"{count / 1_000:.1f}"
    if float(kilobytes) >= 1_000:
        return f"{count / 1_000_000:.1f} MB"
    return f"{kilobytes} KB"

gather_leg

gather_leg(root: Path, packages: tuple[Package, ...], *, marker: LegScope | None = None) -> None

Gather the parts of every suite the leg ran and leave them for its write.

The parts are the ones a native suite's measurer left in the workspace and the ones the listed reductions make of the data the run left, asked for every other suite the leg ran; each suite's parts hold the files of its closure, and they ride the leg's per-run ref under the suite's closure identity, with the scope the leg measured, its size printed raw and gzipped. marker is the scope the leg measured, the gate's own marker when absent. A leg whose gate skipped (a tree already proved, or nothing affected) ran no suite, says so, and leaves its scope alone, so the union knows the leg skipped rather than died. A workspace with no packages (a project just born) runs its own tests unmetered, and they reach no package source; that leg leaves its units with no parts, so the union finds what the leg ran. A suite that ran and has no part is named and left out, and the union names it again; a leg whose suites ran and has no part of any is red, since nothing was measured. Only a CI run leaves the parts.

Source code in packages/extensions/coverage/src/livery/extensions/coverage/_leg.py
def gather_leg(
    root: Path,
    packages: tuple[Package, ...],
    *,
    marker: LegScope | None = None,
) -> None:
    """Gather the parts of every suite the leg ran and leave them for its write.

    The parts are the ones a native suite's measurer left in the
    workspace and the ones the listed reductions make of the data the
    run left, asked for every other suite the leg ran; each suite's
    parts hold the files of its closure, and they ride the leg's
    per-run ref under the suite's closure identity, with the scope the
    leg measured, its size printed raw and gzipped. *marker* is the
    scope the leg measured, the gate's own marker when absent. A leg
    whose gate skipped (a tree already proved, or nothing affected)
    ran no suite, says so, and leaves its scope alone, so the union
    knows the leg skipped rather than died. A workspace with no
    packages (a project just born) runs its own tests unmetered, and
    they reach no package source; that leg leaves its units with no
    parts, so the union finds what the leg ran. A suite that ran and
    has no part is named and left out, and the union names it again;
    a leg whose suites ran and has no part of any is red, since nothing
    was measured. Only a CI run leaves the parts.
    """
    from livery.extensions.coverage._parts import native
    from livery.extensions.coverage._record import Unit, closure_id, unit_keys
    from livery.workshop import ci_run, leg_scope, read_ran_items

    marker = leg_scope(root) if marker is None else marker
    scope = marker.scope
    ran_state = read_ran_items(root)
    item_keys: dict[str, str] = dict(ran_state.skipped)
    if scope == "full":
        base_suites = suites_of(packages) + own_tests(root)
    elif scope in ("affected", MEASURED):
        named = set(marker.packages)
        base_suites = tuple(
            p for p in suites_of(packages) if p.path in named
        ) + own_tests(root)
    else:
        base_suites = ()
    expanded = (
        on_this_shard_units(root, expand_units(root, base_suites))
        if base_suites
        else ()
    )
    run = ci_run()
    if not expanded:
        print(f"  coverage: the gate ran {scope!r}; no suite ran, nothing to gather")
        _leave_leg(root, marker, {}, item_keys=item_keys)
        return
    ran = tuple(
        unit
        for unit in expanded
        if not (
            unit.item
            and unit.path in ran_state.skipped
            and unit.path not in ran_state.ran
        )
    )
    if not ran:
        print(
            f"  coverage: the gate ran {scope!r}; every item was proved, nothing to"
            " gather"
        )
        _leave_leg(root, marker, {}, item_keys=item_keys)
        return
    if not packages:
        # The workspace's own tests ran, unmetered, and reached no
        # package source: each unit the leg ran is left with no parts,
        # so the union finds what ran and judges nothing.
        print(
            "  coverage: the workspace has no packages to measure; its own"
            " tests ran unmetered"
        )
        empty: dict[str, Unit] = {}
        if run is not None:
            empty_keys = unit_keys(root, (), [u.owner for u in ran])
            for unit in ran:
                empty[unit.path] = Unit(
                    unit.path,
                    empty_keys[unit.path],
                    run.run_id,
                    git.head_sha(root),
                )
        _leave_leg(root, marker, empty)
        return
    by_unit: dict[str, list[Part]] = {}
    left = _left_parts(root)
    reduced = _reduced_parts(
        root, packages, [unit for unit in ran if not native(unit.owner)]
    )
    for part in (*left, *reduced):
        by_unit.setdefault(part.unit, []).append(part)
    if not any(by_unit.get(unit.path) for unit in ran):
        fail(
            f"this leg ran {scope!r} and no measurer left a part of any suite it"
            " ran: nothing was measured. A measurer leaves its parts while"
            " coverage is listed and it measures for coverage, so a leg that ran"
            " its suites and left none ran no measured suite, and there is"
            " nothing to union."
        )
    measured: dict[str, Unit] = {}
    pkg_units = [unit.owner for unit in ran if not unit.item]
    keys = (
        unit_keys(root, packages, pkg_units) if (run is not None and pkg_units) else {}
    )
    for unit in ran:
        parts = by_unit.get(unit.path)
        if not parts:
            print(
                f"  coverage store: {unit.path} ran without a measurement; nothing"
                " to store for it"
            )
            continue
        held = [_within(part, packages, unit.owner) for part in parts]
        if run is None:
            found = _stored_unit(held, unit.path, "", "", "")
            print(
                f"  coverage store: {unit.path} measured ({len(found.files)} files,"
                f" {shown_sizes(found)}); outside CI nothing is stored"
            )
            continue
        if unit.item:
            key = ran_state.ran.get(unit.path) or closure_id(root, packages, unit.owner)
            item_keys[unit.path] = key
        else:
            key = keys[unit.path]
        measured[unit.path] = _stored_unit(
            held, unit.path, key, run.run_id, git.head_sha(root)
        )
    if run is not None:
        _leave_leg(root, marker, measured, item_keys=item_keys)

unrecorded

unrecorded(root: Path, run: RunContext, packages: tuple[Package, ...], units: tuple[Package, ...], *, bases: tuple[str, ...]) -> tuple[Package, ...]

Of units, those no record in bases can supply on this leg; each says why.

One read per record. A unit a record holds at its current closure identity is supplied, the branch's record asked before main's; a unit every record lacks or holds at another closure, an unreadable record, a leg without a label, or a closure git cannot identify runs the suite fresh and says why, so the union never lacks a suite and the records need no backfill.

Source code in packages/extensions/coverage/src/livery/extensions/coverage/_leg.py
def unrecorded(
    root: Path,
    run: RunContext,
    packages: tuple[Package, ...],
    units: tuple[Package, ...],
    *,
    bases: tuple[str, ...],
) -> tuple[Package, ...]:
    """Of *units*, those no record in *bases* can supply on this leg; each says why.

    One read per record. A unit a record holds at its current closure
    identity is supplied, the branch's record asked before main's; a
    unit every record lacks or holds at another closure, an unreadable
    record, a leg without a label, or a closure git cannot identify
    runs the suite fresh and says why, so the union never lacks a
    suite and the records need no backfill.
    """
    from livery.extensions.coverage._record import closure_id
    from livery.workshop import proved_unit_keys

    if not units:
        return ()
    if not run.leg:
        for unit in units:
            print(
                f"  coverage store: {unit.path} runs, nothing to reuse (this leg"
                " has no label)"
            )
        return units
    held = _load_records(root, run, bases)
    proved_keys = proved_unit_keys(root, packages, [unit.path for unit in units])
    out: list[Package] = []
    for unit in units:
        try:
            key = proved_keys[unit.path] or closure_id(root, packages, unit)
        except git.GitError as error:
            print(
                f"  coverage store: {unit.path} runs, nothing to reuse (its closure"
                f" has no identity: {error})"
            )
            out.append(unit)
            continue
        states = _missing_states(held, bases, unit.path, key)
        if states is not None:
            print(
                f"  coverage store: {unit.path} runs, nothing to reuse (on this leg"
                f" {', '.join(states)})"
            )
            out.append(unit)
    return tuple(out)

with_unstored_suites

with_unstored_suites(root: Path, run: RunContext, packages: tuple[Package, ...], subset: tuple[Package, ...]) -> tuple[Package, ...]

subset plus every suite no record can supply for this leg.

A leg skips a suite only when its branch's record or main's holds the suite's parts at its current closure on this leg; the rest run fresh, and the line says why.

Source code in packages/extensions/coverage/src/livery/extensions/coverage/_leg.py
def with_unstored_suites(
    root: Path,
    run: RunContext,
    packages: tuple[Package, ...],
    subset: tuple[Package, ...],
) -> tuple[Package, ...]:
    """*subset* plus every suite no record can supply for this leg.

    A leg skips a suite only when its branch's record or main's holds
    the suite's parts at its current closure on this leg; the rest run
    fresh, and the line says why.
    """
    from livery.extensions.coverage._record import record_bases

    kept = {package.path for package in subset}
    skipped = tuple(
        package for package in suites_of(packages) if package.path not in kept
    )
    bases = record_bases("" if run.is_fork_pr else run.head_ref)
    extra = {
        unit.path for unit in unrecorded(root, run, packages, skipped, bases=bases)
    }
    if not extra:
        return subset
    # The workspace's own tests ride the subset as a unit of their own,
    # outside the packages, and stay in it.
    unit = tuple(package for package in subset if package.path == WORKSPACE_TESTS)
    return tuple(package for package in packages if package.path in kept | extra) + unit

top_up

top_up(root: Path, packages: tuple[Package, ...], marker: LegScope) -> LegScope

Run the suites or items no record can supply on this leg; the measured scope.

Inside CI alone, after the gate: a full gate ran every package suite (checking any live-skipped test items for missing coverage parts), and a machine's run has no record to read. A narrowed gate (affected) ran the suites its marker names, and every other suite (plus any live-skipped item of a ran suite) is asked of the branch's record and main's; a gate that judged nothing (nothing) asks the same of every suite; a gate that skipped a proved tree (verified) asks it of every unit a listed test step runs, the workspace's own tests among them, the record of the branch the verified row names first. Missing units run through the test phase's steps (livery.workshop.run_phase_over), measured, and the scope names them. A leg with nothing to run keeps its scope.

Source code in packages/extensions/coverage/src/livery/extensions/coverage/_leg.py
def top_up(root: Path, packages: tuple[Package, ...], marker: LegScope) -> LegScope:
    """Run the suites or items no record can supply on this leg; the measured scope.

    Inside CI alone, after the gate: a full gate ran every package suite
    (checking any live-skipped test items for missing coverage parts),
    and a machine's run has no record to read. A narrowed gate
    (``affected``) ran the suites its marker names, and every other
    suite (plus any live-skipped item of a ran suite) is asked of the
    branch's record and main's; a gate that judged nothing (``nothing``)
    asks the same of every suite; a gate that skipped a proved tree
    (``verified``) asks it of every unit a listed test step runs, the
    workspace's own tests among them, the record of the branch the
    verified row names first. Missing units run through the test phase's
    steps ([livery.workshop.run_phase_over][]), measured, and the scope
    names them. A leg with nothing to run keeps its scope.
    """
    from livery.workshop import ci_run, read_ran_items, record_ran_items, state_store

    run = ci_run()
    scope = marker.scope
    if run is None or scope not in ("full", "affected", "nothing", "verified"):
        return marker
    from livery.extensions.coverage._record import record_bases, record_prefixes
    from livery.git import remote_snapshot
    from livery.workshop import tested

    ran_state = read_ran_items(root)
    named = set(marker.packages)
    if scope == "full":
        if not ran_state.skipped:
            return marker
        expanded = expand_units(root, units_of(root, packages))
        item_candidates = tuple(
            unit
            for unit in expanded
            if unit.item
            and unit.path in ran_state.skipped
            and unit.path not in ran_state.ran
        )
        if not item_candidates:
            return marker
        pkg_candidates: tuple[Package, ...] = ()
        branch = marker.branch or run.head_ref
    elif scope == "verified":
        expanded = expand_units(root, tested(units_of(root, packages)))
        pkg_candidates = tuple(unit.owner for unit in expanded if not unit.item)
        item_candidates = tuple(unit for unit in expanded if unit.item)
        branch = _proving_branch(root)
    else:
        expanded = expand_units(root, units_of(root, packages))
        pkg_candidates = tuple(
            unit.owner
            for unit in expanded
            if not unit.item
            and unit.owner.path not in named
            and unit.owner.path != WORKSPACE_TESTS
        )
        item_candidates = tuple(
            unit
            for unit in expanded
            if unit.item
            and (
                unit.owner.path not in named
                or (unit.path in ran_state.skipped and unit.path not in ran_state.ran)
            )
        )
        branch = marker.branch or run.head_ref

    bases = record_bases("" if run.is_fork_pr else branch)
    missing_pkgs: tuple[Package, ...] = ()
    missing_items: list[CoverageUnit] = []
    with remote_snapshot(
        state_store(root),
        fetch=("proved/", *record_prefixes("" if run.is_fork_pr else branch)),
    ):
        missing_pkgs = unrecorded(root, run, packages, pkg_candidates, bases=bases)
        if item_candidates:
            if not run.leg:
                for unit in item_candidates:
                    print(
                        f"  coverage store: {unit.path} runs, nothing to reuse"
                        " (this leg has no label)"
                    )
                missing_items = list(item_candidates)
            else:
                held = _load_records(root, run, bases)
                proved_owners = (
                    frozenset()
                    if scope == "full"
                    else frozenset(
                        unit.owner.path
                        for unit in item_candidates
                        if unit.owner.path not in named
                    )
                )
                missing_items, carried_keys = _unrecorded_items(
                    root,
                    run,
                    item_candidates,
                    bases=bases,
                    known_keys=ran_state.skipped,
                    held=held,
                    packages=packages,
                    proved_owners=proved_owners,
                )
                if carried_keys:
                    record_ran_items(root, skipped=carried_keys)
    if not missing_pkgs and not missing_items:
        return marker
    import os

    from livery.workshop import NO_SELECT_VARIABLE, run_phase_over

    tests_by_pkg: dict[str, list[str]] = {}
    for unit in missing_items:
        tests_by_pkg.setdefault(unit.owner.path, []).append(unit.path)
    missing_paths = {pkg.path for pkg in missing_pkgs} | set(tests_by_pkg)
    target_pkgs = tuple(pkg for pkg in packages if pkg.path in missing_paths) + tuple(
        unit for unit in own_tests(root) if unit.path in missing_paths
    )
    names = ", ".join(
        [*(pkg.path for pkg in missing_pkgs), *(unit.path for unit in missing_items)]
    )
    proved = "; the gate is proved" if scope == "verified" else ""
    print(f"  measuring: {names} run for their lines alone{proved}")
    # Disable live per-item selection while measuring missing coverage parts so
    # an item proved green without a matching coverage part is not re-skipped.
    prior_no_select = os.environ.get(NO_SELECT_VARIABLE)
    os.environ[NO_SELECT_VARIABLE] = "1"
    try:
        if tests_by_pkg:
            run_phase_over(
                "test",
                target_pkgs,
                tests={path: tuple(items) for path, items in tests_by_pkg.items()},
            )
        else:
            run_phase_over("test", target_pkgs)
    finally:
        if prior_no_select is None:
            os.environ.pop(NO_SELECT_VARIABLE, None)
        else:
            os.environ[NO_SELECT_VARIABLE] = prior_no_select
    if scope == "full":
        return marker
    if scope == "affected":
        kept_paths = named | missing_paths
        ordered = tuple(pkg.path for pkg in packages if pkg.path in kept_paths) + tuple(
            unit.path for unit in own_tests(root) if unit.path in kept_paths
        )
        return replace(marker, packages=ordered)
    return replace(
        marker, scope=MEASURED, packages=tuple(pkg.path for pkg in target_pkgs)
    )