The pipeline · one command
noxfile.py
@nox.session(python=False)
def ci(session: nox.Session) -> None:
"""Static checks, spec lint, tests, report and security checks."""
started = time.monotonic() # history.json keeps the wall time up to the report
session.run("uv", "sync", "--locked", external=True)
# 1. Static checks
uv_run(session, "ruff", "check", ".")
uv_run(session, "ruff", "format", "--check", ".")
uv_run(session, "mypy")
uv_run(session, "lint-imports")
uv_run(session, "python", "-m", "tools.check_dashes")
# 2. Spec lint
uv_run(session, "python", "-m", "tools.check_spec")
# 3. Framework unit and contract tests
uv_run(session, "pytest", "framework_tests")
# 4. Bench suites on the simulator: one clean run, then one run per seeded bug (T12).
bench_seconds: list[str] = []
for tests in sorted(Path("benches").glob("*/tests")):
bench = tests.parent.name
bench_started = time.monotonic()
results = RESULTS_DIR / bench
shutil.rmtree(results, ignore_errors=True) # no stale results from an earlier run
shutil.rmtree(ARTIFACTS_DIR / bench, ignore_errors=True) # nor stale logs
run = ("pytest", "-n", "auto", str(tests), "--bench", bench, "--target", "sim")
uv_run(
session,
*run,
"--results",
str(results / "clean.json"),
"--artifacts",
str(ARTIFACTS_DIR / bench / "clean"),
)
# Failing tests are expected here, so exit code 1 is fine. Anything
# above 1 (interrupted, internal error, usage error, no tests) stops nox.
# tools.break_it reads the results and fails on a bug nobody caught.
bugs_key, bugs = bench_bugs(session, bench)
for bug in bugs:
uv_run(
session,
*run,
"--set",
f"{bugs_key}=[{bug}]",
"--results",
str(results / f"{bug}.json"),
"--artifacts",
str(ARTIFACTS_DIR / bench / bug),
success_codes=[0, 1],
)
uv_run(session, "python", "-m", "tools.break_it", "gate", bench, "--results", str(results))
bench_seconds += ["--bench-seconds", f"{bench}={time.monotonic() - bench_started:.1f}"]
# 5. Report data (STR, RTM, defect drafts, history.json, T13), then the site (T14).
# It prints the exit criteria of each clean run and one line per bug run.
uv_run(
session,
*("python", "-m", "tools.build_report"),
*("--report", str(REPORT_DIR), "--results", str(RESULTS_DIR)),
*("--nox-seconds", f"{time.monotonic() - started:.1f}", *bench_seconds),
)
# The pages, from the spec YAML and the report data (T14, ADR-028).
uv_run(
session,
*("python", "-m", "tools.build_site", "--out", str(BUILD_DIR)),
*("--report", str(REPORT_DIR), "--results", str(RESULTS_DIR)),
)
uv_run(session, "python", "-m", "tools.check_dashes", str(BUILD_DIR), str(REPORT_DIR))
# 6. Security checks: headers, page and script rules, links, secrets
uv_run(session, "python", "-m", "tools.check_security", str(BUILD_DIR))
uv_run(session, "python", "-m", "tools.check_links", str(BUILD_DIR))
# A placeholder fails a publishing run (VLAB_PUBLISH), other runs list them.
uv_run(session, "python", "-m", "tools.check_placeholders", str(BUILD_DIR))
gitleaks = gitleaks_binary()
flags = ("--redact", "--no-banner", "--exit-code", "1")
session.run(str(gitleaks), "git", *flags, ".", external=True)
session.run(str(gitleaks), "dir", *flags, str(BUILD_DIR), external=True)
session.run(str(gitleaks), "dir", *flags, str(REPORT_DIR), external=True)