mirror of
https://github.com/garrytan/gstack.git
synced 2026-06-19 00:00:13 +02:00
fix(gbrain-sync): sourceLocalPath handles wrapped {sources:[...]} shape from gbrain v0.20+
gbrain v0.20+ changed `gbrain sources list --json` to return
{sources: [...]} instead of a flat array. sourceLocalPath crashed
upstream with `list.find is not a function` on every /sync-gbrain
invocation against modern gbrain. Accept both shapes for
forward/backward compat, matching probeSource/sourcePageCount in
lib/gbrain-sources.ts.
Contributed by @jakehann11 via #1571. Closes #1567. Supersedes #1564
(@tonyjzhou, same fix, different shape — credit retained).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -837,4 +837,29 @@ describe("sourceLocalPath", () => {
|
||||
});
|
||||
expect(sourceLocalPath("any-id", envWithBindir(bindir))).toBeNull();
|
||||
});
|
||||
|
||||
// gbrain v0.20+ wraps the response as `{sources: [...]}`. Older versions
|
||||
// returned a flat array. sourceLocalPath was returning null (or crashing
|
||||
// with `list.find is not a function` upstream) because it only handled
|
||||
// the flat-array shape. Pin both shapes here.
|
||||
it("handles {sources: [...]} wrapped shape (gbrain v0.20+)", () => {
|
||||
makeShim(bindir, {
|
||||
"sources list --json": {
|
||||
stdout: JSON.stringify({
|
||||
sources: [
|
||||
{ id: "other-source", local_path: "/x" },
|
||||
{ id: "target-id", local_path: "/repo/match" },
|
||||
],
|
||||
}),
|
||||
},
|
||||
});
|
||||
expect(sourceLocalPath("target-id", envWithBindir(bindir))).toBe("/repo/match");
|
||||
});
|
||||
|
||||
it("returns null when the source is missing in the wrapped shape", () => {
|
||||
makeShim(bindir, {
|
||||
"sources list --json": { stdout: JSON.stringify({ sources: [] }) },
|
||||
});
|
||||
expect(sourceLocalPath("missing-id", envWithBindir(bindir))).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user