fix(gbrain-sync): sourceLocalPath handles wrapped {sources:[...]} shape from gbrain v0.30+#1622
Open
Evode-Manirahari wants to merge 1 commit into
Open
Conversation
gbrain v0.30+ wraps `gbrain sources list --json` output as
`{"sources":[...]}` instead of returning a bare array. The new v1.40
hostname-fold migration helper `sourceLocalPath()` (added in garrytan#1547)
typed the response as a bare array and crashed every first-sync-after-
upgrade with `list.find is not a function`:
$ /sync-gbrain
gstack-gbrain-sync fatal: list.find is not a function.
(In 'list.find((s) => s.id === sourceId)', 'list.find' is undefined)
The sibling helper in lib/gbrain-sources.ts (`statusForSourceId`) already
unwraps the shape correctly — this PR brings sourceLocalPath in line.
Repro: on any machine running gstack v1.40.0.0 + gbrain v0.30.0.0 or
newer (current released gbrain is v0.37.1.0), run /sync-gbrain in any
git repo. The orchestrator dies before any stage runs.
Fix: accept both shapes via `Array.isArray(raw) ? raw : raw.sources || []`.
Tests: 3 new cases in the `sourceLocalPath` describe block pin the
wrapped shape, the wrapped-but-no-match shape, and the
`{sources: undefined}` defensive case. The existing 3 bare-array tests
still cover the legacy path. 38/38 in test/gstack-gbrain-sync.test.ts.
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.
Problem
After upgrading to gstack v1.40.0.0 + gbrain v0.30.0.0 or newer (current released gbrain is v0.37.1.0), the first
/sync-gbrainafter upgrade dies before any stage runs:Root cause
gbrain sources list --jsonstarted wrapping its output as{"sources":[...]}in gbrain v0.30+. The v1.40 hostname-fold migration helpersourceLocalPath()(added in #1547,bin/gstack-gbrain-sync.ts:291) typed the response as a bare array and called.find()on it directly:The sibling helper in
lib/gbrain-sources.ts(statusForSourceId, lines 72-85) already unwraps both shapes correctly —sourceLocalPathwas the lone holdout because it was added separately in the v1.40 migration work.Actual output on a current gbrain:
Fix
Accept both wire shapes (defense against the same regression in either direction):
Tests
Three new cases in the existing
sourceLocalPathdescribe block intest/gstack-gbrain-sync.test.ts:returns local_path when gbrain wraps the list as {sources: [...]} (v0.30+ shape)— the regression.returns null when the wrapped {sources: [...]} shape has no matching id.treats {sources: undefined} the same as an empty list— defensive case for partial responses.The existing 3 bare-array tests still pass, locking in backward compat with pre-v0.30 gbrain shims.
Run:
bun test test/gstack-gbrain-sync.test.ts→ 38 pass, 0 fail (130 expect() calls).Repro on a fresh machine
Found via
Hit this while syncing a freshly-shipped repo against gbrain v0.37.1.0 from a fresh gstack v1.40.0.0 install. Patched locally first; this PR brings the fix upstream.