commit 32df695fe2522f3d499f3d13313be71a6a255ce8
parent c6c1ff55cb4577297e5a67f9e88832daf44a0f3b
Author: triesap <tyson@radroots.org>
Date: Mon, 5 Oct 2026 06:48:42 +0000
design: build the shared labelled search form (HCP-015)
- Render one labelled two-row search form on the anonymous homepage.
- Emit unchanged input through an explicit guarded submission callback.
- Preserve native multiline input and prevent composition-time submission.
- Verify real form behavior while unfinished navigation remains unavailable.
Diffstat:
9 files changed, 572 insertions(+), 3 deletions(-)
diff --git a/web/src/lib/components/SearchForm.svelte b/web/src/lib/components/SearchForm.svelte
@@ -0,0 +1,63 @@
+<script lang="ts">
+ import FormField from './primitives/FormField.svelte';
+ import Button from './primitives/Button.svelte';
+ let {
+ onsubmit,
+ disabled = false
+ }: {
+ onsubmit?: (input: string) => void;
+ disabled?: boolean;
+ } = $props();
+ const id = $props.id();
+ let input = $state('');
+ let composing = $state(false);
+ const unavailable = $derived(disabled || !onsubmit);
+ function submit(event: SubmitEvent) {
+ event.preventDefault();
+ if (!unavailable && !composing) onsubmit?.(input);
+ }
+</script>
+
+<form
+ class="stack"
+ onsubmit={submit}
+ aria-describedby={unavailable ? `${id}-unavailable` : undefined}
+>
+ <FormField
+ {id}
+ label="What are you looking for?"
+ hint="For example, carrots or carrots Victoria."
+ >
+ {#snippet control({ id, describedby, invalid })}
+ <textarea
+ {id}
+ class="input textarea"
+ rows="2"
+ aria-describedby={describedby}
+ aria-invalid={invalid}
+ value={input}
+ oninput={(event) => {
+ input = event.currentTarget.value;
+ }}
+ oncompositionstart={() => {
+ composing = true;
+ }}
+ oncompositionend={() => {
+ composing = false;
+ }}></textarea>
+ {/snippet}
+ </FormField>
+ <div class="cluster">
+ <Button
+ label="Search"
+ type="submit"
+ variant="primary"
+ disabled={unavailable}
+ />
+ </div>
+ {#if unavailable}
+ <p class="notice" id={`${id}-unavailable`}>
+ Search is unavailable during development.
+ </p>
+ {/if}
+</form>
diff --git a/web/src/routes/+page.svelte b/web/src/routes/+page.svelte
@@ -1,3 +1,11 @@
+<script lang="ts">
+ import SearchForm from '../lib/components/SearchForm.svelte';
+</script>
+
<svelte:head>
<title>HarvestCircle</title>
</svelte:head>
+
+<div class="page page--reading">
+ <SearchForm />
+</div>
diff --git a/web/tests/e2e/bootstrap.spec.ts b/web/tests/e2e/bootstrap.spec.ts
@@ -88,6 +88,34 @@ test('actual browser loads guest shell without an extension', async ({
page.getByRole('link', { name: 'HarvestCircle', exact: true })
).toBeVisible();
await expect(page).toHaveTitle('HarvestCircle');
+ const query = page.getByRole('textbox', {
+ name: 'What are you looking for?'
+ });
+ await expect(query).toHaveCount(1);
+ await expect(query).toHaveAttribute('rows', '2');
+ await expect(
+ page.getByText('For example, carrots or carrots Victoria.')
+ ).toBeVisible();
+ await expect(
+ page.getByRole('button', { name: 'Search', exact: true })
+ ).toBeDisabled();
+ await expect(
+ page.getByText('Search is unavailable during development.')
+ ).toBeVisible();
+ await query.fill('carrots');
+ await query.press('Enter');
+ await expect(query).toHaveValue('carrots\n');
+ await page.locator('form').evaluate((form) => {
+ const event = new SubmitEvent('submit', {
+ bubbles: true,
+ cancelable: true
+ });
+ if (form.dispatchEvent(event))
+ throw new Error('Unavailable submit was not prevented');
+ });
+ expect(new URL(page.url()).pathname).toBe('/');
+ // Start the existing skip-link keyboard check from the document again.
+ await page.reload();
await expect(page.getByRole('main')).toHaveCount(1);
await expect(
page.getByRole('navigation', { name: 'Primary', exact: true })
diff --git a/web/tests/e2e/harness/search-form.svelte b/web/tests/e2e/harness/search-form.svelte
@@ -0,0 +1,29 @@
+<script lang="ts">
+ import SearchForm from '../../../src/lib/components/SearchForm.svelte';
+ let calls = $state<string[]>([]);
+ let enabled = $state(true);
+ let disabled = $state(false);
+ function submit(input: string) {
+ calls = [...calls, input];
+ }
+</script>
+
+<div class="page page--reading stack">
+ <h1>HC_TEST_ONLY_SEARCH_FORM</h1>
+ <SearchForm onsubmit={enabled ? submit : undefined} {disabled} />
+ <p role="status">{JSON.stringify(calls)}</p>
+ <button
+ type="button"
+ class="button button--secondary"
+ onclick={() => {
+ enabled = !enabled;
+ }}>Toggle caller</button
+ >
+ <button
+ type="button"
+ class="button button--secondary"
+ onclick={() => {
+ disabled = !disabled;
+ }}>Toggle disabled</button
+ >
+</div>
diff --git a/web/tests/e2e/search-form.spec.ts b/web/tests/e2e/search-form.spec.ts
@@ -0,0 +1,296 @@
+import { expect, test } from '@playwright/test';
+import { createHash } from 'node:crypto';
+import { execFileSync } from 'node:child_process';
+import {
+ cp,
+ mkdtemp,
+ readFile,
+ readdir,
+ rm,
+ writeFile
+} from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import path from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { createStaticHarness } from '../integration/harness/static.ts';
+
+// Isolated qualification clone: actual components compile into disposable output.
+// The primary static payload and product route source are never overwritten.
+const capsule = fileURLToPath(new URL('../../../', import.meta.url));
+let directory: string;
+let server: Awaited<ReturnType<typeof createStaticHarness>>;
+test.beforeAll(async () => {
+ test.setTimeout(120_000);
+ directory = await mkdtemp(path.join(tmpdir(), 'hcp015-search-form-'));
+ try {
+ const checkout = path.join(directory, 'checkout');
+ execFileSync('git', [
+ 'clone',
+ '--quiet',
+ '--no-hardlinks',
+ capsule,
+ checkout
+ ]);
+ for (const relative of [
+ 'web/src/lib/components/AppShell.svelte',
+ 'web/src/app.css',
+ 'web/src/routes/+layout.svelte',
+ 'web/src/lib/components/SearchForm.svelte',
+ 'web/src/routes/+page.svelte',
+ 'web/tests/unit/components/search-form.test.ts',
+ 'web/tests/e2e/search-form.spec.ts',
+ 'web/tests/e2e/harness/search-form.svelte',
+ 'web/tests/integration/harness/static.ts'
+ ])
+ await cp(path.join(capsule, relative), path.join(checkout, relative), {
+ recursive: true
+ });
+ const fixture = await readFile(
+ path.join(capsule, 'web/tests/e2e/harness/search-form.svelte'),
+ 'utf8'
+ );
+ await writeFile(
+ path.join(checkout, 'web/src/routes/+page.svelte'),
+ fixture.replaceAll('../../../src/lib/', '../lib/')
+ );
+ await cp(
+ path.join(capsule, 'web/node_modules'),
+ path.join(checkout, 'web/node_modules'),
+ { recursive: true, verbatimSymlinks: true }
+ );
+ const sourceAudit = execFileSync(
+ process.execPath,
+ ['tools/check-source.mjs'],
+ { cwd: path.join(checkout, 'web') }
+ ).toString();
+ const identities = [];
+ for (const relative of [
+ 'web/src/lib/components/AppShell.svelte',
+ 'web/src/lib/components/SearchForm.svelte',
+ 'web/src/lib/components/primitives/FormField.svelte',
+ 'web/src/lib/components/primitives/Button.svelte',
+ 'web/src/app.css',
+ 'web/src/theme.css',
+ 'web/src/routes/+layout.svelte'
+ ]) {
+ identities.push({
+ name: relative,
+ sha256: createHash('sha256')
+ .update(await readFile(path.join(checkout, relative)))
+ .digest('hex')
+ });
+ }
+ execFileSync(process.execPath, ['tools/build-info.mjs'], {
+ cwd: path.join(checkout, 'web')
+ });
+ const compiled = execFileSync(
+ 'corepack',
+ ['pnpm', 'exec', 'vite', 'build'],
+ {
+ cwd: path.join(checkout, 'web'),
+ stdio: 'pipe',
+ timeout: 90_000
+ }
+ );
+ async function payload(
+ directory: string,
+ prefix = ''
+ ): Promise<{ path: string; sha256: string }[]> {
+ const files = [];
+ for (const entry of await readdir(directory, { withFileTypes: true })) {
+ const relative = prefix + entry.name;
+ if (entry.isDirectory())
+ files.push(
+ ...(await payload(path.join(directory, entry.name), relative + '/'))
+ );
+ else
+ files.push({
+ path: relative,
+ sha256: createHash('sha256')
+ .update(await readFile(path.join(directory, entry.name)))
+ .digest('hex')
+ });
+ }
+ return files.sort((left, right) => left.path.localeCompare(right.path));
+ }
+ console.log(
+ JSON.stringify({
+ fixture: 'HCP015_TEST_ONLY_COMPILE',
+ identities,
+ sourceAudit,
+ productionRouteSha256: createHash('sha256')
+ .update(
+ await readFile(path.join(capsule, 'web/src/routes/+page.svelte'))
+ )
+ .digest('hex'),
+ fixtureSourceSha256: createHash('sha256').update(fixture).digest('hex'),
+ compiledRouteSha256: createHash('sha256')
+ .update(
+ await readFile(path.join(checkout, 'web/src/routes/+page.svelte'))
+ )
+ .digest('hex'),
+ compiledLayoutSha256: createHash('sha256')
+ .update(
+ await readFile(path.join(checkout, 'web/src/routes/+layout.svelte'))
+ )
+ .digest('hex'),
+ retention:
+ 'HASHLOGS_ONLY: disposable compiled fixture output is removed after tests',
+ payload: await payload(path.join(checkout, 'web/build')),
+ compiled: compiled.toString(),
+ metadata: JSON.parse(
+ await readFile(
+ path.join(checkout, 'web/build/build-info.json'),
+ 'utf8'
+ )
+ ) as unknown
+ })
+ );
+ server = await createStaticHarness({
+ buildRoot: path.join(checkout, 'web/build')
+ });
+ } catch (error) {
+ await rm(directory, { recursive: true, force: true });
+ throw error;
+ }
+});
+test.afterAll(async () => {
+ await server?.close();
+ if (directory) await rm(directory, { recursive: true, force: true });
+ if (server)
+ expect(server.state()).toEqual({ listening: false, childProcesses: 0 });
+});
+
+for (const width of [320, 1024]) {
+ test(`actual shared form submits raw blank/multiline input and guards IME/unavailable at ${width}px`, async ({
+ browser
+ }) => {
+ const context = await browser.newContext({
+ viewport: { width, height: 900 }
+ });
+ const external: string[] = [];
+ try {
+ await context.route('**/*', (route) => {
+ if (new URL(route.request().url()).origin === server.url)
+ return route.continue();
+ external.push(route.request().url());
+ return route.abort();
+ });
+ const page = await context.newPage();
+ await page.goto(server.url);
+ const query = page.getByRole('textbox', {
+ name: 'What are you looking for?'
+ });
+ const search = page.getByRole('button', { name: 'Search', exact: true });
+ const status = page.getByRole('status');
+ await expect(query).toHaveCount(1);
+ await expect(query).toHaveAttribute('rows', '2');
+ await expect(search).toBeEnabled();
+ await search.click();
+ await expect(status).toHaveText('[""]');
+ await query.fill(' carrots & Victoria ');
+ await query.press('End');
+ await query.press('Enter');
+ await query.press('x');
+ await expect(query).toHaveValue(' carrots & Victoria \nx');
+ await expect(status).toHaveText('[""]');
+ await query.press('Control+Enter');
+ await query.press('Meta+Enter');
+ await expect(status).toHaveText('[""]');
+ await query.fill(' carrots & Victoria \nx');
+ await search.click();
+ await expect(status).toHaveText(
+ JSON.stringify(['', ' carrots & Victoria \nx'])
+ );
+
+ await query.dispatchEvent('compositionstart', { data: '菜' });
+ await query.dispatchEvent('keydown', {
+ key: 'Enter',
+ ctrlKey: true,
+ isComposing: true
+ });
+ await query.dispatchEvent('keydown', {
+ key: 'Enter',
+ metaKey: true,
+ isComposing: true
+ });
+ await page.locator('form').evaluate((form) => {
+ if (
+ form.dispatchEvent(
+ new SubmitEvent('submit', { bubbles: true, cancelable: true })
+ )
+ )
+ throw new Error('Composing submit was not prevented');
+ });
+ await expect(status).toHaveText(
+ JSON.stringify(['', ' carrots & Victoria \nx'])
+ );
+ await query.dispatchEvent('compositionend', { data: '菜' });
+ await query.fill('菜');
+ await query.press('Tab');
+ await expect(search).toBeFocused();
+ await page.keyboard.press('Enter');
+ const expected = JSON.stringify(['', ' carrots & Victoria \nx', '菜']);
+ await expect(status).toHaveText(expected);
+
+ for (const toggle of ['Toggle disabled', 'Toggle caller']) {
+ await page.getByRole('button', { name: toggle }).click();
+ await expect(search).toBeDisabled();
+ await expect(
+ page.getByText('Search is unavailable during development.')
+ ).toBeVisible();
+ await query.fill('not submitted');
+ await query.press('Control+Enter');
+ await query.press('Meta+Enter');
+ await search.evaluate((button) =>
+ button.dispatchEvent(new MouseEvent('click', { bubbles: true }))
+ );
+ await page.locator('form').evaluate((form) => {
+ if (
+ form.dispatchEvent(
+ new SubmitEvent('submit', { bubbles: true, cancelable: true })
+ )
+ )
+ throw new Error('Unavailable submit was not prevented');
+ });
+ await expect(status).toHaveText(expected);
+ await page.getByRole('button', { name: toggle }).click();
+ await expect(search).toBeEnabled();
+ }
+ const measured = await page.evaluate(() => ({
+ width: innerWidth,
+ scroll: globalThis.document.documentElement.scrollWidth,
+ textarea: (() => {
+ const rect = globalThis.document
+ .querySelector('textarea')!
+ .getBoundingClientRect();
+ return { width: rect.width, height: rect.height, x: rect.x };
+ })(),
+ controls: Array.from(
+ globalThis.document.querySelectorAll('button')
+ ).map((element) => element.getBoundingClientRect().height)
+ }));
+ expect(measured.scroll).toBeLessThanOrEqual(width);
+ expect(measured.textarea.width).toBeGreaterThan(0);
+ expect(measured.textarea.x + measured.textarea.width).toBeLessThanOrEqual(
+ width
+ );
+ for (const height of measured.controls)
+ expect(height).toBeGreaterThanOrEqual(44);
+ console.log(
+ JSON.stringify({
+ fixture: 'HCP015_CONTROLLED_FORM_ONLY',
+ measured,
+ submitted: ['', ' carrots & Victoria \nx', '菜'],
+ shortcut: 'OMITTED',
+ composition: 'forced submit prevented until compositionend'
+ })
+ );
+ expect(new URL(page.url()).pathname).toBe('/');
+ expect(await page.evaluate(() => 'nostr' in window)).toBe(false);
+ expect(external).toEqual([]);
+ } finally {
+ await context.close();
+ }
+ });
+}
diff --git a/web/tests/provenance/output.test.mjs b/web/tests/provenance/output.test.mjs
@@ -101,8 +101,8 @@ await test('actual output qualification', { timeout: 30000 }, async (t) => {
async (t) => {
const f = await fixture(t);
const files = await f.audit();
- // The route-state import adds one compiler-owned state chunk; CSS stays once-imported.
- assert.equal(files.length, 17);
+ // Shared unchanged Button now serves both shell and form; CSS stays once-imported.
+ assert.equal(files.length, 18);
assert.equal(files.filter((name) => name.endsWith('.css')).length, 1);
assert.ok(
files.some((name) =>
@@ -194,6 +194,86 @@ await test('actual output qualification', { timeout: 30000 }, async (t) => {
);
});
}
+ await t.test(
+ 'actual shared Button compiler module has an owned client counterpart',
+ async (t) => {
+ const f = await fixture(t);
+ const manifest = JSON.parse(
+ await readFile(
+ path.join(f.web, '.svelte-kit/output/client/.vite/manifest.json'),
+ 'utf8'
+ )
+ );
+ const entries = Object.entries(manifest).filter(
+ ([, record]) => record.name === 'Button'
+ );
+ assert.equal(entries.length, 1);
+ const [key, button] = entries[0];
+ assert.match(key, /^_[A-Za-z0-9_-]+\.js$/);
+ assert.ok(
+ button.imports.some(
+ /** @param {string} dependency */
+ (dependency) => manifest[dependency].name === 'client'
+ )
+ );
+ for (const consumer of ['nodes/0', 'nodes/2']) {
+ assert.ok(
+ Object.values(manifest).some(
+ (record) => record.name === consumer && record.imports.includes(key)
+ )
+ );
+ }
+ assert.deepEqual(
+ await readFile(path.join(f.web, 'build', button.file)),
+ await readFile(
+ path.join(f.web, '.svelte-kit/output/client', button.file)
+ )
+ );
+ assert.ok((await f.audit()).includes(button.file));
+ }
+ );
+ for (const mutation of [
+ 'unknown-name',
+ 'duplicate-Button',
+ 'missing-counterpart',
+ 'changed-counterpart'
+ ]) {
+ await t.test('Button module fails closed: ' + mutation, async (t) => {
+ const f = await fixture(t);
+ const file = path.join(
+ f.web,
+ '.svelte-kit/output/client/.vite/manifest.json'
+ );
+ const manifest = JSON.parse(await readFile(file, 'utf8'));
+ const state = Object.values(manifest).find(
+ (record) => record.name === 'Button'
+ );
+ assert.ok(
+ state,
+ 'The actual shared Button module must exist before mutation'
+ );
+ if (mutation === 'unknown-name') state.name = 'Button-unapproved';
+ if (mutation === 'duplicate-Button')
+ manifest['_HCduplicate.js'] = { ...state };
+ if (mutation === 'missing-counterpart')
+ await rm(path.join(f.web, 'build', state.file));
+ if (mutation === 'changed-counterpart')
+ await writeFile(
+ path.join(f.web, 'build', state.file),
+ Buffer.concat([
+ await readFile(path.join(f.web, 'build', state.file)),
+ Buffer.from('changed counterpart')
+ ])
+ );
+ await writeFile(file, JSON.stringify(manifest));
+ await assert.rejects(
+ f.audit,
+ mutation.endsWith('name') || mutation === 'duplicate-Button'
+ ? /Undeclared compiler module/
+ : /Static output inventory mismatch|Static output differs from owned compiler input/
+ );
+ });
+ }
for (const name of [
'notes.txt',
'_app/immutable/chunks/innocent.ABC12345.js',
diff --git a/web/tests/unit/bootstrap.test.ts b/web/tests/unit/bootstrap.test.ts
@@ -27,6 +27,16 @@ describe('static guest shell', () => {
expect(prerender).toBe(true);
expect(ssr).toBe(true);
});
+ it('renders the shared anonymous form exactly once with honest unavailable submission', () => {
+ const html = render(Shell).body;
+ expect(html.match(/<textarea\b/g)).toHaveLength(1);
+ expect(html).toContain('What are you looking for?');
+ expect(html).toContain('For example, carrots or carrots Victoria.');
+ expect(html).toContain('rows="2"');
+ expect(html).toMatch(/<button[^>]*type="submit"[^>]*disabled[^>]*>Search/);
+ expect(html).toContain('Search is unavailable during development.');
+ expect(html).not.toContain('<h1>');
+ });
it('composes the actual shared shell and preserves the route body without a global h1', () => {
const output = render(Shell);
expect(output.body).toMatch(
diff --git a/web/tests/unit/components/search-form.test.ts b/web/tests/unit/components/search-form.test.ts
@@ -0,0 +1,54 @@
+import { render } from 'svelte/server';
+import { describe, expect, it } from 'vitest';
+import SearchForm from '../../../src/lib/components/SearchForm.svelte';
+
+describe('shared labelled search form SSR', () => {
+ it('renders one two-row textarea, visible associated label and example hint', () => {
+ const html = render(SearchForm).body;
+ expect(html.match(/<textarea\b/g)).toHaveLength(1);
+ expect(html).toContain('rows="2"');
+ expect(html).toContain('What are you looking for?');
+ expect(html).toContain('For example, carrots or carrots Victoria.');
+ const id = html.match(/<textarea[^>]* id="([^"]+)"/)?.[1];
+ expect(id).toBeTruthy();
+ expect(html).toContain(`for="${id}"`);
+ expect(html).toContain(`aria-describedby="${id}-hint"`);
+ expect(html).toContain(`id="${id}-hint"`);
+ });
+ it('uses native form submission and visibly disables absent callers', () => {
+ const html = render(SearchForm).body;
+ expect(html).toContain('<form');
+ expect(html).toMatch(/<button[^>]*type="submit"[^>]*disabled[^>]*>Search/);
+ expect(html).toContain('Search is unavailable during development.');
+ expect(html).not.toMatch(/action=|placeholder=|maxlength=|required/);
+ });
+ it('enables an explicit typed caller without invoking it during SSR', () => {
+ const html = render(SearchForm, {
+ props: {
+ onsubmit: (input: string) => {
+ throw new Error(`SSR invoked search caller: ${input}`);
+ }
+ }
+ }).body;
+ expect(html).not.toMatch(/<button[^>]*disabled/);
+ expect(html).not.toContain('Search is unavailable');
+ });
+ it('honors explicit disabled even with a caller', () => {
+ const html = render(SearchForm, {
+ props: {
+ disabled: true,
+ onsubmit: () => {
+ throw new Error('SSR invoked disabled caller');
+ }
+ }
+ }).body;
+ expect(html).toMatch(/<button[^>]*disabled/);
+ expect(html).toContain('Search is unavailable');
+ });
+ it('does not add search policy, onboarding or browser effects', () => {
+ const html = render(SearchForm).body;
+ expect(html).not.toMatch(
+ /<h1|location|signup|AI|WebSocket|nostr|\/search\?/
+ );
+ });
+});
diff --git a/web/tools/check-output.mjs b/web/tools/check-output.mjs
@@ -213,7 +213,8 @@ export async function auditOutput(webDirectory) {
'client',
'client.svelte',
'client-entry',
- 'state'
+ 'state',
+ 'Button'
]);
const admitted = new Map([['build-info.json', expectedMetadata]]);
const seen = new Set();