Skip to content

Commit 8fb818b

Browse files
committed
fix(log-view): address Seer and Bugbot review findings
- Cap per_page at API_MAX_PER_PAGE (100) in getLogs to prevent silent truncation when >100 log IDs are requested - Fix parsePositionalArgs docstring: remove false claim about multi-ID auto-detect pattern (2+ args always treats first as target) - Fix trace/logs.ts callers to use normalized return value from validateTraceId instead of discarding it - Update trace/logs test for lowercase normalization
1 parent eac96ec commit 8fb818b

File tree

4 files changed

+10
-11
lines changed

4 files changed

+10
-11
lines changed

src/commands/log/view.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ function splitLogIds(arg: string): string[] {
5252
* Parse positional arguments for log view.
5353
* Handles:
5454
* - `<log-id>` — single log ID (auto-detect org/project)
55-
* - `<log-id1> <log-id2> ...` — multiple log IDs (auto-detect)
5655
* - `<target> <log-id> [<log-id>...]` — explicit target + one or more log IDs
5756
* - `<org>/<project>/<log-id>` — single slash-separated arg
5857
*
58+
* When two or more args are provided, the first is always treated as the
59+
* target (org/project specifier) and the rest as log IDs.
60+
*
5961
* Arguments containing newlines are split into multiple IDs.
6062
*
6163
* @param args - Positional arguments from CLI

src/commands/trace/logs.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,11 @@ export function parsePositionalArgs(args: string[]): {
8989
throw new ContextError("Trace ID", USAGE_HINT);
9090
}
9191

92-
validateTraceId(traceId);
93-
return { traceId, orgArg };
92+
return { traceId: validateTraceId(traceId), orgArg };
9493
}
9594

9695
// Plain trace ID — org will be auto-detected
97-
validateTraceId(first);
98-
return { traceId: first, orgArg: undefined };
96+
return { traceId: validateTraceId(first), orgArg: undefined };
9997
}
10098

10199
// Two or more args — first is org, second is trace ID
@@ -106,8 +104,7 @@ export function parsePositionalArgs(args: string[]): {
106104
throw new ContextError("Trace ID", USAGE_HINT);
107105
}
108106

109-
validateTraceId(traceId);
110-
return { traceId, orgArg };
107+
return { traceId: validateTraceId(traceId), orgArg };
111108
}
112109

113110
export const logsCommand = buildCommand({

src/lib/api-client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,8 +1802,8 @@ export async function getLogs(
18021802
dataset: "logs",
18031803
field: DETAILED_LOG_FIELDS,
18041804
query,
1805-
// per_page must match the number of IDs so the API returns all matches
1806-
per_page: logIds.length,
1805+
// Cap at API_MAX_PER_PAGE — the API silently truncates larger values
1806+
per_page: Math.min(logIds.length, API_MAX_PER_PAGE),
18071807
statsPeriod: "90d",
18081808
},
18091809
});

test/commands/trace/logs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ describe("parsePositionalArgs", () => {
5757
expect(result.orgArg).toBeUndefined();
5858
});
5959

60-
test("accepts mixed-case hex trace ID", () => {
60+
test("normalizes mixed-case hex trace ID to lowercase", () => {
6161
const mixedCase = "AAAA1111bbbb2222CCCC3333dddd4444";
6262
const result = parsePositionalArgs([mixedCase]);
63-
expect(result.traceId).toBe(mixedCase);
63+
expect(result.traceId).toBe(mixedCase.toLowerCase());
6464
expect(result.orgArg).toBeUndefined();
6565
});
6666
});

0 commit comments

Comments
 (0)