Files
benilla-octo/crates/benilla-app/tests/create_frame_template.rs
T
SamandClaude Fable 5.1 9f204d894b a bot walks on the ground, and a stunned cast never leaves the client
- a bot floating a body-height above the ground in mid-stride (B357): cmangos's Playerbots moves its bots as Player objects under `SMSG_MONSTER_MOVE`, and our ground clamp skipped anything that was not a Unit, so a splined Player kept the wire Z verbatim — and a spline is a straight chord, which over a hollow leaves the body in the air; kind is not a question the reference asks (`0x616620` runs every registered mover once per frame, reading only its own flag word), so one rule grounds every Unit plus a Player from the moment a server spline first moves it, never the body we steer; and a re-sent identical wire pose no longer leaves a unit floating (1921); the body we STEER is a mover too — the reference hands a ride's spline displacement to the same vertical-zeroing step as walking, so the spline owns XY and facing and the ground owns Z, closing a +0.47 yd gap at mid-chord on an Elwynn slope, endpoint included (1927)
- the client refuses a stunned, silenced or pacified cast itself, in the requirement validator `0x6094f0` whose mounted and moving legs we already model, before any packet — and the three arms are not symmetric: STUNNED refuses everything, SILENCED and PACIFIED run only where `Spell.dbc PreventionType` declares them, so a silence stops casts and leaves melee abilities alone and a pacify does the reverse; the leg sits above the mounted block and below the equipped-item requirement, so stunned and missing the weapon you are told about the weapon; `PreventionType` is column 165, Auto Shot alone telling it from its look-alike neighbour; the preflight banner splits movement blockers from ability blockers, since a disarm or a pacify touches no movement gate; and the refusal sink is an explicit parameter rather than a ladder field, because a resource reachable twice from one system panics on the first live frame (1903)
- a disarm greys what needs the hidden hand: the spell equipped-item test is `0x5f0c50`, walking all 23 equipment slots, rejecting a deprecated or genuinely broken item, and taking its slot mask from `AttributesEx3` (main-hand-only, off-hand-only, else every slot) — DISARMED strips the hidden hand's bit out of that mask, so a main-hand-only ability whose one allowed hand is the one the disarm took has an empty mask and dies, Heroic Strike greyed with its tooltip line red; using a worn weapon while disarmed answers `ERR_CANT_USE_DISARMED`, the client's own refusal at rung 15 of the item-use ladder's 20, above the bind-confirm arm and never a bag click (1903); and two stale claims go — `UNIT_FLAG_STUNNED` no longer says the idle selectors bail on it (0889 had refuted that at the bytes), and the charter's `ShowPetition` arm is rung #9 of that same ladder, read rather than reasoned
- `UpdateSpells()` is twelve bytes and all of them are the event: it ends in a jump into the event signal with 0x104 = `SPELLS_CHANGED` in hand, whose repaint is FrameXML's alone, so a no-op would not have been faithful and our own repainting stand-in was wrong in both directions at once; it fires synchronously as the reference's does, at the cost of a fire-path refactor rather than a next-tick queue; `PlayerHasSpells()` is a hard-coded 1, no branch, no store read, pinned to answer 1 on an empty spellbook, where a plausible implementation diverges silently (1924); and three integration harnesses loaded every document against an empty base, so a self-sourcing chain file loaded as an empty shell with every handler missing — none of their lists could fail, so the fix lands with a guard watched failing first, `FadingFrame.xml`, one relative script reference and nothing else (1923)

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-04 20:51:44 +07:00

270 lines
12 KiB
Rust

//! `CreateFrame`'s fourth argument against the **real** `assets/ui` templates — the corpus idiom,
//! end to end.
//!
//! The unit tests for the runtime template path live in
//! `benilla-ui/src/script/tests/create_frame_template.rs` and drive synthetic templates. This one
//! exists because the thing an addon actually types is
//!
//! ```lua
//! local tab = CreateFrame("Button", "MyTab", UIParent, "TabButtonTemplate")
//! getglobal("MyTab".."Text"):SetText("Hi")
//! ```
//!
//! against a template *we* wrote, loaded the way the client loads it — six hundred lines of real
//! FrameXML above it, a font registry, an anchor graph — not a four-line fixture. Every assertion
//! below is a global an addon would reach for.
use benilla_ui::script::UiScript;
const UI_DIR: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/assets/ui");
/// The prefix of `benilla.toc`'s load order these templates need: the font registry, the panel kit,
/// UIParent (the parent every addon passes), and the faux-scroll kit.
///
/// **Two of the templates under test are the REFERENCE's since 1860** — `FauxScrollFrameTemplate`
/// and `TabButtonTemplate` were ours until the dead-copy sweep, and both now come off the player's
/// chain from `Interface\FrameXML\UIPanelTemplates.xml`, seated below `UiPanels.xml` exactly as
/// the manifest seats it. So this list carries the chain pair and the loader below has to be able
/// to READ a chain entry, which a disk-only provider under `assets/ui` cannot.
const FILES: [&str; 8] = [
"Interface\\FrameXML\\Fonts.xml",
// A REGRESSION GUARD, not a dependency (1923). FadingFrame.xml's entire body is a single
// `<Script file="FadingFrame.lua"/>`, so it loads correctly ONLY if that relative reference
// resolves against the document's own directory. Load it through the path-less `loader::load`
// and the base is "", the ref stays bare, the provider misses, and the assert below fires —
// which is exactly what it did before this file passed the path.
//
// It is self-contained on BOTH axes, and both had to be checked: zero `inherits=`, AND its Lua
// has no file-scope statements at all — only function definitions. The first guard tried here
// was CombatFeedback.xml, which also has zero `inherits=` but whose Lua calls `TEXT()` at file
// scope (l.7); that global is BasicControls.xml's, so it needed a dependency after all.
// `UnitFrame.lua` fails the same way (`TEXT(MANA)`). Structural dependencies are not the only
// kind.
"Interface\\FrameXML\\FadingFrame.xml",
"MoneyFrame.xml",
"UiPanels.xml",
r"Interface\FrameXML\UIPanelTemplates.lua",
r"Interface\FrameXML\UIPanelTemplates.xml",
"UIParent.xml",
"ScrollTemplates.xml",
];
fn load_ui(script: &UiScript) {
let dir = std::path::Path::new(UI_DIR);
// A manifest entry carrying a path separator is the PLAYER's own file and has to come off the
// patch chain; a bare name is ours, under `assets/ui`. The shipped loader draws the same line
// (`reference_ui::is_chain_entry`), and this test grew the chain half when 1860 moved two of
// the templates it exercises onto it.
let chain = benilla_formats::wow_data().and_then(|d| benilla_formats::open_chain(&d).ok());
let read = |req: &str| -> Option<Vec<u8>> {
let norm = req.replace('\\', "/");
if norm.contains('/') {
if let Some(c) = chain.as_ref() {
if let Ok(b) = c.read(&norm) {
return Some(b);
}
}
}
let base = norm.rsplit('/').next().unwrap_or(&norm);
std::fs::read(dir.join(&norm))
.or_else(|_| std::fs::read(dir.join(base)))
.ok()
};
let provider = |req: &str| -> Option<Vec<u8>> { read(req) };
for file in FILES {
let bytes = read(file).unwrap_or_else(|| panic!("reading {file}"));
// A `.lua` manifest entry is a CHUNK, not a document — the shipped loader draws the same
// line, and `UIPanelTemplates` is split that way because the reference splits it that way.
if file.to_ascii_lowercase().ends_with(".lua") {
script
.run_chunk_named(&bytes, &format!("@{file}"))
.unwrap_or_else(|e| panic!("{file}: {e}"));
continue;
}
let text = benilla_ui::source::decode(&bytes);
let doc =
benilla_ui::framexml::parse(&text).unwrap_or_else(|e| panic!("parsing {file}: {e}"));
// The document's OWN path, not the path-less `load` (1923). The base is what every
// relative `<Script file=>` / `<Include file=>` inside resolves against (1186); with
// an empty base they stay bare and miss the provider entirely, so a self-sourcing
// stock file loads as an empty shell and every handler in it goes missing — silently,
// because nothing in these lists used to be self-sourcing.
let report = benilla_ui::loader::load_in(script, &doc, &file.replace('\\', "/"), &provider);
assert!(
report.errors.is_empty(),
"{file} loaded with errors: {:#?}",
report.errors
);
}
}
/// The line an addon writes, and the globals it reads on the next one.
///
/// `TabButtonTemplate` (UiPanels.xml) is a `<Button>` carrying a `<Size>`, six `<Layers>` slices,
/// a `<ButtonText name="$parentText">`, a `<HighlightTexture name="$parentHighlightTexture">`, the
/// three state fonts and an `<OnUpdate>` — i.e. every decoration pass at once. Instantiating it as
/// `BenillaTemplateProbeTab` must publish `BenillaTemplateProbeTab*`, and must publish nothing
/// named after the template.
#[test]
fn a_real_template_reaches_an_addon_through_create_frame() {
let _data = benilla_formats::wow_data_or_skip!();
let mut s = UiScript::new().unwrap();
s.set_screen_size(1024.0, 768.0);
load_ui(&s);
// Clear anything the UI load itself had to say; what follows is this call's alone.
let _ = s.take_warnings();
let _ = s.take_errors();
s.run(
r#"ProbeTab = CreateFrame("Button", "BenillaTemplateProbeTab", UIParent, "TabButtonTemplate")"#,
)
.expect("the corpus idiom must not error");
// The template's authored `<Size>` is 115x32 in BOTH our retired copy and the reference's, but
// the reference's `<OnLoad>` calls `PanelTemplates_TabResize(0)` — it FITS the tab to its text
// on load, and a freshly created tab has none, so what survives is the two end caps. Ours left
// the fit to an OnUpdate settle (1004), which is why this used to read the pre-fit 115. The
// height is untouched by the fit and still the template's (1860).
let (w, h) = s
.eval::<(f32, f32)>("return ProbeTab:GetWidth(), ProbeTab:GetHeight()")
.unwrap();
assert_eq!(h, 32.0, "the template's own <Size> height");
let caps = s
.eval::<f32>("return 2 * BenillaTemplateProbeTabLeft:GetWidth()")
.unwrap();
// `caps` plus the empty label's one-unit floor (`FONTSTRING_MIN_SPAN`) — the point is that it
// collapsed to its end caps, nowhere near the authored 115.
assert!(
w >= caps && w <= caps + 1.5,
"an unlabelled tab fits down to its two end caps: {w} vs {caps}"
);
assert_eq!(
s.eval::<String>("return ProbeTab:GetParent():GetName()")
.unwrap(),
"UIParent",
"the parent argument, not the template's idea of one"
);
// The globals an addon addresses the parts by — every one named against the INSTANCE. The
// reference's own kit does exactly this (`getglobal(tabName.."Text")` in PanelTemplates).
for suffix in [
"Text", // <ButtonText name="$parentText">
"HighlightTexture", // <HighlightTexture name="$parentHighlightTexture">
"Left", // <Layers> slices
"Middle",
"Right",
"LeftDisabled",
] {
assert!(
s.eval::<bool>(&format!(
r#"return getglobal("BenillaTemplateProbeTab{suffix}") ~= nil"#
))
.unwrap(),
"BenillaTemplateProbeTab{suffix} must exist"
);
assert!(
s.eval::<bool>(&format!(
r#"return getglobal("TabButtonTemplate{suffix}") == nil"#
))
.unwrap(),
"nothing may be published under the TEMPLATE's name (TabButtonTemplate{suffix})"
);
}
// The label is a real FontString the addon can drive.
s.run(r#"getglobal("BenillaTemplateProbeTabText"):SetText("Hi")"#)
.unwrap();
assert_eq!(
s.eval::<String>(r#"return getglobal("BenillaTemplateProbeTabText"):GetText()"#)
.unwrap(),
"Hi"
);
// The template's <Scripts> reached the frame. **`OnLoad`, not `OnUpdate`, since 1860** — the
// OnUpdate was our own text-fit settle (1004), and the reference's `TabButtonTemplate` declares
// exactly one handler: an `<OnLoad>` that calls `PanelTemplates_TabResize(0)` and sizes the
// highlight. That it ran is what the collapsed width above already proves.
assert!(
s.eval::<bool>(r#"return ProbeTab:GetScript("OnLoad") ~= nil"#)
.unwrap(),
"the template's OnLoad is installed"
);
assert!(s.take_errors().is_empty());
assert_eq!(
s.take_warnings(),
Vec::<String>::new(),
"a template that resolves cleanly has nothing to report"
);
}
/// The template the corpus actually asks for, and the handler that proves the naming rule.
///
/// `FauxScrollFrameTemplate` is the most-instantiated template in the 218-addon vanilla corpus that
/// benilla declares at all — 15 `CreateFrame` call sites across AckisRecipeList, FonzAppraiser,
/// Leader, Optional and oRA2. Its `<OnLoad>` is `ScrollFrame_OnLoad`, whose very first line is
///
/// ```lua
/// getglobal(this:GetName() .. "ScrollBarScrollDownButton"):Disable()
/// ```
///
/// so the handler **dies on a nil index** unless the caller's own name won all the way down: the
/// template's nested `<Slider name="$parentScrollBar">` had to become `<caller>ScrollBar`, and
/// *that* slider's own inherited `$parentScrollDownButton` had to become
/// `<caller>ScrollBarScrollDownButton`. Two levels of `$parent`, composed through a runtime
/// template, checked by shipped code rather than by an assertion we wrote to match.
#[test]
fn the_corpus_favourite_template_composes_parent_two_levels_deep() {
let _data = benilla_formats::wow_data_or_skip!();
let mut s = UiScript::new().unwrap();
s.set_screen_size(1024.0, 768.0);
load_ui(&s);
let _ = s.take_warnings();
let _ = s.take_errors();
s.run(
// **A `ScrollFrame`, not a `Frame`, since 1860.** `FauxScrollFrameTemplate` is now the
// reference's own and the reference declares it as a `<ScrollFrame>` carrying a
// `<ScrollChild>`; `framexml::merge` takes the OVERRIDING node's tag, so asking for a
// "Frame" keeps the frame a Frame and the ScrollFrame-only parts — the scroll child among
// them — cannot apply. Our retired copy was a plain `<Frame>`, which is why the corpus
// idiom used to read that way here.
r#"Scroller = CreateFrame("ScrollFrame", "BenillaTemplateProbeScroll", UIParent, "FauxScrollFrameTemplate")"#,
)
.expect("the corpus's most-used template must not error");
// `ScrollFrame_OnLoad` ran to completion — it set `this.offset`, its last statement, which it
// cannot reach if either getglobal above returned nil.
assert_eq!(
s.eval::<f32>("return Scroller.offset").unwrap(),
0.0,
"the template's OnLoad ran to its last line"
);
for suffix in [
"ScrollBar",
"ScrollBarScrollUpButton",
"ScrollBarScrollDownButton",
] {
assert!(
s.eval::<bool>(&format!(
r#"return getglobal("BenillaTemplateProbeScroll{suffix}") ~= nil"#
))
.unwrap(),
"BenillaTemplateProbeScroll{suffix} must exist"
);
}
assert_eq!(
s.eval::<String>("return BenillaTemplateProbeScrollScrollBar:GetParent():GetName()")
.unwrap(),
"BenillaTemplateProbeScroll"
);
assert!(
s.eval::<bool>(r#"return getglobal("FauxScrollFrameTemplateScrollBar") == nil"#)
.unwrap(),
"nothing may be published under the template's own name"
);
assert!(s.take_errors().is_empty());
assert_eq!(s.take_warnings(), Vec::<String>::new());
}