Repository navigation
Reject unknown or wrong-typed top-level JSON commit input keys - #72
Merged
Merged
Conversation
JSON input (stdin and --file) silently ignored every top-level key except intent/body/trailers: a flat schema (trailers at the top level) committed with exit 0 and every trailer dropped, and wrong-typed values were silently coerced (non-string intent became empty, non-string body vanished). JsonInputReader now validates the top-level shape and throws an actionable LoreError (exit 1) instead: unknown keys are named with the allowed schema and a hint that trailer values belong inside the trailers object; non-object payloads, invalid JSON, and wrong-typed intent/body/trailers are rejected with the offending type. Inner trailer parsing stays lenient (non-string values are still filtered); only the top level is strict. Lore-id: cd854cfb Constraint: inner trailer parsing stays lenient (non-string values still filtered); only the top level is strict Constraint: absent intent still defaults to empty string so the downstream commitBuilder.validate missing-intent path is unchanged Tested: npm run build and npm run typecheck clean Tested: vitest 479 passed (2 lenient-coercion tests replaced with rejection tests, 12 top-level validation cases added) Not-tested: npm run lint: fails on origin/main itself (ESLint 9 has no flat config); pre-existing, out of scope Confidence: high Scope-risk: narrow Reversibility: clean
TommyC81
force-pushed
the
fix/commit-input-unknown-keys
branch
from
October 30, 2026 03:48
a648bce to
c011681
Compare
Owner
|
Merged to
|
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.
fix(commit): reject unknown or wrong-typed top-level JSON input keys
What
JsonInputReader(stdin and--fileJSON input) now validates the top-level shape before reading it. Unknown top-level keys are rejected with an error naming each one, the allowed schema (intent,body,trailers), and a hint that trailer values belong inside thetrailersobject. Wrong-typed values (intent/bodymust be strings,trailersmust be an object), non-object payloads (array, number, string, null), and invalid JSON are rejected with the offending type. Every failure is an actionableLoreErrorwith exit 1.Why
The current reader silently ignores every top-level key except
intent/body/trailers: a flat schema ({"intent": "...", "Constraint": [...]}) commits with exit 0 and every trailer dropped, and wrong-typed values are silently coerced (non-stringintentbecomes empty, non-stringbodyvanishes). Tooling that feeds JSON through--fileor stdin gets a barren atom with a success exit code, andlore validatepasses it. Also relevant to the Rust parity port (#71), which currently replicates the lenient behavior.Behavior notes
intentstill defaults to empty string and fails downstream validation exactly as before;{}behaves identically to today.SyntaxErrorpast the error handler.Tests
npm run buildandnpm run typecheckclean.instanceof LoreError, single and multiple unknown keys, nested envelope, array and number top level,__proto__own key, wrong-typed trailers as string/array/null, invalid JSON, empty-object pass-through).npm run lintfails onmainitself (ESLint 9 expects a flat config the repo does not ship yet); pre-existing and out of scope here.Proposed changelog entry (happy to include it directly if maintainers prefer PRs to carry it):