Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2ba7f01bf | ||
|
|
126831e96f | ||
|
|
b0977d4073 | ||
|
|
045e43f0f8 | ||
|
|
5089856c0d | ||
|
|
0696ce31e7 | ||
|
|
dca0b5823b | ||
|
|
615d3dd881 | ||
|
|
a48f0fdf5b | ||
|
|
e87bd67c1f | ||
|
|
5842be70cc | ||
|
|
7291b46271 | ||
|
|
d15688ee99 | ||
|
|
e1a99a7291 |
No files matched your search
@@ -20,7 +20,7 @@
|
|||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "\"${CLAUDE_PROJECT_DIR}/.claude/hooks/kyberforge/.apm/hooks/check-apm-current.sh\"",
|
"command": "\"${CLAUDE_PROJECT_DIR}/.claude/hooks/kyberforge/.apm/hooks/check-apm-current.sh\"",
|
||||||
"timeout": 380
|
"timeout": 400
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"_apm_source": "Mortis/Holocron/plugins/kyberforge"
|
"_apm_source": "Mortis/Holocron/plugins/kyberforge"
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
{
|
{
|
||||||
"type": "command",
|
"type": "command",
|
||||||
"command": "\"${CLAUDE_PROJECT_DIR}/.claude/hooks/kyberforge/.apm/hooks/check-apm-current.sh\"",
|
"command": "\"${CLAUDE_PROJECT_DIR}/.claude/hooks/kyberforge/.apm/hooks/check-apm-current.sh\"",
|
||||||
"timeout": 380
|
"timeout": 400
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,3 +66,7 @@ build/
|
|||||||
# apm copies the whole hooks directory, so a stray cache would deploy with it.
|
# apm copies the whole hooks directory, so a stray cache would deploy with it.
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.pyc
|
*.pyc
|
||||||
|
|
||||||
|
# uv's project environment for the repo-pinned apm (ADR-0034). Created by
|
||||||
|
# `uv sync --frozen` from the committed uv.lock; machine-local, never content.
|
||||||
|
.venv/
|
||||||
@@ -71,7 +71,7 @@ repos:
|
|||||||
|
|
||||||
- id: check-executables-allow-sync
|
- id: check-executables-allow-sync
|
||||||
name: Check executables allow keys sync
|
name: Check executables allow keys sync
|
||||||
description: Verify root apm.yml's executables.allow carries a "<name>#<version>" key matching the apm.yml version of every plugin that ships executables (plugins/<name>/.apm/hooks/ or bin/), reporting every out-of-sync package in one run. apm's grant is version-blind, so a stale key still deploys; this is a record-keeping gate that fails a version bump made without the matching key edit, keeping each key an accurate record of what was approved (see ADR-0019's 2026-09-19 correction and docs/spec/gates.md)
|
description: Verify root apm.yml's executables.allow carries a "<host>/<owner>/<repo>/plugins/<name>#<version>" key -- the full package identity apm 0.39 matches on, derived from root apm.yml's git+path dependency entry for the plugin, plus the plugin's apm.yml version -- for every plugin that ships executables (plugins/<name>/.apm/hooks/ or bin/), reporting every out-of-sync package in one run. A bare "<name>#<version>" key fails, because apm 0.39 parks the hooks under it while root `apm audit --ci` stays green (spike #269). The version half is version-blind to apm, so a stale version still deploys; that half is a record-keeping gate that fails a version bump made without the matching key edit (see ADR-0019's 2026-09-19 correction and docs/spec/gates.md). It also fails when apm.lock.yaml records any gated_* exec_status, a parked executable that root `apm audit --ci` lets through
|
||||||
entry: bash scripts/check-executables-allow-sync.sh
|
entry: bash scripts/check-executables-allow-sync.sh
|
||||||
language: system
|
language: system
|
||||||
stages: [pre-push]
|
stages: [pre-push]
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ Install all of these before setting up. Each one is a hard dependency of a git h
|
|||||||
|
|
||||||
| Tool | Why | Install |
|
| Tool | Why | Install |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| `apm` CLI | Two pre-push hooks shell out to it (`apm-audit-ci` and `apm-pack-check-clean`) | The `apm-install` skill, or `curl -sSL https://aka.ms/apm-unix \| sh`. Verify with `apm --version` |
|
| `uv` | Runs this repo's pinned apm. The root `pyproject.toml` pins `apm-cli==0.39.3` and `uv.lock` locks it (ADR-0034); the `apm-audit-ci` and `apm-pack-check-clean` pre-push hooks run it as `uv run --frozen apm` through `scripts/lib/apm.sh`, and fail below apm 0.39.2 | https://docs.astral.sh/uv/getting-started/installation/. A global `apm` is not needed and not used: a bare `apm` here may be an older one that refuses the v4 `apm.lock.yaml` |
|
||||||
| `python3` + PyYAML | Required by `scripts/skill-size-check.sh` (the `skill-size-check` pre-commit hook) and `scripts/check-skill-version-bump.sh` (the `check-skill-version-bump` pre-push hook), which both parse YAML frontmatter | `python3` is usually present — pre-commit is itself a Python application. `pip install pyyaml` if the hook reports PyYAML missing |
|
| `python3` + PyYAML | Required by `scripts/skill-size-check.sh` (the `skill-size-check` pre-commit hook) and `scripts/check-skill-version-bump.sh` (the `check-skill-version-bump` pre-push hook), which both parse YAML frontmatter | `python3` is usually present — pre-commit is itself a Python application. `pip install pyyaml` if the hook reports PyYAML missing |
|
||||||
| `vale` | Required by the `vale-audit-prefilter-skill` / `-agent` pre-commit hooks, and by the `test-vale-wrap.sh` suite that `run-tests --strict` runs at pre-push | `brew install vale` (macOS), `snap install vale` (Linux), `choco install vale` (Windows), or https://vale.sh/docs/vale-cli/installation/ |
|
| `vale` | Required by the `vale-audit-prefilter-skill` / `-agent` pre-commit hooks, and by the `test-vale-wrap.sh` suite that `run-tests --strict` runs at pre-push | `brew install vale` (macOS), `snap install vale` (Linux), `choco install vale` (Windows), or https://vale.sh/docs/vale-cli/installation/ |
|
||||||
| `claude` CLI | Required by the `validate-marketplace` pre-push hook | Claude Code |
|
| `claude` CLI | Required by the `validate-marketplace` pre-push hook | Claude Code |
|
||||||
@@ -51,14 +51,19 @@ Two notes worth reading before you skip one:
|
|||||||
Run these in order, from the repo root.
|
Run these in order, from the repo root.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 1. Deploy this repo's own skills and agents
|
# 1. Install the pinned apm into .venv/ (gitignored)
|
||||||
apm install
|
uv sync --frozen
|
||||||
|
|
||||||
# 2. Install the git hooks — all three stages
|
# 2. Deploy this repo's own skills and agents
|
||||||
|
uv run --frozen apm install
|
||||||
|
|
||||||
|
# 3. Install the git hooks — all three stages
|
||||||
pre-commit install -t pre-commit -t commit-msg -t pre-push
|
pre-commit install -t pre-commit -t commit-msg -t pre-push
|
||||||
```
|
```
|
||||||
|
|
||||||
**`apm install`** deploys the plugins root `apm.yml` lists into `.claude/skills/` and `.claude/agents/`. Both are gitignored install output, *not* authoring source — `plugins/<name>/.apm/` remains the only place to edit. It needs the network and materializes `apm_modules/` (which stays gitignored).
|
**`uv sync --frozen`** installs the apm that `uv.lock` pins into `.venv/`. Every apm command in this repo runs as `uv run --frozen apm ...`.
|
||||||
|
|
||||||
|
**`apm install`** deploys the plugins root `apm.yml` lists into `.claude/skills/` and `.claude/agents/`. Both are gitignored install output, *not* authoring source — `plugins/<name>/.apm/` remains the only place to edit. Both steps need the network once, and `apm install` materializes `apm_modules/` (which stays gitignored).
|
||||||
|
|
||||||
**Git hooks** must be wired for **all three stages**. This repo's `.pre-commit-config.yaml` has no `default_install_hook_types`, so a plain `pre-commit install` silently skips `commit-msg` (Conventional Commits) and `pre-push` (the full gate) — the `-t` flags above are not optional. The `pc-run` skill handles this and the troubleshooting around it, if you would rather not remember the flags.
|
**Git hooks** must be wired for **all three stages**. This repo's `.pre-commit-config.yaml` has no `default_install_hook_types`, so a plain `pre-commit install` silently skips `commit-msg` (Conventional Commits) and `pre-push` (the full gate) — the `-t` flags above are not optional. The `pc-run` skill handles this and the troubleshooting around it, if you would rather not remember the flags.
|
||||||
|
|
||||||
@@ -92,7 +97,7 @@ pre-commit run --hook-stage pre-push --all-files
|
|||||||
|
|
||||||
See [`docs/spec/gates.md`](docs/spec/gates.md) for what each hook enforces and why.
|
See [`docs/spec/gates.md`](docs/spec/gates.md) for what each hook enforces and why.
|
||||||
|
|
||||||
**Offline?** No pre-push hook needs the network **once `apm install` has populated `apm_modules/`**. Root `apm.yml`'s marketplace has no remote package entries (the last one, `mattpocock-skills`, was removed), so `apm-pack-check-clean` resolves everything from local sources, and `apm-audit-ci`'s install-replay is cache-only against a populated install. On a **fresh clone** there is no cache: `apm-audit-ci`'s `deployed-files-present` fails outright, and its `drift` and `config-consistency` checks clone from the holocron remote. The offline guarantee is a property of a populated `apm_modules/`, not of the hook set — run `apm install` once on a new checkout and it holds from then on.
|
**Offline?** No pre-push hook needs the network **once `uv sync --frozen` and `apm install` have each run once** (ADR-0034). Root `apm.yml`'s marketplace has no remote package entries (the last one, `mattpocock-skills`, was removed), so `apm-pack-check-clean` resolves everything from local sources, and `apm-audit-ci`'s install-replay is cache-only against a populated install. On a **fresh clone** there is no cache: `apm-audit-ci`'s `deployed-files-present` fails outright, and its `drift` and `config-consistency` checks clone from the holocron remote. The offline guarantee is a property of a populated `apm_modules/`, not of the hook set — run `uv sync --frozen` and `uv run --frozen apm install` once on a new checkout and it holds from then on.
|
||||||
|
|
||||||
## Editing plugin content
|
## Editing plugin content
|
||||||
|
|
||||||
|
|||||||
+1103
-56
File diff suppressed because it is too large.
Load diff
@@ -58,26 +58,32 @@ dependencies:
|
|||||||
# verified: `apm approve --list` reports "Executable-trust gate disabled -- all
|
# verified: `apm approve --list` reports "Executable-trust gate disabled -- all
|
||||||
# executables deploy" until an `executables:` block exists.
|
# executables deploy" until an `executables:` block exists.
|
||||||
#
|
#
|
||||||
|
# Keys are the FULL package identity apm 0.39 matches on,
|
||||||
|
# <host>/<owner>/<repo>/<path>#<version>, as `apm approve --list` prints it.
|
||||||
|
# The bare `kyberforge#<version>` form 0.28 accepted no longer matches: under
|
||||||
|
# 0.39.3 it parks both hooks, writes `.claude/settings.json` back to `{}`, and
|
||||||
|
# root `apm audit --ci` still passes (spike #269, on #268). The `#<version>`
|
||||||
|
# suffix is stripped before matching, so the grant is version-blind and a
|
||||||
|
# plugin bump alone does not park the hook; the suffix is a repo convention
|
||||||
|
# that `scripts/check-executables-allow-sync.sh`, a pre-push hook, holds level
|
||||||
|
# with each plugin's apm.yml `version:`.
|
||||||
|
#
|
||||||
|
# The grants are type-level (`hooks: true`), not content-pinned. Every install
|
||||||
|
# warns that they are not pinned to content; that is accepted, because a
|
||||||
|
# content pin parks the hook on every edit to its scripts until someone re-runs
|
||||||
|
# `apm approve`. Do not run `apm approve` here: it rewrites this block, adds
|
||||||
|
# content pins and strips these comments.
|
||||||
|
#
|
||||||
# kyberforge ships the SessionStart hook that keeps this install level with the
|
# kyberforge ships the SessionStart hook that keeps this install level with the
|
||||||
# remote (ADR-0019). The `#2.0.0` suffix below is cosmetic as far as apm is
|
# remote (ADR-0019).
|
||||||
# concerned: grants are version-BLIND in apm 0.28.0. `_map_grants`
|
|
||||||
# (apm_cli/security/executables.py) matches the exact key, the version-blind
|
|
||||||
# name, or any stored key sharing that name, and `materialize_exec_map` also
|
|
||||||
# stores the version-blind name — so approving `kyberforge` covers
|
|
||||||
# `kyberforge#2.0.0` and vice-versa, and a kyberforge version bump does NOT
|
|
||||||
# make this entry stop matching or stop the hook deploying. Do not delete the
|
|
||||||
# suffix anyway: `scripts/check-executables-allow-sync.sh` is a repo-authored
|
|
||||||
# pre-push hook that asserts this key carries the version in
|
|
||||||
# plugins/kyberforge/apm.yml, so a bump here is a repo convention to keep, not
|
|
||||||
# an apm mechanic.
|
|
||||||
executables:
|
executables:
|
||||||
allow:
|
allow:
|
||||||
kyberforge#2.3.0:
|
git.rkdr.net/Mortis/Holocron/plugins/kyberforge#2.3.0:
|
||||||
hooks: true
|
hooks: true
|
||||||
bin: true
|
bin: true
|
||||||
# delivery ships the guard hook (ADR-0032 enforcement layer 2). Same
|
# delivery ships the guard hook (ADR-0032 enforcement layer 2). Same
|
||||||
# version-in-key convention as above, kept by the same sync check.
|
# full-identity, version-in-key convention as above, kept by the same check.
|
||||||
delivery#0.8.0:
|
git.rkdr.net/Mortis/Holocron/plugins/delivery#0.8.0:
|
||||||
hooks: true
|
hooks: true
|
||||||
|
|
||||||
marketplace:
|
marketplace:
|
||||||
|
|||||||
+43
-6
@@ -1164,8 +1164,18 @@ Verified: a malformed dependency entry passes
|
|||||||
`apm pack --check-versions --check-clean --dry-run` and fails `apm audit --ci` in that package's
|
`apm pack --check-versions --check-clean --dry-run` and fails `apm audit --ci` in that package's
|
||||||
directory. Costs ~0.5s per package.
|
directory. Costs ~0.5s per package.
|
||||||
|
|
||||||
**apm runs with git's repo-locating env scrubbed.** Both apm hooks source
|
**Both apm hooks run the repo-pinned apm.** They source `scripts/lib/apm.sh`, the one place the
|
||||||
`scripts/lib/clean-git-env.sh` before calling `apm`, which unsets `GIT_DIR`, `GIT_WORK_TREE`,
|
invocation is spelled: `uv run --project <repo root> --frozen apm` (ADR-0034). `--project` comes
|
||||||
|
from the helper's own location, so it names the repo root even when apm runs inside
|
||||||
|
`plugins/<name>/`. Each hook first checks the resolved apm's version and fails, naming
|
||||||
|
`uv sync --frozen` as the fix, below 0.39.2. The gates keep plain `--frozen`, without the
|
||||||
|
SessionStart hook's `--no-sync --offline`: once `uv sync --frozen` has run, the sync it implies is a
|
||||||
|
no-op that needs no network, and after a pull that moves the pin it brings `.venv/` to the new pin
|
||||||
|
instead of letting a gate certify the tree with a stale apm. `tests/test-apm-gate-invocation.sh`
|
||||||
|
pins the command, the `--project` root, the scrub and the version floor with a fake `uv`.
|
||||||
|
|
||||||
|
**apm runs with git's repo-locating env scrubbed.** Sourcing `scripts/lib/apm.sh` also sources
|
||||||
|
`scripts/lib/clean-git-env.sh` before anything calls `apm`, which unsets `GIT_DIR`, `GIT_WORK_TREE`,
|
||||||
`GIT_INDEX_FILE`, `GIT_OBJECT_DIRECTORY`, `GIT_COMMON_DIR`, `GIT_PREFIX` and
|
`GIT_INDEX_FILE`, `GIT_OBJECT_DIRECTORY`, `GIT_COMMON_DIR`, `GIT_PREFIX` and
|
||||||
`GIT_IMPLICIT_WORK_TREE`. It deliberately keeps the config-passing vars (`GIT_CONFIG_PARAMETERS`,
|
`GIT_IMPLICIT_WORK_TREE`. It deliberately keeps the config-passing vars (`GIT_CONFIG_PARAMETERS`,
|
||||||
`GIT_CONFIG_COUNT`), because they carry `git -c` overrides apm's remote clones may need. The reason: `git push` from a **linked worktree** exports an
|
`GIT_CONFIG_COUNT`), because they carry `git -c` overrides apm's remote clones may need. The reason: `git push` from a **linked worktree** exports an
|
||||||
@@ -1256,6 +1266,33 @@ among them, which is the state ADR-0026 rules out rather than a second scan wort
|
|||||||
|
|
||||||
### `check-executables-allow-sync`
|
### `check-executables-allow-sync`
|
||||||
|
|
||||||
|
**Keys are full package identities (apm 0.39, #271).** apm 0.39.3 matches a grant on the package
|
||||||
|
identity `<host>/<owner>/<repo>/<path>`, as `apm approve --list` prints it, e.g.
|
||||||
|
`git.rkdr.net/Mortis/Holocron/plugins/kyberforge`. The bare `kyberforge#<version>` key that 0.28.0
|
||||||
|
matched no longer matches: the first 0.39 install parks the hooks, rewrites `.claude/settings.json`
|
||||||
|
without them, and root `apm audit --ci` still passes (spike #269, on #268). So the gate now derives
|
||||||
|
each expected key from root `apm.yml`'s own `git:` + `path:` dependency entry for the plugin (URL
|
||||||
|
without scheme, user or `.git`, then the path), appends `#<version>`, and fails a bare key with a
|
||||||
|
message saying why. A shipping plugin with no such entry fails, since no key can be derived, and so
|
||||||
|
does one whose `git:` URL names a port, because how apm writes a port into the identity is
|
||||||
|
unverified. Only an https URL on a lowercase host was checked against `apm approve --list`; the
|
||||||
|
scp-like and `ssh://` forms follow the same rule unchecked, and the host's case is kept as written. The
|
||||||
|
`#<version>` suffix is still stripped before apm matches, so the grant stays version-blind and the
|
||||||
|
version half stays a repo-level record. The grants are type-level (`hooks: true`), not
|
||||||
|
content-pinned: `apm approve` would pin content, strip the block's comments, and park the hook on
|
||||||
|
every script edit until someone approves again.
|
||||||
|
|
||||||
|
**It also fails on a parked executable in `apm.lock.yaml`** (spike #269, section 7.3). apm records
|
||||||
|
each dependency's executables decision as `exec_status:` in the lock, `deployed` or a `gated_*`
|
||||||
|
value such as `gated_pending_approval`. Root `apm audit --ci` passes with executables parked,
|
||||||
|
because `exec-status-current` only checks that the lock agrees with the gate. So the gate scans the
|
||||||
|
lock's `dependencies:` and fails on any `gated_*` entry, naming its identity and status, with
|
||||||
|
`apm approve --list` as the first step of the fix. It runs even when no plugin here ships
|
||||||
|
executables, since a third-party dependency can be parked too. A missing lock is left to
|
||||||
|
`apm-audit-ci`'s `lockfile-exists`. It is a line scan of the shape apm writes, not a YAML parse.
|
||||||
|
|
||||||
|
The rest of this section describes the 0.28.0 matching that the version-blind behaviour comes from.
|
||||||
|
|
||||||
apm gates a package's `hooks/` and `bin/` on root `apm.yml`'s `executables.allow`
|
apm gates a package's `hooks/` and `bin/` on root `apm.yml`'s `executables.allow`
|
||||||
(`apm_cli/security/executables.py`). `is_package_approved` is itself an exact dictionary lookup, but
|
(`apm_cli/security/executables.py`). `is_package_approved` is itself an exact dictionary lookup, but
|
||||||
it is never called with a single key: `install/exec_gate.py` builds a candidate list that includes
|
it is never called with a single key: `install/exec_gate.py` builds a candidate list that includes
|
||||||
@@ -1276,10 +1313,10 @@ It covers every plugin that ships executables, not one named package. The script
|
|||||||
`plugins/*/` and treats a plugin as shipping executables when `plugins/<name>/.apm/hooks/` or
|
`plugins/*/` and treats a plugin as shipping executables when `plugins/<name>/.apm/hooks/` or
|
||||||
`plugins/<name>/bin/` exists — kyberforge ships both, delivery ships a guard hook. For each one it
|
`plugins/<name>/bin/` exists — kyberforge ships both, delivery ships a guard hook. For each one it
|
||||||
reads `name:` and `version:` from `plugins/<name>/apm.yml` and asserts root `apm.yml` carries the
|
reads `name:` and `version:` from `plugins/<name>/apm.yml` and asserts root `apm.yml` carries the
|
||||||
`<name>#<version>` key under `executables.allow`. Keys use the package name, so a `name:` that
|
`<identity>#<version>` key under `executables.allow`. The `name:` must equal the directory name, so
|
||||||
differs from the directory name fails rather than being guessed at. Every failing package is
|
one that differs fails rather than being guessed at. Every failing package is
|
||||||
reported in one run, each with its own Why/Fix block; a stale `<name>#<other-version>` key is quoted
|
reported in one run, each with its own Why/Fix block; a stale `<identity>#<other-version>` key, or a
|
||||||
back as "found instead". It also fails on a shipping plugin with no `apm.yml`, a missing `version:`,
|
bare `<name>#...` key, is quoted back as "found instead". It also fails on a shipping plugin with no `apm.yml`, a missing `version:`,
|
||||||
a missing root `apm.yml`, or no `executables.allow` mapping. A repo with no executable-shipping
|
a missing root `apm.yml`, or no `executables.allow` mapping. A repo with no executable-shipping
|
||||||
plugin at all is the one no-op, and a plugin with neither directory needs no key.
|
plugin at all is the one no-op, and a plugin with neither directory needs no key.
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,21 @@ fill() {
|
|||||||
"$1"
|
"$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# In this repo apm is the one pinned in pyproject.toml/uv.lock, run through
|
||||||
|
# scripts/lib/apm.sh as `uv run --project <repo root> --frozen apm` (ADR-0034),
|
||||||
|
# so these tests exercise 0.39.3 and never whatever apm is on PATH. The pin is
|
||||||
|
# a declared dependency here, so a missing uv or an apm below the helper's
|
||||||
|
# minimum FAILS rather than skips: a skip would let `run-tests.sh --strict` go
|
||||||
|
# green without running these tests. Outside this repo (no helper) the PATH
|
||||||
|
# apm is used, and its absence still skips.
|
||||||
need_apm() {
|
need_apm() {
|
||||||
|
if [[ -f "$REPO_ROOT/scripts/lib/apm.sh" ]]; then
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
source "$REPO_ROOT/scripts/lib/apm.sh"
|
||||||
|
require_apm_version || fail "the repo-pinned apm is unavailable; run 'uv sync --frozen' at $REPO_ROOT"
|
||||||
|
apm() { run_apm "$@"; }
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
command -v apm >/dev/null 2>&1 || skip "apm CLI not installed"
|
command -v apm >/dev/null 2>&1 || skip "apm CLI not installed"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,10 +187,14 @@ need_apm() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# apm behaviour the skill's gotchas rest on (verified against apm 0.28.0)
|
# apm behaviour the skill's gotchas rest on. Verified against apm 0.28.0, then
|
||||||
|
# re-pinned to the repo's 0.39.3 (#271), where three behaviours changed: compile
|
||||||
|
# --target claude writes a CLAUDE.md that imports AGENTS.md, an unquoted applyTo
|
||||||
|
# fails install closed, and compile warns when applyTo matches no file. The
|
||||||
|
# skill's own text still describes 0.28.0 in places; see #271's report.
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
@test "filled scaffold compiles for the Claude target into CLAUDE.md without the description" {
|
@test "filled scaffold compiles for the Claude target: CLAUDE.md imports AGENTS.md, which drops the description" {
|
||||||
need_apm
|
need_apm
|
||||||
make_package
|
make_package
|
||||||
bash "$SCRIPT" my-rule "$ROOT"
|
bash "$SCRIPT" my-rule "$ROOT"
|
||||||
@@ -185,9 +203,11 @@ need_apm() {
|
|||||||
run apm compile --target claude
|
run apm compile --target claude
|
||||||
assert_success
|
assert_success
|
||||||
assert [ -f "$ROOT/CLAUDE.md" ]
|
assert [ -f "$ROOT/CLAUDE.md" ]
|
||||||
run grep -F 'Use type hints.' "$ROOT/CLAUDE.md"
|
run grep -Fx '@AGENTS.md' "$ROOT/CLAUDE.md"
|
||||||
assert_success
|
assert_success
|
||||||
run grep -F 'Python style rules' "$ROOT/CLAUDE.md"
|
run grep -F 'Use type hints.' "$ROOT/AGENTS.md"
|
||||||
|
assert_success
|
||||||
|
run grep -F 'Python style rules' "$ROOT/AGENTS.md"
|
||||||
assert_failure
|
assert_failure
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,17 +241,16 @@ need_apm() {
|
|||||||
assert [ ! -f "$ROOT/CLAUDE.md" ]
|
assert [ ! -f "$ROOT/CLAUDE.md" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "an unquoted applyTo still installs, as a rule with no paths:" {
|
@test "an unquoted applyTo fails install closed and deploys no rule" {
|
||||||
need_apm
|
need_apm
|
||||||
make_package
|
make_package
|
||||||
mkdir -p "$ROOT/.apm/instructions"
|
mkdir -p "$ROOT/.apm/instructions"
|
||||||
printf -- '---\ndescription: x\napplyTo: **/*.py\n---\n# T\n\n- a\n' > "$ROOT/.apm/instructions/bad.instructions.md"
|
printf -- '---\ndescription: x\napplyTo: **/*.py\n---\n# T\n\n- a\n' > "$ROOT/.apm/instructions/bad.instructions.md"
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
run apm install
|
run apm install
|
||||||
assert_success
|
|
||||||
assert [ -f "$ROOT/.claude/rules/bad.md" ]
|
|
||||||
run grep -F 'paths:' "$ROOT/.claude/rules/bad.md"
|
|
||||||
assert_failure
|
assert_failure
|
||||||
|
assert_output --partial "Rejected frontmatter in bad.instructions.md"
|
||||||
|
assert [ ! -f "$ROOT/.claude/rules/bad.md" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "compile --validate exits 0 and hides the warnings a real compile prints" {
|
@test "compile --validate exits 0 and hides the warnings a real compile prints" {
|
||||||
@@ -259,5 +278,8 @@ need_apm() {
|
|||||||
assert_success
|
assert_success
|
||||||
assert_output --partial "dry-run"
|
assert_output --partial "dry-run"
|
||||||
refute_output --partial "Failed to parse"
|
refute_output --partial "Failed to parse"
|
||||||
refute_output --partial "Warning"
|
# 0.39 warns when applyTo matches no file, which an empty package always
|
||||||
|
# does; any other warning is a parse or validation finding.
|
||||||
|
run grep -F "Warning" <<< "$(grep -vF "matched no files" <<< "$output")"
|
||||||
|
assert_failure
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
# Pins this repo's apm with uv (ADR-0034). Not a Python package: there is no
|
||||||
|
# build system, and uv only installs the dev group below. Run apm as
|
||||||
|
# `uv run --frozen apm ...`; the repo's gate scripts spell that once in
|
||||||
|
# scripts/lib/apm.sh. uv pins the apm tool only, never plugin content
|
||||||
|
# (ADR-0024).
|
||||||
|
[project]
|
||||||
|
name = "holocron-tooling"
|
||||||
|
version = "0.0.0"
|
||||||
|
requires-python = ">=3.11"
|
||||||
|
dependencies = []
|
||||||
|
|
||||||
|
[tool.uv]
|
||||||
|
package = false
|
||||||
|
|
||||||
|
[dependency-groups]
|
||||||
|
dev = ["apm-cli==0.39.3"]
|
||||||
+15
-8
@@ -28,7 +28,9 @@
|
|||||||
# and additionally litters it with an apm_modules/ tree
|
# and additionally litters it with an apm_modules/ tree
|
||||||
#
|
#
|
||||||
# So this hook waives exactly one failure: a plugin package whose ONLY failing
|
# So this hook waives exactly one failure: a plugin package whose ONLY failing
|
||||||
# check is `lockfile-exists`. Verified against apm 0.28.0.
|
# check is `lockfile-exists`. Verified against apm 0.28.0, and re-verified
|
||||||
|
# against 0.39.3 (spike #269, on #268): both matched strings below are unchanged,
|
||||||
|
# and no other check fails in any plugin directory.
|
||||||
#
|
#
|
||||||
# WHAT IS DELIBERATELY NOT WAIVED
|
# WHAT IS DELIBERATELY NOT WAIVED
|
||||||
#
|
#
|
||||||
@@ -55,12 +57,17 @@
|
|||||||
|
|
||||||
set -uo pipefail
|
set -uo pipefail
|
||||||
|
|
||||||
# Scrub git's repo-locating env before apm runs: pushed from a linked worktree,
|
# apm is the repo-pinned one, run through scripts/lib/apm.sh as
|
||||||
# the hook inherits an absolute GIT_DIR, and apm's drift replay runs `git init`
|
# `uv run --project <repo root> --frozen apm` (ADR-0034). Sourcing the helper
|
||||||
# / `git checkout` in a temp dir with it -- flipping core.bare=true and moving
|
# also scrubs git's repo-locating env before apm runs: pushed from a linked
|
||||||
# the worktree's HEAD (issue #204). See the helper for the full account.
|
# worktree, the hook inherits an absolute GIT_DIR, and apm's drift replay runs
|
||||||
# shellcheck source=scripts/lib/clean-git-env.sh
|
# `git init` / `git checkout` in a temp dir with it -- flipping core.bare=true
|
||||||
source "$(dirname "${BASH_SOURCE[0]}")/lib/clean-git-env.sh"
|
# and moving the worktree's HEAD (issue #204). See clean-git-env.sh for the
|
||||||
|
# full account.
|
||||||
|
# shellcheck source=scripts/lib/apm.sh
|
||||||
|
source "$(dirname "${BASH_SOURCE[0]}")/lib/apm.sh"
|
||||||
|
|
||||||
|
require_apm_version || exit 1
|
||||||
|
|
||||||
readonly WAIVED_CHECK='declares dependencies but apm.lock.yaml is absent'
|
readonly WAIVED_CHECK='declares dependencies but apm.lock.yaml is absent'
|
||||||
readonly SOLE_FAILURE='1 of 1 check(s) failed'
|
readonly SOLE_FAILURE='1 of 1 check(s) failed'
|
||||||
@@ -68,7 +75,7 @@ readonly SOLE_FAILURE='1 of 1 check(s) failed'
|
|||||||
status=0
|
status=0
|
||||||
|
|
||||||
for manifest_dir in . plugins/*/; do
|
for manifest_dir in . plugins/*/; do
|
||||||
output="$(cd "$manifest_dir" && apm audit --ci 2>&1)"
|
output="$(cd "$manifest_dir" && run_apm audit --ci 2>&1)"
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
|
|
||||||
if [ "$exit_code" -eq 0 ]; then
|
if [ "$exit_code" -eq 0 ]; then
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# apm-pack-check-clean pre-push hook: `apm pack --check-versions --check-clean
|
# apm-pack-check-clean pre-push hook: `apm pack --check-versions --check-clean
|
||||||
# --dry-run`, run with git's repo-locating env scrubbed first. A script rather
|
# --dry-run`, run through scripts/lib/apm.sh. That helper runs the repo-pinned
|
||||||
# than a bare `apm ...` entry only so it can source that scrub -- see
|
# apm as `uv run --project <repo root> --frozen apm` (ADR-0034), fails clearly
|
||||||
|
# below the minimum version, and scrubs git's repo-locating env first -- see
|
||||||
# scripts/lib/clean-git-env.sh and issue #204, and docs/spec/gates.md,
|
# scripts/lib/clean-git-env.sh and issue #204, and docs/spec/gates.md,
|
||||||
# "apm-audit-ci", the "apm runs with git's repo-locating env scrubbed" paragraph.
|
# "apm-audit-ci", the "apm runs with git's repo-locating env scrubbed" paragraph.
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# shellcheck source=scripts/lib/clean-git-env.sh
|
# shellcheck source=scripts/lib/apm.sh
|
||||||
source "$(dirname "${BASH_SOURCE[0]}")/lib/clean-git-env.sh"
|
source "$(dirname "${BASH_SOURCE[0]}")/lib/apm.sh"
|
||||||
|
|
||||||
exec apm pack --check-versions --check-clean --dry-run
|
require_apm_version || exit 1
|
||||||
|
# The guarded expansion keeps bash 3.2 happy under `set -u`: the helper seeds
|
||||||
|
# APM_CMD empty, and require_apm_version has already refused an empty one.
|
||||||
|
exec ${APM_CMD[@]+"${APM_CMD[@]}"} pack --check-versions --check-clean --dry-run
|
||||||
@@ -1,22 +1,37 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# Fails the push when root apm.yml's executables.allow stops naming the actual
|
# Fails the push when root apm.yml's executables.allow stops naming the full
|
||||||
# version of every plugin that ships executables. A plugin ships executables
|
# identity and actual version of every plugin that ships executables. A plugin
|
||||||
# when plugins/<name>/.apm/hooks/ or plugins/<name>/bin/ exists; each one needs
|
# ships executables when plugins/<name>/.apm/hooks/ or plugins/<name>/bin/
|
||||||
# a '<name>#<version>' key, where <name> and <version> come from its own
|
# exists; each one needs a '<identity>#<version>' key:
|
||||||
# apm.yml (and <name> must equal the directory name, since keys use the
|
|
||||||
# package name). Every failing package is reported in one run.
|
|
||||||
#
|
#
|
||||||
# The grant itself is version-blind — apm matches the version-less name
|
# * <identity> is the package identity apm 0.39 matches grants on,
|
||||||
# alongside '<package>#<version>' (exec_gate.py builds the candidate list,
|
# <host>/<owner>/<repo>/<path>, e.g. git.rkdr.net/Mortis/Holocron/plugins/kyberforge.
|
||||||
# _map_grants matches it) — so a stale key keeps granting the package's hooks/
|
# It is derived from root apm.yml's own `git:` + `path:` dependency entry
|
||||||
# and bin/ and deployment does not break. What this gate buys is repo-level,
|
# for plugins/<name>, the same fields apm builds it from: the URL loses its
|
||||||
# not apm-level: a version bump without the matching key edit fails this
|
# scheme, any user@ and a trailing .git, and the path is appended. Verified
|
||||||
# repo's own pre-push, so each key stays an accurate record of what was
|
# against `apm approve --list` on apm 0.39.3 for a git+path entry on a
|
||||||
# approved. See ADR-0019's 2026-09-19 correction and docs/spec/gates.md,
|
# self-hosted host. A plugin with no such entry fails, because no key can be
|
||||||
# "check-executables-allow-sync"; nothing else in the pre-push gate compares
|
# derived for it.
|
||||||
# these files.
|
# * <version> comes from plugins/<name>/apm.yml (whose name: must equal the
|
||||||
|
# directory name).
|
||||||
|
#
|
||||||
|
# Every failing package is reported in one run.
|
||||||
|
#
|
||||||
|
# Under apm 0.28 a bare '<name>#<version>' key matched. Under 0.39.3 it does
|
||||||
|
# not: the hooks are parked, .claude/settings.json is rewritten without them,
|
||||||
|
# and root `apm audit --ci` still passes (spike #269, on #268). So a bare key is
|
||||||
|
# now a real deployment failure that nothing else catches, and this gate names
|
||||||
|
# it as one.
|
||||||
|
#
|
||||||
|
# The '#<version>' suffix is stripped before apm matches, so the grant is
|
||||||
|
# version-blind and a stale version keeps granting the package's hooks/ and
|
||||||
|
# bin/. What the version half buys is repo-level, not apm-level: a version bump
|
||||||
|
# without the matching key edit fails this repo's own pre-push, so each key
|
||||||
|
# stays an accurate record of what was approved. See ADR-0019's 2026-09-19
|
||||||
|
# correction and docs/spec/gates.md, "check-executables-allow-sync"; nothing
|
||||||
|
# else in the pre-push gate compares these files.
|
||||||
#
|
#
|
||||||
# Run from repo root or pass REPO_ROOT as arg.
|
# Run from repo root or pass REPO_ROOT as arg.
|
||||||
|
|
||||||
@@ -49,13 +64,64 @@ for plugin_dir in "$REPO_ROOT"/plugins/*/; do
|
|||||||
done
|
done
|
||||||
shopt -u nullglob
|
shopt -u nullglob
|
||||||
|
|
||||||
# Only a repo with no executable-shipping plugin at all is a legitimate no-op —
|
FAILED=0
|
||||||
# there is no version to pin and no hook to deploy.
|
|
||||||
if [[ ${#PLUGINS[@]} -eq 0 ]]; then
|
# ---------------------------------------------------------------------------
|
||||||
exit 0
|
# Parked executables in the lock (spike #269, on #268, section 7.3)
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# apm records each dependency's executables decision as `exec_status:` in
|
||||||
|
# apm.lock.yaml: `deployed`, or a `gated_*` value (for example
|
||||||
|
# `gated_pending_approval`) when the trust gate parked its hooks, bin or MCP
|
||||||
|
# servers. Root `apm audit --ci` passes in that state, because its
|
||||||
|
# exec-status-current check only asserts the lock agrees with the gate. So a
|
||||||
|
# wrong key, or a content-pinned hook whose script changed, would leave the
|
||||||
|
# SessionStart hook or the delivery guard silently uninstalled with every
|
||||||
|
# other gate green. This fails the push instead. Runs whether or not any
|
||||||
|
# plugin here ships executables: a third-party dependency can be parked too.
|
||||||
|
# A missing lock is not this check's concern (apm-audit-ci's lockfile-exists).
|
||||||
|
#
|
||||||
|
# A line scan, not a YAML parse: apm writes the lock with libyaml in one fixed
|
||||||
|
# shape, with `- repo_url:` opening each dependency and its fields at 2 spaces.
|
||||||
|
LOCKFILE="$REPO_ROOT/apm.lock.yaml"
|
||||||
|
if [[ -f "$LOCKFILE" ]]; then
|
||||||
|
GATED="$(awk '
|
||||||
|
/^[^ -]/ { in_deps = ($0 ~ /^dependencies:/); next }
|
||||||
|
!in_deps { next }
|
||||||
|
/^- / { host = ""; repo = ""; vpath = "" }
|
||||||
|
{
|
||||||
|
line = $0
|
||||||
|
sub(/^- /, " ", line)
|
||||||
|
if (line !~ /^ [a-z_]+: /) next
|
||||||
|
key = line; sub(/^ /, "", key); sub(/: .*/, "", key)
|
||||||
|
val = line; sub(/^ [a-z_]+: /, "", val); gsub(/["\047]/, "", val)
|
||||||
|
if (key == "host") host = val
|
||||||
|
else if (key == "repo_url") repo = val
|
||||||
|
else if (key == "virtual_path") vpath = val
|
||||||
|
else if (key == "exec_status" && val ~ /^gated_/) {
|
||||||
|
id = (host != "" ? host "/" : "") repo (vpath != "" ? "/" vpath : "")
|
||||||
|
printf "%s: %s\n", id, val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
' "$LOCKFILE")"
|
||||||
|
if [[ -n "$GATED" ]]; then
|
||||||
|
echo "FAIL: apm.lock.yaml records executables apm did not deploy:" >&2
|
||||||
|
while IFS= read -r line; do echo " $line" >&2; done <<< "$GATED"
|
||||||
|
echo " Why: a gated_* exec_status means the trust gate parked that package's hooks, bin or" >&2
|
||||||
|
echo " MCP servers: no executables.allow key matches it, or a content pin no longer" >&2
|
||||||
|
echo " does. Root 'apm audit --ci' still passes in that state (spike #269), so without" >&2
|
||||||
|
echo " this check a parked SessionStart hook or guard goes unnoticed." >&2
|
||||||
|
echo " Fix: run 'uv run --frozen apm approve --list' to see why each is parked, correct its" >&2
|
||||||
|
echo " executables.allow key in root apm.yml, then 'uv run --frozen apm install' and" >&2
|
||||||
|
echo " commit the rewritten apm.lock.yaml." >&2
|
||||||
|
FAILED=1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
FAILED=0
|
# Only a repo with no executable-shipping plugin at all is a legitimate no-op
|
||||||
|
# for the key checks below — there is no version to pin and no hook to deploy.
|
||||||
|
if [[ ${#PLUGINS[@]} -eq 0 ]]; then
|
||||||
|
exit "$FAILED"
|
||||||
|
fi
|
||||||
|
|
||||||
# "hooks/ and bin/", "hooks/" or "bin/" — what the plugin actually ships, so a
|
# "hooks/ and bin/", "hooks/" or "bin/" — what the plugin actually ships, so a
|
||||||
# message never claims a package has a bin/ it does not.
|
# message never claims a package has a bin/ it does not.
|
||||||
@@ -110,6 +176,8 @@ fi
|
|||||||
# e<TAB><plugin dir><TAB><message> zero or more — the plugin's facts are unusable
|
# e<TAB><plugin dir><TAB><message> zero or more — the plugin's facts are unusable
|
||||||
# a<TAB>present|absent exactly once — is executables.allow a mapping?
|
# a<TAB>present|absent exactly once — is executables.allow a mapping?
|
||||||
# k<TAB><allow key> zero or more
|
# k<TAB><allow key> zero or more
|
||||||
|
# d<TAB><path><TAB><git url> zero or more — a root dependencies.apm entry
|
||||||
|
# carrying both git: and path:
|
||||||
#
|
#
|
||||||
# python3 + PyYAML is preferred where importable; the fallback below is not a
|
# python3 + PyYAML is preferred where importable; the fallback below is not a
|
||||||
# YAML parser, it recognises only the shapes these manifests use. PyYAML stays
|
# YAML parser, it recognises only the shapes these manifests use. PyYAML stays
|
||||||
@@ -167,6 +235,14 @@ if isinstance(allow, dict):
|
|||||||
print("k\t%s" % key)
|
print("k\t%s" % key)
|
||||||
else:
|
else:
|
||||||
print("a\tabsent")
|
print("a\tabsent")
|
||||||
|
|
||||||
|
dependencies = root.get("dependencies")
|
||||||
|
apm_deps = dependencies.get("apm") if isinstance(dependencies, dict) else None
|
||||||
|
for entry in apm_deps if isinstance(apm_deps, list) else []:
|
||||||
|
if isinstance(entry, dict):
|
||||||
|
git, path = entry.get("git"), entry.get("path")
|
||||||
|
if isinstance(git, str) and isinstance(path, str):
|
||||||
|
print("d\t%s\t%s" % (path, git))
|
||||||
PY
|
PY
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,6 +269,16 @@ top_level_scalar() {
|
|||||||
|
|
||||||
read_facts_bash() {
|
read_facts_bash() {
|
||||||
local line allow_state="absent" in_executables=0 in_allow=0 key plugin manifest
|
local line allow_state="absent" in_executables=0 in_allow=0 key plugin manifest
|
||||||
|
local in_deps=0 in_apm_deps=0 dep_git="" dep_path=""
|
||||||
|
|
||||||
|
# Emits the dependency entry collected so far, if it carried both fields.
|
||||||
|
flush_dep() {
|
||||||
|
if [[ -n "$dep_git" && -n "$dep_path" ]]; then
|
||||||
|
printf 'd\t%s\t%s\n' "$dep_path" "$dep_git"
|
||||||
|
fi
|
||||||
|
dep_git=""
|
||||||
|
dep_path=""
|
||||||
|
}
|
||||||
|
|
||||||
for plugin in ${READABLE[@]+"${READABLE[@]}"}; do
|
for plugin in ${READABLE[@]+"${READABLE[@]}"}; do
|
||||||
manifest="$REPO_ROOT/plugins/$plugin/apm.yml"
|
manifest="$REPO_ROOT/plugins/$plugin/apm.yml"
|
||||||
@@ -208,12 +294,38 @@ read_facts_bash() {
|
|||||||
# A top-level key (column 0) closes whatever block was open. Checked before
|
# A top-level key (column 0) closes whatever block was open. Checked before
|
||||||
# anything else so `marketplace:` after `executables:` cannot leak keys in.
|
# anything else so `marketplace:` after `executables:` cannot leak keys in.
|
||||||
if [[ "$line" != [[:space:]]* ]]; then
|
if [[ "$line" != [[:space:]]* ]]; then
|
||||||
if [[ "$line" == executables:* ]]; then
|
flush_dep
|
||||||
in_executables=1
|
in_executables=0
|
||||||
else
|
in_deps=0
|
||||||
in_executables=0
|
case "$line" in
|
||||||
fi
|
executables:*) in_executables=1 ;;
|
||||||
|
dependencies:*) in_deps=1 ;;
|
||||||
|
esac
|
||||||
in_allow=0
|
in_allow=0
|
||||||
|
in_apm_deps=0
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
# dependencies: -> apm: -> a list of `- git: ...` / ` path: ...` items at
|
||||||
|
# 4-space indent, fields at 6 (or on the dash line itself).
|
||||||
|
if [[ $in_deps -eq 1 ]]; then
|
||||||
|
if [[ "$line" =~ ^\ \ [^[:space:]#] ]]; then
|
||||||
|
flush_dep
|
||||||
|
in_apm_deps=0
|
||||||
|
[[ "$line" =~ ^\ \ apm: ]] && in_apm_deps=1
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
[[ $in_apm_deps -eq 1 ]] || continue
|
||||||
|
if [[ "$line" =~ ^\ \ \ \ -\ * ]]; then
|
||||||
|
flush_dep
|
||||||
|
line=" ${line#*- }"
|
||||||
|
fi
|
||||||
|
if [[ "$line" =~ ^\ \ \ \ \ \ (git|path):(.*)$ ]]; then
|
||||||
|
if [[ "${BASH_REMATCH[1]}" == git ]]; then
|
||||||
|
dep_git="$(unquote "${BASH_REMATCH[2]}")"
|
||||||
|
else
|
||||||
|
dep_path="$(unquote "${BASH_REMATCH[2]}")"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
[[ $in_executables -eq 1 ]] || continue
|
[[ $in_executables -eq 1 ]] || continue
|
||||||
@@ -236,6 +348,7 @@ read_facts_bash() {
|
|||||||
printf 'k\t%s\n' "$key"
|
printf 'k\t%s\n' "$key"
|
||||||
fi
|
fi
|
||||||
done < "$ROOT_MANIFEST"
|
done < "$ROOT_MANIFEST"
|
||||||
|
flush_dep
|
||||||
|
|
||||||
printf 'a\t%s\n' "$allow_state"
|
printf 'a\t%s\n' "$allow_state"
|
||||||
}
|
}
|
||||||
@@ -263,11 +376,69 @@ fact() {
|
|||||||
ALLOW_STATE="$(printf '%s\n' "$FACTS" | sed -n 's/^a\t//p')"
|
ALLOW_STATE="$(printf '%s\n' "$FACTS" | sed -n 's/^a\t//p')"
|
||||||
ALLOW_KEYS="$(printf '%s\n' "$FACTS" | sed -n 's/^k\t//p')"
|
ALLOW_KEYS="$(printf '%s\n' "$FACTS" | sed -n 's/^k\t//p')"
|
||||||
|
|
||||||
|
# Strips one leading ./ and any trailing / from a dependency path.
|
||||||
|
norm_path() {
|
||||||
|
local path="${1#./}"
|
||||||
|
printf '%s' "${path%/}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# dep_url <plugin dir> — the git: URL of root apm.yml's git+path dependency
|
||||||
|
# entry for plugins/<plugin dir>; empty when it has none.
|
||||||
|
dep_url() {
|
||||||
|
local want="plugins/$1" tag path url
|
||||||
|
while IFS=$'\t' read -r tag path url; do
|
||||||
|
[[ "$tag" == d && "$(norm_path "$path")" == "$want" ]] || continue
|
||||||
|
printf '%s' "$url"
|
||||||
|
return
|
||||||
|
done <<< "$FACTS"
|
||||||
|
}
|
||||||
|
|
||||||
|
# url_has_port <url> — true when a scheme URL names a port (host:port).
|
||||||
|
url_has_port() {
|
||||||
|
local rest
|
||||||
|
[[ "$1" == *://* ]] || return 1
|
||||||
|
rest="${1#*://}"
|
||||||
|
rest="${rest%%/*}"
|
||||||
|
rest="${rest#*@}"
|
||||||
|
[[ "$rest" == *:* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
# identity <plugin dir> — <host>/<owner>/<repo>/<path> from that entry; empty
|
||||||
|
# when there is none.
|
||||||
|
#
|
||||||
|
# Verified against apm 0.39.3 (`apm approve --list`) for an https URL on a
|
||||||
|
# lowercase host only. The scp-like (user@host:owner/repo) and ssh:// forms are
|
||||||
|
# derived by the same rule but were not checked against apm, and the host's
|
||||||
|
# case is kept as written, also unchecked. A URL with a port is refused before
|
||||||
|
# this runs (see the per-package checks): where apm puts a port in the
|
||||||
|
# identity is unknown, so a derived key could be wrong while looking right.
|
||||||
|
identity() {
|
||||||
|
local want="plugins/$1" url
|
||||||
|
url="$(dep_url "$1")"
|
||||||
|
[[ -n "$url" ]] || return 0
|
||||||
|
if [[ "$url" == *://* ]]; then
|
||||||
|
url="${url#*://}"
|
||||||
|
elif [[ "$url" == *:* ]]; then
|
||||||
|
url="${url/://}" # scp-like user@host:owner/repo
|
||||||
|
fi
|
||||||
|
url="${url#*@}"
|
||||||
|
url="${url%/}"
|
||||||
|
url="${url%.git}"
|
||||||
|
printf '%s/%s' "$url" "$want"
|
||||||
|
}
|
||||||
|
|
||||||
|
# expected_key <plugin dir> — '<identity>#<version>'.
|
||||||
|
expected_key() {
|
||||||
|
printf '%s#%s' "$(identity "$1")" "$(fact v "$1")"
|
||||||
|
}
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Per-package checks
|
# Per-package checks
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# EXPECTED: plugin dir names whose manifest is usable; the key each needs is
|
# EXPECTED: plugin dir names whose manifest is usable; the key each needs is
|
||||||
# '<dir>#<version>' because a usable manifest's name: equals its dir name.
|
# '<identity>#<version>'. The dir name is what finds the identity: it is
|
||||||
|
# matched against the `path: plugins/<dir>` of a root dependency entry, which
|
||||||
|
# is why a usable manifest's name: must equal it.
|
||||||
EXPECTED=()
|
EXPECTED=()
|
||||||
for plugin in ${READABLE[@]+"${READABLE[@]}"}; do
|
for plugin in ${READABLE[@]+"${READABLE[@]}"}; do
|
||||||
error="$(fact e "$plugin")"
|
error="$(fact e "$plugin")"
|
||||||
@@ -285,8 +456,9 @@ for plugin in ${READABLE[@]+"${READABLE[@]}"}; do
|
|||||||
|
|
||||||
if [[ "$name" != "$plugin" ]]; then
|
if [[ "$name" != "$plugin" ]]; then
|
||||||
echo "FAIL: plugins/$plugin/apm.yml declares name: '${name}', which does not match its directory '$plugin'." >&2
|
echo "FAIL: plugins/$plugin/apm.yml declares name: '${name}', which does not match its directory '$plugin'." >&2
|
||||||
echo " Why: executables.allow keys use the package name; with the two disagreeing this gate" >&2
|
echo " Why: the '<identity>#<version>' key is found through the directory name, which this gate" >&2
|
||||||
echo " cannot tell which '<name>#<version>' key root apm.yml should carry." >&2
|
echo " matches against root apm.yml's 'path: plugins/<dir>' entry; with name: disagreeing" >&2
|
||||||
|
echo " it cannot tell which package the key should be for." >&2
|
||||||
echo " Fix: make plugins/$plugin/apm.yml's name: equal '$plugin', or rename the directory (read by $READER)." >&2
|
echo " Fix: make plugins/$plugin/apm.yml's name: equal '$plugin', or rename the directory (read by $READER)." >&2
|
||||||
FAILED=1
|
FAILED=1
|
||||||
continue
|
continue
|
||||||
@@ -294,20 +466,42 @@ for plugin in ${READABLE[@]+"${READABLE[@]}"}; do
|
|||||||
|
|
||||||
if [[ -z "$version" ]]; then
|
if [[ -z "$version" ]]; then
|
||||||
echo "FAIL: plugins/$plugin/apm.yml declares no version:, so no allow key can be checked against it." >&2
|
echo "FAIL: plugins/$plugin/apm.yml declares no version:, so no allow key can be checked against it." >&2
|
||||||
echo " Why: the executables.allow key is '<package>#<version>'; with no version there is" >&2
|
echo " Why: the executables.allow key is '<identity>#<version>'; with no version there is" >&2
|
||||||
echo " nothing for root apm.yml's key to stay in sync with." >&2
|
echo " nothing for root apm.yml's key to stay in sync with." >&2
|
||||||
echo " Fix: give plugins/$plugin/apm.yml a top-level version: (read by $READER)." >&2
|
echo " Fix: give plugins/$plugin/apm.yml a top-level version: (read by $READER)." >&2
|
||||||
FAILED=1
|
FAILED=1
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -z "$(identity "$plugin")" ]]; then
|
||||||
|
echo "FAIL: root apm.yml has no dependencies.apm entry with git: and path: plugins/$plugin, so the" >&2
|
||||||
|
echo " identity apm approves $plugin's $(ships "$plugin") under cannot be derived." >&2
|
||||||
|
echo " Why: apm 0.39 matches executables.allow on the full identity <host>/<owner>/<repo>/<path>," >&2
|
||||||
|
echo " built from that entry; this gate builds the expected key from the same fields." >&2
|
||||||
|
echo " Fix: declare plugins/$plugin in root apm.yml as a '- git: <url>' / 'path: plugins/$plugin'" >&2
|
||||||
|
echo " dependency (read by $READER)." >&2
|
||||||
|
FAILED=1
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if url_has_port "$(dep_url "$plugin")"; then
|
||||||
|
echo "FAIL: root apm.yml's dependency entry for plugins/$plugin uses a git: URL with a port," >&2
|
||||||
|
echo " '$(dep_url "$plugin")', so its executables.allow key cannot be derived reliably." >&2
|
||||||
|
echo " Why: this gate derives the full package identity apm 0.39 approves under from that URL," >&2
|
||||||
|
echo " and how apm writes a port into the identity was never verified." >&2
|
||||||
|
echo " Fix: use the URL without a port if the host allows it; otherwise read the identity from" >&2
|
||||||
|
echo " 'uv run --frozen apm approve --list' and extend this check to match it." >&2
|
||||||
|
FAILED=1
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
EXPECTED+=("$plugin")
|
EXPECTED+=("$plugin")
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ ${#EXPECTED[@]} -gt 0 && "$ALLOW_STATE" != "present" ]]; then
|
if [[ ${#EXPECTED[@]} -gt 0 && "$ALLOW_STATE" != "present" ]]; then
|
||||||
summary=""
|
summary=""
|
||||||
for plugin in ${EXPECTED[@]+"${EXPECTED[@]}"}; do
|
for plugin in ${EXPECTED[@]+"${EXPECTED[@]}"}; do
|
||||||
summary+="${summary:+, }$plugin#$(fact v "$plugin")"
|
summary+="${summary:+, }$(expected_key "$plugin")"
|
||||||
done
|
done
|
||||||
echo "FAIL: root apm.yml has no executables.allow mapping, but these packages ship executables: $summary." >&2
|
echo "FAIL: root apm.yml has no executables.allow mapping, but these packages ship executables: $summary." >&2
|
||||||
echo " Why: without an allow entry apm refuses to deploy a package's hooks/ and bin/ — for" >&2
|
echo " Why: without an allow entry apm refuses to deploy a package's hooks/ and bin/ — for" >&2
|
||||||
@@ -317,7 +511,7 @@ if [[ ${#EXPECTED[@]} -gt 0 && "$ALLOW_STATE" != "present" ]]; then
|
|||||||
echo " executables:" >&2
|
echo " executables:" >&2
|
||||||
echo " allow:" >&2
|
echo " allow:" >&2
|
||||||
for plugin in ${EXPECTED[@]+"${EXPECTED[@]}"}; do
|
for plugin in ${EXPECTED[@]+"${EXPECTED[@]}"}; do
|
||||||
echo " $plugin#$(fact v "$plugin"):" >&2
|
echo " $(expected_key "$plugin"):" >&2
|
||||||
if [[ -d "$REPO_ROOT/plugins/$plugin/.apm/hooks" ]]; then echo " hooks: true" >&2; fi
|
if [[ -d "$REPO_ROOT/plugins/$plugin/.apm/hooks" ]]; then echo " hooks: true" >&2; fi
|
||||||
if [[ -d "$REPO_ROOT/plugins/$plugin/bin" ]]; then echo " bin: true" >&2; fi
|
if [[ -d "$REPO_ROOT/plugins/$plugin/bin" ]]; then echo " bin: true" >&2; fi
|
||||||
done
|
done
|
||||||
@@ -325,18 +519,30 @@ if [[ ${#EXPECTED[@]} -gt 0 && "$ALLOW_STATE" != "present" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
for plugin in ${EXPECTED[@]+"${EXPECTED[@]}"}; do
|
for plugin in ${EXPECTED[@]+"${EXPECTED[@]}"}; do
|
||||||
expected_key="$plugin#$(fact v "$plugin")"
|
expected_key="$(expected_key "$plugin")"
|
||||||
if grep -qxF -- "$expected_key" <<< "$ALLOW_KEYS"; then
|
if grep -qxF -- "$expected_key" <<< "$ALLOW_KEYS"; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Keys for the right identity at another version, and bare '<name>#...' keys,
|
||||||
|
# which apm 0.28 matched and 0.39 does not.
|
||||||
stale_keys=()
|
stale_keys=()
|
||||||
|
bare_keys=()
|
||||||
while IFS= read -r key; do
|
while IFS= read -r key; do
|
||||||
if [[ -n "$key" && "$key" == "$plugin#"* ]]; then stale_keys+=("$key"); fi
|
[[ -n "$key" ]] || continue
|
||||||
|
if [[ "$key" == "$(identity "$plugin")#"* ]]; then stale_keys+=("$key"); fi
|
||||||
|
if [[ "$key" == "$plugin" || "$key" == "$plugin#"* ]]; then bare_keys+=("$key"); fi
|
||||||
done <<< "$ALLOW_KEYS"
|
done <<< "$ALLOW_KEYS"
|
||||||
|
|
||||||
echo "FAIL: root apm.yml's executables.allow has no '$expected_key' key, but that is $plugin's version." >&2
|
echo "FAIL: root apm.yml's executables.allow has no '$expected_key' key, but that is $plugin's identity and version." >&2
|
||||||
if [[ ${#stale_keys[@]} -gt 0 ]]; then
|
if [[ ${#bare_keys[@]} -gt 0 ]]; then
|
||||||
|
echo " Found instead:" >&2
|
||||||
|
printf ' %s\n' ${bare_keys[@]+"${bare_keys[@]}"} ${stale_keys[@]+"${stale_keys[@]}"} >&2
|
||||||
|
echo " Why: apm 0.39 matches grants on the full package identity. A bare '$plugin#...' key" >&2
|
||||||
|
echo " matches nothing, so $plugin's $(ships "$plugin") are parked, .claude/settings.json" >&2
|
||||||
|
echo " loses its entries, and root 'apm audit --ci' still passes (spike #269, on #268)." >&2
|
||||||
|
echo " Fix: rename the key in root apm.yml to '$expected_key:'." >&2
|
||||||
|
elif [[ ${#stale_keys[@]} -gt 0 ]]; then
|
||||||
echo " Found instead:" >&2
|
echo " Found instead:" >&2
|
||||||
printf ' %s\n' ${stale_keys[@]+"${stale_keys[@]}"} >&2
|
printf ' %s\n' ${stale_keys[@]+"${stale_keys[@]}"} >&2
|
||||||
echo " Why: nothing is broken right now — apm's grant is version-blind, so a key naming another" >&2
|
echo " Why: nothing is broken right now — apm's grant is version-blind, so a key naming another" >&2
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# The one place this repo spells how its scripts run apm (ADR-0034).
|
||||||
|
#
|
||||||
|
# Source it, call `require_apm_version || exit 1` once, then run apm as
|
||||||
|
# `run_apm <args>`. Sourcing also applies scripts/lib/clean-git-env.sh, so every
|
||||||
|
# gate that reaches apm through this helper runs it with git's repo-locating env
|
||||||
|
# scrubbed (issue #204).
|
||||||
|
#
|
||||||
|
# THE COMMAND
|
||||||
|
#
|
||||||
|
# uv run --project <repo root> --frozen apm
|
||||||
|
#
|
||||||
|
# * The pin is the dev group in the root pyproject.toml, locked by uv.lock. A
|
||||||
|
# bare `apm` would be whatever is on PATH, which on this machine is the global
|
||||||
|
# pipx 0.28.0 that refuses the v4 apm.lock.yaml (ADR-0034, consequence 1).
|
||||||
|
# * --project is the repo root, derived from this file's own location, never
|
||||||
|
# from the cwd. apm-audit-ci.sh runs apm from inside each plugins/<name>/, and
|
||||||
|
# uv's project discovery would otherwise start there. --project does not
|
||||||
|
# change the cwd, so apm still reads the manifest of the directory it runs in.
|
||||||
|
# * --frozen runs from uv.lock as committed and never re-resolves it. It does
|
||||||
|
# still sync the environment to that lock before running, and that is
|
||||||
|
# deliberate for gates, unlike the SessionStart hook, which adds --no-sync
|
||||||
|
# --offline (ADR-0034's 2026-12-02 amendment). A gate runs after the one-time
|
||||||
|
# `uv sync --frozen`, where that sync is a no-op that needs no network; and if
|
||||||
|
# the pin moves (a pull that bumps apm-cli), the sync brings the environment
|
||||||
|
# to the new pin instead of letting the gate certify the tree with a stale
|
||||||
|
# apm. The hook cannot afford that sync inside its timeout; a push gate can.
|
||||||
|
#
|
||||||
|
# APM overrides the command, as a seam for tests (ADR-0034, "Invocation"). It is
|
||||||
|
# split on whitespace, so it can name a stub or a full command line. The
|
||||||
|
# minimum-version check applies to it too, and an APM that holds only
|
||||||
|
# whitespace fails that check rather than silently running the default.
|
||||||
|
#
|
||||||
|
# Not meant to be executed directly.
|
||||||
|
|
||||||
|
# shellcheck source=scripts/lib/clean-git-env.sh
|
||||||
|
source "$(dirname "${BASH_SOURCE[0]}")/clean-git-env.sh"
|
||||||
|
|
||||||
|
APM_REPO_ROOT="$(CDPATH='' cd -- "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||||
|
# 0.39.2 is the lowest apm that reads and writes lockfile v4 in a form later
|
||||||
|
# versions accept, and it is above 0.39.0, which keeps Claude command keys such
|
||||||
|
# as disable-model-invocation (ADR-0034, "Minimum version").
|
||||||
|
APM_MIN_VERSION="0.39.2"
|
||||||
|
|
||||||
|
APM_CMD=()
|
||||||
|
if [[ -n "${APM:-}" ]]; then
|
||||||
|
read -r -a APM_CMD <<<"$APM"
|
||||||
|
else
|
||||||
|
APM_CMD=(uv run --project "$APM_REPO_ROOT" --frozen apm)
|
||||||
|
fi
|
||||||
|
|
||||||
|
run_apm() {
|
||||||
|
${APM_CMD[@]+"${APM_CMD[@]}"} "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Fails, with a message naming the fix, when the apm this helper resolves is
|
||||||
|
# missing, unreadable, or below APM_MIN_VERSION. Returns 0 when it is new enough.
|
||||||
|
require_apm_version() {
|
||||||
|
local output version stderr_file
|
||||||
|
if [[ ${#APM_CMD[@]} -eq 0 ]]; then
|
||||||
|
echo "FAIL: APM is set but holds only whitespace, so there is no apm command to run." >&2
|
||||||
|
echo " Fix: unset APM to run the repo-pinned apm, or set it to a command." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if [[ -z "${APM:-}" ]] && ! command -v uv >/dev/null 2>&1; then
|
||||||
|
echo "FAIL: uv is not on PATH, and this repo runs apm as 'uv run --frozen apm' (ADR-0034)." >&2
|
||||||
|
echo " Fix: install uv, then run 'uv sync --frozen' at the repo root." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
# stdout only. uv writes its own lines to stderr when `uv run` syncs first
|
||||||
|
# (`Using CPython 3.14.6`, `Installed 62 packages`), and a merged stream
|
||||||
|
# would hand the parser uv's numbers instead of apm's. stderr is kept aside
|
||||||
|
# and shown only when the check fails.
|
||||||
|
stderr_file="$(mktemp)"
|
||||||
|
if ! output="$(run_apm --version 2>"$stderr_file")"; then
|
||||||
|
cat "$stderr_file" >&2
|
||||||
|
printf '%s\n' "$output" >&2
|
||||||
|
rm -f "$stderr_file"
|
||||||
|
echo "FAIL: could not run '${APM_CMD[*]} --version', so the apm version is unknown." >&2
|
||||||
|
echo " Fix: run 'uv sync --frozen' at the repo root, then retry." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
# Anchored to apm's banner, `Agent Package Manager (APM) CLI version X.Y.Z`,
|
||||||
|
# so no other version-like text on stdout can be taken for apm's version.
|
||||||
|
version="$(grep -oE 'CLI version [0-9]+\.[0-9]+\.[0-9]+' <<<"$output" | head -n 1 || true)"
|
||||||
|
version="${version#CLI version }"
|
||||||
|
if [[ ! "$version" =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
|
||||||
|
cat "$stderr_file" >&2
|
||||||
|
rm -f "$stderr_file"
|
||||||
|
echo "FAIL: '${APM_CMD[*]} --version' printed no 'CLI version X.Y.Z' banner, so the apm version is unknown." >&2
|
||||||
|
echo " Fix: run 'uv sync --frozen' at the repo root, then retry." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
rm -f "$stderr_file"
|
||||||
|
local -a have=("${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" "${BASH_REMATCH[3]}")
|
||||||
|
local -a need
|
||||||
|
IFS=. read -r -a need <<<"$APM_MIN_VERSION"
|
||||||
|
local i
|
||||||
|
for i in 0 1 2; do
|
||||||
|
((10#${have[i]} > 10#${need[i]})) && return 0
|
||||||
|
if ((10#${have[i]} < 10#${need[i]})); then
|
||||||
|
echo "FAIL: apm $version is below $APM_MIN_VERSION, the minimum this repo needs (ADR-0034)." >&2
|
||||||
|
echo " Why: apm before 0.39.2 cannot read this repo's lockfile v4 apm.lock.yaml in a form" >&2
|
||||||
|
echo " later versions accept, and before 0.39.0 it drops Claude command keys." >&2
|
||||||
|
echo " Fix: run 'uv sync --frozen' at the repo root so '${APM_CMD[*]}' resolves the pinned apm." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return 0
|
||||||
|
}
|
||||||
@@ -773,12 +773,29 @@ echo "--- the greped phrase, against the real apm ---"
|
|||||||
# The genuine output is then replayed into the real hook through the mock, so
|
# The genuine output is then replayed into the real hook through the mock, so
|
||||||
# what is asserted is the hook's own matching logic against real apm text —
|
# what is asserted is the hook's own matching logic against real apm text —
|
||||||
# no pattern is duplicated here to drift out of sync.
|
# no pattern is duplicated here to drift out of sync.
|
||||||
|
#
|
||||||
|
# "The real apm" is this repo's pinned one, run through scripts/lib/apm.sh as
|
||||||
|
# `uv run --project <repo root> --frozen apm` (ADR-0034), never whatever apm is
|
||||||
|
# on PATH: that may be an older global install whose wording is not what this
|
||||||
|
# repo ships against. Sourced in a subshell so the helper's git-env scrub and
|
||||||
|
# its functions stay out of this suite's shell. The probe is skipped only when
|
||||||
|
# that apm cannot be run at all (no uv, or `uv sync --frozen` never ran).
|
||||||
|
probe_apm() {
|
||||||
|
(
|
||||||
|
# shellcheck source=scripts/lib/apm.sh
|
||||||
|
source "$REPO_ROOT/scripts/lib/apm.sh"
|
||||||
|
run_apm "$@"
|
||||||
|
)
|
||||||
|
}
|
||||||
SKIP_REASON=""
|
SKIP_REASON=""
|
||||||
if ! command -v apm > /dev/null 2>&1 || ! command -v git > /dev/null 2>&1; then
|
if ! command -v git > /dev/null 2>&1 \
|
||||||
SKIP_REASON="SKIP: apm and git are both required to verify the hook's phrase match against real \`apm outdated\` output — everything above ran, this axis did not"
|
|| ! ( source "$REPO_ROOT/scripts/lib/apm.sh" && require_apm_version ) > /dev/null 2>&1; then
|
||||||
|
SKIP_REASON="SKIP: git and the repo-pinned apm (uv sync --frozen) are both required to verify the hook's phrase match against real \`apm outdated\` output — everything above ran, this axis did not"
|
||||||
echo " $SKIP_REASON"
|
echo " $SKIP_REASON"
|
||||||
else
|
else
|
||||||
PROBE="$(mktemp -d)"
|
PROBE="$(mktemp -d)"
|
||||||
|
UV_REAL_CACHE="${UV_CACHE_DIR:-$(uv cache dir 2> /dev/null || true)}"
|
||||||
|
UV_REAL_PYTHONS="${UV_PYTHON_INSTALL_DIR:-$(uv python dir 2> /dev/null || true)}"
|
||||||
trap 'rm -rf "$FAKE_BIN" "$WORK" "$TOOLS" "$UV_BIN" "$PIN_BIN" "$PATH_APM_BIN" "$PINNED" "$PROBE"' EXIT
|
trap 'rm -rf "$FAKE_BIN" "$WORK" "$TOOLS" "$UV_BIN" "$PIN_BIN" "$PATH_APM_BIN" "$PINNED" "$PROBE"' EXIT
|
||||||
|
|
||||||
UPSTREAM="$PROBE/upstream.git"
|
UPSTREAM="$PROBE/upstream.git"
|
||||||
@@ -821,13 +838,21 @@ else
|
|||||||
done
|
done
|
||||||
echo "deployments: []"
|
echo "deployments: []"
|
||||||
} > "$PROBE/consumer/apm.lock.yaml"
|
} > "$PROBE/consumer/apm.lock.yaml"
|
||||||
|
# env cannot run a shell function, so probe_apm is re-declared in a child bash.
|
||||||
|
# HOME moves to an empty dir, so uv's cache and its managed Pythons (both
|
||||||
|
# under HOME by default) are pinned to the real ones resolved before the
|
||||||
|
# move, and UV_OFFLINE forbids any fetch: the probe runs the already-synced
|
||||||
|
# pin and never needs the network.
|
||||||
(
|
(
|
||||||
cd "$PROBE/consumer" &&
|
cd "$PROBE/consumer" &&
|
||||||
env HOME="$PROBE/home" \
|
env HOME="$PROBE/home" \
|
||||||
|
UV_CACHE_DIR="$UV_REAL_CACHE" \
|
||||||
|
UV_PYTHON_INSTALL_DIR="$UV_REAL_PYTHONS" \
|
||||||
|
UV_OFFLINE=1 \
|
||||||
GIT_CONFIG_GLOBAL="$PROBE/gitconfig" \
|
GIT_CONFIG_GLOBAL="$PROBE/gitconfig" \
|
||||||
GIT_CONFIG_NOSYSTEM=1 \
|
GIT_CONFIG_NOSYSTEM=1 \
|
||||||
GIT_TERMINAL_PROMPT=0 \
|
GIT_TERMINAL_PROMPT=0 \
|
||||||
apm outdated 2>&1
|
bash -c "$(declare -f probe_apm); REPO_ROOT=\"\$1\"; probe_apm outdated" _ "$REPO_ROOT" 2>&1
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Executable
+234
@@ -0,0 +1,234 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Tests how the apm pre-push gates invoke apm (ADR-0034, issue #271).
|
||||||
|
#
|
||||||
|
# Seam B: a fake `uv` and a stub `apm` sit first on a PATH that excludes the
|
||||||
|
# machine's real uv and any global apm. The fake uv records its cwd, its argv
|
||||||
|
# and the GIT_DIR it inherited, accepts only the `run --project <root> --frozen
|
||||||
|
# apm ...` shape, and hands the rest to the stub. The stub answers --version
|
||||||
|
# with $STUB_APM_VERSION and records every other call. Nothing here runs a real
|
||||||
|
# apm or touches the repo this suite lives in.
|
||||||
|
#
|
||||||
|
# It proves, for both scripts/apm-audit-ci.sh and scripts/apm-pack-check-clean.sh:
|
||||||
|
# * the command is `uv run --project <repo root> --frozen apm`, and --project
|
||||||
|
# names the repo root even when apm runs from a plugin directory;
|
||||||
|
# * git's repo-locating env is still scrubbed before apm runs (issue #204);
|
||||||
|
# * an apm below 0.39.2 fails with a clear message before any gate work runs.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
|
AUDIT="$REPO_ROOT/scripts/apm-audit-ci.sh"
|
||||||
|
PACK="$REPO_ROOT/scripts/apm-pack-check-clean.sh"
|
||||||
|
PASS=0
|
||||||
|
FAIL=0
|
||||||
|
|
||||||
|
pass() { echo " PASS: $1"; PASS=$((PASS + 1)); }
|
||||||
|
fail() { echo " FAIL: $1"; FAIL=$((FAIL + 1)); }
|
||||||
|
|
||||||
|
# The test must never inherit an override or the caller's repo.
|
||||||
|
unset APM GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_OBJECT_DIRECTORY GIT_COMMON_DIR
|
||||||
|
|
||||||
|
TMP="$(mktemp -d)"
|
||||||
|
trap 'rm -rf "$TMP"' EXIT
|
||||||
|
|
||||||
|
BIN="$TMP/bin"
|
||||||
|
mkdir -p "$BIN"
|
||||||
|
UV_LOG="$TMP/uv.log"
|
||||||
|
APM_LOG="$TMP/apm.log"
|
||||||
|
|
||||||
|
cat > "$BIN/uv" << EOF
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
{
|
||||||
|
printf 'cwd=%s\n' "\$PWD"
|
||||||
|
printf 'git_dir=%s\n' "\${GIT_DIR-<unset>}"
|
||||||
|
printf 'git_work_tree=%s\n' "\${GIT_WORK_TREE-<unset>}"
|
||||||
|
printf 'argv=%s\n' "\$*"
|
||||||
|
} >> "$UV_LOG"
|
||||||
|
if [[ "\${1:-}" != run || "\${2:-}" != --project || "\${4:-}" != --frozen || "\${5:-}" != apm ]]; then
|
||||||
|
echo "fake uv: unexpected argv: \$*" >&2
|
||||||
|
exit 97
|
||||||
|
fi
|
||||||
|
shift 5
|
||||||
|
# What a real \`uv run --frozen\` prints on stderr when it syncs first, plus a
|
||||||
|
# decoy shaped exactly like apm's banner. The version check must parse apm's
|
||||||
|
# stdout only: a parser reading the merged stream takes 0.0.1 from the decoy
|
||||||
|
# and fails a current apm (review rounds 1 and 2 of #271).
|
||||||
|
echo "Using CPython 3.14.6" >&2
|
||||||
|
echo "uv CLI version 0.0.1" >&2
|
||||||
|
exec "$BIN/apm" "\$@"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat > "$BIN/apm" << EOF
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
if [[ "\${1:-}" == --version ]]; then
|
||||||
|
printf '%s\n' "\${STUB_APM_OUTPUT:-Agent Package Manager (APM) CLI version \${STUB_APM_VERSION:-0.39.3}}"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
printf 'cwd=%s args=%s\n' "\$PWD" "\$*" >> "$APM_LOG"
|
||||||
|
exit 0
|
||||||
|
EOF
|
||||||
|
chmod +x "$BIN/uv" "$BIN/apm"
|
||||||
|
|
||||||
|
# A PATH with the fakes first and only system directories after them: no
|
||||||
|
# /usr/local/bin (the real uv) and no ~/.local/bin (the global pipx apm).
|
||||||
|
FAKE_PATH="$BIN:/usr/bin:/bin"
|
||||||
|
NO_UV_PATH="/usr/bin:/bin"
|
||||||
|
for tool in uv apm; do
|
||||||
|
if PATH="$NO_UV_PATH" command -v "$tool" > /dev/null 2>&1; then
|
||||||
|
echo "SKIP: a real $tool is on $NO_UV_PATH, so the fake cannot be isolated"
|
||||||
|
exit 77
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# A fixture tree for apm-audit-ci.sh's per-manifest loop: a root and one
|
||||||
|
# plugin package. The script iterates `. plugins/*/` relative to its cwd.
|
||||||
|
FIXTURE="$TMP/fixture"
|
||||||
|
mkdir -p "$FIXTURE/plugins/demo"
|
||||||
|
|
||||||
|
reset_logs() { : > "$UV_LOG"; : > "$APM_LOG"; }
|
||||||
|
|
||||||
|
# run_gate <cwd> <script> [VAR=value ...] — sets RC and OUT (stdout+stderr).
|
||||||
|
RC=0
|
||||||
|
OUT=""
|
||||||
|
run_gate() {
|
||||||
|
local cwd="$1" script="$2"
|
||||||
|
shift 2
|
||||||
|
RC=0
|
||||||
|
OUT="$(cd "$cwd" && env PATH="$FAKE_PATH" "$@" bash "$script" 2>&1)" || RC=$?
|
||||||
|
}
|
||||||
|
|
||||||
|
# Every uv call names the repo root as --project and uses --frozen.
|
||||||
|
check_project_root() {
|
||||||
|
local label="$1" n bad
|
||||||
|
n="$(grep -c '^argv=' "$UV_LOG" || true)"
|
||||||
|
if [[ "$n" -eq 0 ]]; then
|
||||||
|
fail "$label: uv was never called"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
bad="$(grep '^argv=' "$UV_LOG" | grep -vF "argv=run --project $REPO_ROOT --frozen apm " || true)"
|
||||||
|
if [[ -z "$bad" ]]; then
|
||||||
|
pass "$label: all $n uv call(s) are 'run --project <repo root> --frozen apm'"
|
||||||
|
else
|
||||||
|
fail "$label: uv called with another shape: $bad"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "--- apm-pack-check-clean: the command, run from a plugin directory ---"
|
||||||
|
reset_logs
|
||||||
|
run_gate "$REPO_ROOT/plugins/kyberforge" "$PACK"
|
||||||
|
[[ $RC -eq 0 ]] && pass "exits 0 when the pinned apm passes" || fail "exited $RC: $OUT"
|
||||||
|
check_project_root "apm-pack-check-clean from plugins/kyberforge"
|
||||||
|
grep -qxF "cwd=$REPO_ROOT/plugins/kyberforge args=pack --check-versions --check-clean --dry-run" "$APM_LOG" \
|
||||||
|
&& pass "runs 'pack --check-versions --check-clean --dry-run' in the caller's cwd" \
|
||||||
|
|| fail "unexpected apm calls: $(cat "$APM_LOG")"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "--- apm-audit-ci: --project stays the repo root inside each plugin dir ---"
|
||||||
|
reset_logs
|
||||||
|
run_gate "$FIXTURE" "$AUDIT"
|
||||||
|
[[ $RC -eq 0 ]] && pass "exits 0 when every audit passes" || fail "exited $RC: $OUT"
|
||||||
|
check_project_root "apm-audit-ci"
|
||||||
|
grep -qxF "cwd=$FIXTURE/plugins/demo args=audit --ci" "$APM_LOG" \
|
||||||
|
&& pass "audits plugins/demo from inside that directory" \
|
||||||
|
|| fail "no audit ran in plugins/demo: $(cat "$APM_LOG")"
|
||||||
|
grep -qxF "cwd=$FIXTURE args=audit --ci" "$APM_LOG" \
|
||||||
|
&& pass "audits the root manifest" || fail "no root audit: $(cat "$APM_LOG")"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "--- the git-env scrub still applies ---"
|
||||||
|
for pair in "apm-audit-ci:$AUDIT" "apm-pack-check-clean:$PACK"; do
|
||||||
|
label="${pair%%:*}"
|
||||||
|
script="${pair#*:}"
|
||||||
|
reset_logs
|
||||||
|
run_gate "$FIXTURE" "$script" GIT_DIR="$TMP/elsewhere/.git" GIT_WORK_TREE="$TMP/elsewhere"
|
||||||
|
[[ $RC -eq 0 ]] || fail "$label: exited $RC with GIT_DIR exported: $OUT"
|
||||||
|
if grep -q '^git_dir=' "$UV_LOG" && ! grep -q '^git_dir=[^<]' "$UV_LOG" \
|
||||||
|
&& ! grep -q '^git_work_tree=[^<]' "$UV_LOG"; then
|
||||||
|
pass "$label: uv (and so apm) saw no GIT_DIR or GIT_WORK_TREE"
|
||||||
|
else
|
||||||
|
fail "$label: git env leaked: $(grep '^git_' "$UV_LOG" | sort -u | tr '\n' ' ')"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "--- the minimum-version check ---"
|
||||||
|
for pair in "apm-audit-ci:$AUDIT" "apm-pack-check-clean:$PACK"; do
|
||||||
|
label="${pair%%:*}"
|
||||||
|
script="${pair#*:}"
|
||||||
|
for old in 0.39.1 0.28.0; do
|
||||||
|
reset_logs
|
||||||
|
run_gate "$FIXTURE" "$script" STUB_APM_VERSION="$old"
|
||||||
|
[[ $RC -ne 0 ]] && pass "$label: fails on apm $old" || fail "$label: apm $old must fail"
|
||||||
|
grep -qF "apm $old is below 0.39.2" <<< "$OUT" && grep -qF "uv sync --frozen" <<< "$OUT" \
|
||||||
|
&& pass "$label: says $old is below 0.39.2 and names the fix" \
|
||||||
|
|| fail "$label: unclear message for $old: $OUT"
|
||||||
|
[[ ! -s "$APM_LOG" ]] && pass "$label: ran no gate work on apm $old" \
|
||||||
|
|| fail "$label: ran apm past the version check: $(cat "$APM_LOG")"
|
||||||
|
done
|
||||||
|
for ok in 0.39.2 0.39.10 1.0.0; do
|
||||||
|
reset_logs
|
||||||
|
run_gate "$FIXTURE" "$script" STUB_APM_VERSION="$ok"
|
||||||
|
[[ $RC -eq 0 ]] && pass "$label: accepts apm $ok" || fail "$label: apm $ok must pass: $OUT"
|
||||||
|
done
|
||||||
|
reset_logs
|
||||||
|
run_gate "$FIXTURE" "$script" STUB_APM_OUTPUT="apm, version unknown"
|
||||||
|
[[ $RC -ne 0 ]] && grep -qF "printed no 'CLI version X.Y.Z' banner" <<< "$OUT" \
|
||||||
|
&& pass "$label: fails when the version cannot be read" \
|
||||||
|
|| fail "$label: an unreadable version must fail clearly (rc=$RC): $OUT"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "--- the version is read from apm's stdout banner, nothing else ---"
|
||||||
|
# The fake uv writes a banner-shaped `uv CLI version 0.0.1` to stderr on every
|
||||||
|
# call, so these fail if stderr reaches the parser.
|
||||||
|
reset_logs
|
||||||
|
run_gate "$FIXTURE" "$PACK" STUB_APM_VERSION=0.39.3
|
||||||
|
[[ $RC -eq 0 ]] && pass "stdout only: apm 0.39.3 passes despite a 0.0.1 decoy on uv's stderr" \
|
||||||
|
|| fail "stdout only: 0.39.3 must pass, the stderr decoy was parsed: $OUT"
|
||||||
|
reset_logs
|
||||||
|
run_gate "$FIXTURE" "$PACK" STUB_APM_VERSION=0.28.0
|
||||||
|
[[ $RC -ne 0 ]] && grep -qF "apm 0.28.0 is below 0.39.2" <<< "$OUT" \
|
||||||
|
&& pass "stdout only: apm 0.28.0 still fails" || fail "stdout only: 0.28.0 must fail: $OUT"
|
||||||
|
|
||||||
|
# Other version-like text on stdout, before the banner, is not the version.
|
||||||
|
reset_logs
|
||||||
|
run_gate "$FIXTURE" "$PACK" \
|
||||||
|
STUB_APM_OUTPUT=$'reads lockfile version 0.40.0\nAgent Package Manager (APM) CLI version 0.28.0'
|
||||||
|
[[ $RC -ne 0 ]] && grep -qF "apm 0.28.0 is below 0.39.2" <<< "$OUT" \
|
||||||
|
&& pass "banner anchor: a 'version 0.40.0' line before the banner does not rescue 0.28.0" \
|
||||||
|
|| fail "banner anchor: the decoy line was taken for the version (rc=$RC): $OUT"
|
||||||
|
reset_logs
|
||||||
|
run_gate "$FIXTURE" "$PACK" \
|
||||||
|
STUB_APM_OUTPUT=$'reads lockfile version 0.40.0\nAgent Package Manager (APM) CLI version 0.39.3'
|
||||||
|
[[ $RC -eq 0 ]] && pass "banner anchor: the banner's 0.39.3 is the version read" \
|
||||||
|
|| fail "banner anchor: 0.39.3 behind a decoy line must pass (rc=$RC): $OUT"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "--- no uv, and the APM override ---"
|
||||||
|
RC=0
|
||||||
|
OUT="$(cd "$FIXTURE" && env PATH="$NO_UV_PATH" bash "$PACK" 2>&1)" || RC=$?
|
||||||
|
[[ $RC -ne 0 ]] && grep -qF "uv is not on PATH" <<< "$OUT" \
|
||||||
|
&& pass "fails clearly when uv is missing" || fail "missing uv must fail clearly (rc=$RC): $OUT"
|
||||||
|
|
||||||
|
reset_logs
|
||||||
|
RC=0
|
||||||
|
OUT="$(cd "$FIXTURE" && env PATH="$NO_UV_PATH" APM="$BIN/apm" bash "$PACK" 2>&1)" || RC=$?
|
||||||
|
[[ $RC -eq 0 && ! -s "$UV_LOG" ]] && grep -qF "args=pack" "$APM_LOG" \
|
||||||
|
&& pass "APM overrides the command and bypasses uv" \
|
||||||
|
|| fail "APM override not honoured (rc=$RC): $OUT"
|
||||||
|
|
||||||
|
RC=0
|
||||||
|
OUT="$(cd "$FIXTURE" && env PATH="$FAKE_PATH" APM=" " bash "$PACK" 2>&1)" || RC=$?
|
||||||
|
[[ $RC -ne 0 ]] && grep -qF "holds only whitespace" <<< "$OUT" \
|
||||||
|
&& pass "a whitespace-only APM fails clearly" \
|
||||||
|
|| fail "a whitespace-only APM must fail clearly (rc=$RC): $OUT"
|
||||||
|
|
||||||
|
reset_logs
|
||||||
|
RC=0
|
||||||
|
OUT="$(cd "$FIXTURE" && env PATH="$NO_UV_PATH" APM="$BIN/apm" STUB_APM_VERSION=0.28.0 bash "$PACK" 2>&1)" || RC=$?
|
||||||
|
[[ $RC -ne 0 ]] && grep -qF "below 0.39.2" <<< "$OUT" \
|
||||||
|
&& pass "the version check applies to an APM override too" \
|
||||||
|
|| fail "an old apm via APM must fail (rc=$RC): $OUT"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Results: $PASS passed, $FAIL failed"
|
||||||
|
[[ "$FAIL" -eq 0 ]]
|
||||||
@@ -13,10 +13,15 @@
|
|||||||
# and `git checkout` inside a fresh `mktemp -d` -- and each hook script is run
|
# and `git checkout` inside a fresh `mktemp -d` -- and each hook script is run
|
||||||
# from a linked worktree of a throwaway repo with GIT_DIR exported the way git
|
# from a linked worktree of a throwaway repo with GIT_DIR exported the way git
|
||||||
# exports it. Nothing here touches the repo this suite lives in.
|
# exports it. Nothing here touches the repo this suite lives in.
|
||||||
|
#
|
||||||
|
# The hooks run apm as `uv run --project <repo root> --frozen apm` (ADR-0034,
|
||||||
|
# scripts/lib/apm.sh), so a fake `uv` sits beside the stub and hands everything
|
||||||
|
# after `apm` to it. tests/test-apm-gate-invocation.sh pins that command shape;
|
||||||
|
# this suite only needs the call to land on the stub.
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
# This suite builds its own repos; it must never inherit the caller's.
|
# This suite builds its own repos; it must never inherit the caller's.
|
||||||
unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_OBJECT_DIRECTORY GIT_COMMON_DIR
|
unset APM GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE GIT_OBJECT_DIRECTORY GIT_COMMON_DIR
|
||||||
export GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1
|
export GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_NOSYSTEM=1
|
||||||
|
|
||||||
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||||
@@ -34,7 +39,8 @@ g() { git -c user.name=fixture -c [email protected] "$@"; }
|
|||||||
|
|
||||||
# Builds <dir>/main (two commits on `main`) and <dir>/wt, a linked worktree on
|
# Builds <dir>/main (two commits on `main`) and <dir>/wt, a linked worktree on
|
||||||
# branch `feature`, with a plugins/demo/ package dir so the audit script's
|
# branch `feature`, with a plugins/demo/ package dir so the audit script's
|
||||||
# per-package loop has something to iterate. Also writes <dir>/bin/apm, the stub.
|
# per-package loop has something to iterate. Also writes <dir>/bin/apm, the stub,
|
||||||
|
# and <dir>/bin/uv, the fake that reaches it.
|
||||||
make_fixture() {
|
make_fixture() {
|
||||||
local dir="$1"
|
local dir="$1"
|
||||||
mkdir -p "$dir/bin"
|
mkdir -p "$dir/bin"
|
||||||
@@ -51,8 +57,18 @@ make_fixture() {
|
|||||||
local locked
|
local locked
|
||||||
locked="$(g -C "$dir/main" rev-parse HEAD~1)"
|
locked="$(g -C "$dir/main" rev-parse HEAD~1)"
|
||||||
|
|
||||||
|
cat > "$dir/bin/uv" <<EOF
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
[[ "\${1:-}" == run && "\${5:-}" == apm ]] || { echo "fake uv: unexpected argv: \$*" >&2; exit 97; }
|
||||||
|
shift 5
|
||||||
|
exec "$dir/bin/apm" "\$@"
|
||||||
|
EOF
|
||||||
|
chmod +x "$dir/bin/uv"
|
||||||
|
|
||||||
|
# --version answers above the gates' 0.39.2 floor and records nothing.
|
||||||
cat > "$dir/bin/apm" <<EOF
|
cat > "$dir/bin/apm" <<EOF
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
if [[ "\${1:-}" == --version ]]; then echo "Agent Package Manager (APM) CLI version 0.39.3"; exit 0; fi
|
||||||
printf '%s\n' "\${GIT_DIR-<unset>}" >> "$dir/apm-saw-git-dir"
|
printf '%s\n' "\${GIT_DIR-<unset>}" >> "$dir/apm-saw-git-dir"
|
||||||
tmp="\$(mktemp -d)"
|
tmp="\$(mktemp -d)"
|
||||||
( cd "\$tmp" && git init -q . >/dev/null 2>&1; git checkout -q --detach $locked >/dev/null 2>&1 ) || true
|
( cd "\$tmp" && git init -q . >/dev/null 2>&1; git checkout -q --detach $locked >/dev/null 2>&1 ) || true
|
||||||
|
|||||||
@@ -46,12 +46,18 @@ make_fixture() {
|
|||||||
echo "description: fixture"
|
echo "description: fixture"
|
||||||
} > "$dir/plugins/kyberforge/apm.yml"
|
} > "$dir/plugins/kyberforge/apm.yml"
|
||||||
|
|
||||||
|
# Both plugins are declared the way the real root apm.yml declares them, as
|
||||||
|
# git + path entries: the gate derives each key's identity from these.
|
||||||
{
|
{
|
||||||
echo "name: ai-development"
|
echo "name: ai-development"
|
||||||
echo "version: 0.0.1"
|
echo "version: 0.0.1"
|
||||||
echo "dependencies:"
|
echo "dependencies:"
|
||||||
echo " apm:"
|
echo " apm:"
|
||||||
echo " - name: kyberforge"
|
echo " - git: https://git.example.invalid/Owner/Repo.git"
|
||||||
|
echo " path: plugins/kyberforge"
|
||||||
|
echo " - git: https://git.example.invalid/Owner/Repo.git"
|
||||||
|
echo " path: plugins/delivery"
|
||||||
|
echo " mcp: []"
|
||||||
[[ -n "$executables_block" ]] && printf '%s\n' "$executables_block"
|
[[ -n "$executables_block" ]] && printf '%s\n' "$executables_block"
|
||||||
# A top-level key after the block: the fallback reader must stop collecting
|
# A top-level key after the block: the fallback reader must stop collecting
|
||||||
# allow keys here rather than reading on into the next section.
|
# allow keys here rather than reading on into the next section.
|
||||||
@@ -74,40 +80,50 @@ add_plugin() {
|
|||||||
} > "$dir/apm.yml"
|
} > "$dir/apm.yml"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# The identity apm 0.39 matches on: <host>/<owner>/<repo>/<path>.
|
||||||
|
ID=git.example.invalid/Owner/Repo/plugins
|
||||||
|
|
||||||
MATCHING_BLOCK='executables:
|
MATCHING_BLOCK='executables:
|
||||||
allow:
|
allow:
|
||||||
kyberforge#1.5.0:
|
git.example.invalid/Owner/Repo/plugins/kyberforge#1.5.0:
|
||||||
hooks: true
|
hooks: true
|
||||||
bin: true'
|
bin: true'
|
||||||
|
|
||||||
STALE_BLOCK='executables:
|
STALE_BLOCK='executables:
|
||||||
allow:
|
allow:
|
||||||
kyberforge#1.4.0:
|
git.example.invalid/Owner/Repo/plugins/kyberforge#1.4.0:
|
||||||
hooks: true
|
hooks: true
|
||||||
bin: true'
|
bin: true'
|
||||||
|
|
||||||
TWO_MATCHING_BLOCK='executables:
|
TWO_MATCHING_BLOCK='executables:
|
||||||
allow:
|
allow:
|
||||||
kyberforge#1.5.0:
|
git.example.invalid/Owner/Repo/plugins/kyberforge#1.5.0:
|
||||||
hooks: true
|
hooks: true
|
||||||
bin: true
|
bin: true
|
||||||
# delivery ships a guard hook; an indented comment must not read as a key.
|
# delivery ships a guard hook; an indented comment must not read as a key.
|
||||||
delivery#0.1.0:
|
git.example.invalid/Owner/Repo/plugins/delivery#0.1.0:
|
||||||
hooks: true'
|
hooks: true'
|
||||||
|
|
||||||
TWO_STALE_BLOCK='executables:
|
TWO_STALE_BLOCK='executables:
|
||||||
allow:
|
allow:
|
||||||
kyberforge#1.4.0:
|
git.example.invalid/Owner/Repo/plugins/kyberforge#1.4.0:
|
||||||
hooks: true
|
hooks: true
|
||||||
bin: true
|
bin: true
|
||||||
delivery#0.0.9:
|
git.example.invalid/Owner/Repo/plugins/delivery#0.0.9:
|
||||||
hooks: true'
|
hooks: true'
|
||||||
|
|
||||||
OTHER_PACKAGE_BLOCK='executables:
|
OTHER_PACKAGE_BLOCK='executables:
|
||||||
allow:
|
allow:
|
||||||
git#1.0.0:
|
git.example.invalid/Owner/Repo/plugins/git#1.0.0:
|
||||||
hooks: true'
|
hooks: true'
|
||||||
|
|
||||||
|
# The bare '<name>#<version>' form apm 0.28 matched and 0.39 does not.
|
||||||
|
BARE_BLOCK='executables:
|
||||||
|
allow:
|
||||||
|
kyberforge#1.5.0:
|
||||||
|
hooks: true
|
||||||
|
bin: true'
|
||||||
|
|
||||||
# run_gate <fixture> — echoes combined output, sets GATE_RC.
|
# run_gate <fixture> — echoes combined output, sets GATE_RC.
|
||||||
GATE_RC=0
|
GATE_RC=0
|
||||||
run_gate() {
|
run_gate() {
|
||||||
@@ -281,6 +297,39 @@ run_gate "$F"
|
|||||||
[[ $GATE_RC -ne 0 ]] && pass "refuses an unquoted 2-component version" \
|
[[ $GATE_RC -ne 0 ]] && pass "refuses an unquoted 2-component version" \
|
||||||
|| fail "a float version must fail rather than be compared in reader-invented form"
|
|| fail "a float version must fail rather than be compared in reader-invented form"
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
echo ""
|
||||||
|
echo "--- the key is the full package identity apm 0.39 matches on ---"
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# The 0.28-era bare key: apm 0.39.3 parks the hooks under it while root
|
||||||
|
# `apm audit --ci` stays green (spike #269), so this gate is what catches it.
|
||||||
|
F="$(make_fixture "version: 1.5.0" "$BARE_BLOCK")"
|
||||||
|
run_gate "$F"
|
||||||
|
[[ $GATE_RC -ne 0 ]] && pass "fails on a bare '<name>#<version>' key" \
|
||||||
|
|| fail "a bare key no longer matches under apm 0.39 and must fail"
|
||||||
|
OUT="$(bash "$SCRIPT" "$F" 2>&1 || true)"
|
||||||
|
grep -qF "$ID/kyberforge#1.5.0" <<< "$OUT" && pass "names the full-identity key to use" \
|
||||||
|
|| fail "the failure must state the full-identity key, got: $OUT"
|
||||||
|
grep -qF "full package identity" <<< "$OUT" && pass "says why a bare key no longer matches" \
|
||||||
|
|| fail "the failure must explain the bare key, got: $OUT"
|
||||||
|
|
||||||
|
# No git+path dependency entry for the plugin means no identity to derive.
|
||||||
|
F="$(make_fixture "version: 1.5.0" "$MATCHING_BLOCK")"
|
||||||
|
# python3, not `sed -i`, whose in-place syntax differs between GNU and BSD sed.
|
||||||
|
python3 - "$F/apm.yml" << 'PY2'
|
||||||
|
import sys
|
||||||
|
path = sys.argv[1]
|
||||||
|
lines = open(path).read().splitlines(keepends=True)
|
||||||
|
open(path, "w").write("".join(l for l in lines if "path: plugins/kyberforge" not in l))
|
||||||
|
PY2
|
||||||
|
run_gate "$F"
|
||||||
|
[[ $GATE_RC -ne 0 ]] && pass "fails when root apm.yml has no git+path entry for the plugin" \
|
||||||
|
|| fail "with no dependency entry the identity cannot be derived; must fail"
|
||||||
|
OUT="$(bash "$SCRIPT" "$F" 2>&1 || true)"
|
||||||
|
grep -qF "cannot be derived" <<< "$OUT" && pass "says the identity cannot be derived" \
|
||||||
|
|| fail "the failure must say why, got: $OUT"
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
echo ""
|
echo ""
|
||||||
echo "--- the fallback reader agrees with the PyYAML reader ---"
|
echo "--- the fallback reader agrees with the PyYAML reader ---"
|
||||||
@@ -338,6 +387,126 @@ run_fallback "$F"
|
|||||||
run_fallback "$REPO_ROOT"
|
run_fallback "$REPO_ROOT"
|
||||||
[[ $GATE_RC -eq 0 ]] && pass "fallback passes the real repo" || fail "fallback disagrees with PyYAML on the real repo"
|
[[ $GATE_RC -eq 0 ]] && pass "fallback passes the real repo" || fail "fallback disagrees with PyYAML on the real repo"
|
||||||
|
|
||||||
|
# Dependency entry shapes that name the same identity: no .git suffix, path
|
||||||
|
# first, quoted values, ./ prefix and trailing slash, and an scp-like URL. Each
|
||||||
|
# must pass under both readers.
|
||||||
|
identity_variant() {
|
||||||
|
local label="$1" entry="$2" f
|
||||||
|
f="$(make_fixture "version: 1.5.0" "$MATCHING_BLOCK")"
|
||||||
|
python3 - "$f/apm.yml" "$entry" << 'PY2'
|
||||||
|
import sys
|
||||||
|
path, entry = sys.argv[1], sys.argv[2]
|
||||||
|
text = open(path).read()
|
||||||
|
old = " - git: https://git.example.invalid/Owner/Repo.git\n path: plugins/kyberforge\n"
|
||||||
|
assert old in text
|
||||||
|
open(path, "w").write(text.replace(old, entry + "\n"))
|
||||||
|
PY2
|
||||||
|
run_gate "$f"
|
||||||
|
[[ $GATE_RC -eq 0 ]] && pass "PyYAML reader derives the identity: $label" \
|
||||||
|
|| fail "PyYAML reader: $label should pass, got: $(bash "$SCRIPT" "$f" 2>&1 | head -2 || true)"
|
||||||
|
run_fallback "$f"
|
||||||
|
[[ $GATE_RC -eq 0 ]] && pass "fallback reader derives the identity: $label" \
|
||||||
|
|| fail "fallback reader: $label should pass"
|
||||||
|
}
|
||||||
|
|
||||||
|
identity_variant "no .git suffix" " - git: https://git.example.invalid/Owner/Repo
|
||||||
|
path: plugins/kyberforge"
|
||||||
|
identity_variant "path before git" " - path: plugins/kyberforge
|
||||||
|
git: https://git.example.invalid/Owner/Repo.git"
|
||||||
|
identity_variant "quoted values, ./ and trailing /" " - git: \"https://git.example.invalid/Owner/Repo.git\"
|
||||||
|
path: './plugins/kyberforge/'"
|
||||||
|
identity_variant "scp-like URL" " - git: [email protected]:Owner/Repo.git
|
||||||
|
path: plugins/kyberforge"
|
||||||
|
|
||||||
|
F="$(make_fixture "version: 1.5.0" "$BARE_BLOCK")"
|
||||||
|
run_fallback "$F"
|
||||||
|
[[ $GATE_RC -ne 0 ]] && pass "fallback fails a bare key" || fail "fallback missed a bare key"
|
||||||
|
|
||||||
|
# A URL with a port: where apm puts the port in the identity is unverified, so
|
||||||
|
# the gate refuses to derive a key rather than derive a plausible wrong one.
|
||||||
|
for port_url in "ssh://[email protected]:2222/Owner/Repo.git" "https://git.example.invalid:8443/Owner/Repo.git"; do
|
||||||
|
F="$(make_fixture "version: 1.5.0" "$MATCHING_BLOCK")"
|
||||||
|
python3 - "$F/apm.yml" "$port_url" << 'PY2'
|
||||||
|
import sys
|
||||||
|
path, url = sys.argv[1], sys.argv[2]
|
||||||
|
text = open(path).read()
|
||||||
|
old = " - git: https://git.example.invalid/Owner/Repo.git\n path: plugins/kyberforge\n"
|
||||||
|
assert old in text
|
||||||
|
open(path, "w").write(text.replace(old, " - git: %s\n path: plugins/kyberforge\n" % url))
|
||||||
|
PY2
|
||||||
|
OUT="$(bash "$SCRIPT" "$F" 2>&1)" && rc=0 || rc=$?
|
||||||
|
[[ $rc -ne 0 ]] && grep -qF "URL with a port" <<< "$OUT" \
|
||||||
|
&& pass "refuses a git: URL with a port: $port_url" \
|
||||||
|
|| fail "a URL with a port must fail clearly ($port_url), got rc=$rc: $OUT"
|
||||||
|
run_fallback "$F"
|
||||||
|
[[ $GATE_RC -ne 0 ]] && pass "fallback refuses a git: URL with a port: $port_url" \
|
||||||
|
|| fail "fallback must refuse a URL with a port ($port_url)"
|
||||||
|
done
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
echo ""
|
||||||
|
echo "--- a parked executable recorded in apm.lock.yaml fails ---"
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# write_lock <fixture> <kyberforge exec_status> — a lock in the shape apm 0.39.3
|
||||||
|
# writes: `- repo_url:` opens each dependency, fields at 2 spaces, host after
|
||||||
|
# repo_url, exec_status last, then a top-level deployments: section.
|
||||||
|
write_lock() {
|
||||||
|
{
|
||||||
|
echo "lockfile_version: '4'"
|
||||||
|
echo "apm_version: 0.39.3"
|
||||||
|
echo "dependencies:"
|
||||||
|
echo "- repo_url: Owner/Repo"
|
||||||
|
echo " name: kyberforge"
|
||||||
|
echo " host: git.example.invalid"
|
||||||
|
echo " virtual_path: plugins/kyberforge"
|
||||||
|
echo " deployed_files:"
|
||||||
|
echo " - .claude/hooks/kyberforge/x.sh"
|
||||||
|
echo " exec_status: $2"
|
||||||
|
echo "- repo_url: Owner/Repo"
|
||||||
|
echo " name: docs"
|
||||||
|
echo " host: git.example.invalid"
|
||||||
|
echo " virtual_path: plugins/docs"
|
||||||
|
echo "deployments:"
|
||||||
|
echo "- exec_status: gated_pending_approval"
|
||||||
|
} > "$1/apm.lock.yaml"
|
||||||
|
}
|
||||||
|
|
||||||
|
F="$(make_fixture "version: 1.5.0" "$MATCHING_BLOCK")"
|
||||||
|
write_lock "$F" deployed
|
||||||
|
run_gate "$F"
|
||||||
|
[[ $GATE_RC -eq 0 ]] && pass "passes a lock whose executables are deployed" \
|
||||||
|
|| fail "exec_status: deployed must pass, got: $(bash "$SCRIPT" "$F" 2>&1 | head -3 || true)"
|
||||||
|
|
||||||
|
F="$(make_fixture "version: 1.5.0" "$MATCHING_BLOCK")"
|
||||||
|
write_lock "$F" gated_pending_approval
|
||||||
|
run_gate "$F"
|
||||||
|
[[ $GATE_RC -ne 0 ]] && pass "fails a lock that records gated_pending_approval" \
|
||||||
|
|| fail "a parked executable in the lock must fail the push"
|
||||||
|
OUT="$(bash "$SCRIPT" "$F" 2>&1 || true)"
|
||||||
|
grep -qF "git.example.invalid/Owner/Repo/plugins/kyberforge: gated_pending_approval" <<< "$OUT" \
|
||||||
|
&& pass "names the parked package by identity and its status" \
|
||||||
|
|| fail "the failure must name the package and status, got: $OUT"
|
||||||
|
grep -q "Why:" <<< "$OUT" && grep -qF "apm approve --list" <<< "$OUT" \
|
||||||
|
&& pass "carries Why: and a Fix: naming apm approve --list" || fail "message must carry Why/Fix: $OUT"
|
||||||
|
grep -qF "plugins/docs" <<< "$OUT" && fail "a dependency with no exec_status must not be reported" \
|
||||||
|
|| pass "reports only the gated dependency, not the next one or the deployments: section"
|
||||||
|
|
||||||
|
F="$(make_fixture "version: 1.5.0" "$MATCHING_BLOCK")"
|
||||||
|
write_lock "$F" gated_definition_changed
|
||||||
|
run_fallback "$F"
|
||||||
|
[[ $GATE_RC -ne 0 ]] && pass "fails any gated_* status, without PyYAML too" \
|
||||||
|
|| fail "gated_definition_changed must fail under the fallback reader"
|
||||||
|
|
||||||
|
# A third-party dependency can be parked in a repo whose own plugins ship no
|
||||||
|
# executables, so the check runs before the no-plugin no-op.
|
||||||
|
F="$(mktemp -d "$RUN_TMP/fx.XXXXXX")"
|
||||||
|
echo "name: someone-else" > "$F/apm.yml"
|
||||||
|
write_lock "$F" gated_pending_approval
|
||||||
|
run_gate "$F"
|
||||||
|
[[ $GATE_RC -ne 0 ]] && pass "fails a parked executable even with no executable-shipping plugin" \
|
||||||
|
|| fail "the lock check must run before the no-plugin no-op"
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
echo ""
|
echo ""
|
||||||
echo "--- wired into the pre-push gate ---"
|
echo "--- wired into the pre-push gate ---"
|
||||||
|
|||||||
Reference in new issue
Block a user