Skip to content

Commit addb354

Browse files
committed
Add trace
1 parent 479c382 commit addb354

6 files changed

Lines changed: 259 additions & 30 deletions

File tree

.github/workflows/ci.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ jobs:
131131
- name: Install dependencies
132132
run: sudo apt-get update && sudo apt-get install -y jq
133133

134+
- name: Environment snapshot
135+
run: |
136+
echo "=== CI Environment Diagnostic ==="
137+
echo "OS: $(uname -a)"
138+
echo "Shell: $SHELL ($BASH_VERSION)"
139+
echo "jq: $(command -v jq && jq --version || echo 'NOT INSTALLED')"
140+
echo "perl: $(perl -v | head -2)"
141+
echo "grep: $(grep --version | head -1)"
142+
echo "================================="
143+
134144
- name: Make scripts executable
135145
run: |
136146
chmod +x ./dist/bin/check-performance.sh

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3232
- **Architecture:** Script defaults to JSON output → parses with `jq` → falls back to text if `jq` unavailable
3333
- **Impact:** Tests now parse JSON correctly in CI environment (9/10 tests passing)
3434

35+
### Added
36+
- **Test Suite** - Comprehensive debugging and validation infrastructure
37+
- **Dependency checks**: Fail-fast validation for `jq` and `perl` with installation instructions
38+
- **Trace mode**: `./tests/run-fixture-tests.sh --trace` for detailed debugging output
39+
- **JSON parsing helper**: `parse_json_output()` function with explicit error handling
40+
- **Numeric validation**: Validates parsed error/warning counts are numeric before comparison
41+
- **Environment snapshot**: Shows OS, shell, tool versions at test start (useful for CI debugging)
42+
- **Detailed tracing**: Logs exit codes, file sizes, parsing method, and intermediate values
43+
- **Explicit format flag**: Tests now use `--format json` explicitly (protects against default changes)
44+
- **Removed dead code**: Eliminated unreachable text parsing fallback (JSON-only architecture)
45+
- **Impact:** Silent failures now caught immediately with clear error messages
46+
3547
### Changed
3648
- **Documentation** - Enhanced `dist/TEMPLATES/README.md` with context and background
3749
- Added "What Are Templates?" section explaining the concept and purpose
@@ -40,6 +52,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4052
- Added location context at the top (`dist/TEMPLATES/` in your WP Code Check installation)
4153
- **Impact:** New users can now understand templates immediately without reading the entire guide
4254

55+
- **Test Suite** - Incremented version to 1.0.81 (from 1.0.80)
56+
- Reflects addition of debugging infrastructure and validation improvements
57+
4358
### Removed
4459
- **GitHub Workflows** - Removed `.github/workflows/example-caller.yml` template file
4560
- This was a documentation-only template file that never ran automatically

PROJECT/1-INBOX/FIX-CICD.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# FIX-CICD: CI fixture tests failing on Ubuntu (jq missing)
2+
3+
**Created:** 2026-01-09
4+
**Status:** Not Started
5+
**Priority:** High
6+
7+
## Problem/Request
8+
GitHub Actions CI was failing (9/10 fixture tests failing on Ubuntu) while passing locally on macOS.
9+
10+
## Root Cause (confirmed)
11+
The fixture test runner [dist/tests/run-fixture-tests.sh](../../dist/tests/run-fixture-tests.sh) parses scanner output as JSON using `jq`.
12+
13+
- In GitHub Actions Ubuntu runners, `jq` is not guaranteed to be present.
14+
- When `jq` is missing, the script’s JSON-parse branch fails and it falls back to *text* parsing.
15+
- Because [dist/bin/check-performance.sh](../../dist/bin/check-performance.sh) defaults to JSON output (`OUTPUT_FORMAT="json"`), the text parsing fallback fails too.
16+
17+
## Code Review Findings
18+
19+
### ✅ What’s good
20+
- **Correct fix direction:** Installing `jq` in CI aligns with a JSON-first architecture and also supports Slack/report tooling in [ .github/workflows/ci.yml](../../.github/workflows/ci.yml).
21+
- **Avoids weakening tests:** Not forcing `--format text` keeps parsing stable and avoids brittle greps for human output.
22+
- **Script already has some resilience:** The fixture runner strips ANSI codes and captures output to temp files, which helps keep parsing deterministic.
23+
24+
### ⚠️ Correctness / Robustness gaps
25+
1. **`jq` absence triggers the wrong fallback path**
26+
- In [dist/tests/run-fixture-tests.sh](../../dist/tests/run-fixture-tests.sh), the decision boundary is “can I run `jq empty`?” rather than “is the output JSON?”.
27+
- Result: if output *is* JSON but `jq` is missing, the script attempts text parsing, which is structurally incapable of working.
28+
29+
2. **Implicit reliance on default output format**
30+
- `run_test()` calls `check-performance.sh` without `--format json`, relying on its default.
31+
- That’s currently stable (default is documented as JSON), but making it explicit would strengthen the contract between the test runner and the scanner.
32+
33+
3. **CHANGELOG inconsistency / mixed narrative**
34+
- In [CHANGELOG.md](../../CHANGELOG.md) under **Unreleased → Fixed → Test Suite**, it claims:
35+
- “Fixed JSON parsing in test script to use grep-based parsing (no jq dependency)”
36+
- But the current script is `jq`-primary and CI explicitly installs `jq`.
37+
- The entry also says both “All 10 fixture tests now pass” and later “(9/10 tests passing)”, which reads as contradictory.
38+
39+
4. **Duplication in CI dependency installation**
40+
- [ .github/workflows/ci.yml](../../.github/workflows/ci.yml) installs `jq` in both jobs separately.
41+
- This is fine, but it’s repeated maintenance surface.
42+
43+
## Recommendations (no code changes requested)
44+
45+
### 1) Make jq a declared prerequisite *or* make JSON parsing dependency-free
46+
Pick one and make it consistent across CI + docs:
47+
48+
- **Option A (declare jq required):**
49+
- Treat `jq` as a hard dependency of the fixture runner.
50+
- In CI, keep installing it.
51+
- In local/dev, add a clear early check like `command -v jq` and fail with an actionable error message.
52+
53+
- **Option B (remove jq dependency):**
54+
- Replace the `jq` parsing path in `run_test()` with a dependency-free JSON extraction (e.g., minimal grep extraction, or `python3 -c` JSON parsing).
55+
- This matches the existing “no jq dependency” statements in the changelog.
56+
57+
### 2) Don’t use “text parsing” as a fallback for “jq missing”
58+
If you keep a fallback:
59+
- First detect whether output is JSON (e.g., begins with `{` after stripping ANSI).
60+
- If output is JSON but `jq` is missing, either:
61+
- fail with a clear message, or
62+
- use a dependency-free JSON parser fallback.
63+
64+
### 3) Make format explicit in tests
65+
Even if the scanner default remains JSON:
66+
- Have the fixture tests call `check-performance.sh --format json` consistently.
67+
- This prevents future surprises if the scanner’s default changes.
68+
69+
### 4) Clarify and reconcile CHANGELOG statements
70+
Update the Unreleased entry so it matches reality:
71+
- If CI installs `jq` and tests rely on it, remove/adjust the “no jq dependency” claim.
72+
- Fix the “All 10 pass” vs “9/10 pass” inconsistency.
73+
74+
### 5) CI hardening (optional)
75+
- Print `jq --version` after install for easier diagnosis.
76+
- Consider using `sudo apt-get install -y jq` (with update) as you already do; it’s fine.
77+
- If apt install is a concern, failing the job is acceptable because tests can’t run correctly without `jq` under the current design.
78+
79+
## Edge Cases / Risks to watch
80+
- **Runner image changes:** `ubuntu-latest` can change; explicit installation avoids surprises.
81+
- **JSON schema changes:** Tests assume `.summary.total_errors` and `.summary.total_warnings` exist.
82+
- If the JSON schema changes, the tests should fail loudly (ideally with a clear schema mismatch message).
83+
- **Non-JSON noise:** Any stderr logging mixed into JSON output will break parsing.
84+
- Scanner already has safeguards to avoid corrupting JSON; ensure future debug logging stays format-aware.
85+
86+
## Acceptance Criteria
87+
- [ ] CI passes fixture validation on `ubuntu-latest` reliably.
88+
- [ ] Fixture tests either (A) explicitly require `jq` with a clear error, or (B) remain dependency-free.
89+
- [ ] CHANGELOG entry accurately describes the final architecture and outcome (10/10 passing).

dist/PATTERN-LIBRARY.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"version": "1.0.0",
3-
"generated": "2026-01-10T04:47:43Z",
3+
"generated": "2026-01-10T05:01:21Z",
44
"summary": {
55
"total_patterns": 29,
66
"enabled": 29,

dist/PATTERN-LIBRARY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Pattern Library Registry
22

33
**Auto-generated by Pattern Library Manager**
4-
**Last Updated:** 2026-01-10 04:47:43 UTC
4+
**Last Updated:** 2026-01-10 05:01:21 UTC
55

66
---
77

@@ -117,6 +117,6 @@
117117

118118
---
119119

120-
**Generated:** 2026-01-10 04:47:43 UTC
120+
**Generated:** 2026-01-10 05:01:21 UTC
121121
**Version:** 1.0.0
122122
**Tool:** Pattern Library Manager

0 commit comments

Comments
 (0)