Skip to content

Commit a9c4c37

Browse files
committed
fix: add defensive guard on child.aliases in collectChildNames
Stricli always provides aliases at runtime (empty array when none), but type it as optional and use ?? [] for defensive safety per Seer and BugBot review feedback.
1 parent 3df1287 commit a9c4c37

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/lib/list-command.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,13 @@ export const LIST_BASE_ALIASES: Aliases<string> = { n: "limit", c: "cursor" };
336336
let _subcommandsByRoute: Map<string, Set<string>> | undefined;
337337

338338
/**
339-
* Get the subcommand names for a given singular route (e.g. "project" → {"list", "view"}).
340-
*
341-
* Lazily walks the Stricli route map on first call. Uses `require()` to break
342-
* the circular dependency: list-command → app → commands → list-command.
339+
* Entry shape returned by Stricli's getAllEntries().
340+
* `aliases` is always present at runtime (empty array when none),
341+
* but typed as optional for defensive safety.
343342
*/
344-
/** Entry shape returned by Stricli's getAllEntries() */
345343
type RouteEntry = {
346344
name: { original: string };
347-
aliases: readonly string[];
345+
aliases?: readonly string[];
348346
target: unknown;
349347
};
350348

@@ -355,13 +353,19 @@ function collectChildNames(parent: {
355353
const names = new Set<string>();
356354
for (const child of parent.getAllEntries()) {
357355
names.add(child.name.original);
358-
for (const alias of child.aliases) {
356+
for (const alias of child.aliases ?? []) {
359357
names.add(alias);
360358
}
361359
}
362360
return names;
363361
}
364362

363+
/**
364+
* Get the subcommand names for a given singular route (e.g. "project" → {"list", "view"}).
365+
*
366+
* Lazily walks the Stricli route map on first call. Uses `require()` to break
367+
* the circular dependency: list-command → app → commands → list-command.
368+
*/
365369
function getSubcommandsForRoute(routeName: string): Set<string> {
366370
if (!_subcommandsByRoute) {
367371
_subcommandsByRoute = new Map();

0 commit comments

Comments
 (0)