Repository navigation
refactor(parser): flatten parse result and drop dead config guards - #220
Merged
Merged
Conversation
J-Engine-Session: unknown
Collaborator
✅ Heimdall Review Status
|
Collaborator
Author
Review round 1Reviewers: cbhq-openai/gpt-6.1-sol
🤖 Reply generated with Toshi |
jackchuma
marked this pull request as ready for review
October 30, 2026 13:51
xenoliss
approved these changes
Oct 30, 2026
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.
What changed? Why?
parseFromStringreturned{ config, result: { success, zodError? } }. TypeScript can't narrowconfigfromresult.success, so both callers carried a guard that could never fire. The shape also needed a separate type file and a single-useparseConfigwrapper.parseFromStringnow returns a plain union,{ success: true; config } | { success: false; zodError }, declared insrc/lib/parser.ts. Callers checkparsed.successand TypeScript narrowsconfigfrom that.src/lib/types/parser.tsand its re-export fromsrc/lib/types/index.ts.parseConfigintoparseFromString.safeParse(JSON.parse(...))stays inside the existingtry, so malformed JSON still returns theInvalid JSON: …error.getValidationSummarynow accepts only the failure variant. Its success branch was dead, because the only caller passes failures.validation-service.ts: updated the success check and the summary argument, and removed the unreachableParsed config missing config dataguard. Every other log and error string is unchanged.upgrade-config/route.ts: removed the redundant'config' in parsedConfigclause.Interfaces removed (all internal):
ParsedConfig,ParseResult,ParseSuccess,ParseFailuretypes. Onlysrc/lib/types/parser.tsandsrc/lib/parser.tsreferenced them. Nothing outsidesrc/libimports them, and they are not part of an API response.parseConfig, a non-exported function with one caller.parseFromStringchanged. Its only consumers arevalidation-service.ts,upgrade-config/route.tsand the route test's mock, all updated here.Notes to reviewers
Behavior stays the same. Success and failure are decided by the same
safeParseandJSON.parsepaths as before. The removed guards could not fire, because a success result was always built together withconfig. The parse output's encoding and the API responses don't change. The code that added this shape (761b8ec,4d7d998) was refactoring and doesn't point to planned use.How has it been tested?
src/lib/__tests__/parser.test.tsto cover outcomes no test covered before: a valid config, schema errors, malformed JSON, and the exact failure-summary text. These tests passed on the old code before the refactor.npm run build,npm run lint,npm run format:check,npx tsc --noEmitandnpm test(158 tests) pass.Why this cleanup
parser.test.ts; the route test changes 2 mock-shape lines and no assertions).ParsedConfig,ParseResult,ParseSuccess,ParseFailure, the non-exportedparseConfig, the dead success branch ofgetValidationSummary, and the unreachableParsed config missing config dataguard.result.successshape, thezodError?: neverworkaround, a separate re-exported types file, a wrapper that only builds that shape, or guards that look like they handle a real case.try, same logs, errors and fallback). Nothing removed was used or added for future work, and the diff is small and easy to review.