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
+19 -9
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`
const MockClient = vi.fn(function () {
return mockApi;
});
return {
ScreepsAPI: vi.fn(function () {
return mockApi;
}),
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", {
main: "old_code",
expect(mockApiInstance.userCodeSet).toHaveBeenCalledTimes(2);
expect(mockApiInstance.userCodeSet).toHaveBeenNthCalledWith(2, {
branch: "default",
modules: {
main: "old_code",
},
});
// Verify it called core.setFailed due to traceback