Skip to content

fix(contract-loader): strip inline comments from frontmatter values - #3

Open
eeshsaxena wants to merge 1 commit into
openprose:mainfrom
eeshsaxena:fix/frontmatter-inline-comment
Open

fix(contract-loader): strip inline comments from frontmatter values#3
eeshsaxena wants to merge 1 commit into
openprose:mainfrom
eeshsaxena:fix/frontmatter-inline-comment

Conversation

@eeshsaxena

Copy link
Copy Markdown

Problem

The flat frontmatter parser in contract-loader.ts skips 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:

---
name: ingress # the edge node
kind: gateway # exposes a webhook
---

kind is read as the literal string "gateway # exposes a webhook". normalizeKind doesn't recognize that, so it silently falls back to the default "responsibility" — a gateway contract is mis-classified. id/name similarly keep their trailing comment text.

sliceContract("---\nkind: gateway # exposes a webhook\n---\n### Maintains\nx\n", "/x/g.prose.md").kind
// before: "responsibility"   (wrong)
// after:  "gateway"

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 # notegateway
  • id: issue#42issue#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 real sliceContract end-to-end via tsx and all assertions pass. I couldn't run the full pnpm typecheck && test:runtime locally (dependency install was too slow in my environment), but the change is a small, localized edit to parseFlatFrontmatter and the type-only imports it touches are unchanged.

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.
@eeshsaxena

Copy link
Copy Markdown
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.

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.

1 participant