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", () => {
|
||||
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");
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user