- Events: loading demo data emptied ProductLink but kept auth_mode, so a site in Accounts mode had no link and nobody could sign in (ACCOUNTS_UNAVAILABLE on events-demo). set-demo.js keeps ProductLink and LinkNonce; a site in Accounts mode without a link reconnects at its next heartbeat; sign-in failures are kept and sent in the heartbeat (stats.signIn). - Contracts 1.13.0: stats.signIn in the Cross Events heartbeat. - Agent 1.3.1: 1.3.0 reported itself as 1.2.0 (AGENT_VERSION not bumped). - What's New notes for Events 3.4.0 / 3.5.0 and Accounts 1.4.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
33 lines
1.7 KiB
TypeScript
33 lines
1.7 KiB
TypeScript
// 3.5.0: how people sign in, for the Hub (heartbeat stats.signIn, contracts 1.13.0).
|
|
import { hub } from '@crosscode/contracts';
|
|
|
|
const mockSettings = new Map<string, string>();
|
|
let mockMode = 'accounts';
|
|
let mockLink: object | null = null;
|
|
|
|
jest.mock('../src/accounts/client', () => ({ accountsLink: async () => mockLink }));
|
|
jest.mock('../src/accounts/mode', () => ({
|
|
authMode: async () => mockMode,
|
|
getSetting: async (k: string) => mockSettings.get(k) ?? null,
|
|
setSetting: async (k: string, v: string | null) => { if (v === null) mockSettings.delete(k); else mockSettings.set(k, v); },
|
|
}));
|
|
|
|
import { clearSignInError, recordSignInError, signInStatus } from '../src/accounts/status';
|
|
|
|
beforeEach(() => { mockSettings.clear(); mockMode = 'accounts'; mockLink = null; });
|
|
|
|
test('Accounts mode without a link, and why the last sign-in failed', async () => {
|
|
await recordSignInError('ACCOUNTS_UNAVAILABLE', 'Accounts isn\'t connected.\nConnect it under Settings → Linked products.', new Date('2026-11-20T10:00:00.000Z'));
|
|
const s = await signInStatus();
|
|
expect(s).toEqual({ mode: 'accounts', accounts: null, lastError: { at: '2026-11-20T10:00:00.000Z', code: 'ACCOUNTS_UNAVAILABLE', message: 'Accounts isn\'t connected. Connect it under Settings → Linked products.' } });
|
|
// It fits the heartbeat's contract.
|
|
expect(hub.eventsStatsSchema.shape.signIn.safeParse(s).success).toBe(true);
|
|
await clearSignInError();
|
|
expect((await signInStatus()).lastError).toBeNull();
|
|
});
|
|
|
|
test('linked: the Accounts install and its address', async () => {
|
|
mockLink = { installId: 'acc-1', url: 'https://accounts.hope.test', secret: 'x', updatedAt: new Date() };
|
|
expect((await signInStatus()).accounts).toEqual({ installId: 'acc-1', url: 'https://accounts.hope.test' });
|
|
});
|