1 Commits

Author SHA1 Message Date
Philipp bf52580bf3 feat: add Screeps console monitoring with configurable error handling and shard support (#84)
Lint / pre-commit Linting (push) Successful in 1m5s
Test / Run Tests (push) Successful in 1m23s
Reviewed-on: #84
2026-05-16 19:44:39 +02:00
4 changed files with 16 additions and 39 deletions
+11 -26
View File
@@ -53,20 +53,20 @@ describe("isOfficialServer", () => {
}); });
describe("buildSubscribePath", () => { describe("buildSubscribePath", () => {
it("returns console for official server (no shard provided)", () => { it("returns shard0/console for official server (no shard provided)", () => {
expect(buildSubscribePath("screeps.com")).toBe("console"); expect(buildSubscribePath("screeps.com")).toBe("shard0/console");
}); });
it("returns console for private server (no shard provided)", () => { it("returns console for private server (no shard provided)", () => {
expect(buildSubscribePath("builder64")).toBe("console"); expect(buildSubscribePath("builder64")).toBe("console");
}); });
it("returns console when shard is provided (official)", () => { it("returns <shard>/console when shard is provided (official)", () => {
expect(buildSubscribePath("screeps.com", "shard3")).toBe("console"); expect(buildSubscribePath("screeps.com", "shard3")).toBe("shard3/console");
}); });
it("returns console when shard is provided (private)", () => { it("returns <shard>/console when shard is provided (private)", () => {
expect(buildSubscribePath("builder64", "myshard")).toBe("console"); expect(buildSubscribePath("builder64", "myshard")).toBe("myshard/console");
}); });
}); });
@@ -228,21 +228,6 @@ describe("handleConsoleEvent", () => {
handleConsoleEvent(event, { logToFile: false }, stdoutBuffer, state), handleConsoleEvent(event, { logToFile: false }, stdoutBuffer, state),
).not.toThrow(); ).not.toThrow();
}); });
it("filters messages by shard when targetShard is provided", () => {
const event = { data: { shard: "shard0", messages: { log: ["msg0"] } } };
handleConsoleEvent(event, { shard: "shard1" }, stdoutBuffer, state);
expect(core.info).not.toHaveBeenCalled();
handleConsoleEvent(event, { shard: "shard0" }, stdoutBuffer, state);
expect(core.info).toHaveBeenCalledWith("msg0");
});
it("does not filter when targetShard is undefined", () => {
const event = { data: { shard: "shard0", messages: { log: ["msg0"] } } };
handleConsoleEvent(event, {}, stdoutBuffer, state);
expect(core.info).toHaveBeenCalledWith("msg0");
});
}); });
// ──────────────────────────────────────────────────────────────────────────── // ────────────────────────────────────────────────────────────────────────────
@@ -372,19 +357,19 @@ describe("monitorConsole", () => {
); );
}); });
it("subscribes to 'console' for the official server (default)", async () => { it("subscribes to 'shard0/console' for the official server (default)", async () => {
const api = buildMockApi({ const api = buildMockApi({
hostname: "screeps.com", hostname: "screeps.com",
ticks: [100, 101, 102, 103], ticks: [100, 101, 102, 103],
}); });
await monitorConsole(api, { ...BASE_OPTS, hostname: "screeps.com" }); await monitorConsole(api, { ...BASE_OPTS, hostname: "screeps.com" });
expect(api.socket.subscribe).toHaveBeenCalledWith( expect(api.socket.subscribe).toHaveBeenCalledWith(
"console", "shard0/console",
expect.any(Function), expect.any(Function),
); );
}); });
it("subscribes to 'console' even when custom shard is provided", async () => { it("subscribes to custom shard when provided", async () => {
const api = buildMockApi({ const api = buildMockApi({
hostname: "screeps.com", hostname: "screeps.com",
ticks: [100, 101, 102, 103], ticks: [100, 101, 102, 103],
@@ -395,10 +380,10 @@ describe("monitorConsole", () => {
shard: "shard3", shard: "shard3",
}); });
expect(api.socket.subscribe).toHaveBeenCalledWith( expect(api.socket.subscribe).toHaveBeenCalledWith(
"console", "shard3/console",
expect.any(Function), expect.any(Function),
); );
// Verify polling still uses shard3 for timing // Verify polling also uses shard3
expect(api.time).toHaveBeenCalledWith("shard3"); expect(api.time).toHaveBeenCalledWith("shard3");
}); });
+1 -1
View File
File diff suppressed because one or more lines are too long
+3 -11
View File
@@ -29,9 +29,8 @@ export function isOfficialServer(hostname) {
* @returns {string} * @returns {string}
*/ */
export function buildSubscribePath(hostname, shard) { export function buildSubscribePath(hostname, shard) {
// The console channel on Screeps official and most private servers is 'console'. if (shard) return `${shard}/console`;
// We subscribe to the aggregate feed and filter by shard in handleConsoleEvent. return isOfficialServer(hostname) ? "shard0/console" : "console";
return "console";
} }
/** /**
@@ -179,15 +178,8 @@ export async function uploadLogArtifact(
* @param {{ sawTraceback: boolean, sawErrorLog: boolean, sawWarningLog: boolean }} state * @param {{ sawTraceback: boolean, sawErrorLog: boolean, sawWarningLog: boolean }} state
*/ */
export function handleConsoleEvent(event, opts, stdoutBuffer, state) { export function handleConsoleEvent(event, opts, stdoutBuffer, state) {
const { logToFile, shard: targetShard } = opts; const { logToFile } = opts;
const data = event?.data ?? {}; const data = event?.data ?? {};
// Shard filtering: If a shard is specified in opts, only process messages from that shard.
// Official server events include a 'shard' property in event.data.
if (targetShard && data.shard && data.shard !== targetShard) {
return;
}
const logLines = data?.messages?.log ?? []; const logLines = data?.messages?.log ?? [];
const results = data?.messages?.results ?? []; const results = data?.messages?.results ?? [];
const errorText = data?.error ?? null; const errorText = data?.error ?? null;
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "screeps-deploy-action", "name": "screeps-deploy-action",
"version": "0.2.1", "version": "0.2.0",
"description": "Deploys screeps code to the official game or a private server.", "description": "Deploys screeps code to the official game or a private server.",
"type": "module", "type": "module",
"main": "index.js", "main": "index.js",