Skip to content

Commit 3aca34b

Browse files
veksenclaude
andcommitted
fix: count only analyzed queries in queryStats.total
Move queryStats.total++ past all early-return filters (ignored, introspection, duplicate, catalog) so it reflects the actual number of unique queries analyzed — not the raw log entry count. This fixes the mismatch between the PR comment ("X queries analyzed") and the app's query list without needing a post-hoc patch in main.ts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 78a3d81 commit 3aca34b

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

src/reporters/github/github.test.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
11
import { test, expect, describe } from "vitest";
2+
import { readFileSync } from "node:fs";
3+
import { fileURLToPath } from "node:url";
4+
import { dirname, join } from "node:path";
5+
import n from "nunjucks";
26
import { formatCost, queryPreview, buildViewModel } from "./github.ts";
3-
import type { ReportContext } from "../reporter.ts";
7+
import { isQueryLong, renderExplain, type ReportContext } from "../reporter.ts";
48
import type { RunComparison } from "../site-api.ts";
59

10+
const __filename = fileURLToPath(import.meta.url);
11+
const __dirname = dirname(__filename);
12+
const successTemplate = readFileSync(join(__dirname, "success.md.j2"), "utf-8");
13+
14+
n.configure({ autoescape: false, trimBlocks: true, lstripBlocks: true });
15+
16+
function renderTemplate(ctx: ReportContext) {
17+
const viewModel = buildViewModel(ctx);
18+
return n.renderString(successTemplate, {
19+
...ctx,
20+
...viewModel,
21+
isQueryLong,
22+
renderExplain,
23+
formatCost,
24+
});
25+
}
26+
627
describe("formatCost", () => {
728
test("formats small numbers without commas", () => {
829
expect(formatCost(9)).toBe("9");
@@ -300,3 +321,22 @@ describe("buildViewModel", () => {
300321
});
301322

302323
});
324+
325+
describe("template rendering", () => {
326+
test("renders queryStats.total as the query count", () => {
327+
const ctx = makeContext({
328+
queryStats: { total: 5, matched: 3, optimized: 1, errored: 0 },
329+
comparison: makeComparison(),
330+
});
331+
const output = renderTemplate(ctx);
332+
expect(output).toContain("5 queries analyzed");
333+
});
334+
335+
test("renders queryStats.total in no-comparison mode", () => {
336+
const ctx = makeContext({
337+
queryStats: { total: 3, matched: 1, optimized: 0, errored: 0 },
338+
});
339+
const output = renderTemplate(ctx);
340+
expect(output).toContain("3 queries analyzed");
341+
});
342+
});

src/reporters/reporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export type ReportMetadata = {
6262
declare const s: unique symbol;
6363

6464
export interface ReportStatistics {
65-
/** Total number of queries seen in the log */
65+
/** Number of unique, non-filtered queries analyzed */
6666
total: number;
6767
/** Number of queries that matched the query pattern */
6868
matched: number;

src/runner.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ export class Runner {
108108
if (loglevel !== "LOG" || !queryString.startsWith("plan:")) {
109109
continue;
110110
}
111-
total++;
112111
const planString: string = queryString.split("plan:")[1].trim();
113112
const json = preprocessEncodedJson(planString);
114113
if (!json) {
@@ -135,6 +134,7 @@ export class Runner {
135134
continue;
136135
}
137136

137+
total++;
138138
const recentQuery = await RecentQuery.fromLogEntry(query, hash);
139139
recentQueries.push(recentQuery)
140140
}

0 commit comments

Comments
 (0)