Skip to content

Add support for additional CommonMark syntax variations and improve JSON parsing#93

Merged
hawkeyexl merged 7 commits intomainfrom
markdown-comment-syntax-support
Dec 3, 2025
Merged

Add support for additional CommonMark syntax variations and improve JSON parsing#93
hawkeyexl merged 7 commits intomainfrom
markdown-comment-syntax-support

Conversation

@hawkeyexl
Copy link
Contributor

@hawkeyexl hawkeyexl commented Dec 3, 2025

Enhance the application by supporting more variations of CommonMark syntax for test comments and normalizing the detectSteps field. Improve the parsing of double-quoted JSON to handle escaped characters more effectively.

Summary by CodeRabbit

  • Documentation

    • Replaced a raw HTTP example with a step-by-step interactive walkthrough for testing the conversion flow.
  • New Features

    • Added recognition for additional CommonMark-style comment variants and expanded Markdown input support.
  • Bug Fixes

    • Improved handling of escaped/double-encoded JSON parsing and normalized boolean detection for test flags; ensure tests include a steps array.
  • Tests

    • Added extensive tests covering new comment formats, YAML/XML embeddings, and cross-format parsing.
  • Chores

    • Updated logging level naming and adjusted test-run input target.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 3, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds CommonMark inline-comment patterns for test annotations, improves parsing to handle escaped/double-encoded JSON and normalize test.detectSteps/steps, swaps a dev test input from DITA to Markdown, replaces a raw HTTP example with a step-by-step walkthrough, and expands test coverage for comment-syntax variants.

Changes

Cohort / File(s) Summary
Documentation & dev entry
dev/doc-content.md, dev/index.js
dev/doc-content.md replaces a raw HTTP PATCH example with a numbered, interactive/test-like walkthrough. dev/index.js changes the test-detection input path from a DITA document to a Markdown document.
Markdown inline-statement patterns
src/config.js
Extends markdown_1_0 inlineStatements to recognize CommonMark comment variants: parentheses (...), single-quoted '...', and double-quoted "...“ forms for test, test start, test end, test ignore start, test ignore end, and step; adds escaping handling for embedded quotes. Changes JSON parse error log level string from "warn" to "warning".
Parsing behavior
src/utils.js
parseObject now attempts to detect and unescape double-encoded/escaped JSON and retries JSON.parse before falling back to YAML.parse. parseContent normalizes "true"/"false" strings to booleans for test.detectSteps and ensures test.steps is initialized to an empty array when absent.
Tests (coverage expansion)
src/index.test.js, src/config.test.js
Adds extensive CommonMark comment-syntax tests (parentheses, single/double/mixed quotes, YAML-embedded, XML-attribute variants), multiple DITA scenarios, and updates an envMerge invalid-JSON test to expect log level "warning" instead of "warn".

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Review regexes and escaping in src/config.js for correctness and edge cases.
  • Verify parseObject's unescape/retry logic in src/utils.js doesn't wrongly transform valid inputs.
  • Spot-check representative new tests in src/index.test.js for redundancy and intended expectations.

Possibly related PRs

Poem

🐰 I hop through comments, brackets, quotes and light,

I coax escaped JSON back into sight.
Steps lined in order, true/false tucked in place,
Tests wake and stretch with a whiskered grace.
A little rabbit cheers — parsing finds its pace.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the two main changes: adding CommonMark syntax variations and improving JSON parsing, matching the primary objectives of the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch markdown-comment-syntax-support

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 158bab0 and e258e21.

📒 Files selected for processing (3)
  • src/config.js (2 hunks)
  • src/config.test.js (1 hunks)
  • src/utils.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/utils.js
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{js,ts}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{js,ts}: Use async/await for asynchronous operations
Prefer destructuring for function parameters
Use meaningful variable names that reflect Doc Detective terminology
Add JSDoc comments for complex functions

Files:

  • src/config.test.js
  • src/config.js
**/*.test.js

📄 CodeRabbit inference engine (AGENTS.md)

**/*.test.js: When possible, directly import and run functions rather than use extensive mocking and stubbing in tests
Mock external dependencies (file system, HTTP requests) in tests
Test both successful and error scenarios
Validate configuration handling thoroughly in tests
Use realistic test data that matches actual usage patterns
Use Mocha for unit tests
Use Chai for assertions

Files:

  • src/config.test.js
src/**/*.js

📄 CodeRabbit inference engine (AGENTS.md)

Use the built-in logging system with available log levels: debug, info, warn, error

Files:

  • src/config.test.js
  • src/config.js
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
Repo: doc-detective/resolver PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:45.298Z
Learning: Applies to src/resolve.js : Follow existing regex patterns for markup detection when adding new features
Learnt from: CR
Repo: doc-detective/resolver PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:45.298Z
Learning: Add comprehensive test coverage when adding new features
📚 Learning: 2025-11-25T23:59:45.298Z
Learnt from: CR
Repo: doc-detective/resolver PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:45.298Z
Learning: Applies to **/*.test.js : Validate configuration handling thoroughly in tests

Applied to files:

  • src/config.test.js
📚 Learning: 2025-11-25T23:59:45.298Z
Learnt from: CR
Repo: doc-detective/resolver PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:45.298Z
Learning: Applies to **/*.test.js : Test both successful and error scenarios

Applied to files:

  • src/config.test.js
📚 Learning: 2025-11-25T23:59:45.298Z
Learnt from: CR
Repo: doc-detective/resolver PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:45.298Z
Learning: Applies to src/resolve.js : Follow existing regex patterns for markup detection when adding new features

Applied to files:

  • src/config.js
📚 Learning: 2025-11-25T23:59:45.298Z
Learnt from: CR
Repo: doc-detective/resolver PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:45.298Z
Learning: Applies to **/*.{js,ts} : Add JSDoc comments for complex functions

Applied to files:

  • src/config.js
🧬 Code graph analysis (1)
src/config.test.js (1)
src/index.test.js (1)
  • sinon (2-2)
🔇 Additional comments (7)
src/config.js (6)

323-332: LGTM! CommonMark syntax support expanded correctly.

The new patterns properly support parentheses, single-quote, and double-quote CommonMark comment variations for test annotations. The double-quote patterns correctly handle escaped characters using (?:[^"\\\\]|\\\\.)* in the string literal (which becomes (?:[^"\\]|\\.)* as the compiled regex).

Based on learnings, the patterns follow existing regex conventions for markup detection. Ensure comprehensive test coverage includes these new syntax variations.


337-342: LGTM! testEnd patterns consistent with testStart.

The CommonMark syntax patterns for test end markers are consistent with the testStart patterns and correctly support all three quote variations.


347-352: LGTM! ignoreStart patterns follow consistent structure.

The CommonMark syntax patterns for ignore start markers correctly mirror the structure established in testStart and testEnd.


357-362: LGTM! ignoreEnd patterns complete the ignore block syntax.

The CommonMark syntax patterns for ignore end markers are correctly implemented and consistent with the other marker patterns.


367-373: LGTM! step patterns support CommonMark syntax with proper capture groups.

The step patterns correctly capture step parameters across all three quote variations and properly handle escaped characters in double-quoted content, consistent with the testStart implementation.


506-506: No action required — "warning" is a valid log level.

The logging system implementation in src/utils.js explicitly supports "warning" as a valid log level (lines 968-983), and this level is already used throughout the codebase. While the coding guidelines documentation lists "debug, info, warn, error," the actual logging system implementation uses "warning" instead of "warn." The code at line 506 is correct.

Likely an incorrect or invalid review comment.

src/config.test.js (1)

84-84: The test correctly uses "warning" — the only valid log level parameter supported by the logging system.

The logging system in src/utils.js only recognizes "warning" as a valid level (not "warn"). The test expectation at line 84 matches the implementation in src/config.js line 506. However, note that the coding guidelines list "warn" as an available level, which is inaccurate. Additionally, src/index.js:37 incorrectly calls log(config, "warn", ...) when it should use "warning".

⛔ Skipped due to learnings
Learnt from: CR
Repo: doc-detective/resolver PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:45.298Z
Learning: Applies to **/*.test.js : Validate configuration handling thoroughly in tests
Learnt from: CR
Repo: doc-detective/resolver PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:45.298Z
Learning: Applies to src/**/*.js : Use the built-in logging system with available log levels: debug, info, warn, error
Learnt from: CR
Repo: doc-detective/resolver PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:45.298Z
Learning: Applies to **/*.test.js : Test both successful and error scenarios

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@promptless
Copy link

promptless bot commented Dec 3, 2025

📝 Documentation updates detected!

New suggestion: Document CommonMark comment syntax quote style variations

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/config.js (1)

492-510: Log level string "warn" won’t ever be emitted by the log helper

In the DOC_DETECTIVE env‑override error path you call:

log(
  config,
  "warn",
  `Invalid JSON in DOC_DETECTIVE environment variable: ${error.message}. Ignoring config overrides.`
);

but log only checks for "error", "warning", "info", and "debug". As written, this message will never be printed for any config.logLevel.

Change the level to "warning" to make this path observable:

-      log(
-        config,
-        "warn",
-        `Invalid JSON in DOC_DETECTIVE environment variable: ${error.message}. Ignoring config overrides.`
-      );
+      log(
+        config,
+        "warning",
+        `Invalid JSON in DOC_DETECTIVE environment variable: ${error.message}. Ignoring config overrides.`
+      );
🧹 Nitpick comments (4)
dev/doc-content.md (1)

1-19: markdownlint MD053 warnings are expected for [comment]: # usage

The [comment]: # '...' lines are intentionally used as test metadata, not as real link reference definitions, so the MD053 “unused reference” warnings are false positives. Consider suppressing MD053 for this file or this specific [comment] label in your markdownlint config instead of changing the syntax.

src/utils.js (2)

124-161: Gate escaped‑JSON unwrapping behind a failed direct JSON.parse

The new looksLikeEscapedJson path nicely handles double‑quoted CommonMark JSON like {\\"testId\\": ...}, but it runs before a normal JSON.parse. That can mis-handle valid JSON that legitimately contains \" inside string values (e.g., JSON with embedded quotes), which previously parsed fine.

Consider trying JSON.parse(stringifiedObject) first and only applying the escaped‑JSON heuristic inside that catch block when parsing fails and the heuristic pattern matches. That keeps the new support for double‑encoded JSON without risking regressions for regular JSON content that happens to contain \".


581-627: detectSteps normalization and default steps array look correct; consider explicit test coverage

Converting "false"/"true" string values to booleans and ensuring test.steps is at least an empty array in the testStart branch aligns behavior with later checks like if (typeof test.detectSteps !== "undefined" && !test.detectSteps) and the “remove tests with no steps” filter in parseTests.

To lock this in, it would be useful to add at least one test where a test comment sets "detectSteps": "false" (string) and assert that the resolved test has detectSteps === false (boolean).

src/index.test.js (1)

889-1101: CommonMark JSON tests are strong; add one "detectSteps": "false" case to hit the new normalization

The new CommonMark Comment Syntax Tests cover parentheses, single‑quote, double‑quote, and mixed‑quote JSON forms very well, and they assert both testId and step shapes end‑to‑end through detectAndResolveTests.

To exercise the detectSteps string‑to‑boolean normalization you just added in parseContent, consider adding or tweaking one test so the JSON uses "detectSteps": "false" (string) and then assert that the resolved test has detectSteps === false (boolean). That will guard against regressions in the normalization logic.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b62b5e and 0126a22.

📒 Files selected for processing (5)
  • dev/doc-content.md (1 hunks)
  • dev/index.js (1 hunks)
  • src/config.js (1 hunks)
  • src/index.test.js (1 hunks)
  • src/utils.js (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{js,ts}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{js,ts}: Use async/await for asynchronous operations
Prefer destructuring for function parameters
Use meaningful variable names that reflect Doc Detective terminology
Add JSDoc comments for complex functions

Files:

  • src/utils.js
  • src/config.js
  • src/index.test.js
  • dev/index.js
src/**/*.js

📄 CodeRabbit inference engine (AGENTS.md)

Use the built-in logging system with available log levels: debug, info, warn, error

Files:

  • src/utils.js
  • src/config.js
  • src/index.test.js
**/*.test.js

📄 CodeRabbit inference engine (AGENTS.md)

**/*.test.js: When possible, directly import and run functions rather than use extensive mocking and stubbing in tests
Mock external dependencies (file system, HTTP requests) in tests
Test both successful and error scenarios
Validate configuration handling thoroughly in tests
Use realistic test data that matches actual usage patterns
Use Mocha for unit tests
Use Chai for assertions

Files:

  • src/index.test.js
🧠 Learnings (6)
📚 Learning: 2025-11-25T23:59:45.298Z
Learnt from: CR
Repo: doc-detective/resolver PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:45.298Z
Learning: Applies to **/*.test.js : Use realistic test data that matches actual usage patterns

Applied to files:

  • src/utils.js
  • src/index.test.js
📚 Learning: 2025-11-25T23:59:45.298Z
Learnt from: CR
Repo: doc-detective/resolver PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:45.298Z
Learning: Applies to **/*.test.js : Validate configuration handling thoroughly in tests

Applied to files:

  • src/utils.js
  • src/index.test.js
  • dev/index.js
📚 Learning: 2025-11-25T23:59:45.298Z
Learnt from: CR
Repo: doc-detective/resolver PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:45.298Z
Learning: Applies to src/resolve.js : Follow existing regex patterns for markup detection when adding new features

Applied to files:

  • src/config.js
  • src/index.test.js
📚 Learning: 2025-11-25T23:59:45.298Z
Learnt from: CR
Repo: doc-detective/resolver PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:45.298Z
Learning: Applies to **/*.{js,ts} : Add JSDoc comments for complex functions

Applied to files:

  • src/config.js
  • src/index.test.js
📚 Learning: 2025-11-25T23:59:45.298Z
Learnt from: CR
Repo: doc-detective/resolver PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:45.298Z
Learning: Add comprehensive test coverage when adding new features

Applied to files:

  • src/index.test.js
📚 Learning: 2025-11-25T23:59:45.298Z
Learnt from: CR
Repo: doc-detective/resolver PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:45.298Z
Learning: Applies to **/*.test.js : Test both successful and error scenarios

Applied to files:

  • src/index.test.js
🪛 markdownlint-cli2 (0.18.1)
dev/doc-content.md

1-1: Link and image reference definitions should be needed
Unused link or image reference definition: "comment"

(MD053, link-image-reference-definitions)


5-5: Link and image reference definitions should be needed
Duplicate link or image reference definition: "comment"

(MD053, link-image-reference-definitions)


9-9: Link and image reference definitions should be needed
Duplicate link or image reference definition: "comment"

(MD053, link-image-reference-definitions)


10-10: Link and image reference definitions should be needed
Duplicate link or image reference definition: "comment"

(MD053, link-image-reference-definitions)


14-14: Link and image reference definitions should be needed
Duplicate link or image reference definition: "comment"

(MD053, link-image-reference-definitions)


18-18: Link and image reference definitions should be needed
Duplicate link or image reference definition: "comment"

(MD053, link-image-reference-definitions)


19-19: Link and image reference definitions should be needed
Duplicate link or image reference definition: "comment"

(MD053, link-image-reference-definitions)

🔇 Additional comments (4)
dev/index.js (1)

14-23: Markdown dev input path update matches new sample document

Switching input to dev/doc-content.md aligns the dev helper with the new Markdown-based sample content and extended CommonMark support; no issues from this change.

src/config.js (1)

320-375: CommonMark [comment]: # inline statement regexes look consistent and robust

The added markdown testStart, testEnd, ignore*, and step patterns for [comment]: # (...), '...', and "..." forms are consistent with existing inlineStatement conventions and correctly capture the payload into group 1, with the double‑quote variants using a safe (?:[^"\\]|\\.)* to handle escaped quotes. They line up with the new tests and parseObject expectations.

src/index.test.js (2)

1105-1301: YAML-based CommonMark tests nicely cover JSON/YAML interchange

The CommonMark Comment Syntax with YAML Tests block drives realistic YAML payloads through all three [comment]: # (/'/") variants, and the assertions on testId, goTo, type, and find steps confirm that both YAML parsing and the markdown patterns are wired up correctly. No issues from these changes.


1304-1411: XML attribute + dot-notation CommonMark tests give excellent coverage of parseXmlAttributes

The XML-attribute and XML-dot CommonMark tests thoroughly exercise parseXmlAttributes, including booleans (detectSteps=false), numbers (wait=500), and nested httpRequest.* properties. The expectations on nested httpRequest.url/method/request.body objects match the intended behavior and validate the new markdown patterns end‑to‑end.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the application's ability to parse test definitions from CommonMark-style markdown comments by supporting multiple quote syntax variations (parentheses, single quotes, and double quotes). It also improves JSON parsing for escaped/double-encoded JSON content and normalizes the detectSteps field to ensure consistent boolean values.

Key Changes

  • Added regex patterns to recognize CommonMark comment syntax with three different quote styles: [comment]: # (...), [comment]: # '...', and [comment]: # "..."
  • Implemented fallback JSON parsing logic to handle escaped and double-encoded JSON strings
  • Added normalization for detectSteps field to convert string values "true"/"false" to boolean types

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/config.js Added regex patterns for CommonMark comment variations (parentheses, single quotes, double quotes) across all statement types; changed log level from "warn" to "warning"
src/config.test.js Updated test assertion to match log level change from "warn" to "warning"
src/utils.js Added escaped/double-encoded JSON parsing fallback logic; added detectSteps string-to-boolean normalization; updated comment for clarity
src/index.test.js Added comprehensive test suites covering all CommonMark syntax variations with JSON, YAML, and XML attribute content formats
dev/index.js Changed test input file from DITA to Markdown format
dev/doc-content.md Replaced HTTP example with interactive test walkthrough using CommonMark comment syntax

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@hawkeyexl hawkeyexl merged commit 79e02b4 into main Dec 3, 2025
12 checks passed
@hawkeyexl hawkeyexl deleted the markdown-comment-syntax-support branch December 3, 2025 19:20
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.

2 participants