<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Wow-Addon | Tobias Theel | Senior Software Engineer</title><link>https://blog.noobygames.de/tags/wow-addon/</link><description>Remote-first Senior Software Engineer specializing in Go, Cloud-Native architecture, and Game Development. 12+ years of experience in distributed environments.</description><generator>Hugo</generator><language>en</language><copyright>© 2026 Tobias Theel</copyright><lastBuildDate>Sun, 29 Nov 2026 08:00:00 +0100</lastBuildDate><atom:link href="https://blog.noobygames.de/tags/wow-addon/index.xml" rel="self" type="application/rss+xml"/><item><title>Building Level Time — Part 3: Release Pipeline with a Go Installer, BigWigs Packager and CurseForge</title><link>https://blog.noobygames.de/blog/level-time-3-release-pipeline/</link><pubDate>Sun, 29 Nov 2026 08:00:00 +0100</pubDate><dc:creator>Tobias Theel</dc:creator><guid isPermaLink="true">https://blog.noobygames.de/blog/level-time-3-release-pipeline/</guid><category>Software Engineering</category><category>wow-addon</category><category>lua</category><category>go</category><category>github-actions</category><category>bigwigs-packager</category><category>curseforge</category><category>release-automation</category><category>ci-cd</category><description>Push a tag, get a release: shipping a WoW addon to CurseForge with GitHub Actions and the BigWigs packager, plus a small Go installer for local builds.</description><content:encoded><![CDATA[<blockquote>
<p><strong>Series: Building Level Time</strong>, part 3 of 4. <a href="/blog/level-time-1-addon-architecture/">Part 1: Addon architecture</a> · <a href="/blog/level-time-2-testing-lua-with-go/">Part 2: Testing Lua with Go</a> · <strong>Part 3: Release pipeline</strong> · <span class="link-upcoming">Part 4: Goals and the public API</span> · Product page: <a href="/page/level-time/">Level Time</a></p>
</blockquote>
<aside class="tldr" aria-label="Key takeaways">
<p class="tldr-title">TL;DR</p>
<ul>
<li>Pushing a <code>v*</code> git tag triggers Level Time&rsquo;s GitHub Actions release workflow, and <code>needs: test</code> blocks the release whenever the test job fails.</li>
<li>The <code>BigWigsMods/packager@v2</code> action zips the addon, generates the changelog from git history and uploads to CurseForge using the <code>.toc</code> project ID and the <code>CF_API_KEY</code> secret.</li>
<li><code>.pkgmeta</code> is a deny-list, so every new non-addon file in the repository must be added to <code>ignore</code> or it ends up in the zip.</li>
<li>Level Time Goals ships from the same repository through a second packager run on a clone rewritten with <code>git filter-branch --subdirectory-filter StreamGoal</code>.</li>
<li>The Go installer in <code>tools/installer</code> copies only the files the <code>.toc</code> lists into each WoW flavor and refuses any path containing <code>WTF</code>, where SavedVariables live.</li>
</ul>

</aside>

<p>Once an addon works, it still has to reach the players, and I did not want to click through several upload forms for every version. For <a href="/page/level-time/">Level Time</a>, a World of Warcraft addon that tracks time, XP and kills per level, I wanted one rule: <strong>I push a git tag and everything else happens by itself.</strong></p>
<p>In this post I walk through the whole path from <code>git tag</code> to a file on CurseForge: the GitHub Actions workflow, the <a href="https://github.com/BigWigsMods/packager" rel="noopener">BigWigs packager</a>, the <code>.pkgmeta</code> file, the <code>.toc</code> files that serve several game clients, a trick for shipping a second addon from the same repository, and the small Go installer I use to test builds in my own WoW folders.</p>
<p>Everything here is taken from the repository&rsquo;s <code>release.yml</code>, <code>.pkgmeta</code>, <code>Makefile</code> and <code>tools/installer</code>. Comments in the repo are in German; I translated the relevant ones.</p>
<hr>
<h2 id="the-goal-a-tag-is-a-release">The goal: a tag is a release</h2>
<p>The workflow triggers on tags matching <code>v*</code>. Nothing else publishes. Regular pushes to <code>main</code> and pull requests run a separate <code>Test</code> workflow (<code>make vet</code> and <code>make test</code>), so a broken test is usually found long before I tag.</p>










<figure class="diagram">
    <div class="diagram-canvas" role="img" aria-label="From tag to release. The test job gates the release job; the packager runs twice because Level Time and Level Time Goals are separate CurseForge projects.">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 420" width="720" height="420">
  <defs>
    <marker id="ar-lt3-pipeline" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
      <path d="M0 0 L10 5 L0 10 z" class="d-arrowhead"/>
    </marker>
  </defs>

  <rect x="260" y="14" width="200" height="44" rx="9" class="d-box d-b"/>
  <text x="360" y="34" class="d-t d-bold" font-size="14" text-anchor="middle">git tag v2.26.0</text>
  <text x="360" y="50" class="d-m" font-size="11.5" text-anchor="middle">git push origin v2.26.0</text>
  <line x1="360" y1="60" x2="360" y2="80" class="d-arrow" marker-end="url(#ar-lt3-pipeline)"/>

  <rect x="220" y="84" width="280" height="44" rx="9" class="d-box"/>
  <text x="360" y="104" class="d-t d-bold" font-size="14" text-anchor="middle">Job "test"</text>
  <text x="360" y="120" class="d-m" font-size="11.5" text-anchor="middle">make test (Lua scenarios, installer, tools)</text>
  <line x1="360" y1="130" x2="360" y2="150" class="d-arrow" marker-end="url(#ar-lt3-pipeline)"/>
  <text x="372" y="144" class="d-m" font-size="11" text-anchor="start">needs: test</text>

  <rect x="220" y="154" width="280" height="44" rx="9" class="d-box"/>
  <text x="360" y="174" class="d-t d-bold" font-size="14" text-anchor="middle">Job "release"</text>
  <text x="360" y="190" class="d-m" font-size="11.5" text-anchor="middle">full git history (fetch-depth: 0)</text>

  <line x1="360" y1="200" x2="360" y2="214" class="d-arrow"/>
  <line x1="190" y1="214" x2="530" y2="214" class="d-arrow"/>
  <line x1="190" y1="214" x2="190" y2="238" class="d-arrow" marker-end="url(#ar-lt3-pipeline)"/>
  <line x1="530" y1="214" x2="530" y2="238" class="d-arrow" marker-end="url(#ar-lt3-pipeline)"/>

  <rect x="60" y="242" width="260" height="62" rx="9" class="d-box d-y"/>
  <text x="190" y="264" class="d-t d-bold" font-size="14" text-anchor="middle">Packager run 1</text>
  <text x="190" y="282" class="d-m" font-size="11.5" text-anchor="middle">repo root: LevelTimer + LevelTimer_Archive</text>
  <text x="190" y="297" class="d-m" font-size="11.5" text-anchor="middle">.pkgmeta move-folders</text>

  <rect x="400" y="242" width="260" height="62" rx="9" class="d-box d-y"/>
  <text x="530" y="264" class="d-t d-bold" font-size="14" text-anchor="middle">Packager run 2</text>
  <text x="530" y="282" class="d-m" font-size="11.5" text-anchor="middle">split clone: StreamGoal/ as root</text>
  <text x="530" y="297" class="d-m" font-size="11.5" text-anchor="middle">GITHUB_OAUTH empty (no 2nd release)</text>

  <line x1="190" y1="306" x2="190" y2="336" class="d-arrow" marker-end="url(#ar-lt3-pipeline)"/>
  <line x1="530" y1="306" x2="530" y2="336" class="d-arrow" marker-end="url(#ar-lt3-pipeline)"/>

  <rect x="40" y="340" width="300" height="58" rx="9" class="d-box d-g"/>
  <text x="190" y="362" class="d-t d-bold" font-size="13" text-anchor="middle">GitHub release + CurseForge 1721235</text>
  <text x="190" y="380" class="d-m" font-size="11.5" text-anchor="middle">Wago / WoWInterface only if ID + secret exist</text>

  <rect x="400" y="340" width="260" height="58" rx="9" class="d-box d-g"/>
  <text x="530" y="362" class="d-t d-bold" font-size="13" text-anchor="middle">CurseForge 1744370</text>
  <text x="530" y="380" class="d-m" font-size="11.5" text-anchor="middle">Level Time Goals</text>
</svg>

    </div>
    <figcaption class="diagram-caption">From tag to release. The test job gates the release job; the packager runs twice because Level Time and Level Time Goals are separate CurseForge projects.</figcaption>
</figure>

<p>The release workflow, trimmed to its skeleton:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">Release</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">on</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">push</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">tags</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span>- <span class="s2">&#34;v*&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">jobs</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">test</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">runs-on</span><span class="p">:</span><span class="w"> </span><span class="l">ubuntu-latest</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">steps</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span>- <span class="nt">uses</span><span class="p">:</span><span class="w"> </span><span class="l">actions/checkout@v7</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span>- <span class="nt">uses</span><span class="p">:</span><span class="w"> </span><span class="l">actions/setup-go@v7</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nt">with</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">          </span><span class="nt">go-version</span><span class="p">:</span><span class="w"> </span><span class="s2">&#34;1.27&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span>- <span class="nt">run</span><span class="p">:</span><span class="w"> </span><span class="l">make test</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">release</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">needs</span><span class="p">:</span><span class="w"> </span><span class="l">test         </span><span class="w"> </span><span class="c"># no green tests, no release</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">runs-on</span><span class="p">:</span><span class="w"> </span><span class="l">ubuntu-latest</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">permissions</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span><span class="nt">contents</span><span class="p">:</span><span class="w"> </span><span class="l">write   </span><span class="w"> </span><span class="c"># needed to create the GitHub release</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">steps</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span>- <span class="nt">uses</span><span class="p">:</span><span class="w"> </span><span class="l">actions/checkout@v7</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nt">with</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">          </span><span class="nt">fetch-depth</span><span class="p">:</span><span class="w"> </span><span class="m">0</span><span class="w"> </span><span class="c"># the packager needs history for version and changelog</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span>- <span class="nt">uses</span><span class="p">:</span><span class="w"> </span><span class="l">BigWigsMods/packager@v2</span><span class="w">
</span></span></span></code></pre></div><p>Three details matter here.</p>
<p><strong><code>needs: test</code>.</strong> The release job only starts when the test job passes. The tests are the Lua scenarios I describe in <a href="/blog/level-time-2-testing-lua-with-go/">Part 2: Testing Lua with Go</a>, plus the tests of the installer and the other Go tools. A tag on a red commit therefore produces no release. See the GitHub docs on <a href="https://docs.github.com/en/actions/using-jobs/using-jobs-in-a-workflow#defining-prerequisite-jobs" rel="noopener"><code>needs</code></a>.</p>
<p><strong><code>fetch-depth: 0</code>.</strong> <code>actions/checkout</code> fetches a single commit by default. The packager derives the version from the git history and builds the changelog from commit messages, so it needs the full history and the tags.</p>
<p><strong><code>contents: write</code>.</strong> Creating a release needs write permission on repository contents. I grant it to the release job only, not to the test job. See <a href="https://docs.github.com/en/actions/tutorials/authenticate-with-github_token" rel="noopener">Automatic token authentication</a>.</p>
<hr>
<h2 id="the-bigwigs-packager">The BigWigs packager</h2>
<p>The packager is a bash script maintained by the BigWigs team and widely used in the addon ecosystem. It does a handful of jobs that are tedious by hand:</p>
<ol>
<li>Copy the addon files into a clean folder, skipping everything in the <code>ignore</code> list.</li>
<li>Replace keywords such as <code>@project-version@</code> in the files.</li>
<li>Generate a changelog from the git history.</li>
<li>Zip the result.</li>
<li>Upload to the platforms the project has configured, and create a GitHub release.</li>
</ol>
<p>The action <code>BigWigsMods/packager@v2</code> wraps the script. Which platforms it uploads to is decided by two things per platform: an ID in the <code>.toc</code> file and an API token in the environment. The workflow header documents the contract:</p>
<table>
	<thead>
			<tr>
					<th>Platform</th>
					<th><code>.toc</code> line</th>
					<th>Secret</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>CurseForge</td>
					<td><code>## X-Curse-Project-ID</code></td>
					<td><code>CF_API_KEY</code></td>
			</tr>
			<tr>
					<td>Wago</td>
					<td><code>## X-Wago-ID</code></td>
					<td><code>WAGO_API_TOKEN</code></td>
			</tr>
			<tr>
					<td>WoWInterface</td>
					<td><code>## X-WoWI-ID</code></td>
					<td><code>WOWI_API_TOKEN</code></td>
			</tr>
	</tbody>
</table>
<p>If an ID or token is missing, that platform is skipped. If everything is missing you still get the GitHub release, which is a nice property: the pipeline degrades gracefully instead of failing. Currently my <code>.toc</code> files carry a CurseForge project ID only (1721235 for Level Time, 1744370 for Level Time Goals). The tokens are repository secrets passed in as environment variables; their values never appear in the repo.</p>
<h3 id="naming-the-upload">Naming the upload</h3>
<p>By default the packager names the file after the tag, such as <code>v2.26.0</code>. I prefer the same name everywhere, so the workflow passes <code>-n</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl">- <span class="nt">uses</span><span class="p">:</span><span class="w"> </span><span class="l">BigWigsMods/packager@v2</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">with</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">args</span><span class="p">:</span><span class="w"> </span>-<span class="kc">n</span><span class="w"> </span><span class="s2">&#34;{package-name}-{project-version}:{package-name}-{project-version}.zip&#34;</span><span class="w">
</span></span></span></code></pre></div><p>The format is <code>{file name}:{label}</code>. Both parts expand to <code>LevelTimer-v2.26.0</code>, so the zip and the CurseForge display name match the files from the days when I uploaded by hand. The placeholders are described in the <a href="https://github.com/BigWigsMods/packager#usage" rel="noopener">packager README</a>.</p>
<hr>
<h2 id="pkgmeta-what-goes-in-the-zip"><code>.pkgmeta</code>: what goes in the zip</h2>
<p>The packager ships the repository minus what <code>.pkgmeta</code> ignores. That is a deny-list, and that has a consequence: <strong>every new non-addon file in the repo must be added to <code>ignore</code></strong>, or it ends up in the zip. This is the full file, with the comments translated:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="c"># Config for the BigWigs packager (.github/workflows/release.yml).</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">package-as</span><span class="p">:</span><span class="w"> </span><span class="l">LevelTimer</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="c"># Load-on-demand archive: its own addon folder next to LevelTimer/</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">move-folders</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">LevelTimer/LevelTimer_Archive</span><span class="p">:</span><span class="w"> </span><span class="l">LevelTimer_Archive</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">ignore</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="l">tests</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="l">StreamGoal</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="l">tools</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="l">curseforge</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="l">Makefile</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="l">README.md</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="l">ROADMAP.md</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="l">ManualToCheck.md</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span>- <span class="l">image.png</span><span class="w">
</span></span></span></code></pre></div><p>Walking through it:</p>
<ul>
<li><strong><code>package-as</code></strong> sets the folder name inside the zip. The repository is called <code>wow-statistics</code>, but WoW expects the addon folder to match the <code>.toc</code> file name, so the folder must be <code>LevelTimer</code>.</li>
<li><strong><code>move-folders</code></strong> solves a placement problem. Level Time has a second, load-on-demand addon, <code>LevelTimer_Archive</code>, a journal archive that is only loaded when needed. WoW only sees addons that sit directly in <code>Interface/AddOns/</code>. Since the archive lives in a subfolder of the repository, the packager first puts it at <code>LevelTimer/LevelTimer_Archive/</code> and <code>move-folders</code> lifts it to the top level of the zip. The archive&rsquo;s own <code>.toc</code> carries <code>## LoadOnDemand: 1</code> and <code>## Dependencies: LevelTimer</code>.</li>
<li><strong><code>ignore</code></strong> excludes tests, Go tools, CurseForge texts and project docs. Also <code>StreamGoal</code>, which is a separate addon with its own package (next section).</li>
</ul>
<p>For the full list of directives see the <a href="https://github.com/BigWigsMods/packager/wiki/Preparing-the-PackageMeta-File" rel="noopener"><code>.pkgmeta</code> documentation</a>.</p>
<hr>
<h2 id="one-toc-several-game-clients">One <code>.toc</code>, several game clients</h2>
<p>World of Warcraft exists in several flavors: Retail, Classic Era and others. They share the addon format but not the full API. The <code>.toc</code> header of Level Time lists several interface versions in one line:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">## Interface: 120105, 11509, 20506, 16001
</span></span><span class="line"><span class="cl">## Title: Level Time
</span></span><span class="line"><span class="cl">## Version: @project-version@
</span></span><span class="line"><span class="cl">## Author: Nerzal
</span></span><span class="line"><span class="cl">## X-Curse-Project-ID: 1721235
</span></span><span class="line"><span class="cl">## SavedVariables: LevelTimerDB, LevelTimerStatsDB, LevelTimerDebugLog
</span></span></code></pre></div><p>The comma-separated <code>## Interface</code> list lets one <code>.toc</code> serve several clients, as described on the <a href="https://warcraft.wiki.gg/wiki/TOC_format" rel="noopener">TOC format page of the WoW wiki</a>. The project notes in the repo state the rule that follows from it: an API call must either exist on all listed clients or be guarded, because there is no per-flavor build. In Lua that is a plain <code>if GetPVPSessionStats then ...</code> check. The structure behind this is part of <a href="/blog/level-time-1-addon-architecture/">Part 1</a>.</p>
<p>The <code>## Version: @project-version@</code> line is the placeholder the packager replaces with the tag. The Go installer replaces the same token, so a locally installed build reports a version too.</p>
<hr>
<h2 id="two-addons-one-repository">Two addons, one repository</h2>
<p>Level Time Goals is a second addon, lives in the <code>StreamGoal/</code> folder, depends on Level Time (<code>## Dependencies: LevelTimer</code>) and has its own CurseForge project (ID 1744370). I cover how it works in <span class="link-upcoming">Part 4</span>. For the pipeline it poses a problem: the packager expects the addon to sit at the <strong>root of a git repository</strong>, and its <code>-t</code> flag even requires a <code>.git</code> there.</p>
<p>My solution is a second packager run against a throwaway clone whose root <em>is</em> <code>StreamGoal/</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl">- <span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">Split StreamGoal history</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">run</span><span class="p">:</span><span class="w"> </span><span class="p">|</span><span class="sd">
</span></span></span><span class="line"><span class="cl"><span class="sd">    git clone -q . sg-repo
</span></span></span><span class="line"><span class="cl"><span class="sd">    cd sg-repo
</span></span></span><span class="line"><span class="cl"><span class="sd">    git filter-branch -f --subdirectory-filter StreamGoal --tag-name-filter cat -- --all
</span></span></span><span class="line"><span class="cl"><span class="sd">    git checkout -q &#34;$GITHUB_REF_NAME&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl">- <span class="nt">uses</span><span class="p">:</span><span class="w"> </span><span class="l">BigWigsMods/packager@v2</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">env</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">GITHUB_OAUTH</span><span class="p">:</span><span class="w"> </span><span class="s2">&#34;&#34;</span><span class="w">   </span><span class="c"># otherwise a second GitHub release is created for the same tag</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">with</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">args</span><span class="p">:</span><span class="w"> </span>-<span class="l">t sg-repo -n &#34;{package-name}-{project-version}:{package-name}-{project-version}.zip&#34;</span><span class="w">
</span></span></span></code></pre></div><p><a href="https://git-scm.com/docs/git-filter-branch" rel="noopener"><code>git filter-branch --subdirectory-filter</code></a> rewrites the clone so the contents of <code>StreamGoal/</code> become the repository root, and only commits that touched that folder remain. <code>--tag-name-filter cat</code> rewrites tags along with the history. A nice side effect is that the changelog for Level Time Goals then contains only commits that actually changed that addon.</p>
<p>Two caveats:</p>
<ul>
<li><code>git filter-branch</code> is flagged by Git itself as discouraged. <a href="https://github.com/newren/git-filter-repo" rel="noopener"><code>git filter-repo</code></a> is the recommended successor, but it is an extra dependency and the clone is disposable, so I have kept the built-in command so far.</li>
<li>Blanking <code>GITHUB_OAUTH</code> for the second run is deliberate. The first run already created the GitHub release for the tag; without that line the second run would try to create another one.</li>
</ul>
<p>The version token works in both runs because both <code>.toc</code> files contain <code>@project-version@</code>.</p>
<hr>
<h2 id="changelog-and-versioning">Changelog and versioning</h2>
<p>I use plain semantic-style tags: <code>v2.25.0</code>, <code>v2.25.1</code>, <code>v2.26.0</code>. Patch for fixes, minor for features. For a tag build the packager&rsquo;s project version is the tag name.</p>
<p>The changelog is generated by the packager from the git history. There is no hand-written <code>CHANGELOG.md</code> in the repository, so the quality of the release notes is the quality of my commit messages. That is a trade-off: it costs no maintenance, but it rewards disciplined commits. The listing text on CurseForge (description and logo) lives separately in the <code>curseforge/</code> folder and is edited by hand, because it describes the addon rather than a single release.</p>
<p>Local builds use the same idea: the <code>Makefile</code> computes <code>VERSION</code> with <code>git describe --tags --always --dirty</code>, so a local zip is named something like <code>LevelTimer-v2.26.0-3-gabc1234-dirty.zip</code> and cannot be confused with a real release.</p>
<hr>
<h2 id="the-go-installer">The Go installer</h2>
<p>The release pipeline covers the public path. For my own testing I need the opposite: a fast way to put the working copy into my WoW folders, for every game version I have installed. Copying by hand gets old after the third time, and an old file left behind in the addon folder can silently load stale code. So <code>tools/installer</code> is a small Go program, using only the standard library, tested with <code>go test</code> like everything else in the repository.</p>










<figure class="diagram">
    <div class="diagram-canvas" role="img" aria-label="The installer plans before it writes. The plan is a diff against what is already installed, and nothing under WTF is ever touched.">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 330" width="720" height="330">
  <defs>
    <marker id="ar-lt3-installer" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
      <path d="M0 0 L10 5 L0 10 z" class="d-arrowhead"/>
    </marker>
  </defs>

  <rect x="10" y="20" width="150" height="58" rx="9" class="d-box d-b"/>
  <text x="85" y="44" class="d-t d-bold" font-size="13" text-anchor="middle">Read .toc files</text>
  <text x="85" y="62" class="d-m" font-size="11.5" text-anchor="middle">file list + Media/</text>
  <line x1="162" y1="49" x2="188" y2="49" class="d-arrow" marker-end="url(#ar-lt3-installer)"/>

  <rect x="192" y="20" width="150" height="58" rx="9" class="d-box d-b"/>
  <text x="267" y="44" class="d-t d-bold" font-size="13" text-anchor="middle">Find WoW root</text>
  <text x="267" y="62" class="d-m" font-size="11.5" text-anchor="middle">-wow / WOW_DIR / scan</text>
  <line x1="344" y1="49" x2="370" y2="49" class="d-arrow" marker-end="url(#ar-lt3-installer)"/>

  <rect x="374" y="20" width="150" height="58" rx="9" class="d-box d-b"/>
  <text x="449" y="44" class="d-t d-bold" font-size="13" text-anchor="middle">Find flavors</text>
  <text x="449" y="62" class="d-m" font-size="11.5" text-anchor="middle">_retail_, _classic_era_ ...</text>
  <line x1="526" y1="49" x2="552" y2="49" class="d-arrow" marker-end="url(#ar-lt3-installer)"/>

  <rect x="556" y="20" width="154" height="58" rx="9" class="d-box d-y"/>
  <text x="633" y="44" class="d-t d-bold" font-size="13" text-anchor="middle">Build plan</text>
  <text x="633" y="62" class="d-m" font-size="11.5" text-anchor="middle">per addon and flavor</text>
  <line x1="633" y1="80" x2="633" y2="112" class="d-arrow" marker-end="url(#ar-lt3-installer)"/>

  <rect x="480" y="116" width="230" height="74" rx="9" class="d-box"/>
  <text x="595" y="138" class="d-t d-bold" font-size="13" text-anchor="middle">Compare bytes</text>
  <text x="595" y="156" class="d-m" font-size="11.5" text-anchor="middle">+ new   ~ updated   unchanged</text>
  <text x="595" y="173" class="d-m" font-size="11.5" text-anchor="middle">- stale (from old manifest)</text>
  <line x1="478" y1="153" x2="446" y2="153" class="d-arrow" marker-end="url(#ar-lt3-installer)"/>

  <rect x="226" y="116" width="216" height="74" rx="9" class="d-box"/>
  <text x="334" y="138" class="d-t d-bold" font-size="13" text-anchor="middle">Show plan, ask</text>
  <text x="334" y="156" class="d-m" font-size="11.5" text-anchor="middle">--dry-run stops here</text>
  <text x="334" y="173" class="d-m" font-size="11.5" text-anchor="middle">--yes skips the question</text>
  <line x1="224" y1="153" x2="192" y2="153" class="d-arrow" marker-end="url(#ar-lt3-installer)"/>

  <rect x="10" y="116" width="180" height="74" rx="9" class="d-box d-g"/>
  <text x="100" y="138" class="d-t d-bold" font-size="13" text-anchor="middle">Apply</text>
  <text x="100" y="156" class="d-m" font-size="11.5" text-anchor="middle">atomic writes, then</text>
  <text x="100" y="173" class="d-m" font-size="11.5" text-anchor="middle">.install-manifest.json</text>

  <rect x="10" y="236" width="700" height="62" rx="9" class="d-box d-r"/>
  <text x="360" y="260" class="d-t d-bold" font-size="13" text-anchor="middle">Hard guard: any path containing WTF is refused</text>
  <text x="360" y="280" class="d-m" font-size="12" text-anchor="middle">SavedVariables live under WTF, so the installer can never touch your settings or history</text>
</svg>

    </div>
    <figcaption class="diagram-caption">The installer plans before it writes. The plan is a diff against what is already installed, and nothing under WTF is ever touched.</figcaption>
</figure>

<p>What it does, in order:</p>
<ol>
<li><strong>Reads the file list from the <code>.toc</code>.</strong> There is one place that says which files belong to the addon (the <code>.toc</code>), plus everything under <code>Media/</code>. No second list to keep in sync. <code>LoadAddons</code> also discovers every sub-folder that contains <code>&lt;folder&gt;/&lt;folder&gt;.toc</code>, so Level Time Goals and the archive are picked up automatically.</li>
<li><strong>Finds the WoW folder.</strong> Priority: the <code>-wow</code> flag, then the <code>WOW_DIR</code> environment variable, then auto-detection. Auto-detection scans typical locations on Windows (drive letters <code>C:</code> to <code>Z:</code>, folders such as <code>World of Warcraft</code>, <code>Games\World of Warcraft</code>, <code>Program Files (x86)\World of Warcraft</code>) and macOS (<code>/Applications/World of Warcraft</code>). <strong>On Linux there is no auto-detection</strong>, so you pass <code>-wow</code> or set <code>WOW_DIR</code>.</li>
<li><strong>Finds the flavors.</strong> Every sub-folder named like <code>_retail_</code> or <code>_classic_era_</code> counts. You may even point <code>-wow</code> at a flavor folder and it steps up one level.</li>
<li><strong>Builds a plan</strong> per addon and flavor by comparing bytes: new file (<code>+</code>), changed (<code>~</code>), unchanged, or stale (<code>-</code>), meaning it was installed earlier but is no longer in the <code>.toc</code>.</li>
<li><strong>Shows the plan and asks.</strong> <code>-dry-run</code> stops here, <code>-yes</code> skips the question and by default updates the flavors that are already installed.</li>
<li><strong>Applies it.</strong> Each file is written to a temporary file and renamed, so the game never reads a half-written file. Then it writes <code>.install-manifest.json</code> into the addon folder with the version, the file list and applied migrations.</li>
</ol>
<p>The manifest is what makes stale-file cleanup safe. The installer only deletes files it knows it installed earlier. For old manual installs without a manifest it removes only code files (<code>.lua</code>, <code>.toc</code>, <code>.xml</code>) that are no longer referenced by the current <code>.toc</code>.</p>
<h3 id="the-one-rule-it-must-never-break">The one rule it must never break</h3>
<p>SavedVariables are where players&rsquo; data lives: history, settings, everything. They sit under the <code>WTF</code> folder. The installer therefore refuses any path that contains a <code>WTF</code> component, checked once for the target and again for every file it writes (<code>ensureNotConfigPath</code>, <code>safeJoin</code>). It also rejects relative paths that would escape the addon folder. A tool that overwrites your save data on a typo would be worse than no tool.</p>
<p>After an install the output tells you whether <code>/reload</code> in game is enough, or whether the client must restart because the <code>.toc</code> changed. WoW only reads <code>.toc</code> files at startup.</p>
<h3 id="using-it">Using it</h3>
<p>The <code>Makefile</code> wraps the common cases.</p>
<div class="os-tabs">
<div class="os-tab" data-label="Linux / macOS">
<p class="os-tab-label">Linux / macOS</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># Interactive wizard: choose flavors, review the plan, confirm</span>
</span></span><span class="line"><span class="cl">make install
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Update every already-installed flavor without questions</span>
</span></span><span class="line"><span class="cl">make update
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Show what would change, write nothing</span>
</span></span><span class="line"><span class="cl">make dry-run
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># Explicit WoW path (required on Linux)</span>
</span></span><span class="line"><span class="cl">make install <span class="nv">ARGS</span><span class="o">=</span><span class="s2">&#34;-flavors retail -wow &#39;</span><span class="nv">$HOME</span><span class="s2">/Games/World of Warcraft&#39;&#34;</span>
</span></span></code></pre></div>
</div>

<div class="os-tab" data-label="Windows (PowerShell)">
<p class="os-tab-label">Windows (PowerShell)</p>
<p>You can use <code>make</code> if you have it, but the Go tool itself only needs Go:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-powershell" data-lang="powershell"><span class="line"><span class="cl"><span class="c"># Interactive wizard from the repository root</span>
</span></span><span class="line"><span class="cl"><span class="n">go</span> <span class="n">-C</span> <span class="n">tools</span><span class="p">/</span><span class="n">installer</span> <span class="n">run</span> <span class="p">.</span> <span class="n">-src</span> <span class="s2">&#34;</span><span class="nv">$PWD</span><span class="s2">&#34;</span> <span class="n">-version</span> <span class="n">dev</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c"># Dry run for one flavor with an explicit path</span>
</span></span><span class="line"><span class="cl"><span class="n">go</span> <span class="n">-C</span> <span class="n">tools</span><span class="p">/</span><span class="n">installer</span> <span class="n">run</span> <span class="p">.</span> <span class="n">-src</span> <span class="s2">&#34;</span><span class="nv">$PWD</span><span class="s2">&#34;</span> <span class="n">-version</span> <span class="n">dev</span> <span class="n">-dry-run</span> <span class="n">-yes</span> <span class="p">`</span>
</span></span><span class="line"><span class="cl">  <span class="n">-flavors</span> <span class="n">retail</span> <span class="n">-wow</span> <span class="s2">&#34;D:\Games\World of Warcraft&#34;</span>
</span></span></code></pre></div>
</div>

</div>

<p>To install Go see <a href="https://go.dev/doc/install" rel="noopener">go.dev/doc/install</a>. The <code>-C</code> flag of the <code>go</code> command needs Go 1.20 or newer, and CI uses Go 1.27.</p>
<p>The same program builds the manual download. <code>make package</code> runs it in <code>-package</code> mode and writes <code>dist/LevelTimer-&lt;version&gt;.zip</code> (with the archive addon inside) and <code>dist/StreamGoal-&lt;version&gt;.zip</code>. That is a handy local rehearsal of what the packager will produce, but the official release zip comes from the packager, not from this path.</p>
<p>If you are interested in how I handle Go tooling elsewhere, <a href="/blog/go-docker/">Dockerizing Go applications</a> covers a different corner of that toolbox.</p>
<hr>
<h2 id="other-go-tools-in-the-repository">Other Go tools in the repository</h2>
<p>The <code>tools/</code> folder holds more programs. A line each, because they are not part of the release path itself:</p>
<ul>
<li><strong><code>tools/addontest</code></strong> is the test harness from <a href="/blog/level-time-2-testing-lua-with-go/">Part 2</a>.</li>
<li><strong><code>tools/artwork</code></strong> draws the CurseForge logo and the in-game icon and textures (<code>make artwork</code>), so the visuals are reproducible code rather than binary files nobody can edit.</li>
<li><strong><code>tools/records</code></strong> fetches speedrun records from speedrun.com and regenerates <code>Speedrun/SpeedrunRecords.lua</code> (<code>make records</code>, needs internet).</li>
<li><strong><code>tools/flights</code></strong> reads the flight times that the addon measured itself from the SavedVariables of every flavor (read-only) and generates <code>Assist/FlightTimesData.lua</code> (<code>make flights</code>). The project notes say to run it before a release to ship the newest measurements.</li>
</ul>
<hr>
<h2 id="how-to-cut-a-release">How to cut a release</h2>
<p>The checklist I follow. Replace the version with your next one.</p>
<div class="os-tabs">
<div class="os-tab" data-label="Linux / macOS">
<p class="os-tab-label">Linux / macOS</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="c1"># 1. Be on a clean, up-to-date main</span>
</span></span><span class="line"><span class="cl">git switch main <span class="o">&amp;&amp;</span> git pull --ff-only
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># 2. Run what CI will run</span>
</span></span><span class="line"><span class="cl">make vet <span class="o">&amp;&amp;</span> make <span class="nb">test</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># 3. Tag and push the tag; this triggers the Release workflow</span>
</span></span><span class="line"><span class="cl">git tag v2.27.0
</span></span><span class="line"><span class="cl">git push origin v2.27.0
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># 4. Watch the run</span>
</span></span><span class="line"><span class="cl">gh run watch
</span></span></code></pre></div>
</div>

<div class="os-tab" data-label="Windows (PowerShell)">
<p class="os-tab-label">Windows (PowerShell)</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-powershell" data-lang="powershell"><span class="line"><span class="cl"><span class="n">git</span> <span class="k">switch</span> <span class="n">main</span><span class="p">;</span> <span class="n">git</span> <span class="n">pull</span> <span class="p">-</span><span class="n">-ff-only</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c"># Same checks as CI</span>
</span></span><span class="line"><span class="cl"><span class="n">make</span> <span class="n">vet</span><span class="p">;</span> <span class="k">if</span> <span class="p">($?)</span> <span class="p">{</span> <span class="n">make</span> <span class="n">test</span> <span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">git</span> <span class="n">tag</span> <span class="n">v2</span><span class="p">.</span><span class="py">27</span><span class="p">.</span><span class="py">0</span>
</span></span><span class="line"><span class="cl"><span class="n">git</span> <span class="n">push</span> <span class="n">origin</span> <span class="n">v2</span><span class="p">.</span><span class="py">27</span><span class="p">.</span><span class="py">0</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">gh</span> <span class="n">run</span> <span class="n">watch</span>
</span></span></code></pre></div>
</div>

</div>

<p>The <a href="https://cli.github.com/" rel="noopener">GitHub CLI</a> (<code>gh</code>) is optional; the Actions tab shows the same run. If the tests are green, the release job packages, creates the GitHub release and uploads to CurseForge. CurseForge may review a new file for a short while before it appears publicly; that part is out of my hands.</p>
<p>If a release goes wrong, there is no rollback button in the pipeline. I fix forward with a new patch tag (<code>v2.27.1</code>) instead of moving an existing tag, because moved tags confuse packager, GitHub and CurseForge alike.</p>
<hr>
<h2 id="lessons-learned">Lessons learned</h2>
<ul>
<li><strong>Make the default path the right path.</strong> One tag, one command. The fewer manual steps, the fewer forgotten ones.</li>
<li><strong>Gate releases on tests.</strong> <code>needs: test</code> costs one line.</li>
<li><strong>Allow-list or deny-list is a real decision.</strong> The packager is deny-list based. It is convenient until you forget to ignore a new file. My local <code>make package</code> is allow-list based (only what the <code>.toc</code> names) and works as a cross-check.</li>
<li><strong>Build tools that cannot hurt users, even yourself.</strong> The WTF guard in the installer exists because I know I will mistype a path one day.</li>
</ul>
<hr>
<h2 id="whats-next">What&rsquo;s next</h2>
<p>In the last part, <span class="link-upcoming">Part 4: Goals and the public API</span>, I show how Level Time Goals plugs into Level Time through an exported API and why the two addons are separate. If you want to try the result, the <a href="/page/level-time/">Level Time page</a> links to CurseForge and GitHub.</p>
]]></content:encoded></item><item><title>Building Level Time — Part 2: Testing a Lua WoW Addon from Go with gopher-lua</title><link>https://blog.noobygames.de/blog/level-time-2-testing-lua-with-go/</link><pubDate>Wed, 18 Nov 2026 08:00:00 +0100</pubDate><dc:creator>Tobias Theel</dc:creator><guid isPermaLink="true">https://blog.noobygames.de/blog/level-time-2-testing-lua-with-go/</guid><category>Software Engineering</category><category>go</category><category>lua</category><category>gopher-lua</category><category>testing</category><category>wow-addon</category><category>world-of-warcraft</category><category>github-actions</category><category>ci</category><category>learning-in-public</category><description>WoW has no test runner. How I run 286 addon scenarios with go test: a gopher-lua VM, a hand-built WoW API stub and layout checks in four languages.</description><content:encoded><![CDATA[<blockquote>
<p><strong>Building Level Time, part 2 of 4.</strong> <a href="/page/level-time/">Level Time</a> is my World of Warcraft addon for tracking leveling time. This series is the engineering story behind it. Part 1: <a href="/blog/level-time-1-addon-architecture/">Addon architecture</a>. <strong>Part 2 (this post): testing Lua from Go.</strong> Part 3: <a href="/blog/level-time-3-release-pipeline/">The release pipeline</a>. Part 4: <span class="link-upcoming">Goals and the public API</span>.</p>
</blockquote>
<aside class="tldr" aria-label="Key takeaways">
<p class="tldr-title">TL;DR</p>
<ul>
<li>Level Time&rsquo;s test harness in <code>tools/addontest</code> runs the addon&rsquo;s Lua code with <code>go test</code> inside gopher-lua, a pure-Go Lua 5.1 VM, with no game client and no Lua installation.</li>
<li>Each of the 286 scenario files gets a fresh <code>lua.NewState()</code> and its own Go subtest, so <code>go test -run 'TestScenarios/session'</code> runs a single scenario.</li>
<li>The <code>tools/addontest</code> harness loads the addon files in <code>.toc</code> order and fakes the WoW API with a stub whose unknown frame methods are no-ops.</li>
<li>Level Time&rsquo;s layout tests check the options and history windows in German, English, French and Spanish, using a crude text width of 6 per byte.</li>
<li>Always pass <code>-count=1</code> to <code>go test</code>, because Go&rsquo;s test cache knows nothing about the Lua files gopher-lua loads.</li>
</ul>

</aside>

<p>A World of Warcraft addon runs inside a game client. There is no <code>npm test</code>, no <code>go test</code>, no <code>pytest</code>, and no way to start the addon&rsquo;s Lua code on its own. The only built-in feedback loop is: edit a file, type <code>/reload</code>, click around, read the chat window.</p>
<p>That loop is fine for a 200-line addon. Level Time is not that anymore. It has a timer window, statistics, a history with tables and charts, an options window with search, speedrun comparisons and a sibling addon. At that size, &ldquo;I clicked around and it looked fine&rdquo; stops being a test strategy.</p>
<p>So I did what I do for every other piece of software: I wrote a test harness. It lives in <code>tools/addontest</code> in the <a href="https://github.com/Noobygames/wow-statistics" rel="noopener">wow-statistics repository</a> and it is a small Go program that runs the addon&rsquo;s Lua code inside a Lua VM, with a hand-written fake of the WoW API. This post shows how it works, what it can check, and, equally important, what it cannot.</p>
<hr>
<h2 id="why-test-an-addon-outside-the-game">Why test an addon outside the game?</h2>
<p>Three problems pushed me there.</p>
<ol>
<li><strong>No runner in the client.</strong> WoW offers <code>/run</code>, <code>/dump</code> and the error popup, but nothing that executes a suite of assertions and reports pass or fail.</li>
<li><strong>Slow, manual reload cycles.</strong> Every check means a reload, a login state that matches the situation (the right level, XP, combat state) and manual clicking. Reproducing &ldquo;what happens at the exact moment I level up with a pending timer&rdquo; by hand is tedious and unreliable.</li>
<li><strong>Regressions in code nobody looks at.</strong> Level Time is localized (German, English, French, Spanish) and runs on several game versions. A change to one module can break a window in a language I did not have open.</li>
</ol>
<p>The harness catches the large class of bugs that are pure logic (counters, state machines, migrations, event handling, layout arithmetic) in about the time it takes to run <code>go test</code>. I still play the game to check everything else.</p>
<hr>
<h2 id="the-architecture-at-a-glance">The architecture at a glance</h2>










<figure class="diagram">
    <div class="diagram-canvas" role="img" aria-label="One Lua VM per scenario: the scenario drives a fake WoW API, the real addon code reacts, assertions collect failures that Go reports.">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 380" width="720" height="380">
  <defs>
    <marker id="ar-lt2-harness" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
      <path d="M0 0 L10 5 L0 10 z" class="d-arrowhead"/>
    </marker>
  </defs>

  <rect x="16" y="50" width="150" height="64" rx="9" class="d-box d-b"/>
  <text x="91" y="76" class="d-t d-bold" font-size="14" text-anchor="middle">go test</text>
  <text x="91" y="96" class="d-m" font-size="11.5" text-anchor="middle">TestScenarios</text>
  <line x1="168" y1="82" x2="196" y2="82" class="d-arrow" marker-end="url(#ar-lt2-harness)"/>

  <rect x="200" y="16" width="504" height="262" rx="12" class="d-box d-y d-dashed"/>
  <text x="216" y="38" class="d-t d-bold" font-size="13">gopher-lua VM (Lua 5.1, fresh per scenario)</text>

  <rect x="222" y="56" width="210" height="72" rx="9" class="d-box d-y"/>
  <text x="327" y="84" class="d-t d-bold" font-size="14" text-anchor="middle">WoW API stub</text>
  <text x="327" y="104" class="d-m" font-size="11.5" text-anchor="middle">frames, events, C_Timer, C_*</text>

  <rect x="474" y="56" width="210" height="72" rx="9" class="d-box d-g"/>
  <text x="579" y="84" class="d-t d-bold" font-size="14" text-anchor="middle">Addon Lua</text>
  <text x="579" y="104" class="d-m" font-size="11.5" text-anchor="middle">loaded in .toc order</text>
  <line x1="434" y1="86" x2="472" y2="86" class="d-arrow" marker-end="url(#ar-lt2-harness)"/>
  <line x1="472" y1="104" x2="434" y2="104" class="d-arrow" marker-end="url(#ar-lt2-harness)"/>
  <text x="453" y="76" class="d-m" font-size="11" text-anchor="middle">events</text>
  <text x="453" y="120" class="d-m" font-size="11" text-anchor="middle">API</text>

  <rect x="222" y="190" width="210" height="72" rx="9" class="d-box d-b"/>
  <text x="327" y="218" class="d-t d-bold" font-size="14" text-anchor="middle">Scenario</text>
  <text x="327" y="238" class="d-m" font-size="11.5" text-anchor="middle">tests/*_test.lua</text>
  <line x1="327" y1="188" x2="327" y2="130" class="d-arrow" marker-end="url(#ar-lt2-harness)"/>
  <text x="335" y="164" class="d-m" font-size="11">wow.login / wow.fire</text>

  <rect x="474" y="190" width="210" height="72" rx="9" class="d-box d-r"/>
  <text x="579" y="218" class="d-t d-bold" font-size="14" text-anchor="middle">Assertions</text>
  <text x="579" y="238" class="d-m" font-size="11.5" text-anchor="middle">expect() fills TEST_FAILURES</text>
  <line x1="434" y1="226" x2="472" y2="226" class="d-arrow" marker-end="url(#ar-lt2-harness)"/>
  <line x1="579" y1="188" x2="579" y2="130" class="d-arrow d-dashed" marker-end="url(#ar-lt2-harness)"/>
  <text x="587" y="164" class="d-m" font-size="11">reads addon state</text>

  <line x1="579" y1="280" x2="579" y2="314" class="d-arrow" marker-end="url(#ar-lt2-harness)"/>
  <rect x="330" y="318" width="374" height="46" rx="9" class="d-box d-b"/>
  <text x="517" y="338" class="d-t d-bold" font-size="13" text-anchor="middle">Go reads TEST_FAILURES + wow.errors</text>
  <text x="517" y="355" class="d-m" font-size="11.5" text-anchor="middle">every entry becomes a t.Error</text>
</svg>

    </div>
    <figcaption class="diagram-caption">One Lua VM per scenario: the scenario drives a fake WoW API, the real addon code reacts, assertions collect failures that Go reports.</figcaption>
</figure>

<p>The pieces:</p>
<ul>
<li><strong><code>tools/addontest/addon_test.go</code></strong>: the Go entry point, about 70 lines.</li>
<li><strong><a href="https://github.com/yuin/gopher-lua" rel="noopener">gopher-lua</a></strong>: a Lua 5.1 virtual machine written in pure Go. No cgo and no external Lua installation, so <code>go test</code> works on any machine with Go.</li>
<li><strong><code>tests/wow_stub.lua</code></strong> plus <code>tests/stub/*.lua</code>: the fake WoW API, split by area (UI, chat, units, addons, player, comfort, economy, social).</li>
<li><strong><code>tests/*_test.lua</code></strong>: the scenarios. At the time of writing there are 286 of them.</li>
<li><strong>The addon itself</strong>, loaded unchanged from the repository.</li>
</ul>
<hr>
<h2 id="the-go-side-one-vm-per-scenario">The Go side: one VM per scenario</h2>
<p>The Go runner globs every <code>tests/*_test.lua</code> and turns each file into a Go subtest. This is a simplified version of the real code (error handling shortened, and the real messages are German like the codebase comments):</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-go" data-lang="go"><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="nf">TestScenarios</span><span class="p">(</span><span class="nx">t</span><span class="w"> </span><span class="o">*</span><span class="nx">testing</span><span class="p">.</span><span class="nx">T</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nx">root</span><span class="p">,</span><span class="w"> </span><span class="nx">_</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">filepath</span><span class="p">.</span><span class="nf">Abs</span><span class="p">(</span><span class="s">&#34;../..&#34;</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nx">scenarios</span><span class="p">,</span><span class="w"> </span><span class="nx">_</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">filepath</span><span class="p">.</span><span class="nf">Glob</span><span class="p">(</span><span class="nx">filepath</span><span class="p">.</span><span class="nf">Join</span><span class="p">(</span><span class="nx">root</span><span class="p">,</span><span class="w"> </span><span class="s">&#34;tests&#34;</span><span class="p">,</span><span class="w"> </span><span class="s">&#34;*_test.lua&#34;</span><span class="p">))</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">for</span><span class="w"> </span><span class="nx">_</span><span class="p">,</span><span class="w"> </span><span class="nx">scenario</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="k">range</span><span class="w"> </span><span class="nx">scenarios</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nx">name</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">strings</span><span class="p">.</span><span class="nf">TrimSuffix</span><span class="p">(</span><span class="nx">filepath</span><span class="p">.</span><span class="nf">Base</span><span class="p">(</span><span class="nx">scenario</span><span class="p">),</span><span class="w"> </span><span class="s">&#34;_test.lua&#34;</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nx">t</span><span class="p">.</span><span class="nf">Run</span><span class="p">(</span><span class="nx">name</span><span class="p">,</span><span class="w"> </span><span class="kd">func</span><span class="p">(</span><span class="nx">t</span><span class="w"> </span><span class="o">*</span><span class="nx">testing</span><span class="p">.</span><span class="nx">T</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">            </span><span class="nf">runScenario</span><span class="p">(</span><span class="nx">t</span><span class="p">,</span><span class="w"> </span><span class="nx">root</span><span class="p">,</span><span class="w"> </span><span class="nx">scenario</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="p">})</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="kd">func</span><span class="w"> </span><span class="nf">runScenario</span><span class="p">(</span><span class="nx">t</span><span class="w"> </span><span class="o">*</span><span class="nx">testing</span><span class="p">.</span><span class="nx">T</span><span class="p">,</span><span class="w"> </span><span class="nx">root</span><span class="p">,</span><span class="w"> </span><span class="nx">scenario</span><span class="w"> </span><span class="kt">string</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nx">L</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">lua</span><span class="p">.</span><span class="nf">NewState</span><span class="p">()</span><span class="w"> </span><span class="c1">// fresh Lua 5.1 state: no shared globals between scenarios</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">defer</span><span class="w"> </span><span class="nx">L</span><span class="p">.</span><span class="nf">Close</span><span class="p">()</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nx">L</span><span class="p">.</span><span class="nf">SetGlobal</span><span class="p">(</span><span class="s">&#34;ADDON_DIR&#34;</span><span class="p">,</span><span class="w"> </span><span class="nx">lua</span><span class="p">.</span><span class="nf">LString</span><span class="p">(</span><span class="nx">filepath</span><span class="p">.</span><span class="nf">ToSlash</span><span class="p">(</span><span class="nx">root</span><span class="p">)))</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nx">L</span><span class="p">.</span><span class="nf">SetGlobal</span><span class="p">(</span><span class="s">&#34;SCENARIO&#34;</span><span class="p">,</span><span class="w"> </span><span class="nx">lua</span><span class="p">.</span><span class="nf">LString</span><span class="p">(</span><span class="nx">strings</span><span class="p">.</span><span class="nf">TrimSuffix</span><span class="p">(</span><span class="nx">filepath</span><span class="p">.</span><span class="nf">Base</span><span class="p">(</span><span class="nx">scenario</span><span class="p">),</span><span class="w"> </span><span class="s">&#34;_test.lua&#34;</span><span class="p">)))</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="c1">// 1. build the fake client and load the addon</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">L</span><span class="p">.</span><span class="nf">DoFile</span><span class="p">(</span><span class="nx">filepath</span><span class="p">.</span><span class="nf">Join</span><span class="p">(</span><span class="nx">root</span><span class="p">,</span><span class="w"> </span><span class="s">&#34;tests&#34;</span><span class="p">,</span><span class="w"> </span><span class="s">&#34;wow_stub.lua&#34;</span><span class="p">));</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">nil</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nx">t</span><span class="p">.</span><span class="nf">Fatalf</span><span class="p">(</span><span class="s">&#34;loading addon: %v&#34;</span><span class="p">,</span><span class="w"> </span><span class="nx">err</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="c1">// 2. run the scenario</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">L</span><span class="p">.</span><span class="nf">DoFile</span><span class="p">(</span><span class="nx">scenario</span><span class="p">);</span><span class="w"> </span><span class="nx">err</span><span class="w"> </span><span class="o">!=</span><span class="w"> </span><span class="kc">nil</span><span class="w"> </span><span class="p">{</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nx">t</span><span class="p">.</span><span class="nf">Fatalf</span><span class="p">(</span><span class="s">&#34;scenario aborted: %v&#34;</span><span class="p">,</span><span class="w"> </span><span class="nx">err</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="p">}</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="c1">// 3. collect failures</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nx">failures</span><span class="w"> </span><span class="o">:=</span><span class="w"> </span><span class="nx">L</span><span class="p">.</span><span class="nf">GetGlobal</span><span class="p">(</span><span class="s">&#34;TEST_FAILURES&#34;</span><span class="p">).(</span><span class="o">*</span><span class="nx">lua</span><span class="p">.</span><span class="nx">LTable</span><span class="p">)</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nx">failures</span><span class="p">.</span><span class="nf">ForEach</span><span class="p">(</span><span class="kd">func</span><span class="p">(</span><span class="nx">_</span><span class="p">,</span><span class="w"> </span><span class="nx">failure</span><span class="w"> </span><span class="nx">lua</span><span class="p">.</span><span class="nx">LValue</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nx">t</span><span class="p">.</span><span class="nf">Error</span><span class="p">(</span><span class="nx">failure</span><span class="p">.</span><span class="nf">String</span><span class="p">())</span><span class="w"> </span><span class="p">})</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="p">}</span><span class="w">
</span></span></span></code></pre></div><p>Three design decisions are hiding in there:</p>
<ul>
<li><strong>A fresh <code>lua.NewState()</code> per scenario.</strong> Real addons keep state in globals (<code>LevelTimerStatsDB</code>, frames registered by name). Sharing a VM between tests would let one scenario leak into the next. With a new state per scenario, every test starts from a just-loaded client.</li>
<li><strong><code>t.Run</code> per file.</strong> Each scenario is addressable: <code>go test -run 'TestScenarios/session'</code> runs just <code>tests/session_test.lua</code>. Go&rsquo;s subtests give me filtering and readable failure output for free.</li>
<li><strong>Lua assertions do not abort.</strong> The Lua side records failures in a global table instead of raising an error, so one run reports every broken expectation, not just the first.</li>
</ul>
<p>There is also a safety net. Every event handler and callback in the addon runs through <code>ns.SafeCall</code>, a wrapper around <code>xpcall</code> that forwards errors to the client&rsquo;s error handler (<code>geterrorhandler()</code>). In the real game this means one broken module cannot stop the others. In the harness, the fake error handler collects those errors into <code>wow.errors</code>, and Go turns each one into a test failure. A scenario that deliberately provokes an error clears the list afterwards.</p>
<hr>
<h2 id="loading-the-addon-in-toc-order">Loading the addon in <code>.toc</code> order</h2>
<p>A WoW addon is not a program with a <code>main</code>. It is a folder with a <code>.toc</code> file that lists the Lua files; the client executes them in that order and passes each file two values through <code>...</code>: the addon name and a private namespace table. See the <a href="https://warcraft.wiki.gg/wiki/TOC_format" rel="noopener">TOC format on warcraft.wiki.gg</a> for the details.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">## Interface: 120105, 11509, 20506, 16001
</span></span><span class="line"><span class="cl">## SavedVariables: LevelTimerDB, LevelTimerStatsDB, LevelTimerDebugLog
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">Core\Client.lua
</span></span><span class="line"><span class="cl">Core\Database.lua
</span></span><span class="line"><span class="cl">Tracking\Stats.lua
</span></span><span class="line"><span class="cl">UI\TimerWindow.lua
</span></span></code></pre></div><p>(Excerpt; the real file lists many more files, grouped by comments.) The harness does the same thing and uses the <code>.toc</code> as the single source of truth instead of keeping a second file list in the test code:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-lua" data-lang="lua"><span class="line"><span class="cl"><span class="n">addon</span> <span class="o">=</span> <span class="p">{}</span>
</span></span><span class="line"><span class="cl"><span class="kr">for</span> <span class="n">line</span> <span class="kr">in</span> <span class="n">io.lines</span><span class="p">(</span><span class="n">ADDON_DIR</span> <span class="o">..</span> <span class="s2">&#34;/LevelTimer.toc&#34;</span><span class="p">)</span> <span class="kr">do</span>
</span></span><span class="line"><span class="cl">  <span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="p">:</span><span class="n">gsub</span><span class="p">(</span><span class="s2">&#34;</span><span class="se">\r</span><span class="s2">&#34;</span><span class="p">,</span> <span class="s2">&#34;&#34;</span><span class="p">):</span><span class="n">gsub</span><span class="p">(</span><span class="s2">&#34;</span><span class="se">\\</span><span class="s2">&#34;</span><span class="p">,</span> <span class="s2">&#34;/&#34;</span><span class="p">)</span>  <span class="c1">-- .toc paths use backslashes</span>
</span></span><span class="line"><span class="cl">  <span class="kr">if</span> <span class="n">line</span> <span class="o">~=</span> <span class="s2">&#34;&#34;</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">line</span><span class="p">:</span><span class="n">match</span><span class="p">(</span><span class="s2">&#34;^#&#34;</span><span class="p">)</span> <span class="kr">then</span>
</span></span><span class="line"><span class="cl">    <span class="kd">local</span> <span class="n">chunk</span><span class="p">,</span> <span class="n">err</span> <span class="o">=</span> <span class="n">loadfile</span><span class="p">(</span><span class="n">ADDON_DIR</span> <span class="o">..</span> <span class="s2">&#34;/&#34;</span> <span class="o">..</span> <span class="n">line</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="kr">if</span> <span class="ow">not</span> <span class="n">chunk</span> <span class="kr">then</span> <span class="n">error</span><span class="p">(</span><span class="n">err</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="kr">end</span>
</span></span><span class="line"><span class="cl">    <span class="n">chunk</span><span class="p">(</span><span class="s2">&#34;LevelTimer&#34;</span><span class="p">,</span> <span class="n">addon</span><span class="p">)</span>  <span class="c1">-- same arguments the client passes: name, namespace</span>
</span></span><span class="line"><span class="cl">  <span class="kr">end</span>
</span></span><span class="line"><span class="cl"><span class="kr">end</span>
</span></span></code></pre></div><p>Two details matter here. First, a file that is missing from the <code>.toc</code> is also missing in the test, which catches the classic &ldquo;works on my machine, never loads in the client&rdquo; mistake. Second, <code>chunk(&quot;LevelTimer&quot;, addon)</code> mimics the client&rsquo;s <code>local addonName, ns = ...</code> convention, and the harness keeps a reference to that namespace so scenarios can reach into modules (<code>addon.Stats</code>, <code>addon.Database</code>, and so on).</p>
<hr>
<h2 id="the-wow-api-stub">The WoW API stub</h2>
<p>The stub is where most of the work lives. It consists of <code>tests/wow_stub.lua</code> plus the area files under <code>tests/stub/</code>. Its core ideas:</p>
<h3 id="frames-that-accept-anything">Frames that accept anything</h3>
<p>WoW UI code calls hundreds of frame methods. Faking all of them is not realistic, so the stub&rsquo;s frame objects use a metatable: <strong>known methods behave like the client, unknown methods are no-ops</strong>.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-lua" data-lang="lua"><span class="line"><span class="cl"><span class="kd">local</span> <span class="n">frameMethods</span> <span class="o">=</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">  <span class="n">SetText</span>   <span class="o">=</span> <span class="kr">function</span><span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="n">text</span><span class="p">)</span> <span class="n">self._text</span> <span class="o">=</span> <span class="n">tostring</span><span class="p">(</span><span class="n">text</span><span class="p">)</span> <span class="kr">end</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">  <span class="n">GetText</span>   <span class="o">=</span> <span class="kr">function</span><span class="p">(</span><span class="n">self</span><span class="p">)</span> <span class="kr">return</span> <span class="n">self._text</span> <span class="kr">end</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">  <span class="n">SetWidth</span>  <span class="o">=</span> <span class="kr">function</span><span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="n">width</span><span class="p">)</span> <span class="n">self._width</span> <span class="o">=</span> <span class="n">width</span> <span class="kr">end</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">  <span class="n">GetWidth</span>  <span class="o">=</span> <span class="kr">function</span><span class="p">(</span><span class="n">self</span><span class="p">)</span> <span class="kr">return</span> <span class="n">self._width</span> <span class="kr">end</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">  <span class="n">SetPoint</span>  <span class="o">=</span> <span class="kr">function</span><span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="p">...)</span> <span class="n">table.insert</span><span class="p">(</span><span class="n">self._points</span><span class="p">,</span> <span class="p">{</span> <span class="p">...</span> <span class="p">})</span> <span class="kr">end</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">  <span class="n">SetScript</span> <span class="o">=</span> <span class="kr">function</span><span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">handler</span><span class="p">)</span> <span class="n">self._scripts</span><span class="p">[</span><span class="n">name</span><span class="p">]</span> <span class="o">=</span> <span class="n">handler</span> <span class="kr">end</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">  <span class="n">RegisterEvent</span> <span class="o">=</span> <span class="kr">function</span><span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="n">event</span><span class="p">)</span> <span class="n">self._events</span><span class="p">[</span><span class="n">event</span><span class="p">]</span> <span class="o">=</span> <span class="kc">true</span> <span class="kr">end</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">  <span class="c1">-- ...</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kr">return</span> <span class="n">setmetatable</span><span class="p">(</span><span class="n">frame</span><span class="p">,</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">  <span class="n">__index</span> <span class="o">=</span> <span class="kr">function</span><span class="p">(</span><span class="n">_</span><span class="p">,</span> <span class="n">key</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="kd">local</span> <span class="n">method</span> <span class="o">=</span> <span class="n">frameMethods</span><span class="p">[</span><span class="n">key</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">    <span class="kr">if</span> <span class="n">method</span> <span class="o">==</span> <span class="kc">false</span> <span class="kr">then</span> <span class="kr">return</span> <span class="kc">nil</span> <span class="kr">end</span> <span class="c1">-- false = &#34;method does not exist in this client&#34;</span>
</span></span><span class="line"><span class="cl">    <span class="kr">return</span> <span class="n">method</span> <span class="ow">or</span> <span class="n">noop</span>
</span></span><span class="line"><span class="cl">  <span class="kr">end</span><span class="p">,</span>
</span></span><span class="line"><span class="cl"><span class="p">})</span>
</span></span></code></pre></div><p>(Simplified. The real table has a few dozen entries.) So <code>frame:SetBackdropBorderColor(...)</code> is silently accepted until a test needs to see its effect, and then I add one line. The <code>false</code> value is a deliberate escape hatch: setting <code>frameMethods.RegisterUnitEvent = false</code> makes the method <em>missing</em>, which lets a scenario exercise the fallback for a client that lacks it.</p>
<p>Note what <code>SetPoint</code> does: it does not lay anything out. It <strong>records</strong> the anchor in <code>frame._points</code>. That is what makes layout tests possible later.</p>
<h3 id="events-and-time-under-test-control">Events and time under test control</h3>
<p>The addon is event-driven, so the stub needs a way to fire events and to move time:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-lua" data-lang="lua"><span class="line"><span class="cl"><span class="kr">function</span> <span class="nc">wow</span><span class="p">.</span><span class="nf">fire</span><span class="p">(</span><span class="n">event</span><span class="p">,</span> <span class="p">...)</span>
</span></span><span class="line"><span class="cl">  <span class="kr">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">frame</span> <span class="kr">in</span> <span class="n">ipairs</span><span class="p">(</span><span class="n">frames</span><span class="p">)</span> <span class="kr">do</span>
</span></span><span class="line"><span class="cl">    <span class="kr">if</span> <span class="n">frame._events</span><span class="p">[</span><span class="n">event</span><span class="p">]</span> <span class="ow">and</span> <span class="n">frame._scripts</span><span class="p">.</span><span class="n">OnEvent</span> <span class="kr">then</span>
</span></span><span class="line"><span class="cl">      <span class="n">frame._scripts</span><span class="p">.</span><span class="n">OnEvent</span><span class="p">(</span><span class="n">frame</span><span class="p">,</span> <span class="n">event</span><span class="p">,</span> <span class="p">...)</span>
</span></span><span class="line"><span class="cl">    <span class="kr">end</span>
</span></span><span class="line"><span class="cl">  <span class="kr">end</span>
</span></span><span class="line"><span class="cl"><span class="kr">end</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kr">function</span> <span class="nc">wow</span><span class="p">.</span><span class="nf">advance</span><span class="p">(</span><span class="n">seconds</span><span class="p">)</span>            <span class="c1">-- GetTime() and time() both move</span>
</span></span><span class="line"><span class="cl">  <span class="n">wow.state</span><span class="p">.</span><span class="n">now</span>   <span class="o">=</span> <span class="n">wow.state</span><span class="p">.</span><span class="n">now</span>   <span class="o">+</span> <span class="n">seconds</span>
</span></span><span class="line"><span class="cl">  <span class="n">wow.state</span><span class="p">.</span><span class="n">clock</span> <span class="o">=</span> <span class="n">wow.state</span><span class="p">.</span><span class="n">clock</span> <span class="o">+</span> <span class="n">seconds</span>
</span></span><span class="line"><span class="cl"><span class="kr">end</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">C_Timer</span> <span class="o">=</span> <span class="p">{</span> <span class="n">After</span> <span class="o">=</span> <span class="kr">function</span><span class="p">(</span><span class="n">_</span><span class="p">,</span> <span class="n">callback</span><span class="p">)</span> <span class="n">table.insert</span><span class="p">(</span><span class="n">wow.timers</span><span class="p">,</span> <span class="n">callback</span><span class="p">)</span> <span class="kr">end</span> <span class="p">}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kr">function</span> <span class="nc">wow</span><span class="p">.</span><span class="nf">runTimers</span><span class="p">()</span> <span class="c1">-- run everything scheduled so far, delay ignored</span>
</span></span><span class="line"><span class="cl">  <span class="kd">local</span> <span class="n">due</span> <span class="o">=</span> <span class="n">wow.timers</span>
</span></span><span class="line"><span class="cl">  <span class="n">wow.timers</span> <span class="o">=</span> <span class="p">{}</span>
</span></span><span class="line"><span class="cl">  <span class="kr">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">callback</span> <span class="kr">in</span> <span class="n">ipairs</span><span class="p">(</span><span class="n">due</span><span class="p">)</span> <span class="kr">do</span> <span class="n">callback</span><span class="p">()</span> <span class="kr">end</span>
</span></span><span class="line"><span class="cl"><span class="kr">end</span>
</span></span></code></pre></div><p>Controlling time is what makes this testable: nothing sleeps. <code>C_Timer.After</code> callbacks are only queued, and <code>wow.runTimers()</code> executes them on demand. A scenario about &ldquo;income appears after the repair bill is paid&rdquo; runs in microseconds and is fully deterministic. <code>wow.update(seconds)</code> does the same for <code>OnUpdate</code> handlers, which is how repeating tasks and the timer window tick.</p>
<p>The game state itself is one table, <code>wow.state</code> (name, level, XP, money, buffs, combat flag, zone and more), which API functions such as <code>UnitLevel</code> and <code>GetTime</code> read from. A scenario changes the state and then fires the event the client would have fired.</p>
<h3 id="namespaces-and-client-flavors">Namespaces and client flavors</h3>
<p>Modern WoW API lives in namespaces such as <code>C_Timer</code>, <code>C_Spell</code>, <code>C_Container</code> or <code>C_UnitAuras</code> (<a href="https://warcraft.wiki.gg/wiki/World_of_Warcraft_API" rel="noopener">overview on warcraft.wiki.gg</a>). The stub defines the ones the addon uses, in the matching area file. The project rule is simple: when the addon starts using a new API function, it gets added to the stub in the same change.</p>
<p>Level Time supports several client flavors (Retail, Classic Era, WoW Forever). The scenario <em>file name</em> picks the flavor: <code>era_*</code> scenarios load as Classic Era (interface 11509), <code>forever_*</code> as WoW Forever (16001), everything else as Retail. That is one line in the stub that reads the <code>SCENARIO</code> global set by the Go runner.</p>
<hr>
<h2 id="a-real-scenario">A real scenario</h2>
<p>Here is a trimmed and simplified scenario in the style of <code>tests/session_test.lua</code>: sessions count in parallel to the level and survive a <code>/reload</code>.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-lua" data-lang="lua"><span class="line"><span class="cl"><span class="kd">local</span> <span class="n">Stats</span> <span class="o">=</span> <span class="n">addon.Stats</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">-- simulate a login at level 10 with 500 XP and one hour played</span>
</span></span><span class="line"><span class="cl"><span class="n">wow.login</span><span class="p">({</span> <span class="n">level</span> <span class="o">=</span> <span class="mi">10</span><span class="p">,</span> <span class="n">xp</span> <span class="o">=</span> <span class="mi">500</span><span class="p">,</span> <span class="n">xpMax</span> <span class="o">=</span> <span class="mi">1000</span><span class="p">,</span> <span class="n">playedSeconds</span> <span class="o">=</span> <span class="mi">3600</span> <span class="p">})</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">-- kill a wolf: the client sends a chat event and the XP bar moves</span>
</span></span><span class="line"><span class="cl"><span class="n">wow.fire</span><span class="p">(</span><span class="s2">&#34;CHAT_MSG_COMBAT_XP_GAIN&#34;</span><span class="p">,</span> <span class="s2">&#34;Wolf dies, you gain 100 experience.&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="n">wow.state</span><span class="p">.</span><span class="n">xp</span> <span class="o">=</span> <span class="mi">600</span>
</span></span><span class="line"><span class="cl"><span class="n">wow.fire</span><span class="p">(</span><span class="s2">&#34;PLAYER_XP_UPDATE&#34;</span><span class="p">,</span> <span class="s2">&#34;player&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="n">wow.advance</span><span class="p">(</span><span class="mi">1200</span><span class="p">)</span> <span class="c1">-- twenty minutes pass</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">expect</span><span class="p">(</span><span class="s2">&#34;level counts the kill&#34;</span><span class="p">,</span>   <span class="n">Stats.Get</span><span class="p">(</span><span class="n">Stats.LEVEL</span><span class="p">,</span> <span class="n">Stats.PVE_KILLS</span><span class="p">),</span> <span class="mi">1</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="n">expect</span><span class="p">(</span><span class="s2">&#34;session counts the kill&#34;</span><span class="p">,</span> <span class="n">Stats.Get</span><span class="p">(</span><span class="n">Stats.SESSION</span><span class="p">,</span> <span class="n">Stats.PVE_KILLS</span><span class="p">),</span> <span class="mi">1</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="n">expectNear</span><span class="p">(</span><span class="s2">&#34;session time&#34;</span><span class="p">,</span>        <span class="n">Stats.GetSeconds</span><span class="p">(</span><span class="n">Stats.SESSION</span><span class="p">),</span> <span class="mi">1200</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="n">expect</span><span class="p">(</span><span class="s2">&#34;level XP matches UnitXP&#34;</span><span class="p">,</span> <span class="n">Stats.GetXp</span><span class="p">(</span><span class="n">Stats.LEVEL</span><span class="p">),</span> <span class="mi">600</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">-- /reload: PLAYER_LOGOUT, then login again</span>
</span></span><span class="line"><span class="cl"><span class="n">wow.logout</span><span class="p">()</span>
</span></span><span class="line"><span class="cl"><span class="n">wow.login</span><span class="p">({</span> <span class="n">level</span> <span class="o">=</span> <span class="mi">10</span> <span class="p">})</span>
</span></span><span class="line"><span class="cl"><span class="n">expectTrue</span><span class="p">(</span><span class="s2">&#34;session survives the reload&#34;</span><span class="p">,</span> <span class="n">addon.character</span><span class="p">.</span><span class="n">currentSession</span> <span class="o">~=</span> <span class="kc">nil</span><span class="p">)</span>
</span></span></code></pre></div><p>(The real scenario uses German chat strings, because the addon parses localized combat-log text, and it checks more.) Every helper used here (<code>wow.login</code>, <code>wow.fire</code>, <code>wow.advance</code>, <code>wow.logout</code>, <code>expect</code>) is defined in the stub. After the login, the test looks at <strong>saved state</strong> (<code>addon.character</code>, which is what ends up in the SavedVariables) and at <strong>UI state</strong> (frame text, visibility, anchors), the same two things a player would eventually observe.</p>
<p>The assertion helpers are deliberately tiny:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-lua" data-lang="lua"><span class="line"><span class="cl"><span class="n">TEST_FAILURES</span> <span class="o">=</span> <span class="p">{}</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="kr">function</span> <span class="nf">expect</span><span class="p">(</span><span class="n">description</span><span class="p">,</span> <span class="n">actual</span><span class="p">,</span> <span class="n">expected</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">  <span class="kr">if</span> <span class="n">actual</span> <span class="o">~=</span> <span class="n">expected</span> <span class="kr">then</span>
</span></span><span class="line"><span class="cl">    <span class="n">table.insert</span><span class="p">(</span><span class="n">TEST_FAILURES</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">      <span class="n">string.format</span><span class="p">(</span><span class="s2">&#34;%s: expected %s, got %s&#34;</span><span class="p">,</span> <span class="n">description</span><span class="p">,</span> <span class="n">tostring</span><span class="p">(</span><span class="n">expected</span><span class="p">),</span> <span class="n">tostring</span><span class="p">(</span><span class="n">actual</span><span class="p">)))</span>
</span></span><span class="line"><span class="cl">  <span class="kr">end</span>
</span></span><span class="line"><span class="cl"><span class="kr">end</span>
</span></span></code></pre></div><p>Plain Lua, no framework. <code>expectNear</code> and <code>expectTrue</code> follow the same shape. The failure message carries the description, so a red Go subtest reads like a sentence.</p>
<hr>
<h2 id="lua-51-versus-the-lua-in-wow">Lua 5.1 versus the Lua in WoW</h2>
<p><a href="https://github.com/yuin/gopher-lua" rel="noopener">gopher-lua implements Lua 5.1</a>, and so does the WoW client, which is why I picked it. That makes the <em>language</em> match: <code>unpack</code> as a global (not <code>table.unpack</code>), no integer type, no <code>goto</code>, no <code>//</code> operator. Code that parses on one parses on the other. The <a href="https://www.lua.org/manual/5.1/" rel="noopener">Lua 5.1 reference manual</a> is the common ground.</p>
<p>But &ldquo;same language version&rdquo; does not mean &ldquo;same runtime&rdquo;. The differences that matter in practice:</p>
<ul>
<li><strong>WoW adds globals that stock Lua lacks.</strong> Examples are <code>strsplit</code>, <code>wipe</code>, <code>tinsert</code>, <code>hooksecurefunc</code> and <code>geterrorhandler</code>. If the addon uses one, the stub must define it. If I forget, the test fails loudly with &ldquo;attempt to call a nil value&rdquo;, which is a cheap reminder.</li>
<li><strong>gopher-lua has its own quirks.</strong> Two are documented in the project&rsquo;s <code>CLAUDE.md</code> because they cost me time. First, <code>tonumber(s:match(...))</code> raises an error when <code>match</code> finds nothing, because <code>tonumber()</code> then receives no argument at all; the fix is the extra parentheses in <code>tonumber((s:match(...)))</code>. Second, after a <code>pcall</code> error, number locals of the test&rsquo;s main chunk that closures captured stopped updating, so counters in tests live in tables.</li>
<li><strong>WoW restricts parts of the environment.</strong> The client removes or sandboxes some standard library functions, and newer game APIs can return &ldquo;secret&rdquo; values that addons must not compare or branch on in certain situations. A stock Lua VM allows all of it, and the stub only models what I added to it.</li>
</ul>
<p>The practical rule: if a gopher-lua quirk bites, I fix it in the test or write code that is valid in both runtimes. I never branch the addon&rsquo;s behavior on &ldquo;am I in a test&rdquo;.</p>
<hr>
<h2 id="layout-tests-in-four-languages">Layout tests in four languages</h2>
<p>The layout tests catch more bugs than I expected. Level Time ships in German, English, French and Spanish (<code>deDE</code>, <code>enUS</code>, <code>frFR</code>, <code>esES</code>). French and Spanish strings are noticeably longer, and an options window that fits in English can push a checkbox label into its neighbor in French.</p>










<figure class="diagram">
    <div class="diagram-canvas" role="img" aria-label="The layout test switches the language, builds the real window, reads the recorded anchors and measured text widths from the stub and asserts that nothing overlaps or leaves the window.">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 330" width="720" height="330">
  <defs>
    <marker id="ar-lt2-layout" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
      <path d="M0 0 L10 5 L0 10 z" class="d-arrowhead"/>
    </marker>
  </defs>

  <text x="360" y="24" class="d-t d-bold" font-size="14" text-anchor="middle">for each language</text>
  <rect x="150" y="38" width="90" height="30" rx="15" class="d-pill d-b"/>
  <text x="195" y="58" class="d-t" font-size="12.5" text-anchor="middle">deDE</text>
  <rect x="255" y="38" width="90" height="30" rx="15" class="d-pill d-b"/>
  <text x="300" y="58" class="d-t" font-size="12.5" text-anchor="middle">enUS</text>
  <rect x="375" y="38" width="90" height="30" rx="15" class="d-pill d-b"/>
  <text x="420" y="58" class="d-t" font-size="12.5" text-anchor="middle">frFR</text>
  <rect x="480" y="38" width="90" height="30" rx="15" class="d-pill d-b"/>
  <text x="525" y="58" class="d-t" font-size="12.5" text-anchor="middle">esES</text>
  <line x1="360" y1="72" x2="360" y2="98" class="d-arrow" marker-end="url(#ar-lt2-layout)"/>

  <rect x="16" y="102" width="150" height="76" rx="9" class="d-box d-b"/>
  <text x="91" y="128" class="d-t d-bold" font-size="13" text-anchor="middle">1. Switch language</text>
  <text x="91" y="148" class="d-m" font-size="11.5" text-anchor="middle">addon.Set(</text>
  <text x="91" y="163" class="d-m" font-size="11.5" text-anchor="middle">"language", code)</text>
  <line x1="168" y1="140" x2="196" y2="140" class="d-arrow" marker-end="url(#ar-lt2-layout)"/>

  <rect x="200" y="102" width="150" height="76" rx="9" class="d-box d-b"/>
  <text x="275" y="128" class="d-t d-bold" font-size="13" text-anchor="middle">2. Build the window</text>
  <text x="275" y="148" class="d-m" font-size="11.5" text-anchor="middle">/lt config runs the</text>
  <text x="275" y="163" class="d-m" font-size="11.5" text-anchor="middle">real addon code</text>
  <line x1="352" y1="140" x2="380" y2="140" class="d-arrow" marker-end="url(#ar-lt2-layout)"/>

  <rect x="384" y="102" width="150" height="76" rx="9" class="d-box d-y"/>
  <text x="459" y="128" class="d-t d-bold" font-size="13" text-anchor="middle">3. Read the stub</text>
  <text x="459" y="148" class="d-m" font-size="11.5" text-anchor="middle">anchors in _points,</text>
  <text x="459" y="163" class="d-m" font-size="11.5" text-anchor="middle">GetStringWidth()</text>
  <line x1="536" y1="140" x2="564" y2="140" class="d-arrow" marker-end="url(#ar-lt2-layout)"/>

  <rect x="568" y="102" width="136" height="76" rx="9" class="d-box d-r"/>
  <text x="636" y="128" class="d-t d-bold" font-size="13" text-anchor="middle">4. Assert</text>
  <text x="636" y="148" class="d-m" font-size="11.5" text-anchor="middle">no overlap,</text>
  <text x="636" y="163" class="d-m" font-size="11.5" text-anchor="middle">fits the window</text>

  <rect x="16" y="214" width="688" height="100" rx="10" class="d-box d-y d-dashed"/>
  <text x="360" y="238" class="d-t d-bold" font-size="13" text-anchor="middle">What "width" means in the stub</text>
  <text x="360" y="262" class="d-t" font-size="12.5" text-anchor="middle">GetStringWidth() = string length in bytes x 6</text>
  <text x="360" y="284" class="d-m" font-size="12" text-anchor="middle">Not real font metrics. Longer languages (fr, es) get wider, so overflow</text>
  <text x="360" y="301" class="d-m" font-size="12" text-anchor="middle">regressions show up, but the exact pixels still need a look in game.</text>
</svg>

    </div>
    <figcaption class="diagram-caption">The layout test switches the language, builds the real window, reads the recorded anchors and measured text widths from the stub and asserts that nothing overlaps or leaves the window.</figcaption>
</figure>

<p>Because <code>SetPoint</code> records anchors and <code>SetText</code> stores the string, the stub can answer &ldquo;where is this widget and how wide is its label&rdquo; without a renderer. The scenario <code>tests/layout_fit_test.lua</code> loops over the languages and, for pairs of toggles that share a row, asserts that the right one starts behind the end of the left one and still fits in the window. A shortened version:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-lua" data-lang="lua"><span class="line"><span class="cl"><span class="kd">local</span> <span class="kr">function</span> <span class="nf">checkOptions</span><span class="p">(</span><span class="n">language</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">  <span class="n">addon.Set</span><span class="p">(</span><span class="s2">&#34;language&#34;</span><span class="p">,</span> <span class="n">language</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">  <span class="n">SlashCmdList.LEVELTIMER</span><span class="p">(</span><span class="s2">&#34;config&#34;</span><span class="p">)</span> <span class="c1">-- open the real options window</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="kr">for</span> <span class="n">_</span><span class="p">,</span> <span class="n">pair</span> <span class="kr">in</span> <span class="n">ipairs</span><span class="p">({</span>
</span></span><span class="line"><span class="cl">    <span class="p">{</span> <span class="s2">&#34;SHOW_XP_BAR&#34;</span><span class="p">,</span> <span class="s2">&#34;AUTO_INSTANCE_TAB&#34;</span> <span class="p">},</span>
</span></span><span class="line"><span class="cl">    <span class="p">{</span> <span class="s2">&#34;ALERT_TOGGLE_RARE&#34;</span><span class="p">,</span> <span class="s2">&#34;ALERT_TOGGLE_ELITE&#34;</span> <span class="p">},</span>
</span></span><span class="line"><span class="cl">  <span class="p">})</span> <span class="kr">do</span>
</span></span><span class="line"><span class="cl">    <span class="kd">local</span> <span class="n">left</span><span class="p">,</span> <span class="n">right</span> <span class="o">=</span> <span class="n">findByLabel</span><span class="p">(</span><span class="n">L</span><span class="p">[</span><span class="n">pair</span><span class="p">[</span><span class="mi">1</span><span class="p">]]),</span> <span class="n">findByLabel</span><span class="p">(</span><span class="n">L</span><span class="p">[</span><span class="n">pair</span><span class="p">[</span><span class="mi">2</span><span class="p">]])</span>
</span></span><span class="line"><span class="cl">    <span class="kd">local</span> <span class="n">leftEnd</span> <span class="o">=</span> <span class="n">anchorX</span><span class="p">(</span><span class="n">left</span><span class="p">)</span> <span class="o">+</span> <span class="n">left</span><span class="p">:</span><span class="n">GetWidth</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">      <span class="o">+</span> <span class="n">addon.Widgets</span><span class="p">.</span><span class="n">CHECKBOX_LABEL_GAP</span> <span class="o">+</span> <span class="n">left.label</span><span class="p">:</span><span class="n">GetStringWidth</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">    <span class="n">expectTrue</span><span class="p">(</span><span class="n">language</span> <span class="o">..</span> <span class="s2">&#34;: &#34;</span> <span class="o">..</span> <span class="n">pair</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">..</span> <span class="s2">&#34; starts behind &#34;</span> <span class="o">..</span> <span class="n">pair</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
</span></span><span class="line"><span class="cl">      <span class="n">anchorX</span><span class="p">(</span><span class="n">right</span><span class="p">)</span> <span class="o">&gt;</span> <span class="n">leftEnd</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">    <span class="n">expectTrue</span><span class="p">(</span><span class="n">language</span> <span class="o">..</span> <span class="s2">&#34;: &#34;</span> <span class="o">..</span> <span class="n">pair</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> <span class="o">..</span> <span class="s2">&#34; fits the window&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">      <span class="n">anchorX</span><span class="p">(</span><span class="n">right</span><span class="p">)</span> <span class="o">+</span> <span class="n">right</span><span class="p">:</span><span class="n">GetWidth</span><span class="p">()</span> <span class="o">+</span> <span class="n">right.label</span><span class="p">:</span><span class="n">GetStringWidth</span><span class="p">()</span> <span class="o">&lt;=</span> <span class="n">options</span><span class="p">:</span><span class="n">GetWidth</span><span class="p">())</span>
</span></span><span class="line"><span class="cl">  <span class="kr">end</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">  <span class="n">SlashCmdList.LEVELTIMER</span><span class="p">(</span><span class="s2">&#34;config&#34;</span><span class="p">)</span> <span class="c1">-- close it again</span>
</span></span><span class="line"><span class="cl"><span class="kr">end</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">checkOptions</span><span class="p">(</span><span class="s2">&#34;deDE&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="n">checkOptions</span><span class="p">(</span><span class="s2">&#34;frFR&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="n">checkOptions</span><span class="p">(</span><span class="s2">&#34;esES&#34;</span><span class="p">)</span>
</span></span></code></pre></div><p>The same file covers the history window (sub-tabs must wrap into extra rows instead of leaving the content area, checked in all four languages), button widths against their text, and table toolbars. A second scenario does the same for the Level Time Goals window. A third, <code>tests/locales_test.lua</code>, checks that every language has every key and that the <code>%s</code> and <code>%d</code> placeholders match the English string, which prevents a whole class of runtime format errors.</p>
<h3 id="how-text-width-is-measured-honestly">How text width is measured, honestly</h3>
<p>This is not pixel-accurate layout testing, because the stub does not know any font. Its text measurement is:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-lua" data-lang="lua"><span class="line"><span class="cl"><span class="n">GetStringWidth</span> <span class="o">=</span> <span class="kr">function</span><span class="p">(</span><span class="n">self</span><span class="p">)</span> <span class="kr">return</span> <span class="o">#</span><span class="n">self._text</span> <span class="o">*</span> <span class="mi">6</span> <span class="kr">end</span><span class="p">,</span>
</span></span></code></pre></div><p>Width equals the string length in <strong>bytes</strong> times 6. That is a crude approximation: a real font has proportional glyphs (an &ldquo;i&rdquo; is narrower than an &ldquo;m&rdquo;), the font and size are configurable in Level Time, and UTF-8 umlauts count as two bytes here although they render as one glyph.</p>
<p>It still catches real bugs because the <em>relative</em> behavior is right. French and Spanish strings are longer, so they get wider in the stub too, and a layout that hard-codes a width for the English text fails the test. The addon&rsquo;s own layout code helps: the widths of the options columns are computed from the measured label widths (<code>fitWidth</code>) instead of being fixed, so the test verifies that the <em>rule</em> holds for every language. It does not prove that the result looks good with the real font.</p>
<p>What it can never tell me is &ldquo;this text is clipped by two pixels in French with the default font&rdquo;. That still takes a look in the game.</p>
<hr>
<h2 id="the-performance-profiler-and-how-it-is-tested">The performance profiler (and how it is tested)</h2>
<p>Level Time has an in-game profiler, <code>/lt debug perf</code>. It is part of the addon (<code>Core/Profiler.lua</code>), not of the Go tooling, and the harness tests it like any other module. I mention it because it shows a nice property of the stub approach: even tooling that depends on client functions can be tested.</p>
<p>What it measures:</p>
<ul>
<li>the time of every <strong>event handler</strong>, every <code>ns.Every</code> background task, every callback dispatched through <code>ns.SafeCall</code> (counters, XP and journal listeners, login, settings apply) and the <code>OnUpdate</code> scripts of the windows;</li>
<li>per entry the <strong>sum and maximum in milliseconds</strong>, the number of calls and the memory growth, using <code>debugprofilestop()</code> and <code>collectgarbage(&quot;count&quot;)</code>.</li>
</ul>
<p>How it works: while the profiler is off, nothing is wrapped, so it costs nothing. When you switch it on, the core swaps the dispatchers for measuring versions, and <code>/lt debug perf report 10</code> prints the top entries to chat. The stub makes this testable by defining <code>debugprofilestop</code> in terms of the fake clock plus a number the test controls (<code>wow.profileMs</code>). The scenario registers a handler that &ldquo;takes&rdquo; 5 ms:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-lua" data-lang="lua"><span class="line"><span class="cl"><span class="n">addon.RegisterEvent</span><span class="p">(</span><span class="s2">&#34;PLAYER_REGEN_ENABLED&#34;</span><span class="p">,</span> <span class="kr">function</span><span class="p">()</span>
</span></span><span class="line"><span class="cl">  <span class="n">wow.profileMs</span> <span class="o">=</span> <span class="n">wow.profileMs</span> <span class="o">+</span> <span class="mi">5</span> <span class="c1">-- pretend this handler is slow</span>
</span></span><span class="line"><span class="cl"><span class="kr">end</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">SlashCmdList.LEVELTIMER</span><span class="p">(</span><span class="s2">&#34;debug perf on&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="n">wow.fire</span><span class="p">(</span><span class="s2">&#34;PLAYER_REGEN_ENABLED&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="n">wow.fire</span><span class="p">(</span><span class="s2">&#34;PLAYER_REGEN_ENABLED&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1">-- ...look up the entry for this handler in addon.Profiler.Results()...</span>
</span></span><span class="line"><span class="cl"><span class="n">expect</span><span class="p">(</span><span class="s2">&#34;two calls&#34;</span><span class="p">,</span> <span class="n">found.count</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="n">expectNear</span><span class="p">(</span><span class="s2">&#34;sum&#34;</span><span class="p">,</span> <span class="n">found.ms</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="n">expectNear</span><span class="p">(</span><span class="s2">&#34;maximum&#34;</span><span class="p">,</span> <span class="n">found.max</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="n">SlashCmdList.LEVELTIMER</span><span class="p">(</span><span class="s2">&#34;debug perf off&#34;</span><span class="p">)</span>
</span></span><span class="line"><span class="cl"><span class="n">expect</span><span class="p">(</span><span class="s2">&#34;dispatcher restored&#34;</span><span class="p">,</span> <span class="n">addon.SafeCall</span><span class="p">,</span> <span class="n">plainSafeCall</span><span class="p">)</span>
</span></span></code></pre></div><p>Note what this test proves: the accounting is right (sums, maxima, call counts) and switching off restores the original functions. It does <strong>not</strong> measure how fast the addon is. The Go harness runs on a developer machine or a CI runner, not inside the game client, so timings from it would mean nothing. Real numbers come from playing with the profiler switched on, which is also how I find hot spots.</p>
<hr>
<h2 id="running-the-tests-in-ci">Running the tests in CI</h2>
<p>The workflow is <code>.github/workflows/test.yml</code>, and it is short:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l">Test</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">on</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">pull_request</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">push</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">branches</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span>- <span class="l">main</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">jobs</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">test</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">runs-on</span><span class="p">:</span><span class="w"> </span><span class="l">ubuntu-latest</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">steps</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span>- <span class="nt">uses</span><span class="p">:</span><span class="w"> </span><span class="l">actions/checkout@v7</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span>- <span class="nt">uses</span><span class="p">:</span><span class="w"> </span><span class="l">actions/setup-go@v7</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nt">with</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">          </span><span class="nt">go-version</span><span class="p">:</span><span class="w"> </span><span class="s2">&#34;1.27&#34;</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">          </span><span class="nt">cache-dependency-path</span><span class="p">:</span><span class="w"> </span><span class="l">tools/*/go.sum</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span>- <span class="nt">run</span><span class="p">:</span><span class="w"> </span><span class="l">make vet</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span>- <span class="nt">run</span><span class="p">:</span><span class="w"> </span><span class="l">make test</span><span class="w">
</span></span></span></code></pre></div><p>It runs on every pull request and every push to <code>main</code>. <code>make vet</code> runs <code>go vet</code> on all Go tools, and <code>make test</code> runs the addon scenarios plus the tests of the other tools (installer, artwork, speedrun records, flights). Since gopher-lua is pure Go, there is nothing to install besides Go itself. In <a href="/blog/level-time-3-release-pipeline/">Part 3</a> the release workflow runs the tests before anything gets packaged.</p>
<hr>
<h2 id="run-it-yourself">Run it yourself</h2>
<p>You need a supported Go release (1.26 or newer). Installation instructions are on <a href="https://go.dev/doc/install" rel="noopener">go.dev/doc/install</a>. Then clone the repository and run the tests.</p>
<div class="os-tabs">
<div class="os-tab" data-label="Linux">
<p class="os-tab-label">Linux</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">git clone https://github.com/Noobygames/wow-statistics.git
</span></span><span class="line"><span class="cl"><span class="nb">cd</span> wow-statistics
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># all addon scenarios (-count=1 disables Go&#39;s test cache, see below)</span>
</span></span><span class="line"><span class="cl">go -C tools/addontest <span class="nb">test</span> -count<span class="o">=</span><span class="m">1</span> ./...
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># only one scenario</span>
</span></span><span class="line"><span class="cl">go -C tools/addontest <span class="nb">test</span> -count<span class="o">=</span><span class="m">1</span> -run <span class="s1">&#39;TestScenarios/session&#39;</span> ./...
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c1"># everything CI runs (needs make)</span>
</span></span><span class="line"><span class="cl">make vet <span class="o">&amp;&amp;</span> make <span class="nb">test</span>
</span></span></code></pre></div>
</div>

<div class="os-tab" data-label="Windows (PowerShell)">
<p class="os-tab-label">Windows (PowerShell)</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-powershell" data-lang="powershell"><span class="line"><span class="cl"><span class="n">git</span> <span class="n">clone</span> <span class="n">https</span><span class="err">:</span><span class="p">//</span><span class="n">github</span><span class="p">.</span><span class="n">com</span><span class="p">/</span><span class="n">Noobygames</span><span class="p">/</span><span class="nb">wow-statistics</span><span class="p">.</span><span class="py">git</span>
</span></span><span class="line"><span class="cl"><span class="nb">Set-Location</span> <span class="nb">wow-statistics</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c"># all addon scenarios</span>
</span></span><span class="line"><span class="cl"><span class="n">go</span> <span class="n">-C</span> <span class="n">tools</span><span class="p">/</span><span class="n">addontest</span> <span class="n">test</span> <span class="n">-count</span><span class="p">=</span><span class="mf">1</span> <span class="p">./...</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="c"># only one scenario</span>
</span></span><span class="line"><span class="cl"><span class="n">go</span> <span class="n">-C</span> <span class="n">tools</span><span class="p">/</span><span class="n">addontest</span> <span class="n">test</span> <span class="n">-count</span><span class="p">=</span><span class="mf">1</span> <span class="n">-run</span> <span class="s1">&#39;TestScenarios/session&#39;</span> <span class="p">./...</span>
</span></span></code></pre></div>
</div>

</div>

<p><code>make</code> is usually not installed on Windows. The <code>go -C</code> commands above are what the Makefile target <code>test-addon</code> calls. The <code>-C</code> flag (change directory before running) needs Go 1.20 or later.</p>
<p><strong>Always pass <code>-count=1</code>.</strong> Go&rsquo;s test cache knows nothing about the Lua files that gopher-lua loads. Without <code>-count=1</code> you can edit an addon file, rerun, and get a stale cached result. It is a documented rule in the repository for exactly that reason.</p>
<p>Adding a feature then means adding or extending a scenario in <code>tests/</code>. A new API function means adding it to the matching <code>tests/stub/*.lua</code> file.</p>
<hr>
<h2 id="honest-limits-what-the-stub-cannot-catch">Honest limits: what the stub cannot catch</h2>
<p>A green suite means the logic does what the scenarios say. It does not mean the addon works in the game. Concretely, the harness cannot tell me:</p>
<ul>
<li><strong>That an API exists in a given client.</strong> The stub defines <code>C_Spell.GetSpellName</code> because I told it to. If the real client of some flavor does not have it, has a different signature, or returns a &ldquo;secret&rdquo; value, the test stays green and the player gets a Lua error. I mitigate this by checking the Blizzard UI source per flavor and by writing nil-safe code, but the stub itself cannot know. The <a href="https://warcraft.wiki.gg/wiki/World_of_Warcraft_API" rel="noopener">WoW API pages on warcraft.wiki.gg</a> are my reference for what exists where.</li>
<li><strong>Real rendering.</strong> Textures, fonts, scaling, strata (which frame is on top), animations and sounds are not simulated. Animations only keep a &ldquo;playing&rdquo; flag.</li>
<li><strong>Timing and ordering of real events.</strong> The stub fires events when a test says so. The real client may fire them in another order, at another time, or in bursts. Event races are my biggest blind spot.</li>
<li><strong>Protected frames and combat lockdown, beyond what is explicitly modeled.</strong> The stub throws on <code>SetAttribute</code> while its combat-lockdown flag is set, but it does not emulate Blizzard&rsquo;s full secure-frame rules.</li>
<li><strong>Performance.</strong> See above: it proves the accounting, not the speed.</li>
<li><strong>My own wrong assumptions.</strong> If I misunderstand what an event delivers, I will write the same misunderstanding into both the addon and the stub, and the test will agree with the bug.</li>
</ul>
<p>Wrong assumptions are the main cost of any hand-written fake. The countermeasure is a manual checklist in the repository (<code>ManualToCheck.md</code>) of things that still need to be tried in the game, plus the discipline to treat &ldquo;tested in the stub&rdquo; and &ldquo;verified in the game&rdquo; as two different statuses.</p>
<hr>
<h2 id="key-takeaways">Key takeaways</h2>
<ul>
<li>A pure-Go Lua VM turns an addon into something <code>go test</code> can run, with no game and no Lua installation.</li>
<li>A fresh VM per scenario plus Go subtests gives isolation and a one-command filter.</li>
<li>A stub with no-op defaults keeps the cost of faking an API low: only fake what a test needs to observe.</li>
<li>Control time (<code>wow.advance</code>, <code>wow.runTimers</code>) and events (<code>wow.fire</code>) explicitly; nothing should sleep.</li>
<li>Record layout inputs (anchors, text, sizes) and test the <em>rules</em> in every language, rather than chasing pixels.</li>
<li>Know your blind spots and keep a manual in-game checklist.</li>
</ul>
<hr>
<h2 id="whats-next">What&rsquo;s next</h2>
<p>In <a href="/blog/level-time-3-release-pipeline/">Part 3</a> I show how a tag turns into a release on GitHub, CurseForge, Wago and WoWInterface with the <a href="https://github.com/BigWigsMods/packager" rel="noopener">BigWigs packager</a>, and how the tests gate it. If you play Classic and want to see what all this code is for, the <a href="/page/level-time/">Level Time page</a> has screenshots and the download link. The tooling mindset also connects to my posts on <a href="/blog/go-docker/">Go in Docker</a> and <a href="/blog/check-static-linking/">checking static linking</a>.</p>
]]></content:encoded></item></channel></rss>