Skip to content

Commit 5588e27

Browse files
committed
fix: add tests for CLI-SC/CLI-WD fixes and update stale comments in app.ts
- Add 3 tests for bare span ID detection (CLI-SC): ContextError type, error message content, and dash-formatted span ID handling - Add 1 test for middle-component platform matching (CLI-WD): javascript-cloudflare → node-cloudflare-pages/workers - Update two comments in app.ts that referenced 'events' as an unrecognized token — now a registered route after CLI-QZ fix
1 parent 456df27 commit 5588e27

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

src/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ const customText: ApplicationText = {
247247
return `${text_en.exceptionWhileParsingArguments(exc, ansiColor)}${pluralHint}`;
248248
}
249249

250-
// With defaultCommand: "view", unknown tokens like "events" fill the
250+
// With defaultCommand: "view", unknown tokens like "metrics" fill the
251251
// positional slot, then extra args (e.g., CLI-AB) trigger this error.
252252
// Check if the first non-route token is a known synonym.
253253
const synonymHint = getSynonymSuggestionFromArgv();
@@ -308,7 +308,7 @@ const customText: ApplicationText = {
308308
throw exc;
309309
}
310310

311-
// Case C: With defaultCommand: "view", unknown tokens like "events" are
311+
// Case C: With defaultCommand: "view", unknown tokens like "metrics" are
312312
// silently consumed as the positional arg. The view command fails at the
313313
// domain level (e.g., ResolutionError). Check argv for a known synonym
314314
// and show the suggestion — skip Sentry capture since these are known

test/commands/span/view.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,32 @@ describe("parsePositionalArgs", () => {
222222
ValidationError
223223
);
224224
});
225+
226+
test("throws ContextError for bare span ID without trace ID (CLI-SC)", () => {
227+
expect(() => parsePositionalArgs(["a1b2c3d4e5f67890"])).toThrow(
228+
ContextError
229+
);
230+
});
231+
232+
test("bare span ID error identifies the input and suggests correct usage", () => {
233+
try {
234+
parsePositionalArgs(["A1B2C3D4E5F67890"]);
235+
expect.unreachable("Should have thrown");
236+
} catch (error) {
237+
expect(error).toBeInstanceOf(ContextError);
238+
const msg = (error as ContextError).message;
239+
expect(msg).toContain("looks like a span ID");
240+
expect(msg).toContain("sentry span view <trace-id> a1b2c3d4e5f67890");
241+
expect(msg).toContain("sentry trace list");
242+
}
243+
});
244+
245+
test("bare span ID with dashes is still detected (CLI-SC)", () => {
246+
// Some tools format span IDs with dashes
247+
expect(() => parsePositionalArgs(["a1b2-c3d4-e5f6-7890"])).toThrow(
248+
ContextError
249+
);
250+
});
225251
});
226252
});
227253

test/lib/platforms.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ describe("suggestPlatform", () => {
6868
expect(results).toContain("javascript-react");
6969
});
7070

71+
test("suggests middle-component match: javascript-cloudflare → node-cloudflare-* (CLI-WD)", () => {
72+
const results = suggestPlatform("javascript-cloudflare");
73+
expect(results).toContain("node-cloudflare-pages");
74+
expect(results).toContain("node-cloudflare-workers");
75+
});
76+
7177
test("returns empty array for garbage input", () => {
7278
expect(suggestPlatform("xyzgarbage")).toEqual([]);
7379
});

0 commit comments

Comments
 (0)