Skip to content

Safeguard config.json loading: in-memory fallback, no disk writes - #35

Merged
btopro merged 1 commit into
mainfrom
fix/config-json-safeguard
Sep 8, 2026
Merged

Safeguard config.json loading: in-memory fallback, no disk writes#35
btopro merged 1 commit into
mainfrom
fix/config-json-safeguard

Conversation

@btopro

@btopro btopro commented Sep 8, 2026

Copy link
Copy Markdown
Member

Summary

Fixes haxtheweb/issues#2967. Replaces the existing self-heal (copyFileSync of the boilerplate config.json into place on missing) with a pure in-memory fallback that never touches disk, and extends the same fallback to empty/corrupt config.json (previously an uncaught JSON.parse throw):

  • New exported loadConfigJson(configDirectory) tries to read/parse the real config.json; on any failure (missing or parse error, covering missing/empty/corrupt) logs the real cause via console.error (no path leak) and falls back to a fresh read-only decode of src/boilerplate/systemsetup/config.json.
  • If the boilerplate is also unavailable, falls back further to a minimal hand-built object matching the same shape used by the PHP backend (themes, security, site.settings/git/static/publishers, mcp, deploymentProfile).
  • The constructor now calls loadConfigJson() in place of the old existsSync + copyFileSync + JSON.parse block; downstream default-seeding logic is unchanged and runs unconditionally as before.

Testing

  • New test/unit/config-safeguard.test.cjs covers missing/corrupt/empty/valid cases, asserting fallback shape validity and that no file is created or modified on disk in any failure path.
  • npm run test:unit — 943 tests, 159 suites, all pass.
  • npm run test:e2e — 172 tests, 171 pass, 1 skipped, non-fatal visual diff warnings only, no functional regressions.

Companion fix for haxcms-php: haxtheweb/haxcms-php#625

Co-Authored-By: Warp agent@warp.dev

…967)

Replace the existing self-heal (copyFileSync of boilerplate config.json
into place on missing) with a pure in-memory fallback that never
touches disk, and extend the same fallback to empty/corrupt config.json
(previously an uncaught JSON.parse throw):

- New exported loadConfigJson(configDirectory) tries to read/parse the
  real config.json; on any failure (missing or parse error, covering
  missing/empty/corrupt) logs the real cause via console.error (no
  path leak) and falls back to a fresh read-only decode of
  src/boilerplate/systemsetup/config.json.
- If the boilerplate is also unavailable, falls back further to a
  minimal hand-built object matching the same shape used by the PHP
  backend (themes, security, site.settings/git/static/publishers, mcp,
  deploymentProfile).
- The constructor now calls loadConfigJson() in place of the old
  existsSync + copyFileSync + JSON.parse block; downstream default-
  seeding logic is unchanged and runs unconditionally as before.

Adds test/unit/config-safeguard.test.cjs covering missing/corrupt/
empty/valid cases, asserting fallback shape validity and that no file
is created or modified on disk in any failure path.

Co-Authored-By: Warp <agent@warp.dev>
Copilot AI lite review requested due to automatic review settings September 8, 2026 19:55
@codesandbox

codesandbox Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@btopro
btopro merged commit 172de1e into main Sep 8, 2026
4 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 8, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Safeguard config.json loading: self-heal + non-null fallback + diagnostics (missing/corrupt/empty)

1 participant