Let a test need more than one thing, and find the romfs where it actually lives

mods_romfs_check needs both a built totk.exe and the extracted romfs, and the romfs was hard-coded to build/extracted/<version>/romfs in two places inside the test. Needs now compose with '+' (exe+romfs) and each gets its own placeholder, the romfs is found in the extracted tree, the work dir or the GUI builder's record (build/build_gui.json), and any build/v143-*/totk.exe counts as the built exe - so the test runs on the layouts people actually build in instead of failing on a path it assumed. The test takes --romfs; its default is the old path, so running it by hand is unchanged.
This commit is contained in:
zzs181 authored and itaskaev2 committed 2026-11-10 18:21:14 +01:00
1 parent 88cd32fddf
commit 5635dd5e3a
2 files changed
+65 -29

No files matched your search

+10 -8
View File
@@ -1,9 +1,9 @@
"""The mods folder served as RomFS overlays (runtime/romfs.c, runtime/mods.c): load order, added files, case, Unicode.
.venv\\Scripts\\python tests\\mods_romfs_check.py --exe build\\v121-<tag>\\totk.exe --version v121
.venv\\Scripts\\python tests\\mods_romfs_check.py --exe build\\v121-<tag>\\totk.exe --version v121 [--romfs <dir>]
Builds a mods folder in a temp directory with files of its own bytes at real RomFS paths (from
build/extracted/<version>/romfs/index.json), runs `totk.exe --probe-fs` on it and reads the `mods:` lines of the log.
build/extracted/<version>/romfs/index.json unless --romfs says otherwise), runs `totk.exe --probe-fs` on it and reads the `mods:` lines of the log.
--probe-fs compares the bytes it reads through the RomFS with every overlay file, so a wrong winner fails it too.
A second folder checks the merged resource size table the start writes to the profile (runtime/romfs.c
restbl_overlay): a grown file's entry, an added file's, a shipped table's and another version's table's.
@@ -25,8 +25,8 @@ ROOT = Path(__file__).resolve().parents[1]
UNI = 'Ж мод'
def pick_paths(version):
index = json.loads((ROOT / 'build/extracted' / version / 'romfs/index.json').read_text())
def pick_paths(version, romfs):
index = json.loads((romfs / 'index.json').read_text(encoding='utf-8'))
paths = [f['path'] for f in index['files'] if 1024 <= f['size'] <= 65536]
have = set(f['path'] for f in index['files'])
p1 = next(p for p in paths if any(c.isalpha() for c in p.rsplit('/', 1)[-1]))
@@ -83,8 +83,7 @@ def key(path):
return zlib.crc32((path[:-3] if path.endswith(('.zs', '.mc')) else path).encode())
def restbl_case(exe, version, check, tmp):
romfs = ROOT / 'build/extracted' / version / 'romfs'
def restbl_case(exe, version, romfs, check, tmp):
index = json.loads((romfs / 'index.json').read_text())
files = {f['path']: f for f in index['files']}
table_path = next(p for p in files if p.startswith('System/Resource/ResourceSizeTable.') and
@@ -129,8 +128,11 @@ def main():
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument('--exe', type=Path, required=True)
ap.add_argument('--version', choices=('v121', 'v143'), required=True)
ap.add_argument('--romfs', type=Path,
default=ROOT / 'build/extracted' / 'v143' / 'romfs',
help='the extracted romfs (its index.json names the real file paths)')
args = ap.parse_args()
p1, p2, p1case = pick_paths(args.version)
p1, p2, p1case = pick_paths(args.version, args.romfs)
fails = 0
def check(ok, what, log=None):
@@ -169,7 +171,7 @@ def main():
check('mods: Low: 3 files served (2 replaced, 1 added), 0 overridden' in log, 'Low serves P1 and the added file', log)
check('mods: Top: ' not in log.replace('mods: Top: off', ''), 'a switched-off mod serves nothing', log)
restbl_case(args.exe, args.version, check, tmp)
restbl_case(args.exe, args.version, args.romfs, check, tmp)
print('mods_romfs_check:', 'FAIL' if fails else 'ok')
return 1 if fails else 0
+55 -21
View File
@@ -35,7 +35,7 @@ def interp(venv):
# name: (venv, needs, args, why the need is there)
# needs: None | 'exefs' | 'exe' | 'embed' | 'gui'
# needs: None | needs joined by '+' (exefs | exe | romfs | embed | gui)
TESTS = {
# ---- no game files, no build ----
'flags_check': ('.venv', None, [], ''),
@@ -49,8 +49,8 @@ TESTS = {
# ---- read the game or a build ----
'jumptables_check': ('.venv', 'exefs', ['--exefs', '<exefs>'],
'replays the modules through Unicorn; needs an unpacked exefs'),
'mods_romfs_check': ('.venv', 'exe', ['--exe', '<exe>', '--version', 'v143'],
'runs the built totk.exe against a mod layout'),
'mods_romfs_check': ('.venv', 'exe+romfs', ['--exe', '<exe>', '--version', 'v143', '--romfs', '<romfs>'],
'runs the built totk.exe against a mod layout, on the extracted romfs'),
'installer_e2e': ('.venv-py314', 'embed', [],
'the release launcher runs installer on the embeddable Python'),
'installer_gui_test': ('.venv-py314', 'gui', [],
@@ -82,8 +82,28 @@ def find_exefs():
def find_exe():
for c in (ROOT / 'build' / 'v143' / 'totk.exe',):
if c.exists():
"""A built totk.exe: the plain v143 tree, else the newest variant (v143-heropath, ...)."""
if (ROOT / 'build' / 'v143' / 'totk.exe').exists():
return ROOT / 'build' / 'v143' / 'totk.exe'
builds = sorted(ROOT.glob('build/v143-*/totk.exe'),
key=lambda p: p.stat().st_mtime, reverse=True)
return builds[0] if builds else None
def find_romfs():
"""The extracted romfs of v143: its index.json names the real file paths."""
cands = [ROOT / 'build' / 'extracted' / 'v143' / 'romfs', load_work_dir() / 'romfs']
gui = ROOT / 'build' / 'build_gui.json' # the GUI builder remembers where it built from
if gui.exists():
try:
import json
r = json.loads(gui.read_text(encoding='utf-8')).get('romfs')
if r:
cands.append(Path(r))
except Exception:
pass
for c in cands:
if (c / 'index.json').exists():
return c
return None
@@ -96,21 +116,32 @@ def find_embed():
def resolve(needs):
"""(what the args take, or None when the need cannot be met here)."""
"""({placeholder: what the arg takes}, or the reasons the needs cannot be met here)."""
if needs is None:
return None, None
if needs == 'exefs':
p = find_exefs()
return (None, 'no unpacked exefs (run tools/extract.py)') if p is None else (str(p), None)
if needs == 'exe':
p = find_exe()
return (None, 'no built build/v143/totk.exe') if p is None else (str(p), None)
if needs == 'embed':
p = find_embed()
return (None, 'no build/py314-embed (tools/make_release.py makes it)') if p is None else (str(p), None)
if needs == 'gui':
return None, 'drives a window; run it by hand on a desktop session'
return None, f'unknown need {needs!r}'
return {}, None
vals, missing = {}, []
for need in needs.split('+'):
if need == 'exefs':
p = find_exefs()
if p is None: missing.append('no unpacked exefs (run tools/extract.py)')
else: vals['<exefs>'] = str(p)
elif need == 'exe':
p = find_exe()
if p is None: missing.append('no built build/v143/totk.exe')
else: vals['<exe>'] = str(p)
elif need == 'romfs':
p = find_romfs()
if p is None: missing.append('no extracted romfs index (run tools/extract.py)')
else: vals['<romfs>'] = str(p)
elif need == 'embed':
p = find_embed()
if p is None: missing.append('no build/py314-embed (tools/make_release.py makes it)')
else: vals['<embed>'] = str(p)
elif need == 'gui':
missing.append('drives a window; run it by hand on a desktop session')
else:
return {}, f'unknown need {need!r}'
return vals, ('; '.join(missing) if missing else None)
def run_one(name, all_ok, timeout, verbose):
@@ -123,8 +154,11 @@ def run_one(name, all_ok, timeout, verbose):
if reason:
return 'SKIP', 0.0, reason, ''
argv = [str(interp(venv)), str(ROOT / 'tests' / f'{name}.py')]
if value:
argv += [a.replace('<exefs>', value).replace('<exe>', value) for a in args]
for a in args: # fill each placeholder with its need's value
s = a
for k, v in value.items():
s = s.replace(k, v)
argv.append(s)
env = dict(os.environ)
if MSYS_BIN.is_dir(): # flags_check and excl_mt compile C
env['PATH'] = str(MSYS_BIN) + os.pathsep + env.get('PATH', '')