Skip to content

Commit 1edd523

Browse files
committed
fix(commands): add regression test for Stricli numberParser defaults (#640)
Stricli does pass string defaults through parse() at runtime, so numberParser flags receive the correct number type. Added a regression test to guard against future Stricli changes and clarified comments at all affected call sites.
1 parent 0898abe commit 1edd523

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

src/commands/auth/login.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export const loginCommand = buildCommand({
127127
kind: "parsed",
128128
parse: numberParser,
129129
brief: "Timeout for OAuth flow in seconds (default: 900)",
130-
// Stricli requires string defaults (raw CLI input); numberParser converts to number
130+
// Stricli passes string defaults through parse(); numberParser converts to number
131131
default: "900",
132132
},
133133
force: {

src/commands/release/set-commits.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ export const setCommitsCommand = buildCommand({
210210
kind: "parsed",
211211
parse: numberParser,
212212
brief: "Number of commits to read with --local",
213-
default: "20",
213+
default: "20", // Stricli passes string defaults through parse(); numberParser converts to number
214214
},
215215
},
216216
},

src/lib/list-command.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ export function paginationHint(opts: {
252252
* Build the `--limit` / `-n` flag for a list command.
253253
*
254254
* @param entityPlural - Plural entity name used in the brief (e.g. "teams")
255-
* @param defaultValue - Default limit as a string (default: "30")
255+
* @param defaultValue - Default limit as a string — Stricli passes it through
256+
* numberParser at runtime, so the command receives a number (default: "30")
256257
*/
257258
export function buildListLimitFlag(
258259
entityPlural: string,

test/lib/command.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,44 @@ describe("buildCommand telemetry integration", () => {
168168
expect(setTagSpy).toHaveBeenCalledWith("flag.limit", "50");
169169
});
170170

171+
test("passes string defaults through parse() — numberParser default is number at runtime", async () => {
172+
let receivedFlags: Record<string, unknown> | null = null;
173+
174+
const command = buildCommand<{ limit: number }, [], TestContext>({
175+
auth: false,
176+
docs: { brief: "Test" },
177+
parameters: {
178+
flags: {
179+
limit: {
180+
kind: "parsed",
181+
parse: numberParser,
182+
brief: "Limit",
183+
default: "10",
184+
},
185+
},
186+
},
187+
// biome-ignore lint/correctness/useYield: test command — no output to yield
188+
async *func(this: TestContext, flags: { limit: number }) {
189+
receivedFlags = flags as unknown as Record<string, unknown>;
190+
},
191+
});
192+
193+
const routeMap = buildRouteMap({
194+
routes: { test: command },
195+
docs: { brief: "Test app" },
196+
});
197+
const app = buildApplication(routeMap, { name: "test" });
198+
const ctx = createTestContext();
199+
200+
// Run WITHOUT --limit to exercise the default path
201+
await run(app, ["test"], ctx as TestContext);
202+
203+
expect(receivedFlags).not.toBeNull();
204+
// Critical: must be number 10, not string "10"
205+
expect(receivedFlags!.limit).toBe(10);
206+
expect(typeof receivedFlags!.limit).toBe("number");
207+
});
208+
171209
test("skips false boolean flags in telemetry", async () => {
172210
const command = buildCommand<{ json: boolean }, [], TestContext>({
173211
auth: false,

0 commit comments

Comments
 (0)