Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix([issue-12750]): wait on the peer-push retry walk instead of a fixed turn count

[._.]/ Adam Eivya7dfa432eae4
diff --git a/server/services/sharing/peerSync.test.js b/server/services/sharing/peerSync.test.js
index 015d5f9df5..3545cd460b 100644
--- a/server/services/sharing/peerSync.test.js
+++ b/server/services/sharing/peerSync.test.js
@@ -1688,12 +1688,22 @@ describe('peerSync', () => {
vi.mocked(peerFetch).mockClear();
let resolveFetch = () => {};
- vi.mocked(peerFetch).mockImplementation(() => new Promise((resolve) => {
- resolveFetch = () => resolve(settled());
- }));
+ let markFetchEntered = () => {};
+ const fetchEntered = new Promise((resolve) => { markFetchEntered = resolve; });
+ vi.mocked(peerFetch).mockImplementation(() => {
+ markFetchEntered();
+ return new Promise((resolve) => {
+ resolveFetch = () => resolve(settled());
+ });
+ });
const walk = retryPendingPushesForPeer('peer-a');
- const tick = () => new Promise((resolve) => { setImmediate(resolve); });
- for (let i = 0; i < 50 && vi.mocked(peerFetch).mock.calls.length === 0; i += 1) await tick();
+ // The walk reads subscriptions from disk before calling the peer, so wait on the walk
+ // itself rather than a fixed turn count; a walk that settles without reaching peerFetch fails here.
+ const walkEnded = walk.then((result) => ({ result }), (error) => ({ error }));
+ const outcome = await Promise.race([fetchEntered.then(() => 'entered'), walkEnded]);
+ if (outcome !== 'entered') {
+ throw new Error(`retry walk settled without calling peerFetch: ${JSON.stringify(outcome.error?.message ?? outcome.result)}`);
+ }
expect(peerFetch).toHaveBeenCalledTimes(1);
expect(await retryPendingPushesForPeer('peer-a')).toEqual({ walked: 0, pushed: 0, skipped: 'in-flight' });