Skip to content

test(lifecycle): M-SCOPE-LOCK drift spine for stale and absent lockfiles (T-3 batch 1) - #4604

Merged
Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
w2-t3-lock-drift
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 2 commits into
mainfrom
w2-t3-lock-drift

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

T-3 (M-SCOPE-LOCK) batch 1 of the 0.38 lifecycle burn-down. 96 obligations leave the baseline: 94 T-3 + 2 T-2. 94 become required; 2 become known-failing and track #4600.

  • Drift spine (test_scope_lock_drift_spine_credits_stale_absent_and_side_doors[project|user]) covers two lockfile states:

    • stale: the manifest and the lock disagree on the toggle package; the spine re-flips it before every command.
    • absent: the lockfile is deleted before every command.

    It runs the lockfile commands the existing spine leaves open in those states. It also runs four side doors at every lock state the generator still lists:

    • apm deny on an installed gated package;
    • apm install --mcp <registry server>;
    • apm install <local bundle>;
    • apm marketplace list (project scope only).

    Every step runs check_cross_cutting (I1-I9). Admitted side doors also assert their own outcome: the requested MCP server is declared and configured, and the bundle's LSP server stays parked. Refusals assert byte-identical durable state.

  • Observed behavior pinned:

    • a stale lock reconciles on install/update/lock and refuses install --frozen;
    • apm deny succeeds under a newer-generator lock (it writes the approval store, never the lockfile) and refuses without a lockfile (nothing is installed);
    • install --mcp and bundle install refuse a newer-generator lock.
  • Lock context. Every lockfile cell also records what its step acted on, via lock_context: source, primitive, gate level, target, network and prior deployment (a deleted lock means present-provenance-unknown). generator/witnesses.py credits those values only on implied ids that name LOCK (the anchor), so a refused write never discharges a success cell. The plain OP x SCOPE x LOCK credit is unchanged.

  • Bench. An absent or unreadable lockfile attributes nothing, so I1 has no ledger to compare. After a deleted lockfile, files stay unattributed until a resolving command records them again; apm lock and the side doors write a lock without them.

  • Strict known cell [BUG] apm marketplace list writes ~/.apm/marketplaces.json #4600. apm marketplace list is a read command, but on a fresh HOME it creates ~/.apm/marketplaces.json (I5). Cell T4|marketplace|project|consistent is known-failing until the fix.

Obligation counts (tests/quality/lifecycle_obligations.json, regenerated on main):

baseline required known-failing
before 1468 1023 0
after 1372 1117 2

T-3 baseline: 243 -> 149. T-2: 496 -> 494.

PR shard cost: one new parametrized test with about 30 CLI steps per scope. Locally on a loaded host it takes 57 s (project) and 32 s (user); expect about half that on CI.

Issue and approved scope

Issue: Refs #4564, Refs #4565, Refs #4097

Human scope-approval comment: #4564 (comment)

Does this PR complete the issue, or what remains? Partial. Still open: T-3 pairs that need other sources, targets, network modes and gate levels under each lock state, and pack under a stale or newer lock (it refuses local-path dependencies).

Type of change

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

Testing

  • Tested locally

  • All existing tests pass

  • Added tests for new functionality (if applicable)

  • pytest tests/lifecycle/machines/test_m_scope_lock.py tests/quality/test_promise_obligations.py tests/quality/test_generated_obligations.py tests/lifecycle/generator/test_generator_rules.py tests/lifecycle/world/test_world.py -k "not policy_variant" -> 175 passed (engine driver, host-guarded)

  • python -m tests.lifecycle.generator --check -> up to date

  • Lint contract: ruff 0.15.12 check and format, lint-auth-signals.sh, complexity ratchet (--base-ref origin/main), tests.quality.taxonomy --changed and check_test_assertions.py -> clean

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md.
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • 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]>

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

Active gaps in the lifecycle tests allow missing ownership records, unauthorized deployment, read-side mutations, unpersisted denials, and incomplete reconciliation to pass undetected.

5 open issues
What changed in this PR

Extends the M-SCOPE-LOCK lifecycle tests for the 0.38 coverage effort, exercising stale and absent lockfiles in project and user scopes without changing production behavior.

Changes:

  • Adds a drift test sequence covering lockfile commands, deny, MCP installation, bundle installation, and marketplace listing.
  • Adds lock-context witness crediting and adjusts observations when lockfile provenance is unavailable.
  • Regenerates obligations: 94 become required and two become known-failing, tracking #4600.
File Description
tests/​quality/​lifecycle_obligations.json Updates obligation statuses, witnesses, and coverage counts.
tests/​lifecycle/​machines/​test_m_scope_lock.py Adds drift scenarios, side-door checks, and the known marketplace failure.
tests/​lifecycle/​machines/​_kit.py Clears managed-path attribution when no readable lockfile exists.
tests/​lifecycle/​generator/​witnesses.py Maps drift cells and lock-specific context to generated obligations.

Review effort: Balanced

self.current = op
exits = self.exits(op)
requested = self._requested(op)
step = self.step(
cells=(cell,),
converged=False,
model=requested,
mutating=op in MUTATING and state != "newer",
mutating=op in MUTATING and state != "newer",
)
refused = step.result.returncode != 0
unchanged = self.durable() if refused else {"outside": ("*",)}
Comment on lines +499 to +500
if not refused:
self.check_side_door(op)
Comment on lines +505 to +506
if not refused and self.bench.lock_path.is_file() and state in DRIFT_STATES:
self.lock_state = "consistent"
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Superseded by the train #4614 (corpus train 2), which merges this branch with --no-ff and regenerates the obligation ledger once. The red here was an unrelated Windows flake (tests/unit/policy/test_cache_atomicity.py). This PR stays open as the linked source until the train lands.

…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]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit e54568c into main Nov 22, 2026
3 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the w2-t3-lock-drift branch November 22, 2026 15:09
Jason 'Jay' Jack (jasonjack-jay) pushed a commit to jasonjack-jay/Agent-Package-Manager that referenced this pull request Nov 23, 2026
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