Skip to content

test(lifecycle): M-SOURCE audit and approve/deny per source (T-2 b5) - #4723

Closed
Daniel Meppiel (danielmeppiel) wants to merge 64 commits into
mainfrom
ql-w1-t2-b5
Closed

Daniel Meppiel (danielmeppiel) wants to merge 64 commits into
mainfrom
ql-w1-t2-b5

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

Train-5 source, T-2 (M-SOURCE) batch 5, stacked on #4711 (corpus train 4, head ff8b116). Until #4711 lands, this diff includes its commits; the b5 change is the top commit.

The M-SOURCE spine now drives audit and approve/deny per dependency source on the real CLI:

  • audit_pass runs apm audit --dry-run, then apm audit, on each converged remote-skill state and after the registry exec pass. It is read-only for every declared form, local bundles included.
  • decide_pass:
    • apm approve --all pins every installed package with executables.
    • A local bundle is approved by the content key that approve --pending prints, then installed again as that hint says.
    • apm deny of a catalog plugin, followed by the apm install its hint names, retires that plugin's executables (I4).
    • The gate is then restored.
  • The model carries the executables decisions, so the deploy oracle checks the approved state.
  • The p-lsp bundle stays parked. Its LSP server has the same name as the local p-lsp's, and once the bundle owns the server, the manifest install is refused by design ("an installed bundle owner never transfers").

R5 (Q&L ruling, approved): approve-deny x {mcp-registry, inline-mcp} maps onto U-FIRST-PARTY-MCP. apm approve and apm deny decide only installed packages (scan_installed_executable_packages scans apm_modules/). test_approve_never_scans_a_root_declared_mcp_server installs a root-declared MCP server next to a package with an MCP server, then asserts the live scan sees only the package. It fails if approve ever starts governing root MCP.

ledger #4711 ff8b116 this PR
baseline 531 452
required 1908 1983
known-failing 8 8
T-2 baseline 220 141

79 cells leave baseline: 75 T-2 cells become required (T3 audit and approve-deny per source x primitive, T5 audit dry-run/real, OP x SRC pairs) and 4 are mapped by R5. No strict known cells were added and no product bug was found.

Coupling (H7): this regenerates tests/quality/lifecycle_obligations.json. Whichever lands second regenerates. R5's Ev uses the line form; if #4702 lands first, it becomes Ev(approve.py, "scan_installed_executable_packages", "apm_modules") on regenerate.

Issue and approved scope

Issue: Refs #4564 (0.38 burn-down; closes when baseline <= 500), Refs #4565 (epic)

Human scope-approval comment: #4564 (comment)

With #4711, this takes the baseline to 452, under the <= 500 target. Closing #4564 is the maintainer's call once both land.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

Local (through host_guard, real CLI APM_BINARY_PATH=.venv/bin/apm):

  • pytest tests/lifecycle/machines/test_m_source.py -k spine: every step and law check passed (502 s on a loaded host). The final receipt check flagged only the parked p-lsp-bundle lsp cell, which the stale ledger still marked required; the ledger was then regenerated. The spine was not re-run afterwards; CI validates it.
  • pytest tests/quality/test_promise_obligations.py tests/quality/test_generated_obligations.py tests/lifecycle/generator/ on those receipts: 87 passed (includes the R5 live-scan test).
  • python -m tests.lifecycle.generator --check, the obligation-status ratchet, the assertion-quality ratchet, the complexity ratchet, tests.quality.taxonomy --changed, and [email protected] check/format --check: clean.

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .github/instructions/changelog.instructions.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour.

…ckfiles

A second scope-lock spine drives a stale lockfile (the manifest and the lock
disagree on the toggle package), an absent lockfile and the side-door commands
(deny, install --mcp, a local bundle, marketplace list) through every lock
state the lockfile spine leaves open. Each step runs I1-I9; admitted side
doors also assert their own outcome. Lockfile cells now carry the context
their step acted on and credit, anchored on LOCK, the pairs it implies.
apm marketplace list creating ~/.apm/marketplaces.json is a strict known
cell (#4600).

Refs #4564
Refs #4097

Co-authored-by: Copilot App <[email protected]>
…owed

The GATE matrix gains a user-scope spine (install --frozen at every gate
level an approval store reaches, T2 FROZEN x SCOPE=user x GATE) with the
user-scope copilot surfaces observed (Bench.surface_globs). Marketplace
commands map onto rule U-MKT (Q&L ruling 2026-11-21): one rule cell
witnessed at the allowed and revoked levels with every project byte
unchanged; the org-policy level keeps its own cells, witnessed under the
dependency deny. The allowed level also uninstalls and reinstalls p-lsp.

Refs #4564
Refs #4095

Co-authored-by: Copilot App <[email protected]>
credits() is the one place that says which ids a machine receipt
discharges (rule ids themselves, anchored cells only their anchor), and
the witness test reads it. U-MKT evidence follows main's line moves.

Refs #4564

Co-authored-by: Copilot App <[email protected]>
…record

Per review on corpus train 2: outcome checks now run before a drift cell
is credited. A resolving command must leave a readable lockfile whose rows
match the manifest and that records each deployed declared skill; a local
bundle install must record p-lsp's approval key and LSP type in
apm_modules/.local-bundle-pending.json while its server stays parked.

Refs #4564

Co-authored-by: Copilot App <[email protected]>
Per review on corpus train 2: the allowed and the revoked marketplace
probes each hold their checked step; the rule cell's receipts are emitted
only once both levels are present, so dropping either probe leaves the
rule uncovered (negative control: umkt_ready per dropped level).

Refs #4564

Co-authored-by: Copilot App <[email protected]>
…every operation

Discharges the T-6b pair obligations (DEPLOYED in {edited, unowned,
present-provenance-unknown} crossed with OP, modifiers, SRC, PRIM, GATE,
TGT and NET) with real-CLI oracle receipts in
tests/lifecycle/scenarios/test_ownership_siblings.py.

- The user's bytes are declared (Scenario.user_write) and must survive
  (I1-X2); a closed gate that keeps them is exempt from I4 only when the
  keep is announced and audit --ci detects it (I4-X2).
- Declared refusals earn credit only through EXPECTED_REFUSALS (exit code,
  cause, the promise it upholds, its source); a refusal on any other pair,
  or a declared pair that exits 0, fails the step
  (tests/quality/test_scenario_refusal_credit.py negative controls).
- run(says=...) asserts announced outcomes and records them as evidence.
- Product failures are strict known cells: #4626 (edited hook, canvas and
  LSP files overwritten silently), #4628 (a user's LSP entry taken over),
  #4268 (refused install --mcp writes first), #4634 (local bundle reinstall
  after a lost lockfile leaves MCP lock state the gates reject).
- TGT reads the declared target set before the step: narrowed drops at
  least one declared target (a switch counts); widened adds and drops none.

T-6b obligations: 141 baseline -> 132 required, 6 known-failing, 3 baseline.

Refs #4564 #4565

Co-authored-by: Copilot App <[email protected]>
Two deterministic spines credit OP x PRIM x GATE for the side doors:
apm install <local bundle> (a run-time packed p-bmix bundle with a skill,
an instruction, a hook and an MCP server, plus the world's p-lsp bundle)
and apm pack --dry-run over git dependencies, each at five gate levels
(unapproved, denied before deploy, allowed, revoked after deploy, gate
off). Every step runs I1-I9; bundle installs must leave exactly the
per-bundle model set and record parked executables as pending; pack must
ship exactly the dependency executables the gate deploys and never a
managed MCP server.

Refs #4564
Refs #4095

Co-authored-by: Copilot App <[email protected]>
Target history (ruling #3): install and every command after a declared
target change, with real-CLI receipts crediting the scenario-lane pairs
their assignments imply (CREDITS). U11 maps changed-TGT x FROZEN onto
refusal|TGT=changed|FROZEN=on, witnessed by
test_frozen_refuses_a_target_change. Strict known cells: #4636 (uninstall
after a target change) and #4638 (frozen widened refusal leaves hook
config).

Refs #4564, #4565, #4100

Co-authored-by: Copilot App <[email protected]>
…sts the refusal-credit module

Co-authored-by: Copilot App <[email protected]>
A hook-only package, deployed and approved, loses its lockfile; a deny
or a dropped approval then retires the hook on the next install.

Refs #4564 #4565

Co-authored-by: Copilot App <[email protected]>
(cherry picked from commit b260b74)
One package with a skill and an instruction, installed through the
scenario kit with org policy on: deployed targets (copilot, claude, cursor)
deploy the instruction, compile-staged ones (codex, gemini, opencode) keep
it under apm_modules until apm compile. Six TGT shapes per route plus
install/compile/update/prune/uninstall/bundle-install per route. 28 T-6c
baseline cells (and 8 T-6a TGT pairs) become required. Strict known cell
uninstall-keeps-a-bundle-owned-instruction tracks #4703.

Refs #4102, #4565

Co-authored-by: Copilot App <[email protected]>
…licy across the factors

Discharges the T-7b pair obligations (GATE=denied-dependency and
NOPOLICY=on crossed with OP, SRC, PRIM, DEPLOYED, TGT, NET and the
modifiers) with real-CLI receipts in tests/lifecycle/scenarios/
test_policy_pairs.py; T-7b joins SCENARIO_LANES and the module joins
SCENARIO_MODULES.

- A denied dependency refuses every resolving install (plain, --force,
  --update, a selected package, each source, offline from the cached
  policy, online from git, after any target change) with exit 1 and no
  write; these credit only through the declared POLICY_REFUSALS table.
- --dry-run reports "Would be blocked by policy" and exits 0; --no-policy
  proceeds and announces that enforcement is off for the run.
- The user's bytes (edited, unowned, lost-lock) survive both.
- An org mcp.deny refuses inline and registry servers; the world gains an
  mcp-deny-all variant because a single "*" stays within one segment of a
  namespaced registry name (policy/matcher.py).
- Strict known cell: a user-scope install never discovers the org policy,
  so a denied plugin with bin/ installs (#3703).

T-7b obligations: 47 baseline -> 43 required, 1 known-failing, 3 baseline.

Refs #4108 #4565

Co-authored-by: Copilot App <[email protected]>
Project-scope history and offline rows no longer credit PRIM=bin (U-BIN), pack history rows are refusals and credit nothing, the registry package stays in the scenario that selects the registry, user-scope scenarios observe plugin bin/ and set user_scope for I1, and the uninstall hint-repeat output cell (closed #4636) is retired.

Co-authored-by: Copilot App <[email protected]>
…o tests (AQ003)

Each flagged test now asserts the exit code it relies on or the durable
file it leaves; the two strict cells (#3703 user-scope deny, #4703
bundle-owned instruction) assert the promised outcome under known_defect
instead of pinning the defect.

Co-authored-by: Copilot App <[email protected]>
# Conflicts:
#	tests/quality/lifecycle_obligations.json
Adds W3's guard test_every_scenario_credit_names_a_collected_node (from danielmeppiel-w3-t6a-history-v2); the 40 target-history keys were built target-first and named nodes pytest never collects.

Co-authored-by: Copilot App <[email protected]>
# Conflicts:
#	tests/quality/lifecycle_obligations.json
…-read each local catalog

Regenerate on the re-stack. refresh_marketplace(every=True) now adds a
probe plugin to each local/file catalog before the refresh and credits
their cells only when the command reports the refreshed count (2 plugins)
for that catalog, then restores it: a skipped or stale read fails.

Co-authored-by: Copilot App <[email protected]>
The M-SOURCE spine now drives two more ops through the real CLI:

- audit_pass: `apm audit --dry-run` then `apm audit` on each converged
  remote-skill state and after the registry exec pass; read-only for every
  declared form, local bundles included.
- decide_pass: `apm approve --all` pins every installed package with
  executables; a local bundle is approved by the content key `approve
  --pending` prints and installed again as that hint says; `apm deny` of a
  catalog plugin and the `apm install` its hint names retire its
  executables (I4); the gate is then restored. The model now carries the
  executables decisions, so the deploy oracle checks approved state.

The p-lsp bundle stays parked: its LSP server shares the local p-lsp's name,
and once the bundle owns it the manifest install is refused by design.

R5 (Q&L ruling): approve-deny x {mcp-registry, inline-mcp} maps onto
U-FIRST-PARTY-MCP; approve decides only installed packages
(scan_installed_executable_packages), witnessed by a live-scan test.

Ledger vs #4711: baseline 531 -> 452 (75 T-2 cells required, 4 mapped by
R5); T-2 baseline 220 -> 141.

Refs #4564
Refs #4565

Co-authored-by: Copilot App <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The promoted audit and approve/deny cells cannot earn receipts because their CLI passes are missing, while several scenario assertions can credit incomplete or incorrect behavior.

7 open issues
What changed in this PR

This test-only PR extends APM’s lifecycle coverage toward the baseline reduction target in #4564. It includes the stacked corpus work from #4711 and adds audit and approval/denial coverage targets to the source machine.

Changes:

  • Expands source, executable-gate, and lockfile lifecycle coverage.
  • Adds policy, ownership, offline, target-history, and file-routing scenarios.
  • Updates obligation mappings, refusal validation, and CI quality checks.
File Description
tests/​quality/​test_scenario_refusal_credit.py Adds negative controls for refusal credits.
tests/​quality/​test_promise_obligations.py Checks scenario credits against collected tests.
tests/​quality/​test_generated_obligations.py Requires both marketplace gate-level probes.
tests/​lifecycle/​world/​test_world.py Adds the MCP deny-all policy expectation.
tests/​lifecycle/​world/​services.py Serves a namespaced MCP deny-all policy.
tests/​lifecycle/​scenarios/​test_policy_pairs.py Adds policy-denial and bypass scenarios.
tests/​lifecycle/​scenarios/​test_ownership_siblings.py Expands user-content preservation scenarios.
tests/​lifecycle/​scenarios/​test_network_offline.py Adds offline lifecycle scenarios.
tests/​lifecycle/​scenarios/​test_history_upgrade.py Covers commands after target changes.
tests/​lifecycle/​scenarios/​test_file_routing.py Covers deployed and compile-staged instructions.
tests/​lifecycle/​scenarios/​_kit.py Adds refusal and output-expectation support.
tests/​lifecycle/​model/​state.py Models the MCP deny-all policy.
tests/​lifecycle/​machines/​test_m_source.py Expands source forms and operation cells.
tests/​lifecycle/​machines/​test_m_scope_lock.py Adds stale-lock, absent-lock, and auxiliary-command coverage.
tests/​lifecycle/​machines/​test_m_gate.py Registers additional executable-gate test sequences.
tests/​lifecycle/​machines/​_kit.py Adds user-scope deployment observations.
tests/​lifecycle/​machines/​_gate_matrix.py Extends user-scope and marketplace gate coverage.
tests/​lifecycle/​machines/​_gate_bundle.py Adds bundle-install and pack gate sequences.
tests/​lifecycle/​machines/​_gate_bin.py Adds user-scope plugin executable coverage.
tests/​lifecycle/​generator/​witnesses.py Maps expanded machine and scenario evidence.
tests/​lifecycle/​generator/​test_generator_rules.py Tests updated mappings and root-MCP scan boundaries.
tests/​lifecycle/​generator/​rules.py Adds marketplace, target-change, and MCP mappings.
tests/​lifecycle/​generator/​emit.py Emits scenario-backed refusal obligations.
tests/​lifecycle/​generator/​covering.py Excludes scenario-owned refusals from generated rows.
.github/​workflows/​merge-train.yml Runs refusal-credit checks in the merge train.
.github/​workflows/​main-architecture-ratchets.yml Runs refusal-credit checks on main.
.github/​workflows/​ci.yml Adds refusal-credit checks to CI.

Review effort: Balanced

]

OPS = ("install", "update", "uninstall", "prune", "compile", "lock", "marketplace")
OPS = ("install", "update", "uninstall", "prune", "compile", "lock", "marketplace", "audit", "approve-deny")
self._args(op),
exits=exits,
cells=(cell,),
converged=False,
# install and writes nothing (policy/install_preflight.py, dependency-denylist).
POLICY_BLOCK = ExpectedRefusal(
1,
r"Blocked by org policy .*Nothing was changed|Nothing was written",
Comment on lines +917 to +918
if not ids:
return
Comment on lines +121 to +123
if route == "deployed":
assert marked, "a deployed instruction is a target file carrying the marker"
assert not any(name.endswith(("AGENTS.md", "GEMINI.md")) for name in marked), marked
for src, line in _MCP_ROWS.items():
credit = [{"OP": "mcp-install", "TGT": tgt, "SRC": src, "PRIM": "mcp", **_CONTEXT}]
scenario.source_moved()
scenario.run(line, credit=credit)
Comment on lines +392 to +394
step = scenario.run(line, credit=[_pair(SRC=src, NOPOLICY="on")], says=[_NO_POLICY_SAYS])
assert step.result.returncode == 0, step.output
scenario.finish()
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Superseded by corpus train 5 (ql/corpus-train-5 @66fa19c30bc), which carries this batch in full together with T-2 b6. Closing to keep one landing path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants