Skip to content

fix(marketplace): marketplace list never creates the user registry (#4600) - #4616

Merged
Daniel Meppiel (danielmeppiel) merged 1 commit into
mainfrom
danielmeppiel-p1-4600-marketplace-list-readonly
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 1 commit into
mainfrom
danielmeppiel-p1-4600-marketplace-list-readonly

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

TL;DR — apm marketplace list is a read command, but on a fresh HOME it created ~/.apm/marketplaces.json ({"marketplaces": []}). The registry owner, src/apm_cli/marketplace/registry.py, now reads a missing registry as empty and creates the file only on the first real write. Output and exit codes are unchanged.

Closes #4600

Dependency order: independent. Interacts with #4604: whichever lands second drops/flips the #4600 known cell (KNOWN_T4 / DRIFT_KNOWN_CELLS) and regenerates obligations.

Problem (WHY)

  • _load() defaulted to create=True and called _ensure_file(), so every reader that used get_registered_marketplaces() (including marketplace list, marketplace_names, get_marketplace_by_name) wrote ~/.apm/marketplaces.json when it was missing.
  • Lifecycle law I5 ("each command writes only its declared write set", tests/lifecycle/oracles.py) flags it: marketplace wrote home:['.apm/marketplaces.json'].
  • There were two read paths (get_registered_marketplaces creating, read_registered_marketplaces not). Readers could pick the wrong one.

Approach (WHAT)

Before After
_load(create=True) → _ensure_file() writes {"marketplaces": []} _load() never writes; a missing file reads as []
_save relied on _ensure_file() _save creates $APM_HOME (mode 0700) and writes atomically (unchanged os.replace)
Two readers: get_registered_marketplaces / read_registered_marketplaces One reader, get_registered_marketplaces; read_registered_marketplaces removed and its 2 callers repointed

Implementation (HOW)

File Change
src/apm_cli/marketplace/registry.py Drop _ensure_file and the create flag; _save makes the config dir itself.
src/apm_cli/marketplace/project_marketplaces.py, reconcile.py Use get_registered_marketplaces (already non-creating semantics).
tests/lifecycle/test_marketplace_registry_reads.py (new) Real-CLI receipt for `T4
tests/unit/marketplace/test_marketplace_registry.py test_reads_never_create_the_registry; fixtures no longer call the removed _ensure_file.
tests/fixtures/lifecycle_bug_ledger/bugs/4600.json, changelog.d/4616.fixed.md Ledger row #4600; one Fixed fragment.

Trade-offs

Benefits

  1. apm marketplace list on a fresh HOME creates nothing under ~/.apm (verified by snapshot, not by string compare).
  2. Listing an existing registry leaves it byte-identical.
  3. One read path in the owner; no caller can pick a writing read.

Issue and approved scope

Issue: Closes #4600

Human scope-approval comment: #4600 (comment)

Does this PR complete the issue, or what remains? Complete. The cell T4|marketplace|project|consistent earns a passing receipt that fails on main; controls and ledger/changelog rows are included.

Type of change

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

Testing

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

Scenario evidence

promise: P-INV-I5 -- each command writes only its declared write set (source: tests/lifecycle/oracles.py ORACLE_LAWS)
cell: OP=marketplace SCOPE=project LOCK=consistent (T4|marketplace|project|consistent)   owner: src/apm_cli/marketplace/registry.py
instrument: target scenario test -> tests/lifecycle/test_marketplace_registry_reads.py::test_marketplace_list_never_creates_or_rewrites_the_registry (new: the replay-row schema forbids every HOME write, so it cannot express the `marketplace add` control)
oracles: [I1-I9 via check_cross_cutting, snapshot-absence, byte-unchanged]  decisive: Evidence(absent={"home": [".apm/marketplaces.json"]}, unchanged={"home": [".apm"]})
failing-before: pytest tests/lifecycle/test_marketplace_registry_reads.py (main owner) -> I5 ...: marketplace wrote home:['.apm/marketplaces.json'] -- 1 failed
passing-after: same command with the fix -> passed
controls: `marketplace add <world marketplace>` creates the registry; `list` then shows `lifecycle-market` and the registry bytes are unchanged
guard+mutation: n/a (fix is inside the owner; no caller bypass)     ledger: #4600
hints executed: none printed beyond "Run 'apm marketplace add <source>'", which the add control runs
Validation commands and results

Engine driver (PR default), env -u GIT_EXEC_PATH "PATH=/usr/bin:/bin:$PATH" APM_BINARY_PATH=$PWD/.venv/bin/apm, run through the host guard:

Command Result
python -m pytest tests/lifecycle/test_marketplace_registry_reads.py -n 0 on main's src/ 1 failed: I5 (each command writes only its declared write set): marketplace wrote home:['.apm/marketplaces.json']
python -m pytest tests/lifecycle/test_marketplace_registry_reads.py tests/unit/marketplace tests/unit/test_thread_safety.py tests/unit/test_outdated_marketplace.py tests/unit/test_outdated_marketplace_detection.py tests/quality/test_lifecycle_bug_ledger.py -n 0 2002 passed, 1 failed (bug in the new unit test, fixed below)
python -m pytest tests/unit/marketplace/test_marketplace_registry.py tests/unit/test_view_command.py tests/unit/test_state_leak_detector.py -n 0 77 passed
uvx [email protected] check / format --check (CI paths) All checks passed / 3001 files already formatted
pylint R0801 --min-similarity-lines=10 10.00/10
bash scripts/lint-auth-signals.sh exit 0
python scripts/check_complexity_ratchet.py --base-ref origin/main [+] complexity ratchet clean
python -m tests.quality.taxonomy --changed [+] tm006: 2 changed test module(s) carry their marker and promise
python scripts/check_test_assertions.py [+] assertion-quality ratchet clean
bash tests/spec_conformance/mode_b_detector.sh [+] mode_b: no critical-path diff; OK
After rebase on 0f9b391: pytest tests/lifecycle/test_marketplace_registry_reads.py tests/unit/marketplace/test_marketplace_registry.py -n 0 18 passed
pytest tests/quality/test_lifecycle_bug_ledger.py 2 passed
changelog_fragments.py check / check-unreleased --base-ref origin/main [+] 1 changelog fragment(s) valid / [+] no new bullets under ## [Unreleased]

How to test

  • mkdir -p /tmp/h /tmp/p && cd /tmp/p && HOME=/tmp/h apm marketplace list → [i] No marketplaces registered. ..., exit 0
  • ls /tmp/h/.apm/marketplaces.json → no such file
  • HOME=/tmp/h apm marketplace add <source> → /tmp/h/.apm/marketplaces.json exists; apm marketplace list shows it and leaves the file bytes unchanged

Changelog

  • One fragment, changelog.d/4616.fixed.md (replaces a line 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.

Co-authored-by: Copilot [email protected]

Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Parked under the program's open-PR cap for this lane; the branch stays pushed and this PR will be reopened when the lead clears it.

…4600)

Reads of ~/.apm/marketplaces.json treat a missing file as an empty
list; only _save (add, remove, manifest sync) creates it. The
create-on-read path and read_registered_marketplaces are gone, so every
reader goes through the one non-creating _load.

The lifecycle receipt T4|marketplace|project|consistent proves on the
real CLI that a fresh HOME lists nothing and creates nothing under
~/.apm, that add still creates the registry, and that list keeps an
existing registry byte-identical.

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.

🟢 Approval recommended

No active review issues are recorded for the change making marketplace registry reads side-effect-free.

No open issues 🎉

What changed in this PR

Fixes #4600 by making marketplace registry reads side-effect-free. A missing registry now reads as empty; registration changes create it when needed, preserving listing output and exit codes.

Changes:

  • Consolidates registry reads into one non-writing path and moves directory creation into _save.
  • Updates reconciliation and project marketplace callers to use the unified reader.
  • Adds regression coverage for missing and existing registries, plus a bug-ledger entry and changelog fragment.
File Description
tests/​unit/​marketplace/​test_marketplace_registry.py Tests non-creating reads and updates registry fixtures.
tests/​lifecycle/​test_marketplace_registry_reads.py Verifies read-only listing and first-registration writes through the CLI.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​4600.json Records the bug and links regression tests.
src/​apm_cli/​marketplace/​registry.py Makes reads non-creating and consolidates the reader API.
src/​apm_cli/​marketplace/​reconcile.py Uses the unified registry reader during reconciliation.
src/​apm_cli/​marketplace/​project_marketplaces.py Uses the unified reader for shadowed-registration notices.
changelog.d/​4616.fixed.md Documents the user-visible listing fix.

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 96a3ec5 into main Nov 21, 2026
92 of 95 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-p1-4600-marketplace-list-readonly branch November 21, 2026 18:30
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.

[BUG] apm marketplace list writes ~/.apm/marketplaces.json

2 participants