Skip to content

refactor(output): remediation-advice owner with executable proofs (#4090, part 1) - #4128

Closed
Daniel Meppiel (danielmeppiel) wants to merge 7 commits into
mainfrom
danielmeppiel-potential-disco
Closed

Daniel Meppiel (danielmeppiel) wants to merge 7 commits into
mainfrom
danielmeppiel-potential-disco

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Description

TL;DR

APM printed about 500 pieces of free-text remediation advice (run 'apm install' to ...), with no owner and no check that the advice works. This PR adds the remediation-advice owner (core/remediation.py): a closed catalog of structured Remediation(command, fixes_promise, clears) entries rendered in one place. It moves every advice site in install/, policy/, commands/audit.py and commands/install.py onto it and runs each of the 81 entries on the installed CLI to show it clears the state it names. Running them exposed 7 pieces of advice that did not work; all are fixed here.

Note

Part 1 of 4 for #4090 (Stream H lane H-I). A closed-world guard pins the 370 sites still outside the owner with an exact, shrink-only per-file baseline. Three follow-up 0.37 PRs (commands/*; integration, marketplace and bundle; everything else) take it to zero before the 0.37 tag.

Problem (WHY)

Why these matter: the repo's architecture rule is "Every durable decision, vocabulary, outcome, write, or contract has exactly ONE canonical owner.", and a centralization is complete only with "a hermetic behavioral regression test" plus "a registered static guard in the architecture linter".

Approach (WHAT)

# Fix
1 New owner core/remediation.py: frozen Remediation(id, command, fixes_promise, before, then, clears), built only by _entry(); renderers clause(), sentence(), either(), each(), bind(), to_json().
2 130 priority-set advice literals now render owner entries, in 81 catalog entries. Drift text and the audit drift check share one selector (drift_render.drift_remediations) through DRIFT_KIND_REMEDIATION.
3 Additive JSON: a failed apm audit --ci check carries remediations: [{id, command, fixes, clears, before?, then?}].
4 Every catalog id has exactly one executed proof (PROVES tuples), enforced by tests/unit/core/test_remediation_catalog.py.
5 Four linter rules, each with a sorted mutation case: closed-world advice; drift kinds (H7); frozen help (DX5); init apply (DX6).

Implementation (HOW)

  • src/apm_cli/core/remediation.py — the owner and its 81-entry catalog. Each entry names the state it clears; unbound {placeholders} raise instead of rendering.
  • policy/ci_checks.py, policy/policy_checks.py, policy/models.py — CheckResult.remediations is serialized in to_json. Messages render owner clauses.
  • install/drift_render.py, install/local_edits.py — the edited-file advice is now Delete <files>, then run 'apm install' to restore the locked content. The --force alternative is kept. Generic re-sync applies only to unintegrated, orphaned and unedited modified findings.
  • install/**, commands/install.py, commands/audit.py, security/executables.py, core/deployment_ledger.py — sites render owner entries. DEPLOYMENT_OWNER_REMEDIATION is retired; consumers use INVALID_DEPLOYMENT_OWNERS.
  • policy/install_preflight.py — --verbose lifts the five-line dry-run policy preview cap, so the overflow advice (apm install --dry-run --verbose <same-arguments>) is true.
  • scripts/architecture_linter/checks/contracts_remediation_advice.py — four rules registered in the contracts_tests group. The registry adds owner remediation-advice (steward-approved). DX5's guard joins frozen-install-mutation-eligibility; DX6's joins onboarding-metadata-only.
  • Tests — the harness tests/utils/remediation_proof.py plus seven proof modules under tests/integration/test_remediation_*. Unit assertions now read the owner instead of copying strings.
  • Docs — reference/cli/audit.md documents remediations; common-errors.md, baseline-checks.md and update.md show the new advice text. The apm-guide commands.md notes the field.

Diagrams

Legend: one owner feeds both renderers (text and audit JSON), and each proof runs the advised command through the installed binary.

flowchart LR
    C["core/remediation.py catalog (81 entries)"] --> T["clause / sentence / either"]
    C --> J["CheckResult.remediations to_json"]
    T --> O["CLI text: install, audit, policy"]
    J --> A["apm audit --ci --format json"]
    O --> P["proof: run advised command via binary"]
    A --> P
    P --> V["state named by clears is gone"]
    G["linter: contracts-tooling-remediation-advice"] -.->|"rejects free text outside owner"| O
Loading

Trade-offs

  • Closed catalog vs ad-hoc Remediation(...) at sites. Chose a closed catalog: "each entry has a proof" is then a set equality, not a convention. Cost: 81 entries, each with a proof.
  • Priority set now, 370 sites baselined. Lead decision. The rule pins an exact per-file count, so new free text fails and the count only shrinks. The three follow-ups are on the 0.37 critical path.
  • Wording becomes uniform ("Run 'X' to Y."). Some messages read differently. Tests now assert the owner's rendering, so future wording changes touch one place.
  • Matcher scope. The rule matches advice naming an apm <cmd>. Prose such as "rerun the same install command without --frozen" is out of scope.
  • Component proofs for 3 entries. prune-package-copies, readmit-codex-plugins and complete-codex-migration need an OSError or a real Codex CLI. Each runs in a fresh process with a single stub and keeps a recorded reason.

Benefits

  1. 81/81 remediation entries have an executed proof; 78 run through the installed binary.
  2. Seven pieces of advice that did not clear their state were found and fixed (below).
  3. apm audit --ci --format json gives scripts an exact command to run for each failed check.
  4. Free-text advice cannot re-enter src/apm_cli outside the baseline, and the baseline can only shrink.

Validation

Advice the proofs disproved, and the fix
Entry Was Now Evidence
frozen-refresh-lock then "retry the frozen install" then "retry as apm install --frozen, without packages or --mcp" --frozen <pkg> always refuses package args
restore-managed-paths apm install first remove the listed symlink or non-regular path install refuses symlinked destinations
clean-download-cache apm cache clean apm cache clean --yes without --yes it prints Aborted! when non-interactive
trust-bin apm install --trust-bin <pkg> (and the native park's bare Re-run: apm install --global --trust-bin) apm install --global --trust-bin bin/ deploys only with the user-scope Claude plugin; the native park now renders the same entry
configure-registry apm config set registry.<n>.url first apm experimental enable registries the set exits 1 without the flag
readmit-codex-plugins apm install apm install -g --target codex plain install: "No apm.yml" / user-scope only
policy-full-report apm audit apm install --dry-run --verbose <same-arguments> the capped preview exists only in dry-run installs

Red before (main 1b96706b7d, installed CLI): test_remediation_advice_lifecycle.py 3/3 FAILED, ... carries no structured remediation. Green after: all executed proofs pass.

$ APM_E2E_TESTS=1 APM_BINARY_PATH=.venv/bin/apm uv run --extra dev pytest tests/integration/test_remediation_advice_lifecycle.py tests/integration/test_remediation_proofs_{audit,drift,frozen,install,surface}.py -n 3
65 passed in 126.01s
$ ... pytest tests/integration/test_remediation_proofs_trust.py -n0
17 passed in 83.23s        # test_trust_bin re-proven after main merge (native park), also under CI=true
$ uv run --extra dev pytest tests/unit/core/test_remediation_catalog.py tests/quality/test_lifecycle_bug_ledger.py
5 passed
CI-mirror lint chain (merged with main)
ruff check (src tests scripts/...)            All checks passed!
ruff format --check                           already formatted
pylint R0801                                  Your code has been rated at 10.00/10
bash scripts/lint-auth-signals.sh             [+] auth-signal lint clean
check_complexity_ratchet.py --base-ref main   [+] complexity ratchet clean: 199 grandfathered violation(s)
YAML / file-length (2100) / relative_to       no output
bash scripts/lint-architecture-boundaries.sh  exit 0
Full local unit + spec + quality + architecture + proofs run

30326 passed, 302 failed. Every failure reproduces on main with the same environment, or is an artifact of this sandbox: installer ownership (246), release metadata (35), network guard (8), git env/transport (4), credential report (1), test_output_mode (6; APM_E2E_TESTS=1 suppresses the update notice by design), and test_orphan_owner_guard_is_closed_world[renamed-evidence-predicate], which also fails on main 640e8c04. The one proof failure, test_trust_bin, was fixed in 9cb1b0ff.

Scenario Evidence

# Scenario (user promise) Principle(s) Test(s) proving it Type
1 Following any advice APM prints clears the problem it reported DevX tests/integration/test_remediation_proofs_*.py, tests/integration/test_remediation_advice_lifecycle.py e2e
2 Every remediation APM can advise is proven exactly once Governed by policy tests/unit/core/test_remediation_catalog.py::test_every_catalog_entry_has_exactly_one_executed_proof unit
3 A locally edited file's drift advice actually restores it; each drift kind clears DevX tests/integration/test_remediation_proofs_drift.py e2e
4 CI scripts can read and run the fix for a failed audit check DevX tests/integration/test_remediation_advice_lifecycle.py::test_audit_remediation_clears_the_reported_check e2e
5 Free text, the H7 map, frozen help and init apply cannot regress silently Governed by policy tests/integration/test_architecture_owner_rule_mutations.py::test_owner_rule_catches_its_guard_mutation integration

How to test

  • APM_E2E_TESTS=1 APM_BINARY_PATH=$PWD/.venv/bin/apm uv run --extra dev pytest tests/integration/test_remediation_advice_lifecycle.py tests/integration/test_remediation_proofs_*.py -n 3 → all pass.
  • In a project, delete apm.lock.yaml, then run apm audit --ci --format json → lockfile-exists carries remediations[0].command == "apm install".
  • Edit a deployed skill file, then run apm audit → the advice says delete, then apm install, with no plain re-sync line.
  • Add "run 'apm install' to restore" to any priority file, then run bash scripts/lint-architecture-boundaries.sh → contracts-tooling-remediation-advice fails.

Issue and approved scope

Issue: Refs #4090 (part 1 of 4). Remaining sites migrate in three follow-up 0.37 PRs that shrink the baseline to zero.

Human scope-approval comment: #4090 (comment)

Does this PR complete the issue, or what remains? Not complete. 370 advice sites in 112 files outside the priority set remain, pinned by the shrink-only baseline in contracts_remediation_advice.py.

Type of change

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

Testing

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

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md: user-visible effect first, 25 words or fewer, ending with (#PR); breaking changes only under upgrade notes; no Highlights; see .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.

apm-spec-waiver: remediation advice wording, an additive audit JSON field and a verbose preview cap; no OpenAPM install, lockfile or policy semantics change

Co-authored-by: Copilot [email protected]

…iation-advice owner (#4090)

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…; fix advice the proofs disproved (#4090)

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…#4090)

The native Claude park now renders the owner's trust-bin entry, and its
proof runs it on the live user-scope path.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
apm-spec-waiver: remediation advice wording, an additive audit JSON field and a verbose preview cap; no OpenAPM install, lockfile or policy semantics change

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Superseded by #4143, which carries the remediation-advice owner and migrates all sites.

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.

1 participant