Files
PotentialStorage/test/browser/global-setup.ts
T
Claude 68d1a1c8e9
CI / Node 24 (push) Successful in 15s
CI / Node 26 (push) Successful in 16s
CI / Node 22 (pull_request) Successful in 13s
CI / Node 24 (pull_request) Failing after 3s
CI / Node 26 (pull_request) Failing after 4s
CI / Chromium (push) Failing after 1m8s
CI / Publish to staging registry (push) Skipped
CI / Chromium (pull_request) Failing after 1m3s
CI / Publish to staging registry (pull_request) Skipped
CI / Node 22 (push) Failing after 4s
Add encryption, Chromium tests and a README
- KVStorageEncrypted: AES-GCM per value (fresh IV, storage key as AAD), keys stay
  readable; decrypts and re-emits pushed changes and passes subscriptions through, so it
  can be a composite source. generateKey / exportKey / importKey / deriveKey (PBKDF2).
- KVStorageHttpServer: allowOrigins (CORS), including cache-control for SSE preflights.
- Chromium tests (Vitest browser mode + Playwright) against a real cross-origin server:
  conformance for IndexedDB, encrypted, HTTP and composite stores; signed requests and
  SSE; two devices syncing, offline writes surviving a reload. New CI job.
- Composite fixes found by those tests: sync() during a running sync schedules one more
  (changes between the first scan and the stream connecting were missed); a queued write
  the source refuses is dropped, restored and reported (onError) instead of blocking the
  queue forever.
- README with examples, mirrored in test/readme.test.ts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017Qxbkp4tA7G5SCWjzWuxmE
2026-10-23 14:25:22 +00:00

34 lines
1.3 KiB
TypeScript

import type { TestProject } from 'vitest/node'
import { KVStorageHttpServer } from '../../src/kv-storage/kv-storage-http-server.js'
import { KVStorageInMemory } from '../../src/kv-storage/kv-storage-in-memory.js'
import { Ed25519Verifier } from '../../src/utils/request-auth.js'
import { serve } from '../kv-storage/node-server.js'
declare module 'vitest' {
interface ProvidedContext {
/** Base URL of the test server. `<url>/open/<space>` and `<url>/signed/<space>` are fresh, isolated stores. */
serverUrl: string
}
}
/** A real HTTP server on another origin than the test page, with one store per `/<auth>/<space>`. */
export default async function setup(project: TestProject): Promise<() => Promise<void>> {
const spaces = new Map<string, KVStorageHttpServer>()
const server = await serve(async (request) => {
const [, auth, space] = new URL(request.url).pathname.split('/')
const basePath = `/${auth}/${space}`
let handler = spaces.get(basePath)
if (!handler) {
handler = new KVStorageHttpServer(new KVStorageInMemory(), {
auth: auth === 'signed' ? { verifiers: [new Ed25519Verifier()] } : 'none',
basePath,
allowOrigins: '*',
})
spaces.set(basePath, handler)
}
return handler.handle(request)
})
project.provide('serverUrl', server.url)
return server.close
}