fix: sanitize branch name and update cli tests#7
Conversation
|
| Filename | Overview |
|---|---|
| lib/doctor.ts | New file implementing all doctor health checks. All four issues from previous review threads are addressed: detached HEAD is handled in checkUpstream (returns null), checkConfigPath now uses existsSync, checkApiKey has no configPath parameter, and checkGhAuth accepts ghAvailable:boolean instead of re-running gh --version. |
| scripts/cli.ts | Adds doctor and pull commands. Pull command correctly uses --rebase by default and checks for upstream before pulling, but does not guard against detached HEAD separately — giving a misleading error message in that state. |
| test/doctor.test.ts | New test file covering parseNodeMajor, summarizeDoctorChecks, and three runDoctorChecks scenarios via injected command runners. Tests correctly cover the detached HEAD/upstream skip, OpenRouter 401 fail, and missing-git-repo paths. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[gitgen doctor] --> B[runDoctorChecks]
B --> C[checkNode]
B --> D[checkGit]
B --> E[checkRepo]
E -->|inside work tree| F[checkBranch]
F -->|named branch| G[checkUpstream]
F -->|detached HEAD| H[null — skip upstream]
G -->|upstream set| I[ok]
G -->|no upstream| J[warn]
B --> K[checkApiKey]
B --> L[checkConfigPath]
B --> M[checkGh]
M -->|gh available| N[checkGhAuth]
M -->|gh missing| O[skip gh auth]
K -->|valid OR key| P[checkOpenRouter via fetch]
K -->|no/invalid key| Q[skip network check]
B --> R[summarizeDoctorChecks]
R --> S{any fail?}
S -->|yes| T[exitCode = 1]
S -->|no| U[exitCode = 0]
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
A[gitgen doctor] --> B[runDoctorChecks]
B --> C[checkNode]
B --> D[checkGit]
B --> E[checkRepo]
E -->|inside work tree| F[checkBranch]
F -->|named branch| G[checkUpstream]
F -->|detached HEAD| H[null — skip upstream]
G -->|upstream set| I[ok]
G -->|no upstream| J[warn]
B --> K[checkApiKey]
B --> L[checkConfigPath]
B --> M[checkGh]
M -->|gh available| N[checkGhAuth]
M -->|gh missing| O[skip gh auth]
K -->|valid OR key| P[checkOpenRouter via fetch]
K -->|no/invalid key| Q[skip network check]
B --> R[summarizeDoctorChecks]
R --> S{any fail?}
S -->|yes| T[exitCode = 1]
S -->|no| U[exitCode = 0]
Reviews (2): Last reviewed commit: "fix: skip upstream check in detached HEA..." | Re-trigger Greptile
Summary
sanitizeBranchNamefunction to lib/branch-name.tsdoctorcommand to check environment healthTest plan
gitgen doctorin a clean project directorygitgen doctorin a directory without Git installed to test Git check failure