sync-to-zesty: recover from 'filename already exists' on POST - #100
Merged
Merged
Conversation
…xisting ZUID Per ardeay (2026-09-09): before this patch, any file present on disk but without a ZUID mapping in zesty.config.json triggers a POST /web/views on stage sync. If the Zesty instance already has a view record with that fileName (usually because it was created manually in the editor before its ZUID made it into config), the POST fails with 400 'filename already exists' and the whole sync crashes. Every subsequent file in newFiles is never touched. The patch teaches createNew() to recover from that specific 400: catch it, GET /web/<endpoint>, find the record whose fileName matches, and continue as if we had just created it. The workflow's writeback step then commits the resolved ZUID into zesty.config.json so subsequent runs treat it as a normal already-mapped resource. Also: - apiRequest now attaches .status and .bodyText onto the thrown Error so callers can introspect (previously only a string message was available) - apiRequest no longer sends body='null' on GET/DELETE (JSON.stringify(null) = 'null', which some fetch implementations flag) - Small test file exercises the shape of the patch — asserts the recovery branch, the helper function, and the body-on-GET guard all exist. Zero runtime cost since it's opt-in (node scripts/sync-to-zesty.test.js)
Contributor
💾 Stage sync previewNew files to create (0): Will add/update — differ from dev (0): Unchanged, skipped: 0 196 mapped resources · zesty-sync |
This was referenced Sep 9, 2026
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Per ardeay (2026-09-09 Discord, Option A on the sync-to-zesty patch).
Problem
When `sync-to-zesty.js` runs a FULL_SYNC and encounters a file on disk that isn't in `zesty.config.json` yet, it POSTs `/web/` to create the view. If the fileName is already taken in Zesty (which happens whenever someone created the view manually in the editor at some point without its ZUID landing back in the config), Zesty returns:
```
400 Bad Request: filename already exists
```
The current script surfaces that as a thrown Error, which crashes the entire run — every subsequent file in `newFiles` never gets touched. Today's example: the run choked on `adobe-experience-manager-vs-content-one.html` and never even attempted to create the 4 pages sam and kaya are waiting on.
Fix
Also fixes a small `apiRequest` quirk: it used to serialize `body: undefined` as `"undefined"` via `JSON.stringify`. Now it only attaches `options.body` when there's actually a body — safer for GET/DELETE.
Test
`scripts/sync-to-zesty.test.js` — a small zero-config test that asserts the shape of the patch (recovery branch present, helper defined, body-guard in place). Run with `node scripts/sync-to-zesty.test.js`. Not wired into CI yet (would need a proper test runner) but it's easy to invoke locally.
Follow-up unblocked
Once this ships, a FULL_SYNC dispatch on stage will self-heal all ~15 currently-orphaned view records into `zesty.config.json` in a single run, eliminating the "manual ZUID hand-off after each new landing page" bottleneck that's been eating operator time all summer.
Test plan