| 1 | # shellcheck shell=bash |
| 2 | # Paths and fixtures come from the derivation environment. |
| 3 | # shellcheck disable=SC2154 |
| 4 | export HOME="$TMPDIR" |
| 5 | export GIT_CONFIG_NOSYSTEM=1 |
| 6 | git config --global user.name valley-check |
| 7 | git config --global user.email valley-check@localhost |
| 8 | git config --global init.defaultBranch main |
| 9 | |
| 10 | policy="$TMPDIR/policy" |
| 11 | mkdir -p "$policy/instance" "$policy/project" |
| 12 | cp "$fixtures/floor.cue" "$policy/instance/floor.cue" |
| 13 | cp "$fixtures/template.cue" "$policy/instance/template.cue" |
| 14 | cp "$fixtures/project.cue" "$policy/project/policy.cue" |
| 15 | |
| 16 | repo="$TMPDIR/tree" |
| 17 | git init --quiet "$repo" |
| 18 | cd "$repo" || exit 1 |
| 19 | mkdir -p docs notes src/deep a/x/y |
| 20 | echo moved > docs/moved.md |
| 21 | for f in docs/kept.md docs/gone.md src/one.rs src/deep/two.rs \ |
| 22 | a/b a/x/y/b Makefile; do |
| 23 | echo seed > "$f" |
| 24 | done |
| 25 | git add -A |
| 26 | git commit --quiet -m base |
| 27 | base="$(git rev-parse HEAD)" |
| 28 | |
| 29 | derive() { |
| 30 | valley checks --schema "$schema" \ |
| 31 | --instance "$policy/instance" --project "$policy/project" \ |
| 32 | "$@" "$base" HEAD |
| 33 | } |
| 34 | |
| 35 | # The check names in the deriver's table, sorted, on one line. |
| 36 | named() { |
| 37 | awk '/^required checks:$/ {f = 1; next} |
| 38 | /^$/ {f = 0} |
| 39 | f && /^ / {print $1}' <<<"$report" | sort | paste -sd' ' - |
| 40 | } |
| 41 | |
| 42 | # Start a case from the base tree; assert its check table. |
| 43 | case_start() { git checkout --quiet -B "$1" "$base"; } |
| 44 | expect() { |
| 45 | local got |
| 46 | got="$(named)" |
| 47 | if [ "$got" != "$1" ]; then |
| 48 | echo "policy-deriver: $2" >&2 |
| 49 | echo " expected: $1" >&2 |
| 50 | echo " got: $got" >&2 |
| 51 | echo "$report" >&2 |
| 52 | exit 1 |
| 53 | fi |
| 54 | } |
| 55 | |
| 56 | # Assert the carry mode the report states. The floor gives flat |
| 57 | # `same-class` and nested `exact`, and no other class a mode. |
| 58 | expect_carry() { |
| 59 | local got |
| 60 | got="$(sed -n 's/^carry mode: //p' <<<"$report")" |
| 61 | if [ "$got" != "$1" ]; then |
| 62 | echo "policy-deriver: $2" >&2 |
| 63 | echo " expected carry mode: $1" >&2 |
| 64 | echo " got: $got" >&2 |
| 65 | echo "$report" >&2 |
| 66 | exit 1 |
| 67 | fi |
| 68 | } |
| 69 | |
| 70 | # `**` crosses segments, `*` does not. One file under src/ |
| 71 | # matches both patterns; one a segment deeper matches only |
| 72 | # the `**` one. |
| 73 | case_start flat |
| 74 | echo edit > src/one.rs |
| 75 | git commit --quiet -am flat |
| 76 | report="$(derive)" |
| 77 | expect "c-deep c-flat" "src/*.rs must match a file directly under src/" |
| 78 | # Overlapping classes compose to the strictest mode: flat's same-class |
| 79 | # over deep's same-paths. |
| 80 | expect_carry same-class "a path in a same-class class and a same-paths one must be same-class" |
| 81 | |
| 82 | case_start deep |
| 83 | echo edit > src/deep/two.rs |
| 84 | git commit --quiet -am deep |
| 85 | report="$(derive)" |
| 86 | expect "c-deep" "src/*.rs must not match across a path separator" |
| 87 | expect_carry same-paths "a class that asks for no mode must be same-paths" |
| 88 | |
| 89 | # A `**` between two segments matches no segment at all … |
| 90 | case_start nested-none |
| 91 | echo edit > a/b |
| 92 | git commit --quiet -am nested-none |
| 93 | report="$(derive)" |
| 94 | expect "c-nested" "a/**/b must match a/b" |
| 95 | expect_carry exact "a path in an exact class must be exact" |
| 96 | |
| 97 | # Paths in different classes compose the same way: exact over same-class. |
| 98 | case_start strictest |
| 99 | echo edit > a/b |
| 100 | echo edit > src/one.rs |
| 101 | git commit --quiet -am strictest |
| 102 | report="$(derive)" |
| 103 | expect "c-deep c-flat c-nested" "a change to two classes must require both" |
| 104 | expect_carry exact "an exact path beside a same-class one must be exact" |
| 105 | |
| 106 | # … and any number of them. |
| 107 | case_start nested-many |
| 108 | echo edit > a/x/y/b |
| 109 | git commit --quiet -am nested-many |
| 110 | report="$(derive)" |
| 111 | expect "c-nested" "a/**/b must match a/x/y/b" |
| 112 | |
| 113 | # A rename counts on both sides: the class covering the old |
| 114 | # path is required as much as the one covering the new. |
| 115 | case_start renamed |
| 116 | git mv docs/moved.md notes/moved.md |
| 117 | git commit --quiet -m renamed |
| 118 | git diff --name-status -M "$base" HEAD | grep -q '^R' \ |
| 119 | || { echo "policy-deriver: the rename case is not a rename" >&2; exit 1; } |
| 120 | report="$(derive)" |
| 121 | expect "c-docs c-notes c-tmpl" "a rename must count on both sides" |
| 122 | |
| 123 | # A deleted path is still a changed path. |
| 124 | case_start deleted |
| 125 | git rm --quiet docs/gone.md |
| 126 | git commit --quiet -m deleted |
| 127 | report="$(derive)" |
| 128 | expect "c-docs c-tmpl" "a deletion must count" |
| 129 | |
| 130 | # The form of the value is the mandatory bit: the floor's |
| 131 | # concrete `true` against the template's `bool | *true`. |
| 132 | grep -qE '^ c-docs +mandatory +docs$' <<<"$report" |
| 133 | grep -qE '^ c-tmpl +default +docs$' <<<"$report" |
| 134 | |
| 135 | # A check's cost is a declared property and changes nothing required. The |
| 136 | # same diff under a project layer that marks c-docs slow requires the same |
| 137 | # checks, for the same classes, with the same mandatory bits: every line above the |
| 138 | # cost summary is the same. Only the summary moves c-docs. |
| 139 | cp -R "$policy/project" "$policy/project-slow" |
| 140 | cat > "$policy/project-slow/slow.cue" <<'EOF' |
| 141 | package verification |
| 142 | project: checks: "c-docs": {runner: "nix", attribute: "c-docs", cost: "slow"} |
| 143 | EOF |
| 144 | derive_slow() { |
| 145 | valley checks --schema "$schema" \ |
| 146 | --instance "$policy/instance" --project "$policy/project-slow" \ |
| 147 | "$@" "$base" HEAD |
| 148 | } |
| 149 | quick_report="$report" |
| 150 | report="$(derive_slow)" |
| 151 | expect "c-docs c-tmpl" "a slow check must be required as a quick one is" |
| 152 | above_summary() { sed -e '/^quick:/,$d' -e '/^policy:/d' <<<"$1"; } |
| 153 | [ "$(above_summary "$quick_report")" = "$(above_summary "$report")" ] || { |
| 154 | echo "policy-deriver: marking a check slow changed what is required" >&2 |
| 155 | diff <(above_summary "$quick_report") <(above_summary "$report") >&2 |
| 156 | exit 1 |
| 157 | } |
| 158 | grep -qx 'quick: c-docs, c-tmpl' <<<"$quick_report" |
| 159 | grep -qx 'slow: none' <<<"$quick_report" |
| 160 | grep -qx 'quick: c-tmpl' <<<"$report" |
| 161 | grep -qx 'slow: c-docs' <<<"$report" |
| 162 | |
| 163 | # The names alone are what an agent reads, so they are exactly the required |
| 164 | # names, one per line, and --cost filters them. |
| 165 | [ "$(derive_slow --names)" = "$(printf 'c-docs\nc-tmpl')" ] |
| 166 | [ "$(derive_slow --names --cost quick)" = c-tmpl ] |
| 167 | [ "$(derive_slow --names --cost slow)" = c-docs ] |
| 168 | [ "$(derive --names --cost slow)" = "" ] |
| 169 | if derive_slow --names --cost fast 2> "$TMPDIR/cost.err"; then |
| 170 | echo "policy-deriver: --cost fast was accepted" >&2 |
| 171 | exit 1 |
| 172 | fi |
| 173 | grep -q "cost takes quick or slow, not 'fast'" "$TMPDIR/cost.err" |
| 174 | if derive_slow --cost quick 2> /dev/null; then |
| 175 | echo "policy-deriver: --cost without --names was accepted" >&2 |
| 176 | exit 1 |
| 177 | fi |
| 178 | |
| 179 | # A change that requires nothing prints no names and no cost summary. |
| 180 | report="$(valley checks --schema "$schema" \ |
| 181 | --instance "$policy/instance" --project "$policy/project-slow" "$base" "$base")" |
| 182 | grep -qx 'required checks: none' <<<"$report" |
| 183 | expect_carry same-paths "a change that touches nothing must be same-paths" |
| 184 | if grep -q '^quick:' <<<"$report"; then |
| 185 | echo "policy-deriver: a change that requires nothing printed a cost summary" >&2 |
| 186 | exit 1 |
| 187 | fi |
| 188 | [ "$(valley checks --schema "$schema" --names \ |
| 189 | --instance "$policy/instance" --project "$policy/project-slow" "$base" "$base")" = "" ] |
| 190 | |
| 191 | # A schema that predates `cost` cannot render the composed policy. The |
| 192 | # deriver refuses rather than reading the empty render as a policy that |
| 193 | # requires nothing. |
| 194 | grep -v '^ cost: \*"quick" | "slow"$' "$schema" > "$TMPDIR/costless.cue" |
| 195 | if cmp -s "$schema" "$TMPDIR/costless.cue"; then |
| 196 | echo "policy-deriver: the costless schema still declares cost, so this case proves nothing" >&2 |
| 197 | exit 1 |
| 198 | fi |
| 199 | if valley checks --schema "$TMPDIR/costless.cue" \ |
| 200 | --instance "$policy/instance" --project "$policy/project" \ |
| 201 | "$base" HEAD > "$TMPDIR/costless.out" 2>&1; then |
| 202 | echo "policy-deriver: a schema the render cannot read derived an answer" >&2 |
| 203 | cat "$TMPDIR/costless.out" >&2 |
| 204 | exit 1 |
| 205 | fi |
| 206 | grep -q 'does not render' "$TMPDIR/costless.out" |
| 207 | |
| 208 | # The same for a schema that predates the carry modes: with no resolved |
| 209 | # mode to render, the deriver refuses rather than reading every class as |
| 210 | # same-paths. |
| 211 | grep -v '^_mode: ' "$schema" > "$TMPDIR/modeless.cue" |
| 212 | if cmp -s "$schema" "$TMPDIR/modeless.cue"; then |
| 213 | echo "policy-deriver: the modeless schema still resolves modes, so this case proves nothing" >&2 |
| 214 | exit 1 |
| 215 | fi |
| 216 | if valley checks --schema "$TMPDIR/modeless.cue" \ |
| 217 | --instance "$policy/instance" --project "$policy/project" \ |
| 218 | "$base" HEAD > "$TMPDIR/modeless.out" 2>&1; then |
| 219 | echo "policy-deriver: a schema with no carry modes derived an answer" >&2 |
| 220 | cat "$TMPDIR/modeless.out" >&2 |
| 221 | exit 1 |
| 222 | fi |
| 223 | grep -q 'does not render' "$TMPDIR/modeless.out" |
| 224 | |
| 225 | # A document may refine `policy` directly, and a mode written there counts. |
| 226 | # The floor gives the deep class no mode, and a project document that |
| 227 | # refines `policy` makes it exact. |
| 228 | cp -R "$policy/project" "$policy/project-refined" |
| 229 | cat > "$policy/project-refined/refined.cue" <<'EOF' |
| 230 | package verification |
| 231 | policy: classes: deep: carry: exact: true |
| 232 | EOF |
| 233 | git checkout --quiet deep |
| 234 | report="$(valley checks --schema "$schema" \ |
| 235 | --instance "$policy/instance" --project "$policy/project-refined" "$base" HEAD)" |
| 236 | expect "c-deep" "refining policy's carry must not change what deep requires" |
| 237 | expect_carry exact "a mode written by refining policy must count" |
| 238 | |
| 239 | # A policy string holding a newline cannot forge a line of the render. Each |
| 240 | # forged layer adds a pattern that would end its own line and start another: |
| 241 | # a looser carry mode for the nested class, which the floor makes exact, or |
| 242 | # a second copy of a requirement. There are three walls, and each is tested |
| 243 | # with the walls before it taken down. The schema refuses the pattern, so |
| 244 | # the layers do not compose. Under a schema that admits it, the render |
| 245 | # refuses the line. Under a copy of the script whose render admits it too, |
| 246 | # the deriver refuses the second line. |
| 247 | for forged in carry requires; do |
| 248 | mkdir -p "$policy/forged-$forged" |
| 249 | cp "$policy/project/policy.cue" "$policy/forged-$forged/policy.cue" |
| 250 | done |
| 251 | cat > "$policy/forged-carry/forged.cue" <<'EOF' |
| 252 | package verification |
| 253 | project: classes: forged: paths: "unused\ncarry\tnested\tsame-paths": true |
| 254 | EOF |
| 255 | cat > "$policy/forged-requires/forged.cue" <<'EOF' |
| 256 | package verification |
| 257 | project: classes: forged: paths: "unused\nrequires\tnested\tc-nested": true |
| 258 | EOF |
| 259 | |
| 260 | # The schema with #Pattern admitting anything, and the script with its |
| 261 | # render's line check removed. Each must differ from what it copies, or the |
| 262 | # case below it proves nothing. |
| 263 | [ "$(grep -c '^#Pattern: ' "$schema")" = 1 ] || { |
| 264 | echo "policy-deriver: #Pattern is not one line of the schema, so the loose schema proves nothing" >&2 |
| 265 | exit 1 |
| 266 | } |
| 267 | { grep -v '^#Pattern: ' "$schema"; echo '#Pattern: string'; } > "$TMPDIR/loose.cue" |
| 268 | sed -e 's/" & line}$/"}/' -e '/^let line = /d' "$cliScript" > "$TMPDIR/valley-unguarded" |
| 269 | if ! grep -q '" & line}$' "$cliScript" || grep -q '& line}\|^let line' "$TMPDIR/valley-unguarded"; then |
| 270 | echo "policy-deriver: the unguarded script still checks its render's lines, so it proves nothing" >&2 |
| 271 | exit 1 |
| 272 | fi |
| 273 | |
| 274 | # refused WHAT TEXT COMMAND…: COMMAND must fail, print nothing on stdout, |
| 275 | # and say TEXT. |
| 276 | refused() { |
| 277 | local what="$1" text="$2" |
| 278 | shift 2 |
| 279 | if "$@" > "$TMPDIR/forged.out" 2> "$TMPDIR/forged.err"; then |
| 280 | echo "policy-deriver: $what derived an answer" >&2 |
| 281 | cat "$TMPDIR/forged.out" >&2 |
| 282 | exit 1 |
| 283 | fi |
| 284 | [ ! -s "$TMPDIR/forged.out" ] || { |
| 285 | echo "policy-deriver: $what printed to stdout" >&2 |
| 286 | exit 1 |
| 287 | } |
| 288 | grep -qF -- "$text" "$TMPDIR/forged.err" || { |
| 289 | echo "policy-deriver: $what was refused without saying $text" >&2 |
| 290 | cat "$TMPDIR/forged.err" >&2 |
| 291 | exit 1 |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | # forged_derive SCHEMA LAYER [SCRIPT]: derive the case at HEAD under SCHEMA |
| 296 | # and the project layer LAYER, with the real deriver or with SCRIPT. |
| 297 | forged_derive() { |
| 298 | local -a deriver=(valley) |
| 299 | [ $# -lt 3 ] || deriver=(bash "$3") |
| 300 | "${deriver[@]}" checks --schema "$1" --instance "$policy/instance" \ |
| 301 | --project "$policy/$2" "$base" HEAD |
| 302 | } |
| 303 | |
| 304 | case_start forged |
| 305 | echo edit > a/b |
| 306 | git commit --quiet -am forged |
| 307 | # Without the walls, an honest layer still derives exact here, so each |
| 308 | # refusal below is the forgery's doing. |
| 309 | report="$(forged_derive "$TMPDIR/loose.cue" project "$TMPDIR/valley-unguarded")" |
| 310 | expect "c-nested" "the unguarded script must derive an honest layer as the real one does" |
| 311 | expect_carry exact "the unguarded script must derive an honest layer's carry mode" |
| 312 | |
| 313 | refused "a forged carry line" "do not compose" \ |
| 314 | forged_derive "$schema" forged-carry |
| 315 | refused "a forged carry line under a schema that admits it" "does not render" \ |
| 316 | forged_derive "$TMPDIR/loose.cue" forged-carry |
| 317 | refused "a forged carry line under a render that admits it" \ |
| 318 | "rendered 'carry nested' twice" \ |
| 319 | forged_derive "$TMPDIR/loose.cue" forged-carry "$TMPDIR/valley-unguarded" |
| 320 | refused "a forged requirement line under a render that admits it" \ |
| 321 | "rendered 'requires nested c-nested' twice" \ |
| 322 | forged_derive "$TMPDIR/loose.cue" forged-requires "$TMPDIR/valley-unguarded" |
| 323 | |
| 324 | # A path no class covers takes the unclassified set, and says |
| 325 | # so by name. It is same-paths. |
| 326 | case_start uncovered |
| 327 | echo edit > Makefile |
| 328 | git commit --quiet -am uncovered |
| 329 | report="$(derive)" |
| 330 | expect "c-uncovered" "an uncovered path must take the unclassified set" |
| 331 | grep -q '^classes matched: unclassified$' <<<"$report" |
| 332 | grep -q '^unclassified: 1 path(s) matched no class$' <<<"$report" |
| 333 | grep -q '^ Makefile$' <<<"$report" |
| 334 | expect_carry same-paths "an unclassified path must be same-paths" |
| 335 | |
| 336 | # A replacement ref changes nothing the derivation reads. Here |
| 337 | # refs/replace/<head> makes git read the uncovered case's head as |
| 338 | # the flat case's, so a deriver that left replacement refs on |
| 339 | # would derive the src/ checks for a change that touches only |
| 340 | # the Makefile — and the caller asking for them is not listened |
| 341 | # to either. |
| 342 | git update-ref "refs/replace/$(git rev-parse uncovered)" "$(git rev-parse flat)" |
| 343 | git diff --name-only "$base" uncovered | grep -x src/one.rs > /dev/null \ |
| 344 | || { echo "policy-deriver: the replacement did not take, so this case proves nothing" >&2; exit 1; } |
| 345 | git checkout --quiet uncovered |
| 346 | report="$(GIT_CONFIG_PARAMETERS="'core.usereplacerefs'='true'" derive)" |
| 347 | expect "c-uncovered" "a replacement ref must not change the derived checks" |
| 348 | git update-ref -d "refs/replace/$(git rev-parse uncovered)" |
| 349 | |
| 350 | # ---------------------------------------------------------------------- |
| 351 | # Every producer fails closed. The deriver's calls of git, sort and cue |
| 352 | # are failed one at a time, one per run, by fail-nth standing in for the |
| 353 | # tool first on PATH. A producer read through a process substitution |
| 354 | # loses its status, and its failure then reads as an empty list — no |
| 355 | # paths, no catalogue, no classes — which derives a change that |
| 356 | # requires nothing. So every failure must end the run non-zero, say so, and print |
| 357 | # nothing on stdout: no report, and no names. |
| 358 | # |
| 359 | # This runs bin/valley itself, because the package's wrapper puts its own |
| 360 | # git ahead of anything on PATH. The case touches a class, a second class |
| 361 | # through `**`, the template's default, and an uncovered path, so every |
| 362 | # producer has something to lose. |
| 363 | case_start mixed |
| 364 | echo edit > docs/kept.md |
| 365 | echo edit > src/one.rs |
| 366 | echo edit > Makefile |
| 367 | git commit --quiet -am mixed |
| 368 | # An unclassified path beside a same-class one makes the change no looser. |
| 369 | report="$(derive)" |
| 370 | expect_carry same-class "an unclassified path must not loosen a same-class change" |
| 371 | |
| 372 | shims="$TMPDIR/shims" |
| 373 | mkdir -p "$shims" |
| 374 | for tool in git sort cue; do ln -s "$failNth" "$shims/$tool"; done |
| 375 | |
| 376 | # shimmed TOOL N [option…]: derive the mixed case with TOOL's Nth call |
| 377 | # failing (0 fails none). The count of TOOL's calls is left in |
| 378 | # $TMPDIR/shim-count. |
| 379 | shimmed() { |
| 380 | local tool="$1" at="$2" status=2 |
| 381 | shift 2 |
| 382 | [ "$tool" != git ] || status=128 # git's own status for a fatal error |
| 383 | echo 0 > "$TMPDIR/shim-count" |
| 384 | SHIM_REAL_PATH="$PATH" SHIM_TOOL="$tool" SHIM_FAIL_AT="$at" \ |
| 385 | SHIM_STATUS="$status" SHIM_COUNT="$TMPDIR/shim-count" PATH="$shims:$PATH" \ |
| 386 | bash "$cliScript" checks --schema "$schema" \ |
| 387 | --instance "$policy/instance" --project "$policy/project" \ |
| 388 | "$@" "$base" HEAD |
| 389 | } |
| 390 | |
| 391 | # The check names a run's stdout requires, sorted, on one line. |
| 392 | required_in() { |
| 393 | if [ "$1" = names ]; then |
| 394 | sort "$2" | paste -sd' ' - |
| 395 | else |
| 396 | report="$(cat "$2")" |
| 397 | named |
| 398 | fi |
| 399 | } |
| 400 | |
| 401 | shim_fail() { |
| 402 | echo "policy-deriver: $1" >&2 |
| 403 | for f in shim.out shim.err; do |
| 404 | echo "--- $f" >&2 |
| 405 | cat "$TMPDIR/$f" >&2 |
| 406 | done |
| 407 | exit 1 |
| 408 | } |
| 409 | |
| 410 | for tool in git sort cue; do |
| 411 | for mode in report names; do |
| 412 | opts=() |
| 413 | [ "$mode" = report ] || opts=(--names) |
| 414 | shimmed "$tool" 0 "${opts[@]}" > "$TMPDIR/shim.want" |
| 415 | want="$(required_in "$mode" "$TMPDIR/shim.want")" |
| 416 | [ "$want" = "c-deep c-docs c-flat c-tmpl c-uncovered" ] || { |
| 417 | echo "policy-deriver: the mixed case requires $want" >&2 |
| 418 | exit 1 |
| 419 | } |
| 420 | calls="$(cat "$TMPDIR/shim-count")" |
| 421 | [ "$calls" -gt 0 ] || { |
| 422 | echo "policy-deriver: the $mode run never called $tool, so failing it proves nothing" >&2 |
| 423 | exit 1 |
| 424 | } |
| 425 | for ((at = 1; at <= calls; at++)); do |
| 426 | what="$mode run, $tool call $at of $calls" |
| 427 | if shimmed "$tool" "$at" "${opts[@]}" > "$TMPDIR/shim.out" 2> "$TMPDIR/shim.err"; then |
| 428 | # The one failure a run may survive is a cue probe after the |
| 429 | # composition and the render: it asks whether a requirement is |
| 430 | # mandatory, and a probe that fails reads as mandatory, the strict |
| 431 | # answer. What is required must not move. |
| 432 | [ "$tool" = cue ] && [ "$at" -gt 2 ] \ |
| 433 | || shim_fail "the $what failed and the deriver still answered" |
| 434 | [ "$(required_in "$mode" "$TMPDIR/shim.out")" = "$want" ] \ |
| 435 | || shim_fail "the $what failed and changed what is required" |
| 436 | continue |
| 437 | fi |
| 438 | [ ! -s "$TMPDIR/shim.out" ] \ |
| 439 | || shim_fail "the $what failed and the deriver printed to stdout" |
| 440 | grep -q '^valley: ' "$TMPDIR/shim.err" \ |
| 441 | || shim_fail "the $what failed and the deriver did not say so" |
| 442 | done |
| 443 | done |
| 444 | done |
| 445 | |
| 446 | # A diff cut short mid-record is a failure too, even though git exited 0: |
| 447 | # cut inside the first path, after one status, and inside the second |
| 448 | # status, after one whole record. The last is the one a plain `while |
| 449 | # read` ends on quietly, dropping the record it cut. |
| 450 | for cut in 1 2; do |
| 451 | for opts in "" --names; do |
| 452 | # shellcheck disable=SC2086 # an empty $opts is no option at all |
| 453 | if SHIM_TRUNCATE="$cut" SHIM_REAL_PATH="$PATH" PATH="$shims:$PATH" \ |
| 454 | bash "$cliScript" checks --schema "$schema" \ |
| 455 | --instance "$policy/instance" --project "$policy/project" $opts \ |
| 456 | "$base" HEAD > "$TMPDIR/shim.out" 2> "$TMPDIR/shim.err"; then |
| 457 | shim_fail "a diff cut after $cut field(s) derived an answer" |
| 458 | fi |
| 459 | [ ! -s "$TMPDIR/shim.out" ] \ |
| 460 | || shim_fail "a diff cut after $cut field(s) printed to stdout" |
| 461 | grep -q 'truncated diff output' "$TMPDIR/shim.err" \ |
| 462 | || shim_fail "a diff cut after $cut field(s) was not named as one" |
| 463 | done |
| 464 | done |
| 465 | |
| 466 | touch "$out" |