-
Notifications
You must be signed in to change notification settings - Fork 22
test(docs): add comprehensive tests and monitoring for llms.txt endpoints #4676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: app
Are you sure you want to change the base?
Changes from all commits
e986247
efbfae1
a8466e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| name: Monitor LLM-friendly Docs Endpoints | ||
|
|
||
| on: | ||
| schedule: | ||
| # Run every 5 minutes | ||
| - cron: '*/5 * * * *' | ||
| workflow_dispatch: # Allow manual triggering | ||
|
|
||
| jobs: | ||
| monitor: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| npm install -g tsx | ||
| npm install node-fetch | ||
|
|
||
| - name: Run monitoring script | ||
| env: | ||
| SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_DOCS_INCIDENTS }} | ||
| INCIDENT_IO_API_KEY: ${{ secrets.INCIDENT_IO_API_KEY }} | ||
| run: | | ||
| tsx scripts/monitor/check-llms-md-endpoints.ts | ||
|
|
||
| - name: Report status | ||
| if: always() | ||
| run: | | ||
| if [ $? -eq 0 ]; then | ||
| echo "✅ All endpoints healthy" | ||
| else | ||
| echo "❌ Some endpoints failed - alerts sent" | ||
| fi | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import { NextRequest } from "next/server"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
|
|
||
| describe("markdown route slug handling", () => { | ||
| const createMockRequest = (pathname: string, searchParams: Record<string, string> = {}) => { | ||
| const url = new URL(`https://example.com${pathname}`); | ||
| Object.entries(searchParams).forEach(([key, value]) => { | ||
| url.searchParams.set(key, value); | ||
| }); | ||
| return new NextRequest(url); | ||
| }; | ||
|
|
||
| it("should prefer slug from search params over pathname", () => { | ||
| const request = createMockRequest("/api/fern-docs/markdown", { slug: "docs/quickstart" }); | ||
|
|
||
| const slugParam = request.nextUrl.searchParams.get("slug"); | ||
| const slug = slugParam ?? request.nextUrl.pathname.replace(/\.(md|mdx)$/, ""); | ||
|
Comment on lines
+14
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test is validating behavior that doesn't exist in the actual route implementation - the route doesn't use search parameters for slug extraction. View Details📝 Patch Detailsdiff --git a/packages/fern-docs/bundle/src/app/[host]/[domain]/[lang]/fern-docs/markdown/route.ts b/packages/fern-docs/bundle/src/app/[host]/[domain]/[lang]/fern-docs/markdown/route.ts
index 35eb56b3c..d8092dda6 100644
--- a/packages/fern-docs/bundle/src/app/[host]/[domain]/[lang]/fern-docs/markdown/route.ts
+++ b/packages/fern-docs/bundle/src/app/[host]/[domain]/[lang]/fern-docs/markdown/route.ts
@@ -27,7 +27,8 @@ export async function GET(req: NextRequest, props: { params: Promise<BaseParams>
const fernToken = (await cookies()).get(COOKIE_FERN_TOKEN)?.value;
const path = req.nextUrl.pathname;
- const slug = path.replace(MARKDOWN_PATTERN, "");
+ const slugParam = req.nextUrl.searchParams.get("slug");
+ const slug = slugParam ?? path.replace(MARKDOWN_PATTERN, "");
const cleanSlug = removeLeadingSlash(slug);
const loader = await createCachedDocsLoader(host, domain, fernToken);
AnalysisRoute ignores slug parameter from middleware, causing incorrect markdown resolutionWhat fails: The markdown route handler in How to reproduce:
Result: Route resolves slug as Expected: Route should check |
||
|
|
||
| expect(slug).toBe("docs/quickstart"); | ||
| }); | ||
|
|
||
| it("should fallback to pathname parsing when slug param is not present", () => { | ||
| const request = createMockRequest("/docs/quickstart.md"); | ||
|
|
||
| const slugParam = request.nextUrl.searchParams.get("slug"); | ||
| const slug = slugParam ?? request.nextUrl.pathname.replace(/\.(md|mdx)$/, ""); | ||
|
|
||
| expect(slug).toBe("/docs/quickstart"); | ||
| }); | ||
|
|
||
| it("should handle .mdx extension in pathname fallback", () => { | ||
| const request = createMockRequest("/docs/quickstart.mdx"); | ||
|
|
||
| const slugParam = request.nextUrl.searchParams.get("slug"); | ||
| const slug = slugParam ?? request.nextUrl.pathname.replace(/\.(md|mdx)$/, ""); | ||
|
|
||
| expect(slug).toBe("/docs/quickstart"); | ||
| }); | ||
|
|
||
| it("should handle nested paths in slug param", () => { | ||
| const request = createMockRequest("/api/fern-docs/markdown", { | ||
| slug: "learn/sdks/overview/quickstart" | ||
| }); | ||
|
|
||
| const slugParam = request.nextUrl.searchParams.get("slug"); | ||
| const slug = slugParam ?? request.nextUrl.pathname.replace(/\.(md|mdx)$/, ""); | ||
|
|
||
| expect(slug).toBe("learn/sdks/overview/quickstart"); | ||
| }); | ||
|
|
||
| it("should handle empty slug param", () => { | ||
| const request = createMockRequest("/api/fern-docs/markdown", { slug: "" }); | ||
|
|
||
| const slugParam = request.nextUrl.searchParams.get("slug"); | ||
| const slug = slugParam ?? request.nextUrl.pathname.replace(/\.(md|mdx)$/, ""); | ||
|
|
||
| expect(slug).toBe(""); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The status check using
$?will always return 0 because it checks the exit code of theifcommand, not the monitoring script.View Details
Analysis
Incorrect exit code check in monitoring workflow always shows success
What fails: The "Report status" step in
.github/workflows/monitor-llms-md-endpoints.ymluses$?to check the monitoring script's exit code, but$?refers to theifcommand (always 0), not the previous step's tsx scriptHow to reproduce:
Result: Always prints "✅ All endpoints healthy" even when monitoring script fails
Expected: Should show failure status when monitoring script exits with code 1
Fix: Removed the misleading "Report status" step since the job's overall status already correctly indicates success/failure and the monitoring script logs appropriate messages