fix(monitor): use global console channel and implement shard filtering
Lint / pre-commit Linting (push) Successful in 44s
Test / Run Tests (push) Successful in 1m4s

This commit is contained in:
2026-05-16 20:26:32 +02:00
parent 6384addc42
commit d02f44f6c7
4 changed files with 39 additions and 16 deletions
+26 -11
View File
@@ -53,20 +53,20 @@ describe("isOfficialServer", () => {
});
describe("buildSubscribePath", () => {
it("returns shard0/console for official server (no shard provided)", () => {
expect(buildSubscribePath("screeps.com")).toBe("shard0/console");
it("returns console for official server (no shard provided)", () => {
expect(buildSubscribePath("screeps.com")).toBe("console");
});
it("returns console for private server (no shard provided)", () => {
expect(buildSubscribePath("builder64")).toBe("console");
});
it("returns <shard>/console when shard is provided (official)", () => {
expect(buildSubscribePath("screeps.com", "shard3")).toBe("shard3/console");
it("returns console when shard is provided (official)", () => {
expect(buildSubscribePath("screeps.com", "shard3")).toBe("console");
});
it("returns <shard>/console when shard is provided (private)", () => {
expect(buildSubscribePath("builder64", "myshard")).toBe("myshard/console");
it("returns console when shard is provided (private)", () => {
expect(buildSubscribePath("builder64", "myshard")).toBe("console");
});
});
@@ -228,6 +228,21 @@ describe("handleConsoleEvent", () => {
handleConsoleEvent(event, { logToFile: false }, stdoutBuffer, state),
).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");
});
});
// ────────────────────────────────────────────────────────────────────────────
@@ -357,19 +372,19 @@ describe("monitorConsole", () => {
);
});
it("subscribes to 'shard0/console' for the official server (default)", async () => {
it("subscribes to 'console' for the official server (default)", async () => {
const api = buildMockApi({
hostname: "screeps.com",
ticks: [100, 101, 102, 103],
});
await monitorConsole(api, { ...BASE_OPTS, hostname: "screeps.com" });
expect(api.socket.subscribe).toHaveBeenCalledWith(
"shard0/console",
"console",
expect.any(Function),
);
});
it("subscribes to custom shard when provided", async () => {
it("subscribes to 'console' even when custom shard is provided", async () => {
const api = buildMockApi({
hostname: "screeps.com",
ticks: [100, 101, 102, 103],
@@ -380,10 +395,10 @@ describe("monitorConsole", () => {
shard: "shard3",
});
expect(api.socket.subscribe).toHaveBeenCalledWith(
"shard3/console",
"console",
expect.any(Function),
);
// Verify polling also uses shard3
// Verify polling still uses shard3 for timing
expect(api.time).toHaveBeenCalledWith("shard3");
});
+1 -1
View File
File diff suppressed because one or more lines are too long
+11 -3
View File
@@ -29,8 +29,9 @@ export function isOfficialServer(hostname) {
* @returns {string}
*/
export function buildSubscribePath(hostname, shard) {
if (shard) return `${shard}/console`;
return isOfficialServer(hostname) ? "shard0/console" : "console";
// The console channel on Screeps official and most private servers is 'console'.
// We subscribe to the aggregate feed and filter by shard in handleConsoleEvent.
return "console";
}
/**
@@ -178,8 +179,15 @@ export async function uploadLogArtifact(
* @param {{ sawTraceback: boolean, sawErrorLog: boolean, sawWarningLog: boolean }} state
*/
export function handleConsoleEvent(event, opts, stdoutBuffer, state) {
const { logToFile } = opts;
const { logToFile, shard: targetShard } = opts;
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 results = data?.messages?.results ?? [];
const errorText = data?.error ?? null;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "screeps-deploy-action",
"version": "0.2.0",
"version": "0.2.1",
"description": "Deploys screeps code to the official game or a private server.",
"type": "module",
"main": "index.js",