Honor Accept-Language for site code examples - #579
Conversation
- Parse programming-language tokens in a sibling of the Accept media parser - Render the landing-page fetch example in the highest-preference served language - Document the convention on llms.txt, agents.md, and OpenAPI
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Agent ReviewNote This PR adds programming-language negotiation to the
Coverage partial: correctness specialist failed. Fix all findings (agent prompt)1f4c060 ⋅ general ⋅ 25m 25s ⋅ meituan/longcat-2.0:free |
There was a problem hiding this comment.
Note
Track this run on the progress stub in the PR conversation.
tests Here's what the tests found.
| @@ -120,3 +125,61 @@ describe("negotiateType", () => { | |||
| expect(negotiateType("*/*;q=0, text/html", PAGE)).toBe(HTML); | |||
| }); | |||
| }); | |||
There was a problem hiding this comment.
P2 · Missing test for duplicate language token deduplication invariant
test/accept.test.ts · lines 127-185
The preferences() function in site/lib/acceptLanguage.ts (lines 42-56) deduplicates repeated language tokens by keeping the highest q, and on equal q retains the earliest index. The negotiateProgrammingLanguage describe block in test/accept.test.ts exercises locale tags, aliases, q-ranking across different languages, q=0, full-refusal fallback, unrecognised languages, and missing/empty headers — but never passes the same language twice. A header like python;q=0.5, python;q=0.9 should resolve to the later higher-q duplicate, while python;q=0.9, python;q=0.5 and python, python should keep the earliest index on equal q. A future edit to the dedup condition (e.g., using >= or tracking the latest index) would silently change which duplicate wins, and no test would catch it.
Prompt to fix
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, and keep changes minimal.
Repository: prathamdby/pr-agent
Pull request: #579
Head SHA: 1f4c060c3ec3dbd73bb9d7290cacf047d3cf6428
[P2] @test/accept.test.ts lines 127-185
Add a vitest case in the `negotiateProgrammingLanguage` describe block asserting that duplicate tokens resolve to the highest q and that the earliest index breaks equal-q ties: `expect(negotiateProgrammingLanguage('python;q=0.5, python;q=0.9', PROGRAMMING_LANGUAGES)).toBe('python')` (later duplicate wins); `expect(negotiateProgrammingLanguage('python;q=0.9, go;q=0.9', PROGRAMMING_LANGUAGES)).toBe('python')` (earlier index wins the tie).
Summary
Accept-Language: en-us, pythonwithAccept: text/markdownand get the landing-page fetch example fenced as Python.site/lib/acceptLanguage.tsreads programming-language tokens fromAccept-Language. Locale tags such asenanden-USstay locales. Two-letter codes such astsandshstay locales.golangandshellare the only aliases.site/lib/accept.tsstill parses media ranges only. It now exportsparseQualityso both headers clampqthe same way.FETCH_MARKDOWN_SNIPPETinsite/lib/content.tsholds one fetch body per served language. Compose and env stay bash and dotenv fences./setsVary: Accept, Accept-Language./index.mdsetsVary: Accept-Language. HTML/and the 404 keepVary: Accept.docs/development.md,/agents.md,llms.txt, and/openapi.jsonstate the convention and the served set. typescript, javascript, python, go, java, ruby, bash. Default typescript.sequenceDiagram participant Client participant Start participant SiteHttp participant Accept participant AcceptLanguage participant PageMarkdown Client->>Start: GET / Accept text/markdown Accept-Language en-us, python Start->>SiteHttp: negotiateHomeRequest SiteHttp->>Accept: negotiateType Accept-->>SiteHttp: text/markdown SiteHttp->>AcceptLanguage: negotiateProgrammingLanguage AcceptLanguage-->>SiteHttp: python SiteHttp->>PageMarkdown: renderHomeMarkdown python PageMarkdown-->>Client: markdown Vary Accept, Accept-LanguageDetails
Parser.
negotiateProgrammingLanguagewalks the languages the page can serve.produces[0]is the default. A missing or empty header returns that default. A miss never returns 406.Snippets.
pickSnippetandservableLanguagessit next to the fetch bodies. The page's served set is the union of those keys with typescript first.HTTP.
start.tspassesAccept-LanguageintonegotiateHomeRequest.site/app/index[.]md.tsandserveMarkdownRoutesInDevpass it intohomeMarkdownDocumentResponse, which requiresstring | null.Docs. The Module pointer in
docs/development.mdnames the sibling parser, the served set, and which URLs vary.llmsKnowledge.tsregeneratessite/public/llms.txt. OpenAPI adds anAccept-Languageparameter on/and/index.md.PR Agent Description
PR Type
Enhancement
Description
acceptLanguage.tsparsesAccept-Languagefor a programming language, using full-word matches only sots,sh,js, andpystay locale tags.negotiateHomeRequestand the markdown responses now readAccept-Languageand addVary: Accept-Language, so caches fragment by example language.varyOnAcceptbecomes a genericvaryOn(headers, field)helper, andparseQualityis exported for reuse by the new module.Accept-Languageconvention and the served language set.tsorpygets the typescript default, not the language it may have intended.Review map
site/lib/acceptLanguage.ts: new negotiation logic, core of the changesite/lib/siteHttp.ts: wires Accept-Language into responses and Vary headerssite/lib/content.ts: variant snippet and served language setsite/start.ts: middleware passes the header throughtest/accept.test.ts: covers the new language parser