diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8fdc5ae..3f16405 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,6 +33,30 @@ jobs: env: NEXT_TELEMETRY_DISABLED: "1" + e2e: + name: E2E (demo journey, desktop + phone) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v4 + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: pnpm + - run: pnpm install --frozen-lockfile + - run: pnpm exec playwright install --with-deps chromium + - run: pnpm e2e + env: + NEXT_TELEMETRY_DISABLED: "1" + - uses: actions/upload-artifact@v4 + if: failure() + with: + name: playwright-report + path: | + playwright-report + test-results + retention-days: 7 + contracts: name: Contracts (cargo check + test) runs-on: ubuntu-latest diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index f17a61b..fb0ff5c 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -242,7 +242,17 @@ On-chain vault = truth for plan and balance. DB = history and metadata. --- ## 8. Demo and dry-run -`pnpm demo`: PGlite + seed (vault with plan, deposits, 3 weeks of buys including `skipped_cost`), `DemoVaultClient` + demo quote/status providers behind `lib/core/adapters.ts`; "fast-forward 30 days"; real dry quotes when online, recorded fixtures offline. No secrets, no funds. +`pnpm demo` = migrate the local PGlite DB, then `next dev`. Zero secrets, no external DB (verified from a fresh clone, K7.5). + +- **Per-visitor demo:** `/demo` → `POST /api/demo/start` creates a fresh `isDemo` user (`saver-.demo`, vault `v.vaults.demo`) with a weekly $100 BTC plan, two credited deposits ($1,296.70) and four weeks of buys including one `skipped_cost`, then signs the visitor in with a demo session. Visitors never share data. +- **Same routes, demo adapters:** `servicesFor(session)` (lib/server/adapters.ts) swaps in `demoQuotes`, `demoStatus` (lib/oneclick/demo.ts) and `demoVaultClient` (lib/near/demo.ts) on the same DB. A session whose demo flag doesn't match the user is rejected. +- **Quotes:** dry quotes try live 1Click first (stand-in refund account `near`; dry quotes move nothing) and fall back to a fee model calibrated on real quotes ($10 BTC ≈ 15%, $100 ≈ 1.75%). Non-dry demo quotes get a `demo--` deposit address whose status advances on its own (~20 s per step → `SUCCESS`). +- **Vault:** plan in `demo_vaults.state` (migration 0002); balance derived from the user's rows (credited deposits − sent/success buys − withdrawn). Owner transactions from the UI go to `POST /api/demo/owner-tx` and follow the contract's rules (1-yocto rules aside): `set_plan` ranges, `resume` needs a plan, `withdraw` ≤ balance, `recover_token` refused. +- **Controls:** `fast-forward` (next 30 days of the plan, same cost check, one fee spike → skip) and `reset`. +- **Isolation:** real worker queries exclude demo users (`listUsersWithVault`, `listActiveFunding`, `listInFlightBuys`); demo tx hashes start with `demo-` and the UI shows "Example only" instead of explorer links. +- **Token list:** `GET /api/tokens` falls back to a small built-in list (`offline: true`) when 1Click is unreachable. + +Two production bugs found by this phase's browser run (both fixed): PGlite must be a Next `serverExternalPackages` entry (bundling breaks its WebAssembly path); the dev session secret lives on `globalThis` because each Next route is its own bundle. --- diff --git a/ARCHITECTURE_ESSENTIALS.md b/ARCHITECTURE_ESSENTIALS.md index 869eb30..d3011b0 100644 --- a/ARCHITECTURE_ESSENTIALS.md +++ b/ARCHITECTURE_ESSENTIALS.md @@ -85,7 +85,12 @@ On-chain vault = truth for plan + balance. - Every skip/refusal/failure writes `buys.note`; refusals and failures `log.alert` ## Demo & dry-run -`pnpm demo` = zero secrets, PGlite, seeded vault + history, fast-forward 30 days with one `skipped_cost`. Never moves funds. +`pnpm demo` = zero secrets, PGlite (verified from a fresh clone). `/demo` → per-visitor demo saver + demo session; Never moves funds. +- Demo sessions use `servicesFor(session)` → demo quotes (live dry first, calibrated model fallback), demo status (time-based), demo vault (`demo_vaults` + balance from rows) +- Owner actions in demo → `POST /api/demo/owner-tx`, same rules as the contract; `fast-forward` 30 days, `reset` +- Real worker queries **exclude demo users**; `demo-` hashes never link to explorers +- `pnpm e2e` = Playwright PRD §8 journey on demo mode, desktop + phone, in CI +- Keep `@electric-sql/pglite` in `serverExternalPackages`; keep the dev session secret on `globalThis` ## Never Add an admin withdraw path · use an unverified quote · show unconfirmed statuses · commit secrets · deploy, sign with real keys, send funds, post, push or submit without the human's explicit OK · finish a contribution without updating `ROADMAP.md` diff --git a/ROADMAP.md b/ROADMAP.md index 93aa2b5..80518e7 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -21,13 +21,13 @@ | 4. API routes | Nov 8–9 | 100% | ✅ done | | 5. Worker (scheduler) | Nov 9–10 | 100% | ✅ done | | 6. UI | Nov 9–11 | 100% | ✅ done | -| 7. Demo mode & dry-run | Nov 11 | 0% | not started | +| 7. Demo mode & dry-run | Nov 11 | 100% | ✅ done | | 8. Hardening & edge cases | Nov 11–12 | 0% | not started | | 9. Deploy & real run | Nov 12 | 0% | not started | | 10. README & public repo | Nov 12–13 | 14% | in progress | | 11. Launch: video, post, submission | Nov 13–14 | 0% | not started | | 12. After submission | Nov 14–25 | 0% | not started | -| **Overall (MVP)** | | **~55%** | | +| **Overall (MVP)** | | **~62%** | | Phase % = done tasks ÷ non-dropped tasks in that phase. Overall = average of all 14 rows (D + phases 0–12). (Earlier entries over-estimated the overall %; recalculated 2026-11-04.) @@ -148,12 +148,12 @@ Format: `- [task id] what blocks it · who can unblock · since date` ## Phase 7 — Demo mode & dry-run (Nov 11) -- [ ] **K7.1** [#63](https://github.com/MFrancis-dev/stack/issues/63) Demo adapters (`DemoVaultClient`, demo quote/status) -- [ ] **K7.2** [#64](https://github.com/MFrancis-dev/stack/issues/64) `seed-demo.ts`: vault with plan, deposits, 3 weeks of buys incl. `skipped_cost` -- [ ] **K7.3** [#65](https://github.com/MFrancis-dev/stack/issues/65) `pnpm demo`: PGlite + seed + banner; real dry quotes online, fixtures offline -- [ ] **K7.4** [#66](https://github.com/MFrancis-dev/stack/issues/66) "Fast-forward 30 days" -- [ ] **K7.5** [#67](https://github.com/MFrancis-dev/stack/issues/67) Fresh-clone check with no `.env` -- [ ] **K7.6** [#68](https://github.com/MFrancis-dev/stack/issues/68) Playwright journey = PRD §8, in CI +- [x] **K7.1** [#63](https://github.com/MFrancis-dev/stack/issues/63) Demo adapters (`DemoVaultClient`, demo quote/status) · 2026-11-05: demo quotes (live dry first, calibrated model fallback), time-based demo status, demo vault client (`demo_vaults`, balance from rows), owner actions without a wallet; routes pick adapters by session +- [x] **K7.2** [#64](https://github.com/MFrancis-dev/stack/issues/64) `seed-demo.ts`: vault with plan, deposits, 3 weeks of buys incl. `skipped_cost` · 2026-11-05: per-visitor demo saver: weekly $100 BTC plan, 2 deposits, 4 weeks of buys incl. a fee-spike skip +- [x] **K7.3** [#65](https://github.com/MFrancis-dev/stack/issues/65) `pnpm demo`: PGlite + seed + banner; real dry quotes online, fixtures offline · 2026-11-05: `pnpm demo` + `/demo` entry + banner; token list falls back offline; browser-reviewed at 1280/390 px +- [x] **K7.4** [#66](https://github.com/MFrancis-dev/stack/issues/66) "Fast-forward 30 days" · 2026-11-05: fast-forward 30 days (same cost check, one skip) + start over +- [x] **K7.5** [#67](https://github.com/MFrancis-dev/stack/issues/67) Fresh-clone check with no `.env` · 2026-11-05: fresh `git clone` → `pnpm install` → `pnpm demo` with no `.env`: demo page 200, start 201, vault/fast-forward/CSV all OK +- [x] **K7.6** [#68](https://github.com/MFrancis-dev/stack/issues/68) Playwright journey = PRD §8, in CI · 2026-11-05: Playwright PRD §8 journey on desktop + phone (4 passing), CI job with trace upload on failure ## Phase 8 — Hardening & edge cases (Nov 11–12) @@ -216,6 +216,7 @@ Format: `- [task id] what blocks it · who can unblock · since date` ## Update log One line per contribution, newest first: `YYYY-MM-DD · who/agent · what changed · tasks` +- 2026-11-05 · agent · Phase 7 demo mode: per-visitor demo, demo adapters, owner actions without a wallet, fast-forward/reset, worker isolation, offline token fallback, Playwright journey in CI; fixed PGlite bundling + per-route dev session secret found in the browser; 119 unit/route tests + 4 e2e · K7.1–K7.6 - 2026-11-05 · agent · Phase 6 UI reviewed in the browser (desktop + phone, redirect and signed-out states, no server errors); sign-in button width fix · K6.1–K6.8 - 2026-11-04 · agent · Phase 6 UI built on branch feat/ui (landing, sign-in, vault creation, fund, plan + cost preview, pause/resume, overview stack, history, settings); visual review pending · K6.1–K6.8 - 2026-11-04 · agent · Phase 5 worker: pollFunding, scheduleBuys (full safety chain, backoff, insert-before-execute), pollBuys, expireQuotes, keeper gas alert, no-overlap runner; `buys.note` migration; 100 TS tests · K5.1–K5.5 diff --git a/app/(dashboard)/layout.tsx b/app/(dashboard)/layout.tsx index eefb26a..2b4282e 100644 --- a/app/(dashboard)/layout.tsx +++ b/app/(dashboard)/layout.tsx @@ -13,6 +13,7 @@ import { Button } from "@/components/ui/Button"; import { Notice } from "@/components/ui/Notice"; import { PauseButton } from "@/components/plan/PauseButton"; import { CreateVault } from "@/components/vault/CreateVault"; +import { DemoBanner } from "@/components/vault/DemoBanner"; import { SignInButton } from "@/components/wallet/SignInButton"; import { useWallet } from "@/components/wallet/WalletProvider"; import { useVault } from "@/lib/client/hooks"; @@ -58,6 +59,7 @@ export default function DashboardLayout({ children }: { children: ReactNode }) { ) : null} + {v?.signedIn && v.demo ? : null}