: nply/foundationpkgs

commit b9df9c400e23fa14665ca30ac22548c1fb455aba
parent 3a60776ec82a8ca49dab139c922f6cd9136a2238
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Thu, 29 Oct 2026 20:54:28 +0530

Document package CI workflow and add verified artifact lookup
7 files changed, 363 insertions(+), 113 deletions(-)
M
.config/Jobfile
|
11
++++++++++-
M
AGENTS.md
|
81
+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
M
docs/ci.md
|
177
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------
M
docs/usage.md
|
69
+++++++++++++++++++++++++++++++++++++--------------------------------
M
scripts/fpkgs-ci.sh
|
47
+++++++++++++++++++++++++++++++++++++++++++++++
A
tests/artifact-status.sh
|
53
+++++++++++++++++++++++++++++++++++++++++++++++++++++
A
tests/staged-install.sh
|
38
++++++++++++++++++++++++++++++++++++++
diff --git a/.config/Jobfile b/.config/Jobfile
@@ -1,5 +1,14 @@
 project=foundationpkgs
-triggers="refs/heads/main: plan packages"
+triggers="refs/heads/main: checks plan packages"
+
+checks() {
+	for file in "$srcdir"/scripts/*.sh "$srcdir"/tests/*.sh; do
+		sh -n "$file" || return 1
+	done
+	for test in "$srcdir"/tests/*.sh; do
+		sh "$test" || return 1
+	done
+}
 
 plan() {
 	FPKGS_ROOT=$srcdir \
diff --git a/AGENTS.md b/AGENTS.md
@@ -1,38 +1,53 @@
 # Agent instructions
 
-Read `CONTEXT.md` before changing package names, recipe layout, artifact paths, or CI behaviour.
-
-## Source of truth
-
-- Write package definitions as POSIX-compatible `APKBUILD` files.
-- Treat `PKGBUILD` and `*.pacscript` as generated runtime intermediates unless the user explicitly asks to maintain legacy pacscripts.
-- Keep scripts under `scripts/` POSIX `sh`: no arrays, `[[ ... ]]`, process substitution, `pipefail`, `local`, or bash-only parameter expansion.
-
-## CI and packaging entry points
-
-- Build one recipe: `scripts/build.sh <pkgname-or-path>`.
-- Convert APKBUILD to pacscript at runtime: `scripts/apkbuild-to-pacscript.sh path/to/APKBUILD`.
-- Install through pacstall from APKBUILD source: `scripts/pacstall-install.sh <pkgname-or-path>`.
-- Plan or run repository package work: `scripts/fpkgs-ci.sh plan [REV]` and `scripts/fpkgs-ci.sh run [REV]`.
-- CI integration uses minci's runner with `.config/Jobfile`.
-
-See `docs/ci.md` for the deployed minci CI and `docs/ci-architecture.dot` for the CI graph.
-
-## Development rules
-
-- Prefer small, detachable scripts with environment-variable configuration over repo-specific hardcoding.
-- Preserve the build-key contract: changes that affect output must change the key; generated intermediates should not.
-- Publish artifacts atomically under `$FPKGS_DL_ROOT/<target>/<pkgname>/<pkgver>-r<pkgrel>/<buildkey>/`; expose their public URL with `$FPKGS_DL_BASE_URL`.
-- Keep minci reporting in minci; `scripts/fpkgs-ci.sh` should remain package build/publish glue.
-- When adding a dependency used by an APKBUILD, add an APKBUILD for it when it is not a system/base package.
-
-## Validation before commit
-
-Run:
+## Add or update a package
+
+1. Read [recipe conventions](docs/usage.md#adding-a-new-recipe) and one comparable
+   APKBUILD. These document the builder contract; inspect implementation scripts
+   when diagnosing a failure or changing the builder, not for routine recipes.
+2. Write a POSIX-compatible `APKBUILD` in the narrowest applicable bucket.
+   `PKGBUILD` and `*.pacscript` are generated intermediates. Add recipes for new
+   dependencies unless they are system/base tools.
+3. Run a targeted build: `scripts/build.sh <recipe-path>`. Explain if the current
+   host cannot build it. Run `sh -n <recipe-path>` and `git diff --check`.
+4. For an authorized CI deployment, commit and push the recipe to `main`, then
+   wait for the requested package artifact. A local commit does not start CI;
+   a successful push does not mean the binary is ready.
+
+## CI and binary availability
+
+- Gitolite on `cdg-1` starts minci after a push to `main`. The effective Jobfile
+  selects jobs. Minci prefers an explicit/external Jobfile, then
+  `origin/integ:.config/Jobfile`, then the checked-out `.config/Jobfile`.
+- **Current foundationpkgs configuration (2026-10-29):** only `main` exists;
+  its `.config/Jobfile` supplies `checks`, `plan`, and `packages`. There is no `integ` branch.
+  See [CI configuration](docs/ci.md#jobfile-selection) when this changes.
+- Check an exact pushed revision on the publication host (full commit SHA):
+
+  ```sh
+  ssh cdg-1 '/home/git/.local/cache/minci/foundationpkgs/scripts/fpkgs-ci.sh status PACKAGE x86_64-unknown-linux-gnu FULL_COMMIT_SHA'
+  ```
+
+  Exit `0`: matching manifest and SHA-256-verified artifact; `1`: not published;
+  `2`: matching publication is incomplete/corrupt. Other errors need diagnosis.
+  See [status and logs](docs/ci.md#check-a-binary) for pending/failed builds.
+- Dashboard: <https://ci.nply.org/cgi-bin/minci.cgi>.
+  Public artifacts: <https://nply.org/dl/foundationpkgs/>.
+- Deploy through [staged installation](docs/ci.md#install-a-ci-binary): verify,
+  extract into a temporary directory, then install selected files. Never extract
+  CI tarballs directly over `/`; their parent metadata belongs to the builder.
+
+## Builder or CI changes
+
+Read `CONTEXT.md` before changing recipe layout, naming, artifact paths, or CI
+behaviour. See [usage](docs/usage.md) for build, conversion, and pacstall commands.
+Keep scripts POSIX `sh`, preserve build-key inputs and atomic publication, and
+keep minci reporting separate from package build/publish logic.
+
+Validate script changes with:
 
 ```sh
-sh -n scripts/*.sh
-scripts/fpkgs-ci.sh plan HEAD | head
+for file in scripts/*.sh tests/*.sh; do sh -n "$file" || exit; done
+for test in tests/*.sh; do sh "$test" || exit; done
+scripts/fpkgs-ci.sh plan HEAD
 ```
-
-If touching a recipe, run at least one targeted build or explain why it cannot run on the current host.
diff --git a/docs/ci.md b/docs/ci.md
@@ -1,70 +1,153 @@
 # CI
 
-`minci.sh` is the runner for foundationpkgs.  The minci CGI at
-`https://ci.nply.org/cgi-bin/minci.cgi` receives authenticated job results and
-serves the dashboard.
+## Normal package workflow
 
-foundationpkgs keeps package logic in this repository.  `scripts/fpkgs-ci.sh`
-plans APKBUILD work, builds packages, and publishes artifacts.  It does not know
-about minci authentication; minci owns reporting.
+Create/update the APKBUILD, run a targeted local build, then commit and push when
+CI deployment is authorized. On `cdg-1`, the Gitolite post-receive hook starts
+`/usr/local/bin/minci.sh -f foundationpkgs` for pushes to `main`. Minci runs jobs
+selected by the effective Jobfile. Committing locally does not trigger CI.
 
-## Runner configuration
+The Jobfile runs `checks`, `plan`, and `packages`. `checks` runs shell syntax
+checks and the offline artifact-status/staged-install regression tests.
+Package builds are sequential;
+your package may be queued behind others. One package can be published even if
+other packages fail and the overall job fails. Verify the requested package,
+target, and revision rather than inferring availability from overall job state.
 
-On `cdg-1`, gitolite invokes `/usr/local/bin/minci.sh` for pushes to
-`refs/heads/main` of `nply/foundationpkgs`.
+## Jobfile selection
 
-The git user has `~git/.minci`:
+The deployed runner selects the first applicable source:
 
-```text
-apikey = ...
-apisecret = ...
-server = https://ci.nply.org/cgi-bin/minci.cgi
-branch = main
-autoup = no
-repo = /home/git/repositories/nply/foundationpkgs.git
-```
+1. The explicitly configured `jobfile`.
+2. An external per-repository Jobfile (default
+   `/etc/minci.d/foundationpkgs/Jobfile`).
+3. `origin/<integbranch>:.config/Jobfile`; `integbranch` defaults to `integ`.
+4. `.config/Jobfile` in the checked-out build branch.
 
-The repository supplies `.config/Jobfile`:
-
-```sh
-project=foundationpkgs
-triggers="refs/heads/main: packages"
-
-packages() {
-	FPKGS_ROOT=$srcdir \
-	FPKGS_WORK_ROOT=$workdir/fpkgs \
-		$srcdir/scripts/fpkgs-ci.sh run "$FETCH_HEAD"
-}
-```
+**Verified 2026-10-29:** foundationpkgs has only `main`; there is no `integ` branch
+and no explicit/external override. It therefore uses `main:.config/Jobfile`,
+whose trigger is `refs/heads/main: checks plan packages` in this revision. If an `integ` branch is added,
+its Jobfile takes precedence; the branch being built remains selected by the
+hook/runner and the jobs' triggers, not by the Jobfile's location.
 
-`minci.sh` clones/freshens the repository, sources the Jobfile, runs matching
-jobs, and reports each job to minci.
+To inspect the configured jobs, read the effective Jobfile, not minci's
+implementation. Check remote branches with `git ls-remote --heads origin`.
+The deployed runner configuration is `/home/git/.minci`; it contains secrets,
+so inspect only named non-secret settings when diagnosing selection problems.
 
-## Package helper
+## Check a binary
 
-Use the package helper directly when developing:
+The CI checkout includes a read-only lookup command:
 
 ```sh
-scripts/fpkgs-ci.sh plan [REV]
-scripts/fpkgs-ci.sh run [REV]
-scripts/fpkgs-ci.sh key APKBUILD TARGET [REV]
+rev=$(git rev-parse HEAD)  # the revision you actually pushed
+ssh cdg-1 "/home/git/.local/cache/minci/foundationpkgs/scripts/fpkgs-ci.sh status minimal-fxa-server x86_64-unknown-linux-gnu $rev"
 ```
 
-It publishes artifacts below:
+The command searches published manifests and verifies the main package archive's
+SHA-256. It returns manifest, archive, and log URLs plus the server archive path.
+It neither starts a build nor modifies artifacts.
+
+| Exit | Meaning | Next action |
+| --- | --- | --- |
+| 0 | Exact revision/target/package found; main artifact checksum verified | Use the returned artifact |
+| 1 | No matching publication yet | Check CI jobs/logs; this alone does not distinguish queued, running, failed, or never triggered |
+| 2 | Matching manifest exists but artifact/checksum is missing or invalid | Investigate publication; do not deploy it |
+
+Invocation/configuration errors are also nonzero and print a diagnostic.
+Use a full commit SHA for remote queries. A local branch name or short SHA is
+resolved against `FPKGS_ROOT` (default current directory). If several builds of
+the same revision exist, the command returns the first complete verified match;
+it is not a "latest version" selector. Split-package archives require their own
+checksum verification; status verifies the main package only.
+
+**Do not compute the build key on your laptop to locate a CI artifact.** Keys
+include builder paths, environment, and tool versions. Read published manifests
+using `status`; the existing `key` command is for build-key diagnostics.
+
+### Status and logs
+
+- Dashboard and recorded job results:
+  <https://ci.nply.org/cgi-bin/minci.cgi>.
+- Published package build log: the `log_url` returned by `status`.
+- Current runner output on `cdg-1`: `/tmp/minci.log`. This is shared/overwritten
+  by jobs; use the dashboard for recorded results.
+- Gitolite trigger diagnostics: `/home/git/minci-post-receive.log`.
+- Unpublished package build logs:
+  `/home/git/.local/cache/minci/work/foundationpkgs/fpkgs/build/<buildkey>/build.log`.
+  The runner output identifies the key when it starts a package or reports a
+  failure. Read that exact log rather than repeatedly scanning processes/files.
+
+### Publication locations
+
+Public base: <https://nply.org/dl/foundationpkgs/>.
+Server root: `/srv/http/dl.nply.org/foundationpkgs`.
+`dl.nply.org` is not the public endpoint until DNS/TLS are intentionally changed.
 
 ```text
-/srv/http/dl.nply.org/foundationpkgs/<target>/<pkg>/<ver-rrel>/<buildkey>/
+<root>/<target>/<pkgname>/<pkgver>-r<pkgrel>/<buildkey>/
+  manifest
+  build.log
+  <pkgname>-<pkgver>-r<pkgrel>.tar.gz
+  <pkgname>-<pkgver>-r<pkgrel>.tar.gz.sha256
+  ...optional split-package archives and digests...
 ```
 
-The public URL is currently:
+The manifest identifies `gitrev`, `target`, `pkgname`, version, build key, public
+URL, and timestamp. The `.sha256` file contains a **bare hexadecimal digest**,
+not a filename-bearing `sha256sum -c` record. Publication is atomic: artifacts,
+log, and manifest are staged together before the directory becomes visible.
 
-```text
-https://nply.org/dl/foundationpkgs/
+## Install a CI binary
+
+On `cdg-1`, use the verified `artifact_path` from `status`. Extract into staging,
+then install only the files required by the deployment. This example is for the
+minimal-fxa-server package; substitute the selected files for other packages.
+
+```sh
+# Run on cdg-1 as root, after status succeeds for the intended revision.
+set -eu
+archive=/srv/http/dl.nply.org/foundationpkgs/TARGET/PACKAGE/VERSION/BUILDKEY/PACKAGE-VERSION.tar.gz
+expected=$(awk 'NR == 1 {print $1}' "$archive.sha256")
+actual=$(sha256sum "$archive" | awk '{print $1}')
+[ "$actual" = "$expected" ]
+
+stage=$(mktemp -d)
+trap 'rm -rf "$stage"' EXIT HUP INT TERM
+before=$(stat -c '%a %u:%g %n' / /usr /usr/bin /usr/share)
+tar -xzf "$archive" -C "$stage"
+install -o root -g root -m 755 "$stage/usr/bin/minimal-fxa-server" /usr/bin/minimal-fxa-server
+install -o root -g root -m 755 "$stage/usr/bin/fxa-user" /usr/bin/fxa-user
+install -d -o root -g root -m 755 /usr/share/licenses/minimal-fxa-server
+install -o root -g root -m 644 "$stage/usr/share/licenses/minimal-fxa-server/LICENSE" /usr/share/licenses/minimal-fxa-server/LICENSE
+after=$(stat -c '%a %u:%g %n' / /usr /usr/bin /usr/share)
+[ "$before" = "$after" ]
 ```
 
-## Notes
+`sh tests/staged-install.sh` tests this pattern against a disposable target tree
+with deliberately different parent modes; it never writes to system directories.
+
+Never extract these CI tarballs directly over `/`: archives contain builder
+ownership and parent-directory modes, including `./` and `./usr/`. Restart the
+service and run its health/integration checks after installing. Back up runtime
+configuration/data before a deployment that changes them.
+
+## Developing CI/package tooling
+
+`minci.sh` owns CI execution/reporting; `scripts/fpkgs-ci.sh` owns package
+planning, building, publishing, and artifact lookup. Keep these responsibilities
+separate. The CI graph is in [ci-architecture.dot](ci-architecture.dot).
+
+Useful local commands:
+
+```sh
+scripts/fpkgs-ci.sh plan FULL_COMMIT_SHA
+scripts/fpkgs-ci.sh run FULL_COMMIT_SHA
+scripts/fpkgs-ci.sh key Unix/minimal-fxa-server/APKBUILD x86_64-unknown-linux-gnu FULL_COMMIT_SHA
+sh tests/artifact-status.sh
+sh tests/staged-install.sh
+```
 
-- APKBUILD is the source of truth.
-- Generated `PKGBUILD` and `*.pacscript` files are runtime intermediates.
-- Scripts and Jobfiles must stay POSIX `sh`.
-- `dl.nply.org` is not used until DNS/certificates are intentionally moved.
+`run` builds/publishes locally; it is not the normal way to trigger deployed CI.
+For test/mirror stores, configure `FPKGS_DL_ROOT` and `FPKGS_DL_BASE_URL`.
+See [usage](usage.md#cipackage-planner) for the remaining environment variables.
diff --git a/docs/usage.md b/docs/usage.md
@@ -30,8 +30,9 @@ On Windows, `Unix/` is skipped.
 Run before committing script or CI changes:
 
 ```sh
-sh -n scripts/*.sh
-scripts/fpkgs-ci.sh plan HEAD | head
+for file in scripts/*.sh tests/*.sh; do sh -n "$file" || exit; done
+for test in tests/*.sh; do sh "$test" || exit; done
+scripts/fpkgs-ci.sh plan HEAD
 ```
 
 If touching a recipe, run a targeted build when possible.

@@ -121,20 +122,10 @@ Public URL is based on `$FPKGS_DL_BASE_URL`.
 
 ## CI integration
 
-The CI runner is minci. The repo job file is:
-
-```text
-.config/Jobfile
-```
-
-Current jobs:
-
-```sh
-plan()     # runs scripts/fpkgs-ci.sh plan "$FETCH_HEAD"
-packages() # runs scripts/fpkgs-ci.sh run "$FETCH_HEAD"
-```
-
-Gitolite/minci invokes these on pushes to `refs/heads/main`.
+For push-triggered builds, effective Jobfile selection (including `integ`
+precedence), exact-revision binary lookup, logs, and staged installation, use
+[the CI workflow](ci.md). Routine packaging does not require reading runner or
+publisher implementation scripts.
 
 ## Convert/install through pacstall helpers
 

@@ -164,11 +155,30 @@ scripts/pacstall-install.sh <pkgname-or-path>
 scripts/build.sh <bucket>/<pkg>/APKBUILD
 ```
 
-8. Check CI plan:
+8. Validate syntax with `sh -n <recipe-path>` and run `git diff --check`.
+9. When CI deployment is authorized, commit and push, then follow
+   [binary lookup](ci.md#check-a-binary). `plan HEAD` reads the committed revision,
+   not an untracked or uncommitted recipe; use the targeted build for WIP.
 
-```sh
-scripts/fpkgs-ci.sh plan HEAD | grep '<pkg>'
-```
+### Builder contract
+
+`scripts/build.sh` sources the APKBUILD as POSIX shell, fetches/unpacks sources,
+applies listed `.patch` sources through `default_prepare`, then runs `build()`
+and `package()`. It does not call a recipe's `prepare()` hook. Build/package
+functions start in `$builddir`; it defaults to `$srcdir`. Prefer an explicit
+`builddir="$srcdir/$pkgname-$pkgver"` when the source archive has that root.
+`$pkgdir` is staging, not the live system; install only beneath it.
+
+The current builder **does not automatically run `check()`**, and it calls
+`build()` even when `options="!build"` is present. Invoke `check` explicitly from
+`build()` when needed; for prebuilt/data-only packages define `build() { :; }`.
+`options` metadata may be used by other tooling, but is not a phase-control
+interface for this builder.
+
+For Unix-wide recipes, use portable `mkdir -p` plus `install -m`; GNU
+`install -D` is not portable to the macOS host. Set executable/data modes
+explicitly. An example with checks and two native binaries is
+[`Unix/minimal-fxa-server/APKBUILD`](../Unix/minimal-fxa-server/APKBUILD).
 
 ## APKBUILD conventions in this repo
 

@@ -185,34 +195,29 @@ license="MIT"
 depends=""
 makedepends=""
 source="..."
-options="!check"
+builddir="$srcdir/$pkgname-$pkgver"
 
 build() {
     make
+    # Run upstream checks here if supplied; check() is not called automatically.
 }
 
 package() {
-    install -Dm755 example "$pkgdir/usr/bin/example"
+    mkdir -p "$pkgdir/usr/bin"
+    install -m755 example "$pkgdir/usr/bin/example"
 }
 ```
 
-Common options:
-
-```sh
-options="!check"        # no check phase
-options="!build"        # recipe has no build phase
-options="!check !build"
-```
-
 Split packages are supported with functions named after the suffix:
 
 ```sh
-subpackages="$pkgname-assets"
+subpackages="assets"
 
 assets() {
     pkgdesc="Public static assets"
     depends=""
-    install -Dm644 file "$subpkgdir/usr/share/example/file"
+    mkdir -p "$subpkgdir/usr/share/example"
+    install -m644 file "$subpkgdir/usr/share/example/file"
 }
 ```
 
diff --git a/scripts/fpkgs-ci.sh b/scripts/fpkgs-ci.sh
@@ -7,6 +7,7 @@
 #   fpkgs-ci.sh run [REV]                    # plan, build, publish for REV
 #   fpkgs-ci.sh plan [REV]                   # print planned work
 #   fpkgs-ci.sh key APKBUILD TARGET [REV]    # print build key
+#   fpkgs-ci.sh status PACKAGE TARGET REV   # find and verify published artifact
 #
 # Environment:
 #   FPKGS_ROOT       repository checkout (default: current directory)

@@ -40,6 +41,7 @@ fi
 usage() {
 	cat >&2 <<EOF
 usage: $SELF run [REV] | plan [REV] | key APKBUILD TARGET [REV]
+       $SELF status PACKAGE TARGET REV
 EOF
 	exit 1
 }

@@ -266,10 +268,55 @@ run() {
 	return "$status"
 }
 
+# Lookup published manifests rather than recomputing a build key: keys include
+# builder paths and environment, which may differ from the querying machine.
+artifact_status() {
+	s_pkg=$1
+	s_target=$2
+	s_rev=$3
+	for s_part in "$s_pkg" "$s_target"; do
+		case "$s_part" in
+		'' | . | .. | *[!a-zA-Z0-9_.+-]*) die "invalid package or target: $s_part" ;;
+		esac
+	done
+	case "$s_rev" in
+	*[!0-9a-f]* | '') s_rev=$(git -C "$FPKGS_ROOT" rev-parse --verify "$s_rev^{commit}") ;;
+	*) [ "${#s_rev}" -eq 40 ] || s_rev=$(git -C "$FPKGS_ROOT" rev-parse --verify "$s_rev^{commit}") ;;
+	esac
+	[ -d "$FPKGS_DL_ROOT" ] || die "publication root unavailable: $FPKGS_DL_ROOT"
+	s_seen=0
+	for s_manifest in "$FPKGS_DL_ROOT/$s_target/$s_pkg"/*/*/manifest; do
+		[ -f "$s_manifest" ] || continue
+		[ "$(pkg_field "$s_manifest" gitrev)" = "$s_rev" ] || continue
+		[ "$(pkg_field "$s_manifest" target)" = "$s_target" ] || continue
+		[ "$(pkg_field "$s_manifest" pkgname)" = "$s_pkg" ] || continue
+		s_seen=1
+		s_dir=${s_manifest%/manifest}
+		s_ver=$(pkg_field "$s_manifest" pkgver)
+		s_rel=$(pkg_field "$s_manifest" pkgrel)
+		s_archive=$s_dir/$s_pkg-$s_ver-r$s_rel.tar.gz
+		[ -f "$s_archive" ] && [ -f "$s_archive.sha256" ] || continue
+		s_expected=$(awk 'NR == 1 {print $1}' "$s_archive.sha256")
+		[ "$(sha256_file "$s_archive")" = "$s_expected" ] || continue
+		s_url=$FPKGS_DL_BASE_URL/$s_target/$s_pkg/$(basename "${s_dir%/*}")/$(basename "$s_dir")
+		printf 'status=published\ngitrev=%s\ntarget=%s\nchecksum=verified\n' "$s_rev" "$s_target"
+		printf 'manifest_url=%s/manifest\nartifact_url=%s/%s\nlog_url=%s/build.log\n' "$s_url" "$s_url" "$(basename "$s_archive")" "$s_url"
+		printf 'artifact_path=%s\n' "$s_archive"
+		return 0
+	done
+	if [ "$s_seen" -eq 1 ]; then
+		printf 'status=unusable\nreason=artifact missing or checksum mismatch\n'
+		return 2
+	fi
+	printf 'status=not-published\ngitrev=%s\ntarget=%s\n' "$s_rev" "$s_target"
+	return 1
+}
+
 cmd=${1:-}
 case "$cmd" in
 run) run "${2:-HEAD}" ;;
 plan) plan "${2:-HEAD}" ;;
 key) [ $# -ge 3 ] || usage; build_key "$2" "$3" "${4:-HEAD}" ;;
+status) [ $# -eq 4 ] || usage; artifact_status "$2" "$3" "$4" ;;
 *) usage ;;
 esac
diff --git a/tests/artifact-status.sh b/tests/artifact-status.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+# Offline regression check; never contacts CI or modifies the publication root.
+set -eu
+root=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
+work=$(mktemp -d)
+trap 'rm -rf "$work"' EXIT HUP INT TERM
+export FPKGS_DL_ROOT=$work/published
+export FPKGS_DL_BASE_URL=https://artifacts.invalid
+mkdir -p "$FPKGS_DL_ROOT"
+rev=1111111111111111111111111111111111111111
+target=x86_64-unknown-linux-gnu
+pkg=fixture
+out=$FPKGS_DL_ROOT/$target/$pkg/1.0-r0/test-key
+
+expect() {
+	want=$1
+	state=$2
+	shift 2
+	got=0
+	sh "$root/scripts/fpkgs-ci.sh" status "$@" >"$work/result" 2>"$work/error" || got=$?
+	[ "$got" -eq "$want" ] || { printf 'Expected exit %s, got %s\n' "$want" "$got"; exit 1; }
+	grep -q "^status=$state$" "$work/result"
+}
+
+expect 1 not-published "$pkg" "$target" "$rev"
+mkdir -p "$out"
+printf 'pkgname=fixture\npkgver=1.0\npkgrel=0\ntarget=%s\ngitrev=%s\n' "$target" "$rev" >"$out/manifest"
+expect 2 unusable "$pkg" "$target" "$rev"
+printf 'synthetic artifact\n' >"$out/fixture-1.0-r0.tar.gz"
+if command -v sha256sum >/dev/null 2>&1; then
+	sha256sum "$out/fixture-1.0-r0.tar.gz" | awk '{print $1}' >"$out/fixture-1.0-r0.tar.gz.sha256"
+else
+	shasum -a 256 "$out/fixture-1.0-r0.tar.gz" | awk '{print $1}' >"$out/fixture-1.0-r0.tar.gz.sha256"
+fi
+expect 0 published "$pkg" "$target" "$rev"
+grep -q '^checksum=verified$' "$work/result"
+grep -q '^manifest_url=https://artifacts.invalid/x86_64-unknown-linux-gnu/fixture/1.0-r0/test-key/manifest$' "$work/result"
+grep -q '^artifact_url=.*fixture-1.0-r0.tar.gz$' "$work/result"
+grep -q '^log_url=.*/build.log$' "$work/result"
+expect 1 not-published "$pkg" "$target" 2222222222222222222222222222222222222222
+expect 1 not-published "$pkg" aarch64-apple-darwin "$rev"
+printf 'corruption\n' >>"$out/fixture-1.0-r0.tar.gz"
+expect 2 unusable "$pkg" "$target" "$rev"
+if sh "$root/scripts/fpkgs-ci.sh" status ../fixture "$target" "$rev" >"$work/result" 2>&1; then
+	echo 'Traversal package unexpectedly accepted' >&2
+	exit 1
+fi
+export FPKGS_DL_ROOT=$work/absent
+if sh "$root/scripts/fpkgs-ci.sh" status "$pkg" "$target" "$rev" >"$work/result" 2>&1; then
+	echo 'Unavailable publication root unexpectedly accepted' >&2
+	exit 1
+fi
+printf 'PASS: published, absent, incomplete, corrupt, wrong revision/target, invalid path, unavailable root\n'
diff --git a/tests/staged-install.sh b/tests/staged-install.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# Exercise the documented build + staged installation without touching /usr.
+set -eu
+root=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
+work=$(mktemp -d)
+trap 'rm -rf "$work"' EXIT HUP INT TERM
+mkdir -p "$work/recipe" "$work/target/usr/bin" "$work/stage"
+cat >"$work/recipe/APKBUILD" <<'RECIPE'
+pkgname=staging-fixture
+pkgver=1
+pkgrel=0
+arch=all
+source=""
+build() {
+	printf '#!/bin/sh\nprintf "staged fixture works\\n"\n' >example
+}
+package() {
+	mkdir -p "$pkgdir/usr/bin"
+	install -m755 example "$pkgdir/usr/bin/example"
+	# Simulate builder metadata that must never overwrite system parents.
+	chmod 0750 "$pkgdir" "$pkgdir/usr" "$pkgdir/usr/bin"
+}
+RECIPE
+sh "$root/scripts/build.sh" -o "$work/dist" -s "$work/sysroot" "$work/recipe/APKBUILD" >"$work/build.log" 2>&1
+archive=$(find "$work/dist" -name '*.tar.gz' -type f)
+[ -f "$archive" ]
+chmod 0700 "$work/target"
+chmod 0751 "$work/target/usr"
+chmod 0711 "$work/target/usr/bin"
+metadata() {
+	ls -ldn "$work/target" "$work/target/usr" "$work/target/usr/bin" | awk '{print $1, $3, $4, $NF}'
+}
+before=$(metadata)
+tar -xzf "$archive" -C "$work/stage"
+install -m755 "$work/stage/usr/bin/example" "$work/target/usr/bin/example"
+[ "$("$work/target/usr/bin/example")" = 'staged fixture works' ]
+[ "$before" = "$(metadata)" ]
+echo 'PASS: targeted build and staged installation preserve existing parent ownership/modes'