Skip to content

Initial codebase assessment#117

Merged
DavidWells merged 3 commits intomasterfrom
cursor/initial-codebase-assessment-4791
Feb 21, 2026
Merged

Initial codebase assessment#117
DavidWells merged 3 commits intomasterfrom
cursor/initial-codebase-assessment-4791

Conversation

@DavidWells
Copy link
Owner

Fixes multiple bugs and performance issues, and updates documentation to improve correctness, reliability, and maintainability.

This PR addresses several confirmed issues identified during a codebase review. Key fixes include preventing silent HTTP error page injection in remote transforms, correcting dependency graph ordering for files with multiple src dependencies, and validating CODE block ID extraction to prevent incorrect content slicing. Performance improvements were also made by reducing duplicate file I/O and optimizing line-number parsing. Additionally, CLI usage and documentation have been aligned to prevent user confusion.


Open in Web Open in Cursor 

Co-authored-by: David Wells <hello@davidwells.io>
@cursor
Copy link

cursor bot commented Feb 21, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

Copy link
Contributor

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Summary

This PR is a solid reliability and correctness pass. The changes fall into two broad categories:

Documentation & naming alignment — all doc files and examples are updated to use the canonical docs / /docs match-word pair and the correct --files CLI flag. The md.config.js preference over markdown.config.js is consistently applied, and the --path alias is plumbed through for backwards compatibility. These are mechanical but important for keeping the docs trustworthy.

Core runtime improvements:

  • createLineNumberResolver (block-parser) — replacing repeated substr(0, pos).split('\n').length calls with a single pre-built binary-search resolver is a clean O(n log n) improvement in the worst case. The implementation is correct and handles all boundary conditions.
  • Preloaded content / parsedBlocks caching (block-replacer, block-transformer, core/index.js) — avoids re-reading files and re-parsing blocks that were already processed during the initial scan. The parsedBlocks short-circuit in blockTransformer is guarded properly with Array.isArray(foundBlocks.blocks).
  • createDependencyGraph (core/index.js) — extracting the graph-building logic into its own function and switching from toposort(graph) to toposort.array(itemIds, graph) fixes the crash when there are no dependency edges (the bare toposort([]) call would return an empty array and lose all file IDs). Using a Set for dependency deduplication is also a nice cleanup.
  • remoteRequest — now handles non-2xx HTTP responses, validates and trims URLs before use, and stops returning undefined for the failed-fetch path (the old code silently swallowed the response body when the try block threw). The new test for 404 is a good addition.
  • CODE transform — validation is now much stricter: both missing markers and reversed/empty sections throw with useful messages, and the old bug where startLine could silently default to 0 (masking a missing START marker) is gone.

Inline comments cover four small items: an unresolved @type annotation, a test that relies implicitly on a default, an empty doc heading, and a missing trailing newline.

Comment on lines +103 to +109
await markdownMagic(tempFile, {
open: 'docs',
close: '/docs',
outputDir: OUTPUT_DIR,
applyTransformsToSource: false,
silent: SILENT
})
Copy link
Contributor

Choose a reason for hiding this comment

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

The 404 test doesn't set failOnMissingRemote: true explicitly, so it silently relies on the default being true. If that default ever changes, the test would stop asserting anything useful (threw would stay false and the final assertion would catch it, but the error message check inside the catch block would never run). Specifying it explicitly makes the test's intent clearer.

Suggested change
await markdownMagic(tempFile, {
open: 'docs',
close: '/docs',
outputDir: OUTPUT_DIR,
applyTransformsToSource: false,
silent: SILENT
})
await markdownMagic(tempFile, {
open: 'docs',
close: '/docs',
outputDir: OUTPUT_DIR,
applyTransformsToSource: false,
failOnMissingRemote: true,
silent: SILENT
})

Comment on lines +65 to 67
### Types and Build

### Building
Copy link
Contributor

Choose a reason for hiding this comment

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

### Types and Build is an empty heading — it has no content before the next ### Building heading immediately follows. Either add a brief description or merge them into a single ### Build and Types section.

Suggested change
### Types and Build
### Building
### Building and Types

__private: {
createDependencyGraph
}
} No newline at end of file
Copy link
Contributor

Choose a reason for hiding this comment

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

File is missing a trailing newline (\ No newline at end of file in the diff). Most editors and linters expect one.

Suggested change
}
}

Comment on lines +87 to +89
if (typeof content === 'string' && srcPath) {
// Allow callers to provide preloaded content for srcPath files
fileContents = content
Copy link
Contributor

Choose a reason for hiding this comment

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

The old guard (throw new Error("Can't set both \"srcPath\" & \"content\"")) was replaced to support the preloaded-content optimization. That's the right call for the caching use case, but note this is a silent behavioral change for any external caller that accidentally passed both: they previously got an explicit error, now their content is silently used as-is and the file on disk is ignored.

The comment captures the intent well. Just worth flagging in case there's external API surface to consider.

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
@DavidWells
Copy link
Owner Author

@claude fix the test failure https://github.com/DavidWells/markdown-magic/actions/runs/22261219621/job/64399767520?pr=117

packages/block-replacer test: }
packages/block-replacer test: • • (9 / 10)
packages/block-replacer test:
packages/block-replacer test: FAIL "should handle both srcPath and content error"
packages/block-replacer test: Expected value to be truthy (ok)
packages/block-replacer test:
packages/block-replacer test: at assert (/home/runner/work/markdown-magic/markdown-magic/node_modules/.pnpm/uvu@0.5.6/node_modules/uvu/assert/index.js:33:8)
packages/block-replacer test: at Object.ok (/home/runner/work/markdown-magic/markdown-magic/node_modules/.pnpm/uvu@0.5.6/node_modules/uvu/assert/index.js:37:2)
packages/block-replacer test: at Object.handler (/home/runner/work/markdown-magic/markdown-magic/packages/block-replacer/test/index.test.js:207:12)
packages/block-replacer test: at async Number.runner (/home/runner/work/markdown-magic/markdown-magic/node_modules/.pnpm/uvu@0.5.6/node_modules/uvu/dist/index.js:78:5)
packages/block-replacer test: at async Module.exec (file:///home/runner/work/markdown-magic/markdown-magic/node_modules/.pnpm/uvu@0.5.6/node_modules/uvu/dist/index.mjs:141:33)
packages/block-replacer test: at async Module.run (file:///home/runner/work/markdown-magic/markdown-magic/node_modules/.pnpm/uvu@0.5.6/node_modules/uvu/run/index.mjs:12:2)
packages/block-replacer test: at async /home/runner/work/markdown-magic/markdown-magic/node_modules/.pnpm/uvu@0.5.6/node_modules/uvu/bin.js:26:5
packages/block-replacer test: Total: 10
packages/block-replacer test: Passed: 9
packages/block-replacer test: Skipped: 0
packages/block-replacer test: Duration: 21.18ms
packages/block-replacer test: Failed
/home/runner/work/markdown-magic/markdown-magic/packages/block-replacer:

@github-actions
Copy link
Contributor

github-actions bot commented Feb 21, 2026

💬 Claude Code execution complete

📊 Execution Info: Pull Request #117 | Next.js (126 files) | @DavidWells
🌿 Branch: cursor/initial-codebase-assessment-4791master
ℹ️ Action Run: https://github.com/DavidWells/markdown-magic/actions/runs/22261399393

🚀 Automated management executed:

  • ✅ Created: 2026-Feb

@github-actions
Copy link
Contributor

github-actions bot commented Feb 21, 2026

Claude finished @DavidWells's task in 1m 15s —— View job


Fix: test failure in block-replacer

  • Read the failing test and source files
  • Understand the behavioral change
  • Fix the test
  • Push

Root cause: The PR changed packages/block-replacer/src/index.js so that passing both srcPath and content no longer throws — instead content is used as preloaded file contents (the caching optimization noted in the review). The test "should handle both srcPath and content error" still expected the old error-throwing behavior.

Fix (packages/block-replacer/test/index.test.js:195): Updated the test to match the new behavior — instead of expecting an error, it now verifies that the call succeeds and returns a result. The test name was also updated to reflect the intent ("should handle both srcPath and content using preloaded content").

Commit: f1394c4
| Branch

When both srcPath and content are provided, content is now used as
preloaded file contents instead of throwing an error. Update the test
to match the new intentional behavior.

Co-authored-by: David Wells <DavidWells@users.noreply.github.com>
@github-actions github-actions bot added auto-generated Automatically generated content claude-code Items created or modified by Claude Code labels Feb 21, 2026
@DavidWells DavidWells marked this pull request as ready for review February 21, 2026 17:51
@DavidWells DavidWells merged commit 4213fdd into master Feb 21, 2026
@DavidWells DavidWells deleted the cursor/initial-codebase-assessment-4791 branch February 21, 2026 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-generated Automatically generated content claude-code Items created or modified by Claude Code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants