Coverage for src/romfarmer/planner/lowering/passthrough.py: 100%
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"""Passthrough lowering rule — copy source file as terminal artifact.
3Used for platforms where the source format IS the target format
4(e.g. 3DS .3ds files, Switch .nsp/.xci, WADs) and no conversion is needed.
6Stage sequence this replaces: ``_none_stages`` (CASIngestStage).
7"""
9from __future__ import annotations
11from romfarmer.ir.actions import (
12 Action,
13 ArtifactDecl,
14 InputRef,
15 PendingRef,
16 Retention,
17 UnitPlan,
18)
19from romfarmer.ir.catalog import GameUnit
20from romfarmer.ir.manifest import BuildManifest
21from romfarmer.planner.lowering.base import (
22 FormatChain,
23 make_action_id,
24 source_action,
25 static_tool_version,
26 zero_prediction,
27)
30class PassthroughLoweringRule:
31 """Lower a unit that needs no transformation."""
33 def __init__(self, action_cache: object | None = None) -> None:
34 self._cache = action_cache
36 def lower(
37 self,
38 unit: GameUnit,
39 chain: FormatChain,
40 manifest: BuildManifest,
41 ) -> UnitPlan:
42 disc = unit.discs[0]
43 src_path = disc.source.path
44 step = 0
45 actions: list[Action] = []
47 src_act = source_action(unit, step, src_path, src_path.name, "source")
48 actions.append(src_act)
49 step += 1
50 src_ref: InputRef = PendingRef(src_act.action_id, 0)
52 # Mark the source directly as terminal — no transform needed
53 pt_act = Action(
54 action_id=make_action_id(str(unit.unit_id), step, "passthrough"),
55 tool="passthrough",
56 tool_version=static_tool_version("passthrough"),
57 params={},
58 inputs=(src_ref,),
59 outputs=(
60 ArtifactDecl(
61 logical_name=src_path.name,
62 kind=src_path.suffix.lstrip(".") or "rom",
63 retention=Retention.TERMINAL,
64 ),
65 ),
66 )
67 actions.append(pt_act)
69 return UnitPlan(
70 unit=unit,
71 actions=tuple(actions),
72 predicted_output_bytes=unit.source_size,
73 prediction=zero_prediction(),
74 )