mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 19:58:36 +00:00
Twelve test files failed on main at2d53a8055(CI's check and semantic-tests steps, run locally): most are a test and the code it checks changed by different pull requests in the same merge round. Each fix below is either taken from a closed pull request that already had it, or restores what an earlier merged change intended. From closed pull requests: - test_make_game_resume: FakeProc gets poll(), which translate() now calls (#7018) - test_make_game_empty_translation: the Exited stub gets poll() and the failed-shard path is checked (#7214) - test_shader_checks: stub table_fetch_test in the Wave64Checks harness and count it (#7433) - test_runtime_paths: runtime.yml's path filter lists tools/replace_retry.py, which rdna2spirv.py imports (#7029) - test_psin_names: patch the same_report_path helpers that report_paths now calls (#8719) - test_report_source_collision: the fixture is a real Bink 2 header; bink_index refuses other files (#7408) - test_missing_input_exit_codes: tile_probe checks its inputs before it asks for numpy (#4771) Restored: - merge_check: a failed `git show` is an error again (5b88d58);21016cfbrought back the lenient read that treated it as a new file, while new files are already left out when the diff is read - rpf_probe: a symlinked --out updates its target again (44d3595); 55d21cc's staged write replaced the link Updated to the code: - test_shader_stage_resume: TRANSLATION_SOURCES lists fssm_unpack.py and shader_stage_manifest.py, which the translator imports; existing work folders translate once more after this - test_tool_stdout_encoding: the 15 programs merged without the stdout guard get the same block as the others - test_rdna2spirv_decode: drop the test of decode_any_format, which SHADER-849 replaced with the table decode that tests/semantic/test_format_decode_table.py checks Co-authored-by: jewmaster1337 <102986566+jewmaster1337@users.noreply.github.com> Co-authored-by: TanmaySatyam <248538550+TanmaySatyam@users.noreply.github.com> Co-authored-by: evilclanker9000 <45567075+evilclanker9000@users.noreply.github.com> Co-authored-by: slint6614-dev <359954236+slint6614-dev@users.noreply.github.com> Co-authored-by: BlackNife <108077267+Poussistar@users.noreply.github.com> Co-authored-by: fiestorra <65175643+fiestorra@users.noreply.github.com> Co-authored-by: fearkov <289226582+fearkov@users.noreply.github.com> Co-authored-by: DoubleD17 <48109637+DoubleD17@users.noreply.github.com>
127 lines
5.0 KiB
Python
127 lines
5.0 KiB
Python
"""Verify single-offset world_drawable_lookup predictions against normal model exports.
|
|
|
|
Source paths may be links to the same archive. Only file metadata is checked, never archive bytes;
|
|
offline reports still work when their normalized source paths agree.
|
|
"""
|
|
import argparse
|
|
from collections import Counter, defaultdict
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
from world_drawable_lookup import report_rows
|
|
import world_build
|
|
import world_names
|
|
|
|
|
|
def _same_archive(first, second):
|
|
if first == second:
|
|
return True
|
|
try:
|
|
return os.path.samefile(first, second)
|
|
except OSError:
|
|
return False
|
|
|
|
|
|
def archive_path(value):
|
|
if not isinstance(value, str) or not value.strip():
|
|
raise ValueError("expected a source archive path")
|
|
return os.path.normcase(os.path.abspath(value))
|
|
|
|
|
|
def verify(predictions, manifests):
|
|
report = report_rows(predictions, "candidates")
|
|
archive = archive_path(report.get("archive"))
|
|
windows = []
|
|
full_scan = False
|
|
observations = Counter()
|
|
named_offsets = set()
|
|
by_identity = defaultdict(set)
|
|
paths = dict.fromkeys(os.path.normcase(os.path.realpath(path)) for path in manifests)
|
|
for path in paths:
|
|
export = report_rows(path, "Items")
|
|
if not _same_archive(archive_path(export.get("src")), archive):
|
|
raise ValueError(f"{path}: different source archive from predictions")
|
|
scan = export.get("Scan")
|
|
if not isinstance(scan, dict):
|
|
raise ValueError(f"{path}: missing Scan metadata")
|
|
bounded = "Start" in scan or "Length" in scan
|
|
if bounded:
|
|
start, length = scan.get("Start"), scan.get("Length")
|
|
if any(type(n) is not int or n < 0 for n in (start, length)):
|
|
raise ValueError(f"{path}: invalid Scan.Start or Scan.Length")
|
|
windows.append((start, start + length))
|
|
else:
|
|
full_scan = True
|
|
for item in export["Items"]:
|
|
offset = item.get("Offset")
|
|
if type(offset) is not int or offset < 0 or (bounded and not start <= offset < start + length):
|
|
raise ValueError(f"{path}: invalid item offset for scan")
|
|
index = world_build.model_name_index([("", item) for item in export["Items"]], world_names)
|
|
for h, entries in index.items():
|
|
for _, item, key in entries:
|
|
offset = item["Offset"]
|
|
observations[h, key, offset] += 1
|
|
named_offsets.add(offset)
|
|
by_identity[h, key].add(offset)
|
|
|
|
identities, placements = Counter(), Counter()
|
|
rows = []
|
|
seen = set()
|
|
for row in report["candidates"]:
|
|
if row.get("status") == "ambiguous":
|
|
continue
|
|
offsets = row.get("offsets")
|
|
if (row.get("status") != "candidate" or not isinstance(offsets, list) or len(offsets) != 1
|
|
or type(offsets[0]) is not int or offsets[0] < 0):
|
|
raise ValueError("expected single-offset candidate")
|
|
offset = offsets[0]
|
|
h, key = int(row["archetype"], 16), int(row["key"], 16)
|
|
if (h, key) in seen:
|
|
raise ValueError("duplicate candidate identity")
|
|
seen.add((h, key))
|
|
n = row["placements"]
|
|
if type(n) is not int or n < 1:
|
|
raise ValueError("expected positive placement count")
|
|
covered = full_scan or any(start <= offset < end for start, end in windows)
|
|
exact = observations[h, key, offset]
|
|
elsewhere = sorted(by_identity[h, key] - {offset})
|
|
if exact:
|
|
status = "confirmed"
|
|
elif offset in named_offsets:
|
|
status = "conflicting_name"
|
|
elif elsewhere:
|
|
status = "conflicting_offset"
|
|
elif covered:
|
|
status = "missing_evidence"
|
|
else:
|
|
status = "outside_windows"
|
|
identities[status] += 1
|
|
placements[status] += n
|
|
rows.append({"archetype": row["archetype"], "key": row["key"], "offset": offset,
|
|
"placements": n, "status": status, "covered": covered,
|
|
"exact_observations": exact, "duplicate_observations": max(0, exact - 1),
|
|
"other_identity_offsets": elsewhere})
|
|
return {"identities": identities, "placements": placements, "rows": rows}
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("predictions", help="local world_drawable_lookup JSON")
|
|
parser.add_argument("manifest", nargs="+", help="rpf9dump models manifest.json from the same archive")
|
|
args = parser.parse_args()
|
|
try:
|
|
result = verify(args.predictions, args.manifest)
|
|
except (KeyError, OSError, TypeError, ValueError) as exc:
|
|
parser.exit(1, f"{parser.prog}: {exc}\n")
|
|
print(json.dumps(result, indent=1))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try: # a redirected stdout is strict ANSI code page under -I; write '?' for what it cannot encode
|
|
sys.stdout.reconfigure(errors="replace")
|
|
except (AttributeError, ValueError, OSError):
|
|
pass
|
|
main()
|