883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
172 lines
8.5 KiB
Python
172 lines
8.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Focused Source graph and real C++ point-rank tests; no server/client build.
|
|
|
|
Optional --source-dbc-dir/--talent-tab-dbc/--spell-chain-tsv qualifies the entire
|
|
cached Source cohort. Normal discovery needs only the committed profiles.
|
|
All generated compiler outputs remain under the Games runtime tree.
|
|
"""
|
|
import argparse
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import subprocess
|
|
import sys
|
|
from types import SimpleNamespace
|
|
import unittest
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.insert(0, str(ROOT / "ops"))
|
|
import turtle_data as data
|
|
|
|
QUALIFY = None
|
|
|
|
|
|
def table(fields, rows):
|
|
return SimpleNamespace(fields=fields, rows=rows, by_id={r[0]: r for r in rows})
|
|
|
|
|
|
def talent(ident, ranks):
|
|
row = [0] * 21
|
|
row[0], row[1] = ident, 10
|
|
row[4:4 + len(ranks)] = ranks
|
|
return row
|
|
|
|
|
|
def ability(ident, spell, successor=0, line=257, mask=1):
|
|
row = [0] * 15
|
|
row[0], row[1], row[2], row[4], row[8] = ident, line, spell, mask, successor
|
|
return row
|
|
|
|
|
|
class SuccessorGraphTest(unittest.TestCase):
|
|
def resolve(self, talents, abilities, chains=(), present=(100, 101, 102, 103, 200)):
|
|
tab = [0] * 15
|
|
tab[0], tab[12] = 10, 1
|
|
return data.validated_talent_rank_successors(
|
|
table(21, talents), table(15, abilities), table(173, [[s] for s in present]),
|
|
chains, talent_tabs=table(15, [tab]))
|
|
|
|
def test_actions_resolve_to_actual_point_spells(self):
|
|
rows = [ability(1, 100, 101), ability(2, 101, 102),
|
|
ability(3, 102, 103), ability(4, 103)]
|
|
result, held = self.resolve([talent(1, [100, 102])], rows)
|
|
self.assertEqual(result, {100: [101], 102: [103]})
|
|
self.assertEqual(held, [])
|
|
|
|
def test_server_chain_adds_authoritative_missing_forward_edges(self):
|
|
rows = [ability(1, 100), ability(2, 101), ability(3, 102)]
|
|
chain = [(100, 0, 100, 1), (101, 100, 100, 2), (102, 101, 100, 3)]
|
|
self.assertEqual(self.resolve([talent(1, [100])], rows, chain), ({100: [101, 102]}, []))
|
|
|
|
def test_ambiguity_cycle_foreign_line_and_class_are_held(self):
|
|
cases = [
|
|
([ability(1, 100, 101), ability(2, 100, 102), ability(3, 101), ability(4, 102)], "ambiguous-ability-successor"),
|
|
([ability(1, 100, 101), ability(2, 101, 100)], "cyclic-ability-successor"),
|
|
([ability(1, 100, 101), ability(2, 101, line=256)], "foreign-or-missing-skill-line"),
|
|
([ability(1, 100, 101), ability(2, 101, mask=2)], "foreign-class"),
|
|
]
|
|
for rows, kind in cases:
|
|
with self.subTest(kind=kind):
|
|
result, held = self.resolve([talent(1, [100])], rows)
|
|
self.assertEqual(result, {})
|
|
self.assertIn(kind, [r["kind"] for r in held])
|
|
|
|
def test_server_cycle_duplicate_rank_and_missing_spell_are_held(self):
|
|
rows = [ability(1, 100), ability(2, 101), ability(3, 102)]
|
|
for chains in [[(100, 101, 100, 1), (101, 100, 100, 2)],
|
|
[(100, 0, 100, 1), (101, 100, 100, 2), (102, 100, 100, 2)]]:
|
|
result, held = self.resolve([talent(1, [100])], rows, chains)
|
|
self.assertEqual(result, {})
|
|
self.assertIn("ambiguous-or-cyclic-server-chain", [r["kind"] for r in held])
|
|
result, held = self.resolve([talent(1, [100])], [ability(1, 100, 101), ability(2, 101)], present=(100,))
|
|
self.assertEqual(result, {})
|
|
self.assertIn("missing-source-spell", [r["kind"] for r in held])
|
|
|
|
def test_shared_action_cannot_choose_a_foreign_talent(self):
|
|
rows = [ability(1, 100, 101), ability(2, 200, 101), ability(3, 101)]
|
|
for talents in [[talent(1, [100]), talent(2, [200])], [talent(1, [100, 200])]]:
|
|
result, held = self.resolve(talents, rows)
|
|
self.assertEqual(result, {})
|
|
self.assertEqual([r["kind"] for r in held], ["ambiguous-trained-action-owner"] * 2)
|
|
|
|
def test_real_cpp_rank_projection(self):
|
|
output = ROOT / "runtime/continuation-20261113/codex/Combined-C52H/Source-spellbook-RCA/native-projection/talent-successors/tests" / str(os.getpid())
|
|
output.mkdir(parents=True, exist_ok=True)
|
|
temporary = output / "tmp"
|
|
temporary.mkdir(exist_ok=True)
|
|
env = dict(os.environ, TMPDIR=str(temporary), TMP=str(temporary), TEMP=str(temporary))
|
|
pairs = [tuple(map(int, p)) for p in re.findall(r"\{(\d+),(\d+)\}", (ROOT / "include/gateway/talent_rank_successors.hpp").read_text())]
|
|
cases = []
|
|
qualification = None
|
|
if QUALIFY:
|
|
source = QUALIFY.source_dbc_dir
|
|
talents = data.DBC(source / "Talent.dbc", 21)
|
|
abilities = data.DBC(source / "SkillLineAbility.dbc", 15)
|
|
spells = data.DBC(source / "Spell.dbc", 173)
|
|
tabs = data.DBC(QUALIFY.talent_tab_dbc, 15)
|
|
chains = data.read_spell_chain(QUALIFY.spell_chain_tsv, include_previous=True)
|
|
resolved, held = data.validated_talent_rank_successors(talents, abilities, spells, chains, talent_tabs=tabs)
|
|
self.assertEqual(pairs, [(r, s) for r, values in resolved.items() for s in values])
|
|
for row in talents.rows:
|
|
for rank, root in enumerate(row[4:9], 1):
|
|
for learned in resolved.get(root, []):
|
|
cases.append((list(row[4:9]), learned, rank))
|
|
self.assertEqual(len(cases), len(pairs))
|
|
self.assertIn((12809, 51602), pairs)
|
|
self.assertIn((23922, 23925), pairs)
|
|
qualification = dict(talents=len(talents.rows), roots=len(resolved), pairs=len(pairs), held=held)
|
|
rows = "\n".join("check({" + ",".join(map(str, ranks)) + "}," + str(spell) + "," + str(rank) + ");" for ranks, spell, rank in cases)
|
|
harness = r'''
|
|
#include "gateway/talents.hpp"
|
|
#include <cassert>
|
|
#include <iostream>
|
|
namespace gateway {
|
|
#include "gateway/talent_rank_successors.hpp"
|
|
}
|
|
using namespace gateway;
|
|
static void check(std::array<uint32_t,5> ranks,uint32_t spell,uint32_t point){
|
|
TalentMapping t{};t.spells=ranks;std::set<uint32_t> known{spell};auto before=known;
|
|
assert(turtle_talent_rank(t,known)==point && known==before);
|
|
}
|
|
int main(){
|
|
unsigned checked=0;
|
|
for(const auto& t:warrior_talent_mappings())for(const auto& alias:TalentRankSuccessors)
|
|
for(unsigned i=0;i<t.spells.size();++i)if(t.spells[i]==alias.rank_spell){
|
|
check(t.spells,alias.learned_spell,i+1);++checked;
|
|
}
|
|
assert(checked>0);
|
|
auto ranks=forever_talent_ranks({51602,23925});
|
|
assert(ranks.size()==2);for(const auto& rank:ranks)assert(rank.rank==1);
|
|
check({0x7fff0001,0x7fff0002,0,0,0},0x7fff0002,2);
|
|
check({12809,0,0,0,0},51602,1);check({23922,0,0,0,0},23925,1);
|
|
check({12809,0,0,0,0},23925,0);
|
|
''' + rows + '\nstd::cout << "PASS native point rank projection\\n";\n}\n'
|
|
source_file = output / "talent-ranks.cpp"
|
|
source_file.write_text(harness)
|
|
executable = output / "talent-ranks"
|
|
command = ["clang++", "-std=c++20", "-O1", "-Wall", "-Wextra", "-Werror",
|
|
"-ffunction-sections", "-fdata-sections", "-I" + str(ROOT / "include"),
|
|
str(source_file), str(ROOT / "src/talents.cpp"), "-Wl,--gc-sections", "-o", str(executable)]
|
|
compile_result = subprocess.run(command, cwd=output, env=env, capture_output=True, text=True, timeout=45)
|
|
(output / "compile.private.log").write_text(compile_result.stdout + compile_result.stderr)
|
|
self.assertEqual(compile_result.returncode, 0, f"See {output / 'compile.private.log'}")
|
|
run = subprocess.run([str(executable)], cwd=output, env=env, capture_output=True, text=True, timeout=5)
|
|
(output / "run.private.log").write_text(run.stdout + run.stderr)
|
|
self.assertEqual(run.returncode, 0, f"See {output / 'run.private.log'}")
|
|
(output / "qualification.private.json").write_text(json.dumps(dict(state="PASS", compile_command=command,
|
|
generated_pairs=len(pairs), full_source_qualification=qualification, native_cases=len(cases)), indent=2) + "\n")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--source-dbc-dir", type=Path)
|
|
parser.add_argument("--talent-tab-dbc", type=Path)
|
|
parser.add_argument("--spell-chain-tsv", type=Path)
|
|
args, remaining = parser.parse_known_args()
|
|
if any((args.source_dbc_dir, args.talent_tab_dbc, args.spell_chain_tsv)):
|
|
if not all((args.source_dbc_dir, args.talent_tab_dbc, args.spell_chain_tsv)):
|
|
parser.error("All three Source qualification inputs are required")
|
|
QUALIFY = args
|
|
unittest.main(argv=[sys.argv[0], *remaining])
|