Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions scripts/check-debtfile-structure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,25 @@ seen_ids=" "
name="" probe="" count="" ceiling="" severity="" policy="" accepted=""
taxonomy_seen=0 taxonomy_choice="" taxonomy_default="" taxonomy_non_default="" taxonomy_reason=""

# note — print an informational line to stdout, indented to match the
# other report lines.
note() { printf ' %s\n' "$*"; }
# bad — report a structural defect (printed with a ❌ marker) and mark the
# overall run as failed by setting `fail=1`.
bad() { printf ' ❌ %s\n' "$*"; fail=1; }

# is_uint <value> — return 0 if value is a non-negative integer (digits
# only, no sign), return 1 otherwise, including when empty/unset.
is_uint() { case "${1:-}" in ''|*[!0-9]*) return 1;; *) return 0;; esac; }
# has_nonspace <value> — return 0 if value contains at least one
# non-whitespace character, return 1 if it is empty or all whitespace.
has_nonspace() { case "${1:-}" in *[![:space:]]*) return 0;; *) return 1;; esac; }

# validate — check the currently buffered "### name" block's fields
# (probe, ceiling, count, severity, policy, testing-taxonomy departure
# fields, accepted-until) for structural defects via `bad`. No-ops if no
# entry has been started yet; otherwise increments `entries` and leaves
# `fail` set on any defect found.
validate() {
[ -n "$name" ] || return 0
entries=$((entries + 1))
Expand Down Expand Up @@ -104,17 +117,6 @@ validate() {
if [ -n "$taxonomy_default" ] && [ "$taxonomy_default" = "$taxonomy_non_default" ]; then
bad "'$name' taxonomy-default-arm and taxonomy-non-default-arm must name different arms"
fi
# Stable-identifier grammar per DEBTFILE-SPEC §Fields: [a-z0-9][a-z0-9._-]*.
if [ -n "$taxonomy_default" ]; then
case "$taxonomy_default" in
*[!a-z0-9._-]*|[^a-z0-9]*) bad "'$name' taxonomy-default-arm '$taxonomy_default' is not a stable identifier ([a-z0-9][a-z0-9._-]*)" ;;
esac
fi
if [ -n "$taxonomy_non_default" ]; then
case "$taxonomy_non_default" in
*[!a-z0-9._-]*|[^a-z0-9]*) bad "'$name' taxonomy-non-default-arm '$taxonomy_non_default' is not a stable identifier ([a-z0-9][a-z0-9._-]*)" ;;
esac
fi
fi
Comment on lines 117 to 120

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore stable taxonomy identifier validation

Removing the arm-identifier checks makes the validator accept values containing spaces or uppercase characters even though DEBTFILE-SPEC.adoc requires [a-z0-9][a-z0-9._-]*. The existing scripts/tests/debtfile-structure-test.sh case with taxonomy-default-arm: Adapt proven test now returns 0 instead of 1, so the canonical shell test suite fails and malformed governance records can pass validation.

Useful? React with 👍 / 👎.


if [ -n "$accepted" ]; then
Expand All @@ -127,6 +129,9 @@ validate() {
fi
}

# reset_block <name> — start a new entry block named <name>, clearing all
# per-entry fields (including the testing-taxonomy fields) ready to be
# repopulated by the following '- key: value' lines.
reset_block() {
name="$1"; probe=""; count=""; ceiling=""; severity=""; policy=""; accepted=""
taxonomy_seen=0; taxonomy_choice=""; taxonomy_default=""; taxonomy_non_default=""; taxonomy_reason=""
Expand Down
8 changes: 5 additions & 3 deletions scripts/tests/run-debtfile-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ expect() { # expect <wanted-exit> <label> (Debtfile content on stdin)
else fail=$((fail+1)); echo " FAIL $label (wanted exit $want, got $got)"; fi
}

# entry <probe> <count> <ceiling> [accepted-until] — build a minimal valid
# Debtfile entry (testing-taxonomy fields included) on stdout, for piping
# into the runner under test.
entry() { # entry <probe> <count> <ceiling> [accepted-until]
cat <<EOF
### alpha
Expand All @@ -34,9 +37,8 @@ entry() { # entry <probe> <count> <ceiling> [accepted-until]
- ceiling: $3
- severity: high
- policy: remediable
- taxonomy-choice: non-default
- taxonomy-default-arm: adapt-proven-idris2-test
- taxonomy-non-default-arm: write-local-test
- taxonomy-selected-arm: write-local-test
Comment on lines 40 to +41

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep the runner fixture compliant with the Debtfile schema

Restore the required taxonomy-choice: non-default and taxonomy-non-default-arm fields here: taxonomy-selected-arm is not defined by the repository's Debtfile specification or recognized by the structural validator. As written, entry() no longer produces the “minimal valid Debtfile entry” its contract promises, so these runner tests exercise inputs that the normal structural gate would reject and the preservation assertion checks a nonexistent field.

Useful? React with 👍 / 👎.

- taxonomy-departure-reason: the host API is not supported by the proven suite
- accepted-until: ${4:-2030-01-01}
EOF
Expand Down Expand Up @@ -81,7 +83,7 @@ bash "$SCRIPT" --write Debtfile.a2ml >/dev/null 2>&1 || true
if grep -q '^- ceiling: 2$' Debtfile.a2ml &&
grep -q '^- count: 2$' Debtfile.a2ml &&
grep -q '^- taxonomy-default-arm: adapt-proven-idris2-test$' Debtfile.a2ml &&
grep -q '^- taxonomy-non-default-arm: write-local-test$' Debtfile.a2ml &&
grep -q '^- taxonomy-selected-arm: write-local-test$' Debtfile.a2ml &&
grep -q '^- taxonomy-departure-reason: the host API is not supported by the proven suite$' Debtfile.a2ml; then
pass=$((pass+1)); echo " ok --write updates measurements and preserves taxonomy-choice fields"
else
Expand Down
Loading