Skip to content

Commit bbc0103

Browse files
androndoclaude
andcommitted
test(sdn): pin the fail-closed suite-mapping contract in validate
Scrub the last "-" mention from the --validate usage doc (the escape no longer exists, so the header asserted the opposite of the behavior), and add the negative bats case the tightened branch was missing: a suite whose hardcoded mapping names a PackageSource absent from the graph must fail validation with the "maps to ..., not a PackageSource" error. Co-Authored-By: Claude Fable 5 <[email protected]> Signed-off-by: Andrey Kolkov <[email protected]>
1 parent f162735 commit bbc0103

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎hack/select-install.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# --validate: check the whole graph AND the suite mapping — every dependsOn
2525
# target resolves to a real PackageSource, there are no dependency cycles, and
2626
# every Chainsaw suite under <suites-dir> resolves via suite_to_source() to a
27-
# real PackageSource or to "-". Exit non-zero on any failure. The graph lives
27+
# real PackageSource. Exit non-zero on any failure. The graph lives
2828
# next to the packages and cannot drift from the suite directories; the
2929
# hand-maintained suite mapping is the only part that can, so it is guarded here.
3030
#

‎hack/select-install_test.bats‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,31 @@ YAML
172172
fi
173173
}
174174

175+
@test "validate detects a suite mapped to a source absent from the graph" {
176+
# suite_to_source() hardcodes securitygroup -> cozystack.securitygroup-controller;
177+
# a sources dir without that PackageSource must fail validation (fail closed),
178+
# pinning the contract that EVERY mapping resolves to a real source — there is
179+
# no bypass value (the old "-" escape is gone).
180+
tmp=$(mktemp -d)
181+
trap 'rm -rf "$tmp"' EXIT
182+
mkdir -p "$tmp/sources" "$tmp/suites/securitygroup"
183+
: > "$tmp/suites/securitygroup/chainsaw-test.yaml"
184+
cat > "$tmp/sources/standalone.yaml" <<'YAML'
185+
apiVersion: cozystack.io/v1alpha1
186+
kind: PackageSource
187+
metadata:
188+
name: cozystack.standalone
189+
spec:
190+
variants:
191+
- name: default
192+
YAML
193+
err=$(hack/select-install.sh --validate "$tmp/sources" "$tmp/suites" 2>&1 1>/dev/null) && {
194+
echo "expected validation to fail on a mapping to a missing source" >&2
195+
exit 1
196+
}
197+
echo "$err" | grep -q "maps to 'cozystack.securitygroup-controller', not a PackageSource"
198+
}
199+
175200
@test "validate fails when the suites dir does not exist" {
176201
tmp=$(mktemp -d)
177202
trap 'rm -rf "$tmp"' EXIT

0 commit comments

Comments
 (0)