diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 88f70826..fadfbd41 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -127,7 +127,7 @@ beans/ .github/workflows/ # release.yml: manual signed Beans releases; test.yml: full PR/manual test matrix; docs.yml: PR/manual doc check; catalog.yml: PR/manual catalog/index check ``` -`pnpm run android` rebuilds the Rust core for Android, then builds and runs the Expo dev client on the Android emulator. `cd mobile && pnpm run core` rebuilds the Rust core for both phone platforms; `pnpm run mobile:dev` is the iOS development loop described below. +See [Phone development](docs/architecture/phone-app.md#development-loop) for phone rebuild commands. `pnpm run dev` runs the macOS Beans Dev loop; `pnpm run build` produces the Beans release bundle. See [macOS development and builds](docs/architecture/macos-app.md#development-and-builds) for rebuild, launch and SDK-stamping mechanisms. `pnpm run relay` runs a local relay. The [phone development loop](docs/architecture/phone-app.md#development-loop) fingerprints native inputs, rebuilds stale pieces and leaves production Beans processes alone. diff --git a/Cargo.lock b/Cargo.lock index 8aedd77b..5df2b781 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6298,9 +6298,9 @@ dependencies = [ [[package]] name = "rustls-platform-verifier" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d1e2536ce4f35f4846aa13bff16bd0ff40157cdb14cc056c7b14ba41233ba0" +checksum = "1167586491e2b18b8bfbb293e8180ec17c201c4f076d7cb3070ca964e7598f98" dependencies = [ "core-foundation 0.10.1", "core-foundation-sys", @@ -6319,9 +6319,9 @@ dependencies = [ [[package]] name = "rustls-platform-verifier-android" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f87165f0995f63a9fbeea62b64d10b4d9d8e78ec6d7d51fb2125fda7bb36788f" +checksum = "eec689c0bc40ff2458a5977b6619cb718087084a18e02a131c599b62d05e1a5f" [[package]] name = "rustls-webpki" diff --git a/docs/architecture/phone-app.md b/docs/architecture/phone-app.md index 845e91bf..a7d349c9 100644 --- a/docs/architecture/phone-app.md +++ b/docs/architecture/phone-app.md @@ -56,4 +56,6 @@ The production app icon uses the coral Beans mark. Editable SVG masters in `desi ## Development loop +`pnpm run android` rebuilds the Rust core for Android, then builds and runs the Expo dev client on the Android emulator. `cd mobile && pnpm run core` rebuilds the Rust core for both phone platforms; `pnpm run mobile:dev` is the iOS development loop described here. + `pnpm run mobile:dev` (`scripts/mobile.ts`) is the Beans Dev phone loop on the iOS Simulator, or on `--device `: it fingerprints the crates the phone links, the prebuild inputs (Expo config, assets, `package.json`, plugins, targets), the pod inputs with the checkout's path, and the native module sources (stamps in `mobile/.expo/dev-stamps.json`), rebuilds what is stale (`pnpm run core ios`, a clean `expo prebuild`, `pod install`, `expo run:ios`), starts Metro, and opens the dev client on it. A Rust save while it runs rebuilds the core and installs the app again. The Mac and phone loops leave production Beans processes alone, so all builds run side by side. diff --git a/docs/architecture/website.md b/docs/architecture/website.md index a0d39bdd..63b33e4d 100644 --- a/docs/architecture/website.md +++ b/docs/architecture/website.md @@ -8,13 +8,9 @@ The Windows download resolves both the staged `Beans Setup .exe` name a The Vercel project `hr-teconologia/beans` connects to `bloodf/beans` on GitHub. Pushes to `main` target production at `usebeans.app`; other branches create previews. Its root directory is `web`, with source files outside that directory enabled. Installation runs `cd .. && pnpm install --frozen-lockfile`, and the build runs `pnpm run build`. -The project's Ignored Build Step compares `VERCEL_GIT_PREVIOUS_SHA` with `HEAD` for `web/`, `desktop/`, the root `package.json` and `bun.lock`, `crates/models/catalog.json`, `crates/cli/marketplace/index.json`, and `.vercelignore`. These paths cover the site, embedded desktop demo, workspace dependencies and served catalogs. An unchanged diff skips the build. A missing previous deployment SHA or unavailable Git history allows the build. Vercel's automatic affected-project detection is disabled so it cannot skip changes to the served catalogs outside the JavaScript workspaces. +The Ignored Build Step in `web/vercel.json` runs `sh ./vercel-ignore.sh` within the 256-character configuration limit. The script requires `VERCEL_GIT_PREVIOUS_SHA` to be a full 40- or 64-character hexadecimal ID of an available Git commit before comparing it with `HEAD` for the site, embedded desktop demo, root package and pnpm lock/workspace settings, Blobatar package, served catalogs and `.vercelignore`. Only a successful unchanged diff skips the build. Missing previous deployment SHA or unavailable Git history returns exit 1 to run the build instead of failing deployment with Git's error status. Vercel's automatic affected-project detection is disabled so it cannot skip changes to served catalogs outside the JavaScript workspaces. -`.vercelignore` retains Git metadata so the Ignored Build Step can compare commits. This filter is stored in the Vercel project settings and runs from `web`: - -```sh -test -n "$VERCEL_GIT_PREVIOUS_SHA" && git diff --quiet "$VERCEL_GIT_PREVIOUS_SHA" HEAD -- . ../desktop ../package.json ../bun.lock ../crates/models/catalog.json ../crates/cli/marketplace/index.json ../.vercelignore -``` +`.vercelignore` retains Git metadata for this comparison. The repository configuration overrides the project's Ignored Build Step and runs from `web`. `python3 scripts/test_vercel_ignore.py` verifies unchanged, changed, empty and unavailable previous revisions using real temporary Git commits. ## Landing-page motion diff --git a/scripts/test_vercel_ignore.py b/scripts/test_vercel_ignore.py new file mode 100644 index 00000000..eaee479d --- /dev/null +++ b/scripts/test_vercel_ignore.py @@ -0,0 +1,87 @@ +import json +import os +from pathlib import Path +import subprocess +import tempfile +import unittest + + +COMMAND = json.loads((Path(__file__).resolve().parents[1] / "web/vercel.json").read_text())["ignoreCommand"] + + +class IgnoreBuildTest(unittest.TestCase): + def test_sha256_commit(self): + with tempfile.TemporaryDirectory(prefix="beans-vercel-sha256-") as directory: + root = Path(directory) + web = root / "web" + web.mkdir() + (web / "vercel-ignore.sh").write_bytes((Path(__file__).resolve().parents[1] / "web/vercel-ignore.sh").read_bytes()) + subprocess.run(["git", "init", "-q", "--object-format=sha256"], cwd=root, check=True, capture_output=True) + subprocess.run(["git", "add", "."], cwd=root, check=True, capture_output=True) + subprocess.run(["git", "-c", "user.name=Beans test", "-c", "user.email=test@example.invalid", "commit", "-qm", "initial"], cwd=root, check=True, capture_output=True) + previous = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=root, text=True).strip() + self.assertEqual(len(previous), 64) + env = {**os.environ, "VERCEL_GIT_PREVIOUS_SHA": previous} + self.assertEqual(subprocess.run(["sh", "-c", COMMAND], cwd=web, env=env, capture_output=True).returncode, 0) + (web / "page.txt").write_text("changed") + subprocess.run(["git", "add", "."], cwd=root, check=True, capture_output=True) + subprocess.run(["git", "-c", "user.name=Beans test", "-c", "user.email=test@example.invalid", "commit", "-qm", "changed"], cwd=root, check=True, capture_output=True) + self.assertEqual(subprocess.run(["sh", "-c", COMMAND], cwd=web, env=env, capture_output=True).returncode, 1) + + def test_real_git_inputs(self): + with tempfile.TemporaryDirectory(prefix="beans-vercel-ignore-") as directory: + root = Path(directory) + web = root / "web" + web.mkdir() + self.assertLessEqual(len(COMMAND), 256) + (web / "vercel-ignore.sh").write_bytes((Path(__file__).resolve().parents[1] / "web/vercel-ignore.sh").read_bytes()) + + def git(*args): + return subprocess.run(["git", *args], cwd=root, check=True, capture_output=True, text=True).stdout.strip() + + def ignored(previous): + env = {**os.environ, "VERCEL_GIT_PREVIOUS_SHA": previous} + return subprocess.run(["sh", "-c", COMMAND], cwd=web, env=env, capture_output=True).returncode + + git("init", "-q") + git("config", "user.name", "Beans test") + git("config", "user.email", "test@example.invalid") + (web / "page.txt").write_text("initial") + (root / "pnpm-lock.yaml").write_text("initial") + git("add", ".") + git("commit", "-qm", "initial") + initial = git("rev-parse", "HEAD") + self.assertEqual(ignored(initial), 0) + self.assertEqual(ignored(""), 1) + self.assertEqual(ignored("f" * 40), 1) + for invalid in ("--cached", "--quiet", "HEAD", "refs/heads/main", "g" * 40, "a" * 39, "a" * 41, "a" * 63, "a" * 65, "f" * 64): + with self.subTest(previous=invalid): + self.assertEqual(ignored(invalid), 1) + missing_env = dict(os.environ) + missing_env.pop("VERCEL_GIT_PREVIOUS_SHA", None) + self.assertEqual(subprocess.run(["sh", "-c", COMMAND], cwd=web, env=missing_env, capture_output=True).returncode, 1) + blob = git("rev-parse", "HEAD:web/page.txt") + tree = git("rev-parse", "HEAD^{tree}") + self.assertEqual(ignored(blob), 1) + self.assertEqual(ignored(tree), 1) + (root / ".git").rename(root / "git-unavailable") + try: + self.assertEqual(ignored(initial), 1) + finally: + (root / "git-unavailable").rename(root / ".git") + (web / "page.txt").write_text("changed") + git("commit", "-qam", "website change") + self.assertEqual(ignored(initial), 1) + website = git("rev-parse", "HEAD") + (root / "pnpm-lock.yaml").write_text("changed") + git("commit", "-qam", "dependency change") + self.assertEqual(ignored(website), 1) + dependency = git("rev-parse", "HEAD") + (root / "Cargo.lock").write_text("Rust-only change") + git("add", ".") + git("commit", "-qm", "unrelated Rust change") + self.assertEqual(ignored(dependency), 0) + + +if __name__ == "__main__": + unittest.main() diff --git a/web/vercel-ignore.sh b/web/vercel-ignore.sh new file mode 100644 index 00000000..ba0baf20 --- /dev/null +++ b/web/vercel-ignore.sh @@ -0,0 +1,10 @@ +#!/bin/sh +case "$VERCEL_GIT_PREVIOUS_SHA" in + ''|*[!0123456789abcdefABCDEF]*) exit 1 ;; +esac +case "${#VERCEL_GIT_PREVIOUS_SHA}" in + 40|64) ;; + *) exit 1 ;; +esac +test "$(git cat-file -t "$VERCEL_GIT_PREVIOUS_SHA")" = commit || exit 1 +git diff --quiet "$VERCEL_GIT_PREVIOUS_SHA" HEAD -- . ../desktop ../package.json ../pnpm-lock.yaml ../pnpm-workspace.yaml ../.npmrc ../packages/beans-blobatar ../crates/models/catalog.json ../crates/cli/marketplace/index.json ../.vercelignore; result=$?; test "$result" -eq 0 diff --git a/web/vercel.json b/web/vercel.json index cecc1936..4a90457a 100644 --- a/web/vercel.json +++ b/web/vercel.json @@ -21,5 +21,6 @@ ] } ], - "installCommand": "pnpm install --frozen-lockfile" + "installCommand": "pnpm install --frozen-lockfile", + "ignoreCommand": "sh ./vercel-ignore.sh" }