fix(demo): make reset actually undo the code demo's seeded defect
The code demo seeds its defect by pushing to master, and the fix only lands if someone merges the pull request - which, by design, nobody does during a demo. So master stays broken, and reset only printed "revert it before demoing" while leaving it that way. The second run of the day then aborted on "defect already present" before anything started. Reset now reverts it on master. The substitution is anchored so it cannot match an already-correct divisor, which keeps reset idempotent: running it on a healthy repository changes nothing rather than corrupting the file. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
86420ecfee
commit
151cd574a9
@ -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"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user