commit 06d3087cffb3e3761078ff12f4d2402d33b2f015
parent dc7a7e2bc2982b17dc4857c843d71897f62deb9e
Author: triesap <tyson@radroots.org>
Date: Mon, 5 Oct 2026 21:27:44 +0000
test: bind shell keyboard checks to real hydration (HCP-020)
- Gate injected shell fixture callbacks on actual client initialization
- Verify keyboard focus before testing connection and disconnection callbacks
- Exercise delayed real scripts without changing production shell behavior
- Retain prior failure evidence and qualify the scoped successor independently
Diffstat:
2 files changed, 71 insertions(+), 3 deletions(-)
diff --git a/web/tests/e2e/harness/shell.svelte b/web/tests/e2e/harness/shell.svelte
@@ -1,8 +1,13 @@
<script lang="ts">
+ import { onMount } from 'svelte';
import AppShell from '../../../src/lib/components/AppShell.svelte';
let connected = $state(false);
let commands = $state(0);
let enabled = $state(true);
+ let ready = $state(false);
+ onMount(() => {
+ ready = true;
+ });
const publicKey = 'HC_TEST_ONLY_PUBLIC_KEY_' + 'a'.repeat(64);
function connect() {
commands++;
@@ -21,9 +26,9 @@
? {
kind: 'connected',
publicKey,
- ondisconnect: enabled ? disconnect : undefined
+ ondisconnect: ready && enabled ? disconnect : undefined
}
- : { kind: 'guest', onconnect: enabled ? connect : undefined }}
+ : { kind: 'guest', onconnect: ready && enabled ? connect : undefined }}
>
<h1>HC_TEST_ONLY_SHELL</h1>
<p role="status">Commands: {commands}</p>
diff --git a/web/tests/e2e/shell.spec.ts b/web/tests/e2e/shell.spec.ts
@@ -242,6 +242,9 @@ for (const width of [320, 1024]) {
const page = await context.newPage();
await page.goto(server.url);
const skip = page.getByRole('link', { name: 'Skip to main content' });
+ await expect(
+ page.getByRole('button', { name: 'Connect extension' })
+ ).toBeEnabled();
await page.keyboard.press('Tab');
await expect(skip).toBeFocused();
await expect(skip).toBeVisible();
@@ -267,7 +270,11 @@ for (const width of [320, 1024]) {
'List food',
'Connect extension'
]);
- await page.getByRole('button', { name: 'Connect extension' }).focus();
+ const guestConnect = page.getByRole('button', {
+ name: 'Connect extension'
+ });
+ await guestConnect.focus();
+ await expect(guestConnect).toBeFocused();
await page.keyboard.press('Enter');
await expect(page.getByRole('status')).toHaveText('Commands: 1');
await expect(primary).toContainText(
@@ -320,6 +327,7 @@ for (const width of [320, 1024]) {
.getByRole('button', { name: 'Toggle command availability' })
.click();
await disconnect.focus();
+ await expect(disconnect).toBeFocused();
await page.keyboard.press('Enter');
await expect(page.getByRole('status')).toHaveText('Commands: 2');
await page
@@ -341,3 +349,58 @@ for (const width of [320, 1024]) {
expect(context.pages()).toHaveLength(0);
});
}
+
+test('controlled shell callbacks become available only after actual hydration', async ({
+ browser
+}) => {
+ const context = await browser.newContext({
+ viewport: { width: 320, height: 900 }
+ });
+ let releaseScripts!: () => void;
+ const scriptsReady = new Promise<void>((resolve) => {
+ releaseScripts = resolve;
+ });
+ let delayedScripts = 0;
+ const external: string[] = [];
+ try {
+ await context.route('**/*', async (route) => {
+ if (new URL(route.request().url()).origin !== server.url) {
+ external.push(route.request().url());
+ return route.abort();
+ }
+ if (new URL(route.request().url()).pathname.endsWith('.js')) {
+ delayedScripts++;
+ await scriptsReady;
+ }
+ return route.continue();
+ });
+ const page = await context.newPage();
+ await page.goto(server.url, { waitUntil: 'commit' });
+ const connect = page.getByRole('button', { name: 'Connect extension' });
+ await expect(
+ page.getByRole('heading', { name: 'HC_TEST_ONLY_SHELL' })
+ ).toBeVisible();
+ await expect.poll(() => delayedScripts).toBeGreaterThan(0);
+ await expect(connect).toBeDisabled();
+ await expect(page.getByRole('status')).toHaveText('Commands: 0');
+ releaseScripts();
+ await expect(connect).toBeEnabled();
+ await connect.focus();
+ await expect(connect).toBeFocused();
+ await page.keyboard.press('Enter');
+ await expect(page.getByRole('status')).toHaveText('Commands: 1');
+ const identity = page.locator('summary');
+ await identity.focus();
+ await expect(identity).toBeFocused();
+ await page.keyboard.press('Enter');
+ await expect(page.locator('details')).toHaveAttribute('open', '');
+ await expect(
+ page.getByRole('button', { name: 'Disconnect', exact: true })
+ ).toBeEnabled();
+ expect(external).toEqual([]);
+ } finally {
+ releaseScripts();
+ await context.close();
+ }
+ expect(context.pages()).toHaveLength(0);
+});