Enforce per-medium track cardinality in the upload service via MediumRules

Promote the Session/Mix single-track rule from a CMS-form convention to a
domain invariant: declare cardinality as data in MediumRules, enforce it in
UnifiedTrackService before the vault write (no orphan), return 409, and read
the same rule in the batch-form collapse.
This commit is contained in:
daniel-c-harvey
2026-06-13 14:12:01 -04:00
parent 6f42464294
commit b893ca84de
8 changed files with 261 additions and 9 deletions
@@ -136,14 +136,15 @@
// UploadTrackAsync call below passes _medium, and PUT api/track/meta resets ReleaseType to its
// default server-side for a non-Cut medium.
//
// Switching to a single-track medium (Session/Mix) collapses any multi-track list to the first row
// so the single-track invariant (§9.3) holds before save — the same collapse BatchUpload.OnMediumChanged
// performs. Dropping rows 2..n is an in-memory trim only; existing tracks are not deleted server-side
// (RemoveRow owns deletion), so the hidden rows simply fall out of this edit session.
// Switching to a single-track medium collapses any multi-track list to the first row so the
// single-track invariant (§9.3) holds before save — the same collapse BatchUpload.OnMediumChanged
// performs, reading the same MediumRules cardinality the upload service enforces. Dropping rows
// 2..n is an in-memory trim only; existing tracks are not deleted server-side (RemoveRow owns
// deletion), so the hidden rows simply fall out of this edit session.
private void OnMediumChanged(ReleaseMedium medium)
{
_medium = medium;
if (medium != ReleaseMedium.Cut && _tracks.Count > 1)
if (MediumRules.CardinalityOf(medium).IsSingleTrack && _tracks.Count > 1)
{
_tracks.RemoveRange(1, _tracks.Count - 1);
_selectedIndex = _tracks.Count > 0 ? 0 : -1;
@@ -194,7 +195,9 @@
Status = BatchRowStatus.Queued
}).ToList();
if (_medium != ReleaseMedium.Cut && _tracks.Count > 1)
// Same single-track collapse on the load path, via the shared MediumRules declaration: a
// release whose stored medium is single-track surfaces only its first row for editing.
if (MediumRules.CardinalityOf(_medium).IsSingleTrack && _tracks.Count > 1)
{
_tracks.RemoveRange(1, _tracks.Count - 1);
}