Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion scripts/check-kpi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ let minTimestampMs = Number.POSITIVE_INFINITY;
let maxTimestampMs = Number.NEGATIVE_INFINITY;
let exchangesWithTimestamp = 0;

for (const line of lines) {
for (const [index, line] of lines.entries()) {
let record;
try {
record = JSON.parse(line);
} catch {
if (/^\s*[\[{]/.test(line)) {
console.error(`Malformed JSON in KPI log line ${index + 1}.`);
process.exit(1);
Comment on lines +63 to +65

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Malformed-JSON diagnostic reports wrong line number

lines drops blank lines via filter(Boolean), so the index from lines.entries() is a position in the filtered array, not the file line. Any blank line before a malformed JSON-looking line makes the reported line N point at the wrong line.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

}
// Wrangler tail can include non-JSON diagnostic noise; preserve that tolerance.
continue;
}
Expand Down
Empty file modified scripts/compute-kpi.mjs
100755 → 100644
Empty file.
19 changes: 19 additions & 0 deletions test/check-kpi-input-integrity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ describe("KPI threshold input integrity", () => {
}
});

it("rejects malformed JSON-looking lines instead of silently dropping threshold evidence", () => {
const dir = mkdtempSync(join(tmpdir(), "noema-check-kpi-"));
try {
const logPath = join(dir, "exchange-30d.ndjson");
writeFileSync(
logPath,
'{"event":"http_request","route":"/exchange","status_code":500,"latency_ms":120\n',
);

const result = runCheckKpi(logPath);

expect(result.status).toBe(1);
expect(result.stderr).toContain("Malformed JSON in KPI log line 1");
expect(result.stdout).toBe("");
} finally {
rmSync(dir, { recursive: true, force: true });
}
});

it("rejects an impossible calendar timestamp instead of normalizing it into window evidence", () => {
const dir = mkdtempSync(join(tmpdir(), "noema-check-kpi-time-"));
try {
Expand Down
Loading