From fe9705009662890f3b47cd5cca61c15bf281d4f2 Mon Sep 17 00:00:00 2001 From: Everton Fraga Date: Fri, 23 Oct 2026 01:00:26 -0400 Subject: [PATCH] ci: make the checks labelled REQ-PBT-002/004/008 check what they say MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three CI stages, and `lake test`, could pass without checking what they are labelled with: - REQ-PBT-008 validated the committed bench/results.csv, last written in May, so the check could only fail if someone edited that file. CI now runs bench/bench.sh (about 5 s; the old reason for skipping it, that b6_erc20 takes 10+ minutes, no longer holds) and validates the CSV it writes. The committed CSV is refreshed: its rows were stale (b3_token 9 obligations instead of 12, b5_escrow "error" instead of 9/9 passed). - REQ-PBT-004's pytest tests skip themselves when the binary or solc is missing, so the stage could pass with all 15 skipped. Under CI a skipped test now fails the run (Tools/Solidity/test/conftest.py). - REQ-PBT-002 (pipeline determinism) had a driver but no CI step. CI now runs it on its default fixture and on test/examples/b3_token.sol. - `lake test` replayed JsonOutputTest's cached result when only the fixtures it runs the binary on changed. lakefile.lean declares those fixtures as an input_dir of the test library, so a fixture change runs the tests again (checked: unchanged → replayed, fixture edited → built). Also corrects run_pbt_determinism.sh's stale notes (the wrapper no longer calls mktemp, and the pipeline has no Python or Ion stage), and README's CI step list. --- .github/workflows/ci.yml | 44 ++++++++++++------- README.md | 12 ++--- .../Solidity/run_pbt_determinism.sh | 20 ++++----- Tools/Solidity/test/conftest.py | 28 ++++++++++-- bench/results.csv | 12 ++--- lakefile.lean | 16 +++++-- 6 files changed, 86 insertions(+), 46 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26deca7..61c57f6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -174,25 +174,37 @@ jobs: LEAN_ABORT_ON_PANIC: '1' run: bash test/run_tests.sh - # ---- Stage 6 (schema-only): REQ-PBT-008 against committed CSV ---- - # bench/bench.sh itself is intentionally NOT run in CI: b6_erc20 - # routinely takes 10+ minutes locally, which is too slow for the - # hot path. The schema enforcer is run against the committed - # bench/results.csv so any drift in the CSV header or row shape - # (REQ-TEST-032..REQ-TEST-034) blocks the merge. - - name: bench/check_csv_schema.py (REQ-PBT-008, committed CSV) - run: python3 bench/check_csv_schema.py bench/results.csv - - # ---- Stage 7: SARIF 2.1.0 schema compliance (REQ-PBT-004) ---- - # The pytest fixture spawns strata-verify.sh --sarif against curated - # fixtures and validates the stdout against the vendored OASIS schema. - # Skipped automatically if the binary or solc are missing (the test - # prints a Skip with a reason); this stage fails only on a real - # schema violation. + # ---- Stage 6: REQ-PBT-008 benchmark CSV ---- + # Runs the benchmarks (about 5 s in total) and validates the CSV they + # write, so the schema check applies to the current binary's output, + # not only to the committed bench/results.csv. + - name: bench/bench.sh (REQ-PBT-008) + env: + LEAN_ABORT_ON_PANIC: '1' + run: bash bench/bench.sh + + # ---- Stage 7: SARIF 2.1.0 schema and verdicts (REQ-PBT-004) ---- + # The tests run strata-verify.sh --sarif on curated fixtures: they + # validate the output against the vendored OASIS schema and check + # that its verdicts, locations, fingerprints and counterexamples + # agree with the plain-text and --json output. A test skips itself + # when the binary or solc is missing; under CI a skipped test fails + # the run (Tools/Solidity/test/conftest.py), so this stage cannot + # pass without checking anything. - name: pytest Tools/Solidity/test (REQ-PBT-004 SARIF schema) env: LEAN_ABORT_ON_PANIC: '1' - run: python3 -m pytest Tools/Solidity/test -v + run: python3 -m pytest Tools/Solidity/test -v -rs + + # ---- Stage 7b: pipeline determinism (REQ-PBT-002) ---- + # Two --pipeline-json runs of the same fixture must agree on the + # Laurel and Core programs, the obligations and their statuses. + - name: pipeline determinism (REQ-PBT-002) + env: + LEAN_ABORT_ON_PANIC: '1' + run: | + lake run pbt-determinism + lake run pbt-determinism test/examples/b3_token.sol # ---- Stage 8: docs/site builds from current docs/guide/src ---- # Catches a broken template placeholder or a SUMMARY.md/file-name diff --git a/README.md b/README.md index 3eba160..7e6e30e 100644 --- a/README.md +++ b/README.md @@ -43,13 +43,13 @@ lake build 1. Checks out StrataSolidity with `submodules: recursive` so the Strata submodule is materialized at the recorded SHA 2. Verifies the submodule layout via `scripts/check-strata.sh` -3. Installs `solc` (via the `ethereum/ethereum` PPA) and the CI-only Python deps in `Tools/Solidity/requirements-dev.txt` -4. Runs `lake build` and `lake test` via [`leanprover/lean-action`](https://github.com/leanprover/lean-action), which handles elan install and caches the root `.lake`; Strata builds into `Strata/.lake`, which separate steps restore and save, keyed on the toolchain, the manifest and the submodule commit +3. Installs `solc` (via the `ethereum/ethereum` PPA), z3, and the CI-only Python deps in `Tools/Solidity/requirements-dev.txt` +4. Runs `lake build` and `lake test` via [`leanprover/lean-action`](https://github.com/leanprover/lean-action), which handles elan install and caches the root `.lake`; Strata builds into `Strata/.lake`, which separate steps restore and save, keyed on the toolchain, the manifest and the submodule commit. `lake test` runs the tests again when the binary or a fixture under `StrataSolidityTest/Solidity/tests` changes 5. Runs `test/run_tests.sh` (golden suite + REQ-PBT-007 exit-code sub-stage) -6. Runs `python3 bench/check_csv_schema.py bench/results.csv` (REQ-PBT-008 schema enforcer against the committed CSV) -7. Runs `python3 -m pytest Tools/Solidity/test` (REQ-PBT-004 SARIF 2.1.0 schema compliance) - -`bench/bench.sh` itself is intentionally not in the hot path (b6_erc20 is slow). +6. Runs `bench/bench.sh`, which validates the CSV it writes (REQ-PBT-008) +7. Runs `python3 -m pytest Tools/Solidity/test` (REQ-PBT-004 SARIF 2.1.0 schema and verdicts); a skipped test fails the run under CI +8. Runs the pipeline-determinism check twice (`lake run pbt-determinism`, REQ-PBT-002) +9. Builds the documentation site (`docs/site`) Lean panics are errors in CI. A `panic!` prints a message and continues with a default value, which in the verifier could mean a wrong verdict, so every diff --git a/StrataSolidityTest/Solidity/run_pbt_determinism.sh b/StrataSolidityTest/Solidity/run_pbt_determinism.sh index 64c35c6..e7d955f 100755 --- a/StrataSolidityTest/Solidity/run_pbt_determinism.sh +++ b/StrataSolidityTest/Solidity/run_pbt_determinism.sh @@ -16,20 +16,19 @@ # JSON outputs for informational evidence; any difference there is printed as # a warning, but only differences in the five structural fields fail the run. # -# Note — SMT field variance. The `obligations[*].smt` field embeds the -# `strata-verify.sh` temp-directory path in a `(set-info :file …)` annotation, -# which differs per run because `strata-verify.sh` calls `mktemp -d`. This is -# an incidental artifact of the shell wrapper, not a pipeline determinism -# violation, so REQ-PBT-002 deliberately excludes `smt` and `smtResult` from -# the determinism contract (see tasks.md task 2.3 and requirements.md §13). +# Note — SMT field. REQ-PBT-002 excludes `obligations[*].smt` and `smtResult` +# from the contract (see tasks.md task 2.3 and requirements.md §13). In +# practice the raw output is byte-equal too: `--pipeline-json` writes its SMT +# files to the same fixed directory on every run, so no per-run path ends up +# in them. # # Usage: # StrataSolidityTest/Solidity/run_pbt_determinism.sh [fixture.sol] # # If no fixture is given, defaults to # StrataSolidityTest/Solidity/tests/test_arithmetic.sol, a compact pass-only -# fixture that minimizes noise from VC status and exercises the full -# Python → Ion → Lean → Laurel → Core → SMT pipeline (REQ-PIPE-001..005). +# fixture that minimizes noise from VC status and exercises the whole +# pipeline (solc → Lean frontend → Laurel → Core → SMT). set -euo pipefail @@ -81,9 +80,8 @@ if cmp -s "$RUN_A" "$RUN_B"; then raw_equal=1 else echo "[warn] raw --pipeline-json output differs across runs" - echo " (diff below; expected to be confined to obligations[*].smt" - echo " which embeds the per-run strata-verify.sh TMPDIR and is NOT" - echo " part of the REQ-PBT-002 determinism contract)" + echo " (diff below; outside the REQ-PBT-002 contract only if it is" + echo " confined to obligations[*].smt)" diff -u "$RUN_A" "$RUN_B" || true raw_equal=0 fi diff --git a/Tools/Solidity/test/conftest.py b/Tools/Solidity/test/conftest.py index 8095240..387324a 100644 --- a/Tools/Solidity/test/conftest.py +++ b/Tools/Solidity/test/conftest.py @@ -4,8 +4,28 @@ """pytest configuration for the Tools/Solidity characterization tests. -Keeping this file empty (aside from the module docstring) is intentional: the -individual tests carry their own fixtures. Its presence lets pytest discover -this directory as a test package regardless of the invocation's working -directory. +The tests skip themselves when the `strataSolidity` binary or solc is +missing, which is convenient locally. Under CI (the `CI` environment +variable is set, as on GitHub Actions) a skipped test fails the run +instead: a CI stage whose tests all skipped would otherwise pass while +checking nothing. """ + +import os + +import pytest + + +def pytest_sessionfinish(session: pytest.Session, exitstatus: int) -> None: + if not os.environ.get("CI") or exitstatus != pytest.ExitCode.OK: + return + reporter = session.config.pluginmanager.get_plugin("terminalreporter") + skipped = len(reporter.stats.get("skipped", [])) if reporter else 0 + if skipped: + if reporter: + reporter.write_line( + f"error: {skipped} test(s) skipped under CI; " + "build strataSolidity and put solc and z3 on PATH", + red=True, + ) + session.exitstatus = pytest.ExitCode.TESTS_FAILED diff --git a/bench/results.csv b/bench/results.csv index 12c083c..0bccdac 100644 --- a/bench/results.csv +++ b/bench/results.csv @@ -1,7 +1,7 @@ benchmark,functions,specs,state_vars,mappings,status,time_ms,pass,fail,unknown,total -b1_trivial,2,1,1,0,ok,551,2,0,0,2 -b2_counter,2,7,2,0,ok,311,6,0,0,6 -b3_token,3,12,2,1,ok,330,9,0,0,9 -b4_vault,3,10,4,1,ok,329,8,0,0,8 -b5_escrow,4,14,5,0,error,197,0,0,0,0 -b6_erc20,4,16,5,3,ok,899061,14,0,0,14 +b1_trivial,2,1,1,0,ok,751,2,0,0,2 +b2_counter,2,7,2,0,ok,615,6,0,0,6 +b3_token,3,12,2,1,ok,714,12,0,0,12 +b4_vault,3,10,4,1,ok,642,8,0,0,8 +b5_escrow,4,14,5,0,ok,1018,9,0,0,9 +b6_erc20,4,16,5,3,ok,818,11,0,0,11 diff --git a/lakefile.lean b/lakefile.lean index 8582a6b..8ad71fa 100644 --- a/lakefile.lean +++ b/lakefile.lean @@ -12,11 +12,21 @@ require Strata from "Strata" @[default_target] lean_exe strataSolidity where root := `StrataSolidityMain +/-- The Solidity fixtures that `JsonOutputTest` runs the binary on. Lake does +not see the files a test reads while it runs; listing them here makes the +tests run again when a fixture changes, instead of replaying their cached +result. -/ +input_dir solidityTestFixtures where + path := "StrataSolidityTest/Solidity/tests" + text := true + filter := .extension "sol" + lean_lib StrataSolidityTest where globs := #[`StrataSolidityTest.+] - -- `JsonOutputTest` runs the binary: build it first, and run the tests - -- again whenever it changes (otherwise Lake replays their cached result). - needs := #[strataSolidity] + -- `JsonOutputTest` runs the binary on fixtures: build it first, and run + -- the tests again whenever the binary or a fixture changes (otherwise + -- Lake replays their cached result). + needs := #[strataSolidity, solidityTestFixtures] /-- Group A step 2: print a structural summary of the Lean-built Solidity DDM