Coverage for src/romfarmer/ir/manifest.py: 75%
59 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-09-05 02:19 -0700
« prev ^ index » next coverage.py v7.15.4, created at 2026-09-05 02:19 -0700
1"""romfarmer.ir.manifest — BuildManifest: the resolved build configuration.
3``BuildManifest`` is the output of the RESOLVE phase and the primary input to
4the PLAN phase. Every planner pass receives a ``BuildManifest`` alongside the
5``Catalog`` it is filtering.
7This is a frozen IR-layer type. It may only import from ``romfarmer.ir.*``
8and the standard library — never from legacy ``romfarmer`` modules.
9"""
11from __future__ import annotations
13from dataclasses import dataclass
15from .catalog import PlatformId
16from .chain import FormatChain
19@dataclass(frozen=True, slots=True)
20class BuildManifest:
21 """Resolved build configuration for one platform (or a generation group).
23 Constructed by the RESOLVE phase from the YAML configs and passed
24 unchanged to every planner pass.
26 Attributes:
27 platform: The target platform id, or ``None`` for a multi-platform
28 generation-level manifest.
29 preferred_regions: Region preferences in descending priority order,
30 e.g. ``("USA", "World", "Europe", "Japan")``.
31 chain: The negotiated ``FormatChain`` (recipe ∩ target profile); its
32 first element is the CostModel tool key. ``()`` = unknown.
33 rating_min: Minimum rating threshold on the **unit interval** (0.0–1.0;
34 ``ScrapedGame.rating`` is stored 0–1). Values > 1.0 are rejected
35 at construction. ``None`` = disabled.
36 rating_unrated: What the rating pass does with units that have no
37 rating when ``rating_min`` is set: ``"keep"`` (unknown ≠ bad) or
38 ``"drop"``.
39 budget_unrated_as: Where the budget pass ranks unrated units:
40 ``"median"`` (default — the per-platform median of rated units,
41 computed over the catalog entering the pass), ``"worst"``,
42 ``"best"``, or a float on the unit interval.
43 rating_top_n: Keep at most *n* highest-rated games. ``None`` = no
44 limit.
45 budget_bytes: Total output size budget in bytes. ``None`` = unlimited.
46 safety_margin: Legacy fixed headroom fraction. Retired — defaults to 0;
47 the card-level constraint is the measured aggregate p90 headroom.
48 generation_name: Logical generation key (e.g. ``"gen6"``). ``None``
49 = no cross-platform generation deduplication.
50 generation_platform_order: Platform ids in priority order for the
51 generation pass (highest priority first). Ignored when
52 ``generation_name`` is ``None``.
53 curated_include: Canonical game names that must *not* be removed by
54 any pass (rescued games / always-include lists).
55 curated_exclude: Canonical game names that must always be removed
56 regardless of other pass results.
57 arcade_working_only: Arcade pass — keep only ``driver_status=good``
58 games.
59 arcade_include_hacks: Arcade pass — retain known hacks.
60 arcade_include_bootlegs: Arcade pass — retain known bootlegs.
61 ps3_keys_directory: PS3 lowering — directory containing Redump
62 "Disc Keys TXT" zips, keyed by disc stem. ``None`` = not PS3
63 (or keys unavailable; lowering will fail at EXECUTE time).
64 """
66 platform: PlatformId | None = None
67 chain: FormatChain = ()
68 # Region
69 preferred_regions: tuple[str, ...] = ()
70 # Rating
71 rating_min: float | None = None
72 rating_top_n: int | None = None
73 rating_unrated: str = "keep"
74 # Budget
75 budget_bytes: int | None = None
76 budget_unrated_as: str = "median"
77 safety_margin: float = 0.0 # retired 2026-09-03: p90 headroom (PlanSummary) is the constraint
78 # Generation dedup
79 generation_name: str | None = None
80 generation_platform_order: tuple[str, ...] = ()
81 # Curated lists
82 curated_include: frozenset[str] = frozenset()
83 curated_exclude: frozenset[str] = frozenset()
84 # Arcade
85 arcade_working_only: bool = True
86 arcade_include_hacks: bool = False
87 arcade_include_bootlegs: bool = False
88 # Arcade selection decided at RESOLVE from DAT facts (cloneof/sourcefile/
89 # romof/comment/driver_status) the catalog never sees. None = not arcade.
90 arcade_selected: frozenset[str] | None = None
91 arcade_rejections: tuple[tuple[str, str], ...] = ()
92 # DAT gate: drop units with no DAT match (the 1G1R DAT defines the set)
93 dat_filter: bool = False
94 # Name-heuristic 1G1R. Off when the DAT is already a Retool 1G1R export —
95 # every entry it kept is a distinct title by Retool's judgement.
96 one_g_one_r: bool = True
97 # Test builds: seeded random subset applied after all other passes
98 sample_n: int | None = None
99 sample_seed: int = 0
100 # PS3 lowering
101 ps3_keys_directory: str | None = None
103 def __post_init__(self) -> None:
104 # Rating thresholds are on the unit interval. A threshold like 3.5
105 # (a 0–10 scale assumption) would silently remove every rated unit.
106 if self.rating_min is not None and not (0.0 <= self.rating_min <= 1.0):
107 raise ValueError(
108 f"rating_min must be on the unit interval 0.0–1.0, got {self.rating_min!r}"
109 )
110 if self.rating_top_n is not None and self.rating_top_n < 1:
111 raise ValueError(f"rating_top_n must be >= 1, got {self.rating_top_n!r}")
112 if self.rating_unrated not in ("keep", "drop"):
113 raise ValueError(
114 f"rating_unrated must be 'keep' or 'drop', got {self.rating_unrated!r}"
115 )
116 self.unrated_rank() # validates budget_unrated_as
117 if not (0.0 <= self.safety_margin < 1.0):
118 raise ValueError(f"safety_margin must be in [0, 1), got {self.safety_margin!r}")
120 def unrated_rank(self) -> float | None:
121 """``budget_unrated_as`` as a rating, or ``None`` for ``"median"`` (pass computes it)."""
122 v = self.budget_unrated_as
123 if v == "median":
124 return None
125 if v == "worst":
126 return float("-inf")
127 if v == "best":
128 return float("inf")
129 try:
130 f = float(v)
131 except ValueError:
132 raise ValueError(
133 f"budget_unrated_as must be 'median', 'worst', 'best' or a float, got {v!r}"
134 ) from None
135 if not (0.0 <= f <= 1.0):
136 raise ValueError(f"budget_unrated_as float must be on the unit interval, got {f!r}")
137 return f
139 @property
140 def effective_budget_bytes(self) -> int | None:
141 """``budget_bytes * (1 - safety_margin)``, or ``None`` if no budget."""
142 if self.budget_bytes is None:
143 return None
144 return int(self.budget_bytes * (1.0 - self.safety_margin))