mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 23:53:13 +09:00
Compare commits
37
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2121bcd7a | ||
|
|
464baabf96 | ||
|
|
dd20054151 | ||
|
|
dbedc4bc08 | ||
|
|
bf33f4f52e | ||
|
|
a845b7ac52 | ||
|
|
eefb4be44b | ||
|
|
b8e96989af | ||
|
|
e814309750 | ||
|
|
d42d9d3743 | ||
|
|
c2e08540d0 | ||
|
|
62f17a20af | ||
|
|
8374e4e3cd | ||
|
|
5aaea1f213 | ||
|
|
35f9609865 | ||
|
|
710bf8b636 | ||
|
|
211180a801 | ||
|
|
bb6ce06e5a | ||
|
|
6363f15cb9 | ||
|
|
838a43428b | ||
|
|
5cf14eb15b | ||
|
|
adc92fbdb0 | ||
|
|
dbe56638f9 | ||
|
|
cd7c850a16 | ||
|
|
3d1ca99027 | ||
|
|
89f966bb68 | ||
|
|
42e2e0284b | ||
|
|
c2c7edf1b7 | ||
|
|
09d79d775f | ||
|
|
c6bc81b0df | ||
|
|
8acb54985c | ||
|
|
ec2bc6504b | ||
|
|
154ebe294a | ||
|
|
a0c42225a4 | ||
|
|
a959ff25a4 | ||
|
|
0b0e2fd377 | ||
|
|
b6bc118297 |
No files matched your search
@@ -0,0 +1,30 @@
|
|||||||
|
name: Changelog
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types: [opened, edited, synchronize, reopened]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
check:
|
||||||
|
# Bot pull requests do not fill in the template.
|
||||||
|
if: github.event.pull_request.user.type != 'Bot'
|
||||||
|
runs-on: blacksmith-4vcpu-ubuntu-2604
|
||||||
|
timeout-minutes: 5
|
||||||
|
steps:
|
||||||
|
- uses: useblacksmith/checkout@v1
|
||||||
|
with:
|
||||||
|
sparse-checkout: scripts
|
||||||
|
- uses: actions/setup-node@v7
|
||||||
|
with:
|
||||||
|
node-version: 24.x
|
||||||
|
- name: Check changelog in pull request description
|
||||||
|
env:
|
||||||
|
PR_BODY: ${{ github.event.pull_request.body }}
|
||||||
|
run: node scripts/check_pr_changelog.mts
|
||||||
@@ -15,14 +15,14 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
changes:
|
changes:
|
||||||
runs-on: ubuntu-latest
|
runs-on: blacksmith-4vcpu-ubuntu-2604
|
||||||
timeout-minutes: 5
|
timeout-minutes: 5
|
||||||
outputs:
|
outputs:
|
||||||
build_and_test: ${{ steps.syntax.outputs.build_and_test || steps.paths.outputs.code }}
|
build_and_test: ${{ steps.syntax.outputs.build_and_test || steps.paths.outputs.code }}
|
||||||
js_lint: ${{ steps.lint.outputs.js_lint }}
|
js_lint: ${{ steps.lint.outputs.js_lint }}
|
||||||
lua_lint: ${{ steps.lint.outputs.lua_lint }}
|
lua_lint: ${{ steps.lint.outputs.lua_lint }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: useblacksmith/checkout@v1
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- uses: dorny/paths-filter@v4
|
- uses: dorny/paths-filter@v4
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ jobs:
|
|||||||
lint:
|
lint:
|
||||||
needs: changes
|
needs: changes
|
||||||
if: ${{ !cancelled() && needs.changes.outputs.lua_lint != 'false' }}
|
if: ${{ !cancelled() && needs.changes.outputs.lua_lint != 'false' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: blacksmith-4vcpu-ubuntu-2604
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: useblacksmith/checkout@v1
|
||||||
- uses: actions/setup-node@v7
|
- uses: actions/setup-node@v7
|
||||||
with:
|
with:
|
||||||
node-version: lts/*
|
node-version: lts/*
|
||||||
|
|||||||
@@ -23,15 +23,15 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
needs: changes
|
needs: changes
|
||||||
if: ${{ !cancelled() && needs.changes.outputs.build_and_test != 'false' }}
|
if: ${{ !cancelled() && needs.changes.outputs.build_and_test != 'false' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: blacksmith-4vcpu-ubuntu-2604
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
# To stay within the concurrent job limit, every Factorio version is
|
# To stay within the concurrent job limit, every Factorio version is
|
||||||
# tested on the latest Node.js, and every other supported Node.js
|
# tested on the latest Node.js, and the oldest supported Node.js only
|
||||||
# version only with the latest Factorio. Coverage is performed on the
|
# with the latest Factorio. Versions in between are not tested.
|
||||||
# oldest supported Node.js.
|
# Coverage is performed on the oldest supported Node.js.
|
||||||
# Node.js release schedule: https://nodejs.org/en/about/releases/
|
# Node.js release schedule: https://nodejs.org/en/about/releases/
|
||||||
# Supported factorio versions are latest stable and one minor version before stable (even if from a previous major)
|
# Supported factorio versions are latest stable and one minor version before stable (even if from a previous major)
|
||||||
node-version: [26.x]
|
node-version: [26.x]
|
||||||
@@ -42,12 +42,6 @@ jobs:
|
|||||||
tests: [ctl, other]
|
tests: [ctl, other]
|
||||||
|
|
||||||
include:
|
include:
|
||||||
- node-version: 24.x
|
|
||||||
factorio-version: 2.1.17
|
|
||||||
tests: ctl
|
|
||||||
- node-version: 24.x
|
|
||||||
factorio-version: 2.1.17
|
|
||||||
tests: other
|
|
||||||
- node-version: 22.x
|
- node-version: 22.x
|
||||||
factorio-version: 2.1.17
|
factorio-version: 2.1.17
|
||||||
tests: ctl
|
tests: ctl
|
||||||
@@ -67,9 +61,15 @@ jobs:
|
|||||||
run: wget -q -O factorio.tar.gz https://www.factorio.com/get-download/${{ matrix.factorio-version }}/headless/linux64 && tar -xf factorio.tar.gz && rm factorio.tar.gz
|
run: wget -q -O factorio.tar.gz https://www.factorio.com/get-download/${{ matrix.factorio-version }}/headless/linux64 && tar -xf factorio.tar.gz && rm factorio.tar.gz
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
if: ${{ !matrix.coverage }}
|
if: ${{ !matrix.coverage }}
|
||||||
|
env:
|
||||||
|
# Re-run with debug logging to see output from passing tests
|
||||||
|
TEST_OUTPUT: ${{ runner.debug == '1' && 'verbose' || 'normal' }}
|
||||||
run: pnpm test --grep "^(Integration of Clusterio (clusterioctl|plugin system)|Clusterio Instance) " ${{ matrix.tests == 'other' && '--invert' || '' }}
|
run: pnpm test --grep "^(Integration of Clusterio (clusterioctl|plugin system)|Clusterio Instance) " ${{ matrix.tests == 'other' && '--invert' || '' }}
|
||||||
- name: Run coverage
|
- name: Run coverage
|
||||||
if: ${{ matrix.coverage }}
|
if: ${{ matrix.coverage }}
|
||||||
|
env:
|
||||||
|
# Re-run with debug logging to see output from passing tests
|
||||||
|
TEST_OUTPUT: ${{ runner.debug == '1' && 'verbose' || 'normal' }}
|
||||||
run: pnpm run ci-cover --grep "^(Integration of Clusterio (clusterioctl|plugin system)|Clusterio Instance) " ${{ matrix.tests == 'other' && '--invert' || '' }}
|
run: pnpm run ci-cover --grep "^(Integration of Clusterio (clusterioctl|plugin system)|Clusterio Instance) " ${{ matrix.tests == 'other' && '--invert' || '' }}
|
||||||
- name: Upload coverage to Codecov
|
- name: Upload coverage to Codecov
|
||||||
if: ${{ matrix.coverage }}
|
if: ${{ matrix.coverage }}
|
||||||
@@ -89,7 +89,7 @@ jobs:
|
|||||||
version-compat:
|
version-compat:
|
||||||
needs: changes
|
needs: changes
|
||||||
if: ${{ !cancelled() && needs.changes.outputs.build_and_test != 'false' }}
|
if: ${{ !cancelled() && needs.changes.outputs.build_and_test != 'false' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: blacksmith-4vcpu-ubuntu-2604
|
||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
env:
|
env:
|
||||||
# npm version spec for the published side of the compatibility test.
|
# npm version spec for the published side of the compatibility test.
|
||||||
@@ -121,7 +121,7 @@ jobs:
|
|||||||
lint:
|
lint:
|
||||||
needs: changes
|
needs: changes
|
||||||
if: ${{ !cancelled() && needs.changes.outputs.js_lint != 'false' }}
|
if: ${{ !cancelled() && needs.changes.outputs.js_lint != 'false' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: blacksmith-4vcpu-ubuntu-2604
|
||||||
timeout-minutes: 5
|
timeout-minutes: 5
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: actions/checkout@v7
|
||||||
@@ -134,7 +134,7 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
needs: changes
|
needs: changes
|
||||||
if: ${{ !cancelled() && needs.changes.outputs.build_and_test != 'false' }}
|
if: ${{ !cancelled() && needs.changes.outputs.build_and_test != 'false' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: blacksmith-4vcpu-ubuntu-2604
|
||||||
timeout-minutes: 5
|
timeout-minutes: 5
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: actions/checkout@v7
|
||||||
|
|||||||
@@ -12,10 +12,10 @@ permissions:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
npm:
|
npm:
|
||||||
runs-on: ubuntu-latest
|
runs-on: blacksmith-4vcpu-ubuntu-2604
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: useblacksmith/checkout@v1
|
||||||
- uses: pnpm/action-setup@v6
|
- uses: pnpm/action-setup@v6
|
||||||
- uses: actions/setup-node@v7
|
- uses: actions/setup-node@v7
|
||||||
with:
|
with:
|
||||||
@@ -30,10 +30,10 @@ jobs:
|
|||||||
files: pnpm-lock.yaml
|
files: pnpm-lock.yaml
|
||||||
|
|
||||||
factorio:
|
factorio:
|
||||||
runs-on: ubuntu-latest
|
runs-on: blacksmith-4vcpu-ubuntu-2604
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v7
|
- uses: useblacksmith/checkout@v1
|
||||||
- uses: pnpm/action-setup@v6
|
- uses: pnpm/action-setup@v6
|
||||||
- uses: actions/setup-node@v7
|
- uses: actions/setup-node@v7
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -31,6 +31,13 @@ Many thanks to the following for contributing to this release:
|
|||||||
[@username](https://github.com/username)
|
[@username](https://github.com/username)
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
### Fixes
|
||||||
|
|
||||||
|
- Fixed cramped plugin rows and wrapping header branding on mobile screens.
|
||||||
|
|
||||||
|
|
||||||
## Version 2.1.0
|
## Version 2.1.0
|
||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|||||||
+3
-1
@@ -11,7 +11,9 @@ RUN apt update \
|
|||||||
&& apt install -y wget \
|
&& apt install -y wget \
|
||||||
&& mkdir /clusterio
|
&& mkdir /clusterio
|
||||||
WORKDIR /clusterio
|
WORKDIR /clusterio
|
||||||
RUN wget -q -O factorio.tar.gz https://www.factorio.com/get-download/latest/headless/linux64 && tar -xf factorio.tar.gz && rm factorio.tar.gz
|
ARG TARGETARCH
|
||||||
|
RUN if [ "$TARGETARCH" = "arm64" ]; then build=linux-arm64; else build=linux64; fi \
|
||||||
|
&& wget -q -O factorio.tar.gz https://www.factorio.com/get-download/latest/headless/$build && tar -xf factorio.tar.gz && rm factorio.tar.gz
|
||||||
# Copy project files into the container
|
# Copy project files into the container
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
|||||||
@@ -129,6 +129,10 @@ Check out all our of decisions for [node, factorio, and operation support](/docs
|
|||||||
|
|
||||||
3. Optionally copy the generated systemd service files in `systemd` folder to `/etc/systemd/system/`.
|
3. Optionally copy the generated systemd service files in `systemd` folder to `/etc/systemd/system/`.
|
||||||
|
|
||||||
|
Hosts on Linux download the headless build of Factorio as needed.
|
||||||
|
On ARM64 (aarch64) Linux this only works for Factorio 2.1.18 and later, which is the first version Factorio published an ARM64 headless build for.
|
||||||
|
Older versions have to be installed manually, for example the x64 build run through an emulator.
|
||||||
|
|
||||||
|
|
||||||
**Ubuntu with Docker**
|
**Ubuntu with Docker**
|
||||||
|
|
||||||
@@ -306,7 +310,7 @@ If you want to use a different user for the command line interface, you can gene
|
|||||||
|
|
||||||
- `@hornwitser/server_select@2.0.1` fails to load with Clusterio 2.0 because its entrypoints omit the required `.js` extension.
|
- `@hornwitser/server_select@2.0.1` fails to load with Clusterio 2.0 because its entrypoints omit the required `.js` extension.
|
||||||
`@hornwitser/discord_bridge@0.2.5` is not automatically discovered because it lacks the `clusterio-plugin` keyword.
|
`@hornwitser/discord_bridge@0.2.5` is not automatically discovered because it lacks the `clusterio-plugin` keyword.
|
||||||
The Clusterio 2.0.2 installer still offers these versions; leave them unchecked until compatible plugin releases are available.
|
The installer no longer offers them, but installs made with the 2.0.2 installer or earlier may still have them.
|
||||||
If already installed, stop the controller and host, run `npm uninstall @hornwitser/server_select @hornwitser/discord_bridge` in each affected installation directory, and restart them to continue with the core plugins.
|
If already installed, stop the controller and host, run `npm uninstall @hornwitser/server_select @hornwitser/discord_bridge` in each affected installation directory, and restart them to continue with the core plugins.
|
||||||
See [#1102](https://github.com/clusterio/clusterio/issues/1102).
|
See [#1102](https://github.com/clusterio/clusterio/issues/1102).
|
||||||
- After updating Factorio you may get the error `Error: Expected empty response but got "Cannot execute command. Error: [string "clusterio_private.update_instance(..."]:1: attempt to index global 'clusterio_private' (a nil value)?` on instance start.
|
- After updating Factorio you may get the error `Error: Expected empty response but got "Cannot execute command. Error: [string "clusterio_private.update_instance(..."]:1: attempt to index global 'clusterio_private' (a nil value)?` on instance start.
|
||||||
|
|||||||
@@ -284,6 +284,7 @@ Defaults to true.
|
|||||||
|
|
||||||
ID of the mod pack to use for instances that don't have factorio.mod_pack_id set.
|
ID of the mod pack to use for instances that don't have factorio.mod_pack_id set.
|
||||||
Instances without a mod pack of their own fail to start if this is null.
|
Instances without a mod pack of their own fail to start if this is null.
|
||||||
|
When the controller adds the default mod packs to a new cluster it sets this to the newest Base Game pack if it is null.
|
||||||
|
|
||||||
Defaults to null.
|
Defaults to null.
|
||||||
|
|
||||||
@@ -591,7 +592,8 @@ Defaults to "latest".
|
|||||||
### factorio.executable_path
|
### factorio.executable_path
|
||||||
|
|
||||||
Path relative to the Factorio installation directory of the executable to run.
|
Path relative to the Factorio installation directory of the executable to run.
|
||||||
If null the path is auto detected, which is `bin/x64/factorio` on Linux and Windows and `MacOS/factorio` on macOS.
|
If null the path is auto detected, which is `MacOS/factorio` on macOS and otherwise `bin/x64/factorio` or `bin/arm64/factorio`, whichever exists.
|
||||||
|
When both exist the one matching the CPU is used.
|
||||||
Only needed in special setups.
|
Only needed in special setups.
|
||||||
|
|
||||||
Defaults to null.
|
Defaults to null.
|
||||||
|
|||||||
@@ -197,6 +197,9 @@ Use `pnpm run fast-test` to skip tests marked as slow, or `pnpm run no-external-
|
|||||||
These correspond to setting the `FAST_TEST` and `NO_EXTERNAL_TEST` environment variables and can be combined.
|
These correspond to setting the `FAST_TEST` and `NO_EXTERNAL_TEST` environment variables and can be combined.
|
||||||
For example, `FAST_TEST=y NO_EXTERNAL_TEST=y pnpm test` combines both exclusions.
|
For example, `FAST_TEST=y NO_EXTERNAL_TEST=y pnpm test` combines both exclusions.
|
||||||
These flags still run the remaining integration setup and tests; neither produces an isolated unit-test run.
|
These flags still run the remaining integration setup and tests; neither produces an isolated unit-test run.
|
||||||
|
Console and log output is only printed for tests and hooks that fail, just above the failure.
|
||||||
|
Set `TEST_OUTPUT=verbose` to print all of it as it happens, or `TEST_OUTPUT=silent` (`pnpm run silent-test`) to print only the results.
|
||||||
|
In CI, re-running a job with debug logging enabled gives verbose output.
|
||||||
When writing slow tests call `slowTest(this)`, and for external API tests call `externalTest(this)`; both are exported from `test/common.js`.
|
When writing slow tests call `slowTest(this)`, and for external API tests call `externalTest(this)`; both are exported from `test/common.js`.
|
||||||
For tests that need a Factorio installation, call `requiresFactorio(this)` in the test or pass the suite to `requiresFactorio`, imported from `test/integration/index.js`.
|
For tests that need a Factorio installation, call `requiresFactorio(this)` in the test or pass the suite to `requiresFactorio`, imported from `test/integration/index.js`.
|
||||||
`test/common.js` also provides JSON round-trip/schema helpers, and `test/mock.js` provides shared mocks.
|
`test/common.js` also provides JSON round-trip/schema helpers, and `test/mock.js` provides shared mocks.
|
||||||
|
|||||||
+24
-16
@@ -209,31 +209,39 @@ Note: This bans the user from logging in to Factorio servers in the cluster, it
|
|||||||
|
|
||||||
### Bulk importing admin, whitelist and ban lists
|
### Bulk importing admin, whitelist and ban lists
|
||||||
|
|
||||||
Whitelists and admin lists can be bulk imported with the following commands:
|
Admin lists, whitelists and banlists can be bulk imported with the following command:
|
||||||
|
|
||||||
ctl> user whitelist-bulk-import <file> [--create]
|
ctl> user import <file> [--admins|--whitelist|--bans|--users]
|
||||||
ctl> user admin-bulk-import <file> [--create]
|
|
||||||
|
|
||||||
The file should simply be newline seperated names:
|
The admin list and whitelist files should be a JSON array of names, the same format as Factorio's server-adminlist.json and server-whitelist.json:
|
||||||
|
|
||||||
joe
|
["joe", "bob", "allan"]
|
||||||
bob
|
|
||||||
allan
|
|
||||||
|
|
||||||
The `--create` option will create the user if they do not exist, and then set the relevent value.
|
The banlist file uses the format of Factorio's server-banlist.json, where each entry is either a name or an object with a username and reason:
|
||||||
|
|
||||||
Banlists can be bulk imported with the following command:
|
[
|
||||||
|
"joe",
|
||||||
|
{"username": "bob", "reason": "stole materials"},
|
||||||
|
{"username": "allan", "reason": "rude language"}
|
||||||
|
]
|
||||||
|
|
||||||
ctl> user banned-bulk-import <file> [--create]
|
The `--users` option imports a file written by `user export`, which holds the admin, whitelist and ban status of every user.
|
||||||
|
If no option is given the type is guessed from the file, files with an `export_version` field are treated as user exports, otherwise the file name must contain ban, admin or whitelist.
|
||||||
|
Users that do not exist are created.
|
||||||
|
Importing only adds to the existing lists, it never removes anyone from them.
|
||||||
|
|
||||||
The file should be names, followed by a ban reason:
|
To replace a list instead, use restore:
|
||||||
|
|
||||||
joe greifed copper mines
|
ctl> user restore <file> [--admins|--whitelist|--bans|--users] [--no-backup]
|
||||||
bob stole materials
|
|
||||||
allan rude language
|
|
||||||
|
|
||||||
The first string on the line is used as the username, the others are used as the ban reason.
|
This takes the same files as import, but removes everyone not in the file from the list.
|
||||||
The `--create` option will create the user if they do not exist, then ban them.
|
The previous list is written to `<type>-backup.json` in the current directory unless `--no-backup` is passed.
|
||||||
|
|
||||||
|
The current lists can be exported with the following command:
|
||||||
|
|
||||||
|
ctl> user export <file> [--admins|--whitelist|--bans|--users]
|
||||||
|
|
||||||
|
Defaults to exporting users.
|
||||||
|
|
||||||
### Set Cluster Roles
|
### Set Cluster Roles
|
||||||
|
|
||||||
|
|||||||
@@ -151,6 +151,10 @@ The following properties are recognized:
|
|||||||
Array of features the plugin needs from the instances it is loaded on, any of `"SavePatching"`, `"ScriptCommands"` and `"LuaUdp"`.
|
Array of features the plugin needs from the instances it is loaded on, any of `"SavePatching"`, `"ScriptCommands"` and `"LuaUdp"`.
|
||||||
See [Handling Invalid Configuration](#handling-invalid-configuration)
|
See [Handling Invalid Configuration](#handling-invalid-configuration)
|
||||||
|
|
||||||
|
**requiredMods**:
|
||||||
|
Array of Factorio mods the plugin needs in the mod pack of the instances it is loaded on, written as Factorio dependency strings.
|
||||||
|
See [Handling Invalid Configuration](#handling-invalid-configuration)
|
||||||
|
|
||||||
**messages**:
|
**messages**:
|
||||||
Array of request and event classes for this plugin.
|
Array of request and event classes for this plugin.
|
||||||
See guide for [defining link messages](#defining-link-messages) below.
|
See guide for [defining link messages](#defining-link-messages) below.
|
||||||
@@ -321,6 +325,25 @@ export const plugin = {
|
|||||||
Enabling the plugin on an instance that has the feature turned off then fails config validation, so the mistake is caught when the config is edited instead of when the instance starts.
|
Enabling the plugin on an instance that has the feature turned off then fails config validation, so the mistake is caught when the config is edited instead of when the instance starts.
|
||||||
Instances that have the feature turned off get the plugin disabled by default when it is added.
|
Instances that have the feature turned off get the plugin disabled by default when it is added.
|
||||||
|
|
||||||
|
If the plugin talks to a Factorio mod, list the mod under `requiredMods` using the same format as `dependencies` in a mod's info.json, without a prefix.
|
||||||
|
List a mod twice to give a version range:
|
||||||
|
|
||||||
|
```js
|
||||||
|
export const plugin = {
|
||||||
|
name: "foo_frobber",
|
||||||
|
// ...
|
||||||
|
requiredMods: ["frobber >= 1.2.0", "frobber < 2.0.0"],
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
An instance with the plugin loaded refuses to start if its mod pack is missing one of the mods, has it disabled, or has a version outside the range.
|
||||||
|
Leave out the dependencies of the required mods. Factorio checks those itself.
|
||||||
|
When the controller starts it downloads required mods it does not have, and their dependencies, from the mod portal for the Factorio version of the default mod pack.
|
||||||
|
This needs `controller.factorio_username` and `controller.factorio_token` to be set.
|
||||||
|
The mods still have to be added to the mod packs by hand.
|
||||||
|
|
||||||
|
Forks of a required mod are not supported.
|
||||||
|
|
||||||
Other constraints on config fields are expressed with a `validator` on the field definition, which throws when the value is not acceptable.
|
Other constraints on config fields are expressed with a `validator` on the field definition, which throws when the value is not acceptable.
|
||||||
Use `dependsOn` when the check involves other fields so that the validator runs when those change too.
|
Use `dependsOn` when the check involves other fields so that the validator runs when those change too.
|
||||||
See [Configuration System](config-system.md) for details.
|
See [Configuration System](config-system.md) for details.
|
||||||
|
|||||||
+3
-3
@@ -8,8 +8,8 @@
|
|||||||
"build": "tsc --build",
|
"build": "tsc --build",
|
||||||
"watch": "tsc --build --watch",
|
"watch": "tsc --build --watch",
|
||||||
"build-mod": "pnpm run -r build-mod --output-dir ../../dist",
|
"build-mod": "pnpm run -r build-mod --output-dir ../../dist",
|
||||||
"test": "pnpm run build && NODE_EXTRA_CA_CERTS=$(pwd)/test/file/tls/cert.pem mocha --enable-source-maps --check-leaks -R spec --recursive test \"plugins/*/test/**\" --exclude \"test/manual/**\"",
|
"test": "pnpm run build && NODE_EXTRA_CA_CERTS=$(pwd)/test/file/tls/cert.pem mocha --enable-source-maps --check-leaks -R ./test/reporter.cjs --recursive test \"plugins/*/test/**\" --exclude \"test/manual/**\"",
|
||||||
"silent-test": "SILENT_TEST=y pnpm test",
|
"silent-test": "TEST_OUTPUT=silent pnpm test",
|
||||||
"fast-test": "FAST_TEST=y pnpm test",
|
"fast-test": "FAST_TEST=y pnpm test",
|
||||||
"no-external-test": "NO_EXTERNAL_TEST=y pnpm test",
|
"no-external-test": "NO_EXTERNAL_TEST=y pnpm test",
|
||||||
"cover": "c8 pnpm test",
|
"cover": "c8 pnpm test",
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
"c8": "^12.0.0",
|
"c8": "^12.0.0",
|
||||||
"express": "catalog:",
|
"express": "catalog:",
|
||||||
"jsonwebtoken": "catalog:",
|
"jsonwebtoken": "catalog:",
|
||||||
"mocha": "^11.8.0",
|
"mocha": "^12.0.3",
|
||||||
"oxlint": "^1.88.0",
|
"oxlint": "^1.88.0",
|
||||||
"typescript": "catalog:",
|
"typescript": "catalog:",
|
||||||
"yargs": "catalog:",
|
"yargs": "catalog:",
|
||||||
|
|||||||
@@ -631,7 +631,8 @@ export default class ControlConnection extends BaseConnection {
|
|||||||
* @param request - The request object containing factorioVersion.
|
* @param request - The request object containing factorioVersion.
|
||||||
*/
|
*/
|
||||||
async handleModPortalGetAllRequest(request: lib.ModPortalGetAllRequest) {
|
async handleModPortalGetAllRequest(request: lib.ModPortalGetAllRequest) {
|
||||||
const cacheKey = `${request.factorioVersion}-${request.hide_deprecated}`;
|
const hideDeprecated = request.hide_deprecated ?? false;
|
||||||
|
const cacheKey = `${request.factorioVersion}-${hideDeprecated}`;
|
||||||
const cachedData = this._controller.modPortalCache.get(cacheKey);
|
const cachedData = this._controller.modPortalCache.get(cacheKey);
|
||||||
|
|
||||||
const cacheDuration = this._controller.config.get("controller.mod_portal_cache_duration_minutes") * 60 * 1000;
|
const cacheDuration = this._controller.config.get("controller.mod_portal_cache_duration_minutes") * 60 * 1000;
|
||||||
@@ -644,7 +645,7 @@ export default class ControlConnection extends BaseConnection {
|
|||||||
const mods = await lib.ModStore.fetchAllModsFromPortal(
|
const mods = await lib.ModStore.fetchAllModsFromPortal(
|
||||||
request.factorioVersion,
|
request.factorioVersion,
|
||||||
this._controller.config.get("controller.mod_portal_page_size"),
|
this._controller.config.get("controller.mod_portal_page_size"),
|
||||||
request.hide_deprecated
|
hideDeprecated
|
||||||
);
|
);
|
||||||
this._controller.modPortalCache.set(cacheKey, { timestamp: Date.now(), data: mods });
|
this._controller.modPortalCache.set(cacheKey, { timestamp: Date.now(), data: mods });
|
||||||
// The Response class is defined inline within the Request class
|
// The Response class is defined inline within the Request class
|
||||||
@@ -661,36 +662,7 @@ export default class ControlConnection extends BaseConnection {
|
|||||||
* @param request - Request object with mod name, version, and factorioVersion.
|
* @param request - Request object with mod name, version, and factorioVersion.
|
||||||
*/
|
*/
|
||||||
async handleModPortalDownloadRequest(request: lib.ModPortalDownloadRequest) {
|
async handleModPortalDownloadRequest(request: lib.ModPortalDownloadRequest) {
|
||||||
const factorioVersion = request.factorioVersion;
|
await this._controller.downloadModsFromPortal(request.mods, request.factorioVersion);
|
||||||
const toDownload = this._controller.modStore.filterInstalled(request.mods, false);
|
|
||||||
|
|
||||||
if (toDownload.length > 0) {
|
|
||||||
// Get Factorio credentials from config
|
|
||||||
const username = this._controller.config.get("controller.factorio_username");
|
|
||||||
const token = this._controller.config.get("controller.factorio_token");
|
|
||||||
|
|
||||||
if (!username || username === "" || !token || token === "") {
|
|
||||||
throw new lib.ConflictError("Factorio credentials (username, token) not configured on the controller.");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
logger.info(`Downloading ${toDownload.length} mods for Factorio ${factorioVersion} from portal.`);
|
|
||||||
await this._controller.modStore.downloadMods(toDownload, username, token, factorioVersion);
|
|
||||||
|
|
||||||
} catch (error: any) {
|
|
||||||
logger.error(`Error downloading mods from portal: ${error.message}`);
|
|
||||||
const errorMessage = "Mod portal download failed";
|
|
||||||
if (error.message.includes("401") || error.message.includes("Unauthorized")) {
|
|
||||||
throw new lib.ConflictError(
|
|
||||||
`${errorMessage}: Authentication failed. Check Factorio username/token in controller config.`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (error.message.includes("404") || error.message.includes("Not Found")) {
|
|
||||||
throw new lib.NotFoundError(`${errorMessage}: Mod version not found on the portal.`);
|
|
||||||
}
|
|
||||||
throw new lib.InternalServerError(`${errorMessage}: ${error.message}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify all mods are present
|
// Verify all mods are present
|
||||||
const modInfos = [];
|
const modInfos = [];
|
||||||
@@ -706,183 +678,9 @@ export default class ControlConnection extends BaseConnection {
|
|||||||
return modInfos;
|
return modInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line complexity
|
|
||||||
async handleModDependencyResolveRequest(request: lib.ModDependencyResolveRequest) {
|
async handleModDependencyResolveRequest(request: lib.ModDependencyResolveRequest) {
|
||||||
const {factorioVersion, checkForUpdates} = request;
|
return await this._controller.resolveModDependencies(
|
||||||
const searchQueue = [...request.mods];
|
request.mods, request.factorioVersion, request.checkForUpdates,
|
||||||
const localInfos = [...this._controller.modStore.mods()];
|
|
||||||
|
|
||||||
const builtInModNames = lib.ModPack.getBuiltinModNames(factorioVersion);
|
|
||||||
const skipSearch = new Set(builtInModNames);
|
|
||||||
|
|
||||||
type ModPortalModType = InstanceType<typeof lib.ModPortalGetAllRequest.Response>["mods"][number];
|
|
||||||
type ModPortalReleaseType = NonNullable<ModPortalModType["releases"]>[number];
|
|
||||||
const dependencyRequirements = new Map<string, lib.ModVersionRange>();
|
|
||||||
const recommendedRequirements = new Map<string, lib.ModVersionRange>();
|
|
||||||
const optionalRequirements = new Map<string, lib.ModVersionRange>();
|
|
||||||
const candidateReleases = new Map<string, lib.ModInfo>();
|
|
||||||
const errors = new Map<string, lib.ModDependencyResolveErrors>();
|
|
||||||
|
|
||||||
const _modPortalReleases = new Map<string, ModPortalModType | null>();
|
|
||||||
async function fetchModReleases(modName: string) {
|
|
||||||
let releases = _modPortalReleases.get(modName);
|
|
||||||
if (releases === undefined) {
|
|
||||||
try {
|
|
||||||
releases = await lib.ModStore.fetchModReleases(modName);
|
|
||||||
} catch (error: any) {
|
|
||||||
if (!error.message.includes("404") && !error.message.includes("Not Found")) {
|
|
||||||
logger.error(`Error fetching mod from portal: ${error.message}`);
|
|
||||||
throw new lib.InternalServerError(`Dependency resolution failed: ${error.message}`);
|
|
||||||
} else {
|
|
||||||
releases = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_modPortalReleases.set(modName, releases);
|
|
||||||
return releases;
|
|
||||||
}
|
|
||||||
|
|
||||||
function selectModRelease(releases: ModPortalModType | null, versionRange: lib.ModVersionRange) {
|
|
||||||
if (!releases || !releases.releases) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Select the latest matching version for the mod pack's Factorio version
|
|
||||||
const release = releases.releases
|
|
||||||
.filter(info => (
|
|
||||||
versionRange.testVersion(info.version)
|
|
||||||
&& lib.normaliseMajorMinorVersion(
|
|
||||||
lib.normaliseSourceVersion(info.info_json.factorio_version)
|
|
||||||
) === factorioVersion
|
|
||||||
))
|
|
||||||
.reduce<ModPortalReleaseType | undefined>((max, cur) => (
|
|
||||||
max && lib.integerSourceVersion(max.version) > lib.integerSourceVersion(cur.version) ? max : cur
|
|
||||||
), undefined);
|
|
||||||
|
|
||||||
if (!release) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the mod info class from the selected
|
|
||||||
try {
|
|
||||||
return lib.ModInfo.fromJSON({
|
|
||||||
...release.info_json, // includes dependencies
|
|
||||||
sha1: release.sha1,
|
|
||||||
version: release.version,
|
|
||||||
name: releases.name,
|
|
||||||
author: releases.owner,
|
|
||||||
title: releases.title,
|
|
||||||
});
|
|
||||||
} catch {
|
|
||||||
// Can error if there are invalid dependencies
|
|
||||||
errors.set(releases.name, "invalidDependency");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
while (searchQueue.length > 0) {
|
|
||||||
// Dequeue the next mod, skip if incompatible
|
|
||||||
const mod = searchQueue.shift()!;
|
|
||||||
if (mod.incompatible) {
|
|
||||||
errors.set(mod.name, "incompatible");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the current version range (dependencies can be promoted to a stricter requirement)
|
|
||||||
const versionRange =
|
|
||||||
dependencyRequirements.get(mod.name)
|
|
||||||
?? recommendedRequirements.get(mod.name)
|
|
||||||
?? optionalRequirements.get(mod.name)
|
|
||||||
?? new lib.ModVersionRange();
|
|
||||||
|
|
||||||
if (mod.required) {
|
|
||||||
// Add to required, remove from recommended and optional
|
|
||||||
dependencyRequirements.set(mod.name, versionRange);
|
|
||||||
recommendedRequirements.delete(mod.name);
|
|
||||||
optionalRequirements.delete(mod.name);
|
|
||||||
|
|
||||||
} else if (mod.recommended) {
|
|
||||||
// If not required, add to recommended and remove from optional
|
|
||||||
if (!dependencyRequirements.has(mod.name)) {
|
|
||||||
recommendedRequirements.set(mod.name, versionRange);
|
|
||||||
optionalRequirements.delete(mod.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (
|
|
||||||
!dependencyRequirements.has(mod.name)
|
|
||||||
&& !recommendedRequirements.has(mod.name)
|
|
||||||
) {
|
|
||||||
// If not required or recommended, add to optional
|
|
||||||
optionalRequirements.set(mod.name, versionRange);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update the version range if needed
|
|
||||||
if (mod.version) {
|
|
||||||
versionRange.combineVersion(mod.version);
|
|
||||||
if (!versionRange.valid) {
|
|
||||||
candidateReleases.delete(mod.name);
|
|
||||||
errors.set(mod.name, "unsatisfiable");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do not add dependencies for errors, skips, optionals, or valid candidates
|
|
||||||
const existingCandidate = candidateReleases.get(mod.name);
|
|
||||||
if (errors.has(mod.name) || skipSearch.has(mod.name) || optionalRequirements.has(mod.name) || (
|
|
||||||
existingCandidate && versionRange.testVersion(existingCandidate.version)
|
|
||||||
)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if a local version fits the requirements
|
|
||||||
let candidate = localInfos
|
|
||||||
.filter(info => (
|
|
||||||
info.name === mod.name
|
|
||||||
&& info.factorioVersion === factorioVersion
|
|
||||||
&& versionRange.testVersion(info.version)
|
|
||||||
))
|
|
||||||
.reduce<lib.ModInfo | undefined>((max, cur) => (
|
|
||||||
max && max.integerVersion > cur.integerVersion ? max : cur
|
|
||||||
), undefined);
|
|
||||||
|
|
||||||
// Check if a mod poral version fits the requirements
|
|
||||||
if (!candidate || checkForUpdates) {
|
|
||||||
const releases = await fetchModReleases(mod.name);
|
|
||||||
const release = selectModRelease(releases, versionRange);
|
|
||||||
// We only select the mod portal release if it is more recent than the local candidate
|
|
||||||
if (release && (!candidate || release.integerVersion > candidate.integerVersion)) {
|
|
||||||
candidate = release;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Queue the dependencies of the new candidate
|
|
||||||
if (candidate) {
|
|
||||||
candidateReleases.set(mod.name, candidate);
|
|
||||||
for (const dep of candidate.dependencies) {
|
|
||||||
searchQueue.push(dep);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
candidateReleases.delete(mod.name);
|
|
||||||
skipSearch.add(mod.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the not found dependencies as errors
|
|
||||||
for (const modName of dependencyRequirements.keys()) {
|
|
||||||
if (!candidateReleases.has(modName) && !errors.has(modName)) {
|
|
||||||
errors.set(modName, "notFound");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove incompatible and unsatisfiable dependencies if they aren't required by others
|
|
||||||
for (const [modName, error] of errors) {
|
|
||||||
if (!dependencyRequirements.has(modName) && (error === "incompatible" || error === "unsatisfiable")) {
|
|
||||||
errors.delete(modName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new lib.ModDependencyResolveRequest.Response(
|
|
||||||
[...candidateReleases.values()], errors,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import type winston from "winston";
|
|||||||
import { BlockList, type AddressInfo, isIPv4, isIPv6 } from "net";
|
import { BlockList, type AddressInfo, isIPv4, isIPv6 } from "net";
|
||||||
import type { ControllerArgs } from "../controller.js";
|
import type { ControllerArgs } from "../controller.js";
|
||||||
import type ControlConnection from "./ControlConnection.js";
|
import type ControlConnection from "./ControlConnection.js";
|
||||||
|
import type HostConnection from "./HostConnection.js";
|
||||||
import express, { type Request, type Response, type NextFunction, type Application } from "express";
|
import express, { type Request, type Response, type NextFunction, type Application } from "express";
|
||||||
import type { Static } from "@sinclair/typebox";
|
import type { Static } from "@sinclair/typebox";
|
||||||
import finalhandler from "finalhandler";
|
import finalhandler from "finalhandler";
|
||||||
@@ -233,6 +234,12 @@ export default class Controller {
|
|||||||
// Add default mod packs
|
// Add default mod packs
|
||||||
if (modPacks.size === 0) {
|
if (modPacks.size === 0) {
|
||||||
modPacks.setMany(lib.ModPack.defaultModPacks);
|
modPacks.setMany(lib.ModPack.defaultModPacks);
|
||||||
|
if (config.get("controller.default_mod_pack_id") === null) {
|
||||||
|
const baseGame = lib.ModPack.defaultModPacks
|
||||||
|
.filter(pack => pack.name.startsWith("Base Game "))
|
||||||
|
.reduce((a, b) => (b.integerFactorioVersion > a.integerFactorioVersion ? b : a));
|
||||||
|
config.set("controller.default_mod_pack_id", baseGame.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add default roles
|
// Add default roles
|
||||||
@@ -502,11 +509,14 @@ export default class Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.hostPairing.start();
|
this.hostPairing.start();
|
||||||
this.onAutosaveIntervalChanged();
|
|
||||||
this.onSystemMetricsIntervalChanged();
|
|
||||||
|
|
||||||
logger.info("Started controller");
|
logger.info("Started controller");
|
||||||
this.startedAtMs = Date.now();
|
this.startedAtMs = Date.now();
|
||||||
|
this.downloadRequiredMods().catch(
|
||||||
|
err => logger.warn(`Unable to download mods required by plugins: ${err.message}`)
|
||||||
|
);
|
||||||
|
this.onAutosaveIntervalChanged();
|
||||||
|
this.onSystemMetricsIntervalChanged();
|
||||||
this._state = "running";
|
this._state = "running";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -663,6 +673,7 @@ export default class Controller {
|
|||||||
this.updateSystems.bind(this),
|
this.updateSystems.bind(this),
|
||||||
systemMetricsIntervalSeconds * 1000
|
systemMetricsIntervalSeconds * 1000
|
||||||
);
|
);
|
||||||
|
this.updateSystems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -688,6 +699,20 @@ export default class Controller {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Fetch system info from a host that just connected instead of waiting for the next interval */
|
||||||
|
async updateHostSystem(hostConnection: HostConnection) {
|
||||||
|
if (!(this.config.get("controller.system_metrics_interval") > 0)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.systems.set(await hostConnection.send(new lib.SystemInfoRequest()));
|
||||||
|
} catch (err: any) {
|
||||||
|
logger.error(
|
||||||
|
`Unexpected error updating system info of host ${hostConnection.id}:\n${err.stack ?? err.message}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Plugins on the controller, including those installed or updated since it started */
|
/** Plugins on the controller, including those installed or updated since it started */
|
||||||
async listPlugins() {
|
async listPlugins() {
|
||||||
return await lib.listPluginDetails(
|
return await lib.listPluginDetails(
|
||||||
@@ -1147,6 +1172,265 @@ export default class Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download mods from the Factorio mod portal to the mod store
|
||||||
|
*
|
||||||
|
* Mods already in the mod store are skipped.
|
||||||
|
*
|
||||||
|
* @throws {lib.ConflictError} if the Factorio credentials are not configured.
|
||||||
|
*/
|
||||||
|
async downloadModsFromPortal(mods: lib.ModNameVersionPair[], factorioVersion: lib.MajorMinorVersion) {
|
||||||
|
const toDownload = this.modStore.filterInstalled(mods, false);
|
||||||
|
|
||||||
|
if (toDownload.length > 0) {
|
||||||
|
// Get Factorio credentials from config
|
||||||
|
const username = this.config.get("controller.factorio_username");
|
||||||
|
const token = this.config.get("controller.factorio_token");
|
||||||
|
|
||||||
|
if (!username || username === "" || !token || token === "") {
|
||||||
|
throw new lib.ConflictError("Factorio credentials (username, token) not configured on the controller.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
logger.info(`Downloading ${toDownload.length} mods for Factorio ${factorioVersion} from portal.`);
|
||||||
|
await this.modStore.downloadMods(toDownload, username, token, factorioVersion);
|
||||||
|
|
||||||
|
} catch (error: any) {
|
||||||
|
logger.error(`Error downloading mods from portal: ${error.message}`);
|
||||||
|
const errorMessage = "Mod portal download failed";
|
||||||
|
if (error.message.includes("401") || error.message.includes("Unauthorized")) {
|
||||||
|
throw new lib.ConflictError(
|
||||||
|
`${errorMessage}: Authentication failed. Check Factorio username/token in controller config.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (error.message.includes("404") || error.message.includes("Not Found")) {
|
||||||
|
throw new lib.NotFoundError(`${errorMessage}: Mod version not found on the portal.`);
|
||||||
|
}
|
||||||
|
throw new lib.InternalServerError(`${errorMessage}: ${error.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve mods and their dependencies against the mod store and the Factorio mod portal
|
||||||
|
*/
|
||||||
|
// eslint-disable-next-line complexity
|
||||||
|
async resolveModDependencies(
|
||||||
|
mods: lib.ModDependency[],
|
||||||
|
factorioVersion: lib.MajorMinorVersion,
|
||||||
|
checkForUpdates = false,
|
||||||
|
) {
|
||||||
|
const searchQueue = [...mods];
|
||||||
|
const localInfos = [...this.modStore.mods()];
|
||||||
|
|
||||||
|
const builtInModNames = lib.ModPack.getBuiltinModNames(factorioVersion);
|
||||||
|
const skipSearch = new Set(builtInModNames);
|
||||||
|
|
||||||
|
type ModPortalModType = InstanceType<typeof lib.ModPortalGetAllRequest.Response>["mods"][number];
|
||||||
|
type ModPortalReleaseType = NonNullable<ModPortalModType["releases"]>[number];
|
||||||
|
const dependencyRequirements = new Map<string, lib.ModVersionRange>();
|
||||||
|
const recommendedRequirements = new Map<string, lib.ModVersionRange>();
|
||||||
|
const optionalRequirements = new Map<string, lib.ModVersionRange>();
|
||||||
|
const candidateReleases = new Map<string, lib.ModInfo>();
|
||||||
|
const errors = new Map<string, lib.ModDependencyResolveErrors>();
|
||||||
|
|
||||||
|
const _modPortalReleases = new Map<string, ModPortalModType | null>();
|
||||||
|
async function fetchModReleases(modName: string) {
|
||||||
|
let releases = _modPortalReleases.get(modName);
|
||||||
|
if (releases === undefined) {
|
||||||
|
try {
|
||||||
|
releases = await lib.ModStore.fetchModReleases(modName);
|
||||||
|
} catch (error: any) {
|
||||||
|
if (!error.message.includes("404") && !error.message.includes("Not Found")) {
|
||||||
|
logger.error(`Error fetching mod from portal: ${error.message}`);
|
||||||
|
throw new lib.InternalServerError(`Dependency resolution failed: ${error.message}`);
|
||||||
|
} else {
|
||||||
|
releases = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_modPortalReleases.set(modName, releases);
|
||||||
|
return releases;
|
||||||
|
}
|
||||||
|
|
||||||
|
function selectModRelease(releases: ModPortalModType | null, versionRange: lib.ModVersionRange) {
|
||||||
|
if (!releases || !releases.releases) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select the latest matching version for the mod pack's Factorio version
|
||||||
|
const release = releases.releases
|
||||||
|
.filter(info => (
|
||||||
|
versionRange.testVersion(info.version)
|
||||||
|
&& lib.normaliseMajorMinorVersion(
|
||||||
|
lib.normaliseSourceVersion(info.info_json.factorio_version)
|
||||||
|
) === factorioVersion
|
||||||
|
))
|
||||||
|
.reduce<ModPortalReleaseType | undefined>((max, cur) => (
|
||||||
|
max && lib.integerSourceVersion(max.version) > lib.integerSourceVersion(cur.version) ? max : cur
|
||||||
|
), undefined);
|
||||||
|
|
||||||
|
if (!release) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the mod info class from the selected
|
||||||
|
try {
|
||||||
|
return lib.ModInfo.fromJSON({
|
||||||
|
...release.info_json, // includes dependencies
|
||||||
|
sha1: release.sha1,
|
||||||
|
version: release.version,
|
||||||
|
name: releases.name,
|
||||||
|
author: releases.owner,
|
||||||
|
title: releases.title,
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
// Can error if there are invalid dependencies
|
||||||
|
errors.set(releases.name, "invalidDependency");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (searchQueue.length > 0) {
|
||||||
|
// Dequeue the next mod, skip if incompatible
|
||||||
|
const mod = searchQueue.shift()!;
|
||||||
|
if (mod.incompatible) {
|
||||||
|
errors.set(mod.name, "incompatible");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the current version range (dependencies can be promoted to a stricter requirement)
|
||||||
|
const versionRange =
|
||||||
|
dependencyRequirements.get(mod.name)
|
||||||
|
?? recommendedRequirements.get(mod.name)
|
||||||
|
?? optionalRequirements.get(mod.name)
|
||||||
|
?? new lib.ModVersionRange();
|
||||||
|
|
||||||
|
if (mod.required) {
|
||||||
|
// Add to required, remove from recommended and optional
|
||||||
|
dependencyRequirements.set(mod.name, versionRange);
|
||||||
|
recommendedRequirements.delete(mod.name);
|
||||||
|
optionalRequirements.delete(mod.name);
|
||||||
|
|
||||||
|
} else if (mod.recommended) {
|
||||||
|
// If not required, add to recommended and remove from optional
|
||||||
|
if (!dependencyRequirements.has(mod.name)) {
|
||||||
|
recommendedRequirements.set(mod.name, versionRange);
|
||||||
|
optionalRequirements.delete(mod.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (
|
||||||
|
!dependencyRequirements.has(mod.name)
|
||||||
|
&& !recommendedRequirements.has(mod.name)
|
||||||
|
) {
|
||||||
|
// If not required or recommended, add to optional
|
||||||
|
optionalRequirements.set(mod.name, versionRange);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the version range if needed
|
||||||
|
if (mod.version) {
|
||||||
|
versionRange.combineVersion(mod.version);
|
||||||
|
if (!versionRange.valid) {
|
||||||
|
candidateReleases.delete(mod.name);
|
||||||
|
errors.set(mod.name, "unsatisfiable");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not add dependencies for errors, skips, optionals, or valid candidates
|
||||||
|
const existingCandidate = candidateReleases.get(mod.name);
|
||||||
|
if (errors.has(mod.name) || skipSearch.has(mod.name) || optionalRequirements.has(mod.name) || (
|
||||||
|
existingCandidate && versionRange.testVersion(existingCandidate.version)
|
||||||
|
)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if a local version fits the requirements
|
||||||
|
let candidate = localInfos
|
||||||
|
.filter(info => (
|
||||||
|
info.name === mod.name
|
||||||
|
&& info.factorioVersion === factorioVersion
|
||||||
|
&& versionRange.testVersion(info.version)
|
||||||
|
))
|
||||||
|
.reduce<lib.ModInfo | undefined>((max, cur) => (
|
||||||
|
max && max.integerVersion > cur.integerVersion ? max : cur
|
||||||
|
), undefined);
|
||||||
|
|
||||||
|
// Check if a mod poral version fits the requirements
|
||||||
|
if (!candidate || checkForUpdates) {
|
||||||
|
const releases = await fetchModReleases(mod.name);
|
||||||
|
const release = selectModRelease(releases, versionRange);
|
||||||
|
// We only select the mod portal release if it is more recent than the local candidate
|
||||||
|
if (release && (!candidate || release.integerVersion > candidate.integerVersion)) {
|
||||||
|
candidate = release;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Queue the dependencies of the new candidate
|
||||||
|
if (candidate) {
|
||||||
|
candidateReleases.set(mod.name, candidate);
|
||||||
|
for (const dep of candidate.dependencies) {
|
||||||
|
searchQueue.push(dep);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
candidateReleases.delete(mod.name);
|
||||||
|
skipSearch.add(mod.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the not found dependencies as errors
|
||||||
|
for (const modName of dependencyRequirements.keys()) {
|
||||||
|
if (!candidateReleases.has(modName) && !errors.has(modName)) {
|
||||||
|
errors.set(modName, "notFound");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove incompatible and unsatisfiable dependencies if they aren't required by others
|
||||||
|
for (const [modName, error] of errors) {
|
||||||
|
if (!dependencyRequirements.has(modName) && (error === "incompatible" || error === "unsatisfiable")) {
|
||||||
|
errors.delete(modName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new lib.ModDependencyResolveRequest.Response(
|
||||||
|
[...candidateReleases.values()], errors,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download the mods required by plugins that are missing from the mod store
|
||||||
|
*
|
||||||
|
* Resolves for the Factorio version of the default mod pack. Dependencies
|
||||||
|
* of the required mods are downloaded too.
|
||||||
|
*/
|
||||||
|
async downloadRequiredMods() {
|
||||||
|
const required = this.pluginInfos.flatMap(pluginInfo => lib.pluginRequiredMods(pluginInfo));
|
||||||
|
const modPackId = this.config.get("controller.default_mod_pack_id");
|
||||||
|
const modPack = modPackId !== null ? this.modPacks.get(modPackId) : undefined;
|
||||||
|
if (!required.length || !modPack) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const factorioVersion = lib.normaliseMajorMinorVersion(modPack.factorioVersion);
|
||||||
|
const { dependencies, errors } = await this.resolveModDependencies(required, factorioVersion);
|
||||||
|
const builtInMods = new Set(lib.ModPack.getBuiltinModNames(factorioVersion));
|
||||||
|
for (const [name, error] of errors) {
|
||||||
|
if (!builtInMods.has(name)) {
|
||||||
|
logger.warn(`Unable to resolve mod ${name} required by plugins: ${error}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const toDownload = this.modStore.filterInstalled(dependencies.map(
|
||||||
|
info => ({ name: info.name, version: new lib.ModVersionEquality("=", info.normalisedVersion) })
|
||||||
|
), false);
|
||||||
|
if (!toDownload.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const names = toDownload.map(mod => `${mod.name} ${mod.version.version}`).join(", ");
|
||||||
|
logger.info(`Downloading mods required by plugins: ${names}`);
|
||||||
|
await this.downloadModsFromPortal(toDownload, factorioVersion);
|
||||||
|
}
|
||||||
|
|
||||||
modPacksUpdated(modPacks: lib.ModPack[]) {
|
modPacksUpdated(modPacks: lib.ModPack[]) {
|
||||||
this.subscriptions.broadcast(new lib.ModPackUpdatesEvent(modPacks));
|
this.subscriptions.broadcast(new lib.ModPackUpdatesEvent(modPacks));
|
||||||
this.hooks.modPacksUpdated.invoke(modPacks);
|
this.hooks.modPacksUpdated.invoke(modPacks);
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ export default class HostConnection extends BaseConnection {
|
|||||||
for (let event of ["connect", "drop", "resume", "close"] as const) {
|
for (let event of ["connect", "drop", "resume", "close"] as const) {
|
||||||
this.connector.on(event, () => this._controller.hooks.hostConnectionEvent.invoke(this, event));
|
this.connector.on(event, () => this._controller.hooks.hostConnectionEvent.invoke(this, event));
|
||||||
}
|
}
|
||||||
|
this.connector.on("connect", () => { this._controller.updateHostSystem(this); });
|
||||||
|
|
||||||
this.connector.on("close", () => {
|
this.connector.on("close", () => {
|
||||||
// Update status to unknown for instances on this host.
|
// Update status to unknown for instances on this host.
|
||||||
|
|||||||
@@ -446,7 +446,7 @@ set "NODE_OPTIONS=--enable-source-maps %NODE_OPTIONS%"
|
|||||||
:restart
|
:restart
|
||||||
call .\\node_modules\\.bin\\clusteriocontroller.cmd run --can-restart
|
call .\\node_modules\\.bin\\clusteriocontroller.cmd run --can-restart
|
||||||
if %errorlevel% equ 0 exit /b
|
if %errorlevel% equ 0 exit /b
|
||||||
if %errorlevel% equ 8 exit /b
|
if %errorlevel% equ 8 exit /b 8
|
||||||
goto restart
|
goto restart
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
@@ -458,7 +458,8 @@ goto restart
|
|||||||
export "NODE_OPTIONS=--enable-source-maps $NODE_OPTIONS"
|
export "NODE_OPTIONS=--enable-source-maps $NODE_OPTIONS"
|
||||||
while true; do
|
while true; do
|
||||||
./node_modules/.bin/clusteriocontroller run --can-restart
|
./node_modules/.bin/clusteriocontroller run --can-restart
|
||||||
if [[ $? -eq 0 || $? -eq 8 ]]; then exit $?; fi
|
code=$?
|
||||||
|
if [[ $code -eq 0 || $code -eq 8 ]]; then exit $code; fi
|
||||||
done
|
done
|
||||||
`,
|
`,
|
||||||
{ mode: 0o755 },
|
{ mode: 0o755 },
|
||||||
@@ -498,7 +499,7 @@ set "NODE_OPTIONS=--enable-source-maps %NODE_OPTIONS%"
|
|||||||
${extraCaCertsLine}:restart
|
${extraCaCertsLine}:restart
|
||||||
call .\\node_modules\\.bin\\clusteriohost.cmd run --can-restart
|
call .\\node_modules\\.bin\\clusteriohost.cmd run --can-restart
|
||||||
if %errorlevel% equ 0 exit /b
|
if %errorlevel% equ 0 exit /b
|
||||||
if %errorlevel% equ 8 exit /b
|
if %errorlevel% equ 8 exit /b 8
|
||||||
goto restart
|
goto restart
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
@@ -511,7 +512,8 @@ goto restart
|
|||||||
export "NODE_OPTIONS=--enable-source-maps $NODE_OPTIONS"
|
export "NODE_OPTIONS=--enable-source-maps $NODE_OPTIONS"
|
||||||
${extraCaCertsLine}while true; do
|
${extraCaCertsLine}while true; do
|
||||||
./node_modules/.bin/clusteriohost run --can-restart
|
./node_modules/.bin/clusteriohost run --can-restart
|
||||||
if [[ $? -eq 0 || $? -eq 8 ]]; then exit $?; fi
|
code=$?
|
||||||
|
if [[ $code -eq 0 || $code -eq 8 ]]; then exit $code; fi
|
||||||
done
|
done
|
||||||
`,
|
`,
|
||||||
{ mode: 0o755 },
|
{ mode: 0o755 },
|
||||||
|
|||||||
@@ -1,4 +1,15 @@
|
|||||||
|
import asTableModule from "as-table";
|
||||||
|
|
||||||
export function print(...content: any) {
|
export function print(...content: any) {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
console.log(...content);
|
console.log(...content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatCell(value: unknown) {
|
||||||
|
if (value instanceof Set) {
|
||||||
|
return [...value].join(", ");
|
||||||
|
}
|
||||||
|
return String(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
export const asTable = asTableModule.configure({ delimiter: " | ", print: formatCell });
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
import asTableModule from "as-table";
|
|
||||||
|
|
||||||
import * as lib from "@clusterio/lib";
|
import * as lib from "@clusterio/lib";
|
||||||
import { logger } from "@clusterio/lib";
|
import { logger } from "@clusterio/lib";
|
||||||
import type { Ctl } from "../ctl.js";
|
import type { Ctl } from "../ctl.js";
|
||||||
import { print } from "./command_ops.js";
|
import { asTable, print } from "./command_ops.js";
|
||||||
|
|
||||||
const asTable = asTableModule.configure({ delimiter: " | " });
|
|
||||||
|
|
||||||
export const roleCommands = new lib.CommandTree({ name: "role", description: "Role management" });
|
export const roleCommands = new lib.CommandTree({ name: "role", description: "Role management" });
|
||||||
roleCommands.add(new lib.Command({
|
roleCommands.add(new lib.Command({
|
||||||
|
|||||||
@@ -1,12 +1,9 @@
|
|||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import asTableModule from "as-table";
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
import * as lib from "@clusterio/lib";
|
import * as lib from "@clusterio/lib";
|
||||||
import type { Ctl } from "../ctl.js";
|
import type { Ctl } from "../ctl.js";
|
||||||
import { print } from "./command_ops.js";
|
import { asTable, print } from "./command_ops.js";
|
||||||
|
|
||||||
const asTable = asTableModule.configure({ delimiter: " | " });
|
|
||||||
|
|
||||||
export const userCommands = new lib.CommandTree({ name: "user", alias: ["u"], description: "User management" });
|
export const userCommands = new lib.CommandTree({ name: "user", alias: ["u"], description: "User management" });
|
||||||
userCommands.add(new lib.Command({
|
userCommands.add(new lib.Command({
|
||||||
|
|||||||
@@ -1032,6 +1032,39 @@ end`.replace(/\r?\n/g, " ");
|
|||||||
}
|
}
|
||||||
|
|
||||||
await this.syncMods();
|
await this.syncMods();
|
||||||
|
this.checkRequiredMods(this.activeModPack);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check that the mod pack has the mods required by the loaded plugins
|
||||||
|
*
|
||||||
|
* @throws {lib.ConflictError} if a required mod is missing, disabled or the wrong version.
|
||||||
|
*/
|
||||||
|
checkRequiredMods(modPack: lib.ModPack) {
|
||||||
|
const problems = [];
|
||||||
|
for (const pluginInfo of this.loadedPlugins) {
|
||||||
|
const unmet = [];
|
||||||
|
for (const dependency of lib.pluginRequiredMods(pluginInfo)) {
|
||||||
|
const mod = modPack.mods.get(dependency.name);
|
||||||
|
if (!mod) {
|
||||||
|
unmet.push(`${dependency.spec} (missing)`);
|
||||||
|
} else if (!mod.enabled) {
|
||||||
|
unmet.push(`${dependency.spec} (disabled)`);
|
||||||
|
} else if (dependency.version && !dependency.version.testVersion(mod.version)) {
|
||||||
|
unmet.push(`${dependency.spec} (found ${mod.version})`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (unmet.length) {
|
||||||
|
problems.push(`Plugin ${pluginInfo.name} requires ${unmet.join(", ")}.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (problems.length) {
|
||||||
|
throw new lib.ConflictError(
|
||||||
|
`Mod pack ${modPack.name} does not have the mods required by the loaded plugins. ` +
|
||||||
|
`${problems.join(" ")} ` +
|
||||||
|
"Add the mods to the mod pack or set <plugin>.load_plugin to false for this instance."
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -297,9 +297,12 @@ export async function ensurePaired(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// The host has not started yet, so the new token needs no restart.
|
||||||
|
const restartRequired = config.restartRequired;
|
||||||
config.set("host.id", result.hostId);
|
config.set("host.id", result.hostId);
|
||||||
config.set("host.name", result.name);
|
config.set("host.name", result.name);
|
||||||
config.set("host.controller_token", result.token);
|
config.set("host.controller_token", result.token);
|
||||||
|
config.restartRequired = restartRequired;
|
||||||
await config.save();
|
await config.save();
|
||||||
logger.info(`Host approved as "${result.name}" with id ${result.hostId}`);
|
logger.info(`Host approved as "${result.name}" with id ${result.hostId}`);
|
||||||
}
|
}
|
||||||
+42
-12
@@ -1,6 +1,6 @@
|
|||||||
// Factorio Server interface
|
// Factorio Server interface
|
||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import { type FSWatcher, createWriteStream, watch as fsWatch, writeFileSync } from "node:fs";
|
import { type FSWatcher, createWriteStream, existsSync, watch as fsWatch, writeFileSync } from "node:fs";
|
||||||
import child_process from "child_process";
|
import child_process from "child_process";
|
||||||
import dgram from "dgram";
|
import dgram from "dgram";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
@@ -182,6 +182,15 @@ async function downloadAndExtractTar(url: string, targetDir: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factorio Linux build architecture matching this host
|
||||||
|
*
|
||||||
|
* @returns "arm64" on ARM64 Linux, otherwise "x64".
|
||||||
|
*/
|
||||||
|
function factorioArch(): lib.FactorioHeadlessArch {
|
||||||
|
return process.platform === "linux" && process.arch === "arm64" ? "arm64" : "x64";
|
||||||
|
}
|
||||||
|
|
||||||
// Factorio downloads in progress by target directory, shared by every server in the process
|
// Factorio downloads in progress by target directory, shared by every server in the process
|
||||||
const downloadsInProgress = new Map<string, Promise<void>>();
|
const downloadsInProgress = new Map<string, Promise<void>>();
|
||||||
|
|
||||||
@@ -202,14 +211,27 @@ export async function checkForUpdates(
|
|||||||
logger: lib.Logger = lib.logger,
|
logger: lib.Logger = lib.logger,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const latestVersion = availableVersions
|
const matchesTarget = (version: string) => (
|
||||||
.filter(v => (
|
targetVersion === "latest" || version === targetVersion || version.startsWith(targetVersion)
|
||||||
targetVersion === "latest" || v.version === targetVersion || v.version.startsWith(targetVersion)
|
);
|
||||||
))
|
const arch = factorioArch();
|
||||||
|
const matching = availableVersions.filter(v => matchesTarget(v.version));
|
||||||
|
const latestVersion = matching
|
||||||
|
.filter(v => process.platform !== "linux" || lib.hasFactorioHeadless(v.version, "linux", arch))
|
||||||
.sort((v1, v2) => versionOrder(v1.version, v2.version))
|
.sort((v1, v2) => versionOrder(v1.version, v2.version))
|
||||||
[0];
|
[0];
|
||||||
|
|
||||||
if (!latestVersion) {
|
if (!latestVersion) {
|
||||||
|
if (matching.length && arch === "arm64" && process.platform === "linux") {
|
||||||
|
const installed = await listFactorioVersions(factorioDir);
|
||||||
|
if (!installed.direct && ![...installed.versions].some(matchesTarget)) {
|
||||||
|
throw new Error(
|
||||||
|
`Factorio ${targetVersion} has no ARM64 Linux headless build to download, ` +
|
||||||
|
`ARM64 builds start at ${lib.minimumArm64HeadlessVersion}. Install it manually ` +
|
||||||
|
`or use version ${lib.minimumArm64HeadlessVersion} or later.`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +264,7 @@ export async function checkForUpdates(
|
|||||||
logger.info(`A newer version of factorio is available (${v}), waiting for download...`);
|
logger.info(`A newer version of factorio is available (${v}), waiting for download...`);
|
||||||
} else {
|
} else {
|
||||||
logger.info(`A newer version of factorio is available (${v}), starting download...`);
|
logger.info(`A newer version of factorio is available (${v}), starting download...`);
|
||||||
download = downloadAndExtractTar(latestVersion.headlessUrl, dst).finally(() => {
|
download = downloadAndExtractTar(lib.factorioHeadlessUrl(v, "linux", arch), dst).finally(() => {
|
||||||
downloadsInProgress.delete(dst);
|
downloadsInProgress.delete(dst);
|
||||||
});
|
});
|
||||||
downloadsInProgress.set(dst, download);
|
downloadsInProgress.set(dst, download);
|
||||||
@@ -1155,9 +1177,8 @@ export class FactorioServer extends events.EventEmitter<FactorioServerEvents> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newWhitelist = new Set(newWhitelistJson);
|
const newWhitelist = new Set(newWhitelistJson);
|
||||||
// Set.difference added in node v22 and so we can not use this due to v20 support
|
const added = [...newWhitelist.difference(this._whitelist)];
|
||||||
const added = newWhitelistJson.filter(e => !this._whitelist.has(e));
|
const removed = [...this._whitelist.difference(newWhitelist)];
|
||||||
const removed = [...this._whitelist.values()].filter(e => !newWhitelist.has(e));
|
|
||||||
this._whitelist = newWhitelist;
|
this._whitelist = newWhitelist;
|
||||||
|
|
||||||
this.emit("whitelist-change", added, removed);
|
this.emit("whitelist-change", added, removed);
|
||||||
@@ -1735,8 +1756,8 @@ export class FactorioServer extends events.EventEmitter<FactorioServerEvents> {
|
|||||||
/**
|
/**
|
||||||
* Get Factorio binary path
|
* Get Factorio binary path
|
||||||
*
|
*
|
||||||
* Get the path to the factorio binary depending on the configuration
|
* Get the path to the factorio binary depending on the configuration,
|
||||||
* and or the platform (MacOS support)
|
* the platform (MacOS support) and the bin/x64 or bin/arm64 dir present
|
||||||
*
|
*
|
||||||
* @returns Path to factorio binary
|
* @returns Path to factorio binary
|
||||||
*/
|
*/
|
||||||
@@ -1747,7 +1768,16 @@ export class FactorioServer extends events.EventEmitter<FactorioServerEvents> {
|
|||||||
if (process.platform === "darwin") {
|
if (process.platform === "darwin") {
|
||||||
return this.dataPath("..", "MacOS", "factorio");
|
return this.dataPath("..", "MacOS", "factorio");
|
||||||
}
|
}
|
||||||
return this.dataPath("..", "bin", "x64", "factorio");
|
// Prefer the native build, fall back to whichever one is installed
|
||||||
|
const arches = factorioArch() === "arm64" ? ["arm64", "x64"] : ["x64", "arm64"];
|
||||||
|
for (const arch of arches) {
|
||||||
|
const binary = this.dataPath("..", "bin", arch, "factorio");
|
||||||
|
// eslint-disable-next-line node/no-sync
|
||||||
|
if (existsSync(binary)) {
|
||||||
|
return binary;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this.dataPath("..", "bin", arches[0], "factorio");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+52
-2
@@ -1,5 +1,5 @@
|
|||||||
import { Static, Type } from "@sinclair/typebox";
|
import { Static, Type } from "@sinclair/typebox";
|
||||||
import { FullVersionSchema, integerFullVersion, isFullVersion } from "../data/version.js";
|
import { FullVersion, FullVersionSchema, integerFullVersion, isFullVersion } from "../data/version.js";
|
||||||
|
|
||||||
const ARCHIVE_URL = "https://factorio.com/download/archive/";
|
const ARCHIVE_URL = "https://factorio.com/download/archive/";
|
||||||
|
|
||||||
@@ -9,11 +9,61 @@ const ARCHIVE_URL = "https://factorio.com/download/archive/";
|
|||||||
export const ExternalFactorioVersionSchema = Type.Object({
|
export const ExternalFactorioVersionSchema = Type.Object({
|
||||||
stable: Type.Boolean(),
|
stable: Type.Boolean(),
|
||||||
version: FullVersionSchema,
|
version: FullVersionSchema,
|
||||||
|
/** @deprecated Linux x64 only, use {@link factorioHeadlessUrl} instead. */
|
||||||
headlessUrl: Type.String(),
|
headlessUrl: Type.String(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type ExternalFactorioVersion = Static<typeof ExternalFactorioVersionSchema>;
|
export type ExternalFactorioVersion = Static<typeof ExternalFactorioVersionSchema>;
|
||||||
|
|
||||||
|
/** Platforms Factorio may publish headless builds for, named as in Node's process.platform */
|
||||||
|
export type FactorioHeadlessPlatform = "linux" | "win32";
|
||||||
|
|
||||||
|
/** CPU architectures Factorio may publish headless builds for, named as in Node's process.arch */
|
||||||
|
export type FactorioHeadlessArch = "x64" | "arm64";
|
||||||
|
|
||||||
|
/** First Factorio version with an ARM64 Linux headless build */
|
||||||
|
export const minimumArm64HeadlessVersion = "2.1.18";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if Factorio publishes a headless build of a version
|
||||||
|
*
|
||||||
|
* @param version - Factorio version to check.
|
||||||
|
* @param platform - Platform of the build.
|
||||||
|
* @param arch - CPU architecture of the build.
|
||||||
|
* @returns true if the build can be downloaded.
|
||||||
|
*/
|
||||||
|
export function hasFactorioHeadless(
|
||||||
|
version: FullVersion,
|
||||||
|
platform: FactorioHeadlessPlatform,
|
||||||
|
arch: FactorioHeadlessArch,
|
||||||
|
) {
|
||||||
|
if (platform !== "linux") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return arch === "x64" || integerFullVersion(version) >= integerFullVersion(minimumArm64HeadlessVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Download URL of the headless build of a Factorio version
|
||||||
|
*
|
||||||
|
* @param version - Factorio version to download.
|
||||||
|
* @param platform - Platform of the build.
|
||||||
|
* @param arch - CPU architecture of the build.
|
||||||
|
* @returns URL redirecting to the archive.
|
||||||
|
* @throws Error if Factorio has no headless build for the platform and arch.
|
||||||
|
*/
|
||||||
|
export function factorioHeadlessUrl(
|
||||||
|
version: FullVersion,
|
||||||
|
platform: FactorioHeadlessPlatform,
|
||||||
|
arch: FactorioHeadlessArch,
|
||||||
|
) {
|
||||||
|
if (!hasFactorioHeadless(version, platform, arch)) {
|
||||||
|
throw new Error(`Factorio ${version} has no headless build for ${platform} ${arch}`);
|
||||||
|
}
|
||||||
|
const build = arch === "arm64" ? "linux-arm64" : "linux64";
|
||||||
|
return `https://www.factorio.com/get-download/${version}/headless/${build}`;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch all factorio versions that support headless
|
* Fetch all factorio versions that support headless
|
||||||
*
|
*
|
||||||
@@ -60,7 +110,7 @@ function parseFactorioVersions(html: string): ExternalFactorioVersion[] {
|
|||||||
versions.set(version, {
|
versions.set(version, {
|
||||||
version: version,
|
version: version,
|
||||||
stable: kind === "stable",
|
stable: kind === "stable",
|
||||||
headlessUrl: `https://www.factorio.com/get-download/${version}/headless/linux64`,
|
headlessUrl: factorioHeadlessUrl(version, "linux", "x64"),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import type { PermissionDefinition } from "./permissions.js";
|
|||||||
import type { PlayerStats, Role } from "./data/index.js";
|
import type { PlayerStats, Role } from "./data/index.js";
|
||||||
import type { SyncHook } from "./SyncHook.js";
|
import type { SyncHook } from "./SyncHook.js";
|
||||||
import type { ErrorClass } from "./link/index.js";
|
import type { ErrorClass } from "./link/index.js";
|
||||||
|
import { ModDependency } from "./data/ModInfo.js";
|
||||||
|
|
||||||
export const PluginFeatureFlags = [
|
export const PluginFeatureFlags = [
|
||||||
/** The plugin requires module code to be patched into the save */
|
/** The plugin requires module code to be patched into the save */
|
||||||
@@ -41,6 +42,11 @@ export type PluginDeclaration = {
|
|||||||
migrationEntrypoint?: string;
|
migrationEntrypoint?: string;
|
||||||
|
|
||||||
features?: (typeof PluginFeatureFlags)[number][];
|
features?: (typeof PluginFeatureFlags)[number][];
|
||||||
|
/**
|
||||||
|
* Factorio mods the plugin needs in the instance's mod pack, as Factorio
|
||||||
|
* dependency strings like `"subspace_storage >= 2.3.0"`.
|
||||||
|
*/
|
||||||
|
requiredMods?: string[];
|
||||||
|
|
||||||
messages?: any[];
|
messages?: any[];
|
||||||
errors?: ErrorClass[];
|
errors?: ErrorClass[];
|
||||||
@@ -65,6 +71,23 @@ export function pluginNeedsWebBuild(info: PluginDeclaration) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the requiredMods of a plugin
|
||||||
|
*
|
||||||
|
* A mod listed more than once must satisfy every entry, which gives a range.
|
||||||
|
*
|
||||||
|
* @throws Error if an entry is invalid or has a dependency prefix.
|
||||||
|
*/
|
||||||
|
export function pluginRequiredMods(pluginInfo: PluginDeclaration) {
|
||||||
|
return (pluginInfo.requiredMods ?? []).map(spec => {
|
||||||
|
const dependency = new ModDependency(spec);
|
||||||
|
if (dependency.type !== "required") {
|
||||||
|
throw new Error(`requiredMods entry "${spec}" can not have a dependency prefix`);
|
||||||
|
}
|
||||||
|
return dependency;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export type PluginNodeEnvInfo = PluginDeclaration & {
|
export type PluginNodeEnvInfo = PluginDeclaration & {
|
||||||
/**
|
/**
|
||||||
* Path to the folder with the static files that should be hosted on the web
|
* Path to the folder with the static files that should be hosted on the web
|
||||||
|
|||||||
@@ -84,6 +84,12 @@ export async function loadPluginInfos(pluginList: Map<string, string>, skippedNp
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
libPlugin.pluginRequiredMods(pluginInfo);
|
||||||
|
} catch (err: any) {
|
||||||
|
throw new libErrors.PluginError(pluginName, err);
|
||||||
|
}
|
||||||
|
|
||||||
// migrate: ignore incompatible old plugins
|
// migrate: ignore incompatible old plugins
|
||||||
if (pluginInfo.messages && !(pluginInfo.messages instanceof Array)) {
|
if (pluginInfo.messages && !(pluginInfo.messages instanceof Array)) {
|
||||||
logger.warn(`Ignoring incompatible pre alpha.14 plugin ${pluginName}`);
|
logger.warn(`Ignoring incompatible pre alpha.14 plugin ${pluginName}`);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { InvalidFieldError, InvalidValueError } from "./errors.js";
|
|||||||
import { logger } from "./logging.js";
|
import { logger } from "./logging.js";
|
||||||
import * as libHelpers from "./helpers.js";
|
import * as libHelpers from "./helpers.js";
|
||||||
import { LockFile } from "./LockFile.js";
|
import { LockFile } from "./LockFile.js";
|
||||||
|
import { LineSplitter } from "./stream.js";
|
||||||
import { pathToFileURL } from "url";
|
import { pathToFileURL } from "url";
|
||||||
|
|
||||||
|
|
||||||
@@ -88,11 +89,21 @@ function npmInstall(packageSpec: string) {
|
|||||||
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
|
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
const child = spawn(npm, ["install", "--save", "--no-audit", "--no-fund", packageSpec], {
|
const child = spawn(npm, ["install", "--save", "--no-audit", "--no-fund", packageSpec], {
|
||||||
stdio: "inherit",
|
stdio: ["ignore", "pipe", "pipe"],
|
||||||
shell: process.platform === "win32",
|
shell: process.platform === "win32",
|
||||||
});
|
});
|
||||||
|
for (const [output, level] of [[child.stdout, "info"], [child.stderr, "warn"]] as const) {
|
||||||
|
const lines = new LineSplitter({ readableObjectMode: true });
|
||||||
|
lines.on("data", (line: Buffer) => {
|
||||||
|
const text = line.toString("utf8").trimEnd();
|
||||||
|
if (text) {
|
||||||
|
logger.log(level, text);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
output.pipe(lines);
|
||||||
|
}
|
||||||
child.on("error", reject);
|
child.on("error", reject);
|
||||||
child.on("exit", code => {
|
child.on("close", code => {
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -4,5 +4,7 @@
|
|||||||
"exclude": ["src/**/*.browser.ts"],
|
"exclude": ["src/**/*.browser.ts"],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
|
// SubscriptionFilters.union clashes with the native Set.union
|
||||||
|
"lib": ["es2024"],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, {useContext, useState} from "react";
|
import React, {useContext, useState} from "react";
|
||||||
import { Descriptions, Flex, Popconfirm, Space, Tooltip, Typography } from "antd";
|
import { Descriptions, Flex, Modal, Popconfirm, Space, Tooltip, Typography } from "antd";
|
||||||
import { ExclamationCircleOutlined } from "@ant-design/icons";
|
import { ExclamationCircleOutlined } from "@ant-design/icons";
|
||||||
|
|
||||||
import * as lib from "@clusterio/lib";
|
import * as lib from "@clusterio/lib";
|
||||||
@@ -28,6 +28,7 @@ type ControllerControlButtonProps = { canRestart?: boolean, restartRequired?: bo
|
|||||||
function ControllerControlButton({ canRestart, restartRequired }: ControllerControlButtonProps) {
|
function ControllerControlButton({ canRestart, restartRequired }: ControllerControlButtonProps) {
|
||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
const control = useContext(ControlContext);
|
const control = useContext(ControlContext);
|
||||||
|
const [modal, modalContext] = Modal.useModal();
|
||||||
const actions: VariableDropdownButtonProps["actions"] = [];
|
const actions: VariableDropdownButtonProps["actions"] = [];
|
||||||
|
|
||||||
if (account.hasPermission("core.controller.restart") && canRestart) {
|
if (account.hasPermission("core.controller.restart") && canRestart) {
|
||||||
@@ -40,9 +41,18 @@ function ControllerControlButton({ canRestart, restartRequired }: ControllerCont
|
|||||||
</Space></Tooltip>
|
</Space></Tooltip>
|
||||||
),
|
),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
control.send(
|
modal.confirm({
|
||||||
new lib.ControllerRestartRequest()
|
title: "Restart the controller?",
|
||||||
).catch(notifyErrorHandler("Error restarting controller"));
|
content: "Hosts and this page lose their connection until the controller is back.",
|
||||||
|
okText: "Restart",
|
||||||
|
okButtonProps: { danger: true },
|
||||||
|
autoFocusButton: "cancel",
|
||||||
|
onOk: () => {
|
||||||
|
control.send(
|
||||||
|
new lib.ControllerRestartRequest()
|
||||||
|
).catch(notifyErrorHandler("Error restarting controller"));
|
||||||
|
},
|
||||||
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -87,7 +97,10 @@ function ControllerControlButton({ canRestart, restartRequired }: ControllerCont
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return <VariableDropdownButton actions={actions} />;
|
return <>
|
||||||
|
<VariableDropdownButton actions={actions} />
|
||||||
|
{modalContext}
|
||||||
|
</>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useContext, useState } from "react";
|
import React, { useContext, useState } from "react";
|
||||||
import { Descriptions, Typography, Button, Space, Popconfirm, Flex, Tooltip } from "antd";
|
import { Descriptions, Typography, Button, Space, Popconfirm, Flex, Tooltip, Modal } from "antd";
|
||||||
import { ExclamationCircleOutlined } from "@ant-design/icons";
|
import { ExclamationCircleOutlined } from "@ant-design/icons";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
|
|
||||||
@@ -29,11 +29,17 @@ import VariableDropdownButton, { VariableDropdownButtonProps } from "./VariableD
|
|||||||
|
|
||||||
const { Title } = Typography;
|
const { Title } = Typography;
|
||||||
|
|
||||||
type HostControlButtonProps = { hostId: number, canRestart?: boolean, restartRequired?: boolean };
|
type HostControlButtonProps = {
|
||||||
|
hostId: number,
|
||||||
|
instances: ReadonlyMap<number, lib.InstanceDetails>,
|
||||||
|
canRestart?: boolean,
|
||||||
|
restartRequired?: boolean,
|
||||||
|
};
|
||||||
|
|
||||||
function HostControlButton({ hostId, canRestart, restartRequired }: HostControlButtonProps) {
|
function HostControlButton({ hostId, instances, canRestart, restartRequired }: HostControlButtonProps) {
|
||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
const control = useContext(ControlContext);
|
const control = useContext(ControlContext);
|
||||||
|
const [modal, modalContext] = Modal.useModal();
|
||||||
const actions: VariableDropdownButtonProps["actions"] = [];
|
const actions: VariableDropdownButtonProps["actions"] = [];
|
||||||
|
|
||||||
if (account.hasPermission("core.host.restart") && canRestart) {
|
if (account.hasPermission("core.host.restart") && canRestart) {
|
||||||
@@ -46,10 +52,28 @@ function HostControlButton({ hostId, canRestart, restartRequired }: HostControlB
|
|||||||
</Space></Tooltip>
|
</Space></Tooltip>
|
||||||
),
|
),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
control.sendTo(
|
const running = [...instances.values()]
|
||||||
{ hostId },
|
.filter(instance => !["unknown", "unassigned", "stopped", "deleted"].includes(instance.status))
|
||||||
new lib.HostRestartRequest()
|
.map(instance => instance.name);
|
||||||
).catch(notifyErrorHandler("Error restarting host"));
|
modal.confirm({
|
||||||
|
title: "Restart the host?",
|
||||||
|
content: running.length
|
||||||
|
? <>
|
||||||
|
This stops {running.length} running {running.length === 1 ? "instance" : "instances"}:
|
||||||
|
{" "}{running.join(", ")}.<br />
|
||||||
|
They stay stopped after the restart unless instance.auto_start is enabled.
|
||||||
|
</>
|
||||||
|
: "No instances are running on this host.",
|
||||||
|
okText: "Restart",
|
||||||
|
okButtonProps: { danger: true },
|
||||||
|
autoFocusButton: "cancel",
|
||||||
|
onOk: () => {
|
||||||
|
control.sendTo(
|
||||||
|
{ hostId },
|
||||||
|
new lib.HostRestartRequest()
|
||||||
|
).catch(notifyErrorHandler("Error restarting host"));
|
||||||
|
},
|
||||||
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -96,7 +120,10 @@ function HostControlButton({ hostId, canRestart, restartRequired }: HostControlB
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return <VariableDropdownButton actions={actions} />;
|
return <>
|
||||||
|
<VariableDropdownButton actions={actions} />
|
||||||
|
{modalContext}
|
||||||
|
</>;
|
||||||
}
|
}
|
||||||
|
|
||||||
type RevokeHostButtonProps = { host: lib.HostDetails, instances: ReadonlyMap<number, lib.InstanceDetails> };
|
type RevokeHostButtonProps = { host: lib.HostDetails, instances: ReadonlyMap<number, lib.InstanceDetails> };
|
||||||
@@ -146,7 +173,12 @@ export default function HostViewPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let hostButtons = <Space wrap>
|
let hostButtons = <Space wrap>
|
||||||
<HostControlButton hostId={hostId} canRestart={system?.canRestart} restartRequired={system?.restartRequired}/>
|
<HostControlButton
|
||||||
|
hostId={hostId}
|
||||||
|
instances={hostInstances}
|
||||||
|
canRestart={system?.canRestart}
|
||||||
|
restartRequired={system?.restartRequired}
|
||||||
|
/>
|
||||||
{account.hasPermission("core.host.revoke") && <RevokeHostButton host={host} instances={hostInstances} />}
|
{account.hasPermission("core.host.revoke") && <RevokeHostButton host={host} instances={hostInstances} />}
|
||||||
{canShowNpm && (
|
{canShowNpm && (
|
||||||
<NpmButton target={{ hostId }} canRestart={system?.canRestart} disabled={!host["connected"]}/>
|
<NpmButton target={{ hostId }} canRestart={system?.canRestart} disabled={!host["connected"]}/>
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ function InstanceButtons(props: { instance: lib.InstanceDetails }) {
|
|||||||
function confirmDelete() {
|
function confirmDelete() {
|
||||||
Modal.confirm({
|
Modal.confirm({
|
||||||
autoFocusButton: "cancel",
|
autoFocusButton: "cancel",
|
||||||
content: "Permamently delete instance and server saves?",
|
content: "Permanently delete instance and server saves?",
|
||||||
okText: "Delete",
|
okText: "Delete",
|
||||||
okButtonProps: { danger: true },
|
okButtonProps: { danger: true },
|
||||||
onOk: () => {
|
onOk: () => {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import * as lib from "@clusterio/lib";
|
|||||||
|
|
||||||
import { useAccount } from "../model/account";
|
import { useAccount } from "../model/account";
|
||||||
import { useMods } from "../model/mods";
|
import { useMods } from "../model/mods";
|
||||||
import { useModPacks } from "../model/mod_pack";
|
import { useDefaultModPack, useModPacks } from "../model/mod_pack";
|
||||||
import { notifyErrorHandler } from "../util/notify";
|
import { notifyErrorHandler } from "../util/notify";
|
||||||
import ControlContext from "./ControlContext";
|
import ControlContext from "./ControlContext";
|
||||||
import PageHeader from "./PageHeader";
|
import PageHeader from "./PageHeader";
|
||||||
@@ -143,6 +143,16 @@ function CreateModPackButton() {
|
|||||||
</>;
|
</>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function defaultSearchVersion(modPack?: lib.ModPack): lib.MajorMinorVersion {
|
||||||
|
if (modPack) {
|
||||||
|
const version = lib.normaliseMajorMinorVersion(modPack.factorioVersion);
|
||||||
|
if ((lib.ApiVersions as readonly string[]).includes(version)) {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return lib.ApiVersions[lib.ApiVersions.length - 1];
|
||||||
|
}
|
||||||
|
|
||||||
function SearchModsButton() {
|
function SearchModsButton() {
|
||||||
const control = useContext(ControlContext);
|
const control = useContext(ControlContext);
|
||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
@@ -150,7 +160,9 @@ function SearchModsButton() {
|
|||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const nameInputRef = useRef<InputRef>(null);
|
const nameInputRef = useRef<InputRef>(null);
|
||||||
const [searchText, setSearchText] = useState("");
|
const [searchText, setSearchText] = useState("");
|
||||||
const [factorioVersion, setFactorioVersion] = useState<lib.MajorMinorVersion>("2.0");
|
const defaultModPack = useDefaultModPack();
|
||||||
|
const [pickedVersion, setPickedVersion] = useState<lib.MajorMinorVersion>();
|
||||||
|
const factorioVersion = pickedVersion ?? defaultSearchVersion(defaultModPack);
|
||||||
|
|
||||||
// State for all mods fetched from backend
|
// State for all mods fetched from backend
|
||||||
const [allMods, setAllMods] = useState<ModPortalModType[]>([]);
|
const [allMods, setAllMods] = useState<ModPortalModType[]>([]);
|
||||||
@@ -274,22 +286,20 @@ function SearchModsButton() {
|
|||||||
return filtered.length;
|
return filtered.length;
|
||||||
}, [allMods, searchText]);
|
}, [allMods, searchText]);
|
||||||
|
|
||||||
// Update search text and factorio version from form
|
// Update search text from form
|
||||||
const handleSearch = (changedValues: any, allValues: any) => {
|
const handleSearch = (changedValues: any, allValues: any) => {
|
||||||
const nameValue = allValues.name;
|
const nameValue = allValues.name;
|
||||||
const versionValue = allValues.factorioVersion as lib.MajorMinorVersion | undefined;
|
|
||||||
|
|
||||||
// Only trigger state updates if values actually changed
|
|
||||||
if (nameValue !== searchText) {
|
if (nameValue !== searchText) {
|
||||||
setSearchText(nameValue || "");
|
setSearchText(nameValue || "");
|
||||||
|
setPage(1);
|
||||||
}
|
}
|
||||||
if (versionValue && versionValue !== factorioVersion) {
|
};
|
||||||
setFactorioVersion(versionValue);
|
|
||||||
|
const handleVersionChange = (version: lib.MajorMinorVersion) => {
|
||||||
|
if (version !== factorioVersion) {
|
||||||
|
setPickedVersion(version);
|
||||||
setAllMods([]); // Clear mods when version changes, useEffect will fetch new ones
|
setAllMods([]); // Clear mods when version changes, useEffect will fetch new ones
|
||||||
setLoading(true); // Show loading indicator immediately
|
setLoading(true); // Show loading indicator immediately
|
||||||
}
|
|
||||||
// Reset page only if search text or version changed
|
|
||||||
if (nameValue !== searchText || (versionValue && versionValue !== factorioVersion)) {
|
|
||||||
setPage(1);
|
setPage(1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -349,16 +359,13 @@ function SearchModsButton() {
|
|||||||
labelCol={{ span: 6 }}
|
labelCol={{ span: 6 }}
|
||||||
wrapperCol={{ span: 18 }}
|
wrapperCol={{ span: 18 }}
|
||||||
onValuesChange={handleSearch}
|
onValuesChange={handleSearch}
|
||||||
initialValues={{ factorioVersion: factorioVersion, name: searchText }}
|
initialValues={{ name: searchText }}
|
||||||
>
|
>
|
||||||
<Form.Item name="name" label="Filter by Name or Title">
|
<Form.Item name="name" label="Filter by Name or Title">
|
||||||
<Input ref={nameInputRef} placeholder="Start typing to filter..." />
|
<Input ref={nameInputRef} placeholder="Start typing to filter..." />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item
|
<Form.Item label="Factorio Version">
|
||||||
name="factorioVersion"
|
<Select value={factorioVersion} onChange={handleVersionChange}>
|
||||||
label="Factorio Version"
|
|
||||||
>
|
|
||||||
<Select>
|
|
||||||
{lib.ApiVersions.map(version => (
|
{lib.ApiVersions.map(version => (
|
||||||
<Select.Option key={version} value={version}>
|
<Select.Option key={version} value={version}>
|
||||||
{version}
|
{version}
|
||||||
|
|||||||
@@ -172,10 +172,12 @@ export function PluginVersions(props: { status: PluginStatus, latest?: string })
|
|||||||
{versions.map(version => {
|
{versions.map(version => {
|
||||||
const now = count(machine => machine.running === version);
|
const now = count(machine => machine.running === version);
|
||||||
const after = count(machine => machine.afterRestart === version);
|
const after = count(machine => machine.afterRestart === version);
|
||||||
return <div key={version}>
|
return <div key={version} className="plugin-version">
|
||||||
<Text>{version}</Text>
|
<span>
|
||||||
{props.latest === version && <Tag color="success" style={{ marginLeft: 6 }}>latest</Tag>}
|
<Text>{version}</Text>
|
||||||
<Text type="secondary" style={{ marginLeft: 12 }}>
|
{props.latest === version && <Tag color="success" style={{ marginLeft: 6 }}>latest</Tag>}
|
||||||
|
</span>
|
||||||
|
<Text type="secondary">
|
||||||
{plural(now, "machine")}{now !== after && ` → ${after} after restart`}
|
{plural(now, "machine")}{now !== after && ` → ${after} after restart`}
|
||||||
</Text>
|
</Text>
|
||||||
</div>;
|
</div>;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useContext, useEffect, useState } from "react";
|
import React, { useContext, useEffect, useState } from "react";
|
||||||
import { Space, Table, Tooltip, Typography } from "antd";
|
import { Grid, Space, Table, Tooltip, Typography } from "antd";
|
||||||
import CloseCircleFilled from "@ant-design/icons/CloseCircleFilled";
|
import CloseCircleFilled from "@ant-design/icons/CloseCircleFilled";
|
||||||
|
|
||||||
import type { PluginWebApi } from "@clusterio/lib";
|
import type { PluginWebApi } from "@clusterio/lib";
|
||||||
@@ -48,6 +48,8 @@ function WebError(props: { error: string }) {
|
|||||||
export default function PluginsPage() {
|
export default function PluginsPage() {
|
||||||
const control = useContext(ControlContext);
|
const control = useContext(ControlContext);
|
||||||
const account = useAccount();
|
const account = useAccount();
|
||||||
|
const screens = Grid.useBreakpoint();
|
||||||
|
const isMobile = screens.md === false;
|
||||||
let [pluginList, setPluginList] = useState<PluginWebApi[]>([]);
|
let [pluginList, setPluginList] = useState<PluginWebApi[]>([]);
|
||||||
const tableState = useTableQueryState<PluginRow>({
|
const tableState = useTableQueryState<PluginRow>({
|
||||||
namespace: "plugin", defaultSortKey: "name",
|
namespace: "plugin", defaultSortKey: "name",
|
||||||
@@ -96,6 +98,24 @@ export default function PluginsPage() {
|
|||||||
const latestOf = (plugin: PluginRow) => (
|
const latestOf = (plugin: PluginRow) => (
|
||||||
plugin.status?.npmPackage ? latestVersions[plugin.status.npmPackage] : undefined
|
plugin.status?.npmPackage ? latestVersions[plugin.status.npmPackage] : undefined
|
||||||
);
|
);
|
||||||
|
const versions = (plugin: PluginRow) => <>
|
||||||
|
{plugin.status
|
||||||
|
? <PluginVersions status={plugin.status} latest={latestOf(plugin)} />
|
||||||
|
: plugin.meta?.version}
|
||||||
|
{plugin.webError && <WebError error={plugin.webError} />}
|
||||||
|
</>;
|
||||||
|
const updateAction = (plugin: PluginRow) => (plugin.status
|
||||||
|
// Keep clicks on the update action from opening the plugin.
|
||||||
|
? <span onClick={event => { event.stopPropagation(); }}>
|
||||||
|
<PluginUpdateButton
|
||||||
|
status={plugin.status}
|
||||||
|
title={plugin.title}
|
||||||
|
latest={latestOf(plugin)}
|
||||||
|
installer={installer}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
: null
|
||||||
|
);
|
||||||
|
|
||||||
return <PageLayout nav={[{ name: "Plugins" }]}>
|
return <PageLayout nav={[{ name: "Plugins" }]}>
|
||||||
<PageHeader
|
<PageHeader
|
||||||
@@ -115,14 +135,22 @@ export default function PluginsPage() {
|
|||||||
</Space>}
|
</Space>}
|
||||||
/>
|
/>
|
||||||
<Table
|
<Table
|
||||||
|
className="plugins-table"
|
||||||
|
tableLayout={isMobile ? "fixed" : "auto"}
|
||||||
columns={[
|
columns={[
|
||||||
{
|
{
|
||||||
title: "Name",
|
title: "Name",
|
||||||
key: "name",
|
key: "name",
|
||||||
className: "table-link-cell",
|
className: "table-link-cell",
|
||||||
render: (_, plugin) => <Link to={pluginPath(plugin)} style={{ color: "inherit" }}>
|
render: (_, plugin) => <>
|
||||||
{plugin.title}
|
<Link to={pluginPath(plugin)} style={{ color: "inherit" }}>
|
||||||
</Link>,
|
{plugin.title}
|
||||||
|
</Link>
|
||||||
|
{isMobile && <div className="plugin-mobile-details">
|
||||||
|
<div>{versions(plugin)}</div>
|
||||||
|
{updateAction(plugin)}
|
||||||
|
</div>}
|
||||||
|
</>,
|
||||||
sorter: (a, b) => strcmp(a.title, b.title),
|
sorter: (a, b) => strcmp(a.title, b.title),
|
||||||
sortOrder: tableState.sortOrder("name"),
|
sortOrder: tableState.sortOrder("name"),
|
||||||
filteredValue: tableState.filteredValue("name"),
|
filteredValue: tableState.filteredValue("name"),
|
||||||
@@ -131,28 +159,14 @@ export default function PluginsPage() {
|
|||||||
{
|
{
|
||||||
title: "Versions",
|
title: "Versions",
|
||||||
key: "versions",
|
key: "versions",
|
||||||
render: (_, plugin) => <>
|
responsive: ["md"],
|
||||||
{plugin.status
|
render: (_, plugin) => versions(plugin),
|
||||||
? <PluginVersions status={plugin.status} latest={latestOf(plugin)} />
|
|
||||||
: plugin.meta?.version}
|
|
||||||
{plugin.webError && <WebError error={plugin.webError} />}
|
|
||||||
</>,
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: "actions",
|
key: "actions",
|
||||||
align: "right",
|
align: "right",
|
||||||
render: (_, plugin) => (plugin.status
|
responsive: ["md"],
|
||||||
// Keep clicks on the update action from opening the plugin
|
render: (_, plugin) => updateAction(plugin),
|
||||||
? <span onClick={event => { event.stopPropagation(); }}>
|
|
||||||
<PluginUpdateButton
|
|
||||||
status={plugin.status}
|
|
||||||
title={plugin.title}
|
|
||||||
latest={latestOf(plugin)}
|
|
||||||
installer={installer}
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
: null
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
dataSource={tableContents}
|
dataSource={tableContents}
|
||||||
|
|||||||
@@ -169,8 +169,10 @@ export default function SiteLayout() {
|
|||||||
/>;
|
/>;
|
||||||
|
|
||||||
let accountMenu = <Dropdown menu={accountMenuProps} trigger={["click"]} placement="bottomRight">
|
let accountMenu = <Dropdown menu={accountMenuProps} trigger={["click"]} placement="bottomRight">
|
||||||
<Button type="text" icon={<UserOutlined />} style={{ marginInlineStart: "auto" }}>
|
<Button type="text" icon={<UserOutlined />} style={{ marginInlineStart: "auto" }}
|
||||||
{account.name}
|
aria-label={`Account menu for ${account.name}`}
|
||||||
|
>
|
||||||
|
<span className="site-layout-account-name">{account.name}</span>
|
||||||
</Button>
|
</Button>
|
||||||
</Dropdown>;
|
</Dropdown>;
|
||||||
|
|
||||||
@@ -228,7 +230,7 @@ export default function SiteLayout() {
|
|||||||
<Link to="/" style={{ display: "flex", alignItems: "center" }}>
|
<Link to="/" style={{ display: "flex", alignItems: "center" }}>
|
||||||
<img src={logo} width={56} height={56} alt="Clusterio logo" />
|
<img src={logo} width={56} height={56} alt="Clusterio logo" />
|
||||||
</Link>
|
</Link>
|
||||||
<Flex vertical justify="center">
|
<Flex vertical justify="center" className="site-layout-brand">
|
||||||
<Typography.Title level={4} style={{ margin: 0, lineHeight: 1.2 }}>Clusterio</Typography.Title>
|
<Typography.Title level={4} style={{ margin: 0, lineHeight: 1.2 }}>Clusterio</Typography.Title>
|
||||||
<Tooltip title="View changelog" placement="right">
|
<Tooltip title="View changelog" placement="right">
|
||||||
<Typography.Text
|
<Typography.Text
|
||||||
|
|||||||
@@ -72,6 +72,38 @@ body {
|
|||||||
background: #001529;
|
background: #001529;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.site-layout-brand {
|
||||||
|
flex-shrink: 0;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 767px) {
|
||||||
|
.site-layout-account-name {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.plugins-table .table-link-cell > a {
|
||||||
|
font-weight: 600;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.plugin-mobile-details {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 12px;
|
||||||
|
margin-top: 8px;
|
||||||
|
overflow-wrap: anywhere;
|
||||||
|
}
|
||||||
|
|
||||||
|
.plugin-version {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: baseline;
|
||||||
|
column-gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
/* Keep the sidebar fixed in place (below the header) while content scrolls. */
|
/* Keep the sidebar fixed in place (below the header) while content scrolls. */
|
||||||
.site-layout-sider {
|
.site-layout-sider {
|
||||||
position: sticky;
|
position: sticky;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ As a player, it mostly just works. Most important to know is that factorio data
|
|||||||
|
|
||||||
A note on crashing servers:
|
A note on crashing servers:
|
||||||
|
|
||||||
When a server crashes while you are online there won't be time to immediately upload the inventory. Instead, the inventory is uploaded as soon as the server restarts. This means if you have been playing on a different server from the one that crashed and gathered/consumed items but are offline at the time of the first server coming online again your inventory will reset to the autosave.
|
When a server crashes while you are online there won't be time to immediately upload the inventory. Instead, the inventory is uploaded as soon as the server restarts. If you have been playing on a different server in the meantime the controller keeps what that server uploaded, and the crashed server downloads it the next time you join it.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
|||||||
@@ -258,6 +258,7 @@ export default async function(context: ControllerPluginContext) {
|
|||||||
prefetch(instanceId, request.destinationInstanceId, merged);
|
prefetch(instanceId, request.destinationInstanceId, merged);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return new msg.UploadRequest.Response(store);
|
||||||
});
|
});
|
||||||
|
|
||||||
controller.handle(msg.DownloadRequest, async (request: msg.DownloadRequest) => {
|
controller.handle(msg.DownloadRequest, async (request: msg.DownloadRequest) => {
|
||||||
|
|||||||
@@ -200,11 +200,12 @@ export default async function(context: InstancePluginContext) {
|
|||||||
delete player_data.destination_instance_id;
|
delete player_data.destination_instance_id;
|
||||||
|
|
||||||
logger.verbose(`Uploading ${player_data.name} (${JSON.stringify(player_data).length / 1000}kB)`);
|
logger.verbose(`Uploading ${player_data.name} (${JSON.stringify(player_data).length / 1000}kB)`);
|
||||||
|
let stored: boolean;
|
||||||
try {
|
try {
|
||||||
await instance.sendTo(
|
({ stored } = await instance.sendTo(
|
||||||
"controller",
|
"controller",
|
||||||
new UploadRequest(instance.id, player_data.name, player_data, destinationInstanceId),
|
new UploadRequest(instance.id, player_data.name, player_data, destinationInstanceId),
|
||||||
);
|
));
|
||||||
|
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (!(err instanceof lib.SessionLost)) {
|
if (!(err instanceof lib.SessionLost)) {
|
||||||
@@ -213,8 +214,10 @@ export default async function(context: InstancePluginContext) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A copy the controller did not store must not pass for the stored one: the save downloads at the next join
|
||||||
|
const reply = stored ? "confirm_upload" : "reject_upload";
|
||||||
await instance.sendRcon(
|
await instance.sendRcon(
|
||||||
`/sc player_sync.confirm_upload("${player_data.name}", ${player_data.generation})`, true, plugin.name
|
`/sc player_sync.${reply}("${player_data.name}", ${player_data.generation})`, true, plugin.name
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -262,12 +262,30 @@ export class ReleaseRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class UploadResponse {
|
||||||
|
constructor(
|
||||||
|
/** False when the controller kept what it has: another copy is newer, locked or from another epoch */
|
||||||
|
public stored: boolean,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// No type: a controller from before this response replies with nothing, which counts as stored
|
||||||
|
static jsonSchema = Type.Unsafe<{ stored: boolean } | undefined>({
|
||||||
|
properties: { "stored": { type: "boolean" } },
|
||||||
|
});
|
||||||
|
|
||||||
|
static fromJSON(json: Static<typeof UploadResponse.jsonSchema>) {
|
||||||
|
return new this(json?.stored ?? true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export class UploadRequest {
|
export class UploadRequest {
|
||||||
declare ["constructor"]: typeof UploadRequest;
|
declare ["constructor"]: typeof UploadRequest;
|
||||||
static type = "request" as const;
|
static type = "request" as const;
|
||||||
static src = "instance" as const;
|
static src = "instance" as const;
|
||||||
static dst = "controller" as const;
|
static dst = "controller" as const;
|
||||||
static plugin = "player_sync" as const;
|
static plugin = "player_sync" as const;
|
||||||
|
static Response = UploadResponse;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public instanceId: number,
|
public instanceId: number,
|
||||||
|
|||||||
@@ -384,12 +384,14 @@ function player_sync.check_players_in_cutscene()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Whether a join should take the stored data: there is some, and this save hasn't synced the player in that epoch at
|
-- Whether a join should take the stored data: there is some, and this save hasn't synced the player in that epoch at
|
||||||
-- that generation or newer with every component synced here now. A player without a record here has nothing to keep.
|
-- that generation or newer with every component synced here now, or the controller did not store its last upload
|
||||||
|
-- (reject_upload). A player without a record here has nothing to keep.
|
||||||
local function download_needed(player_record, acquire_response, script_data)
|
local function download_needed(player_record, acquire_response, script_data)
|
||||||
return acquire_response.has_data
|
return acquire_response.has_data
|
||||||
and (
|
and (
|
||||||
not player_record
|
not player_record
|
||||||
or not player_record.sync
|
or not player_record.sync
|
||||||
|
or player_record.outdated
|
||||||
or (player_record.epoch or 0) ~= (acquire_response.epoch or 0)
|
or (player_record.epoch or 0) ~= (acquire_response.epoch or 0)
|
||||||
or acquire_response.generation > player_record.generation
|
or acquire_response.generation > player_record.generation
|
||||||
or serialize.newly_synced(player_record.components, script_data.components)
|
or serialize.newly_synced(player_record.components, script_data.components)
|
||||||
@@ -543,6 +545,8 @@ function player_sync.sync_player(acquire_response)
|
|||||||
start_sync(player_record, script_data.components)
|
start_sync(player_record, script_data.components)
|
||||||
player_record.dirty = true
|
player_record.dirty = true
|
||||||
player_record.sync_in_progress = false
|
player_record.sync_in_progress = false
|
||||||
|
-- Nothing stored to download: the copy here is all there is
|
||||||
|
player_record.outdated = nil
|
||||||
-- Deleted data keeps its generation and epoch so the next upload is accepted as the new baseline
|
-- Deleted data keeps its generation and epoch so the next upload is accepted as the new baseline
|
||||||
player_record.epoch = epoch
|
player_record.epoch = epoch
|
||||||
-- A copy from another epoch has nothing to do with the stored generation
|
-- A copy from another epoch has nothing to do with the stored generation
|
||||||
@@ -573,6 +577,7 @@ function player_sync.finish_download(player, finished_record)
|
|||||||
|
|
||||||
player_record.dirty = true
|
player_record.dirty = true
|
||||||
player_record.sync_in_progress = false
|
player_record.sync_in_progress = false
|
||||||
|
player_record.outdated = nil
|
||||||
start_sync(player_record, finished_record.components)
|
start_sync(player_record, finished_record.components)
|
||||||
player_record.generation = finished_record.generation
|
player_record.generation = finished_record.generation
|
||||||
player_record.epoch = finished_record.epoch
|
player_record.epoch = finished_record.epoch
|
||||||
@@ -634,6 +639,7 @@ player_sync.on_nth_tick[33] = function(event)
|
|||||||
player_sync.check_players_in_cutscene()
|
player_sync.check_players_in_cutscene()
|
||||||
player_sync.check_active_downloads()
|
player_sync.check_active_downloads()
|
||||||
player_sync.check_active_uploads()
|
player_sync.check_active_uploads()
|
||||||
|
player_sync.check_missing_quick_bar_records()
|
||||||
end
|
end
|
||||||
|
|
||||||
player_sync.events[defines.events.on_cutscene_waypoint_reached] = function(event)
|
player_sync.events[defines.events.on_cutscene_waypoint_reached] = function(event)
|
||||||
@@ -724,6 +730,32 @@ function player_sync.confirm_upload(player_name, generation)
|
|||||||
player_record.dirty = false
|
player_record.dirty = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Invoked by the instance code when the controller did not store the uploaded data: it holds another copy that is
|
||||||
|
-- newer, locked by another instance or from another epoch. This save's copy lost, even at the same generation, so it
|
||||||
|
-- is not uploaded again and the next join downloads. A retry of an upload the controller already stored ends up here
|
||||||
|
-- too, and then downloads what this save sent.
|
||||||
|
function player_sync.reject_upload(player_name, generation)
|
||||||
|
local player = game.get_player(player_name)
|
||||||
|
if not player then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local script_data = get_script_data()
|
||||||
|
-- A player who is back already still waits for the acquire reply, which the controller sent after this one, and
|
||||||
|
-- that join then downloads. Past that reply the join has decided and this is not about the copy here any more.
|
||||||
|
if player.connected and not script_data.players_waiting_for_acquire[player_name] then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local player_record = script_data.players[player.name]
|
||||||
|
if not player_record or player_record.generation ~= generation then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
log("Upload of " .. player_name .. " was not stored, the next join downloads")
|
||||||
|
script_data.active_uploads[player_name] = nil
|
||||||
|
player_record.dirty = false
|
||||||
|
player_record.outdated = true
|
||||||
|
end
|
||||||
|
|
||||||
function player_sync.initiate_inventory_download(player, player_record, generation, epoch)
|
function player_sync.initiate_inventory_download(player, player_record, generation, epoch)
|
||||||
player.print("Initiating inventory download...")
|
player.print("Initiating inventory download...")
|
||||||
local record = {
|
local record = {
|
||||||
@@ -781,6 +813,25 @@ function player_sync.check_active_downloads()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Quick bar slots pointing into the blueprint library are set once the save has the player's library
|
||||||
|
function player_sync.check_missing_quick_bar_records()
|
||||||
|
local script_data = get_script_data()
|
||||||
|
-- Not once the quick bar stopped being synced here. The entries stay for the upload, which goes by the
|
||||||
|
-- components of the player's session.
|
||||||
|
if not serialize.syncs(script_data.components, "quick_bar") then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
for player_name, failed in pairs(script_data.failed_deserialization) do
|
||||||
|
local player = failed.quick_bar and game.get_player(player_name)
|
||||||
|
if player and player.connected then
|
||||||
|
failed.quick_bar = serialize.restore_missing_quick_bar_records(player, failed.quick_bar)
|
||||||
|
if not next(failed) then
|
||||||
|
script_data.failed_deserialization[player_name] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function player_sync.check_active_uploads()
|
function player_sync.check_active_uploads()
|
||||||
local script_data = get_script_data()
|
local script_data = get_script_data()
|
||||||
for player_name, record in pairs(script_data.active_uploads) do
|
for player_name, record in pairs(script_data.active_uploads) do
|
||||||
|
|||||||
@@ -494,6 +494,27 @@ local function find_item_path(inventory, item_number)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- The record a quick bar slot entry points at, if the player's library has it at that path
|
||||||
|
--- @param player LuaPlayer
|
||||||
|
--- @param entry QuickBarSlotEncoded.record
|
||||||
|
--- @return LuaRecord?
|
||||||
|
local function find_record(player, entry)
|
||||||
|
-- The record must still be what was stored, a shifted library must not set the wrong one
|
||||||
|
local records = player.blueprints
|
||||||
|
local record --[[@as LuaRecord?]]
|
||||||
|
for _, index in ipairs(entry.p) do
|
||||||
|
record = records[index]
|
||||||
|
if not (record and record.valid) then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
records = record.type == "blueprint-book" and record.contents or {}
|
||||||
|
end
|
||||||
|
if record and record.type == entry.y and (record.label or "") == (entry.l or "") then
|
||||||
|
return record
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
--- @param filter ItemFilter
|
--- @param filter ItemFilter
|
||||||
--- @return QuickBarSlotEncoded
|
--- @return QuickBarSlotEncoded
|
||||||
local function serialize_filter(filter)
|
local function serialize_filter(filter)
|
||||||
@@ -611,18 +632,8 @@ function serialize.deserialize_quick_bar_slot(entry, player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if entry.t == "r" then
|
if entry.t == "r" then
|
||||||
-- The record must still be what was stored, a shifted library must not set the wrong one
|
local record = find_record(player, entry)
|
||||||
local records = player.blueprints
|
if record then
|
||||||
local record --[[@as LuaRecord?]]
|
|
||||||
for _, index in ipairs(entry.p) do
|
|
||||||
record = records[index]
|
|
||||||
if not (record and record.valid) then
|
|
||||||
record = nil
|
|
||||||
break
|
|
||||||
end
|
|
||||||
records = record.type == "blueprint-book" and record.contents or {}
|
|
||||||
end
|
|
||||||
if record and record.valid and record.type == entry.y and (record.label or "") == (entry.l or "") then
|
|
||||||
return { type = "record", record = record } --[[@as QuickBarSlot]]
|
return { type = "record", record = record } --[[@as QuickBarSlot]]
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -670,8 +681,9 @@ local function quick_bar_slot_count(player)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- @param player LuaPlayer
|
--- @param player LuaPlayer
|
||||||
|
--- @param missing table<string, QuickBarSlotEncoded.record>? Entries deserialize_quick_bar could not find the record of
|
||||||
--- @return table<string, QuickBarSlotEncoded>?
|
--- @return table<string, QuickBarSlotEncoded>?
|
||||||
function serialize.serialize_quick_bar(player)
|
function serialize.serialize_quick_bar(player, missing)
|
||||||
local serialized
|
local serialized
|
||||||
local width = v2_1_quick_bar_api and player.quick_bar_width
|
local width = v2_1_quick_bar_api and player.quick_bar_width
|
||||||
|
|
||||||
@@ -696,19 +708,63 @@ function serialize.serialize_quick_bar(player)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- A record still missing here is stored again as it came, unless the player put something else in its slot
|
||||||
|
for index, entry in pairs(missing or {}) do
|
||||||
|
serialized = serialized or {}
|
||||||
|
serialized[index] = serialized[index] or entry
|
||||||
|
end
|
||||||
|
|
||||||
return serialized
|
return serialized
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Slot index to page and slot on it
|
||||||
|
--- @param player LuaPlayer
|
||||||
|
--- @param i integer
|
||||||
|
local function quick_bar_location(player, i)
|
||||||
|
local width = player.quick_bar_width
|
||||||
|
return math.floor((i - 1) / width) + 1, ((i - 1) % width) + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Set the slots whose records were not in the player's library when the data was applied. A save gets the library
|
||||||
|
--- of a player from the client some seconds after the join, later than the data of a player new to it is applied.
|
||||||
|
--- @param player LuaPlayer
|
||||||
|
--- @param missing table<string, QuickBarSlotEncoded.record>
|
||||||
|
--- @return table<string, QuickBarSlotEncoded.record>? missing Entries whose record is still not there
|
||||||
|
function serialize.restore_missing_quick_bar_records(player, missing)
|
||||||
|
for index, entry in pairs(missing) do
|
||||||
|
local page, page_slot = quick_bar_location(player, tonumber(index) --[[@as integer]])
|
||||||
|
if player.get_quick_bar_slot(page, page_slot) ~= nil then
|
||||||
|
-- The player put something else there
|
||||||
|
missing[index] = nil
|
||||||
|
else
|
||||||
|
local record = find_record(player, entry)
|
||||||
|
if record then
|
||||||
|
player.set_quick_bar_slot(page, page_slot, { type = "record", record = record })
|
||||||
|
missing[index] = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return next(missing) and missing or nil
|
||||||
|
end
|
||||||
|
|
||||||
--- @param player LuaPlayer
|
--- @param player LuaPlayer
|
||||||
--- @param serialized table<string, string | QuickBarSlotEncoded>?
|
--- @param serialized table<string, string | QuickBarSlotEncoded>?
|
||||||
|
--- @return table<string, QuickBarSlotEncoded.record>? missing Entries whose record is not in the player's library
|
||||||
function serialize.deserialize_quick_bar(player, serialized)
|
function serialize.deserialize_quick_bar(player, serialized)
|
||||||
-- Every slot is set, and the ones not in the data are cleared, so a slot moved or cleared on the
|
-- Every slot is set, and the ones not in the data are cleared, so a slot moved or cleared on the
|
||||||
-- previous server does not come back from this server's old copy
|
-- previous server does not come back from this server's old copy
|
||||||
serialized = serialized or {}
|
serialized = serialized or {}
|
||||||
local width = v2_1_quick_bar_api and player.quick_bar_width
|
local width = v2_1_quick_bar_api and player.quick_bar_width
|
||||||
|
local missing
|
||||||
for i = 1, quick_bar_slot_count(player) do
|
for i = 1, quick_bar_slot_count(player) do
|
||||||
local entry = serialized[tostring(i)]
|
local entry = serialized[tostring(i)]
|
||||||
local slot = entry ~= nil and serialize.deserialize_quick_bar_slot(entry, player) or nil
|
local slot = entry ~= nil and serialize.deserialize_quick_bar_slot(entry, player) or nil
|
||||||
|
if slot == nil and v2_1_quick_bar_api and type(entry) == "table" and entry.t == "r" then
|
||||||
|
-- ponytail: kept until the record shows up or the slot is used for something else, so the entry of a
|
||||||
|
-- record deleted from the library is carried along. Drop them by age if that ever matters.
|
||||||
|
missing = missing or {}
|
||||||
|
missing[tostring(i)] = entry
|
||||||
|
end
|
||||||
if v2_1_quick_bar_api then
|
if v2_1_quick_bar_api then
|
||||||
local page = math.floor((i - 1) / width) + 1
|
local page = math.floor((i - 1) / width) + 1
|
||||||
local page_slot = ((i - 1) % width) + 1
|
local page_slot = ((i - 1) % width) + 1
|
||||||
@@ -718,6 +774,7 @@ function serialize.deserialize_quick_bar(player, serialized)
|
|||||||
player.set_quick_bar_slot(i, slot)
|
player.set_quick_bar_slot(i, slot)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return missing
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Quick bar page shown on each quick bar row of the screen, kept by every save on its own
|
--- Quick bar page shown on each quick bar row of the screen, kept by every save on its own
|
||||||
@@ -1212,7 +1269,7 @@ function serialize.serialize_player(player, failed_deserialization, components)
|
|||||||
|
|
||||||
-- Serialize quick bar
|
-- Serialize quick bar
|
||||||
if syncs(components, "quick_bar") then
|
if syncs(components, "quick_bar") then
|
||||||
serialized.quick_bar = serialize.serialize_quick_bar(player)
|
serialized.quick_bar = serialize.serialize_quick_bar(player, failed_deserialization.quick_bar)
|
||||||
serialized.quick_bar_pages = serialize.serialize_quick_bar_pages(player)
|
serialized.quick_bar_pages = serialize.serialize_quick_bar_pages(player)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1333,6 +1390,7 @@ end
|
|||||||
|
|
||||||
--- @class FailedDeserializationPlayerData
|
--- @class FailedDeserializationPlayerData
|
||||||
--- @field recipe_notifications string[]?
|
--- @field recipe_notifications string[]?
|
||||||
|
--- @field quick_bar table<string, QuickBarSlotEncoded.record>? Slots whose record is not in the library (yet)
|
||||||
|
|
||||||
--- @param player LuaPlayer
|
--- @param player LuaPlayer
|
||||||
--- @param serialized SerializedPlayerData
|
--- @param serialized SerializedPlayerData
|
||||||
@@ -1495,7 +1553,9 @@ function serialize.deserialize_player(player, serialized, components, local_cont
|
|||||||
|
|
||||||
-- Deserialize quick bar (named hotbar in old data)
|
-- Deserialize quick bar (named hotbar in old data)
|
||||||
if syncs(components, "quick_bar") then
|
if syncs(components, "quick_bar") then
|
||||||
serialize.deserialize_quick_bar(player, serialized.quick_bar or serialized.hotbar)
|
failed_deserialization.quick_bar = serialize.deserialize_quick_bar(
|
||||||
|
player, serialized.quick_bar or serialized.hotbar
|
||||||
|
)
|
||||||
serialize.deserialize_quick_bar_pages(player, serialized.quick_bar_pages)
|
serialize.deserialize_quick_bar_pages(player, serialized.quick_bar_pages)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,18 @@ describe("player_sync controller", function() {
|
|||||||
.playerData;
|
.playerData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it("should reply whether the upload was stored", async function() {
|
||||||
|
const handler = mock.getHandler(controller, msg.UploadRequest);
|
||||||
|
const send = (instanceId, generation) => handler(
|
||||||
|
{ instanceId, playerName: "test", playerData: { generation, name: "test" } }
|
||||||
|
);
|
||||||
|
assert.deepEqual(await send(1, 2), new msg.UploadRequest.Response(true));
|
||||||
|
// A crashed instance restarting with the generation another instance already uploaded
|
||||||
|
assert.deepEqual(await send(1, 2), new msg.UploadRequest.Response(false));
|
||||||
|
await mock.getHandler(controller, msg.AcquireRequest)(new msg.AcquireRequest(1, "test"));
|
||||||
|
controller.instances.set(2, controller.instances.get(1));
|
||||||
|
assert.deepEqual(await send(2, 3), new msg.UploadRequest.Response(false));
|
||||||
|
});
|
||||||
it("should store the upload as is when it has no components", async function() {
|
it("should store the upload as is when it has no components", async function() {
|
||||||
const playerData = { generation: 2, name: "test", force: "enemy", tag: "uploaded" };
|
const playerData = { generation: 2, name: "test", force: "enemy", tag: "uploaded" };
|
||||||
assert.deepEqual(await upload(playerData), playerData);
|
assert.deepEqual(await upload(playerData), playerData);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import * as lib from "@clusterio/lib";
|
|||||||
|
|
||||||
import * as mock from "../../../test/mock.js";
|
import * as mock from "../../../test/mock.js";
|
||||||
import loadInstancePlugin, { recipeNotificationDelta, applyRecipeNotificationDelta } from "../dist/node/instance.js";
|
import loadInstancePlugin, { recipeNotificationDelta, applyRecipeNotificationDelta } from "../dist/node/instance.js";
|
||||||
import { AcquireResponse, DownloadResponse, PrefetchEvent } from "../dist/node/messages.js";
|
import { AcquireResponse, DownloadResponse, PrefetchEvent, UploadResponse } from "../dist/node/messages.js";
|
||||||
import { components } from "../dist/node/components.js";
|
import { components } from "../dist/node/components.js";
|
||||||
import { plugin as info } from "../dist/node/index.js";
|
import { plugin as info } from "../dist/node/index.js";
|
||||||
|
|
||||||
@@ -275,6 +275,25 @@ describe("player_sync", function() {
|
|||||||
const request = await upload({ name: "test", generation: 2 });
|
const request = await upload({ name: "test", generation: 2 });
|
||||||
assert.equal(request.destinationInstanceId, undefined);
|
assert.equal(request.destinationInstanceId, undefined);
|
||||||
});
|
});
|
||||||
|
async function rconAfterReply(stored) {
|
||||||
|
instance.server.reset();
|
||||||
|
instance.connector.once("send", message => {
|
||||||
|
instance.connector.emit("message", new lib.MessageResponse(
|
||||||
|
1, message.dst, message.src, new UploadResponse(stored)
|
||||||
|
));
|
||||||
|
});
|
||||||
|
instance.server.emit("ipc-player_sync_upload", { name: "test", generation: 2 });
|
||||||
|
for (let i = 0; i < 100 && !instance.server.rconCommands.length; i++) {
|
||||||
|
await lib.wait(1);
|
||||||
|
}
|
||||||
|
return instance.server.rconCommands;
|
||||||
|
}
|
||||||
|
it("should confirm an upload the controller stored", async function() {
|
||||||
|
assert.deepEqual(await rconAfterReply(true), ['/sc player_sync.confirm_upload("test", 2)']);
|
||||||
|
});
|
||||||
|
it("should reject an upload the controller did not store", async function() {
|
||||||
|
assert.deepEqual(await rconAfterReply(false), ['/sc player_sync.reject_upload("test", 2)']);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("PrefetchEvent", function() {
|
describe("PrefetchEvent", function() {
|
||||||
|
|||||||
@@ -60,6 +60,14 @@ describe("player_sync plugin", function() {
|
|||||||
assert(!validate({ instanceId: 1, playerName: "player", playerData: data }), `accepted ${deleted}`);
|
assert(!validate({ instanceId: 1, playerName: "player", playerData: data }), `accepted ${deleted}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
it("should take the empty reply of an older controller as a stored upload", function() {
|
||||||
|
const validate = lib.compile(msg.UploadResponse.jsonSchema);
|
||||||
|
assert(validate(undefined));
|
||||||
|
assert.equal(msg.UploadResponse.fromJSON(undefined).stored, true);
|
||||||
|
assert(validate({ stored: false }));
|
||||||
|
assert.equal(msg.UploadResponse.fromJSON({ stored: false }).stored, false);
|
||||||
|
assert(!validate({ stored: "no" }));
|
||||||
|
});
|
||||||
describe("SetPlayerDataRequest schema", function() {
|
describe("SetPlayerDataRequest schema", function() {
|
||||||
const validate = lib.compile(msg.SetPlayerDataRequest.jsonSchema);
|
const validate = lib.compile(msg.SetPlayerDataRequest.jsonSchema);
|
||||||
// Shaped like module/serialize.lua output
|
// Shaped like module/serialize.lua output
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ Run the following commands in the folder Clusterio is installed to:
|
|||||||
|
|
||||||
Substitute clusteriocontroller with clusteriohost or clusterioctl if this a dedicate host or ctl installation respectively.
|
Substitute clusteriocontroller with clusteriohost or clusterioctl if this a dedicate host or ctl installation respectively.
|
||||||
|
|
||||||
|
The plugin needs the [Subspace Storage mod](https://mods.factorio.com/mod/subspace_storage) in the mod pack of every instance it is loaded on.
|
||||||
|
The controller downloads it from the mod portal on start if the Factorio credentials are configured, but you have to add it to the mod packs yourself.
|
||||||
|
Instances with the plugin loaded refuse to start without it. Set `subspace_storage.load_plugin` to false on instances that should not use it.
|
||||||
|
|
||||||
|
|
||||||
## Controller Configuration
|
## Controller Configuration
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ export const plugin: lib.PluginDeclaration = {
|
|||||||
title: "Subspace Storage",
|
title: "Subspace Storage",
|
||||||
description: "Provides shared storage across instances for the Subspace Storage mod",
|
description: "Provides shared storage across instances for the Subspace Storage mod",
|
||||||
instanceEntrypoint: "dist/node/instance.js",
|
instanceEntrypoint: "dist/node/instance.js",
|
||||||
|
requiredMods: ["subspace_storage >= 1.99.0"],
|
||||||
instanceConfigFields: {
|
instanceConfigFields: {
|
||||||
"subspace_storage.log_item_transfers": {
|
"subspace_storage.log_item_transfers": {
|
||||||
title: "Log Item Transfers",
|
title: "Log Item Transfers",
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
// Checks the changelog section of a pull request body, read from the PR_BODY environment variable.
|
||||||
|
import fs from "node:fs";
|
||||||
|
import { checkPullRequestBody, changelogSections } from "./pr_to_changelog.mts";
|
||||||
|
|
||||||
|
const expectedFormat = [
|
||||||
|
"### Changelog",
|
||||||
|
"```",
|
||||||
|
"### Features",
|
||||||
|
"- Added doodad to web interface. #123",
|
||||||
|
"",
|
||||||
|
"### Fixes",
|
||||||
|
"- Fixed doodad not showing up. #456",
|
||||||
|
"```",
|
||||||
|
"",
|
||||||
|
"Or, when nothing user facing changed, replace the code block with:",
|
||||||
|
"",
|
||||||
|
"### Changelog",
|
||||||
|
"None. Reason no change log is required.",
|
||||||
|
].join("\n");
|
||||||
|
|
||||||
|
/** Returns the problems found in the body, an empty list means it is valid. */
|
||||||
|
export function findChangelogProblems(body: string | null | undefined) {
|
||||||
|
const { error, warnings } = checkPullRequestBody(body);
|
||||||
|
return error ? [error] : warnings;
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeAnnotation(text: string) {
|
||||||
|
return text.replaceAll("%", "%25").replaceAll("\r", "%0D").replaceAll("\n", "%0A");
|
||||||
|
}
|
||||||
|
|
||||||
|
function main() {
|
||||||
|
const problems = findChangelogProblems(process.env.PR_BODY);
|
||||||
|
const summaryPath = process.env.GITHUB_STEP_SUMMARY;
|
||||||
|
if (!problems.length) {
|
||||||
|
console.log("Changelog section is valid.");
|
||||||
|
if (summaryPath) {
|
||||||
|
fs.appendFileSync(summaryPath, "Changelog section is valid.\n");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const problem of problems) {
|
||||||
|
console.log(`::error title=Invalid changelog::${escapeAnnotation(problem)}`);
|
||||||
|
}
|
||||||
|
const rules = `Valid sections are ${changelogSections.join(", ")}. ` +
|
||||||
|
"Each entry must reference an issue, or this pull request if there is no issue.";
|
||||||
|
console.log(`\n${rules}`);
|
||||||
|
console.log(`Expected format in the pull request description:\n\n${expectedFormat}`);
|
||||||
|
if (summaryPath) {
|
||||||
|
fs.appendFileSync(summaryPath, [
|
||||||
|
"## Invalid changelog",
|
||||||
|
"",
|
||||||
|
"The changelog section of the pull request description has problems:",
|
||||||
|
"",
|
||||||
|
...problems.map(problem => `- ${problem.replaceAll("<", "<")}`),
|
||||||
|
"",
|
||||||
|
rules,
|
||||||
|
"Edit the description and this check runs again. Expected format:",
|
||||||
|
"",
|
||||||
|
"````markdown",
|
||||||
|
expectedFormat,
|
||||||
|
"````",
|
||||||
|
"",
|
||||||
|
].join("\n"));
|
||||||
|
}
|
||||||
|
process.exitCode = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (import.meta.main) {
|
||||||
|
main();
|
||||||
|
}
|
||||||
+43
-16
@@ -20,7 +20,7 @@ type Statistics = {
|
|||||||
const repository = "clusterio/clusterio";
|
const repository = "clusterio/clusterio";
|
||||||
const branch = "master";
|
const branch = "master";
|
||||||
|
|
||||||
const changelogSections = [
|
export const changelogSections = [
|
||||||
"Major Features",
|
"Major Features",
|
||||||
"Features",
|
"Features",
|
||||||
"Fixes",
|
"Fixes",
|
||||||
@@ -79,7 +79,7 @@ function extractPullRequestChangelog(
|
|||||||
{
|
{
|
||||||
const headerFail = skipToLine(parser, /^###? Changelog *$/);
|
const headerFail = skipToLine(parser, /^###? Changelog *$/);
|
||||||
if (headerFail) {
|
if (headerFail) {
|
||||||
return [failure, , "Header not found"];
|
return [failure, , "\"### Changelog\" header not found"];
|
||||||
}
|
}
|
||||||
parser.pos += 1;
|
parser.pos += 1;
|
||||||
skipEmptyLines(parser);
|
skipEmptyLines(parser);
|
||||||
@@ -97,10 +97,19 @@ function extractPullRequestChangelog(
|
|||||||
if (blockEndFail) {
|
if (blockEndFail) {
|
||||||
return [failure, , "End of code block not found after header"];
|
return [failure, , "End of code block not found after header"];
|
||||||
}
|
}
|
||||||
return [success, parser.lines.slice(blockStartPos, parser.pos)];
|
const lines = parser.lines.slice(blockStartPos, parser.pos);
|
||||||
|
if (!lines.some(line => line.trim() !== "")) {
|
||||||
|
return [failure, , "Code block is empty, replace it with \"None.\" if nothing applies"];
|
||||||
|
}
|
||||||
|
return [success, lines];
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseChangelog(parser: ParserState, pr: Issue, issues: Issue[]): [Changelog, string[]] {
|
/** Pass no issues to skip the checks that need the GitHub API. */
|
||||||
|
function parseChangelog(
|
||||||
|
parser: ParserState,
|
||||||
|
pr?: Issue,
|
||||||
|
issues?: Issue[],
|
||||||
|
): [Changelog, string[]] {
|
||||||
let section: string | undefined;
|
let section: string | undefined;
|
||||||
let changelog: Changelog = Object.create(null);
|
let changelog: Changelog = Object.create(null);
|
||||||
let warnings: string[] = [];
|
let warnings: string[] = [];
|
||||||
@@ -120,6 +129,10 @@ function parseChangelog(parser: ParserState, pr: Issue, issues: Issue[]): [Chang
|
|||||||
changelog[section] = changelog[section] ?? [];
|
changelog[section] = changelog[section] ?? [];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!section && /^None/i.test(line)) {
|
||||||
|
warnings.push(`"${line}" on line ${parser.pos} must replace the code block, not sit inside it`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!section) {
|
if (!section) {
|
||||||
warnings.push(`Unexpected content "${line}" outside of a changelog section on line ${parser.pos}`);
|
warnings.push(`Unexpected content "${line}" outside of a changelog section on line ${parser.pos}`);
|
||||||
continue;
|
continue;
|
||||||
@@ -132,6 +145,9 @@ function parseChangelog(parser: ParserState, pr: Issue, issues: Issue[]): [Chang
|
|||||||
let hasRef = false
|
let hasRef = false
|
||||||
for (const ref of entry.matchAll(/#(\d+)/g)) {
|
for (const ref of entry.matchAll(/#(\d+)/g)) {
|
||||||
hasRef = true;
|
hasRef = true;
|
||||||
|
if (!issues || !pr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const id = Number.parseInt(ref[1], 10);
|
const id = Number.parseInt(ref[1], 10);
|
||||||
const refIssue = issues.find(issue => issue.number === id);
|
const refIssue = issues.find(issue => issue.number === id);
|
||||||
if (!refIssue) {
|
if (!refIssue) {
|
||||||
@@ -157,23 +173,34 @@ function parseChangelog(parser: ParserState, pr: Issue, issues: Issue[]): [Chang
|
|||||||
return [changelog, warnings];
|
return [changelog, warnings];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function checkPullRequestBody(
|
||||||
|
body: string | null | undefined,
|
||||||
|
pr?: Issue,
|
||||||
|
issues?: Issue[],
|
||||||
|
): { changelog: Changelog, error?: string, warnings: string[] } {
|
||||||
|
if (!body) {
|
||||||
|
return { changelog: Object.create(null), error: "Pull request has no body", warnings: [] };
|
||||||
|
}
|
||||||
|
const [
|
||||||
|
changelogFail,
|
||||||
|
changelogLines,
|
||||||
|
changelogFailReason
|
||||||
|
] = extractPullRequestChangelog(createParser(body.split(/\r?\n/)));
|
||||||
|
if (changelogFail) {
|
||||||
|
return { changelog: Object.create(null), error: changelogFailReason, warnings: [] };
|
||||||
|
}
|
||||||
|
const [changelog, warnings] = parseChangelog(createParser(changelogLines), pr, issues);
|
||||||
|
return { changelog, warnings };
|
||||||
|
}
|
||||||
|
|
||||||
function changelogFromPullRequests(pullRequests: Issue[], issues: Issue[]) {
|
function changelogFromPullRequests(pullRequests: Issue[], issues: Issue[]) {
|
||||||
const mergedChangelog: Changelog = Object.create(null);
|
const mergedChangelog: Changelog = Object.create(null);
|
||||||
for (const pr of pullRequests) {
|
for (const pr of pullRequests) {
|
||||||
if (!pr.body) {
|
const { changelog, error, warnings } = checkPullRequestBody(pr.body, pr, issues);
|
||||||
console.error(`Failed to extract changelog in ${pr.html_url}: Pull request has no body`);
|
if (error) {
|
||||||
|
console.error(`Failed to extract changelog in ${pr.html_url}: ${error}`)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const [
|
|
||||||
changelogFail,
|
|
||||||
changelogLines,
|
|
||||||
changelogFailReason
|
|
||||||
] = extractPullRequestChangelog(createParser(pr.body.split(/\r?\n/)));
|
|
||||||
if (changelogFail) {
|
|
||||||
console.error(`Failed to extract changelog in ${pr.html_url}: ${changelogFailReason}`)
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const [changelog, warnings] = parseChangelog(createParser(changelogLines), pr, issues);
|
|
||||||
for (const warning of warnings) {
|
for (const warning of warnings) {
|
||||||
console.warn(`Warning in changelog for ${pr.html_url}: ${warning}`)
|
console.warn(`Warning in changelog for ${pr.html_url}: ${warning}`)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,6 +123,43 @@ describe("controller/src/ControlConnection", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe(".handleModPortalGetAllRequest()", function() {
|
||||||
|
let mockController;
|
||||||
|
let _fetch;
|
||||||
|
let urls;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
mockController = {
|
||||||
|
config: new lib.ControllerConfig("controller"),
|
||||||
|
modPortalCache: new Map(),
|
||||||
|
};
|
||||||
|
urls = [];
|
||||||
|
_fetch = global.fetch;
|
||||||
|
global.fetch = async url => {
|
||||||
|
urls.push(new URL(url));
|
||||||
|
return { ok: true, json: async () => ({ results: [], pagination: { page_count: 1 } }) };
|
||||||
|
};
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
global.fetch = _fetch;
|
||||||
|
});
|
||||||
|
|
||||||
|
async function getAll(request) {
|
||||||
|
return await ControlConnection.prototype.handleModPortalGetAllRequest.call(
|
||||||
|
{ _controller: mockController }, request,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
it("treats a missing hide_deprecated as false", async function() {
|
||||||
|
await getAll(new lib.ModPortalGetAllRequest("2.1"));
|
||||||
|
assert.deepEqual([...mockController.modPortalCache.keys()], ["2.1-false"]);
|
||||||
|
assert.equal(urls[0].searchParams.get("hide_deprecated"), "false");
|
||||||
|
|
||||||
|
await getAll(new lib.ModPortalGetAllRequest("2.1", false));
|
||||||
|
assert.equal(urls.length, 1, "explicit false should hit the cache");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe(".handleInstanceCreateRequest()", function() {
|
describe(".handleInstanceCreateRequest()", function() {
|
||||||
let mockController;
|
let mockController;
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,43 @@ describe("controller/src/Controller", function() {
|
|||||||
assert(loaded.modPacks.size > 0, "default mod packs were not added");
|
assert(loaded.modPacks.size > 0, "default mod packs were not added");
|
||||||
await fs.access(modsDirectory);
|
await fs.access(modsDirectory);
|
||||||
});
|
});
|
||||||
|
it("should default to the newest Base Game pack on a new cluster", async function() {
|
||||||
|
const config = new ControllerConfig("controller", {
|
||||||
|
"controller.version": controllerVersion,
|
||||||
|
"controller.database_directory": path.join(dir, "database"),
|
||||||
|
"controller.mods_directory": path.join(dir, "mods"),
|
||||||
|
});
|
||||||
|
|
||||||
|
const loaded = await Controller.fromConfig(config, [], {});
|
||||||
|
const id = config.get("controller.default_mod_pack_id");
|
||||||
|
assert.equal(loaded.modPacks.get(id).name, "Base Game 2.1");
|
||||||
|
});
|
||||||
|
it("should keep a set default mod pack when seeding mod packs", async function() {
|
||||||
|
const config = new ControllerConfig("controller", {
|
||||||
|
"controller.version": controllerVersion,
|
||||||
|
"controller.database_directory": path.join(dir, "database"),
|
||||||
|
"controller.mods_directory": path.join(dir, "mods"),
|
||||||
|
"controller.default_mod_pack_id": 42,
|
||||||
|
});
|
||||||
|
|
||||||
|
await Controller.fromConfig(config, [], {});
|
||||||
|
assert.equal(config.get("controller.default_mod_pack_id"), 42);
|
||||||
|
});
|
||||||
|
it("should not set a default mod pack when mod packs exist", async function() {
|
||||||
|
const databaseDirectory = path.join(dir, "database");
|
||||||
|
await fs.mkdir(databaseDirectory);
|
||||||
|
await fs.writeFile(path.join(databaseDirectory, "mod-packs.json"), JSON.stringify([
|
||||||
|
new ModPack().toJSON(),
|
||||||
|
]));
|
||||||
|
const config = new ControllerConfig("controller", {
|
||||||
|
"controller.version": controllerVersion,
|
||||||
|
"controller.database_directory": databaseDirectory,
|
||||||
|
"controller.mods_directory": path.join(dir, "mods"),
|
||||||
|
});
|
||||||
|
|
||||||
|
await Controller.fromConfig(config, [], {});
|
||||||
|
assert.equal(config.get("controller.default_mod_pack_id"), null);
|
||||||
|
});
|
||||||
it("should start and stop with an existing database", async function() {
|
it("should start and stop with an existing database", async function() {
|
||||||
this.timeout(10000);
|
this.timeout(10000);
|
||||||
const databaseDirectory = path.join(dir, "database");
|
const databaseDirectory = path.join(dir, "database");
|
||||||
@@ -268,6 +305,50 @@ describe("controller/src/Controller", function() {
|
|||||||
await assert.rejects(Controller.loadJsonObject(path.join(dir, "invalid.json")), SyntaxError);
|
await assert.rejects(Controller.loadJsonObject(path.join(dir, "invalid.json")), SyntaxError);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe(".downloadRequiredMods()", function() {
|
||||||
|
let ctrl, resolveCalls, downloadCalls, resolved;
|
||||||
|
function modInfo(name, version) {
|
||||||
|
return lib.ModInfo.fromJSON({ name, version, factorio_version: "2.0" });
|
||||||
|
}
|
||||||
|
beforeEach(function() {
|
||||||
|
const config = new ControllerConfig("controller", { "controller.version": controllerVersion });
|
||||||
|
ctrl = new Controller({}, [
|
||||||
|
{ name: "foo", title: "Foo", requiredMods: ["foo_mod >= 1.0.0"] },
|
||||||
|
{ name: "bar", title: "Bar" },
|
||||||
|
], config);
|
||||||
|
const modPack = ModPack.fromJSON({ id: 7, name: "default", factorio_version: "2.0.10" });
|
||||||
|
ctrl.modPacks.set(modPack);
|
||||||
|
config.set("controller.default_mod_pack_id", 7);
|
||||||
|
resolveCalls = [];
|
||||||
|
downloadCalls = [];
|
||||||
|
resolved = [modInfo("foo_mod", "1.2.0"), modInfo("dep_mod", "0.1.0")];
|
||||||
|
ctrl.resolveModDependencies = async (mods, factorioVersion) => {
|
||||||
|
resolveCalls.push([mods.map(mod => mod.spec), factorioVersion]);
|
||||||
|
return new lib.ModDependencyResolveRequest.Response(resolved, new Map());
|
||||||
|
};
|
||||||
|
ctrl.downloadModsFromPortal = async (mods, factorioVersion) => {
|
||||||
|
downloadCalls.push([mods.map(mod => `${mod.name} ${mod.version}`), factorioVersion]);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should download required mods and their dependencies for the default mod pack", async function() {
|
||||||
|
await ctrl.downloadRequiredMods();
|
||||||
|
assert.deepEqual(resolveCalls, [[["foo_mod >= 1.0.0"], "2.0"]]);
|
||||||
|
assert.deepEqual(downloadCalls, [[["foo_mod = 1.2.0", "dep_mod = 0.1.0"], "2.0"]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should skip mods already in the mod store", async function() {
|
||||||
|
ctrl.modStore = new lib.ModStore("mods", new Map(resolved.map(info => [info.filename, info])));
|
||||||
|
await ctrl.downloadRequiredMods();
|
||||||
|
assert.deepEqual(downloadCalls, []);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should do nothing when no plugin requires mods", async function() {
|
||||||
|
ctrl.pluginInfos = [{ name: "bar", title: "Bar" }];
|
||||||
|
await ctrl.downloadRequiredMods();
|
||||||
|
assert.deepEqual(resolveCalls, []);
|
||||||
|
});
|
||||||
|
});
|
||||||
describe(".loggableHeaders()", function() {
|
describe(".loggableHeaders()", function() {
|
||||||
it("should redact credentials and keep other headers", function() {
|
it("should redact credentials and keep other headers", function() {
|
||||||
const headers = {
|
const headers = {
|
||||||
@@ -597,6 +678,32 @@ describe("controller/src/Controller", function() {
|
|||||||
assert.equal(controller.config.restartRequired, true);
|
assert.equal(controller.config.restartRequired, true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe(".onSystemMetricsIntervalChanged()", function() {
|
||||||
|
let calls;
|
||||||
|
beforeEach(function() {
|
||||||
|
calls = 0;
|
||||||
|
controller.updateSystems = async () => { calls += 1; };
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
clearInterval(controller.systemMetricsInterval);
|
||||||
|
controller.systemMetricsInterval = undefined;
|
||||||
|
delete controller.updateSystems;
|
||||||
|
controller.config.set("controller.system_metrics_interval", 10);
|
||||||
|
});
|
||||||
|
it("updates systems right away and then on every interval", async function() {
|
||||||
|
controller.config.set("controller.system_metrics_interval", 0.01);
|
||||||
|
controller.onSystemMetricsIntervalChanged();
|
||||||
|
assert.equal(calls, 1, "first update waited for the interval");
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 35));
|
||||||
|
assert(calls >= 3, `expected interval updates, got ${calls} calls`);
|
||||||
|
});
|
||||||
|
it("does nothing when the interval is 0", function() {
|
||||||
|
controller.config.set("controller.system_metrics_interval", 0);
|
||||||
|
controller.onSystemMetricsIntervalChanged();
|
||||||
|
assert.equal(calls, 0);
|
||||||
|
assert.equal(controller.systemMetricsInterval, undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
describe(".checkRestartDowngrade()", function() {
|
describe(".checkRestartDowngrade()", function() {
|
||||||
it("returns null when the installed version matches", async function() {
|
it("returns null when the installed version matches", async function() {
|
||||||
controller.config.set("controller.version", controllerVersion);
|
controller.config.set("controller.version", controllerVersion);
|
||||||
|
|||||||
@@ -136,6 +136,46 @@ describe("controller/src/HostConnection", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("system info on connect", function() {
|
||||||
|
let controller;
|
||||||
|
let connector;
|
||||||
|
let connection;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
controller = new Controller(lib.logger, [], new lib.ControllerConfig("controller"));
|
||||||
|
controller.hosts.records.set(new HostRecord(10, "host-10", "1.0.0", new Map()));
|
||||||
|
connector = new MockConnector(addr("controller"), addr({ hostId: 10 }));
|
||||||
|
connection = new HostConnection(
|
||||||
|
new lib.RegisterHostData("", "2.0.0", 10, {}), connector, controller, "10.0.0.1"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
function systemInfoRequests() {
|
||||||
|
return connector.sentMessages.filter(message => message.name === "SystemInfoRequest");
|
||||||
|
}
|
||||||
|
|
||||||
|
it("should request system info as soon as the host connects", async function() {
|
||||||
|
connector.emit("connect");
|
||||||
|
const [request] = systemInfoRequests();
|
||||||
|
assert(request, "SystemInfoRequest was not sent");
|
||||||
|
assert.equal(connection.id, 10);
|
||||||
|
|
||||||
|
const info = await lib.gatherSystemInfo(10, false, true, 0);
|
||||||
|
connector.emit("message", new lib.MessageResponse(request.seq, request.dst, request.src, info));
|
||||||
|
await new Promise(resolve => setImmediate(resolve));
|
||||||
|
assert.equal(controller.systems.get(10)?.restartRequired, true);
|
||||||
|
});
|
||||||
|
it("should not request system info when a session resumes", function() {
|
||||||
|
connector.emit("resume");
|
||||||
|
assert.deepEqual(systemInfoRequests(), []);
|
||||||
|
});
|
||||||
|
it("should not request system info when system metrics are disabled", function() {
|
||||||
|
controller.config.set("controller.system_metrics_interval", 0);
|
||||||
|
connector.emit("connect");
|
||||||
|
assert.deepEqual(systemInfoRequests(), []);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe(".handleInstanceSaveDetailsUpdatesEvent()", function() {
|
describe(".handleInstanceSaveDetailsUpdatesEvent()", function() {
|
||||||
// Instance 1 is on host 10, instance 2 is on host 20.
|
// Instance 1 is on host 10, instance 2 is on host 20.
|
||||||
const assignments = new Map([[1, 10], [2, 20]]);
|
const assignments = new Map([[1, 10], [2, 20]]);
|
||||||
|
|||||||
@@ -195,6 +195,20 @@ describe("create installer CLI", function() {
|
|||||||
await fs.access(path.join(directory, `run-host${process.platform === "win32" ? ".cmd" : ".sh"}`));
|
await fs.access(path.join(directory, `run-host${process.platform === "win32" ? ".cmd" : ".sh"}`));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("writes a run script that exits with the code that stopped the restart loop", async function() {
|
||||||
|
if (process.platform === "win32") {
|
||||||
|
this.skip();
|
||||||
|
}
|
||||||
|
await run(hostArgs());
|
||||||
|
const binDir = path.join(directory, "node_modules", ".bin");
|
||||||
|
await fs.mkdir(binDir, { recursive: true });
|
||||||
|
await fs.writeFile(path.join(binDir, "clusteriohost"), "#!/bin/sh\nexit 8\n", { mode: 0o755 });
|
||||||
|
await assert.rejects(
|
||||||
|
execFileAsync(path.join(directory, "run-host.sh"), [], { cwd: directory }),
|
||||||
|
{ code: 8 },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it("adds the trailing slash the host requires to the controller URL", async function() {
|
it("adds the trailing slash the host requires to the controller URL", async function() {
|
||||||
await run(hostArgs(controllerUrl.slice(0, -1)));
|
await run(hostArgs(controllerUrl.slice(0, -1)));
|
||||||
assert((await commands()).includes(hostSet("host.controller_url", controllerUrl)));
|
assert((await commands()).includes(hostSet("host.controller_url", controllerUrl)));
|
||||||
|
|||||||
@@ -336,6 +336,49 @@ describe("class Instance", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe(".checkRequiredMods()", function() {
|
||||||
|
beforeEach(function() {
|
||||||
|
instance.loadedPlugins = new Set([
|
||||||
|
{ name: "foo", requiredMods: ["foo_mod", "bar_mod >= 1.1.0", "bar_mod < 2.0.0"] },
|
||||||
|
{ name: "bar" },
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
function modPack(mods) {
|
||||||
|
return lib.ModPack.fromJSON({ name: "pack", mods });
|
||||||
|
}
|
||||||
|
|
||||||
|
it("should accept a mod pack with the required mods", function() {
|
||||||
|
instance.checkRequiredMods(modPack([
|
||||||
|
{ name: "foo_mod", enabled: true, version: "1.0.0" },
|
||||||
|
{ name: "bar_mod", enabled: true, version: "1.1.0" },
|
||||||
|
]));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should reject missing, disabled and out of range mods", function() {
|
||||||
|
const expected = (unmet) => new lib.ConflictError(
|
||||||
|
"Mod pack pack does not have the mods required by the loaded plugins. " +
|
||||||
|
`Plugin foo requires ${unmet}. ` +
|
||||||
|
"Add the mods to the mod pack or set <plugin>.load_plugin to false for this instance."
|
||||||
|
);
|
||||||
|
assert.throws(
|
||||||
|
() => instance.checkRequiredMods(modPack([{ name: "bar_mod", enabled: true, version: "1.0.0" }])),
|
||||||
|
expected("foo_mod (missing), bar_mod >= 1.1.0 (found 1.0.0)"),
|
||||||
|
);
|
||||||
|
assert.throws(
|
||||||
|
() => instance.checkRequiredMods(modPack([
|
||||||
|
{ name: "foo_mod", enabled: false, version: "1.0.0" },
|
||||||
|
{ name: "bar_mod", enabled: true, version: "2.0.0" },
|
||||||
|
])),
|
||||||
|
expected("foo_mod (disabled), bar_mod < 2.0.0 (found 2.0.0)"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should ignore plugins that are not loaded", function() {
|
||||||
|
instance.loadedPlugins = new Set([{ name: "bar" }]);
|
||||||
|
instance.checkRequiredMods(modPack([]));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("save name checks", function() {
|
describe("save name checks", function() {
|
||||||
it("should reject a start save outside the saves directory", async function() {
|
it("should reject a start save outside the saves directory", async function() {
|
||||||
await assert.rejects(
|
await assert.rejects(
|
||||||
|
|||||||
@@ -252,6 +252,7 @@ describe("host/src/pairing", function() {
|
|||||||
config = new lib.HostConfig("host", undefined, path.join(directory, "config-host.json"));
|
config = new lib.HostConfig("host", undefined, path.join(directory, "config-host.json"));
|
||||||
config.set("host.name", "My Host");
|
config.set("host.name", "My Host");
|
||||||
config.set("host.controller_url", stub.url);
|
config.set("host.controller_url", stub.url);
|
||||||
|
config.restartRequired = false;
|
||||||
});
|
});
|
||||||
afterEach(async function() {
|
afterEach(async function() {
|
||||||
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10 });
|
await fs.rm(directory, { recursive: true, force: true, maxRetries: 10 });
|
||||||
@@ -279,6 +280,9 @@ describe("host/src/pairing", function() {
|
|||||||
assert.equal(saved["host.id"], 1234);
|
assert.equal(saved["host.id"], 1234);
|
||||||
assert.equal(saved["host.name"], "Approved");
|
assert.equal(saved["host.name"], "Approved");
|
||||||
assert.equal(saved["host.controller_token"], "host-token");
|
assert.equal(saved["host.controller_token"], "host-token");
|
||||||
|
assert.equal(config.restartRequired, false, "pairing flagged a restart");
|
||||||
|
config.set("host.controller_token", "other-token");
|
||||||
|
assert.equal(config.restartRequired, true, "later change did not flag a restart");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does nothing when the controller accepts the saved token", async function() {
|
it("does nothing when the controller accepts the saved token", async function() {
|
||||||
@@ -294,6 +298,7 @@ describe("host/src/pairing", function() {
|
|||||||
|
|
||||||
it("asks to join again with the user token when the saved token is not accepted", async function() {
|
it("asks to join again with the user token when the saved token is not accepted", async function() {
|
||||||
config.set("host.controller_token", "revoked-token");
|
config.set("host.controller_token", "revoked-token");
|
||||||
|
config.restartRequired = false;
|
||||||
stub.handler = ({ url, headers }) => {
|
stub.handler = ({ url, headers }) => {
|
||||||
if (url === "/api/host-pairing/check") {
|
if (url === "/api/host-pairing/check") {
|
||||||
return [401, undefined];
|
return [401, undefined];
|
||||||
@@ -307,6 +312,7 @@ describe("host/src/pairing", function() {
|
|||||||
assert.equal(saved["host.id"], 5);
|
assert.equal(saved["host.id"], 5);
|
||||||
assert.equal(saved["host.controller_token"], "new-token");
|
assert.equal(saved["host.controller_token"], "new-token");
|
||||||
assert(!JSON.stringify(saved).includes("user-token"), "user token must not be saved");
|
assert(!JSON.stringify(saved).includes("user-token"), "user token must not be saved");
|
||||||
|
assert.equal(config.restartRequired, false, "pairing flagged a restart");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("stops when aborted while checking the saved token", async function() {
|
it("stops when aborted while checking the saved token", async function() {
|
||||||
|
|||||||
+103
-2
@@ -273,6 +273,28 @@ describe("host/server", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("._watchWhitelist()", function() {
|
||||||
|
it("should emit the added and removed players on change", async function() {
|
||||||
|
const whitelistPath = path.join(writePath, "server-whitelist.json");
|
||||||
|
await fs.mkdir(writePath, { recursive: true });
|
||||||
|
await fs.writeFile(whitelistPath, JSON.stringify(["a", "b"]));
|
||||||
|
server.enableWhitelist = true;
|
||||||
|
server._whitelist = new Set(["a", "b"]);
|
||||||
|
server._watchWhitelist();
|
||||||
|
try {
|
||||||
|
const waiter = events.once(server, "whitelist-change");
|
||||||
|
await fs.writeFile(whitelistPath, JSON.stringify(["b", "c", "c"]));
|
||||||
|
const [added, removed] = await waiter;
|
||||||
|
assert.deepEqual(added, ["c"]);
|
||||||
|
assert.deepEqual(removed, ["a"]);
|
||||||
|
assert.deepEqual([...server._whitelist], ["b", "c"]);
|
||||||
|
} finally {
|
||||||
|
server._whitelistWatcher?.close();
|
||||||
|
server.enableWhitelist = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe(".fromOptions()", function() {
|
describe(".fromOptions()", function() {
|
||||||
it("should resolve the requested version", async function() {
|
it("should resolve the requested version", async function() {
|
||||||
const found = await hostServer.FactorioServer.fromOptions(
|
const found = await hostServer.FactorioServer.fromOptions(
|
||||||
@@ -306,6 +328,54 @@ describe("host/server", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe(".binaryPath()", function() {
|
||||||
|
const _platform = process.platform;
|
||||||
|
const _arch = process.arch;
|
||||||
|
const installDir = path.join("temp", "test", "binary-path");
|
||||||
|
function serverFor(dir) {
|
||||||
|
return new hostServer.FactorioServer(
|
||||||
|
installDir, writePath, path.join(installDir, dir, "data"), "2.1.24", { rconPassword: "" }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
function mockHost(platform, arch) {
|
||||||
|
Object.defineProperty(process, "platform", { value: platform });
|
||||||
|
Object.defineProperty(process, "arch", { value: arch });
|
||||||
|
}
|
||||||
|
before(async function() {
|
||||||
|
await fs.rm(installDir, { force: true, recursive: true });
|
||||||
|
const layouts = [["none", []], ["x64", ["x64"]], ["arm64", ["arm64"]], ["both", ["x64", "arm64"]]];
|
||||||
|
for (const [dir, arches] of layouts) {
|
||||||
|
await fs.mkdir(path.join(installDir, dir, "data"), { recursive: true });
|
||||||
|
for (const arch of arches) {
|
||||||
|
await fs.mkdir(path.join(installDir, dir, "bin", arch), { recursive: true });
|
||||||
|
await fs.writeFile(path.join(installDir, dir, "bin", arch, "factorio"), "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
mockHost(_platform, _arch);
|
||||||
|
});
|
||||||
|
const binary = (dir, arch) => path.join(installDir, dir, "bin", arch, "factorio");
|
||||||
|
for (const [platform, arch, dir, expected] of [
|
||||||
|
["linux", "x64", "both", "x64"],
|
||||||
|
["linux", "arm64", "both", "arm64"],
|
||||||
|
["linux", "x64", "arm64", "arm64"],
|
||||||
|
["linux", "arm64", "x64", "x64"],
|
||||||
|
["linux", "x64", "none", "x64"],
|
||||||
|
["linux", "arm64", "none", "arm64"],
|
||||||
|
["win32", "arm64", "none", "x64"],
|
||||||
|
]) {
|
||||||
|
it(`should pick bin/${expected} on ${platform} ${arch} with ${dir} installed`, function() {
|
||||||
|
mockHost(platform, arch);
|
||||||
|
assert.equal(serverFor(dir).binaryPath(), binary(dir, expected));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
it("should use MacOS/factorio on darwin", function() {
|
||||||
|
mockHost("darwin", "arm64");
|
||||||
|
assert.equal(serverFor("both").binaryPath(), path.join(installDir, "both", "MacOS", "factorio"));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("._handleIpc()", function() {
|
describe("._handleIpc()", function() {
|
||||||
it("should emit the correct ipc event", async function() {
|
it("should emit the correct ipc event", async function() {
|
||||||
let waiter = events.once(server, "ipc-channel");
|
let waiter = events.once(server, "ipc-channel");
|
||||||
@@ -738,15 +808,46 @@ describe("host/server", function() {
|
|||||||
stable: false,
|
stable: false,
|
||||||
version: "0.1.0",
|
version: "0.1.0",
|
||||||
headlessUrl: "test3",
|
headlessUrl: "test3",
|
||||||
}], logger), new Error("Failed to fetch test1: -1 Fetch called"));
|
}], logger), /Failed to fetch \S+\/get-download\/0\.1\.5\/headless\/linux64/);
|
||||||
|
|
||||||
assert.equal(fetchCalledWith, "test1");
|
assert.equal(fetchCalledWith, "https://www.factorio.com/get-download/0.1.5/headless/linux64");
|
||||||
assert.ok(logLine !== null);
|
assert.ok(logLine !== null);
|
||||||
assert.ok(logLine.endsWith("starting download..."));
|
assert.ok(logLine.endsWith("starting download..."));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
/* eslint-enable no-loop-func */
|
/* eslint-enable no-loop-func */
|
||||||
}
|
}
|
||||||
|
describe("on ARM64 Linux", function() {
|
||||||
|
const _arch = process.arch;
|
||||||
|
const factorioDir = path.join("test", "file", "factorio");
|
||||||
|
beforeEach(function() {
|
||||||
|
Object.defineProperty(process, "platform", { value: "linux" });
|
||||||
|
Object.defineProperty(process, "arch", { value: "arm64" });
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
Object.defineProperty(process, "arch", { value: _arch });
|
||||||
|
});
|
||||||
|
const versions = [
|
||||||
|
{ stable: false, version: "2.1.25", headlessUrl: "test1" },
|
||||||
|
{ stable: true, version: "2.1.17", headlessUrl: "test2" },
|
||||||
|
{ stable: true, version: "0.1.5", headlessUrl: "test3" },
|
||||||
|
];
|
||||||
|
it("should download the linux-arm64 build", async function() {
|
||||||
|
await assert.rejects(hostServer.checkForUpdates(factorioDir, "latest", versions), /Fetch called/);
|
||||||
|
assert.equal(fetchCalledWith, "https://www.factorio.com/get-download/2.1.25/headless/linux-arm64");
|
||||||
|
});
|
||||||
|
it("should reject versions older than 2.1.18", async function() {
|
||||||
|
await assert.rejects(
|
||||||
|
hostServer.checkForUpdates(factorioDir, "2.1.17", versions),
|
||||||
|
/Factorio 2.1.17 has no ARM64 Linux headless build to download, ARM64 builds start at 2.1.18/
|
||||||
|
);
|
||||||
|
assert.equal(fetchCalledWith, null);
|
||||||
|
});
|
||||||
|
it("should accept an older version that is already installed", async function() {
|
||||||
|
await hostServer.checkForUpdates(factorioDir, "0.1", versions);
|
||||||
|
assert.equal(fetchCalledWith, null);
|
||||||
|
});
|
||||||
|
});
|
||||||
describe("concurrent downloads", function() {
|
describe("concurrent downloads", function() {
|
||||||
const versions = [{ stable: true, version: "0.1.5", headlessUrl: "test1" }];
|
const versions = [{ stable: true, version: "0.1.5", headlessUrl: "test1" }];
|
||||||
|
|
||||||
|
|||||||
@@ -2204,8 +2204,10 @@ describe("Integration of Clusterio", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("role list", function() {
|
describe("role list", function() {
|
||||||
it("runs", async function() {
|
it("prints permissions as a list", async function() {
|
||||||
await execCtl("role list");
|
const output = await execCtlOutput("role list");
|
||||||
|
assert(!output.includes("[object"), output);
|
||||||
|
assert.match(output, /Cluster Admin .*core\.admin/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -2316,8 +2318,10 @@ describe("Integration of Clusterio", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("user list", function() {
|
describe("user list", function() {
|
||||||
it("runs", async function() {
|
it("prints roles and instances as lists", async function() {
|
||||||
await execCtl("user list");
|
const output = await execCtlOutput("user list");
|
||||||
|
assert(!output.includes("[object"), output);
|
||||||
|
assert.match(output, /roleIds/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+21
-20
@@ -297,16 +297,8 @@ export async function writeHostConfig(configPath, pairing, fields = {}) {
|
|||||||
/** @returns {Promise<child_process.ChildProcess>} */
|
/** @returns {Promise<child_process.ChildProcess>} */
|
||||||
export function spawn(name, cmd, waitFor, options = {}) {
|
export function spawn(name, cmd, waitFor, options = {}) {
|
||||||
|
|
||||||
const silent = process.env.SILENT_TEST;
|
|
||||||
const bootstrap = !controllerProcess || !hostProcess;
|
|
||||||
function log(...args) {
|
|
||||||
if (!silent || bootstrap) {
|
|
||||||
console.log(...args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
log(cmd);
|
console.log(cmd);
|
||||||
let parts = cmd.split(" ");
|
let parts = cmd.split(" ");
|
||||||
let process = child_process.spawn(parts[0], parts.slice(1), childOptions(options));
|
let process = child_process.spawn(parts[0], parts.slice(1), childOptions(options));
|
||||||
let stdout = new LineSplitter({ readableObjectMode: true });
|
let stdout = new LineSplitter({ readableObjectMode: true });
|
||||||
@@ -314,13 +306,9 @@ export function spawn(name, cmd, waitFor, options = {}) {
|
|||||||
let onData = line => {
|
let onData = line => {
|
||||||
line = line.toString("utf8");
|
line = line.toString("utf8");
|
||||||
if (waitFor.test(line)) {
|
if (waitFor.test(line)) {
|
||||||
if (silent) {
|
|
||||||
stdout.off("data", onData);
|
|
||||||
stderr.off("data", onData);
|
|
||||||
}
|
|
||||||
resolve(process);
|
resolve(process);
|
||||||
}
|
}
|
||||||
log(name, line);
|
console.log(name, line);
|
||||||
};
|
};
|
||||||
stdout.on("data", onData);
|
stdout.on("data", onData);
|
||||||
stderr.on("data", onData);
|
stderr.on("data", onData);
|
||||||
@@ -336,12 +324,6 @@ export function spawnNode(name, cmd, waitFor, options) {
|
|||||||
before(async function() {
|
before(async function() {
|
||||||
this.timeout(40000);
|
this.timeout(40000);
|
||||||
|
|
||||||
|
|
||||||
const silent = process.env.SILENT_TEST;
|
|
||||||
if (silent) {
|
|
||||||
console.log("SILENT_TEST is present in env, loggers after bootstrap will be muted.");
|
|
||||||
}
|
|
||||||
|
|
||||||
// If fast test is enabled then output that it is
|
// If fast test is enabled then output that it is
|
||||||
|
|
||||||
if (process.env.FAST_TEST) {
|
if (process.env.FAST_TEST) {
|
||||||
@@ -371,6 +353,22 @@ before(async function() {
|
|||||||
sourceDir: "packages/host/lua/clusterio_lib",
|
sourceDir: "packages/host/lua/clusterio_lib",
|
||||||
outputDir: modsDir,
|
outputDir: modsDir,
|
||||||
});
|
});
|
||||||
|
// Stand-in for the mod required by the subspace_storage plugin
|
||||||
|
const subspaceStorageDir = path.join("temp", "test", "subspace_storage");
|
||||||
|
await fs.rm(subspaceStorageDir, { force: true, recursive: true });
|
||||||
|
await fs.mkdir(subspaceStorageDir, { recursive: true });
|
||||||
|
await fs.writeFile(path.join(subspaceStorageDir, "info.json"), JSON.stringify({
|
||||||
|
name: "subspace_storage",
|
||||||
|
variants: [
|
||||||
|
{ version: "2.3.11", factorio_version: "1.1" },
|
||||||
|
{ version: "2.3.20", factorio_version: "2.0" },
|
||||||
|
{ version: "2.3.21", factorio_version: "2.1" },
|
||||||
|
],
|
||||||
|
title: "Subspace Storage test stub",
|
||||||
|
author: "Clusterio Team",
|
||||||
|
dependencies: ["base", "clusterio_lib"],
|
||||||
|
}));
|
||||||
|
await lib.build({ build: true, pack: true, sourceDir: subspaceStorageDir, outputDir: modsDir });
|
||||||
|
|
||||||
console.log("Setting Controller Config");
|
console.log("Setting Controller Config");
|
||||||
await execController("config create");
|
await execController("config create");
|
||||||
@@ -428,6 +426,9 @@ before(async function() {
|
|||||||
|
|
||||||
const [major, minor] = lib.normaliseMajorMinorVersion(latestFactorioVersion).split(".");
|
const [major, minor] = lib.normaliseMajorMinorVersion(latestFactorioVersion).split(".");
|
||||||
testPack.mods.set("clusterio_lib", { name: "clusterio_lib", enabled: true, version: `2.1.${major}${minor}` });
|
testPack.mods.set("clusterio_lib", { name: "clusterio_lib", enabled: true, version: `2.1.${major}${minor}` });
|
||||||
|
testPack.mods.set(
|
||||||
|
"subspace_storage", { name: "subspace_storage", enabled: true, version: `2.3.${major}${minor}` }
|
||||||
|
);
|
||||||
|
|
||||||
await control.sendTo("controller", new lib.ModPackCreateRequest(testPack));
|
await control.sendTo("controller", new lib.ModPackCreateRequest(testPack));
|
||||||
await control.sendTo(
|
await control.sendTo(
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ describe("Integration of lib/link", function() {
|
|||||||
hostConnector = new TestHostConnector(url, 0.2);
|
hostConnector = new TestHostConnector(url, 0.2);
|
||||||
hostConnector.token = linkHost.token;
|
hostConnector.token = linkHost.token;
|
||||||
hostConnector.hostId = linkHost.hostId;
|
hostConnector.hostId = linkHost.hostId;
|
||||||
|
// The controller requests system info on connect and waits for it before disconnecting
|
||||||
|
const hostLink = new lib.Link(hostConnector);
|
||||||
|
hostLink.handle(lib.SystemInfoRequest, () => lib.gatherSystemInfo(linkHost.hostId, false, false, 0));
|
||||||
});
|
});
|
||||||
afterEach(async function() {
|
afterEach(async function() {
|
||||||
await controlConnector.disconnect();
|
await controlConnector.disconnect();
|
||||||
|
|||||||
+40
-1
@@ -1,10 +1,49 @@
|
|||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import { readFile } from "node:fs/promises";
|
import { readFile } from "node:fs/promises";
|
||||||
|
|
||||||
import { fetchFactorioVersions } from "@clusterio/lib";
|
import { factorioHeadlessUrl, fetchFactorioVersions, hasFactorioHeadless } from "@clusterio/lib";
|
||||||
import { slowTest, externalTest } from "../../common.js";
|
import { slowTest, externalTest } from "../../common.js";
|
||||||
|
|
||||||
describe("FactorioVersions", function() {
|
describe("FactorioVersions", function() {
|
||||||
|
describe("hasFactorioHeadless", function() {
|
||||||
|
for (const [version, platform, arch, expected] of [
|
||||||
|
["0.17.79", "linux", "x64", true],
|
||||||
|
["2.1.17", "linux", "arm64", false],
|
||||||
|
["2.1.18", "linux", "arm64", true],
|
||||||
|
["2.1.24", "win32", "x64", false],
|
||||||
|
["2.1.24", "win32", "arm64", false],
|
||||||
|
]) {
|
||||||
|
it(`should return ${expected} for ${version} ${platform} ${arch}`, function() {
|
||||||
|
assert.equal(hasFactorioHeadless(version, platform, arch), expected);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
describe("factorioHeadlessUrl", function() {
|
||||||
|
it("should return the linux64 build for x64", function() {
|
||||||
|
assert.equal(
|
||||||
|
factorioHeadlessUrl("2.1.24", "linux", "x64"),
|
||||||
|
"https://www.factorio.com/get-download/2.1.24/headless/linux64",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it("should return the linux-arm64 build for arm64", function() {
|
||||||
|
assert.equal(
|
||||||
|
factorioHeadlessUrl("2.1.24", "linux", "arm64"),
|
||||||
|
"https://www.factorio.com/get-download/2.1.24/headless/linux-arm64",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it("should throw for Windows", function() {
|
||||||
|
assert.throws(
|
||||||
|
() => factorioHeadlessUrl("2.1.24", "win32", "x64"),
|
||||||
|
new Error("Factorio 2.1.24 has no headless build for win32 x64"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
it("should throw for linux arm64 before 2.1.18", function() {
|
||||||
|
assert.throws(
|
||||||
|
() => factorioHeadlessUrl("2.1.17", "linux", "arm64"),
|
||||||
|
new Error("Factorio 2.1.17 has no headless build for linux arm64"),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
describe("fetchFactorioVersions", function() {
|
describe("fetchFactorioVersions", function() {
|
||||||
const originalFetch = global.fetch;
|
const originalFetch = global.fetch;
|
||||||
|
|
||||||
|
|||||||
@@ -24,4 +24,22 @@ describe("lib/plugin", function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe("pluginRequiredMods()", function() {
|
||||||
|
it("should parse dependency strings", function() {
|
||||||
|
const mods = lib.pluginRequiredMods({
|
||||||
|
name: "foo", title: "Foo", requiredMods: ["bar", "baz >= 1.2.0", "baz < 2.0.0"],
|
||||||
|
});
|
||||||
|
assert.deepEqual(mods.map(mod => [mod.name, mod.version?.toString()]), [
|
||||||
|
["bar", undefined], ["baz", ">= 1.2.0"], ["baz", "< 2.0.0"],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
it("should return an empty list without requiredMods", function() {
|
||||||
|
assert.deepEqual(lib.pluginRequiredMods({ name: "foo", title: "Foo" }), []);
|
||||||
|
});
|
||||||
|
it("should reject dependency prefixes and invalid versions", function() {
|
||||||
|
for (const spec of ["? bar", "! bar", "~ bar", "bar >= 1..2"]) {
|
||||||
|
assert.throws(() => lib.pluginRequiredMods({ name: "foo", title: "Foo", requiredMods: [spec] }));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -2,6 +2,21 @@
|
|||||||
|
|
||||||
This folder contains files used for performing manual tests that are non-trivial to automate.
|
This folder contains files used for performing manual tests that are non-trivial to automate.
|
||||||
|
|
||||||
|
|
||||||
|
## Plugins page on small screens
|
||||||
|
|
||||||
|
Use a cluster with several plugins, including one with different running and installed versions and one with a web load error.
|
||||||
|
Compare the Plugins page at 390px and 1440px viewport widths, and check the 768px breakpoint.
|
||||||
|
|
||||||
|
1. On phones, check that each row shows its name, versions, machine counts, status and update action vertically, without clipping or breaking ordinary words.
|
||||||
|
2. Check that a long plugin name wraps and the header branding stays on one line.
|
||||||
|
3. Search and sort by name, reload, and check that the selected filter and sort order remain applied.
|
||||||
|
4. Open an update or restart checklist, then cancel it; update actions must not navigate to the plugin page.
|
||||||
|
5. Open a plugin by its name and by clicking elsewhere in its row.
|
||||||
|
6. Open the account menu using the user icon on mobile; the full account name should appear in the menu.
|
||||||
|
7. On desktop, check that the name, versions and update action remain separate columns.
|
||||||
|
|
||||||
|
|
||||||
## Setup test mod
|
## Setup test mod
|
||||||
|
|
||||||
Run `node packages/lib/dist/node/build_mod.js --source-dir test/manual/test_mod/ --output-dir mods/` to create the test mod.
|
Run `node packages/lib/dist/node/build_mod.js --source-dir test/manual/test_mod/ --output-dir mods/` to create the test mod.
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
import assert from "node:assert/strict";
|
||||||
|
|
||||||
|
import { checkPullRequestBody } from "../scripts/pr_to_changelog.mts";
|
||||||
|
import { findChangelogProblems } from "../scripts/check_pr_changelog.mts";
|
||||||
|
|
||||||
|
|
||||||
|
describe("scripts/check_pr_changelog", function() {
|
||||||
|
function body(...lines) {
|
||||||
|
return ["Description.", "", "### Changelog", ...lines].join("\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
it("accepts entries in a code block", function() {
|
||||||
|
const text = body(
|
||||||
|
"```",
|
||||||
|
"### Features",
|
||||||
|
"- Added doodad. #12",
|
||||||
|
"",
|
||||||
|
"### Fixes",
|
||||||
|
"- Fixed [#13](https://github.com/clusterio/clusterio/issues/13)",
|
||||||
|
"```",
|
||||||
|
);
|
||||||
|
assert.deepEqual(findChangelogProblems(text), []);
|
||||||
|
assert.deepEqual({ ...checkPullRequestBody(text).changelog }, {
|
||||||
|
"Features": ["Added doodad. #12"],
|
||||||
|
"Fixes": ["Fixed #13"],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
it("accepts None. in place of the code block", function() {
|
||||||
|
assert.deepEqual(findChangelogProblems(body("", "None. Only changes CI.")), []);
|
||||||
|
});
|
||||||
|
it("rejects a missing body or section", function() {
|
||||||
|
assert.deepEqual(findChangelogProblems(null), ["Pull request has no body"]);
|
||||||
|
assert.deepEqual(findChangelogProblems("Description only."), ["\"### Changelog\" header not found"]);
|
||||||
|
assert.deepEqual(findChangelogProblems(body("Text")), ["Code block not found after header"]);
|
||||||
|
assert.deepEqual(findChangelogProblems(body("```", "### Fixes")), ["End of code block not found after header"]);
|
||||||
|
assert.deepEqual(findChangelogProblems(body("```", "", "```")), [
|
||||||
|
"Code block is empty, replace it with \"None.\" if nothing applies",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
it("rejects None. inside the code block", function() {
|
||||||
|
assert.deepEqual(findChangelogProblems(body("```", "None.", "```")), [
|
||||||
|
"\"None.\" on line 1 must replace the code block, not sit inside it",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
it("rejects malformed entries", function() {
|
||||||
|
const text = body("```", "- Orphan #1", "### Bugs", "- Fixed it", "Loose text", "```");
|
||||||
|
assert.deepEqual(findChangelogProblems(text), [
|
||||||
|
"Unexpected content \"- Orphan #1\" outside of a changelog section on line 1",
|
||||||
|
"Changelog section Bugs on line 2 is not one of " +
|
||||||
|
"Major Features, Features, Fixes, Changes, Breaking Changes, Meta",
|
||||||
|
"Changelog entry on line 3 does not reference an issue",
|
||||||
|
"Unexpected content \"Loose text\" on line 4",
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
it("rejects the unedited template", function() {
|
||||||
|
const text = body(
|
||||||
|
"```", "### Features", "- Added doodad to web interface. #999", "", "### Changes", "- ...", "```",
|
||||||
|
);
|
||||||
|
assert.deepEqual(findChangelogProblems(text), ["Changelog entry on line 5 does not reference an issue"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
// Spec reporter controlling console output with TEST_OUTPUT:
|
||||||
|
// verbose prints everything, normal (default) prints only output from failing
|
||||||
|
// tests and hooks, silent prints only the results.
|
||||||
|
"use strict";
|
||||||
|
const util = require("node:util");
|
||||||
|
const Mocha = require("mocha");
|
||||||
|
|
||||||
|
const { Spec } = Mocha.reporters;
|
||||||
|
const { EVENT_TEST_FAIL, EVENT_TEST_PASS, EVENT_TEST_PENDING } = Mocha.Runner.constants;
|
||||||
|
const methods = ["log", "info", "debug", "warn", "error"];
|
||||||
|
const modes = ["verbose", "normal", "silent"];
|
||||||
|
|
||||||
|
class CaptureReporter extends Spec {
|
||||||
|
constructor(runner, options) {
|
||||||
|
super(runner, options);
|
||||||
|
const mode = process.env.TEST_OUTPUT || "normal";
|
||||||
|
if (!modes.includes(mode)) {
|
||||||
|
throw new Error(`Invalid TEST_OUTPUT "${mode}", expected one of ${modes.join(", ")}`);
|
||||||
|
}
|
||||||
|
if (mode === "verbose") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const original = {};
|
||||||
|
const captured = [];
|
||||||
|
for (const method of methods) {
|
||||||
|
original[method] = console[method];
|
||||||
|
console[method] = mode === "silent"
|
||||||
|
? () => {}
|
||||||
|
: (...args) => { captured.push([method, util.format(...args)]); };
|
||||||
|
}
|
||||||
|
|
||||||
|
const discard = () => { captured.length = 0; };
|
||||||
|
runner.on(EVENT_TEST_PASS, discard);
|
||||||
|
runner.on(EVENT_TEST_PENDING, discard);
|
||||||
|
// Prepend so the output lands above the failure line.
|
||||||
|
runner.prependListener(EVENT_TEST_FAIL, () => {
|
||||||
|
for (const [method, text] of captured) {
|
||||||
|
original[method](text);
|
||||||
|
}
|
||||||
|
discard();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = CaptureReporter;
|
||||||
@@ -5,11 +5,8 @@ import { ConsoleTransport, TerminalFormat, logger } from "@clusterio/lib";
|
|||||||
// running tests individually.
|
// running tests individually.
|
||||||
|
|
||||||
before(function() {
|
before(function() {
|
||||||
const silent = process.env.SILENT_TEST;
|
|
||||||
|
|
||||||
logger.add(new ConsoleTransport({
|
logger.add(new ConsoleTransport({
|
||||||
level: "info",
|
level: "info",
|
||||||
format: new TerminalFormat(),
|
format: new TerminalFormat(),
|
||||||
filter: () => !silent,
|
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"extends": "./tsconfig.base.json",
|
"extends": "./tsconfig.base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"lib": ["es2023"],
|
"lib": ["es2024", "es2025.collection"],
|
||||||
"types": ["node"],
|
"types": ["node"],
|
||||||
"module": "nodenext",
|
"module": "nodenext",
|
||||||
"moduleResolution": "node16",
|
"moduleResolution": "node16",
|
||||||
|
|||||||
Reference in new issue
Block a user