Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
d0467d2
FEAT: impl new tests container
Paliak Dec 20, 2023
bc1de3f
FEAT: initial implementaion of test build logic
Paliak Dec 25, 2023
ad84c6a
DOCS: add some documentation on how to use emmy lua with docker
Paliak Dec 25, 2023
97529ce
DOCS: update line about modcache
Paliak Dec 25, 2023
7b3d334
FIX: docker compose build-diff script
Paliak Dec 25, 2023
b0a455a
FIX: simplify test.yml
Paliak Dec 25, 2023
2c334d2
FIX: make sure directory is root before takign hash of dev
Paliak Dec 25, 2023
60dca6e
FIX: use dedicated cache folder in spec
Paliak Dec 25, 2023
a75b2a1
FIX: use non conical sparse checkout due to a non directory path
Paliak Dec 25, 2023
0875d6e
FIX: path issue when generating dev builds
Paliak Dec 25, 2023
9d581fc
FIX: remove outdate cache when using docker compose
Paliak Dec 25, 2023
3ea5a77
TEST: test tests
Paliak Dec 25, 2023
8883655
Revert "TEST: test tests"
Paliak Dec 25, 2023
3304edd
FIX: issues with docker-compose
Paliak Dec 25, 2023
9f7e0e8
FIX: typo in docker-compose
Paliak Dec 26, 2023
f48955b
FIX: pull out path generation into a variable
Paliak Dec 26, 2023
0bccf5d
FIX: make the build cache back into valid lua file
Paliak Dec 28, 2023
bfc3887
FIX: github actions uses sh -e which uses the diff exit code.
Paliak Dec 29, 2023
412dc18
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Dec 31, 2023
1151597
FIX: manually trigger gc to stave off out of memory crash. Misc fixes.
Paliak Jan 1, 2024
4640e81
FIX: remove outdated comment
Paliak Jan 1, 2024
e49be40
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Jan 4, 2024
d472b1e
FEAT: add needed pkgs to Dockerfile
Paliak Jan 5, 2024
203f9b8
FIX: minor hardening of test runner containers
Paliak Jan 5, 2024
1ff1d08
FEAT: more verbose diff. Fixes to timeless data. Impl import from link.
Paliak Jan 5, 2024
933ee46
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Jan 5, 2024
b11a199
Merge branch 'dev' of https://github.com/Paliak/PathOfBuilding into dev
Paliak Jan 5, 2024
c60cd20
FIX: update the test.yml action
Paliak Jan 5, 2024
51f09ac
FIX: more info for mismatch count
Paliak Jan 5, 2024
9328c99
FEAT: add more builds
Paliak Jan 5, 2024
ecc4d61
FIX: luadiff script
Paliak Jan 5, 2024
5434b3c
FIX: specify origin for dev ref
Paliak Jan 5, 2024
6b86ef6
FIX: fetch a commit from every branch
Paliak Jan 5, 2024
e6f44c5
FIX: unknown ref git error
Paliak Jan 5, 2024
b2a9f55
FIX: minor security/convenience improvements
Paliak Jan 6, 2024
529336a
FEAT: cache downloaded builds
Paliak Jan 6, 2024
6e0829f
FIX: cache folder permissions on github action
Paliak Jan 6, 2024
18623c5
FIX: temp batch files getting clobbered
Paliak Jan 6, 2024
4190be8
FIX: cache folder permissions again
Paliak Jan 6, 2024
61b3d10
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Jan 9, 2024
cdb3143
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Jan 15, 2024
ea6d72f
FIX: apply suggestions. Docs wording. Use repo owner in docker label.
Paliak Jan 15, 2024
5380e0c
FIX: line ending issue on windows
Paliak Jan 18, 2024
a26750d
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Jan 21, 2024
516df64
FIX: rename magiclines func.
Paliak Jan 21, 2024
ddf1033
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Jan 21, 2024
16c7976
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Jan 23, 2024
13c7522
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Jan 24, 2024
a5b0eae
FIX: GetTime func scale
Paliak Jan 29, 2024
88fab37
FEAT: impl save options. Allows for saving full output to xml.
Paliak Jan 29, 2024
5848348
FIX: docker compose exit code propagation
Paliak Jan 29, 2024
2df962b
FIX: nil deref when save options are not specified.
Paliak Jan 29, 2024
3faf02e
FEAT: impl build download throttling.
Paliak Jan 29, 2024
b62d55a
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Feb 2, 2024
a15d7e7
FIX: attempt to fix exit-code-from switch missing on gh.
Paliak Feb 2, 2024
d16e0ed
Merge branch 'dev' of https://github.com/Paliak/PathOfBuilding into dev
Paliak Feb 2, 2024
86656df
FIX: name comflicts in DFS stat traversal.
Paliak Feb 11, 2024
b424234
FIX: format xml into canonical form before diff.
Paliak Feb 11, 2024
14e9317
FIX: only print the header if there's a diff to display.
Paliak Feb 11, 2024
dba3a8f
FEAT: upload the diff output as an artefact in gha.
Paliak Feb 11, 2024
4c9b6fb
FIX: tests failing
Paliak Feb 11, 2024
cb8f0ec
FEAT: wrap diff output in markdown block.
Paliak Feb 11, 2024
04d1996
FEAT: rework buildDiff.sh
Paliak Feb 11, 2024
2701fdd
FIX: fill output not being included in xml for test output.
Paliak Feb 12, 2024
213ee29
FIX: different approach of avoiding creation of an emppty artefact.
Paliak Feb 12, 2024
c27c0b7
FIX: artefact creation. Log artefact contents.
Paliak Feb 12, 2024
c04c3c0
FIX: another attampt at fixing artefact generation
Paliak Feb 13, 2024
33ca340
FIX: sort player and minion stats to prevent stats from moving arounud
Paliak Feb 15, 2024
325b1ff
FIX: nil compare
Paliak Feb 15, 2024
57f4c51
FIX: allow empty git patch
Paliak Feb 16, 2024
3dec1b2
FIX: download cache not working. GenerateBuild.lua formatting.
Paliak Feb 16, 2024
ef37476
FIX: use the same version of luajit as new SG.
Paliak Feb 23, 2024
84de79b
FIX: remove batching.
Paliak Feb 23, 2024
5fd5da7
FIX: exit code not propagating up the call chain
Paliak Feb 23, 2024
cd9640d
Revert "FIX: use the same version of luajit as new SG."
Paliak Feb 23, 2024
b80b4c5
Revert "FIX: remove batching."
Paliak Feb 23, 2024
7842581
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Mar 1, 2024
c78ad3b
FEAT: add output only diff.
Paliak Mar 1, 2024
b049b8d
FIX: rename folder as it actually contains headref
Paliak Mar 2, 2024
a5a7df8
FIX: stricter download limits
Paliak Mar 4, 2024
197f897
FIX: curl user agent
Paliak Mar 4, 2024
8394e2f
FIX: staged changes to tests code not applying to devref.
Paliak Mar 8, 2024
6d55153
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Mar 25, 2024
82248ec
FEAT: tweaks to existing workflows
Paliak Mar 25, 2024
469115d
FEAT: add automatic test build list update
Paliak Mar 25, 2024
ed84520
FIX: yaml formatting
Paliak Mar 26, 2024
7d1fa2a
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Apr 8, 2024
11015db
Merge remote-tracking branch 'POB/dev' into dev
Paliak Jun 28, 2024
4e94dfa
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Jun 28, 2024
c040cb8
FIX: flipped arguments dev<-->head
Paliak Jun 28, 2024
d8422a8
FIX: specify latest version in the compose file
Paliak Jun 28, 2024
6ceb81f
Merge branch 'dev' of https://github.com/Paliak/PathOfBuilding into dev
Paliak Jun 28, 2024
6f4d79b
WIP: testing builds.txt update logic
Paliak Jun 28, 2024
0ca6d01
FIX: Export newly generated build list an an artefact. Use 3rd party …
Paliak Jun 29, 2024
79d00f0
FEAT: implement build xml caching independent from dev ref cache.
Paliak Jun 29, 2024
f493e49
FIX: yaml formatting. remove unnecessary repo name check.
Paliak Jun 29, 2024
029c980
WIP: initial work on artitrary branch diffing
Paliak Jun 30, 2024
456e84e
FEAT: Add note to image if not ran through docker compose.
Paliak Jun 30, 2024
6f97050
FIX: link
Paliak Jun 30, 2024
b6b8822
WIP: more work on arbitrary brancch diffing
Paliak Jun 30, 2024
7d419fe
FIX: only fetch origin/dev
Paliak Jul 1, 2024
ab7489e
FIX: Make the dev ref cache an artefact. Make tests that use dev ref …
Paliak Jul 1, 2024
c01d4d4
FIX: origin/dev is not found. Pull all.
Paliak Jul 1, 2024
85ed5c9
FIX: make sure the /tmp/cache directory exists
Paliak Jul 1, 2024
da8e447
FIX: try fetching only dev
Paliak Jul 1, 2024
9c06352
FIX: If the last run used cache it will not re export the same cache …
Paliak Jul 1, 2024
aa34d46
FIX: Minor security improvements.
Paliak Jul 1, 2024
c7490f6
FXI: use the correct option to look for last avilable artefact.
Paliak Jul 1, 2024
3fe71e0
FEAT: implement runtime comparison. Some formatting.
Paliak Jul 2, 2024
f959c17
FIX: missing string concat
Paliak Jul 2, 2024
2bb9f22
FIX: flipped start time and current time
Paliak Jul 2, 2024
e39e791
FIX: add runtime performance to artefact. less-than -> greater -> than
Paliak Jul 2, 2024
8485b2b
FIX: directory exists error when downloadnig newest built list.
Paliak Jul 2, 2024
30057bd
FIX: mangled sed command
Paliak Jul 2, 2024
436b4c1
FIX: DiffRuntime.lua exit code. Percentage being printed as float
Paliak Jul 2, 2024
0e635ab
FIX: missing round bracket
Paliak Jul 2, 2024
768f136
DOCS: update docs to better reflect current testing implementation
Paliak Jul 3, 2024
4e8861c
FIX: spelling
Paliak Jul 10, 2024
edf53f6
FIX: specifty a path for artefact download action in update list
Paliak Jul 10, 2024
04dfbed
FIX: quote cron string
Paliak Jul 10, 2024
929fb8d
FIX: return the full list of static build link to builds.txt and use it
Paliak Jul 11, 2024
f2ff705
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Jul 13, 2024
8ffcee2
FIX: ambiguous branch error
Paliak Jul 13, 2024
aa107d2
Merge branch 'dev' of https://github.com/Paliak/PathOfBuilding into dev
Paliak Jul 13, 2024
a12d49b
Merge branch 'dev' into dev
Paliak Jul 17, 2024
526a34a
FEAT: initial work on formatting/linting/coverage tooling support
Paliak Jul 18, 2024
199e05c
Merge branch 'dev' of https://github.com/Paliak/PathOfBuilding into dev
Paliak Jul 18, 2024
562acc9
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Jul 18, 2024
ab4e908
Merge branch 'dev' of https://github.com/Paliak/PathOfBuilding into dev
Paliak Jul 18, 2024
b64a077
FIX: dockerfile luarocks install
Paliak Jul 18, 2024
7efa325
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Jul 22, 2024
7a119f7
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Jul 28, 2024
71f7a82
Merge remote-tracking branch 'POB/dev' into dev
Paliak Aug 3, 2024
a34de95
Merge branch 'PathOfBuildingCommunity:dev' into dev
Paliak Aug 14, 2024
501d036
Merge branch 'dev' into tests-branch
Paliak Sep 7, 2026
687405e
Connect existing build comparison tests to the PoB Codes corpus (#15)
AdamZ-8113 Sep 10, 2026
2bdd6fd
Merge branch 'PathOfBuildingCommunity:dev' into tests-branch
Paliak Sep 10, 2026
40dd96d
Rename builddiff.yaml action
Paliak Sep 10, 2026
9201d9b
Remove merge conflict leftovers
Paliak Sep 10, 2026
59c25d2
Script CI header edit due to missing __mainObject__
Paliak Sep 10, 2026
6d65c38
Fix headless startup by removing old callback definitions
AdamZ-8113 Sep 10, 2026
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
6 changes: 4 additions & 2 deletions .github/workflows/beta.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
name: Push beta branch
on:
on:
schedule:
- cron: '0 0 * * 5'
push:
branches:
- 'master'
- master
workflow_dispatch:
jobs:
push-beta:
if: github.repository == 'PathOfBuildingCommunity/PathOfBuilding'
runs-on: ubuntu-22.04
steps:
- name: Set line endings
Expand Down Expand Up @@ -52,3 +53,4 @@ jobs:
run: |
git commit -am "Weekly beta release" --allow-empty --author="github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>"
git push origin HEAD:beta --force
>>>>>>> dev
2 changes: 1 addition & 1 deletion .github/workflows/builddocker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
labels: ${{ steps.meta.outputs.labels }}
50 changes: 50 additions & 0 deletions .github/workflows/buildtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
name: Run Build Diff Tests
on:
pull_request:
branches:
- dev
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
run_build_diff:
runs-on: ubuntu-latest
steps:
- name: Checkout HEAD
uses: actions/checkout@v4
- name: Fetch Dev branch
id: get-dev-ref
run: |
git fetch --depth=1 origin dev
echo "devref=$(git rev-parse origin/dev)" >> "$GITHUB_OUTPUT"
- name: Download Dev branch cache
id: download-dev-ref-cache
uses: dawidd6/action-download-artifact@3ecf4024886f219d9290351234889bfb45d1b9da
with:
name: corpus-cache-devref-${{ steps.get-dev-ref.outputs.devref }}
path: /tmp/cache/
if_no_artifact_found: warn
search_artifacts: true
- name: Calculate build xmls and differences between them
shell: bash
run: |
mkdir /tmp/cache || true # Make sure /tmp/cache exists. Ignore exit code
chmod -R 777 /tmp/cache && docker compose run -v '/tmp/cache/:/cache' -e 'CACHEDIR=/cache' busted-diff | tee /tmp/dockerlog
- name: Generate artefact
run: |
sed -n '/Runtime comparison for/,/Savefile Diff for/{/Savefile Diff for/!p;}' /tmp/dockerlog > /tmp/artefact
sed -n '/Savefile Diff for/, $p' /tmp/dockerlog >> /tmp/artefact
[ -s /tmp/artefact ] || rm /tmp/artefact
- name: Upload artefact
uses: actions/upload-artifact@v4
with:
name: build-diff-output
path: /tmp/artefact
- name: Upload dev ref cache
if: ${{ steps.download-dev-ref-cache.outputs.found_artifact == 'false' }}
uses: actions/upload-artifact@v4
with:
name: corpus-cache-devref-${{ steps.get-dev-ref.outputs.devref }}
path: /tmp/cache/
17 changes: 17 additions & 0 deletions .github/workflows/unittest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Run Unit Tests
on:
workflow_dispatch:
push:
branches:
- dev
pull_request:
branches:
- dev
jobs:
run_unit_tests:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run busted tests
run: docker compose run --no-TTY busted-tests
8 changes: 8 additions & 0 deletions .lua-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
column_limit: 160
indent_width: 1
use_tab: true
tab_width: 4
continuation_indent_width: 4
spaces_before_call: 1
keep_simple_control_block_one_line: false
keep_simple_function_one_line: false
4 changes: 4 additions & 0 deletions .luacheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
globals = { "round", "modLib", "LoadModule", "data", "ModFlag", "KeywordFlag", "SkillType", "launch", "IsKeyDown", "copyTable", "main", "colorCodesA"}
read_globals = {"DrawString", "SetDrawLayer", "GetDrawLayer", "ConPrintf", "SetDrawColor", "DrawStringWidth", "GetCursorPos", "SetViewport", "GetTime", "DrawImage", "NewFileSearch", "MakeDir"}
max_line_length = false
exclude_files = { "src\\TreeData", "src\\Data"}
4 changes: 3 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,13 @@
```

## Testing
Pob uses two types of tests. Unit tests that test specific calculations or mechanics and "build diff" tests that calculate the effect the changes have on a given list of builds.
While both can be ran locally it's recommended to use the provided docker image for both ease of use and to keep everyone on the same page.

PoB uses the [Busted](https://lunarmodules.github.io/busted/) framework to run its tests. Tests are stored under `spec/System` and run automatically when a PR is modified.
More tests can be added to this folder to test specific functionality, or new test builds can be added to ensure nothing changed that wasn't intended.

### Running tests
To run the build difference tests run `docker compose up busted-diff`. `busted-diff` first downloads the build corpus from `https://api.pob.codes/test-builds/corpus` and computes it alongside `spec/TestBuilds/` using the current working changes. Then it uses git to checkout the branch specified by `DEVREF` or `dev` by default and computes the same builds. Lastly it finds the differences in the outputs generated from both, does some post processing, and prints all of the information out. The downloaded builds and list stay with the calculated `DEVREF` cache and are reused together until that cache changes.

Check warning on line 308 in CONTRIBUTING.md

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (DEVREF)

Check warning on line 308 in CONTRIBUTING.md

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (DEVREF)

1. Install [Docker](https://www.docker.com/get-started)
2. Run `docker-compose up` from the command line
Expand Down
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,28 @@ services:
working_dir: /workdir
volumes:
- ./:/workdir:ro
busted-diff:
#build: .
image: ghcr.io/pathofbuildingcommunity/pathofbuilding-tests:latest
environment: #Where in the container the folders are stored
WORKDIR: /workdir
HOME: /tmp
DEVREF: ${DEVREF:-origin/dev}
HEADREF: $HEADREF
LUA_PATH: "/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;;"
LUA_CPATH: "/usr/lib/lua/5.1/?.so;;"
container_name: busted-diff
tty: true
# Dependencies used by the existing build-diff scripts; the image provides LuaJIT.
command:
- /bin/sh
- -ec
- |
apk add --no-cache git parallel libxml2-utils lua5.1-posix lua5.1-curl zlib-dev
luarocks install lua-zlib 1.4-0
exec su -p nobody -s /bin/sh -c 'dos2unix < /workdir/spec/BuildDiff.sh | /bin/sh'
security_opt:
- no-new-privileges:true
working_dir: /workdir
volumes:
- ./:/workdir:ro
81 changes: 81 additions & 0 deletions spec/BuildDiff.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/sh
set -eo pipefail
umask 0

# If external cache dir has not been defined keep it inside the container
if [[ -z "$CACHEDIR" ]]

Check warning on line 6 in spec/BuildDiff.sh

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (CACHEDIR)
then
mkdir /tmp/cachedir

Check warning on line 8 in spec/BuildDiff.sh

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (cachedir)
export CACHEDIR="/tmp/cachedir"

Check warning on line 9 in spec/BuildDiff.sh

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (cachedir)

Check warning on line 9 in spec/BuildDiff.sh

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (CACHEDIR)
fi

# Copy mounted workdir to allow for changes during test run
rm -rf /tmp/workdir && mkdir /tmp/workdir && cp -rf "$WORKDIR"/. /tmp/workdir/ && cd /tmp/workdir

git config --global --add safe.directory /tmp/workdir
git config --global --add advice.detachedHead false

if [[ ! -z "$HEADREF" ]]

Check warning on line 18 in spec/BuildDiff.sh

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (HEADREF)
then
git diff --no-color "$HEADREF" -- /tmp/workdir/.busted /tmp/workdir/src/HeadlessWrapper.lua /tmp/workdir/spec/ > /tmp/HeadPatch &&

Check warning on line 20 in spec/BuildDiff.sh

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (HEADREF)
git reset --hard "$HEADREF" && git clean -fd && git apply --allow-empty --index /tmp/HeadPatch

Check warning on line 21 in spec/BuildDiff.sh

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (HEADREF)
fi

headsha=$(git rev-parse HEAD)

Check warning on line 24 in spec/BuildDiff.sh

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (headsha)
devsha=$(git rev-parse "$DEVREF")

# Keep the input corpus with the calculated base, as in the existing workflow.
if [[ ! -f "$CACHEDIR/$devsha" ]]; then
curl --fail --show-error --silent https://api.pob.codes/test-builds/corpus -o "$CACHEDIR/corpus.json"
luajit spec/FetchTestBuilds.lua "$CACHEDIR"
fi
cp "$CACHEDIR/builds.txt" spec/builds.txt

rm -rf /tmp/headsha && mkdir /tmp/headsha
rm -f /tmp/workdir/src/Settings.xml
cat /tmp/workdir/spec/builds.txt | dos2unix | parallel --will-cite --ungroup --pipe -N50 'LINKSBATCH="$(mktemp){#}"; cat > $LINKSBATCH; BUILDLINKS="$LINKSBATCH" BUILDCACHEPREFIX="/tmp/headsha" busted --lua=luajit -r generate' && \
BUILDCACHEPREFIX='/tmp/headsha' busted --lua=luajit -r generate && date > "/tmp/headsha/$headsha" && echo "[+] Build cache computed for $headsha (headsha)" || exit $?

if [[ ! -f "$CACHEDIR/$devsha" ]] # Output of builds outdated or nonexistent
then
rm -rf "$CACHEDIR"/*.build

# Keep new changes to tests related files
git diff --no-color "$DEVREF" -- /tmp/workdir/.busted /tmp/workdir/src/HeadlessWrapper.lua /tmp/workdir/spec/ > /tmp/DevPatch && \
git reset --hard "$DEVREF" && git clean -fd && git apply --allow-empty --index /tmp/DevPatch && \
cat /tmp/workdir/spec/builds.txt | dos2unix | parallel --will-cite --ungroup --pipe -N50 'LINKSBATCH="$(mktemp){#}"; cat > $LINKSBATCH; BUILDLINKS="$LINKSBATCH" BUILDCACHEPREFIX="$CACHEDIR" busted --lua=luajit -r generate' && \
BUILDCACHEPREFIX="$CACHEDIR" busted --lua=luajit -r generate && date > "$CACHEDIR/$devsha" && echo "[+] Build cache computed for $devsha (devsha)" || exit $?
fi

for runTime in "$CACHEDIR"/*.time
do
BASENAME=$(basename "$runTime")

DIFFOUTPUT=$(luajit spec/DiffRuntime.lua "/tmp/headsha/$BASENAME" "$runTime" "$BASENAME") || {
echo "## Runtime comparison for $BASENAME"
echo '```'
echo "$DIFFOUTPUT"
echo '```'
}
done

for build in "$CACHEDIR"/*.build
do
BASENAME=$(basename "$build")

# Only print the header if there is a diff to display
DIFFOUTPUT=$(diff <(xmllint --exc-c14n "$build") <(xmllint --exc-c14n "/tmp/headsha/$BASENAME")) || {
echo "## Savefile Diff for $BASENAME"
echo '```diff'
echo "$DIFFOUTPUT"
echo '```'
}

# Dedicated output diff
DIFFOUTPUT=$(luajit spec/DiffOutput.lua "/tmp/headsha/$BASENAME" "$build") || {
echo "## Output Diff for $BASENAME"
echo '```'
echo "$DIFFOUTPUT"
echo '```'
}
done
74 changes: 74 additions & 0 deletions spec/DiffOutput.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
-- 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 headhnd = io.open(arg[1], "r")
local devhnd = io.open(arg[2], "r")

if headhnd and devhnd then
local playerHEADOutput, minionHEADOutput = buildOutputMap(headhnd:read("*a"))
local playerDEVOutput, minionDEVOutput = buildOutputMap(devhnd:read("*a"))
local mismatch = {}
local mismatchFound = false
for key, val in pairs(playerHEADOutput) do
if not playerDEVOutput[key] or playerDEVOutput[key] ~= val then
mismatch[key] = {devOutput = playerDEVOutput[key], headOutput = val}
mismatchFound = true
end
end
for key, val in pairs(playerDEVOutput) do
if not mismatch[key] and (not playerHEADOutput[key] or playerHEADOutput[key] ~= val) then
mismatch[key] = {headOutput = playerHEADOutput[key], devOutput = val}
mismatchFound = true
end
end
for key, val in pairs(mismatch) do
print(key .. " Mismatch in player outputs: ")
print("\t" .."head Output: " .. tostring(val["headOutput"]))
print("\t" .."dev Output: " .. tostring(val["devOutput"]))
end
mismatch = {}
for key, val in pairs(minionHEADOutput) do
if not minionDEVOutput[key] or minionDEVOutput[key] ~= val then
mismatch[key] = {devOutput = minionDEVOutput[key], headOutput = val}
mismatchFound = true
end
end
for key, val in pairs(minionDEVOutput) do
if not mismatch[key] and (not minionHEADOutput[key] or minionHEADOutput[key] ~= val) then
mismatch[key] = {headOutput = minionHEADOutput[key], devOutput = val}
mismatchFound = true
end
end
for key, val in pairs(mismatch) do
print(key .. " Mismatch in minion outputs: ")
print("\t" .."head Output: " .. tostring(val["headOutput"]))
print("\t" .."dev Output: " .. tostring(val["devOutput"]))
end
if mismatchFound then
os.exit(1) -- Make the exit codes of the script match the exit codes of the diff utility
end
else
os.exit(2)
end
17 changes: 17 additions & 0 deletions spec/DiffRuntime.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
local headHnd = io.open(arg[1], "r")
local devHnd = io.open(arg[2], "r")
local baseName = arg[3]

if headHnd and devHnd then
local headRuntime = tonumber(headHnd:read("*a"))
local devRuntime = tonumber(devHnd:read("*a"))
local runtimeDifference = math.abs(headRuntime / devRuntime - 1)
if runtimeDifference >= 0.1 then
print(string.format("%s Took longer than 10%% to calculate (%d%%)", baseName, math.floor(runtimeDifference*100)))
print("\thead runtime: " .. headRuntime .. "ms")
print("\tdev Output: " .. devRuntime .. "ms")
os.exit(1) -- Make the exit codes of the script match the exit codes of the diff utility
end
else
os.exit(2)
end
21 changes: 21 additions & 0 deletions spec/FetchTestBuilds.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-- Store the API corpus alongside the calculated base cache, outside Git.
package.path = "runtime/lua/?.lua;" .. package.path
local json = require("dkjson")
local base64 = require("base64")
local zlib = require("zlib")
local cache = assert(arg[1])
local input = assert(io.open(cache .. "/corpus.json", "r"))
local corpus = assert(json.decode(input:read("*a")))
input:close()
assert(corpus.schemaVersion == 2 and #corpus.builds > 0 and #corpus.builds == corpus.count, "Invalid build corpus")
local list = assert(io.open(cache .. "/builds.txt", "w"))
for _, entry in ipairs(corpus.builds) do
assert(#entry.sha256 == 64 and entry.sha256:match("^%x+$"), "Invalid build filename")
local xml = zlib.inflate()(base64.decode(entry.code:gsub("-", "+"):gsub("_", "/")))
local output = assert(io.open(cache .. "/" .. entry.sha256 .. ".xml", "w"))
output:write(xml)
output:close()
list:write(entry.sha256, "\n")
end
list:close()
print("[+] Downloaded " .. corpus.count .. " builds from corpus " .. corpus.snapshotId)
Loading
Loading