fix: support underscored docs and md URLs#2095
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe PR enables document IDs and paths to start with underscores by updating backend validation regex patterns, adding frontend path normalization to strip ChangesUnderscore-Prefixed Document Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
internal/agent/doc.go (1)
141-141: ⚡ Quick winAvoid hardcoding the regex pattern text in the error message.
ValidateDocIDnow has the pattern in two places (regexp + error string). Consider deriving the message fromvalidDocIDRegexp.String()(or a shared constant) to prevent silent drift on future edits.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/agent/doc.go` at line 141, The error message in ValidateDocID hardcodes the regex text causing duplication; change the fmt.Errorf call to reference the canonical regexp (validDocIDRegexp.String()) or a shared constant instead of the literal pattern so the message is derived from validDocIDRegexp, e.g. build the error with fmt.Errorf("%w: must match pattern %s", ErrInvalidDocID, validDocIDRegexp.String()), keeping ErrInvalidDocID as the wrapped error.ui/src/pages/docs/lib/__tests__/doc-url.test.ts (1)
5-20: ⚡ Quick winAdd an explicit uppercase extension case to lock in case-insensitive behavior.
The implementation uses a case-insensitive regex; add a direct
.MDassertion so future changes can’t accidentally narrow behavior.Proposed test addition
it('strips a markdown extension from URL paths', () => { expect(normalizeDocPathFromURL('runbooks/deploy.md')).toBe( 'runbooks/deploy' ); + expect(normalizeDocPathFromURL('runbooks/DEPLOY.MD')).toBe( + 'runbooks/DEPLOY' + ); });🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@ui/src/pages/docs/lib/__tests__/doc-url.test.ts` around lines 5 - 20, Add a test case to doc-url.test.ts that asserts normalizeDocPathFromURL treats uppercase ".MD" the same as ".md" (e.g., expect(normalizeDocPathFromURL('runbooks/deploy.MD')).toBe('runbooks/deploy')), so the case-insensitive behavior of normalizeDocPathFromURL is locked in; locate the existing tests in this file that cover lowercase ".md" and the non-markdown suffix and insert the uppercase ".MD" assertion near them.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@ui/src/pages/docs/lib/__tests__/doc-url.test.ts`:
- Around line 1-2: This test file is missing the required GPLv3 license header;
add the project-standard GPLv3 header at the very top of the file (above the
imports) to match other TypeScript sources, then run the repository's license
tool (make addlicense) or commit the exact header used elsewhere so the file
containing imports and symbols like normalizeDocPathFromURL, describe, expect,
and it passes the repository's license checks.
In `@ui/src/pages/docs/lib/__tests__/doc-validation.test.ts`:
- Around line 1-2: This new TypeScript test file is missing the required GPLv3
license header; add the repository's standard GPL v3 header at the very top of
ui/src/pages/docs/lib/__tests__/doc-validation.test.ts (above the imports) so it
matches other *.ts files—either run the repository helper (make addlicense) to
insert the correct header automatically or paste the exact GPLv3 header used
elsewhere in the repo into the top of this file.
In `@ui/src/pages/docs/lib/doc-url.ts`:
- Around line 1-3: This file is missing the repository-required GPLv3 license
header; add the standard GPLv3 header to the top of the TypeScript file (above
the export) so it matches the project's licensing policy, either by running the
repository tool (make addlicense) or by inserting the canonical GPLv3 header
comment manually before the normalizeDocPathFromURL function declaration; ensure
the header format matches other .ts/.tsx files in the repo.
---
Nitpick comments:
In `@internal/agent/doc.go`:
- Line 141: The error message in ValidateDocID hardcodes the regex text causing
duplication; change the fmt.Errorf call to reference the canonical regexp
(validDocIDRegexp.String()) or a shared constant instead of the literal pattern
so the message is derived from validDocIDRegexp, e.g. build the error with
fmt.Errorf("%w: must match pattern %s", ErrInvalidDocID,
validDocIDRegexp.String()), keeping ErrInvalidDocID as the wrapped error.
In `@ui/src/pages/docs/lib/__tests__/doc-url.test.ts`:
- Around line 5-20: Add a test case to doc-url.test.ts that asserts
normalizeDocPathFromURL treats uppercase ".MD" the same as ".md" (e.g.,
expect(normalizeDocPathFromURL('runbooks/deploy.MD')).toBe('runbooks/deploy')),
so the case-insensitive behavior of normalizeDocPathFromURL is locked in; locate
the existing tests in this file that cover lowercase ".md" and the non-markdown
suffix and insert the uppercase ".MD" assertion near them.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 70fc983d-3ba8-405c-bf76-c79fe5476fae
📒 Files selected for processing (7)
internal/agent/doc.gointernal/persis/filedoc/store_test.goui/src/pages/docs/index.tsxui/src/pages/docs/lib/__tests__/doc-url.test.tsui/src/pages/docs/lib/__tests__/doc-validation.test.tsui/src/pages/docs/lib/doc-url.tsui/src/pages/docs/lib/doc-validation.ts
a9588c2 to
e20ea9a
Compare
fbc6e7e to
035bd23
Compare
Summary
_so existing_index.md-style docs are listed and readable.mdbefore opening the document tabRoot cause
Document ID validation required every path segment to start with an alphanumeric character, so
_-prefixed Markdown files were treated as non-conforming and skipped or rejected. The docs page also used the raw route path as the document ID, so/docs/foo.mdattempted to loadfoo.mdinstead of the storedfoodocument.Testing
go test ./internal/agent ./internal/persis/filedoc ./internal/service/frontend/api/v1pnpm test src/pages/docs/lib/__tests__/doc-url.test.ts src/pages/docs/lib/__tests__/doc-validation.test.tspnpm typecheckmake test TEST_TARGET="./internal/agent ./internal/persis/filedoc ./internal/service/frontend/api/v1"pnpm testmake checkSummary by CodeRabbit
New Features
_index,guides/_partial)..mdextensions when syncing tabs.Tests