fix: handle null projects/scans arrays in checkmarx list commands - #278
Conversation
CxOne returns null (not []) for projects/scans when the tenant is empty. Guard with ?? [] so listProjects() and listScans() return [] instead of crashing with "Cannot read properties of null (reading 'length')". Closes #277 Co-authored-by: Sunny Kolattukudy <kolatts@users.noreply.github.com>
Generated-with: OpenAI Codex (GPT-5)
Generated-with: OpenAI Codex (GPT-5)
Generated-with: OpenAI Codex (GPT-5)
|
Claude finished @kolatts's task in 1m 52s —— View job PR Review
SummaryThis is a clean, minimal fix. No blocking issues. Here's what I checked:
One non-blocking note: if the API ever returns GitHub blocked a formal APPROVE because the bot actor can't approve PRs it's associated with, but this is a clean pass. |
There was a problem hiding this comment.
Clean, minimal fix. The null guard pattern and type update are correct.
src/types/checkmarx.ts — projects: CxOneProject[] | null and scans: CxOneScan[] | null accurately reflect the CxOne API contract. Good that this is surfaced in the type rather than buried in a silent cast.
src/services/checkmarx/client.ts — const projects = res.projects ?? [] before the length comparison and the return is the right shape: the local binding means TypeScript narrows correctly and the warning comparison stays correct.
src/services/checkmarx/client.test.ts — both null-response cases are covered with assertions on both the return value and the API call params. Follows the existing stub-fetch pattern from http.test.ts.
.github/workflows/claude-review.yml — the added condition (github-actions[bot] + claude/issue-* branch) is tight and intentional. actions: read is minimal-privilege. github_token is needed so the action can authenticate its review post.
One thing to be aware of (not blocking): if the API ever returns a non-zero filteredTotalCount alongside a null array, the warning will print "X found; only showing first 0" — technically true but a bit cryptic. Not worth changing here; worth noting if that case ever surfaces in production.
Note: GitHub prevents self-approval on bot-authored PRs sharing the same actor identity — no formal APPROVE status was set, but this review is a clean pass with no blocking issues.
Generated-with: OpenAI Codex (GPT-5)
|
Claude finished @kolatts's task in 1m 51s —— View job PR Review
SummaryPASS — clean, minimal fix. No blocking issues.
One non-blocking note: if the API ever returns GitHub blocked a formal APPROVE because the bot actor cannot approve its own PRs, but this is a clean pass. |
Generated-with: OpenAI Codex (GPT-5)
|
Claude finished @kolatts's task in 1m 29s —— View job PR Review
SummaryPASS — clean, minimal fix. No blocking issues.
One non-blocking observation: if the API ever returns |
There was a problem hiding this comment.
PASS — clean, minimal fix. No blocking issues.
src/types/checkmarx.ts — projects: CxOneProject[] | null and scans: CxOneScan[] | null accurately reflect the CxOne API contract. Surfacing nullability in the type (rather than silently casting at call sites) is the right call.
src/services/checkmarx/client.ts — const projects = res.projects ?? [] is applied before both the .length comparison and the return, so TypeScript narrows correctly through the local binding. Pattern is symmetric across both listProjects and listScans.
src/services/checkmarx/client.test.ts — Both null-response cases are covered with assertions on the return value and the API call params. Follows the existing stub-fetch pattern from http.test.ts.
.github/workflows/claude-review.yml — Multiple changes, all intentional:
- The updated
ifcondition correctly admitsgithub-actions[bot]PRs onclaude/issue-*branches while remaining tight against other bots. fetch-depth: 0is required for the newgit diffSHA comparison step.- The "Detect review workflow changes" step and conditional
github_tokeninjection (changed == 'true' && github.token || '') correctly handle the case where the Claude app token can't self-validate a modified workflow file. REVIEW ACTORderivation is logically consistent withgithub_tokenselection.actions: readis minimal-privilege for the SHA comparison.
One non-blocking observation: if the API ever returns filteredTotalCount > 0 alongside a null array, the warning will print "X found; only showing first 0" — technically accurate but slightly cryptic. Not worth changing here; worth noting if it surfaces in production.
Summary
The CxOne API returns
null(not[]) for theprojectsandscansfields when a tenant has no results.CheckmarxClient.listProjects()andlistScans()unconditionally accessed.lengthon these fields, causing a crash:Changes
src/types/checkmarx.ts— updatedCxOneProjectsResponse.projectsandCxOneScansResponse.scansto| nullto accurately reflect the API contractsrc/services/checkmarx/client.ts— guard both list methods with?? []so an empty tenant returns{"ok":true,"data":[]}instead of crashingAll three checks pass:
npm run typecheck,npm run lint,npm test(391 tests).Closes #277
Generated with Claude Code