fix(controlplane): restore PR-mode promotion suppression and auto-repair newest pre-release version
Draft
MI
1mo ago+245+245+012345678901234567890123456789-41-41-01234567890123456789
Summary
PR #3289 removed PR mode's incomplete suppression of latest-version promotion. This PR restores that suppression and completes the behavior in the control plane.
refs https://github.com/chainloop-dev/chainloop/issues/3265
Changes
CLI — restore the PR-mode promotion default
- Restored the PR #3268 rule in
app/cli/pkg/action/attestation_init.go: whenisPRis true, setopts.MarkAsLatestto&falseunless the user explicitly passed--mark-latest=true(via the restoredexplicitMarkAsLatestTruehelper). - Preserves all three observable states: omitted
--mark-latestbecomes false in PR mode, explicit--mark-latest=falseremains false, explicit--mark-latest=trueremains the user override. Non-PR mode leaves the pointer untouched so omitted promotion intent reaches the server asnil. - Restored the
--prhelp literal andTestExplicitMarkAsLatestTrue(nil/false/true cases).
Control plane — auto-promote only the newest existing version when intent is omitted
- Refactored the existing-version branch in
WorkflowRunRepo.Createto always re-read the targetProjectVersionwithForUpdateinside the transaction. - Explicit states preserved exactly:
truepromotes (released versions rejected);false(PR sentinel / explicit opt-out) makes no change. - New
nilpath: if the fresh version is active, pre-release, and not already latest, query for any other active version withcreated_atstrictly greater than the target's immutableCreatedAt. If none exists, callpromoteVersionToLatestWithTx. A timestamp tie is not "strictly newer", matching the historicalORDER BY project_id, created_at DESCmigration. - Released versions are never auto-promoted.
UseLatestVersionand new-version creation are unchanged.
API contract
- Updated the
mark_as_latestproto comment to describe the completed nil/true/false semantics; regenerated Go, TypeScript, JSON Schema, and CLI reference artifacts viamake generate.
Tests
- Added four integration subtests covering: the repair lifecycle (
v1latest → PR-simv2not latest → non-PRv2repaired to latest withv1demoted); older version not promoted over newer; explicit-false suppression wins over automatic repair on a newer version; newest released version not auto-promoted.
Verification
go test ./app/cli/pkg/action -run 'Test(ExplicitMarkAsLatestTrue|ResolvePRMode)$'— PASSgo test ./app/controlplane/pkg/biz -run 'TestWorkflowRunUseCase/TestCreate'— PASS (all 29 subtests)go test ./app/cli/pkg/action/ ./app/controlplane/pkg/data/ ./app/controlplane/pkg/biz/— PASSmake generate— generated artifacts consistent, no hand-authored schema changesgofmt,go vet,buf lint— clean
🤖 Posted by Maximus bot (Claude Code) on behalf of @migmartri