bigpowers 2.58.2 → 2.58.4

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.
@@ -1,31 +1,8 @@
1
1
  #!/usr/bin/env bash
2
2
  # story: e38s09
3
- #
4
- # validate-okf.sh — provenance gate for OKF bundles (e40/e31/e44 style).
5
- #
6
- # Kind-aware: validates story-metrics, spec-migration, and migration-registry
7
- # bundles against their respective schemas. Fail-closed: unknown flags exit 2,
8
- # missing directories exit 1. Multi-dir default scans specs/metrics/ AND
9
- # specs/migrations/.
10
- #
11
- # A story-metrics bundle is valid iff:
12
- # 1. The generator ran (generator field matches scripts/record-cycle-time.sh).
13
- # 2. commit_range resolves to real commits in the repo.
14
- # 3. Source enum is valid (measured|estimated|backfilled).
15
- # 4. Required keys are present with non-null values.
16
- #
17
- # A spec-migration bundle is valid iff:
18
- # 1. id, title, since_version, order, actions_needed are present.
19
- # 2. fingerprint.any has at least one file/exists check.
20
- #
21
- # A migration-registry bundle is valid iff:
22
- # 1. migrations list has at least one entry with id + file + status.
23
- #
24
- # This script gates on PROVENANCE, NEVER on a specific metric value.
25
- #
26
- # Usage:
27
- # scripts/validate-okf.sh [--dir <path>] [--bundle <file>] [--help]
28
- #
3
+ # validate-okf.sh — kind-aware, fail-closed provenance gate for OKF bundles.
4
+ # Validates story-metrics, spec-migration, and migration-registry bundles.
5
+ # Multi-dir default: specs/metrics/ + specs/migrations/.
29
6
  set -euo pipefail
30
7
 
31
8
  ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" || { echo "validate-okf: not inside a git repo"; exit 1; }
@@ -33,7 +10,7 @@ EXIT_CODE=0
33
10
 
34
11
  RED='\033[0;31m'; GREEN='\033[0;32m'; YELLOW='\033[0;33m'; NC='\033[0m'
35
12
 
36
- usage() {
13
+ usage_okf() {
37
14
  cat <<'EOF'
38
15
  Usage: scripts/validate-okf.sh [flags]
39
16
 
@@ -55,6 +32,14 @@ EOF
55
32
  exit 0
56
33
  }
57
34
 
35
+ # ---- Helpers ------------------------------------------------------------
36
+
37
+ # True if value is empty, null JSON literal, or Python None string.
38
+ val_nullish() { [ -z "$1" ] || [ "$1" = "null" ] || [ "$1" = "None" ]; }
39
+
40
+ # True if value is nullish OR the JSON empty array literal.
41
+ val_nullish_or_empty() { val_nullish "$1" || [ "$1" = "[]" ]; }
42
+
58
43
  # ---- YAML frontmatter parser (datetime-safe) ---------------------------
59
44
  parse_frontmatter() {
60
45
  local file="$1"
@@ -89,11 +74,10 @@ validate_story_metrics() {
89
74
  local file="$1" fm="$2" name="$3"
90
75
  local errs=0
91
76
 
92
- # Required keys
93
77
  for key in id epic bcps commit_range source generated_at generator; do
94
78
  local val
95
79
  val="$(echo "$fm" | python3 -c "import json,sys; d=json.load(sys.stdin); print(d.get('$key',''))" 2>/dev/null)"
96
- if [ -z "$val" ] || [ "$val" = "null" ] || [ "$val" = "None" ]; then
80
+ if val_nullish "$val"; then
97
81
  printf "${RED}FAIL${NC} %s: missing required key '%s'\n" "$name" "$key"
98
82
  errs=$((errs + 1))
99
83
  fi
@@ -150,11 +134,10 @@ validate_spec_migration() {
150
134
  local file="$1" fm="$2" name="$3"
151
135
  local errs=0
152
136
 
153
- # Required keys
154
137
  for key in id title since_version order actions_needed; do
155
138
  local val
156
139
  val="$(echo "$fm" | python3 -c "import json,sys; d=json.load(sys.stdin); print(d.get('$key',''))" 2>/dev/null)"
157
- if [ -z "$val" ] || [ "$val" = "null" ] || [ "$val" = "None" ] || [ "$val" = "[]" ]; then
140
+ if val_nullish_or_empty "$val"; then
158
141
  printf "${RED}FAIL${NC} %s: missing required key '%s'\n" "$name" "$key"
159
142
  errs=$((errs + 1))
160
143
  fi
@@ -262,7 +245,6 @@ scan_dir() {
262
245
  # ---- main ----------------------------------------------------------------
263
246
  DIRS=()
264
247
  BUNDLE=""
265
- DEFAULT_DIRS=("$ROOT/specs/metrics" "$ROOT/specs/migrations")
266
248
 
267
249
  if [ $# -eq 0 ]; then
268
250
  DIRS=("$ROOT/specs/metrics" "$ROOT/specs/migrations")
@@ -272,10 +254,10 @@ while [ $# -gt 0 ]; do
272
254
  case "$1" in
273
255
  --dir) DIRS+=("$2"); shift 2 ;;
274
256
  --bundle) BUNDLE="$2"; shift 2 ;;
275
- --help|-h) usage ;;
257
+ --help|-h) usage_okf ;;
276
258
  *)
277
259
  echo "validate-okf: unknown flag: $1" >&2
278
- echo "Run 'scripts/validate-okf.sh --help' for usage." >&2
260
+ echo "Run 'scripts/validate-okf.sh --help' for help." >&2
279
261
  exit 2
280
262
  ;;
281
263
  esac
@@ -18,7 +18,7 @@ BRANCH=$(git branch --show-current 2>/dev/null || echo "main")
18
18
  COMMIT=""
19
19
  OUTPUT_JSON=false
20
20
 
21
- usage() {
21
+ usage_ci() {
22
22
  sed -n '2,12p' "$0" | sed 's/^# //'
23
23
  }
24
24
 
@@ -29,8 +29,8 @@ while [[ $# -gt 0 ]]; do
29
29
  --branch) BRANCH="$2"; shift 2 ;;
30
30
  --commit) COMMIT="$2"; shift 2 ;;
31
31
  --json) OUTPUT_JSON=true; shift ;;
32
- --help) usage; exit 0 ;;
33
- *) echo "Unknown flag: $1"; usage; exit 2 ;;
32
+ --help) usage_ci; exit 0 ;;
33
+ *) echo "Unknown flag: $1"; usage_ci; exit 2 ;;
34
34
  esac
35
35
  done
36
36