Repository navigation
fix(manifest): route init re-init target rewrites through the declaration owner; reject apm.yml YAML anchors - #3867
Conversation
…YAML anchors apm init re-init now carries an existing apm.yml's targets over through the one rewrite mapping apm manifest migrate uses (rewritten_manifest_targets -> plan_target_migration), so `target: agents` becomes `targets: [copilot]` instead of an invalid `targets: [agents]`. Unmappable tokens are refused before writing, and every rewrite is parsed back (verify_rewritten_manifest) before it is written. The apm.yml read owner (models/manifest_io.py) now rejects YAML anchors and aliases with the file and line, as OpenAPM req-mf-020(b) requires, for install, compile, audit, manifest migrate and every other manifest read. The migrate path that rewrote anchored target lists is removed. Static guards extended in registry_delegation.target_vocabulary and install-deployment-consumer-manifest-rewrite, with mutation cases. Fixes #3857 Fixes #3858 Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Manifest anchor errors can cause re-initialization to silently discard declared targets and overwrite the manifest, while CI audits can fail before producing JSON/SARIF reports.
2 open issues
What changed in this PR
This PR addresses #3857 and #3858 by centralizing manifest target rewrites and enforcing OpenAPM’s ban on YAML anchors and aliases.
Changes:
- Reuses the migration target mapping during re-init and validates rendered manifests before writing.
- Adds shared anchor/alias rejection and updates manifest consumers and architecture guards.
- Adds regression coverage and updates documentation and conformance records.
| File | Description |
|---|---|
| tests/unit/test_init_phase3w5.py | Tests re-init mapping and refusal behavior. |
| tests/unit/models/test_manifest_targets.py | Checks re-init uses migration semantics. |
| tests/unit/models/test_manifest_target_migration.py | Tests shared mapping and rewrite validation. |
| tests/unit/models/test_manifest_io.py | Tests anchor and alias rejection. |
| tests/spec_conformance/test_manifest_reqs.py | Adds req-mf-020 rejection coverage. |
| tests/integration/test_manifest_rewrite_preservation_lifecycle.py | Replaces alias-preservation expectations. |
| tests/integration/test_manifest_anchor_rejection_lifecycle.py | Checks CLI rejection without project changes. |
| tests/integration/test_init_reinit_targets_lifecycle.py | Checks re-init produces installable targets. |
| tests/integration/test_architecture_owner_rule_mutations.py | Tests guards against owner bypasses. |
| src/apm_cli/models/manifest_targets.py | Routes target reads through manifest validation. |
| src/apm_cli/models/manifest_target_migration.py | Shares rewrite mapping and validates output. |
| src/apm_cli/models/manifest_io.py | Adds anchor detection and shared error base. |
| src/apm_cli/commands/init.py | Uses migration mapping during re-init. |
| src/apm_cli/commands/deps/cli.py | Propagates shared manifest rejection errors. |
| src/apm_cli/commands/audit.py | Adds manifest preflight before content scanning. |
| src/apm_cli/commands/_helpers.py | Supports validation before scaffold writes. |
| scripts/architecture_linter/checks/registry_owner_guards.py | Guards target rewrite ownership. |
| scripts/architecture_linter/checks/install_lsp_plugin.py | Guards manifest reads and anchor rejection. |
| packages/apm-guide/.apm/skills/apm-usage/package-authoring.md | Documents forbidden YAML anchors and aliases. |
| packages/apm-guide/.apm/skills/apm-usage/commands.md | Documents re-init and migration behavior. |
| docs/src/content/docs/troubleshooting/common-errors.md | Explains anchor errors and remediation. |
| docs/src/content/docs/reference/cli/manifest.md | Documents shared mapping and anchor refusal. |
| docs/src/content/docs/reference/cli/init.md | Documents re-init mapping and failure cases. |
| CONFORMANCE.md | Updates req-mf-020 test count. |
| CONFORMANCE.json | Records new conformance test cases. |
| CHANGELOG.md | Describes both manifest fixes. |
| .apm/architecture/owners/install-deployment.json | Updates manifest read ownership contract. |
| .apm/architecture/owners/core-runtime.json | Records shared target rewrite ownership. |
Review effort: Balanced
…ion owner `apm manifest migrate` is being removed (#3868), so the one target-token rewrite mapping now lives in models/manifest_targets.py (rewrite_target_names, verify_rewritten_manifest). apm init re-init calls it directly; plan_target_migration delegates to it and keeps only its user-scope `all` refusal. Panel folds: re-init refuses an apm.yml the read owner refuses (anchors, duplicate keys) instead of silently dropping its targets; rewrite errors keep their cause chain; the guard pins both init verify=True writes; lifecycle coverage for `apm audit --ci` and anchored dependency manifests. Co-authored-by: Copilot App <[email protected]>
APM Review Panel:
|
| Persona | B | R | N | Takeaway |
|---|---|---|---|---|
| Python Architect | 0 | 3 | 0 | Owner routing is sound and well guarded. Verification was opt-in and init had its own reader for the target declaration; both are tightened at ddb6660. |
| Test Coverage Expert | 0 | 3 | 0 | The real-binary lifecycle tests pin both fixes. The gaps for audit --ci, anchored dependency manifests and init verify wiring are closed at ddb6660. |
B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.
Top 4 follow-ups
- [Test Coverage Expert] Make bootstrap write paths (for example
apm install -g --mcp X --target intellij) translate legacy target names withrewrite_target_namesand check the result withverify_rewritten_manifest, the same as init. -- This is the last known path that can still write an invalidtargets:value ([intellij]). It is the same kind of bug as [BUG] apm init re-init rewrites target: agents to an invalid targets: [agents] #3857 on a different command. - [Test Coverage Expert] Clean up the dependency-manifest error: name the dependency's logical path instead of the staging directory, and remove the doubled period from the resolver wrapper (duplicate-key errors have the same problem). -- Users who hit the new anchor refusal in a transitive dependency see a temporary path and sloppy punctuation.
- [Python Architect] Keep the plain message of
TargetResolutionErrorseparate from its CLI-formatted text, so the[x]prefix stripping can be deleted. -- String-stripping at the CLI layer is fragile coupling, and [BUG] Deprecate vscode as an alias of copilot; copilot writes project MCP servers to workspace-root .mcp.json #3866 and [FEATURE] Drop apm manifest migrate; make the target: deprecation warning show the exact replacement #3868 should not copy the pattern. - [Python Architect] Have the [FEATURE] Drop apm manifest migrate; make the target: deprecation warning show the exact replacement #3868 and [BUG] Deprecate vscode as an alias of copilot; copilot writes project MCP servers to workspace-root .mcp.json #3866 removal PRs call
rewrite_target_namesandverify_rewritten_manifestfrommodels/manifest_targets.py, with no second copy of the mapping. -- Having one owner for the target rewrite mapping is the main structural gain here.
Recommendation
Merge at ddb6660. Both accepted issues are fixed at the right owners, every panel finding was folded with tests or guards, and the anchor change ships with a CHANGELOG entry that tells users how to fix their manifest. The highest-signal follow-up is the intellij bootstrap path that still writes an invalid targets: value. Track that next, and before the #3866/#3868 removals land, confirm they reuse the shared rewrite owner.
Full per-persona findings
Python Architect
- [recommended]
verify_rewritten_manifestis opt-in (verify=Falseby default), and the guard only checked that the call text exists in_helpers, not that init turns it on. Atsrc/apm_cli/commands/_helpers.py:672.
Folded: the guard now requires bothverify=Truecall sites ininit.py(2 mutation cases). The marketplace block appended after verification is a static template from the deprecated--marketplaceflag and is left as is. - [recommended]
init._read_existing_targetstreated an apm.yml the read owner refuses (InvalidManifestError) as having no targets. Atsrc/apm_cli/commands/init.py:849.
Folded: the error now propagates to the same refuse-before-write branch (exit 1 when non-interactive, a warning when interactive), with a unit test. - [recommended] Rewrite errors were flattened by string handling, and
from Nonedropped the cause. Atsrc/apm_cli/models/manifest_target_migration.py:101.
Folded: errors are now raisedfrom exc. The owner raisesTargetRewriteErroronly for "no equivalent" and "changes what deploys"; invalid declarations keep their own error types. SeparatingTargetResolutionError's plain message from its CLI rendering is follow-up 3.
Test Coverage Expert
- [recommended] No test covered an anchored dependency
apm.yml.
Folded:tests/integration/test_manifest_anchor_rejection_lifecycle.py::test_dependency_manifest_anchor_is_refused_before_any_write. Install refuses, the message names./pkgs/alpha, and nothing is deployed. The staging-path wording is follow-up 2. - [recommended] No test covered
apm audit --cion an anchoredapm.yml.
Folded:("audit", "--ci")is now in the lifecycle_COMMANDS. - [recommended] Dropping
verify=Truefrom the init call sites went undetected.
Folded: guard tokens plus theinit-skips-rewrite-verificationandplugin-init-skips-rewrite-verificationmutation cases.
This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.
Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.
…f aborting On a cold checkout (lockfile, no apm_modules/) `apm audit --ci` builds a scratch replay. An apm.yml the read owner refuses (YAML anchor, duplicate key) escaped as a raw error, so no JSON/SARIF report was rendered. It is now a materialization error, and the report shows the failed manifest-parse check. Covered by a cold-checkout lifecycle test. apm-spec-waiver: surfaces the existing req-mf-020(b) manifest rejection as a CI audit check failure; no new normative behaviour (req-mf-020 tests in test_manifest_reqs.py) Co-authored-by: Copilot App <[email protected]>
…ifest refusals PyYAML and ruamel anchor any object that appears twice in the data, so a manifest APM (or a test fixture) wrote could carry `&id001` and then be refused by the apm.yml read owner. dump_yaml / yaml_to_str now use a SafeDumper with ignore_aliases, and the round-trip writer ignores aliases, guarded in install-deployment-consumer-manifest-rewrite. `apm compile -g` frames an anchored user manifest as an error, and an undecodable one still reaches it as a YAML error now that read_manifest_target_declaration reads through the manifest owner. apm-spec-waiver: writer-side support for the existing req-mf-020(b) rejection; no new normative behaviour Co-authored-by: Copilot App <[email protected]>
Merge worker: ready to merge (maintainer merges)Folded in this run
Copilot signals reviewed
Deferred (out-of-scope follow-ups)
Regression-trap evidence (mutation-break gate)
Lint contractAt 61b4a34: uvx [email protected] check + format --check clean (incl. scripts/architecture_linter, windows probe); pylint R0801 10.00/10; scripts/lint-auth-signals.sh clean; scripts/lint_architecture_boundaries.py --root . clean. CIObserved green at exact head 61b4a34 (base main 511a801): gh pr checks 35 pass, 3 skipping, 0 pending/failed; mergeable MERGEABLE, mergeStateStatus BLOCKED (review required). First CI round at 7a33bfe failed: compile -g tests (load_yaml patch / UnicodeDecodeError) and opencode lifecycle fixture written with &id001 anchors; both fixed at 61b4a34. (after 2 CI round(s)). Generated by autopilot-pr-merge-worker. This comment is AI-generated and may contain errors. |
Co-authored-by: Copilot App <[email protected]>
…idance (#3903) * docs(changelog): enforce one-line entries in agent and contributor guidance Make the changelog rule concrete in its single source (.apm/instructions/changelog.instructions.md): one line, user-visible effect first, 25 words or fewer, ending with (#PR); breaking changes in "Breaking changes and upgrade notes" with a one-line migration; never a second line for the same change; no entry for internal-only PRs; two good and two bad examples from the current changelog. cut-release now re-sanitizes the whole [Unreleased] block at release time (dedupe, condense, Highlights, upgrade notes, ref/credit check). The delivery and merge autopilot workers, pr-description-skill, CONTRIBUTING.md, the PR template and the development guide point at the rule. Generated .github/ and .agents/ copies and apm.lock.yaml hashes are re-synced with apm install. Clean the current [Unreleased] block into that shape: drop the long duplicates of #3765/#3818, #3769, #3788, #3865, #3867, #3873, #3875, #3882 and the spec lines, fold their user-relevant caveats into the short lines, and drop test-only #3877. Co-authored-by: Copilot App <[email protected]> * docs(changelog): scope delivery-worker CHANGELOG edits to one task; shorten sanitizer example Address review: only the task whose files_hint owns CHANGELOG.md edits it (wave gate forbids shared-file edits across task branches), and the worked example now fits rule 2 while keeping its caveat and four refs. Co-authored-by: Copilot App <[email protected]> --------- Co-authored-by: danielmeppiel <[email protected]> Co-authored-by: Copilot App <[email protected]>


Description
Two manifest-owner defects in how
apm.ymlis read and rewritten.#3857 --
apm initre-init wrote an invalidtargets: [agents]. Before: re-runningapm init --yesovertarget: agentswrotetargets: [agents], and the nextapm installfailed withUnknown target 'agents'. After: the one target-token rewrite mapping now lives in the declaration owner,models/manifest_targets.py::rewrite_target_names. It was lifted out ofplan_target_migrationand is verified againstEffectiveTargetDecisionas before. Re-init calls it and writestargets: [copilot](agybecomesantigravity, a CSV becomes a list, and legacyallexpands exactly as re-init did before), so the project installs.plan_target_migrationdelegates to it, so removingapm manifest migrate(#3868) only deletes the planner. A legacy token with notargets:equivalent (intellij), an invalid declaration, or an apm.yml the read owner refuses is rejected before writing: under--yesor non-interactive, exit 1 with a--targethint; interactively, a warning and then the prompt.verify_rewritten_manifest(same owner) parses the rendered manifest back beforeapm initwrites it, and migrate verifies its rewrite the same way.#3858 -- manifest parsing accepted YAML anchors. Before:
&anchor/*alias(including<<: *base) inapm.ymlwere accepted by install, compile and audit, andapm manifest migratehad a special path for anchoredtarget:lists. After: the apm.yml read owner (models/manifest_io.py) rejects the first anchor or alias with the file and line, as OpenAPM req-mf-020(b) requires, before any write.read_manifest_target_declarationandapm manifest migratenow read through that owner,apm auditchecks the manifest before scanning, and the_detached_sequenceanchored-list path is removed. Duplicate-key and anchor errors share anInvalidManifestErrorbase.Owners and guards:
registry_delegation.target_vocabulary(guardregistry-delegation-manifest-target-declaration): the declaration owner must definerewrite_target_namesandverify_rewritten_manifest. Init must call the mapping and passverify=Trueon both scaffold writes, the scaffold writer must call the check, and migrate must delegate..authored_names(is allowed only in the owner, and onlyapm manifest migratemay import the in-place rewrite module. 8 new mutation cases.install-deployment-consumer-manifest-rewrite: the read owner must run the anchor check on every read; the target declaration reader, migrate and audit must read through it; the anchored-list rewrite tokens must not return. 6 new mutation cases..apm/architecture/owners/are updated.Notes:
load_manifest, whichAPMPackage.from_apm_ymluses for every apm.yml it reads, including dependency manifests (as duplicate-key rejection already does). This matches req-mf-020(b)'s consumer requirement.tests/integration/test_manifest_rewrite_preservation_lifecycle.pyasserted that aliases survive rewrites. That contract contradicts req-mf-020(b), so the fixture now uses a plain extension entry.vscodetarget ([BUG] Deprecate vscode as an alias of copilot; copilot writes project MCP servers to workspace-root .mcp.json #3866) andapm manifest migrate([FEATURE] Drop apm manifest migrate; make the target: deprecation warning show the exact replacement #3868) are being removed in separate PRs. The mapping lives only inrewrite_target_names, so those PRs reuse it, and the new tests do not assert anything aboutvscode.verify=Truewrites; lifecycle coverage now includesapm audit --ciand an anchored dependency manifest.Issue and approved scope
Issue: Fixes #3857
Issue: Fixes #3858
Human scope-approval comment:
Does this PR complete the issue, or what remains? It completes both records' Done-when. Lockfile and policy YAML anchor rules are out of scope per the #3858 record.
Type of change
Testing
Validation evidence (local, macOS, head of this branch):
APM_E2E_TESTS=1 APM_BINARY_PATH=$PWD/.venv/bin/apm .venv/bin/python -m pytest -p no:xdist tests/integration/test_init_reinit_targets_lifecycle.py tests/integration/test_manifest_anchor_rejection_lifecycle.py: passed. Before the fix, 5 of 6 failed: init wrotetargets: [agents]/[intellij], and install accepted an anchored manifest.test_manifest_rewrite_preservation_lifecycle.py test_manifest_duplicate_key_lifecycle.py test_manifest_target_migrate_lifecycle.py test_init_bootstrap_chain_lifecycle.py test_wave6_init_pack_coverage.pyplus the two new files: 105 passed..venv/bin/python -m pytest -p no:xdist tests/unit/models tests/unit/test_init_phase3w5.py tests/unit/commands/test_manifest_migrate.py tests/unit/test_audit_command.py tests/unit/test_init_command.py tests/spec_conformance/test_manifest_reqs.py(and related compile/deps/audit/helpers unit files): 1023 passed. The one failure,test_helpers.py::test_is_tool_available, is environmental (nopythonon macOS PATH) and pre-existing. With the src changes reverse-applied, 9 of the new unit and spec tests failed..venv/bin/python -m pytest -p no:xdist tests/integration/test_architecture_owner_rule_mutations.py -k "manifest_target_declaration_guard or consumer_manifest_guard or consumer-manifest or manifest-target": 29 passed.uvx [email protected] checkandformat --check, pylint R0801,bash scripts/lint-auth-signals.sh, andscripts/lint_architecture_boundaries.py --root .: all clean.Spec conformance (OpenAPM v0.1)
docs/src/content/docs/specs/openapm-v0.1.mdupdated (not needed: req-mf-020(b) already requires the rejection; spec text unchanged).docs/src/content/docs/specs/manifests/openapm-v0.1.requirements.ymlupdated (not needed).@pytest.mark.req("req-mf-020")test undertests/spec_conformance/added or extended (test_consumer_rejects_manifest_anchor_and_alias).CONFORMANCE.{md,json}regenerated viauv run --extra dev python -m tests.spec_conformance.gen_statementand committed.