@chrono-meta/fh-gate 2.8.0 → 2.9.1

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.
Files changed (45) hide show
  1. package/.claude/rules/fh_4axis_gate.md +33 -5
  2. package/.claude-plugin/marketplace.json +2 -2
  3. package/AGENTS.md +5 -0
  4. package/CLAUDE.md +47 -12
  5. package/README.ja.md +44 -29
  6. package/README.ko.md +43 -28
  7. package/README.md +48 -33
  8. package/README.zh.md +41 -28
  9. package/docs/ETHOS.md +48 -8
  10. package/docs/GATE_DAY.md +235 -0
  11. package/docs/OUTPUT_EVIDENCE.md +13 -2
  12. package/docs/codex-compat.md +10 -2
  13. package/knowledge/shared/harness-core/agents_md_runtime_details.md +10 -3
  14. package/knowledge/shared/harness-core/fh_three_layer_canon.md +20 -2
  15. package/knowledge/shared/harness-core/field_verdict_crossfamily_gate.md +23 -5
  16. package/knowledge/shared/harness-core/harness_incubator_doctrine.md +6 -1
  17. package/knowledge/shared/harness-core/measurement-integrity-checklist.md +31 -0
  18. package/knowledge/shared/harness-core/ship_readiness_gate.md +2 -2
  19. package/knowledge/shared/learnings/subagent_invocations_log.yaml +31 -0
  20. package/knowledge/shared/rules/multi_session_close_protocol.md +8 -1
  21. package/package.json +17 -3
  22. package/plugins/fh-commons/.claude-plugin/plugin.json +1 -1
  23. package/plugins/fh-meta/.claude-plugin/plugin.json +1 -1
  24. package/plugins/fh-meta/CHANGELOG.md +122 -0
  25. package/plugins/fh-meta/skills/cross-ecosystem-synergy-detection/SKILL.md +93 -3
  26. package/scripts/chamber_candidate_collect.sh +71 -13
  27. package/scripts/compaction_probe.sh +17 -2
  28. package/scripts/fh-gate.sh +58 -0
  29. package/scripts/files_manifest_shipping_check.sh +314 -0
  30. package/scripts/mapped_tracks.sh +113 -0
  31. package/scripts/package_coverage_check.sh +54 -0
  32. package/scripts/postinstall_notice.js +9 -2
  33. package/scripts/prior_art_prompt.sh +49 -2
  34. package/scripts/selfcheck.sh +58 -2
  35. package/scripts/session_close_check.sh +56 -3
  36. package/scripts/test_chamber_sig_lanes.sh +151 -0
  37. package/scripts/test_files_manifest_shipping_lanes.sh +260 -0
  38. package/scripts/test_leak_scan_control_lanes.sh +163 -0
  39. package/scripts/test_mapped_tracks_lanes.sh +162 -0
  40. package/scripts/test_peer_worktree_detect_lanes.sh +138 -0
  41. package/scripts/test_prepush_destructive_lanes.sh +366 -0
  42. package/scripts/test_prior_art_prompt_lanes.sh +48 -0
  43. package/scripts/test_regression_guard_ci_lanes.sh +124 -0
  44. package/templates/predelete_check.test.sh +56 -0
  45. package/templates/regression_guard.sh +75 -3
@@ -463,6 +463,34 @@ else
463
463
  fail=1
464
464
  fi
465
465
 
466
+ # files-manifest-shipping — sibling of package-coverage, DIFFERENT question. That check walks
467
+ # REFERENCES (a shipped doc names a path, does the path ship); this one walks package.json's files[]
468
+ # ARRAY ITSELF and asks whether every declared entry exists on disk. selfcheck.sh's own branch_claim
469
+ # block (below) names the exact gap this closes: "measured 2026-08-09, package_coverage_check.sh
470
+ # returns PASS on a files[] entry whose file does not exist, so a deleted subject would be green on
471
+ # every surface" — that comment calls fixing it, for every subject and not just branch_claim.sh, "a
472
+ # separate change with its own verification". This is that change.
473
+ if [ ! -f scripts/files_manifest_shipping_check.sh ]; then
474
+ _absent_subject_verdict "test_files_manifest_shipping_lanes.sh" "scripts/files_manifest_shipping_check.sh" || fail=1
475
+ elif [ -f scripts/test_files_manifest_shipping_lanes.sh ]; then
476
+ if ! bash scripts/test_files_manifest_shipping_lanes.sh; then
477
+ fail=1
478
+ fi
479
+ # Same applicability guard as package-coverage directly above, same reason: a repo with no npm
480
+ # surface has no files[] to audit, and that is NOT-APPLICABLE, not a red.
481
+ if [ -f package.json ] || [ -d bin ]; then
482
+ if ! bash scripts/files_manifest_shipping_check.sh; then
483
+ fail=1
484
+ fi
485
+ else
486
+ echo "SKIP files-manifest-shipping — NOT APPLICABLE: this repo ships no npm surface"
487
+ echo " (checked mechanically: package.json absent, bin/ absent — not a claim, a test)"
488
+ fi
489
+ else
490
+ echo "FAIL test_files_manifest_shipping_lanes.sh: files_manifest_shipping_check.sh present but its anchor is missing"
491
+ fail=1
492
+ fi
493
+
466
494
  # lane-runner — sibling of package-coverage one level up: that one asks "does the CONSUMER get the
467
495
  # file a shipped doc names", this one asks "does ANYTHING execute the lane suite we wrote". Measured
468
496
  # 2026-08-12 (reship axis, card §🔱⑮ A): 12 of 43 suites under scripts/ had no runner in selfcheck,
@@ -531,17 +559,30 @@ fi
531
559
  # test_capability_entrypoint_shipping.sh pins two (degrade_probe_capability.sh and
532
560
  # psa_probe_capability.sh); degrade is named here as the sentinel — the suite itself checks both and
533
561
  # fails if either is gone, so nothing is lost by not listing both in this table.
562
+ # test_script_caller_ratchet_lanes.sh is the second of that shape: it pins BOTH
563
+ # scripts/script_caller_ratchet.sh (the checker) and scripts/ratchet_base_resolve.sh (the base
564
+ # resolver its L24–L26 lanes execute), and it hard-exits 1 naming the missing file if either is
565
+ # gone. The checker is the sentinel because it is the one whose absence means the gate itself is
566
+ # gone; the resolver's absence is a narrower failure the suite still reports by name. Neither
567
+ # script ships — both, and this anchor, are declared in package_coverage_check.sh ACCEPTED_ABSENT.
568
+ # On a consumer install the SUBJECT arm fires first and `_ships_per_files` returns 1, so the row
569
+ # resolves to "SKIP (subject not in files[], and absent)" — the anchor arm is never reached.
534
570
  _LANE_TO=""; command -v timeout >/dev/null 2>&1 && _LANE_TO="timeout 300"
535
571
  for _pair in \
536
572
  "scripts/degrade_probe_capability.sh|scripts/test_capability_entrypoint_shipping.sh" \
537
573
  "scripts/chamber_run.sh|scripts/test_chamber_run_lanes.sh" \
574
+ "scripts/chamber_candidate_collect.sh|scripts/test_chamber_sig_lanes.sh" \
538
575
  "scripts/destructive_pre_gate.sh|scripts/test_destructive_pre_gate_lanes.sh" \
576
+ "templates/.git-hooks/pre-push|scripts/test_prepush_destructive_lanes.sh" \
577
+ "templates/.git-hooks/pre-push|scripts/test_prepush_destructive_liveness.sh" \
578
+ "scripts/session_close_check.sh|scripts/test_peer_worktree_detect_lanes.sh" \
539
579
  "scripts/env_purity_scan.sh|scripts/test_env_purity_lanes.sh" \
540
580
  "scripts/frontier_digest_daily.sh|scripts/test_frontier_digest_retry.sh" \
541
581
  "scripts/knowledge_seam_check.sh|scripts/test_knowledge_seam_lanes.sh" \
542
582
  "templates/.git-hooks/pre-commit|scripts/test_marker_crossfamily_lanes.sh" \
543
583
  "templates/.git-hooks/pre-commit|scripts/test_marker_floor_lanes.sh" \
544
584
  ".github/workflows/regression-guard.yml|scripts/test_regression_guard_ci_lanes.sh" \
585
+ ".github/workflows/validate.yml|scripts/test_leak_scan_control_lanes.sh" \
545
586
  "templates/.git-hooks/pre-commit|scripts/test_marker_standpoint_lanes.sh" \
546
587
  "templates/.git-hooks/pre-commit|scripts/test_marker_thirdparty_lanes.sh" \
547
588
  "templates/.git-hooks/pre-commit|scripts/test_marker_soul_check_lanes.sh" \
@@ -549,7 +590,9 @@ for _pair in \
549
590
  "scripts/reviewer_capability_corpus.tsv|scripts/test_reviewer_capability_conformance.sh" \
550
591
  "scripts/field_canon_preload.sh|scripts/test_field_canon_lanes.sh" \
551
592
  "scripts/stale_clone_guard.sh|scripts/test_stale_clone_guard_lanes.sh" \
552
- "plugins/fh-commons/skills/ko-tech-writer/SKILL.md|scripts/test_ko_tech_writer_lanes.sh"
593
+ "plugins/fh-commons/skills/ko-tech-writer/SKILL.md|scripts/test_ko_tech_writer_lanes.sh" \
594
+ "scripts/script_caller_ratchet.sh|scripts/test_script_caller_ratchet_lanes.sh" \
595
+ "scripts/mapped_tracks.sh|scripts/test_mapped_tracks_lanes.sh"
553
596
  do
554
597
  _subj="${_pair%%|*}"; _anc="${_pair##*|}"; _lbl="${_anc##*/}"
555
598
  if [ ! -f "$_subj" ]; then
@@ -1065,8 +1108,19 @@ else
1065
1108
  fi
1066
1109
 
1067
1110
  # listing_watch — 같은 형태. 🟥 이 블록을 «레인을 짓는 같은 커밋에서» 붙인다: 바로 위 주석이
1068
- # 기록한 「레인은 지었는데 selfcheck 배선을 안 했다」 재발이 최소 세 번이고, 그 셋 다 CI 나
1111
+ # 기록한 「레인은 지었는데 selfcheck 배선을 안 했다」 재발이 **최소 다섯 번**이고, 그 다섯 다 CI 나
1069
1112
  # lane-runner 가 뒤늦게 잡았다. 순서를 바꾸는 것이 유일한 처방이라 여기서 그렇게 한다.
1113
+ # 🟥 **2026-08-23 정정 — 「세 번」은 stale 이었다. 그리고 숫자보다 함의가 중요하다**: 네 번째는
1114
+ # 2026-08-22 에 났는데, **이 주석 바로 아래에서** 났다. 처방이 «읽히는 자리»에 있었는데도 재발한
1115
+ # 것이다. ⇒ 「주석을 더 잘 쓰자」가 아니라 **「살리언스로는 이 축이 안 닫힌다」**의 근거다.
1116
+ # (회수 경위: 그 관측은 폐기된 워크트리 사본에만 있었고, peer 세션이 버리기 전에 건져 올렸다.)
1117
+ # 🟥 **다섯 번째 = 바로 이 주석을 「네 번」으로 고친 그 커밋 자신이다** (2026-08-23, CI 적발).
1118
+ # 그 델타가 `:546` 의 `chamber_candidate_collect.sh|test_chamber_sig_lanes.sh` 배선 한 줄을
1119
+ # **의도 없이 지웠고**, 레인 파일은 그대로 남아 lane-runner 가 「돌리는 게 없는 스위트」로
1120
+ # 잡았다. 즉 **이 축을 서술하는 행위가 이 축의 다음 사례를 생산했다.** 자력 적발 0.
1121
+ # ⚠️ 이번 것은 앞의 넷과 형태가 하나 다르다 — 앞의 넷은 «배선을 안 붙였다»(누락)인데
1122
+ # 이건 «있던 배선을 지웠다»(회귀)다. 같은 계기(lane-runner)가 둘 다 잡았으므로 한 카운터에
1123
+ # 두지만, 처방이 갈릴 수 있다는 뜻이므로 접지 말고 여기 적어 둔다.
1070
1124
  if [ ! -f scripts/listing_watch.sh ]; then
1071
1125
  echo "FAIL scripts/listing_watch.sh is in package.json files[] but absent — a deleted subject, not a skip"
1072
1126
  fail=1
@@ -1083,6 +1137,8 @@ fi
1083
1137
  # 지으면서 여기 배선을 안 했고, `lane-runner` 가 «돌리는 게 없는 스위트는 산문이다» 로 CI 에서
1084
1138
  # 잡았다. 아래 target_freeze 주석이 기록한 그 형태의 **최소 세 번째**다 — 즉 이건 개인 부주의가
1085
1139
  # 아니라 «레인을 짓는 사람이 배선 지점을 안 본다» 는 구조적 순서 문제다.
1140
+ # ⚠️ 2026-08-23: 그 뒤 **네 번째**가 났다(위 listing_watch 주석 참조). 이 «세 번째»는 시점 기록이라
1141
+ # 그대로 두고, 누계는 위 주석이 갱신본이다 — 두 곳에 같은 카운터를 두면 하나는 반드시 낡는다.
1086
1142
  if [ ! -f scripts/residency_admission_check.sh ]; then
1087
1143
  echo "FAIL scripts/residency_admission_check.sh is wired into pre-commit but absent — a deleted subject, not a skip"
1088
1144
  fail=1
@@ -139,6 +139,12 @@ if [ -z "${CLAUDE_CODE_CHILD_SESSION:-}${CLAUDE_CODE_AGENT:-}" ] && [ "${FH_PEER
139
139
  : # solo/top-level surface — ①-c is out of scope here, and silence is the correct output
140
140
  else
141
141
  PEER_LIVE=0; PEER_UNKNOWN=0; PEER_STALE=0; PEER_SPARE=0; PEER_IDS=""
142
+ # Two more counters, added 2026-08-22. WHY they are SEPARATE values and not one bucket: a peer whose
143
+ # cwd resolves to a DIFFERENT repo has been placed — excluding it is a measurement. A peer whose cwd
144
+ # resolves to no repo at all has NOT been placed, and folding that into the same number would render
145
+ # an unmeasured thing as a decided one (not-found != zero, one level up from line 170's case).
146
+ PEER_OTHERREPO=0 # placed, and it is somebody else's repo → correctly excluded, stays quiet
147
+ PEER_OFFTREE=0 # cwd READ but placeable in neither this repo nor any repo → must not read as 0
142
148
  SOCK_DIR="${FH_PEER_SOCK_DIR:-/tmp/cc-socks}"
143
149
  # Self-exclusion must walk the ANCESTOR chain, not compare `$$`. This script is a grandchild of the
144
150
  # session process that owns the socket, so `$$` never matches it — measured: the first run counted
@@ -155,6 +161,27 @@ _peer_cwd() { # $1=pid → cwd on stdout, empty if unresolvable
155
161
  command -v lsof >/dev/null 2>&1 || return 0
156
162
  lsof -a -p "$1" -d cwd -Fn 2>/dev/null | sed -n 's/^n//p' | head -1
157
163
  }
164
+ # Repo identity, NOT directory prefix. Measured 2026-08-22 (probe_2026-08-22_A2_replication.md):
165
+ # `--show-toplevel` yields the WORKTREE's own path, and a worktree by definition lives outside the
166
+ # main tree — so `"$FH"/*` prefix matching fails STRUCTURALLY for every worktree of this repo, in
167
+ # both directions. From the main tree it silently dropped the worktree peer (no counter moved at
168
+ # all); from a worktree it printed a confident "✅ no live peer" with three live same-repo sessions
169
+ # running. `git rev-parse --git-common-dir` returns the MAIN tree's .git from inside any worktree,
170
+ # which is exactly the equality this question needs — the same property templates/.git-hooks/pre-commit
171
+ # already relies on to reach evidence from a worktree.
172
+ # ⚠️ It can return a RELATIVE path (plain '.git' when run at a repo root — measured here, git 2.50),
173
+ # so the raw output of the main tree and of its own worktree DIFFER as strings. Normalising to an
174
+ # absolute real path is not tidiness; comparing raw output would reproduce the very bug being fixed.
175
+ _repo_id() { # $1=dir → absolute real path of the repo's COMMON .git, empty if not placeable in a repo
176
+ ( cd "$1" 2>/dev/null || exit 0
177
+ _c=$(git rev-parse --git-common-dir 2>/dev/null) || exit 0
178
+ [ -n "$_c" ] || exit 0
179
+ cd "$_c" 2>/dev/null || exit 0
180
+ pwd -P )
181
+ }
182
+ # Computed once. Empty = $FH itself is not inside a git repo; then repo-identity cannot decide
183
+ # anything and every off-prefix peer falls through to PEER_OFFTREE (unplaceable), never to "absent".
184
+ FH_REPO_ID="$(_repo_id "$FH")"
158
185
  if [ -d "$SOCK_DIR" ]; then
159
186
  for _s in "$SOCK_DIR"/*.sock; do
160
187
  [ -e "$_s" ] || continue
@@ -174,6 +201,26 @@ if [ -d "$SOCK_DIR" ]; then
174
201
  fi
175
202
  case "$_pcwd" in
176
203
  "$FH"|"$FH"/*) PEER_LIVE=$((PEER_LIVE+1)); PEER_IDS="$PEER_IDS $_pid" ;;
204
+ *)
205
+ # The `default` arm that was missing until 2026-08-22. Every peer that reaches here has a
206
+ # READ cwd that is not under $FH, and previously left the loop without touching a single
207
+ # counter — so the ladder below could not tell it from "there was nobody". Three outcomes,
208
+ # and the point is that they are three, not two.
209
+ _prepo="$(_repo_id "$_pcwd")"
210
+ if [ -n "$FH_REPO_ID" ] && [ "$_prepo" = "$FH_REPO_ID" ]; then
211
+ # Same repo, different worktree — a real peer of THIS harness. The case this fix exists for.
212
+ PEER_LIVE=$((PEER_LIVE+1)); PEER_IDS="$PEER_IDS $_pid"
213
+ elif [ -n "$_prepo" ]; then
214
+ # Placed in a DIFFERENT repo. Excluding it is a measurement, so it stays quiet on purpose:
215
+ # warning here would nag every close about unrelated projects, and an advisory that fires
216
+ # on every close trains skimming past the lines that matter.
217
+ PEER_OTHERREPO=$((PEER_OTHERREPO+1))
218
+ else
219
+ # cwd read, but it belongs to no repo we can name (or $FH is not in a repo). UNPLACEABLE —
220
+ # routed to the existing UNPLACEABLE branch below rather than to a new verdict of its own.
221
+ PEER_OFFTREE=$((PEER_OFFTREE+1))
222
+ fi
223
+ ;;
177
224
  esac
178
225
  done
179
226
  else
@@ -207,11 +254,17 @@ elif [ "$PEER_LIVE" -gt 0 ]; then
207
254
  echo " 2026-08-09: 2 of 5 notices were held while the card already claimed all 5 informed."
208
255
  echo " Record ANSWERS, not sends, and put the unanswered count in the card."
209
256
  [ "$PEER_UNKNOWN" -gt 0 ] && echo " + $PEER_UNKNOWN live session(s) whose directory is UNKNOWN (counted, not dismissed)"
210
- elif [ "$PEER_UNKNOWN" -gt 0 ]; then
211
- echo "⚠️ ①-c 0 peers placed in this harness, but $PEER_UNKNOWN live session(s) are UNPLACEABLE"
257
+ [ "$PEER_OFFTREE" -gt 0 ] && echo " + $PEER_OFFTREE live session(s) whose directory belongs to NO repo (counted, not dismissed)"
258
+ elif [ "$PEER_UNKNOWN" -gt 0 ] || [ "$PEER_OFFTREE" -gt 0 ]; then
259
+ echo "⚠️ ①-c 0 peers placed in this harness, but $((PEER_UNKNOWN+PEER_OFFTREE)) live session(s) are UNPLACEABLE"
260
+ echo " ($PEER_UNKNOWN with no readable cwd · $PEER_OFFTREE whose cwd belongs to no repo)"
212
261
  echo " — treat as possible peers and ask; do not read this as 'closing alone'."
213
262
  else
214
- echo "✅ ①-c no live peer in this harness (${PEER_STALE} stale · ${PEER_SPARE} pre-warmed spare(s) ignored)"
263
+ # The parenthetical must account for EVERY kind that was dropped, not only the flattering ones.
264
+ # Before 2026-08-22 it listed stale+spare while silently discarding same-repo worktree peers, so
265
+ # "0 stale · 0 spare" read as "three kinds swept, all empty" at the exact moment three real peers
266
+ # had been thrown away. A green line is only allowed to be green about what it actually counted.
267
+ echo "✅ ①-c no live peer in this harness (${PEER_STALE} stale · ${PEER_SPARE} pre-warmed spare(s) · ${PEER_OTHERREPO} in other repo(s) — all placed)"
215
268
  fi
216
269
 
217
270
  fi
@@ -0,0 +1,151 @@
1
+ #!/usr/bin/env bash
2
+ # test_chamber_sig_lanes.sh — known-pair calibration for chamber_candidate_collect.sh's LAYER-2
3
+ # dedup signature (`_sig`/`_ksig`) on a NON-ASCII corpus.
4
+ #
5
+ # WHY (measured 2026-08-22, live corpus, this repo):
6
+ # A freshly-registered candidate was grepped correctly by LAYER 1 and then VANISHED from the
7
+ # ranked queue. The loss was LAYER 2. Root cause = **locale-dependent collation**, and it is not
8
+ # one bug but a family, all in the same pipeline:
9
+ # · `sort -u` in en_US.UTF-8 treats Hangul syllables as EQUAL to one another. Measured on
10
+ # macOS/BSD sort: 8 distinct Korean tokens → 2 survivors (grouped by syllable count, first
11
+ # one wins, input-order dependent). Measured on GNU coreutils 9.7 sort: same 8 → **1**.
12
+ # · `comm -12` inherits that collation, so it reports two COMPLETELY DIFFERENT Korean tokens
13
+ # as a common line. Measured: comm -12 <(레인) <(발주) → prints a line. The jaccard
14
+ # numerator is therefore computed against a collation, not against the tokens.
15
+ # · `awk 'length()>=4'` counts BYTES on BSD awk and CHARACTERS on gawk in a UTF-8 locale. The
16
+ # same 2-syllable Korean token passes on macOS (6 bytes) and is DROPPED on Linux (2 chars),
17
+ # so the two platforms disagree about the signature before any comparison happens.
18
+ # Net effect on the live corpus (64 raw markers): unrelated candidates were folded into clusters
19
+ # of 11, 7, 7, 4 and 3, and only each cluster's FIRST member reached the output. Everything else
20
+ # was silently deleted from the queue while the run reported a healthy "deduped candidates: 31".
21
+ #
22
+ # That is the [[feedback_not_found_is_not_zero_family]] shape — a silent fold rendered as a clean
23
+ # number — which is why it needs a mechanical anchor rather than a note.
24
+ #
25
+ # WHAT IT PINS (the lanes below, in pairs, because a merge check with only one direction is not a
26
+ # measurement — over-merging and never-merging both produce a "correct" number on half the corpus):
27
+ # L1 Korean, DIFFERENT → must NOT merge (known-positive: the actual live mis-merge)
28
+ # L2 Korean, SAME → must merge (known-negative: the fix must not kill real dedup)
29
+ # L3 English, DIFFERENT → must NOT merge (control: the defect is Hangul-only; if this lane ever
30
+ # goes red the diagnosis above is wrong)
31
+ # L4 English, SAME → must merge (control, other direction)
32
+ # L5 Korean ×3 unrelated → must stay 3 ("does it collapse a set, not just a pair")
33
+ # L6 Korean vs English → must NOT merge (mixed-script pair)
34
+ #
35
+ # 🟥 EVERY LANE DRIVES THE REAL SCRIPT. Nothing here re-implements `_sig`. A lane suite that carries
36
+ # its own copy of the logic grades the copy ([[feedback_adversarial_review_not_substitute_for_first_use]]
37
+ # — "초록의 출처를 물어라: 사본이 통과시키고 있었다").
38
+ #
39
+ # 🟥 FIXTURES ARE SELF-BUILT under mktemp, never this repo's own tracks/ — a suite that reads
40
+ # repo-specific paths FAILs wholesale once the script is ported (portability_lint P9).
41
+ #
42
+ # Usage: bash scripts/test_chamber_sig_lanes.sh
43
+ # Exit: 0 = all lanes pass · 1 = a lane failed · 10 = harness error (could not measure)
44
+
45
+ set -uo pipefail
46
+
47
+ REPO="$(cd "$(dirname "$0")/.." && pwd)"
48
+ SUBJ="$REPO/scripts/chamber_candidate_collect.sh"
49
+ [ -f "$SUBJ" ] || { echo "HARNESS ERROR: subject missing: $SUBJ"; exit 10; }
50
+
51
+ TMP="$(mktemp -d 2>/dev/null)" || { echo "HARNESS ERROR: mktemp failed"; exit 10; }
52
+ trap 'rm -rf "$TMP"' EXIT
53
+
54
+ fail=0
55
+ lane=0
56
+
57
+ # Build a throwaway FH root holding exactly the given marker lines, run the REAL collector inside
58
+ # it, and echo "NRAW NDEDUP". The collector locates its own FH root from its dirname, so the copy
59
+ # has to live in <root>/scripts/ — that is also why this cannot be done by calling the repo copy
60
+ # with an env var: the script offers no such knob and inventing one for the test would move the
61
+ # measurement off the shipped path.
62
+ _run() { # $@ = marker descriptions
63
+ local root="$TMP/fx.$lane"
64
+ rm -rf "$root"
65
+ mkdir -p "$root/scripts" "$root/tracks/_meta" "$root/plugins" || return 10
66
+ cp "$SUBJ" "$root/scripts/" || return 10
67
+ # NOTE: chamber_candidate_screen.sh is deliberately NOT copied. Its verdict column is irrelevant
68
+ # here and its absence keeps the fixture independent of this repo's asset tree.
69
+ local f="$root/tracks/_meta/fh_signal_2000-01-01_fixture.md"
70
+ : > "$f"
71
+ local d
72
+ for d in "$@"; do printf 'CHAMBER-CANDIDATE: %s\n' "$d" >> "$f"; done
73
+ local out
74
+ out=$(bash "$root/scripts/chamber_candidate_collect.sh" 2>&1) || true
75
+ local nraw ndedup
76
+ nraw=$(printf '%s\n' "$out" | sed -n 's/.*raw candidate markers found: \([0-9][0-9]*\).*/\1/p' | head -1)
77
+ ndedup=$(printf '%s\n' "$out" | sed -n 's/^deduped candidates: \([0-9][0-9]*\) .*/\1/p' | head -1)
78
+ printf '%s %s\n' "${nraw:-X}" "${ndedup:-X}"
79
+ }
80
+
81
+ # $1=label $2=expected dedup count $3..=descriptions
82
+ _lane() {
83
+ lane=$((lane+1))
84
+ local label="$1" want="$2"; shift 2
85
+ local got nraw ndedup
86
+ got=$(_run "$@")
87
+ nraw="${got%% *}"; ndedup="${got##* }"
88
+ # Instrument control BEFORE the verdict: if LAYER 1 did not even see the markers, a "correct"
89
+ # dedup number would be an accident. `not found` is not a zero.
90
+ if [ "$nraw" != "$#" ]; then
91
+ echo "HARNESS ERROR $label: collector saw $nraw raw markers, fixture planted $# — instrument dead, verdict void"
92
+ fail=1; return
93
+ fi
94
+ if [ "$ndedup" = "$want" ]; then
95
+ echo "PASS $label (deduped=$ndedup, expected $want)"
96
+ else
97
+ echo "FAIL $label: deduped=$ndedup, expected $want ($nraw raw markers)"
98
+ fail=1
99
+ fi
100
+ }
101
+
102
+ echo "── chamber signature lanes (LAYER-2 dedup, non-ASCII corpus) ──"
103
+
104
+ # L1 — KNOWN-POSITIVE. Both strings are lifted VERBATIM from this repo's live corpus, and this is
105
+ # the exact pair that folded on 2026-08-22: the second was swallowed by the first and never reached
106
+ # the queue. Deliberately NOT a synthetic minimal pair — the punctuation soup («」·—/+()) is the
107
+ # "뚫리는 표기" that a clean two-word fixture would step over.
108
+ # ⚠️ The strings must stay VERBATIM. A first draft of this lane paraphrased six characters of the
109
+ # second string's tail ("행위로 굳힌다" for "행위자가 읽는 곳에.") and the pair stopped folding —
110
+ # the lane went green against the very code it was written to indict. Do not "tidy" these.
111
+ _lane "L1 ko/different (live mis-merge pair)" 2 \
112
+ '「미사용 자산의 원인 3분할(값어치·배선·계기)」을 tier 전에 강제하는 렌즈 — 처분 tier 가 원인 판정을 앞서지 못하게 한다' \
113
+ '병렬 레인 발주 계약 — 보고 의무 3줄 + 취향/판정/승인 3축 라우팅 + idle 구독을 카드 안에 박은 형태. 별도 규칙 파일 없이 행위자가 읽는 곳에.'
114
+
115
+ # L2 — KNOWN-NEGATIVE. Real duplicates must still collapse; a fix that merely stops merging would
116
+ # pass L1 and destroy the feature. Same candidate, re-listed with a trailing qualifier.
117
+ _lane "L2 ko/same (true duplicate must still merge)" 1 \
118
+ 'session-token-ledger — 세션 및 서브에이전트 토큰 실사용을 기계 출처에서 수집해 원장화하고 추정기가 역참조하는 계기' \
119
+ 'session-token-ledger — 세션 및 서브에이전트 토큰 실사용을 기계 출처에서 수집해 원장화하고 추정기가 역참조하는 계기 (동일 건 재등재, 앵커 보강만)'
120
+
121
+ # L3/L4 — ENGLISH CONTROL. These pin the diagnosis, not the feature: the defect is a Hangul
122
+ # collation defect, so both English lanes must be green BEFORE and AFTER the repair. If L3 or L4
123
+ # is ever red, the cause is somewhere other than where this header says it is.
124
+ _lane "L3 en/different (control)" 2 \
125
+ 'parallel lane dispatch contract — reporting duty condensed into three lines plus an idle subscription card' \
126
+ 'unused asset triage lens — forces value versus wiring versus instrument before any disposal tier is assigned'
127
+
128
+ _lane "L4 en/same (control)" 1 \
129
+ 'session token ledger — collect subagent token usage from a mechanical source and let the estimator dereference it' \
130
+ 'session token ledger — collect subagent token usage from a mechanical source and let the estimator dereference it, relisted'
131
+
132
+ # L5 — SET COLLAPSE, not just a pair. The live failure produced clusters of 11; a pairwise-only
133
+ # suite would have called a 3→1 fold "one merge" and moved on.
134
+ _lane "L5 ko/three unrelated" 3 \
135
+ '낭독 렌즈 — 「소리 내어 읽히는가」를 재는 계기. 문서 린터가 구조적으로 못 보는 축이다' \
136
+ 'fh-router-demotion — salience 상시부하를 플랫폼 네이티브 메커니즘으로 이관하는 대수술' \
137
+ '인물 시뮬레이터 하네스 — 닫힌 코퍼스 + 그라운딩 게이트 + 페르소나 캐스트를 한 틀로 묶는다'
138
+
139
+ # L6 — MIXED SCRIPT. A Korean signature that collapses to near-nothing can also collide with an
140
+ # unrelated ASCII one, which is a different failure path from ko↔ko.
141
+ _lane "L6 ko vs en" 2 \
142
+ '원정 수련 — 세계 강력 레포에서 배워오는 반복 루틴. 탐색 판별 흡수 3단이다' \
143
+ 'entrypoint wiring generator — emit runtime-native hook settings from a single event manifest'
144
+
145
+ echo ""
146
+ if [ "$fail" -eq 0 ]; then
147
+ echo "chamber signature lanes: ALL PASS ($lane lanes)"
148
+ else
149
+ echo "chamber signature lanes: FAILURES PRESENT ($lane lanes run)"
150
+ fi
151
+ exit "$fail"
@@ -0,0 +1,260 @@
1
+ #!/usr/bin/env bash
2
+ # test_files_manifest_shipping_lanes.sh — regression anchor for
3
+ # scripts/files_manifest_shipping_check.sh.
4
+ #
5
+ # Known-pair calibration (CLAUDE.md §Instrument-Calibration): a phantom files[] entry (declared,
6
+ # absent on disk) must FAIL; the real, unmodified package.json must PASS. Both lanes exercise the
7
+ # actual script against a real npm invocation via a scratch package.json copy — not a stub — so a
8
+ # regression in the node extraction logic (the bash-3.2 heredoc-in-$(...) class this script was
9
+ # rewritten to avoid, see the subject's own header) shows up here.
10
+ #
11
+ # Usage: bash scripts/test_files_manifest_shipping_lanes.sh
12
+ # Exit: 0 = no lane failed. 1 = a regression.
13
+ set -uo pipefail
14
+
15
+ REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
16
+ SUBJECT="$REPO_ROOT/scripts/files_manifest_shipping_check.sh"
17
+ [ -f "$SUBJECT" ] || { echo "FAIL: $SUBJECT not found"; exit 1; }
18
+ cd "$REPO_ROOT" || exit 1
19
+
20
+ pass=0; fail=0
21
+ ok() { printf ' \xe2\x9c\x85 %s\n' "$1"; pass=$((pass+1)); }
22
+ bad() { printf ' \xe2\x9d\x8c %s\n' "$1"; fail=$((fail+1)); }
23
+
24
+ echo "files-manifest-shipping lane suite"
25
+
26
+ # Lane 1 — real tree, declaration mode: must PASS. This is the everyday run, offline, no npm.
27
+ if bash "$SUBJECT" >/tmp/fmsc_lane1.$$.out 2>&1; then
28
+ ok "lane 1: real package.json (declaration mode) PASSes"
29
+ else
30
+ bad "lane 1: real package.json (declaration mode) unexpectedly FAILed"
31
+ sed 's/^/ /' /tmp/fmsc_lane1.$$.out
32
+ fi
33
+ rm -f /tmp/fmsc_lane1.$$.out
34
+
35
+ # Lane 2 — known-negative → known-positive pair, same tree, one flipped field. Inject a phantom
36
+ # entry into a SCRATCH copy of package.json (never mutate the real one in place — a failure mid-lane
37
+ # must not leave the repo's actual manifest corrupted), point the subject at it via a temp cwd copy.
38
+ LANE2_DIR="$(mktemp -d)"
39
+ trap 'rm -rf "$LANE2_DIR"' EXIT
40
+
41
+ # The check does `cd` to its own repo root via BASH_SOURCE, so exercising it against a modified
42
+ # manifest means running it FROM a copy of the tree — cheapest correct way: symlink everything the
43
+ # check might touch (package.json, .git, scripts/) into the scratch dir is fragile across
44
+ # filesystems, so instead we run the REAL subject in the REAL tree but swap package.json out and
45
+ # back atomically, exactly as the manual known-pair check that authored this suite did.
46
+ cp package.json "$LANE2_DIR/package.json.orig"
47
+ node -e '
48
+ const fs = require("fs");
49
+ const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
50
+ pkg.files.push("scripts/__test_fixture_does_not_exist__.sh");
51
+ fs.writeFileSync("package.json", JSON.stringify(pkg, null, 2) + "\n");
52
+ '
53
+ restore_pkg() { cp "$LANE2_DIR/package.json.orig" package.json; }
54
+
55
+ if bash "$SUBJECT" >/tmp/fmsc_lane2.$$.out 2>&1; then
56
+ bad "lane 2 (known-positive: phantom files[] entry): expected FAIL, got PASS — the detector is blind"
57
+ sed 's/^/ /' /tmp/fmsc_lane2.$$.out
58
+ restore_pkg
59
+ else
60
+ if grep -q "scripts/__test_fixture_does_not_exist__.sh" /tmp/fmsc_lane2.$$.out; then
61
+ ok "lane 2: injected phantom files[] entry correctly FAILs and is named"
62
+ else
63
+ bad "lane 2: FAILed, but did not name the injected phantom — wrong reason"
64
+ sed 's/^/ /' /tmp/fmsc_lane2.$$.out
65
+ fi
66
+ restore_pkg
67
+ fi
68
+ rm -f /tmp/fmsc_lane2.$$.out
69
+
70
+ # Lane 3 — restore integrity check: the real package.json must be back and byte-identical, and the
71
+ # subject must PASS again on it. If lane 2's restore silently failed, this is where it surfaces
72
+ # instead of leaking a broken manifest out of the test.
73
+ if diff -q "$LANE2_DIR/package.json.orig" package.json >/dev/null 2>&1; then
74
+ ok "lane 3: package.json restored byte-identical after lane 2"
75
+ else
76
+ bad "lane 3: package.json was NOT restored — repo manifest is corrupted, fix immediately"
77
+ fi
78
+ if bash "$SUBJECT" >/tmp/fmsc_lane3.$$.out 2>&1; then
79
+ ok "lane 3: subject PASSes again on the restored real manifest"
80
+ else
81
+ bad "lane 3: subject FAILed on the restored manifest (should be identical to lane 1)"
82
+ sed 's/^/ /' /tmp/fmsc_lane3.$$.out
83
+ fi
84
+ rm -f /tmp/fmsc_lane3.$$.out
85
+
86
+ # ─────────────────────────────────────────────────────────────────────────────────────────────
87
+ # Lanes 4+ — cross-family review fixes (2026-08-23). Each lane exercises an axis the REPAIR itself
88
+ # did NOT touch as its detection vocabulary (CLAUDE.md feedback_lane_vocabulary_blind_to_its_own_fix
89
+ # — a lane written in the same words as the fix can pass while the defect survives). These build
90
+ # throwaway fixture trees (script copy + package.json + optional .git) the same way lane 2 does, so
91
+ # the SUBJECT is exercised for real, never stubbed.
92
+
93
+ fixture_dir() {
94
+ local d; d="$(mktemp -d)"
95
+ mkdir -p "$d/scripts"
96
+ cp "$SUBJECT" "$d/scripts/files_manifest_shipping_check.sh"
97
+ printf '%s' "$d"
98
+ }
99
+
100
+ # Lane 4 — S2: an unrecognized argument (typo'd flag) must FAIL, never silently downgrade to the
101
+ # weaker declaration-mode default. Real package.json, real repo — only the argument is wrong.
102
+ if out=$(bash "$SUBJECT" --vs-tarbll 2>&1); rc=$?; [ "$rc" -ne 0 ] && printf '%s' "$out" | grep -q "unrecognized argument"; then
103
+ ok "lane 4: typo'd --vs-tarbll argument FAILs loudly, does not downgrade to declaration mode"
104
+ else
105
+ bad "lane 4: typo'd argument should FAIL and name itself — got rc=$rc"
106
+ printf '%s\n' "$out" | sed 's/^/ /'
107
+ fi
108
+
109
+ # Lane 5 — S1: no .git must degrade DIFFERENTLY by mode. Declaration mode: SKIP rc=0 (an installed
110
+ # package legitimately has nothing comparable to check). Tarball mode: FAIL rc=1, fail-closed — the
111
+ # ONLY caller of --vs-tarball is the publish path, which always runs from a real source checkout, so
112
+ # "no .git" there means the environment is off-shape, not that the check has nothing to do.
113
+ D5="$(fixture_dir)"
114
+ cp package.json "$D5/package.json"
115
+ if out=$(bash "$D5/scripts/files_manifest_shipping_check.sh" 2>&1); rc=$?; [ "$rc" -eq 0 ] && printf '%s' "$out" | grep -q "^SKIP"; then
116
+ ok "lane 5a: no .git, declaration mode: SKIPs rc=0"
117
+ else
118
+ bad "lane 5a: no .git, declaration mode: expected SKIP rc=0, got rc=$rc"
119
+ printf '%s\n' "$out" | sed 's/^/ /'
120
+ fi
121
+ if out=$(bash "$D5/scripts/files_manifest_shipping_check.sh" --vs-tarball 2>&1); rc=$?; [ "$rc" -ne 0 ] && printf '%s' "$out" | grep -q "^FAIL"; then
122
+ ok "lane 5b: no .git, --vs-tarball mode: FAILs rc=1 (fail-closed on the publish surface)"
123
+ else
124
+ bad "lane 5b: no .git, --vs-tarball mode: expected FAIL rc!=0, got rc=$rc"
125
+ printf '%s\n' "$out" | sed 's/^/ /'
126
+ fi
127
+ rm -rf "$D5"
128
+
129
+ # Lane 6 — A1: files[] declared as a non-array (e.g. a bare string) must FAIL as an invalid
130
+ # manifest, never silently coerce and report "1 entry checked".
131
+ D6="$(fixture_dir)"
132
+ mkdir -p "$D6/.git"
133
+ node -e '
134
+ const fs = require("fs");
135
+ const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
136
+ pkg.files = ".";
137
+ fs.writeFileSync(process.argv[1], JSON.stringify(pkg, null, 2) + "\n");
138
+ ' "$D6/package.json"
139
+ if out=$(bash "$D6/scripts/files_manifest_shipping_check.sh" 2>&1); rc=$?; [ "$rc" -ne 0 ] && printf '%s' "$out" | grep -q "not an array"; then
140
+ ok "lane 6: files[] as a non-array (string) FAILs as an invalid manifest"
141
+ else
142
+ bad "lane 6: malformed files[] type should FAIL — got rc=$rc"
143
+ printf '%s\n' "$out" | sed 's/^/ /'
144
+ fi
145
+ rm -rf "$D6"
146
+
147
+ # Lane 7 — A3: a files[] entry containing a literal newline (and a forged verdict token) must never
148
+ # render a bare, unescaped "PASS" line — the injected content must stay visibly inside a quoted,
149
+ # escaped value so no downstream grep/human reader can mistake it for the real verdict. The run must
150
+ # still exit 1 (it IS a phantom entry).
151
+ D7="$(fixture_dir)"
152
+ mkdir -p "$D7/.git"
153
+ node -e '
154
+ const fs = require("fs");
155
+ const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
156
+ pkg.files.push("missing\nPASS\\t999 entries checked, 0 phantom, 0 unpacked");
157
+ fs.writeFileSync(process.argv[1], JSON.stringify(pkg, null, 2) + "\n");
158
+ ' "$D7/package.json"
159
+ out=$(bash "$D7/scripts/files_manifest_shipping_check.sh" 2>&1); rc=$?
160
+ if [ "$rc" -ne 0 ] && ! printf '%s' "$out" | grep -qE '^PASS( |$)'; then
161
+ ok "lane 7: newline-injected phantom entry FAILs and never renders a bare PASS line"
162
+ else
163
+ bad "lane 7: newline injection should FAIL without a bare PASS line — got rc=$rc"
164
+ printf '%s\n' "$out" | sed 's/^/ /'
165
+ fi
166
+ rm -rf "$D7"
167
+
168
+ # Lane 8 — A4: when `git ls-files` itself fails against a declared directory (corrupted index,
169
+ # rejected pathspec, or similar — simulated here with a shim, since actually uninstalling git would
170
+ # also break this SUITE'S own tooling), the finding must render as an INSTRUMENT failure, never as
171
+ # "declared directory, zero git-tracked files" — the latter says the TARGET is empty, which was not
172
+ # established; the git oracle itself did not run.
173
+ D8="$(fixture_dir)"
174
+ mkdir -p "$D8/.git" "$D8/scripts_dummy"
175
+ echo x > "$D8/scripts_dummy/foo.sh"
176
+ node -e '
177
+ const fs = require("fs");
178
+ const pkg = JSON.parse(fs.readFileSync("package.json", "utf8"));
179
+ pkg.files = ["scripts_dummy"];
180
+ delete pkg.scripts.prepare;
181
+ delete pkg.scripts.prepublishOnly;
182
+ fs.writeFileSync(process.argv[1], JSON.stringify(pkg, null, 2) + "\n");
183
+ ' "$D8/package.json"
184
+ FAKEBIN8="$(mktemp -d)"
185
+ REALGIT="$(command -v git)"
186
+ cat > "$FAKEBIN8/git" <<EOF
187
+ #!/usr/bin/env bash
188
+ if [ "\$1" = "ls-files" ]; then
189
+ echo "fatal: simulated git ls-files failure" >&2
190
+ exit 128
191
+ fi
192
+ exec "$REALGIT" "\$@"
193
+ EOF
194
+ chmod +x "$FAKEBIN8/git"
195
+ out=$(PATH="$FAKEBIN8:$PATH" bash "$D8/scripts/files_manifest_shipping_check.sh" --vs-tarball 2>&1); rc=$?
196
+ if [ "$rc" -ne 0 ] && printf '%s' "$out" | grep -q "instrument failure" && ! printf '%s' "$out" | grep -q "zero git-tracked files"; then
197
+ ok "lane 8: git ls-files failure renders as INSTRUMENT failure, not a phantom empty directory"
198
+ else
199
+ bad "lane 8: git ls-files failure should render as instrument failure, not target-empty — got rc=$rc"
200
+ printf '%s\n' "$out" | sed 's/^/ /'
201
+ fi
202
+ rm -rf "$D8" "$FAKEBIN8"
203
+
204
+ # Lane 9 — B1/B2: a glob entry (`dist/*.js`) is out-of-scope, never a false PHANTOM; a `./`-prefixed
205
+ # entry is npm's own literal notation and must match normally in tarball mode, never a false
206
+ # UNPACKED. Both in one small real repo (git init'd for real, so npm pack sees real tracked files).
207
+ D9="$(mktemp -d)"
208
+ mkdir -p "$D9/scripts" "$D9/dist"
209
+ cp "$SUBJECT" "$D9/scripts/files_manifest_shipping_check.sh"
210
+ echo 'console.log("hi");' > "$D9/dist/index.js"
211
+ echo 'console.log("hi");' > "$D9/index.js"
212
+ cat > "$D9/package.json" <<'EOF'
213
+ {
214
+ "name": "fmsc-lane9-fixture",
215
+ "version": "1.0.0",
216
+ "files": ["dist/*.js", "./index.js"]
217
+ }
218
+ EOF
219
+ ( cd "$D9" && git init -q && git -c user.email=t@t -c user.name=t add -A && git -c user.email=t@t -c user.name=t commit -q -m init )
220
+ if out=$(bash "$D9/scripts/files_manifest_shipping_check.sh" 2>&1); rc=$?; [ "$rc" -eq 0 ] && printf '%s' "$out" | grep -q "out-of-scope"; then
221
+ ok "lane 9a: glob entry (dist/*.js) reported out-of-scope, not phantom (declaration mode PASSes)"
222
+ else
223
+ bad "lane 9a: glob entry should be out-of-scope, not phantom — got rc=$rc"
224
+ printf '%s\n' "$out" | sed 's/^/ /'
225
+ fi
226
+ if out=$(bash "$D9/scripts/files_manifest_shipping_check.sh" --vs-tarball 2>&1); rc=$?; [ "$rc" -eq 0 ] && ! printf '%s' "$out" | grep -q "UNPACKED"; then
227
+ ok "lane 9b: ./-prefixed entry matches the real tarball, no false UNPACKED (tarball mode PASSes)"
228
+ else
229
+ bad "lane 9b: ./index.js should match normally in tarball mode — got rc=$rc"
230
+ printf '%s\n' "$out" | sed 's/^/ /'
231
+ fi
232
+ rm -rf "$D9"
233
+
234
+ # Lane 10 — B3: a legitimately tiny tarball (< 10 files) must be an ADVISORY, not an automatic FAIL.
235
+ # Reuses lane 9's fixture repo, which packs 3 files (package.json + dist/index.js + index.js).
236
+ D10="$(mktemp -d)"
237
+ mkdir -p "$D10/scripts" "$D10/dist"
238
+ cp "$SUBJECT" "$D10/scripts/files_manifest_shipping_check.sh"
239
+ echo 'console.log("hi");' > "$D10/dist/index.js"
240
+ cat > "$D10/package.json" <<'EOF'
241
+ {
242
+ "name": "fmsc-lane10-fixture",
243
+ "version": "1.0.0",
244
+ "files": ["dist/index.js"]
245
+ }
246
+ EOF
247
+ ( cd "$D10" && git init -q && git -c user.email=t@t -c user.name=t add -A && git -c user.email=t@t -c user.name=t commit -q -m init )
248
+ if out=$(bash "$D10/scripts/files_manifest_shipping_check.sh" --vs-tarball 2>&1); rc=$?; [ "$rc" -eq 0 ] && printf '%s' "$out" | grep -q "ADVISORY\|small package"; then
249
+ ok "lane 10: tiny (<10-file) tarball PASSes with an advisory, not an automatic FAIL"
250
+ else
251
+ bad "lane 10: tiny valid tarball should PASS with advisory, not hard-fail on count — got rc=$rc"
252
+ printf '%s\n' "$out" | sed 's/^/ /'
253
+ fi
254
+ rm -rf "$D10"
255
+
256
+ echo "files-manifest-shipping lanes: $pass passed, $fail failed"
257
+ if [ "$fail" -gt 0 ]; then
258
+ exit 1
259
+ fi
260
+ exit 0