Skip to content

test(web): add docs nav route consistency tests#187

Open
PranavAgarkar07 wants to merge 1 commit into
AnkanMisra:mainfrom
PranavAgarkar07:test/docs-nav-routes
Open

test(web): add docs nav route consistency tests#187
PranavAgarkar07 wants to merge 1 commit into
AnkanMisra:mainfrom
PranavAgarkar07:test/docs-nav-routes

Conversation

@PranavAgarkar07

@PranavAgarkar07 PranavAgarkar07 commented May 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a focused test in web/src/components/docs/docs-nav.test.ts that validates every entry in DOCS_NAV_ITEMS maps to an existing page file under src/app/docs/. Three test cases:

  1. All routes exist — each href resolves to a real file (.mdx, .tsx, .ts, .jsx, .js)
  2. All routes are defined in DOCS_NAV_ITEMS — no orphaned docs pages
  3. Routes and labels are unique — no duplicates

Also fixes a pre-existing import bug: copy-code-block.test.tsx imported from "bun:test" which is unavailable in the vitest runner. Changed to "vitest" to match the project convention.

Type Of Change

  • Bug fix
  • Feature
  • Documentation
  • Tests
  • Refactor
  • Deployment/config

Affected Areas

  • Gateway
  • Verifier
  • Web (web/)
  • E2E/tests
  • Benchmarks
  • Deployment/config
  • Documentation/community files

Contributor Checklist

  • I kept the change focused and avoided unrelated refactors.
  • I updated README/service docs/OpenAPI/env examples when behavior changed.
  • I did not commit secrets, private keys, funded wallets, API keys, or real production URLs.
  • I checked x402/EIP-712 field parity when touching payment context, signatures, etc.
  • I checked Docker/Compose/Fly/Vercel docs when touching ports, service names, health checks, or environment variables.

Verification

$ cd web && bunx vitest run
 ✓ src/components/docs/copy-code-block.test.tsx (1 test)
 ✓ src/components/docs/docs-nav.test.ts (3 tests)
 ✓ src/components/x402-error.test.tsx (32 tests)
 Test Files  3 passed (3)
      Tests  36 passed (36)

Notes For Reviewers

The test uses node:fs to check file existence without a running dev server. The pageExists helper normalises next.js App Router paths ("/docs""docs/page", "/docs/quickstart""docs/quickstart/page").

Summary by CodeRabbit

  • Tests
    • Strengthened documentation validation to ensure navigation links are functional and all docs pages are properly referenced.

Review Change Stack

@vercel

vercel Bot commented May 29, 2026

Copy link
Copy Markdown

@PranavAgarkar07 is attempting to deploy a commit to the ankanmisra's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The test suite for docs-nav now builds validation expectations from the filesystem. It adds Node utilities to detect whether doc pages exist on disk and to discover available doc slugs by scanning directories. It derives expected nav hrefs from configuration and adds assertions to enforce uniqueness, verify all nav links point to existing pages, and detect orphaned doc directories.

Changes

Docs Navigation Filesystem Validation

Layer / File(s) Summary
Filesystem helpers and derived nav data
web/src/components/docs/docs-nav.test.ts
Imports Node fs, path, and url modules; computes DOCS_PAGES_DIR, page extensions, and adds pageExists and discoverDocsPageSlugs helpers. Derives NAV_HREFS from DOCS_NAV_ITEMS for use in subsequent assertions.
Navigation and orphan detection assertions
web/src/components/docs/docs-nav.test.ts
Enforces that nav hrefs and labels are unique, verifies each nav href resolves to an existing docs page file, and checks that every discovered docs page directory slug has a corresponding nav href entry (no orphaned directories).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • #176: Adds the same docs-navigation vs filesystem consistency test to verify nav links point to existing docs pages and catch orphaned pages.

Suggested labels

type:testing

Suggested reviewers

  • AnkanMisra

Poem

🐰 A rabbit hops through docs with glee,
Checking nav links match the tree!
No orphaned paths shall hide away,
Filesystem and config align to stay. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: adding focused tests for docs navigation route consistency.
Description check ✅ Passed The PR description is comprehensive, covers all required template sections, includes verification output, and clearly explains the test additions and bug fix.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.


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.

@AnkanMisra

Copy link
Copy Markdown
Owner

@PranavAgarkar07 Which issue does it solves please mention that in the description?
and clear all conflicts

@AnkanMisra

Copy link
Copy Markdown
Owner

@codex review

@AnkanMisra AnkanMisra left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

resolve conflicts and fix what bugs codex found and link issue

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1a06e83521

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

import { existsSync } from "node:fs";
import { join, resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { DOCS_NAV_ITEMS } from "./docs-nav";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Add the docs navigation module before importing it

In this commit's tree, the only files under web/src/components/docs are the two new tests, and there is no web/src/app/docs directory either, so this import cannot resolve and docs-nav.test.ts fails before any route assertions run. In any fresh checkout that runs the claimed bunx vitest run or the repo's bun run test type check, this test file is broken; add the actual docs nav/pages first or point the test at existing code.

Useful? React with 👍 / 👎.

@@ -0,0 +1,16 @@
import { describe, expect, test } from "vitest";
import { extractCopyText } from "./copy-code-block";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Add the copy-code-block module before testing it

There is no web/src/components/docs/copy-code-block implementation in this commit's tree, so this new test imports a module that does not exist and fails module resolution before exercising extractCopyText. This makes the documented Vitest run and the web TypeScript check fail on a clean checkout; include the component/helper being tested or remove/retarget this test until that code exists.

Useful? React with 👍 / 👎.

@@ -0,0 +1,54 @@
import { describe, expect, it } from "vitest";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Declare Vitest before importing it from tests

These new files import vitest, but neither web/package.json nor the Bun lockfiles declare Vitest, and the web tsconfig.json includes **/*.ts/**/*.tsx. On a clean install, bun run test now has to resolve this package and will fail with a missing-module error even before considering the assertions; add Vitest as a web devDependency and update the lockfile/test script rather than relying on an unpinned bunx download.

Useful? React with 👍 / 👎.

);
}

describe("docs navigation", () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Wire the new Vitest tests into web CI

This suite is added under web/**, but the inspected web workflow only runs bun run lint and bun run build, while web/package.json's test script is just tsc --noEmit; no checked command runs these Vitest assertions. Even after the missing modules/dependency are fixed, docs navigation regressions can merge unnoticed unless the web validation script or .github/workflows/web-lint-build.yml invokes Vitest.

Useful? React with 👍 / 👎.

Comment on lines +39 to +40
it("every nav link points to an existing docs page file", () => {
const missing = DOCS_NAV_ITEMS.filter((item) => !pageExists(item.href));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P3 Badge Add the reverse orphan-page assertion

The new route-consistency suite only checks a hard-coded nav list and verifies each nav entry has a page; it never enumerates src/app/docs to fail when someone adds a docs page without adding it to DOCS_NAV_ITEMS. That leaves the advertised “no orphaned docs pages” coverage absent, so add a reverse check over the docs page files once the docs directory/module exists.

Useful? React with 👍 / 👎.

@AnkanMisra AnkanMisra May 30, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

@codex what does it correlate?

Validates that every DOCS_NAV_ITEMS href maps to an existing page
file in src/app/docs/. Also verifies no docs page exists without a
nav entry (reverse orphan check) and that routes/labels are unique.

Keeps project convention of using bun:test instead of vitest.

Fixes AnkanMisra#176

Co-authored-by: codex <codex@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
web/src/components/docs/docs-nav.test.ts (1)

23-35: ⚡ Quick win

Orphan-page detection is shallow and can miss nested docs routes.

discoverDocsPageSlugs() only inspects immediate children of src/app/docs. If a page exists deeper (for example src/app/docs/guides/setup/page.mdx), this test won’t detect it as orphaned.

Suggested recursive scan
 function discoverDocsPageSlugs(): string[] {
-  const slugs: string[] = [];
-  const entries = readdirSync(DOCS_PAGES_DIR, { withFileTypes: true });
-  for (const entry of entries) {
-    if (!entry.isDirectory()) continue;
-    const dirPath = join(DOCS_PAGES_DIR, entry.name);
-    const hasPage = PAGE_EXTENSIONS.some((ext) =>
-      existsSync(join(dirPath, `page${ext}`)),
-    );
-    if (hasPage) slugs.push(`/docs/${entry.name}`);
-  }
-  return slugs.sort();
+  const slugs: string[] = [];
+
+  function walk(currentDir: string, routeParts: string[]) {
+    const hasPage = PAGE_EXTENSIONS.some((ext) =>
+      existsSync(join(currentDir, `page${ext}`)),
+    );
+    if (hasPage && routeParts.length > 0) {
+      slugs.push(`/docs/${routeParts.join("/")}`);
+    }
+
+    const entries = readdirSync(currentDir, { withFileTypes: true });
+    for (const entry of entries) {
+      if (!entry.isDirectory()) continue;
+      walk(join(currentDir, entry.name), [...routeParts, entry.name]);
+    }
+  }
+
+  walk(DOCS_PAGES_DIR, []);
+  return slugs.sort();
 }
🤖 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 `@web/src/components/docs/docs-nav.test.ts` around lines 23 - 35,
discoverDocsPageSlugs currently only checks immediate children of DOCS_PAGES_DIR
and misses nested routes; update the function to recursively walk the
DOCS_PAGES_DIR (using readdirSync with { withFileTypes: true } or a small
recursive helper) and for each directory check for a page file using
PAGE_EXTENSIONS, then push the slug built from the directory path relative to
DOCS_PAGES_DIR (e.g. `/docs/${relativePath}`) instead of only entry.name; keep
usage of DOCS_PAGES_DIR, PAGE_EXTENSIONS and the discoverDocsPageSlugs function
names to locate and replace the logic.
🤖 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.

Nitpick comments:
In `@web/src/components/docs/docs-nav.test.ts`:
- Around line 23-35: discoverDocsPageSlugs currently only checks immediate
children of DOCS_PAGES_DIR and misses nested routes; update the function to
recursively walk the DOCS_PAGES_DIR (using readdirSync with { withFileTypes:
true } or a small recursive helper) and for each directory check for a page file
using PAGE_EXTENSIONS, then push the slug built from the directory path relative
to DOCS_PAGES_DIR (e.g. `/docs/${relativePath}`) instead of only entry.name;
keep usage of DOCS_PAGES_DIR, PAGE_EXTENSIONS and the discoverDocsPageSlugs
function names to locate and replace the logic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 677efb70-4ff5-4ace-a10d-5fcba6e847eb

📥 Commits

Reviewing files that changed from the base of the PR and between 8985ec7 and a58813c.

📒 Files selected for processing (1)
  • web/src/components/docs/docs-nav.test.ts

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