fix(monitor): use global console channel and implement shard filtering
This commit is contained in:
+26
-11
@@ -53,20 +53,20 @@ describe("isOfficialServer", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("buildSubscribePath", () => {
|
describe("buildSubscribePath", () => {
|
||||||
it("returns shard0/console for official server (no shard provided)", () => {
|
it("returns console for official server (no shard provided)", () => {
|
||||||
expect(buildSubscribePath("screeps.com")).toBe("shard0/console");
|
expect(buildSubscribePath("screeps.com")).toBe("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 <shard>/console when shard is provided (official)", () => {
|
it("returns console when shard is provided (official)", () => {
|
||||||
expect(buildSubscribePath("screeps.com", "shard3")).toBe("shard3/console");
|
expect(buildSubscribePath("screeps.com", "shard3")).toBe("console");
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns <shard>/console when shard is provided (private)", () => {
|
it("returns console when shard is provided (private)", () => {
|
||||||
expect(buildSubscribePath("builder64", "myshard")).toBe("myshard/console");
|
expect(buildSubscribePath("builder64", "myshard")).toBe("console");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -228,6 +228,21 @@ 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");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ────────────────────────────────────────────────────────────────────────────
|
// ────────────────────────────────────────────────────────────────────────────
|
||||||
@@ -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({
|
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(
|
||||||
"shard0/console",
|
"console",
|
||||||
expect.any(Function),
|
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({
|
const api = buildMockApi({
|
||||||
hostname: "screeps.com",
|
hostname: "screeps.com",
|
||||||
ticks: [100, 101, 102, 103],
|
ticks: [100, 101, 102, 103],
|
||||||
@@ -380,10 +395,10 @@ describe("monitorConsole", () => {
|
|||||||
shard: "shard3",
|
shard: "shard3",
|
||||||
});
|
});
|
||||||
expect(api.socket.subscribe).toHaveBeenCalledWith(
|
expect(api.socket.subscribe).toHaveBeenCalledWith(
|
||||||
"shard3/console",
|
"console",
|
||||||
expect.any(Function),
|
expect.any(Function),
|
||||||
);
|
);
|
||||||
// Verify polling also uses shard3
|
// Verify polling still uses shard3 for timing
|
||||||
expect(api.time).toHaveBeenCalledWith("shard3");
|
expect(api.time).toHaveBeenCalledWith("shard3");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+11
-3
@@ -29,8 +29,9 @@ export function isOfficialServer(hostname) {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
export function buildSubscribePath(hostname, shard) {
|
export function buildSubscribePath(hostname, shard) {
|
||||||
if (shard) return `${shard}/console`;
|
// The console channel on Screeps official and most private servers is 'console'.
|
||||||
return isOfficialServer(hostname) ? "shard0/console" : "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
|
* @param {{ sawTraceback: boolean, sawErrorLog: boolean, sawWarningLog: boolean }} state
|
||||||
*/
|
*/
|
||||||
export function handleConsoleEvent(event, opts, stdoutBuffer, state) {
|
export function handleConsoleEvent(event, opts, stdoutBuffer, state) {
|
||||||
const { logToFile } = opts;
|
const { logToFile, shard: targetShard } = 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
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "screeps-deploy-action",
|
"name": "screeps-deploy-action",
|
||||||
"version": "0.2.0",
|
"version": "0.2.1",
|
||||||
"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",
|
||||||
|
|||||||
Reference in New Issue
Block a user