Skip to content

Commit 2cb8c74

Browse files
test(release): cover the split-map and repository-less ref shapes
No fixture in verify-promoted-packages_test.bats built a shape-3 split map -- `repository:` on one key, `tag: <tag>@sha256:<digest>` on another -- which hack/lib/image-refs.sh itself calls the dominant shape in the tree. The existing fixture's single-string ref carries a registry host, so its rc-to-stable rewrite normalizes through the other branch and passes whether or not host-less refs are handled, which is why the suite looked covered while a clean promotion could still be rejected. Add two cases. The first promotes a split map whose tag moves from rc to stable with the repository and digest held constant; reverting the normalization fix reddens it on "promotion changed the container repository/digest set", diffing v9.9.9-rc.3@sha256:eee... against v9.9.9@sha256:eee... -- the same tag-as-repository pair, with identical digests, that CI reported. The second pins the property a blunter fix would break. A digest-only `image:` map with no `repository:` (the kuberture shape) is seen by no rule but shape 1, so it must still contribute its digest: the case moves that digest and nothing else, and asserts the rejection comes from the digest set rather than a neighbouring leg. Replacing the fix with an outright `continue` over host-less refs makes the verifier exit 0 on that changed digest and reddens the case at its exit-status assertion. Negative assertions are counted rather than `!`-negated: under hack/cozytest.sh a `! grep -q` cannot fail, so it would be a comment shaped like an assertion. Signed-off-by: Myasnikov Daniil <[email protected]>
1 parent 4fcc111 commit 2cb8c74

1 file changed

Lines changed: 105 additions & 0 deletions

File tree

‎hack/verify-promoted-packages_test.bats‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,108 @@ EOF
365365
[ "$rc" -ne 0 ]
366366
grep -q 'promotion changed the container repository/digest set' "$tmp/err"
367367
}
368+
369+
# Shape 3 — `repository:` on one key, `tag: <tag>@sha256:<digest>` on another —
370+
# is the shape hack/lib/image-refs.sh itself calls the dominant one, and the one
371+
# no fixture above builds. The collector emits TWO entries for such a map: the
372+
# correctly joined repository@digest, plus shape 1's recursive scrape of the
373+
# bare `tag` scalar, which names no repository at all. Promotion rewrites
374+
# exactly that scalar, so normalization keeping it — treating the tag as the
375+
# repository — makes every clean promotion look as though it moved container
376+
# bytes. The single-string ref in _make_verify_fixture cannot reach that path:
377+
# it carries a registry host, so it normalizes through the other branch and its
378+
# own rc-to-stable rewrite passes either way. That is why the suite looked
379+
# covered while the dominant shape went untested.
380+
_write_split_map() {
381+
cat > "$1" <<EOF
382+
linstorCSI:
383+
image:
384+
repository: ghcr.io/cozystack/cozystack/linstor-csi
385+
tag: $2@sha256:eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
386+
EOF
387+
}
388+
389+
# Same repository and the same digest on every side. ONLY the tag string moves,
390+
# which is exactly and only what promotion is meant to change.
391+
_add_split_map_package() {
392+
t="$1"
393+
mkdir -p "$t/release/system/linstor" "$t/artifact/system/linstor" \
394+
"$t/rc-artifact/system/linstor"
395+
_write_split_map "$t/release/system/linstor/values.yaml" v9.9.9
396+
_write_split_map "$t/artifact/system/linstor/values.yaml" v9.9.9
397+
_write_split_map "$t/rc-artifact/system/linstor/values.yaml" v9.9.9-rc.3
398+
}
399+
400+
@test "accepts a split-map tag rewritten from rc to stable" {
401+
tmp="$(_test_workspace)/fixture"
402+
_make_verify_fixture "$tmp"
403+
_add_split_map_package "$tmp"
404+
405+
rc=0
406+
MOCK_ARTIFACT="$tmp/artifact" MOCK_RC_ARTIFACT="$tmp/rc-artifact" MOCK_FLUX_LOG="$tmp/flux.log" \
407+
VERIFY_PACKAGES_WORKDIR="$tmp/work" \
408+
PATH="$tmp/bin:$PATH" \
409+
hack/verify-promoted-packages.sh 9.9.9 "$tmp/release" \
410+
> "$tmp/out" 2> "$tmp/err" || rc=$?
411+
if [ "$rc" -ne 0 ]; then
412+
echo "verification exited $rc" >&2
413+
cat "$tmp/err" >&2
414+
return "$rc"
415+
fi
416+
417+
grep -q "stable tags, identical package tree, and the rc artifact's container digests" "$tmp/out"
418+
}
419+
420+
# The property a blunter fix would break. packages/system/kuberture/values.yaml
421+
# carries an `image:` map with a `tag:` and no `repository:` — shape 2 wants a
422+
# `digest` key and shape 3 a `repository` key, so shape 1's scrape of the bare
423+
# tag scalar is the ONLY rule that ever sees that image's digest. Discarding
424+
# host-less refs rather than comparing them on their digest would silently stop
425+
# proving it unchanged, which is a hole in the same guard being repaired here.
426+
# Asserted from the rejecting direction, because that is the direction able to
427+
# go red: the digest moves and nothing else does, so the digest-set comparison
428+
# is the only leg that can fire — artifact and release tree stay byte-identical,
429+
# no rc string appears in the candidate, and the installer values match.
430+
_write_repository_less_map() {
431+
cat > "$1" <<EOF
432+
kuberture:
433+
image:
434+
tag: 0.1.1@sha256:$2
435+
EOF
436+
}
437+
438+
_add_repository_less_package() {
439+
t="$1"
440+
mkdir -p "$t/release/system/kuberture" "$t/artifact/system/kuberture" \
441+
"$t/rc-artifact/system/kuberture"
442+
_repoless_stable=1111111111111111111111111111111111111111111111111111111111111111
443+
_repoless_rc=2222222222222222222222222222222222222222222222222222222222222222
444+
_write_repository_less_map "$t/release/system/kuberture/values.yaml" "$_repoless_stable"
445+
_write_repository_less_map "$t/artifact/system/kuberture/values.yaml" "$_repoless_stable"
446+
_write_repository_less_map "$t/rc-artifact/system/kuberture/values.yaml" "$_repoless_rc"
447+
}
448+
449+
@test "rejects a changed digest carried only by a repository-less image map" {
450+
tmp="$(_test_workspace)/fixture"
451+
_make_verify_fixture "$tmp"
452+
_add_repository_less_package "$tmp"
453+
454+
rc=0
455+
MOCK_ARTIFACT="$tmp/artifact" MOCK_RC_ARTIFACT="$tmp/rc-artifact" MOCK_FLUX_LOG="$tmp/flux.log" \
456+
VERIFY_PACKAGES_WORKDIR="$tmp/work" \
457+
PATH="$tmp/bin:$PATH" \
458+
hack/verify-promoted-packages.sh 9.9.9 "$tmp/release" \
459+
> "$tmp/out" 2> "$tmp/err" || rc=$?
460+
461+
[ "$rc" -ne 0 ]
462+
grep -q 'promotion changed the container repository/digest set' "$tmp/err"
463+
# The rejection has to come from the digest set and not from a neighbouring leg
464+
# rejecting a tree this test never perturbed, or it would still pass with the
465+
# digest dropped from the comparison entirely. Counted rather than negated with
466+
# `!`, which suppresses errexit and would pass regardless.
467+
for _other in 'contain different files' 'differs from release tree' \
468+
'still carries rc image references' 'installer values differ'; do
469+
count="$(grep -c "$_other" "$tmp/err" || true)"
470+
[ "${count:-0}" -eq 0 ]
471+
done
472+
}

0 commit comments

Comments
 (0)