test: add infra stage parser coverage#1868
Conversation
| it("extracts branch names from git branch preview stages", () => { | ||
| expect(parseStageName("git-branch-add-infra-tests")).toEqual({ | ||
| variant: "git-branch", | ||
| branch: "add-infra-tests", | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Missing edge-case: empty branch after the prefix
parseStageName("git-branch-") currently returns { variant: "git-branch", branch: "" } — an empty string branch. Downstream in sst.config.ts, that value is interpolated directly into a Vercel preview URL, yielding a double-dash segment (…-git--mc-ilroy.vercel.app) which Vercel won't resolve. A test asserting that "git-branch-" either throws or is treated as unsupported would make the acceptable input contract explicit.
Prompt To Fix With AI
This is a comment left during a code review.
Path: infra/stage.test.ts
Line: 10-15
Comment:
**Missing edge-case: empty branch after the prefix**
`parseStageName("git-branch-")` currently returns `{ variant: "git-branch", branch: "" }` — an empty string branch. Downstream in `sst.config.ts`, that value is interpolated directly into a Vercel preview URL, yielding a double-dash segment (`…-git--mc-ilroy.vercel.app`) which Vercel won't resolve. A test asserting that `"git-branch-"` either throws or is treated as unsupported would make the acceptable input contract explicit.
How can I resolve this? If you propose a fix, please make it concise.| if (stage.startsWith("git-branch-")) | ||
| return { | ||
| variant: "git-branch", | ||
| branch: stage.slice("git-branch-".length), | ||
| }; |
There was a problem hiding this comment.
Guard against a bare
"git-branch-" input (empty branch name). An empty branch string propagates silently and produces a malformed Vercel preview URL in sst.config.ts.
| if (stage.startsWith("git-branch-")) | |
| return { | |
| variant: "git-branch", | |
| branch: stage.slice("git-branch-".length), | |
| }; | |
| if (stage.startsWith("git-branch-")) { | |
| const branch = stage.slice("git-branch-".length); | |
| if (!branch) throw new Error("Unsupported stage"); | |
| return { variant: "git-branch", branch }; | |
| } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: infra/stage.ts
Line: 9-13
Comment:
Guard against a bare `"git-branch-"` input (empty branch name). An empty `branch` string propagates silently and produces a malformed Vercel preview URL in `sst.config.ts`.
```suggestion
if (stage.startsWith("git-branch-")) {
const branch = stage.slice("git-branch-".length);
if (!branch) throw new Error("Unsupported stage");
return { variant: "git-branch", branch };
}
```
How can I resolve this? If you propose a fix, please make it concise.|
Follow-up after the automated review: I addressed Greptile's edge-case note in f70b8ca by rejecting a bare \git-branch-\ stage and adding coverage for it. The non-Vercel checks are green/neutral; the remaining Vercel status appears to be the authorization URL rather than a code failure. |
/claim #54
Summary
Validation
Greptile Summary
This PR extracts the inline
parsedStageclosure insst.config.tsinto a standaloneparseStageNamehelper instage.ts, and wires up a focused Vitest suite for the@cap/infraworkspace.stage.ts: New module exportingParsedStagediscriminated union andparseStageName; logic is a direct lift from the original inline function with no behavioural change.stage.test.ts: Four Vitest cases coveringstaging,production, agit-branch-*prefix, and an unsupported stage throw; the empty-prefix edge case (\"git-branch-\"→ emptybranchstring) is not currently tested or guarded.package.json/pnpm-lock.yaml: Adds vitest~2.1.9as a dev dependency (reuses an existing resolved entry in the lockfile) and atestscript, making the workspace participate inpnpm turbo test.Confidence Score: 4/5
Safe to merge; the only gap is a silent empty-branch path that was already latent before this change.
The refactor is a straightforward extraction with no changed behaviour. The one unaddressed case — parseStageName("git-branch-") returning an empty branch — was already silently possible before this PR via the inline function, and is not made worse here. The tests and helper both look correct for all documented stage names.
infra/stage.ts and infra/stage.test.ts — the empty-branch guard and corresponding test case.
Important Files Changed
Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "test: add infra stage parser coverage" | Re-trigger Greptile