diff --git a/scripts/ops/hermes_triage_demo.sh b/scripts/ops/hermes_triage_demo.sh index 5990869c9..042ad60f8 100755 --- a/scripts/ops/hermes_triage_demo.sh +++ b/scripts/ops/hermes_triage_demo.sh @@ -147,13 +147,35 @@ for b in json.load(sys.stdin): done fi + # The code demo seeds its defect by pushing to master, and the fix only lands + # if someone merges the pull request. A demo that ended without a merge - the + # usual case, since the point is that nothing merges itself - leaves master + # broken, and the next run aborts on "defect already present". Reset has to + # undo the seed rather than just report it, or the second demo of the day + # fails before it starts. if [ -d "$CODE_REPO_DIR/.git" ]; then note "restoring the demo repository working state" - ( cd "$CODE_REPO_DIR" && git checkout -q master && git pull -q --ff-only 2>/dev/null || true ) + ( cd "$CODE_REPO_DIR" && git checkout -q master && git fetch -q origin && + git reset -q --hard origin/master ) || note " could not sync master" if grep -q 'percent / 100' "$CODE_REPO_DIR/src/discount.py" 2>/dev/null; then note " src/discount.py is correct; demo is armable" else - note " src/discount.py still carries the seeded defect — revert it before demoing" + note " src/discount.py carries the seeded defect; reverting it on master" + ( cd "$CODE_REPO_DIR" && + python3 - <<'PY' +import pathlib, re, sys + +path = pathlib.Path("src/discount.py") +source = path.read_text() +# Matches the seeded `percent / 10` without also matching a correct +# `percent / 100`, so re-running reset on a healthy file changes nothing. +fixed = re.sub(r"percent / 10(?!\d)", "percent / 100", source) +if fixed == source: + sys.exit("unrecognised defect; fix src/discount.py by hand") +path.write_text(fixed) +PY + git commit -qam "revert: restore the discount divisor" && git push -q origin master && + note " reverted and pushed; demo is armable" ) || note " revert failed — fix src/discount.py by hand" fi else note "demo repository not cloned at $CODE_REPO_DIR; skipping"