Safeguard config.json loading: in-memory fallback, no disk writes - #35
Merged
Conversation
…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>
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.parsethrow):loadConfigJson(configDirectory)tries to read/parse the realconfig.json; on any failure (missing or parse error, covering missing/empty/corrupt) logs the real cause viaconsole.error(no path leak) and falls back to a fresh read-only decode ofsrc/boilerplate/systemsetup/config.json.themes,security,site.settings/git/static/publishers,mcp,deploymentProfile).loadConfigJson()in place of the oldexistsSync+copyFileSync+JSON.parseblock; downstream default-seeding logic is unchanged and runs unconditionally as before.Testing
test/unit/config-safeguard.test.cjscovers 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