Skip to content

test: cmark memory/leak/concurrency/multibyte-position safety harness - #9

Merged
hebertialmeida merged 2 commits into
masterfrom
test/safety-harness
Jul 21, 2026
Merged

test: cmark memory/leak/concurrency/multibyte-position safety harness#9
hebertialmeida merged 2 commits into
masterfrom
test/safety-harness

Conversation

@hebertialmeida

Copy link
Copy Markdown
Owner

Adds a test-and-tooling-only safety net around the cmark_gfm wrapper, with no production code changes. This hardens coverage of the failure modes that the current suite is structurally blind to, so a future performance change to CMNode (reducing wrapper-object allocation) can be made safely.

What's added

  • MultibytePositionTests — byte-vs-character position correctness (emoji/CJK/combining/ZWJ/CRLF/tabs), asserted at the substring level.
  • MemorySafetyTests — retained nodes outliving the document, Iterator reset/re-enumerate, tight re-parse and wrapper-graph churn loops.
  • LeakTests — retain-cycle weak-ref checks + bounded-growth loops.
  • ConcurrencyTests — hundreds of concurrent parses (same/different inputs).
  • CI — Address- and Thread-sanitizer test steps.

Results

  • 62 → 98 tests (+36). Green under plain swift test, ASan, and TSan — zero sanitizer diagnostics.

Findings

  • No latent memory-safety, leak, concurrency, or multibyte-position bug. The utf8.index-based position mapping is already byte-correct; the old tests only used ASCII (input.range(0...N)), where char- and byte-offsets coincide, so multibyte was untested — now closed.
  • Pre-existing, not introduced here: ParserInlineTests.testInvalidLink crashes locally (index-out-of-range on an unexpected parse shape) but is gated by XCTSkipIf(isCI), so CI stays green; it awaits an upstream swift-cmark fix.

Purpose

Prerequisite for a later, guarded CMNode wrapper-allocation reduction: the three ownership-break failure modes are now watched by sanitizers on every PR (a dropped owner → ASan use-after-free; a leaked node/cycle → LeakTests + ASan; shared mutable wrapper state → TSan race). Not covered: allocation/perf baselines (safety only, not churn magnitude).

🤖 Generated with Claude Code

hebertialmeida and others added 2 commits July 21, 2026 00:28
…ness

Adds four test files that close the blind spots in the existing suite ahead of
a possible CMNode wrapper-churn optimization:

- MultibytePositionTests: byte-vs-character position correctness (emoji, CJK,
  accents, combining marks, ZWJ, CRLF, tabs); asserts input[range] substrings.
- MemorySafetyTests: retained nested nodes outlive the owning document, iterator
  enumerate/reset, tight re-parse and wrapper-graph churn loops (run under ASan).
- LeakTests: weak-reference cycle checks + bounded-growth loops.
- ConcurrencyTests: hundreds of concurrent parses, same/different inputs (run under TSan).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Guards the hand-rolled cmark memory model with ASan/TSan on every PR, so a future
CMNode wrapper-churn optimization that introduces a use-after-free, double-free,
leak, or data race is caught in CI. Sanitizer steps run after the coverage step so
they don't clobber its profraw data.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (8cb12b3) to head (dc00264).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master        #9   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          137       133    -4     
=========================================
- Hits           137       133    -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hebertialmeida
hebertialmeida merged commit ab0f381 into master Jul 21, 2026
3 checks passed
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