Coverage for src/romfarmer/planner/lowering/rvz.py: 43%

21 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-09-05 02:19 -0700

1"""RVZ lowering rule — unzip RVZ from source archive. 

2 

3Stage sequence this replaces (``stages/builder.py::_rvz_stages``): 

4 [CachePreCheckStage →] UnzipRVZStage [→ CacheStoreStage] 

5 

6IR action sequence: 

7 source-copy (INTERMEDIATE) — ingest source ZIP into CAS 

8 unzip-rvz (TERMINAL) — extract .rvz from ZIP 

9""" 

10 

11from __future__ import annotations 

12 

13from romfarmer.ir.actions import ( 

14 Action, 

15 ArtifactDecl, 

16 InputRef, 

17 PendingRef, 

18 Retention, 

19 UnitPlan, 

20) 

21from romfarmer.ir.catalog import GameUnit 

22from romfarmer.ir.manifest import BuildManifest 

23from romfarmer.planner.lowering.base import ( 

24 FormatChain, 

25 make_action_id, 

26 probe_tool_version, 

27 source_action, 

28 zero_prediction, 

29) 

30 

31 

32class RVZLoweringRule: 

33 """Lower a GameCube/Wii RVZ game unit to an action sequence.""" 

34 

35 def __init__(self, action_cache: object | None = None) -> None: 

36 self._cache = action_cache 

37 

38 def lower( 

39 self, 

40 unit: GameUnit, 

41 chain: FormatChain, 

42 manifest: BuildManifest, 

43 ) -> UnitPlan: 

44 disc = unit.discs[0] 

45 src_path = disc.source.path 

46 stem = src_path.stem 

47 step = 0 

48 actions: list[Action] = [] 

49 

50 src_act = source_action(unit, step, src_path, src_path.name, "zip") 

51 actions.append(src_act) 

52 step += 1 

53 src_ref: InputRef = PendingRef(src_act.action_id, 0) 

54 

55 rvz_act = Action( 

56 action_id=make_action_id(str(unit.unit_id), step, "unzip-rvz"), 

57 tool="unzip-rvz", 

58 tool_version=probe_tool_version("dolphin-tool"), 

59 params={}, 

60 inputs=(src_ref,), 

61 outputs=( 

62 ArtifactDecl( 

63 logical_name=f"{stem}.rvz", 

64 kind="rvz", 

65 retention=Retention.TERMINAL, 

66 ), 

67 ), 

68 ) 

69 actions.append(rvz_act) 

70 

71 return UnitPlan( 

72 unit=unit, 

73 actions=tuple(actions), 

74 predicted_output_bytes=unit.source_size, 

75 prediction=zero_prediction(), 

76 )