Skip to main content

judge.score

judge.score(spec, unit, candidate, *, base, python, timeout, out)

Judge a candidate module for unit against a base commit (spotregen score).

The unit as recorded at base (its evaluations, unit tests and consumers) is judged: the candidate replaces the module in a scratch worktree of base, the evaluations run, then the unit tests and the dependents, each in a fresh worktree. run.toml and the outputs of every step go into out. The result is the same for the same candidate, base commit, Python and pytest.

Parameters

Name Type Description Default
spec RegenSpec The loaded spec; its root is the repository. required
unit Unit The unit. required
candidate Path The module to judge. required
base str A revision of the repository, for example "HEAD". required
python Path | None Interpreter that runs pytest, or None for resolve_python. required
timeout float Seconds each pytest run and each dependent may take; positive and finite. required
out Path | None Run directory, or None for a new temporary directory. required

Returns

Name Type Description
int int 0 if accept accepts the candidate, 1 if not.

Raises

Name Type Description
ConfigurationError If timeout is not positive and finite, candidate is not a file or base is not a commit.
ExternalToolError If git is not installed.
SpecError If unit does not exist at base.

Examples

import subprocess
import sys
from pathlib import Path
from tempfile import TemporaryDirectory

from spotregen import load_spec, make_sample_repo, resolve_unit
from spotregen.judge import score

def git(root, *args):
    subprocess.run(
        ["git", "-c", "user.name=t", "-c", "user.email=t@example.org", *args],
        cwd=root, check=True, capture_output=True,
    )

with TemporaryDirectory() as tmp:
    root = make_sample_repo(Path(tmp) / "demo")
    git(root, "init", "-q")
    git(root, "add", ".")
    git(root, "commit", "-q", "-m", "init")
    spec = load_spec(root)
    unit = resolve_unit(spec, "core.calc")
    code = score(
        spec, unit, root / unit.path, base="HEAD", python=Path(sys.executable),
        timeout=60, out=Path(tmp) / "run",
    )
    print(code)
unit = "core.calc"
protocol = "score"
spotregen_version = "0.12.2"
started = "2026-11-25T00:07:45Z"
finished = "2026-11-25T00:07:46Z"
status = "completed"
accepted = true
rule = "accept/1"

[base]
commit = "28dfb08c1a89e1c679291b5cedb61bc3b508f8fe"

[tool]
python = "3.14.2"
pytest = "9.1.1"
packages_sha256 = "395585913c6acf994fc06f43629bbb27bd1c37d8ea2726aa68ea5037713bf37d"
scoring_timeout_s = 60

[inputs]
bundle_sha256 = "321ed6accb41cec1a1d5a5212d76e4238d591498dea4d22d9e00760344747478"
module_sha256 = "b2a0020e4c5cff711b643d4f8e5682ba96d8c9a3a498cf23fbf67eb6b62cc104"
allowed = []
allowed_sha256 = []
candidate_sha256 = "b2a0020e4c5cff711b643d4f8e5682ba96d8c9a3a498cf23fbf67eb6b62cc104"

[final]
attempt = 1
sha256 = "b2a0020e4c5cff711b643d4f8e5682ba96d8c9a3a498cf23fbf67eb6b62cc104"
unit_tests_passed = 0
unit_tests_failed = 0
unit_tests_errors = 0
dependents_passed = 1
dependents_failed = 0

[[attempt]]
n = 1
wrote_module = true
sha256 = "b2a0020e4c5cff711b643d4f8e5682ba96d8c9a3a498cf23fbf67eb6b62cc104"
evaluations_passed = 1
evaluations_failed = 0
evaluations_errors = 0

run directory: /private/var/folders/dw/pvtj6mt91znd0hftcztqb0k00000gn/T/tmpq_mjb90p/run
0