Compare commits

...
Author SHA1 Message Date
waozi 2e98b878a6 Release Arcade catalog 0.7.118 with the latest game releases 2026-11-02 04:43:13 +00:00
waozi 3007fa8ed2 Bound each separately loaded Arcade payload and use locked game packages 2026-11-02 01:28:27 -03:00
waozi 1063591d2f Keep qualified game UI imports in the Kryon namespace 2026-11-02 00:53:23 -03:00
waozi 6f6d13cbfa Accept the explicit node permission in the browser smoke test 2026-11-01 23:55:21 -03:00
waozi d5eb9ff080 Update shared sign-in and disambiguate the KSS build dependency 2026-11-01 23:40:30 -03:00
waozi 5a386646b9 Pin Entity sign-in and Android profile fixes 2026-11-01 23:08:01 -03:00
waozi b4cb5815c6 Adopt reviewed shared profile dependencies and lossless game packaging 2026-11-01 22:47:56 -03:00
waozi 22bbe66f7d Pass the KSS package to game bundles so Choano 0.1.5 and later build 2026-11-01 21:57:17 -03:00
waozi 8bef62f896 Offer the signed-in account to other Waozi apps on Android 2026-11-01 20:46:39 -03:00
waozi 02eb8248d8 Build liboqs with ML-KEM for device links 2026-11-01 20:03:27 -03:00
waozi 9bae15b7ce Build Arcade on Ziran 972dc244 so Breeze hosts reading ZX 26 open it
Toolchain b8d0ac17 wrote and read only ZX 27, which the Breeze host on
Ziran c8c6c96c refuses ("unsupported ZX version"). 972dc244 writes ZX 26
except for add-ons composing library modules (Shovey Editor) and reads both.
The rebuilt Apps controller differs only by that header: trust cc913d86.

The Android catalog check and tests accept both versions, and the
collection UI test answers consent before waiting for the library and
expects the declared titles shown since 755e0ae.
2026-10-31 12:23:56 -03:00
waozi 2975dd3f60 Keep release version validation independent of image build tools 2026-10-31 03:51:15 -03:00
waozi d44f1eee22 Load the signed Arcade library and previews with connection consent 2026-10-31 03:50:03 -03:00
waozi c2fd3a8921 Separate Arcade catalog and native host releases 2026-10-31 01:29:55 -03:00
waozi 51d002410a Prepare locked dependencies before publishing verified Android APKs 2026-10-31 00:19:28 -03:00
waozi 84225f873f Use the build dependency mode when verifying Android assets 2026-10-31 00:06:55 -03:00
waozi 50445a571a Release Arcade 0.7.116 as a thin Android launcher 2026-10-30 23:22:06 -03:00
waozi 41251f1d61 Use shared Android account key file filters 2026-10-30 22:01:16 -03:00
waozi a71021c7da Fix Android startup, offline game launch and launcher icon 2026-10-30 21:56:33 -03:00
waozi 30d347a393 Release Arcade 0.7.114 with approved Editor cover thumbnails 2026-10-30 20:49:29 -03:00
waozi ad2f5c252a Release Arcade 0.7.113 with correctly packaged Choano artwork 2026-10-30 19:58:35 -03:00
waozi e6693ad6c5 Preserve website readiness command line continuation 2026-10-30 19:14:30 -03:00
waozi 6dbad8d73f Include Choano in the collection release regression 2026-10-30 19:14:02 -03:00
waozi 755e0ae1d0 Show declared library titles with the shared Apps controller 2026-10-30 19:06:43 -03:00
waozi 244d3ef9a3 Add Choano to Arcade 2026-10-30 19:00:18 -03:00
waozi 80ac2c61a5 Restore Wurm launches in standalone Arcade 2026-10-30 02:19:04 -03:00
waozi d757bf455c Release Arcade 0.7.111 with the latest game releases 2026-10-30 03:54:37 +00:00
waozi 40d42a4d99 Release Arcade 0.7.110 with the latest game releases 2026-10-30 03:32:48 +00:00
waozi 7bb417c86c Verify separate game and editor catalog leaves 2026-10-29 22:59:33 -03:00
waozi d3f85d3425 Offer account-backed level sharing to Arcade editors 2026-10-29 22:24:11 -03:00
waozi 058ae8be0c Serve library thumbnails from the website 2026-10-29 19:57:01 -03:00
waozi e19fb2c761 Build Arcade's own Android APKs with the whole library offline
make android, android-fdroid and android-gplay pack the collection with every
game, its art and the Apps controller, and give the APK Arcade's icon. A
collection whose receipt says its games are packed opens without download
hooks. The Android workflow signs the three editions with Arcade's own key,
checks that only -gplay holds a Google library, and attaches them to the
node-arcade-VERSION release; Game updates and the node release start it.
2026-10-29 19:28:19 -03:00
waozi 2b4b9f9e37 Release Arcade 0.7.109 with the latest game releases 2026-10-29 21:33:43 +00:00
waozi c49c9b66ad Ship Arcade's Unreleased notes with the next followed release 2026-10-29 18:21:58 -03:00
waozi 004f813255 Ignore module imports when checking a game's text keys
Shovey imports shovey_theme, which shares the text key prefix.
2026-10-29 18:21:58 -03:00
waozi 53f6395939 Pin Shovey on its rewritten history
The old pin named a commit the history rewrite removed, so every
fetch failed. Pin the first rewritten commit whose tree matches the
public Shovey, so the release follower can move it to 0.6.162.
2026-10-29 18:21:58 -03:00
waozi 80518a9e93 Tell games on a desktop that the main input is a keyboard and mouse
The collection answers kryon.input.desktop: a native build from its
platform, and the bundle inside Breeze by asking Breeze, so games skip
their touch-controls question on a computer. arcade.controls mode follows.
2026-10-29 17:26:54 -03:00
waozi 6d2c43eb11 Leave Shovey Island out of Arcade
The owner keeps Shovey Island private, outside Git, so Shovey 0.6.160 no
longer declares it. Arcade's disabled "Coming Soon" Island tile and its
ledger entry asked for it anyway, and game updates stopped with
KeyError: 'shovey-island'.
2026-10-29 16:57:20 -03:00
waozi b75ca75b70 Build with the Ziran that locks Shovey's shared packages
Game updates could not follow Shovey 0.6.160: Shovey pins curl at the
commit Breeze takes as master, and Ziran 41244ad3 made two lock entries
with one id ("cannot update project lock"). Ziran a97e88b5 locks them
once.
2026-10-29 16:50:23 -03:00
waozi b1c8213e3e Take Play Billing from Kryon's Google Play edition file
Only the -gplay edition may name a Google library. The Play Billing
dependency and Kryon's PlayBilling source no longer sit inside an if in
build.gradle; the gplay edition applies Kryon's templates/android-gplay.gradle,
so the direct and F-Droid builds read no Google library. Kryon moves to
7217475d, which carries that file.
2026-10-29 16:28:12 -03:00
waozi e93839b45b Give Apps the host interface Arcade's players run
Apps 5b67236 checks games against AppPlatform.host_api, so the collection
players pass GAME_HOST_API. It moves with the game contract version into
src/game_contract.zi, shared by the standalone and collection players, and
check-games.py compares it with the standard and the ledger there.
2026-10-29 15:29:03 -03:00
waozi 904183956c Let Arcade's own players open host-41 games
Its game check still refused anything newer than host interface 12, so the
desktop players could not open the format-59 games of Arcade 0.7.108.
check-games.py now fails whenever GAME_HOST_API, the game standard and the
ledger name different host interfaces.
2026-10-29 15:24:50 -03:00
waozi d2a2799180 Open host-41 games in Arcade's own players
Apps cabc042 accepts games that declare host interface 41, so the desktop
and web players open the format-59 games of Arcade 0.7.108. Arcade pins
that reviewed Apps commit; the shared controller is unchanged.
2026-10-29 15:18:10 -03:00
waozi f5f1f7500d Run a game's Ziran asset preparation program
A catalog's prepare_assets may now name a .zi program as well as a .py
script. Arcade builds it with its own compiler and standard library, then
runs it from the game's checkout with the staged resources and generated
folders, as the Python step was run. Wurm's portable assets moved to Ziran.
2026-10-29 15:17:17 -03:00
waozi e5a952f221 Pin Shovey 1d3a2be and Apfelwurm 0.2.26 for Arcade 0.7.108
Shovey's campaign restyle and cave pieces match the live level campaign
on the node; Apfelwurm 0.2.26 gives the new skins plainer bodies. Both
declare host interface 41.
2026-10-29 14:14:32 -03:00
waozi c7be52fd7b Pin Shovey 576b084 with the 2.1.61 release wording
Only Shovey's changelog lines change: they name Inner Breeze 2.1.61 as the
release with the smaller app format.
2026-10-29 14:01:30 -03:00
waozi a0d7e69509 Raise the game contract to host interface 41
Games built in saved IR format 59 run only on hosts from 41, so the game
standard, Chess and the pinned Shovey 5b01cef and Apfelwurm d3f0a52
declare it. Released hosts keep their current games.
2026-10-29 13:47:12 -03:00
waozi 97f6465d27 Run Arcade 0.7.108 in Ziran's compact saved IR for host 41
The toolchain moves to Ziran 41244ad3 (saved IR format 59) and Apps to
ffebcc7, whose shared controller is e41f568f… Hosts read only their own
program format, so the collection and every game declare host interface
41; released Inner Breeze (host 40) keeps its current Arcade. Every game
gets a new version so the node accepts its new bytes: Shovey 0.6.160,
Editor 0.2.145, Island 0.4.8, Apfelwurm 0.2.25 and Chess 1.2.1.
2026-10-29 13:42:59 -03:00
waozi 4903caf607 Release Arcade 0.7.107 with the latest game releases 2026-10-29 14:40:07 +00:00
waozi 6cbb364c47 Release Arcade 0.7.106 with the latest game releases 2026-10-29 07:10:05 +00:00
waozi e140792243 Trust the reordered Apps controller 2026-10-29 04:01:29 -03:00
waozi 45bbb923ca Release Arcade 0.7.105 with the latest game releases 2026-10-29 04:09:23 +00:00
waozi e41df5dcc6 Trust the current Apps controller 2026-10-29 00:59:08 -03:00
waozi 67d63c9cb6 Keep Apps controller mismatch wording stable 2026-10-29 00:48:25 -03:00
waozi 55e654508d Report Apps controller digest mismatches 2026-10-29 00:48:04 -03:00
waozi 20edc6db9c Update Kryon for hosted overlays 2026-10-29 00:33:39 -03:00
waozi f8426f7c73 Update Kryon for hosted game bundles 2026-10-28 23:51:08 -03:00
waozi 09f2aa86c9 Advance the locked game toolchain 2026-10-28 23:22:40 -03:00
waozi e8594214a6 Exercise the current Apfelwurm launch and Back flow 2026-10-28 15:35:49 -03:00
waozi e3481ba30f Release Arcade 0.7.104 with the latest game releases 2026-10-28 17:49:51 +00:00
waozi 5841794413 Release Arcade 0.7.103 with the latest game releases 2026-10-28 16:32:15 +00:00
waozi 549872d581 Align game packages with the new Play Dew releases 2026-10-28 13:00:46 -03:00
waozi 89d356040d Advance Shovey Play release with shared Dew pricing 2026-10-28 12:39:25 -03:00
waozi 02601a6696 Update shared Profile with Play Dew savings 2026-10-28 12:34:48 -03:00
waozi 9216224da7 Include the shared 10 Dew option in hosted Google Play profiles 2026-10-28 11:58:25 -03:00
waozi 70b05d585e Release Arcade 0.7.101 with the latest game releases 2026-10-28 07:05:31 +00:00
waozi 2760ba162a Wait for Arcade's failure signal when the test frame races 2026-10-28 03:43:27 -03:00
waozi 3d5661f1a4 Keep Arcade recoverable after a failed installed game frame 2026-10-28 03:30:52 -03:00
waozi 10feef0941 Release Arcade 0.7.100 with the latest game releases 2026-10-27 22:24:38 +00:00
waozi 4e2119ac22 Pin Kryon that repaints separate changes apart 2026-10-27 18:53:09 -03:00
waozi 2e2bae31f3 Release Arcade 0.7.99 with the latest game releases 2026-10-27 21:48:39 +00:00
waozi 7ccefe55da Pin Kryon with cached canvas text and the last image looked up first 2026-10-27 18:30:37 -03:00
waozi a76516a5d3 Release Arcade 0.7.98 with Shovey 0.6.158
In Shovey's Google Play version, buy Dew in Profile through Google Play.
Pip explains wooden doors when Shovey walks up to one, rather than when
the level starts.
2026-10-27 18:08:04 -03:00
waozi 1b12719e11 Sell Dew through Google Play in Shovey's Google Play bundle
The Play bundle is now Kryon's Google Play edition (app.edition=gplay).
It compiles Kryon's PlayBilling class from the Kryon checkout, adds Play
Billing 9.1.0 with one Kotlin version, uses AndroidX and needs Android 6.
Entity's edition turns Monero funding off there, so the Profile's Top up
opens Entity's Dew page with Play's prices instead of dew.waozi.xyz;
Arcade no longer disables funding itself. The direct download keeps
Monero.
2026-10-27 18:06:50 -03:00
waozi 3a62cd55b6 Release Arcade 0.7.97 with the latest game releases 2026-10-27 21:05:53 +00:00
waozi a0f8946692 Release Arcade 0.7.96 with the latest game releases 2026-10-27 20:48:00 +00:00
waozi fb5d8d0af8 Keep Arcade browser runtime files on one cache revision 2026-10-27 17:26:02 -03:00
waozi 37f11bfe0b Release Arcade 0.7.95 with Shovey 0.6.157
Pip's tips keep what he points at in view: his card moves under the top
bar when it would cover it, such as the home in level 1.
2026-10-27 17:11:36 -03:00
waozi f687a500e7 Load arcade.waozi.xyz's runtime and Apps library sooner
The page fetched apps.zx (1.9 MB) uncompressed, since Cloudflare Pages does
not compress binary files, and only then started the 3.6 MB runtime. The
build now writes gzip copies beside apps.zx and runtime.data, which the page
unpacks with DecompressionStream (apps.zx 1.9 MB -> 0.24 MB), falling back
to the plain files; the file package is handed to the runtime rather than
fetched again. runtime.js and runtime.wasm are preloaded, so they download
while the page fetches the collection's files and waits for the sign-in.
2026-10-27 16:51:12 -03:00
waozi 7d5789d34d Release Arcade 0.7.94 with smaller library covers
The library downloaded 3.2 MB of art from the node before its covers
showed: six 640-pixel covers stored as lossless PNG made up 2.7 MB of it.
Opaque cover art is now a JPEG at quality 85 (445 KiB for all six), so the
art bundle is about a quarter of its size. Logos keep their transparency
and previews their pixel art as PNG. Every host decodes these JPEGs:
browsers, GdkPixbuf on Linux, and raylib with JPEG on Android and Windows.
2026-10-27 16:40:15 -03:00
waozi 732f28e025 Sign in once for every waozi.xyz site 2026-10-27 16:35:20 -03:00
waozi f4725cbf21 Rank Apfelwurm's best run by level and score, and open the Profile when a saved key is unreadable 2026-10-27 16:23:42 -03:00
waozi f52111be88 Compile the released Shovey into its browser page
scripts/build-web.py --shovey now passes the release's shovey.zx and
entity.zx to Entity's --linked, so the page compiles their programs, and the
game and Apps controller packed in shovey.zx, as Ziran's linked code
(Ziran 2e2fea84, Entity 9a88349). The page still opens those exact bytes;
the Shovey editor, which needs the game as a library, stays on the VM.
Walking in level 1 at 6x CPU throttle: 33 fps on the VM, 59 fps linked.

The lock follows Ziran and Entity master, which moved liboqs main too.
2026-10-27 16:10:43 -03:00
waozi cd64689a93 Repaint only damaged pixels in Arcade's browser edition
The browser host ended every frame with EndFrame, which repainted the whole
page: in a Shovey level that was 235 images and 1157 fills a frame, against
12 and 26 with Kryon's damage-only EndCanvasUiFrame (Kryon e09f3816).

The host can also run the released Shovey player, as the downloads do: a
receipt whose id is arcade.shovey-player opens Shovey's covers, and
scripts/build-web.py --shovey DIR --site DIR builds that page from a Shovey
download's shovey.zx, shovey.json and entity.zx, for shovey.waozi.xyz.
2026-10-27 15:07:33 -03:00
waozi d53446a2a6 Open dew.waozi.xyz from the Profile's Top up 2026-10-27 14:30:44 -03:00
waozi e6aa902016 Release Arcade 0.7.93 with the latest game releases 2026-10-27 16:37:17 +00:00
waozi bfd38fca73 Start the node follower as soon as Arcade releases a game update
GitHub runs scheduled workflows hours late, so a new node-arcade release
now starts Breeze's node follower directly with RELEASE_FOLLOW_TOKEN, a
token that may only start workflows. Without it the timer still follows.
2026-10-27 13:20:30 -03:00
waozi 0788c12f40 Release Arcade 0.7.92 with Shovey 0.6.156
Finishing Shovey's 175 levels opens a reward window to claim Dew paid by
finishing place: 100 for the first 10, 50 for the next 20, 20 up to the
100th and 5 after.
2026-10-27 13:07:43 -03:00
waozi 3c405887b8 Release Arcade 0.7.91 with the latest game releases 2026-10-27 06:34:13 +00:00
waozi 0c747f2c49 Release Arcade 0.7.90 with Shovey 0.6.155
Entity ca637d0 saves account aliases typed with capitals, an @ or spaces
and says when an alias is taken, in Arcade and its games.
2026-10-27 02:17:30 -03:00
waozi bc5606e32c Pin the shared Profile and verify installed-only game boards 2026-10-27 01:14:32 -03:00
waozi 37a0d8b0a7 Merge remote-tracking branch 'origin/master' 2026-10-27 00:58:42 -03:00
waozi 8452563b03 Release Arcade 0.7.89 with the latest game releases 2026-10-27 02:51:10 +00:00
waozi 96932541db Connect installed Arcade games to Profile leaderboards 2026-10-26 23:47:05 -03:00
waozi a442fe0621 Release Arcade 0.7.88 with the latest game releases 2026-10-27 01:41:10 +00:00
waozi d6ebf18af2 Preserve manifest sections while pinning game releases 2026-10-26 22:17:34 -03:00
waozi 84b3fd552a Use smaller cached thumbnails for every Arcade library cover 2026-10-26 22:06:28 -03:00
waozi 1239df4855 Resolve released game dependencies through Ziran 2026-10-26 22:01:00 -03:00
waozi 476e38ca41 Release Arcade 0.7.86 with the latest game releases 2026-10-27 00:26:50 +00:00
waozi 0b07d0d374 Follow published game source after recording release metadata 2026-10-26 20:56:33 -03:00
waozi 48d2216394 Record synchronized Shovey chests and current game releases 2026-10-26 20:42:19 -03:00
waozi bd5f4a4ccb Disable Dew funding in Google Play builds 2026-10-26 16:54:18 -03:00
waozi 9d050ff20b Include verified live legacy reward recovery in the shared host 2026-10-26 14:36:10 -03:00
waozi 6e835a5dad Ship legacy Shovey reward migration in the shared game host 2026-10-26 14:29:42 -03:00
waozi 4592ce5d95 Acknowledge Pip before testing native gameplay 2026-10-26 14:01:13 -03:00
waozi 1889eff0b7 Use the published game controls and reward dialog updates 2026-10-26 13:55:39 -03:00
waozi e4c52c82fe Merge the published Arcade release with title screen improvements 2026-10-26 13:53:43 -03:00
waozi 3fa55eb32f Show full-colour startup previews before original title art 2026-10-26 13:15:07 -03:00
waozi 11fce1e7db Keep original colours and resolution in game title screens 2026-10-26 12:58:20 -03:00
104 changed files with 5539 additions and 450 deletions

No files matched your search

+212
View File
@@ -0,0 +1,212 @@
name: Android
# Native host releases have their own VERSION and arcade-VERSION release.
# Catalog/game publication never starts this workflow. All three signed
# editions are verified before this workflow creates the native release tag.
# Existing node-arcade-VERSION releases and their APK URLs remain unchanged.
on:
workflow_dispatch:
inputs:
version:
description: Native host release version; empty uses VERSION at the chosen ref
required: false
type: string
permissions:
contents: write
concurrency:
group: arcade-android-${{ github.ref }}
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 10
outputs:
version: ${{ steps.release.outputs.version }}
due: ${{ steps.release.outputs.due }}
toolchain: ${{ steps.release.outputs.toolchain }}
shovey: ${{ steps.release.outputs.shovey }}
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
- name: Check version and release boundaries
run: python3 tests/catalog_versions_test.py
- name: Find the release and its locked dependencies
id: release
env:
GH_TOKEN: ${{ github.token }}
REQUESTED: ${{ inputs.version }}
run: |
set -eu
version=$(cat VERSION)
if [ -n "$REQUESTED" ] && [ "$REQUESTED" != "$version" ]; then
echo "::error::$GITHUB_REF is at Arcade $version, not $REQUESTED"
exit 1
fi
# A new native release needs no matching node catalog release.
due=true
if assets=$(gh release view "arcade-$version" --json assets --jq '.assets[].name'); then
due=false
for name in "arcade-$version.apk" "arcade-$version-fdroid.apk" "arcade-$version-gplay.apk"; do
printf '%s\n' "$assets" | grep -qxF "$name" || due=true
done
fi
if [ "$due" = false ]; then
echo "::notice title=Android::Arcade $version already has its APKs"
fi
python3 - <<'PY' >> "$GITHUB_OUTPUT"
import json
lock = json.load(open('ziran.lock'))
shovey = lock['root']['dependencies']['shovey']
print('toolchain=' + lock['toolchain']['commit'])
print('shovey=' + next(p['commit'] for p in lock['packages'] if p['id'] == shovey))
PY
echo "version=$version" >> "$GITHUB_OUTPUT"
echo "due=$due" >> "$GITHUB_OUTPUT"
build:
needs: release
if: needs.release.outputs.due == 'true'
runs-on: ubuntu-24.04
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
edition: [direct, fdroid, gplay]
defaults:
run:
working-directory: waozixyz/arcade
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
with:
path: waozixyz/arcade
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
with:
repository: ziranlang/ziran
ref: ${{ needs.release.outputs.toolchain }}
path: ziranlang/ziran
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
with:
repository: waozixyz/shovey
ref: ${{ needs.release.outputs.shovey }}
path: waozixyz/shovey
# Only the Google Play edition may name a Google library, in its build
# files as in its APK.
- name: Keep Google libraries out of the normal and F-Droid build files
if: matrix.edition != 'gplay'
uses: kryonlabs/kryon/.github/actions/google-free@7217475dfa7f462939e47e3f0bc918aef248b179
with:
source: waozixyz/arcade
- name: Install build dependencies
working-directory: .
run: |
sh ziranlang/ziran/scripts/ci_packages.sh build-essential cmake pkg-config python3-pil python3-numpy python3-cryptography
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
- name: Install the Android SDK parts Kryon's Android host needs
working-directory: .
run: |
sdkmanager="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager"
yes | "$sdkmanager" --licenses > /dev/null
"$sdkmanager" --install 'ndk;28.2.13676358' 'build-tools;36.0.0' 'platforms;android-36' 'cmake;3.22.1' > /dev/null
- name: Build the locked toolchain and fetch packages
run: |
make -j2 -C ../../ziranlang/ziran
echo "$GITHUB_WORKSPACE/ziranlang/ziran/build/bin" >> "$GITHUB_PATH"
# The game is generated in its own checkout at the locked release.
printf '[overrides]\nshovey = "../shovey"\nziran = "../../ziranlang/ziran"\n' > ziran.local.toml
../../ziranlang/ziran/build/bin/ziran fetch
- name: Build the APK
env:
EDITION: ${{ matrix.edition }}
run: |
make -C ../shovey levels landscape
if [ "$EDITION" = direct ]; then make android; else make "android-$EDITION"; fi
- name: Keep Google libraries out of the normal and F-Droid APK
if: matrix.edition != 'gplay'
uses: kryonlabs/kryon/.github/actions/google-free@7217475dfa7f462939e47e3f0bc918aef248b179
with:
packages: waozixyz/arcade/build/android/arcade*-unsigned.apk
source: ''
# The check must still recognise Play Billing, or its passes on the
# other editions prove nothing.
- name: Find Play Billing in the Google Play APK
if: matrix.edition == 'gplay'
uses: kryonlabs/kryon/.github/actions/google-free@7217475dfa7f462939e47e3f0bc918aef248b179
with:
packages: waozixyz/arcade/build/android/arcade-gplay-unsigned.apk
source: ''
expect-google: 'true'
- name: Sign and check the APK
env:
KEYSTORE: ${{ secrets.ARCADE_ANDROID_KEYSTORE }}
PASSWORD: ${{ secrets.ARCADE_ANDROID_KEYSTORE_PASSWORD }}
VERSION: ${{ needs.release.outputs.version }}
EDITION: ${{ matrix.edition }}
run: |
set -eu
umask 077
suffix=$([ "$EDITION" = direct ] && echo '' || echo "-$EDITION")
printf '%s' "$KEYSTORE" | base64 -d > "$RUNNER_TEMP/arcade-release.p12"
printf '%s\n' "$PASSWORD" > "$RUNNER_TEMP/password"
python3 scripts/android-release.py sign "build/android/arcade$suffix-unsigned.apk" \
--edition "$EDITION" --version "$VERSION" \
--keystore "$RUNNER_TEMP/arcade-release.p12" --password-file "$RUNNER_TEMP/password" \
--output "build/downloads/arcade-$VERSION$suffix.apk"
rm -f "$RUNNER_TEMP/arcade-release.p12" "$RUNNER_TEMP/password"
- uses: actions/upload-artifact@v4
with:
name: arcade-android-${{ matrix.edition }}
path: waozixyz/arcade/build/downloads/*.apk
if-no-files-found: error
retention-days: 7
publish:
needs: [release, build]
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
with:
repository: ziranlang/ziran
ref: ${{ needs.release.outputs.toolchain }}
path: ziranlang/ziran
- name: Prepare the locked asset verifier dependencies
run: |
make -j2 -C ziranlang/ziran
echo "$GITHUB_WORKSPACE/ziranlang/ziran/build/bin" >> "$GITHUB_PATH"
printf '[overrides]\nziran = "ziranlang/ziran"\n' > ziran.local.toml
ziranlang/ziran/build/bin/ziran fetch
- uses: actions/download-artifact@v4
with:
pattern: arcade-android-*
path: build/downloads
merge-multiple: true
- name: Verify all editions and publish the native host release
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.release.outputs.version }}
run: |
set -eu
for edition in direct fdroid gplay; do
suffix=$([ "$edition" = direct ] && echo '' || echo "-$edition")
python3 scripts/android-release.py verify "build/downloads/arcade-$VERSION$suffix.apk" \
--edition "$edition" --version "$VERSION"
done
tag="arcade-$VERSION"
if gh release view "$tag" >/dev/null 2>&1; then
# Retry only the same verified source, preserving past release URLs.
target=$(gh api "repos/$GITHUB_REPOSITORY/commits/$tag" --jq '.sha')
test "$target" = "$GITHUB_SHA"
gh release upload "$tag" "build/downloads/arcade-$VERSION.apk" \
"build/downloads/arcade-$VERSION-fdroid.apk" "build/downloads/arcade-$VERSION-gplay.apk" --clobber
else
gh release create "$tag" "build/downloads/arcade-$VERSION.apk" \
"build/downloads/arcade-$VERSION-fdroid.apk" "build/downloads/arcade-$VERSION-gplay.apk" \
--target "$GITHUB_SHA" --title "Arcade $VERSION" \
--notes 'Native Arcade for Android: normal, F-Droid and Google Play editions. Games and library updates arrive separately.'
fi
+63 -31
View File
@@ -2,10 +2,12 @@ name: Game updates
# Arcade follows its games by itself. When a game package (Shovey, Apfelwurm)
# publishes a GitHub release, this pins Arcade to that release, adds the
# game's notes to Arcade's changelog, builds and checks the collection,
# commits the new Arcade version and attaches its catalog and game archive to
# game's notes to Arcade's catalog changelog, builds and checks the collection,
# commits the new catalog version and attaches its catalog and game archive to
# the node-arcade-VERSION release. Inner Breeze's node follower then signs
# that release and publishes it to Waozi's node, where Arcade downloads games.
# A game's release workflow starts this at once; the timer is the fallback,
# since GitHub runs scheduled workflows hours late.
on:
schedule:
- cron: '7,22,37,52 * * * *'
@@ -13,6 +15,7 @@ on:
permissions:
contents: write
actions: write
concurrency:
group: arcade-node-release
@@ -29,13 +32,17 @@ jobs:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
with:
path: waozixyz/arcade
- name: Pin the latest game releases
id: pin
- name: Check release following
run: |
python3 tests/game_updates_test.py
python3 tests/catalog_versions_test.py
- name: Find newer game releases
id: updates
env:
GH_TOKEN: ${{ github.token }}
run: |
python3 scripts/follow-game-releases.py pin
if git diff --quiet -- ziran.lock; then
python3 scripts/follow-game-releases.py check
if [ "$(python3 -c 'import json; print(len(json.load(open("build/game-updates.json"))))')" = 0 ]; then
echo "changed=false" >> "$GITHUB_OUTPUT"
echo "Arcade already pins every game's latest release."
exit 0
@@ -44,45 +51,56 @@ jobs:
python3 - <<'PY' >> "$GITHUB_OUTPUT"
import json
lock = json.load(open('ziran.lock'))
shovey = lock['root']['dependencies']['shovey']
print('toolchain=' + lock['toolchain']['commit'])
PY
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
if: steps.updates.outputs.changed == 'true'
with:
repository: ziranlang/ziran
ref: ${{ steps.updates.outputs.toolchain }}
path: ziranlang/ziran
- name: Install build dependencies
if: steps.updates.outputs.changed == 'true'
working-directory: .
run: sh ziranlang/ziran/scripts/ci_packages.sh build-essential python3-pil python3-cryptography
- name: Build the locked toolchain and pin game dependencies
id: pin
if: steps.updates.outputs.changed == 'true'
env:
GH_TOKEN: ${{ github.token }}
run: |
make -j2 -C ../../ziranlang/ziran
echo "$GITHUB_WORKSPACE/ziranlang/ziran/build/bin" >> "$GITHUB_PATH"
python3 scripts/follow-game-releases.py pin --ziran ../../ziranlang/ziran/build/bin/ziran
python3 - <<'PY' >> "$GITHUB_OUTPUT"
import json
lock = json.load(open('ziran.lock'))
shovey = lock['root']['dependencies']['shovey']
print('shovey=' + next(p['commit'] for p in lock['packages'] if p['id'] == shovey))
PY
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
if: steps.pin.outputs.changed == 'true'
with:
repository: ziranlang/ziran
ref: ${{ steps.pin.outputs.toolchain }}
path: ziranlang/ziran
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
if: steps.pin.outputs.changed == 'true'
if: steps.updates.outputs.changed == 'true'
with:
repository: waozixyz/shovey
ref: ${{ steps.pin.outputs.shovey }}
path: waozixyz/shovey
- name: Install build dependencies
if: steps.pin.outputs.changed == 'true'
working-directory: .
run: sh ziranlang/ziran/scripts/ci_packages.sh build-essential python3-pil python3-cryptography
- name: Build the locked toolchain and fetch packages
if: steps.pin.outputs.changed == 'true'
- name: Fetch the updated packages
if: steps.updates.outputs.changed == 'true'
run: |
make -j2 -C ../../ziranlang/ziran
echo "$GITHUB_WORKSPACE/ziranlang/ziran/build/bin" >> "$GITHUB_PATH"
# The game is generated in its own checkout at the pinned release.
printf '[overrides]\nshovey = "../shovey"\nziran = "../../ziranlang/ziran"\n' > ziran.local.toml
../../ziranlang/ziran/build/bin/ziran fetch
- name: Write the Arcade release
id: release
if: steps.pin.outputs.changed == 'true'
if: steps.updates.outputs.changed == 'true'
run: |
python3 scripts/follow-game-releases.py changelog --ziran ../../ziranlang/ziran/build/bin/ziran
sh update_version.sh
sh update_version.sh --catalog
python3 scripts/follow-game-releases.py art
echo "version=$(cat VERSION)" >> "$GITHUB_OUTPUT"
head -12 CHANGELOG.md
echo "version=$(cat catalog/VERSION)" >> "$GITHUB_OUTPUT"
head -12 catalog/CHANGELOG.md
- name: Build and check the collection
if: steps.pin.outputs.changed == 'true'
if: steps.updates.outputs.changed == 'true'
run: |
make -C ../shovey levels landscape
make collection
@@ -90,18 +108,18 @@ jobs:
python3 tests/publisher_test.py
- name: Commit the release
id: commit
if: steps.pin.outputs.changed == 'true'
if: steps.updates.outputs.changed == 'true'
env:
VERSION: ${{ steps.release.outputs.version }}
run: |
git config user.name Waozi
git config user.email [email protected]
git add ziran.lock CHANGELOG.md VERSION apps/versions.json assets/arcade/library
git commit -q -m "Release Arcade $VERSION with the latest game releases"
git add ziran.toml ziran.lock catalog/CHANGELOG.md catalog/VERSION apps/versions.json assets/arcade/library
git commit -q -m "Release Arcade catalog $VERSION with the latest game releases"
git push origin HEAD:master
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
- name: Attach the checked catalog and game archive
if: steps.pin.outputs.changed == 'true'
if: steps.updates.outputs.changed == 'true'
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ steps.release.outputs.version }}
@@ -112,3 +130,17 @@ jobs:
--target "$SHA" --title "Arcade $VERSION" \
--notes 'Arcade downloads the selected game separately and preserves earned progress.'
echo "Arcade $VERSION is ready for the node: sha256 $(sha256sum build/node-apps/arcade.zx | cut -d' ' -f1)"
# Breeze's node follower signs this release and publishes it to the
# node now, not at its next timer. RELEASE_FOLLOW_TOKEN may only start
# workflows in Arcade and Breeze; the follower takes no input and
# checks Arcade's newest release itself. Without it the timer follows.
- name: Start the node follower
if: steps.updates.outputs.changed == 'true'
env:
GH_TOKEN: ${{ secrets.RELEASE_FOLLOW_TOKEN }}
run: |
if [ -z "$GH_TOKEN" ]; then
echo "No RELEASE_FOLLOW_TOKEN: Breeze's node follower picks this release up on its timer."
exit 0
fi
gh workflow run node-app-follow.yml -R waozixyz/breeze --ref master
+4 -1
View File
@@ -10,6 +10,7 @@ on:
permissions:
contents: write
actions: write
concurrency:
group: arcade-node-release
@@ -26,6 +27,8 @@ jobs:
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262
with:
path: waozixyz/arcade
- name: Check version and release boundaries
run: python3 tests/catalog_versions_test.py
- name: Read the fixed dependency revisions
id: dependencies
env:
@@ -92,7 +95,7 @@ jobs:
GH_TOKEN: ${{ github.token }}
run: |
set -eu
version=$(cat VERSION)
version=$(cat catalog/VERSION)
tag="node-arcade-$version"
if gh release view "$tag" >/dev/null 2>&1; then
mkdir -p build/prior-node-release
+10 -5
View File
@@ -48,7 +48,7 @@ jobs:
node-version: 22
- name: Install build dependencies
working-directory: .
run: sh ziranlang/ziran/scripts/ci_packages.sh build-essential cmake pkg-config
run: sh ziranlang/ziran/scripts/ci_packages.sh build-essential cmake pkg-config python3-pil
- uses: mymindstorm/setup-emsdk@v14
with:
version: '6.0.6'
@@ -68,18 +68,23 @@ jobs:
-q '[.[] | select(.isDraft | not) | .tagName | select(startswith("node-arcade-"))][0]')
test -n "$tag"
mkdir -p build/published
gh release download "$tag" --repo waozixyz/arcade --pattern arcade.zx --dir build/published
# The Apps library that release packs, by the digest its own commit trusts.
git show "$tag:apps-controller.sha256" > build/published/apps-controller.sha256
# Its game archive holds the library art the site serves itself.
gh release download "$tag" --repo waozixyz/arcade --pattern arcade.zx \
--pattern arcade.games.tar --dir build/published
echo "version=${tag#node-arcade-}" >> "$GITHUB_OUTPUT"
- name: Build the browser edition
run: |
python3 tests/web_library_art_test.py
python3 scripts/build-entity.py
python3 scripts/build-apps.py --output build/apps-ui
python3 scripts/build-web.py --bundle build/published/arcade.zx \
--controller-sha256 "$(cat build/published/apps-controller.sha256)" \
--controller-sha256 "$(cat apps-controller.sha256)" \
--version '${{ steps.published.outputs.version }}'
rm -f build/web-site/runtime.html
- name: Wait for the published games the browser will download
run: |
python3 scripts/wait-published-games.py --deadline-seconds 900 --poll-seconds 30 \
build/published/arcade.zx build/published/arcade.games.tar
- name: Open Arcade in a private browser
run: |
export CHROMIUM="$(command -v google-chrome || command -v chromium)"
+1
View File
@@ -1,5 +1,6 @@
/build/
/backup/
/work/
/ziran.local.toml
__pycache__/
*.pyc
+206
View File
@@ -1,5 +1,211 @@
# Arcade changelog
## [Unreleased]
- Use Entity's reviewed account authorization and shared Apps controller.
- Keep the full game collection within the host payload limit by packing opaque pictures without redundant alpha data; decoded pixels stay identical.
- On Android, Continue as can use the account from another signed-in Waozi app, once you approve it there.
- Arcade and its games open again in Breeze builds that read the previous app bundle format.
## 0.7.117
- Ask before connecting to the node for Arcade's signed app library and compressed previews, with an offline choice and a connection control.
- Refresh library membership and game versions independently of the APK, keeping downloaded apps and saved progress available offline.
- Recover library thumbnails after failed requests and keep the native host release version separate from catalog releases.
## 0.7.116
- Android Arcade downloads games and library thumbnails on demand instead of bundling the entire game library; installed games remain playable offline with saved progress.
- Filter account-key imports to key files and related backup types on Android.
## 0.7.115
- Arcade opens correctly on Android instead of closing during startup.
- Bundled offline games open with the full library installed.
- The Android launcher icon fills its launcher shape with a larger gamepad.
## 0.7.114
- Apfelwurm Editor uses its painted logo cover in the library.
- Tall library previews keep their titles visible in small, compressed cards.
## 0.7.113
- Choano 0.1.3 loads its artwork and sound from the paths the game requests.
## 0.7.112
- Every library cover shows its declared app title, including Apfelwurm Editor.
- Choano appears in Arcade and launches from its own game package.
- Apfelwurm and Apfelwurm Editor open correctly in standalone Arcade.
## 0.7.111
- Apfelwurm 0.2.27: Earn coins for every level you clear and spend them on new skins.
- Apfelwurm 0.2.27: Claim a daily reward from the chest on the title: 30 days of coins, two new skins and rare Dew on days 10 and 25.
- Apfelwurm 0.2.27: The title has painted Shop, Profile, Leaderboard and Settings icons, with your coins and Dew beside the Shop.
- Apfelwurm 0.2.27: The Shop has Skins, Coins and Dew tabs: buy coin packs with Dew and top up Dew without leaving it.
- Apfelwurm 0.2.27: Browse thirteen skins with slimmer bodies, closer segments, clean edges and matching leaderboard pictures.
- Apfelwurm 0.2.27: Open the level editor directly from the title. Settings previews both touch control styles, or shows the steering keys on a computer.
- Apfelwurm 0.2.27: The level editor has its own title screen. Start a **New level** in any landscape you have reached, or copy one **From a level**.
- Apfelwurm 0.2.27: Keep your levels in **My levels**, in collections you can name and reorder. They stay private to you.
- Apfelwurm 0.2.27: Share a collection with your friends or everyone, and find other players' collections in **Community**. Added collections become your own private copies.
- Apfelwurm 0.2.27: Campaign levels you changed before still play as you made them; **Campaign changes** lists them so you can reset each one.
- Apfelwurm 0.2.27: Open the editor as its own **Apfelwurm Editor** app in Arcade.
- Apfelwurm 0.2.27: Play local desktop rounds with two to four players, separate bottom entrances and four keyboard control sets.
- Apfelwurm 0.2.27: Name each local player and pick their skin; start local rounds from Settings. Each open entrance has rock posts beside it.
- Apfelwurm 0.2.27: Play every level in the same layout in portrait and landscape, shaped after the portrait, with roomier portrait boards.
- Apfelwurm 0.2.27: Your own portrait level now also shapes its landscape until you save a landscape of your own.
- Apfelwurm 0.2.27: On a computer, play starts without asking how to steer, also inside Breeze and Arcade, and the keyboard steers without an on-screen pad.
- Apfelwurm 0.2.27: Level 19 is roomier: every side passage is wide enough to turn and come back out.
## 0.7.110
- Arcade is available as an Android app that plays every game offline, in normal, F-Droid and Google Play editions.
- On arcade.waozi.xyz the game covers appear sooner, as smaller WebP pictures from the site itself.
- Editors can share level collections through Arcade's signed-in Entity account.
- Shovey 0.6.163: Keep named collections in the Editor, share them with friends or everyone, and add new private collections from Explore.
- Shovey 0.6.163: Mirror and laser names and the level heading display correctly in every language.
## 0.7.109
- On a computer, games start without asking how to move, also inside Breeze.
- Shovey 0.6.162: Coloured pits have new artwork.
- Shovey 0.6.162: On a computer, play starts without asking how to move.
## 0.7.108
- Every game runs in Inner Breeze 2.1.61's smaller app format.
- Shovey 0.6.160, Editor 0.2.145 and Island 0.4.8, and Apfelwurm 0.2.26 with newly painted skins that have calm, plain bodies.
## 0.7.107
- Apfelwurm 0.2.24: Keep the entrance area free of enemies: none start there or wander in, so nothing vanishes when you lose a life.
- Apfelwurm 0.2.24: Restart Profile and Leaderboard by themselves if they stop, or say why instead of showing an empty page.
## 0.7.106
- Apfelwurm 0.2.23: Move a little faster throughout the campaign, with a consistent pace across Meadow.
## 0.7.105
- Apfelwurm 0.2.22: Keep the leaderboard visible when you or a friend uses a special Wurm skin.
## 0.7.104
- Apfelwurm 0.2.12: Download the Google Play edition as a separate `-gplay.apk`. The standard and F-Droid APKs exclude Google libraries and keep Monero top-ups.
## 0.7.103
- Apfelwurm 0.2.11: Buy a small 10 Dew pack in the Google Play edition and see each larger pack’s savings per Dew.
## 0.7.102
- Update Apfelwurm and Shovey with a small 10 Dew pack and visible larger-pack savings in their Google Play editions.
## 0.7.101
- Apfelwurm 0.2.10: Keep signed-in progress and unfinished runs after closing or updating Apfelwurm inside Arcade and Breeze.
- Apfelwurm 0.2.10: Restore earned unlocks from older account saves without changing completed levels or the current run.
- Apfelwurm 0.2.10: Give Apfelwurm its own Android launcher icon.
## 0.7.100
- Apfelwurm 0.2.9: More portal rooms in the mountains: five more boards have a walled corner room whose doorway closes, so a ring is the only way in, and boards there that bring portals use their room. Seven of the last twenty boards now have a portal room.
## 0.7.99
- Shovey 0.6.158: In the Google Play version, buy Dew in Profile through Google Play.
- Shovey 0.6.158: Pip explains wooden doors when Shovey walks up to one, rather than when the level starts.
- Apfelwurm 0.2.8: After the meadow, a new idea arrives every few dozen levels and keeps coming back: squirrels that dash and sit from level 45, hedgehogs that curl into a spiky ball as you come close from 85, keys that open a gate from 101, frogs that hop two tiles from 125, switch stones that open and close a gate from 141, rolling stones from 165 and portal rooms, reached only through a ring, from 181.
- Apfelwurm 0.2.8: Each new idea takes every other board for ten levels. After that, the ideas you have met take turns, with no more than two plain boards in a row.
- Apfelwurm 0.2.8: A gate closes a doorway up to four tiles wide. Its key opens it for good and is worth 2 points; a switch stone flips it each time you arrive on it. Boards with a gate or a portal room score more.
- Apfelwurm 0.2.8: New pictures for the squirrel, hedgehog, frog, rolling stone, key, switch stone and gate.
## 0.7.98
- Shovey 0.6.158: In the Google Play version, buy Dew in Profile through Google Play.
- Shovey 0.6.158: Pip explains wooden doors when Shovey walks up to one, rather than when the level starts.
## 0.7.97
- Apfelwurm 0.2.6: Glowing portals arrive from level 61: first on a few boards, then more often, with two pairs late in the mountains. Steer into one ring to come out of its partner, keeping your direction. Each ring stands in open ground, so you can always go around it.
- Apfelwurm 0.2.6: See your best run on the Profile leaderboard: the furthest level you reached and your highest score, as separate Level and Score columns ranked against your friends.
- Apfelwurm 0.2.6: Sign in once for every waozi.xyz site: a profile signed in on Arcade, Dew or here is used by the others in the same browser.
- Apfelwurm 0.2.6: Buy Dew inside the Google Play version through Google Play, priced in your own currency. The direct download and F-Droid versions keep buying Dew with Monero.
- Apfelwurm 0.2.6: The privacy page explains Google Play purchases and how to delete your account.
## 0.7.96
- Shovey 0.6.157: Pip's tips keep what he points at in view: his card moves under the top bar when it would cover it, such as the home in level 1.
- Apfelwurm 0.2.4: Play on the whole page at wurm.waozi.xyz, without a title bar above the game.
## 0.7.95
- Shovey 0.6.157: Pip's tips keep what he points at in view: his card moves under the top bar when it would cover it, such as the home in level 1.
## 0.7.94
- The library's game covers download about four times faster.
## 0.7.93
- Shovey 0.6.156: Finishing all 175 levels opens a reward window: press Claim to get your Dew. The first 10 players to finish get 100 Dew, the next 20 get 50, players up to the 100th get 20, and everyone after gets 5.
## 0.7.92
- Shovey 0.6.156: Finishing all 175 levels opens a reward window: press Claim to get your Dew. The first 10 players to finish get 100 Dew, the next 20 get 50, players up to the 100th get 20, and everyone after gets 5.
## 0.7.91
- Shovey 0.6.155: Set an account alias with capitals, an @ or spaces; a taken alias now says so.
- Apfelwurm 0.2.2: Set an account alias with capitals, an @ or spaces; a taken alias now says so.
## 0.7.90
- Set an account alias with capitals, an @ or spaces; a taken alias now says so.
- Shovey 0.6.155: Set an account alias with capitals, an @ or spaces; a taken alias now says so.
## 0.7.89
- Apfelwurm 0.2.1: Use Arcade or Inner Breeze's Profile, Dew and navigation when playing inside them, without duplicate title controls or an extra Back button.
- Apfelwurm 0.2.1: Open the shared Profile reliably from the skin shop's sign-in button.
## 0.7.88
- Apfelwurm 0.2.0: Play with softer Dusk, Forest and Sage themes, with saved sound and control settings.
- Apfelwurm 0.2.0: See a continuous painted meadow instead of a repeating grass grid, and clear Profile and Dew icons on the title.
- Apfelwurm 0.2.0: Sign in through the shared Profile to sync completed levels, playtime, settings and your chosen character across devices.
- Apfelwurm 0.2.0: Browse the skin shop from the title beside Profile and your Dew balance. Mint, Berry and Rose cost 10, 20 and 30 Dew, with confirmation before buying.
- Apfelwurm 0.2.0: Earn Night owl after five hours of active play, Golden apple by reaching level 40, and Explorer by visiting waozi.xyz. Purchased skins belong to your account.
- Apfelwurm 0.2.0: Unlock all 200 levels by playing. The mobile selector shows large previews for unlocked levels and only a lock for later ones. Dew is used for optional cosmetics.
## 0.7.87
- Open the game library faster with smaller cached cover thumbnails for every game.
- Keep covers sharp and logos transparent while downloading much less artwork.
## 0.7.86
- Shovey 0.6.154: Keep opened chests open across restarts and account sync; show the blue Dew diamond only while their reward is unclaimed.
- Shovey 0.6.154: Show an empty open chest after its Dew is claimed.
- Shovey 0.6.154: Use corrected campaign boards after an update, including level 29 when an older campaign was cached offline.
## 0.7.85
- Shovey keeps opened and claimed chests synchronized, with a blue diamond only for an unclaimed reward.
- Shovey uses corrected boards after an update instead of an older cached campaign.
- Apfelwurm shows level previews only after they are unlocked.
## 0.7.84
- Complete automatic reward recovery for older Shovey saves.
## 0.7.83
- Preserve earned Shovey reward eligibility when upgrading older synced saves.
## 0.7.82
- Apfelwurm 0.1.6: Try again after game over starts the furthest unlocked level with three lives and a fresh score.
+29 -1
View File
@@ -20,7 +20,7 @@ DATA_DIR ?= $(if $(XDG_DATA_HOME),$(XDG_DATA_HOME),$(HOME)/.local/share)
all: collection build/entity.zx build/arcade build/shovey
games:
python3 scripts/check-games.py
python3 scripts/check-games.py --ziran '$(ZIRAN)' $(LOCK_FLAGS)
python3 scripts/build-games.py --ziran '$(ZIRAN)' $(LOCK_FLAGS)
$(APPS_BUNDLE): ziran.lock apps-controller.sha256 scripts/build-apps.py Makefile
@@ -54,11 +54,19 @@ run: all
./build/arcade
test: all
python3 tests/game_module_paths_test.py
python3 tests/game_resource_packing_test.py
python3 tests/game_translation_keys_test.py
python3 tests/android_catalog_test.py
python3 tests/android_jni_contract_test.py
python3 tests/game_updates_test.py
$(ZIRAN) fmt --check src/*.zi apps/chess/*.zi tests/chess_engine_behavior.zi tests/chess_app_behavior.zi
python3 tests/chess_locale_test.py
INBE_SOURCE='$(INBE_SOURCE)' python3 tests/catalog_test.py
python3 tests/publisher_test.py
python3 tests/apps_controller_test.py
python3 tests/startup_art_test.py
python3 tests/web_library_art_test.py
./build/arcade --list
sh tests/chess_engine_zi_test.sh '$(ZIRAN)'
sh tests/chess_app_test.sh '$(ZIRAN)'
@@ -131,6 +139,26 @@ install: all install-arcade
install -m 0644 build/shovey-icon.png '$(DATA_DIR)/icons/hicolor/256x256/apps/xyz.waozi.shovey.png'
install -m 0644 packaging/xyz.waozi.arcade.desktop packaging/xyz.waozi.shovey.desktop '$(DATA_DIR)/applications/'
# Arcade's APK is a thin catalog with on-demand games and art. Each builds an unsigned
# release APK in build/android/; only -gplay carries a Google library.
# scripts/android-release.py signs and checks them.
.PHONY: android android-fdroid android-gplay
android: collection
python3 scripts/build-android.py --product arcade --release
android-fdroid: collection
python3 scripts/build-android.py --product arcade --release --edition fdroid
android-gplay: collection
python3 scripts/build-android.py --product arcade --release --edition gplay
# Test the Android catalog through the generic install/cache path privately.
.PHONY: android-offline-ui-test
android-offline-ui-test: build/arcade build/entity.zx
env -u DISPLAY -u WAYLAND_DISPLAY -u XAUTHORITY -u DBUS_SESSION_BUS_ADDRESS \
-u SESSION_MANAGER -u GDK_DISPLAY YUE_DESKTOP_RECOVERY=0 SDL_AUDIODRIVER=dummy \
timeout 240s xvfb-run -a -n 400 -s '-screen 0 1280x1000x24' python3 tests/android_offline_ui_test.py --binary '$(CURDIR)/build/arcade' --inbe-source '$(INBE_SOURCE)'
.PHONY: android-shovey android-shovey-release android-shovey-bundle
android-shovey: collection
python3 scripts/build-android.py
+62 -11
View File
@@ -6,14 +6,16 @@ title-screen covers from the shared Apps controller. Click a cover to open
an installed game or download it first. There are no separate launch buttons.
Standalone Shovey opens on its own cover carousel;
swipe, use the arrows or scroll the wheel to choose, then press Play/Open.
Its desktop startup first draws a small full-colour title preview, then uses
the original artwork when the collection is ready.
Chess is temporarily disabled in Arcade; its code and
existing saved games remain available for a later return.
Each edition has a separate save and earned unlocks. Unlocked puzzles show
their whole board; locked puzzles keep their lock until earned.
The published Arcade carries only its catalog, well under one megabyte. Its host supplies the shared Apps controller (Inner Breeze its own, standalone Arcade the `apps.zx` installed beside it), and the covers and previews download once as one separate art bundle: small copies of each game's art in `assets/arcade/library/` (`python3 scripts/library-art.py` refreshes them when a game's art changes; the build stops until it does). Inner Breeze needs host interface 35 for it. Each game
The published Arcade carries only its catalog, well under one megabyte. Its host supplies the shared Apps controller (Inner Breeze its own, standalone Arcade the `apps.zx` installed beside it), and the covers and previews download once as one separate art bundle. Library covers use thumbnails up to 640 pixels on their longest side, and logos up to 512 pixels, preserving full colours and transparency. Games keep their original artwork. The verified art bundle stays cached across restarts and is replaced when its content changes. The art lives in `assets/arcade/library/` (`python3 scripts/library-art.py` refreshes it when a game's art changes; the build stops until it does). Inner Breeze needs host interface 35 for it. Each game
downloads when opened, with its existing identity and saved progress. This
catalog requires Inner Breeze host API 34. Downloaded games work offline;
catalog requires Inner Breeze host API 41. Downloaded games work offline;
standalone Shovey keeps its complete offline collection. Apfelwurm comes from
its own package, with the same game identity and private editor records.
@@ -44,19 +46,26 @@ review are not implemented.
## Shared Apps library
Arcade embeds the shared `apps.zx` controller and artwork in a verified
catalog. The catalog fixes the digest of every separately downloaded game. Each game package lists its apps in its own `apps.json`:
Arcade includes the reviewed shared `apps.zx` controller and a small seed
catalog. It asks before connecting to its node for the signed app library
and compressed previews. The connection control can switch back to offline;
verified cached apps, previews and saved progress remain available.
The catalog fixes the digest of every separately downloaded game. Each game package lists its apps in its own `apps.json`:
the app's `catalog.json`, and for an app the library opens from a cover, the
cover's portrait art, landscape art, logo, caption and action. `games.json`
names the game packages, and Arcade's own `apps.json` its own apps. Arcade
presents every declared leaf directly, without a second chooser, and a cover
opens its app straight into play or editing. Shovey’s separate standalone
collection uses the same leaves and saves. Kryon’s shared `Carousel` handles
navigation and painting. The local player does not offer node updates or OS
actions it
cannot perform. Inbe supplies its own account and package policy.
navigation and painting. Library refreshes use the reusable Apps signed catalog
loader and do not update the native host. Inbe supplies its own account and package policy.
Arcade's launcher icon is MingCute's `game_2` gamepad (Apache-2.0).
An optional `artwork` mapping in `games.json` names a locked source-only
dependency for a game's library pictures. Its paths still come from that
game's declarations. This lets covers advance independently of playable
code; the thumbnail source hashes remain checked when the catalog builds.
## One Chess game
Chess remains an installable app in Inner Breeze, where it also fits thoughtful
@@ -121,8 +130,44 @@ make
Desktop builds need SDL2, Cairo, FreeType, Fontconfig and Pango development
packages, a C compiler, Python 3 and Ziran. `make install` installs the command
and desktop-menu entry for the current user; it does not publish a release.
Harmony registry delivery and Android builds are not implemented in this first
desktop version.
## Android
Arcade's APK contains only the catalog, shared Apps controller, Entity host,
font and launcher resources. Library thumbnails download when needed; games
and their declared dependencies install after download consent. Installed
games remain available offline, and updates preserve downloads and saves.
Entity keeps ordinary profile pictures; optional game imagery falls back to
the profile picture when absent.
Standalone Shovey retains its complete offline collection. `make android` builds an
unsigned release APK in `build/android/`. `make android-fdroid` and
`make android-gplay` build the other editions; only `-gplay` carries a Google
library (Play Billing). Builds need the Android SDK with NDK 28.2.13676358,
build-tools 36.0.0, platform 36 and CMake 3.22.1, and Java 21.
```sh
make android
python3 scripts/android-release.py sign build/android/arcade-unsigned.apk --version "$(cat VERSION)"
make android-offline-ui-test
```
The release key is `backup/android-signing/arcade-release.p12` (ignored) and
the GitHub secrets `ARCADE_ANDROID_KEYSTORE` and
`ARCADE_ANDROID_KEYSTORE_PASSWORD`; `packaging/android/certificate.pem` is its
public certificate. The Android workflow attaches `arcade-VERSION.apk`,
`arcade-VERSION-fdroid.apk` and `arcade-VERSION-gplay.apk` to a native
`arcade-VERSION` release after verifying all three editions. Existing APKs
on older `node-arcade-VERSION` releases keep their original URLs.
The native host uses root `CHANGELOG.md` and `VERSION`; synchronize a native
release with `sh update_version.sh`. The signed game catalog uses
`catalog/CHANGELOG.md` and `catalog/VERSION`; synchronize its release with
`sh update_version.sh --catalog`. Both use numeric changelog entries and keep
each game's own version ledger. Catalog publication keeps the existing
`node-arcade-VERSION` tags and never starts Android builds. Game updates
advance the catalog only, leaving pending native changes for the next host
release. An APK's embedded seed catalog may have a different version from
its native host.
Game packages are registered in `games.json`; each declares its apps in its
`apps.json`. `scripts/build-games.py` generates the catalog and bundles
@@ -190,14 +235,20 @@ in the person's private data directory.
## Shovey
[Shovey](https://github.com/waozixyz/shovey) has its own repository: Classic,
Island and Editor, their artwork, puzzles and tests live there. Arcade builds
[Shovey](https://github.com/waozixyz/shovey) has its own repository: Classic
and the Editor, their artwork, puzzles and tests live there. Arcade builds
Shovey from that package and offers it as a separate download. Opening Classic
or Editor goes straight to its own screen; Levels lets you replay any unlocked
puzzle. Shovey also runs as its own desktop app.
## Shared Entity profile
Leaderboard is inside the shared Profile, including standalone Arcade and
Shovey. Games report their own level totals under their verified identity;
Profile shows only games that are installed, with friend rankings for a
connected account. Removing a game hides its board while retaining its save
and reported score. Account switches keep rankings separate.
Standalone Shovey's Profile control on its covers opens the shared `entity.zx`
supplied by the Entity package. The host keeps account keys and native file
access behind Entity's versioned management service. Returning from Profile
+1 -1
View File
@@ -1 +1 @@
0.7.82
0.7.117
+1 -1
View File
@@ -1 +1 @@
a81eb5b14d2066925d19c3fd922865af40c90673cf54fb11bd7f9bf89a29cb98
4bed077eacf6879f44fd581d59cfff20b15a813cfbe6c4eecd16535693b99329
+4
View File
@@ -1,5 +1,9 @@
# Chess changelog
## [1.2.1] - 2026-10-29
- Runs in Inner Breeze 2.1.61's smaller app format.
## [1.2.0] - 2026-10-18
- Paste one PGN game or a FEN position into the study board.
+1 -1
View File
@@ -5,7 +5,7 @@
"kind": "game",
"contract_version": 1,
"module_api": 2,
"host_api": 12,
"host_api": 41,
"save_schema": 1,
"harnesses": ["arcade", "inbe"],
"entry": "chess:Main",
+31 -24
View File
@@ -1,49 +1,56 @@
{
"host_api": 12,
"oldest_host_api": 12,
"host_api": 41,
"oldest_host_api": 41,
"module_api": 2,
"node_apps": {
"chess": {
"id": "inbe.chess",
"title": "Chess",
"version": "1.2.0",
"sequence": 5,
"host_api": 12
"version": "1.2.1",
"sequence": 6,
"host_api": 41
},
"choano": {
"id": "xyz.waozi.choano",
"title": "Choano",
"version": "0.1.8",
"sequence": 3,
"host_api": 41
},
"shovey": {
"id": "arcade.shovey",
"title": "Shovey",
"version": "0.6.150",
"sequence": 158,
"host_api": 12
},
"shovey-island": {
"id": "arcade.shovey-island",
"title": "Shovey Island \u2014 Coming Soon",
"version": "0.4.7",
"sequence": 11,
"host_api": 12
"version": "0.6.163",
"sequence": 170,
"host_api": 41
},
"shovey-editor": {
"id": "arcade.shovey-editor",
"title": "Shovey Editor",
"version": "0.2.142",
"sequence": 144,
"host_api": 12
"version": "0.2.147",
"sequence": 149,
"host_api": 41
},
"arcade": {
"id": "inbe.arcade",
"title": "Arcade",
"version": "0.7.82",
"sequence": 161,
"host_api": 36
"version": "0.7.118",
"sequence": 197,
"host_api": 41
},
"wurm": {
"id": "xyz.waozi.wurm",
"title": "Apfelwurm",
"version": "0.1.6",
"sequence": 4,
"host_api": 12
"version": "0.2.28",
"sequence": 23,
"host_api": 41
},
"wurm-editor": {
"id": "xyz.waozi.wurm-editor",
"title": "Apfelwurm Editor",
"version": "0.1.1",
"sequence": 2,
"host_api": 41
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 368 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 145 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 376 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 345 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 332 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

+20 -2
View File
@@ -1,4 +1,13 @@
{
"choano-landscape": {
"source_sha256": "1ca6e31c1062a7cca41bace4cf1bb221291988aea4a1dd61271899c2f5f28307"
},
"choano-portrait": {
"source_sha256": "47b07722c474a67ee4a06b7644a3aff211503674391e363c17eb06a34ce60d6c"
},
"choano-preview": {
"source_sha256": "1ca6e31c1062a7cca41bace4cf1bb221291988aea4a1dd61271899c2f5f28307"
},
"shovey-editor-landscape": {
"source_sha256": "7b1eae4209ede14807806a4cbce1e2bf7a14d342e75c89042958a524cf60d67e"
},
@@ -9,7 +18,7 @@
"source_sha256": "bf0bbeb15249f3d73c1b410e9737f7fd207310dcb5f28b7c3ce45401b77c8f9e"
},
"shovey-editor-preview": {
"source_sha256": "1846b823110fffe82a3dbb319960ce768eefc16699d507d48b8608151eaff430"
"source_sha256": "bcbf63563187f9dcdb6c7580f638e2fb2770b221240ee5699e54dc3c00be172c"
},
"shovey-landscape": {
"source_sha256": "40c01eb8300e4c5db52b2d75373e17cdaf7f68140c33c0a225613fc174660747"
@@ -21,7 +30,16 @@
"source_sha256": "ddcbf989eab5971157d8cdc73494ed03660bb4c7a7679543248f45be260777e3"
},
"shovey-preview": {
"source_sha256": "b1f2e5662cb96f2f5062cb0e5a8cd8ede153173ebc32ad17e26b404f3baf5924"
"source_sha256": "96db251f36835c76cd03cd0104a6e1b5096e4c442d410960457edcd8e2377a38"
},
"wurm-editor-landscape": {
"source_sha256": "b3616e68f1b391d1a4f9dd5d91538a63a889a7f977991e625831ec9caffa71c5"
},
"wurm-editor-portrait": {
"source_sha256": "07ff2ff0142c262cdcba3643bbc4d7d3d71643b7f9f4e678a910fee2bfd3eba1"
},
"wurm-editor-preview": {
"source_sha256": "b3616e68f1b391d1a4f9dd5d91538a63a889a7f977991e625831ec9caffa71c5"
},
"wurm-landscape": {
"source_sha256": "472773b7c106325e12777a81a29209496e22e0853782ca76955b6587824b1b30"
Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 561 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 497 KiB

+21
View File
@@ -0,0 +1,21 @@
# Arcade catalog changelog
## 0.7.118
- Apfelwurm 0.2.28: The editor title painting includes the Apfelwurm Editor logo in portrait and landscape.
- Choano 0.1.8: Keep the Fish HUD clear of the misleading Avoid indicator and introduce the sea with a little fish guide and speech bubbles.
- Choano 0.1.8: Wear a better-fitted ribbon or crown, with three optional Dew decorations: a pearl, a flower, and a wizard hat.
- Choano 0.1.8: Choose decorations by tapping their Shop cards, with clear locks and Dew purchase confirmation.
- Choano 0.1.8: Sign in through the shared Profile in native editions and restore Dew decorations with the same account.
- Choano 0.1.8: Meet a slimmer shark whose fins flash red on contact.
- Choano 0.1.8: Keep Shop and Settings navigation separate and preserve each icon’s original colors.
- Choano 0.1.8: Fit Profile and Downloads beside the title icons on narrow screens.
## 0.7.117
- Game and library updates arrive separately from native Arcade app updates.
- Publish the verified game modules and compressed previews with the aligned shared host dependencies.
## 0.7.116
- Continue the existing signed Arcade catalog and game library release history.
+1
View File
@@ -0,0 +1 @@
0.7.118
+27 -7
View File
@@ -22,6 +22,18 @@ def ledger = new groovy.json.JsonSlurper().parse(file('../../apps/versions.json'
def appRelease = ledger.node_apps[standaloneShovey ? 'shovey' : 'arcade']
def appCodegen = envOrProp('KRYON_PROJECT_CODEGEN', 'app.codegen') ?: 'c99'
// Kryon's three editions: -Papp.edition=direct (the default), fdroid or gplay.
// Only the Google Play edition carries a Google library: Kryon's
// android-gplay.gradle adds Play Billing (kryon/play_billing), so Entity sells
// Dew through Google Play; it needs Android 6 and AndroidX
// (-Pandroid.useAndroidX=true). Native code sees GOOGLE_PLAY or FDROID.
def appEdition = (project.findProperty('app.edition') ?:
(project.findProperty('app.googlePlay') == 'true' ? 'gplay' : 'direct')).toString()
if (!(appEdition in ['direct', 'fdroid', 'gplay'])) {
throw new GradleException('app.edition must be direct, fdroid or gplay')
}
def googlePlay = appEdition == 'gplay'
def requestedMinSdk = Integer.parseInt((project.findProperty('app.minSdk') ?: '21').toString())
def verificationOutput = project.findProperty('app.outputDir')
if (verificationOutput != null) { buildDir = file(verificationOutput) }
@@ -32,11 +44,11 @@ android {
defaultConfig {
applicationId project.findProperty('app.id') ?: (standaloneShovey ? 'xyz.waozi.shovey' : 'xyz.waozi.arcade')
minSdk Integer.parseInt((project.findProperty('app.minSdk') ?: '21').toString())
minSdk googlePlay ? Math.max(requestedMinSdk, 23) : requestedMinSdk
targetSdk 36
versionCode Integer.parseInt((project.findProperty('app.versionCode') ?: appRelease.sequence).toString())
versionName project.findProperty('app.versionName') ?: appRelease.version
manifestPlaceholders = [appLabel: standaloneShovey ? 'Shovey' : 'Arcade', appIcon: standaloneShovey ? '@mipmap/ic_launcher' : '@android:drawable/sym_def_app_icon', zxPlayer: (appCodegen == 'zx').toString(),
manifestPlaceholders = [appLabel: standaloneShovey ? 'Shovey' : 'Arcade', appIcon: '@mipmap/ic_launcher', zxPlayer: (appCodegen == 'zx').toString(),
nativeLaunchMode: appCodegen == 'zx' ? 'singleTask' : 'standard']
ndk {
abiFilters += androidAbis
@@ -47,7 +59,8 @@ android {
'-DZIRAN_DIR=' + ziranDir,
'-DRAYLIB_DIR=' + raylibDir,
'-DAPP_CODEGEN=' + appCodegen,
'-DSHOVEY_STANDALONE=' + (standaloneShovey ? 'ON' : 'OFF')
'-DSHOVEY_STANDALONE=' + (standaloneShovey ? 'ON' : 'OFF'),
'-DAPP_EDITION=' + appEdition
}
}
}
@@ -60,12 +73,12 @@ android {
}
}
sourceSets.main.java.srcDir new File(kryonDir, 'templates/droid/droid/app/src/main/java/org/kryonlabs/platform')
sourceSets.main.assets.srcDir "${rootProject.projectDir}/../build/entity-assets"
// Arcade's collection and receipt, staged by make android.
// The collection, its receipt and the launcher icon, staged by make android
// (scripts/build-android.py).
sourceSets.main.assets.srcDir "${rootProject.projectDir}/../build/${standaloneShovey ? 'android-shovey-assets' : 'android-assets'}"
if (standaloneShovey) {
sourceSets.main.res.srcDir "${rootProject.projectDir}/../build/android-shovey-res"
}
sourceSets.main.res.srcDir "${rootProject.projectDir}/../build/${standaloneShovey ? 'android-shovey-res' : 'android-res'}"
if (appCodegen == 'zx') {
sourceSets.main.assets.srcDir "${rootProject.projectDir}/../build/android/zx-assets"
@@ -80,9 +93,16 @@ android {
}
}
if (googlePlay) {
apply from: new File(kryonDir, 'templates/android-gplay.gradle')
}
// The shared profile is a host asset, never a child of a game collection.
tasks.register('prepareEntity', Exec) {
workingDir file('../..')
commandLine 'python3', 'scripts/build-entity.py'
}
tasks.named('preBuild').configure { dependsOn 'prepareEntity' }
// "Continue as @name" between waozi apps, in every edition.
apply from: new File(kryonDir, 'templates/android-account-handoff.gradle')
+7 -1
View File
@@ -26,6 +26,12 @@ set(APP_ZIRAN_DEFINES --define ANDROID_BUILD)
if(SHOVEY_STANDALONE)
list(APPEND APP_ZIRAN_DEFINES --define SHOVEY_STANDALONE)
endif()
# The app's edition (build.gradle app.edition): Google Play or F-Droid.
if(APP_EDITION STREQUAL "gplay")
list(APPEND APP_ZIRAN_DEFINES --define GOOGLE_PLAY)
elseif(APP_EDITION STREQUAL "fdroid")
list(APPEND APP_ZIRAN_DEFINES --define FDROID)
endif()
if(NOT DEFINED APP_CODEGEN)
set(APP_CODEGEN c99)
endif()
@@ -89,7 +95,7 @@ if(NOT MONOCYPHER_DIR)
endif()
set(OQS_BUILD_ONLY_LIB ON CACHE BOOL "" FORCE)
set(OQS_USE_OPENSSL OFF CACHE BOOL "" FORCE)
set(OQS_MINIMAL_BUILD "SIG_ml_dsa_44" CACHE STRING "" FORCE)
set(OQS_MINIMAL_BUILD "SIG_ml_dsa_44;KEM_ml_kem_768" CACHE STRING "" FORCE)
set(OQS_DIST_BUILD OFF CACHE BOOL "" FORCE)
set(OQS_OPT_TARGET generic CACHE STRING "" FORCE)
foreach(feature ADX AES AVX AVX2 AVX512 AVX512BW AVX512DQ AVX512F BMI1 BMI2 FMA PCLMULQDQ POPCNT SSE SSE2 SSE3 VPCLMULQDQ)
@@ -52,6 +52,8 @@ public class ArcadeActivity extends NativeActivity {
private native void nativeTextInputCommit(int codepoint);
private native void nativeTextInputBackspace();
private native void nativeTextInputEnter();
// Registered by the locked Kryon host even when using key-event input.
private native void nativeTextInputState(long target, long revision, byte[] value, int cursor, int anchor);
private native int nativeSyncLifecycleState(boolean paused, boolean windowFocused);
private native void nativeInvalidateGraphicsResources();
// Kryon's android_picker: a picked file arrives as a private copy's path.
@@ -402,7 +404,7 @@ public class ArcadeActivity extends NativeActivity {
try {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType(mimeTypes == null || mimeTypes.isEmpty() ? "*/*" : mimeTypes);
org.kryonlabs.platform.DocumentTypes.apply(intent, mimeTypes);
startActivityForResult(intent, REQUEST_OPEN_DOCUMENT);
} catch (Exception error) {
Log.e(TAG, "Could not open the document picker", error);
+2 -1
View File
@@ -1,3 +1,4 @@
{
"packages": ["shovey", "wurm"]
"packages": ["shovey", "wurm", "choano"],
"artwork": {"wurm": "wurm_art"}
}
+29
View File
@@ -0,0 +1,29 @@
-----BEGIN CERTIFICATE-----
MIIFBzCCAu+gAwIBAgIIV4HQ6go6XYwwDQYJKoZIhvcNAQEMBQAwMTELMAkGA1UE
BhMCUFkxEjAQBgNVBAoTCXdhb3ppLnh5ejEOMAwGA1UEAxMFV2FvemkwIBcNMjYx
MDI5MjIwNzU3WhgPMjA3NjEwMjgyMjA3NTdaMDExCzAJBgNVBAYTAlBZMRIwEAYD
VQQKEwl3YW96aS54eXoxDjAMBgNVBAMTBVdhb3ppMIICIjANBgkqhkiG9w0BAQEF
AAOCAg8AMIICCgKCAgEAxuar9BhVOeDtMIY1xUFfiEFZZlV+kiTDNWgW/3omykxd
tPz4Y28FgqkV2SX7eEqzMzrsjJ6Z8U2QD1TsY1cTrxjih1f8yhNP5poZAgD6DhHb
ra1DYHXMRJTCJlASUnoZj5xr4M7ha428xit4Fz0IR88TpN6NZsNNwCy5xQSj/cIX
fCTo9n/3itJIGpiKas2J4xancfVSXoLpGBaXf/Vaf/w0UfTxIgImam/U/mx366M+
Vv23XPLBa6csT1EjKTOTB6Oyj3fxDJ/HI7T0pm86eA7hvu+LrQ1v2q1I7DwUg5RG
HoAeFsNnsHSEluVdnuD+7ESnKTkoNlQe8cAiBXvlpcw6uDdpp/2oMktdrd4xt1tU
ozVqiPrvvF/G0Ki1MCS9PXJ6FERBQVjaklPYVa8c2tuXvTcX6VNCpcyFqgNo6AUk
nNkhOhPJ2R0OhQGloG5CcdkjHY1W60gudQKK9MMLjf2+or7ewl/nOkHKhPUKjBQO
UjTlRG6M+hOzZ/rI+LIJsxCZD4xAP6g2oyH0ROR8SXm3x7l+VZ7r9qW0i8cKxOvC
IlX/JQfUkAwcyK0HPQVUPutvtySiMSefZTczvvi+YmiDqr+cxW0T9388SxV+lKQz
Rz+6Tby6OyRDM6bJtXaqZTH+lSdmrAI/lbBx5+Yx8+xgHcfgGbpU2h+WOnqwtCEC
AwEAAaMhMB8wHQYDVR0OBBYEFPTOgtLO/ZKqfXFOQshN7JHi5yVyMA0GCSqGSIb3
DQEBDAUAA4ICAQCxiEH8bPrJlkin92zESDrwXqyfNc7VuoFrANxCD4Mu6/rGU+4V
UIVz3BPhDFZV281ztD0eSJef+P5UX/k4Y0pVIzw82iKAjaMiu8wFZghcFsaADQQn
YEqrU9158++2H2nsxSL2uSen8qPOea7IMll9SUtg+YqAkXqEToqIv60SDFZUpKnb
O3W/NYzVqNKYCk7/HcOYuNf5r76EGVYz6aPHP1CgEpnXNC8NotbH24ZNF3Zgy+UP
ypoNx1jffUK+wQbXkE+IadBhw7B1vPIzCZji1zz54sBxhqvTAKCWE10fMEllSu3v
HRB0x4feOs4tfuX38UdUrFHDxG7vrrNrCRDwnQ6k6FWUVpJRM9CV9jbUe0bcBQfP
SpqJfQMOXPVET799rC4lW4HMGIhfoTkPymYuWZAZx4pF3SYLHor7cQv05a3RuvjP
46xkz9ZA9HNU6P2+mgpRuuFSbxyxi5uyT9z5J/vrU45wq2UjwdNn8J/3o4ITcT9o
jP20JOHovIrprLi8Wzpb/0o1BagRuqlfVoCJrRNCpoZY98ynAM9swlgL+s5O9LVo
mTTtZdDoTyMN+IXxark7oHjUHhWgd/VThTXJu1rQ++vSh/GajYRSOKDjxayGHBp2
rjWy9esT5/VdzFlMfOZefeEjSol8tZdjNCCmWRFuOqF+zw7Lc4I5fXqK8g==
-----END CERTIFICATE-----
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
<background android:drawable="@drawable/ic_launcher_background" />
<foreground android:drawable="@drawable/ic_launcher_foreground" />
</adaptive-icon>
+1
View File
@@ -0,0 +1 @@
196
+6
View File
@@ -0,0 +1,6 @@
{
"origin": "https://api.waozi.xyz",
"app_id": "inbe.arcade",
"key_id": "inbe-2026-10",
"public_key": "d9a549043c0ac91a5197d85053a815c831d342a1082143c2bd1ffd43e1e6f145"
}
+145
View File
@@ -0,0 +1,145 @@
#!/usr/bin/env python3
"""Sign and verify Arcade's Android APKs: the normal and F-Droid editions,
which hold no Google library, and the Google Play edition, the only one with
Play Billing. Arcade downloads games on demand."""
import argparse
import hashlib
import json
import os
from pathlib import Path
import re
import shutil
import subprocess
import zipfile
ROOT = Path(__file__).resolve().parents[1]
ABIS = ['arm64-v8a', 'armeabi-v7a']
def verify_launcher(apk, tools, names):
"""Resolve compiled resource IDs, including shortened release paths."""
resources = subprocess.check_output(
[str(tools / 'aapt'), 'dump', '--values', 'resources', str(apk)], text=True)
entries = re.findall(r'resource (0x[0-9a-f]+) [^\n]+:(drawable/ic_launcher_\w+|mipmap/ic_launcher):[^\n]*\n\s*\(string8\) "([^"]+)"', resources)
paths = {path for _, _, path in entries}
assert paths <= set(names), 'A launcher resource is missing from the APK'
legacy = [path for _, name, path in entries if name == 'mipmap/ic_launcher' and path.endswith('.png')]
assert len(legacy) == 5, 'All five legacy icon densities must be present'
adaptive = [path for _, name, path in entries if name == 'mipmap/ic_launcher' and path.endswith('.xml')]
assert len(adaptive) == 1 and 'config anydpi-v26:' in resources, 'The Android adaptive icon is missing'
layers = {name: identifier for identifier, name, _ in entries if name.startswith('drawable/')}
tree = subprocess.check_output(
[str(tools / 'aapt'), 'dump', 'xmltree', str(apk), adaptive[0]], text=True)
assert 'E: adaptive-icon' in tree, 'The launcher XML is not adaptive'
for layer in ('background', 'foreground'):
identifier = layers.get('drawable/ic_launcher_' + layer)
assert identifier and re.search(r'E: ' + layer + r'[^\n]*\n[^\n]*@' + identifier, tree), \
f'The adaptive {layer} drawable is missing'
def build_tools():
sdk = Path(os.environ.get('ANDROID_SDK_ROOT') or os.environ.get('ANDROID_HOME') or Path.home() / 'Android/Sdk')
folders = sorted((sdk / 'build-tools').glob('*'), key=lambda p: tuple(int(n) for n in re.findall(r'\d+', p.name)))
return next(p for p in reversed(folders) if all((p / name).is_file() for name in ('aapt', 'apksigner', 'zipalign')))
def verify(apk, version, tools, edition='direct'):
assert re.fullmatch(r'\d+\.\d+\.\d+', version), 'A numeric release version is required'
changelog = (ROOT / 'CHANGELOG.md').read_text()
assert re.search(r'^## \[?' + re.escape(version) + r'\]?\s', changelog, re.M), 'Release version is absent from the changelog'
badging = subprocess.check_output([str(tools / 'aapt'), 'dump', 'badging', str(apk)], text=True)
package = re.search(r"^package: name='([^']+)' versionCode='(\d+)' versionName='([^']+)'", badging, re.M)
assert package and package[1] == 'xyz.waozi.arcade' and package[3] == version, 'APK identity or version differs'
assert "application-label:'Arcade'" in badging, 'The APK is not labelled Arcade'
# Release builds shorten resource names; the manifest names the icon.
icon = re.search(r"^application: label='Arcade' icon='(res/[^']+\.(?:png|xml))'", badging, re.M)
assert icon, "Arcade's launcher icon is missing"
assert 'application-debuggable' not in badging, 'A debug build cannot be published'
google_play = edition == 'gplay'
assert ("'com.android.vending.BILLING'" in badging) == google_play, \
'Only the Google Play edition may ask for Play Billing'
certificate = subprocess.check_output(['openssl', 'x509', '-in', str(ROOT / 'packaging/android/certificate.pem'), '-outform', 'DER'])
expected = hashlib.sha256(certificate).hexdigest()
signature = subprocess.check_output([str(tools / 'apksigner'), 'verify', '--verbose', '--print-certs', str(apk)], text=True)
actual = re.findall(r'^(?:Signer #\d+|V[\d.]+ Signer:) certificate SHA-256 digest: ([0-9a-f]+)$', signature, re.M)
assert 'Number of signers: 1' in signature and set(actual) == {expected}, 'APK signer differs from the Arcade release certificate'
subprocess.run([str(tools / 'zipalign'), '-c', '-P', '16', '4', str(apk)], check=True, capture_output=True)
with zipfile.ZipFile(apk) as archive:
names = archive.namelist()
abis = sorted(p.split('/')[1] for p in names if re.fullmatch(r'lib/[^/]+/libmain\.so', p))
assert abis == ABIS, 'Both supported ARM architectures must be present'
assert icon[1] in names, "Arcade's launcher icon is missing"
if tuple(map(int, version.split('.'))) >= (0, 7, 115):
verify_launcher(apk, tools, names)
metadata = json.loads(archive.read('assets/arcade.json'))
payload = archive.read('assets/arcade.zx')
assert metadata['id'] == 'inbe.arcade', 'Embedded catalog identity differs'
catalog_version = (ROOT / 'catalog/VERSION').read_text().strip()
assert re.fullmatch(r'\d+\.\d+\.\d+', catalog_version), 'A numeric catalog version is required'
assert metadata['version'] == catalog_version, 'Embedded catalog version differs from its source'
assert metadata['sha256'] == hashlib.sha256(payload).hexdigest(), 'Embedded collection differs from its receipt'
from android_catalog import verify_assets
verify_assets({name.removeprefix('assets/'): archive.read(name)
for name in names if name.startswith('assets/') and not name.endswith('/')}, edition=edition)
dex = b''.join(archive.read(name) for name in names if re.fullmatch(r'classes\d*\.dex', name))
for marker in (b'Lorg/kryonlabs/play/PlayBilling;', b'Lcom/android/billingclient/'):
assert (marker in dex) == google_play, 'Only the Google Play edition may include Play Billing'
with apk.open('rb') as source:
apk_digest = hashlib.file_digest(source, 'sha256').hexdigest()
return dict(version=version, version_code=int(package[2]), package=package[1], abis=abis, edition=edition,
sha256=apk_digest, certificate_sha256=expected,
catalog_version=metadata['version'], payload_sha256=metadata['sha256'], games=[child['id'] for child in metadata['children']],
bytes=apk.stat().st_size)
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('action', choices=('sign', 'verify'))
parser.add_argument('apk', type=Path)
parser.add_argument('--version', required=True)
parser.add_argument('--edition', choices=('direct', 'fdroid', 'gplay'), default='direct')
parser.add_argument('--output', type=Path, help='Signed APK; build/android/arcade-VERSION[-EDITION].apk by default')
parser.add_argument('--keystore', type=Path, default=ROOT / 'backup/android-signing/arcade-release.p12')
parser.add_argument('--password-file', type=Path, default=ROOT / 'backup/android-signing/password')
parser.add_argument('--alias', default='arcade')
args = parser.parse_args()
tools = build_tools()
apk = args.apk.resolve(strict=True)
if args.action == 'verify':
verify(apk, args.version, tools, args.edition)
print(f'Arcade {args.version} {args.edition}: APK identity, signer, alignment and thin catalog verified')
return
suffix = '' if args.edition == 'direct' else '-' + args.edition
output = (args.output or ROOT / f'build/android/arcade-{args.version}{suffix}.apk').resolve()
output.parent.mkdir(parents=True, exist_ok=True)
aligned = output.with_name(output.stem + '.aligned-unsigned.apk')
temporary = output.with_name(output.stem + '.new.apk')
if subprocess.run([str(tools / 'zipalign'), '-c', '-P', '16', '4', str(apk)], capture_output=True).returncode == 0:
shutil.copyfile(apk, aligned)
else:
subprocess.run([str(tools / 'zipalign'), '-P', '16', '-f', '4', str(apk), str(aligned)], check=True)
try:
# Keep the aligned entries as they are, so a rebuild from source can
# take this signature unchanged.
subprocess.run([str(tools / 'apksigner'), 'sign', '--alignment-preserved',
'--ks', str(args.keystore.resolve(strict=True)), '--ks-key-alias', args.alias,
'--ks-pass', 'file:' + str(args.password_file.resolve(strict=True)),
'--out', str(temporary), str(aligned)], check=True)
finally:
aligned.unlink(missing_ok=True)
try:
result = verify(temporary, args.version, tools, args.edition)
except BaseException:
temporary.unlink(missing_ok=True)
raise
temporary.replace(output)
temporary.with_name(temporary.name + '.idsig').unlink(missing_ok=True)
result['apk'] = str(output)
records = ROOT / 'backup/android-release'
records.mkdir(parents=True, exist_ok=True)
(records / f'verification{suffix}.json').write_text(json.dumps(result, indent=2) + '\n')
print(f'Arcade {args.version} {args.edition}: signed {output}; identity, signer, alignment and thin catalog verified')
if __name__ == '__main__':
main()
+95
View File
@@ -0,0 +1,95 @@
"""Strict content boundary for the thin Android Arcade launcher."""
import hashlib
import io
import json
import struct
import subprocess
from functools import lru_cache
from pathlib import Path
from node_config import node_source
ROOT = Path(__file__).resolve().parents[1]
ESSENTIALS = {'arcade.zx', 'arcade.json', 'apps.zx', 'entity.zx', 'kryon-font.ttf'}
@lru_cache(maxsize=1)
def profile_asset_hashes():
flags = [] if (ROOT / 'ziran.local.toml').is_file() else ['--locked']
package = Path(subprocess.check_output(
[str(ROOT / 'scripts/ziran.sh'), 'pkg', 'path', 'entity', *flags],
cwd=ROOT, text=True).strip())
paths = json.loads((package / 'asset-groups.json').read_text())['profile']
result = {}
for path in paths:
with (package / path).open('rb') as source:
result[path] = hashlib.file_digest(source, 'sha256').hexdigest()
return result
def profile_assets():
return set(profile_asset_hashes())
def bundle_assets(payload, limit):
# The catalog is tiny. Reject packed collections before allocating/reading
# their contents, then inspect every actual asset rather than path strings
# in the JSON (which intentionally names remote game and art resources).
assert len(payload) <= limit, 'Bundle exceeds its asset policy budget'
stream = io.BytesIO(payload)
def take(size):
assert 0 <= size <= len(payload), 'Invalid bundle field'
data = stream.read(size)
assert len(data) == size, 'Truncated bundle'
return data
def number():
return struct.unpack('<I', take(4))[0]
def text():
return take(number())
# ZX 26 and 27 share this layout; 27 only marks composed library modules.
assert take(8) in (b'ZX\0\0\x1a\0\0\0', b'ZX\0\0\x1b\0\0\0'), 'Unsupported catalog bundle'
text(); text()
for _ in range(number()):
text(); text()
for _ in range(number()):
for _ in range(7):
text()
take(8); text(); take(4)
for _ in range(number()):
text(); text(); text()
take(number())
assets = {}
for _ in range(number()):
name = text().decode()
assert name not in assets, 'Duplicate bundle asset'
assets[name] = take(number())
assert not stream.read(1), 'Trailing bundle bytes'
return assets
def catalog_assets(payload):
assets = bundle_assets(payload, 256 * 1024)
assert set(assets) == {'assets/apps/catalog.json', 'assets/arcade/sidebar.shape'}, 'Game payload or art bundled in Arcade'
return json.loads(assets['assets/apps/catalog.json'])
def verify_assets(assets, essentials=True, edition='direct'):
expected = ESSENTIALS if essentials else ESSENTIALS - {'entity.zx', 'kryon-font.ttf'}
if essentials and edition == 'gplay':
# AndroidX's generated ART startup profiles accompany Play Billing.
expected = expected | {'dexopt/baseline.prof', 'dexopt/baseline.profm'}
assert set(assets) == expected, 'Unexpected or missing Android asset: ' + str(set(assets) ^ expected)
metadata = json.loads(assets['arcade.json'])
assert metadata['id'] == 'inbe.arcade' and metadata.get('games') != 'packed'
assert metadata.get('node') == node_source(ROOT), 'Node publisher binding differs from the reviewed host configuration'
assert hashlib.sha256(assets['arcade.zx']).hexdigest() == metadata['sha256']
trusted = (ROOT / 'apps-controller.sha256').read_text().strip()
assert hashlib.sha256(assets['apps.zx']).hexdigest() == metadata['apps_sha256'] == trusted
if essentials:
pictures = bundle_assets(assets['entity.zx'], 16 * 1024 * 1024)
assert set(pictures) == profile_assets(), 'Entity contains undeclared or game artwork'
assert {name: hashlib.sha256(data).hexdigest() for name, data in pictures.items()} == profile_asset_hashes(), 'Entity profile artwork differs from its pinned declaration'
assert not bundle_assets(assets['apps.zx'], 2 * 1024 * 1024), 'Apps controller must contain no art or game payloads'
catalog = catalog_assets(assets['arcade.zx'])
assert catalog['children'] == metadata['children'] and catalog['art'] == metadata['art']
assert catalog['harness'] == 'assets/apps/apps.zx'
return metadata
+97 -21
View File
@@ -1,28 +1,75 @@
#!/usr/bin/env python3
"""Package Arcade's existing native host with the standalone Shovey collection."""
"""Package Arcade's native Android host: a thin on-demand launcher,
or the older standalone Shovey collection."""
import argparse
import hashlib
import json
import os
import re
from pathlib import Path
import shutil
import subprocess
from PIL import Image
ROOT = Path(__file__).resolve().parents[1]
def native_release():
version = (ROOT / 'VERSION').read_text().strip()
code = int((ROOT / 'packaging/android/version-code').read_text().strip())
if not re.fullmatch(r'(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)', version) or not 0 < code <= 2100000000:
raise ValueError('Invalid native Android version or versionCode')
return dict(version=version, sequence=code)
def package(name):
return Path(subprocess.check_output([str(ROOT / 'scripts/ziran.sh'), 'pkg', 'path', name], cwd=ROOT, text=True).strip())
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--release', action='store_true', help='Build an unsigned release APK for the release signer')
parser.add_argument('--bundle', action='store_true', help='Build an unsigned release Android App Bundle for Google Play')
parser.add_argument('--application-id', help='Use an isolated package for device tests')
parser.add_argument('--abis', default='arm64-v8a,armeabi-v7a', help='Native ABIs to build')
parser.add_argument('--build-dir', type=Path, help='Separate Gradle and CMake output for verification')
args = parser.parse_args()
subprocess.run(['make', 'build/entity.zx'], cwd=ROOT, check=True)
def ziran_bundle(*arguments):
# A local checkout overrides packages in ziran.local.toml, as make does.
locked = [] if (ROOT / 'ziran.local.toml').exists() else ['--locked']
subprocess.run([str(ROOT / 'scripts/ziran.sh'), 'bundle', '--project', *locked, *arguments],
cwd=ROOT, check=True)
def launcher_icon(source, resources):
"""Density variants are mechanical packaging of the original logo."""
from PIL import Image
icon = Image.open(source).convert('RGBA')
if resources.exists():
shutil.rmtree(resources)
for density, size in (('mdpi', 48), ('hdpi', 72), ('xhdpi', 96), ('xxhdpi', 144), ('xxxhdpi', 192)):
folder = resources / ('mipmap-' + density)
folder.mkdir(parents=True)
icon.resize((size, size), Image.Resampling.LANCZOS).save(folder / 'ic_launcher.png')
def stage_arcade():
"""Stage the catalog and reviewed shared controller without game payloads. Returns Arcade's release."""
collection = ROOT / 'build/collection'
receipt = json.loads((collection / 'receipt.json').read_text())
release = json.loads((ROOT / 'apps/versions.json').read_text())['node_apps']['arcade']
if receipt['version'] != release['version'] or receipt['version'] != (ROOT / 'catalog/VERSION').read_text().strip():
raise ValueError('The Arcade version changed; rebuild the collection first')
controller = (collection / 'assets/apps/apps.zx').read_bytes()
if hashlib.sha256(controller).hexdigest() != receipt['apps_sha256']:
raise ValueError('The staged Apps controller differs from the receipt')
assets = ROOT / 'build/android-assets'
if assets.exists():
shutil.rmtree(assets)
assets.mkdir(parents=True)
# Reuse the standard thin catalog; standalone Shovey remains packed.
for name in ('arcade.zx', 'arcade.json'):
shutil.copyfile(ROOT / 'build' / name, assets / name)
shutil.copyfile(collection / 'assets/apps/apps.zx', assets / 'apps.zx')
from android_catalog import verify_assets
metadata = verify_assets({p.name: p.read_bytes() for p in assets.iterdir()}, essentials=False)
if metadata['version'] != release['version']:
raise ValueError('The thin catalog version changed; rebuild the collection first')
# Android before 10 has no font lookup; the Windows build ships the same font.
shutil.copyfile(package('kryon') / 'assets/fonts/LiberationSans-Regular.ttf', assets / 'kryon-font.ttf')
launcher_icon(ROOT / 'site/android-launcher-512.png', ROOT / 'build/android-res')
# Only Arcade gets this adaptive icon; standalone Shovey keeps its art.
shutil.copytree(ROOT / 'packaging/android/icon-res', ROOT / 'build/android-res', dirs_exist_ok=True)
return native_release()
def stage_shovey():
"""Shovey's standalone collection from Arcade's staging. Returns its release."""
metadata = json.loads((ROOT / 'build/shovey.json').read_text())
payload = (ROOT / 'build/shovey.zx').read_bytes()
if hashlib.sha256(payload).hexdigest() != metadata['sha256']:
@@ -34,26 +81,47 @@ def main():
assets.mkdir(parents=True, exist_ok=True)
for suffix in ('zx', 'json'):
shutil.copyfile(ROOT / f'build/shovey.{suffix}', assets / f'arcade.{suffix}')
# Android before 10 has no font lookup; the Windows build ships the same font.
shutil.copyfile(package('kryon') / 'assets/fonts/LiberationSans-Regular.ttf', assets / 'kryon-font.ttf')
# Density variants are mechanical packaging of the original generated logo.
icon = Image.open(package('shovey') / 'assets/branding/shovey-icon.png').convert('RGBA')
resources = ROOT / 'build/android-shovey-res'
for density, size in (('mdpi', 48), ('hdpi', 72), ('xhdpi', 96), ('xxhdpi', 144), ('xxxhdpi', 192)):
folder = resources / ('mipmap-' + density)
folder.mkdir(parents=True, exist_ok=True)
icon.resize((size, size), Image.Resampling.LANCZOS).save(folder / 'ic_launcher.png')
launcher_icon(package('shovey') / 'assets/branding/shovey-icon.png', ROOT / 'build/android-shovey-res')
return release
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--product', choices=('shovey', 'arcade'), default='shovey',
help='arcade: thin Arcade launcher; shovey: the standalone Shovey collection')
parser.add_argument('--release', action='store_true', help='Build an unsigned release APK for the release signer')
parser.add_argument('--edition', choices=('direct', 'fdroid', 'gplay'), default='direct',
help='The APK edition; only gplay carries a Google library')
parser.add_argument('--bundle', action='store_true',
help="Build the Google Play edition's unsigned release Android App Bundle")
parser.add_argument('--application-id', help='Use an isolated package for device tests')
parser.add_argument('--abis', default='arm64-v8a,armeabi-v7a', help='Native ABIs to build')
parser.add_argument('--build-dir', type=Path, help='Separate Gradle and CMake output for verification')
args = parser.parse_args()
subprocess.run(['python3', str(ROOT / 'tests/android_jni_contract_test.py')],
cwd=ROOT, check=True)
arcade = args.product == 'arcade'
if arcade and args.bundle:
parser.error('Arcade builds APKs; the App Bundle is the standalone Shovey one')
subprocess.run(['make', 'build/entity.zx'], cwd=ROOT, check=True)
release = stage_arcade() if arcade else stage_shovey()
sdk = Path(os.environ.get('ANDROID_SDK_ROOT') or os.environ.get('ANDROID_HOME') or Path.home() / 'Android/Sdk')
env = {key: value for key, value in os.environ.items() if key not in ('DISPLAY', 'WAYLAND_DISPLAY', 'XAUTHORITY', 'DBUS_SESSION_BUS_ADDRESS')}
env.update(ANDROID_HOME=str(sdk), ANDROID_SDK_ROOT=str(sdk),
LIBOQS_DIR=str(package('liboqs')), MONOCYPHER_DIR=str(package('monocypher')))
command = ['sh', str(ROOT / 'droid/gradlew'), '-p', str(ROOT / 'droid'), '--no-daemon', '--max-workers=2',
'-Papp.product=shovey', '-Papp.abis=' + args.abis,
'-Papp.product=' + args.product, '-Papp.abis=' + args.abis,
'-Pkryon.dir=' + str(package('kryon')), '-Pziran.dir=' + str(package('ziran')),
'-Praylib.dir=' + str(package('raylib') / 'src'),
'-Papp.versionName=' + metadata['version'], '-Papp.versionCode=' + str(release['sequence']),
'-Papp.versionName=' + release['version'], '-Papp.versionCode=' + str(release['sequence']),
'-Pandroid.aapt2FromMavenOverride=' + str(sdk / 'build-tools/36.0.0/aapt2'),
'bundleRelease' if args.bundle else 'assembleRelease' if args.release else 'assembleDebug']
# Kryon's Google Play edition adds Play Billing, so Dew is bought through Play.
edition = 'gplay' if args.bundle else args.edition
if edition == 'gplay':
command[-1:-1] = ['-Papp.edition=gplay', '-Pandroid.useAndroidX=true']
elif edition == 'fdroid':
command.insert(-1, '-Papp.edition=fdroid')
if args.application_id:
command.insert(-1, '-Papp.id=' + args.application_id)
if args.build_dir:
@@ -68,6 +136,14 @@ def main():
return
apk = app_output / ('outputs/apk/release/app-release-unsigned.apk' if args.release else
'outputs/apk/debug/app-debug.apk')
if arcade:
suffix = '' if edition == 'direct' else '-' + edition
output = ROOT / 'build/android' / (f'arcade{suffix}-unsigned.apk' if args.release else f'arcade{suffix}.apk')
output.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(apk, output)
subprocess.run(['python3', str(ROOT / 'tests/android_catalog_test.py'), str(output), '--edition', edition], cwd=ROOT, check=True)
print(f'Arcade APK: {output}')
return
output = ROOT / ('build/shovey-test-unsigned.apk' if args.application_id else
'build/shovey-unsigned.apk' if args.release else 'build/shovey.apk')
shutil.copyfile(apk, output)
+21 -2
View File
@@ -47,8 +47,27 @@ def build(root, output):
controller_context(root, context)
package = Path(subprocess.check_output(
['ziran', 'pkg', 'path', 'apps', '--locked'], cwd=context, text=True).strip())
subprocess.run([sys.executable, str(package / 'scripts/build-ui.py'),
'--output', str(output.resolve())], cwd=root, check=True)
subprocess.run([sys.executable, str(package / 'scripts/generate-ui-locales.py'), '--check'],
cwd=root, check=True)
toolchain = Path(subprocess.check_output(
['ziran', 'pkg', 'path', 'ziran', '--locked'], cwd=context, text=True).strip())
compiler = toolchain / 'build/bin/ziran'
if not compiler.is_file():
compiler = root / 'build/toolchain/bin/ziran'
subprocess.run(['make', '-s', '-C', str(toolchain),
'BUILD_DIR=' + str(root / 'build/toolchain'), 'all'], check=True)
output.mkdir(parents=True, exist_ok=True)
kryon = Path(subprocess.check_output(
['ziran', 'pkg', 'path', 'kryon', '--locked'], cwd=context, text=True).strip())
# Keep Apps' supported source entry mode with this host's exact graph.
subprocess.run([str(compiler), 'bundle',
'--module-path', str(package / 'src'),
'--module-path', 'kryon=' + str(kryon / 'src/ui'),
'--module-path', 'kryon=' + str(kryon / 'src/backend'),
'--module-path', str(toolchain / 'std'),
'--root', str(package / 'ui'), '--entry', 'apps:Main',
'--define', 'KRYON_HOSTED_UI', '-o', str(output.resolve() / 'apps.zx'),
str(package / 'ui/apps.zi')], cwd=context, check=True)
def main():
+103 -37
View File
@@ -10,27 +10,77 @@ import re
import shutil
import subprocess
import tarfile
import tempfile
from game_packages import declared_packages
from node_config import node_source
ROOT = Path(__file__).resolve().parents[1]
MAX_PAYLOAD_BYTES = 64 * 1024 * 1024
MAX_GAMES = 16
def payload_limit(size, label):
if size > MAX_PAYLOAD_BYTES:
raise ValueError(f"{label} exceeds the host's payload limit")
def catalog_bytes(catalog):
return (json.dumps(catalog, indent=2) + "\n").encode()
def child_paths(child):
return [child["bundle"], child["preview"], *(
value for key, value in child.get("cover", {}).items()
if key in ("portrait", "landscape", "logo"))]
def package_catalog(package, children):
return dict(schema=1, id=package["id"], title=package["title"],
harness="assets/apps/apps.zx", children=children)
def bundle(command, root, source, entry, assets, target, env):
"""Check the complete ZX (including code/index overhead) before promotion."""
work = root / "work"
subprocess.run(["git", "check-ignore", "-q", "work/"], cwd=root, check=True)
work.mkdir(exist_ok=True)
with tempfile.TemporaryDirectory(prefix="collection-bundle-", dir=work) as directory:
candidate = Path(directory) / target.name
subprocess.run([*command, "--root", str(root / "src"), "--entry", entry,
"--asset-dir", "assets=" + str(assets), "-o", str(candidate),
str(root / "src" / source)], cwd=root, env=env, check=True)
payload_limit(candidate.stat().st_size, target.name)
target.parent.mkdir(parents=True, exist_ok=True)
candidate.replace(target)
def digest(path):
return hashlib.sha256(path.read_bytes()).hexdigest()
def catalog_version(root):
"""The node receipt must name the synchronized catalog release."""
version = (root / "catalog/VERSION").read_text().strip()
component = json.loads((root / "apps/versions.json").read_text())["node_apps"]["arcade"]
if (not re.fullmatch(r"\d+\.\d+\.\d+", version)
or component["id"] != "inbe.arcade" or component["version"] != version):
raise ValueError("Catalog version differs from its signed release ledger; run update_version.sh --catalog")
return version
def library_art(root, name, key, source):
"""Arcade's committed small copy of a game's art (scripts/library-art.py).
The library shows art, the games download separately: never pack the
packages' full-size images, and never pack a copy of outdated art."""
"""Arcade's committed library thumbnail (scripts/library-art.py), as
(bytes, suffix): a PNG, or a JPEG for opaque cover art. Never pack a copy
of outdated art."""
library = Path(root) / "assets/arcade/library"
sources = json.loads((library / "sources.json").read_text())
copy = f"{name}-{key}"
if sources.get(copy, {}).get("source_sha256") != hashlib.sha256(source).hexdigest():
raise ValueError(f"{copy} art changed; run scripts/library-art.py")
return (library / f"{copy}.png").read_bytes()
for suffix in (".png", ".jpg"):
if (library / (copy + suffix)).is_file():
return (library / (copy + suffix)).read_bytes(), suffix
raise ValueError(f"{copy} has no library copy; run scripts/library-art.py")
def stage(root, controller, expected_controller_digest, output):
@@ -38,17 +88,20 @@ def stage(root, controller, expected_controller_digest, output):
catalog and each game package with the IDs of its packed apps."""
if not re.fullmatch(r"[0-9a-f]{64}", expected_controller_digest):
raise ValueError("An exact trusted Apps controller SHA-256 is required")
payload_limit(controller.stat().st_size, "Apps controller")
controller_bytes = controller.read_bytes()
if hashlib.sha256(controller_bytes).hexdigest() != expected_controller_digest:
raise ValueError("Apps controller differs from the trusted SHA-256")
packages = declared_packages(root)
controller_digest = hashlib.sha256(controller_bytes).hexdigest()
if controller_digest != expected_controller_digest:
raise ValueError(f"Apps controller differs from the trusted SHA-256: {controller_digest} != {expected_controller_digest}")
payload_limit(len(controller_bytes), "Apps controller")
lock_flags = () if (root / "ziran.local.toml").is_file() else ("--locked",)
packages = declared_packages(root, lock_flags=lock_flags)
arcade = packages[0]
if not 1 <= sum(len(package["apps"]) for package in packages) <= MAX_GAMES:
raise ValueError("Arcade needs 1 to 16 games")
ledger = json.loads((root / "apps/versions.json").read_text())["node_apps"]
children, copies, identities = [], [], set()
collection_ids = {package["id"] for package in packages}
total = len(controller_bytes)
for package in packages:
package["children"] = []
for app in package["apps"]:
@@ -73,19 +126,21 @@ def stage(root, controller, expected_controller_digest, output):
preview = root / "build/games" / (name + "-preview.png")
# The game build embeds this exact legacy descriptor. Its verified
# name binds node/2's legacy handshake to the stable signed app ID.
payload_limit(bundle.stat().st_size, f"Game {name}")
bundle_bytes, preview_bytes = bundle.read_bytes(), preview.read_bytes()
if not bundle_bytes or not preview_bytes:
raise ValueError("Game bundles and previews must be built first")
preview_bytes = library_art(root, name, "preview", preview_bytes)
total += len(bundle_bytes) + len(preview_bytes)
payload_limit(len(bundle_bytes), f"Game {name}")
preview_bytes, preview_suffix = library_art(root, name, "preview",
(app["art_source"] / game["preview"]).read_bytes())
child = dict(
id=identifier, title=game["title"],
bundle=f"assets/arcade/games/{name}.zx", protocol="node/2",
expected_id=name, version=component["version"],
sha256=hashlib.sha256(bundle_bytes).hexdigest(),
bytes=len(bundle_bytes),
preview=f"assets/arcade/previews/{name}.png",
icon=f"assets/arcade/previews/{name}.png")
preview=f"assets/arcade/previews/{name}{preview_suffix}",
icon=f"assets/arcade/previews/{name}{preview_suffix}")
# A thin add-on links its required games' verified code as libraries.
if app.get('shared_code'):
child['shared_code'] = True
@@ -106,22 +161,37 @@ def stage(root, controller, expected_controller_digest, output):
if key not in cover:
continue
relative = Path(cover[key])
if relative.is_absolute() or ".." in relative.parts or relative.suffix != ".png":
if relative.is_absolute() or ".." in relative.parts or relative.suffix not in {".png", ".jpg"}:
raise ValueError("Invalid cover asset path")
contents = library_art(root, name, key, (app["source"] / relative).read_bytes())
destination = Path("arcade/covers") / f"{name}-{key}.png"
contents, suffix = library_art(root, name, key, (app["art_source"] / relative).read_bytes())
destination = Path("arcade/covers") / f"{name}-{key}{suffix}"
packed_cover[key] = "assets/" + destination.as_posix()
copies.append((contents, destination))
total += len(contents)
child["cover"] = packed_cover
children.append(child)
package["children"].append(identifier)
copies += [(bundle_bytes, Path("arcade/games") / (name + ".zx")),
(preview_bytes, Path("arcade/previews") / (name + ".png"))]
if total > MAX_PAYLOAD_BYTES:
raise ValueError("Arcade collection exceeds the host's payload limit")
(preview_bytes, Path("arcade/previews") / (name + preview_suffix))]
catalog = dict(schema=1, id=arcade["id"], title=arcade["title"],
harness="assets/apps/apps.zx", presentation={"mode": "covers"}, children=children)
sidebar = (root / "assets/arcade/sidebar.shape").read_bytes()
# The stage is a source for several independently loaded roots, not one
# root containing the whole library. Bound their input bytes separately;
# bundle() also checks the final compiled sizes, including ZX overhead.
payloads = {"assets/" + path.as_posix(): data for data, path in copies}
art_paths = {path for child in children for path in child_paths(child)[1:]}
payload_limit(sum(len(payloads[path]) for path in art_paths), "Library art")
payload_limit(len(catalog_bytes(catalog)) + len(sidebar), "Arcade catalog")
for package in packages[1:]:
if not (root / "src" / f"{package['name']}_collection.zi").is_file():
continue
leaves = [child for child in children if child["id"] in package["children"]]
if not leaves:
raise ValueError(f"{package['name']} declares no enabled apps")
paths = {path for child in leaves for path in child_paths(child)}
size = (len(controller_bytes) + len(catalog_bytes(package_catalog(package, leaves)))
+ sum(len(payloads[path]) for path in paths))
payload_limit(size, f"Standalone {package['name']}")
# This stable directory contains disposable build output only. Clear it
# after all inputs validate so removed registrations cannot linger.
if output.exists():
@@ -129,14 +199,14 @@ def stage(root, controller, expected_controller_digest, output):
assets = output / "assets"
(assets / "apps").mkdir(parents=True)
(assets / "apps/apps.zx").write_bytes(controller_bytes)
(assets / "apps/catalog.json").write_text(json.dumps(catalog, indent=2) + "\n")
(assets / "apps/catalog.json").write_bytes(catalog_bytes(catalog))
for contents, relative in copies:
destination = assets / relative
destination.parent.mkdir(parents=True, exist_ok=True)
destination.write_bytes(contents)
# Inbe draws Arcade's launcher icon from assets/arcade/sidebar.shape.
(assets / "arcade").mkdir(exist_ok=True)
(assets / "arcade/sidebar.shape").write_bytes((root / "assets/arcade/sidebar.shape").read_bytes())
(assets / "arcade/sidebar.shape").write_bytes(sidebar)
return catalog, packages[1:]
@@ -154,6 +224,7 @@ def stage_downloads(catalog, source, output, games, art):
data = (source / child["bundle"]).read_bytes()
if hashlib.sha256(data).hexdigest() != child["sha256"]:
raise ValueError("Game differs from the collection's declared digest")
payload_limit(len(data), f"Game {child['id']}")
payloads[child["sha256"]] = data
for directory in (output, games, art):
if directory.exists():
@@ -178,6 +249,7 @@ def stage_downloads(catalog, source, output, games, art):
def add_art(output, games, art_bundle):
"""Publish the art bundle beside the games and name it in the catalog."""
data = art_bundle.read_bytes()
payload_limit(len(data), "Library art bundle")
digest = hashlib.sha256(data).hexdigest()
(games / (digest + ".zx")).write_bytes(data)
path = output / "assets/apps/catalog.json"
@@ -205,14 +277,11 @@ def main():
parser.add_argument("--apps-bundle", type=Path, required=True)
parser.add_argument("--apps-sha256", required=True)
args = parser.parse_args()
version = catalog_version(ROOT)
output = ROOT / "build/collection"
catalog, packages = stage(ROOT, args.apps_bundle, args.apps_sha256, output)
command = [args.ziran, "bundle", "--project", *(["--locked"] if args.locked else [])]
env = os.environ.copy()
def bundle(source, entry, assets, target):
subprocess.run([*command, "--root", str(ROOT / "src"), "--entry", entry,
"--asset-dir", "assets=" + str(assets), "-o", str(target),
str(ROOT / "src" / source)], cwd=ROOT, env=env, check=True)
# A game package with a standalone player (src/NAME_collection.zi) also
# gets its own collection of exactly the leaves Arcade packs, with their
@@ -230,18 +299,15 @@ def main():
assets = standalone / "assets"
(assets / "apps").mkdir(parents=True)
shutil.copyfile(output / "assets/apps/apps.zx", assets / "apps/apps.zx")
standalone_catalog = dict(schema=1, id=package["id"], title=package["title"],
harness="assets/apps/apps.zx", children=children)
(assets / "apps/catalog.json").write_text(json.dumps(standalone_catalog, indent=2) + "\n")
standalone_catalog = package_catalog(package, children)
(assets / "apps/catalog.json").write_bytes(catalog_bytes(standalone_catalog))
for child in children:
resources = [child[field] for field in ("bundle", "preview")]
resources += [value for field, value in child.get("cover", {}).items()
if field in ("portrait", "landscape", "logo")]
for relative in resources:
for relative in child_paths(child):
destination = standalone / relative
destination.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(output / relative, destination)
bundle(f"{name}_collection.zi", f"{name}_collection:Main", assets, ROOT / f"build/{name}.zx")
bundle(command, ROOT, f"{name}_collection.zi", f"{name}_collection:Main",
assets, ROOT / f"build/{name}.zx", env)
metadata = dict(id=package["id"], version=children[0]["version"],
sha256=digest(ROOT / f"build/{name}.zx"), apps_sha256=args.apps_sha256,
children=children, source_mode="project")
@@ -254,17 +320,17 @@ def main():
game_downloads = node_apps / "arcade.games"
art_assets = node_apps / "arcade-art"
stage_downloads(catalog, output, catalog_assets, game_downloads, art_assets)
bundle("art.zi", "art:Main", art_assets / "assets", node_apps / "arcade-art.zx")
bundle(command, ROOT, "art.zi", "art:Main", art_assets / "assets", node_apps / "arcade-art.zx", env)
art = add_art(catalog_assets, game_downloads, node_apps / "arcade-art.zx")
archive_downloads(game_downloads, node_apps / "arcade.games.tar")
bundle("collection.zi", "collection:Main", catalog_assets / "assets", node_apps / "arcade.zx")
bundle(command, ROOT, "collection.zi", "collection:Main", catalog_assets / "assets", node_apps / "arcade.zx", env)
shutil.copyfile(node_apps / "arcade.zx", ROOT / "build/arcade.zx")
# The desktop host supplies its controller from beside the collection.
shutil.copyfile(args.apps_bundle, ROOT / "build/apps.zx")
receipt = dict(id=catalog["id"], version=(ROOT / "VERSION").read_text().strip(),
receipt = dict(id=catalog["id"], version=version,
sha256=digest(ROOT / "build/arcade.zx"),
apps_sha256=args.apps_sha256, children=catalog["children"], art=art,
source_mode="project")
source_mode="project", node=node_source(ROOT))
(output / "receipt.json").write_text(json.dumps(receipt, indent=2) + "\n")
(ROOT / "build/arcade.json").write_text(json.dumps(receipt, indent=2) + "\n")
node_receipt = receipt | {"sha256": digest(node_apps / "arcade.zx")}
+14 -5
View File
@@ -11,6 +11,18 @@ ROOT = Path(__file__).resolve().parents[1]
ZIRAN = str(ROOT / 'scripts/ziran.sh')
def stage_startup_art(source, output):
"""Draw small full-colour images before the collection's originals load."""
from PIL import Image
startup = output / 'startup/shovey'
startup.mkdir(parents=True, exist_ok=True)
for name, edge in [('title-portrait.png', 640), ('title-landscape.png', 640), ('logo.png', 512)]:
with Image.open(source / 'assets/shovey' / name) as original:
image = original.convert('RGBA' if 'A' in original.getbands() else 'RGB')
image.thumbnail((edge, edge), Image.Resampling.LANCZOS)
image.save(startup / name, optimize=True)
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--output', type=Path)
@@ -42,7 +54,7 @@ def main():
subprocess.run(['cmake', '-S', str(oqs_source), '-B', str(oqs),
'-DCMAKE_BUILD_TYPE=MinSizeRel', '-DBUILD_SHARED_LIBS=OFF',
'-DOQS_BUILD_ONLY_LIB=ON', '-DOQS_USE_OPENSSL=OFF', '-DOQS_DIST_BUILD=OFF',
'-DOQS_OPT_TARGET=generic', '-DOQS_MINIMAL_BUILD=SIG_ml_dsa_44'], check=True)
'-DOQS_OPT_TARGET=generic', '-DOQS_MINIMAL_BUILD=SIG_ml_dsa_44;KEM_ml_kem_768'], check=True)
subprocess.run(['cmake', '--build', str(oqs), '--target', 'oqs', '-j2'], check=True)
temporary = output.with_suffix('.new')
output.parent.mkdir(parents=True, exist_ok=True)
@@ -59,10 +71,7 @@ def main():
if args.standalone_shovey:
from PIL import Image
source = Path(subprocess.check_output([ZIRAN, 'pkg', 'path', 'shovey', *lock], cwd=ROOT, text=True).strip())
startup = output.parent / 'startup/shovey'
startup.mkdir(parents=True, exist_ok=True)
for name in ('title-portrait.png', 'title-landscape.png', 'logo.png'):
shutil.copyfile(source / 'assets/shovey' / name, startup / name)
stage_startup_art(source, output.parent)
Image.open(source / 'assets/branding/shovey-icon.png').resize((256, 256), Image.Resampling.LANCZOS).save(output.parent / 'shovey-icon.png')
print(('Shovey' if args.standalone_shovey else 'Arcade') + ' native build passed')
+4 -1
View File
@@ -14,6 +14,9 @@ flags = ['--locked'] if args.locked or not (ROOT / 'ziran.local.toml').exists()
def package(name):
return Path(subprocess.check_output([ZIRAN, 'pkg', 'path', name, *flags], cwd=ROOT, text=True).strip())
entity, kryon, toolchain, qrcode = map(package, ('entity', 'kryon', 'ziran', 'qrcode'))
staged = ROOT / 'build/entity-profile-source'
subprocess.run(['python3', str(entity / 'scripts/stage-assets.py'), '--group', 'profile',
'--output', str(staged)], cwd=ROOT, check=True)
subprocess.run([ZIRAN, 'bundle', '--root', str(entity),
'--module-path', str(entity / 'src'),
'--module-path', str(kryon / 'src/ui'),
@@ -21,7 +24,7 @@ subprocess.run([ZIRAN, 'bundle', '--root', str(entity),
'--module-path', 'kryon=' + str(kryon / 'src/backend'),
'--module-path', 'qrcode=' + str(qrcode / 'src'),
'--module-path', str(toolchain / 'std'),
'--define', 'KRYON_HOSTED_UI', '--asset-dir', 'assets=' + str(entity / 'assets'),
'--define', 'KRYON_HOSTED_UI', '--asset-dir', 'assets=' + str(staged / 'assets'),
'--entry', 'entity:Main', '-o', str(ROOT / 'build/entity.zx'), str(entity / 'src/entity.zi')],
cwd=entity, check=True)
+23 -11
View File
@@ -7,7 +7,8 @@ import shutil
import subprocess
from pathlib import Path
from game_packages import declared_apps
from game_resources import dependency_order, share_resources
from game_module_paths import kryon_module_paths
from game_resources import dependency_order, pack_opaque_pngs, share_resources
ROOT = Path(__file__).resolve().parents[1]
@@ -37,16 +38,17 @@ def build(ziran, lock_flags):
[ziran, "pkg", "path", name, *lock_flags], cwd=ROOT, text=True).strip())
kryon = package("kryon")
game2d = package("game2d")
toolchain = package("ziran")
entity = package("entity")
compiler = toolchain / "build/bin/ziran"
if not compiler.is_file():
compiler = ROOT / "build/toolchain/bin/ziran"
def dependency(name, project):
return Path(subprocess.check_output(
[str(compiler), "pkg", "path", name, *lock_flags], cwd=project, text=True).strip())
daochi_client = dependency("daochi_client", entity)
crypto = dependency("crypto", daochi_client)
# Resolve transitive packages from Arcade's lock, never their private graphs.
daochi_client = package("daochi_client")
crypto = package("crypto")
# Shared KSS themes (Choano 0.1.5 and later import kss/Kss).
kss = package("kss")
entries = []
apps = dependency_order(declared_apps(ROOT, ziran, lock_flags))
by_id = {app['descriptor']['id']: app for app in apps}
@@ -99,9 +101,19 @@ def build(ziran, lock_flags):
generated.mkdir(parents=True, exist_ok=True)
if descriptor.get('prepare_assets'):
prepare = Path(descriptor['prepare_assets'])
if prepare.is_absolute() or '..' in prepare.parts or prepare.suffix != '.py':
if prepare.is_absolute() or '..' in prepare.parts or prepare.suffix not in ('.py', '.zi'):
raise ValueError('Invalid game asset preparation script')
subprocess.run(['python3', str(source / prepare), str(resources), str(generated)], check=True)
if prepare.suffix == '.zi':
# A Ziran preparation program builds with Arcade's compiler and
# runs from the game's checkout, where its own files are.
tool = ROOT / 'build/game-tools' / name
subprocess.run([str(compiler), 'build', '--target=c', '--exe', '--root', str((source / prepare).parent),
'--module-path', 'std=' + str(toolchain / 'std'), '--entry', prepare.stem + ':main',
'-o', str(tool), str(source / prepare)], cwd=ROOT, check=True)
subprocess.run([str(tool / prepare.stem), str(resources), str(generated)], cwd=source, check=True)
else:
subprocess.run(['python3', str(source / prepare), str(resources), str(generated)], check=True)
pack_opaque_pngs(resources)
shared = share_resources(app, apps, resources, ROOT / 'build/game-assets')
metadata = ROOT / 'build/games' / (name + '-resources.json')
metadata.parent.mkdir(parents=True, exist_ok=True)
@@ -130,9 +142,8 @@ def build(ziran, lock_flags):
# Game packages without a src folder (Shovey) keep sources beside their catalogs.
*(["--module-path", str(source / "src")] if (source / "src").is_dir() else []),
"--module-path", str(generated),
"--module-path", str(kryon / "src/ui"),
"--module-path", "kryon=" + str(kryon / "src/ui"),
"--module-path", "kryon=" + str(kryon / "src/backend"),
*kryon_module_paths(source, descriptor, kryon),
"--module-path", "game2d=" + str(game2d / "src"),
"--module-path", "std=" + str(toolchain / "std"),
"--module-path", str(toolchain / "std"),
"--module-path", "apps=" + str(package("apps") / "src"),
@@ -140,6 +151,7 @@ def build(ziran, lock_flags):
"--module-path", "entity=" + str(entity / "src"),
"--module-path", "daochi_client=" + str(daochi_client),
"--module-path", "crypto=" + str(crypto / "src"),
"--module-path", "kss=" + str(kss / "src"),
*[flag for name in defines for flag in ('--define', name)],
*[flag for entry in app['library_entries'] for flag in ('--retain', entry)],
*[flag for dependency_id in app['requires'] if app['shared_code']
+204 -8
View File
@@ -6,18 +6,161 @@ the website passes the published one Inner Breeze downloads. Arcade's own host
is compiled to WebAssembly with the account Profile. The receipt names the
collection's digest and the Apps library it trusts. Arcade's own copy of that
library goes beside it for collections that do not pack one.
With --shovey the page is shovey.waozi.xyz: the same host runs a released
Shovey download's own shovey.zx, shovey.json and entity.zx, unchanged, on the
page files --site names. Their programs, and the game and Apps controller
packed in shovey.zx, are compiled into the page, so they run as fast as a
native build of them; the page still opens those exact bytes.
The library's pictures come from the site too (stage_web_library_art), so
the covers never wait for the art bundle from api.waozi.xyz.
"""
import argparse
import gzip
import hashlib
import io
import json
import os
from pathlib import Path
import re
import shutil
import struct
import subprocess
import sys
import tarfile
ROOT = Path(__file__).resolve().parents[1]
ZIRAN = str(ROOT / 'scripts/ziran.sh')
ART_LIMIT = 64 * 1024 * 1024
# The committed library copies are at most this large (scripts/library-art.py).
PICTURE_LONGEST = 640
COVER_QUALITY = 80
def bundle_assets(data):
"""The files embedded in a ZX v26/v27 bundle by path; never runs it."""
if data[:8] not in (b'ZX\0\0\x1a\0\0\0', b'ZX\0\0\x1b\0\0\0') or len(data) > ART_LIMIT:
raise ValueError('unsupported bundle')
at = 8
def take(size):
nonlocal at
if at + size > len(data):
raise ValueError('truncated bundle')
value = data[at:at + size]
at += size
return value
def number():
return struct.unpack('<I', take(4))[0]
def text():
return take(number())
text(); text()
for _ in range(number()):
text(); text()
for _ in range(number()):
for _ in range(7):
text()
take(8); text(); take(4)
for _ in range(number()):
for _ in range(3):
text()
take(number())
assets = {}
for _ in range(number()):
path = text().decode()
if path in assets:
raise ValueError('duplicate bundle file')
assets[path] = take(number())
if at != len(data):
raise ValueError('trailing bundle bytes')
return assets
def published_art(folder, digest):
"""The art bundle a collection names, from the release's game archive
beside it or a local build's arcade.games folder."""
built = folder / 'arcade.games' / f'{digest}.zx'
if built.is_file():
return built.read_bytes()
archive = folder / 'arcade.games.tar'
if archive.is_file():
with tarfile.open(archive) as games:
member = next((entry for entry in games if entry.name == f'{digest}.zx'), None)
if member is not None and member.isfile() and member.size <= ART_LIMIT:
return games.extractfile(member).read()
raise ValueError('The collection\'s art bundle is not beside it')
def web_picture(data, exact):
"""(bytes, suffix) of the page's copy of one verified library picture: a
WebP, lossless when exact (pixel-art previews), unless the original is
smaller. Transparency is kept; nothing is larger than PICTURE_LONGEST."""
from PIL import Image
image = Image.open(io.BytesIO(data))
image.load()
original = '.' + image.format.lower().replace('jpeg', 'jpg')
alpha = 'A' in image.getbands() or 'transparency' in image.info
image = image.convert('RGBA' if alpha else 'RGB')
scale = min(1.0, PICTURE_LONGEST / max(image.size))
if scale < 1.0:
size = (max(1, round(image.width * scale)), max(1, round(image.height * scale)))
image = image.resize(size, Image.Resampling.LANCZOS)
output = io.BytesIO()
if exact:
image.save(output, 'WEBP', lossless=True, method=6)
else:
image.save(output, 'WEBP', quality=COVER_QUALITY, method=6)
if scale == 1.0 and len(data) <= output.tell():
return data, original
return output.getvalue(), '.webp'
def stage_web_library_art(bundle, output):
"""Serve the collection's separate library art from the site.
The art bundle must have the exact digest and size the collection's
signed catalog names. Its pictures go to output/library as small WebP
copies, named by content and listed in library.json under that digest;
the exact bundle goes beside them for browsers that cannot draw WebP.
Returns the listing, or None when the collection packs its own art.
"""
assets = bundle_assets(bundle.read_bytes())
catalog = json.loads(assets['assets/apps/catalog.json'])
art = catalog.get('art')
if art is None:
return None
digest, size = art.get('sha256', ''), art.get('bytes')
if not re.fullmatch(r'[0-9a-f]{64}', digest) or not isinstance(size, int):
raise ValueError('Invalid art in the collection catalog')
data = published_art(bundle.parent, digest)
if len(data) != size or hashlib.sha256(data).hexdigest() != digest:
raise ValueError('The art bundle differs from the collection catalog')
pictures = bundle_assets(data)
previews = {child[key] for child in catalog['children'] for key in ('preview', 'icon') if child.get(key)}
covers = {path for child in catalog['children'] for key, path in child.get('cover', {}).items()
if key in ('portrait', 'landscape', 'logo')}
copies = {}
for path in sorted(previews | covers):
if path not in pictures:
raise ValueError(f'The art bundle lacks {path}')
copies[path] = web_picture(pictures[path], path in previews)
library = output / 'library'
if library.exists():
shutil.rmtree(library)
library.mkdir(parents=True)
(library / f'{digest}.zx').write_bytes(data)
listed = {}
for path, (contents, suffix) in copies.items():
name = hashlib.sha256(contents).hexdigest()
(library / (name + suffix)).write_bytes(contents)
listed[path] = dict(file=f'library/{name}{suffix}', sha256=name, bytes=len(contents))
manifest = dict(art=digest, bytes=size, pictures=listed)
(output / 'library.json').write_text(json.dumps(manifest, indent=2) + '\n')
return manifest
def package(name):
@@ -25,6 +168,35 @@ def package(name):
return Path(subprocess.check_output([ZIRAN, 'pkg', 'path', name, *flags], cwd=ROOT, text=True).strip())
def compress(path):
"""A gzip copy beside path, which the page fetches first: Cloudflare
Pages does not compress binary files (apps.zx 1.9 MB -> 0.24 MB)."""
with open(path.with_name(path.name + '.gz'), 'wb') as raw:
with gzip.GzipFile(filename='', mode='wb', compresslevel=9, fileobj=raw, mtime=0) as packed:
packed.write(path.read_bytes())
def version_assets(output, receipt):
"""Keep the runtime, its data and the verified collection on one cache key."""
page = output / 'index.html'
html = page.read_text()
if '__ARCADE_ASSET_REVISION__' not in html:
return
digest = hashlib.sha256()
for name in ('runtime.js', 'runtime.wasm', 'runtime.data', 'arcade.json', 'apps.zx', 'library.json'):
path = output / name
if path.is_file():
digest.update(name.encode() + b'\0')
digest.update(path.read_bytes())
revision = digest.hexdigest()
page.write_text(html.replace('__ARCADE_ASSET_REVISION__', revision))
source = subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=ROOT, text=True).strip()
(output / 'build.json').write_text(json.dumps({
'source_revision': source, 'version': receipt['version'],
'assets_sha256': revision,
}, indent=2) + '\n')
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--bundle', type=Path, default=ROOT / 'build/node-apps/arcade.zx')
@@ -33,32 +205,56 @@ def main():
parser.add_argument('--profile', type=Path, default=ROOT / 'build/entity.zx')
parser.add_argument('--controller', type=Path, default=ROOT / 'build/apps-ui/apps.zx')
parser.add_argument('--output', type=Path, default=ROOT / 'build/web-site')
parser.add_argument('--shovey', type=Path, help='a released Shovey download folder')
parser.add_argument('--site', type=Path, default=ROOT / 'site')
args = parser.parse_args()
bundle = args.bundle.resolve()
receipt = dict(id='inbe.arcade', version=args.version,
sha256=hashlib.sha256(bundle.read_bytes()).hexdigest(),
apps_sha256=args.controller_sha256)
if args.shovey:
bundle = (args.shovey / 'shovey.zx').resolve()
receipt = json.loads((args.shovey / 'shovey.json').read_text())
if receipt.get('id') != 'arcade.shovey-player' or \
hashlib.sha256(bundle.read_bytes()).hexdigest() != receipt.get('sha256'):
raise SystemExit('The Shovey download does not match its shovey.json')
args.profile = args.shovey / 'entity.zx'
args.controller_sha256 = receipt['apps_sha256']
args.version = receipt['version']
else:
from node_config import node_source
bundle = args.bundle.resolve()
receipt = dict(id='inbe.arcade', version=args.version,
sha256=hashlib.sha256(bundle.read_bytes()).hexdigest(),
apps_sha256=args.controller_sha256, node=node_source(ROOT))
# The host reads the receipt into a 4 KiB buffer.
text = json.dumps(receipt, separators=(',', ':')) if args.shovey else json.dumps(receipt, indent=2) + '\n'
if len(text.encode()) >= 4096:
raise SystemExit('The receipt exceeds the host buffer')
work = ROOT / 'build/web'
work.mkdir(parents=True, exist_ok=True)
env = {**os.environ, 'ZIRAN': str(package('ziran') / 'build/bin/ziran')}
linked = [item for path in (bundle, args.profile.resolve()) for item in ('--linked', str(path))] \
if args.shovey else []
subprocess.run([sys.executable, str(package('entity') / 'scripts/build-web.py'),
'--bundle', str(bundle), '--profile', str(args.profile.resolve()),
'--output', str(work / 'runtime.html'),
'--output', str(work / 'runtime.html'), *linked,
'--entry', 'runtime:main', '--source', 'src/web/runtime.zi'], cwd=ROOT, env=env, check=True)
output = args.output.resolve()
if output.exists():
shutil.rmtree(output)
shutil.copytree(ROOT / 'site', output)
shutil.copytree(args.site, output)
for name in ('runtime.js', 'runtime.wasm', 'runtime.data'):
shutil.copyfile(work / name, output / name)
(output / 'arcade.json').write_text(json.dumps(receipt, indent=2) + '\n')
compress(output / 'runtime.data')
(output / 'arcade.json').write_text(text)
# Only the library the receipt trusts; the host refuses any other.
controller = args.controller.read_bytes() if args.controller.is_file() else b''
if hashlib.sha256(controller).hexdigest() == args.controller_sha256:
(output / 'apps.zx').write_bytes(controller)
compress(output / 'apps.zx')
else:
print('No matching Apps controller beside the collection; it must pack its own')
print(f'Arcade {args.version} for the browser in {output}')
if not args.shovey and stage_web_library_art(bundle, output) is None:
print('The collection packs its own library art')
version_assets(output, receipt)
print(f'{"Shovey" if args.shovey else "Arcade"} {args.version} for the browser in {output}')
if __name__ == '__main__':
+1 -1
View File
@@ -119,7 +119,7 @@ def main():
oqs = BUILD / 'oqs/lib/liboqs.a'
if not built(oqs, oqs_source):
cmake(oqs_source, BUILD / 'oqs', tools, '-DCMAKE_BUILD_TYPE=MinSizeRel', '-DOQS_BUILD_ONLY_LIB=ON',
'-DOQS_USE_OPENSSL=OFF', '-DOQS_DIST_BUILD=OFF', '-DOQS_OPT_TARGET=generic', '-DOQS_MINIMAL_BUILD=SIG_ml_dsa_44')
'-DOQS_USE_OPENSSL=OFF', '-DOQS_DIST_BUILD=OFF', '-DOQS_OPT_TARGET=generic', '-DOQS_MINIMAL_BUILD=SIG_ml_dsa_44;KEM_ml_kem_768')
subprocess.run(['cmake', '--build', str(BUILD / 'oqs'), '--target', 'oqs', '-j4'], check=True)
record(oqs, oqs_source)
+23 -4
View File
@@ -1,6 +1,7 @@
#!/usr/bin/env python3
"""Check game ownership, shared interface versions, translations and update metadata."""
import json
import argparse
from pathlib import Path
import re
from game_packages import declared_apps
@@ -8,10 +9,24 @@ from game_packages import declared_apps
ROOT = Path(__file__).resolve().parents[1]
def check():
def translation_keys(code, prefix):
# Package imports and integer fields read from server JSON are not labels.
# Strip only those argument occurrences: the same key used by the UI must
# still have a translation.
code = re.sub(r'^\s*#import\s+"[^"\n]*"', '', code, flags=re.M)
code = re.sub(r'\bShopInteger\s*\(\s*[^,\n]+,\s*"[^"\n]*"', '', code)
return set(re.findall(r'"(' + re.escape(prefix) + r'[a-z0-9_]+)"', code))
def check(ziran, lock_flags):
standard = json.loads((ROOT / 'standards/game-v1.json').read_text())
ledger = json.loads((ROOT / 'apps/versions.json').read_text())
for app in declared_apps(ROOT):
# Arcade's own players refuse games newer than GAME_HOST_API, so it moves
# with the standard and the ledger whenever the host interface does.
player = re.search(r'^GAME_HOST_API :: (\d+)$', (ROOT / 'src/game_contract.zi').read_text(), re.M)
assert player and int(player[1]) == standard['host_api'] == ledger['host_api'], \
'src/game_contract.zi GAME_HOST_API, standards/game-v1.json and apps/versions.json must name the same host interface'
for app in declared_apps(ROOT, ziran, lock_flags):
source, manifest, game = app['source'], app['manifest'], app['descriptor']
for field in ['contract_version', 'module_api', 'host_api']:
assert game[field] == standard[field], f'{game["name"]}: incompatible {field}'
@@ -27,7 +42,7 @@ def check():
assert component['sequence'] > 0
required = set()
for file in manifest.parent.glob('*.zi'):
required.update(re.findall(r'"(' + re.escape(game['locale_prefix']) + r'[a-z0-9_]+)"', file.read_text()))
required.update(translation_keys(file.read_text(), game['locale_prefix']))
locales = {}
for file in (source / game['locales']).glob('*.txt'):
text = file.read_text()
@@ -54,5 +69,9 @@ def check():
if __name__ == '__main__':
check()
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--ziran', default=str(ROOT / 'scripts/ziran.sh'))
parser.add_argument('--locked', action='store_true')
arguments = parser.parse_args()
check(arguments.ziran, ['--locked'] if arguments.locked else [])
print('Game contract, package sources, translated text and independent version ledger passed')
+64 -54
View File
@@ -1,13 +1,13 @@
#!/usr/bin/env python3
"""Follow the published releases of Arcade's game packages.
`pin` moves each game package in ziran.lock to the commit of its repository's
latest published GitHub release, when that commit is ahead of the current pin.
Only the game's own entry changes: its dependencies keep Arcade's pins, so the
games build against the same Kryon and Apps as Arcade. The ids and layout are
the ones `ziran lock` writes. The updates are recorded in build/game-updates.json.
`check` records newer published game releases without changing dependencies.
`pin` selects their exact commits in ziran.toml and asks Ziran to update each
game and its transitive dependencies. New game imports must reach the lock;
unrelated packages and the compiler stay pinned. The updates are recorded in
build/game-updates.json.
`changelog` adds an Arcade release entry naming each updated game with the
`changelog` adds an Arcade catalog release entry naming each updated game with the
notes of its newest release, for update_version.sh to synchronize.
`art` remakes the library's small copies of game art (scripts/library-art.py)
@@ -26,31 +26,6 @@ ROOT = Path(__file__).resolve().parents[1]
UPDATES = ROOT / 'build/game-updates.json'
def package_id(url, commit):
"""The id `ziran lock` gives a source at a commit (PkgSourceId)."""
return 'p' + hashlib.sha256((url + '\n' + commit).encode()).hexdigest()[:16]
def write_lock(lock):
"""The lock as Ziran writes it: sorted keys, one-line maps, packages kept
in their order."""
def value(item):
if isinstance(item, dict):
return '{' + ', '.join(json.dumps(k) + ': ' + json.dumps(item[k]) for k in sorted(item)) + '}'
return json.dumps(item)
def block(item, indent):
pad = ' ' * indent
fields = [pad + ' ' + json.dumps(k) + ': ' + value(item[k]) for k in sorted(item)]
return pad + '{\n' + ',\n'.join(fields) + '\n' + pad + '}'
text = '{\n "format": ' + json.dumps(lock['format']) + ',\n "packages": [\n'
text += ',\n'.join(block(item, 4) for item in lock['packages']) + '\n ],\n'
text += ' "root": ' + block(lock['root'], 2).lstrip() + ',\n'
text += ' "toolchain": ' + block(lock['toolchain'], 2).lstrip() + '\n}\n'
return text
def gh(*args):
return subprocess.check_output(['gh', *args], text=True).strip()
@@ -62,13 +37,9 @@ def repository(url):
return match[1]
def pin():
lock_path = ROOT / 'ziran.lock'
lock = json.loads(lock_path.read_text())
if write_lock(lock) != lock_path.read_text():
raise SystemExit('ziran.lock is not in the layout ziran lock writes')
def released_updates():
lock = json.loads((ROOT / 'ziran.lock').read_text())
names = json.loads((ROOT / 'games.json').read_text())['packages']
ledger = json.loads((ROOT / 'apps/versions.json').read_text())['node_apps']
updates = []
for name in names:
old_id = lock['root']['dependencies'][name]
@@ -76,30 +47,61 @@ def pin():
repo = repository(entry['url'])
tag = gh('release', 'view', '--repo', repo, '--json', 'tagName', '--jq', '.tagName')
commit = gh('api', f'repos/{repo}/commits/{tag}', '--jq', '.sha')
if not re.fullmatch(r'[0-9a-f]{40}', commit):
raise SystemExit(f'{name}: invalid release commit')
if commit == entry['commit']:
continue
# A later tag of the version Arcade already ships is not a new release.
if name in ledger and ledger[name]['version'] == tag.removeprefix('v'):
continue
# Release metadata can be recorded before the game is published.
# The pinned source must still advance to that release's commit.
# Never move back: the release must contain the pinned commit.
status = gh('api', f'repos/{repo}/compare/{entry["commit"]}...{commit}', '--jq', '.status')
if status != 'ahead':
print(f'{name}: release {tag} is {status} of the pinned {entry["commit"][:12]}; kept')
continue
new_id = package_id(entry['url'], commit)
entry['commit'] = commit
entry['id'] = new_id
for owner in [lock['root'], *lock['packages']]:
for alias, target in owner['dependencies'].items():
if target == old_id:
owner['dependencies'][alias] = new_id
updates.append({'name': name, 'repository': repo, 'tag': tag, 'commit': commit})
print(f'{name}: {repo} {tag} ({commit[:12]})')
lock_path.write_text(write_lock(lock))
return updates
def record_updates(updates):
UPDATES.parent.mkdir(parents=True, exist_ok=True)
UPDATES.write_text(json.dumps(updates, indent=2) + '\n')
def pin(ziran):
updates = released_updates()
manifest = ROOT / 'ziran.toml'
lock_path = ROOT / 'ziran.lock'
original_manifest = manifest.read_bytes()
original_lock = lock_path.read_bytes()
try:
for update in updates:
name, commit = update['name'], update['commit']
# Edit the declaration; only the package manager writes the graph.
section = re.compile(r'(^\[dependencies\.' + re.escape(name) +
r'\]\s*\n)([^\[]*)', re.M)
text = manifest.read_text()
match = section.search(text)
if match is None:
raise ValueError(f'{name}: missing dependency declaration')
body, count = re.subn(r'^ref[ \t]*=[ \t]*"[^"\n]*"[ \t]*$',
f'ref = "{commit}"', match[2], flags=re.M)
if count != 1:
raise ValueError(f'{name}: expected one dependency ref')
manifest.write_text(text[:match.start(2)] + body + text[match.end(2):])
subprocess.run([str(ziran), 'update', name], cwd=ROOT, check=True)
lock = json.loads(lock_path.read_text())
target = lock['root']['dependencies'][name]
entry = next(p for p in lock['packages'] if p['id'] == target)
if entry['commit'] != commit:
raise ValueError(f'{name}: Ziran did not select the released commit; remove its local override')
except BaseException:
manifest.write_bytes(original_manifest)
lock_path.write_bytes(original_lock)
raise
record_updates(updates)
def newest_notes(changelog):
"""The bullets of a changelog's newest numeric release."""
text = changelog.read_text()
@@ -125,15 +127,21 @@ def changelog(ziran):
version, notes = newest_notes(manifest.with_name('CHANGELOG.md'))
title = declaration['title']
lines += [f'- {title} {version}: {note}' for note in notes] or [f'- {title} {version}.']
path = ROOT / 'CHANGELOG.md'
path = ROOT / 'catalog/CHANGELOG.md'
text = path.read_text()
current = re.search(r'^## (\d+)\.(\d+)\.(\d+)\s*$', text, re.M)
if current is None:
raise SystemExit('CHANGELOG.md needs a numeric release entry')
raise SystemExit('catalog/CHANGELOG.md needs a numeric release entry')
# Pending catalog changes ship with the next catalog release.
pending = re.search(r'^## \[Unreleased\]\s*$', text[:current.start()], re.M)
if pending is not None:
lines = [line for line in text[pending.end():current.start()].splitlines() if line.startswith('- ')] + lines
text = text[:pending.start()] + text[current.start():]
current = re.search(r'^## (\d+)\.(\d+)\.(\d+)\s*$', text, re.M)
version = f'{current[1]}.{current[2]}.{int(current[3]) + 1}'
entry = f'## {version}\n\n' + '\n'.join(lines) + '\n\n'
path.write_text(text[:current.start()] + entry + text[current.start():])
print(f'Arcade {version}')
print(f'Arcade catalog {version}')
def art():
@@ -149,11 +157,13 @@ def art():
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('command', choices=['pin', 'changelog', 'art'])
parser.add_argument('command', choices=['check', 'pin', 'changelog', 'art'])
parser.add_argument('--ziran', default=str(ROOT / 'scripts/ziran.sh'))
args = parser.parse_args()
if args.command == 'pin':
pin()
if args.command == 'check':
record_updates(released_updates())
elif args.command == 'pin':
pin(args.ziran)
elif args.command == 'changelog':
changelog(args.ziran)
else:
+41
View File
@@ -0,0 +1,41 @@
"""Select Kryon namespaces from a game's own source imports."""
import re
from pathlib import Path
_TOKENS = re.compile(r'//[^\n]*|/\*.*?\*/|"(?:\\.|[^"\\])*"|#import\b|\S', re.DOTALL)
def _imports(text):
previous = None
for match in _TOKENS.finditer(text):
token = match.group()
if token.startswith(('//', '/*')):
continue
if previous == '#import' and token.startswith('"'):
yield token[1:-1]
previous = token
def _module_names(root):
return ({path.stem for path in root.glob('*.zi')} |
{path.parent.name for path in root.glob('*/module.zi')})
def kryon_module_paths(source: Path, descriptor: dict, kryon: Path) -> list[str]:
"""Keep qualified UI imports scoped unless game code needs short imports.
Registering the UI directory both plain and named makes Ziran load Kryon
into the application's flat namespace. Only direct imports of UI modules
the application does not own justify that legacy mode.
"""
ui = kryon / 'src/ui'
roots = {source / 'src' if (source / 'src').is_dir() else source,
(source / descriptor['source']).parent}
owned = set().union(*(_module_names(root) for root in roots))
shared = _module_names(ui) - owned
needs_plain = any(name in shared for root in roots for path in root.rglob('*.zi')
for name in _imports(path.read_text()))
paths = [str(ui)] if needs_plain else []
paths += ['kryon=' + str(ui), 'kryon=' + str(kryon / 'src/backend')]
return [flag for path in paths for flag in ('--module-path', path)]
+9 -2
View File
@@ -30,12 +30,19 @@ def relative_path(text):
def declared_packages(root, ziran=None, lock_flags=()):
"""Arcade first, then each registered game package, with their apps."""
names = ['self', *json.loads((Path(root) / 'games.json').read_text())['packages']]
registration = json.loads((Path(root) / 'games.json').read_text())
names = ['self', *registration['packages']]
if len(set(names)) != len(names):
raise ValueError('Duplicate game package')
artwork = registration.get('artwork', {})
if not isinstance(artwork, dict) or any(name not in names[1:] or
not isinstance(alias, str) or not re.fullmatch(r'[A-Za-z_][A-Za-z0-9_]*', alias)
for name, alias in artwork.items()):
raise ValueError('Invalid artwork package')
packages = []
for name in names:
source = package_root(root, name, ziran, lock_flags)
art_source = package_root(root, artwork[name], ziran, lock_flags) if name in artwork else source
declaration = json.loads((source / 'apps.json').read_text())
apps = []
for app in declaration['apps']:
@@ -61,7 +68,7 @@ def declared_packages(root, ziran=None, lock_flags=()):
not re.fullmatch(r'[A-Za-z_][A-Za-z0-9_]*:[A-Za-z_][A-Za-z0-9_]*', item)
for item in library_entries) or len(set(library_entries)) != len(library_entries):
raise ValueError(f'{name}: invalid portable library entries')
apps.append(dict(package=name, source=source, manifest=manifest,
apps.append(dict(package=name, source=source, art_source=art_source, manifest=manifest,
descriptor=json.loads(manifest.read_text()),
cover=app.get('cover'), requires=requires, shared_code=shared_code,
shared_records=shared_records,
+33
View File
@@ -1,5 +1,8 @@
"""Pack additions once; signed collection links bind shared game resources."""
import hashlib
import io
import json
from PIL import Image
from pathlib import Path
import shutil
@@ -83,3 +86,33 @@ def share_resources(app, apps, resources, staged):
if len(links) > 16:
raise ValueError('Too many shared resource links')
return dict(dependencies=requirements, resources=links)
def pack_opaque_pngs(resources):
"""Drop redundant alpha bytes without changing any decoded pixel.
Prepared copies receive the same encoding before dependency comparison.
Metadata-bearing images stay untouched so their color interpretation is
preserved; transparent images keep their alpha channel.
"""
changed = set()
for path in resources.rglob('*.png'):
with Image.open(path) as image:
if image.mode != 'RGBA' or image.info or image.getextrema()[3] != (255, 255):
continue
packed = io.BytesIO()
image.convert('RGB').save(packed, format='PNG', optimize=True)
if packed.tell() < path.stat().st_size:
path.write_bytes(packed.getbuffer())
changed.add(path)
# Art inventories describe the staged bytes, including lossless encoding.
for manifest in resources.rglob('art.json'):
inventory = json.loads(manifest.read_text())
updated = False
for item in inventory.get('files', []):
asset = manifest.parent / item['path']
if asset in changed and 'sha256' in item:
item['sha256'] = hashlib.sha256(asset.read_bytes()).hexdigest()
updated = True
if updated:
manifest.write_text(json.dumps(inventory, indent=2) + '\n')
+56 -23
View File
@@ -1,10 +1,11 @@
#!/usr/bin/env python3
"""Make Arcade's small copies of each game's cover and preview art.
"""Stage bounded thumbnails for every game's library covers and previews.
Game packages keep their full-size art for their own players and stores.
Arcade only shows that art in its library, so it packs copies sized for the
screen with a 256-colour palette: about a fifth of the bytes, with no visible
change. Arcade stays a small launcher; the games download separately.
Library covers retain full colour and transparency at thumbnail resolution:
opaque cover art is a JPEG, a sixth of its PNG size, while logos keep their
transparency and previews their pixel art as PNG. Games keep their own
original title artwork. Arcade downloads this small art
bundle separately from its launcher and caches it by its content digest.
The copies and sources.json, which records the SHA-256 of the art each copy
was made from, are committed. The collection build uses them as they are,
@@ -20,25 +21,53 @@ from game_packages import declared_packages
ROOT = Path(__file__).resolve().parents[1]
LIBRARY = ROOT / 'assets/arcade/library'
# Longest side: covers fill the library's screen, logos sit on them and
# previews are small tiles and icons.
LONGEST = {'portrait': 1280, 'landscape': 1280, 'logo': 800, 'preview': 480}
PREVIEW_LONGEST = 480
COVER_LONGEST = 640
LOGO_LONGEST = 512
COVER_QUALITY = 85
SUFFIXES = ('.png', '.jpg')
def copy_path(name):
"""The committed copy for name, whichever format it was made in."""
for suffix in SUFFIXES:
if (LIBRARY / (name + suffix)).is_file():
return LIBRARY / (name + suffix)
raise FileNotFoundError(f'{name} has no library copy; run scripts/library-art.py')
def small_copy(data, key):
"""(bytes, suffix) of the library's copy of one picture."""
image = Image.open(io.BytesIO(data))
image.load()
scale = min(1.0, LONGEST[key] / max(image.size))
# The shared library cards are 2:3. Keep the top of taller paintings,
# where their title lives, rather than letting the card centre-crop it.
# Originals remain untouched; this framing belongs to the thumbnail.
if key == 'portrait' and image.height > image.width * 1.5:
image = image.crop((0, 0, image.width, round(image.width * 1.5)))
longest = PREVIEW_LONGEST if key == 'preview' else LOGO_LONGEST if key == 'logo' else COVER_LONGEST
scale = min(1.0, longest / max(image.size))
alpha = 'A' in image.getbands() or 'transparency' in image.info
photo = key in ('portrait', 'landscape') and not alpha
if scale == 1.0 and key != 'preview' and not photo:
return data, '.png'
image = image.convert('RGBA' if alpha else 'RGB')
if scale < 1.0:
size = (round(image.width * scale), round(image.height * scale))
image = image.convert('RGBA' if 'A' in image.getbands() else 'RGB').resize(size, Image.Resampling.LANCZOS)
if 'A' in image.getbands():
image = image.convert('RGBA').quantize(256, method=Image.Quantize.FASTOCTREE, dither=Image.Dither.FLOYDSTEINBERG)
else:
image = image.convert('RGB').quantize(256, dither=Image.Dither.FLOYDSTEINBERG)
size = (max(1, round(image.width * scale)), max(1, round(image.height * scale)))
image = image.resize(size, Image.Resampling.LANCZOS)
if key == 'preview':
if alpha:
image = image.quantize(256, method=Image.Quantize.FASTOCTREE, dither=Image.Dither.FLOYDSTEINBERG)
else:
image = image.quantize(256, dither=Image.Dither.FLOYDSTEINBERG)
output = io.BytesIO()
if photo:
image.save(output, 'JPEG', quality=COVER_QUALITY, optimize=True, progressive=True)
return output.getvalue(), '.jpg'
image.save(output, 'PNG', optimize=True)
return output.getvalue()
return output.getvalue(), '.png'
def art(root=ROOT):
@@ -48,24 +77,28 @@ def art(root=ROOT):
if not app['enabled']:
continue
name = app['descriptor']['name']
yield name, 'preview', (app['source'] / app['descriptor']['preview']).read_bytes()
yield name, 'preview', (app['art_source'] / app['descriptor']['preview']).read_bytes()
for key in ('portrait', 'landscape', 'logo'):
if app['cover'] and key in app['cover']:
yield name, key, (app['source'] / app['cover'][key]).read_bytes()
yield name, key, (app['art_source'] / app['cover'][key]).read_bytes()
def main():
LIBRARY.mkdir(parents=True, exist_ok=True)
sources = {}
written = set()
for name, key, data in art():
copy = f'{name}-{key}'
(LIBRARY / f'{copy}.png').write_bytes(small_copy(data, key))
contents, suffix = small_copy(data, key)
(LIBRARY / (copy + suffix)).write_bytes(contents)
written.add(copy + suffix)
sources[copy] = {'source_sha256': hashlib.sha256(data).hexdigest()}
for stale in LIBRARY.glob('*.png'):
if stale.stem not in sources:
stale.unlink()
for suffix in SUFFIXES:
for stale in LIBRARY.glob('*' + suffix):
if stale.name not in written:
stale.unlink()
(LIBRARY / 'sources.json').write_text(json.dumps(dict(sorted(sources.items())), indent=2) + '\n')
total = sum((LIBRARY / f'{copy}.png').stat().st_size for copy in sources)
total = sum((LIBRARY / name).stat().st_size for name in written)
print(f'{len(sources)} library images, {total / 1048576:.1f} MiB')
+17
View File
@@ -0,0 +1,17 @@
"""The native host's reviewed public node publisher binding."""
import json
import re
def node_source(root):
source = json.loads((root / 'packaging/node.json').read_text())
if (set(source) != {'origin', 'app_id', 'key_id', 'public_key'}
or source['origin'] != 'https://api.waozi.xyz'
or source['app_id'] != 'inbe.arcade'
or not re.fullmatch(r'[a-z0-9][a-z0-9.-]{0,62}', source['key_id'])
or not re.fullmatch(r'[a-f0-9]{64}', source['public_key'])):
raise ValueError('Invalid reviewed node publisher binding')
sequence = json.loads((root / 'apps/versions.json').read_text())['node_apps']['arcade']['sequence']
if type(sequence) is not int or not 1 <= sequence <= 2147483647:
raise ValueError('Invalid catalog release floor')
return source | {'minimum_sequence': sequence}
+238
View File
@@ -0,0 +1,238 @@
#!/usr/bin/env python3
"""Wait for the game packages a published Arcade catalog advertises.
The site still tests the real Inbe API before its browser gate. The publisher
can follow a GitHub release by several minutes, so readiness is conditional and
has a hard deadline; no package is extracted or executed.
"""
import argparse
import hashlib
import json
import re
import struct
import sys
import tarfile
import time
import urllib.error
import urllib.request
from pathlib import Path
API_ROOT = "https://api.waozi.xyz"
CATALOG_PATH = "assets/apps/catalog.json"
BUNDLE_LIMIT = 64 * 1024 * 1024
CATALOG_LIMIT = 1024 * 1024
READ_CHUNK = 1024 * 1024
PREFIX_BYTES = 16
REQUEST_TIMEOUT_SECONDS = 15
class Reader:
def __init__(self, path):
self.size = path.stat().st_size
if self.size > BUNDLE_LIMIT:
raise ValueError("published Arcade bundle is too large")
self.remaining = self.size
self.file = path.open("rb")
def __enter__(self):
return self
def __exit__(self, kind, value, traceback):
self.file.close()
def take(self, size):
if size < 0 or size > self.remaining:
raise ValueError("truncated bundle")
data = self.file.read(size)
if len(data) != size:
raise ValueError("truncated bundle")
self.remaining -= size
return data
def skip(self, size):
if size < 0 or size > self.remaining:
raise ValueError("truncated bundle")
self.file.seek(size, 1)
self.remaining -= size
def number(self):
return struct.unpack("<I", self.take(4))[0]
def text(self, limit=BUNDLE_LIMIT):
size = self.number()
if size > limit or size > self.remaining:
raise ValueError("oversized bundle field")
return self.take(size)
def finish(self):
if self.file.read(1):
raise ValueError("trailing bundle bytes")
self.file.close()
def catalog_from_bundle(path):
with Reader(path) as reader:
if reader.take(8) not in (b"ZX\0\0\x1a\0\0\0", b"ZX\0\0\x1b\0\0\0"):
raise ValueError("unsupported bundle")
reader.text()
reader.text()
for _ in range(reader.number()):
reader.text()
reader.text()
for _ in range(reader.number()):
for _ in range(7):
reader.text()
reader.take(8)
reader.text()
reader.take(4)
for _ in range(reader.number()):
for _ in range(3):
reader.text()
reader.skip(reader.number())
assets = reader.number()
catalog = None
seen = set()
for _ in range(assets):
name = reader.text().decode()
if name in seen:
raise ValueError("duplicate bundle file")
seen.add(name)
size = reader.number()
if name == CATALOG_PATH:
if catalog is not None or size > CATALOG_LIMIT:
raise ValueError("invalid collection catalog")
catalog = reader.take(size)
else:
reader.skip(size)
reader.finish()
if catalog is None:
raise ValueError("the collection lacks a catalog")
return json.loads(catalog)
def expected_games(catalog):
children = catalog.get("children")
if not isinstance(children, list):
raise ValueError("invalid collection catalog")
games = {}
for child in children:
digest, size = child.get("sha256", ""), child.get("bytes")
if not re.fullmatch(r"[0-9a-f]{64}", digest) or not isinstance(size, int) \
or not 0 < size <= BUNDLE_LIMIT:
raise ValueError("invalid game in the collection catalog")
games[digest] = size
return games
def archive_members(archive, games):
members = {}
with tarfile.open(archive, "r:") as content:
for entry in content:
digest = entry.name.removesuffix(".zx")
if digest not in games:
continue
if not entry.isfile() or digest in members or entry.size != games[digest]:
raise ValueError("the release game archive differs from the catalog")
source = content.extractfile(entry)
source_digest = hashlib.sha256()
prefix = bytearray()
read = 0
while chunk := source.read(min(READ_CHUNK, games[digest] - read)):
source_digest.update(chunk)
if len(prefix) < PREFIX_BYTES:
prefix.extend(chunk[:PREFIX_BYTES - len(prefix)])
read += len(chunk)
if read != games[digest] or source_digest.hexdigest() != digest:
raise ValueError("the release game archive differs from the catalog")
members[digest] = (source_digest.hexdigest(), bytes(prefix))
if set(members) != set(games):
raise ValueError("the release game archive lacks a catalog game")
return members
def package_ready(api_root, digest, size, prefix, timeout_seconds=REQUEST_TIMEOUT_SECONDS):
url = f"{api_root.rstrip('/')}/api/v2/packages/inbe.arcade/{digest}.zx"
request = urllib.request.Request(
url,
headers={"Range": f"bytes=0-{PREFIX_BYTES - 1}", "User-Agent": "arcade-site-readiness"},
)
try:
with urllib.request.urlopen(request, timeout=timeout_seconds) as response:
status = response.status
content_type = response.headers.get_content_type()
etag = response.headers.get("ETag")
content_range = response.headers.get("Content-Range")
content_length = response.headers.get("Content-Length")
body = response.read(PREFIX_BYTES)
except urllib.error.HTTPError as error:
error.close()
return False
except (TimeoutError, urllib.error.URLError):
return False
if etag != f'"{digest}"':
return False
expected_length = size if status == 200 else min(PREFIX_BYTES, size)
if content_length is not None:
try:
length = int(content_length)
except ValueError:
return False
if length != expected_length:
return False
if status == 206:
match = re.fullmatch(r"bytes 0-(\d+)/(\d+)", content_range or "")
if not match or int(match[1]) != min(PREFIX_BYTES, size) - 1 or int(match[2]) != size:
return False
elif status != 200:
return False
return content_type == "application/octet-stream" and body == prefix
def wait_for_published_games(api_root, archive, games, members, deadline_seconds,
poll_seconds=30, clock=time.monotonic, sleep=time.sleep):
deadline = clock() + deadline_seconds
pending = set(games)
while True:
for digest in list(pending):
remaining = deadline - clock()
if remaining <= 0:
raise TimeoutError(
f"published game packages still unavailable: {', '.join(sorted(pending))}"
)
ready = package_ready(
api_root, digest, games[digest], members[digest][1],
timeout_seconds=min(REQUEST_TIMEOUT_SECONDS, remaining),
)
if not ready:
continue
pending.remove(digest)
if not pending:
return
now = clock()
remaining = deadline - now
if remaining <= 0:
raise TimeoutError(f"published game packages still unavailable: {', '.join(pending)}")
sleep(min(poll_seconds, remaining))
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--api-root", default=API_ROOT)
parser.add_argument("--deadline-seconds", type=int, default=900)
parser.add_argument("--poll-seconds", type=float, default=30)
parser.add_argument("bundle", type=Path)
parser.add_argument("archive", type=Path)
arguments = parser.parse_args()
catalog = catalog_from_bundle(arguments.bundle)
games = expected_games(catalog)
members = archive_members(arguments.archive, games)
wait_for_published_games(arguments.api_root, arguments.archive, games, members,
arguments.deadline_seconds, arguments.poll_seconds)
print(f"all {len(games)} catalog game packages are published and ready")
if __name__ == "__main__":
try:
main()
except (OSError, ValueError, TimeoutError, tarfile.TarError) as error:
raise SystemExit(str(error))
Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

+120 -15
View File
@@ -10,6 +10,9 @@
<link rel="icon" href="icon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<link rel="manifest" href="manifest.webmanifest">
<!-- The runtime downloads while the page fetches the collection's files. -->
<link rel="preload" href="runtime.js?v=__ARCADE_ASSET_REVISION__" as="script">
<link rel="preload" href="runtime.wasm?v=__ARCADE_ASSET_REVISION__" as="fetch" type="application/wasm" crossorigin>
<meta property="og:type" content="website">
<meta property="og:url" content="https://arcade.waozi.xyz/">
<meta property="og:title" content="Arcade">
@@ -27,6 +30,8 @@
#loading .failed { display: none; color: #ffb4a8; text-align: center; padding: 0 24px; }
#loading.error .failed { display: block; }
#loading.error .track { display: none; }
#loading.error { opacity: 1; pointer-events: auto; }
#loading button { border: 0; border-radius: 12px; padding: 14px 24px; background: #ffd166; color: #111223; font: inherit; cursor: pointer; }
</style>
</head>
<body>
@@ -35,20 +40,30 @@
<!-- MingCute game_2 gamepad, Apache-2.0 -->
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M15 9v3M13.5 10.5h3M7 5c1 0 3 1 5 1s4-1 5-1c3 0 7 14 3 14-3 0-4.5-4-8-4s-5 4-8 4C0 19 4 5 7 5Zm3 5.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Z"/></svg>
<div class="track"><div class="bar"></div></div>
<p class="failed">Arcade could not start. Reload the page to try again.</p>
<p class="failed">Arcade stopped while opening an app. Your saved games are kept.</p>
<button class="failed" id="retry" type="button">Return to library</button>
</div>
<script>
(function () {
var loading = document.getElementById('loading');
var bar = loading.querySelector('.bar');
function failed() { loading.classList.add('error'); }
// Arcade's Profile reports ready once the library is about to draw.
var assetRevision = '__ARCADE_ASSET_REVISION__';
function assetUrl(name) {
var url = new URL(name, document.baseURI);
url.searchParams.set('v', assetRevision);
return url.href;
}
function failed() { loading.classList.remove('done'); loading.classList.add('error'); }
document.getElementById('retry').addEventListener('click', function () { location.reload(); });
// Keep watching after startup: a later game failure also needs recovery.
function watch() {
if (window.Module && Module.profileReady) { loading.classList.add('done'); return; }
if (window.Module && Module.arcadeFailed) { failed(); return; }
if (window.Module && Module.profileReady) loading.classList.add('done');
requestAnimationFrame(watch);
}
window.Module = {
canvas: document.getElementById('canvas'),
locateFile: assetUrl,
setStatus: function (text) {
var match = /\((\d+(?:\.\d+)?)\/(\d+)\)/.exec(text || '');
if (match) bar.style.width = Math.min(100, 100 * match[1] / match[2]) + '%';
@@ -56,26 +71,116 @@
onAbort: failed,
onExit: function (code) { if (code !== 0) failed(); }
};
// Bundles travel gzip-compressed beside their plain copies: Cloudflare
// does not compress binary files. Browsers without DecompressionStream,
// or a missing .gz, take the plain file; null when neither exists.
function plain(name) {
return fetch(assetUrl(name)).then(function (response) {
return response.ok ? response.arrayBuffer() : null;
});
}
function bundle(name) {
if (typeof DecompressionStream !== 'function') return plain(name);
return fetch(assetUrl(name + '.gz')).then(function (response) {
if (!response.ok) throw new Error(response.status);
return response.arrayBuffer();
}).then(function (packed) {
var head = new Uint8Array(packed, 0, Math.min(2, packed.byteLength));
// A server that already decoded it hands over the plain bytes.
if (head[0] !== 0x1f || head[1] !== 0x8b) return packed;
return new Response(new Blob([packed]).stream()
.pipeThrough(new DecompressionStream('gzip'))).arrayBuffer();
}).catch(function () { return plain(name); });
}
function hex(buffer) {
return Array.prototype.map.call(new Uint8Array(buffer), function (byte) {
return (byte < 16 ? '0' : '') + byte.toString(16);
}).join('');
}
function file(name) {
return fetch(assetUrl(name)).then(function (response) {
if (!response.ok) throw new Error(response.status);
return response.arrayBuffer();
});
}
// The library's pictures come from this site, never api.waozi.xyz:
// small copies of the collection's signed art (library.json), each
// checked against its digest, or the exact art bundle for a browser
// that cannot draw WebP or check them. The host verifies that bundle.
function library() {
return fetch(assetUrl('library.json')).then(function (response) {
return response.ok ? response.json() : null;
}).then(function (listing) {
if (!listing) return null;
var paths = Object.keys(listing.pictures);
return Promise.all(paths.map(function (path) {
var picture = listing.pictures[path];
return file(picture.file).then(function (bytes) {
return crypto.subtle.digest('SHA-256', bytes).then(function (digest) {
if (hex(digest) !== picture.sha256) throw new Error(path);
return bytes;
});
});
})).then(function (copies) {
var webp = paths.findIndex(function (path) { return /\.webp$/.test(listing.pictures[path].file); });
var drawn = webp < 0 ? Promise.resolve() : createImageBitmap(new Blob([copies[webp]])).then(function (bitmap) { bitmap.close(); });
return drawn.then(function () { return { art: listing.art, paths: paths, copies: copies }; });
}).catch(function () {
return file('library/' + listing.art + '.zx').then(function (bundle) {
return { art: listing.art, bundle: bundle };
});
});
}).catch(function () { return null; });
}
function writeLibrary(pictures) {
if (pictures.bundle) {
FS.mkdirTree('/packages');
FS.writeFile('/packages/' + pictures.art + '.zx', new Uint8Array(pictures.bundle));
return;
}
pictures.paths.forEach(function (path, index) {
var name = '/library/' + pictures.art + '/' + path;
FS.mkdirTree(name.slice(0, name.lastIndexOf('/')));
FS.writeFile(name, new Uint8Array(pictures.copies[index]));
});
}
// The build receipt names the collection's digest and its trusted Apps
// library; Arcade's own copy of that library goes in beside it.
Promise.all([
fetch('arcade.json', { cache: 'no-cache' }).then(function (response) {
fetch(assetUrl('arcade.json'), { cache: 'no-cache' }).then(function (response) {
if (!response.ok) throw new Error(response.status);
return response.text();
}),
fetch('apps.zx').then(function (response) {
return response.ok ? response.arrayBuffer() : null;
})
bundle('apps.zx'),
bundle('runtime.data'),
library()
]).then(function (loaded) {
Module.arcadeReceipt = loaded[0];
if (loaded[1]) {
Module.preRun = [function () { FS.writeFile('/apps.zx', new Uint8Array(loaded[1])); }];
Module.preRun = [function () {
if (loaded[1]) FS.writeFile('/apps.zx', new Uint8Array(loaded[1]));
if (loaded[3]) writeLibrary(loaded[3]);
}];
// The runtime's file package, already here, is not fetched again.
if (loaded[2]) {
Module.getPreloadedPackage = function () { return loaded[2]; };
}
var script = document.createElement('script');
script.src = 'runtime.js';
script.onerror = failed;
document.body.appendChild(script);
watch();
function start() {
var script = document.createElement('script');
script.src = assetUrl('runtime.js');
script.onerror = failed;
document.body.appendChild(script);
watch();
}
// One sign-in for every waozi.xyz site: account.waozi.xyz hands over
// the shared profile before Arcade starts, or Arcade starts without it.
var started = false;
function go() { if (!started) { started = true; start(); } }
var shared = document.createElement('script');
shared.src = 'https://account.waozi.xyz/share.js';
shared.onload = function () { WaoziAccount.attach(Module, 2500).then(go, go); };
shared.onerror = go;
setTimeout(go, 4000);
document.head.appendChild(shared);
}).catch(failed);
})();
</script>
+2
View File
@@ -1,5 +1,6 @@
#import "android_device"
#import "android_jni"
Handoff :: #import "entity/account_handoff";
#import "android_picker"
#import "c_string"
@@ -23,6 +24,7 @@ JNI_OnLoad :: (vm: *JniVm, reserved: *void) -> s32 {
unused reserved
version := AndroidJniOnLoad(vm, "xyz/waozi/arcade/ArcadeActivity")
if version != JniVersion { return version }
Handoff.AccountHandoffJniOnLoad(vm)
env: *JniEnv
if vm.functions.GetEnv(vm, *env, JniVersion) != 0 || env == null { return -1 }
class_name: [64]u8
+2
View File
@@ -43,6 +43,8 @@ ArcadeStart :: () -> bool {
// Standalone Shovey opens on its covers, as Arcade opens on its library.
opened = CollectionOpenShoveyBytes(bundle, metadata, data)
} else {
// The reviewed shared Apps controller is a host asset, like Entity.
collection_controller = ReadAppAsset("apps.zx")
opened = CollectionOpenBytes(bundle, metadata, data)
}
if !opened {
+5 -4
View File
@@ -9,13 +9,14 @@ Game :: struct {
enabled: bool
}
GameCount :: 5
GameCount :: 6
GameAt :: (index: s32) -> Game {
if index == 0 { return Game.{.id = "inbe.chess", .name = "chess", .title = "Chess", .bundle = "chess.zx", .preview = "chess-preview.png", .package = "self", .enabled = false} }
if index == 1 { return Game.{.id = "arcade.shovey", .name = "shovey", .title = "Shovey", .bundle = "shovey.zx", .preview = "shovey-preview.png", .package = "shovey", .enabled = true} }
if index == 2 { return Game.{.id = "arcade.shovey-island", .name = "shovey-island", .title = "Shovey Island", .bundle = "shovey-island.zx", .preview = "shovey-island-preview.png", .package = "shovey", .enabled = false} }
if index == 3 { return Game.{.id = "arcade.shovey-editor", .name = "shovey-editor", .title = "Shovey Editor", .bundle = "shovey-editor.zx", .preview = "shovey-editor-preview.png", .package = "shovey", .enabled = true} }
if index == 4 { return Game.{.id = "xyz.waozi.wurm", .name = "wurm", .title = "Apfelwurm", .bundle = "wurm.zx", .preview = "wurm-preview.png", .package = "wurm", .enabled = true} }
if index == 2 { return Game.{.id = "arcade.shovey-editor", .name = "shovey-editor", .title = "Shovey Editor", .bundle = "shovey-editor.zx", .preview = "shovey-editor-preview.png", .package = "shovey", .enabled = true} }
if index == 3 { return Game.{.id = "xyz.waozi.wurm", .name = "wurm", .title = "Apfelwurm", .bundle = "wurm.zx", .preview = "wurm-preview.png", .package = "wurm", .enabled = true} }
if index == 4 { return Game.{.id = "xyz.waozi.wurm-editor", .name = "wurm-editor", .title = "Apfelwurm Editor", .bundle = "wurm-editor.zx", .preview = "wurm-editor-preview.png", .package = "wurm", .enabled = true} }
if index == 5 { return Game.{.id = "xyz.waozi.choano", .name = "choano", .title = "Choano", .bundle = "choano.zx", .preview = "choano-preview.png", .package = "choano", .enabled = true} }
return Game.{}
}
+46 -2
View File
@@ -25,6 +25,13 @@ CollectionPackage :: struct {
collection_packages: *CollectionPackage;
collection_package_result: string;
collection_package_files: *AppFiles;
// Packages the platform already holds, read-only and verified like a
// download: the website's own copy of the library art. "" for none.
collection_package_folder: string;
// Set by the host's origin-specific connection choice. Cached bytes do not
// need a connection; no new transfer is permitted while it is off.
collection_package_allowed: bool;
collection_package_origin: string;
package_c :: #system_library "c";
PackageFree :: (memory: *void) #foreign package_c "free";
CollectionDownloadsOpen :: (files: *AppFiles) { collection_package_files = files }
@@ -61,6 +68,20 @@ CollectionPackageFor :: (entry: *AppEntry) -> *CollectionPackage {
package.bytes = ""
package.failed = true
}
if package.bytes == "" && collection_package_folder != "" {
held: Vec(u8)
BuilderPrint(*held, "%/%.zx", collection_package_folder, TextUntilNul(package.digest[:]))
path := BuilderFinish(held)
package.bytes = CollectionReadPackage(path)
AppFileFree(path)
if package.bytes != "" && CollectionPackageValid(package) {
package.failed = false
} else if package.bytes != "" {
AppFileFree(package.bytes)
package.bytes = ""
package.failed = true
}
}
package.next = collection_packages
collection_packages = package
return package
@@ -103,11 +124,12 @@ CollectionFetch :: (context: *void, account: string, parent: *AppNode,
if operation != APPS_INSTALL { return false }
// Cached installs and removals use the host's ordinary saved state.
if package.bytes != "" { return false }
if !collection_package_allowed { reply.status = APPS_REJECTED; return true }
if package.transfer.status != .Downloading {
FileDownloadRelease(*package.transfer)
package.failed = false
base := EnvironmentText("ARCADE_PACKAGE_ORIGIN")
if base == "" { base = "https://api.waozi.xyz" }
base := collection_package_origin
if base == "" { return false }
url: Vec(u8)
BuilderPrint(*url, "%/api/v2/packages/inbe.arcade/%.zx", base, TextUntilNul(package.digest[:]))
address := BuilderFinish(url)
@@ -119,6 +141,28 @@ CollectionFetch :: (context: *void, account: string, parent: *AppNode,
return true
}
CollectionDownloadsBusy :: () -> bool {
package := collection_packages
while package != null {
if package.transfer.status == .Downloading { return true }
package = package.next
}
return false
}
CollectionDownloadsAllow :: (allowed: bool) {
collection_package_allowed = allowed
if allowed { return }
package := collection_packages
while package != null {
if package.transfer.status == .Downloading {
FileDownloadRelease(*package.transfer)
package.failed = true
}
package = package.next
}
}
CollectionDownloadsPump :: () {
package := collection_packages
while package != null {
+341 -14
View File
@@ -26,6 +26,9 @@
#import "kryon/app_files"
#import "kryon/app_protocol"
#import "kryon/app_context_host"
#if !#defined(PLATFORM_DESKTOP) && !#defined(ANDROID_BUILD) && !#defined(PLATFORM_WEB) {
CollectionHost :: #import "kryon/app_context";
}
#import "kryon/key_input"
#import "kryon/system_clipboard"
#import "apps/host"
@@ -38,15 +41,21 @@ Node :: #import "apps/node_types";
Codec :: #import "apps/node_codec";
#import "platform"
#import, file "collection_downloads.zi";
#import, file "game_contract.zi";
#import "sound"
#import "entity_host"
#import "entity/publications"
#import "entity/publications_read"
#import "entity/entity_records"
#import "entity/entity_dew"
#import "entity/leaderboard_native"
#import "kryon/widget_palette"
#import "kryon/image_raster"
#import "kryon/loading_indicator"
#import, file "collection_loading.zi";
#import "apps/connection"
#import "apps/remote_catalog"
Labels :: #import "apps/words";
#import "shovey/shovey_theme"
ProfileIcon :: #import "mingcute/mingcute_regular_user_4";
DewIcon :: #import "mingcute/mingcute_filled_drop";
@@ -90,12 +99,23 @@ collection_leave_to_library: bool;
// 2 not answered yet.
collection_updates: s32 = -1;
CollectionTouchFirst :: () -> bool {
#if #defined(PLATFORM_DESKTOP) {
return false
// Whether the device's main input is a keyboard and mouse. A native build
// knows its platform; the collection running as a bundle inside Breeze asks
// Breeze (Kryon's kryon.input.desktop), and passes the answer to its games.
CollectionInputDesktop :: () -> bool {
#if #defined(PLATFORM_DESKTOP) && !#defined(ANDROID_BUILD) && !#defined(PLATFORM_WEB) {
return true
} else {
#if #defined(ANDROID_BUILD) || #defined(PLATFORM_WEB) {
return false
} else {
return CollectionHost.AppSupports(COLLECTION_INPUT_DESKTOP)
}
}
return true
}
COLLECTION_INPUT_DESKTOP :: "kryon.input.desktop"
CollectionTouchFirst :: () -> bool { return !CollectionInputDesktop() }
CollectionRecordsFor :: (id: string) -> *CollectionRecords {
saved := collection_records
@@ -129,11 +149,13 @@ CollectionAllows :: (context: *void, node: *AppNode, name: string) -> bool {
return name == "AppRecordHost" || name == "SaveAppRecordHost" ||
name == "AppFriendHost" || name == "AppSharedHost" || name == "AppSharedItemHost" ||
name == "AppInvitationHost" || name == "RefreshAppSharedHost" || name == "SendAppSharedHost" ||
name == "SmoothFramesHost" || name == "AppLocaleHost" || name == "AppSoundHost" ||
name == "SmoothFramesHost" || name == "AppLocaleHost" || name == "AppSoundHost" || name == "AppNowHost" ||
name == "tile_map.sampling" || name == "arcade.controls" || name == "arcade.sound" || name == "arcade.navigation" ||
name == "arcade.updates" ||
name == PUBLICATIONS_READ_SERVICE || name == ENTITY_RECORDS_SERVICE || name == ENTITY_DEW_SERVICE ||
name == "entity.profile"
name == PUBLICATIONS_SERVICE || name == PUBLICATIONS_READ_SERVICE ||
name == ENTITY_RECORDS_SERVICE || name == ENTITY_DEW_SERVICE ||
name == "entity.profile" || name == "leaderboard" ||
(name == COLLECTION_INPUT_DESKTOP && CollectionInputDesktop())
}
CollectionCall :: (context: *void, node: *AppNode, module: *u8, function: *u8,
@@ -167,6 +189,12 @@ CollectionCall :: (context: *void, node: *AppNode, module: *u8, function: *u8,
result.* = HostScalar("bool", ifx asset.found && SoundPlay(asset.data) then 1 else 0)
return 1
}
// Seconds since 1970: Apfelwurm counts its daily rewards by them.
if name == "AppNowHost" && count == 0 {
result.* = HostValue.{.kind = cast(s32)HostReal, .type_name = HostTextData("float64"),
.real = cast(float64)UnixMilliseconds() / 1000.0}
return 1
}
if name == "SmoothFramesHost" && count == 1 {
result.* = HostScalar("bool", 1)
return 1
@@ -176,7 +204,19 @@ CollectionCall :: (context: *void, node: *AppNode, module: *u8, function: *u8,
HostScalarValid(arguments[1], "string", cast(s32)HostString) {
service := AppArgumentText(arguments[0])
request := AppArgumentText(arguments[1])
if service == "leaderboard" {
saved := EntityLeaderboardReport("arcade", "Arcade", TextUntilNul(node.identity.id[:]),
TextUntilNul(node.entry.title[:]), request)
result.* = AppHostText(ifx saved then "{\"status\":\"saved\"}" else "{\"status\":\"rejected\"}")
return 1
}
// Public level collections, such as a game's live campaign.
if service == PUBLICATIONS_SERVICE {
// Publications sign as this device's native Entity account.
EntityPump()
result.* = AppHostText(PublicationsAnswer(request))
return 1
}
if service == PUBLICATIONS_READ_SERVICE {
result.* = AppHostText(PublicationsReadAnswer(request))
return 1
@@ -280,14 +320,47 @@ CollectionCall :: (context: *void, node: *AppNode, module: *u8, function: *u8,
return 0
}
// The website's small copies of a collection's separate library art, under
// its signed catalog's art digest. The page writes only copies whose digests
// match its library.json (scripts/build-web.py); "" on other hosts.
collection_thumbnails: string;
CollectionThumbnail :: (node: *AppNode, path: string) -> string {
if collection_thumbnails == "" || node == null || !node.collection ||
node.catalog.art_sha256[0] == 0 || !AppAssetPathValid(path) { return "" }
copy: Vec(u8)
BuilderPrint(*copy, "%/%/%", collection_thumbnails, TextUntilNul(node.catalog.art_sha256[:]), path)
thumbnail := BuilderFinish(copy)
file := OpenRead(thumbnail)
if file.valid { unused CloseFile(file); return thumbnail }
AppFileFree(thumbnail)
return ""
}
// The website names where its page writes the library's pictures: small
// copies, or the exact art bundle for a browser that cannot draw them.
CollectionWebLibrary :: (thumbnails: string, packages: string) {
collection_thumbnails = thumbnails
collection_package_folder = packages
}
CollectionAssetAllowed :: (path: string) -> bool {
return path == "" || (collection_widget_node != null && (AppHostAsset(collection_widget_node, path).found ||
AppHostAssetPending(collection_widget_node, path)))
if path == "" { return true }
if collection_widget_node == null { return false }
// Checked first: asking for the art itself starts its download.
thumbnail := CollectionThumbnail(collection_widget_node, path)
if thumbnail != "" { AppFileFree(thumbnail); return true }
return AppHostAsset(collection_widget_node, path).found || AppHostAssetPending(collection_widget_node, path)
}
CollectionAssetPath :: (path: string) -> string {
if path == "" { return "" }
if collection_widget_node == null { return "" }
thumbnail := CollectionThumbnail(collection_widget_node, path)
if thumbnail != "" {
if !VecPush(collection_frame_paths, thumbnail) { AppFileFree(thumbnail); return "" }
return thumbnail
}
asset := AppHostAsset(collection_widget_node, path)
if !asset.found { collection_pictures_missing = true; return "" }
relative := Join(TextUntilNul(collection_widget_node.entry.sha256[:]), path)
@@ -322,6 +395,27 @@ CollectionWidgets :: (context: *void, node: *AppNode, module: *u8, function: *u8
return WidgetHostCall(context, module, function, arguments, count, result)
}
// Check the same saved install state and verified download plan as Apps.
// A cached payload or an old score alone is never installed membership.
CollectionLeaderboardInstalled :: (game: string) -> bool {
if !collection_ready { return false }
for slot: cast(s64)0..collection_host.tree.nodes.count - 1 {
parent := collection_host.tree.nodes[slot].node
if parent == null || !parent.collection { continue }
index := AppCatalogFind(*parent.catalog, game)
if index < 0 { continue }
entry := AppCatalogAt(*parent.catalog, index)
identity := AppIdentity.{.authority = parent.identity.authority, .id = entry.id}
state: AppState
plan: AppInstallPlan
if CollectionState(null, "local", *identity, *state) && state.installed &&
AppHostInstallPlan(*collection_host, parent, entry, *plan) && plan.count == 0 {
return true
}
}
return false
}
CollectionSave :: (context: *void, node: *AppNode) -> bool {
saved := collection_records
while saved != null {
@@ -397,22 +491,42 @@ CollectionController :: (context: *void) -> HostedAsset {
return controller
}
// Packed standalone collections carry their games and art. Thin Arcade
// uses the ordinary generic Apps download, install and cached bundle path.
CollectionOpen :: (bundle: string, digest: string, harness_digest: string,
data: string, locale: string) -> bool {
data: string, locale: string, packed: bool) -> bool {
if collection_ready { return false }
leaderboard_installed = CollectionLeaderboardInstalled
collection_directory = data
collection_resource_root = Join(data, "resources")
opened := AppFilesOpen(*collection_resources, collection_resource_root)
if !opened { Report("Arcade: cannot open the private resources folder"); return false }
CollectionDownloadsOpen(*collection_resources)
return CollectionStart(bundle, digest, harness_digest, locale, packed)
}
// Replacing a verified catalog reuses the host services and per-game saves.
CollectionStart :: (bundle: string, digest: string, harness_digest: string,
locale: string, packed: bool) -> bool {
platform := AppPlatform.{.allows = CollectionAllows, .call = CollectionCall,
.widgets = CollectionWidgets, .save = CollectionSave, .state = CollectionState,
.effect = CollectionEffect,
.bundle = CollectionBundle, .download = CollectionDownload, .fetch = CollectionFetch,
.effect = CollectionEffect, .host_api = GAME_HOST_API,
// Covers show only the art; the download dialog names the size.
.controller = CollectionController, .presentation = AppPresentation.{.cover_grid = true, .hide_sizes = true}}
if !packed {
platform.bundle = CollectionBundle
platform.download = CollectionDownload
platform.fetch = CollectionFetch
}
collection_ready = AppHostStart(*collection_host, bundle, "arcade.local", "inbe.arcade",
"arcade", digest, "local", platform, harness_digest, locale)
// The offline collection already contains every game's payload. Keep the
// ordinary bounded game budget available in addition to that resident
// collection; otherwise its packed bytes consume the game's allowance
// before the first game opens. AppHostStart bounds the root to 64 MiB.
if collection_ready && packed {
collection_host.tree.byte_limit = APP_HOST_BYTE_LIMIT + bundle.count
}
if !collection_ready { Report("Arcade: the shared Apps host refused the collection") }
return collection_ready
}
@@ -440,6 +554,7 @@ CollectionOpenBytes :: (bytes: string, metadata: string, data: string) -> bool {
id: [128]u8
digest: [65]u8
harness: [65]u8
games: [16]u8
if !AppsReadText(metadata, 0, "id", id[:]) || TextUntilNul(id[:]) != "inbe.arcade" ||
!AppsReadText(metadata, 0, "sha256", digest[:]) ||
!AppsReadText(metadata, 0, "apps_sha256", harness[:]) {
@@ -448,7 +563,24 @@ CollectionOpenBytes :: (bytes: string, metadata: string, data: string) -> bool {
}
locale := EnvironmentText("LANG")
language := ifx locale.count >= 2 then locale[:2] else "en"
return CollectionOpen(bytes, TextUntilNul(digest[:]), TextUntilNul(harness[:]), data, language)
packed := AppsReadText(metadata, 0, "games", games[:]) && TextUntilNul(games[:]) == "packed"
selected := bytes
selected_digest := TextUntilNul(digest[:])
if !packed {
if !CollectionNodeOpen(metadata, data, bytes, selected_digest, TextUntilNul(harness[:]), language) { return false }
if collection_node.ready {
selected = collection_node.bytes
selected_digest = TextUntilNul(collection_node.release.artifacts[0].sha256[:])
}
}
opened := CollectionOpen(selected, selected_digest, TextUntilNul(harness[:]), data, language, packed)
if !opened && !packed && collection_node_remote {
collection_node_remote = false
collection_node.failed = true
opened = CollectionStart(collection_seed, TextUntilNul(collection_seed_digest[:]),
TextUntilNul(collection_harness_digest[:]), language, false)
}
return opened
}
// The standalone player needs only Shovey's own payload and metadata. Its
@@ -464,8 +596,16 @@ CollectionOpenShovey :: (directory: string, data: string) -> bool {
return found && metadata_found && CollectionOpenShoveyBytes(bytes, metadata, data)
}
// Metadata of the standalone Shovey player, as the downloads and
// shovey.waozi.xyz carry it, rather than of Arcade's collection.
CollectionShoveyReceipt :: (metadata: string) -> bool {
id: [128]u8
return AppsReadText(metadata, 0, "id", id[:]) && TextUntilNul(id[:]) == "arcade.shovey-player"
}
CollectionOpenShoveyBytes :: (bytes: string, metadata: string, data: string) -> bool {
if collection_ready { return false }
leaderboard_installed = CollectionLeaderboardInstalled
id: [128]u8
digest: [65]u8
harness: [65]u8
@@ -480,7 +620,7 @@ CollectionOpenShoveyBytes :: (bytes: string, metadata: string, data: string) ->
language := ifx locale.count >= 2 then locale[:2] else "en"
platform := AppPlatform.{.allows = CollectionAllows, .call = CollectionCall,
.widgets = CollectionWidgets, .save = CollectionSave, .state = CollectionState,
.effect = CollectionEffect}
.effect = CollectionEffect, .host_api = GAME_HOST_API}
collection_ready = AppHostStart(*collection_host, bytes, "arcade.local", "arcade.shovey-player",
"shovey", TextUntilNul(digest[:]), "local", platform, TextUntilNul(harness[:]), language)
return collection_ready
@@ -498,6 +638,7 @@ CollectionCollect :: () {
if entity_ready { EntityPump() }
PublicationsReadPump()
AppHostCollect(*collection_host)
CollectionNodePump()
for path: collection_frame_paths { AppFileFree(path) }
while collection_frame_paths.count > 0 { unused VecPop(collection_frame_paths) }
collection_widget_node = null
@@ -507,6 +648,7 @@ CollectionClose :: () -> bool {
if !EntityClose() { return false }
if collection_ready && !AppHostStop(*collection_host) { return false }
collection_ready = false
CollectionNodeClose()
collection_loading = .{}
CollectionDownloadsClose()
CollectionCollect()
@@ -646,6 +788,7 @@ CollectionUpdatesQuestion :: (session: Session, viewport: Rectangle) {
CollectionFrame :: (session: Session, viewport: Rectangle, key: s32, modifiers: s32) -> bool {
collection_toolbar_visible = true
defer { CollectionToolbar(session, viewport) }
if CollectionNodeScreen(session, viewport) { collection_toolbar_visible = false; return true }
if entity_visible { return EntityFrame(session, viewport, key, modifiers) }
runtime := AppHostActiveRuntime(*collection_host)
if runtime == null { Report("Arcade: no app is running\n"); return false }
@@ -663,6 +806,7 @@ CollectionFrame :: (session: Session, viewport: Rectangle, key: s32, modifiers:
asking := runtime.node.collection && !collection_host.platform.presentation.cover_grid && CollectionUpdates() == 2
if asking { key = 0 }
top: s32 = ifx !covered && !runtime.node.collection && (entity_ready || nested) then 56 else 0
if runtime.node.collection && collection_node.files != null { top = 88 }
now := cast(float64)MonotonicMilliseconds() / 1000.0
runtime.app.session = session
runtime.app.bounds = Rectangle.{viewport.x, viewport.y + cast(float32)top, viewport.width, viewport.height - cast(float32)top}
@@ -721,6 +865,7 @@ CollectionFrame :: (session: Session, viewport: Rectangle, key: s32, modifiers:
}
} else if runtime.node.collection {
collection_loading = .{}
CollectionNodeToolbar(session, viewport)
}
if asking {
unused WidgetPaletteUse(session, ifx entity_shovey then ShoveyPalette() else AppCoversPalette())
@@ -771,3 +916,185 @@ CollectionToolbar :: (session: Session, viewport: Rectangle) {
c :: #system_library "c";
CollectionFree :: (memory: *void) #foreign c "free";
// The native host composes the shared Apps connection and signed catalog.
// Replacing a root uses the same services and saved-game namespaces.
collection_node: AppRemoteCatalog;
collection_node_files: AppFiles;
collection_node_root: string;
collection_node_choice: s32;
collection_node_notice: bool;
collection_node_initial: bool;
collection_node_apply: bool;
collection_node_remote: bool;
collection_seed: string;
collection_seed_digest: [65]u8;
collection_harness_digest: [65]u8;
collection_node_locale: [16]u8;
collection_signature :: #system_library "c";
CollectionCheckSignature :: (signature: *u8, public_key: *u8, message: *u8,
length: usize) -> s32 #foreign collection_signature "crypto_ed25519_check";
CollectionVerifyRelease :: (signature: *u8, public_key: *u8, message: *u8,
length: usize) -> bool { return CollectionCheckSignature(signature, public_key, message, length) == 0 }
CollectionNodeOpen :: (metadata: string, data: string, seed: string,
digest: string, harness: string, locale: string) -> bool {
source: AppRemoteSource
source.oldest_host_api = 1
source.host_api = GAME_HOST_API
source.module_api = 2
at := FieldAt(metadata, 0, "node")
if at < 0 || !AppRemoteSourceRead(metadata, at, *source) || TextUntilNul(source.app_id[:]) != "inbe.arcade" { return false }
// Private loopback fixtures can exercise the real transport. A production
// environment variable cannot silently redirect a publisher's requests.
test_origin := EnvironmentText("ARCADE_PACKAGE_ORIGIN")
if test_origin.count > 17 && test_origin[:17] == "http://127.0.0.1:" && AppRemoteOriginValid(test_origin) {
unused CopyCString(test_origin, source.origin[:])
}
collection_node_root = Join(data, "node")
if !AppFilesOpen(*collection_node_files, collection_node_root) { return false }
if !AppRemoteCatalogOpen(*collection_node, source, *collection_node_files, CollectionVerifyRelease) { return false }
collection_seed = AppRemoteCopy(seed)
unused CopyCString(digest, collection_seed_digest[:])
unused CopyCString(harness, collection_harness_digest[:])
unused CopyCString(locale, collection_node_locale[:])
collection_package_origin = AppRemoteCopy(TextUntilNul(collection_node.source.origin[:]))
collection_node_choice = AppConnectionRead(*collection_node_files, collection_package_origin)
collection_node_notice = collection_node_choice == APP_CONNECTION_UNDECIDED
allowed := collection_node_choice == APP_CONNECTION_ALLOWED
CollectionDownloadsAllow(allowed)
AppRemoteCatalogAllow(*collection_node, allowed)
collection_node_remote = collection_node.ready
if allowed { unused AppRemoteCatalogRefresh(*collection_node) }
return true
}
CollectionNodeChoose :: (choice: s32) -> bool {
if !AppConnectionRemember(*collection_node_files, collection_package_origin, choice) { return false }
collection_node_choice = choice
collection_node_notice = false
allowed := choice == APP_CONNECTION_ALLOWED
CollectionDownloadsAllow(allowed)
AppRemoteCatalogAllow(*collection_node, allowed)
if allowed {
collection_node_initial = !collection_node_remote
collection_node_apply = true
unused AppRemoteCatalogRefresh(*collection_node)
}
return true
}
CollectionNodeActivate :: () -> bool {
if !collection_node.changed || CollectionDownloadsBusy() { return false }
runtime := AppHostActiveRuntime(*collection_host)
if runtime == null || !runtime.node.collection { return false }
if !AppHostStop(*collection_host) { return false }
collection_ready = false
{
bytes := collection_node.bytes
digest := TextUntilNul(collection_node.release.artifacts[0].sha256[:])
collection_ready = CollectionStart(bytes, digest, TextUntilNul(collection_harness_digest[:]),
TextUntilNul(collection_node_locale[:]), false)
}
if collection_ready {
collection_node_remote = true
AppRemoteCatalogCollect(*collection_node)
} else {
// Keep the former library and every game's separate save namespace.
if collection_node.previous_bytes != "" {
unused AppRemoteCatalogRestore(*collection_node)
} else {
unused AppFileWrite(*collection_node_files, "current.json", "")
collection_node_remote = false
collection_node.changed = false
collection_node.failed = true
}
old_bytes := ifx collection_node_remote then collection_node.bytes else collection_seed
old_digest := ifx collection_node_remote then TextUntilNul(collection_node.release.artifacts[0].sha256[:]) else TextUntilNul(collection_seed_digest[:])
collection_ready = CollectionStart(old_bytes, old_digest, TextUntilNul(collection_harness_digest[:]),
TextUntilNul(collection_node_locale[:]), false)
}
collection_loading = .{}
return collection_ready
}
CollectionNodePump :: () {
if collection_node.files == null { return }
AppRemoteCatalogPump(*collection_node)
if collection_node_apply && collection_node.stage == 0 {
if collection_node.changed && !CollectionNodeActivate() { return }
collection_node_apply = false
collection_node_initial = false
}
}
// Returns true when the notice/loading screen owns this frame's input.
CollectionNodeScreen :: (session: Session, viewport: Rectangle) -> bool {
if collection_node.files == null { return false }
if collection_node_notice {
choice := AppConnectionNotice(session, viewport, TextUntilNul(collection_node_locale[:]),
collection_package_origin, cast(u64)49500)
if choice != APP_CONNECTION_UNDECIDED { unused CollectionNodeChoose(choice) }
return true
}
if collection_node_initial && collection_node.stage != 0 {
Box(session, BoxProps.{.key = cast(u64)49510, .bounds = viewport, .fill = Color.{17, 18, 35, 255}})
Text(session, TextProps.{.key = cast(u64)49511, .text = Labels.AppsLabel(TextUntilNul(collection_node_locale[:]), "loading_library"),
.font = 20, .bounds = Rectangle.{viewport.x + 24.0, viewport.y + viewport.height / 2.0, viewport.width - 48.0, 64.0}})
if Button(session, ButtonProps.{.key = cast(u64)49512, .id = 49512,
.label = Labels.AppsLabel(TextUntilNul(collection_node_locale[:]), "stay_offline"),
.bounds = Rectangle.{viewport.x + 24.0, viewport.y + viewport.height / 2.0 + 72.0, viewport.width - 48.0, 44.0},
.tone = ButtonTone.ButtonToneNeutral, .emphasis = ButtonEmphasis.ButtonEmphasisSoft}) != 0 {
unused CollectionNodeChoose(APP_CONNECTION_OFFLINE)
}
return true
}
return false
}
CollectionNodeToolbar :: (session: Session, viewport: Rectangle) {
if collection_node.files == null { return }
unused WidgetPaletteUse(session, AppCoversPalette())
defer { unused WidgetPaletteRestore(session) }
Box(session, BoxProps.{.key = cast(u64)49519,
.bounds = Rectangle.{viewport.x, viewport.y, viewport.width, 88.0},
.fill = Color.{17, 18, 35, 255}})
locale := TextUntilNul(collection_node_locale[:])
allowed := collection_node_choice == APP_CONNECTION_ALLOWED
status := ifx !allowed then "offline_library" else ifx collection_node.stage != 0 then "loading_library" else ifx collection_node.failed then "library_unavailable" else "saved_library"
width := ifx viewport.width - 180.0 < 320.0 then viewport.width - 180.0 else 320.0
if Button(session, ButtonProps.{.key = cast(u64)49520, .id = 49520,
.label = Labels.AppsLabel(locale, ifx allowed then "refresh_library" else "connect_node"),
.bounds = Rectangle.{viewport.x + 8.0, viewport.y + 6.0, width, 44.0},
.tone = ButtonTone.ButtonToneNeutral, .emphasis = ButtonEmphasis.ButtonEmphasisSoft}) != 0 {
if !allowed { collection_node_notice = true }
else if collection_node.changed { collection_node_apply = true }
else { collection_node_apply = true; unused AppRemoteCatalogRefresh(*collection_node) }
}
// A separate connection control keeps revocation available after consent.
if Button(session, ButtonProps.{.key = cast(u64)49521, .id = 49521,
.label = Labels.AppsLabel(locale, "node_connection"),
.bounds = Rectangle.{viewport.x + viewport.width - 170.0, viewport.y + 52.0, 158.0, 28.0},
.tone = ButtonTone.ButtonToneNeutral, .emphasis = ButtonEmphasis.ButtonEmphasisSoft}) != 0 {
collection_node_notice = true
}
Text(session, TextProps.{.key = cast(u64)49522, .text = Labels.AppsLabel(locale, status), .font = 12, .wrap = TextWrap.TextWrapAuto,
.bounds = Rectangle.{viewport.x + 16.0, viewport.y + 58.0, viewport.width - 196.0, 26.0}})
}
CollectionNodeClose :: () {
CollectionDownloadsAllow(false)
AppFileFree(collection_package_origin)
collection_package_origin = ""
AppRemoteCatalogClose(*collection_node)
AppFilesClose(*collection_node_files)
AppFileFree(collection_node_root)
AppFileFree(collection_seed)
collection_node_root = ""
collection_seed = ""
collection_node_notice = false
collection_node_initial = false
collection_node_apply = false
collection_node_remote = false
}
+2
View File
@@ -18,6 +18,8 @@
sdl :: #system_library "SDL2";
SetTitle :: (window: *void, title: *u8) #foreign sdl "SDL_SetWindowTitle";
// First show small RGB/RGBA previews. The collection replaces them with its
// original artwork when ready, using the same layout and coloured logo.
DrawStartup :: (session: Session, directory: string, standalone: bool = true) -> bool {
if !PollDesktop() || WindowTakeCloseRequestHost() { return false }
BeginDesktopFrame()
+6
View File
@@ -0,0 +1,6 @@
// The game standard every Arcade game implements (standards/game-v1.json).
// GAME_HOST_API is the newest host interface Arcade's players run; a game
// that declares a newer one is refused. scripts/check-games.py fails while it
// differs from the standard and the ledger.
GAME_CONTRACT_VERSION :: 1
GAME_HOST_API :: 41
+1 -2
View File
@@ -1,6 +1,7 @@
// Runs the registered game bundles. The host owns files and input;
// each game owns its rules and screens. Chess also runs in Inbe.
#import "std/file"
#import, file "game_contract.zi";
#import "std/bundle_host"
#import "std/byte_text_linux"
#import "std/date_time_linux"
@@ -19,8 +20,6 @@
using HostValueKind;
GAME_CONTRACT_VERSION :: 1
GAME_HOST_API :: 12
GameHost :: struct {
app: HostedApp
+1 -1
View File
@@ -1,4 +1,4 @@
// Classic, Island and Editor keep independent verified identities.
// Classic and the Editor keep independent verified identities.
#import "kryon/app_context"
#import "kryon/app_protocol"
+20 -4
View File
@@ -1,6 +1,8 @@
// Arcade in the browser: the same arcade.zx Inner Breeze downloads, with its
// shared Apps library, the account Profile and each game downloaded from the
// node when someone opens it. Saves stay in the page's persistent storage.
// Given the released Shovey player instead, the shovey.zx and shovey.json of
// the downloads, it is shovey.waozi.xyz and opens on Shovey's covers.
using Canvas :: #import "kryon/Canvas";
#import "kryon/bundle_storage_web"
#import "kryon/app_files"
@@ -54,7 +56,8 @@ ArcadeFrame :: (session: Session) -> bool {
TreeCancel(session)
return false
}
if EndFrame(session) != FrameStatus.FrameOk { return false }
// Only damaged pixels are cleared and repainted; the rest of the page stays.
if EndCanvasUiFrame(session) != FrameStatus.FrameOk { return false }
TestDriverFrame(session)
CanvasCursor(session)
ok := EndCanvasFrame()
@@ -78,17 +81,30 @@ main :: () -> s32 {
// The page writes Arcade's own Apps controller beside the collection.
controller, controller_found := ReadEntireFile("/apps.zx")
if controller_found { collection_controller = controller } else { AppFileFree(controller) }
if !found || !profile_found || receipt == "" || !CollectionOpenBytes(bytes, receipt, data) { return 1 }
if !EntityOpen(profile, data) { unused CollectionClose(); return 1 }
if !found || !profile_found || receipt == "" { return 1 }
// The page writes the library's pictures from this site: small copies
// under /library, or else the exact art bundle under /packages.
CollectionWebLibrary("/library", "/packages")
shovey := CollectionShoveyReceipt(receipt)
opened := ifx shovey then CollectionOpenShoveyBytes(bytes, receipt, data) else CollectionOpenBytes(bytes, receipt, data)
if !opened { return 1 }
if !EntityOpen(profile, data, shovey) { unused CollectionClose(); return 1 }
session := SessionOpen()
if !SessionValid(session) { unused CollectionClose(); return 1 }
defer { SessionClose(session) }
WebSet(WebGetObject(WebGlobal, WebName("Module")), WebName("profileReady"), WebBool(true))
saved := PageNow()
ok := true
while ok && PollCanvas() {
scope := WebScope()
ok = ArcadeFrame(session)
// main returning does not notify Emscripten's onExit unless its
// runtime exits too. Tell the page explicitly, so a failed game can
// never leave an apparently live library with no input loop.
if !ok {
WebSet(WebGetObject(WebGlobal, WebName("Module")), WebName("arcadeFailed"), WebBool(true))
} else {
WebSet(WebGetObject(WebGlobal, WebName("Module")), WebName("profileReady"), WebBool(true))
}
// Saves reach the browser's storage about once a second.
if PageNow() - saved >= 1000.0 {
unused BundleStorageSync(false)
+1 -1
View File
@@ -2,7 +2,7 @@
"name": "kryon-node-app",
"contract_version": 1,
"module_api": 2,
"host_api": 12,
"host_api": 41,
"identity": "Stable signed package ID; moving source must not rename installed games",
"frames": {
"matching": "Fields match by name",
+145
View File
@@ -0,0 +1,145 @@
"""Assert the actual staged/packaged Android assets contain no games or art."""
import json
import importlib.util
from pathlib import Path
import sys
import struct
import hashlib
import unittest
from unittest.mock import patch
import tempfile
import zipfile
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'scripts'))
from android_catalog import verify_assets
import android_catalog
class ProfileAssetResolutionTests(unittest.TestCase):
def test_dependency_resolution_matches_build_mode(self):
(ROOT / 'work').mkdir(exist_ok=True)
with tempfile.TemporaryDirectory(dir=ROOT / 'work') as temporary:
root = Path(temporary)
package = root / 'entity'
package.mkdir()
(package / 'asset-groups.json').write_text('{"profile": []}')
try:
for local in (False, True):
if local:
(root / 'ziran.local.toml').write_text('[overrides]\n')
android_catalog.profile_asset_hashes.cache_clear()
with self.subTest(local=local), patch.object(android_catalog, 'ROOT', root), \
patch.object(android_catalog.subprocess, 'check_output', return_value=str(package)) as resolve:
self.assertEqual(android_catalog.profile_asset_hashes(), {})
resolve.assert_called_once_with(
[str(root / 'scripts/ziran.sh'), 'pkg', 'path', 'entity',
*([] if local else ['--locked'])], cwd=root, text=True)
finally:
android_catalog.profile_asset_hashes.cache_clear()
class AndroidCatalogTests(unittest.TestCase):
@classmethod
def setUpClass(cls):
spec = importlib.util.spec_from_file_location('android_builder', ROOT / 'scripts/build-android.py')
builder = importlib.util.module_from_spec(spec)
spec.loader.exec_module(builder)
builder.stage_arcade()
def setUp(self):
self.assets = {name: (ROOT / 'build' / name).read_bytes()
for name in ('arcade.zx', 'arcade.json', 'apps.zx', 'entity.zx')}
self.assets['kryon-font.ttf'] = b'font' # Content boundary, not a font renderer.
def test_standard_catalog(self):
verify_assets(self.assets)
def test_reject_changed_node_trust_binding(self):
for key, value in (('origin', 'https://example.org'), ('public_key', 'a' * 64),
('app_id', 'inbe.other'), ('minimum_sequence', 0)):
metadata = json.loads(self.assets['arcade.json'])
metadata['node'][key] = value
with self.subTest(field=key), self.assertRaisesRegex(AssertionError, 'publisher binding'):
verify_assets(self.assets | {'arcade.json': json.dumps(metadata).encode()})
def test_reject_game_or_thumbnail_beside_catalog(self):
for name in ('games/shovey.zx', 'covers/shovey.png'):
with self.subTest(name=name), self.assertRaises(AssertionError):
verify_assets(self.assets | {name: b'payload'})
def test_reject_packed_collection(self):
with self.assertRaises(AssertionError):
verify_assets(self.assets | {'arcade.zx': b'packed' * 100000})
def test_reject_game_or_art_inside_bundle(self):
def number(n):
return struct.pack('<I', n)
def text(data):
return number(len(data)) + data
# Structurally valid ZX with a catalog and an extra embedded asset,
# in both bundle versions the toolchain writes (26 plain, 27 composed).
cases = [(version, path) for version in (26, 27)
for path in (b'assets/arcade/games/test.zx', b'assets/arcade/covers/test.png')]
for version, path in cases:
payload = b'ZX\0\0' + number(version) + text(b'') * 2 + number(0) * 4
payload += number(2) + text(b'assets/apps/catalog.json') + text(b'{}')
payload += text(path) + text(b'payload')
metadata = json.loads(self.assets['arcade.json'])
metadata['sha256'] = hashlib.sha256(payload).hexdigest()
with self.subTest(version=version, path=path), \
self.assertRaisesRegex(AssertionError, 'Game payload or art'):
verify_assets(self.assets | {'arcade.zx': payload, 'arcade.json': json.dumps(metadata).encode()})
def test_reject_game_art_nested_in_entity(self):
from android_catalog import profile_assets
def text(data):
return struct.pack('<I', len(data)) + data
names = sorted(profile_assets() | {'assets/entity/game-art.png'})
payload = b'ZX\0\0\x1b\0\0\0' + text(b'') * 2 + struct.pack('<IIII', 0, 0, 0, 0)
payload += struct.pack('<I', len(names))
payload += b''.join(text(name.encode()) + text(b'image') for name in names)
with self.assertRaisesRegex(AssertionError, 'Entity contains'):
verify_assets(self.assets | {'entity.zx': payload})
def test_reject_modified_profile_art(self):
from android_catalog import profile_assets
def text(data):
return struct.pack('<I', len(data)) + data
names = sorted(profile_assets())
payload = b'ZX\0\0\x1b\0\0\0' + text(b'') * 2 + struct.pack('<IIII', 0, 0, 0, 0)
payload += struct.pack('<I', len(names))
payload += b''.join(text(name.encode()) + text(b'changed image') for name in names)
with self.assertRaisesRegex(AssertionError, 'profile artwork differs'):
verify_assets(self.assets | {'entity.zx': payload})
def test_reject_packed_policy(self):
metadata = json.loads(self.assets['arcade.json']) | {'games': 'packed'}
with self.assertRaises(AssertionError):
verify_assets(self.assets | {'arcade.json': json.dumps(metadata).encode()})
def test_reject_unreviewed_controller(self):
with self.assertRaises(AssertionError):
verify_assets(self.assets | {'apps.zx': b'altered'})
def test_staged_android_assets(self):
folder = ROOT / 'build/android-assets'
if not folder.exists():
self.skipTest('Run make android to stage Android assets')
verify_assets({str(p.relative_to(folder)): p.read_bytes() for p in folder.rglob('*') if p.is_file()} |
{'entity.zx': (ROOT / 'build/entity.zx').read_bytes()})
if __name__ == '__main__':
if len(sys.argv) >= 2 and sys.argv[1].endswith('.apk'):
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('apk')
parser.add_argument('--edition', choices=('direct', 'fdroid', 'gplay'), default='direct')
args = parser.parse_args()
with zipfile.ZipFile(args.apk) as apk:
verify_assets({name[7:]: apk.read(name) for name in apk.namelist()
if name.startswith('assets/') and not name.endswith('/')}, edition=args.edition)
print('APK contains only the thin catalog and host essentials')
else:
unittest.main()
+44
View File
@@ -0,0 +1,44 @@
"""Every native registered on ArcadeActivity must exist with its JNI signature.
Android rejects the entire library in JNI_OnLoad when even one method is
missing. Check the resolved host, so a package update cannot silently ship
an activity that crashes before onCreate.
"""
from pathlib import Path
import re
import subprocess
ROOT = Path(__file__).resolve().parents[1]
def verify():
kryon = Path(subprocess.check_output(
[str(ROOT / 'scripts/ziran.sh'), 'pkg', 'path', 'kryon'],
cwd=ROOT, text=True).strip())
host = (kryon / 'src/backend/android_device.zi').read_text()
glue = (ROOT / 'src/android_glue.zi').read_text()
java = (ROOT / 'droid/app/src/main/java/xyz/waozi/arcade/ArcadeActivity.java').read_text()
types = {'void': 'V', 'int': 'I', 'long': 'J', 'boolean': 'Z',
'float': 'F', 'byte[]': '[B', 'String': 'Ljava/lang/String;'}
declared = {}
for result, name, arguments in re.findall(
r'native\s+(\w+)\s+(\w+)\(([^)]*)\)', java):
parameters = [argument.strip().split()[0] for argument in arguments.split(',') if argument.strip()]
declared[name] = '(' + ''.join(types[t] for t in parameters) + ')' + types[result]
registered = 0
for source in (host, glue):
names = dict((index, name) for name, index in re.findall(
r'CopyCString\("(native\w+)", names\[(\d+)\]', source))
signatures = dict((index, signature) for signature, index in re.findall(
r'CopyCString\("([^"]+)", signatures\[(\d+)\]', source))
for index, name in names.items():
expected = signatures[index]
assert declared.get(name) == expected, (
f'{name}{expected} registered by native host, Java declares {declared.get(name)}')
registered += 1
assert registered >= 12, 'No Android JNI registration contract found'
print(f'Android JNI contract: {registered} registered methods match ArcadeActivity')
if __name__ == '__main__':
verify()
+150
View File
@@ -0,0 +1,150 @@
"""Exercise APK assets through generic Apps install, open and offline cache."""
import argparse
import contextlib
import hashlib
import json
import os
from pathlib import Path
import shutil
import subprocess
import sys
import tempfile
import time
root = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(root / 'scripts'))
from android_catalog import verify_assets
from collection_ui_test import package_server, answer_library_question, answer_level_updates
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--binary', type=Path, required=True)
parser.add_argument('--inbe-source', type=Path, required=True)
args = parser.parse_args()
assert int(os.environ['DISPLAY'].split(':')[-1].split('.')[0]) >= 400
assert os.environ['YUE_DESKTOP_RECOVERY'] == '0'
assets = root / 'build/android-assets'
metadata = verify_assets({p.name: p.read_bytes() for p in assets.iterdir() if p.is_file()} |
{'entity.zx': (root / 'build/entity.zx').read_bytes()})
entries = {entry['expected_id']: entry for entry in metadata['children']}
sys.path.insert(0, str(args.inbe_source / 'tests'))
from ui_driver import UiDriver
output = root / 'work/android-offline-ui-test'
output.mkdir(parents=True, exist_ok=True)
driver = UiDriver(output / 'driver')
with tempfile.TemporaryDirectory(prefix='host-', dir=output) as temporary, package_server(root) as (origin, server):
install = Path(temporary) / 'app'
install.mkdir()
shutil.copy2(args.binary, install / 'arcade')
for name in ('arcade.zx', 'arcade.json', 'apps.zx'):
shutil.copyfile(assets / name, install / name)
shutil.copyfile(root / 'build/entity.zx', install / 'entity.zx')
profile = Path(temporary) / 'profile'
retained = profile / 'games/inbe.chess/records/computer'
retained.parent.mkdir(parents=True)
retained.write_bytes(b'existing private save')
record = profile / 'games/arcade.shovey/records/local.campaign'
@contextlib.contextmanager
def application(name):
log_path = output / (name + '.log')
with log_path.open('w') as log:
child = subprocess.Popen([str(install / 'arcade')], cwd=install,
env=os.environ | driver.environment() |
{'ARCADE_DATA': str(profile), 'ENTITY_DATA': str(profile / 'entity'),
'LANG': 'en_US.UTF-8', 'ARCADE_PACKAGE_ORIGIN': origin},
stdout=log, stderr=subprocess.STDOUT)
driver.attach(child, log_path)
try:
yield child
finally:
if child.poll() is None:
child.terminate()
child.wait(timeout=10)
def download(label='Download'):
driver.wait(label=label, role='button', timeout=60)
action = max(driver.find(label=label, role='button', visible=True), key=lambda node: node['width'])
driver.press(key=action['key'], role='button')
def play():
answer_level_updates(driver)
if driver.find(label='How do you want to move?', role='text'):
driver.press(label='Swipe and tap')
driver.wait(label='Restart', role='button', timeout=60)
assert not driver.find(label='Download', role='button')
with application('install'):
answer_library_question(driver)
games = {entry['sha256'] for entry in metadata['children']}
assert not games & set(server['requests']), 'No game before download consent'
driver.press(label='Shovey Editor', role='button')
driver.wait(label='Cancel', role='button')
driver.press(label='Cancel', role='button')
assert not games & set(server['requests']), 'Cancel must download nothing'
driver.press(label='Shovey Editor', role='button')
server['corrupt_shovey'] = True
download()
driver.wait(label='Try again', role='button', timeout=60)
assert not driver.find(label='New level', role='text'), 'Corrupt dependency must not open'
server['corrupt_shovey'] = False
download('Try again')
driver.wait(label='New level', role='text', timeout=60)
assert server['requests'].count(entries['shovey']['sha256']) == 2
assert server['requests'].count(entries['shovey-editor']['sha256']) == 1
driver.key('escape')
driver.wait(label='Shovey', role='button')
driver.press(label='Shovey', role='button')
play()
driver.key('right')
deadline = time.monotonic() + 20
while not record.exists() and time.monotonic() < deadline:
driver.wait_idle(frames=5)
assert record.exists(), 'Game must persist progress'
driver.press(label='Back', role='button')
driver.wait(label='Shovey', role='button')
driver.press(label='Apfelwurm', role='button')
download()
driver.wait(label='Play', role='button', timeout=60)
driver.key('escape')
driver.wait(label='Shovey', role='button')
driver.press(label='Profile', role='button')
driver.wait(label='Account', role='text')
driver.press(label='Leaderboard', role='button')
driver.wait(label='Apfelwurm', role='button')
driver.press(label='Apfelwurm', role='button')
# The profile stays usable with its optional game sheets omitted.
driver.wait(label='Back', role='button')
driver.press(label='Back', role='button')
driver.wait(label='Account', role='text')
driver.press(label='Back', role='button')
driver.key('escape')
driver.wait(label='Node connection', role='button')
driver.press(label='Node connection', role='button')
driver.wait(label='Stay offline', role='button')
driver.press(label='Stay offline', role='button')
driver.wait(label='Shovey', role='button')
saved = record.read_bytes()
for name in ('shovey', 'shovey-editor', 'wurm'):
entry = entries[name]
cached = profile / 'resources/downloads' / (entry['sha256'] + '.zx')
assert hashlib.sha256(cached.read_bytes()).hexdigest() == entry['sha256']
assert metadata['art']['sha256'] in server['requests'], 'Art must download separately'
requested = list(server['requests'])
server['offline'] = True
with application('offline'):
answer_library_question(driver)
driver.press(label='Shovey', role='button')
play()
driver.press(label='Back', role='button')
driver.wait(label='Shovey Editor', role='button')
driver.press(label='Shovey Editor', role='button')
driver.wait(label='New level', role='text', timeout=60)
driver.key('escape')
driver.wait(label='Apfelwurm', role='button')
driver.press(label='Apfelwurm', role='button')
driver.wait(label='Play', role='button', timeout=60)
assert server['requests'] == requested, 'Installed apps/art must reopen offline without requests'
assert record.read_bytes() == saved, 'Offline restart must preserve saved progress'
assert retained.read_bytes() == b'existing private save'
print('Android catalog: consent, dependency verification/retry, install/open, cached offline and retained saves passed')
+15 -6
View File
@@ -14,7 +14,9 @@ spec.loader.exec_module(builder)
class ControllerSourceTests(unittest.TestCase):
def test_local_overrides_do_not_reach_locked_resolution(self):
with tempfile.TemporaryDirectory() as directory:
scratch = ROOT / 'work/apps-controller-test'
scratch.mkdir(parents=True, exist_ok=True)
with tempfile.TemporaryDirectory(dir=scratch) as directory:
root = Path(directory)
manifest = ('[package]\nname = "Arcade"\n'
'[toolchain]\ngit = "https://github.com/ziranlang/ziran.git"\nref = "master"\n'
@@ -30,10 +32,13 @@ class ControllerSourceTests(unittest.TestCase):
(root / 'ziran.local.toml').write_text('unreviewed local dependency')
package = root / 'cached-apps'
output = root / 'output'
compiler = root / 'cached-ziran/build/bin/ziran'
compiler.parent.mkdir(parents=True)
compiler.write_text('fixture compiler path; subprocess calls are mocked')
contexts = []
def resolve(command, *, cwd, text):
self.assertEqual(command, ['ziran', 'pkg', 'path', 'apps', '--locked'])
self.assertIn(command, [['ziran', 'pkg', 'path', name, '--locked'] for name in ('apps', 'ziran', 'kryon')])
self.assertTrue(text)
self.assertNotIn('dependencies.wurm', (cwd / 'ziran.toml').read_text())
selected = json.loads((cwd / 'ziran.lock').read_text())
@@ -42,14 +47,18 @@ class ControllerSourceTests(unittest.TestCase):
self.assertEqual(selected['toolchain'], lock['toolchain'])
self.assertEqual({p.name for p in cwd.iterdir()}, {'ziran.toml', 'ziran.lock'})
contexts.append(cwd)
return str(package) + '\n'
return str(package if command[3] == 'apps' else root / ('cached-' + command[3])) + '\n'
with patch.object(builder.subprocess, 'check_output', side_effect=resolve), \
patch.object(builder.subprocess, 'run') as run:
builder.build(root, output)
run.assert_called_once_with(
[builder.sys.executable, str(package / 'scripts/build-ui.py'),
'--output', str(output)], cwd=root, check=True)
self.assertEqual(run.call_count, 2)
command = run.call_args.args[0]
self.assertEqual(command[0], str(compiler))
self.assertIn(str(package / 'ui/apps.zi'), command)
self.assertIn('kryon=' + str(root / 'cached-kryon/src/ui'), command)
self.assertIn(str(root / 'cached-ziran/std'), command)
self.assertNotIn('--project', command)
self.assertFalse(contexts[0].exists())
self.assertEqual((root / 'ziran.toml').read_text(), manifest)
self.assertEqual(json.loads((root / 'ziran.lock').read_text()), lock)
+17 -4
View File
@@ -13,6 +13,11 @@ inbe = Path(os.environ['INBE_SOURCE']) if 'INBE_SOURCE' in os.environ else Path(
catalog = json.loads((ROOT / "build/catalog.json").read_text())["games"]
chess = next(game for game in catalog if game["name"] == "chess")
assert chess["id"] == "inbe.chess"
choano = next(game for game in catalog if game["name"] == "choano")
assert choano["id"] == "xyz.waozi.choano"
assert choano["kind"] == "game"
assert choano["entry"] == "portable:Main"
assert choano["package"] == "choano"
# Inbe releases before its node apps have no node_apps ledger at all.
assert "chess" not in json.loads((inbe / "apps/versions.json").read_text()).get("node_apps", {})
assert set(chess["harnesses"]) == {"arcade", "inbe"}
@@ -20,13 +25,15 @@ assert chess["kind"] == "game"
assert (ROOT / "apps/chess/engine.zi").is_file(), "Arcade must own the game"
assert not (inbe / "apps/chess").exists(), "Inbe must consume Chess, not own another copy"
assert chess["contract_version"] == 1 and chess["module_api"] == 2
assert chess["host_api"] == 12 and chess["save_schema"] == 1
assert chess["host_api"] == 41 and chess["save_schema"] == 1
assert (ROOT / chess["preview"]).is_file()
env = {key: value for key, value in os.environ.items()
if key not in {"DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "DBUS_SESSION_BUS_ADDRESS"}}
listed = subprocess.run([str(ROOT / "build/arcade"), "--list"], env=env, capture_output=True, timeout=10)
assert listed.returncode == 0 and b"inbe.chess" not in listed.stderr + listed.stdout
assert b"arcade.shovey\n" in listed.stderr + listed.stdout
listed_output = listed.stderr + listed.stdout
assert listed.returncode == 0 and b"inbe.chess" not in listed_output
assert b"arcade.shovey\n" in listed_output
assert b"xyz.waozi.choano\n" in listed_output
unknown = subprocess.run([str(ROOT / "build/arcade"), "--app", "unknown"],
env=env, capture_output=True, timeout=10)
assert unknown.returncode == 1 and b"unknown game" in unknown.stderr
@@ -34,7 +41,13 @@ original = (ROOT / 'build/games/chess.zx').read_bytes()
container = (ROOT / 'build/arcade.zx').read_bytes()
metadata = json.loads((ROOT / 'build/arcade.json').read_text())
assert original not in container, 'Disabled Chess must not remain in the published collection'
assert {child['id'] for child in metadata['children']} == {'arcade.shovey', 'arcade.shovey-editor', 'xyz.waozi.wurm'}
assert {child['id'] for child in metadata['children']} == {
'arcade.shovey', 'arcade.shovey-editor', 'xyz.waozi.choano',
'xyz.waozi.wurm', 'xyz.waozi.wurm-editor'
}
choano_child = next(child for child in metadata['children'] if child['id'] == 'xyz.waozi.choano')
assert choano_child['expected_id'] == 'choano'
assert choano_child['bundle'] == 'assets/arcade/games/choano.zx'
for child in metadata['children']:
name = child['expected_id']
exact = (ROOT / f'build/games/{name}.zx').read_bytes()
+281
View File
@@ -0,0 +1,281 @@
"""Catalog releases advance independently; native APK verification stays strict."""
import hashlib
import importlib.util
import json
from pathlib import Path
import shutil
import struct
import subprocess
import sys
import tempfile
import unittest
from unittest.mock import patch
import zipfile
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'scripts'))
import android_catalog
def load(name, script):
spec = importlib.util.spec_from_file_location(name, ROOT / 'scripts' / script)
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
builder = load('collection_versions', 'build-collection.py')
release = load('android_release_versions', 'android-release.py')
native_builder = load('android_native_versions', 'build-android.py')
class Fixture(unittest.TestCase):
def setUp(self):
work = ROOT / 'work'
work.mkdir(exist_ok=True)
temporary = tempfile.TemporaryDirectory(prefix='catalog-versions-', dir=work)
self.addCleanup(temporary.cleanup)
self.root = Path(temporary.name)
for directory in ('scripts', 'apps', 'catalog'):
(self.root / directory).mkdir()
(self.root / 'packaging').mkdir()
shutil.copyfile(ROOT / 'packaging/node.json', self.root / 'packaging/node.json')
class SynchronizerTests(Fixture):
def setUp(self):
super().setUp()
shutil.copyfile(ROOT / 'update_version.sh', self.root / 'update_version.sh')
(self.root / 'scripts/game_packages.py').write_text(
"from pathlib import Path\n"
"def declared_apps(root):\n"
" return [dict(descriptor=dict(name='game', id='inbe.game', title='Game', host_api=41),\n"
" manifest=Path('apps/catalog.json'))]\n")
(self.root / 'CHANGELOG.md').write_text('## [Unreleased]\n\n- Later host.\n\n## 0.7.117\n')
(self.root / 'VERSION').write_text('0.7.116\n')
(self.root / 'packaging/android').mkdir(parents=True)
(self.root / 'packaging/android/version-code').write_text('195\n')
(self.root / 'catalog/CHANGELOG.md').write_text('## 0.7.118\n\n- New games.\n')
(self.root / 'catalog/VERSION').write_text('0.7.116\n')
(self.root / 'packaging').mkdir(exist_ok=True)
shutil.copyfile(ROOT / 'packaging/node.json', self.root / 'packaging/node.json')
(self.root / 'apps/CHANGELOG.md').write_text('## [1.0.0] - 2026-10-31\n')
self.original = {'node_apps': {
'arcade': {'id': 'inbe.arcade', 'version': '0.7.116', 'sequence': 120},
'game': {'id': 'inbe.game', 'version': '1.0.0', 'sequence': 7}}}
self.write_ledger(self.original)
def write_ledger(self, value):
(self.root / 'apps/versions.json').write_text(json.dumps(value))
def sync(self, *args, success=True):
result = subprocess.run(['sh', str(self.root / 'update_version.sh'), *args],
capture_output=True, text=True)
self.assertEqual(result.returncode == 0, success, result.stdout + result.stderr)
return json.loads((self.root / 'apps/versions.json').read_text())['node_apps']
def test_catalog_release_never_bumps_host_and_is_idempotent(self):
ledger = self.sync('--catalog')
self.assertEqual((self.root / 'VERSION').read_text(), '0.7.116\n')
self.assertEqual((self.root / 'packaging/android/version-code').read_text(), '195\n')
self.assertEqual((self.root / 'catalog/VERSION').read_text(), '0.7.118\n')
self.assertEqual((ledger['arcade']['version'], ledger['arcade']['sequence']), ('0.7.118', 121))
self.assertEqual(ledger['game'], self.original['node_apps']['game'])
self.assertEqual(self.sync('--catalog'), ledger)
def test_host_release_never_advances_catalog_sequence(self):
(self.root / 'catalog/CHANGELOG.md').write_text('## 0.7.116\n')
ledger = self.sync()
self.assertEqual((self.root / 'VERSION').read_text(), '0.7.117\n')
self.assertEqual((self.root / 'packaging/android/version-code').read_text(), '196\n')
self.assertEqual(ledger, self.original['node_apps'])
self.assertEqual(builder.catalog_version(self.root), '0.7.116')
self.assertEqual(self.sync(), ledger)
self.assertEqual((self.root / 'packaging/android/version-code').read_text(), '196\n')
def test_native_apk_identity_ignores_catalog_sequence(self):
with patch.object(native_builder, 'ROOT', self.root):
self.assertEqual(native_builder.native_release(), {'version': '0.7.116', 'sequence': 195})
self.sync('--catalog')
with patch.object(native_builder, 'ROOT', self.root):
self.assertEqual(native_builder.native_release(), {'version': '0.7.116', 'sequence': 195})
def test_invalid_native_code_preserves_all_versions(self):
(self.root / 'packaging/android/version-code').write_text('0\n')
self.sync(success=False)
self.assertEqual((self.root / 'VERSION').read_text(), '0.7.116\n')
self.assertEqual((self.root / 'catalog/VERSION').read_text(), '0.7.116\n')
self.assertEqual(json.loads((self.root / 'apps/versions.json').read_text()), self.original)
def test_catalog_release_updates_game_ledger_from_its_own_changelog(self):
(self.root / 'apps/CHANGELOG.md').write_text('## [1.0.1] - 2026-10-31\n')
ledger = self.sync('--catalog')
self.assertEqual((ledger['game']['version'], ledger['game']['sequence']), ('1.0.1', 8))
def test_catalog_version_cannot_go_back_and_failure_preserves_files(self):
(self.root / 'catalog/CHANGELOG.md').write_text('## 0.7.115\n')
ledger = self.sync('--catalog', success=False)
self.assertEqual(ledger, self.original['node_apps'])
self.assertEqual((self.root / 'VERSION').read_text(), '0.7.116\n')
self.assertEqual((self.root / 'catalog/VERSION').read_text(), '0.7.116\n')
def test_collection_rejects_stale_catalog_ledger(self):
(self.root / 'catalog/VERSION').write_text('0.7.118\n')
with self.assertRaisesRegex(ValueError, 'signed release ledger'):
builder.catalog_version(self.root)
def test_unknown_switch_does_not_change_versions(self):
self.sync('--wrong', success=False)
self.assertEqual((self.root / 'VERSION').read_text(), '0.7.116\n')
def bundle(assets):
def number(value):
return struct.pack('<I', value)
def text(value):
return number(len(value)) + value
return (b'ZX\0\0\x1b\0\0\0' + text(b'') * 2 + number(0) * 4 + number(len(assets))
+ b''.join(text(name.encode()) + text(value) for name, value in assets.items()))
class AndroidVerifierTests(Fixture):
def setUp(self):
super().setUp()
(self.root / 'CHANGELOG.md').write_text('## 0.7.117\n')
(self.root / 'catalog/VERSION').write_text('0.7.116\n')
controller = bundle({})
self.controller_digest = hashlib.sha256(controller).hexdigest()
(self.root / 'apps-controller.sha256').write_text(self.controller_digest)
catalog = {'children': [], 'art': {'sha256': 'a' * 64, 'bytes': 123},
'harness': 'assets/apps/apps.zx'}
payload = bundle({'assets/apps/catalog.json': json.dumps(catalog).encode(),
'assets/arcade/sidebar.shape': b'shape'})
self.metadata = {'id': 'inbe.arcade', 'version': '0.7.116',
'sha256': hashlib.sha256(payload).hexdigest(),
'apps_sha256': self.controller_digest, 'children': [], 'art': catalog['art']}
ledger = {'node_apps': {'arcade': {'sequence': 195}}}
(self.root / 'apps/versions.json').write_text(json.dumps(ledger))
self.metadata['node'] = builder.node_source(self.root)
self.assets = {'assets/arcade.zx': payload, 'assets/apps.zx': controller,
'assets/entity.zx': bundle({}), 'assets/kryon-font.ttf': b'font',
'res/icon.png': b'icon', 'lib/arm64-v8a/libmain.so': b'arm64',
'lib/armeabi-v7a/libmain.so': b'arm', 'classes.dex': b'normal'}
self.badging = ("package: name='xyz.waozi.arcade' versionCode='121' versionName='0.7.117'\n"
"application-label:'Arcade'\napplication: label='Arcade' icon='res/icon.png'\n")
self.signer = hashlib.sha256(b'certificate').hexdigest()
def verify(self, edition='direct'):
apk = self.root / 'fixture.apk'
with zipfile.ZipFile(apk, 'w') as output:
for name, data in self.assets.items():
output.writestr(name, data)
output.writestr('assets/arcade.json', json.dumps(self.metadata))
def command(args, **kwargs):
if args[0] == 'openssl':
return b'certificate'
if 'apksigner' in args[0]:
return 'Number of signers: 1\nSigner #1 certificate SHA-256 digest: ' + self.signer + '\n'
self.assertIn('badging', args)
return self.badging
with patch.object(release, 'ROOT', self.root), patch.object(android_catalog, 'ROOT', self.root), \
patch.object(android_catalog, 'profile_asset_hashes', return_value={}), \
patch.object(release, 'verify_launcher'), \
patch.object(release.subprocess, 'check_output', side_effect=command), \
patch.object(release.subprocess, 'run'):
return release.verify(apk, '0.7.117', self.root / 'tools', edition)
def test_host_and_embedded_catalog_versions_may_differ(self):
for edition in ('direct', 'fdroid'):
result = self.verify(edition)
self.assertEqual((result['version'], result['catalog_version']), ('0.7.117', '0.7.116'))
def test_wrong_native_identity_or_version_rejected(self):
for old, new in (('xyz.waozi.arcade', 'xyz.waozi.other'), ('0.7.117', '0.7.116')):
original = self.badging
self.badging = original.replace(old, new)
with self.assertRaisesRegex(AssertionError, 'APK identity or version'):
self.verify()
self.badging = original
def test_wrong_catalog_identity_or_source_version_rejected(self):
for key, value in (('id', 'inbe.other'), ('version', '0.7.117')):
original = self.metadata[key]
self.metadata[key] = value
with self.assertRaisesRegex(AssertionError, 'catalog (identity|version)'):
self.verify()
self.metadata[key] = original
def test_payload_hash_stays_required(self):
self.assets['assets/arcade.zx'] += b'changed'
with self.assertRaisesRegex(AssertionError, 'differs from its receipt'):
self.verify()
def test_controller_digest_stays_required(self):
self.assets['assets/apps.zx'] += b'changed'
with self.assertRaises(AssertionError):
self.verify()
def test_extra_assets_and_oversized_catalog_rejected(self):
self.assets['assets/game.zx'] = b'game'
with self.assertRaisesRegex(AssertionError, 'Unexpected or missing'):
self.verify()
del self.assets['assets/game.zx']
self.assets['assets/arcade.zx'] = b'x' * (256 * 1024 + 1)
self.metadata['sha256'] = hashlib.sha256(self.assets['assets/arcade.zx']).hexdigest()
with self.assertRaisesRegex(AssertionError, 'asset policy budget'):
self.verify()
def test_google_edition_gates_stay_required(self):
self.badging += "uses-permission: name='com.android.vending.BILLING'\n"
with self.assertRaisesRegex(AssertionError, 'Only the Google Play edition'):
self.verify()
self.assets['assets/dexopt/baseline.prof'] = b'profile'
self.assets['assets/dexopt/baseline.profm'] = b'metadata'
with self.assertRaisesRegex(AssertionError, 'Only the Google Play edition'):
self.verify('gplay')
self.assets['classes.dex'] = b'Lorg/kryonlabs/play/PlayBilling; Lcom/android/billingclient/'
self.assertEqual(self.verify('gplay')['edition'], 'gplay')
self.badging = self.badging.split('uses-permission:')[0]
del self.assets['assets/dexopt/baseline.prof']
del self.assets['assets/dexopt/baseline.profm']
with self.assertRaisesRegex(AssertionError, 'Only the Google Play edition'):
self.verify()
def test_signer_and_native_architectures_stay_required(self):
self.signer = '0' * 64
with self.assertRaisesRegex(AssertionError, 'APK signer differs'):
self.verify()
self.signer = hashlib.sha256(b'certificate').hexdigest()
del self.assets['lib/armeabi-v7a/libmain.so']
with self.assertRaisesRegex(AssertionError, 'Both supported ARM architectures'):
self.verify()
class WorkflowTests(unittest.TestCase):
def test_catalog_publication_never_dispatches_android(self):
for name in ('game-updates.yml', 'node-release.yml'):
text = (ROOT / '.github/workflows' / name).read_text()
self.assertNotIn('gh workflow run android.yml', text)
self.assertNotIn('cat VERSION', text)
self.assertIn('cat catalog/VERSION', text)
follower = (ROOT / '.github/workflows/game-updates.yml').read_text()
self.assertIn('sh update_version.sh --catalog', follower)
self.assertNotIn('ziran.lock CHANGELOG.md VERSION', follower)
def test_native_release_is_created_after_all_editions_verify(self):
text = (ROOT / '.github/workflows/android.yml').read_text()
publish = text[text.index(' publish:'):]
self.assertIn('edition: [direct, fdroid, gplay]', text)
self.assertIn('needs: [release, build]', publish)
self.assertIn('for edition in direct fdroid gplay', publish)
self.assertLess(publish.index('scripts/android-release.py verify'), publish.index('gh release create'))
self.assertIn('tag="arcade-$VERSION"', publish)
self.assertIn('--target "$GITHUB_SHA"', publish)
self.assertNotIn('"node-arcade-', text)
self.assertIn("expect-google: 'true'", text)
if __name__ == '__main__':
unittest.main()
@@ -0,0 +1,40 @@
#import, file "../src/collection_host.zi";
#import "entity/publications"
#import "entity/publications_read"
#import "std/bundle_host"
#import "hosted_values"
#import "std/byte_text_linux"
using HostValueKind;
CopyText :: (text: string, bytes: []u8) -> bool {
if text.count >= bytes.count { return false }
for byte, at: text { bytes[at] = byte }
bytes[text.count] = 0
return true
}
TextValue :: (text: string) -> HostValue {
return HostValue.{.kind = cast(s32)HostString, .type_name = HostTextData("string"),
.data = HostTextData(text), .length = cast(usize)text.count}
}
BorrowedText :: (value: HostValue) -> string {
return TextFromBytes(BytesFromPointer(value.data, cast(u64)value.length))
}
#program_export
Check :: () -> s32 {
if !CollectionAllows(null, null, PUBLICATIONS_SERVICE) { return 1 }
if !CollectionAllows(null, null, PUBLICATIONS_READ_SERVICE) { return 2 }
function: [32]u8
if !CopyText("AppServiceHost", function[:]) { return 3 }
arguments: [2]HostValue
arguments[0] = TextValue(PUBLICATIONS_SERVICE)
arguments[1] = TextValue("{\"operation\":\"fetch\",\"id\":\"fixture\"}")
result: HostValue
if CollectionCall(null, null, null, *function[0], *arguments[0], 2, *result) != 1 { return 4 }
if result.kind != cast(s32)HostString { return 5 }
if BorrowedText(result) != "{\"status\":\"rejected\",\"error\":\"signed-out\"}" { return 6 }
return 42
}
@@ -0,0 +1,90 @@
"""Check that Arcade routes writable publications through Entity's account gate."""
import fcntl
import os
from pathlib import Path
import shutil
import subprocess
ROOT = Path(__file__).resolve().parents[1]
WORK = ROOT / "build/collection-publications-host-test"
ENVIRONMENT = {
key: value for key, value in os.environ.items()
if key not in {"DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "DBUS_SESSION_BUS_ADDRESS"}
}
def run(program, *arguments):
return subprocess.run([program, *arguments], cwd=ROOT, check=True,
env=ENVIRONMENT, text=True)
def main():
generated = WORK / "c"
binary = WORK / "test"
for path in (binary, binary.with_suffix(".new")):
if path.is_dir():
shutil.rmtree(path)
elif path.exists():
path.unlink()
if generated.exists():
shutil.rmtree(generated)
generated.mkdir(parents=True)
ziran = str(ROOT / "scripts/ziran.sh")
lock = [] if (ROOT / "ziran.local.toml").exists() else ["--locked"]
run(ziran, "build", "--project", *lock, "--target=c", "--no-main",
"--define", "PLATFORM_DESKTOP", "--entry",
"collection_publications_host_behavior:Check", "-o", str(generated),
"tests/collection_publications_host_behavior.zi")
main_c = generated / "main.c"
main_c.write_text('#include "collection_publications_host_behavior.h"\n'
'int main(void) { return Check(); }\n')
toolchain = Path(subprocess.check_output(
[ziran, "pkg", "path", "ziran", *lock], cwd=ROOT, text=True,
env=ENVIRONMENT).strip())
runtime = ROOT / "build/ziran/libziran.a"
if not runtime.exists():
run("make", "-j1", str(runtime))
def package(name):
return Path(subprocess.check_output(
[ziran, "pkg", "path", name, *lock], cwd=ROOT, text=True,
env=ENVIRONMENT).strip())
oqs_source = package("liboqs")
oqs = WORK / ("oqs-" + oqs_source.name)
oqs.parent.mkdir(parents=True, exist_ok=True)
with open(oqs.with_name(oqs.name + ".lock"), "w") as exclusive:
fcntl.flock(exclusive, fcntl.LOCK_EX)
run("cmake", "-S", str(oqs_source), "-B", str(oqs),
"-DCMAKE_BUILD_TYPE=MinSizeRel", "-DBUILD_SHARED_LIBS=OFF",
"-DOQS_BUILD_ONLY_LIB=ON", "-DOQS_USE_OPENSSL=OFF",
"-DOQS_DIST_BUILD=OFF", "-DOQS_OPT_TARGET=generic",
"-DOQS_MINIMAL_BUILD=SIG_ml_dsa_44;KEM_ml_kem_768")
run("cmake", "--build", str(oqs), "--target", "oqs", "--", "-j1")
libraries = subprocess.check_output(
["pkg-config", "--libs", "sdl2", "cairo", "freetype2", "fontconfig",
"pangocairo", "gtk+-3.0"], text=True, env=ENVIRONMENT).split()
monocypher = package("monocypher")
includes = [item for path in generated.rglob("*") if path.is_dir()
for item in ("-iquote", str(path))]
temporary = binary.with_suffix(".new")
run(os.environ.get("CC", "cc"), "-std=c11", "-O2", "-ffunction-sections",
"-fdata-sections", "-I" + str(toolchain / "include"), "-iquote",
str(generated), *includes, *map(str, generated.rglob("*.c")),
str(ROOT / "build/ziran/libziran.a"), "-I" + str(monocypher / "src"),
str(monocypher / "src/monocypher.c"),
str(monocypher / "src/optional/monocypher-ed25519.c"),
str(oqs / "lib/liboqs.a"), "-Wl,--gc-sections", *libraries,
"-lX11", "-l:libcurl.so.4", "-lz", "-lm", "-lpthread", "-o", str(temporary))
temporary.replace(binary)
result = subprocess.run([binary], cwd=ROOT, env=ENVIRONMENT |
{"SDL_AUDIODRIVER": "dummy"})
if result.returncode != 42:
raise SystemExit(
f"collection publications host check returned {result.returncode}")
print("Arcade publications host: writable service dispatches through Entity's account gate")
if __name__ == "__main__":
main()
+483 -25
View File
@@ -1,27 +1,83 @@
"""Exercise packaging from the actual registered game builds, preserving bytes."""
import hashlib
import importlib.util
import io
import json
import os
from pathlib import Path
import shlex
import shutil
import subprocess
import tempfile
import unittest
from unittest.mock import patch
import sys
import tarfile
from PIL import Image
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "scripts"))
spec = importlib.util.spec_from_file_location("build_collection", ROOT / "scripts/build-collection.py")
builder = importlib.util.module_from_spec(spec)
spec.loader.exec_module(builder)
art_spec = importlib.util.spec_from_file_location("library_art", ROOT / "scripts/library-art.py")
artist = importlib.util.module_from_spec(art_spec)
art_spec.loader.exec_module(artist)
spec = importlib.util.spec_from_file_location("published_games", ROOT / "scripts/wait-published-games.py")
published_games = importlib.util.module_from_spec(spec)
spec.loader.exec_module(published_games)
def bundle_asset_paths(path):
"""Read the actual bundle index without loading its images or executing it."""
with published_games.Reader(path) as reader:
if reader.take(8) not in (b"ZX\0\0\x1a\0\0\0", b"ZX\0\0\x1b\0\0\0"):
raise ValueError("Unsupported game bundle")
reader.text()
reader.text()
for _ in range(reader.number()):
reader.text()
reader.text()
for _ in range(reader.number()):
for _ in range(7):
reader.text()
reader.take(8)
reader.text()
reader.take(4)
for _ in range(reader.number()):
for _ in range(3):
reader.text()
reader.skip(reader.number())
paths = set()
for _ in range(reader.number()):
name = reader.text().decode()
if name in paths:
raise ValueError("Duplicate game asset: " + name)
paths.add(name)
reader.skip(reader.number())
reader.finish()
return paths
class CollectionTests(unittest.TestCase):
def test_choano_runtime_images_are_packed_at_their_runtime_paths(self):
# Fixed runtime references catch a doubled namespace in the real
# compiled payload, independently of the packaging declaration.
assets = bundle_asset_paths(ROOT / "build/games/choano.zx")
for path in ("assets/choano/background-inside.png", "assets/choano/organisms-hd.png",
"assets/choano/title-landscape.jpg", "assets/choano/fish/sea.png"):
self.assertTrue(path in assets, "Choano runtime image missing from its bundle: " + path)
def setUp(self):
self.directory = tempfile.TemporaryDirectory(prefix="collection-", dir=ROOT / "build")
subprocess.run(["git", "check-ignore", "-q", "work/"], cwd=ROOT, check=True)
(ROOT / "work").mkdir(exist_ok=True)
self.directory = tempfile.TemporaryDirectory(prefix="collection-", dir=ROOT / "work")
self.addCleanup(self.directory.cleanup)
self.root = Path(self.directory.name)
self.lock_flags = ("--locked",)
if (ROOT / "ziran.local.toml").is_file():
(self.root / "ziran.local.toml").touch()
self.lock_flags = ()
(self.root / "apps").mkdir()
for name in ("games.json", "apps.json", "apps/versions.json"):
shutil.copyfile(ROOT / name, self.root / name)
@@ -39,6 +95,9 @@ class CollectionTests(unittest.TestCase):
(self.root / "assets/arcade").mkdir(parents=True)
shutil.copyfile(ROOT / "assets/arcade/sidebar.shape", self.root / "assets/arcade/sidebar.shape")
shutil.copytree(ROOT / "assets/arcade/library", self.root / "assets/arcade/library")
(self.root / "src").mkdir()
for source in (ROOT / "src").glob("*_collection.zi"):
shutil.copyfile(source, self.root / "src" / source.name)
# Only a native VM identity gate can trust a controller. This fixture
# tests packing and its exact-content requirement, not that handshake.
self.controller = self.root / "controller.zx"
@@ -49,37 +108,293 @@ class CollectionTests(unittest.TestCase):
def stage(self):
return builder.stage(self.root, self.controller, self.controller_digest, self.output)[0]
def staged_bytes(self):
return {str(path.relative_to(self.output)): builder.digest(path)
for path in self.output.rglob("*") if path.is_file()}
def small_payloads(self):
# Real on-disk input sizes, bounded independently of production limits.
for path in (self.root / "build/games").glob("*.zx"):
path.write_bytes(b"game fixture".ljust(32 * 1024, b"\0"))
for path in (self.root / "assets/arcade/library").iterdir():
if path.suffix in (".png", ".jpg"):
path.write_bytes(b"art fixture".ljust(128, b"\0"))
def test_separately_loaded_games_can_exceed_one_root_limit_together(self):
# The registered games exceed 64 MiB together; each game and the
# Shovey standalone pair still fit. Never alter the real build outputs.
for path in (self.root / "build/games").glob("*.zx"):
with path.open("r+b") as data:
data.truncate(max(path.stat().st_size, 16 * 1024 * 1024))
catalog = self.stage()
self.assertGreater(sum(child["bytes"] for child in catalog["children"]), 64 * 1024 * 1024)
small, games, art = (self.root / name for name in ("small", "downloads", "art"))
builder.stage_downloads(catalog, self.output, small, games, art)
for child in catalog["children"]:
packed = games / (child["sha256"] + ".zx")
self.assertEqual(builder.digest(packed), child["sha256"])
self.assertEqual(packed.stat().st_size, child["bytes"])
self.assertLessEqual(packed.stat().st_size, 64 * 1024 * 1024)
def test_oversized_single_payload_preserves_previous_stage(self):
self.stage()
previous = self.staged_bytes()
largest = max(path.stat().st_size for path in (self.root / "build/games").glob("*.zx"))
with patch.object(builder, "MAX_PAYLOAD_BYTES", largest - 1):
with self.assertRaisesRegex(ValueError, "Game .* exceeds.*payload limit"):
self.stage()
self.assertEqual(self.staged_bytes(), previous)
with patch.object(builder, "MAX_PAYLOAD_BYTES", self.controller.stat().st_size - 1):
with self.assertRaisesRegex(ValueError, "Apps controller exceeds.*payload limit"):
self.stage()
self.assertEqual(self.staged_bytes(), previous)
def test_oversized_standalone_group_preserves_previous_stage(self):
self.stage()
previous = self.staged_bytes()
self.small_payloads()
# Each game is 32 KiB; the offline Shovey pair exceeds 48 KiB before
# even counting its controller, catalog and art. Other roots fit.
with patch.object(builder, "MAX_PAYLOAD_BYTES", 48 * 1024):
with self.assertRaisesRegex(ValueError, "Standalone shovey exceeds.*payload limit"):
self.stage()
self.assertEqual(self.staged_bytes(), previous)
def test_oversized_art_and_catalog_preserve_previous_stage(self):
self.stage()
previous = self.staged_bytes()
self.small_payloads()
for path in (self.root / "build/games").glob("*.zx"):
path.write_bytes(b"game")
# Art is one separately loaded root, even though it has many files.
pictures = [path for path in (self.root / "assets/arcade/library").iterdir()
if path.suffix in (".png", ".jpg")]
for path in pictures:
path.write_bytes(b"x" * 8192)
with patch.object(builder, "MAX_PAYLOAD_BYTES", 48 * 1024):
with self.assertRaisesRegex(ValueError, "Library art exceeds.*payload limit"):
self.stage()
self.assertEqual(self.staged_bytes(), previous)
for path in pictures:
path.write_bytes(b"art")
catalog_size = (self.output / "assets/apps/catalog.json").stat().st_size
with patch.object(builder, "MAX_PAYLOAD_BYTES", catalog_size - 1):
with self.assertRaisesRegex(ValueError, "Arcade catalog exceeds.*payload limit"):
self.stage()
self.assertEqual(self.staged_bytes(), previous)
def test_compiled_limit_includes_zx_overhead_and_preserves_previous_bundle(self):
assets = self.root / "bundle-assets"
assets.mkdir()
(assets / "fixture").write_bytes(b"asset fixture")
target = self.root / "art.zx"
command = [os.environ.get("ZIRAN", str(ROOT / "scripts/ziran.sh")),
"bundle", "--project", *self.lock_flags]
def compile_art():
builder.bundle(command, ROOT, "art.zi", "art:Main", assets, target, None)
compile_art()
previous = target.read_bytes()
self.assertGreater(len(previous), (assets / "fixture").stat().st_size)
with patch.object(builder, "MAX_PAYLOAD_BYTES", len(previous)):
compile_art()
self.assertEqual(target.read_bytes(), previous)
with patch.object(builder, "MAX_PAYLOAD_BYTES", len(previous) - 1):
with self.assertRaisesRegex(ValueError, "art.zx exceeds.*payload limit"):
compile_art()
self.assertEqual(target.read_bytes(), previous)
def test_staging_uses_locked_packages_unless_local_overrides_exist(self):
packages = builder.declared_packages(self.root, lock_flags=self.lock_flags)
artwork = json.loads((self.root / "games.json").read_text()).get("artwork", {})
sources = {package["name"]: package["source"] for package in packages[1:]}
for package in packages[1:]:
if package["name"] in artwork:
sources[artwork[package["name"]]] = package["apps"][0]["art_source"]
log = self.root / "resolver-args"
# Capture real subprocess arguments while resolving the same selected
# source directories, including the deliberately unlocked local case.
lines = ["#!/bin/sh", f"printf '%s\\n' \"$*\" >> {shlex.quote(str(log))}",
'case "$3" in']
lines += [f"{shlex.quote(name)}) printf '%s\\n' {shlex.quote(str(path))} ;;"
for name, path in sources.items()]
lines += ["*) exit 1 ;;", "esac"]
(self.root / "scripts/ziran.sh").write_text("\n".join(lines) + "\n")
local = self.root / "ziran.local.toml"
for override in (False, True):
with self.subTest(local_override=override):
if override:
local.touch()
else:
local.unlink(missing_ok=True)
log.unlink(missing_ok=True)
self.stage()
calls = [line.split() for line in log.read_text().splitlines()]
self.assertEqual({call[2] for call in calls}, set(sources))
for call in calls:
self.assertEqual(call, ["pkg", "path", call[2]] + ([] if override else ["--locked"]))
def assert_children_match_declarations(self, catalog, packages, payload_root):
declarations = builder.declared_packages(self.root, lock_flags=self.lock_flags)
ledger = json.loads((self.root / "apps/versions.json").read_text())["node_apps"]
expected_children = []
for app in (app for package in declarations for app in package["apps"] if app["enabled"]):
descriptor = app["descriptor"]
cover = app["cover"] or {}
expected_children.append((
descriptor["id"], descriptor["title"], descriptor["name"],
ledger[descriptor["name"]]["version"], cover.get("caption", ""),
cover.get("action"), tuple(app["requires"]), app["shared_code"],
))
self.assertEqual([(
child["id"], child["title"], child["expected_id"], child["version"],
child.get("cover", {}).get("caption", ""), child.get("cover", {}).get("action"),
tuple(child.get("dependencies", [])), child.get("shared_code", False),
) for child in catalog["children"]], expected_children)
self.assertEqual([(p["name"], p["id"], p["children"]) for p in packages],
[(package["name"], package["id"],
[app["descriptor"]["id"] for app in package["apps"] if app["enabled"]])
for package in declarations[1:]])
library = payload_root / "assets/arcade/library"
for child in catalog["children"]:
name = child["expected_id"]
source = payload_root / f"build/games/{name}.zx"
packed = self.output / child["bundle"]
self.assertEqual(packed.read_bytes(), source.read_bytes())
self.assertEqual(builder.digest(packed), child["sha256"])
self.assertEqual(child["bytes"], source.stat().st_size)
self.assertEqual(child["protocol"], "node/2")
expected_preview = next(library.glob(f"{name}-preview.*"))
self.assertEqual(child["preview"], child["icon"])
self.assertEqual(child["preview"], f"assets/arcade/previews/{name}{expected_preview.suffix}")
self.assertEqual((self.output / child["preview"]).read_bytes(), expected_preview.read_bytes())
for key in ("portrait", "landscape", "logo"):
if key not in child.get("cover", {}):
continue
expected_cover = next(library.glob(f"{name}-{key}.*"))
self.assertEqual(child["cover"][key],
f"assets/arcade/covers/{name}-{key}{expected_cover.suffix}")
self.assertEqual((self.output / child["cover"][key]).read_bytes(),
expected_cover.read_bytes())
def add_library_copy(self, name, key, data):
library = self.root / "assets/arcade/library"
sources = json.loads((library / "sources.json").read_text())
contents, suffix = artist.small_copy(data, key)
copy = library / f"{name}-{key}{suffix}"
copy.write_bytes(contents)
sources[f"{name}-{key}"] = {"source_sha256": hashlib.sha256(data).hexdigest()}
(library / "sources.json").write_text(json.dumps(sources))
def stage_four_leaf_wurm_fixture(self):
registration = self.root / 'games.json'
value = json.loads(registration.read_text())
value.pop('artwork', None)
registration.write_text(json.dumps(value))
source = self.root / "fixture-packages/wurm"
(source / "editor").mkdir(parents=True)
(source / "assets").mkdir()
def image(color, path):
picture = Image.new("RGB", (640, 480), color)
picture.save(path)
return path.read_bytes()
(source / "catalog.json").write_text(json.dumps({
"id": "xyz.waozi.wurm", "name": "wurm", "title": "Apfelwurm",
"kind": "game", "contract_version": 1, "module_api": 2, "host_api": 41,
"harnesses": ["arcade"], "preview": "assets/wurm-preview.png",
}))
(source / "editor/catalog.json").write_text(json.dumps({
"id": "xyz.waozi.wurm-editor", "name": "wurm-editor", "title": "Apfelwurm Editor",
"kind": "game", "contract_version": 1, "module_api": 2, "host_api": 41,
"harnesses": ["arcade"], "preview": "assets/wurm-editor-preview.png",
}))
images = {
"wurm-preview": image((255, 0, 0), source / "assets/wurm-preview.png"),
"wurm-portrait": image((0, 255, 0), source / "assets/wurm-portrait.png"),
"wurm-editor-preview": image((0, 0, 255), source / "assets/wurm-editor-preview.png"),
"wurm-editor-portrait": image((255, 255, 0), source / "assets/wurm-editor-portrait.png"),
}
(source / "apps.json").write_text(json.dumps({
"id": "xyz.waozi.wurm-player", "title": "Apfelwurm", "apps": [
{"manifest": "catalog.json", "cover": {
"portrait": "assets/wurm-portrait.png", "caption": "Classic", "action": "play"}},
{"manifest": "editor/catalog.json",
"requires": ["xyz.waozi.wurm"], "cover": {
"portrait": "assets/wurm-editor-portrait.png", "caption": "Editor", "action": "open"}},
],
}))
games = self.root / "build/games"
for name, prefix in (("wurm", b"synthetic wurm payload\n"),
("wurm-editor", b"synthetic wurm editor payload\n")):
(games / f"{name}.zx").write_bytes(prefix + name.encode())
preview_name = f"{name}-preview.png"
(games / preview_name).write_bytes(images[f"{name}-preview"])
(games / "wurm-editor-resources.json").write_text(json.dumps({
"dependencies": ["xyz.waozi.wurm"],
"resources": [{"dependency": "xyz.waozi.wurm", "path": "assets/wurm/classic/",
"source": "assets/wurm-preview.png"}],
}))
for name, key in (("wurm", "preview"), ("wurm", "portrait"),
("wurm-editor", "preview"), ("wurm-editor", "portrait")):
self.add_library_copy(name, key, images[f"{name}-{key}"])
ledger_path = self.root / "apps/versions.json"
ledger = json.loads(ledger_path.read_text())
ledger["node_apps"]["wurm-editor"] = {
"id": "xyz.waozi.wurm-editor", "title": "Apfelwurm Editor", "version": "0.1.0",
"sequence": 1, "host_api": 41,
}
ledger_path.write_text(json.dumps(ledger))
resolver = self.root / "scripts/ziran.sh"
resolver.write_text(
f'#!/bin/sh\n'
f'if [ "$1" = pkg ] && [ "$2" = path ] && [ "$3" = wurm ]; then\n'
f' printf \'%s\\n\' {shlex.quote(str(source))}\n'
f' exit 0\n'
f'fi\n'
f'cd {shlex.quote(str(ROOT))} && exec ./scripts/ziran.sh "$@"\n'
)
def test_unchanged_games_keep_canonical_identity_and_version(self):
catalog, packages = builder.stage(self.root, self.controller, self.controller_digest, self.output)
self.assertEqual(catalog["id"], "inbe.arcade")
# Inbe draws the launcher icon from the collection's own assets.
self.assertEqual((self.output / "assets/arcade/sidebar.shape").read_bytes(),
(ROOT / "assets/arcade/sidebar.shape").read_bytes())
# The ledger also versions Arcade itself, which is not one of its games.
ledger = json.loads((ROOT / "apps/versions.json").read_text())["node_apps"]
self.assertEqual({c["id"] for c in catalog["children"]},
{"arcade.shovey", "arcade.shovey-editor", "xyz.waozi.wurm"})
# Each leaf keeps the cover its own package declares.
self.assertEqual([c["cover"].get("caption", "") for c in catalog["children"]], ["Classic", "Editor", ""])
self.assertEqual([(p["name"], p["id"], p["children"]) for p in packages],
[("shovey", "arcade.shovey-player", ["arcade.shovey", "arcade.shovey-editor"]),
("wurm", "xyz.waozi.wurm-player", ["xyz.waozi.wurm"])])
for child in catalog["children"]:
name = child["expected_id"]
packed = self.output / child["bundle"]
self.assertEqual(packed.read_bytes(), (ROOT / f"build/games/{name}.zx").read_bytes())
self.assertEqual(builder.digest(packed), child["sha256"])
self.assertEqual(child["version"], ledger[name]["version"])
self.assertEqual(child["protocol"], "node/2")
# The library packs its own small copy of each game's art.
self.assertEqual((self.output / child["preview"]).read_bytes(),
(ROOT / f"assets/arcade/library/{name}-preview.png").read_bytes())
for key, path in child["cover"].items():
if key in ("portrait", "landscape", "logo"):
self.assertEqual((self.output / path).read_bytes(),
(ROOT / f"assets/arcade/library/{name}-{key}.png").read_bytes())
# Expected identities and versions come from each package's declarations.
self.assert_children_match_declarations(catalog, packages, ROOT)
self.assertEqual((self.output / catalog["harness"]).read_bytes(), self.controller.read_bytes())
pinned_ledger = json.loads((ROOT / "apps/versions.json").read_text())["node_apps"]
wurm_version = pinned_ledger["wurm"]["version"]
self.stage_four_leaf_wurm_fixture()
catalog, packages = builder.stage(self.root, self.controller, self.controller_digest, self.output)
self.assert_children_match_declarations(catalog, packages, self.root)
self.assertEqual([child["id"] for child in catalog["children"]],
["arcade.shovey", "arcade.shovey-editor",
"xyz.waozi.wurm", "xyz.waozi.wurm-editor", "xyz.waozi.choano"])
wurm_package = next(package for package in packages if package["name"] == "wurm")
self.assertEqual(wurm_package["children"], ["xyz.waozi.wurm", "xyz.waozi.wurm-editor"])
children = {child["id"]: child for child in catalog["children"]}
self.assertEqual(children["xyz.waozi.choano"]["title"], "Choano")
self.assertEqual(children["xyz.waozi.choano"]["version"], pinned_ledger["choano"]["version"])
self.assertEqual(children["xyz.waozi.choano"]["expected_id"], "choano")
self.assertEqual(children["xyz.waozi.wurm"]["version"], wurm_version)
self.assertEqual(children["xyz.waozi.wurm-editor"]["version"], "0.1.0")
self.assertEqual(children["xyz.waozi.wurm"]["cover"]["caption"], "Classic")
self.assertEqual(children["xyz.waozi.wurm-editor"]["cover"]["caption"], "Editor")
self.assertEqual(children["xyz.waozi.wurm-editor"]["dependencies"], ["xyz.waozi.wurm"])
self.assertFalse(children["xyz.waozi.wurm-editor"].get("shared_code", False))
self.assertEqual(children["xyz.waozi.wurm-editor"]["resources"], [{
"dependency": "xyz.waozi.wurm", "path": "assets/wurm/classic/",
"source": "assets/wurm-preview.png"}])
self.assertEqual(children["xyz.waozi.wurm"]["expected_id"], "wurm")
self.assertEqual(children["xyz.waozi.wurm-editor"]["expected_id"], "wurm-editor")
self.assertNotEqual(children["xyz.waozi.wurm"]["bundle"],
children["xyz.waozi.wurm-editor"]["bundle"])
def test_changed_game_art_needs_fresh_library_copies(self):
sources = self.root / "assets/arcade/library/sources.json"
value = json.loads(sources.read_text())
@@ -88,6 +403,83 @@ class CollectionTests(unittest.TestCase):
with self.assertRaisesRegex(ValueError, "wurm-portrait art changed"):
self.stage()
def test_artwork_input_changes_no_game_payload_or_version(self):
packages = builder.declared_packages(self.root, lock_flags=self.lock_flags)
# Released code/art aliases may resolve to the same package revision.
# Give the artwork its own fixture source so this still exercises an
# independent override, retaining the exact reviewed artwork bytes.
art_source = self.root / 'fixture-art'
wurm = next(package for package in packages if package['name'] == 'wurm')
for app in wurm['apps']:
paths = [app['descriptor']['preview']]
paths += [value for key, value in (app['cover'] or {}).items()
if key in ('portrait', 'landscape', 'logo')]
for relative in paths:
destination = art_source / relative
destination.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(app['art_source'] / relative, destination)
alias = json.loads((self.root / 'games.json').read_text())['artwork']['wurm']
(self.root / 'scripts/ziran.sh').write_text(
'#!/bin/sh\n'
f'if [ "$1" = pkg ] && [ "$2" = path ] && [ "$3" = {shlex.quote(alias)} ]; then\n'
f' printf \'%s\\n\' {shlex.quote(str(art_source))}\n'
' exit 0\n'
'fi\n'
f'cd {shlex.quote(str(ROOT))} && exec ./scripts/ziran.sh "$@"\n')
packages = builder.declared_packages(self.root, lock_flags=self.lock_flags)
game = next(app for package in packages for app in package['apps']
if app['descriptor']['name'] == 'wurm-editor')
self.assertNotEqual(game['source'], game['art_source'])
self.assertEqual(hashlib.sha256((game['art_source'] / game['cover']['portrait']).read_bytes()).hexdigest(),
'07ff2ff0142c262cdcba3643bbc4d7d3d71643b7f9f4e678a910fee2bfd3eba1')
ledger_path = self.root / 'apps/versions.json'
ledger = ledger_path.read_bytes()
version = json.loads(ledger)['node_apps']['wurm-editor']['version']
game_digest = builder.digest(self.root / 'build/games/wurm-editor.zx')
catalog = self.stage()
child = next(item for item in catalog['children'] if item['expected_id'] == 'wurm-editor')
self.assertEqual(child['version'], version)
self.assertEqual(child['sha256'], game_digest)
self.assertEqual(builder.digest(self.root / 'build/games/wurm-editor.zx'), game_digest)
self.assertEqual(ledger_path.read_bytes(), ledger)
def test_artwork_override_must_name_a_registered_game(self):
path = self.root / 'games.json'
value = json.loads(path.read_text())
value['artwork'] = {'unknown-game': 'wurm_art'}
path.write_text(json.dumps(value))
with self.assertRaisesRegex(ValueError, 'Invalid artwork package'):
self.stage()
def test_every_library_cover_uses_a_bounded_thumbnail(self):
catalog, packages = builder.stage(self.root, self.controller, self.controller_digest, self.output)
children = {child['id']: child for child in catalog['children']}
for package in packages:
for app in package['apps']:
if not app['enabled'] or not app['cover']:
continue
child = children[app['descriptor']['id']]
for key in ('portrait', 'landscape', 'logo'):
if key not in app['cover']:
continue
original = (app['art_source'] / app['cover'][key]).read_bytes()
with self.subTest(app=child['id'], image=key):
with Image.open(io.BytesIO(original)) as source:
with Image.open(self.output / child['cover'][key]) as thumbnail:
limit = 512 if key == 'logo' else 640
self.assertLessEqual(max(thumbnail.size), limit)
self.assertLessEqual(thumbnail.width, source.width)
self.assertLessEqual(thumbnail.height, source.height)
expected_ratio = source.width / source.height
if key == 'portrait':
expected_ratio = max(2 / 3, expected_ratio)
self.assertAlmostEqual(thumbnail.width / thumbnail.height,
expected_ratio, delta=0.01)
self.assertIn(thumbnail.mode, ('RGB', 'RGBA'))
# Opaque cover art is a JPEG; transparency stays PNG.
self.assertEqual(thumbnail.format, 'JPEG' if key != 'logo' and
thumbnail.mode == 'RGB' else 'PNG')
def test_editor_download_reuses_verified_shovey_assets(self):
catalog = self.stage()
children = {child['id']: child for child in catalog['children']}
@@ -221,7 +613,7 @@ class CollectionTests(unittest.TestCase):
(self.root / "games.json").write_text(json.dumps({"packages": []}))
self.assertEqual(self.stage()["children"], [])
self.assertFalse((self.output / "assets/arcade/games/shovey.zx").exists())
self.assertFalse((self.output / "assets/arcade/covers/shovey-portrait.png").exists())
self.assertFalse((self.output / "assets/arcade/covers/shovey-portrait.jpg").exists())
def test_unknown_declaration_field_rejected(self):
declaration = json.loads((self.root / "apps.json").read_text())
@@ -232,5 +624,71 @@ class CollectionTests(unittest.TestCase):
self.assertFalse(self.output.exists())
class LibraryThumbnailTests(unittest.TestCase):
def test_tall_portrait_keeps_title_inside_the_library_card(self):
source = Image.new('RGB', (800, 1600), (25, 50, 75))
source.paste((220, 180, 40), (80, 100, 720, 220))
data = io.BytesIO()
source.save(data, 'PNG')
contents, suffix = artist.small_copy(data.getvalue(), 'portrait')
self.assertEqual(suffix, '.jpg')
with Image.open(io.BytesIO(contents)) as thumbnail:
self.assertEqual(thumbnail.size, (427, 640))
# The real card's centred cover fit now leaves the title intact.
red, green, blue = thumbnail.getpixel((213, 85))
self.assertGreater(red, 200)
self.assertGreater(green, 160)
self.assertLess(blue, 60)
def test_cover_keeps_full_colour_at_thumbnail_resolution(self):
source = Image.new('RGB', (900, 1200))
source.putdata([(x % 256, y % 256, (x + y) % 256)
for y in range(1200) for x in range(900)])
data = io.BytesIO()
source.save(data, 'PNG')
contents, suffix = artist.small_copy(data.getvalue(), 'portrait')
self.assertEqual(suffix, '.jpg')
with Image.open(io.BytesIO(contents)) as thumbnail:
self.assertEqual(thumbnail.format, 'JPEG')
self.assertEqual(thumbnail.size, (480, 640))
self.assertEqual(thumbnail.mode, 'RGB')
self.assertIsNone(thumbnail.getcolors(256))
def test_logo_retains_transparency(self):
source = Image.new('RGBA', (1200, 400), (45, 155, 90, 0))
source.paste((200, 35, 100, 255), (100, 50, 1100, 350))
data = io.BytesIO()
source.save(data, 'PNG')
contents, suffix = artist.small_copy(data.getvalue(), 'logo')
self.assertEqual(suffix, '.png')
with Image.open(io.BytesIO(contents)) as thumbnail:
self.assertEqual(thumbnail.size, (512, 171))
self.assertEqual(thumbnail.mode, 'RGBA')
self.assertEqual(thumbnail.getpixel((0, 0))[3], 0)
self.assertEqual(thumbnail.getpixel((256, 85))[3], 255)
def test_small_covers_are_not_enlarged(self):
source = Image.new('RGB', (120, 180), (25, 50, 75))
data = io.BytesIO()
source.save(data, 'PNG')
contents, suffix = artist.small_copy(data.getvalue(), 'portrait')
self.assertEqual(suffix, '.jpg')
with Image.open(io.BytesIO(contents)) as thumbnail:
self.assertEqual(thumbnail.size, (120, 180))
def test_small_transparent_art_is_not_reencoded(self):
source = Image.new('RGBA', (120, 60), (25, 50, 75, 128))
data = io.BytesIO()
source.save(data, 'PNG')
self.assertEqual(artist.small_copy(data.getvalue(), 'logo'), (data.getvalue(), '.png'))
def test_thin_logos_keep_at_least_one_pixel(self):
source = Image.new('RGBA', (4096, 1), (25, 50, 75, 255))
data = io.BytesIO()
source.save(data, 'PNG')
with Image.open(io.BytesIO(artist.small_copy(data.getvalue(), 'logo')[0])) as thumbnail:
self.assertEqual(thumbnail.size, (512, 1))
if __name__ == "__main__":
unittest.main()
+39 -6
View File
@@ -18,7 +18,15 @@ from PIL import Image
LEVEL_UPDATES = 'Download new levels when they come out?'
def answer_library_question(driver):
"""Keep the test's bundled levels when the library asks about updates."""
"""Consent to the loopback library, keeping bundled game levels."""
deadline = time.monotonic() + 60
while time.monotonic() < deadline:
if driver.find(label='Connect', role='button', visible=True):
driver.press(label='Connect', role='button')
break
if driver.find(label='Shovey', role='button', visible=True):
break
driver.wait_idle(frames=3)
driver.wait(label='Shovey', role='button', timeout=60)
if driver.find(label=LEVEL_UPDATES, role='text'):
driver.press(label='Not now', role='button')
@@ -151,7 +159,7 @@ def main():
assert not driver.find(label='Play', role='button')
assert not driver.find(label='Open', role='button')
for label in ('Shovey', 'Shovey Editor', 'Apfelwurm'):
assert not driver.find(label=label, role='text'), 'Title artwork must not repeat its name underneath'
assert driver.find(label=label, role='text'), 'Every library cover shows its declared title'
driver.wait(label='Apfelwurm', role='button', visible=False)
smallest = (100, 140) if phone else (180, 200)
covers = [node for node in driver.find(role='image', visible=True)
@@ -211,7 +219,7 @@ def main():
return value[:start], state[:32]
with application(profile, "grid") as child:
driver.wait(label="Shovey", role="button")
# A fresh profile asks for consent before it shows the library.
answer_library_question(driver)
window = subprocess.check_output(['xdotool', 'search', '--onlyvisible', '--pid', str(child.pid)], text=True).splitlines()[0]
subprocess.run(['xdotool', 'windowsize', window, '480', '820'], check=True)
@@ -224,6 +232,12 @@ def main():
driver.press(label='Profile', role='button')
driver.wait(label='Account', role='text')
capture(child, 'arcade-profile')
driver.press(label='Leaderboard', role='button')
driver.wait(label='Leaderboard', role='text')
driver.wait(label='No leaderboard data yet.', role='text')
capture(child, 'leaderboard-empty')
driver.press(label='Back', role='button')
driver.wait(label='Account', role='text')
driver.press(label="Back", role="button")
driver.wait(label='Shovey', role='button')
assert not [path for path in (profile / 'resources/downloads').glob('*.zx') if path.stem in games]
@@ -261,6 +275,23 @@ def main():
saved = wait(lambda: record.read_bytes() if record.exists() else None, "Classic did not save")
driver.press(label="Back", role="button")
driver.wait(label="Shovey Editor", role="button")
driver.press(label='Profile', role='button')
driver.press(label='Leaderboard', role='button')
driver.wait(label='Shovey', role='button')
assert not driver.find(label='Apfelwurm', role='button'), 'An undownloaded game has a board'
assert not driver.find(label='Shovey Editor', role='button'), 'An unranked editor has a board'
capture(child, 'leaderboard-installed')
state = profile / 'resources/state/arcade.shovey.json'
state.parent.mkdir(parents=True, exist_ok=True)
state.write_text('{"v":1,"installed":0,"favorite":0}')
driver.wait(label='No leaderboard data yet.', role='text')
assert not driver.find(label='Shovey', role='button'), 'A retained score kept an uninstalled board visible'
state.write_text('{"v":1,"installed":1,"favorite":0}')
driver.wait(label='Shovey', role='button')
driver.press(label='Back', role='button')
driver.wait(label='Account', role='text')
driver.press(label='Back', role='button')
driver.wait(label='Shovey Editor', role='button')
assert not driver.find(label=sizes["shovey"], role="text"), "Installed games must omit their download size"
driver.press(label="Shovey Editor", role="button")
driver.wait(label='Download size: ' + sizes['shovey-editor'], role='text')
@@ -287,8 +318,10 @@ def main():
assert not driver.find(label='Pause', role='button'), 'Unverified bytes must never run'
server['corrupt_wurm'] = False
primary_download('Try again')
# The cover is its title: Apfelwurm asks once how to move, then plays.
driver.wait(label='How do you want to move?', role='text', timeout=60)
# The hosted player opens its title before its first steering choice.
driver.wait(label='Play', role='button', timeout=60)
driver.press(label='Play', role='button')
driver.wait(label='How do you want to move?', role='text')
driver.press(label='Swipe', role='button')
driver.wait(label='Pause', role='button')
capture(child, 'wurm-playing')
@@ -297,7 +330,7 @@ def main():
driver.press(label='Back to title', role='button')
driver.wait(label='Play', role='button')
capture(child, 'wurm-title')
driver.press(label='Back', role='button')
driver.key('escape')
driver.wait(label='Shovey', role='button')
for entry in json.loads((root / 'build/arcade.json').read_text())['children']:
path = profile / 'resources/downloads' / (entry['sha256'] + '.zx')
+152
View File
@@ -0,0 +1,152 @@
#!/usr/bin/env python3
"""Game imports select scoped Kryon paths; real bundles cover theme collisions."""
import os
from pathlib import Path
import subprocess
import sys
import tempfile
import unittest
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / 'scripts'))
from game_module_paths import kryon_module_paths
class SourceFixture(unittest.TestCase):
def setUp(self):
scratch = ROOT / 'work/game-module-path-tests'
subprocess.run(['git', 'check-ignore', '-q', str(scratch)], cwd=ROOT, check=True)
scratch.mkdir(parents=True, exist_ok=True)
self.folder = tempfile.TemporaryDirectory(dir=scratch)
self.addCleanup(self.folder.cleanup)
self.root = Path(self.folder.name)
self.source = self.root / 'game'
self.ui = self.root / 'kryon/src/ui'
self.ui.mkdir(parents=True)
for name in ('scroll', 'theme', 'geometry'):
(self.ui / (name + '.zi')).touch()
def write(self, path, text=''):
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(text)
def paths(self, entry='src/app.zi'):
return kryon_module_paths(self.source, {'source': entry}, self.root / 'kryon')
class ModulePathsTest(SourceFixture):
def test_qualified_imports_and_owned_theme_stay_scoped(self):
self.write(self.source / 'src/app.zi', '#import "theme"\n#import "kryon/scroll"')
self.write(self.source / 'src/theme.zi')
self.assertEqual(self.paths(), ['--module-path', 'kryon=' + str(self.ui),
'--module-path', 'kryon=' + str(self.ui.parent / 'backend')])
def test_short_import_in_nested_source_needs_plain_path(self):
self.write(self.source / 'src/app.zi', '#import "theme"')
self.write(self.source / 'src/theme.zi')
self.write(self.source / 'src/views/game.zi', 'Geometry :: #import /* reason */ "geometry";')
self.assertEqual(self.paths()[:2], ['--module-path', str(self.ui)])
def test_entry_outside_src_and_package_without_src(self):
self.write(self.source / 'src/host.zi')
self.write(self.source / 'apps/chess/view.zi', '#import "geometry"')
self.assertEqual(self.paths('apps/chess/view.zi')[:2], ['--module-path', str(self.ui)])
self.write(self.source / 'view.zi', '#import "scroll"')
(self.source / 'src/host.zi').unlink()
(self.source / 'src').rmdir()
self.assertEqual(self.paths('view.zi')[:2], ['--module-path', str(self.ui)])
def test_only_owned_root_names_shadow_shared_modules(self):
self.write(self.source / 'src/app.zi', '#import "geometry"')
self.write(self.source / 'src/nested/geometry.zi')
self.assertIn(str(self.ui), self.paths())
self.write(self.source / 'src/geometry/module.zi')
self.assertNotIn(str(self.ui), self.paths())
def test_comments_strings_file_imports_and_other_packages_do_not_flatten(self):
self.write(self.source / 'src/app.zi', '''
// #import "scroll"
/* #import "geometry" */
Text :: "#import \\"scroll\\""
#import, file "scroll.zi";
#import "other/geometry"
#import "not_a_ui_module"
''')
self.assertNotIn(str(self.ui), self.paths())
class BundleTest(SourceFixture):
@classmethod
def setUpClass(cls):
wrapper = str(ROOT / 'scripts/ziran.sh')
flags = [] if (ROOT / 'ziran.local.toml').exists() else ['--locked']
def package(name):
return Path(subprocess.check_output([wrapper, 'pkg', 'path', name, *flags], cwd=ROOT, text=True).strip())
cls.toolchain = Path(os.environ['ZIRAN_SOURCE']) if 'ZIRAN_SOURCE' in os.environ else package('ziran')
cls.kryon = Path(os.environ['KRYON_SOURCE']) if 'KRYON_SOURCE' in os.environ else package('kryon')
cls.compiler = os.environ.get('ZIRAN', str(cls.toolchain / 'build/bin/ziran'))
def compiler_run(self, *args):
env = os.environ.copy()
for key in ('DISPLAY', 'WAYLAND_DISPLAY', 'XAUTHORITY', 'DBUS_SESSION_BUS_ADDRESS'):
env.pop(key, None)
return subprocess.run([self.compiler, *map(str, args)],
cwd=ROOT, env=env, text=True, capture_output=True, timeout=180)
def bundle(self, imports, local_theme=False, old_paths=False):
entry = self.source / 'src/guest.zi'
self.write(entry, imports + '''
using ButtonState;
#program_export
Answer :: () -> s32 {
thumb := ScrollFace(StyleKindScrollThumb(), 0, false,
cast(s32)ButtonStateNormal, 10.0)
''' + (' if AppTheme.LocalTheme() != cast(u32)0xaabbccdd { return 1 }\n' if local_theme else '') + '''
if thumb.value.background != cast(u32)0x889faaff { return 2 }
return 42
}
''')
if local_theme:
self.write(entry.with_name('theme.zi'), '''
#program_export
LocalTheme :: () -> u32 { return cast(u32)0xaabbccdd }
''')
paths = kryon_module_paths(self.source, {'source': 'src/guest.zi'}, self.kryon)
if old_paths:
paths = ['--module-path', str(self.kryon / 'src/ui'), *paths]
output = self.root / 'guest.zx'
result = self.compiler_run('bundle', '--root', entry.parent, *paths,
'--module-path', self.toolchain / 'std',
'--entry', 'guest:Answer', '-o', output, entry)
return result, output
def test_scoped_bundle_preserves_app_theme_and_kryon_palette(self):
imports = '''AppTheme :: #import "theme";
#import "kryon/scroll"
#import "kryon/style_sheet"
#import "kryon/control_props"
'''
old, _ = self.bundle(imports, local_theme=True, old_paths=True)
self.assertNotEqual(old.returncode, 0, old.stdout)
self.assertIn('LightBorderStrong', old.stderr + old.stdout)
result, output = self.bundle(imports, local_theme=True)
self.assertEqual(result.returncode, 0, (result.stderr + result.stdout)[-8000:])
run = self.compiler_run('run', output)
self.assertEqual(run.returncode, 0, run.stderr)
self.assertEqual(run.stdout.strip(), '42')
def test_legacy_short_import_bundle_keeps_shared_path(self):
result, output = self.bundle('''#import "scroll"
#import "style_sheet"
#import "control_props"
''')
self.assertEqual(result.returncode, 0, (result.stderr + result.stdout)[-8000:])
run = self.compiler_run('run', output)
self.assertEqual(run.returncode, 0, run.stderr)
self.assertEqual(run.stdout.strip(), '42')
if __name__ == '__main__':
unittest.main()
+55
View File
@@ -0,0 +1,55 @@
#!/usr/bin/env python3
"""Lossless resource packing keeps color, transparency and dependency copies."""
import hashlib
import json
import random
import sys
import tempfile
import unittest
from pathlib import Path
from PIL import Image, PngImagePlugin
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'scripts'))
from game_resources import pack_opaque_pngs
class PackingTest(unittest.TestCase):
def test_only_redundant_alpha_is_removed(self):
scratch = Path(__file__).resolve().parents[1] / 'work/resource-packing-tests'
scratch.mkdir(parents=True, exist_ok=True, mode=0o700)
with tempfile.TemporaryDirectory(dir=scratch) as folder:
root = Path(folder)
rng = random.Random(1)
image = Image.new('RGBA', (64, 64))
image.putdata([(rng.randrange(256), rng.randrange(256), rng.randrange(256), 255)
for _ in range(64 * 64)])
opaque = root / 'opaque.png'
image.save(opaque, compress_level=0)
inventory = root / 'art.json'
inventory.write_text(json.dumps({'files': [{'path': 'opaque.png', 'sha256': hashlib.sha256(opaque.read_bytes()).hexdigest()}]}))
expected = image.tobytes()
old_size = opaque.stat().st_size
transparent = root / 'transparent.png'
image.putpixel((0, 0), (1, 2, 3, 127))
image.save(transparent)
before_transparent = transparent.read_bytes()
tagged = root / 'tagged.png'
info = PngImagePlugin.PngInfo()
info.add_text('source', 'fixture')
image.putpixel((0, 0), (1, 2, 3, 255))
image.save(tagged, pnginfo=info)
before_tagged = tagged.read_bytes()
pack_opaque_pngs(root)
self.assertLess(opaque.stat().st_size, old_size)
with Image.open(opaque) as actual:
self.assertEqual(actual.convert('RGBA').tobytes(), expected)
self.assertEqual(json.loads(inventory.read_text())['files'][0]['sha256'], hashlib.sha256(opaque.read_bytes()).hexdigest())
self.assertEqual(transparent.read_bytes(), before_transparent)
self.assertEqual(tagged.read_bytes(), before_tagged)
once = opaque.read_bytes()
pack_opaque_pngs(root)
self.assertEqual(opaque.read_bytes(), once)
if __name__ == '__main__':
unittest.main()
+21
View File
@@ -0,0 +1,21 @@
#!/usr/bin/env python3
"""Data fields must not suppress translation validation for actual labels."""
import importlib.util
from pathlib import Path
import sys
root = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(root / 'scripts'))
spec = importlib.util.spec_from_file_location('check_games', root / 'scripts/check-games.py')
checker = importlib.util.module_from_spec(spec)
spec.loader.exec_module(checker)
code = '\n'.join([
'#import "shovey_data"',
'owned := ShopInteger(reply, "shovey_owned", 7)',
'coins := ShopInteger(reply, "shovey_coins", 1000)',
'Text(Label("shovey_title"))',
])
assert checker.translation_keys(code, 'shovey_') == {'shovey_title'}
assert checker.translation_keys(code + '\nText(Label("shovey_owned"))', 'shovey_') == {'shovey_title', 'shovey_owned'}
assert checker.translation_keys('Label("shovey_missing_translation")', 'shovey_') == {'shovey_missing_translation'}
print('JSON fields excluded; actual labels still require translations')
+130
View File
@@ -0,0 +1,130 @@
"""Released games must bring new dependency edges without moving backwards."""
import importlib.util
import json
from pathlib import Path
import subprocess
import tempfile
import tomllib
import unittest
from unittest.mock import patch
ROOT = Path(__file__).resolve().parents[1]
spec = importlib.util.spec_from_file_location('follow_game_releases', ROOT / 'scripts/follow-game-releases.py')
follower = importlib.util.module_from_spec(spec)
spec.loader.exec_module(follower)
class GameUpdates(unittest.TestCase):
def follow(self, comparison, same_commit=False, failure=False, wrong_commit=False):
with tempfile.TemporaryDirectory(prefix='arcade-release-metadata-') as temporary:
root = Path(temporary)
(root / 'apps').mkdir()
old = '1' * 40
new = old if same_commit else '2' * 40
lock = {'format': 1, 'toolchain': {'commit': 'compiler'},
'root': {'dependencies': {'wurm': 'old', 'other': 'unrelated'}},
'packages': [{'id': 'old', 'name': 'Apfelwurm',
'url': 'https://github.com/waozixyz/wurm.git',
'commit': old, 'ref': 'master', 'dependencies': {}},
{'id': 'unrelated', 'commit': 'unchanged', 'dependencies': {}}]}
original_lock = json.dumps(lock)
(root / 'ziran.lock').write_text(original_lock)
original_manifest = ('[package]\nname = "Arcade"\n\n[dependencies.wurm]\n'
'git = "https://github.com/waozixyz/wurm.git"\nref = "master"\n\n'
'[dependencies.other]\nref = "stable"\n')
(root / 'ziran.toml').write_text(original_manifest)
(root / 'games.json').write_text(json.dumps({'packages': ['wurm']}))
# Release metadata may name a release before its source is pinned.
(root / 'apps/versions.json').write_text(json.dumps({'node_apps': {'wurm': {'version': '0.2.0'}}}))
def gh(*arguments):
if arguments[0] == 'release':
return 'v0.2.0'
return comparison if '/compare/' in arguments[1] else new
def resolve(command, **kwargs):
self.assertEqual(command, ['verified-ziran', 'update', 'wurm'])
self.assertEqual(kwargs, {'cwd': root, 'check': True})
self.assertIn(f'ref = "{new}"', (root / 'ziran.toml').read_text())
declaration = tomllib.loads((root / 'ziran.toml').read_text())
self.assertEqual(declaration['dependencies']['wurm']['ref'], new)
self.assertEqual(declaration['dependencies']['other']['ref'], 'stable')
if failure:
(root / 'ziran.lock').write_text('partial resolver output')
raise subprocess.CalledProcessError(1, command)
# A package-manager result with a newly introduced Entity import.
# The follower must retain this graph verbatim, rather than
# replacing the game id while preserving its old empty edges.
lock['root']['dependencies']['wurm'] = 'released'
lock['packages'][0].update(id='released', commit=old if wrong_commit else new,
ref=new, dependencies={'entity': 'accounts'})
lock['packages'].append({'id': 'accounts', 'commit': 'new-entity', 'dependencies': {}})
(root / 'ziran.lock').write_text(json.dumps(lock))
updates = root / 'updates.json'
with patch.object(follower, 'ROOT', root), patch.object(follower, 'UPDATES', updates), \
patch.object(follower, 'gh', gh), patch.object(follower.subprocess, 'run', side_effect=resolve) as run:
# Discovery must not require a compiler or modify either input.
follower.record_updates(follower.released_updates())
self.assertEqual((root / 'ziran.lock').read_text(), original_lock)
self.assertEqual((root / 'ziran.toml').read_text(), original_manifest)
run.assert_not_called()
if failure or wrong_commit:
with self.assertRaises((subprocess.CalledProcessError, ValueError)):
follower.pin('verified-ziran')
self.assertEqual((root / 'ziran.lock').read_text(), original_lock)
self.assertEqual((root / 'ziran.toml').read_text(), original_manifest)
else:
follower.pin('verified-ziran')
calls = run.call_count
return json.loads((root / 'ziran.lock').read_text()), json.loads(updates.read_text()), old, new, calls
def test_new_release_refreshes_transitive_graph(self):
lock, updates, old, new, calls = self.follow('ahead')
self.assertEqual(lock['packages'][0]['commit'], new)
self.assertEqual(lock['root']['dependencies']['wurm'], lock['packages'][0]['id'])
self.assertEqual(lock['packages'][0]['dependencies'], {'entity': 'accounts'})
self.assertEqual(lock['packages'][1]['commit'], 'unchanged')
self.assertEqual(lock['toolchain']['commit'], 'compiler')
self.assertEqual((len(updates), calls), (1, 1))
def test_same_source_is_unchanged(self):
lock, updates, old, new, calls = self.follow('identical', same_commit=True)
self.assertEqual(lock['packages'][0]['commit'], old)
self.assertEqual((updates, calls), ([], 0))
def test_older_release_never_moves_the_pin_back(self):
lock, updates, old, new, calls = self.follow('behind')
self.assertEqual(lock['packages'][0]['commit'], old)
self.assertEqual((updates, calls), ([], 0))
def test_failed_resolution_restores_manifest_and_lock(self):
self.follow('ahead', failure=True)
def test_local_override_cannot_publish_wrong_game(self):
self.follow('ahead', wrong_commit=True)
def test_release_ships_unreleased_notes(self):
with tempfile.TemporaryDirectory(prefix='arcade-release-notes-') as temporary:
root = Path(temporary)
game = root / 'game'
game.mkdir()
(game / 'apps.json').write_text(json.dumps({'title': 'Apfelwurm', 'apps': [{'manifest': 'catalog.json'}]}))
(game / 'CHANGELOG.md').write_text('## [Unreleased]\n\n- Later.\n\n## [0.2.1] - 2026-10-29\n\n- Faster.\n')
(root / 'catalog').mkdir()
(root / 'CHANGELOG.md').write_text('## 9.0.0\n\n- Host changes stay here.\n')
(root / 'catalog/CHANGELOG.md').write_text('# Arcade changelog\n\n## [Unreleased]\n\n- Keyboard first.\n\n'
'## 0.7.1\n\n- Older.\n')
updates = root / 'updates.json'
updates.write_text(json.dumps([{'name': 'wurm'}]))
with patch.object(follower, 'ROOT', root), patch.object(follower, 'UPDATES', updates), \
patch.object(follower.subprocess, 'check_output', return_value=str(game) + '\n'):
follower.changelog('ziran')
self.assertEqual((root / 'CHANGELOG.md').read_text(), '## 9.0.0\n\n- Host changes stay here.\n')
self.assertEqual((root / 'catalog/CHANGELOG.md').read_text(),
'# Arcade changelog\n\n## 0.7.2\n\n- Keyboard first.\n'
'- Apfelwurm 0.2.1: Faster.\n\n## 0.7.1\n\n- Older.\n')
if __name__ == '__main__':
unittest.main()
+272
View File
@@ -0,0 +1,272 @@
"""Private host test: consent, signed node membership, art and offline cache."""
import argparse
import contextlib
import hashlib
import http.server
import io
import json
import os
from pathlib import Path
import shutil
import struct
import subprocess
import sys
import tempfile
import threading
from PIL import Image
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
ROOT = Path(__file__).resolve().parents[1]
def capture_window(child, path):
window = subprocess.check_output(['xdotool', 'search', '--onlyvisible', '--pid', str(child.pid)],
text=True, timeout=10).splitlines()[0]
assert int(subprocess.check_output(['xdotool', 'getwindowpid', window], text=True, timeout=10)) == child.pid
subprocess.run(['import', '-window', window, str(path)], check=True, timeout=10)
return path
def live_library(binary, driver, work):
"""Use a disposable profile against the real public node; download no game."""
import time
from android_catalog import catalog_assets
with tempfile.TemporaryDirectory(dir=work) as temporary:
profile = Path(temporary)
log_path = work / 'live-node.log'
with log_path.open('w') as log:
child = subprocess.Popen([str(binary.resolve())], cwd=ROOT,
env=os.environ | driver.environment() | {'ARCADE_DATA': str(profile),
'ENTITY_DATA': str(profile / 'entity'), 'LANG': 'en_US.UTF-8'},
stdout=log, stderr=subprocess.STDOUT)
driver.attach(child, log_path)
try:
driver.wait(label='Connect', role='button', timeout=60)
driver.press(label='Connect', role='button')
driver.wait(label='Apfelwurm Editor', role='button', timeout=60)
driver.wait(label='Choano', role='button', timeout=60)
metadata = json.loads((profile / 'node/current.json').read_text())
assert metadata['app_id'] == 'inbe.arcade'
source = json.loads((ROOT / 'build/arcade.json').read_text())['node']
assert metadata['sequence'] >= source['minimum_sequence']
digest = next(item['sha256'] for item in metadata['artifacts'] if item['variant'] == 'module')
catalog = catalog_assets((profile / 'node' / (digest + '.zx')).read_bytes())
art = profile / 'resources/downloads' / (catalog['art']['sha256'] + '.zx')
deadline = time.monotonic() + 60
while (not art.exists() or art.stat().st_size != catalog['art']['bytes']) and time.monotonic() < deadline:
driver.wait_idle(frames=5)
assert art.stat().st_size == catalog['art']['bytes']
with art.open('rb') as stream:
assert hashlib.file_digest(stream, 'sha256').hexdigest() == catalog['art']['sha256']
driver.wait_idle(frames=40)
card = driver.wait(label='Shovey', role='button')
with Image.open(capture_window(child, work / 'live-node-library.png')) as image:
crop = image.crop((card['x'], card['y'], card['x'] + card['width'], card['y'] + card['height']))
assert len(crop.convert('RGB').getcolors(1000000) or []) > 500
cached = {path.stem for path in (profile / 'resources/downloads').glob('*.zx')}
assert cached == {catalog['art']['sha256']}, 'No game payload may download during library browsing'
print('Live node signed catalog and verified thumbnail pixels passed:', metadata['version'])
finally:
if child.poll() is None:
child.terminate()
child.wait(timeout=10)
def with_catalog(payload, catalog):
"""Keep the real root program and replace only its fixture catalog asset."""
assert len(payload) <= 262144
source = io.BytesIO(payload)
def number():
return struct.unpack('<I', source.read(4))[0]
def text():
return source.read(number())
assert source.read(8) in (b'ZX\0\0\x1a\0\0\0', b'ZX\0\0\x1b\0\0\0')
text(); text()
for _ in range(number()):
text(); text()
for _ in range(number()):
for _ in range(7):
text()
source.read(8); text(); source.read(4)
for _ in range(number()):
text(); text(); text()
source.read(number())
prefix = payload[:source.tell()]
assets = {text(): text() for _ in range(number())}
assert not source.read(1)
assets[b'assets/apps/catalog.json'] = json.dumps(catalog).encode()
def packed(value):
return struct.pack('<I', len(value)) + value
return prefix + struct.pack('<I', len(assets)) + b''.join(
packed(name) + packed(value) for name, value in assets.items())
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--binary', type=Path, required=True)
parser.add_argument('--inbe-source', type=Path, required=True)
parser.add_argument('--apps-source', type=Path, required=True)
parser.add_argument('--live', action='store_true', help='Verify the real public node using a disposable profile')
args = parser.parse_args()
assert int(os.environ['DISPLAY'].split(':')[-1].split('.')[0]) >= 400
assert os.environ['YUE_DESKTOP_RECOVERY'] == '0'
subprocess.run(['git', 'check-ignore', 'work/node-library-ui/data'], cwd=ROOT, check=True)
sys.path[:0] = [str(args.inbe_source / 'tests'), str(args.apps_source / 'tests'), str(ROOT / 'scripts')]
from ui_driver import UiDriver
from remote_catalog_test import descriptor
from android_catalog import catalog_assets
work = ROOT / 'work/node-library-ui'
work.mkdir(parents=True, exist_ok=True)
driver = UiDriver(work / 'driver')
if args.live:
live_library(args.binary, driver, work)
return
key = Ed25519PrivateKey.generate()
seed = (ROOT / 'build/arcade.zx').read_bytes()
catalog = catalog_assets(seed)
entry = next(child for child in catalog['children'] if child['expected_id'] == 'shovey')
first_entry = dict(entry, title='Node Shovey')
if 'cover' in entry:
first_entry['cover'] = dict(entry['cover'], caption='Node Shovey')
first = dict(catalog, children=[first_entry])
payloads = [with_catalog(seed, first), with_catalog(seed, catalog)]
digests = [hashlib.sha256(data).hexdigest() for data in payloads]
state = {'revision': 0, 'requests': []}
class Handler(http.server.BaseHTTPRequestHandler):
def log_message(self, *args):
pass
def do_GET(self):
state['requests'].append(self.path)
relative = self.path.removeprefix('/api/v2/packages/inbe.arcade/')
if relative.startswith('latest?'):
index = state['revision']
data = json.dumps(descriptor(key, payloads[index], 196 + index, module_api=2)).encode()
elif relative.removesuffix('.zx') in digests:
data = payloads[digests.index(relative.removesuffix('.zx'))]
else:
package = ROOT / 'build/node-apps/arcade.games' / relative
if not package.is_file():
self.send_error(404)
return
data = package.read_bytes()
self.send_response(200)
self.send_header('Content-Length', str(len(data)))
self.end_headers()
self.wfile.write(data)
server = http.server.ThreadingHTTPServer(('127.0.0.1', 0), Handler)
thread = threading.Thread(target=server.serve_forever)
thread.start()
origin = f'http://127.0.0.1:{server.server_port}'
try:
with tempfile.TemporaryDirectory(dir=work) as temporary:
folder = Path(temporary)
app = folder / 'app'
app.mkdir()
shutil.copy2(args.binary, app / 'arcade')
for name in ('arcade.zx', 'apps.zx', 'entity.zx'):
shutil.copyfile(ROOT / 'build' / name, app / name)
receipt = json.loads((ROOT / 'build/arcade.json').read_text())
receipt['node'] = dict(origin=origin, app_id='inbe.arcade', key_id='fixture-2026', minimum_sequence=195,
public_key=key.public_key().public_bytes(serialization.Encoding.Raw, serialization.PublicFormat.Raw).hex())
(app / 'arcade.json').write_text(json.dumps(receipt))
profile = folder / 'data'
save = profile / 'games/inbe.chess/records/computer'
save.parent.mkdir(parents=True)
save.write_bytes(b'prior saved game')
@contextlib.contextmanager
def application(name):
log_path = work / (name + '.log')
with log_path.open('w') as log:
child = subprocess.Popen([str(app / 'arcade')], cwd=app,
env=os.environ | driver.environment() | {'ARCADE_DATA': str(profile),
'ENTITY_DATA': str(profile / 'entity'), 'LANG': 'en_US.UTF-8'},
stdout=log, stderr=subprocess.STDOUT)
driver.attach(child, log_path)
try:
yield child
finally:
if child.poll() is None:
child.terminate()
child.wait(timeout=10)
def capture(child, name):
return capture_window(child, work / (name + '.png'))
def resize(child, width, height):
window = subprocess.check_output(['xdotool', 'search', '--onlyvisible', '--pid', str(child.pid)],
text=True, timeout=10).splitlines()[0]
subprocess.run(['xdotool', 'windowsize', window, str(width), str(height)], check=True, timeout=10)
# The previous tree may already be stable while X11's resize
# event is still queued. Wait for the accepted viewport first.
import time
deadline = time.monotonic() + 10
while max(node['width'] for node in driver.tree()) != width:
assert time.monotonic() < deadline, 'The host did not accept the new viewport'
time.sleep(0.05)
driver.wait_idle(frames=20)
with application('consent-refresh') as child:
driver.wait(label='Connect', role='button')
driver.wait_idle(frames=20)
assert not state['requests'], 'No node traffic before consent'
capture(child, 'consent')
resize(child, 360, 740)
capture(child, 'phone-consent')
resize(child, 1000, 820)
driver.press(label='Stay offline', role='button')
driver.wait(label='Shovey', role='button')
driver.wait_idle(frames=20)
assert not state['requests'], 'Offline choice must prevent preview downloads'
driver.press(label='Node connection', role='button')
driver.wait(label='Connect', role='button')
driver.press(label='Connect', role='button')
driver.wait(label='Node Shovey', role='button', timeout=60)
assert not driver.find(label='Choano', role='button'), 'Membership must come from the signed node catalog'
driver.wait_idle(frames=60)
assert any(path.endswith(catalog['art']['sha256'] + '.zx') for path in state['requests']), 'Node previews must be fetched'
assert driver.find(role='image', visible=True), 'Verified previews must draw'
card = driver.wait(label='Node Shovey', role='button')
assert card['y'] >= 88, 'The library must leave room for its connection controls'
with Image.open(capture(child, 'node-library')) as image:
crop = image.crop((card['x'], card['y'], card['x'] + card['width'], card['y'] + card['height']))
assert len(crop.convert('RGB').getcolors(1000000) or []) > 500, 'The preview must paint actual image pixels'
game_hashes = {entry['sha256'] for entry in catalog['children']}
assert not any(any(digest in path for digest in game_hashes) for path in state['requests']), 'No game payload before Download'
state['revision'] = 1
driver.press(label='Refresh library', role='button')
driver.wait(label='Choano', role='button', timeout=60)
driver.wait(label='Apfelwurm Editor', role='button')
driver.wait_idle(frames=20)
capture(child, 'refreshed-library')
resize(child, 360, 740)
capture(child, 'phone-library')
resize(child, 1000, 820)
assert save.read_bytes() == b'prior saved game'
driver.press(label='Node connection', role='button')
driver.wait(label='Stay offline', role='button')
driver.press(label='Stay offline', role='button')
driver.wait(label='Choano', role='button')
driver.wait_idle(frames=10)
count = len(state['requests'])
driver.wait_idle(frames=40)
assert len(state['requests']) == count, 'Revocation must stop node traffic'
with application('cached-offline'):
driver.wait(label='Choano', role='button', timeout=60)
driver.wait(label='Apfelwurm Editor', role='button')
driver.wait_idle(frames=40)
assert len(state['requests']) == count, 'Saved offline choice and signed catalog must survive restart'
assert save.read_bytes() == b'prior saved game'
finally:
server.shutdown()
server.server_close()
thread.join()
print('Arcade node consent, signed membership refresh, preview rendering, game download consent and offline restart passed')
if __name__ == '__main__':
main()
+3
View File
@@ -230,6 +230,9 @@ def main():
resize_owned_window(child, 480, 820)
driver.press(label='Swipe and tap')
driver.wait_gone(label='How do you want to move?', role='text')
driver.wait(label='Got it', role='button')
driver.press(label='Got it', role='button')
driver.wait_gone(label='Got it', role='button')
assert (profile / 'games/arcade.shovey-player/records/controls').read_text() == 'off'
assert not driver.find(label='Continue', role='button'), 'Classic must open straight on a level'
assert driver.find(label='Shovey', role='image', visible=True), 'Shovey must be drawn as a picture'
+3
View File
@@ -117,6 +117,9 @@ def main():
answer_level_updates(driver)
driver.press(label='Swipe and tap')
driver.wait_gone(label='How do you want to move?', role='text')
driver.wait(label='Got it', role='button')
driver.press(label='Got it', role='button')
driver.wait_gone(label='Got it', role='button')
# Entering play may save the untouched campaign; a fresh profile may
# have no record until the first move.
deadline = time.monotonic() + 10
+51
View File
@@ -0,0 +1,51 @@
"""Startup previews keep full colour and alpha while the originals stay intact."""
import importlib.util
from pathlib import Path
import tempfile
import unittest
from PIL import Image
ROOT = Path(__file__).resolve().parents[1]
spec = importlib.util.spec_from_file_location('build_desktop', ROOT / 'scripts/build-desktop.py')
desktop = importlib.util.module_from_spec(spec)
spec.loader.exec_module(desktop)
class StartupArtTests(unittest.TestCase):
def test_previews_keep_colour_alpha_and_aspect_ratio(self):
work = ROOT / 'build/scratch'
work.mkdir(parents=True, exist_ok=True)
with tempfile.TemporaryDirectory(prefix='startup-art-', dir=work) as temporary:
root = Path(temporary)
source = root / 'source/assets/shovey'
source.mkdir(parents=True)
# A continuous RGB gradient needs more than a 256-colour palette.
gradient = Image.new('RGB', (900, 1200))
gradient.putdata([(x % 256, y % 256, (x + y) % 256)
for y in range(1200) for x in range(900)])
gradient.save(source / 'title-portrait.png')
gradient.transpose(Image.Transpose.ROTATE_90).save(source / 'title-landscape.png')
logo = gradient.resize((1200, 400)).convert('RGBA')
alpha = Image.new('L', logo.size, 0)
alpha.paste(255, (100, 50, 1100, 350))
logo.putalpha(alpha)
logo.save(source / 'logo.png')
originals = {path.name: path.read_bytes() for path in source.iterdir()}
output = root / 'output'
desktop.stage_startup_art(root / 'source', output)
expected = {'title-portrait.png': (480, 640),
'title-landscape.png': (640, 480), 'logo.png': (512, 171)}
for name, size in expected.items():
with self.subTest(image=name), Image.open(output / 'startup/shovey' / name) as preview:
self.assertEqual(preview.size, size)
self.assertEqual(preview.mode, 'RGBA' if name == 'logo.png' else 'RGB')
self.assertIsNone(preview.getcolors(256), 'Title previews must not use a 256-colour palette')
if name == 'logo.png':
self.assertEqual(preview.getpixel((0, 0))[3], 0)
self.assertEqual(preview.getpixel((256, 85))[3], 255)
self.assertEqual((source / name).read_bytes(), originals[name])
if __name__ == '__main__':
unittest.main()
+77
View File
@@ -0,0 +1,77 @@
"""Verify coloured startup previews, original covers and title transitions privately."""
import argparse
import json
import os
from pathlib import Path
import subprocess
import sys
import tempfile
from PIL import Image
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--binary', type=Path, required=True)
parser.add_argument('--driver-source', type=Path, required=True)
args = parser.parse_args()
assert int(os.environ['DISPLAY'].split(':')[-1].split('.')[0]) >= 400
assert os.environ['YUE_DESKTOP_RECOVERY'] == '0'
sys.path.insert(0, str(args.driver_source / 'tests'))
from ui_driver import UiDriver
root = Path(__file__).resolve().parents[1]
output = root / 'build/scratch/title-progressive/ui'
output.mkdir(parents=True, exist_ok=True)
binary = args.binary.resolve()
driver = UiDriver(output / 'driver')
with tempfile.TemporaryDirectory(prefix='profile-', dir=output) as temporary:
profile = Path(temporary)
records = profile / 'games/arcade.shovey-player/records'
records.mkdir(parents=True)
(records / 'level-updates').write_text('off')
log_path = output / 'game.log'
with log_path.open('w') as log:
child = subprocess.Popen([str(binary)], cwd=binary.parent,
env=os.environ | driver.environment() |
{'ARCADE_DATA': str(profile), 'ENTITY_DATA': str(profile / 'entity'),
'LANG': 'en_US.UTF-8', 'SDL_AUDIODRIVER': 'dummy'},
stdout=log, stderr=subprocess.STDOUT)
driver.attach(child, log_path)
try:
startup = driver.tree()
assert driver.last['frame'] <= 3, 'Preview must precede collection loading'
images = [node for node in startup if node['kind'] == 'image' and node['label'] == 'Shovey']
assert len(images) == 2, 'Startup must show the artwork and coloured logo together'
for node in images:
assert 'startup/shovey/' in node['detail']
with Image.open(node['detail']) as picture:
assert picture.mode in ('RGB', 'RGBA'), 'Startup art must retain full colour'
assert max(picture.size) <= 640, 'Startup must use a small preview'
(output / 'startup-tree.json').write_text(json.dumps(driver.last, indent=2) + '\n')
driver.wait(label='Play', role='button', timeout=60)
full = [node for node in driver.tree() if node['kind'] == 'image' and
'arcade/covers/shovey-' in node.get('detail', '')]
assert len(full) >= 2
assert any(max(Image.open(node['detail']).size) >= 1200 for node in full), \
'Ready cover must replace the preview with the original artwork'
windows = subprocess.check_output(['xdotool', 'search', '--onlyvisible', '--pid', str(child.pid)], text=True).split()
assert len(windows) == 1
window = windows[0]
assert subprocess.check_output(['xdotool', 'getwindowpid', window], text=True).strip() == str(child.pid)
subprocess.run(['xdotool', 'windowmove', window, '0', '0'], check=True)
subprocess.run(['import', '-window', window, str(output / 'classic-ready.png')], check=True)
driver.key('right')
subprocess.run(['import', '-window', window, str(output / 'logo-fading.png')], check=True)
driver.wait(label='Editor', role='text')
driver.wait(label='Open', role='button')
driver.wait_idle(frames=5)
subprocess.run(['import', '-window', window, str(output / 'editor-ready.png')], check=True)
driver.key('left')
driver.wait(label='Classic', role='text')
driver.wait(label='Play', role='button')
assert child.poll() is None
finally:
if child.poll() is None:
child.terminate()
child.wait(timeout=10)
print('Local title UI test: full-colour previews precede original covers; Classic/Editor transitions work')
+175
View File
@@ -0,0 +1,175 @@
import hashlib
import http.server
import io
import importlib.util
import json
from pathlib import Path
import struct
import tarfile
import tempfile
import threading
import unittest
ROOT = Path(__file__).resolve().parents[1]
spec = importlib.util.spec_from_file_location(
"wait_published_games", ROOT / "scripts/wait-published-games.py"
)
readiness = importlib.util.module_from_spec(spec)
spec.loader.exec_module(readiness)
def bundle(files):
def text(value):
return struct.pack("<I", len(value)) + value
data = b"ZX\0\0\x1b\0\0\0" + text(b"arcade") + text(b"Main")
data += struct.pack("<IIII", 0, 0, 0, 0) + struct.pack("<I", len(files))
for path in sorted(files):
data += text(path.encode()) + text(files[path])
return data
class Clock:
def __init__(self):
self.now = 0.0
def __call__(self):
return self.now
def sleep(self, seconds):
self.now += seconds
class Handler(http.server.BaseHTTPRequestHandler):
responses = {}
def do_GET(self):
digest = self.path.rsplit("/", 1)[-1].removesuffix(".zx")
response = self.responses.get(digest, "ready")
if isinstance(response, list):
response = response.pop(0)
if response == "ready":
game = getattr(self.server, "games", {})
body = game.get(digest, b"")[:16]
self.send_response(200)
self.send_header("Content-Type", "application/octet-stream")
self.send_header("ETag", f'"{digest}"')
self.end_headers()
self.wfile.write(body)
return
if isinstance(response, int):
self.send_response(response)
self.send_header("Content-Type", "application/json")
self.end_headers()
self.wfile.write(b"{}")
return
body = response.get("body", b"ZX\0\0\x1b\0\0\0port")
self.send_response(response.get("status", 200))
self.send_header("Content-Type", response.get("type", "application/octet-stream"))
if "etag" in response:
self.send_header("ETag", response["etag"])
if "range" in response:
self.send_header("Content-Range", response["range"])
self.send_header("Content-Length", str(response.get("length", len(body))))
self.end_headers()
self.wfile.write(body)
def log_message(self, format, *arguments):
pass
class WaitPublishedGamesTests(unittest.TestCase):
def setUp(self):
work = ROOT / "build/scratch"
work.mkdir(parents=True, exist_ok=True)
self.temporary = tempfile.TemporaryDirectory(prefix="published-games-", dir=work)
self.root = Path(self.temporary.name)
self.games = {
hashlib.sha256(b"first game").hexdigest(): b"first game",
hashlib.sha256(b"second game").hexdigest(): b"second game",
hashlib.sha256(b"third game with bytes").hexdigest(): b"third game with bytes",
}
catalog = {
"children": [
{"sha256": digest, "bytes": len(data)} for digest, data in self.games.items()
]
}
self.bundle = self.root / "arcade.zx"
self.bundle.write_bytes(bundle({"assets/apps/catalog.json": json.dumps(catalog).encode()}))
self.archive = self.root / "arcade.games.tar"
with tarfile.open(self.archive, "w") as content:
for digest, data in self.games.items():
member = tarfile.TarInfo(digest + ".zx")
member.size = len(data)
content.addfile(member, io.BytesIO(data))
Handler.responses = {}
self.server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Handler)
self.server.games = {digest: data for digest, data in self.games.items()}
self.thread = threading.Thread(target=self.server.serve_forever, daemon=True)
self.thread.start()
self.api_root = f"http://127.0.0.1:{self.server.server_port}"
def tearDown(self):
self.server.shutdown()
self.server.server_close()
self.thread.join(timeout=5)
self.temporary.cleanup()
def wait(self, deadline=1.0):
games = readiness.expected_games(readiness.catalog_from_bundle(self.bundle))
members = readiness.archive_members(self.archive, games)
clock = Clock()
readiness.wait_for_published_games(self.api_root, self.archive, games, members,
deadline, poll_seconds=0.01,
clock=clock, sleep=clock.sleep)
def test_all_packages_ready(self):
self.wait()
def test_a_404_is_retried_until_the_package_is_ready(self):
digest = next(iter(self.games))
Handler.responses[digest] = [404, "ready"]
self.wait(deadline=0.03)
def test_a_permanent_404_fails_at_the_deadline(self):
Handler.responses[next(iter(self.games))] = 404
with self.assertRaisesRegex(TimeoutError, "still unavailable"):
self.wait(deadline=0.01)
def test_error_or_mismatched_responses_do_not_count_as_ready(self):
digest = next(iter(self.games))
for response in (
{"etag": '"0" * 64'},
{"type": "text/plain"},
{"body": b"not the verified prefix"},
{"body": b"0123456789abcdef", "etag": None},
{"status": 206, "range": "bytes 0-15/1"},
500,
):
Handler.responses[digest] = response
with self.subTest(response=response), self.assertRaises(TimeoutError):
self.wait()
def test_an_exact_partial_response_counts_as_ready(self):
digest, game = next(item for item in self.games.items() if len(item[1]) > 16)
Handler.responses[digest] = {
"status": 206,
"etag": f'"{digest}"',
"range": f"bytes 0-{min(16, len(game)) - 1}/{len(game)}",
"body": game[:16],
}
self.wait()
def test_a_wrong_full_response_content_length_does_not_count_as_ready(self):
digest, game = next(iter(self.games.items()))
Handler.responses[digest] = {
"etag": f'"{digest}"',
"body": game,
"length": len(game) + 1,
}
with self.assertRaisesRegex(TimeoutError, digest):
self.wait(deadline=0.02)
if __name__ == "__main__":
unittest.main()
+191
View File
@@ -0,0 +1,191 @@
"""The website serves small verified copies of the collection's library art."""
import hashlib
import importlib.util
import io
import json
from pathlib import Path
import struct
import tarfile
import tempfile
import unittest
from PIL import Image
ROOT = Path(__file__).resolve().parents[1]
spec = importlib.util.spec_from_file_location('build_web', ROOT / 'scripts/build-web.py')
web = importlib.util.module_from_spec(spec)
spec.loader.exec_module(web)
def bundle(files):
"""A minimal ZX v27 bundle: empty program sections, then its files."""
def text(value):
return struct.pack('<I', len(value)) + value
data = b'ZX\0\0\x1b\0\0\0' + text(b'art') + text(b'Main') + struct.pack('<IIII', 0, 0, 0, 0)
data += struct.pack('<I', len(files))
for path in sorted(files):
data += text(path.encode()) + text(files[path])
return data
def png(image):
output = io.BytesIO()
image.save(output, 'PNG', optimize=True)
return output.getvalue()
def jpeg(image):
output = io.BytesIO()
image.save(output, 'JPEG', quality=85)
return output.getvalue()
def gradient(width, height):
image = Image.new('RGB', (width, height))
image.putdata([(x * 255 // width, y * 255 // height, (x * y) % 256)
for y in range(height) for x in range(width)])
return image
def decoded(data):
image = Image.open(io.BytesIO(data))
image.load()
return image
class WebLibraryArtTests(unittest.TestCase):
def setUp(self):
work = ROOT / 'build/scratch'
work.mkdir(parents=True, exist_ok=True)
self.temporary = tempfile.TemporaryDirectory(prefix='web-art-', dir=work)
self.root = Path(self.temporary.name)
self.published = self.root / 'published'
self.published.mkdir()
self.site = self.root / 'site'
self.site.mkdir()
# A photographic cover, larger than any library copy should be.
self.portrait = jpeg(gradient(800, 1200))
self.landscape = jpeg(gradient(640, 427))
logo = gradient(512, 180).convert('RGBA')
logo.putalpha(Image.new('L', logo.size, 0))
logo.paste(gradient(300, 100), (100, 40))
self.logo = png(logo)
# Pixel art with a palette, which must stay exact.
pixels = Image.new('P', (48, 32))
pixels.putpalette([value for index in range(16) for value in (index * 16, 255 - index * 16, index * 8)])
pixels.putdata([(x // 4 + y // 4) % 16 for y in range(32) for x in range(48)])
self.preview = png(pixels)
self.art = bundle({
'assets/arcade/covers/wurm-portrait.jpg': self.portrait,
'assets/arcade/covers/wurm-landscape.jpg': self.landscape,
'assets/arcade/covers/wurm-logo.png': self.logo,
'assets/arcade/previews/wurm.png': self.preview,
})
def tearDown(self):
self.temporary.cleanup()
def collection(self, art=None, archive=True):
art = self.art if art is None else art
catalog = dict(schema=1, id='inbe.arcade', title='Arcade', harness='assets/apps/apps.zx',
art=dict(sha256=hashlib.sha256(self.art).hexdigest(), bytes=len(self.art)),
children=[dict(id='xyz.waozi.wurm', title='Apfelwurm',
preview='assets/arcade/previews/wurm.png',
icon='assets/arcade/previews/wurm.png',
cover=dict(portrait='assets/arcade/covers/wurm-portrait.jpg',
landscape='assets/arcade/covers/wurm-landscape.jpg',
logo='assets/arcade/covers/wurm-logo.png',
caption='Play'))])
path = self.published / 'arcade.zx'
path.write_bytes(bundle({'assets/apps/catalog.json': json.dumps(catalog).encode()}))
digest = catalog['art']['sha256']
if archive:
# The release's game archive, as the website workflow downloads it.
with tarfile.open(self.published / 'arcade.games.tar', 'w') as games:
for name, data in ((f'{digest}.zx', art), ('0' * 64 + '.zx', b'ZX\0\0game')):
entry = tarfile.TarInfo(name)
entry.size = len(data)
games.addfile(entry, io.BytesIO(data))
else:
(self.published / 'arcade.games').mkdir()
(self.published / 'arcade.games' / f'{digest}.zx').write_bytes(art)
return path, digest
def test_small_webp_copies_keep_alpha_pixels_and_the_exact_art(self):
path, digest = self.collection()
listing = web.stage_web_library_art(path, self.site)
self.assertEqual(listing['art'], digest)
self.assertEqual(json.loads((self.site / 'library.json').read_text()), listing)
# The exact signed bundle stays beside the copies, for the fallback.
self.assertEqual((self.site / 'library' / f'{digest}.zx').read_bytes(), self.art)
pictures = listing['pictures']
self.assertEqual(set(pictures), {'assets/arcade/covers/wurm-portrait.jpg',
'assets/arcade/covers/wurm-landscape.jpg',
'assets/arcade/covers/wurm-logo.png',
'assets/arcade/previews/wurm.png'})
copies = {}
for name, picture in pictures.items():
data = (self.site / picture['file']).read_bytes()
self.assertEqual(hashlib.sha256(data).hexdigest(), picture['sha256'])
self.assertEqual(len(data), picture['bytes'])
self.assertEqual(picture['file'], f'library/{picture["sha256"]}' + Path(picture['file']).suffix)
copies[name] = data
portrait = decoded(copies['assets/arcade/covers/wurm-portrait.jpg'])
self.assertEqual(portrait.format, 'WEBP')
self.assertEqual(portrait.size, (427, 640))
landscape = copies['assets/arcade/covers/wurm-landscape.jpg']
self.assertEqual(decoded(landscape).format, 'WEBP')
self.assertLess(len(landscape), len(self.landscape))
logo = decoded(copies['assets/arcade/covers/wurm-logo.png'])
self.assertEqual((logo.format, logo.mode, logo.size), ('WEBP', 'RGBA', (512, 180)))
self.assertEqual(logo.getpixel((5, 5))[3], 0)
self.assertEqual(logo.getpixel((200, 80))[3], 255)
preview = copies['assets/arcade/previews/wurm.png']
if decoded(preview).format == 'WEBP':
self.assertLess(len(preview), len(self.preview))
self.assertEqual(decoded(preview).convert('RGB').tobytes(),
decoded(self.preview).convert('RGB').tobytes())
else:
# WebP is no smaller: the verified original goes as it is.
self.assertEqual(preview, self.preview)
def test_a_local_build_folder_also_supplies_the_art(self):
path, digest = self.collection(archive=False)
self.assertEqual(web.stage_web_library_art(path, self.site)['art'], digest)
def test_corrupt_or_resized_art_is_refused_before_anything_is_written(self):
corrupt = bytearray(self.art)
corrupt[-1] ^= 1
for art in (bytes(corrupt), self.art + b'\0'):
path, _ = self.collection(art)
with self.assertRaisesRegex(ValueError, 'differs from the collection catalog'):
web.stage_web_library_art(path, self.site)
self.assertFalse((self.site / 'library.json').exists())
self.assertFalse((self.site / 'library').exists())
def test_missing_art_or_pictures_are_refused(self):
path, _ = self.collection()
(self.published / 'arcade.games.tar').unlink()
with self.assertRaisesRegex(ValueError, 'not beside it'):
web.stage_web_library_art(path, self.site)
self.art = bundle({'assets/arcade/previews/wurm.png': self.preview})
path, _ = self.collection()
with self.assertRaisesRegex(ValueError, 'lacks assets/arcade/covers'):
web.stage_web_library_art(path, self.site)
self.assertFalse((self.site / 'library.json').exists())
def test_a_collection_that_packs_its_art_needs_no_copies(self):
catalog = dict(schema=1, id='inbe.arcade', children=[])
path = self.published / 'arcade.zx'
path.write_bytes(bundle({'assets/apps/catalog.json': json.dumps(catalog).encode()}))
self.assertIsNone(web.stage_web_library_art(path, self.site))
self.assertEqual(list(self.site.iterdir()), [])
def test_truncated_or_trailing_bundles_are_refused(self):
for data in (self.art[:-3], self.art + b'x', b'PK' + self.art[2:]):
with self.assertRaises(ValueError):
web.bundle_assets(data)
if __name__ == '__main__':
unittest.main()
Loaded 100 of 104 files, more files were not shown because too many files have changed in this diff. Show more