Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions .github/workflows/buildtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: Compare build corpus
run-name: Corpus comparison (${{ inputs.candidate_ref || github.sha }})
on:
push:
branches: ['release-[0-9]*']
workflow_dispatch:
inputs:
base_ref:
description: Baseline commit or branch (defaults to the latest stable PoB release)
type: string
candidate_ref:
description: Candidate commit or branch (defaults to the selected workflow revision)
type: string
expected_digest:
description: Optional SHA-256 of the exact corpus response
type: string
strict:
description: Fail when a stat changes value or is added or removed
default: false
type: boolean
override_verdict:
description: Pass blocking comparison findings after maintainer review
default: false
type: boolean

permissions:
contents: read

jobs:
compare:
name: Compare build corpus
if: ${{ !github.event.deleted }}
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Check out comparison tools and fixtures
uses: actions/checkout@v4
with:
path: harness
persist-credentials: false
sparse-checkout: |
spec/corpus
spec/TestBuilds
runtime/lua
- name: Find latest stable PoB release
id: stable
if: ${{ !inputs.base_ref }}
env:
GH_TOKEN: ${{ github.token }}
run: |
tag=$(gh api repos/PathOfBuildingCommunity/PathOfBuilding/releases/latest --jq .tag_name)
test -n "$tag"
echo "ref=refs/tags/$tag" >> "$GITHUB_OUTPUT"
echo "STABLE_TAG=$tag" >> "$GITHUB_ENV"
- name: Test comparison tools
run: |
python3 -m unittest discover -s harness/spec/corpus -p 'test_*.py'
sh harness/spec/corpus/test_verdict.sh
- name: Check out baseline
uses: actions/checkout@v4
with:
path: base
repository: ${{ inputs.base_ref && github.repository || 'PathOfBuildingCommunity/PathOfBuilding' }}
ref: ${{ inputs.base_ref || steps.stable.outputs.ref }}
persist-credentials: false
- name: Check out candidate
uses: actions/checkout@v4
with:
path: candidate
ref: ${{ inputs.candidate_ref || github.sha }}
persist-credentials: false
- name: Pin corpus and comparison inputs
id: inputs
env:
EXPECTED: ${{ inputs.expected_digest }}
run: |
mkdir -p "$RUNNER_TEMP/corpus-results" "$RUNNER_TEMP/corpus-base"
curl --fail --silent --show-error --retry 3 --retry-delay 2 --retry-all-errors \
--max-time 60 --max-filesize 16777216 \
https://api.pob.codes/test-builds/corpus -o "$RUNNER_TEMP/corpus.json"
digest=$(sha256sum "$RUNNER_TEMP/corpus.json" | cut -d ' ' -f 1)
if [[ -n "$EXPECTED" && "$EXPECTED" != "$digest" ]]; then echo "Corpus digest changed"; exit 1; fi
base=$(git -C base rev-parse HEAD)
candidate=$(git -C candidate rev-parse HEAD)
tools=$(git -C harness rev-parse HEAD:spec/corpus HEAD:spec/TestBuilds HEAD:runtime/lua | sha256sum | cut -d ' ' -f 1)
echo "key=corpus-v1-$base-$digest-$tools" >> "$GITHUB_OUTPUT"
echo "BASE_SHA=$base" >> "$GITHUB_ENV"
echo "CANDIDATE_SHA=$candidate" >> "$GITHUB_ENV"
- name: Restore calculated baseline
id: cache
uses: actions/cache/restore@v4
with:
key: ${{ steps.inputs.outputs.key }}
path: ${{ runner.temp }}/corpus-base
- name: Compare both revisions
env:
STRICT: ${{ inputs.strict }}
OVERRIDE_VERDICT: ${{ inputs.override_verdict }}
run: |
docker build -t pob-corpus harness/spec/corpus
docker run --rm --network none --user "$(id -u):$(id -g)" \
-v "$PWD/harness:/harness:ro" -v "$PWD/base:/base:ro" -v "$PWD/candidate:/candidate:ro" \
-v "$RUNNER_TEMP/corpus.json:/corpus.json:ro" -v "$RUNNER_TEMP/corpus-results:/results" \
-v "$RUNNER_TEMP/corpus-base:/baseline" -e BASE_SHA -e CANDIDATE_SHA -e STRICT -e OVERRIDE_VERDICT \
pob-corpus sh /harness/spec/corpus/run.sh
- name: Check baseline completeness
id: completed
if: ${{ !cancelled() && steps.cache.outcome == 'success' && steps.cache.outputs.cache-hit != 'true' }}
run: |
if test -f "$RUNNER_TEMP/corpus-base/complete"; then echo "save=true" >> "$GITHUB_OUTPUT"; fi
- uses: actions/cache/save@v4
if: ${{ !cancelled() && steps.completed.outputs.save == 'true' }}
with:
key: ${{ steps.inputs.outputs.key }}
path: ${{ runner.temp }}/corpus-base
- name: Write the build comparison report
if: ${{ !cancelled() }}
env:
STRICT: ${{ inputs.strict }}
OVERRIDE_VERDICT: ${{ inputs.override_verdict }}
BASE_REPO: ${{ inputs.base_ref && github.repository || 'PathOfBuildingCommunity/PathOfBuilding' }}
BASELINE_CACHE_HIT: ${{ steps.cache.outputs.cache-hit }}
run: |
python3 harness/spec/corpus/report.py "$RUNNER_TEMP/corpus-results" "$RUNNER_TEMP/corpus.json" \
harness "$GITHUB_REPOSITORY" "$(git -C harness rev-parse HEAD)"
- uses: actions/upload-artifact@v4
id: report
if: ${{ !cancelled() }}
with:
name: build-diff-output
path: ${{ runner.temp }}/corpus-results/report/
- name: Show the result
if: ${{ !cancelled() }}
env:
REPORT_URL: ${{ steps.report.outputs.artifact-url }}
run: |
if test -s "$RUNNER_TEMP/corpus-results/actions-summary.md"; then
cat "$RUNNER_TEMP/corpus-results/actions-summary.md" >> "$GITHUB_STEP_SUMMARY"
else
echo '# Failed - Report unavailable' >> "$GITHUB_STEP_SUMMARY"
echo 'Open the first failed step in the Actions log for the error.' >> "$GITHUB_STEP_SUMMARY"
fi
if test -n "$REPORT_URL"; then
printf '\n[Download the full report and build list](%s)\n' "$REPORT_URL" >> "$GITHUB_STEP_SUMMARY"
fi
printf '\n[How the PoB Codes test corpus is selected and maintained](https://pob.codes/content/test-corpus/)\n' >> "$GITHUB_STEP_SUMMARY"
24 changes: 22 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ on:
jobs:
release:
runs-on: ubuntu-latest
outputs:
release_pr: ${{ steps.prepare.outputs.pull-request-number }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: 'dev'
- name: Generate Release notes
Expand All @@ -35,7 +37,8 @@ jobs:
chmod +x .github/tweak_changelogs.sh
.github/tweak_changelogs.sh "v${{ github.event.inputs.releaseVersion }}"
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
id: prepare
uses: peter-evans/create-pull-request@v7
with:
draft: true
title: Release ${{ github.event.inputs.releaseVersion }}
Expand All @@ -44,4 +47,21 @@ jobs:
Draft release of ${{ github.event.inputs.releaseVersion }}.

Edits will be made as necessary to prepare the codebase for release.

See the Checks tab for the build corpus comparison against the latest stable release.
See [how the PoB Codes test corpus is selected and maintained](https://pob.codes/content/test-corpus/).
commit-message: 'Prepare release ${{ github.event.inputs.releaseVersion }}'
start-corpus-check:
needs: release
if: ${{ needs.release.outputs.release_pr }}
runs-on: ubuntu-latest
permissions:
actions: write
steps:
# A branch push made by the release job's GITHUB_TOKEN does not start push workflows.
- name: Start comparison on the prepared release branch
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
RELEASE_BRANCH: release-${{ inputs.releaseVersion }}
run: gh workflow run buildtest.yml --repo "$GH_REPO" --ref "$RELEASE_BRANCH"
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ It is a good idea to prefer Docker due to it having a very reliable Lua setup. B
3. Run `luarocks install busted`
4. Run `busted --lua=luajit` to run the tests. You can also use e.g. `-p TestUtils_spec.lua` to run a specific file.

Release candidates automatically run the [build corpus comparison](spec/corpus/README.md). You can also run it manually to compare two PoB revisions on the same public builds.

### Debugging tests
When running tests with a docker container it is possible to use EmmyLua for debugging. Paste in the following right under `function launch:OnInit()` in `./src/Launch.lua`:
```lua
Expand Down
17 changes: 17 additions & 0 deletions spec/corpus/BuildStats.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Preserve PoB's saved display stats and append scalar calculation results.
-- Nested tables include live actor, item and skill objects with cycles.
return function(xml, output, element)
local saved, extra = {}, {}
for _, child in ipairs(xml) do
if child.elem == element then saved[child.attrib.stat] = true end
end
for key, value in pairs(output) do
if type(key) == "string" and not saved[key] and (type(value) == "number" or type(value) == "boolean") then
extra[#extra + 1] = key
end
end
table.sort(extra)
for _, key in ipairs(extra) do
xml[#xml + 1] = { elem = element, attrib = { stat = key, value = tostring(output[key]) } }
end
end
53 changes: 53 additions & 0 deletions spec/corpus/Calculate.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
local batch, cursorPath, outDir = assert(arg[1]), assert(arg[2]), assert(arg[3])
local startAt = assert(tonumber(arg[4]))
local zlib = require("zlib")
local appendStats = dofile("/harness/spec/corpus/BuildStats.lua")
dofile("HeadlessWrapper.lua")
assert(build and not launch.promptMsg, launch.promptMsg or "PoB failed to start")

-- SimpleGraphic supplies these functions in the desktop application. The
-- headless definitions are stubs, including the inflater used by Timeless jewels.
function Inflate(data)
return (zlib.inflate(47)(data))
end
function Deflate(data)
return (zlib.deflate()(data, "finish"))
end

local save = build.Save
function build:Save(xml)
save(self, xml)
local output = self.calcsTab.mainOutput
appendStats(xml, output, "PlayerStat")
if output.Minion then appendStats(xml, output.Minion, "MinionStat") end
end

local function write(path, value)
local file = assert(io.open(path, "wb"))
assert(file:write(value))
assert(file:close())
end

local index = 0
for name in io.lines(batch) do
index = index + 1
if index >= startAt then
write(cursorPath, tostring(index))
write(cursorPath .. ".stage", "loading")
local file = assert(io.open("/results/inputs/" .. name .. ".xml", "rb"))
local xml = file:read("*a")
file:close()
io.stderr:write("Loading ", name, "\n")
local start = os.clock()
local document, err = common.xml.ParseXML(xml)
assert(document and not err and document[1].elem == "PathOfBuilding", "Invalid PoB XML")
loadBuildFromXML(xml, name)
assert(not launch.promptMsg, launch.promptMsg)
assert(not build.abortSave and type(build.calcsTab.mainOutput.Life) == "number", "No calculated player output")
local elapsed = os.clock() - start
write(cursorPath .. ".stage", "saving")
io.stderr:write("Saving ", name, "\n")
write(outDir .. "/" .. name .. ".build", assert(build:SaveDB("Cache")))
write(outDir .. "/" .. name .. ".time", tostring(elapsed * 1000))
end
end
49 changes: 49 additions & 0 deletions spec/corpus/DiffOutput.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
-- https://stackoverflow.com/questions/19326368/iterate-over-lines-including-blank-lines
local function splitLines(s)
if s:sub(-1)~="\n" then s=s.."\n" end
return s:gmatch("(.-)\n")
end

local function buildOutputMap(filecontent)
local playerOutput = {}
local minionOutput = {}
for line in splitLines(filecontent) do
local stat = line:match('<PlayerStat%s+([^>]+)')
local key, val = stat and stat:match('stat="(.-)"'), stat and stat:match('value="(.-)"')
if key then
playerOutput[key] = val
else
local stat = line:match('<MinionStat%s+([^>]+)')
local key, val = stat and stat:match('stat="(.-)"'), stat and stat:match('value="(.-)"')
if key then
minionOutput[key] = val
end
end
end
return playerOutput, minionOutput
end

local function readBuild(path)
local file = assert(io.open(path, "r"))
local player, minion = buildOutputMap(file:read("*a"))
file:close()
return player, minion
end

local function compare(actor, before, after)
local function record(key)
assert(not key:find("[%c]"), "Invalid stat name")
print(table.concat({ arg[3], actor, key, before[key] or "", after[key] or "" }, "\t"))
end
for key, value in pairs(before) do
if after[key] ~= value then record(key) end
end
for key in pairs(after) do
if before[key] == nil then record(key) end
end
end

local playerAfter, minionAfter = readBuild(arg[1])
local playerBefore, minionBefore = readBuild(arg[2])
compare("Player", playerBefore, playerAfter)
compare("Minion", minionBefore, minionAfter)
3 changes: 3 additions & 0 deletions spec/corpus/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM ghcr.io/pathofbuildingcommunity/pathofbuilding-tests@sha256:171dc3da232b8c874882e4ae3b3aa4a6e130a6c9450a31904b312435a6bf5daf
RUN apk add --no-cache git libxml2-utils zlib-dev && luarocks install lua-zlib 1.4-0
ENV HOME=/tmp
42 changes: 42 additions & 0 deletions spec/corpus/FetchTestBuilds.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
local json = require("dkjson")
local base64 = require("base64")
local sha256 = require("sha2").sha256
local zlib = require("zlib")
local corpusFile, inputs = assert(arg[1]), assert(arg[2])

local input = assert(io.open(corpusFile, "rb"))
assert(input:seek("end") <= 16 * 1024 * 1024, "Oversized corpus")
input:seek("set")
local corpus, _, err = json.decode(input:read("*a"))
input:close()
assert(corpus and not err and corpus.schemaVersion == 2 and type(corpus.snapshotId) == "string", "Invalid corpus")
assert(corpus.count == #corpus.builds and corpus.count > 0 and corpus.count <= 750, "Invalid corpus count")

local function write(path, content)
local file = assert(io.open(path, "wb"))
assert(file:write(content))
assert(file:close())
end

local seen = {}
for _, entry in ipairs(corpus.builds) do
local code, hash = entry.code, entry.sha256
assert(#code <= 150 * 1024 and code:match("^[%w_+/=%-]+$"), "Invalid encoded build")
assert(sha256(code) == hash and not seen[hash], "Incorrect or duplicate build SHA-256")
seen[hash] = true
local compressed = base64.decode(code:gsub("-", "+"):gsub("_", "/"))
local inflate, chunks, size, eof = zlib.inflate(), {}, 0, false
for offset = 1, #compressed, 1024 do
assert(not eof, "Trailing compressed input")
local chunk, finished, consumed = inflate(compressed:sub(offset, offset + 1023))
size = size + #chunk
assert(size <= 4 * 1024 * 1024 and (not finished or consumed == #compressed), "Invalid inflated build")
chunks[#chunks + 1], eof = chunk, finished
end
assert(eof and size > 0, "Incomplete compressed build")
write(inputs .. "/" .. hash .. ".xml", table.concat(chunks))
local tags = entry.criteria or {}
for _, tag in ipairs(tags) do assert(tag:match("^[a-z0-9%-]+$"), "Invalid criterion") end
write(inputs .. "/" .. hash .. ".tags", table.concat(tags, ", "))
end
print(string.format("Corpus %s: %d verified API builds", corpus.snapshotId, corpus.count))
Loading
Loading