refactor: migrate to screeps-api v2 and update actions to node 22
Test / Run Tests (push) Failing after 1s
Recompile dist/ on Renovate PR / recompile (pull_request) Failing after 0s
Test / Run Tests (pull_request) Failing after 0s
Philipp/Global-Workflows: Pre-commit Lint (Scoped) / pre-commit (pull_request) Failing after 1s

This commit is contained in:
2026-09-04 23:56:04 +02:00
parent d644b19b47
commit cfb97819ae
8 changed files with 68 additions and 33 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ jobs:
- uses: pnpm/action-setup@0977fd99725f1db4007ccb2928dbb4e90d06cc86 # v6.0.10
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: '24'
node-version: '22'
cache: pnpm
- run: pnpm install --frozen-lockfile
shell: bash
+1
View File
@@ -34,6 +34,7 @@ repos:
hooks:
- id: check-renovate
- id: check-github-actions
exclude: ^action\.yaml$
- id: check-github-workflows
- repo: https://github.com/pre-commit/pre-commit-hooks
+18 -8
View File
@@ -24,16 +24,23 @@ vi.mock("../monitor.js", () => ({
vi.mock("screeps-api", () => {
const mockApi = {
auth: vi.fn().mockResolvedValue(),
authSignin: vi.fn().mockResolvedValue({ ok: 1, token: "test_token" }),
userCodeGet: vi
.fn()
.mockResolvedValue({ ok: 1, modules: { main: "old_code" } }),
userCodeSet: vi.fn().mockResolvedValue({ ok: 1 }),
code: {
get: vi.fn().mockResolvedValue({ ok: 1, modules: { main: "old_code" } }),
set: vi.fn().mockResolvedValue({ ok: 1 }),
},
};
// Use a regular function so it can be called with `new`
return {
ScreepsAPI: vi.fn(function () {
const MockClient = vi.fn(function () {
return mockApi;
}),
});
return {
ScreepsHttpClient: MockClient,
ScreepsAPI: MockClient,
};
});
@@ -48,7 +55,7 @@ import {
applyOnAction,
postCode,
} from "../index.js";
import { ScreepsAPI } from "screeps-api";
import { ScreepsHttpClient } from "screeps-api";
import fs from "fs";
import path from "path";
import os from "os";
@@ -330,14 +337,17 @@ describe("postCode — monitor wiring", () => {
await postCode();
// Verify rollback was performed
const mockApiInstance = new ScreepsAPI();
const mockApiInstance = new ScreepsHttpClient();
// `code.set` should be called twice:
// `userCodeSet` should be called twice:
// 1st time: uploading the new files
// 2nd time: rolling back to oldCode
expect(mockApiInstance.code.set).toHaveBeenCalledTimes(2);
expect(mockApiInstance.code.set).toHaveBeenNthCalledWith(2, "default", {
expect(mockApiInstance.userCodeSet).toHaveBeenCalledTimes(2);
expect(mockApiInstance.userCodeSet).toHaveBeenNthCalledWith(2, {
branch: "default",
modules: {
main: "old_code",
},
});
// Verify it called core.setFailed due to traceback
+12 -4
View File
@@ -382,13 +382,21 @@ function buildMockApi({
disconnect: vi.fn(),
};
const api = {
opts: { hostname },
time: vi.fn().mockImplementation(() => {
const getTime = vi.fn().mockImplementation(() => {
const t = ticks[Math.min(tickIndex, ticks.length - 1)];
tickIndex++;
return Promise.resolve({ time: t });
}),
});
const api = {
opts: { hostname },
time: getTime,
get gameTime() {
return this.time;
},
set gameTime(fn) {
this.time = fn;
},
socket,
// Expose so tests can fire console events
_fireConsole: (eventData) => {
+1 -1
View File
@@ -79,5 +79,5 @@ outputs:
saw_warning_log:
description: true if console.warn output was detected during monitoring.
runs:
using: node20
using: node22
main: dist/index.js
+7 -7
View File
File diff suppressed because one or more lines are too long
+16 -4
View File
@@ -1,4 +1,4 @@
import { ScreepsAPI } from "screeps-api";
import { ScreepsHttpClient } from "screeps-api";
import * as core from "@actions/core";
import fs from "fs";
import { glob } from "glob";
@@ -180,12 +180,16 @@ export async function postCode() {
core.error(errorMessage);
return;
}
let api = new ScreepsAPI(login_arguments);
let api = new ScreepsHttpClient(login_arguments);
if (!token) {
core.info(`Logging in as user ${username}`);
try {
if (typeof api.authSignin === "function") {
await api.authSignin(username, password);
} else {
await api.auth(username, password, login_arguments);
}
} catch (err) {
core.error(`Authentication error: ${err}`);
throw err;
@@ -205,7 +209,9 @@ export async function postCode() {
`Downloading existing code from branch ${branch} for potential rollback...`,
);
try {
const getResponse = await api.code.get(branch);
const getResponse = await (api.userCodeGet
? api.userCodeGet(branch)
: api.code.get(branch));
if (getResponse && getResponse.ok && getResponse.modules) {
oldCode = getResponse.modules;
core.info(
@@ -226,7 +232,9 @@ export async function postCode() {
}
try {
const response = await api.code.set(branch, files_to_push);
const response = await (api.userCodeSet
? api.userCodeSet({ branch, modules: files_to_push })
: api.code.set(branch, files_to_push));
core.info(JSON.stringify(response, null, 2));
core.info(`Code set successfully to ${branch}`);
} catch (err) {
@@ -279,7 +287,11 @@ export async function postCode() {
"Action failed based on monitor configuration. Rolling back to previous code...",
);
try {
if (typeof api.userCodeSet === "function") {
await api.userCodeSet({ branch, modules: oldCode });
} else {
await api.code.set(branch, oldCode);
}
core.info(
`Successfully rolled back to previous code on branch ${branch}.`,
);
+8 -4
View File
@@ -250,7 +250,7 @@ function sleep(ms) {
* Calls `onProgress(elapsed, targetTicks)` on every poll so the caller can
* log progress at whatever cadence it chooses.
*
* @param {import('screeps-api').ScreepsAPI} api
* @param {import('screeps-api').ScreepsHttpClient} api
* @param {number} startTick - Tick number recorded before monitoring started
* @param {number} targetTicks - Stop when (currentTick - startTick) >= this
* @param {string|undefined} shard - "shard0" for official, undefined for private
@@ -270,7 +270,9 @@ export async function pollUntilDone(
let elapsed = 0;
while (elapsed < targetTicks && !shouldStop()) {
await sleep(intervalMs);
const { time } = await api.time(shard);
const { time } = await (typeof api.gameTime === "function"
? api.gameTime(shard)
: api.time(shard));
elapsed = time - startTick;
onProgress(elapsed, targetTicks);
}
@@ -309,7 +311,7 @@ export async function pollUntilDone(
* 6. If logToFile=true: write buffered stdout to a temp file and upload artifact.
* 7. Return MonitorResult.
*
* @param {import('screeps-api').ScreepsAPI} api
* @param {import('screeps-api').ScreepsHttpClient} api
* @param {MonitorOptions} opts
* @returns {Promise<MonitorResult>}
*/
@@ -337,7 +339,9 @@ export async function monitorConsole(api, opts) {
let lastProgressTick = 0;
// Step 1: record starting tick
const { time: startTick } = await api.time(shard);
const { time: startTick } = await (typeof api.gameTime === "function"
? api.gameTime(shard)
: api.time(shard));
// Step 2: connect socket + subscribe
await api.socket.connect();