ci: move the stale-Analysis assertion into a checked-in script
ci/woodpecker/push/main Pipeline was successful

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.
This commit is contained in:
cflmy committed 2026-11-25 11:51:56 +08:00
1 parent 8473ac9827
commit b1fc211916
2 files changed
+57 -8

No files matched your search

+1 -8
View File
@@ -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
+56
View File
@@ -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))