attach-arm64: address review (never roll back a newer publish, mandatory --expect-index, --follow-tag, trunk-only, pin checks to planned amd64 digest)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0185ukXi4YX5FxJGqhi6qab6
This commit is contained in:
shadowdaoandClaude Sonnet 5.5 committed 2026-11-19 21:11:26 -08:00
1 parent 02de5c6568
commit 42f72e24ff
3 files changed
+120 -22

No files matched your search

+67 -12
View File
@@ -95,6 +95,7 @@ for t, c in list(tags.items()):
json.dump(tags, open(S + '/tags.json', 'w')); json.dump(blobs, open(S + '/blobs.json', 'w')); json.dump(arch, open(S + '/arch.json', 'w'))
PY
}
EXP=sha256:$(printf '0%.0s' {1..64})
tagdig() { python3 -I -c '
import json,hashlib,sys
t=json.load(open(sys.argv[1]))[sys.argv[2]]
@@ -109,6 +110,7 @@ creates() { grep -c '^create' "$T/st/log" || true; }
# ---- happy path: amd64-only tag + new arm64 -> index with amd64 UNCHANGED + arm64
mk amd64only; before=$(tagdig)
chk "attach to amd64-only tag -> rc 0" "$(run --repo $R --tag php82 --arm64 "$B" --expect-index "$before")" 0
chk " amd64 manifest digest unchanged, arm64 added" "$(plats)" "amd64=$A arm64=$B"
chk " amd64 attestation carried over" "$(python3 -I -c 'import json,sys;print(sum(1 for m in json.load(open(sys.argv[1]))[sys.argv[2]]["manifests"] if m["digest"]==sys.argv[3]))' "$T/st/tags.json" "$R:php82" "$AT")" 1
chk " exactly one create, from the old index + the arm64 digest" "$(grep -c "^create -t $R:php82 $R@$before $R@$B\$" "$T/st/log")" 1
@@ -117,11 +119,11 @@ chk " prints before/after/amd64" "$(grep -c "^before_index=$before\$\|^amd64=$A
# ---- already multi-arch: refuse (3), nothing written
mk both; before=$(tagdig)
chk "tag already has arm64 -> rc 3" "$(run --repo $R --tag php82 --arm64 "$B")" 3
chk "tag already has arm64 -> rc 3" "$(run --repo $R --tag php82 --arm64 "$B" --expect-index "$before")" 3
chk " no create" "$(creates)" 0
chk " tag untouched" "$(tagdig)" "$before"
# ---- --force replaces the arm64 entry, amd64 manifest untouched
chk "--force on multi-arch -> rc 0" "$(run --repo $R --tag php82 --arm64 "$B" --force)" 0
chk "--force on multi-arch -> rc 0" "$(run --repo $R --tag php82 --arm64 "$B" --force --expect-index "$(tagdig)")" 0
chk " arm64 replaced, amd64 same" "$(plats)" "amd64=$A arm64=$B"
chk " create used the amd64 child only (old arm64 not a source)" "$(grep -c "^create -t $R:php82 $R@$A $R@$B\$" "$T/st/log")" 1
@@ -137,9 +139,9 @@ chk "--plan-only on multi-arch tag still refuses (3)" "$(run --repo $R --tag php
# ---- bad inputs / bad tags
mk amd64only
chk "arm64 digest that is not arm64 -> rc 1" "$(run --repo $R --tag php82 --arm64 "$C")" 1
chk "arm64 digest == amd64 digest -> rc 1" "$(run --repo $R --tag php82 --arm64 "$A")" 1
chk "arm64 digest unknown to registry -> rc 1" "$(run --repo $R --tag php82 --arm64 "$(d 7)")" 1
chk "arm64 digest that is not arm64 -> rc 1" "$(run --repo $R --tag php82 --arm64 "$C" --expect-index "$EXP")" 1
chk "arm64 digest == amd64 digest -> rc 1" "$(run --repo $R --tag php82 --arm64 "$A" --expect-index "$EXP")" 1
chk "arm64 digest unknown to registry -> rc 1" "$(run --repo $R --tag php82 --arm64 "$(d 7)" --expect-index "$EXP")" 1
chk "malformed --arm64 -> rc 2" "$(run --repo $R --tag php82 --arm64 nope)" 2
chk "--arm64 missing without --plan-only -> rc 2" "$(run --repo $R --tag php82)" 2
chk "malformed --expect-index -> rc 2" "$(run --repo $R --tag php82 --arm64 "$B" --expect-index x)" 2
@@ -147,29 +149,82 @@ chk "bad tag (injection) -> rc 2" "$(run --repo $R --tag 'a b;c' --arm64 "$B")"
chk "unknown argument -> rc 2" "$(run --repo $R --tag php82 --arm64 "$B" --bogus)" 2
chk " none of those created anything" "$(creates)" 0
mk missing
chk "missing tag -> rc 1" "$(run --repo $R --tag php82 --arm64 "$B")" 1
chk "missing tag -> rc 1" "$(run --repo $R --tag php82 --arm64 "$B" --expect-index "$EXP")" 1
mk noamd
chk "tag without amd64 -> rc 1" "$(run --repo $R --tag php82 --arm64 "$B")" 1
chk "tag without amd64 -> rc 1" "$(run --repo $R --tag php82 --arm64 "$B" --expect-index "$EXP")" 1
mk twoamd
chk "tag with two amd64 entries -> rc 1" "$(run --repo $R --tag php82 --arm64 "$B")" 1
chk "tag with two amd64 entries -> rc 1" "$(run --repo $R --tag php82 --arm64 "$B" --expect-index "$EXP")" 1
chk " no create" "$(creates)" 0
# ---- plain single amd64 manifest tag
mk single; before=$(tagdig)
chk "single amd64 manifest tag -> rc 0" "$(run --repo $R --tag php82 --arm64 "$B")" 0
chk "single amd64 manifest tag -> rc 0" "$(run --repo $R --tag php82 --arm64 "$B" --expect-index "$before")" 0
chk " create from the manifest digest + arm64" "$(grep -c "^create -t $R:php82 $R@$before $R@$B\$" "$T/st/log")" 1
# ---- post-create verification: a create that loses amd64 is detected and rolled back
mk amd64only; before=$(tagdig)
rc=$(MANGLE=drop-amd64 run --repo $R --tag php82 --arm64 "$B"); chk "create dropped amd64 -> rc 1" "$rc" 1
rc=$(MANGLE=drop-amd64 run --repo $R --tag php82 --arm64 "$B" --expect-index "$before"); chk "create dropped amd64 -> rc 1" "$rc" 1
chk " restored: tag is the previous index again" "$(plats)" "amd64=$A"
chk " second create was the restore from the old index" "$(grep -c "^create -t $R:php82 $R@$before\$" "$T/st/log")" 1
mk amd64only
rc=$(MANGLE=fail run --repo $R --tag php82 --arm64 "$B"); chk "create failing -> rc != 0" "$([ "$rc" != 0 ] && echo yes)" yes
rc=$(MANGLE=fail run --repo $R --tag php82 --arm64 "$B" --expect-index "$(tagdig)"); chk "create failing -> rc != 0" "$([ "$rc" != 0 ] && echo yes)" yes
chk " tag untouched" "$(plats)" "amd64=$A"
chk "missing --expect-index -> rc 2" "$(run --repo $R --tag php82 --arm64 "$B")" 2
# concurrent publish during attach: tag ends with a different amd64 -> never rolled back
mk amd64only; before=$(tagdig)
cat >"$T/race.sh" <<'RS'
#!/usr/bin/env bash
python3 "$STUBPY" "$@"; rc=$?
if [ "$1" = create ] && [ ! -f "$STATE/raced" ]; then touch "$STATE/raced"; python3 - <<'PY'
import json, os
S = os.environ['STATE']; t = json.load(open(S + '/tags.json'))
k = [x for x in t if x.endswith(':php82')][0]
t[k] = {'manifests': [{'digest': 'sha256:' + 'd' * 64, 'platform': {'os': 'linux', 'architecture': 'amd64'}}]}
json.dump(t, open(S + '/tags.json', 'w'))
PY
fi
exit $rc
RS
chmod +x "$T/race.sh"
rc=$(STUBPY=$T/stub.py IMAGETOOLS="$T/race.sh" run --repo $R --tag php82 --arm64 "$B" --expect-index "$before"); chk "publish raced in during attach -> rc 1" "$rc" 1
chk " newer amd64 NOT rolled back" "$(plats)" "amd64=sha256:$(printf 'd%.0s' {1..64})"
chk " no restore create" "$(grep -c "^create -t $R:php82 $R@$before\$" "$T/st/log" || true)" 0
# ---- --follow-tag: an alias (latest == php85) follows; a different latest is left alone
mk amd64only
python3 -I - "$T/st/tags.json" "$R" <<'PY'
import json, sys
t = json.load(open(sys.argv[1])); t[sys.argv[2] + ':latest'] = t[sys.argv[2] + ':php82']; json.dump(t, open(sys.argv[1], 'w'))
PY
chk "--follow-tag latest (alias) -> rc 0" "$(run --repo $R --tag php82 --arm64 "$B" --expect-index "$(tagdig)" --follow-tag latest)" 0
chk " latest now equals the new php82 index" "$(python3 -I -c '
import json,sys
t=json.load(open(sys.argv[1])); print(t[sys.argv[2]+":latest"]==t[sys.argv[2]+":php82"])' "$T/st/tags.json" "$R")" True
chk " latest has amd64 unchanged + arm64" "$(python3 -I -c '
import json,sys
t=json.load(open(sys.argv[1])); print(" ".join(m["platform"]["architecture"]+"="+m["digest"] for m in t[sys.argv[2]+":latest"]["manifests"] if "annotations" not in m))' "$T/st/tags.json" "$R")" "amd64=$A arm64=$B"
mk amd64only
python3 -I - "$T/st/tags.json" "$R" "$A" <<'PY'
import json, sys
t = json.load(open(sys.argv[1])); t[sys.argv[2] + ':latest'] = {'manifests': [{'digest': sys.argv[3], 'platform': {'os': 'linux', 'architecture': 'amd64'}}]}; json.dump(t, open(sys.argv[1], 'w'))
PY
lbefore=$(python3 -I -c '
import json,hashlib,sys
t=json.load(open(sys.argv[1]))[sys.argv[2]+":latest"]
print("sha256:"+hashlib.sha256(json.dumps(t,sort_keys=True).encode()).hexdigest())' "$T/st/tags.json" "$R")
chk "--follow-tag latest (not an alias) -> rc 0, tag attached" "$(run --repo $R --tag php82 --arm64 "$B" --expect-index "$(tagdig)" --follow-tag latest)" 0
chk " latest untouched" "$(python3 -I -c '
import json,hashlib,sys
t=json.load(open(sys.argv[1]))[sys.argv[2]+":latest"]
print("sha256:"+hashlib.sha256(json.dumps(t,sort_keys=True).encode()).hexdigest())' "$T/st/tags.json" "$R")" "$lbefore"
mk amd64only
chk "--follow-tag with missing latest -> rc 0, left alone" "$(run --repo $R --tag php82 --arm64 "$B" --expect-index "$(tagdig)" --follow-tag latest)" 0
chk "bad --follow-tag -> rc 2" "$(run --repo $R --tag php82 --arm64 "$B" --expect-index "$(tagdig)" --follow-tag 'x y')" 2
chk "--follow-tag == --tag -> rc 2" "$(run --repo $R --tag php82 --arm64 "$B" --expect-index "$(tagdig)" --follow-tag php82)" 2
# ---- GITHUB_OUTPUT
mk amd64only; GITHUB_OUTPUT=$T/gho "$HERE/attach-arm64-index.sh" --repo $R --tag php82 --arm64 "$B" >/dev/null 2>&1
mk amd64only; GITHUB_OUTPUT=$T/gho "$HERE/attach-arm64-index.sh" --repo $R --tag php82 --arm64 "$B" --expect-index "$(tagdig)" >/dev/null 2>&1
chk "GITHUB_OUTPUT has after_index and platforms" "$(grep -c '^after_index=\|^platforms=linux/amd64,linux/arm64$' "$T/gho")" 2
[ "$fail" -eq 0 ] && echo "ALL PASS" || { echo FAILURES; exit 1; }