Skip to content

ci: auto-repair invalid JSON in PRs and on direct pushes to main - #247

Open
Core447 wants to merge 13 commits into
mainfrom
ci/json-autofix-guard
Open

ci: auto-repair invalid JSON in PRs and on direct pushes to main#247
Core447 wants to merge 13 commits into
mainfrom
ci/json-autofix-guard

Conversation

@Core447

@Core447 Core447 commented Aug 6, 2026

Copy link
Copy Markdown
Member

Summary

  • Replaces the syntax-only limitusus/json-syntax-check check with a homegrown scripts/validate_json.py.
  • On a PR from a branch in this repo, invalid JSON is auto-repaired (trailing commas, minor syntax slips) via json_repair and pushed back to the PR as a fix commit. If it can't be safely repaired, the check fails.
  • On a PR from a fork, we can't push to it, so it just checks and reports (GitHub Actions can't write to fork branches).
  • On a direct push to main, it tries the same repair, and if that isn't safe (e.g. it would drop most entries), it restores the file to the last version in git history that parsed as valid JSON — so main is never left pointing at broken JSON that the app would choke on.

Verified live on this PR

  • Broke Icons.json (trailing comma) on a same-repo branch → the workflow detected it, repaired it with json_repair, and pushed the fix commit back automatically. Confirmed multiple times.
  • Confirmed the fix commit is pushed using STORE_AUTOMATION_TOKEN (not the default GITHUB_TOKEN), since GITHUB_TOKEN pushes don't re-trigger workflow runs.

Known open issue — do not make this a required status check yet

Even using STORE_AUTOMATION_TOKEN (confirmed to be a valid, non-empty secret), the auto-fix commit is not reliably getting its own new check run in testing — same symptom as with the default token. Root cause isn't nailed down (ruled out: token being empty/misconfigured). Until this is understood, making this check required on main could leave a PR stuck showing no status for its current HEAD even though the file is already valid, which would block merges instead of just protecting them. Recommend holding off on the branch-protection change until this is resolved or someone confirms the behavior is more reliable outside of rapid back-to-back test pushes.

Test plan

  • Locally verified scripts/validate_json.py repairs a trailing-comma break in Icons.json and leaves it valid.
  • Locally verified it fails safely (won't repair) on severely truncated JSON, and correctly restores from git history with --restore-fallback.
  • Live end-to-end verification on this PR: break → auto-repair → fix commit pushed.
  • Diagnose why the fix commit doesn't reliably get its own check run before enabling required-status-check enforcement.

Core447 and others added 13 commits August 6, 2026 20:20
The JSON check previously only reported syntax errors; it didn't block
merges and couldn't fix anything. This adds:

- scripts/validate_json.py: validates the top-level *.json files, with
  a --fix mode that repairs minor syntax issues (trailing commas, etc.)
  via json_repair, and a --restore-fallback mode that reverts a file to
  its last known-good version from git history if a repair isn't safe
  (e.g. it would drop most of the entries).
- On pull_request (same-repo branches): auto-repairs and pushes the fix
  back to the PR branch; still fails the check if something can't be
  fixed, so it can be made a required status check to block merging.
- On push to main (direct commits): auto-repairs, falling back to
  restoring the last known-good version, so main is never left pointing
  at broken JSON that the app would choke on.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…token

The default GITHUB_TOKEN deliberately doesn't trigger new workflow runs
when it pushes (anti-recursion protection). Verified this live on PR
#247: the fix commit landed but never got its own check run, which
would permanently block merging once this becomes a required status
check. Push with STORE_AUTOMATION_TOKEN instead so the fix commit
re-triggers CI and reports its own green check.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.

2 participants