fix: accept null merged_yaml/includes in CI lint result - #639
Open
nkz-soft wants to merge 1 commit into
Open
Conversation
GitLab returns null (not an omitted field) for merged_yaml and includes whenever the CI config is invalid. Zod's .optional() accepts undefined but rejects null, so GitLabCiLintResultSchema.parse() threw and validate_ci_lint surfaced a schema error instead of the lint result — failing in exactly the case the tool is called for. On a valid config it worked, which kept the bug invisible. Same class as zereight#575; regression test added alongside those cases. Fixes zereight#638
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📜 Recent review details🔇 Additional comments (2)
📝 WalkthroughSummary by CodeRabbit
Walkthrough
ChangesCI lint response validation
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #638.
Problem
validate_ci_lint(andvalidate_project_ci_lint) throw instead of returning a result whenever the CI config is invalid — exactly the case the tool is called for. On a valid config they work, which is why the bug stays invisible until a user actually has a broken.gitlab-ci.yml.GitLab returns
merged_yaml: nullandincludes: nullfor an invalid config.GitLabCiLintResultSchemadeclared both as.optional(), which in Zod acceptsundefinedbut rejectsnull, so.parse()threw and the caller got a schema error instead of the lint result:The actual explanation from GitLab — e.g.
image is defined in top-level and `default:` entry— never reached the caller.Change
.optional()→.nullish()on the two fields GitLab actually nulls. Same class as #575, so the regression test goes next to those cases intest/nullable-gitlab-response-fields.test.ts.Scope is deliberately minimal:
warningsandjobscome back as arrays in every response I observed, so I left them alone rather than widening the schema speculatively.Verification
The new test reproduces the reported failure before the schema change:
and passes after it. All three CI gates pass locally:
npm run test:mocknpm run test:consumer-smokeConsumer install smoke passed.npx tsc --noEmitReproduced against a self-hosted GitLab 19.2.0-ee on 2.1.42 and 2.1.46, stdio transport with PAT auth, using this config:
Direct API response for it:
{"valid":false,"errors":["image is defined in top-level and `default:` entry"],"warnings":[],"merged_yaml":null,"includes":null}Why it matters
An agent using this tool to validate CI changes cannot distinguish "the config is invalid" from "the tool is broken". In our case the agent concluded the latter, fell back to
prettier --check— which checks YAML formatting, not GitLab CI semantics — and reported success on a config that was invalid. The two errors it needed to catch (a job namedimage, andneedsreferencing a nonexistent job) are both caught by the lint endpoint in under a second and are both invisible to a formatter.