Skip to content

fix: full JSON output for analyze/status/list/check - #7

Merged
MarcinDudekDev merged 3 commits into
mainfrom
feat/json-output
Sep 13, 2026
Merged

MarcinDudekDev merged 3 commits into
mainfrom
feat/json-output

Conversation

@MarcinDudekDev

Copy link
Copy Markdown
Owner

Fixes #6

--json for analyze, status, list, and check now emits real data instead of placeholders.

  • list --json runs detect_nginx_instances; .instances is {type,name,path}[] (36 on this machine, was always []).
  • analyze --json runs detection. Each feature is {display, applied, detected} — applied from state, detected from the registry. The two are allowed to differ.
  • check --json mirrors the human checks: prerequisites, nginx -t, registry, backup dir, .issues[], .ready iff issues empty.
  • Payloads built with jq -n/--arg so display names cannot break JSON.
  • --help documents the four commands.

Tests: new JSON section in tests/run-tests.sh (assertions fail on main). 123/123. shellcheck --severity=warning clean.

The --json branches were placeholders:

- list --json never called detect_nginx_instances, so .instances was
  always []
- analyze --json never ran registry detection, so features had no
  detected key and applied was read straight from state
- check --json ignored the backup dir, the feature registry and issue
  counting; ready meant only "nginx -t passed"

Now, all four build their payloads with jq (-n/--arg/--argjson) so
display names and paths cannot break the document:

- list --json: .instances is the same {type,name,path} set the human
  list shows (detection runs silenced to keep stdout pure JSON)
- analyze --json: .features.<id> = {display, applied, detected};
  detected runs the registry (custom detector on the primary file,
  declared pattern/template bulk-grepped across every relevant file);
  .instances is included so callers don't need a second call; an
  unknown site returns a JSON error instead of a text line + exit
- check --json: mirrors the human checks — prerequisites, nginx -t
  (system or wp-test-proxy), registry loaded, backup dir writable —
  with an .issues array; .ready is true iff .issues is empty, and the
  exit code matches the human command
- status --json: same payload as before, built with jq and hardened
  against a missing/corrupt state file

Helpers live next to json_output: _json_instances, _json_feature_list,
_json_detect_files (http-context files are global; server-context files
scope to the target site), _json_primary_file, _json_feature_detected,
_json_feature_applied.
New "JSON Output Tests" section asserts stdout of list/analyze/status/
check --json and --json --version parses with jq and carries the real
schema: instances/features arrays for list, display+applied+detected
booleans per feature for analyze, issues/ready/backup_writable/
nginx_valid for check (with ready == issues-empty consistency), and
.applied array for status.

The list instance-count assertion compares against the human `list`
count on the same machine and skips with a reason when detection truly
finds zero (e.g. CI without nginx). These assertions fail on the
placeholder implementation.
--json for analyze/status/list/check now emits real detection data
instead of placeholders; the --help line lists the commands it covers.
@MarcinDudekDev
MarcinDudekDev merged commit 25f1de2 into main Sep 13, 2026
4 checks passed
@MarcinDudekDev
MarcinDudekDev deleted the feat/json-output branch September 13, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Full JSON output for analyze/status/list/check (not placeholder)

1 participant