Skip to content

fix(lockfile): an unsupported lockfile version names both remedies - #4469

Merged
Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
bug-sweep/p4233
Nov 21, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 5 commits into
mainfrom
bug-sweep/p4233

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

A lockfile with an unsupported lockfile_version (one written by a newer APM) failed every lockfile reader with a bare Unsupported lockfile version '99'; supported versions: 1, 2, 3, 4. It offered no way out. apm audit --ci reached the generic top-level Error: handler without an [x] line, and apm install --frozen appended unrelated "fix the file" advice. OpenAPM req-lk-004 requires the diagnostic to offer both remedies.

Every reader now fails with exit 1 and an [x] diagnostic naming both remedies, rendered from the remediation catalog (core/remediation.py, from #4143):

[x] Error installing dependencies: Unsupported lockfile version '99'; supported versions: 1, 2, 3, 4. Move apm.lock.yaml aside, then run 'apm lock' to regenerate it from apm.yml at a supported version, or 'apm self-update' to install an APM release that reads lockfile version '99'.
  • core/remediation.py: two catalog entries. lockfile-version-unsupported is apm lock with the step "move {path} aside" first. lockfile-version-upgrade-apm is apm self-update. The lockfile stays fail-closed: apm lock never silently downgrades a newer lock, so the regenerate remedy names the move-aside step.
  • deps/lockfile.py: LockFile.read() and the write path's existing-lock check raise UnsupportedLockfileVersionError with both remedies bound to the lock's path. A user-scope lock gets apm lock -g. The error also carries the structured remediations.
  • policy/ci_checks.py: apm audit --ci reports it as a failed lockfile-exists check, with both remediations in JSON and SARIF. commands/audit.py drift detection skips that lock instead of crashing. install/audit_replay.py reports it as a replay error.
  • install/service.py: --frozen prints the remedies without the contradicting generic advice. commands/lock.py prints its error with [x].

Issue and approved scope

Fixes #4233 (scope record: #4233 (comment))

Human scope-approval comment: #4233 (comment)

Does this PR complete the issue, or what remains? It completes it. It is stacked on #4143 (remediation catalog) and based on that branch; once #4143 merges it retargets to main.

Type of change

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

Testing

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

New tests/integration/test_unsupported_lockfile_version_lifecycle.py (installed CLI, lifecycle_smoke, req-lk-004). For each of install, install --frozen, lock and audit --ci against a lockfile_version: "99" lock, it asserts:

  • exit 1;
  • the [x] line;
  • both remedies, exactly;
  • the project unchanged byte for byte.

It then follows the printed regenerate remedy literally (moves the named file aside, runs the printed apm lock) and asserts the lock is rewritten at a supported version.

Results:

  • New test: 4 passed. Without the fix: 4 failed.
  • tests/unit/core (remediation catalog proofs), lockfile, audit, deps and remediation-advice suites: no new failures. The only failures (test_output_mode, test_auth_credential_report, test_bare_cache_sparse) fail the same way without this change.
  • tests/quality/test_lifecycle_bug_ledger.py and tests/quality/test_test_taxonomy.py: 38 passed.
  • ruff check / format, pylint R0801, auth-signal lint and the complexity ratchet: clean. scripts/check_test_assertions.py: no [x].

There is no strict xfail for req-lk-004 in tests/spec_conformance, so nothing to flip. CONFORMANCE is not regenerated.

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.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 -- the behaviour req-lk-004 already requires is implemented here; the spec, manifest and CONFORMANCE are unchanged per the scope record.

…egenerate or upgrade APM (#4233)

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Base automatically changed from danielmeppiel-bookish-train to main November 20, 2026 18:45
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
…it --ci

- run_baseline_checks still needs LockFile at runtime (NameError in audit --ci).
- The remedy helper becomes UnsupportedLockfileVersionError.for_path, keeping
  deps/lockfile.py under the 2100-line guard.
- install/service.py stays within its 1000-line budget.

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 20, 2026 19:21

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

Unresolved lockfile-handling issues can misdirect global-lock recovery, abort policy-enabled CI audits before reporting failures, and omit regeneration guidance when both schema and generator versions are newer.

3 open issues
What changed in this PR

This PR addresses #4233 by adding regeneration and upgrade advice to unsupported-lockfile-version errors, using the remediation catalog introduced in #4143.

Changes:

  • Adds catalog entries and path-bound remedies to unsupported-version errors.
  • Updates install, lock and CI audit error handling.
  • Adds installed-CLI coverage for diagnostics, unchanged project files and regeneration.
File Description
tests/​unit/​core/​test_remediation_commands_catalog.py Records validation coverage for the new remedies.
tests/​integration/​test_unsupported_lockfile_version_lifecycle.py Tests failure diagnostics, state preservation and recovery.
tests/​fixtures/​lifecycle_bug_ledger.json Links issue #4233 to its regression test.
src/​apm_cli/​policy/​ci_checks.py Reports unsupported versions as failed baseline checks.
src/​apm_cli/​install/​service.py Avoids conflicting generic advice during frozen installs.
src/​apm_cli/​install/​audit_replay.py Converts unsupported versions into replay errors.
src/​apm_cli/​deps/​lockfile.py Attaches path-aware remedies to unsupported-version exceptions.
src/​apm_cli/​core/​remediation.py Defines regeneration and APM upgrade advice.
src/​apm_cli/​commands/​lock.py Adds the [x] symbol to generic lock-generation errors.
src/​apm_cli/​commands/​audit.py Skips drift parsing for unsupported lockfile versions.
CHANGELOG.md Documents the improved recovery diagnostic.

Review effort: Balanced

Comment thread src/apm_cli/deps/lockfile.py Outdated
Comment on lines +256 to +258
regen = remediation.LOCKFILE_VERSION_UNSUPPORTED.bind(path=path.name)
if is_user_scope_root(path.parent):
regen = regen.with_command("apm lock -g")
Comment thread src/apm_cli/deps/lockfile.py Outdated
Comment on lines +1847 to +1848
except UnsupportedLockfileVersionError as exc:
raise exc.for_path(path) from exc
result = CIAuditResult()
lockfile_path = get_lockfile_path(project_root)
lock = LockFile.read(lockfile_path)
lock, unreadable = _read_audited_lock(lockfile_path)
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
…es both remedies

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

# Conflicts:
#	tests/fixtures/lifecycle_bug_ledger.json
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
…module

The remedy for a lockfile version this APM cannot read moves to
deps/lockfile_version_remedy.py (with_version_remedy); lockfile.py keeps
one import, staying within its line budget on the train.

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
…; audit reads the lockfile guarded (#4469 x #4495) (04daadaf)

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 1599ca2 into main Nov 21, 2026
40 of 44 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the bug-sweep/p4233 branch November 21, 2026 05:24
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.

Unknown lockfile version error does not offer the upgrade or regenerate remediation

2 participants