devrock-gametests 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +172 -3
- package/container/Containerfile +12 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +115 -0
- package/dist/commands.d.ts +17 -0
- package/dist/commands.js +304 -0
- package/dist/deploy.d.ts +53 -0
- package/dist/deploy.js +336 -0
- package/dist/game.d.ts +47 -0
- package/dist/game.js +110 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/list-worker.d.ts +1 -0
- package/dist/list-worker.js +6 -0
- package/dist/nbt.d.ts +32 -0
- package/dist/nbt.js +112 -0
- package/dist/outcome.d.ts +31 -0
- package/dist/outcome.js +21 -0
- package/dist/parallel.d.ts +96 -0
- package/dist/parallel.js +190 -0
- package/dist/podman.d.ts +40 -0
- package/dist/podman.js +201 -0
- package/dist/preflight.d.ts +30 -0
- package/dist/preflight.js +71 -0
- package/dist/project.d.ts +43 -0
- package/dist/project.js +204 -0
- package/dist/registrations.d.ts +38 -0
- package/dist/registrations.js +194 -0
- package/dist/report.d.ts +87 -0
- package/dist/report.js +243 -0
- package/dist/server.d.ts +45 -0
- package/dist/server.js +157 -0
- package/dist/shared.d.ts +23 -0
- package/dist/shared.js +19 -0
- package/dist/world.d.ts +10 -0
- package/dist/world.js +30 -0
- package/package.json +47 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 KingFX
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,172 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# devrock-gametests
|
|
2
|
+
|
|
3
|
+
Run the GameTests of a Minecraft Bedrock add-on on the Linux Bedrock Dedicated Server (BDS). Each server runs in a Podman container with no network, and a full run splits the tests across several servers at once. A run fails when a test fails, or when the server's content log has a warning or an error.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Podman. On Windows and macOS, you also need a Podman machine. Run `devrock-gametests check` to see what is missing.
|
|
8
|
+
- An x86-64 processor. BDS runs only on x86-64.
|
|
9
|
+
- Node.js 22.15 or later.
|
|
10
|
+
|
|
11
|
+
On a Linux host with SELinux on, such as Fedora or RHEL, each server container turns SELinux label checks off for itself with `--security-opt label=disable`, so it can read the run folder the runner writes. It changes nothing on a host without SELinux.
|
|
12
|
+
|
|
13
|
+
The first run builds a container image for the server version and downloads BDS into it. When you use BDS, you agree to the [Minecraft End User License Agreement](https://www.minecraft.net/eula) and the [Microsoft Privacy Policy](https://go.microsoft.com/fwlink/?LinkId=521839). Only the image build uses the network. Every server container runs with `--network none`.
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
npm install --save-dev devrock-gametests @minecraft/server @minecraft/server-gametest
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Your tests import `@minecraft/server` and `@minecraft/server-gametest`, and the runner reads their type definitions to list the tests before a run. Any version works, beta versions included. Pick the versions that match your server version, such as `@minecraft/server-gametest@1.0.0-beta.1.26.66-stable` for BDS 1.26.66.
|
|
22
|
+
|
|
23
|
+
Add `.devrock-gametests/` to your `.gitignore`. The runner keeps its downloads, the template world, the run folders, and the logs there.
|
|
24
|
+
|
|
25
|
+
## Configure a project
|
|
26
|
+
|
|
27
|
+
The runner reads two files in the project root.
|
|
28
|
+
|
|
29
|
+
`.devrock/project.json` names the add-on. The runner reads these fields and ignores any others:
|
|
30
|
+
|
|
31
|
+
| Field | Meaning |
|
|
32
|
+
|---|---|
|
|
33
|
+
| `namespace` | The add-on's namespace, without the colon: letters, digits, underscores, dots, and hyphens. A content-log line that contains `<namespace>:` belongs to the add-on. |
|
|
34
|
+
| `behavior_pack` | The behavior pack folder. Its name can't be `<namespace>_test_bp` in any letter case, which is the name the test pack gets in the world. |
|
|
35
|
+
| `resource_pack` | The resource pack folder. |
|
|
36
|
+
|
|
37
|
+
`.devrock/gametests.json` says how to build and run the tests. Every field is required.
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"serverVersion": "1.26.66.1",
|
|
42
|
+
"entry": "gametests/main.ts",
|
|
43
|
+
"build": ["node", "esbuild.config.mjs", "--debug"],
|
|
44
|
+
"testPack": "gametests/pack",
|
|
45
|
+
"define": { "DEBUG": "true" }
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
| Field | Meaning |
|
|
50
|
+
|---|---|
|
|
51
|
+
| `serverVersion` | The BDS version that the tests run on. |
|
|
52
|
+
| `entry` | The GameTest entry file. The runner bundles it with esbuild into the test pack's `scripts/main.js`. |
|
|
53
|
+
| `build` | The command that builds the add-on into its packs, as an array of the program and its arguments. It runs in the project root without a shell, so on Windows use `node`, not `npm`. |
|
|
54
|
+
| `testPack` | The folder with the test pack's `manifest.json` and any other files the pack needs, such as test entities. The manifest needs a script module with the entry `scripts/main.js`, and dependencies on `@minecraft/server` and `@minecraft/server-gametest`, each with a version. The header uuids of the behavior pack, the resource pack, and the test pack must all differ. |
|
|
55
|
+
| `define` | The esbuild `define` values for the entry. Use them for the build flags that the entry and the add-on's scripts read. |
|
|
56
|
+
|
|
57
|
+
When a field is missing or wrong, the run stops with a message that names the file and the field. The same goes for the `header` of each pack's `manifest.json`, where the runner reads `name`, `uuid`, and `version`. The `version` is a semantic version such as `"1.0.0"` or `"1.0.0-beta.1"`, or an array such as `[1, 0, 0]`. The server lets packs use the script modules stock BDS allows: `@minecraft/server`, `server-ui`, `server-gametest`, `server-admin`, `server-editor`, and `debug-utilities`. The runner checks the pack folders when it reads the config, before the `build` command runs, so each pack folder and its `manifest.json` must exist before the build.
|
|
58
|
+
|
|
59
|
+
## Write a test
|
|
60
|
+
|
|
61
|
+
Register each test with `TEST_TAG` and `PLOT_STRUCTURE` from `devrock-gametests/game`:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import { registerAsync } from '@minecraft/server-gametest';
|
|
65
|
+
import { PLOT_STRUCTURE, TEST_TAG } from 'devrock-gametests/game';
|
|
66
|
+
|
|
67
|
+
registerAsync('my_class', 'my_test', async (test) => {
|
|
68
|
+
test.succeed();
|
|
69
|
+
})
|
|
70
|
+
.structureName(PLOT_STRUCTURE)
|
|
71
|
+
.tag(TEST_TAG);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Give each test an id of its own. A test id is `class:name`, and neither half can have an ASCII space, a control character, or a colon. GameTest matches ids in any letter case and runs only one test per id, so when two tests share an id, even in different letter case, the test pack prints a warning, and the warning fails the run. A batch name can't have a line break, for the same reason.
|
|
75
|
+
|
|
76
|
+
Register tests while the scripts load: at the top level of a module, after a top-level `await`, or in a `system.beforeEvents.startup` callback. A test registered on a later tick, such as in `system.run`, may not run at all. On BDS 1.26.66.1 the engine ran one beside tests registered while the scripts loaded, and found no test when it was the only one.
|
|
77
|
+
|
|
78
|
+
If a test has a batch, call `.batch()` before `.tag(TEST_TAG)`. A full run decides which server runs the test when it tags itself, so a batch set after the tag can't keep the test with its batch. The test pack prints a warning that names the test, and the warning fails the run. A named run runs on one server, so it doesn't mind the order.
|
|
79
|
+
|
|
80
|
+
The runner gives tests the tags `devrock_gametests_named` and `devrock_gametests_elsewhere` itself. A test that tags itself with one of them gets a warning, which fails the run, and doesn't get the tag.
|
|
81
|
+
|
|
82
|
+
A test can use `maxAttempts`, `requiredSuccessfulAttempts`, and `rotateTest`. The engine prints a verdict for each attempt and each rotation. A test passes only if every one of them passed, so a failed attempt fails the test even when a later attempt passes.
|
|
83
|
+
|
|
84
|
+
`PLOT_STRUCTURE` is a stone floor with air above it, `PLOT_SIZE` blocks in size. The runner writes the structure into the test pack, so your project needs no structure files. In test coordinates, (0, 1, 0) is the block above the structure block. Put blocks and mobs at y=2 or higher.
|
|
85
|
+
|
|
86
|
+
`devrock-gametests/game` also exports helpers for tests that need more than their plot:
|
|
87
|
+
|
|
88
|
+
| Export | What it does |
|
|
89
|
+
|---|---|
|
|
90
|
+
| `waitUntil(test, predicate, maxTicks)` | Checks `predicate` once a tick. Returns true when it holds, or false if it still doesn't once `maxTicks` have passed. |
|
|
91
|
+
| `registerFarAreaTest(className, testName, x, body, radius = 8)` | Registers a test that unloads and reloads chunks. The test gets a batch of its own and a `FarArea` centred on (x, x), outside the test area. `FarArea.load()` adds a ticking area and waits for its chunks. The ticking area is removed when the test ends. |
|
|
92
|
+
| `addTickingArea(dimension, name, add)` | Calls `add` until it adds a ticking area. Between tries, it frees the ticking areas of finished tests, because Bedrock allows only 10. |
|
|
93
|
+
|
|
94
|
+
The runner keeps x and z from 0 to `TEST_AREA_END` loaded for the test plots. Put anything that a test loads or unloads itself beyond `TEST_AREA_END`.
|
|
95
|
+
|
|
96
|
+
## Commands
|
|
97
|
+
|
|
98
|
+
Run each command from the project root. Each command checks Podman first.
|
|
99
|
+
|
|
100
|
+
| Command | What it does |
|
|
101
|
+
|---|---|
|
|
102
|
+
| `devrock-gametests check` | Checks that Podman can run the GameTests and answers on its connection. Starts the Podman machine if it is stopped. |
|
|
103
|
+
| `devrock-gametests run [--containers <n>] [--verbose]` | Runs every test tagged `TEST_TAG` across several servers at once, and checks the content log. `--containers` sets the number of servers: 8 by default, or fewer when Podman has less than about 5 GiB of memory. `--verbose` prints the output of every server as it arrives, with the server's number at the start of each line. |
|
|
104
|
+
| `devrock-gametests run <class:test>...` | Runs the named tests on one server, and checks the content log. It matches each id in any letter case, gives the tests it finds the tag `devrock_gametests_named`, and runs them with `/gametest runset`, so every attempt, rotation, and batch runs as in a full run. A test id that the game doesn't have fails. |
|
|
105
|
+
| `devrock-gametests console [--settle <ms>] "<command>"...` | Sends console commands to a fresh server and prints the answers. A `"wait <ms>"` argument pauses instead of sending a command. `--settle` sets how long to wait after the last command before the server stops. The default is 2000 ms. |
|
|
106
|
+
|
|
107
|
+
Each server gets 20 minutes for its tests, in a full run and in a named run. A test still running after that fails.
|
|
108
|
+
|
|
109
|
+
The exit code is 0 when everything passed and 1 when a test or the content log failed. It is 2 when there is no result, for example after a usage error, a config error, a Podman problem, or a server that never ran the tests. When one server gives no result and another has a failure, the exit code is 2, because the run is incomplete. The output still lists every failure.
|
|
110
|
+
|
|
111
|
+
To build the image from a Linux BDS zip that you downloaded yourself, set `BDS_ZIP=<path>`.
|
|
112
|
+
|
|
113
|
+
To run the tests with `npm run test:minecraft`, add the command to `package.json`:
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
"scripts": {
|
|
117
|
+
"test:minecraft": "devrock-gametests run"
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## How a run works
|
|
122
|
+
|
|
123
|
+
1. The runner builds the image `localhost/devrock-gametests-bds:<serverVersion>` if Podman does not have it.
|
|
124
|
+
2. It makes a template world for the version if `.devrock-gametests/template/<serverVersion>/level.dat` does not exist. It starts a server once, stops it, and turns on Beta APIs in `level.dat`. To make the template again, delete that file.
|
|
125
|
+
3. It runs the project's `build` command once, and checks that the behavior pack's script entry exists. Then it makes a new run folder for each server in `.devrock-gametests/run/<n>/`, with `server.properties`, `config/`, and a world that has the template's `level.dat`, copies of the add-on packs, and the test pack. The copy of the behavior pack gets a small script, `devrock_gametests_console.js` or the first free `devrock_gametests_console_<n>.js`, that its script entry imports first. Your packs don't change.
|
|
126
|
+
4. It starts each server in a container that mounts the server's run folder, sends the test commands, and stops the server. Podman removes the container when the server stops.
|
|
127
|
+
|
|
128
|
+
The runner removes its containers at once when it stops on Ctrl+C, Ctrl+Break, a closed terminal, or a crash. If something kills the runner outright, its Podman client dies with it. The server's console input then closes, the container sends the server `stop`, and Podman removes the container after the server stops. A kill that lands while Podman is still starting a container can leave it stopped but not removed, and a server stuck in a script never reads its `stop`. So each run first removes the runner containers that were started on the same machine and process namespace as it, and whose runner process is gone. A container started by a runner on another machine that shares the same Podman service is never touched.
|
|
129
|
+
|
|
130
|
+
The full output of each server is in `.devrock-gametests/logs/`, one file for each server.
|
|
131
|
+
|
|
132
|
+
Only one run at a time can use a project's run folders.
|
|
133
|
+
|
|
134
|
+
### How `run` splits the tests
|
|
135
|
+
|
|
136
|
+
After the build and before it starts a server, `run` lists the tests that the entry registers, without the game. If the listing fails, for example because the entry awaits something only the game settles, the run says so and runs every test on one server, so it can't split them but still checks every result. The listing gets 30 seconds. It groups the tests tagged `TEST_TAG` by GameTest batch. The tests with no batch name form one batch. A batch is never split, because the engine runs a batch's tests at the same time, and a test that changes the whole world, such as the weather, needs a batch of its own.
|
|
137
|
+
|
|
138
|
+
`run` gives out the batches longest first. Each batch goes to the server with the least time so far. A batch's time is what it took in the last full run, kept in `.devrock-gametests/batch-seconds.json`. Before any run has measured the batch, its time is its longest `maxTicks`.
|
|
139
|
+
|
|
140
|
+
The runner bundles a separate test pack for each server, which knows which server runs each batch. When a test tags itself `TEST_TAG`, the test pack keeps that tag only on the server that runs the test's batch. On every other server, the test gets the tag `devrock_gametests_elsewhere`, so `/gametest runset` there skips it. Each server's test pack prints the id of each test it registers, each test it keeps, and each test it skips. The runner checks each server's results against the tests it kept, and checks that the servers agree. Your test source doesn't change.
|
|
141
|
+
|
|
142
|
+
The listing runs your entry outside the game, with stand-ins for the game's modules, so it can miss a test or get a name wrong. For example, it misses a test registered in a loop over a game enum, in a startup callback, or behind a value only the game knows. The game decides what runs, not the listing. A test the listing missed runs with its batch, or on server 1 if the listing found no test in that batch. The summary names the tests the listing missed and the names it found that the game never registered. To let a run time and split every batch, register each test unconditionally at the top level of a module.
|
|
143
|
+
|
|
144
|
+
Each server's test pack decides on its own, so a project whose tests register differently on each server, for example in a different batch or under a random name, can split a batch or run a test twice. The run then fails, and names the test or batch.
|
|
145
|
+
|
|
146
|
+
A full run takes at least as long as its longest batch, plus about 7 seconds to start and stop a server. In one measured run, 117 tests in 71 batches took 129 s on 8 servers and 834 s on one server. The longest batch took 121 s, and each server used about 350 MiB of memory.
|
|
147
|
+
|
|
148
|
+
### What fails a run
|
|
149
|
+
|
|
150
|
+
The run fails if any server has a failed test, a content-log line that is not harmless, an unclean stop, a test that never finished, or a test that it was not given. The runner merges the results after every server has stopped, and each failure names its server. The summary lists each server's tests, its expected and measured time, and its log.
|
|
151
|
+
|
|
152
|
+
A content-log line is harmless if it is at INFO level, or if it is a line that BDS prints in clean runs. Before the first test starts, each server waits for the test area's chunks to load. The probe that checks them prints `Cannot access blocks outside of the world`, and that line passes only while the probe runs. At any other time, the same line fails the run. When no test has `TEST_TAG`, the two lines the engine prints to say so pass too.
|
|
153
|
+
|
|
154
|
+
A full run and a named run both wait until each test has failed an attempt or passed as many as it needs, and no test has an attempt or rotation left open. The test pack tells the runner how many passes each test needs, from the last values it gave `requiredSuccessfulAttempts` and `rotateTest`. A rotated test needs that many passes in each of its 4 rotations. A test short of them never passes: it fails with the number it passed. The engine loads a test's next attempt just after the last attempt's verdict, about 150 ms later on BDS 1.26.66.1, so the runner treats a run as finished once it has looked complete for 1 second. A failed attempt also fails the content log.
|
|
155
|
+
|
|
156
|
+
BDS prints each argument of a `console` call or `print` as `String(argument)`, and each line after a line break on its own, with no level. To keep those lines from looking like the engine's own lines, the test pack and the copy of the behavior pack patch `console` and `print`. The patch starts each of those lines with ` | `, and the runner reads such a line as part of the message before it.
|
|
157
|
+
|
|
158
|
+
A full run in which no test ran fails when it should have run some: when the listing found tests but no server's test pack kept any, when the listing or the game found tests but none has `TEST_TAG`, and when the listing failed and the game registered no test with `TEST_TAG`. It fails, too, if a server reported fewer verdicts than the engine announced tests. A verdict that arrives after a server's 20-minute deadline doesn't count.
|
|
159
|
+
|
|
160
|
+
## Other exports
|
|
161
|
+
|
|
162
|
+
The package root, `devrock-gametests`, exports the runner's parts: the content-log report parser, the Podman check, and the test listing. The package is at version 0.x, so these exports can change in any release.
|
|
163
|
+
|
|
164
|
+
## Develop
|
|
165
|
+
|
|
166
|
+
- `npm test` runs the unit tests.
|
|
167
|
+
- `npm run typecheck`, `npm run lint`, and `npm run build` type-check, lint, and build the package.
|
|
168
|
+
- `npm run test:live` builds the package and runs the CLI against `test/fixtures/project` in Podman.
|
|
169
|
+
|
|
170
|
+
## License
|
|
171
|
+
|
|
172
|
+
MIT
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# The Linux Bedrock Dedicated Server. The runner puts the server zip next to this file, mounts the world,
|
|
2
|
+
# server.properties and config at run time, and runs the container with no network.
|
|
3
|
+
FROM docker.io/library/ubuntu:24.04
|
|
4
|
+
RUN apt-get update \
|
|
5
|
+
&& apt-get install -y --no-install-recommends libcurl4 ca-certificates unzip \
|
|
6
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
7
|
+
COPY bedrock-server.zip /tmp/
|
|
8
|
+
RUN unzip -q /tmp/bedrock-server.zip -d /bds && rm /tmp/bedrock-server.zip && chmod +x /bds/bedrock_server
|
|
9
|
+
WORKDIR /bds
|
|
10
|
+
# The server loads its bundled libraries from its own folder.
|
|
11
|
+
ENV LD_LIBRARY_PATH=.
|
|
12
|
+
ENTRYPOINT ["./bedrock_server"]
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { parseArgs } from 'node:util';
|
|
3
|
+
import { runAll, runConsole, runNamed } from './commands.js';
|
|
4
|
+
import { defaultContainers, MAX_DEFAULT_CONTAINERS } from './parallel.js';
|
|
5
|
+
import { podmanMemory } from './podman.js';
|
|
6
|
+
import { nodeHost, preflight } from './preflight.js';
|
|
7
|
+
import { loadProject } from './project.js';
|
|
8
|
+
import { TEST_ID } from './report.js';
|
|
9
|
+
const USAGE = `Usage: devrock-gametests <command>
|
|
10
|
+
|
|
11
|
+
Commands:
|
|
12
|
+
check Check that Podman can run the GameTests, and start its machine if it is stopped.
|
|
13
|
+
run [--containers <n>] [--verbose] Run every GameTest and check the content log, split by batch across n
|
|
14
|
+
containers at once: ${MAX_DEFAULT_CONTAINERS}, or fewer if Podman has too little
|
|
15
|
+
memory for that many.
|
|
16
|
+
run <class:test> [<class:test>...] Run the named GameTests, in any letter case, on one server with runset, and
|
|
17
|
+
check the content log.
|
|
18
|
+
console [--settle <ms>] <command>...
|
|
19
|
+
Send console commands to a fresh server and print what it answers.
|
|
20
|
+
A "wait <ms>" command pauses instead. --settle waits after the last one (2000).
|
|
21
|
+
|
|
22
|
+
Exit codes: 0 everything passed, 1 a test or the content log failed, 2 no result.`;
|
|
23
|
+
const TEST_ID_RE = new RegExp(`^${TEST_ID}$`);
|
|
24
|
+
const DEFAULT_SETTLE_MS = 2000;
|
|
25
|
+
function check() {
|
|
26
|
+
let result;
|
|
27
|
+
try {
|
|
28
|
+
result = preflight(nodeHost);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
console.error(`Can't run the GameTests: the Podman check failed unexpectedly.\n${error.message}`);
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
if (result.kind === 'blocked') {
|
|
35
|
+
console.error(result.message);
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
/** Parses the arguments into the command to run, which returns its exit code. Throws on a usage error. */
|
|
41
|
+
function command(args) {
|
|
42
|
+
const { values, positionals } = parseArgs({
|
|
43
|
+
args,
|
|
44
|
+
allowPositionals: true,
|
|
45
|
+
options: { verbose: { type: 'boolean' }, settle: { type: 'string' }, containers: { type: 'string' } },
|
|
46
|
+
});
|
|
47
|
+
const [name, ...rest] = positionals;
|
|
48
|
+
const only = (option, allowed) => {
|
|
49
|
+
if (values[option] !== undefined && !allowed)
|
|
50
|
+
throw new Error(`--${option} doesn't apply here.`);
|
|
51
|
+
};
|
|
52
|
+
if (name === 'check' && rest.length === 0) {
|
|
53
|
+
only('verbose', false);
|
|
54
|
+
only('settle', false);
|
|
55
|
+
only('containers', false);
|
|
56
|
+
return async () => {
|
|
57
|
+
if (!check())
|
|
58
|
+
return 2;
|
|
59
|
+
console.log('Podman is ready to run the GameTests.');
|
|
60
|
+
return 0;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
if (name === 'run') {
|
|
64
|
+
only('settle', false);
|
|
65
|
+
only('verbose', rest.length === 0);
|
|
66
|
+
only('containers', rest.length === 0);
|
|
67
|
+
const containers = values.containers;
|
|
68
|
+
if (containers !== undefined && !/^[1-9][0-9]*$/.test(containers)) {
|
|
69
|
+
throw new Error('--containers needs a whole number of containers, 1 or more.');
|
|
70
|
+
}
|
|
71
|
+
const bad = rest.find((test) => !TEST_ID_RE.test(test));
|
|
72
|
+
if (bad !== undefined)
|
|
73
|
+
throw new Error(`"${bad}" isn't a test id like my_class:my_test.`);
|
|
74
|
+
return withProject((project) => rest.length === 0
|
|
75
|
+
? runAll(project, values.verbose ?? false, Number(containers ?? defaultContainers(podmanMemory())))
|
|
76
|
+
: runNamed(project, rest));
|
|
77
|
+
}
|
|
78
|
+
if (name === 'console') {
|
|
79
|
+
only('verbose', false);
|
|
80
|
+
only('containers', false);
|
|
81
|
+
const settle = values.settle ?? String(DEFAULT_SETTLE_MS);
|
|
82
|
+
if (!/^\d+$/.test(settle))
|
|
83
|
+
throw new Error('--settle needs a whole number of milliseconds.');
|
|
84
|
+
if (rest.length === 0)
|
|
85
|
+
throw new Error('console needs at least one command.');
|
|
86
|
+
return withProject((project) => runConsole(project, rest, Number(settle)));
|
|
87
|
+
}
|
|
88
|
+
throw new Error(name === undefined ? 'No command given.' : `Unknown command "${positionals.join(' ')}".`);
|
|
89
|
+
}
|
|
90
|
+
/** Runs the Podman check, then reads the project in the working directory and hands it to `run`. */
|
|
91
|
+
function withProject(run) {
|
|
92
|
+
return async () => {
|
|
93
|
+
if (!check())
|
|
94
|
+
return 2;
|
|
95
|
+
return run(loadProject(process.cwd()));
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
async function main(args) {
|
|
99
|
+
let run;
|
|
100
|
+
try {
|
|
101
|
+
run = command(args);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
console.error(`${error.message}\n\n${USAGE}`);
|
|
105
|
+
return 2;
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
return await run();
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
console.error(`[devrock-gametests] ${error.message}`);
|
|
112
|
+
return 2;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
process.exitCode = await main(process.argv.slice(2));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Project } from './project.js';
|
|
2
|
+
/**
|
|
3
|
+
* Runs every test tagged TEST_TAG, split by whole batch across up to `containers` containers that run at the same
|
|
4
|
+
* time. Returns 0 if everything passed, 1 if a test, the content log or a container failed, and 2 if a container
|
|
5
|
+
* gave no result.
|
|
6
|
+
*/
|
|
7
|
+
export declare function runAll(project: Project, verbose: boolean, containers: number): Promise<number>;
|
|
8
|
+
/**
|
|
9
|
+
* Runs the named tests, in any letter case, on one server with the same `runset` a full run uses, so every attempt,
|
|
10
|
+
* rotation and batch runs as it would there. Returns like `runAll`, and fails a name the game has no test for.
|
|
11
|
+
*/
|
|
12
|
+
export declare function runNamed(project: Project, ids: readonly string[]): Promise<number>;
|
|
13
|
+
/**
|
|
14
|
+
* Sends console commands to a fresh server and prints what it answered. A `wait <ms>` command pauses here instead
|
|
15
|
+
* of being sent. Waits `settleMs` after the last one before it stops the server.
|
|
16
|
+
*/
|
|
17
|
+
export declare function runConsole(project: Project, commands: readonly string[], settleMs: number): Promise<number>;
|