# Build and acceptance Build a deployable newsman application in its own directory. The local test suite runs against isolated Cloudflare-compatible bindings, a mock identity provider, controlled time, signed feedback fixtures and a recording mail transport. A publisher can install it without access to the AudioTech repository. AudioTech supplies the reference integration contract. Checkout credentials, subscribers and private articles are never build inputs to this public spec. ## 1. Start a single publication (R1, R8, R9) Ship a pinned TypeScript project, lockfile, Cloudflare CLI configuration, numbered D1 migrations and local sample configuration. Bind a Worker with static admin assets, subscriber D1, private R2, OAuth KV, Cron, a send queue and a dead-letter queue. Bind the site’s public form by custom domain route or service binding. Keep deployment names, AWS region, origins, allowed operator addresses and sending identities configurable. A clean install uses the local mail sink, a closed operator list until bootstrapped, and paused production dispatch. Resolve pull settings for publication name, HTTPS public origin, IANA time zone, archive lag in whole days, and SES region. Validate them on bootstrap. Store editable publication settings with a version; changing the existing public origin requires identity and archive revalidation. Set the initial operator allowlist in deployment configuration using verified emails. If the list is empty, show the infrastructure owner how to add their first entry through the documented bootstrap. Cloudflare Access, AWS identity and OAuth client registration remain infrastructure setup. Document every binding, its purpose, creation or rotation procedure, health check and the distinction between preview and live. Keep secrets in the publisher’s secret store. Synthetic development uses fixture keys. **Check** a new publisher installs on their own accounts without a third-party newsman service. The local admin can complete setup from the console and read the same readiness results from a remote MCP client. A missing AWS sender identity leaves draft and preview available and live dispatch paused. ## 2. Establish the operation registry before building screens (R1, R8) Load [operations.json](operations.json), resolve the per-operation schemas, and generate types, two transport adapters and the initial web view inventory. Implement the identity contract in [access.md](access.md). Render lightweight console views for Overview, Issues, Campaigns, Audience, Segments, Templates, Reports, Transfers, Migration, Jobs, Operations, Audit, Operators, Connections and Settings. Include Archive in an issue’s detail view. Display clear empty, loading, conflict and unavailable states. Reuse the publication’s existing public form and confirmation pages. **Check** two verified identities try the same actions. Only the allowlisted operator succeeds. An unattended delegated client with full scopes can initialize, upload, read, write, send, export and manage its grant without screen automation. Removing its operator invalidates a previously authorized client. Run every test in [parity.md](parity.md), including the deliberately broken web-only control. ## 3. Build consent and segmentation (R2, R3, R7) Make the D1 schema enforce unique normalized address lookup and a stable opaque subscriber ID. Keep an append-only consent history, suppression rules, challenge digest and expiry, confirmed timestamp and immutable first-touch attribution. Key tombstones with a secret distinct from token signing. Store timestamps in UTC. A reader’s address comparison rule must be identical during signup, opt-out and import. Trim whitespace and normalize the domain; document the local-part policy and quarantine ambiguous import collisions. Never strip plus tags. Keep subscriber identities, evidence files and operator exports private. Index segment filters before offering them to the operator. For the existing site accept same-origin form-encoded `POST /api/newsletter/subscribe` with `email` and four optional UTM fields. Keep only values matching `[A-Za-z0-9_.-]{1,128}`. On acceptance respond `303 Location: /subscribe/#check-inbox`. Present generic expiry/resend paths and redirect a valid confirmation to `/confirmed/`. Configure signup abuse limits across web and reader MCP. Permanent suppressions apply to both. A normal browser session can reach the site’s archive and feed during mail downtime. **Check** submit the same reader twice across transports, open the confirmation URL with a scanner GET, then consume it once with an explicit POST. Only that last action confirms. Replay, direct confirmed-page visits and later import produce zero additional confirmed events. One-click opt-out blocks a scheduled recipient even if their audience membership was already frozen. ## 4. Import, edit and schedule a weekly edition (R4, R5, R6) Load the versioned issue bundle and render escaped, sanitized HTML and plain text. Pin subject, preheader, sender, reply address, links and the immutable hero at approval. Make test delivery and web/mobile previews available before scheduling. Keep the existing archive URL, Atom ID, edition date, archive release time and correction time separate in the adapter. Preserve the host site's preview and publication flags. Check the public feed content type and reader links. Schedule in local publication time with an explicit zone offset or validated UTC instant; ambiguous daylight-saving input requires an explicit offset. **Check** a sample edition with one editorial destination, one sponsor link and a hero renders both parts, passes accessible alt text checks, sends a labeled proof, and schedules from either channel. Reusing a stale approved plan after a content edit fails. Sending leaves the protected edition out of the host site's public archive until release. After the host deploys, verify the original canonical and Atom identity. Reimporting a source correction increments the edition revision without generating another send. ## 5. Deliver once where the provider outcome is known (R5, R7, R9) Store one plan/campaign receipt per accepted command, one frozen membership per campaign and reader, and a separate identity for each submission attempt. Index due work and maintain a suppression lookup at the final send boundary. Test against a clock advanced through rate limits, a feedback stream with delayed and reordered events, and a consumer killed both before and after it submits to SES. | Synthetic case | Required result | | --- | --- | | Two concurrent commits of the same plan; queue redelivers one item three times | One campaign and one accepted submission to the local mail sink for each eligible reader. | | Worker loses its SES response after provider acceptance | Attempt becomes unknown. A matching signed feedback event correlates it without another send. Without evidence, it remains unresolved or is permanently skipped. | | Complaint arrives after scheduling; later an older delivery event arrives | The reader stays suppressed across all subsequent campaigns. The previous delivery remains correctly attributed. | | Consent revoked after the send worker has handed the request to SES | Record that in-flight boundary in the audit. Block all following submissions for that reader. | | SNS callbacks repeat, arrive out of order, carry a different topic or have a bad signature | Count a valid event once. An untrusted callback leaves no consent or delivery mutation. | | CSV upload or result download is interrupted; same bytes are resumed from MCP | Per-chunk and final digest checks pass. The resumed import or export has one receipt. | **Check** the operator can pause and inspect a partially processed send, resolve an attempt using evidence, and resume eligible work through either interface. Check actual SES regional quota and a controlled proof before production. Use [delivery.md](delivery.md) for the failure boundaries and recovery plan. ## 6. Verify cost, migration and a working handoff (R3, R6, R7, R9) Exercise [migration.md](migration.md) using its eight input rows. Test the rollback as well as the forward switch. For a 10,000-recipient four-issue model, the baseline issue count is 40,000 SES messages before tests, confirmations, retries and new readers. The dashboard compares forecast and actual billable activity and surfaces monthly headroom. Compare the new bill against the publisher’s actual prior plan and hosting costs. The build must never require a beehiiv subscription for ordinary operation after legacy link obligations are resolved. **Check** a fresh self-hoster can run the documented installation, authorize a remote client, import a newsletter, rehearse a send, verify one-click unsubscribe, inspect an export and restore a backup in isolation. For the AudioTech adapter compare the signup response and archive/Atom fixtures to [the recorded evidence](evidence.md). Historical and QA events stay out of new-acquisition counts. ## Definition of done for an implementation The built project supplies `npm ci`, `npm test`, `npm run test:parity`, `npm run test:e2e` and `npm run build`. A clean checkout passes them with a local capture transport. A Cloudflare dry run through `npx cf deploy --dry-run` validates its bindings. Capture an MCP discovery transcript, assertion totals for every registered action, cross-channel duplicate-send results, a private migration reconciliation receipt and a restore drill. Use synthetic examples in shared reports. Production deployment, domain verification and real recipient sends are operator actions in the resulting installation.