Merge upstream: sharded test runs, auto-release follows CI (3.1.0)
Some checks failed
CI / plan (push) Waiting to run
CI / part (push) Blocked by required conditions
CI / build (push) Waiting to run
CI / translations (push) Waiting to run
CI / test (push) Blocked by required conditions
CI / timings (push) Blocked by required conditions
Container image / test (push) Has been cancelled
Container image / publish (push) Has been cancelled

The fork's Unreleased bullets stay above upstream's 3.1.0 section. The dark
mode test reads the theme script from the page's HTML, since the harness
now runs script bodies outside the DOM.
This commit is contained in:
jvanvik 2026-11-07 10:29:33 +01:00
commit 4b922aba02
22 changed files with 287 additions and 128 deletions

View file

@ -5,8 +5,9 @@ description: Cut and ship a Series of Tubes release (patch or minor) from main v
# Releasing Series of Tubes # Releasing Series of Tubes
Bumping `version` in `package.json` on `main` is the release button. The Bumping `version` in `package.json` on `main` is the release button. CI tests the push
`auto-release.yml` workflow tests, tags `v<version>`, publishes a GitHub release with as usual; when it passes, `auto-release.yml` (which runs after every CI on `main`) sees
the new version, tags `v<version>` on the commit CI tested, publishes a GitHub release with
that version's CHANGELOG section as notes, and dispatches `release.yml`, which builds that version's CHANGELOG section as notes, and dispatches `release.yml`, which builds
`_site/` (`npm run build`: the page assembled from `src/` plus `site/`) and deploys it `_site/` (`npm run build`: the page assembled from `src/` plus `site/`) and deploys it
to GitHub Pages (https://seriesoftub.es). GitHub Pages is the only host, ever: see the to GitHub Pages (https://seriesoftub.es). GitHub Pages is the only host, ever: see the
@ -65,8 +66,8 @@ gh api repos/fjaeckel/seriesoftubes/releases/latest --jq '.tag_name+" "+.publish
## Steps ## Steps
1. Don't run the test suite, the game or benchmarks before a release: CI and the 1. Don't run the test suite, the game or benchmarks before a release: CI tests the
auto-release workflow test it, and the Performance workflow benchmarks it. Just version bump (a red CI releases nothing), and the Performance workflow benchmarks it. Just
check that the latest CI run on `main` is green (`gh run list --repo fjaeckel/seriesoftubes --limit 4`). check that the latest CI run on `main` is green (`gh run list --repo fjaeckel/seriesoftubes --limit 4`).
2. In `CHANGELOG.md`, move the bullets from `## [Unreleased]` into a new section 2. In `CHANGELOG.md`, move the bullets from `## [Unreleased]` into a new section
right below it: `## [x.y.z] — YYYY-MM-DD` (em dash, today's date). Keep an empty right below it: `## [x.y.z] — YYYY-MM-DD` (em dash, today's date). Keep an empty
@ -81,7 +82,7 @@ gh api repos/fjaeckel/seriesoftubes/releases/latest --jq '.tag_name+" "+.publish
--author="Frederic Jung <frederic@jc-ix.net>" -m "Short summary (x.y.z)" --author="Frederic Jung <frederic@jc-ix.net>" -m "Short summary (x.y.z)"
git push origin main git push origin main
``` ```
6. Watch the workflows until both finish: 6. Watch the workflows until all three finish (CI, then Auto-release, then Release to GitHub Pages):
```bash ```bash
gh run list --repo fjaeckel/seriesoftubes --limit 4 gh run list --repo fjaeckel/seriesoftubes --limit 4
gh run watch <id> --repo fjaeckel/seriesoftubes gh run watch <id> --repo fjaeckel/seriesoftubes

View file

@ -5,10 +5,15 @@ name: Auto-release
# as notes, and starts the deploy. Releases created with the workflow token do # as notes, and starts the deploy. Releases created with the workflow token do
# not fire the "released" event, so the deploy is started explicitly, from the # not fire the "released" event, so the deploy is started explicitly, from the
# tag, which keeps the github-pages environment's v* tag rule happy. # tag, which keeps the github-pages environment's v* tag rule happy.
#
# It runs when CI finishes on main, so a release never repeats the push's tests:
# CI green on the commit that bumped the version is the go. A red CI releases
# nothing. Started by hand, it has no CI result to go by, so it tests first.
on: on:
push: workflow_run:
workflows: [CI]
types: [completed]
branches: [main] branches: [main]
paths: [package.json]
workflow_dispatch: workflow_dispatch:
permissions: permissions:
@ -20,18 +25,26 @@ concurrency:
cancel-in-progress: false cancel-in-progress: false
jobs: jobs:
release: check:
# After CI: only a green run of a push to main (not a PR's run, not a release's own call).
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push')
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
GH_TOKEN: ${{ github.token }} GH_TOKEN: ${{ github.token }}
outputs:
skip: ${{ steps.v.outputs.skip }}
ver: ${{ steps.v.outputs.ver }}
tag: ${{ steps.v.outputs.tag }}
pre: ${{ steps.v.outputs.pre }}
# The commit CI tested (main may have moved on since); by hand, main as it is now.
sha: ${{ github.event.workflow_run.head_sha || github.sha }}
steps: steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with: with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
fetch-depth: 0 fetch-depth: 0
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: 24
cache: npm
- name: Work out the version and whether it is new - name: Work out the version and whether it is new
id: v id: v
@ -57,34 +70,47 @@ jobs:
case "$ver" in *-*) echo "pre=true" >> "$GITHUB_OUTPUT";; *) echo "pre=false" >> "$GITHUB_OUTPUT";; esac case "$ver" in *-*) echo "pre=true" >> "$GITHUB_OUTPUT";; *) echo "pre=false" >> "$GITHUB_OUTPUT";; esac
echo "skip=false" >> "$GITHUB_OUTPUT" echo "skip=false" >> "$GITHUB_OUTPUT"
- name: Test before releasing # Only when started by hand: after a push, CI has already tested this commit.
if: steps.v.outputs.skip == 'false' tests:
run: npm ci && npm test needs: check
if: needs.check.outputs.skip == 'false' && github.event_name == 'workflow_dispatch'
uses: ./.github/workflows/ci.yml
with:
ref: ${{ needs.check.outputs.sha }}
release:
needs: [check, tests]
if: >-
always() && needs.check.result == 'success' && needs.check.outputs.skip == 'false' &&
(needs.tests.result == 'success' || needs.tests.result == 'skipped')
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ needs.check.outputs.tag }}
VER: ${{ needs.check.outputs.ver }}
PRE: ${{ needs.check.outputs.pre }}
SHA: ${{ needs.check.outputs.sha }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ needs.check.outputs.sha }}
- name: Publish the release - name: Publish the release
if: steps.v.outputs.skip == 'false'
env:
TAG: ${{ steps.v.outputs.tag }}
VER: ${{ steps.v.outputs.ver }}
PRE: ${{ steps.v.outputs.pre }}
run: | run: |
set -euo pipefail set -euo pipefail
awk -v v="$VER" 'index($0,"## ["v"]")==1{f=1;next} /^## \[/{f=0} f' CHANGELOG.md | sed -e '/./,$!d' > notes.md
pre=(); [ "$PRE" = "true" ] && pre=(--prerelease) pre=(); [ "$PRE" = "true" ] && pre=(--prerelease)
gh release create "$TAG" --repo "$GITHUB_REPOSITORY" \ gh release create "$TAG" --repo "$GITHUB_REPOSITORY" \
--target "$GITHUB_SHA" --title "$VER" --notes-file notes.md "${pre[@]}" --target "$SHA" --title "$VER" --notes-file notes.md "${pre[@]}"
- name: Deploy it - name: Deploy it
# Pre-releases are for testing and never go live. # Pre-releases are for testing and never go live. CI (or the tests above) already passed on this commit,
if: steps.v.outputs.skip == 'false' && steps.v.outputs.pre == 'false' # so the deploy does not test it again (tested=true).
env: if: env.PRE == 'false'
TAG: ${{ steps.v.outputs.tag }} run: gh workflow run release.yml --repo "$GITHUB_REPOSITORY" --ref "$TAG" -f tag="$TAG" -f tested=true
run: gh workflow run release.yml --repo "$GITHUB_REPOSITORY" --ref "$TAG" -f tag="$TAG"
- name: Publish the Docker image - name: Publish the Docker image
# Same pattern as the deploy above: the image is built and pushed from the # Same pattern as the deploy above: the image is built and pushed from the
# release tag by docker.yml. Pre-releases get one too: an image tag is # release tag by docker.yml. Pre-releases get one too: an image tag is
# pulled on purpose, so a test image costs nothing. # pulled on purpose, so a test image costs nothing.
if: steps.v.outputs.skip == 'false'
env:
TAG: ${{ steps.v.outputs.tag }}
run: gh workflow run docker.yml --repo "$GITHUB_REPOSITORY" --ref "$TAG" -f tag="$TAG" run: gh workflow run docker.yml --repo "$GITHUB_REPOSITORY" --ref "$TAG" -f tag="$TAG"

View file

@ -1,44 +1,89 @@
name: CI name: CI
# Every push and PR, and the releases too (auto-release.yml and release.yml call this workflow), so the tests run
# one way, split over several runners, everywhere.
on: on:
push: push:
branches: [main] branches: [main]
pull_request: pull_request:
workflow_call:
inputs:
ref:
description: The commit or tag to test (a release tag); the caller's commit when empty
type: string
default: ''
permissions: permissions:
contents: read contents: read
# A newer push to the same pull request makes the older run pointless: cancel it instead of queueing behind it. # A newer push to the same pull request makes the older run pointless: cancel it instead of queueing behind it.
# Runs on main always finish. # Runs on main always finish. A release's call gets a group of its own, so it never waits behind main's push run.
concurrency: concurrency:
group: ci-${{ github.ref }} group: ci-${{ github.event_name == 'pull_request' && github.ref || github.run_id }}${{ inputs.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }} cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
# Runners for the tests. Standard GitHub-hosted runners (4 cores each) are the only free ones for a public repo,
# and a run may use up to 20 at once, so more parts is how the tests get faster. Each part costs ~30 s of setup.
PARTS: 6
jobs: jobs:
# The tests in four parts of about equal time, each on its own runner, each running as many files at once as # Splits the test files into parts of about equal time, once, so every part works from the same plan. The times
# it has cores (scripts/test.js; the split comes from tests/durations.json). # come from the last run on main (the cache, see "timings" below), else from the committed tests/durations.json.
plan:
runs-on: ubuntu-latest
outputs:
parts: ${{ steps.plan.outputs.parts }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.ref }}
- uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: tests/durations.json
key: test-durations-${{ github.run_id }}
restore-keys: test-durations-
- id: plan
run: echo "parts=$(node scripts/test.js --plan "$PARTS")" >> "$GITHUB_OUTPUT"
part: part:
name: test ${{ matrix.part }}/4 name: part ${{ strategy.job-index }}
needs: plan
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 20 timeout-minutes: 20
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
part: [1, 2, 3, 4] files: ${{ fromJSON(needs.plan.outputs.parts) }}
steps: steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.ref }}
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with: with:
node-version: 24 node-version: 24
cache: npm cache: npm
- run: npm ci - run: npm ci
- run: npm test -- --shard ${{ matrix.part }}/4 - name: Tests
env:
FILES: ${{ matrix.files }}
# Word splitting on purpose: FILES is a space-separated list of tests/*.test.js paths.
run: npm test -- --timings "$RUNNER_TEMP/timings.json" $FILES
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
if: always()
with:
name: timings-${{ strategy.job-index }}
path: ${{ runner.temp }}/timings.json
retention-days: 1
if-no-files-found: ignore
build: build:
name: build name: build
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.ref }}
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with: with:
node-version: 24 node-version: 24
@ -47,21 +92,12 @@ jobs:
- name: Build (not deployed — only releases deploy) - name: Build (not deployed — only releases deploy)
run: npm run build run: npm run build
# The one check to look at, named as before: green only when every part and the build are.
test:
needs: [part, build]
if: always()
runs-on: ubuntu-latest
steps:
- name: Every part and the build passed
run: |
echo "parts: ${{ needs.part.result }}, build: ${{ needs.build.result }}"
test "${{ needs.part.result }}" = success && test "${{ needs.build.result }}" = success
translations: translations:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: ${{ inputs.ref }}
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with: with:
node-version: 24 node-version: 24
@ -69,3 +105,38 @@ jobs:
- run: npm ci - run: npm ci
- name: Translation coverage - name: Translation coverage
run: node scripts/i18n-check.js --summary "$GITHUB_STEP_SUMMARY" run: node scripts/i18n-check.js --summary "$GITHUB_STEP_SUMMARY"
# The one check to look at: green only when the plan, every part, the build and the translations are.
test:
needs: [plan, part, build, translations]
if: always()
runs-on: ubuntu-latest
steps:
- name: Everything passed
run: |
echo "plan: ${{ needs.plan.result }}, parts: ${{ needs.part.result }}, build: ${{ needs.build.result }}, translations: ${{ needs.translations.result }}"
test "${{ needs.plan.result }}" = success && test "${{ needs.part.result }}" = success
test "${{ needs.build.result }}" = success && test "${{ needs.translations.result }}" = success
# After a run on main: each file's time from this run goes into the cache, so the next run (main or a PR) splits
# its parts by today's tests. Nobody has to remember to refresh tests/durations.json.
timings:
needs: part
if: always() && github.event_name == 'push' && github.ref == 'refs/heads/main' && needs.part.result != 'skipped'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: tests/durations.json
key: test-durations-${{ github.run_id }}
restore-keys: test-durations-
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
pattern: timings-*
path: ${{ runner.temp }}/timings
- run: node scripts/test-timings.js --merge "$RUNNER_TEMP/timings"
- uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: tests/durations.json
key: test-durations-${{ github.run_id }}

View file

@ -23,6 +23,10 @@ on:
description: Only the weekly puzzles changed (weekly-puzzle.yml); the release itself was tested when it shipped description: Only the weekly puzzles changed (weekly-puzzle.yml); the release itself was tested when it shipped
type: boolean type: boolean
default: false default: false
tested:
description: The tag's tests already passed (auto-release.yml tests it before tagging)
type: boolean
default: false
# Least privilege: only the deploy job can write to Pages. # Least privilege: only the deploy job can write to Pages.
permissions: permissions:
@ -33,9 +37,18 @@ concurrency:
cancel-in-progress: false cancel-in-progress: false
jobs: jobs:
# The release's tests, split over several runners like every push (ci.yml). Skipped when auto-release.yml has just
# run them on this tag, and for a weekly redeploy (the build step below tests the weekly files against the tag).
tests:
if: ${{ (github.event_name == 'workflow_dispatch' || !github.event.release.prerelease) && !inputs.weekly && !inputs.tested }}
uses: ./.github/workflows/ci.yml
with:
ref: ${{ github.event.release.tag_name || inputs.tag }}
build: build:
needs: tests
# Pre-releases are for testing and never go live. # Pre-releases are for testing and never go live.
if: ${{ github.event_name == 'workflow_dispatch' || !github.event.release.prerelease }} if: ${{ always() && (github.event_name == 'workflow_dispatch' || !github.event.release.prerelease) && (needs.tests.result == 'success' || needs.tests.result == 'skipped') }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
TAG: ${{ github.event.release.tag_name || inputs.tag }} TAG: ${{ github.event.release.tag_name || inputs.tag }}
@ -93,10 +106,9 @@ jobs:
node scripts/weekly-puzzle.js --check node scripts/weekly-puzzle.js --check
if [ -f scripts/weekly-scenario.js ]; then node scripts/weekly-scenario.js --check; fi if [ -f scripts/weekly-scenario.js ]; then node scripts/weekly-scenario.js --check; fi
if [ -f scripts/weekly-architect.js ]; then node scripts/weekly-architect.js --check; fi if [ -f scripts/weekly-architect.js ]; then node scripts/weekly-architect.js --check; fi
- run: npm test # The weekly files come from main, not the tag: whatever tested the tag, they are tested against it here.
if: ${{ !inputs.weekly }}
- name: Test the weekly puzzles against this release - name: Test the weekly puzzles against this release
if: ${{ inputs.weekly && hashFiles('scripts/weekly-puzzle.js') != '' }} if: ${{ hashFiles('scripts/weekly-puzzle.js') != '' }}
run: npm test -- tests/weekly-puzzle.test.js tests/puzzles.test.js $(ls tests/weekly-scenario.test.js tests/weekly-architect.test.js 2>/dev/null) run: npm test -- tests/weekly-puzzle.test.js tests/puzzles.test.js $(ls tests/weekly-scenario.test.js tests/weekly-architect.test.js 2>/dev/null)
- name: Build site - name: Build site
run: VERSION="${TAG#v}" REQUIRE_NOTES=1 npm run build run: VERSION="${TAG#v}" REQUIRE_NOTES=1 npm run build

View file

@ -10,16 +10,19 @@ All notable changes to this project are documented here. The project follows
- CGNAT gets a little cheaper every year: the world moves to IPv6 about two points a year, so less of your homes' traffic needs IPv4 and the CGNAT and NAT64 boxes carry less of it. - CGNAT gets a little cheaper every year: the world moves to IPv6 about two points a year, so less of your homes' traffic needs IPv4 and the CGNAT and NAT64 boxes carry less of it.
- The router model and the line system your intern standardizes on are now picked in one place, the build standard. Keep routers ahead and Upgrade optical transport take them from there and say so, with a button to the sheet. With a model or line system in the standard, both orders bring everything up to it and stop there (Upgrade optical transport on every fiber, even at POPs that Keep to the build standard skips); "Keep as is" leaves them to the next one up when busy. A model or line system you had picked in an order that was running moves into your standard, so new POPs get that model too. - The router model and the line system your intern standardizes on are now picked in one place, the build standard. Keep routers ahead and Upgrade optical transport take them from there and say so, with a button to the sheet. With a model or line system in the standard, both orders bring everything up to it and stop there (Upgrade optical transport on every fiber, even at POPs that Keep to the build standard skips); "Keep as is" leaves them to the next one up when busy. A model or line system you had picked in an order that was running moves into your standard, so new POPs get that model too.
- Your intern no longer takes a fiber dark for the build standard just because it looks quiet: like the optical upgrade order, it first checks that every gigabit, circuit and express gets around the fiber for the day. The two orders share one line system swap a night (two for Kevin), never work on the same fiber in one shift, and a wave the standard just upgraded is no longer handed back the same day. - Your intern no longer takes a fiber dark for the build standard just because it looks quiet: like the optical upgrade order, it first checks that every gigabit, circuit and express gets around the fiber for the day. The two orders share one line system swap a night (two for Kevin), never work on the same fiber in one shift, and a wave the standard just upgraded is no longer handed back the same day.
- Whoever runs sales can now answer renewal haggles for you, each in their own way: switch it on at the sales desk. The engineer keeps nerdy customers at the market price and gives everyone else their discount, the shark refuses discounts and some customers walk, and the CEO settles it on the golf course, for better or worse.
- The three interns now each have something they are best at: Anycast Annie peers every day and orders PNIs twice a week, Kevin from the night shift swaps two line systems a night and never fat-fingers anything, and Tracy Route buys capacity as if traffic were already 10% higher. They run the same orders at the same salary.
- Your intern can upgrade optical transport: a new standing order moves full, busy fiber to a bigger line system, or trades its smallest channels for bigger optics. Pick a line system, and every fiber on a smaller one is moved up to it. A line system swap takes the fiber down for a day, so the intern only does it where the traffic gets around it and no customer rides it, one a night.
- Copies of the game you host yourself can now have multiplayer: friends join your session with a six-character code and build their networks next to yours in the same world, with a leaderboard, a feed with chat, saves kept on your server and a link to carry a network to another device. It needs the small session server that comes with the source code, so the game at seriesoftub.es stays single-player. - Copies of the game you host yourself can now have multiplayer: friends join your session with a six-character code and build their networks next to yours in the same world, with a leaderboard, a feed with chat, saves kept on your server and a link to carry a network to another device. It needs the small session server that comes with the source code, so the game at seriesoftub.es stays single-player.
- Dark mode: pick Light, Dark or Auto (follows your device) under Settings › Theme. The panels, the NOC dashboard and the map all go dark, with a night-time sea and land, and the setting is kept on your device (#80). - Dark mode: pick Light, Dark or Auto (follows your device) under Settings › Theme. The panels, the NOC dashboard and the map all go dark, with a night-time sea and land, and the setting is kept on your device (#80).
- Express lightpaths: light a wave straight through the cities between your own dark fibers, without touching the routers there. Wherever two or more of your ROADM fibers on land meet, a fiber's panel lists where an express can go and the link window gets an Express tab; it uses ports only at its two ends, saves a hop of latency and takes one channel slot on every fiber it rides, and the light has to reach all the way between regen sites. A cut or a line system swap on any of those fibers darkens it, and a fiber can only be given up once no express rides it. (#58) - Express lightpaths: light a wave straight through the cities between your own dark fibers, without touching the routers there. Wherever two or more of your ROADM fibers on land meet, a fiber's panel lists where an express can go and the link window gets an Express tab; it uses ports only at its two ends, saves a hop of latency and takes one channel slot on every fiber it rides, and the light has to reach all the way between regen sites. A cut or a line system swap on any of those fibers darkens it, and a fiber can only be given up once no express rides it. (#58)
- Teleports bring satellites to small islands and remote towns, long before you have a cable there or a rocket company (#83). Build one at a POP from level 2 and rent GEO circuits (about 600 ms round trip, and users notice) or, with tracking antennas from level 3, MEO circuits (about 130 ms) to any island or town its satellites see. Next to an island's only cable a circuit waits on standby (whether the cable or the circuit came first) and carries the island when the cable is cut, and a city with no cable at all gets a POP and a circuit in one order. - Teleports bring satellites to small islands and remote towns, long before you have a cable there or a rocket company (#83). Build one at a POP from level 2 and rent GEO circuits (about 600 ms round trip, and users notice) or, with tracking antennas from level 3, MEO circuits (about 130 ms) to any island or town its satellites see. Next to an island's only cable a circuit waits on standby (whether the cable or the circuit came first) and carries the island when the cable is cut, and a city with no cable at all gets a POP and a circuit in one order.
- Your intern can standardize your routers on a model you choose: pick it in Keep routers ahead, and every POP on a smaller model is swapped to it, the busiest first, within the monthly budget. Every setting in the Standing orders sheet is now a list to pick from instead of a button to tap through.
- Set a build standard for your whole network: routers, a second building and a generator at every POP, LAGs, exchange ports and PNIs, line systems, optics and wave sizes, all in one sheet. New POPs get the POP part the day they open, the sheet shows what is below the standard and what fixing it costs, one tap brings everything up, and the new "Keep to the build standard" order has your intern do it a few jobs a day with money to spare. Find it in the menu, the Standing orders sheet and every POP's router section. - Set a build standard for your whole network: routers, a second building and a generator at every POP, LAGs, exchange ports and PNIs, line systems, optics and wave sizes, all in one sheet. New POPs get the POP part the day they open, the sheet shows what is below the standard and what fixing it costs, one tap brings everything up, and the new "Keep to the build standard" order has your intern do it a few jobs a day with money to spare. Find it in the menu, the Standing orders sheet and every POP's router section.
- IPv4 is scarce now: business customers need public address blocks, and the homes that do not fit share addresses behind CGNAT. A new network starts with a /21 from its registry, enough for its first months; buy, lease or sell blocks from /24 to /16 on the transfer market in the bank's new Address space section, or lease spare ones out for a monthly income. An offer you have no addresses for says so and waits, a customer that wants to grow at renewal stays at its size until you have the addresses, CGNAT costs a little and annoys some gamers, and you pick how many homes share an address. IPv6 stays free for everyone. This is part of On-call and BGP at 3 a.m.; the gentler rules, Sandbox, puzzles and scenarios keep IPv4 plentiful, and saved games get the addresses they already use plus room to grow (#150). - IPv4 is scarce now: business customers need public address blocks, and the homes that do not fit share addresses behind CGNAT. A new network starts with a /21 from its registry, enough for its first months; buy, lease or sell blocks from /24 to /16 on the transfer market in the bank's new Address space section, or lease spare ones out for a monthly income. An offer you have no addresses for says so and waits, a customer that wants to grow at renewal stays at its size until you have the addresses, CGNAT costs a little and annoys some gamers, and you pick how many homes share an address. IPv6 stays free for everyone. This is part of On-call and BGP at 3 a.m.; the gentler rules, Sandbox, puzzles and scenarios keep IPv4 plentiful, and saved games get the addresses they already use plus room to grow (#150).
## [3.1.0] — 2026-11-07
- Whoever runs sales can now answer renewal haggles for you, each in their own way: switch it on at the sales desk. The engineer keeps nerdy customers at the market price and gives everyone else their discount, the shark refuses discounts and some customers walk, and the CEO settles it on the golf course, for better or worse.
- The three interns now each have something they are best at: Anycast Annie peers every day and orders PNIs twice a week, Kevin from the night shift swaps two line systems a night and never fat-fingers anything, and Tracy Route buys capacity as if traffic were already 10% higher. They run the same orders at the same salary.
- Your intern can upgrade optical transport: a new standing order moves full, busy fiber to a bigger line system, or trades its smallest channels for bigger optics. Pick a line system, and every fiber on a smaller one is moved up to it. A line system swap takes the fiber down for a day, so the intern only does it where the traffic gets around it and no customer rides it, one a night.
- Your intern can standardize your routers on a model you choose: pick it in Keep routers ahead, and every POP on a smaller model is swapped to it, the busiest first, within the monthly budget. Every setting in the Standing orders sheet is now a list to pick from instead of a button to tap through.
- France gets seven more cities: Lyon, Toulouse, Lille, Bordeaux, Strasbourg, Rennes and Nantes, all but Nantes with an exchange of their own (#288). SF-Error Telecom and Boy-Egg Telecom bring home broadband and mobile, Ov-Hatch Cloud and Scale-Away bring French clouds, Tangerine Telecom and Free as in Beer reach the new cities, Cogentle reaches Toulouse, Lille, Bordeaux and Strasbourg, and Andorable Telecom comes up to Toulouse. The Atlantic cables now come ashore where they really do: Ami-Tea at Bordeaux and Dunno-ant at Nantes, and Dunno-ant starts at Virginia Beach. - France gets seven more cities: Lyon, Toulouse, Lille, Bordeaux, Strasbourg, Rennes and Nantes, all but Nantes with an exchange of their own (#288). SF-Error Telecom and Boy-Egg Telecom bring home broadband and mobile, Ov-Hatch Cloud and Scale-Away bring French clouds, Tangerine Telecom and Free as in Beer reach the new cities, Cogentle reaches Toulouse, Lille, Bordeaux and Strasbourg, and Andorable Telecom comes up to Toulouse. The Atlantic cables now come ashore where they really do: Ami-Tea at Bordeaux and Dunno-ant at Nantes, and Dunno-ant starts at Virginia Beach.
- Big networks at ×8 no longer stop for a moment when a day reroutes, after a failure, an event, the intern's shift or the sales desk's signing. Every routing a day needs now runs in the background like the day's own, a long day lets the map draw between its steps, and the check for customers afraid of sharks no longer walks every land fiber for each of them. Quiet notifications now also apply while the game is running. - Big networks at ×8 no longer stop for a moment when a day reroutes, after a failure, an event, the intern's shift or the sales desk's signing. Every routing a day needs now runs in the background like the day's own, a long day lets the map draw between its steps, and the check for customers afraid of sharks no longer walks every land fiber for each of them. Quiet notifications now also apply while the game is running.

View file

@ -83,9 +83,10 @@ Development runs on `npm run dev` (assembles the development page on every reque
| `scripts/agent/relay.js`, `scripts/lib/mcp-browser.js`, `scripts/lib/relay-client.js` | The agent relay `npm run dev` hosts at `/agent`, and the MCP server's side of it: how a tool reaches the game in the player's tab | | `scripts/agent/relay.js`, `scripts/lib/mcp-browser.js`, `scripts/lib/relay-client.js` | The agent relay `npm run dev` hosts at `/agent`, and the MCP server's side of it: how a tool reaches the game in the player's tab |
| `scripts/i18n-check.js`, `scripts/i18n-add.js`, `scripts/lib/dict.js` | Translation coverage and dictionary order; adding, renaming and removing entries | | `scripts/i18n-check.js`, `scripts/i18n-add.js`, `scripts/lib/dict.js` | Translation coverage and dictionary order; adding, renaming and removing entries |
| `scripts/legacy/` | The splitter that made `src/` from the old `site/index.html` (and gave its text labels), and `port-branch.js`, which carries older branches over | | `scripts/legacy/` | The splitter that made `src/` from the old `site/index.html` (and gave its text labels), and `port-branch.js`, which carries older branches over |
| `tests/harness.js` | Loads the assembled page in jsdom with a seeded `Math.random` and a fake canvas: the players' page, or the development page with `{agent: true}` | | `tests/harness.js` | Loads the assembled page in jsdom with a seeded `Math.random` and a fake canvas: the players' page, or the development page with `{agent: true}`. The page's scripts run straight in the window (jsdom's parser is slow on 2 MB of script) |
| `.github/workflows/ci.yml` | Tests and build on every push and PR | | `scripts/test.js`, `tests/durations.json` | Runs the tests, every file in its own process; splits them into parts of equal time for CI (`--plan`, `--shard`) by each file's seconds, which CI refreshes after every run on `main` |
| `.github/workflows/auto-release.yml` | On a `package.json` version bump on `main`: test, tag, GitHub release from the CHANGELOG, start the deploy | | `.github/workflows/ci.yml` | Tests (split over 6 runners), build and translations on every push and PR; the releases call it too, so the tests run one way everywhere |
| `.github/workflows/auto-release.yml` | After every green CI on `main`: if `package.json` has a new version, tag the commit CI tested, publish the GitHub release from the CHANGELOG, start the deploy (`tested=true`, so it does not test again) |
| `.github/workflows/release.yml` | Builds and deploys to GitHub Pages, the only workflow that can | | `.github/workflows/release.yml` | Builds and deploys to GitHub Pages, the only workflow that can |
| `.github/workflows/weekly-puzzle.yml` | Sunday 03:37 UTC: makes the week's puzzle, commits it to `main` (data only, no release) and starts `release.yml` for the live release tag with `weekly=true` | | `.github/workflows/weekly-puzzle.yml` | Sunday 03:37 UTC: makes the week's puzzle, commits it to `main` (data only, no release) and starts `release.yml` for the live release tag with `weekly=true` |
| `scripts/weekly-puzzle.js`, `site/puzzles/weekly/` | The weekly puzzle generator and its output, one `<key>.json` per week plus `index.json` (see below) | | `scripts/weekly-puzzle.js`, `site/puzzles/weekly/` | The weekly puzzle generator and its output, one `<key>.json` per week plus `index.json` (see below) |

4
package-lock.json generated
View file

@ -1,12 +1,12 @@
{ {
"name": "seriesoftubes", "name": "seriesoftubes",
"version": "3.0.0", "version": "3.1.0",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "seriesoftubes", "name": "seriesoftubes",
"version": "3.0.0", "version": "3.1.0",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@modelcontextprotocol/node": "2.1.2", "@modelcontextprotocol/node": "2.1.2",

View file

@ -1,6 +1,6 @@
{ {
"name": "seriesoftubes", "name": "seriesoftubes",
"version": "3.0.0", "version": "3.1.0",
"description": "A cartoon browser game about building the internet.", "description": "A cartoon browser game about building the internet.",
"private": true, "private": true,
"license": "MIT", "license": "MIT",

View file

@ -0,0 +1,18 @@
// A node:test reporter that writes how long each test file took, as JSON {"tests/x.test.js": seconds}, to its
// destination. scripts/test.js adds it next to the usual output with --timings FILE; CI merges the parts' files
// into tests/durations.json, which the next run splits its parts by.
const path = require('node:path');
module.exports = async function* timings(source) {
const sec = {};
for await (const { type, data } of source) {
// Top-level tests only: their durations include their subtests.
if ((type === 'test:pass' || type === 'test:fail') && data.nesting === 0 && data.file && data.details) {
const f = path.relative(process.cwd(), data.file).split(path.sep).join('/');
sec[f] = (sec[f] || 0) + (data.details.duration_ms || 0) / 1000;
}
}
const out = {};
for (const f of Object.keys(sec).sort()) out[f] = Math.round(sec[f] * 10) / 10;
yield JSON.stringify(out, null, 1) + '\n';
};

View file

@ -5,6 +5,7 @@
// machine has cores, so absolute numbers vary, but their sizes relative to each other are what count. // machine has cores, so absolute numbers vary, but their sizes relative to each other are what count.
// //
// npm run test:timings // npm run test:timings
// node scripts/test-timings.js --merge DIR (CI) fold the parts' --timings files into it
const fs = require('node:fs'); const fs = require('node:fs');
const os = require('node:os'); const os = require('node:os');
const path = require('node:path'); const path = require('node:path');
@ -12,6 +13,24 @@ const { spawn } = require('node:child_process');
const root = path.join(__dirname, '..'); const root = path.join(__dirname, '..');
const dir = path.join(root, 'tests'); const dir = path.join(root, 'tests');
// --merge DIR: fold the timings CI's parts wrote (scripts/test.js --timings) into tests/durations.json. Files that are
// gone drop out; files no part ran keep their old time.
const mi = process.argv.indexOf('--merge');
if (mi >= 0) {
const from = process.argv[mi + 1], dur = path.join(dir, 'durations.json');
let out = {};
try { out = JSON.parse(fs.readFileSync(dur, 'utf8')); } catch (e) { /* none yet */ }
let n = 0;
for (const f of fs.readdirSync(from, { recursive: true }).filter((f) => String(f).endsWith('.json'))) {
for (const [k, v] of Object.entries(JSON.parse(fs.readFileSync(path.join(from, String(f)), 'utf8')))) if (v > 0) { out[k] = v; n++; }
}
const have = new Set(fs.readdirSync(dir).filter((f) => f.endsWith('.test.js')).map((f) => 'tests/' + f));
const sorted = Object.fromEntries(Object.keys(out).filter((k) => have.has(k)).sort().map((k) => [k, out[k]]));
fs.writeFileSync(dur, JSON.stringify(sorted, null, 1) + '\n');
console.log(`merged ${n} timings; tests/durations.json has ${Object.keys(sorted).length} of ${have.size} files`);
process.exit(0);
}
const files = fs.readdirSync(dir).filter((f) => f.endsWith('.test.js')).sort().map((f) => 'tests/' + f); const files = fs.readdirSync(dir).filter((f) => f.endsWith('.test.js')).sort().map((f) => 'tests/' + f);
const jobs = Math.max(1, parseInt(process.env.TEST_JOBS, 10) || os.availableParallelism()); const jobs = Math.max(1, parseInt(process.env.TEST_JOBS, 10) || os.availableParallelism());
const out = {}; const out = {};

View file

@ -5,14 +5,18 @@
// //
// npm test everything // npm test everything
// npm test -- tests/peering.test.js just these files (other arguments go to node --test) // npm test -- tests/peering.test.js just these files (other arguments go to node --test)
// npm test -- --shard 2/4 one of four parts of about equal time (CI runs the four at once) // npm test -- --shard 2/4 one of four parts of about equal time
// npm test -- --shard 2/4 --list which files that part holds, without running them // npm test -- --shard 2/4 --list which files that part holds, without running them
// node scripts/test.js --plan 6 the split into 6 parts as JSON (CI's plan job: one list per runner)
// npm test -- --timings out.json also write each file's seconds to out.json (CI merges these into
// the durations the next run splits by)
// TEST_JOBS=1 npm test one file at a time, as it used to be // TEST_JOBS=1 npm test one file at a time, as it used to be
// npm test -- --stress 8 tests/x.test.js hunt a flaky test: 8 copies of these files at once, on a machine kept // npm test -- --stress 8 tests/x.test.js hunt a flaky test: 8 copies of these files at once, on a machine kept
// busier than CI ever is, and how many runs failed (and why) // busier than CI ever is, and how many runs failed (and why)
// //
// Parts are balanced by tests/durations.json, each file's typical seconds (refresh: npm run test:timings). // Parts are balanced by tests/durations.json, each file's typical seconds. CI keeps it fresh in its cache from every
// A file missing from it counts as a typical one, so a stale list only makes the parts a little uneven. // run on main (.github/workflows/ci.yml); npm run test:timings rewrites the committed copy. A file missing from it
// counts as a typical one, so a stale list only makes the parts a little uneven.
const fs = require('node:fs'); const fs = require('node:fs');
const os = require('node:os'); const os = require('node:os');
const path = require('node:path'); const path = require('node:path');
@ -31,6 +35,12 @@ if (ti >= 0) {
if (!(stress >= 1)) { console.error('--stress wants a count, like --stress 8'); process.exit(2); } if (!(stress >= 1)) { console.error('--stress wants a count, like --stress 8'); process.exit(2); }
args.splice(ti, 2); args.splice(ti, 2);
} }
let timings = null;
const tmi = args.indexOf('--timings');
if (tmi >= 0) { timings = args[tmi + 1]; args.splice(tmi, 2); if (!timings) { console.error('--timings wants a file'); process.exit(2); } }
let plan = 0;
const pi = args.indexOf('--plan');
if (pi >= 0) { plan = parseInt(args[pi + 1], 10); args.splice(pi, 2); if (!(plan >= 1)) { console.error('--plan wants a count, like --plan 6'); process.exit(2); } }
let shard = null; let shard = null;
const si = args.indexOf('--shard'); const si = args.indexOf('--shard');
if (si >= 0) { if (si >= 0) {
@ -58,6 +68,10 @@ function part(list, i, n) {
} }
return out[i - 1].sort(); return out[i - 1].sort();
} }
if (plan) {
console.log(JSON.stringify(Array.from({ length: plan }, (_, i) => part(files, i + 1, plan).join(' '))));
process.exit(0);
}
if (shard && files.length) { if (shard && files.length) {
files = part(files, shard[0], shard[1]); files = part(files, shard[0], shard[1]);
console.log(`# part ${shard[0]}/${shard[1]}: ${files.length} files`); console.log(`# part ${shard[0]}/${shard[1]}: ${files.length} files`);
@ -84,5 +98,7 @@ if (stress) {
}); });
return; return;
} }
const r = spawnSync(process.execPath, ['--test', `--test-concurrency=${jobs}`, ...args, ...files], { stdio: 'inherit', cwd: root }); const rep = timings ? ['--test-reporter=spec', '--test-reporter-destination=stdout',
`--test-reporter=${path.join(__dirname, 'lib', 'timings-reporter.js')}`, `--test-reporter-destination=${timings}`] : [];
const r = spawnSync(process.execPath, ['--test', `--test-concurrency=${jobs}`, ...rep, ...args, ...files], { stdio: 'inherit', cwd: root });
process.exit(r.status ?? 1); process.exit(r.status ?? 1);

View file

@ -38,9 +38,10 @@ test('a new network runs plain IGP: no Auto-TE until the backbone is upgraded, o
assert.deepEqual(JSON.parse(ev('JSON.stringify(S.core)')), { lv: 0, run: 0 }); assert.deepEqual(JSON.parse(ev('JSON.stringify(S.core)')), { lv: 0, run: 0 });
ev('ACT.buyTE()'); ev('ACT.buyTE()');
assert.equal(ev('!!S.te'), false, 'no Auto-TE on plain IGP'); assert.equal(ev('!!S.te'), false, 'no Auto-TE on plain IGP');
ev("ACT.leftTab({t:'noc'})"); // The backbone lives in the NOC's routing window; the refusal is a toast.
assert.match(dom.window.document.body.textContent, /Backbone/); ev('ACT.routingOpen()');
assert.match(dom.window.document.body.textContent, /Auto-TE needs an RSVP-TE/); assert.match(dom.window.document.getElementById('modal').textContent, /Backbone/);
assert.match(dom.window.document.getElementById('toasts').textContent, /Auto-TE needs an RSVP-TE/);
const cash = ev('S.cash'); const cash = ev('S.cash');
ev('ACT.coreUp()'); ev('ACT.coreUp()');
assert.equal(ev('S.core.lv'), 1); assert.equal(ev('S.core.lv'), 1);

View file

@ -23,14 +23,6 @@ test('#257 the calendar has real months and leap years',()=>{
assert.deepEqual(errors,[]); assert.deepEqual(errors,[]);
}finally{dom.window.close();} }finally{dom.window.close();}
}); });
test('#257 a calendar month costs its monthly price, whatever its length',()=>{
const {ev,dom}=load();try{
ev("ACT.start({});S.day=31");// 1 February Y1
const before=ev('S.cash'),net=ev('R.revMo-R.costMo');
ev("for(let i=0;i<28;i++)S.cash+=(R.revMo-R.costMo)/monLen(S.day+i)");
assert.ok(Math.abs(ev('S.cash')-before-net)<1e-6,'28 days of February add up to one month');
}finally{dom.window.close();}
});
test('#257 loan statements and the intern budget follow calendar months',()=>{ test('#257 loan statements and the intern budget follow calendar months',()=>{
const {ev,dom}=load();try{ const {ev,dom}=load();try{
ev("ACT.start({})"); ev("ACT.start({})");

View file

@ -49,10 +49,11 @@ test('the choice applies at boot, from the <head>, before the page is painted',
assert.deepEqual(errors, []); assert.deepEqual(errors, []);
dom.window.close(); dom.window.close();
} }
// The script that sets it sits in the <head>, before the styles: nothing is painted in the wrong colours first. // The script that sets it sits in the <head>, before the styles: nothing is painted in the wrong colours first. Read
const doc = load().dom.window.document, head = [...doc.head.children]; // from the page's HTML (the harness runs script bodies outside the DOM, so a <script>'s text is empty there).
const s = head.findIndex((e) => e.tagName === 'SCRIPT' && /sot-theme/.test(e.textContent)), st = head.findIndex((e) => e.tagName === 'STYLE'); const html = assemble().html, headEnd = html.indexOf('</head>'), st = html.indexOf('<style>');
assert.ok(s >= 0 && s < st, 'the theme script runs before the stylesheet'); const scripts = [...html.slice(0, headEnd).matchAll(/<script>([\s\S]*?)<\/script>/g)], s = scripts.find((m) => /sot-theme/.test(m[1]));
assert.ok(s && st >= 0 && st < headEnd && s.index < st, 'the theme script runs before the stylesheet');
// Auto with a dark device: dark from the first paint as well. // Auto with a dark device: dark from the first paint as well.
const d = device(true), h = load({ browser: d }); const d = device(true), h = load({ browser: d });
assert.equal(h.dom.window.document.documentElement.getAttribute('data-theme'), 'dark'); assert.equal(h.dom.window.document.documentElement.getAttribute('data-theme'), 'dark');

View file

@ -15,12 +15,6 @@ test('every city sits on its landmass', () => {
assert.equal(off, ''); assert.equal(off, '');
}); });
test('every cable lands at two known cities and has a length', () => {
const { ev } = load();
const bad = ev("CABLE_PAIRS.filter(c=>!CITY[c.a]||!CITY[c.b]||!(c.km>0)).map(c=>c.cid).join()");
assert.equal(bad, '');
});
test('a year of scripted play stays healthy', () => { test('a year of scripted play stays healthy', () => {
const { ev, errors } = load(); const { ev, errors } = load();
seed(ev, 7); seed(ev, 7);

View file

@ -6,6 +6,7 @@
// it fails here rather than in production. // it fails here rather than in production.
const fs = require('node:fs'); const fs = require('node:fs');
const path = require('node:path'); const path = require('node:path');
const vm = require('node:vm');
const { JSDOM, VirtualConsole } = require('jsdom'); const { JSDOM, VirtualConsole } = require('jsdom');
const { assemble, simId } = require('../scripts/lib/page'); const { assemble, simId } = require('../scripts/lib/page');
@ -15,6 +16,26 @@ const page = (dev, mp) => PAGE[dev + '|' + mp] || (PAGE[dev + '|' + mp] = assemb
let SIM; let SIM;
const simOf = () => SIM || (SIM = simId(assemble({ mp: true }).html)); const simOf = () => SIM || (SIM = simId(assemble({ mp: true }).html));
// The page's inline scripts, taken out of the HTML once per process and compiled once. jsdom's HTML parser is slow
// on 2 MB of script text (it was more than half of every load()), so the DOM is built from the rest of the page and
// the scripts then run in its window, in order, the same way jsdom runs them (vm.Script.runInContext). Only plain
// <script> tags run, as in the browser here; data blocks (ld+json) stay in the page untouched.
const SPLIT = new Map();
function split(html) {
let s = SPLIT.get(html);
if (s) return s;
const code = [];
const shell = html.replace(/<script>([\s\S]*?)<\/script>/g, (m, src) => {
code.push(new vm.Script(src, { filename: `page-script-${code.length}.js` }));
return '<script></script>';
});
// With scripting on, the parser keeps a <noscript>'s content as text; with scripts run from outside it builds those
// elements (an extra <h1>, <p>, <div>). Escaped, the content stays one text node, as players' browsers have it.
const page = shell.replace(/(<noscript>)([\s\S]*?)(<\/noscript>)/g, (m, a, body, b) => a + body.replace(/&/g, '&amp;').replace(/</g, '&lt;') + b);
SPLIT.set(html, s = { shell: page, code });
return s;
}
// opts.file: a built or older page to load instead (the perf bench, the release build test). // opts.file: a built or older page to load instead (the perf bench, the release build test).
// opts.agent: the development page, with src/agent/. // opts.agent: the development page, with src/agent/.
// opts.mp: the page with multiplayer on, as MP_API=… npm run build makes it: the server-play client in it, MP_API // opts.mp: the page with multiplayer on, as MP_API=… npm run build makes it: the server-play client in it, MP_API
@ -29,12 +50,13 @@ function load(opts = {}) {
// jsdom has no canvas; drawing calls are expected to be unimplemented. // jsdom has no canvas; drawing calls are expected to be unimplemented.
if (!/getContext|Not implemented/.test(e.message)) errors.push(e.message); if (!/getContext|Not implemented/.test(e.message)) errors.push(e.message);
}); });
const dom = new JSDOM(html, { const { shell, code } = split(html);
const dom = new JSDOM(shell, {
// opts.url: the origin the page is "served" from. Tests that dial the agent relay pass the relay's own host, so // opts.url: the origin the page is "served" from. Tests that dial the agent relay pass the relay's own host, so
// the page's WebSocket Origin matches (the relay refuses a cross-site one); everything else stays on a made-up // the page's WebSocket Origin matches (the relay refuses a cross-site one); everything else stays on a made-up
// https origin nothing can reach. // https origin nothing can reach.
url: opts.url || 'https://tests.invalid/', url: opts.url || 'https://tests.invalid/',
runScripts: 'dangerously', runScripts: 'outside-only',
pretendToBeVisual: true, pretendToBeVisual: true,
virtualConsole: vc, virtualConsole: vc,
beforeParse(window) { beforeParse(window) {
@ -71,6 +93,14 @@ function load(opts = {}) {
window.HTMLCanvasElement.prototype.toBlob = (cb) => cb(null); window.HTMLCanvasElement.prototype.toBlob = (cb) => cb(null);
}, },
}); });
// The language picker document.write()s a dictionary <script src> for a non-English player. jsdom fetched nothing
// for it anyway (opts.lang registers the dictionary), and after parsing a real write would wipe the page.
const doc = dom.window.document, ctx = dom.getInternalVMContext();
doc.write = () => {};
for (const sc of code) {
try { sc.runInContext(ctx); } catch (e) { vc.emit('jsdomError', Object.assign(new Error(`Uncaught [${e}]`), { detail: e })); }
}
delete doc.write;
const ev = (src) => dom.window.eval(src); const ev = (src) => dom.window.eval(src);
// Deterministic by default so a test never passes or fails by luck; pass {seed:false} to opt out. // Deterministic by default so a test never passes or fails by luck; pass {seed:false} to opt out.
// (Seeded in beforeParse, so the game's own seeded-games wrapper around Math.random stays in place.) // (Seeded in beforeParse, so the game's own seeded-games wrapper around Math.random stays in place.)

View file

@ -19,11 +19,13 @@ test('diversity map: the indexed graph answers like disjointRoutes() over every
const cp = ev('CABLE_PAIRS[0].cid+":"+CABLE_PAIRS[0].a+"-"+CABLE_PAIRS[0].b'); const cp = ev('CABLE_PAIRS[0].cid+":"+CABLE_PAIRS[0].a+"-"+CABLE_PAIRS[0].b');
for (const st of [{ won: false }, { won: true }, { won: false, scn: { rules: { banCities: ['jam', 'lon'], banPairs: [cp] } } }]) { for (const st of [{ won: false }, { won: true }, { won: false, scn: { rules: { banCities: ['jam', 'lon'], banPairs: [cp] } } }]) {
const r = JSON.parse(ev(`(()=>{const st=${lit(st)},L=plainLinks(st);diversityMap=null;diversityPossible('fra','nyc',st); const r = JSON.parse(ev(`(()=>{const st=${lit(st)},L=plainLinks(st);diversityMap=null;diversityPossible('fra','nyc',st);
const ids=CITIES.map(c=>c.id),bad=[];let n=0;for(let i=0;i<ids.length;i+=3)for(let j=i+1;j<ids.length;j+=3){n++;const a=ids[i],b=ids[j]; const ids=CITIES.map(c=>c.id),bad=[];let n=0;for(let i=0;i<ids.length;i+=9)for(let j=i+1;j<ids.length;j+=9){n++;const a=ids[i],b=ids[j];
const want=(st.scn&&st.scn.rules.banCities.some(x=>x===a||x===b))?diversityPossible(a,b,st):disjointRoutes(a,b,L);if(diversityPossible(a,b,st)!==want)bad.push(a+'-'+b);} const want=(st.scn&&st.scn.rules.banCities.some(x=>x===a||x===b))?diversityPossible(a,b,st):disjointRoutes(a,b,L);if(diversityPossible(a,b,st)!==want)bad.push(a+'-'+b);}
return JSON.stringify({links:L.length,mine:diversityMap.links,n,bad})})()`)); return JSON.stringify({links:L.length,mine:diversityMap.links,n,bad})})()`));
assert.equal(r.mine, r.links, 'the same possible links'); assert.equal(r.mine, r.links, 'the same possible links');
assert.ok(r.n > 2000); // Every 9th city against every 9th after it: over a thousand pairs, near and far, in all regions (each pair walks
// every possible link the plain way, so all pairs took 90 s).
assert.ok(r.n > 1000);
assert.deepEqual(r.bad, [], JSON.stringify(st)); assert.deepEqual(r.bad, [], JSON.stringify(st));
} }
assert.deepEqual(errors, []); assert.deepEqual(errors, []);
@ -41,7 +43,7 @@ test('link curves: skipping far-away cities gives the same bend around the ones
const cand=[1,1.5,2.1,2.9,3.8].map(k=>lim(sg*mag*k)).concat([1,1.5,2.1,2.9,3.8].map(k=>lim(-sg*Math.max(mag,base)*k)));let best=null,bs=-Infinity; const cand=[1,1.5,2.1,2.9,3.8].map(k=>lim(sg*mag*k)).concat([1,1.5,2.1,2.9,3.8].map(k=>lim(-sg*Math.max(mag,base)*k)));let best=null,bs=-Infinity;
for(const off of cand){const cx=mx+nx*off,cy=my+ny*off,c=clear(cx,cy);if(c>=need){best=[cx,cy];break;}const sc=Math.min(c,need)-Math.abs(off)*0.35;if(sc>bs){bs=sc;best=[cx,cy];}} for(const off of cand){const cx=mx+nx*off,cy=my+ny*off,c=clear(cx,cy);if(c>=need){best=[cx,cy];break;}const sc=Math.min(c,need)-Math.abs(off)*0.35;if(sc>bs){bs=sc;best=[cx,cy];}}
return {ax:A.x,ay:A.y,bx,by,cx:best[0],cy:best[1],len};}`); return {ax:A.x,ay:A.y,bx,by,cx:best[0],cy:best[1],len};}`);
const bad = JSON.parse(ev(`(()=>{const ids=CITIES.map(c=>c.id),bad=[];for(let i=0;i<ids.length;i+=6)for(let j=i+1;j<ids.length;j+=5)for(const k of [0,1,4]){ const bad = JSON.parse(ev(`(()=>{const ids=CITIES.map(c=>c.id),bad=[];for(let i=0;i<ids.length;i+=12)for(let j=i+1;j<ids.length;j+=10)for(const k of [0,1,4]){
const l={id:'x'+i+'_'+j,a:ids[i],b:ids[j]};if(JSON.stringify(bezGeom(l,k))!==JSON.stringify(plainGeom(l,k)))bad.push(l.a+'-'+l.b+'#'+k);}return JSON.stringify(bad)})()`)); const l={id:'x'+i+'_'+j,a:ids[i],b:ids[j]};if(JSON.stringify(bezGeom(l,k))!==JSON.stringify(plainGeom(l,k)))bad.push(l.a+'-'+l.b+'#'+k);}return JSON.stringify(bad)})()`));
assert.deepEqual(bad, []); assert.deepEqual(bad, []);
assert.deepEqual(errors, []); assert.deepEqual(errors, []);

View file

@ -105,14 +105,3 @@ test('old saves with inbox, max-prefix and Large Peering Model state load and pl
assert.equal(ev('__o.pdeskRep'), null); assert.equal(ev('__o.pdeskRep'), null);
assert.deepEqual(errors, []); assert.deepEqual(errors, []);
}); });
test('max-prefix incidents can no longer fire', () => {
const { ev, errors } = load();
setup(ev);
assert.equal(ev("failureRun.toString().includes('maxpfx')"), false);
ev("S.day=100;const src=failureRun.toString().replace(/^function\* failureRun/,'function*').replace('let tot=opts.reduce',\"opts.splice(0,opts.length,['funny',1]);let tot=opts.reduce\");window.__ff=eval('('+src+')')");
ev("__reseed(7);for(let i=0;i<200;i++){runNow(__ff());S.inc=S.inc.filter(x=>x.type!=='maxpfx'||(window.__mp=1,0));}");
assert.equal(ev('!!window.__mp'), false);
assert.equal(ev("typeof inboxDay+typeof ibx+typeof ACT.inboxRaiseAll+typeof ACT.inboxBot"), 'undefinedundefinedundefinedundefined');
assert.deepEqual(errors, []);
});

View file

@ -127,23 +127,6 @@ test('launches fill crusts, the party is billed, heavy test flights explode', ()
assert.deepEqual(errors, []); assert.deepEqual(errors, []);
}); });
test('O5: launches only fail with chaos on, and never in the first 90 days', () => {
const run = (after) => {
const { ev } = load();
won(ev); company(ev);
ev(`S.day=S.pie.born+${after};Math.random=()=>0`); // the unluckiest dice there are
ev("ACT.pieLaunch({rk:'falcon',cr:'short'});S.pie.q[0].day=S.day;pieDay(S.day)");
return ev("pieLive('short')");
};
assert.equal(run(10), 20, 'quiet days');
assert.equal(run(120), 0, 'chaos can lose a launch');
const { ev } = load();
sandbox(ev);
company(ev);
ev("S.day=500;S.pie.pads[0].next=0;Math.random=()=>0;ACT.pieLaunch({rk:'falcon',cr:'short'});S.pie.q[0].day=S.day;pieDay(S.day)");
assert.equal(ev("pieLive('short')"), 20, 'chaos none: nothing fails');
});
test('cohorts wear out over the end of their life, and a crust carries a share from 40%, all of it from 60%', () => { test('cohorts wear out over the end of their life, and a crust carries a share from 40%, all of it from 60%', () => {
const { ev, errors } = load(); const { ev, errors } = load();
won(ev); won(ev);
@ -186,7 +169,9 @@ test('promises slip a year and get broken', () => {
won(ev); won(ev);
company(ev); company(ev);
assert.equal(ev('S.pie.founder.promises'), 1); assert.equal(ev('S.pie.founder.promises'), 1);
ev('for(let i=0;i<361;i++)dayTick()'); assert.ok(ev('S.pie.founder.due[0]-S.day') >= 359, 'due a year from the promise');
// Then a year passes: rather than play 360 days, the due date moves to tomorrow.
ev('S.pie.founder.due[0]=S.day+1;for(let i=0;i<2;i++)dayTick()');
assert.equal(ev('S.pie.founder.broken'), 1); assert.equal(ev('S.pie.founder.broken'), 1);
assert.ok(ev("S.pie.founder.posts.some(p=>p.k==='pie.fp_slip')")); assert.ok(ev("S.pie.founder.posts.some(p=>p.k==='pie.fp_slip')"));
assert.match(ev('pieFpText(S.pie.founder.posts[0])'), /\w/); assert.match(ev('pieFpText(S.pie.founder.posts[0])'), /\w/);

View file

@ -166,11 +166,6 @@ test('F4: the chaos monkey snips a laser link while it visits, healed within a w
assert.deepEqual(errors, []); assert.deepEqual(errors, []);
}); });
test('the booster that falls over on the drone ship is the foundation\'s', () => {
const { ev } = load();
assert.ok(ev("pieFly.toString().includes('fp_booster')"));
});
test('sanitize drops orbit incidents that make no sense, and old saves are untouched', () => { test('sanitize drops orbit incidents that make no sense, and old saves are untouched', () => {
const { ev, errors } = load(); const { ev, errors } = load();
sky(ev); sky(ev);

View file

@ -1021,7 +1021,8 @@ test('Down Under: routers upside down, BrisVegas, Next-Door-DC and everything tr
assert.match(ev("siteName('bne','b')"), /^Next-Door-DC B[12]$/); assert.match(ev("siteName('bne','b')"), /^Next-Door-DC B[12]$/);
assert.equal(ev("siteName('cbr','b')"), 'Next-Door-DC C1'); assert.equal(ev("siteName('cbr','b')"), 'Next-Door-DC C1');
// everything is trying to kill you: the new outages can come up on Australian links and POPs // everything is trying to kill you: the new outages can come up on Australian links and POPs
const src = ev("document.documentElement.innerHTML"); // (The game's English text, where the outages are written; the page once carried it in its <script>.)
const src = ev("JSON.stringify(I18N.en)");
for (const s of ['drop bear', 'eastern brown snake', 'Magpie swooping', 'Box jellyfish', 'Vegemite as thermal paste', 'brought Marmite', 'four o’clock storm']) assert.ok(src.includes(s), s); for (const s of ['drop bear', 'eastern brown snake', 'Magpie swooping', 'Box jellyfish', 'Vegemite as thermal paste', 'brought Marmite', 'four o’clock storm']) assert.ok(src.includes(s), s);
assert.match(ev("ixName('syd~2')"), /At-The-Edge/); assert.match(ev("XIX.find(x=>x.id==='syd~2').blurb"), /Vegemite/); assert.match(ev("ixName('syd~2')"), /At-The-Edge/); assert.match(ev("XIX.find(x=>x.id==='syd~2').blurb"), /Vegemite/);
ev('cam.z=2;draw(0);cam.z=0.4;draw(0)'); ev('cam.z=2;draw(0);cam.z=0.4;draw(0)');

View file

@ -22,8 +22,10 @@ test('#157 a POP can grow past six routers, with a cage extension', () => {
assert.equal(withCage - without, ev('ROUTER_MO+RG[S.pops.fra.rgen||0].mo+CAGE_MO'), 'the cage extension is billed monthly'); assert.equal(withCage - without, ev('ROUTER_MO+RG[S.pops.fra.rgen||0].mo+CAGE_MO'), 'the cage extension is billed monthly');
ev("S.pops.fra.routers=7;compute()"); ev("S.pops.fra.routers=7;compute()");
assert.ok(ev('nodeCap("fra")') === ev('RG[S.pops.fra.rgen||0].cap*7'), 'every router adds forwarding'); assert.ok(ev('nodeCap("fra")') === ev('RG[S.pops.fra.rgen||0].cap*7'), 'every router adds forwarding');
ev("UI.sel={k:'city',id:'fra'};renderAll()"); // The routers live on the city's Infra tab. (Not the whole body: that once held the game's source, dictionary
assert.match(dom.window.document.body.innerHTML, /Cage extension/); // and all, so a phrase was always found there.)
ev("UI.sel={type:'city',id:'fra'};UI.tab='links';renderAll()");
assert.match(dom.window.document.getElementById('panel').innerHTML, /Cage extension/);
assert.deepEqual(errors, []); assert.deepEqual(errors, []);
}); });