checkwright 0.38.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/payload/artifact/aarch64-apple-darwin/checkwright-gates +0 -0
- package/payload/artifact/aarch64-apple-darwin/checkwright-gates.sha256 +1 -1
- package/payload/artifact/aarch64-pc-windows-msvc/checkwright-gates.exe +0 -0
- package/payload/artifact/aarch64-pc-windows-msvc/checkwright-gates.exe.sha256 +1 -1
- package/payload/artifact/aarch64-unknown-linux-gnu/checkwright-gates +0 -0
- package/payload/artifact/aarch64-unknown-linux-gnu/checkwright-gates.sha256 +1 -1
- package/payload/artifact/aarch64-unknown-linux-musl/checkwright-gates +0 -0
- package/payload/artifact/aarch64-unknown-linux-musl/checkwright-gates.sha256 +1 -1
- package/payload/artifact/x86_64-apple-darwin/checkwright-gates +0 -0
- package/payload/artifact/x86_64-apple-darwin/checkwright-gates.sha256 +1 -1
- package/payload/artifact/x86_64-pc-windows-msvc/checkwright-gates.exe +0 -0
- package/payload/artifact/x86_64-pc-windows-msvc/checkwright-gates.exe.sha256 +1 -1
- package/payload/artifact/x86_64-unknown-linux-gnu/checkwright-gates +0 -0
- package/payload/artifact/x86_64-unknown-linux-gnu/checkwright-gates.sha256 +1 -1
- package/payload/artifact/x86_64-unknown-linux-musl/checkwright-gates +0 -0
- package/payload/artifact/x86_64-unknown-linux-musl/checkwright-gates.sha256 +1 -1
- package/payload/canon-kit/gate-tests/check-amendment-queue.test.sh +3 -3
- package/payload/canon-kit/gate-tests/check-amendment-update-target.test.sh +3 -3
- package/payload/canon-kit/gate-tests/check-deprecation-task.test.sh +2 -2
- package/payload/canon-kit/gate-tests/check-measured-claim.test.sh +3 -3
- package/payload/canon-kit/gate-tests/check-prose-bounds.test.sh +1 -1
- package/payload/canon-kit/gate-tests/check-prose-enum.test.sh +2 -2
- package/payload/canon-kit/gate-tests/check-provenance-seam/good/TASK-QUEUE.md +4 -0
- package/payload/canon-kit/gate-tests/check-provenance-seam/good/widget-toolkit/SPEC.md +1 -1
- package/payload/canon-kit/gate-tests/check-todo-task-liveness.test.sh +1 -1
- package/payload/canon-kit/gate-tests/check-unmarked-claim.test.sh +7 -7
- package/payload/context-kit/gate-tests/check-surface-ratchet.test.sh +7 -6
- package/payload/delegation-kit/README.md +1 -1
- package/payload/doctrine-kit/gate-tests/check-doctrine-registration.test.sh +2 -2
- package/payload/evidence-kit/gate-tests/check-battery-roster.test.sh +2 -2
- package/payload/evidence-kit/gate-tests/pre-hook.test.sh +5 -5
- package/payload/evidence-kit/gate-tests/producer-lock.test.sh +7 -7
- package/payload/evidence-kit/gate-tests/statement-store.test.sh +5 -5
- package/payload/evidence-kit/gate-tests/verify-gate-run-strict.test.sh +5 -4
- package/payload/gate-sdk/README.md +7 -0
- package/payload/gate-sdk/bin/build-native.sh +5 -4
- package/payload/gate-sdk/bin/run-gates.ps1 +8 -7
- package/payload/gate-sdk/bin/run-gates.sh +10 -8
- package/payload/gate-sdk/checks/check-binary-strings.gate +4 -0
- package/payload/gate-sdk/checks/check-exec-write.gate +4 -0
- package/payload/gate-sdk/checks/check-migration-guard.gate +4 -0
- package/payload/gate-sdk/checks/check-path-names.gate +4 -0
- package/payload/gate-sdk/checks/check-pipefail-readers.gate +4 -0
- package/payload/gate-sdk/checks/check-script-preflight.gate +4 -0
- package/payload/gate-sdk/checks/check-site-count.gate +4 -0
- package/payload/gate-sdk/checks/check-tree-terms.gate +1 -1
- package/payload/gate-sdk/gate-tests/binary-only-recipe.test.sh +2 -2
- package/payload/gate-sdk/gate-tests/check-action-run-shell.test.sh +11 -11
- package/payload/gate-sdk/gate-tests/check-binary-strings/bad/expect.txt +5 -0
- package/payload/gate-sdk/gate-tests/check-binary-strings/bad/out/app.elf +0 -0
- package/payload/gate-sdk/gate-tests/check-binary-strings/bad/out/notes.bin +0 -0
- package/payload/gate-sdk/gate-tests/check-binary-strings/bad/out/short.bin +0 -0
- package/payload/gate-sdk/gate-tests/check-binary-strings/bad/scripts/gate-sdk-config.knobs +3 -0
- package/payload/gate-sdk/gate-tests/check-binary-strings/bad/shapes.list +2 -0
- package/payload/gate-sdk/gate-tests/check-binary-strings/bad/terms.list +4 -0
- package/payload/gate-sdk/gate-tests/check-binary-strings/good/expect.txt +1 -0
- package/payload/gate-sdk/gate-tests/check-binary-strings/good/out/app.elf +0 -0
- package/payload/gate-sdk/gate-tests/check-binary-strings/good/scripts/gate-sdk-config.knobs +3 -0
- package/payload/gate-sdk/gate-tests/check-binary-strings/good/shapes.list +4 -0
- package/payload/gate-sdk/gate-tests/check-binary-strings/good/terms.list +4 -0
- package/payload/gate-sdk/gate-tests/check-binary-strings.test.sh +74 -0
- package/payload/gate-sdk/gate-tests/check-exec-write/bad/expect.txt +14 -0
- package/payload/gate-sdk/gate-tests/check-exec-write/bad/scripts/gate-sdk-config.knobs +2 -0
- package/payload/gate-sdk/gate-tests/check-exec-write/bad/src/caller.rs +5 -0
- package/payload/gate-sdk/gate-tests/check-exec-write/bad/src/helper.rs +5 -0
- package/payload/gate-sdk/gate-tests/check-exec-write/bad/src/sites.rs +21 -0
- package/payload/gate-sdk/gate-tests/check-exec-write/good/expect.txt +1 -0
- package/payload/gate-sdk/gate-tests/check-exec-write/good/scripts/gate-sdk-config.knobs +2 -0
- package/payload/gate-sdk/gate-tests/check-exec-write/good/src/helper.rs +5 -0
- package/payload/gate-sdk/gate-tests/check-exec-write/good/src/main.rs +15 -0
- package/payload/gate-sdk/gate-tests/check-exec-write.test.sh +69 -0
- package/payload/gate-sdk/gate-tests/check-identity.test.sh +2 -2
- package/payload/gate-sdk/gate-tests/check-migration-guard/bad/args +2 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/bad/base/0001_init.sql +1 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/bad/base/0002_orders.sql +1 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/bad/base/0003_audit.sql +1 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/bad/destructive.list +4 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/bad/expect.txt +8 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/bad/migrations/0001_init.sql +1 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/bad/migrations/0002_late.sql +1 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/bad/migrations/0003_audit_log.sql +1 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/bad/migrations/0004_prune.sql +3 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/bad/migrations/0005_accounts.sql +2 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/bad/migrations/0005_users.sql +2 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/bad/scripts/gate-sdk-config.knobs +2 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/good/args +2 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/good/base/0001_init.sql +1 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/good/base/0002_legacy.sql +1 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/good/destructive.list +4 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/good/expect.txt +1 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/good/migrations/0001_init.sql +1 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/good/migrations/0002_legacy.sql +1 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/good/migrations/0003_retire_legacy.sql +6 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/good/migrations/0004_index_accounts.sql +2 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard/good/scripts/gate-sdk-config.knobs +2 -0
- package/payload/gate-sdk/gate-tests/check-migration-guard.test.sh +277 -0
- package/payload/gate-sdk/gate-tests/check-path-names/bad/expect.txt +6 -0
- package/payload/gate-sdk/gate-tests/check-path-names/bad/scripts/gate-sdk-config.knobs +1 -0
- package/payload/gate-sdk/gate-tests/check-path-names/bad/terms.list +3 -0
- package/payload/gate-sdk/gate-tests/check-path-names/bad/tree/ZePhYr.md +1 -0
- package/payload/gate-sdk/gate-tests/check-path-names/bad/tree/foo/a.txt +1 -0
- package/payload/gate-sdk/gate-tests/check-path-names/bad/tree/foo/zephyr.txt +1 -0
- package/payload/gate-sdk/gate-tests/check-path-names/bad/tree/foo-cli.sh +1 -0
- package/payload/gate-sdk/gate-tests/check-path-names/bad/tree/foo.rs +1 -0
- package/payload/gate-sdk/gate-tests/check-path-names/bad/tree/foo_x.txt +1 -0
- package/payload/gate-sdk/gate-tests/check-path-names/good/expect.txt +1 -0
- package/payload/gate-sdk/gate-tests/check-path-names/good/scripts/gate-sdk-config.knobs +1 -0
- package/payload/gate-sdk/gate-tests/check-path-names/good/terms.list +1 -0
- package/payload/gate-sdk/gate-tests/check-path-names/good/tree/foobar.rs +1 -0
- package/payload/gate-sdk/gate-tests/check-path-names/good/tree/food/a.txt +1 -0
- package/payload/gate-sdk/gate-tests/check-path-names/good/tree/xfoo.txt +1 -0
- package/payload/gate-sdk/gate-tests/check-path-names.test.sh +66 -0
- package/payload/gate-sdk/gate-tests/check-pipefail-readers/bad/baseline.tsv +4 -0
- package/payload/gate-sdk/gate-tests/check-pipefail-readers/bad/expect.txt +17 -0
- package/payload/gate-sdk/gate-tests/check-pipefail-readers/bad/scripts/gate-sdk-config.knobs +2 -0
- package/payload/gate-sdk/gate-tests/check-pipefail-readers/bad/tree/over.sh +5 -0
- package/payload/gate-sdk/gate-tests/check-pipefail-readers/bad/tree/readers.sh +16 -0
- package/payload/gate-sdk/gate-tests/check-pipefail-readers/bad/tree/shared-lib.sh +3 -0
- package/payload/gate-sdk/gate-tests/check-pipefail-readers/bad/tree/stale.sh +4 -0
- package/payload/gate-sdk/gate-tests/check-pipefail-readers/good/baseline.tsv +2 -0
- package/payload/gate-sdk/gate-tests/check-pipefail-readers/good/expect.txt +1 -0
- package/payload/gate-sdk/gate-tests/check-pipefail-readers/good/scripts/gate-sdk-config.knobs +2 -0
- package/payload/gate-sdk/gate-tests/check-pipefail-readers/good/tree/clean.sh +17 -0
- package/payload/gate-sdk/gate-tests/check-pipefail-readers/good/tree/lib/baselined-lib.sh +4 -0
- package/payload/gate-sdk/gate-tests/check-pipefail-readers/good/tree/no-pipefail.sh +4 -0
- package/payload/gate-sdk/gate-tests/check-pipefail-readers.test.sh +127 -0
- package/payload/gate-sdk/gate-tests/check-portability-floor.test.sh +1 -1
- package/payload/gate-sdk/gate-tests/check-script-preflight/bad/expect.txt +10 -0
- package/payload/gate-sdk/gate-tests/check-script-preflight/bad/rules.list +23 -0
- package/payload/gate-sdk/gate-tests/check-script-preflight/bad/scripts/gate-sdk-config.knobs +2 -0
- package/payload/gate-sdk/gate-tests/check-script-preflight/bad/tree/submit-job.sh +13 -0
- package/payload/gate-sdk/gate-tests/check-script-preflight/good/expect.txt +1 -0
- package/payload/gate-sdk/gate-tests/check-script-preflight/good/rules.list +23 -0
- package/payload/gate-sdk/gate-tests/check-script-preflight/good/scripts/gate-sdk-config.knobs +2 -0
- package/payload/gate-sdk/gate-tests/check-script-preflight/good/tree/submit-job.sh +17 -0
- package/payload/gate-sdk/gate-tests/check-script-preflight.test.sh +110 -0
- package/payload/gate-sdk/gate-tests/check-site-count/bad/expect.txt +4 -0
- package/payload/gate-sdk/gate-tests/check-site-count/bad/rules.list +5 -0
- package/payload/gate-sdk/gate-tests/check-site-count/bad/scripts/gate-sdk-config.knobs +1 -0
- package/payload/gate-sdk/gate-tests/check-site-count/bad/sites.tsv +3 -0
- package/payload/gate-sdk/gate-tests/check-site-count/bad/tree/new.txt +1 -0
- package/payload/gate-sdk/gate-tests/check-site-count/bad/tree/over.txt +3 -0
- package/payload/gate-sdk/gate-tests/check-site-count/bad/tree/under.txt +1 -0
- package/payload/gate-sdk/gate-tests/check-site-count/good/expect.txt +1 -0
- package/payload/gate-sdk/gate-tests/check-site-count/good/rules.list +5 -0
- package/payload/gate-sdk/gate-tests/check-site-count/good/scripts/gate-sdk-config.knobs +1 -0
- package/payload/gate-sdk/gate-tests/check-site-count/good/sites.tsv +2 -0
- package/payload/gate-sdk/gate-tests/check-site-count/good/tree/blob.bin +0 -0
- package/payload/gate-sdk/gate-tests/check-site-count/good/tree/pinned.txt +2 -0
- package/payload/gate-sdk/gate-tests/check-site-count/good/tree/plain.txt +1 -0
- package/payload/gate-sdk/gate-tests/check-site-count/good/tree/tests/helper.txt +2 -0
- package/payload/gate-sdk/gate-tests/check-site-count.test.sh +90 -0
- package/payload/gate-sdk/gate-tests/check-tree-terms/bad/expect.txt +11 -8
- package/payload/gate-sdk/gate-tests/check-tree-terms/bad/patterns.list +4 -1
- package/payload/gate-sdk/gate-tests/check-tree-terms/bad/scripts/gate-sdk-config.knobs +1 -0
- package/payload/gate-sdk/gate-tests/check-tree-terms/bad/terms.list +4 -0
- package/payload/gate-sdk/gate-tests/check-tree-terms/bad/tree/terms.txt +2 -0
- package/payload/gate-sdk/gate-tests/check-tree-terms/good/expect.txt +1 -1
- package/payload/gate-sdk/gate-tests/check-tree-terms/good/scripts/gate-sdk-config.knobs +1 -0
- package/payload/gate-sdk/gate-tests/check-tree-terms/good/tree/rosters/terms.list +2 -0
- package/payload/gate-sdk/gate-tests/check-tree-terms/good/tree/words.txt +1 -0
- package/payload/gate-sdk/gate-tests/check-tree-terms.test.sh +36 -16
- package/payload/gate-sdk/gate-tests/enforcement-map.test.sh +5 -6
- package/payload/gate-sdk/gate-tests/lib-gate.test.sh +8 -8
- package/payload/gate-sdk/gate-tests/lib-test-hermetic.test.sh +35 -1
- package/payload/gate-sdk/gate-tests/native-git-hooks.test.sh +7 -7
- package/payload/gate-sdk/gate-tests/run-dispatch-streams.test.sh +4 -4
- package/payload/gate-sdk/gate-tests/run-for-path.test.sh +3 -3
- package/payload/gate-sdk/gate-tests/run-gates-linked-worktree.test.sh +6 -6
- package/payload/gate-sdk/gate-tests/run-json.test.sh +52 -0
- package/payload/gate-sdk/gate-tests/verdict-store.test.sh +99 -0
- package/payload/gate-sdk/lib/gate.sh +12 -9
- package/payload/gate-sdk/lib/test-hermetic.sh +25 -8
- package/payload/gate-sdk/templates/check-skeleton.sh +2 -1
- package/payload/gate-sdk/templates/migration-destructive.list +10 -0
- package/payload/gate-sdk/templates/script-rules.list +39 -0
- package/payload/gate-sdk/templates/strings-shapes.list +15 -0
- package/payload/guard-kit/gate-tests/consumer-rules.test.sh +5 -5
- package/payload/guard-kit/gate-tests/door-binding-corpus.test.sh +2 -2
- package/payload/lifecycle-kit/gate-tests/boundary-worktree-refusal.test.sh +1 -1
- package/payload/lifecycle-kit/gate-tests/check-dispatch-entry.test.sh +1 -1
- package/payload/lifecycle-kit/gate-tests/check-lesson-disposition.test.sh +3 -3
- package/payload/lifecycle-kit/gate-tests/check-lifecycle-registration.test.sh +1 -1
- package/payload/lifecycle-kit/gate-tests/check-survey-record.test.sh +2 -2
- package/payload/lifecycle-kit/gate-tests/lead-journal-open.test.sh +18 -2
- package/payload/lifecycle-kit/gate-tests/peer-channel.test.sh +35 -6
- package/payload/lifecycle-kit/gate-tests/preflight-valve.test.sh +4 -4
- package/payload/lifecycle-kit/templates/consult.md +1 -1
- package/payload/lifecycle-kit/templates/stages/scope.md +1 -1
- package/payload/queue-kit/README.md +1 -1
- package/payload/queue-kit/gate-tests/check-queue-slug-liveness.test.sh +2 -2
- package/payload/queue-kit/gate-tests/check-task-conservation.test.sh +4 -4
- package/payload/site-kit/gate-tests/check-docs-liquid-parse-parser.test.sh +4 -4
- package/payload/site-kit/gate-tests/check-docs-render-fidelity-batch.test.sh +9 -9
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Behavioral test of check-migration-guard's git arm, which the good/+bad/ pair cannot reach: the
|
|
3
|
+
# pair stands a directory in for the merge base, since a committed fixture is identical to HEAD.
|
|
4
|
+
# Each case runs in a sandbox repository whose history the case builds.
|
|
5
|
+
#
|
|
6
|
+
# Run by the --run-gate-tests arm (any <tests-dir>/*.test.sh; must exit 0).
|
|
7
|
+
set -uo pipefail
|
|
8
|
+
source "$(dirname "${BASH_SOURCE[0]}")/../../gate-sdk/lib/test-hermetic.sh"
|
|
9
|
+
|
|
10
|
+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" # gate-sdk/
|
|
11
|
+
CHECKS="$DIR/checks"
|
|
12
|
+
SANDBOX="$(mktemp -d)"
|
|
13
|
+
trap 'rm -rf "$SANDBOX"' EXIT
|
|
14
|
+
|
|
15
|
+
fails=0
|
|
16
|
+
cases=0
|
|
17
|
+
|
|
18
|
+
expect() { # expect <label> <want-rc> <substring> <got-rc> <output>
|
|
19
|
+
cases=$((cases + 1))
|
|
20
|
+
if [[ "$4" -ne "$2" ]]; then
|
|
21
|
+
echo " FAIL [$1]: want exit $2, got $4 -- $5"; fails=$((fails + 1))
|
|
22
|
+
elif ! grep -qF -- "$3" <<<"$5"; then
|
|
23
|
+
echo " FAIL [$1]: exit $2 but output lacks '$3': $5"; fails=$((fails + 1))
|
|
24
|
+
fi
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
refute() { # refute <label> <substring> <output>
|
|
28
|
+
if grep -qF -- "$2" <<<"$3"; then
|
|
29
|
+
echo " FAIL [$1]: output holds '$2': $3"; fails=$((fails + 1))
|
|
30
|
+
fi
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
LIST="$SANDBOX/destructive.list"
|
|
34
|
+
printf '# the template floor\nDROP (TABLE|INDEX|VIEW|TRIGGER)\nALTER TABLE .* DROP\nALTER TABLE .* RENAME\n' > "$LIST"
|
|
35
|
+
|
|
36
|
+
# --- the knob empty: clean, not applicable, before any repository is needed.
|
|
37
|
+
mkdir -p "$SANDBOX/plain"
|
|
38
|
+
out="$( cd "$SANDBOX/plain" && gate_run check-migration-guard "$CHECKS" 2>&1 )"; rc=$?
|
|
39
|
+
expect not-applicable 0 'not applicable: no migration directory configured' "$rc" "$out"
|
|
40
|
+
|
|
41
|
+
# A fresh repository on main with two merged migrations, a topic branch checked out over it.
|
|
42
|
+
fresh() { # fresh <name> — prints the repository path
|
|
43
|
+
local r="$SANDBOX/$1"
|
|
44
|
+
mkdir -p "$r/db/migrations"
|
|
45
|
+
git -C "$r" init -q -b main
|
|
46
|
+
printf 'CREATE TABLE a (id INTEGER);\n' > "$r/db/migrations/0001_a.sql"
|
|
47
|
+
printf 'CREATE TABLE b (id INTEGER);\n' > "$r/db/migrations/0002_b.sql"
|
|
48
|
+
git -C "$r" add db
|
|
49
|
+
git -C "$r" -c user.name=t -c user.email=t@e.invalid commit -qm base
|
|
50
|
+
git -C "$r" checkout -qb topic
|
|
51
|
+
printf '%s' "$r"
|
|
52
|
+
}
|
|
53
|
+
guard() { # guard <repo> [gate args…] — the gate in <repo> over db/migrations
|
|
54
|
+
local r="$1"
|
|
55
|
+
shift
|
|
56
|
+
( cd "$r" && gate_env GATE_SDK_MIGRATION_DIR=db/migrations GATE_SDK_MIGRATION_DESTRUCTIVE="$LIST" \
|
|
57
|
+
&& gate_run check-migration-guard "$CHECKS" "$@" 2>&1 )
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
# --- a tree whose base is its own HEAD, then an uncommitted addition counted from a subdirectory.
|
|
61
|
+
r="$(fresh own-head)"
|
|
62
|
+
out="$(guard "$r" --base HEAD)"; rc=$?
|
|
63
|
+
expect own-head 0 'clean (2 migration(s), 0 added, against merge base' "$rc" "$out"
|
|
64
|
+
printf 'CREATE TABLE c (id INTEGER);\n' > "$r/db/migrations/0003_c.sql"
|
|
65
|
+
out="$(guard "$r")"; rc=$?
|
|
66
|
+
expect untracked-addition 0 'clean (3 migration(s), 1 added, against merge base' "$rc" "$out"
|
|
67
|
+
out="$( cd "$r/db" && gate_env GATE_SDK_MIGRATION_DIR=migrations GATE_SDK_MIGRATION_DESTRUCTIVE="$LIST" \
|
|
68
|
+
&& gate_run check-migration-guard "$CHECKS" 2>&1 )"; rc=$?
|
|
69
|
+
expect from-subdirectory 0 'clean (3 migration(s), 1 added, against merge base' "$rc" "$out"
|
|
70
|
+
|
|
71
|
+
# --- an edit, uncommitted and then committed on the branch.
|
|
72
|
+
r="$(fresh edit)"
|
|
73
|
+
printf 'CREATE TABLE a (id INTEGER, x TEXT);\n' > "$r/db/migrations/0001_a.sql"
|
|
74
|
+
out="$(guard "$r")"; rc=$?
|
|
75
|
+
expect edit-uncommitted 1 'db/migrations/0001_a.sql: [MIGRATION-EDITED]' "$rc" "$out"
|
|
76
|
+
git -C "$r" -c user.name=t -c user.email=t@e.invalid commit -qam edit
|
|
77
|
+
out="$(guard "$r")"; rc=$?
|
|
78
|
+
expect edit-committed 1 'db/migrations/0001_a.sql: [MIGRATION-EDITED]' "$rc" "$out"
|
|
79
|
+
|
|
80
|
+
# --- the checkout form: a clean filter hiding an edit from git diff reds, an untouched file in an
|
|
81
|
+
# autocrlf or an LF clone is clean, and an edit in the autocrlf clone reds.
|
|
82
|
+
r="$(fresh filtered)"
|
|
83
|
+
git -C "$r" config filter.strip.clean "tr -d '#'"
|
|
84
|
+
git -C "$r" config filter.strip.smudge cat
|
|
85
|
+
printf '*.sql filter=strip\n' > "$r/.git/info/attributes"
|
|
86
|
+
printf 'CREATE TABLE a (id INTEGER);#\n' > "$r/db/migrations/0001_a.sql"
|
|
87
|
+
out="$(guard "$r")"; rc=$?
|
|
88
|
+
expect filter-hidden-edit 1 'db/migrations/0001_a.sql: [MIGRATION-EDITED]' "$rc" "$out"
|
|
89
|
+
refute filter-untouched 'db/migrations/0002_b.sql: [MIGRATION-EDITED]' "$out"
|
|
90
|
+
o="$(fresh clone-src)"
|
|
91
|
+
git -C "$o" checkout -q main
|
|
92
|
+
r="$SANDBOX/crlf"
|
|
93
|
+
git clone -q -c core.autocrlf=true "$o" "$r" && git -C "$r" checkout -qb topic
|
|
94
|
+
out="$(guard "$r")"; rc=$?
|
|
95
|
+
expect autocrlf-untouched 0 'clean (2 migration(s), 0 added, against merge base' "$rc" "$out"
|
|
96
|
+
printf 'CREATE TABLE b (id INTEGER, y TEXT);\r\n' > "$r/db/migrations/0002_b.sql"
|
|
97
|
+
out="$(guard "$r")"; rc=$?
|
|
98
|
+
expect autocrlf-edit 1 'db/migrations/0002_b.sql: [MIGRATION-EDITED]' "$rc" "$out"
|
|
99
|
+
r="$SANDBOX/lf"
|
|
100
|
+
git clone -q "$o" "$r" && git -C "$r" checkout -qb topic
|
|
101
|
+
out="$(guard "$r")"; rc=$?
|
|
102
|
+
expect lf-untouched 0 'clean (2 migration(s), 0 added, against merge base' "$rc" "$out"
|
|
103
|
+
|
|
104
|
+
# --- a conversion attribute changed since the merge base reds; a filter naming no configured
|
|
105
|
+
# driver cannot be read in its checkout form, which is 3, never a pass.
|
|
106
|
+
r="$(fresh attr-drift)"
|
|
107
|
+
printf 'db/migrations/*.sql eol=lf\n' > "$r/.gitattributes"
|
|
108
|
+
out="$(guard "$r")"; rc=$?
|
|
109
|
+
expect attr-drift 1 'db/migrations/0001_a.sql: [MIGRATION-ATTR] eol unspecified -> lf' "$rc" "$out"
|
|
110
|
+
refute attr-drift-edit 'MIGRATION-EDITED' "$out"
|
|
111
|
+
r="$(fresh no-driver)"
|
|
112
|
+
printf '*.sql filter=nodriver\n' > "$r/.git/info/attributes"
|
|
113
|
+
out="$(guard "$r")"; rc=$?
|
|
114
|
+
expect no-driver 3 "its filter attribute names driver 'nodriver'" "$rc" "$out"
|
|
115
|
+
|
|
116
|
+
# --- a delete and a rename.
|
|
117
|
+
r="$(fresh delete)"
|
|
118
|
+
git -C "$r" rm -q db/migrations/0002_b.sql
|
|
119
|
+
out="$(guard "$r")"; rc=$?
|
|
120
|
+
expect delete 1 'db/migrations/0002_b.sql: [MIGRATION-EDITED]' "$rc" "$out"
|
|
121
|
+
r="$(fresh rename)"
|
|
122
|
+
git -C "$r" mv db/migrations/0002_b.sql db/migrations/0002_bee.sql
|
|
123
|
+
out="$(guard "$r")"; rc=$?
|
|
124
|
+
expect rename-gone 1 'db/migrations/0002_b.sql: [MIGRATION-EDITED]' "$rc" "$out"
|
|
125
|
+
expect rename-order 1 'db/migrations/0002_bee.sql: [MIGRATION-ORDER] 0002 <= 0002' "$rc" "$out"
|
|
126
|
+
|
|
127
|
+
# --- a misnumbered addition.
|
|
128
|
+
r="$(fresh order)"
|
|
129
|
+
printf 'CREATE TABLE z (id INTEGER);\n' > "$r/db/migrations/0001_z.sql"
|
|
130
|
+
out="$(guard "$r")"; rc=$?
|
|
131
|
+
expect misnumbered 1 'db/migrations/0001_z.sql: [MIGRATION-ORDER] 0001 <= 0002' "$rc" "$out"
|
|
132
|
+
|
|
133
|
+
# --- a destructive addition without a reason, then with one; the list absent turns it off.
|
|
134
|
+
r="$(fresh destructive)"
|
|
135
|
+
printf 'drop table a;\n' > "$r/db/migrations/0003_drop.sql"
|
|
136
|
+
out="$(guard "$r")"; rc=$?
|
|
137
|
+
expect destructive 1 "db/migrations/0003_drop.sql:1: [MIGRATION-DESTRUCTIVE] matches 'DROP (TABLE|INDEX|VIEW|TRIGGER)'" "$rc" "$out"
|
|
138
|
+
printf 'drop table a; -- migration-ok: a is folded into b\n' > "$r/db/migrations/0003_drop.sql"
|
|
139
|
+
out="$(guard "$r")"; rc=$?
|
|
140
|
+
expect declared 0 'clean (3 migration(s), 1 added, against merge base' "$rc" "$out"
|
|
141
|
+
printf 'drop table a; -- migration-ok:\n' > "$r/db/migrations/0003_drop.sql"
|
|
142
|
+
out="$(guard "$r")"; rc=$?
|
|
143
|
+
expect empty-reason 1 'its waiver reason empty' "$rc" "$out"
|
|
144
|
+
out="$( cd "$r" && gate_env GATE_SDK_MIGRATION_DIR=db/migrations GATE_SDK_MIGRATION_DESTRUCTIVE=absent.list \
|
|
145
|
+
&& gate_run check-migration-guard "$CHECKS" 2>&1 )"; rc=$?
|
|
146
|
+
expect list-absent 0 'destructive check off: no list at absent.list' "$rc" "$out"
|
|
147
|
+
|
|
148
|
+
# --- the width is the directory's own: a five-digit history takes a five-digit addition, and a
|
|
149
|
+
# four-digit history refuses a five-digit one at 3, naming it.
|
|
150
|
+
r="$SANDBOX/wide"
|
|
151
|
+
mkdir -p "$r/db/migrations"
|
|
152
|
+
git -C "$r" init -q -b main
|
|
153
|
+
printf 'CREATE TABLE a (id INTEGER);\n' > "$r/db/migrations/00001_a.sql"
|
|
154
|
+
git -C "$r" add db
|
|
155
|
+
git -C "$r" -c user.name=t -c user.email=t@e.invalid commit -qm base
|
|
156
|
+
git -C "$r" checkout -qb topic
|
|
157
|
+
printf 'CREATE TABLE b (id INTEGER);\n' > "$r/db/migrations/00002_b.sql"
|
|
158
|
+
out="$(guard "$r")"; rc=$?
|
|
159
|
+
expect five-digit-history 0 'clean (2 migration(s), 1 added, against merge base' "$rc" "$out"
|
|
160
|
+
r="$(fresh widened)"
|
|
161
|
+
printf 'CREATE TABLE c (id INTEGER);\n' > "$r/db/migrations/10003_c.sql"
|
|
162
|
+
out="$(guard "$r")"; rc=$?
|
|
163
|
+
expect width-mixed 3 'db/migrations/10003_c.sql: its number is 5 digit(s) wide' "$rc" "$out"
|
|
164
|
+
|
|
165
|
+
# A commit on <branch> adding one migration, the topic branch checked out again after it.
|
|
166
|
+
on() { # on <repo> <branch> <file> <content> — branch made from main when absent
|
|
167
|
+
local r="$1"
|
|
168
|
+
git -C "$r" checkout -q "$2" 2>/dev/null || git -C "$r" checkout -qb "$2" main
|
|
169
|
+
printf '%s\n' "$4" > "$r/db/migrations/$3"
|
|
170
|
+
git -C "$r" add db
|
|
171
|
+
git -C "$r" -c user.name=t -c user.email=t@e.invalid commit -qm "$3"
|
|
172
|
+
git -C "$r" checkout -q topic
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
# --- a clash with an unmerged sibling, and none for one adding the same name with other content.
|
|
176
|
+
r="$(fresh clash)"
|
|
177
|
+
on "$r" sib 0003_theirs.sql 'CREATE TABLE t (id INTEGER);'
|
|
178
|
+
printf 'CREATE TABLE m (id INTEGER);\n' > "$r/db/migrations/0003_mine.sql"
|
|
179
|
+
out="$(guard "$r")"; rc=$?
|
|
180
|
+
expect clash 1 'db/migrations/0003_mine.sql: [MIGRATION-CLASH] 0003 refs/heads/sib 0003_theirs.sql' "$rc" "$out"
|
|
181
|
+
r="$(fresh same-name)"
|
|
182
|
+
on "$r" sib 0003_c.sql 'CREATE TABLE theirs (id INTEGER);'
|
|
183
|
+
printf 'CREATE TABLE mine (id INTEGER);\n' > "$r/db/migrations/0003_c.sql"
|
|
184
|
+
out="$(guard "$r")"; rc=$?
|
|
185
|
+
expect same-name 0 'clean (3 migration(s), 1 added, against merge base' "$rc" "$out"
|
|
186
|
+
expect same-name-read 0 ', 1 other ref(s) read' "$rc" "$out"
|
|
187
|
+
|
|
188
|
+
# --- a sibling merged into the base after the branch forked reads as ORDER, never CLASH; a file
|
|
189
|
+
# the base took by cherry-pick under its name is the base's, and the branch passes clean.
|
|
190
|
+
r="$(fresh merged)"
|
|
191
|
+
on "$r" sib 0003_theirs.sql 'CREATE TABLE t (id INTEGER);'
|
|
192
|
+
git -C "$r" checkout -q main && git -C "$r" merge -q --ff-only sib && git -C "$r" checkout -q topic
|
|
193
|
+
printf 'CREATE TABLE m (id INTEGER);\n' > "$r/db/migrations/0003_mine.sql"
|
|
194
|
+
out="$(guard "$r")"; rc=$?
|
|
195
|
+
expect merged-after-fork 1 'db/migrations/0003_mine.sql: [MIGRATION-ORDER] 0003 <= 0003' "$rc" "$out"
|
|
196
|
+
refute merged-after-fork 'MIGRATION-CLASH' "$out"
|
|
197
|
+
r="$(fresh picked)"
|
|
198
|
+
on "$r" topic 0003_c.sql 'DROP TABLE a;'
|
|
199
|
+
git -C "$r" checkout -q main && git -C "$r" -c user.name=t -c user.email=t@e.invalid cherry-pick topic >/dev/null \
|
|
200
|
+
&& git -C "$r" checkout -q topic
|
|
201
|
+
out="$(guard "$r")"; rc=$?
|
|
202
|
+
expect cherry-picked 0 'clean (3 migration(s), 0 added, against merge base' "$rc" "$out"
|
|
203
|
+
|
|
204
|
+
# --- the precedence: an addition both a duplicate and a clash prints DUP alone.
|
|
205
|
+
r="$(fresh precedence)"
|
|
206
|
+
on "$r" sib 0003_q.sql 'CREATE TABLE q (id INTEGER);'
|
|
207
|
+
printf 'CREATE TABLE a2 (id INTEGER);\n' > "$r/db/migrations/0003_a.sql"
|
|
208
|
+
printf 'CREATE TABLE b2 (id INTEGER);\n' > "$r/db/migrations/0003_b.sql"
|
|
209
|
+
out="$(guard "$r")"; rc=$?
|
|
210
|
+
expect precedence-dup 1 'db/migrations/0003_b.sql: [MIGRATION-DUP] 0003 also 0003_a.sql' "$rc" "$out"
|
|
211
|
+
expect precedence-clash 1 'db/migrations/0003_a.sql: [MIGRATION-CLASH] 0003 refs/heads/sib 0003_q.sql' "$rc" "$out"
|
|
212
|
+
refute precedence-one 'db/migrations/0003_b.sql: [MIGRATION-CLASH]' "$out"
|
|
213
|
+
|
|
214
|
+
# --- the ref set: a detached HEAD excludes no ref, an orphan is skipped, `none` turns the check
|
|
215
|
+
# off, a glob narrows it, and a glob opening with '-' is refused at 2.
|
|
216
|
+
r="$(fresh detached)"
|
|
217
|
+
on "$r" topic 0003_c.sql 'CREATE TABLE c (id INTEGER);'
|
|
218
|
+
out="$(guard "$r")"; rc=$?
|
|
219
|
+
expect own-ref 0 ', 0 other ref(s) read' "$rc" "$out"
|
|
220
|
+
git -C "$r" checkout -q --detach topic
|
|
221
|
+
out="$(guard "$r")"; rc=$?
|
|
222
|
+
expect detached 0 ', 1 other ref(s) read' "$rc" "$out"
|
|
223
|
+
o="$SANDBOX/orphan-src"
|
|
224
|
+
mkdir -p "$o/db/migrations"
|
|
225
|
+
git -C "$o" init -q -b main
|
|
226
|
+
printf 'CREATE TABLE x (id INTEGER);\n' > "$o/db/migrations/0003_x.sql"
|
|
227
|
+
git -C "$o" add db
|
|
228
|
+
git -C "$o" -c user.name=t -c user.email=t@e.invalid commit -qm lone
|
|
229
|
+
r="$(fresh orphan)"
|
|
230
|
+
git -C "$r" fetch -q "$o" main:refs/heads/lone
|
|
231
|
+
printf 'CREATE TABLE m (id INTEGER);\n' > "$r/db/migrations/0003_mine.sql"
|
|
232
|
+
out="$(guard "$r")"; rc=$?
|
|
233
|
+
expect orphan 0 'clean (3 migration(s), 1 added, against merge base' "$rc" "$out"
|
|
234
|
+
expect orphan-unread 0 ', 0 other ref(s) read' "$rc" "$out"
|
|
235
|
+
r="$SANDBOX/clash"
|
|
236
|
+
refs() { # refs <value> — the gate in the clash repository under GATE_SDK_MIGRATION_REFS=<value>
|
|
237
|
+
( cd "$r" && gate_env GATE_SDK_MIGRATION_DIR=db/migrations GATE_SDK_MIGRATION_DESTRUCTIVE="$LIST" \
|
|
238
|
+
GATE_SDK_MIGRATION_REFS="$1" && gate_run check-migration-guard "$CHECKS" 2>&1 )
|
|
239
|
+
}
|
|
240
|
+
out="$(refs none)"; rc=$?
|
|
241
|
+
expect refs-none 0 '; clash check off: GATE_SDK_MIGRATION_REFS is none' "$rc" "$out"
|
|
242
|
+
out="$(refs 'refs/heads/feat/**')"; rc=$?
|
|
243
|
+
expect refs-narrowed 0 ', 0 other ref(s) read' "$rc" "$out"
|
|
244
|
+
out="$(refs -x)"; rc=$?
|
|
245
|
+
expect refs-option 2 "'-x' opens with '-'" "$rc" "$out"
|
|
246
|
+
|
|
247
|
+
# --- a stray file is 3; an unresolved base, a malformed list and a bad argument are 2.
|
|
248
|
+
r="$(fresh refusals)"
|
|
249
|
+
printf 'notes\n' > "$r/db/migrations/README.md"
|
|
250
|
+
out="$(guard "$r")"; rc=$?
|
|
251
|
+
expect stray 3 'db/migrations/README.md: not a migration file' "$rc" "$out"
|
|
252
|
+
rm "$r/db/migrations/README.md"
|
|
253
|
+
out="$(guard "$r" --base nope)"; rc=$?
|
|
254
|
+
expect base-unresolved 2 "base 'nope' names no commit" "$rc" "$out"
|
|
255
|
+
out="$( cd "$r" && gate_env GATE_SDK_MIGRATION_DIR=db/migrations GATE_SDK_BASE_REF=trunk \
|
|
256
|
+
GATE_SDK_MIGRATION_DESTRUCTIVE="$LIST" && gate_run check-migration-guard "$CHECKS" 2>&1 )"; rc=$?
|
|
257
|
+
expect base-knob 2 "base 'trunk' names no commit" "$rc" "$out"
|
|
258
|
+
printf 'DROP (TABLE\n' > "$SANDBOX/bad.list"
|
|
259
|
+
out="$( cd "$r" && gate_env GATE_SDK_MIGRATION_DIR=db/migrations GATE_SDK_MIGRATION_DESTRUCTIVE="$SANDBOX/bad.list" \
|
|
260
|
+
&& gate_run check-migration-guard "$CHECKS" 2>&1 )"; rc=$?
|
|
261
|
+
expect list-malformed 2 'bad.list:1:' "$rc" "$out"
|
|
262
|
+
out="$(guard "$r" --base main --base-dir db)"; rc=$?
|
|
263
|
+
expect base-and-dir 2 'takes no --base' "$rc" "$out"
|
|
264
|
+
out="$(guard "$r" --since main)"; rc=$?
|
|
265
|
+
expect usage 2 "unknown argument '--since'" "$rc" "$out"
|
|
266
|
+
|
|
267
|
+
# --- outside a work tree there is no corpus, which is refused, never clean.
|
|
268
|
+
out="$( cd "$SANDBOX/plain" && gate_env GATE_SDK_MIGRATION_DIR=db/migrations \
|
|
269
|
+
&& gate_run check-migration-guard "$CHECKS" 2>&1 )"; rc=$?
|
|
270
|
+
expect no-work-tree 2 'not a git repository' "$rc" "$out"
|
|
271
|
+
|
|
272
|
+
if [[ "$fails" -gt 0 ]]; then
|
|
273
|
+
echo "check-migration-guard.test.sh: $fails case(s) failed"
|
|
274
|
+
exit 1
|
|
275
|
+
fi
|
|
276
|
+
echo "check-migration-guard.test.sh: clean (the git arm's edit, checkout-form, attribute-drift, missing-driver, delete, rename, order, width, duplicate, clash, ref-set and destructive cases, and its exit classes — $cases cases)"
|
|
277
|
+
exit 0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
GATE_SDK_DENY_TERMS = terms.list
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
f
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
a
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
b
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
c
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
e
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
d
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PATH-NAMES: clean (5 tracked path(s) read; no component carries one of the 1 deny term(s) as its stem)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
GATE_SDK_DENY_TERMS = terms.list
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
foo
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
b
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
a
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
c
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Behavioral test of check-path-names over the arms the good/+bad/ pair cannot
|
|
3
|
+
# reach: each expect.txt line is an independent substring assertion, so the
|
|
4
|
+
# absence of a record under a directory hit and the record order live here, as
|
|
5
|
+
# do a cwd outside any work tree and a configuration naming no live term.
|
|
6
|
+
#
|
|
7
|
+
# Run by the --run-gate-tests arm (any <tests-dir>/*.test.sh; must exit 0).
|
|
8
|
+
set -uo pipefail
|
|
9
|
+
source "$(dirname "${BASH_SOURCE[0]}")/../../gate-sdk/lib/test-hermetic.sh"
|
|
10
|
+
|
|
11
|
+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" # gate-sdk/
|
|
12
|
+
CHECKS="$DIR/checks"
|
|
13
|
+
CASES="$DIR/gate-tests/check-path-names"
|
|
14
|
+
SANDBOX="$(mktemp -d)"
|
|
15
|
+
trap 'rm -rf "$SANDBOX"' EXIT
|
|
16
|
+
|
|
17
|
+
fails=0
|
|
18
|
+
|
|
19
|
+
expect() { # expect <label> <want-rc> <substring> <got-rc> <output>
|
|
20
|
+
if [[ "$4" -ne "$2" ]]; then
|
|
21
|
+
echo " FAIL [$1]: want exit $2, got $4 -- $5"; fails=$((fails + 1))
|
|
22
|
+
elif ! grep -qF -- "$3" <<<"$5"; then
|
|
23
|
+
echo " FAIL [$1]: exit $2 but output lacks '$3': $5"; fails=$((fails + 1))
|
|
24
|
+
fi
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
# --- outside a work tree there is no tracked path set to be clean about: refused at 2.
|
|
28
|
+
mkdir -p "$SANDBOX/plain"
|
|
29
|
+
printf 'foo\n' > "$SANDBOX/plain/terms.list"
|
|
30
|
+
out="$( cd "$SANDBOX/plain" && gate_env GATE_SDK_DENY_TERMS=terms.list \
|
|
31
|
+
&& gate_run check-path-names "$CHECKS" 2>&1 )"; rc=$?
|
|
32
|
+
expect non-repo 2 'not a git repository' "$rc" "$out"
|
|
33
|
+
|
|
34
|
+
# --- a list holding only comments and blanks configures no term: clean, not applicable.
|
|
35
|
+
mkdir -p "$SANDBOX/repo"
|
|
36
|
+
git -C "$SANDBOX/repo" init -q
|
|
37
|
+
printf '# rule: CODENAME\n\n' > "$SANDBOX/repo/terms.list"
|
|
38
|
+
out="$( cd "$SANDBOX/repo" && gate_env GATE_SDK_DENY_TERMS=terms.list \
|
|
39
|
+
&& gate_run check-path-names "$CHECKS" 2>&1 )"; rc=$?
|
|
40
|
+
expect no-term 0 'not applicable: no deny term configured' "$rc" "$out"
|
|
41
|
+
|
|
42
|
+
# --- the bad pair's full record set, in order: one record at the directory hit, none for
|
|
43
|
+
# the term-named file under it, and nothing for the tracked list itself.
|
|
44
|
+
out="$( cd "$CASES/bad" && gate_env GATE_SDK_DENY_TERMS=terms.list \
|
|
45
|
+
&& gate_run check-path-names "$CHECKS" 2>&1 )"; rc=$?
|
|
46
|
+
got="$(grep -E '^tree/' <<<"$out")"
|
|
47
|
+
want="$(printf '%s\n' \
|
|
48
|
+
'tree/ZePhYr.md: [CODENAME]' \
|
|
49
|
+
'tree/foo: [NAMES-DENIED]' \
|
|
50
|
+
'tree/foo-cli.sh: [NAMES-DENIED]' \
|
|
51
|
+
'tree/foo.rs: [NAMES-DENIED]' \
|
|
52
|
+
'tree/foo_x.txt: [NAMES-DENIED]')"
|
|
53
|
+
if [[ "$rc" -ne 1 ]]; then
|
|
54
|
+
echo " FAIL [record-set]: want exit 1, got $rc -- $out"; fails=$((fails + 1))
|
|
55
|
+
elif [[ "$got" != "$want" ]]; then
|
|
56
|
+
echo " FAIL [record-set]: records are not the shortest-prefix set in path order:"
|
|
57
|
+
printf ' %s\n' "$got"
|
|
58
|
+
fails=$((fails + 1))
|
|
59
|
+
fi
|
|
60
|
+
|
|
61
|
+
if [[ "$fails" -gt 0 ]]; then
|
|
62
|
+
echo "check-path-names.test.sh: $fails case(s) failed"
|
|
63
|
+
exit 1
|
|
64
|
+
fi
|
|
65
|
+
echo "check-path-names.test.sh: clean (the arms a case dir cannot reach: a cwd outside a work tree, a list with no live term, and the bad pair's exact record set — 3 cases)"
|
|
66
|
+
exit 0
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
early-exit reader(s) fed under `pipefail`
|
|
2
|
+
tree/over.sh:4: [PIPEFAIL-EARLY-EXIT] head [auto-fix]
|
|
3
|
+
tree/over.sh:5: [PIPEFAIL-EARLY-EXIT] grep -q [auto-fix]
|
|
4
|
+
tree/readers.sh:4: [PIPEFAIL-EARLY-EXIT] grep -q [auto-fix]
|
|
5
|
+
tree/readers.sh:5: [PIPEFAIL-EARLY-EXIT] grep -m [auto-fix]
|
|
6
|
+
tree/readers.sh:6: [PIPEFAIL-EARLY-EXIT] grep -l
|
|
7
|
+
tree/readers.sh:7: [PIPEFAIL-EARLY-EXIT] head [auto-fix]
|
|
8
|
+
tree/readers.sh:8: [PIPEFAIL-EARLY-EXIT] read
|
|
9
|
+
tree/readers.sh:9: [PIPEFAIL-EARLY-EXIT] sed q
|
|
10
|
+
tree/readers.sh:10: [PIPEFAIL-EARLY-EXIT] awk exit
|
|
11
|
+
tree/readers.sh:11: [PIPEFAIL-EARLY-EXIT] while-read break
|
|
12
|
+
tree/readers.sh:14: [PIPEFAIL-EARLY-EXIT] grep -q [auto-fix]
|
|
13
|
+
tree/readers.sh:16: [PIPEFAIL-EARLY-EXIT] waiver reason under 1 characters [auto-fix]
|
|
14
|
+
tree/shared-lib.sh:3: [PIPEFAIL-EARLY-EXIT] head [auto-fix]
|
|
15
|
+
tree/gone.sh: [BASELINE-STALE] 0/2
|
|
16
|
+
tree/stale.sh: [BASELINE-STALE] 1/3
|
|
17
|
+
--emit pipefail-fix <path>…
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# One site per early-exit reader, under pipefail from the set.
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
ls | grep -q x
|
|
5
|
+
ls | grep -m 1 x
|
|
6
|
+
ls | grep -l x
|
|
7
|
+
ls | head -n 3
|
|
8
|
+
ls | read -r first
|
|
9
|
+
ls | sed '/x/q'
|
|
10
|
+
ls | awk '/x/ { print; exit }'
|
|
11
|
+
ls | while read -r l; do
|
|
12
|
+
[[ "$l" == x ]] && break
|
|
13
|
+
done
|
|
14
|
+
v="$(ls |
|
|
15
|
+
grep -Fxq x && echo y)"
|
|
16
|
+
ls | grep -q x # pipefail-ok:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
PIPEFAIL-READERS: clean (3 shell file(s) read, 2 linted under `pipefail`; 2 early-exit reader(s) within the baseline)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Early-exit readers before the set, a guarded producer, a waived site, full readers, and
|
|
3
|
+
# early-exit text inside quotes, a here-doc and a case pattern.
|
|
4
|
+
ls | head -1
|
|
5
|
+
set -euo pipefail
|
|
6
|
+
{ ls || true; } | head -1
|
|
7
|
+
ls | grep -q x # pipefail-ok: the listing is one directory, read whole before grep exits
|
|
8
|
+
ls | grep -c x
|
|
9
|
+
ls | sed -n '1,3p'
|
|
10
|
+
ls | awk '{ print $1 }'
|
|
11
|
+
echo "a | head -1"
|
|
12
|
+
cat <<'EOF'
|
|
13
|
+
ls | grep -q x
|
|
14
|
+
EOF
|
|
15
|
+
case "$1" in
|
|
16
|
+
a|b) ls | sort ;;
|
|
17
|
+
esac
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Behavioral test of check-pipefail-readers and its fix arm over what the good/+bad/ pair
|
|
3
|
+
# cannot reach: an empty configuration, operands, the exit-2 and exit-3 classes, the
|
|
4
|
+
# whole-file knob, the prune set, and the arm rewriting a tree in place.
|
|
5
|
+
#
|
|
6
|
+
# Run by the --run-gate-tests arm (any <tests-dir>/*.test.sh; must exit 0).
|
|
7
|
+
set -uo pipefail
|
|
8
|
+
source "$(dirname "${BASH_SOURCE[0]}")/../../gate-sdk/lib/test-hermetic.sh"
|
|
9
|
+
|
|
10
|
+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" # gate-sdk/
|
|
11
|
+
CHECKS="$DIR/checks"
|
|
12
|
+
CASES="$DIR/gate-tests/check-pipefail-readers"
|
|
13
|
+
SANDBOX="$(mktemp -d)"
|
|
14
|
+
trap 'rm -rf "$SANDBOX"' EXIT
|
|
15
|
+
|
|
16
|
+
fails=0
|
|
17
|
+
cases=0
|
|
18
|
+
|
|
19
|
+
expect() { # expect <label> <want-rc> <substring> <got-rc> <output>
|
|
20
|
+
cases=$((cases + 1))
|
|
21
|
+
if [[ "$4" -ne "$2" ]]; then
|
|
22
|
+
echo " FAIL [$1]: want exit $2, got $4 -- $5"; fails=$((fails + 1))
|
|
23
|
+
elif ! grep -qF -- "$3" <<<"$5"; then
|
|
24
|
+
echo " FAIL [$1]: exit $2 but output lacks '$3': $5"; fails=$((fails + 1))
|
|
25
|
+
fi
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
refute() { # refute <label> <substring> <output>
|
|
29
|
+
if grep -qF -- "$2" <<<"$3"; then
|
|
30
|
+
echo " FAIL [$1]: output holds '$2': $3"; fails=$((fails + 1))
|
|
31
|
+
fi
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
# --- no path configured: clean, not applicable.
|
|
35
|
+
mkdir -p "$SANDBOX/empty"
|
|
36
|
+
out="$( cd "$SANDBOX/empty" && gate_run check-pipefail-readers "$CHECKS" 2>&1 )"; rc=$?
|
|
37
|
+
expect not-applicable 0 'not applicable: no shell path configured' "$rc" "$out"
|
|
38
|
+
|
|
39
|
+
# --- an operand naming nothing on disk is refused at 2.
|
|
40
|
+
out="$( cd "$SANDBOX/empty" && gate_run check-pipefail-readers "$CHECKS" gone.sh 2>&1 )"; rc=$?
|
|
41
|
+
expect absent-operand 2 'no shell file or directory at gone.sh' "$rc" "$out"
|
|
42
|
+
|
|
43
|
+
# --- an operand narrows the corpus: only its records, and no stale row for a file outside it.
|
|
44
|
+
out="$( cd "$CASES/bad" && gate_env GATE_SDK_PIPEFAIL_BASELINE=baseline.tsv \
|
|
45
|
+
&& gate_run check-pipefail-readers "$CHECKS" tree/over.sh 2>&1 )"; rc=$?
|
|
46
|
+
expect operand 1 'tree/over.sh:5: [PIPEFAIL-EARLY-EXIT] grep -q [auto-fix]' "$rc" "$out"
|
|
47
|
+
refute operand-readers 'tree/readers.sh' "$out"
|
|
48
|
+
refute operand-stale 'BASELINE-STALE' "$out"
|
|
49
|
+
|
|
50
|
+
# --- the whole-file knob lints a file that never sets pipefail.
|
|
51
|
+
out="$( cd "$CASES/good" && gate_env GATE_SDK_PIPEFAIL_PATHS=tree GATE_SDK_PIPEFAIL_BASELINE=baseline.tsv GATE_SDK_PIPEFAIL_ALL=1 \
|
|
52
|
+
&& gate_run check-pipefail-readers "$CHECKS" 2>&1 )"; rc=$?
|
|
53
|
+
expect all-files 1 'tree/no-pipefail.sh:3: [PIPEFAIL-EARLY-EXIT] head [auto-fix]' "$rc" "$out"
|
|
54
|
+
|
|
55
|
+
# --- a value outside 0|1 is refused at 2.
|
|
56
|
+
out="$( cd "$SANDBOX/empty" && gate_env GATE_SDK_PIPEFAIL_ALL=yes \
|
|
57
|
+
&& gate_run check-pipefail-readers "$CHECKS" 2>&1 )"; rc=$?
|
|
58
|
+
expect all-value 2 'GATE_SDK_PIPEFAIL_ALL must be 0|1' "$rc" "$out"
|
|
59
|
+
|
|
60
|
+
# --- the waiver floor is the consumer's: a five-character reason the default passes reds under
|
|
61
|
+
# a floor of 10, and a value that is no positive integer is refused at 2.
|
|
62
|
+
mkdir -p "$SANDBOX/floor"
|
|
63
|
+
printf '#!/usr/bin/env bash\nset -o pipefail\nls | head -1 # pipefail-ok: short\n' > "$SANDBOX/floor/waived.sh"
|
|
64
|
+
out="$( cd "$SANDBOX/floor" && gate_run check-pipefail-readers "$CHECKS" waived.sh 2>&1 )"; rc=$?
|
|
65
|
+
expect floor-default 0 'clean (1 shell file(s) read' "$rc" "$out"
|
|
66
|
+
out="$( cd "$SANDBOX/floor" && gate_env GATE_SDK_PIPEFAIL_WAIVER_MIN=10 \
|
|
67
|
+
&& gate_run check-pipefail-readers "$CHECKS" waived.sh 2>&1 )"; rc=$?
|
|
68
|
+
expect floor-raised 1 'waived.sh:3: [PIPEFAIL-EARLY-EXIT] waiver reason under 10 characters' "$rc" "$out"
|
|
69
|
+
out="$( cd "$SANDBOX/floor" && gate_env GATE_SDK_PIPEFAIL_WAIVER_MIN=0 \
|
|
70
|
+
&& gate_run check-pipefail-readers "$CHECKS" waived.sh 2>&1 )"; rc=$?
|
|
71
|
+
expect floor-value 2 'GATE_SDK_PIPEFAIL_WAIVER_MIN must be a positive integer' "$rc" "$out"
|
|
72
|
+
|
|
73
|
+
# --- a span the reader cannot read is LINT-PARSE at 3, and the fix arm writes nothing to it.
|
|
74
|
+
mkdir -p "$SANDBOX/parse"
|
|
75
|
+
printf '#!/usr/bin/env bash\nset -o pipefail\necho "open\nls | head -1\n' > "$SANDBOX/parse/broken.sh"
|
|
76
|
+
cp "$SANDBOX/parse/broken.sh" "$SANDBOX/parse.orig"
|
|
77
|
+
out="$( cd "$SANDBOX/parse" && gate_run check-pipefail-readers "$CHECKS" broken.sh 2>&1 )"; rc=$?
|
|
78
|
+
expect lint-parse 3 'broken.sh:3: [LINT-PARSE]' "$rc" "$out"
|
|
79
|
+
out="$( cd "$SANDBOX/parse" && gate_arm_run --emit pipefail-fix broken.sh 2>&1 )"; rc=$?
|
|
80
|
+
expect fix-unparsed 3 'could not rewrite' "$rc" "$out"
|
|
81
|
+
cmp -s "$SANDBOX/parse/broken.sh" "$SANDBOX/parse.orig" \
|
|
82
|
+
|| { echo " FAIL [fix-unparsed]: the arm wrote to an unparseable file"; fails=$((fails + 1)); }
|
|
83
|
+
|
|
84
|
+
# --- a baseline: absent is refused at 2, a malformed row is exit 3 naming its line.
|
|
85
|
+
mkdir -p "$SANDBOX/base"
|
|
86
|
+
printf '#!/usr/bin/env bash\nset -o pipefail\nls | head -1\n' > "$SANDBOX/base/one.sh"
|
|
87
|
+
out="$( cd "$SANDBOX/base" && gate_env GATE_SDK_PIPEFAIL_PATHS=. GATE_SDK_PIPEFAIL_BASELINE=missing.tsv \
|
|
88
|
+
&& gate_run check-pipefail-readers "$CHECKS" 2>&1 )"; rc=$?
|
|
89
|
+
expect baseline-absent 2 'missing.tsv' "$rc" "$out"
|
|
90
|
+
printf '# rows\none\tone.sh\n' > "$SANDBOX/base/bad.tsv"
|
|
91
|
+
out="$( cd "$SANDBOX/base" && gate_env GATE_SDK_PIPEFAIL_PATHS=. GATE_SDK_PIPEFAIL_BASELINE=bad.tsv \
|
|
92
|
+
&& gate_run check-pipefail-readers "$CHECKS" 2>&1 )"; rc=$?
|
|
93
|
+
expect baseline-malformed 3 'bad.tsv:2' "$rc" "$out"
|
|
94
|
+
|
|
95
|
+
# --- a directory in the prune set is never walked.
|
|
96
|
+
mkdir -p "$SANDBOX/prune/node_modules/pkg"
|
|
97
|
+
cp "$SANDBOX/base/one.sh" "$SANDBOX/prune/node_modules/pkg/one.sh"
|
|
98
|
+
out="$( cd "$SANDBOX/prune" && gate_env GATE_SDK_PIPEFAIL_PATHS=. \
|
|
99
|
+
&& gate_run check-pipefail-readers "$CHECKS" 2>&1 )"; rc=$?
|
|
100
|
+
expect prune 0 'clean (0 shell file(s) read' "$rc" "$out"
|
|
101
|
+
|
|
102
|
+
# --- the fix arm rewrites every auto-fix site in place, keeps the mode, and leaves the hand fixes.
|
|
103
|
+
mkdir -p "$SANDBOX/fix"
|
|
104
|
+
cp "$CASES/bad/tree/readers.sh" "$CASES/bad/tree/over.sh" "$SANDBOX/fix/"
|
|
105
|
+
chmod 755 "$SANDBOX/fix/readers.sh"
|
|
106
|
+
out="$( cd "$SANDBOX/fix" && gate_arm_run --emit pipefail-fix . 2>&1 )"; rc=$?
|
|
107
|
+
expect fix-run 0 'readers.sh:5: fixed' "$rc" "$out"
|
|
108
|
+
expect fix-other 0 'over.sh:4: fixed' "$rc" "$out"
|
|
109
|
+
[[ -x "$SANDBOX/fix/readers.sh" ]] \
|
|
110
|
+
|| { echo " FAIL [fix-mode]: the rewrite dropped the file's mode"; fails=$((fails + 1)); }
|
|
111
|
+
grep -qxF "ls | grep x | sed -n '1,1p'" "$SANDBOX/fix/readers.sh" \
|
|
112
|
+
|| { echo " FAIL [fix-text]: grep -m 1 was not rewritten to a sed range"; fails=$((fails + 1)); }
|
|
113
|
+
out="$( cd "$SANDBOX/fix" && gate_env GATE_SDK_PIPEFAIL_PATHS=. \
|
|
114
|
+
&& gate_run check-pipefail-readers "$CHECKS" 2>&1 )"; rc=$?
|
|
115
|
+
expect fix-leaves 1 'readers.sh:11: [PIPEFAIL-EARLY-EXIT] while-read break' "$rc" "$out"
|
|
116
|
+
refute fix-leaves '[auto-fix]' "$out"
|
|
117
|
+
|
|
118
|
+
# --- with no path configured the arm has nothing to rewrite.
|
|
119
|
+
out="$( cd "$SANDBOX/empty" && gate_arm_run --emit pipefail-fix 2>&1 )"; rc=$?
|
|
120
|
+
expect fix-empty 0 'nothing to rewrite' "$rc" "$out"
|
|
121
|
+
|
|
122
|
+
if [[ "$fails" -gt 0 ]]; then
|
|
123
|
+
echo "check-pipefail-readers.test.sh: $fails case(s) failed"
|
|
124
|
+
exit 1
|
|
125
|
+
fi
|
|
126
|
+
echo "check-pipefail-readers.test.sh: clean (configuration, operands, exit classes, the whole-file knob, the waiver floor, pruning and the fix arm — $cases cases)"
|
|
127
|
+
exit 0
|