Events 3.5.0, contracts 1.13.0, agent 1.3.1: demo data keeps the Accounts link; sign-in health for the Hub
- 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>
This commit is contained in:
@@ -7,7 +7,9 @@ let mockLink: object | null = null;
|
||||
jest.mock('../src/links/connect', () => ({ connectTo: async (...args: unknown[]) => { mockConnects.push(args); mockLink = { installId: args[0] }; } }));
|
||||
jest.mock('../src/links/store', () => ({ linkedProducts: async () => mockListed }));
|
||||
jest.mock('../src/accounts/client', () => ({ accountsLink: async () => mockLink }));
|
||||
let mockMode = 'local';
|
||||
jest.mock('../src/accounts/mode', () => ({
|
||||
viaAccounts: async () => mockMode === 'accounts',
|
||||
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); },
|
||||
}));
|
||||
@@ -21,6 +23,7 @@ beforeEach(() => {
|
||||
mockConnects.length = 0;
|
||||
mockListed = [];
|
||||
mockLink = null;
|
||||
mockMode = 'local';
|
||||
});
|
||||
|
||||
test('connects to the Accounts the Hub lists, as the system, once', async () => {
|
||||
@@ -46,3 +49,13 @@ test('already connected by an admin: just remembers it', async () => {
|
||||
expect(mockConnects).toEqual([]);
|
||||
expect(mockSettings.has(AUTO_KEY)).toBe(true);
|
||||
});
|
||||
|
||||
test('3.5.0: a site in Accounts mode that lost its link (a demo load before 3.5.0) connects again', async () => {
|
||||
mockSettings.set(AUTO_KEY, '2026-11-19T10:00:00.000Z');
|
||||
mockListed = [{ installId: ACCOUNTS, product: 'accounts' }];
|
||||
// On its own sign-in, an earlier Disconnect stays.
|
||||
expect(await connectAccountsIfListed()).toBe('skipped');
|
||||
mockMode = 'accounts';
|
||||
expect(await connectAccountsIfListed()).toBe('connected');
|
||||
expect(mockConnects).toEqual([[ACCOUNTS, { id: null, role: 'system' }, null, expect.any(Date)]]);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// 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' });
|
||||
});
|
||||
Reference in New Issue
Block a user