Skip to content

Commit 5e5ec97

Browse files
ggazzoclaude
andcommitted
chore(sdk): instrument SDK reconnect + Accounts._pollStoredLoginToken
Log every SDK 'connected' event, the stored token at that moment, the Meteor userId, and every _pollStoredLoginToken call (with the current/last token and whether it would fire). Will revert once we have :87 nailed down — the trace currently shows nothing between the force-logout disconnect and the failing waitForLogin assertion, so we need eyes on what actually runs in that window. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 39bf2fc commit 5e5ec97

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

apps/meteor/client/meteor/overrides/stubMeteorStream.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Accounts } from 'meteor/accounts-base';
12
import { DDPCommon } from 'meteor/ddp-common';
23
import { Meteor } from 'meteor/meteor';
34
import { Tracker } from 'meteor/tracker';
@@ -233,14 +234,47 @@ queueMicrotask(() => {
233234
// ddpSdkCollectionBridge.
234235
const sdk = getDdpSdk();
235236
let firstConnectHandled = false;
237+
let reconnectCount = 0;
236238
sdk.connection.on('connected', () => {
237239
if (!firstConnectHandled) {
238240
firstConnectHandled = true;
241+
console.warn('[stubMeteorStream] first SDK connected (no reset)');
239242
return;
240243
}
244+
reconnectCount += 1;
245+
const storedToken = typeof window !== 'undefined' ? window.localStorage.getItem('Meteor.loginToken') : null;
246+
console.warn(`[stubMeteorStream] SDK reconnect #${reconnectCount} — firing reset`, {
247+
storedToken: storedToken ? `${storedToken.slice(0, 6)}…` : null,
248+
userId: (Meteor.connection as unknown as { _userId?: string | null })._userId ?? null,
249+
});
241250
try {
242251
fire('reset');
243252
} catch (err) {
244253
console.warn('[stubMeteorStream] reset on SDK reconnect failed', err);
245254
}
246255
});
256+
257+
// Diagnostic: wrap _pollStoredLoginToken to log every call so we can see
258+
// whether the test's loginByUserState actually triggers a login on the
259+
// failing :87 cycle, or whether it short-circuits because the cached
260+
// _lastLoginTokenWhenPolled still matches what's in storage.
261+
{
262+
const acc = Accounts as unknown as {
263+
_pollStoredLoginToken?: () => void;
264+
_lastLoginTokenWhenPolled?: string | null;
265+
_storedLoginToken?: () => string | null;
266+
};
267+
const originalPoll = acc._pollStoredLoginToken;
268+
if (typeof originalPoll === 'function') {
269+
acc._pollStoredLoginToken = function patchedPoll(this: typeof acc): void {
270+
const current = acc._storedLoginToken?.() ?? null;
271+
const last = acc._lastLoginTokenWhenPolled ?? null;
272+
console.warn('[stubMeteorStream] _pollStoredLoginToken', {
273+
current: current ? `${current.slice(0, 6)}…` : null,
274+
last: last ? `${last.slice(0, 6)}…` : null,
275+
willFire: current !== last,
276+
});
277+
return originalPoll.call(this);
278+
};
279+
}
280+
}

0 commit comments

Comments
 (0)