#!/usr/bin/env bats # A test that creates a tenant `Kubernetes` cluster must wait for that release # to become Ready before the assertions it ends on. The mechanism, and how the # budget is sized, are derived once in docs/agents/e2e-testing.md section 4 -- # not restated here, because two copies of a derivation drift and the one that # drifts is the one nobody re-reads. # # Why the rule holds in every OIDC mode and why the budget's floor does not is # derived with the rest of it, in the conventions named above. What follows from # it here: the size of the budget is not checked, only its parse and its sign. # # What follows are the cases this cannot see, each with its mechanism and # whether it fails loudly or quietly. A path that exits between the CR and the # wait ends the run mid-install too, and the script writes many `exit 1` sites # between the two. None carries an assertion name, so the rule reports ok on # them -- deliberately for the failing ones: those runs are already red, and # the rule is about a run that asserts, passes and ends. # # That argument covers a failure and nothing else. A path leaving successfully # before the wait -- `exit 0`, or a `return` -- ends mid-install with a green # run and the rule still answers ok, and this cannot see it: the exit carries # no assertion name either. Silent, and the only entry here that is. What keeps # it from being live is the subject: between the CR and the wait it writes one # `exit 0`, inside a quoted `sh -c` that runs in a probe Pod, and no `return` # at all. # # An indented assertion-helper definition is not exempted by the composition # rule, which anchors at column 0, so its inner call counts as a call site and # the ordering can red on a script that broke nothing. The diagnosis then names # a line inside a definition body, which runs wherever the helper is called. # # A backslash at the end of a line inside single quotes is literal to the shell # and a continuation to this fold, so the two lines are joined here and separate # there, as /bin/sh reads it. The direction is loud: joining brings the # next line's operators onto the wait's command, so a `|| true` that belongs to # a different command reads as this one's and the case reds. Nothing in the # subject writes it. # # The fold's EOF flush matters only for a file whose last line ends in a # backslash, which no subject writes. The fixture `eof-continuation.sh` is that # file, and the case reading it is what keeps the flush from being deleted as # tolerance nothing needs. # # `set +e` in a CALLER, not in the body. Errexit being off is a property of the # shell where the wait runs rather than of the line, and what can be read is the # body around it: `_errexit_before` reds on a `set +e` above the wait in the same # body. Above it in whatever called that body it does not, because the print # stops at the definition. Narrowed, not closed, and silent -- as is the other # silent one here, an assertion whose name the convention does not cover, which # reads as no assertion at all. Every other entry costs a false red instead. What keeps it from being a live hole # is the subject, which disables errexit nowhere, and suites that run under # `set -eu`. # # What it does see, and refuses: a wait inside a compound command. `_wait_nesting` # reads the level from bash's own printing of the parsed body, so a wait under # `if`, `while`, `for` or `case` is reported as nested and the rule fails. It # is a refusal rather than a verdict about the install -- whether the branch is # taken is a runtime fact -- and it is refused because the alternative is the # one shape that passes while the install runs unbounded. # # The cost is a false red on shapes that change nothing, and each answers with # a different verdict, so the diagnosis names a different cause than the shape # suggests. A wait inside a `{ ...; }` group, measured on all three spellings: # written on one line it carries a `;`, which SEQUENCE_OK_RE refuses, so no # wait is found; written across lines its closing brace stands alone, which the # extraction refuses, so the body is `unextractable`; written `{ cmd` on the # opening line the command no longer starts the line and the command matcher # passes it by. `nested` is reachable for `if`, `while` and `case` and for no # brace group. A wait wrapped in a subshell is a fourth answer: `( cmd` prints # on the line that opens the subshell, so the printed body shows no wait and # the verdict is `absent`. All of them are loud, and none is written in the # body this guard reads. # # The opposite error is also possible and reds valid code: function bodies are # delimited by a `}` at column 0, so a heredoc carrying one -- a JSON patch # body, say -- ends the body early and the ordering rule answers `unscoped`. # The message says so rather than blaming the ordering, which is why this is # listed rather than guarded against. # # The conditional restore of xtrace is pinned as a property of this file's own # text, not of a runner's behaviour. Turning xtrace on where the runner had it # off makes bats' failure formatter trace its own output, and a later failure in # that case then arrives as a hang rather than a red -- exit 124 against exit 1, # measured on a two-case file written for that measurement. Watching it happen # needs the real `bats` binary, which the lane enforcing this guard does not # have -- `hack/cozytest.sh` never calls it -- and a case that skips where the # guard runs is a case that passes there. So the behavioural check is not built, # and the form is held instead: the case below reads this file and refuses an # unconditional restore. # # What that text rule does not see is another spelling: a conditional restore # written some other way reads as absent, and an unconditional trace-on written # with anything but a bare `set -x` on its own line reads as fine. Direction: # the first reds and names the line, the second passes -- the trade the matchers # here make wherever a spelling has to be listed, and the reason the measurement # above sits beside it rather than standing in for it. # # An assertion helper whose name starts with an underscore does not open an # exempt body: the composition rule anchors on `cozy_assert_` and # `cozy_switch_and_assert_`, while the subject writes its private helpers under # a `_cozy_` prefix. A helper named `_cozy_assert_x` would therefore have its # inner calls counted as call sites. Loud, like the indented definition above, # and the same remedy -- name the helper so the rule sees it, or widen the # anchor here. # # The creator sweep's root is not the whole of what it leaves out. The lane at # `hack/e2e-apps` is outside it, and the file types the sweep reads (`.sh`, # `.yaml`, `.yml`) leave it out a second time, since that lane holds `.bats` # suites: widening the root alone would still read nothing there. Both halves # fail in the same silent direction, and closing one of them closes half. # # The creator sweep pairs an apiVersion with a kind and cannot tell an `apply:` # block from an `assert:` one, so a suite that only asserts on a tenant cluster # is reported as creating one. Direction is loud -- the uniqueness case reds and # names the file -- and the diagnosis says to check that before treating the # file as a subject. Telling them apart needs the document structure, which is # a parser; the sweep reads lines. # # The fixtures' marks are comments, and they stay invisible to the matchers that # read those fixtures because the comment cut runs before each match. Mechanism: # a mark is `# @name`, so a matcher that sees comments sees marks. Direction # belongs to the pair of element and edit, not to the element: drop the cut from # the call matcher and a comment counted as a call reds the shapes case; drop # it from the fold and the wait vanishes under a `<