Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ae51bdb
test(lifecycle): the project plugin bin spine re-installs with each m…
danielmeppiel Nov 24, 2026
5a41afb
test(lifecycle): install --mcp over a deployed bin/ credits the mcp-i…
danielmeppiel Nov 24, 2026
284c75b
test(lifecycle): guard that a local bundle never routes a bin/ file
danielmeppiel Nov 24, 2026
2f5f569
test(lifecycle): rule U-BIN-BUNDLE, a local bundle never deploys bin/
danielmeppiel Nov 24, 2026
d52be38
test(lifecycle): the model expects bin/ only for a Claude target
danielmeppiel Nov 24, 2026
6f7178b
test(lifecycle): the plugin bin spine re-installs with two targets de…
danielmeppiel Nov 24, 2026
7afc1d7
test(lifecycle): pack over a deployed native plugin is a strict known…
danielmeppiel Nov 24, 2026
55fcbf2
test(lifecycle): pack under the org deny over a deployed native plugi…
danielmeppiel Nov 24, 2026
23e6923
Merge branch 'w3e/lifecycle-t1b' into w3e/lifecycle-t1c
danielmeppiel Nov 24, 2026
5310880
test(lifecycle): re-pin U-BIN-BUNDLE after main narrowed bundle routing
danielmeppiel Nov 24, 2026
e54ba50
Merge branch 'w3e/lifecycle-t1b' into w3e/lifecycle-t1c
danielmeppiel Nov 24, 2026
eadafed
test(lifecycle): pin the local bundle caller's target on its routing …
danielmeppiel Nov 24, 2026
06e1809
Merge commit 'refs/w2c/main' into w3e/lifecycle-t1c
danielmeppiel Nov 24, 2026
fed2773
Merge branch 'w3e/lifecycle-t1b' into w3e/lifecycle-t1c
danielmeppiel Nov 24, 2026
4c7f583
Merge commit 'refs/w2c/main' into w3e/lifecycle-t1c
danielmeppiel Nov 24, 2026
999e790
Merge commit 'refs/w2c/main' into w3e/lifecycle-t1c
danielmeppiel Nov 24, 2026
d91215c
Merge main into T-1c; drop the #5253 pack known cell main fixed
danielmeppiel Nov 24, 2026
291eb99
test(lifecycle): the pack omission check applies to an admitted pack,…
danielmeppiel Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion tests/lifecycle/generator/bin_pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
holds the approved value, and a mismatch turns the project-scope bin cells
into must-cover obligations. ``user_org_policy_digest`` pins
``core/scope.policy_discovery_uses_git_remote`` the same way for
U-USER-SCOPE-ORG-POLICY (``rules.U_USER_ORG_POLICY_PIN``).
U-USER-SCOPE-ORG-POLICY (``rules.U_USER_ORG_POLICY_PIN``), and
``bundle_bin_digest`` pins the local bundle's deploy routing for U-BIN-BUNDLE
(``rules.U_BIN_BUNDLE_PIN``).
"""

from __future__ import annotations
Expand Down Expand Up @@ -95,3 +97,54 @@ def user_org_policy_digest(src_root: Path = SRC_ROOT) -> str:
module, name = USER_ORG_POLICY
tokens = element_tokens(src_root / module, name)
return hashlib.sha256(tokens.encode("utf-8")).hexdigest()


# U-BIN-BUNDLE: a local bundle routes only target primitives, so it never deploys bin/.
BUNDLE_BIN = (
("install/local_bundle_paths.py", "bundle_deploy_relative_path"),
("install/local_bundle_paths.py", "_lower_to_target"),
("install/local_bundle_paths.py", "_is_primitive_deploy_path"),
)
Comment thread
danielmeppiel marked this conversation as resolved.
Resolved
Comment thread
danielmeppiel marked this conversation as resolved.
Resolved


# The caller's routing contract: integrate_local_bundle passes its target to every
# routing call; without it _lower_to_target(..., None) would pass bin/ through.
BUNDLE_BIN_CALLER = ("install/services.py", "integrate_local_bundle", "_bundle_rel", "target")


def call_keyword_tokens(path: Path, function: str, callee: str, keyword: str) -> str:
"""``callee(keyword=<value>)`` for every call of *callee* inside top-level *function*.

A call without *keyword* reads ``callee(keyword=<missing>)``; no call at all raises.
"""
tree = ast.parse(path.read_text(encoding="utf-8"))
for node in tree.body:
if not (isinstance(node, ast.FunctionDef) and node.name == function):
continue
calls = [
call
for call in ast.walk(node)
if isinstance(call, ast.Call)
and isinstance(call.func, ast.Name)
and call.func.id == callee
]
if not calls:
raise LookupError(f"{function} in {path} no longer calls {callee}")
values = [
next((ast.unparse(k.value) for k in call.keywords if k.arg == keyword), "<missing>")
for call in calls
]
return " ".join(f"{callee}({keyword}={value})" for value in values)
raise LookupError(f"{function} not found in {path}")


@cache
def bundle_bin_digest(src_root: Path = SRC_ROOT) -> str:
tokens = "\n".join(
f"{module}::{name} {element_tokens(src_root / module, name)}" for module, name in BUNDLE_BIN
)
module, function, callee, keyword = BUNDLE_BIN_CALLER
tokens += f"\n{module}::{function} " + call_keyword_tokens(
src_root / module, function, callee, keyword
)
return hashlib.sha256(tokens.encode("utf-8")).hexdigest()
7 changes: 6 additions & 1 deletion tests/lifecycle/generator/emit.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
import yaml

from tests.lifecycle.generator import covering
from tests.lifecycle.generator.bin_pin import predicate_digest, user_org_policy_digest
from tests.lifecycle.generator.bin_pin import (
bundle_bin_digest,
predicate_digest,
user_org_policy_digest,
)
from tests.lifecycle.generator.factors import (
EXCEPTION_FACTORS,
FACTORS,
Expand Down Expand Up @@ -284,6 +288,7 @@ def _build() -> tuple[dict[str, Any], dict[str, object], dict[str, str]]:
"removed": {key: list(rules) for key, rules in sorted(space.removed.items())},
"pins": {
"U-BIN": predicate_digest(),
"U-BIN-BUNDLE": bundle_bin_digest(),
"U-USER-SCOPE-ORG-POLICY": user_org_policy_digest(),
},
}
Expand Down
74 changes: 74 additions & 0 deletions tests/lifecycle/generator/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,42 @@ def __str__(self) -> str:
Ev("src/apm_cli/install/exec_gate.py", "plugin_bin_deployable", "InstallScope.USER"),
),
),
"U-BIN-BUNDLE": (
"a local bundle never deploys bin/, at any scope or gate level (#4095 lane T-1c, "
"QL ruling): integrate_local_bundle routes every packed file through "
"bundle_deploy_relative_path, which keeps only files under a primitive a target "
"deploys (_lower_to_target, _is_primitive_deploy_path); no target declares a bin "
"primitive, and the only bin/ deploy decision (exec_gate.plugin_bin_deployable) "
"belongs to the package pipeline, which the bundle side door never calls. So every "
"PRIM=bin cell of OP=bundle-install or SRC=local-bundle is vacuous for bin/, the "
"org-policy level included: the bundle spine still witnesses the deny's refusal "
"itself. Self-reinstating: bin_pin.bundle_bin_digest hashes the routing elements; "
"when it differs from U_BIN_BUNDLE_PIN the cells become must-cover, and the "
"tripwire test_no_target_routes_a_bundle_bin_file fails if any target ever routes "
"a bundle bin/ path",
(
Ev(
"src/apm_cli/install/services.py",
"integrate_local_bundle",
"_deploy_rel = _bundle_rel(",
),
Ev(
"src/apm_cli/install/local_bundle_paths.py",
"bundle_deploy_relative_path",
"return _lower_to_target(deploy_rel, target, rendering_extension)",
),
Ev(
"src/apm_cli/install/local_bundle_paths.py",
"_lower_to_target",
"if not _is_primitive_deploy_path(rel_path, target):",
),
Ev(
"src/apm_cli/install/exec_gate.py",
"plugin_bin_deployable",
"PackageType.MARKETPLACE_PLUGIN",
),
),
),
"U-BIN-SRC": (
"a local path whose package can deploy bin/ is a Claude plugin directory, which is "
"the native-plugin source: bin/ deploys only for a MARKETPLACE_PLUGIN package, "
Expand Down Expand Up @@ -693,6 +729,8 @@ def definition_rule(cell: Mapping[str, str]) -> str | None:
return "U8"
if u_bin_ops_applies(cell) and u_bin_pinned():
Comment thread
danielmeppiel marked this conversation as resolved.
Resolved
return "U-BIN-OPS"
if u_bin_bundle_applies(cell) and u_bin_bundle_pinned():
return "U-BIN-BUNDLE"
if u_user_org_policy_applies(cell) and u_user_org_policy_pinned():
return "U-USER-SCOPE-ORG-POLICY"
if cell.get("SCOPE") == "user" and cell.get("MCPOWN") in RETIRED_MCP_OWNERS:
Expand Down Expand Up @@ -805,6 +843,8 @@ def must_cover_rules(cell: Mapping[str, str]) -> tuple[str, ...]:
rules.append("U9")
if u_bin_applies(cell) and not u_bin_pinned():
rules.append("U-BIN")
if u_bin_bundle_applies(cell) and not u_bin_bundle_pinned():
rules.append("U-BIN-BUNDLE")
if u_user_org_policy_applies(cell) and not u_user_org_policy_pinned():
rules.append("U-USER-SCOPE-ORG-POLICY")
return tuple(rules)
Expand Down Expand Up @@ -870,6 +910,40 @@ def u_bin_pinned() -> bool:
return predicate_digest() == U_BIN_PIN


# -- U-BIN-BUNDLE: a local bundle never deploys bin/ (#4095 lane T-1c) ----------

# The approved digest of the bundle deploy routing (generator/bin_pin.py). While the
# live digest equals it, every PRIM=bin cell of a local bundle is removed; when it
# differs they are must-cover and --check fails until a reviewed change updates it.
# Re-pinned after main's bundle frontmatter-hooks fixes (2dfb0a11..37df5b73): they add one
# more skip (_declares_unapproved_hooks) to bundle_deploy_relative_path and leave
# _lower_to_target and _is_primitive_deploy_path unchanged, so routing only narrowed.
# The pin also covers integrate_local_bundle's target= on its routing call
# (bin_pin.BUNDLE_BIN_CALLER).
U_BIN_BUNDLE_PIN = "b83d2577325ef5b20d7d43c0bc0f3e1c5baa8e7cf090d1a7a0defc10f5b301f7"


def u_bin_bundle_applies(cell: Mapping[str, str]) -> bool:
"""U-BIN-BUNDLE: a PRIM=bin cell whose package arrives as a local bundle.

A command U8 maps to a rule cell (one that refuses or ignores a local bundle)
keeps that mapping: the refusal is proven there, whatever the bundle ships.
install of a local bundle is bundle-install, so it is removed with it.
"""
if cell.get("PRIM") != "bin" or not (
cell.get("OP") == "bundle-install" or cell.get("SRC") == "local-bundle"
):
return False
mapped = mapped_cell(cell)
return mapped is None or not isinstance(mapped[0], str)


def u_bin_bundle_pinned() -> bool:
from tests.lifecycle.generator.bin_pin import bundle_bin_digest

return bundle_bin_digest() == U_BIN_BUNDLE_PIN


# -- U-USER-SCOPE-ORG-POLICY: user scope discovers no org policy (#3703) ----------

# The approved digest of core/scope.policy_discovery_uses_git_remote. #3703 must
Expand Down
58 changes: 56 additions & 2 deletions tests/lifecycle/generator/test_generator_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@
RETIRED_MCP_OWNERS,
RULE_CELL_REFUSALS,
RULES,
U_BIN_BUNDLE_PIN,
U_BIN_PIN,
U_USER_ORG_POLICY_PIN,
UNINSTALL_MCP_REFUSALS,
USER_SCOPE_EVIDENCE,
Verdict,
classify,
mapped_cell,
refusal_cell,
)
from tests.lifecycle.generator.space import Entry, build_space, raw_cells
Expand Down Expand Up @@ -572,6 +574,7 @@ def _raw() -> dict[str, dict[str, str]]:
("U6", _u6),
("U8", lambda cell: _u8(cell) is not None),
("U-BIN-OPS", lambda cell: _u_bin_ops(cell)),
("U-BIN-BUNDLE", lambda cell: _u_bin_bundle(cell)),
("U-MCPOWN-USER", _u_mcpown_user),
("U-USER-SCOPE-ORG-POLICY", lambda cell: _u_user_org_policy(cell)),
],
Expand Down Expand Up @@ -639,7 +642,12 @@ def test_executable_gate_levels_of_an_mcp_source_map_to_the_first_party_rule_cel
def test_u8_mappings_name_the_cell_or_refusal_each_shape_lands_on() -> None:
data = json.loads(_OBLIGATIONS.read_text(encoding="utf-8"))
mapped = {key: entry for key, entry in data["mapped"].items() if entry["rules"][0] == "U8"}
named = {key for key, cell in _raw().items() if _u8_mapping(cell) is not None}
# U-BIN-BUNDLE removes install of a local bundle shipping bin/ before U8 maps it.
named = {
key
for key, cell in _raw().items()
if _u8_mapping(cell) is not None and key not in _removed_by("U-BIN-BUNDLE")
}
assert set(mapped) == named, sorted(set(mapped) ^ named)[:10]
clauses: dict[str, int] = {}
for key, entry in mapped.items():
Expand All @@ -661,7 +669,7 @@ def test_u8_mappings_name_the_cell_or_refusal_each_shape_lands_on() -> None:
else:
assert entry["maps_to"] == UNINSTALL_MCP_REFUSALS[cell["SRC"]], key
assert clauses == {
"install of a local bundle is bundle-install": 9,
"install of a local bundle is bundle-install": 8,
"marketplace add of a source without a catalog": 43,
"uninstall of a local bundle": 9,
"update of a local bundle": 9,
Expand Down Expand Up @@ -725,6 +733,7 @@ def test_u_bin_pin_matches_the_predicate_and_is_recorded() -> None:
data = json.loads(_OBLIGATIONS.read_text(encoding="utf-8"))
assert data["pins"] == {
"U-BIN": U_BIN_PIN,
"U-BIN-BUNDLE": U_BIN_BUNDLE_PIN,
"U-USER-SCOPE-ORG-POLICY": U_USER_ORG_POLICY_PIN,
}

Expand All @@ -748,6 +757,51 @@ def test_a_whole_plugin_keeps_project_bin_cells_and_witnesses_prune() -> None:
assert entry["status"] == "required" and entry["witness"].endswith(spine), (key, entry)


# -- U-BIN-BUNDLE: a local bundle never deploys bin/ (#4095 lane T-1c) ----------


def _u_bin_bundle(cell) -> bool:
"""A PRIM=bin cell of a local bundle that no earlier rule removes and U8 maps to
no rule cell (install of a local bundle is bundle-install, so it goes too)."""
if cell.get("PRIM") != "bin" or not (
cell.get("OP") == "bundle-install" or cell.get("SRC") == "local-bundle"
):
return False
if _u_bin_ops(cell) or _u6(cell) or _u8(cell) is not None:
return False
mapped = mapped_cell(cell)
return mapped is None or not isinstance(mapped[0], str)


def test_u_bin_bundle_removes_the_bundle_bin_cells_and_keeps_the_deny_refusal() -> None:
"""The ruled cells are removed; the bundle deny itself stays witnessed by the spine."""
removed = _removed_by("U-BIN-BUNDLE")
for key in (
"T1|OP=bundle-install|PRIM=bin|GATE=denied-dependency",
"pair|OP=bundle-install|PRIM=bin",
*(
f"T3|OP={op}|SRC=local-bundle|PRIM=bin"
for op in ("approve-deny", "audit", "bundle-install", "compile", "lock")
),
):
assert key in removed, key
assert bin_pin.bundle_bin_digest() == U_BIN_BUNDLE_PIN, (
"the bundle deploy routing changed: re-prove that a bundle deploys no bin/ "
"(test_u_bin_seam.py tripwire), then update U_BIN_BUNDLE_PIN"
)
kept = json.loads(_OBLIGATIONS.read_text(encoding="utf-8"))["obligations"]
deny = kept["pair|OP=bundle-install|GATE=denied-dependency"]
assert deny["status"] == "required", deny


def test_a_changed_bundle_routing_reinstates_the_bundle_bin_cells(monkeypatch) -> None:
cell = {"OP": "bundle-install", "PRIM": "bin", "GATE": "denied-dependency"}
assert classify("T1", cell) == Verdict("removed", ("U-BIN-BUNDLE",))
monkeypatch.setattr(bin_pin, "bundle_bin_digest", lambda *_: "0" * 64)
assert classify("T1", cell).rules == ("U-BIN-BUNDLE",)
assert classify("T1", cell).must_cover


# -- U-USER-SCOPE-ORG-POLICY: user scope discovers no org policy (#3703) ----------


Expand Down
86 changes: 86 additions & 0 deletions tests/lifecycle/generator/test_u_bin_seam.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

from __future__ import annotations

import shutil
from pathlib import Path

import pytest

from tests.lifecycle.generator import bin_pin
Expand All @@ -28,3 +31,86 @@ def test_a_matching_pin_keeps_project_bin_cells_plain_obligations() -> None:
def test_a_changed_pin_makes_the_project_bin_cells_must_cover(monkeypatch) -> None:
monkeypatch.setattr(bin_pin, "predicate_digest", lambda *_: "0" * 64)
assert classify("pair", _PROJECT_BIN) == Verdict("obligation", ("U-BIN",), must_cover=True)


def test_no_target_routes_a_bundle_bin_file() -> None:
"""Tripwire of the U-BIN-BUNDLE rule (#4095 lane T-1c): a local bundle never
deploys bin/, at any scope, for any target.

``integrate_local_bundle`` (install/services.py) routes each packed file through
``bundle_deploy_relative_path``, which keeps only primitive files a target deploys;
no target declares a ``bin`` primitive, and the only bin/ deploy decisions
(``exec_gate.plugin_bin_deployable``) are made by the package pipeline, which the
bundle side door never calls. If this starts routing a bin/ path, the bundle-install
x bin cells become real deploy cells and the rule must go.
"""
from apm_cli.install.local_bundle_paths import (
bundle_deploy_relative_path,
known_bundle_deploy_prefixes,
target_bundle_deploy_prefixes,
)
from apm_cli.integration.targets import KNOWN_TARGETS

assert not [name for name, target in KNOWN_TARGETS.items() if "bin" in target.primitives]
tool = "p-native-claude-bin"
paths = (f".agents/plugins/{tool}/bin/{tool}", f"bin/{tool}", f".agents/bin/{tool}")
routed = {
(name, path): deployed
for name, target in sorted(KNOWN_TARGETS.items())
for path in (*paths, *(f"{target.root_dir.strip('/')}/bin/{tool}",))
if (
deployed := bundle_deploy_relative_path(
path,
target_bundle_deploy_prefixes(target),
known_bundle_deploy_prefixes(),
target=target,
hooks_approved=True,
canvas_approved=True,
)
)
is not None
}
assert not routed, routed
# Anti-vacuity: the same call routes a primitive the claude target does deploy.
claude = KNOWN_TARGETS["claude"]
skill = bundle_deploy_relative_path(
f".claude/skills/{tool}/SKILL.md",
target_bundle_deploy_prefixes(claude),
known_bundle_deploy_prefixes(),
target=claude,
hooks_approved=True,
canvas_approved=True,
)
assert skill is not None


def test_the_model_expects_bin_only_for_a_claude_target() -> None:
"""bin/ has a Claude surface only: with claude and copilot declared, the model
expects the plugin's bin/ once, for claude (exec_gate.plugin_bin_deployable)."""
from tests.lifecycle.model.expected import expected_deployed
from tests.lifecycle.model.state import ModelState

model = ModelState(
declared=frozenset({"p"}), targets=frozenset({"claude", "copilot"}), exec_gate=False
)
deployed = expected_deployed(model, {"p": frozenset({"bin", "skill"})})
assert {target for _pkg, kind, target in deployed if kind == "bin"} == {"claude"}
assert {target for _pkg, kind, target in deployed if kind == "skill"} == {"claude", "copilot"}


def test_dropping_the_callers_target_changes_the_bundle_pin(tmp_path: Path) -> None:
"""U-BIN-BUNDLE pins integrate_local_bundle's ``target=`` on its routing call too:
without it ``_lower_to_target(..., None)`` would pass a bundle's bin/ through."""
module, function, callee, _keyword = bin_pin.BUNDLE_BIN_CALLER
for relative in {module, *(m for m, _name in bin_pin.BUNDLE_BIN)}:
(tmp_path / relative).parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(bin_pin.SRC_ROOT / relative, tmp_path / relative)
Comment thread
danielmeppiel marked this conversation as resolved.
Resolved
assert bin_pin.bundle_bin_digest.__wrapped__(tmp_path) == bin_pin.bundle_bin_digest()
caller = tmp_path / module
text = caller.read_text(encoding="utf-8")
call = text.index(f"= {callee}(")
keyword = text.index("target=target,", call)
assert keyword < text.index(")", call), "the routing call passes no target"
caller.write_text(text[:keyword] + text[keyword + len("target=target,") :], encoding="utf-8")
assert "<missing>" in bin_pin.call_keyword_tokens(caller, function, callee, "target")
assert bin_pin.bundle_bin_digest.__wrapped__(tmp_path) != bin_pin.bundle_bin_digest()
Loading
Loading