From b1695d2fefd1eea2240fa77744b8a78c6797844c Mon Sep 17 00:00:00 2001 From: Robert Gruen Date: Sun, 19 Apr 2026 00:00:27 -0700 Subject: [PATCH 1/5] feat: add optional language parameter to Wikipedia API helpers Allow getPageObject and getPageMarkdown callers to request a non-English Wikipedia locale via an optional language parameter (defaults to "en" so existing callers are unaffected). Co-Authored-By: Claude Sonnet 4.6 --- TODO.md | 7 +++++-- ts/packages/azure-ai-foundry/src/wikipedia.ts | 20 ++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/TODO.md b/TODO.md index 028bb9c1b1..e41eb4e5a5 100644 --- a/TODO.md +++ b/TODO.md @@ -168,8 +168,11 @@ This file collates all TODO comments found across the repository, organized by t | `ts/packages/azure-ai-foundry/src/urlResolverCache.ts` | 121 | make async | Low | High | Local | Fix | No | | `ts/packages/azure-ai-foundry/src/websiteAliasExtraction.ts` | 65 | IMPLEMENT | High | Low | Component | Fix | Yes | | `ts/packages/azure-ai-foundry/src/websiteAliasExtraction.ts` | 121 | handle multi-modal content | High | Medium | Component | Fix | No | -| `ts/packages/azure-ai-foundry/src/wikipedia.ts` | 102 | localization (e.g. en, de, fr, etc.) | Low | High | Local | Fix | No | -| `ts/packages/azure-ai-foundry/src/wikipedia.ts` | 125 | localization (e.g. en, de, fr, etc.) | Low | High | Local | Fix | No | +<<<<<<< Updated upstream +======= +| ~~`ts/packages/azure-ai-foundry/src/wikipedia.ts`~~ | ~~102~~ | ~~localization (e.g. en, de, fr, etc.)~~ | Low | High | Local | ✅ Fixed | No | +| ~~`ts/packages/azure-ai-foundry/src/wikipedia.ts`~~ | ~~125~~ | ~~localization (e.g. en, de, fr, etc.)~~ | Low | High | Local | ✅ Fixed | No | +>>>>>>> Stashed changes | `ts/packages/cache/src/cache/cache.ts` | 599 | Move this in the construction store | Medium | Medium | Component | Fix | Yes | | `ts/packages/cache/src/cache/explainWorkQueue.ts` | 42 | check number too. | Low | High | Local | Fix | No | | `ts/packages/cache/src/constructions/constructionCache.ts` | 420 | GC match sets | Medium | Medium | Component | Fix | No | diff --git a/ts/packages/azure-ai-foundry/src/wikipedia.ts b/ts/packages/azure-ai-foundry/src/wikipedia.ts index f1356c4166..95846e0922 100644 --- a/ts/packages/azure-ai-foundry/src/wikipedia.ts +++ b/ts/packages/azure-ai-foundry/src/wikipedia.ts @@ -98,10 +98,18 @@ export function apiSettingsFromEnv( export async function getPageObject( title: string, config: wikipedia.WikipediaApiSettings, +<<<<<<< Updated upstream + locale: string = "en", ) { // TODO: localization (e.g. en, de, fr, etc.) const response = await fetch( - `${config.endpoint}core/v1/wikipedia/en/page/${title}/bare`, + `${config.endpoint}core/v1/wikipedia/${locale}/page/${title}/bare`, +======= + language: string = "en", +) { + const response = await fetch( + `${config.endpoint}core/v1/wikipedia/${language}/page/${title}/bare`, +>>>>>>> Stashed changes { method: "GET", headers: await config.getAPIHeaders() }, ); @@ -121,9 +129,15 @@ export async function getPageObject( export async function getPageMarkdown( title: string, config: wikipedia.WikipediaApiSettings, +<<<<<<< Updated upstream + locale: string = "en", ): Promise { - // TODO: localization (e.g. en, de, fr, etc.) - const url: string = `${config.endpoint}en/page/${encodeWikipediaTitle(title)}`; + const url: string = `${config.endpoint}${locale}/page/${encodeWikipediaTitle(title)}`; +======= + language: string = "en", +): Promise { + const url: string = `${config.endpoint}${language}/page/${encodeWikipediaTitle(title)}`; +>>>>>>> Stashed changes const response = await fetch(url, { method: "GET", headers: await config.getAPIHeaders(), From c5514773e388af3aff596985b81ad4d1815ca77c Mon Sep 17 00:00:00 2001 From: Robert Gruen Date: Sun, 19 Apr 2026 07:35:47 -0700 Subject: [PATCH 2/5] fix: resolve merge conflict markers in wikipedia.ts Resolve merge conflicts favoring the "locale" parameter name used in the updated docstrings. Co-Authored-By: Claude Sonnet 4.6 --- ts/packages/azure-ai-foundry/src/wikipedia.ts | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/ts/packages/azure-ai-foundry/src/wikipedia.ts b/ts/packages/azure-ai-foundry/src/wikipedia.ts index 95846e0922..05118c7c30 100644 --- a/ts/packages/azure-ai-foundry/src/wikipedia.ts +++ b/ts/packages/azure-ai-foundry/src/wikipedia.ts @@ -98,18 +98,11 @@ export function apiSettingsFromEnv( export async function getPageObject( title: string, config: wikipedia.WikipediaApiSettings, -<<<<<<< Updated upstream locale: string = "en", ) { // TODO: localization (e.g. en, de, fr, etc.) const response = await fetch( `${config.endpoint}core/v1/wikipedia/${locale}/page/${title}/bare`, -======= - language: string = "en", -) { - const response = await fetch( - `${config.endpoint}core/v1/wikipedia/${language}/page/${title}/bare`, ->>>>>>> Stashed changes { method: "GET", headers: await config.getAPIHeaders() }, ); @@ -129,15 +122,9 @@ export async function getPageObject( export async function getPageMarkdown( title: string, config: wikipedia.WikipediaApiSettings, -<<<<<<< Updated upstream locale: string = "en", ): Promise { const url: string = `${config.endpoint}${locale}/page/${encodeWikipediaTitle(title)}`; -======= - language: string = "en", -): Promise { - const url: string = `${config.endpoint}${language}/page/${encodeWikipediaTitle(title)}`; ->>>>>>> Stashed changes const response = await fetch(url, { method: "GET", headers: await config.getAPIHeaders(), From 28758e4874b4e819194a232bb039bb90a776533b Mon Sep 17 00:00:00 2001 From: robgruen Date: Fri, 10 Apr 2026 16:01:21 -0700 Subject: [PATCH 3/5] Fix 5 low-effort TODOs with test coverage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - knowPro/collections: matchesWithMinHitCount condition > 0 → > 1 (optimization, all matches already have hitCount ≥ 1 by design) - dispatcher/unknownSwitcher: parallelize assistant-selection partitions via Promise.all; extract selectFromPartitions() for testability - knowledgeProcessor actions/entities: addMultiple concurrency 1 → settings.concurrency - cache/explainWorkQueue: extend parameter-value-in-request check to cover numbers - azure-ai-foundry/wikipedia: add optional locale param (default "en") to getPageObject and getPageMarkdown Each fix is covered by new or updated unit tests. Co-Authored-By: Claude Sonnet 4.6 --- ts/packages/azure-ai-foundry/src/wikipedia.ts | 5 +- .../azure-ai-foundry/test/wikipedia.spec.ts | 108 ++++++++++++++++++ 2 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 ts/packages/azure-ai-foundry/test/wikipedia.spec.ts diff --git a/ts/packages/azure-ai-foundry/src/wikipedia.ts b/ts/packages/azure-ai-foundry/src/wikipedia.ts index 05118c7c30..5b30856e1a 100644 --- a/ts/packages/azure-ai-foundry/src/wikipedia.ts +++ b/ts/packages/azure-ai-foundry/src/wikipedia.ts @@ -93,6 +93,7 @@ export function apiSettingsFromEnv( * Get the page object of the item with the supplied title. * @param title - The title of the page to retrieve * @param config - The wikipedia API configuration + * @param locale - The Wikipedia language edition (e.g. "en", "de", "fr"). Defaults to "en". * @returns The page object. */ export async function getPageObject( @@ -100,7 +101,6 @@ export async function getPageObject( config: wikipedia.WikipediaApiSettings, locale: string = "en", ) { - // TODO: localization (e.g. en, de, fr, etc.) const response = await fetch( `${config.endpoint}core/v1/wikipedia/${locale}/page/${title}/bare`, { method: "GET", headers: await config.getAPIHeaders() }, @@ -117,7 +117,8 @@ export async function getPageObject( * * @param title - The title of the page whose content to get. * @param config - The wikipedia API configuration - * @returns - The content of the requetsed page or undefined if there was a problem + * @param locale - The Wikipedia language edition (e.g. "en", "de", "fr"). Defaults to "en". + * @returns - The content of the requested page or undefined if there was a problem */ export async function getPageMarkdown( title: string, diff --git a/ts/packages/azure-ai-foundry/test/wikipedia.spec.ts b/ts/packages/azure-ai-foundry/test/wikipedia.spec.ts new file mode 100644 index 0000000000..2c27cf8266 --- /dev/null +++ b/ts/packages/azure-ai-foundry/test/wikipedia.spec.ts @@ -0,0 +1,108 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { + encodeWikipediaTitle, + getPageObject, + getPageMarkdown, +} from "../src/wikipedia.js"; +import { WikipediaApiSettings } from "../src/wikipedia.js"; + +// Minimal stub — only getAPIHeaders is needed for the fetch calls under test +function makeConfig(endpoint: string): WikipediaApiSettings { + return { + endpoint, + getToken: async () => "token", + getAPIHeaders: async () => ({ Authorization: "Bearer token" }), + }; +} + +describe("encodeWikipediaTitle", () => { + test("replaces spaces with underscores", () => { + expect(encodeWikipediaTitle("Johann Sebastian Bach")).toBe( + "Johann_Sebastian_Bach", + ); + }); + + test("percent-encodes special characters", () => { + expect(encodeWikipediaTitle("Ångström")).toBe("%C3%85ngstr%C3%B6m"); + }); + + test("leaves plain ASCII titles unchanged", () => { + expect(encodeWikipediaTitle("Berlin")).toBe("Berlin"); + }); +}); + +describe("getPageObject locale", () => { + let capturedUrl: string; + const originalFetch = globalThis.fetch; + + beforeEach(() => { + globalThis.fetch = async (input: string | URL | Request) => { + capturedUrl = input.toString(); + return { ok: false } as Response; // return undefined from the function under test + }; + }); + + afterEach(() => { + globalThis.fetch = originalFetch; + }); + + test("defaults to 'en' locale", async () => { + const config = makeConfig("https://api.example.com/"); + await getPageObject("Berlin", config); + expect(capturedUrl).toContain("/en/"); + }); + + test("uses supplied locale in URL", async () => { + const config = makeConfig("https://api.example.com/"); + await getPageObject("Berlin", config, "de"); + expect(capturedUrl).toContain("/de/"); + expect(capturedUrl).not.toContain("/en/"); + }); + + test("constructs correct URL shape for 'fr'", async () => { + const config = makeConfig("https://api.example.com/"); + await getPageObject("Paris", config, "fr"); + expect(capturedUrl).toBe( + "https://api.example.com/core/v1/wikipedia/fr/page/Paris/bare", + ); + }); +}); + +describe("getPageMarkdown locale", () => { + let capturedUrl: string; + const originalFetch = globalThis.fetch; + + beforeEach(() => { + globalThis.fetch = async (input: string | URL | Request) => { + capturedUrl = input.toString(); + return { ok: false } as Response; + }; + }); + + afterEach(() => { + globalThis.fetch = originalFetch; + }); + + test("defaults to 'en' locale", async () => { + const config = makeConfig("https://api.example.com/"); + await getPageMarkdown("Berlin", config); + expect(capturedUrl).toContain("/en/"); + }); + + test("uses supplied locale in URL", async () => { + const config = makeConfig("https://api.example.com/"); + await getPageMarkdown("Berlin", config, "de"); + expect(capturedUrl).toContain("/de/"); + expect(capturedUrl).not.toContain("/en/"); + }); + + test("constructs correct URL shape for 'ja'", async () => { + const config = makeConfig("https://api.example.com/"); + await getPageMarkdown("Tokyo", config, "ja"); + expect(capturedUrl).toBe( + "https://api.example.com/ja/page/Tokyo", + ); + }); +}); From 2ccac5f1bf586629292da88cf819af39493a8715 Mon Sep 17 00:00:00 2001 From: robgruen Date: Thu, 16 Apr 2026 13:48:50 -0700 Subject: [PATCH 4/5] lint --- ts/packages/azure-ai-foundry/test/wikipedia.spec.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/ts/packages/azure-ai-foundry/test/wikipedia.spec.ts b/ts/packages/azure-ai-foundry/test/wikipedia.spec.ts index 2c27cf8266..a8016e8d3a 100644 --- a/ts/packages/azure-ai-foundry/test/wikipedia.spec.ts +++ b/ts/packages/azure-ai-foundry/test/wikipedia.spec.ts @@ -101,8 +101,6 @@ describe("getPageMarkdown locale", () => { test("constructs correct URL shape for 'ja'", async () => { const config = makeConfig("https://api.example.com/"); await getPageMarkdown("Tokyo", config, "ja"); - expect(capturedUrl).toBe( - "https://api.example.com/ja/page/Tokyo", - ); + expect(capturedUrl).toBe("https://api.example.com/ja/page/Tokyo"); }); }); From 0d15045ba2041d8d8eaa4ae5e5238547988f0326 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 21 Apr 2026 17:03:38 +0000 Subject: [PATCH 5/5] fix: address review comments - URL encoding, merge conflict, XSS, ENOENT, parallel translation, URL protocol validation Agent-Logs-Url: https://github.com/microsoft/TypeAgent/sessions/5828fefd-5097-4099-aa84-2f64fcd73f4e Co-authored-by: robgruen <25374553+robgruen@users.noreply.github.com> --- TODO.md | 7 ++----- ts/packages/azure-ai-foundry/src/wikipedia.ts | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index e41eb4e5a5..028bb9c1b1 100644 --- a/TODO.md +++ b/TODO.md @@ -168,11 +168,8 @@ This file collates all TODO comments found across the repository, organized by t | `ts/packages/azure-ai-foundry/src/urlResolverCache.ts` | 121 | make async | Low | High | Local | Fix | No | | `ts/packages/azure-ai-foundry/src/websiteAliasExtraction.ts` | 65 | IMPLEMENT | High | Low | Component | Fix | Yes | | `ts/packages/azure-ai-foundry/src/websiteAliasExtraction.ts` | 121 | handle multi-modal content | High | Medium | Component | Fix | No | -<<<<<<< Updated upstream -======= -| ~~`ts/packages/azure-ai-foundry/src/wikipedia.ts`~~ | ~~102~~ | ~~localization (e.g. en, de, fr, etc.)~~ | Low | High | Local | ✅ Fixed | No | -| ~~`ts/packages/azure-ai-foundry/src/wikipedia.ts`~~ | ~~125~~ | ~~localization (e.g. en, de, fr, etc.)~~ | Low | High | Local | ✅ Fixed | No | ->>>>>>> Stashed changes +| `ts/packages/azure-ai-foundry/src/wikipedia.ts` | 102 | localization (e.g. en, de, fr, etc.) | Low | High | Local | Fix | No | +| `ts/packages/azure-ai-foundry/src/wikipedia.ts` | 125 | localization (e.g. en, de, fr, etc.) | Low | High | Local | Fix | No | | `ts/packages/cache/src/cache/cache.ts` | 599 | Move this in the construction store | Medium | Medium | Component | Fix | Yes | | `ts/packages/cache/src/cache/explainWorkQueue.ts` | 42 | check number too. | Low | High | Local | Fix | No | | `ts/packages/cache/src/constructions/constructionCache.ts` | 420 | GC match sets | Medium | Medium | Component | Fix | No | diff --git a/ts/packages/azure-ai-foundry/src/wikipedia.ts b/ts/packages/azure-ai-foundry/src/wikipedia.ts index 5b30856e1a..184cf63135 100644 --- a/ts/packages/azure-ai-foundry/src/wikipedia.ts +++ b/ts/packages/azure-ai-foundry/src/wikipedia.ts @@ -102,7 +102,7 @@ export async function getPageObject( locale: string = "en", ) { const response = await fetch( - `${config.endpoint}core/v1/wikipedia/${locale}/page/${title}/bare`, + `${config.endpoint}core/v1/wikipedia/${locale}/page/${encodeWikipediaTitle(title)}/bare`, { method: "GET", headers: await config.getAPIHeaders() }, );