fix(contract-loader): strip inline comments from frontmatter values - #3
Open
eeshsaxena wants to merge 1 commit into
Open
fix(contract-loader): strip inline comments from frontmatter values#3eeshsaxena wants to merge 1 commit into
eeshsaxena wants to merge 1 commit into
Conversation
The flat frontmatter parser skips full-line '#' comments but keeps an inline YAML comment as part of the value. A commented field such as `kind: gateway # exposes a webhook` was read as the literal string "gateway # exposes a webhook", which normalizeKind does not recognize, so the contract silently fell back to the default "responsibility" kind (and id/name kept their comment text too). Treat a whitespace-preceded '#' as an inline comment on unquoted scalars, so the value ends before it. A '#' with no preceding whitespace, or one inside a quoted scalar, stays literal. Verified against the real sliceContract.
Author
|
The reason this bites in practice: kind drives behavior (gateway/function/pattern/test vs the responsibility default), so a one-line inline comment on the kind field silently changes how a contract is treated, with no error. The fix follows YAML comment rules (a # only starts a comment when preceded by whitespace) so values like issue#42 and quoted scalars are untouched. |
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.
Problem
The flat frontmatter parser in
contract-loader.tsskips full-line#comments but does not treat an inline YAML comment as a comment, so it becomes part of the value.The most visible impact is on
kind. Given:kindis read as the literal string"gateway # exposes a webhook".normalizeKinddoesn't recognize that, so it silently falls back to the default"responsibility"— a gateway contract is mis-classified.id/namesimilarly keep their trailing comment text.Fix
Treat a whitespace-preceded
#as an inline comment on unquoted scalars, so the value ends before it — matching YAML (a comment indicator must be preceded by whitespace) and the parser's existing full-line-comment handling.kind: gateway # note→gatewayid: issue#42→issue#42(no whitespace before#, so literal)name: "release #1"→release #1(quoted scalar,#literal)Testing
Added two tests to
contract-loader.test.ts(the inline-comment case and the literal-#cases). I also ran the realsliceContractend-to-end via tsx and all assertions pass. I couldn't run the fullpnpm typecheck && test:runtimelocally (dependency install was too slow in my environment), but the change is a small, localized edit toparseFlatFrontmatterand the type-only imports it touches are unchanged.