Skip to content

Commit db8e1bd

Browse files
committed
fix(observability-map): print the unknown-suppression warning once
The CLI sent the warning to stderr for the whole-report path and renderTerminal embedded the same lines in the stdout report body, so a plain run showed every warning twice. Stderr now carries it only when stdout is JSON a caller parses, which is the reason that loop existed. The terminal report keeps it in the body, so redirecting stdout to a file loses nothing. The single-route path is unchanged: its terminal output never carried the warning, so it never duplicated.
1 parent 77179f1 commit db8e1bd

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

internal-packages/observability-map/src/cli.test.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,29 @@ describe("map", () => {
155155
});
156156
});
157157

158-
// B6. Stdout can be JSON a caller parses, so the warning goes to stderr in every mode, and the
159-
// terminal report carries it too (see report.test.ts).
158+
// B6. Stdout can be JSON a caller parses, so the warning goes to stderr whenever stdout is JSON.
159+
// The terminal report carries it in its body instead (`src/report/terminal.test.ts`), and printing
160+
// it on both streams meant a plain run showed every warning twice.
160161
describe("warning about a suppression that names no check", () => {
161-
it("names the file and the bad id on stderr for the whole report", () => {
162+
it("names the file and the bad id in the whole report", () => {
162163
const r = run("--no-write");
163164
expect(r.code).toBe(0);
165+
expect(r.out).toContain("api.v1.typo.ts");
166+
expect(r.out).toContain("eror-classification");
167+
});
168+
169+
it("prints the warning once for a terminal run of the whole report", () => {
170+
const r = run("--no-write");
171+
const lines = `${r.out}${r.err}`.split("\n").filter((l) => l.startsWith("UNKNOWN SUPPRESSION"));
172+
expect(lines).toHaveLength(1);
173+
});
174+
175+
it("names the file and the bad id on stderr when the whole report is json", () => {
176+
const r = run("--no-write", "--json");
177+
expect(r.code).toBe(0);
164178
expect(r.err).toContain("api.v1.typo.ts");
165179
expect(r.err).toContain("eror-classification");
180+
expect(r.out).not.toContain("UNKNOWN SUPPRESSION");
166181
});
167182

168183
it("warns for a single route without putting the warning in the json", () => {

internal-packages/observability-map/src/cli.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ export function main(argv: string[], io: Io = processIo): number {
130130
}
131131

132132
const report = buildReport(entryPoints, parseFailures);
133-
for (const line of unknownSuppressionLines(report)) io.err(`${line}\n`);
133+
// JSON only. `renderTerminal` puts these lines in the report body, so warning here as well
134+
// printed each one twice in a terminal run. Stderr is what the JSON path has instead, since a
135+
// warning on stdout would be inside the document a caller parses.
136+
if (asJson) for (const line of unknownSuppressionLines(report)) io.err(`${line}\n`);
134137
io.out(asJson ? renderJson(report) : renderTerminal(report));
135138
io.out("\n");
136139
if (!noWrite) {

0 commit comments

Comments
 (0)