app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

commit 43f63e1d5a348ec4ac926377341b849062b9fc8a
parent 110fbcca9df81964c6c20463b53820942d0c3fd9
Author: triesap <tyson@radroots.org>
Date:   Mon,  5 Oct 2026 20:39:54 +0000

web: declare eleven route shells and index policy (HCP-020)

- Declare the exact eleven pages with bounded dynamic parameter matching.
- Keep protected pages behind generic unavailable connection and unlock gates.
- Apply private noindex policy and verify SSR has no account or data effects.
- Admit measured static counterparts and preserve output and import controls.

Diffstat:
Aweb/src/lib/components/AccountGate.svelte | 17+++++++++++++++++
Mweb/src/lib/nostr/references.ts | 2+-
Aweb/src/params.ts | 8++++++++
Mweb/src/params/local_id.ts | 2+-
Mweb/src/params/naddr.ts | 2+-
Aweb/src/routes/+error.svelte | 12++++++++++++
Mweb/src/routes/+layout.svelte | 12+++++++++++-
Aweb/src/routes/about/+page.svelte | 11+++++++++++
Aweb/src/routes/messages/+page.svelte | 5+++++
Aweb/src/routes/messages/[conversationId=local_id]/+page.svelte | 5+++++
Aweb/src/routes/messages/[conversationId=local_id]/+page.ts | 1+
Aweb/src/routes/privacy/+page.svelte | 5+++++
Aweb/src/routes/products/[naddr=naddr]/+page.svelte | 5+++++
Aweb/src/routes/products/[naddr=naddr]/+page.ts | 1+
Aweb/src/routes/products/[naddr=naddr]/edit/+page.svelte | 5+++++
Aweb/src/routes/products/[naddr=naddr]/edit/+page.ts | 1+
Aweb/src/routes/sell/+page.svelte | 5+++++
Aweb/src/routes/selling/+page.svelte | 5+++++
Aweb/src/routes/selling/drafts/[draftId=local_id]/+page.svelte | 5+++++
Aweb/src/routes/selling/drafts/[draftId=local_id]/+page.ts | 1+
Aweb/static/robots.txt | 5+++++
Mweb/tests/e2e/bootstrap.spec.ts | 2+-
Aweb/tests/e2e/route-inventory.spec.ts | 155+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mweb/tests/e2e/search-form.spec.ts | 2++
Mweb/tests/integration/loopback.test.ts | 26+++++++++++++++++++++++++-
Mweb/tests/provenance/output.test.mjs | 81++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
Mweb/tests/provenance/source-boundaries.test.mjs | 46++++++++++++++++++++++++++++++++++++++++++++++
Aweb/tests/unit/route-inventory.test.ts | 138+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mweb/tools/check-output.mjs | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
Mweb/tools/source-boundaries.mjs | 45++++++++++++++++++++++++++++++++++++++++-----
30 files changed, 661 insertions(+), 43 deletions(-)

diff --git a/web/src/lib/components/AccountGate.svelte b/web/src/lib/components/AccountGate.svelte @@ -0,0 +1,17 @@ +<script lang="ts"> + import Button from './primitives/Button.svelte'; +</script> + +<svelte:head> + <title>HarvestCircle</title> + <meta name="robots" content="noindex" /> +</svelte:head> +<div class="page page--reading stack"> + <h1>Connect or unlock</h1> + <p>Connect an extension and unlock your account to continue.</p> + <p class="notice">Account access is unavailable during development.</p> + <div class="cluster"> + <Button label="Connect extension" disabled /> + <Button label="Unlock" disabled /> + </div> +</div> diff --git a/web/src/lib/nostr/references.ts b/web/src/lib/nostr/references.ts @@ -1,6 +1,6 @@ import { decodePointer, naddrEncode } from 'applesauce-core/helpers/pointers'; import { bech32 } from '@scure/base'; -import { canonicalPublicKey } from '../contracts/public-key'; +import { canonicalPublicKey } from '../contracts/public-key.ts'; const maximumRouteBytes = 2048; const encoder = new TextEncoder(); diff --git a/web/src/params.ts b/web/src/params.ts @@ -0,0 +1,8 @@ +import { defineParams } from '@sveltejs/kit/params'; +import { match as localIdMatches } from './params/local_id.ts'; +import { match as naddrMatches } from './params/naddr.ts'; + +export const params = defineParams({ + local_id: (value: string) => (localIdMatches(value) ? value : undefined), + naddr: (value: string) => (naddrMatches(value) ? value : undefined) +}); diff --git a/web/src/params/local_id.ts b/web/src/params/local_id.ts @@ -1,4 +1,4 @@ -import { canonicalLocalId } from '../lib/private-handles'; +import { canonicalLocalId } from '../lib/private-handles.ts'; export function match(value: string): boolean { return canonicalLocalId(value) !== undefined; diff --git a/web/src/params/naddr.ts b/web/src/params/naddr.ts @@ -1,4 +1,4 @@ -import { decodeProductReference } from '../lib/nostr/references'; +import { decodeProductReference } from '../lib/nostr/references.ts'; export function match(value: string): boolean { return decodeProductReference(value) !== undefined; diff --git a/web/src/routes/+error.svelte b/web/src/routes/+error.svelte @@ -0,0 +1,12 @@ +<script lang="ts"> + import { page } from '$app/state'; +</script> + +<svelte:head> + <title>HarvestCircle</title> + <meta name="robots" content="noindex" /> +</svelte:head> +<div class="page page--reading stack"> + <h1>{page.status === 404 ? '404' : 'Unavailable'}</h1> + <p>{page.status === 404 ? 'Not Found' : 'This page is unavailable.'}</p> +</div> diff --git a/web/src/routes/+layout.svelte b/web/src/routes/+layout.svelte @@ -8,6 +8,16 @@ let { children }: { children: Snippet } = $props(); </script> -<AppShell currentPath={page.url.pathname}> +<AppShell + currentPath={page.url.pathname} + availableRoutes={[ + '/search', + '/sell', + '/selling', + '/messages', + '/about', + '/privacy' + ]} +> {@render children()} </AppShell> diff --git a/web/src/routes/about/+page.svelte b/web/src/routes/about/+page.svelte @@ -0,0 +1,11 @@ +<svelte:head><title>About — HarvestCircle</title></svelte:head> +<div class="page page--reading stack"> + <h1>About</h1> + <p class="notice"> + Information about HarvestCircle is unavailable during development. + </p> + <section id="help"> + <h2>Help / report</h2> + <p>Help and reporting are unavailable during development.</p> + </section> +</div> diff --git a/web/src/routes/messages/+page.svelte b/web/src/routes/messages/+page.svelte @@ -0,0 +1,5 @@ +<script lang="ts"> + import AccountGate from '../../lib/components/AccountGate.svelte'; +</script> + +<AccountGate /> diff --git a/web/src/routes/messages/[conversationId=local_id]/+page.svelte b/web/src/routes/messages/[conversationId=local_id]/+page.svelte @@ -0,0 +1,5 @@ +<script lang="ts"> + import AccountGate from '../../../lib/components/AccountGate.svelte'; +</script> + +<AccountGate /> diff --git a/web/src/routes/messages/[conversationId=local_id]/+page.ts b/web/src/routes/messages/[conversationId=local_id]/+page.ts @@ -0,0 +1 @@ +export const prerender = false; diff --git a/web/src/routes/privacy/+page.svelte b/web/src/routes/privacy/+page.svelte @@ -0,0 +1,5 @@ +<svelte:head><title>Privacy — HarvestCircle</title></svelte:head> +<div class="page page--reading stack"> + <h1>Privacy</h1> + <p class="notice">Privacy information is unavailable during development.</p> +</div> diff --git a/web/src/routes/products/[naddr=naddr]/+page.svelte b/web/src/routes/products/[naddr=naddr]/+page.svelte @@ -0,0 +1,5 @@ +<svelte:head><title>Food — HarvestCircle</title></svelte:head> +<div class="page page--reading stack"> + <h1>Food</h1> + <p class="notice">Food details are unavailable during development.</p> +</div> diff --git a/web/src/routes/products/[naddr=naddr]/+page.ts b/web/src/routes/products/[naddr=naddr]/+page.ts @@ -0,0 +1 @@ +export const prerender = false; diff --git a/web/src/routes/products/[naddr=naddr]/edit/+page.svelte b/web/src/routes/products/[naddr=naddr]/edit/+page.svelte @@ -0,0 +1,5 @@ +<script lang="ts"> + import AccountGate from '../../../../lib/components/AccountGate.svelte'; +</script> + +<AccountGate /> diff --git a/web/src/routes/products/[naddr=naddr]/edit/+page.ts b/web/src/routes/products/[naddr=naddr]/edit/+page.ts @@ -0,0 +1 @@ +export const prerender = false; diff --git a/web/src/routes/sell/+page.svelte b/web/src/routes/sell/+page.svelte @@ -0,0 +1,5 @@ +<script lang="ts"> + import AccountGate from '../../lib/components/AccountGate.svelte'; +</script> + +<AccountGate /> diff --git a/web/src/routes/selling/+page.svelte b/web/src/routes/selling/+page.svelte @@ -0,0 +1,5 @@ +<script lang="ts"> + import AccountGate from '../../lib/components/AccountGate.svelte'; +</script> + +<AccountGate /> diff --git a/web/src/routes/selling/drafts/[draftId=local_id]/+page.svelte b/web/src/routes/selling/drafts/[draftId=local_id]/+page.svelte @@ -0,0 +1,5 @@ +<script lang="ts"> + import AccountGate from '../../../../lib/components/AccountGate.svelte'; +</script> + +<AccountGate /> diff --git a/web/src/routes/selling/drafts/[draftId=local_id]/+page.ts b/web/src/routes/selling/drafts/[draftId=local_id]/+page.ts @@ -0,0 +1 @@ +export const prerender = false; diff --git a/web/static/robots.txt b/web/static/robots.txt @@ -0,0 +1,5 @@ +User-agent: * +Disallow: /sell +Disallow: /selling +Disallow: /messages +Disallow: /products/*/edit diff --git a/web/tests/e2e/bootstrap.spec.ts b/web/tests/e2e/bootstrap.spec.ts @@ -131,7 +131,7 @@ test('actual browser loads guest shell without an extension', async ({ ).toBeVisible(); await expect( page.getByRole('link', { name: 'Search', exact: true }) - ).toHaveCount(0); + ).toHaveCount(1); await page.keyboard.press('Tab'); await expect( page.getByRole('link', { name: 'Skip to main content' }) diff --git a/web/tests/e2e/route-inventory.spec.ts b/web/tests/e2e/route-inventory.spec.ts @@ -0,0 +1,155 @@ +import { test, expect } from '@playwright/test'; +import { encodeProductReference } from '../../src/lib/nostr/references'; +import { createStaticHarness } from '../integration/harness/static'; + +// Canonical coordinate uses the already qualified public generator point. +const naddr = encodeProductReference({ + kind: 30402, + pubkey: '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798', + identifier: 'HCP020_TEST_ONLY' +}); +if (!naddr) throw new Error('Qualified coordinate could not be encoded'); +const handle = '12345678-1234-4234-8234-123456789abc'; +const cases = [ + { path: '/', title: 'HarvestCircle', private: false }, + { path: '/search', title: 'Search food — HarvestCircle', private: false }, + { path: '/products/' + naddr, title: 'Food — HarvestCircle', private: false }, + { path: '/sell', title: 'HarvestCircle', private: true }, + { path: '/selling', title: 'HarvestCircle', private: true }, + { path: '/selling/drafts/' + handle, title: 'HarvestCircle', private: true }, + { + path: '/products/' + naddr + '/edit', + title: 'HarvestCircle', + private: true + }, + { path: '/messages', title: 'HarvestCircle', private: true }, + { path: '/messages/' + handle, title: 'HarvestCircle', private: true }, + { path: '/about', title: 'About — HarvestCircle', private: false }, + { path: '/privacy', title: 'Privacy — HarvestCircle', private: false } +]; +for (const routeCase of cases) { + test( + 'direct navigation and reload preserve actual route shell ' + + routeCase.path, + async ({ browser }) => { + const server = await createStaticHarness(); + const context = await browser.newContext(); + try { + await context.route('**/*', (route) => + new URL(route.request().url()).origin === server.url + ? route.continue() + : route.abort() + ); + // Tripwires enforce no guest account/storage/signing/relay acquisition. + await context.addInitScript(() => { + for (const name of ['indexedDB', 'nostr', 'WebSocket']) + Object.defineProperty(window, name, { + configurable: true, + get() { + throw new Error('Guest attempted ' + name); + } + }); + }); + const page = await context.newPage(); + const errors: string[] = []; + page.on('pageerror', (error) => errors.push(error.message)); + for (const navigate of [ + () => page.goto(server.url + routeCase.path), + () => page.reload() + ]) { + expect((await navigate())?.status()).toBe(200); + await expect(page).toHaveTitle(routeCase.title); + await expect(page.getByRole('main')).toHaveCount(1); + expect(new URL(page.url()).pathname).toBe(routeCase.path); + await expect( + page.getByRole('link', { name: 'Search', exact: true }) + ).toHaveCount(1); + if (routeCase.private) { + await expect( + page.getByRole('heading', { + name: 'Connect or unlock', + exact: true + }) + ).toBeVisible(); + await expect(page.locator('meta[name="robots"]')).toHaveAttribute( + 'content', + 'noindex' + ); + await expect( + page.getByRole('button', { name: 'Unlock', exact: true }) + ).toBeDisabled(); + await expect(page.locator('main button')).toHaveCount(2); + await expect( + page.locator('main input, main textarea, main form') + ).toHaveCount(0); + expect(await page.locator('main').textContent()).not.toContain( + handle + ); + expect(await page.locator('main').textContent()).not.toContain( + naddr + ); + } + } + expect(errors).toEqual([]); + } finally { + await context.close(); + await server.close(); + } + expect(context.pages()).toHaveLength(0); + expect(server.state()).toEqual({ listening: false, childProcesses: 0 }); + } + ); +} + +test('unknown routes and invalid opaque syntax never substitute data or return missing assets as HTML', async ({ + browser +}) => { + const server = await createStaticHarness(); + const context = await browser.newContext(); + try { + const page = await context.newPage(); + for (const pathname of [ + '/orders', + '/checkout', + '/login', + '/api/login', + '/profiles' + ]) { + const response = await context.request.get(server.url + pathname, { + headers: { accept: 'text/html' } + }); + expect(response.status()).toBe(404); + expect(await response.text()).toBe(''); + } + for (const pathname of [ + '/products/unsupported-coordinate', + '/selling/drafts/unknown-draft', + '/messages/unknown-conversation' + ]) { + await page.goto(server.url + pathname); + await expect( + page.getByRole('heading', { name: '404', exact: true }) + ).toBeVisible(); + await expect(page).toHaveTitle('HarvestCircle'); + await expect( + page.locator('main input, main textarea, main form') + ).toHaveCount(0); + } + for (const pathname of [ + '/missing.js', + '/missing.css', + '/_app/missing.js' + ]) { + const response = await context.request.get(server.url + pathname, { + headers: { accept: 'text/html' } + }); + expect(response.status()).toBe(404); + expect(await response.text()).toBe(''); + } + } finally { + await context.close(); + await server.close(); + } + expect(context.pages()).toHaveLength(0); + expect(server.state()).toEqual({ listening: false, childProcesses: 0 }); +}); diff --git a/web/tests/e2e/search-form.spec.ts b/web/tests/e2e/search-form.spec.ts @@ -32,6 +32,8 @@ test.beforeAll(async () => { checkout ]); for (const relative of [ + 'web/src', + 'web/tools/source-boundaries.mjs', 'web/src/lib/components/AppShell.svelte', 'web/src/app.css', 'web/src/routes/+layout.svelte', diff --git a/web/tests/integration/loopback.test.ts b/web/tests/integration/loopback.test.ts @@ -45,6 +45,30 @@ await test('navigation fallback serves actual separate output and preserves miss new URL('../../build/search.html', import.meta.url), 'utf8' ); + const prerendered = new Map([['/search', search]]); + for (const pathname of [ + '/sell', + '/selling', + '/messages', + '/about', + '/privacy' + ]) { + prerendered.set( + pathname, + await readFile( + new URL('../../build' + pathname + '.html', import.meta.url), + 'utf8' + ) + ); + } + for (const pathname of ['/sell', '/selling', '/messages']) { + const html = prerendered.get(pathname); + assert.ok(html); + assert.match(html, /<title>HarvestCircle<\/title>/); + assert.match(html, /name="robots" content="noindex"/); + assert.match(html, /Account access is unavailable during development/); + assert.doesNotMatch(html, /<form|<input|<textarea/); + } assert.notEqual(search, fallback); assert.match(search, /<title>Search food — HarvestCircle<\/title>/); assert.match(search, /Search data is unavailable during development\./); @@ -67,7 +91,7 @@ await test('navigation fallback serves actual separate output and preserves miss assert.equal(result.headers.get('content-type'), 'text/html'); assert.equal( await result.text(), - pathname === '/search?q=food' ? search : fallback + prerendered.get(new URL(pathname, server.url).pathname) ?? fallback ); } for (const pathname of [ diff --git a/web/tests/provenance/output.test.mjs b/web/tests/provenance/output.test.mjs @@ -20,7 +20,7 @@ import { fileURLToPath } from 'node:url'; import { generateBuildInfo } from '../../tools/build-info.mjs'; import { auditOutput } from '../../tools/check-output.mjs'; -// Allow bounded setup/copy time for all 73 checks and two real compilations. +// Allow bounded setup/copy time for all 83 checks and two real compilations. // Admission checks get 10 seconds; cold compiler work gets 60 seconds. await test('actual output qualification', { timeout: 180000 }, async (t) => { /** @param {string} name @param {(context: import('node:test').TestContext) => Promise<void>} run @param {number} [timeout] */ @@ -114,8 +114,8 @@ await test('actual output qualification', { timeout: 180000 }, async (t) => { async (t) => { const f = await fixture(t); const files = await f.audit(); - // Exact new search node/shared routes chunk/page; CSS stays once-imported. - assert.equal(files.length, 21); + // Exact eleven-route module/page/static admission; CSS stays once-imported. + assert.equal(files.length, 41); assert.ok(files.includes('search.html')); assert.equal(files.filter((name) => name.endsWith('.css')).length, 1); assert.ok( @@ -135,27 +135,29 @@ await test('actual output qualification', { timeout: 180000 }, async (t) => { ); } ); - await check( - 'search route admission requires its owned source and exact module/page counterparts', - async (t) => { - const f = await fixture(t); - const source = path.join(f.web, 'src/routes/search/+page.svelte'); - const original = await readFile(source); - await rm(source); - git(f.root, 'add', '--', 'web/src/routes/search/+page.svelte'); - await generateBuildInfo(f.web); - const metadata = await readFile( - path.join(f.web, 'static/build-info.json') - ); - await writeFile(path.join(f.web, 'build/build-info.json'), metadata); - await writeFile( - path.join(f.web, '.svelte-kit/output/client/build-info.json'), - metadata - ); - await assert.rejects(f.audit, /Undeclared compiler module/); - await writeFile(source, original); - } - ); + for (const routeSource of ['search/+page.svelte', 'messages/+page.svelte']) + await check( + routeSource + + ' admission requires its owned source and exact module/page counterparts', + async (t) => { + const f = await fixture(t); + const source = path.join(f.web, 'src/routes', routeSource); + const original = await readFile(source); + await rm(source); + git(f.root, 'add', '--', 'web/src/routes/' + routeSource); + await generateBuildInfo(f.web); + const metadata = await readFile( + path.join(f.web, 'static/build-info.json') + ); + await writeFile(path.join(f.web, 'build/build-info.json'), metadata); + await writeFile( + path.join(f.web, '.svelte-kit/output/client/build-info.json'), + metadata + ); + await assert.rejects(f.audit, /Undeclared compiler module/); + await writeFile(source, original); + } + ); for (const mutation of [ 'unknown-name', 'duplicate', @@ -192,6 +194,33 @@ await test('actual output qualification', { timeout: 180000 }, async (t) => { } ); } + for (const mutation of ['missing', 'changed']) { + await check('full-route static robots rejects ' + mutation, async (t) => { + const f = await fixture(t); + const target = path.join(f.web, 'build/robots.txt'); + if (mutation === 'missing') await rm(target); + else await writeFile(target, 'User-agent: *\nAllow: /\n'); + await assert.rejects(f.audit); + }); + } + await check( + 'full-route compiler rejects an unowned thirteenth node', + 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 entry = Object.entries(manifest).find( + ([, record]) => record.name === 'nodes/12' + ); + assert.ok(entry); + entry[1].name = 'nodes/13'; + await writeFile(file, JSON.stringify(manifest)); + await assert.rejects(f.audit, /Undeclared compiler module/); + } + ); await check( 'actual route-state compiler module has an owned client counterpart', async (t) => { @@ -520,7 +549,9 @@ await test('actual output qualification', { timeout: 180000 }, async (t) => { '.svelte-kit/output/client/.vite/manifest.json', '.svelte-kit/output/prerendered/pages/index.html', '.svelte-kit/output/prerendered/pages/search.html', - 'src/routes/search/+page.svelte' + 'src/routes/search/+page.svelte', + 'static/robots.txt', + '.svelte-kit/output/prerendered/pages/messages.html' ]) { for (const kind of ['fifo', 'symlink', 'hardlink']) { await check( diff --git a/web/tests/provenance/source-boundaries.test.mjs b/web/tests/provenance/source-boundaries.test.mjs @@ -1808,3 +1808,49 @@ for (const command of ['check', 'lint', 'build', 'test:unit', 'dev']) /svelte-check found|vite v.*building|RUN\s+v/ ); })); + +test('HCP020 admits the pinned Kit3 consolidated parameter module at its exact source location', async () => { + await fixture(async ({ directory, put, execute }) => { + await confineSvelte(directory); + for (const name of ['package.json', 'src/exports/params/index.js']) { + await put( + 'node_modules/@sveltejs/kit/' + name, + await readFile(path.join(root, 'node_modules/@sveltejs/kit', name)) + ); + } + await put( + 'src/params.ts', + "import { defineParams } from '@sveltejs/kit/params'; export const params = defineParams({ local_id: (value: string) => value === 'known' ? value : undefined });" + ); + await put( + 'src/routes/+page.ts', + "import { params } from '../params'; export const value = params;" + ); + const result = execute(); + assert.equal(result.status, 0, result.stderr); + }); +}); +for (const [name, specifier] of [ + ['src/routes/+page.ts', '@sveltejs/kit/params'], + ['src/params.ts', '@sveltejs/kit/params/unknown'] +]) { + test( + 'HCP020 rejects unrelated Kit3 parameter import ' + name + ' ' + specifier, + async () => { + await fixture(async ({ put, execute }) => { + await put( + name, + "import { defineParams } from '" + + specifier + + "'; export const value = defineParams;" + ); + if (name === 'src/params.ts') + await put( + 'src/routes/+page.ts', + "import { value } from '../params'; export { value };" + ); + reject(execute(), /forbidden production import/); + }); + } + ); +} diff --git a/web/tests/unit/route-inventory.test.ts b/web/tests/unit/route-inventory.test.ts @@ -0,0 +1,138 @@ +import { prerender as editPrerender } from '../../src/routes/products/[naddr=naddr]/edit/+page'; +import { params } from '../../src/params'; +import { readFileSync, readdirSync } from 'node:fs'; +import { fileURLToPath } from 'node:url'; +import { render } from 'svelte/server'; +import { describe, expect, it, vi } from 'vitest'; + +import Sell from '../../src/routes/sell/+page.svelte'; +import Selling from '../../src/routes/selling/+page.svelte'; +import Draft from '../../src/routes/selling/drafts/[draftId=local_id]/+page.svelte'; +import Edit from '../../src/routes/products/[naddr=naddr]/edit/+page.svelte'; +import Messages from '../../src/routes/messages/+page.svelte'; +import Conversation from '../../src/routes/messages/[conversationId=local_id]/+page.svelte'; +import Product from '../../src/routes/products/[naddr=naddr]/+page.svelte'; +import About from '../../src/routes/about/+page.svelte'; +import Privacy from '../../src/routes/privacy/+page.svelte'; +import ErrorPage from '../../src/routes/+error.svelte'; +import { prerender as productPrerender } from '../../src/routes/products/[naddr=naddr]/+page'; +import { prerender as draftPrerender } from '../../src/routes/selling/drafts/[draftId=local_id]/+page'; +import { prerender as conversationPrerender } from '../../src/routes/messages/[conversationId=local_id]/+page'; + +const errorState = vi.hoisted(() => ({ + status: 404, + error: { message: 'PRIVATE_TEST_ONLY' } +})); +vi.mock('$app/state', () => ({ page: errorState })); + +const routeRoot = fileURLToPath(new URL('../../src/routes/', import.meta.url)); +const expectedPages = [ + '+page.svelte', + 'search/+page.svelte', + 'products/[naddr=naddr]/+page.svelte', + 'sell/+page.svelte', + 'selling/+page.svelte', + 'selling/drafts/[draftId=local_id]/+page.svelte', + 'products/[naddr=naddr]/edit/+page.svelte', + 'messages/+page.svelte', + 'messages/[conversationId=local_id]/+page.svelte', + 'about/+page.svelte', + 'privacy/+page.svelte' +].sort(); + +describe('approved route inventory', () => { + it('owns exactly eleven page files with the existing bounded parameter matchers', () => { + const pages = readdirSync(routeRoot, { recursive: true }) + .filter((name): name is string => typeof name === 'string') + .filter((name) => name.endsWith('+page.svelte')) + .sort(); + expect(pages).toEqual(expectedPages); + }); +}); + +describe('thin protected route SSR', () => { + for (const [name, component] of Object.entries({ + Sell, + Selling, + Draft, + Edit, + Messages, + Conversation + })) { + it( + name + + ' renders only a generic unavailable connection/unlock gate without browser effects', + () => { + const output = render(component); + expect(output.head).toContain('<title>HarvestCircle</title>'); + expect(output.head).toMatch(/name="robots" content="noindex"/); + expect(output.body).toContain('Connect or unlock'); + expect(output.body).toContain( + 'Account access is unavailable during development.' + ); + expect(output.body).toMatch( + /<button[^>]*disabled[^>]*>Connect extension/ + ); + expect(output.body).toMatch(/<button[^>]*disabled[^>]*>Unlock/); + expect(output.body).not.toMatch( + /<form|<textarea|<input|PRIVATE_TEST_ONLY|naddr1/ + ); + // The shared SSR setup throws on IDB, extension, socket or fetch access. + } + ); + } + it('dynamic routes inherit SSR and use navigation fallback rather than fake prerendered identities', () => { + expect([ + productPrerender, + draftPrerender, + conversationPrerender, + editPrerender + ]).toEqual([false, false, false, false]); + }); + it('public shells honestly disclose unavailable content without invented listings or support', () => { + for (const component of [Product, About, Privacy]) { + const output = render(component); + expect(output.body).toContain('unavailable during development.'); + expect(output.body).not.toMatch(/<form|<textarea|<input|mailto:|tel:/); + expect(output.head).not.toContain('noindex'); + } + expect(render(About).body).toContain('id="help"'); + }); + for (const status of [404, 500]) { + it( + 'error ' + + status + + ' never renders arbitrary error details or route state', + () => { + errorState.status = status; + const output = render(ErrorPage); + expect(output.head).toContain('<title>HarvestCircle</title>'); + expect(output.head).toContain('noindex'); + expect(output.body).not.toContain('PRIVATE_TEST_ONLY'); + expect(output.body).toContain( + status === 404 ? 'Not Found' : 'This page is unavailable.' + ); + } + ); + } + it('robots excludes private indexes and opaque edit paths without inventing a sitemap or access control', () => { + expect( + readFileSync(new URL('../../static/robots.txt', import.meta.url), 'utf8') + ).toBe( + 'User-agent: *\nDisallow: /sell\nDisallow: /selling\nDisallow: /messages\nDisallow: /products/*/edit\n' + ); + }); +}); + +it('the pinned Kit3 consolidated matcher adapter preserves existing bounded syntax admission', async () => { + const valid = '12345678-1234-4234-8234-123456789abc'; + expect(await params.local_id['~standard'].validate(valid)).toEqual({ + value: valid + }); + expect( + await params.local_id['~standard'].validate('unknown-draft') + ).toHaveProperty('issues'); + expect( + await params.naddr['~standard'].validate('unsupported-coordinate') + ).toHaveProperty('issues'); +}); diff --git a/web/tools/check-output.mjs b/web/tools/check-output.mjs @@ -210,6 +210,49 @@ export async function auditOutput(webDirectory) { if (!(error instanceof Error && 'code' in error && error.code === 'ENOENT')) throw error; } + const fullRouteSources = [ + 'sell/+page.svelte', + 'selling/+page.svelte', + 'selling/drafts/[draftId=local_id]/+page.svelte', + 'products/[naddr=naddr]/+page.svelte', + 'products/[naddr=naddr]/edit/+page.svelte', + 'messages/+page.svelte', + 'messages/[conversationId=local_id]/+page.svelte', + 'about/+page.svelte', + 'privacy/+page.svelte' + ]; + let presentRoutes = 0; + for (const name of fullRouteSources) { + try { + await readOwned(web, 'src/routes/' + name); + presentRoutes++; + } catch (error) { + if (!( + error instanceof Error && + 'code' in error && + error.code === 'ENOENT' + )) + throw error; + } + } + const hasFullRoutes = presentRoutes !== 0; + if (hasFullRoutes) { + if (presentRoutes !== fullRouteSources.length || !hasSearch) + throw new Error('Undeclared compiler module: incomplete route source'); + for (const name of [ + 'products/[naddr=naddr]/+page.ts', + 'products/[naddr=naddr]/edit/+page.ts', + 'selling/drafts/[draftId=local_id]/+page.ts', + 'messages/[conversationId=local_id]/+page.ts' + ]) + await readOwned(web, 'src/routes/' + name); + for (const name of [ + 'src/params.ts', + 'src/routes/+error.svelte', + 'src/lib/components/AccountGate.svelte' + ]) + await readOwned(web, name); + } // Admit compiler-owned module identities, not arbitrary extensions/copy roots. const names = new Set([ 'entry/app', @@ -230,6 +273,17 @@ export async function auditOutput(webDirectory) { names.add('nodes/3'); names.add('routes'); } + if (hasFullRoutes) { + for (let index = 4; index <= 12; index++) names.add('nodes/' + index); + for (const name of [ + 'AccountGate', + 'references', + 'legacy', + 'rolldown-runtime', + 'shared-errors' + ]) + names.add(name); + } const admitted = new Map([['build-info.json', expectedMetadata]]); const seen = new Set(); for (const [key, record] of Object.entries(manifest)) { @@ -246,9 +300,11 @@ export async function auditOutput(webDirectory) { if (!names.has(record.name) || seen.has(record.name)) throw new Error('Undeclared compiler module'); seen.add(record.name); - const generatedModule = hasSearch - ? /^\.svelte-kit\/generated\/build\/(?:client-optimized\/(?:app|nodes\/[0123])|shared\/error-template)\.js$/ - : /^\.svelte-kit\/generated\/build\/(?:client-optimized\/(?:app|nodes\/[012])|shared\/error-template)\.js$/; + const generatedModule = hasFullRoutes + ? /^\.svelte-kit\/generated\/build\/(?:client-optimized\/(?:app|nodes\/(?:[0-9]|1[012]))|shared\/error-template)\.js$/ + : hasSearch + ? /^\.svelte-kit\/generated\/build\/(?:client-optimized\/(?:app|nodes\/[0123])|shared\/error-template)\.js$/ + : /^\.svelte-kit\/generated\/build\/(?:client-optimized\/(?:app|nodes\/[012])|shared\/error-template)\.js$/; const frameworkModule = /^node_modules\/\.pnpm\/[^/]+\/node_modules\/@sveltejs\/kit\/src\/runtime\/client\/(?:client-entry|entry|payload)\.js$/; if (!( @@ -306,6 +362,16 @@ export async function auditOutput(webDirectory) { } } equal([...seen].sort(), [...names].sort(), 'Incomplete compiler modules'); + if (hasFullRoutes) { + const robots = await readOwned(web, 'static/robots.txt'); + publicText(robots); + equal( + client.get('robots.txt'), + robots, + 'Robots differs from owned static source' + ); + admitted.set('robots.txt', robots); + } const versionBytes = client.get('_app/version.json'); if (!versionBytes) throw new Error('Missing compiler version'); const version = parse(publicText(versionBytes)); @@ -326,10 +392,24 @@ export async function auditOutput(webDirectory) { expectedMetadata, 'Compiler provenance mismatch' ); - const expectedPages = hasSearch - ? ['index.html', 'search.html'] - : ['index.html']; - equal([...pages.keys()], expectedPages, 'Undeclared prerendered pages'); + const expectedPages = hasFullRoutes + ? [ + 'about.html', + 'index.html', + 'messages.html', + 'privacy.html', + 'search.html', + 'sell.html', + 'selling.html' + ] + : hasSearch + ? ['index.html', 'search.html'] + : ['index.html']; + equal( + [...pages.keys()].sort(), + expectedPages, + 'Undeclared prerendered pages' + ); for (const name of expectedPages) admitted.set(name, pages.get(name)); // Adapter fallback has no separate disk input. Reconstruct the exact current // compiler bootstrap shell from the actual index/manifest/version and source diff --git a/web/tools/source-boundaries.mjs b/web/tools/source-boundaries.mjs @@ -1159,6 +1159,34 @@ export async function auditSource(root) { await inventory(sourceRoot); const { pkg, aliases } = await configuration(root); const dependencies = { ...pkg.dependencies, ...pkg.devDependencies }; + // Kit3 params is an import-only export; validate the installed, confined + // exact package declaration without using parent or CommonJS fallbacks. + let kitParamsFile; + if (files.has(path.join(root, 'src/params.ts'))) { + try { + const packageFile = createRequire( + path.join(root, 'package.json') + ).resolve('@sveltejs/kit/package.json'); + if (!inside(path.join(root, 'node_modules'), packageFile)) + throw new Error('outside web dependencies'); + const installed = JSON.parse(await readSource(packageFile)); + if ( + installed.version !== dependencies['@sveltejs/kit'] || + installed.exports?.['./params']?.import !== + './src/exports/params/index.js' + ) + throw new Error('unqualified Kit params export'); + const target = path.join( + path.dirname(packageFile), + 'src/exports/params/index.js' + ); + await readSource(target); + kitParamsFile = target; + } catch { + // A consumed import below reports unresolved admission, never passes. + } + } + const cssImports = []; function local(file, target, specifier) { if ( @@ -1323,7 +1351,7 @@ export async function auditSource(root) { import: '@scure/base', file: 'src/lib/nostr/references.ts', sha256: - 'b417864961a184cab732bebab4fb35089034dbb6a742068d2742f7b353525d80' + '94077cc85e443a8df1fcd24726bcd8d084fae22de7aea7e1341e1acd7cadce9c' } }; const primitive = Object.hasOwn(primitiveAdmissions, actualName) @@ -1338,7 +1366,11 @@ export async function auditSource(root) { primitive.sha256; if ( (actualName === '@sveltejs/kit' && - !['@sveltejs/kit', '@sveltejs/kit/hooks'].includes(actualImport)) || + !['@sveltejs/kit', '@sveltejs/kit/hooks'].includes(actualImport) && + !( + actualImport === '@sveltejs/kit/params' && + relative(root, file) === 'src/params.ts' + )) || (actualName === 'svelte' && /^(svelte\/(compiler|internal|server|attachments|package\.json))/.test( actualImport @@ -1365,9 +1397,12 @@ export async function auditSource(root) { // Direct package imports must be exported by the installed, pinned package; // never search parent node_modules or fall back to a sibling workspace. try { - const resolved = createRequire(path.join(root, 'package.json')).resolve( - specifier - ); + const resolved = + actualImport === '@sveltejs/kit/params' && + relative(root, file) === 'src/params.ts' + ? kitParamsFile + : createRequire(path.join(root, 'package.json')).resolve(specifier); + if (typeof resolved !== 'string') throw new Error('unresolved export'); if (!inside(path.join(root, 'node_modules'), resolved)) throw new Error('outside web dependencies'); } catch {