@boyingliu01/xp-gate 0.38.32 → 0.38.34

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 (34) hide show
  1. package/adapters/gate-3.sh +39 -3
  2. package/adapters/gate-4.sh +1 -1
  3. package/adapters/iac.sh +13 -0
  4. package/adapters/php.sh +362 -0
  5. package/gate-3.sh +39 -3
  6. package/gate-4.sh +1 -1
  7. package/hooks/gate-3.sh +39 -3
  8. package/hooks/gate-4.sh +1 -1
  9. package/lib/__tests__/language-capability.test.js +291 -0
  10. package/lib/__tests__/language-tools-detect.test.js +82 -0
  11. package/lib/language-capability-surfaces.js +315 -0
  12. package/lib/language-capability.js +474 -0
  13. package/lib/language-tools.js +107 -0
  14. package/lib/mattpocock-license-verdict.json +1 -1
  15. package/package.json +1 -1
  16. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  17. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  18. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  19. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  20. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  21. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  22. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  23. package/plugins/opencode/package.json +1 -1
  24. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  25. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  26. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  27. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  28. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  29. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  30. package/principles/adapters/php.ts +77 -0
  31. package/principles/analyzer.ts +6 -0
  32. package/skills/delphi-review/AGENTS.md +1 -1
  33. package/skills/sprint-flow/AGENTS.md +1 -1
  34. package/skills/test-specification-alignment/AGENTS.md +1 -1
@@ -363,7 +363,20 @@ else
363
363
  LIZARD_PATH=$(eval echo "$LIZARD_CMD")
364
364
 
365
365
  # Get changed source files for complexity check (includes test files)
366
- CC_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|swift|cpp|c|hpp|h|m|mm|kt|cs)$' || true)
366
+ #
367
+ # #847: `dart` added. The writer (scripts/ccn-report.cjs SOURCE_EXT) has
368
+ # listed `dart` all along, and so do Gate 2's SOURCE_FILES, Gate 4's
369
+ # PRINCIPLES_FILES and both dart.sh/flutter.sh adapters -- so the READER of
370
+ # the baseline was the one place that disagreed with everything else, and
371
+ # Dart cyclomatic complexity was never graded. Measured: `lizard --csv -C 5`
372
+ # on a Dart file emits a real CCN row, so the gap was never tool capability.
373
+ #
374
+ # THIS FILE HAS A TWIN. `githooks/gate-3.sh` and `githooks/adapters/gate-3.sh`
375
+ # were byte-identical before this change (md5 1d4e07cc...), and tests source
376
+ # the one under `adapters/`. A fix applied to only one of them leaves the
377
+ # other silently wrong -- which is how this edit was first written and how
378
+ # the accompanying test failed. Any change here must land in BOTH.
379
+ CC_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|swift|cpp|c|hpp|h|m|mm|kt|cs|dart|php|phtml)$' || true)
367
380
 
368
381
  # Grade exactly the population the baseline was written from. The two must
369
382
  # match or the ratchet reports pre-existing code as "new", which is a false
@@ -484,8 +497,31 @@ else
484
497
  _cc_pop_skipped=""
485
498
  while IFS= read -r _cc_row; do
486
499
  [ -n "$_cc_row" ] || continue
487
- _cc_row_path=$(printf '%s' "$_cc_row" | awk -F, '{print $1}')
488
- if ccn_file_in_population ".ccn-baseline.json" "$_cc_row_path"; then
500
+ # The path is column 7 (index 6) of a lizard --csv row, NOT column 1.
501
+ #
502
+ # Column order (lizard --csv, no header, 11 fields):
503
+ # 0 NLOC | 1 CCN | 2 token_len | 3 param_count | 4 location_size
504
+ # 5 "name@start-end@path" | 6 path | 7 name | 8 signature | ...
505
+ # This read `$1` -- that is NLOC, not the path -- so every path
506
+ # handed to ccn_file_in_population was a bare number like "17".
507
+ # No number matches a declared root or extension, so EVERY row was
508
+ # classified "outside the baseline population" and dropped: the gate
509
+ # graded nothing, printed "not graded, not ratcheted", and fell
510
+ # through to "UNVERIFIED no parsable CCN row". The population filter
511
+ # therefore disabled the ratchet for ALL languages, not just the one
512
+ # it was being added for.
513
+ #
514
+ # Quote-aware via the shared awk helper rather than a second `-F,`
515
+ # split: the signature column (8) contains commas, so a naive field
516
+ # split lands on the wrong column as soon as a signature is present.
517
+ _cc_row_path=$(printf '%s' "$_cc_row" | csv_to_unit_separated | awk -F'\\037' '{print $7}')
518
+ # A row we cannot locate cannot be scoped: keep it and let the
519
+ # verifier decide, rather than silently dropping it as "out of
520
+ # population" — dropping is how "checked" became "checked nothing".
521
+ if [ -z "$_cc_row_path" ]; then
522
+ _cc_pop_kept="${_cc_pop_kept}${_cc_row}
523
+ "
524
+ elif ccn_file_in_population ".ccn-baseline.json" "$_cc_row_path"; then
489
525
  _cc_pop_kept="${_cc_pop_kept}${_cc_row}
490
526
  "
491
527
  else
@@ -76,7 +76,7 @@ if [ "$PROJECT_LANG" = "documentation-only" ]; then
76
76
 
77
77
  else
78
78
  # Get source files to check against principles
79
- PRINCIPLES_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|kt|dart|swift|cpp|c|hpp|h|m|mm|cs)$' || true)
79
+ PRINCIPLES_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|kt|dart|swift|cpp|c|hpp|h|m|mm|cs|php)$' || true)
80
80
 
81
81
  # One path per line, into an array. Passing $PRINCIPLES_FILES unquoted relies on
82
82
  # word splitting to turn the list into separate argv entries, which also splits
package/adapters/iac.sh CHANGED
@@ -59,6 +59,19 @@ detect_iac_files() {
59
59
 
60
60
  run_static_analysis() {
61
61
  local changed_files="$1"
62
+ # Gate 1 calls this with NO argument (githooks/gate-entries/gate-1-entry.sh
63
+ # does `G1A_OUTPUT=$(run_static_analysis 2>&1)`) and routes by $CURRENT_LANG
64
+ # instead. An empty $1 therefore means "everything the gate already decided is
65
+ # in scope", not "nothing to do" -- fall back to the staged set the gate keeps
66
+ # in $CHANGED_FILES. Without this, `detect_iac_files ""` finds no files,
67
+ # `has_iac` is false, and the function returns 0 before reaching any check.
68
+ #
69
+ # Measured: through the hook, Gate 1 printed "✅ PASSED - Language-specific
70
+ # code quality checks." for an unparseable .tf file; called directly with the
71
+ # filename it returned 1. The adapter was fine; the argument was empty.
72
+ if [ -z "$changed_files" ] && [ -n "${CHANGED_FILES:-}" ]; then
73
+ changed_files="$CHANGED_FILES"
74
+ fi
62
75
  local iac_files=$(detect_iac_files "$changed_files")
63
76
 
64
77
  # Check if any IaC files are present
@@ -0,0 +1,362 @@
1
+ #!/usr/bin/env bash
2
+ # ============================================================================
3
+ # PHP adapter -- GATE 1/5 (#731, following the C# adapter's shape)
4
+ #
5
+ # Sourced directly by the gate entries; there is no dispatcher between them
6
+ # (#688). Every function below must therefore exist and must return a status the
7
+ # caller can turn into a verdict:
8
+ #
9
+ # 0 = PASS tool ran, found nothing
10
+ # 1 = FAIL tool ran, found violations (blocks)
11
+ # 2 = BLOCK tool could NOT run -> fail closed, never "clean"
12
+ # 3 = WARN non-blocking observation
13
+ #
14
+ # ---------------------------------------------------------------------------
15
+ # WHY THIS FILE DOES NOT COPY THE C# ADAPTER'S DETECTION TRICK
16
+ #
17
+ # csharp.sh hoists its manifest detection arm to the FRONT of the detection
18
+ # chain. PHP must not: `composer.json` is NOT exclusive -- a JavaScript project
19
+ # with a composer wrapper for one build step has one too, and promoting it would
20
+ # relabel the whole repo as PHP. PHP therefore has to be correct on the
21
+ # EXTENSION side, and this file never assumes a repo is PHP just because a
22
+ # composer.json exists (`_php_detect_root` only *locates* the working directory;
23
+ # the gate decides whether to call this adapter at all).
24
+ #
25
+ # ---------------------------------------------------------------------------
26
+ # MEASURED TOOL CONTRACTS (2026-11-19, php 8.4.27 + composer 2.11.2)
27
+ #
28
+ # phpcs (squizlabs/php_codesniffer 3.11)
29
+ # 0 = clean
30
+ # 2 = errors found
31
+ # 3 = THE TOOL COULD NOT RUN (unknown --standard, missing path)
32
+ # Exit 3 is the trap: it is NOT "more violations". An adapter that folds
33
+ # everything non-zero into FAIL reports "your code is bad" when the standard
34
+ # was merely misspelled. 3 maps to BLOCK (2), matching csharp.sh's 126/127
35
+ # handling of `dotnet format`.
36
+ #
37
+ # phpstan (2.x)
38
+ # 0 = no errors
39
+ # 1 = errors found
40
+ # 1 = ALSO used for a bad path / bad config, i.e. phpstan does not
41
+ # distinguish "found problems" from "could not run" in its exit code.
42
+ # Because the exit code cannot separate those two, the structured output is
43
+ # parsed instead: `--error-format=raw` emits `path:line:message`, while a
44
+ # configuration failure writes its explanation to stderr and no raw rows. A
45
+ # non-zero exit with ZERO raw rows is therefore "could not run" (BLOCK), not
46
+ # "clean" -- the same defect class as reading a scanner's exit code as a
47
+ # severity.
48
+ #
49
+ # phpunit (11.x)
50
+ # 0 = pass, 1 = failures, 2 = errors/aborted
51
+ #
52
+ # Coverage: PHPUnit emits Cobertura natively via --coverage-cobertura.
53
+ # Gate 5 Stage 2 already parses <coverage line-rate="..."> (#768), so no new
54
+ # verdict parser is needed -- choosing clover instead would have produced a
55
+ # syntactically valid report Gate 5 cannot read, which is exactly the #768
56
+ # failure this adapter must not repeat. Verified by measuring both formats.
57
+ #
58
+ # A coverage driver is required for ANY coverage report: pcov or xdebug.
59
+ # Without one PHPUnit prints "No code coverage driver available", writes NO
60
+ # file, and exits 0. That combination is indistinguishable from "coverage is
61
+ # 100%" to a caller that only checks the exit code, so run_coverage detects the
62
+ # missing artifact and reports it instead of returning a silent PASS.
63
+ # ============================================================================
64
+
65
+ # Root of the PHP project: the nearest directory with a composer.json, else the
66
+ # nearest with a phpunit.xml, else the current directory.
67
+ #
68
+ # Returns 0 and prints the root; returns 1 when no PHP project marker exists.
69
+ _php_detect_root() {
70
+ local dir="${1:-$PWD}"
71
+ local probe="$dir" found=""
72
+ while [ -n "$probe" ] && [ "$probe" != "/" ]; do
73
+ if [ -f "$probe/composer.json" ]; then found="$probe"; break; fi
74
+ if [ -f "$probe/phpunit.xml" ] || [ -f "$probe/phpunit.xml.dist" ]; then
75
+ found="$probe"; break
76
+ fi
77
+ probe=$(dirname "$probe")
78
+ done
79
+ if [ -z "$found" ]; then
80
+ if [ -f "composer.json" ] || [ -f "phpunit.xml" ] || [ -f "phpunit.xml.dist" ]; then
81
+ found="$PWD"
82
+ fi
83
+ fi
84
+ [ -n "$found" ] || return 1
85
+ printf '%s\n' "$found"
86
+ }
87
+
88
+ # A PHP command name that actually resolves. `php` may be satisfied by a shim.
89
+ _php_bin() {
90
+ local c
91
+ for c in php php84 php83 php82; do
92
+ if command -v "$c" >/dev/null 2>&1; then command -v "$c"; return 0; fi
93
+ done
94
+ return 1
95
+ }
96
+
97
+ # Resolve a vendor/bin tool. PHP tools live in vendor/bin, installed by
98
+ # composer, and are NOT on PATH -- four independent tools means four separate
99
+ # "not on PATH" cases, which is the PHP-specific difference from C#'s single
100
+ # `dotnet` entry point. Each one is probed in both the bare and .bat forms
101
+ # because MSYS2 only resolves .bat when the extension is spelled out.
102
+ # Usage: _php_vendor_bin <root> <name> ; prints the path or returns 1.
103
+ _php_vendor_bin() {
104
+ local root="$1" name="$2" base cand
105
+ for base in "vendor/bin" ".build/vendor/bin" "tools/vendor/bin"; do
106
+ for cand in "$root/$base/$name" "$root/$base/$name.bat" "$root/$base/$name.phar"; do
107
+ if [ -f "$cand" ]; then printf '%s\n' "$cand"; return 0; fi
108
+ done
109
+ done
110
+ # Also accept a globally installed tool (phpcs/phpstan installed via composer
111
+ # global). Probing PATH is what makes the adapter usable outside a project.
112
+ for cand in "$name" "$name.bat" "$name.phar"; do
113
+ if command -v "$cand" >/dev/null 2>&1; then command -v "$cand"; return 0; fi
114
+ done
115
+ return 1
116
+ }
117
+
118
+ # Composer is needed for install/test discovery, and is its own failure mode.
119
+ _php_composer_bin() {
120
+ local c
121
+ for c in composer composer.bat composer.phar; do
122
+ if command -v "$c" >/dev/null 2>&1; then command -v "$c"; return 0; fi
123
+ done
124
+ return 1
125
+ }
126
+
127
+ # ---------------------------------------------------------------------------
128
+ # run_static_analysis -- phpstan
129
+ #
130
+ # Returns 0 (clean) / 1 (findings) / 2 (could not run) / 3 (warn).
131
+ # ---------------------------------------------------------------------------
132
+ run_static_analysis() {
133
+ local root php phpstan level out rc rows
134
+ root=$(_php_detect_root) || { echo "No composer.json / phpunit.xml found -- not a PHP project"; return 0; }
135
+ php=$(_php_bin) || {
136
+ echo "php is not installed -- static analysis not measurable"
137
+ echo " Install: scoop install php (or winget install PHP.PHP.8.4)"
138
+ return 2
139
+ }
140
+
141
+ if ! phpstan=$(_php_vendor_bin "$root" phpstan); then
142
+ echo "phpstan is not installed -- static analysis not measurable"
143
+ echo " Install: composer require --dev phpstan/phpstan"
144
+ return 2
145
+ fi
146
+
147
+ # Honour the project's declared level; default to 5 (phpstan's own practical
148
+ # baseline) rather than 0, which analyses almost nothing and would report a
149
+ # clean run over code it barely inspected.
150
+ level="${XP_GATE_PHPSTAN_LEVEL:-}"
151
+ if [ -z "$level" ]; then
152
+ if [ -f "$root/phpstan.neon" ] || [ -f "$root/phpstan.neon.dist" ]; then
153
+ level="" # let phpstan read its own config
154
+ else
155
+ level="--level=5"
156
+ fi
157
+ else
158
+ level="--level=${level}"
159
+ fi
160
+
161
+ # --error-format=raw makes the verdict machine-readable; without it the table
162
+ # renderer's output would have to be parsed, which is what the G1 contract
163
+ # forbids.
164
+ # shellcheck disable=SC2086
165
+ out=$("$php" "$phpstan" analyse $level --no-progress --error-format=raw 2>&1)
166
+ rc=$?
167
+
168
+ # Count only rows that look like diagnostics (path:line:message). A non-zero
169
+ # exit with zero such rows is a configuration/execution fault, NOT "clean".
170
+ rows=$(printf '%s\n' "$out" | grep -cE '^[^ ]+:[0-9]+:' || true)
171
+
172
+ if [ "$rc" -eq 0 ]; then
173
+ echo "phpstan: no errors"
174
+ return 0
175
+ fi
176
+ if [ "${rows:-0}" -gt 0 ]; then
177
+ printf '%s\n' "$out" | sed -n '1,25p'
178
+ echo "phpstan reported ${rows} finding(s)"
179
+ return 1
180
+ fi
181
+ # Non-zero, no diagnostics: the tool could not do its job.
182
+ printf '%s\n' "$out" | sed -n '1,15p'
183
+ echo "phpstan could not run (no diagnostic rows produced) -- refusing to report this as clean"
184
+ return 2
185
+ }
186
+
187
+ # ---------------------------------------------------------------------------
188
+ # run_lint -- phpcs
189
+ #
190
+ # Exit 3 is deliberately mapped to BLOCK(2): measured, phpcs uses 3 for an
191
+ # unknown --standard and for a missing path, not for "more errors".
192
+ # ---------------------------------------------------------------------------
193
+ run_lint() {
194
+ local root php phpcs standard out rc
195
+ root=$(_php_detect_root) || { echo "No composer.json / phpunit.xml found -- not a PHP project"; return 0; }
196
+ php=$(_php_bin) || {
197
+ echo "php is not installed -- lint not measurable"
198
+ return 2
199
+ }
200
+
201
+ if ! phpcs=$(_php_vendor_bin "$root" phpcs); then
202
+ echo "phpcs is not installed -- lint not measurable"
203
+ echo " Install: composer require --dev squizlabs/php_codesniffer"
204
+ return 2
205
+ fi
206
+
207
+ # A project that declares its own standard wins; otherwise PSR12. The value is
208
+ # validated rather than trusted: an unknown standard makes phpcs exit 3, which
209
+ # is a tool failure, and silently falling back would hide a typo in the
210
+ # project's own config.
211
+ standard="${XP_GATE_PHPCS_STANDARD:-}"
212
+ if [ -z "$standard" ]; then
213
+ if [ -f "$root/phpcs.xml" ] || [ -f "$root/phpcs.xml.dist" ] \
214
+ || [ -f "$root/.phpcs.xml" ] || [ -f "$root/.phpcs.xml.dist" ]; then
215
+ standard="" # phpcs picks up its own ruleset
216
+ else
217
+ standard="--standard=PSR12"
218
+ fi
219
+ else
220
+ standard="--standard=${standard}"
221
+ fi
222
+
223
+ # Target the conventional source roots when they exist, so a repo's tests
224
+ # directory does not produce style noise about production code.
225
+ local targets=() t
226
+ for t in src app lib; do [ -d "$root/$t" ] && targets+=("$t"); done
227
+ if [ "${#targets[@]}" -eq 0 ]; then
228
+ echo "phpcs: no src/ app/ lib/ directory found to lint"
229
+ return 0
230
+ fi
231
+
232
+ # shellcheck disable=SC2086
233
+ out=$("$php" "$phpcs" $standard --report=full "${targets[@]/#/$root/}" 2>&1)
234
+ rc=$?
235
+
236
+ case "$rc" in
237
+ 0)
238
+ echo "phpcs: no violations"
239
+ return 0
240
+ ;;
241
+ 1|2)
242
+ printf '%s\n' "$out" | sed -n '1,25p'
243
+ echo "phpcs found violations"
244
+ return 1
245
+ ;;
246
+ 3)
247
+ # Measured: unknown --standard or a path phpcs cannot open.
248
+ printf '%s\n' "$out" | sed -n '1,15p'
249
+ echo "phpcs could not run (exit 3: bad standard or unusable path), not a violation"
250
+ return 2
251
+ ;;
252
+ *)
253
+ printf '%s\n' "$out" | sed -n '1,15p'
254
+ echo "phpcs exited ${rc} -- unexpected status, treating as could-not-run"
255
+ return 2
256
+ ;;
257
+ esac
258
+ }
259
+
260
+ # ---------------------------------------------------------------------------
261
+ # run_tests -- phpunit
262
+ # ---------------------------------------------------------------------------
263
+ run_tests() {
264
+ local root php phpunit out rc
265
+ root=$(_php_detect_root) || { echo "No composer.json / phpunit.xml found -- not a PHP project"; return 0; }
266
+ php=$(_php_bin) || {
267
+ echo "php is not installed -- tests not measurable"
268
+ return 2
269
+ }
270
+
271
+ if [ ! -f "$root/phpunit.xml" ] && [ ! -f "$root/phpunit.xml.dist" ]; then
272
+ echo "No phpunit.xml(.dist) found -- test suite not discoverable"
273
+ echo " Gate 5 cannot distinguish 'no tests' from 'tests not configured'; declare a suite to have it run"
274
+ return 2
275
+ fi
276
+
277
+ if ! phpunit=$(_php_vendor_bin "$root" phpunit); then
278
+ echo "phpunit is not installed -- tests not measurable"
279
+ echo " Install: composer require --dev phpunit/phpunit"
280
+ return 2
281
+ fi
282
+
283
+ out=$(cd "$root" && "$php" "$phpunit" --no-progress 2>&1)
284
+ rc=$?
285
+ printf '%s\n' "$out" | sed -n '1,30p'
286
+
287
+ case "$rc" in
288
+ 0) echo "phpunit: all tests passed"; return 0 ;;
289
+ 1) echo "phpunit: test failures"; return 1 ;;
290
+ 2) echo "phpunit: errors or aborted run -- not a test verdict"; return 2 ;;
291
+ 255) echo "phpunit could not start (bad configuration or bootstrap)"; return 2 ;;
292
+ *) echo "phpunit exited ${rc} -- unexpected status"; return 2 ;;
293
+ esac
294
+ }
295
+
296
+ # ---------------------------------------------------------------------------
297
+ # run_coverage -- phpunit --coverage-cobertura
298
+ #
299
+ # DOES run the suite: PHPUnit's coverage options execute the tests and write the
300
+ # report in one invocation, so Gate 5 does not need a second pass. Declared via
301
+ # coverage_runs_tests() below, which is what lets Gate 5 run the suite once
302
+ # instead of twice (the C# adapter made the same declaration after #798 measured
303
+ # a 28.5s+30.0s duplicate).
304
+ # ---------------------------------------------------------------------------
305
+ coverage_runs_tests() { return 0; }
306
+
307
+ run_coverage() {
308
+ local root php phpunit out rc report
309
+ root=$(_php_detect_root) || { echo "No composer.json / phpunit.xml found -- not a PHP project"; return 0; }
310
+ php=$(_php_bin) || {
311
+ echo "php is not installed -- coverage not measurable"
312
+ return 2
313
+ }
314
+
315
+ if [ ! -f "$root/phpunit.xml" ] && [ ! -f "$root/phpunit.xml.dist" ]; then
316
+ echo "No phpunit.xml(.dist) found -- coverage not measurable"
317
+ return 2
318
+ fi
319
+
320
+ if ! phpunit=$(_php_vendor_bin "$root" phpunit); then
321
+ echo "phpunit is not installed -- coverage not measurable"
322
+ return 2
323
+ fi
324
+
325
+ # A coverage driver is mandatory. Without one PHPUnit writes no report and
326
+ # still exits 0, which reads as full coverage to anything checking only the
327
+ # exit status. Detect it up front so the reason is explicit.
328
+ local drivers
329
+ drivers=$("$php" -r 'echo implode(",", array_filter(["pcov","xdebug"], fn($d)=>extension_loaded($d)));' 2>/dev/null)
330
+ if [ -z "$drivers" ]; then
331
+ echo "No PHP coverage driver installed (pcov or xdebug required) -- coverage not measurable"
332
+ echo " Install: php_pcov.dll from windows.php.net/downloads/pecl/releases/pcov, or xdebug"
333
+ echo " Refusing to report 0% (a measured value) for an unmeasured suite"
334
+ return 2
335
+ fi
336
+ echo "Coverage driver: ${drivers}"
337
+
338
+ # Cobertura, not clover: Gate 5 Stage 2 parses <coverage line-rate="...">
339
+ # (#768) and has no clover arm. Choosing clover here would produce a valid
340
+ # report the gate cannot read -- the exact #768 shape.
341
+ report="$root/coverage/cobertura.xml"
342
+ mkdir -p "$root/coverage" 2>/dev/null || true
343
+ rm -f "$report" 2>/dev/null || true
344
+
345
+ out=$(cd "$root" && "$php" "$phpunit" --no-progress --coverage-cobertura "$report" 2>&1)
346
+ rc=$?
347
+ printf '%s\n' "$out" | sed -n '1,25p'
348
+
349
+ if [ ! -f "$report" ]; then
350
+ echo "phpunit produced no Cobertura report at ${report} -- coverage not measurable"
351
+ return 2
352
+ fi
353
+ echo "Coverage report: ${report}"
354
+
355
+ # A suite whose tests failed still produced a report; report the failure so the
356
+ # caller's verdict reflects the tests, not just the percentage.
357
+ if [ "$rc" -ne 0 ]; then
358
+ echo "phpunit exited ${rc} while collecting coverage -- tests did not all pass"
359
+ return 1
360
+ fi
361
+ return 0
362
+ }
package/gate-3.sh CHANGED
@@ -363,7 +363,20 @@ else
363
363
  LIZARD_PATH=$(eval echo "$LIZARD_CMD")
364
364
 
365
365
  # Get changed source files for complexity check (includes test files)
366
- CC_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|swift|cpp|c|hpp|h|m|mm|kt|cs)$' || true)
366
+ #
367
+ # #847: `dart` added. The writer (scripts/ccn-report.cjs SOURCE_EXT) has
368
+ # listed `dart` all along, and so do Gate 2's SOURCE_FILES, Gate 4's
369
+ # PRINCIPLES_FILES and both dart.sh/flutter.sh adapters -- so the READER of
370
+ # the baseline was the one place that disagreed with everything else, and
371
+ # Dart cyclomatic complexity was never graded. Measured: `lizard --csv -C 5`
372
+ # on a Dart file emits a real CCN row, so the gap was never tool capability.
373
+ #
374
+ # THIS FILE HAS A TWIN. `githooks/gate-3.sh` and `githooks/adapters/gate-3.sh`
375
+ # were byte-identical before this change (md5 1d4e07cc...), and tests source
376
+ # the one under `adapters/`. A fix applied to only one of them leaves the
377
+ # other silently wrong -- which is how this edit was first written and how
378
+ # the accompanying test failed. Any change here must land in BOTH.
379
+ CC_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|swift|cpp|c|hpp|h|m|mm|kt|cs|dart|php|phtml)$' || true)
367
380
 
368
381
  # Grade exactly the population the baseline was written from. The two must
369
382
  # match or the ratchet reports pre-existing code as "new", which is a false
@@ -484,8 +497,31 @@ else
484
497
  _cc_pop_skipped=""
485
498
  while IFS= read -r _cc_row; do
486
499
  [ -n "$_cc_row" ] || continue
487
- _cc_row_path=$(printf '%s' "$_cc_row" | awk -F, '{print $1}')
488
- if ccn_file_in_population ".ccn-baseline.json" "$_cc_row_path"; then
500
+ # The path is column 7 (index 6) of a lizard --csv row, NOT column 1.
501
+ #
502
+ # Column order (lizard --csv, no header, 11 fields):
503
+ # 0 NLOC | 1 CCN | 2 token_len | 3 param_count | 4 location_size
504
+ # 5 "name@start-end@path" | 6 path | 7 name | 8 signature | ...
505
+ # This read `$1` -- that is NLOC, not the path -- so every path
506
+ # handed to ccn_file_in_population was a bare number like "17".
507
+ # No number matches a declared root or extension, so EVERY row was
508
+ # classified "outside the baseline population" and dropped: the gate
509
+ # graded nothing, printed "not graded, not ratcheted", and fell
510
+ # through to "UNVERIFIED no parsable CCN row". The population filter
511
+ # therefore disabled the ratchet for ALL languages, not just the one
512
+ # it was being added for.
513
+ #
514
+ # Quote-aware via the shared awk helper rather than a second `-F,`
515
+ # split: the signature column (8) contains commas, so a naive field
516
+ # split lands on the wrong column as soon as a signature is present.
517
+ _cc_row_path=$(printf '%s' "$_cc_row" | csv_to_unit_separated | awk -F'\\037' '{print $7}')
518
+ # A row we cannot locate cannot be scoped: keep it and let the
519
+ # verifier decide, rather than silently dropping it as "out of
520
+ # population" — dropping is how "checked" became "checked nothing".
521
+ if [ -z "$_cc_row_path" ]; then
522
+ _cc_pop_kept="${_cc_pop_kept}${_cc_row}
523
+ "
524
+ elif ccn_file_in_population ".ccn-baseline.json" "$_cc_row_path"; then
489
525
  _cc_pop_kept="${_cc_pop_kept}${_cc_row}
490
526
  "
491
527
  else
package/gate-4.sh CHANGED
@@ -76,7 +76,7 @@ if [ "$PROJECT_LANG" = "documentation-only" ]; then
76
76
 
77
77
  else
78
78
  # Get source files to check against principles
79
- PRINCIPLES_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|kt|dart|swift|cpp|c|hpp|h|m|mm|cs)$' || true)
79
+ PRINCIPLES_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|kt|dart|swift|cpp|c|hpp|h|m|mm|cs|php)$' || true)
80
80
 
81
81
  # One path per line, into an array. Passing $PRINCIPLES_FILES unquoted relies on
82
82
  # word splitting to turn the list into separate argv entries, which also splits
package/hooks/gate-3.sh CHANGED
@@ -363,7 +363,20 @@ else
363
363
  LIZARD_PATH=$(eval echo "$LIZARD_CMD")
364
364
 
365
365
  # Get changed source files for complexity check (includes test files)
366
- CC_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|swift|cpp|c|hpp|h|m|mm|kt|cs)$' || true)
366
+ #
367
+ # #847: `dart` added. The writer (scripts/ccn-report.cjs SOURCE_EXT) has
368
+ # listed `dart` all along, and so do Gate 2's SOURCE_FILES, Gate 4's
369
+ # PRINCIPLES_FILES and both dart.sh/flutter.sh adapters -- so the READER of
370
+ # the baseline was the one place that disagreed with everything else, and
371
+ # Dart cyclomatic complexity was never graded. Measured: `lizard --csv -C 5`
372
+ # on a Dart file emits a real CCN row, so the gap was never tool capability.
373
+ #
374
+ # THIS FILE HAS A TWIN. `githooks/gate-3.sh` and `githooks/adapters/gate-3.sh`
375
+ # were byte-identical before this change (md5 1d4e07cc...), and tests source
376
+ # the one under `adapters/`. A fix applied to only one of them leaves the
377
+ # other silently wrong -- which is how this edit was first written and how
378
+ # the accompanying test failed. Any change here must land in BOTH.
379
+ CC_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|swift|cpp|c|hpp|h|m|mm|kt|cs|dart|php|phtml)$' || true)
367
380
 
368
381
  # Grade exactly the population the baseline was written from. The two must
369
382
  # match or the ratchet reports pre-existing code as "new", which is a false
@@ -484,8 +497,31 @@ else
484
497
  _cc_pop_skipped=""
485
498
  while IFS= read -r _cc_row; do
486
499
  [ -n "$_cc_row" ] || continue
487
- _cc_row_path=$(printf '%s' "$_cc_row" | awk -F, '{print $1}')
488
- if ccn_file_in_population ".ccn-baseline.json" "$_cc_row_path"; then
500
+ # The path is column 7 (index 6) of a lizard --csv row, NOT column 1.
501
+ #
502
+ # Column order (lizard --csv, no header, 11 fields):
503
+ # 0 NLOC | 1 CCN | 2 token_len | 3 param_count | 4 location_size
504
+ # 5 "name@start-end@path" | 6 path | 7 name | 8 signature | ...
505
+ # This read `$1` -- that is NLOC, not the path -- so every path
506
+ # handed to ccn_file_in_population was a bare number like "17".
507
+ # No number matches a declared root or extension, so EVERY row was
508
+ # classified "outside the baseline population" and dropped: the gate
509
+ # graded nothing, printed "not graded, not ratcheted", and fell
510
+ # through to "UNVERIFIED no parsable CCN row". The population filter
511
+ # therefore disabled the ratchet for ALL languages, not just the one
512
+ # it was being added for.
513
+ #
514
+ # Quote-aware via the shared awk helper rather than a second `-F,`
515
+ # split: the signature column (8) contains commas, so a naive field
516
+ # split lands on the wrong column as soon as a signature is present.
517
+ _cc_row_path=$(printf '%s' "$_cc_row" | csv_to_unit_separated | awk -F'\\037' '{print $7}')
518
+ # A row we cannot locate cannot be scoped: keep it and let the
519
+ # verifier decide, rather than silently dropping it as "out of
520
+ # population" — dropping is how "checked" became "checked nothing".
521
+ if [ -z "$_cc_row_path" ]; then
522
+ _cc_pop_kept="${_cc_pop_kept}${_cc_row}
523
+ "
524
+ elif ccn_file_in_population ".ccn-baseline.json" "$_cc_row_path"; then
489
525
  _cc_pop_kept="${_cc_pop_kept}${_cc_row}
490
526
  "
491
527
  else
package/hooks/gate-4.sh CHANGED
@@ -76,7 +76,7 @@ if [ "$PROJECT_LANG" = "documentation-only" ]; then
76
76
 
77
77
  else
78
78
  # Get source files to check against principles
79
- PRINCIPLES_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|kt|dart|swift|cpp|c|hpp|h|m|mm|cs)$' || true)
79
+ PRINCIPLES_FILES=$(echo "$CHANGED_FILES" | grep -E '\.(ts|tsx|js|jsx|py|go|java|kt|dart|swift|cpp|c|hpp|h|m|mm|cs|php)$' || true)
80
80
 
81
81
  # One path per line, into an array. Passing $PRINCIPLES_FILES unquoted relies on
82
82
  # word splitting to turn the list into separate argv entries, which also splits