Comments that pointed at other YAML as `file.yaml:N` went stale on any edit above the cited line; three drift fixes had been merged by hand (REN-181). The cited block now carries `# anchor: <name>` and the comment cites `path.yaml#<name>`. - Sweep: all 32 line-number citations in YAML comments converted. Several were already stale at head and now point at the right block (see PR). Vendored files (Flux gotk-components, IMC CRD) get no anchor; those two citations name the object/schema path instead. - Guard: scripts/ci/yaml-citations.sh in ci-manifests-test.yml; fails on a line-number citation or a path#name whose file/anchor is gone. Self-test in ci-scripts-test.yml. - CONTRIBUTING.md: the convention in three lines. Comment-only under kubernetes/: every file parses to identical objects before and after, so Flux applies nothing and no ConfigMap data changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
63 lines
2.1 KiB
Bash
63 lines
2.1 KiB
Bash
#!/bin/sh
|
|
# Offline self-test for yaml-citations.sh: each case is a small fixture tree
|
|
# that must FAIL (or, for happy-path, PASS). Run: sh scripts/ci/test-yaml-citations.sh
|
|
set -eu
|
|
|
|
HERE="$(cd "$(dirname "$0")" && pwd)"
|
|
SUT="$HERE/yaml-citations.sh"
|
|
[ -f "$SUT" ] || { echo "FAIL: $SUT not found"; exit 1; }
|
|
|
|
TMP="$(mktemp -d)"
|
|
trap 'rm -rf "$TMP"' EXIT INT TERM
|
|
fails=0
|
|
|
|
# new_tree NAME — a fixture with one anchored target the cases can cite.
|
|
new_tree() {
|
|
d="$TMP/$1"; mkdir -p "$d/k/a" "$d/k/b"
|
|
printf 'kind: X\n# anchor: target-block\nspec: {}\n' > "$d/k/a/target.yaml"
|
|
echo "$d"
|
|
}
|
|
|
|
# expect CASE want(pass|fail) DIR
|
|
expect() {
|
|
if YAML_CITATIONS_FLOOR=1 sh "$SUT" "$3" > "$TMP/$1.out" 2>&1; then got=pass; else got=fail; fi
|
|
if [ "$got" = "$2" ]; then echo "ok $1 ($got)"
|
|
else echo "FAIL $1: wanted $2, got $got"; sed 's/^/ /' "$TMP/$1.out"; fails=1; fi
|
|
}
|
|
|
|
d=$(new_tree happy-path)
|
|
printf '# see target.yaml#target-block and ../a/target.yaml#target-block\nx: 1\n' > "$d/k/a/same-dir.yaml"
|
|
printf '# root-relative: k/a/target.yaml#target-block\nx: 1\n' > "$d/k/b/root.yaml"
|
|
printf 'url: "http://h/p.yaml#frag" # a # inside a value is not a comment\n' > "$d/k/b/url.yaml"
|
|
expect happy-path pass "$d"
|
|
|
|
d=$(new_tree line-number)
|
|
printf '# see ../a/target.yaml:2\nx: 1\n' > "$d/k/b/c.yaml"
|
|
expect line-number fail "$d"
|
|
|
|
d=$(new_tree line-range-yml)
|
|
printf '# see ../a/target.yml:2-3\nx: 1\n' > "$d/k/b/c.yml"
|
|
expect line-range-yml fail "$d"
|
|
|
|
d=$(new_tree missing-file)
|
|
printf '# see ../a/gone.yaml#target-block\nx: 1\n' > "$d/k/b/c.yaml"
|
|
expect missing-file fail "$d"
|
|
|
|
d=$(new_tree missing-anchor)
|
|
printf '# see ../a/target.yaml#no-such-block\nx: 1\n' > "$d/k/b/c.yaml"
|
|
expect missing-anchor fail "$d"
|
|
|
|
d=$(new_tree duplicate-anchor)
|
|
printf '# anchor: target-block\n' >> "$d/k/a/target.yaml"
|
|
expect duplicate-anchor fail "$d"
|
|
|
|
d=$(new_tree malformed-anchor)
|
|
printf '# anchor: Not_Kebab\nx: 1\n' > "$d/k/b/c.yaml"
|
|
expect malformed-anchor fail "$d"
|
|
|
|
d="$TMP/empty-discovery"; mkdir -p "$d"
|
|
if sh "$SUT" "$d" > "$TMP/empty.out" 2>&1; then echo "FAIL empty-discovery: passed with no files"; fails=1
|
|
else echo "ok empty-discovery (fail)"; fi
|
|
|
|
exit $fails
|