diff --git a/bin/lib/fingerprint.mjs b/bin/lib/fingerprint.mjs index 17dbaf8f..53c0c708 100644 --- a/bin/lib/fingerprint.mjs +++ b/bin/lib/fingerprint.mjs @@ -2,8 +2,8 @@ // affects the bundle has changed, so a re-launch goes (almost) straight to the native // build. → user ask: "if the web build didn't change, bypass steps, launch faster". // -// The fingerprint is a hash of every app file's path + size + mtime (a superset of the -// SPA inputs). Over-inclusive on purpose: an unrelated edit just triggers a rebuild +// The fingerprint is a hash of every app file's path + content (a superset of the SPA +// inputs). Over-inclusive on purpose: an unrelated edit just triggers a rebuild // (safe), whereas a missed edit would launch stale code (never acceptable). `--force` // bypasses it. This module only COMPUTES the hashes; what was last seen is remembered in // the `build` section of `.adaptv/state.json` (see `state.mjs`). @@ -41,17 +41,15 @@ const SKIP_DIRS = new Set([ const SKIP_FILES = new Set(["capacitor.config.json", ".DS_Store"]) /** - * A hash of the app's source tree — path + size + **mtime** of every non-skipped file. + * A hash of the app's source tree — path + **content** of every non-skipped file. * - * Deliberately mtime-based, NOT content-based like `nativeFingerprint()`, and the two are - * intentionally different for a reason: the native tree is re-stamped by `generateAssets` - * every run (byte-identical files, fresh mtimes) so mtime there false-positives forever — - * hence content. The web SOURCE tree has no such re-stamping: a file's mtime only moves - * when it's genuinely edited, so mtime is both correct AND cheap here. Measured 2026-09-02 - * on the playground app (182 files / 3.5 MB): 1.7 ms median per walk, against ~4× that for - * content over the same files — a cost that grows with the asset tree, for zero correctness - * gain. So this stays mtime; the divergence is by design, not an oversight. Over-inclusive - * either way: a false rebuild is free, a missed edit shipping stale code is not. + * Content, like `nativeFingerprint()`, for the same reason: a step that rewrites a file with + * identical bytes gives it a fresh mtime, and an mtime hash then throws the cache away (that is + * exactly how the native one never hit once). Content is the honest question — what the tree + * CONTAINS, not when it was last touched. The cost is not material: measured 2026-09-02 on the + * playground app (422 files / 11.0 MB), 11.3 ms by content against 3.0 ms by mtime, in a 29 s + * build. Over-inclusive either way: a false rebuild is free, a missed edit shipping stale code + * is not. */ export function fingerprint(appRoot) { const h = createHash("sha1") @@ -67,11 +65,12 @@ export function fingerprint(appRoot) { if (e.isDirectory()) { if (!SKIP_DIRS.has(e.name)) walk(path.join(dir, e.name)) } else if (e.isFile() && !SKIP_FILES.has(e.name)) { + const full = path.join(dir, e.name) try { - const s = statSync(path.join(dir, e.name)) - h.update( - `${path.relative(appRoot, path.join(dir, e.name))}:${s.size}:${Math.round(s.mtimeMs)}\n`, - ) + const body = readFileSync(full) + h.update(`${path.relative(appRoot, full)}:`) + h.update(body) + h.update("\n") } catch {} } } @@ -96,7 +95,7 @@ export function fingerprint(appRoot) { * import graph would cost an esbuild bundle on every poll to catch changes that mostly are * not native ones. * - * mtime + size for the art, like `fingerprint()` and for the same reason: nothing re-stamps + * mtime + size for the art, like `cliSourceFingerprint()`: nothing re-stamps * the dev's SOURCE icons, so an mtime only moves when they genuinely edit one. (The native * tree needs content hashing precisely because `generateAssets` rewrites it every run.) */ @@ -161,7 +160,7 @@ const NATIVE_SKIP_FILES = new Set([".DS_Store", "local.properties"]) * dependencies (adding/removing a native plugin), and the native project's own sources * (Info.plist, AndroidManifest, gradle, pbxproj, generated icons/splash). * - * Hashes CONTENT, not size+mtime like `fingerprint()` does. That difference is load- + * Hashes CONTENT, not size+mtime, as `fingerprint()` now does too. That is load- * bearing: `generateAssets` re-stamps icons, colours and the launch storyboard into the * native project on every single run, writing byte-identical files with fresh mtimes. An * mtime-based hash therefore changed every run and the cache never hit once (measured). @@ -235,7 +234,7 @@ export function nativeFingerprint(appRoot, platform) { * was restarted. `dev` polls this so it can SAY "restart to apply" instead of leaving the dev to * wonder why their framework edit did nothing. * - * mtime + size, like `fingerprint()`: nothing re-stamps these sources, so an mtime only moves on a + * mtime + size, like the icon art in `appConfigFingerprint()`: nothing re-stamps these sources, so an mtime only moves on a * genuine edit. `.test.mjs` is skipped — a test edit changes no runtime behaviour, so it must not * nag for a restart. Zero false notices for a real (installed) consumer; the whole signal for a * framework dev. diff --git a/bin/lib/fingerprint.test.mjs b/bin/lib/fingerprint.test.mjs index eeba9174..0d48b6b4 100644 --- a/bin/lib/fingerprint.test.mjs +++ b/bin/lib/fingerprint.test.mjs @@ -190,4 +190,14 @@ describe("fingerprint — did anything the web bundle is built FROM change?", () utimesSync(file, t, t) expect(fingerprint(root)).not.toBe(before) }) + + it("holds when a step rewrites a file with identical bytes and a fresh mtime — what it contains, not when it was touched", () => { + const root = tree() + const before = fingerprint(root) + const file = path.join(root, "src", "app.tsx") + writeFileSync(file, "export const a = 1") + const t = Date.now() / 1000 + 5 + utimesSync(file, t, t) + expect(fingerprint(root)).toBe(before) + }) }) diff --git a/docs/roadmap/README.md b/docs/roadmap/README.md index 53d7f6d5..0b934563 100644 --- a/docs/roadmap/README.md +++ b/docs/roadmap/README.md @@ -34,7 +34,7 @@ against shipped code are not roadmap items either — those live as `B` entries | 2 | **`dist` cutover** | [`dist-cutover.md`](dist-cutover.md) | small | `exports` and `files` point at `dist/`. An app installed from the `pnpm pack` tarball runs (`examples/basic`). The `create-adaptv` template carries the patches. Left: whether the two `link:` shims stay. | | 4 | **Capability gaps** | [`capability-gaps.md`](capability-gaps.md) | large | Tier 2 (dialogs, notifications, camera, biometrics, deep links; filesystem shipped 2026-09-02) is the best-formed roadmap material in the repo. Tier 3 is the long tail. | | 5 | **Component gaps** | [`component-gaps.md`](component-gaps.md) | large | Ranked against Ionic and Expo. `Modal` and `Tabs` are the named holes; `Text`, `Collapsible`, `Slider`, `Select`, `FieldGroup`, `Icon`, `RadioGroup`, an inline `Spinner`, `ProgressBar`, `Skeleton` and `Divider` are **done**. | -| 6 | **Dev-loop debt** | [`dev-loop-debt.md`](dev-loop-debt.md) | medium | Four named items. Five of the original nine are discharged and were removed. | +| 6 | **Dev-loop debt** | [`dev-loop-debt.md`](dev-loop-debt.md) | medium | Three named items. Six of the original nine are discharged and were removed. | | 7 | **Owed device verification** | [`owed-device-verification.md`](owed-device-verification.md) | small each | Eight checks no unit test can close. Cheap individually; they need hardware. | | 8 | **Native keyboard curve** | [`native-keyboard-curve.md`](native-keyboard-curve.md) | small–medium | Agreed after PR #47, unbuilt. `src/capabilities/keyboard.ts` still emits height only; the OS duration/curve is thrown away. Additive, low risk. | | 9 | **Open questions** | [`open-questions.md`](open-questions.md) | — | The questions under "Still open", plus one the register never carried; O22 (overlays) was answered 2026-09-09, O24 (Tailwind) 2026-10-05. Not work — decisions owed. | diff --git a/docs/roadmap/dev-loop-debt.md b/docs/roadmap/dev-loop-debt.md index 5e047bce..a444b6c5 100644 --- a/docs/roadmap/dev-loop-debt.md +++ b/docs/roadmap/dev-loop-debt.md @@ -1,13 +1,14 @@ # adaptv — dev-loop debt -> 📐 **Four named items of debt against machinery that already works.** Was +> 📐 **Three named items of debt against machinery that already works.** Was > `DEV-LOOP-REVIEW.md`; renamed and moved here 2026-08-30 because every remaining item is work not yet > done. > -> **Five of the original nine are discharged and have been removed:** +> **Six of the original nine are discharged and have been removed:** > > | Was | Discharged by | > |---|---| +> | **§B** — "two fingerprints, two different hashing strategies" | `bin/lib/fingerprint.mjs` `fingerprint()` now hashes each file's path + content, like `nativeFingerprint()`, so a step that rewrites a file with identical bytes no longer throws the web build cache away. Measured before the switch (2026-09-02, playground app, 422 files / 11.0 MB): 11.3 ms by content against 3.0 ms by mtime, in a 29 s build. The `.output` hole that measurement turned up was fixed with it earlier (`SKIP_DIRS`). Pinned by `bin/lib/fingerprint.test.mjs` "holds when a step rewrites a file with identical bytes and a fresh mtime". | > | **§C** — "the `adb reverse` keeper treats a symptom; add the instance lock instead" | `bin/lib/lock.mjs` **is** that instance lock. A second `dev` now fails fast naming the pid and url, and `preview`/`build` refuse while a `dev` run owns the config. | > | **§D** — "`relaunchAndroidApp` still touches every connected device" | `bin/lib/native.mjs` `relaunchAndroidApp` resolves the run's serial through `androidSerialForTarget` and force-stops / relaunches on that ONE serial; the all-devices sweep is reached only when the target cannot be resolved. Pinned by `bin/lib/native-relaunch.test.mjs` — "force-stops and relaunches on the ONE serial the AVD name resolves to" and "falls back to every connected device only when the target is unresolvable". | > | **§F** — "`OFFLINE_PAGE` is duplicated with a *keep in sync* comment" | Still duplicated, but the duplication is now **mechanised** by `src/shell/offline-page-name.test.ts`, so drift fails the suite. The concern, not the duplication, was the item. | @@ -86,38 +87,6 @@ with the app foreground), then decide. --- -## B. Two fingerprints, two different hashing strategies - -**Today.** `fingerprint()` hashes the whole app tree by **path + size + mtime**. -`nativeFingerprint()` hashes a curated native input set by **content**. - -**Why.** The native one *had* to be content-based: `generateAssets` re-stamps -byte-identical icons and theme files on every run, so an mtime hash never matched -and the cache never hit once (measured). - -**What to do.** Pick one strategy. The web fingerprint has the same hazard in -principle — any step that rewrites an identical file invalidates it — and the two -being different is a trap for whoever reads this next. Content hashing is the -honest question ("what does it contain"), and at native scale it costs nothing. - -**Measured (2026-09-02, M3 Max, warm cache, median of 5×30).** Over `fingerprint()`'s -exact walk of the playground app — 422 files / 11.0 MB — mtime costs **3.0 ms** and a -sha1 content hash costs **11.3 ms**: 3.8×, ~8 ms absolute, called twice per -`build ios` (both times with the same answer) in a build that takes 29 s. The native -set is 0.93 ms (ios, 28 files) / 1.81 ms (android, 73 files) by content — the -"22.9 ms" figure the code once cited does not reproduce. So the cost is not material -either way; pick on honesty, not speed. - -**The larger finding the measurement turned up.** 242 of those 422 files (57%) and -8.1 of the 11.0 MB (74%) were `.output/` — the SSR lineage's build output, which -`SKIP_DIRS` did not list (it had `dist`, not `.output`). Reproduced twice: -`build ios` 34.5 s → `build web` 4.1 s (rewrites `.output/`) → `build ios` **33.9 s** -full rebuild with nothing under `src/` changed → `build ios` 4.2 s. Fixed in the -same PR as this note by adding `.output` to the skip list, with a test — L14 says -the two lineages never cross, and the fingerprint was the one place they did. - ---- - ## E. `warmDevServer`'s heuristic could become a real signal Waiting for "two reads >500 bytes, then 1s of quiet" is a proxy for "Vite finished @@ -169,6 +138,10 @@ is the transport, and the only document that travels over it is a static page ad unbuilt. Note it interacts with the run cache: a different appId is a different installed app, so the cache key needs it, and alternating modes rebuilds unless outputs are cached per-mode. +- **A framework-only change reports `✓ web build · cached`** (`docs/DEVELOPMENT.md` names it "a + real bug"). Neither fingerprint hashes framework source: `fingerprint()` skips `node_modules`, and + `nativeFingerprint()` hashes the config, declared deps and the native project. Unifying their + hashing strategy (§B, discharged) did not change that; `--force` is the workaround. --- @@ -177,12 +150,8 @@ is the transport, and the only document that travels over it is a static page ad 1. **A** (Vite's ws events) — measured 2026-09-02 (§A): the event is now subscribed and the no-token fallback is gone; the proxy stays until a physical device shows whether the socket dies with or without a `close`. Nothing further deletes without that. -2. **B** (unify fingerprints) — measured (§B, 2026-09-02): ~8 ms either way, so the pick is on - honesty, not speed; the `.output` hole the measurement turned up is already fixed. ⚠️ **This is the same bug - `docs/DEVELOPMENT.md` calls out**: a framework-only change reports `✓ web build · cached`, which - that doc names "a real bug". Two fingerprints with two hashing strategies is the cause. -3. **E** — only if already in the file. **G** is discharged: its claim is a test now. -4. The **Known-unfixed** list — none of it is from this work, and none of it has an owner yet. +2. **E** — only if already in the file. **G** is discharged: its claim is a test now. +3. The **Known-unfixed** list — none of it is from this work, and none of it has an owner yet. **A** is now the one item that changes how much code exists (**C**, its partner, has shipped as `bin/lib/lock.mjs`, and **D**, **H** and **I** were already in the code — what they lacked was a