Skip to content

refactor(parser): flatten parse result and drop dead config guards - #220

Merged
jackchuma merged 1 commit into
mainfrom
refactor/flatten-parser-result
Oct 30, 2026
Merged

jackchuma merged 1 commit into
mainfrom
refactor/flatten-parser-result

Conversation

@jackchuma

@jackchuma jackchuma commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

What changed? Why?

parseFromString returned { config, result: { success, zodError? } }. TypeScript can't narrow config from result.success, so both callers carried a guard that could never fire. The shape also needed a separate type file and a single-use parseConfig wrapper.

parseFromString now returns a plain union, { success: true; config } | { success: false; zodError }, declared in src/lib/parser.ts. Callers check parsed.success and TypeScript narrows config from that.

  • Deleted src/lib/types/parser.ts and its re-export from src/lib/types/index.ts.
  • Inlined parseConfig into parseFromString. safeParse(JSON.parse(...)) stays inside the existing try, so malformed JSON still returns the Invalid JSON: … error.
  • getValidationSummary now 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 unreachable Parsed config missing config data guard. Every other log and error string is unchanged.
  • upgrade-config/route.ts: removed the redundant 'config' in parsedConfig clause.

Interfaces removed (all internal):

  • ParsedConfig, ParseResult, ParseSuccess, ParseFailure types. Only src/lib/types/parser.ts and src/lib/parser.ts referenced them. Nothing outside src/lib imports them, and they are not part of an API response.
  • parseConfig, a non-exported function with one caller.
  • The return shape of parseFromString changed. Its only consumers are validation-service.ts, upgrade-config/route.ts and the route test's mock, all updated here.

Notes to reviewers

Behavior stays the same. Success and failure are decided by the same safeParse and JSON.parse paths as before. The removed guards could not fire, because a success result was always built together with config. 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?

  • Added src/lib/__tests__/parser.test.ts to 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.
  • The route test's mocks were updated to the new shape. No assertions changed.
  • npm run build, npm run lint, npm run format:check, npx tsc --noEmit and npm test (158 tests) pass.

Why this cleanup

  • Production: +15 / -62 lines (net -47) across 5 files. Tests: +49 / -2 (new parser.test.ts; the route test changes 2 mock-shape lines and no assertions).
  • Interfaces removed: ParsedConfig, ParseResult, ParseSuccess, ParseFailure, the non-exported parseConfig, the dead success branch of getValidationSummary, and the unreachable Parsed config missing config data guard.
  • A reader no longer has to follow the nested result.success shape, the zodError?: never workaround, a separate re-exported types file, a wrapper that only builds that shape, or guards that look like they handle a real case.
  • Keep-gate judge: remaining behavior is unchanged (same try, same logs, errors and fallback). Nothing removed was used or added for future work, and the diff is small and easy to review.

@cb-heimdall

cb-heimdall commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Heimdall Review Status

Requirement Status More Info
Reviews ✅ 1/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@jackchuma

Copy link
Copy Markdown
Collaborator Author

Review round 1

Reviewers: cbhq-openai/gpt-6.1-sol

  • Dropped in triage: [P2] spec check: getConfigData in validation-service.ts has no test. The spec expected this gap and limits that file to the forced caller update. A flipped success check would now fail tsc, because .config and getValidationSummary only typecheck on the narrowed branch.
    Synced with main: c781909 (already current)
    Validation: build, lint, format:check, tsc --noEmit, npm test (158 tests) pass; CI green

🤖 Reply generated with Toshi

@jackchuma
jackchuma marked this pull request as ready for review October 30, 2026 13:51
@jackchuma
jackchuma requested review from 0xth4nh and xenoliss October 30, 2026 13:51
@jackchuma
jackchuma merged commit 95658dc into main Oct 30, 2026
6 checks passed
@jackchuma
jackchuma deleted the refactor/flatten-parser-result branch October 30, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants