diff --git a/hydra-gates/scripts/lib/test_or_abstraction_exceptions.sh b/hydra-gates/scripts/lib/test_or_abstraction_exceptions.sh new file mode 100755 index 000000000..f89acde2c --- /dev/null +++ b/hydra-gates/scripts/lib/test_or_abstraction_exceptions.sh @@ -0,0 +1,329 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: EUPL-1.2 +# +# test_or_abstraction_exceptions.sh — self-test for the ADR-022 exception path +# in scripts/lint-or-abstraction-anti-patterns.sh. +# +# WHY THIS EXISTS +# --------------- +# ADR-022 says an exception applies where it is recorded in an app-local ADR, +# and it ships a worked example. Until 2026-09-11 the gate asked only in rule 7 +# (the ADR-051 capability table): `_cap_suppressed()` was defined once, below +# rules 2 to 6, and called from the rule-7 loop alone. Rules 2 to 6 had no +# exception path at all, so the gate was narrower than the ADR it enforces. +# +# Two of those rules match on FILE NAME. In dossiq that flagged +# lib/Service/TenantService.php and lib/Service/TenantAuditTrailService.php — +# the two classes that already consume OpenRegister's OrganisationMapper, +# TenantLifecycleService and AuditTrailMapper. The only way to clear a name +# rule is a rename, which changes nothing. The gate penalised the correct +# architecture and rewarded a cosmetic edit. +# +# WHAT THIS SUITE RATCHETS +# ------------------------ +# An exception path is a hole by construction, so every assertion below is +# about the hole's edges: +# +# * a flagged file with NO ADR still fails (the positive control) +# * an ADR that does not cite ADR-022 buys nothing +# * an ADR naming a SIBLING path buys nothing +# * every suppression is PRINTED with its ADR (no silent exceptions) +# * an ADR with NO sunset suppresses but is PRINTED as a warning, so it +# cannot become permanent quietly +# * an ADR whose sunset has PASSED stops suppressing +# * an audit-trail file that CALLS AuditTrailMapper is compliant and printed; +# a file that only names it in a COMMENT is not +# +# Run: bash scripts/lib/test_or_abstraction_exceptions.sh (exit 0 = pass) +# +# Set GATE= to point the suite at another copy of the gate script. That +# is how these assertions were mutation-checked: run against the pre-change +# script and the suppression, sunset and consumer arms all go red. +set -uo pipefail + +LIB_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)" +GATE="${GATE:-${LIB_DIR}/../lint-or-abstraction-anti-patterns.sh}" + +if [ ! -f "${GATE}" ]; then + echo "FAIL — gate script not found at ${GATE}; this suite cannot assert anything." + echo "Refusing to report passes for a subject that is absent." + exit 1 +fi + +FAILS=0 +WORK="$(mktemp -d)" +trap 'rm -rf "${WORK}"' EXIT + +mkdir -p "${WORK}/lib/Service" "${WORK}/lib/Middleware" "${WORK}/appinfo" "${WORK}/openspec/architecture" +printf '\n\n fixtureapp\n\n' > "${WORK}/appinfo/info.xml" + +FUTURE="$(date -u -d '+180 days' +%Y-%m-%d)" +PAST="$(date -u -d '-2 days' +%Y-%m-%d)" + +# Force BOTH epochs so the exit status carries the verdict for the umbrella +# rules AND the capability table. In WARN mode the script returns 0 whether or +# not anything matched, so a suite reading the byte in WARN mode asserts +# nothing — which is how these findings stayed invisible in the first place. +run_gate() ( + cd "${WORK}" \ + && HYDRA_OR_GATE_BLOCK_AFTER_EPOCH=0 \ + HYDRA_OR_CAPABILITY_GATE_BLOCK_AFTER_EPOCH=0 \ + bash "${GATE}" >"${WORK}/.out" 2>&1 + echo $? +) + +assert_rc() { #