Skip to content

Commit c3f1684

Browse files
masatohoshinovincentkoc
authored andcommitted
fix(logs): report truncated channel tails
Punchcard-Session: golden-timber-willow-68
1 parent 4343b38 commit c3f1684

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎src/commands/channels.logs.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ function readJsonPayload() {
5353
return JSON.parse(String(runtime.log.mock.calls[0]?.[0])) as {
5454
file: string;
5555
channel: string;
56+
truncated: boolean;
5657
lines: Array<{ message: string; raw: string }>;
5758
};
5859
}
@@ -216,6 +217,21 @@ describe("channelsLogsCommand", () => {
216217
]);
217218
});
218219

220+
it("reports when the byte window omits all matching channel records", async () => {
221+
const omitted = logLine({ module: "gateway/channels/slack/send", message: "omitted" });
222+
const filler = logLine({ module: "gateway/health", message: "x".repeat(1000) });
223+
await fs.writeFile(logPath, `${omitted}\n${filler.repeat(1100)}`);
224+
225+
await channelsLogsCommand({ channel: "slack", json: true }, runtime);
226+
expect(readJsonPayload()).toMatchObject({ truncated: true, lines: [] });
227+
228+
runtime.log.mockClear();
229+
await channelsLogsCommand({ channel: "slack" }, runtime);
230+
expect(runtime.log.mock.calls.flat().join("\n")).toContain(
231+
"Log tail truncated; earlier entries were omitted.",
232+
);
233+
});
234+
219235
it("treats an omitted channel filter as all", async () => {
220236
await fs.writeFile(
221237
logPath,

‎src/commands/channels/logs.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,20 @@ export async function channelsLogsCommand(
104104
maxBytes: MAX_BYTES,
105105
filter: (line) => matchesChannel(line, filter),
106106
});
107-
const lines = tail.lines;
107+
const { lines, truncated } = tail;
108108

109109
if (opts.json) {
110-
writeRuntimeJson(runtime, { file: tail.file, channel, lines });
110+
writeRuntimeJson(runtime, { file: tail.file, channel, truncated, lines });
111111
return;
112112
}
113113

114114
runtime.log(theme.info(`Log file: ${tail.file}`));
115115
if (channel !== "all") {
116116
runtime.log(theme.info(`Channel: ${channel}`));
117117
}
118+
if (truncated) {
119+
runtime.log(theme.warn("Log tail truncated; earlier entries were omitted."));
120+
}
118121
if (lines.length === 0) {
119122
runtime.log(theme.muted("No matching log lines."));
120123
return;

0 commit comments

Comments
 (0)