From b1fc211916b533ac011c0557588308bd54a5492a Mon Sep 17 00:00:00 2001 From: cflmy Date: Wed, 25 Nov 2026 11:51:56 +0800 Subject: [PATCH] ci: move the stale-Analysis assertion into a checked-in script The runner does not preserve shell quoting inside multiline YAML commands, so a single-quoted Python -c kept aborting the contract lane. Use a small checked-in tool instead; it appends one byte, runs the independent Observation consumer and fails the lane unless the stale artifact is rejected. --- .woodpecker/main.yml | 9 +---- tools/ci/assert_stale_analysis.py | 56 +++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 tools/ci/assert_stale_analysis.py diff --git a/.woodpecker/main.yml b/.woodpecker/main.yml index 9224de5..d07b483 100644 --- a/.woodpecker/main.yml +++ b/.woodpecker/main.yml @@ -29,14 +29,7 @@ steps: python3 tests/consumers/observation_consumer.py --snapshot --analysis /tmp/control-analysis.json /tmp/control-observation.json python3 tests/consumers/observation_consumer.py --validate-schema --analysis /tmp/control-analysis.json /tmp/control-events.jsonl - python3 tools/ci/verify_observation_stream.py /tmp/control-events.jsonl /tmp/control-observation.json - - | - set -eu - python3 -c 'import pathlib; p = pathlib.Path("/tmp/control-analysis.json"); pathlib.Path("/tmp/analysis-stale.json").write_bytes(p.read_bytes() + b" ")' - python3 tests/consumers/observation_consumer.py --analysis /tmp/analysis-stale.json /tmp/control-events.jsonl && { - echo "stale Analysis was accepted" >&2 - exit 1 - } - echo "stale Analysis rejected" + - python3 tools/ci/assert_stale_analysis.py /tmp/control-analysis.json /tmp/control-events.jsonl test: image: rust:1.100-bookworm diff --git a/tools/ci/assert_stale_analysis.py b/tools/ci/assert_stale_analysis.py new file mode 100644 index 0000000..2ab1a29 --- /dev/null +++ b/tools/ci/assert_stale_analysis.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +"""Assert that an Observation consumer rejects a drifted Analysis artifact. + +The CI contract lane must prove that stale Analysis bytes are not accepted by a +consumer. The check lives in a checked-in script because the CI runner does not +reliably preserve shell quoting inside multiline YAML commands. + +usage: assert_stale_analysis.py ANALYSIS EVENTS +""" +import pathlib +import subprocess +import sys +import tempfile + +ROOT = pathlib.Path(__file__).resolve().parents[2] + + +def main(argv): + if len(argv) != 3: + raise SystemExit("usage: assert_stale_analysis.py ANALYSIS EVENTS") + analysis_path = pathlib.Path(argv[1]) + events_path = pathlib.Path(argv[2]) + temporary = None + try: + with tempfile.NamedTemporaryFile( + prefix="marqdo-stale-", suffix=".json", delete=False + ) as handle: + handle.write(analysis_path.read_bytes() + b" ") + temporary = pathlib.Path(handle.name) + result = subprocess.run( + [ + sys.executable, + str(ROOT / "tests" / "consumers" / "observation_consumer.py"), + "--analysis", + str(temporary), + str(events_path), + ], + capture_output=True, + text=True, + check=False, + ) + if result.returncode == 0: + print("stale Analysis was accepted", file=sys.stderr) + return 1 + print("stale Analysis rejected") + return 0 + finally: + if temporary is not None: + try: + temporary.unlink() + except FileNotFoundError: + pass + + +if __name__ == "__main__": + sys.exit(main(sys.argv))