Skip to content

Commit 920d649

Browse files
fix: request xai release notes as html (#72)
1 parent cd09e90 commit 920d649

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

convex/ingest.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,28 @@ function canUseConditionalCache(source: SourceFetchTarget) {
6969
return sourceLooksLikeDirectFeed(source) || !source.parserKey || !FEED_PARSER_KEYS.has(source.parserKey);
7070
}
7171

72-
function buildFetchHeaders(userAgent: string, source?: SourceFetchTarget) {
72+
function sourceNeedsHtmlFirstAccept(source?: SourceFetchTarget) {
73+
if (!source) {
74+
return false;
75+
}
76+
77+
if (source.parserKey === "xai:docs_page") {
78+
return true;
79+
}
80+
81+
try {
82+
const url = new URL(source.url);
83+
return url.hostname === "docs.x.ai" && url.pathname.replace(/\/$/, "") === "/developers/release-notes";
84+
} catch {
85+
return /docs\.x\.ai\/developers\/release-notes\/?$/i.test(source.url);
86+
}
87+
}
88+
89+
export function buildFetchHeaders(userAgent: string, source?: SourceFetchTarget) {
7390
const accept = sourceLooksLikeDirectFeed(source ?? { url: "" })
7491
? "application/rss+xml,application/atom+xml,application/xml;q=0.9,text/xml;q=0.8,*/*;q=0.7"
92+
: sourceNeedsHtmlFirstAccept(source)
93+
? "text/html,application/xhtml+xml,application/xml;q=0.9,text/plain;q=0.8,*/*;q=0.7"
7594
: "text/markdown,text/html,application/xhtml+xml,application/xml;q=0.9,text/plain;q=0.8,*/*;q=0.7";
7695

7796
const headers: Record<string, string> = {

src/lib/ingestion/ingest-state.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
classifyThrownError,
66
SourceIngestionError,
77
} from "../../../convex/ingestionErrors";
8+
import { buildFetchHeaders } from "../../../convex/ingest";
89
import {
910
findSameSourceCandidateByTitle,
1011
getFailureBackoffUntil,
@@ -21,6 +22,30 @@ import {
2122
shouldPollLifecycleState,
2223
} from "../../../convex/sourceLifecycle";
2324

25+
describe("buildFetchHeaders", () => {
26+
it("requests xAI release notes as HTML instead of the stripped Markdown view", () => {
27+
const headers = buildFetchHeaders("VersionWatchBot/1.0", {
28+
url: "https://docs.x.ai/developers/release-notes",
29+
parserKey: "xai:docs_page",
30+
sourceType: "docs_page",
31+
});
32+
33+
expect(headers.Accept).toContain("text/html");
34+
expect(headers.Accept).not.toContain("text/markdown");
35+
});
36+
37+
it("keeps direct feeds on RSS/XML-first accept headers", () => {
38+
const headers = buildFetchHeaders("VersionWatchBot/1.0", {
39+
url: "https://resend.com/changelog/index.xml",
40+
parserKey: "resend:rss",
41+
sourceType: "rss",
42+
});
43+
44+
expect(headers.Accept).toContain("application/rss+xml");
45+
expect(headers.Accept).not.toContain("text/html");
46+
});
47+
});
48+
2449
describe("hasMeaningfulTitle", () => {
2550
it("allows short semver release titles for GitHub release sources", () => {
2651
expect(hasMeaningfulTitle("v1.14.21", "https://github.com/anomalyco/opencode/releases")).toBe(true);

0 commit comments

Comments
 (0)