Skip to content

fix(public): resolve duplicate guide slugs by precedence, not scan order - #4011

Merged
PierreBrisorgueil merged 4 commits into
masterfrom
fix/3979-guide-slug-precedence
Aug 4, 2026
Merged

fix(public): resolve duplicate guide slugs by precedence, not scan order#4011
PierreBrisorgueil merged 4 commits into
masterfrom
fix/3979-guide-slug-precedence

Conversation

@PierreBrisorgueil

@PierreBrisorgueil PierreBrisorgueil commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • What changed: guide slug collisions in the public docs API are now resolved by a precedence policy instead of file-scan order. An application-level guide (any module outside the stack's existing CORE_MODULES set) always overrides a framework-provided one (core/auth/users/home) on a slug collision — deterministic, regardless of scan order. buildDocsTree and the bySlug index are now built from the SAME deduped entry list, so GET /api/public/docs (listing) and GET /api/public/docs/:slug.md (fetch) can never disagree, and the tree never shows a duplicate nav entry. A same-tier collision (two framework or two application guides) keeps the existing deterministic tiebreak and logs a warning naming the actual remedy, instead of "rename one" as the only option.
  • Why: today compute() warns and keeps the last-scanned guide, but buildDocsTree keeps BOTH entries — the listing shows a duplicate while the fetch endpoint can return a different guide than what's listed. Worse, a consumer colliding with a framework-shipped sample guide (e.g. its own 00-welcome) has no actionable remedy: renaming a framework file isn't possible, and the only escape (config.docs.excludeModules) isn't discoverable without reading config/index.js.
  • Related issues: Closes 🐛 Duplicate guide slugs resolve by scan order, and the documented remedy is not actionable for the colliding consumer #3979

Scope

  • Module(s) impacted: modules/public (docs service + tree helper)
  • Cross-module impact: none (reuses the existing lib/helpers/config.js CORE_MODULES export, does not modify it)
  • Risk level: low

Validation

  • npm run lint
  • npm test (unit: 2316/2316 passing; integration: 597/597 passing, incl. new collision-precedence cases)
  • Manual checks done (if applicable) — verified coverage: 100% stmts/branches/funcs on the two touched source files

Guardrails check

  • No secrets or credentials introduced (.env*, secrets/**, keys, tokens)
  • No risky rename/move of core stack paths
  • Changes remain merge-friendly for downstream projects
  • Tests added or updated when behavior changed

Notes for reviewers

  • Security considerations: none — read-only public docs endpoint, no new input surface.
  • Mergeability considerations: none — additive change to modules/public only, no shared/config file touched.
  • Follow-up tasks (optional): shape (1) from the issue (excluding sample guides by default) was explicitly rejected — separate product-default decision, may come later.

Summary by CodeRabbit

  • Bug Fixes
    • Resolved duplicate documentation guide slugs consistently across guide listings and direct links.
    • Application-provided guides now take precedence over framework guides with the same slug.
    • Same-level conflicts are handled deterministically, with warnings for visibility.
  • Tests
    • Added coverage for guide precedence, duplicate handling, ordering, and invalid entries.

An application-level guide (any module other than home) now
deterministically overrides a framework-provided (home) guide on a slug
collision, silently. A same-tier collision (two framework or two
application guides) keeps a deterministic tiebreak and warns with the
actual remedy instead of "rename one" as the only option.

buildDocsTree and the bySlug index are now built from the SAME deduped
entry list (resolveGuideEntries), so the listing (/api/public/docs) and
the fetch endpoint (/api/public/docs/:slug.md) can never disagree, and
the tree never shows a duplicate nav entry.

Closes #3979
…k map

- precedenceTier now reuses the stack's existing framework-module set
  (lib/helpers/config.js CORE_MODULES) instead of a new single-module
  constant — same classification filterByActivation already relies on.
- Drop PRECEDENCE_RANK: with only two tiers and same-tier collisions
  already handled earlier, the remaining branch is just "challenger is
  application".
@PierreBrisorgueil PierreBrisorgueil added the Fix A bug fix label Aug 4, 2026
@PierreBrisorgueil PierreBrisorgueil self-assigned this Aug 4, 2026
@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@PierreBrisorgueil, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 22 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4b790798-9e4b-4fc5-ab09-f7b45e8a0093

📥 Commits

Reviewing files that changed from the base of the PR and between c385cd6 and cca8e9f.

📒 Files selected for processing (1)
  • modules/public/tests/public.docs.integration.tests.js

Walkthrough

The public docs system now applies configuration-aware guide slug precedence. Application guides override framework guides. Same-tier collisions keep the later deterministic entry with a warning. The resolved entries feed both the documentation tree and slug index.

Changes

Guide slug precedence

Layer / File(s) Summary
Guide classification and collision resolution
modules/public/helpers/public.docs.tree.js, modules/public/tests/public.docs.tree.unit.tests.js
Added exported precedence classification and slug resolution. Application entries override framework entries. Same-tier collisions retain the later entry and emit a warning.
Shared resolved data flow
modules/public/services/public.docs.service.js, modules/public/tests/public.docs.service.fallback.unit.tests.js, modules/public/tests/public.docs.service.unit.tests.js
compute uses resolved entries for both tree construction and bySlug. Service mocks and tests verify this shared input.
Application guide precedence integration
modules/public/tests/public.docs.integration.tests.js
Added temporary fixture coverage for application override behavior in guide listings and content fetches.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DocsService as public.docs.service.compute
  participant Resolver as docsTree.resolveGuideEntries
  participant Tree as buildDocsTree
  participant SlugIndex as bySlug
  DocsService->>Resolver: Resolve loaded guide entries
  Resolver-->>DocsService: Return deduplicated entries
  DocsService->>Tree: Build tree from resolved entries
  DocsService->>SlugIndex: Index the same resolved entries
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation satisfies issue #3979 by applying precedence and sharing deduplicated entries between the docs tree and slug index.
Out of Scope Changes check ✅ Passed The changes remain within modules/public and support the linked issue through implementation updates and focused tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly summarizes the main change: resolving duplicate guide slugs by precedence instead of scan order.
Description check ✅ Passed The description covers the required summary, scope, validation, guardrails, and reviewer notes with specific implementation and testing details.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/3979-guide-slug-precedence

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.

@PierreBrisorgueil
PierreBrisorgueil marked this pull request as ready for review August 4, 2026 12:52
@PierreBrisorgueil

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@codecov

codecov Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.54%. Comparing base (257a061) to head (cca8e9f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4011      +/-   ##
==========================================
+ Coverage   93.52%   93.54%   +0.01%     
==========================================
  Files         170      170              
  Lines        5744     5759      +15     
  Branches     1842     1847       +5     
==========================================
+ Hits         5372     5387      +15     
  Misses        302      302              
  Partials       70       70              
Flag Coverage Δ
integration 61.83% <85.71%> (+0.15%) ⬆️
unit 76.12% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 257a061...cca8e9f. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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 `@modules/public/tests/public.docs.integration.tests.js`:
- Line 143: Update the fixture setup at config.files.guides so appGuidePath is
placed before the framework’s original guide sources, ensuring the test fails
under old later-entry-wins scan behavior and verifies application precedence
independently of file order.
🪄 Autofix

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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 056fe5aa-7c99-494d-85e3-656a7335344b

📥 Commits

Reviewing files that changed from the base of the PR and between 257a061 and c385cd6.

📒 Files selected for processing (6)
  • modules/public/helpers/public.docs.tree.js
  • modules/public/services/public.docs.service.js
  • modules/public/tests/public.docs.integration.tests.js
  • modules/public/tests/public.docs.service.fallback.unit.tests.js
  • modules/public/tests/public.docs.service.unit.tests.js
  • modules/public/tests/public.docs.tree.unit.tests.js

Comment thread modules/public/tests/public.docs.integration.tests.js Outdated
The welcome-slug fixture used an absolute OS-tmpdir path, which always
sorts before the relative modules/home/... path loadGuideEntries scans —
so it only proved the override when the app guide is scanned FIRST.

Add a second fixture (quickstart slug) at a relative path that sorts
AFTER modules/home/..., proving the override also holds when the app
guide is scanned LAST — end-to-end, not just via the mocked orderings
already covered in public.docs.tree.unit.tests.js.

Addresses CodeRabbit review on PR #4011.
path.join(process.cwd(), ...) is always absolute, so the "opposite
scan-order direction" fixture was in fact absolute too — both
integration fixtures sorted before modules/home/..., meaning the app
guide was the incumbent in both collisions and the explicit
"challenger overrides incumbent" branch in resolveGuideEntries was
never exercised at the integration level (verified by execution: a
debug-spy showed zero calls, and reverting the source made both
"opposite direction" assertions fail identically).

Push a real relative path (path.relative(process.cwd(), ...)) into
config.files.guides for the quickstart fixture instead, so it sorts
AFTER modules/home/... and the framework guide is genuinely incumbent.
Add a logger.debug spy proving the override branch fires only for that
case, and scope the "welcome" test's assertion to its own slug (the
same compute() pass also resolves the quickstart collision, so a
blanket "not called" would be a false negative).
@PierreBrisorgueil
PierreBrisorgueil merged commit adbc2b8 into master Aug 4, 2026
8 checks passed
@PierreBrisorgueil
PierreBrisorgueil deleted the fix/3979-guide-slug-precedence branch August 4, 2026 13:42
PierreBrisorgueil added a commit that referenced this pull request Aug 4, 2026
* fix(public): make docs integration tests consumer-independent

The public docs integration suite still read real on-disk guide
content/counts in several places (tree grouping, the raw-markdown
:slug.md test, the front-matter leak check). A consumer shipping its
own guide at a globally-shared slug (welcome/quickstart) now
deterministically wins that slug by design (#4011), so any assertion
pinned to which real guide wins is a consumer-dependence bug.

Split the file's first describe block into a shape/status-only block
(no fixture needed, content is irrelevant) and a controlled-fixture
block that fully replaces config.files.guides with self-authored
guides (the #4014 pattern), restored in afterAll. The raw-markdown
test now targets a fixture guide at a unique slug and asserts its own
content. The slug-collision precedence block is untouched.

Verified the invariant holds by running the suite with a synthetic
extra guide file injected at the welcome/quickstart slugs from a fake
non-core module — identical green result with or without it.

Closes #4015

* fix(public): scope the unknown-slug 404 test to the controlled fixture

CodeRabbit review on #4016: the 404-for-unknown-slug test lived in the
shape/status-only block and queried a hardcoded slug against whatever
config.files.guides resolves to at boot. A consumer could in principle
configure a guide at that exact slug, making the test consumer-dependent
again. Move it into the controlled-fixture block (config.files.guides
fully replaced there) and query a slug guaranteed absent from that
fixture set.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Duplicate guide slugs resolve by scan order, and the documented remedy is not actionable for the colliding consumer

1 participant