From ae2f6abe86302a7f808d187dc5e0677b5435bda4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6?= <14975046+skjnldsv@users.noreply.github.com> Date: Thu, 1 Oct 2026 18:34:14 +0200 Subject: [PATCH] feat(scope): say which copy is elected viewer of the page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With the server and apps each bundling a copy, which one runs is the first thing to know when the viewer misbehaves. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: John Molakvoæ <14975046+skjnldsv@users.noreply.github.com> --- __tests__/scope.spec.ts | 14 ++++++++++++++ lib/scope.ts | 2 ++ 2 files changed, 16 insertions(+) diff --git a/__tests__/scope.spec.ts b/__tests__/scope.spec.ts index e9783da..58153b9 100644 --- a/__tests__/scope.spec.ts +++ b/__tests__/scope.spec.ts @@ -89,6 +89,20 @@ describe('electing an implementation', () => { expect(loaded).toEqual(['2.2.0']) }) + it('announces the winner', async () => { + const debug = vi.spyOn(logger, 'debug') + registerImplementation({ version: '2.1.0', load: async () => {} }) + registerImplementation({ version: '2.2.0', load: async () => {} }) + + await loadImplementation() + + expect(debug).toHaveBeenCalledWith( + '🗳️ The votes are in: 2.2.0 is elected viewer of this page (2 running: 2.1.0, 2.2.0)', + { versions: ['2.1.0', '2.2.0'] }, + ) + debug.mockRestore() + }) + it('loads once however many callers ask', async () => { const load = vi.fn().mockResolvedValue(undefined) registerImplementation({ version: '2.0.0', load }) diff --git a/lib/scope.ts b/lib/scope.ts index 063ece8..2111621 100644 --- a/lib/scope.ts +++ b/lib/scope.ts @@ -162,6 +162,8 @@ export function loadImplementation(): Promise { if (best === undefined) { throw new Error('No viewer implementation is available on this page') } + const versions = scope.candidates.map((candidate) => candidate.version) + logger.debug(`🗳️ The votes are in: ${best.version} is elected viewer of this page (${versions.length} running: ${versions.join(', ')})`, { versions }) return best.load() })().catch((error) => { // A load that failed is not the answer for the rest of the page's