Coverage for src/romfarmer/ir/tool_impl.py: 100%
6 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"""Per-tool implementation versions — the cache-invalidation lever.
3``IMPL_VERSIONS`` records the "implementation version" for every tool known
4to the lowering layer. It is the mechanism for invalidating cached
5``Action`` rows when a transform's subprocess flags or default parameters
6change in a way that produces different output bytes.
8Rules:
9 1. All entries start at 1. The ``probe_tool_version`` function and the
10 ``static_tool_version`` helper append ``"+i{n}"`` **only when n ≥ 2**,
11 so no currently-emitted ``tool_version`` string is affected by the
12 addition of this file.
13 2. When a transform's command construction, env pins, or ``params.get``
14 defaults change in a way that produces different output bytes, bump that
15 tool's entry by 1.
16 3. A bump is **tool-scoped**: only ``Action`` rows for that specific tool
17 miss the cache; all other tools are unaffected.
18 4. Never change the frozen canonical form in ``ir/actions.py``.
19 5. Add a brief comment next to any entry whose value is ≥ 2 explaining
20 what changed and when.
22First bumps landed 2026-09-01 (T9 determinism): ``7z`` and ``mksquashfs``.
23"""
25from __future__ import annotations
27from types import MappingProxyType
29IMPL_VERSIONS: MappingProxyType[str, int] = MappingProxyType(
30 {
31 # Built-in / synthetic tools (no external binary)
32 "source-copy": 1,
33 "passthrough": 1,
34 "m3u-create": 1,
35 # External tools
36 "unzip": 1,
37 "7z": 2, # 2026-09-01: -mtm=off -mmt=4 + pinned env — reproducible output (T9)
38 "chdman": 1,
39 "mksquashfs": 2, # 2026-09-01: SOURCE_DATE_EPOCH=0 env + -all-root -no-xattrs -processors 4 (T9)
40 "extract-xiso": 1,
41 "dolphin-tool": 1,
42 "wit": 1,
43 "ps3dec": 1,
44 "ps3-dkey-lookup": 1,
45 "ps3-extract-tree": 1,
46 }
47)
50def impl_version_suffix(tool: str) -> str:
51 """Return ``'+i{n}'`` for n ≥ 2, or ``''`` for n == 1 (no suffix today).
53 This keeps every currently-emitted ``tool_version`` string byte-identical
54 to its pre-T5 value — no existing cache row is invalidated.
56 Usage::
58 # In probe_tool_version (for tools with external binaries):
59 version = "7z 24.05" # from subprocess
60 return version + impl_version_suffix("7z") # "7z 24.05" (n==1 today)
62 # In static_tool_version (for synthetic tools):
63 return "1" + impl_version_suffix("m3u-create") # "1" (n==1 today)
64 """
65 n = IMPL_VERSIONS.get(tool, 1)
66 return f"+i{n}" if n >= 2 else ""