@@ -21,6 +21,26 @@ assert_contains_package() {
2121 printf ' %s\n' " $1 " | tr ' ' ' \n' | grep -Fxq " $2 "
2222}
2323
24+ assert_output_graph_error () {
25+ mode=$1
26+ sources=$2
27+ expected=$3
28+ out=$( mktemp)
29+ err=$( mktemp)
30+ if [ " $mode " = disabled ]; then
31+ if hack/select-install.sh --disabled postgres " $sources " > " $out " 2> " $err " ; then
32+ echo " expected disabled mode to reject invalid graph $sources " >&2
33+ exit 1
34+ fi
35+ elif hack/select-install.sh postgres " $sources " > " $out " 2> " $err " ; then
36+ echo " expected closure mode to reject invalid graph $sources " >&2
37+ exit 1
38+ fi
39+ [ ! -s " $out " ]
40+ grep -Fq " $expected " " $err "
41+ rm -f " $out " " $err "
42+ }
43+
2444@test " single app selects its forward dependency closure" {
2545 output=$( hack/select-install.sh " postgres" )
2646 assert_contains_package " $output " cozystack.postgres-application
@@ -135,7 +155,8 @@ assert_contains_package() {
135155
136156@test " validate detects a dangling dependency" {
137157 tmp=$( mktemp -d)
138- mkdir -p " $tmp /sources" " $tmp /suites"
158+ mkdir -p " $tmp /sources" " $tmp /suites/foo"
159+ : > " $tmp /suites/foo/chainsaw-test.yaml"
139160 cat > " $tmp /sources/foo-application.yaml" << 'YAML '
140161apiVersion: cozystack.io/v1alpha1
141162kind: PackageSource
@@ -147,17 +168,24 @@ spec:
147168 dependsOn:
148169 - cozystack.does-not-exist
149170YAML
150- # empty suites-dir isolates this to the graph check
151- if hack/select-install.sh --validate " $tmp /sources" " $tmp /suites" 2> /dev/null ; then
171+ out= " $tmp /out " ; err= " $tmp /err "
172+ if hack/select-install.sh --validate " $tmp /sources" " $tmp /suites" > " $out " 2> " $err " ; then
152173 echo " expected validation to fail on a dangling dependency" >&2
153174 exit 1
154175 fi
176+ [ ! -s " $out " ]
177+ grep -Fq " dangling dependency 'cozystack.does-not-exist'" " $err "
178+ if grep -Fq " found no chainsaw-test.yaml" " $err " ; then
179+ echo " positive-control suite discovery failed instead of graph validation" >&2
180+ exit 1
181+ fi
155182 rm -rf " $tmp "
156183}
157184
158185@test " validate detects a dependency cycle" {
159186 tmp=$( mktemp -d)
160- mkdir -p " $tmp /sources" " $tmp /suites"
187+ mkdir -p " $tmp /sources" " $tmp /suites/a"
188+ : > " $tmp /suites/a/chainsaw-test.yaml"
161189 cat > " $tmp /sources/a.yaml" << 'YAML '
162190apiVersion: cozystack.io/v1alpha1
163191kind: PackageSource
@@ -180,11 +208,64 @@ spec:
180208 dependsOn:
181209 - cozystack.a
182210YAML
183- # empty suites-dir isolates this to the graph check
184- if hack/select-install.sh --validate " $tmp /sources" " $tmp /suites" 2> /dev/null ; then
211+ out= " $tmp /out " ; err= " $tmp /err "
212+ if hack/select-install.sh --validate " $tmp /sources" " $tmp /suites" > " $out " 2> " $err " ; then
185213 echo " expected validation to fail on a dependency cycle" >&2
186214 exit 1
187215 fi
216+ [ ! -s " $out " ]
217+ grep -Fq " dependency cycle detected involving 'cozystack.a'" " $err "
218+ if grep -Fq " found no chainsaw-test.yaml" " $err " ; then
219+ echo " positive-control suite discovery failed instead of graph validation" >&2
220+ exit 1
221+ fi
222+ rm -rf " $tmp "
223+ }
224+
225+ @test " output modes reject a removed runtime source" {
226+ tmp=$( mktemp -d)
227+ cp -r packages/core/platform/sources " $tmp /sources"
228+ mv " $tmp /sources/reloader.yaml" " $tmp /reloader.yaml"
229+ for mode in closure disabled; do
230+ assert_output_graph_error " $mode " " $tmp /sources" \
231+ " dangling dependency 'cozystack.reloader'"
232+ done
233+
234+ yq -i ' (.spec.variants[].dependsOn) -= ["cozystack.reloader"]' \
235+ " $tmp /sources/linstor.yaml"
236+ for mode in closure disabled; do
237+ assert_output_graph_error " $mode " " $tmp /sources" \
238+ " required runtime PackageSource(s) not found in $tmp /sources: cozystack.reloader"
239+ done
240+ rm -rf " $tmp "
241+ }
242+
243+ @test " output modes reject a dangling dependency in an unselected package" {
244+ tmp=$( mktemp -d)
245+ cp -r packages/core/platform/sources " $tmp /sources"
246+ yq -i ' .spec.variants[0].dependsOn += ["cozystack.does-not-exist"]' \
247+ " $tmp /sources/kafka-application.yaml"
248+ for mode in closure disabled; do
249+ assert_output_graph_error " $mode " " $tmp /sources" \
250+ " dangling dependency 'cozystack.does-not-exist' (referenced by: cozystack.kafka-application)"
251+ done
252+ rm -rf " $tmp "
253+ }
254+
255+ @test " output modes reject selected and unselected dependency cycles" {
256+ tmp=$( mktemp -d)
257+ cp -r packages/core/platform/sources " $tmp /selected"
258+ cp -r packages/core/platform/sources " $tmp /unselected"
259+ yq -i ' .spec.variants[0].dependsOn += ["cozystack.postgres-application"]' \
260+ " $tmp /selected/postgres-application.yaml"
261+ yq -i ' .spec.variants[0].dependsOn += ["cozystack.kafka-application"]' \
262+ " $tmp /unselected/kafka-application.yaml"
263+ for mode in closure disabled; do
264+ assert_output_graph_error " $mode " " $tmp /selected" \
265+ " dependency cycle detected involving 'cozystack.postgres-application'"
266+ assert_output_graph_error " $mode " " $tmp /unselected" \
267+ " dependency cycle detected involving 'cozystack.kafka-application'"
268+ done
188269 rm -rf " $tmp "
189270}
190271
@@ -331,6 +412,19 @@ YAML
331412 [ " $drop " -eq 68 ]
332413}
333414
415+ @test " disabled mode accepts a valid inventory with an empty complement" {
416+ tmp=$( mktemp -d)
417+ mkdir -p " $tmp /sources"
418+ keep=$( hack/select-install.sh postgres)
419+ for source in $keep ; do
420+ name=${source# cozystack.}
421+ cp " packages/core/platform/sources/$name .yaml" " $tmp /sources/"
422+ done
423+ output=$( hack/select-install.sh --disabled postgres " $tmp /sources" )
424+ [ -z " $output " ]
425+ rm -rf " $tmp "
426+ }
427+
334428@test " disabled mode: never lists a package the closure keeps" {
335429 keep=$( hack/select-install.sh " postgres kafka" )
336430 drop=$( hack/select-install.sh --disabled " postgres kafka" )
0 commit comments