Coverage for src/romfarmer/planner/passes/curated_lists.py: 35%
20 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"""curated_lists pass — apply include / exclude lists.
3``manifest.curated_exclude``: set of canonical game names to always remove.
4``manifest.curated_include``: set of canonical game names to always keep
5 (rescue list — overrides any previous pass's removal).
7The pass runs in two steps:
81. Remove all units in ``curated_exclude`` (exact canonical_name match).
92. Re-add (restore) units whose ``canonical_name`` is in ``curated_include``
10 that were somehow already removed — **but** the in-memory Catalog only
11 contains surviving units, so this pass can only protect units that are
12 *still present*. Units not in the current catalog are silently ignored
13 (they may have been removed by a prior pass for a good reason, or never
14 existed in the source).
16The ``added`` field of ``PassTrace`` records any units that were *prevented*
17from being removed (i.e., units in ``curated_include`` that were also in
18``curated_exclude`` — the include list wins).
19"""
21from __future__ import annotations
23from typing import TYPE_CHECKING
25from romfarmer.ir.catalog import Catalog, PassResult, PassTrace, UnitId
27if TYPE_CHECKING:
28 from romfarmer.analysis.knowledge import KnowledgeBase
29 from romfarmer.ir.manifest import BuildManifest
30 from romfarmer.planner.costmodel import CostModel
32PASS_NAME = "curated_lists"
35def run(
36 catalog: Catalog,
37 manifest: BuildManifest,
38 kb: KnowledgeBase,
39 cost_model: CostModel,
40) -> PassResult:
41 """Apply curated include/exclude lists."""
42 if not manifest.curated_exclude and not manifest.curated_include:
43 return PassResult(
44 catalog=catalog,
45 trace=PassTrace(pass_name=PASS_NAME, removed=(), added=()),
46 )
48 removed: list[tuple[UnitId, str]] = []
49 rescued: list[tuple[UnitId, str]] = []
51 for unit in catalog.units:
52 name = unit.canonical_name
53 in_exclude = name in manifest.curated_exclude
54 in_include = name in manifest.curated_include
56 if in_exclude and not in_include:
57 removed.append((unit.unit_id, f"curated_exclude: {name!r}"))
58 elif in_exclude and in_include:
59 # include wins — note it as rescued/added
60 rescued.append((unit.unit_id, f"curated_include rescued {name!r} from exclude list"))
62 removed_ids = {uid for uid, _ in removed}
63 new_catalog = catalog.without(removed_ids)
64 return PassResult(
65 catalog=new_catalog,
66 trace=PassTrace(
67 pass_name=PASS_NAME,
68 removed=tuple(removed),
69 added=tuple(rescued),
70 ),
71 )