PDX-463: feat(mcp): fetch NitroX component packages from factPackages repo at release time#156
Conversation
… repo at release time RCA: NitroX component packages were statically bundled in the repo and not updated automatically; the source of truth is the ProvarTesting/factPackages GitHub repo (main branch), so packages would silently drift stale between releases. Fix: Added scripts/fetch-nitrox-packages.cjs to the prepack hook; it downloads all component package files from factPackages@main, regenerates NITROX_COMPONENT_CATALOG.md, and writes NITROX_CATALOG_SOURCE.json with the commit SHA. On failure (no token, network error) it logs a warning and falls back to the committed catalog — the release is never blocked. A new provar://nitrox/catalog-source MCP resource exposes the bundled version so consumers can verify which factPackages commit is in use.
Quality Orchestrator🟢 LOW · 🧪 Tests to Run · Running 2 of 42 tests
▶ Run commandnpx vitest run \
unit/mcp/server.test.ts \
unit/mcp/updateChecker.test.ts⚡ quality-orchestrator · |
There was a problem hiding this comment.
Pull request overview
This PR adds a release-time mechanism to refresh the bundled NitroX component catalog from ProvarTesting/factPackages, records the source commit metadata, and exposes that metadata via a new MCP resource so consumers can verify which catalog version is bundled.
Changes:
- Add
scripts/fetch-nitrox-packages.cjsand run it duringprepackto fetch component package files and regeneratedocs/NITROX_COMPONENT_CATALOG.md. - Add
docs/NITROX_CATALOG_SOURCE.json+readCatalogSource()and expose it as a new MCP resourceprovar://nitrox/catalog-source. - Update build copying/tests/docs to include and validate the new catalog source metadata.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
scripts/fetch-nitrox-packages.cjs |
New prepack-time fetch + catalog regeneration script and source metadata writer. |
package.json |
Runs the fetch script in prepack and includes the source JSON in compile outputs. |
src/mcp/server.ts |
Adds provar://nitrox/catalog-source resource and readCatalogSource() helper. |
test/unit/mcp/server.test.ts |
Adds unit coverage for readCatalogSource() fallback/parse behavior. |
docs/NITROX_CATALOG_SOURCE.json |
Adds default committed source metadata (null SHA/timestamp). |
docs/mcp.md |
Documents auto-refresh behavior and the new MCP resource. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| async function downloadRaw(filePath, token) { | ||
| const url = `https://raw.githubusercontent.com/${REPO_OWNER}/${REPO_NAME}/${BRANCH}/${filePath}`; |
| function httpsGet(url, headers) { | ||
| return new Promise((resolve, reject) => { | ||
| const parsed = new URL(url); | ||
| const reqHeaders = { | ||
| 'User-Agent': 'provardx-cli/fetch-nitrox-packages', | ||
| Accept: 'application/json', | ||
| ...headers, | ||
| }; | ||
| const req = https.get( | ||
| { hostname: parsed.hostname, path: parsed.pathname + parsed.search, headers: reqHeaders }, |
| function httpsGetBuffer(url, headers) { | ||
| return new Promise((resolve, reject) => { | ||
| const parsed = new URL(url); | ||
| const req = https.get({ hostname: parsed.hostname, path: parsed.pathname + parsed.search, headers }, (res) => { | ||
| if (res.statusCode === 301 || res.statusCode === 302) { | ||
| resolve(httpsGetBuffer(res.headers.location, headers)); | ||
| return; | ||
| } | ||
| const chunks = []; | ||
| res.on('data', (chunk) => chunks.push(chunk)); |
…ings RCA: The factPackages repo stores component files under fact-*/src/components/ not fact-*/components/, so the path-matching regexes and catalog builder needed updating; additionally nine pre-existing unicorn/numeric-separators-style lint warnings in updateChecker.ts and its test file were left unaddressed. Fix: Updated PKG_JSON_RE and COMPONENT_FILE_RE in fetch-nitrox-packages.cjs to match the fact-*/src/ layout and adjusted buildCatalogFromDir to navigate the src/ subdirectory; ran eslint --fix on updateChecker.ts and updateChecker.test.ts to resolve all numeric-separator warnings, leaving the project at 0 lint errors and 0 warnings.
RCA: downloadRaw() used the branch name (main) in the raw URL rather than the resolved commit SHA, so files could be fetched from a different commit than the one the tree listing described; additionally both httpsGet and httpsGetBuffer had no timeout, meaning a stalled network connection would block prepack indefinitely. Fix: Added REQUEST_TIMEOUT_MS (15s) to both http helpers via req.setTimeout/req.destroy so hangs fail fast and fall through to the graceful fallback; updated downloadRaw to accept and use the commitSha parameter so all downloads are pinned to the same commit as the tree.
|
Addressed all three Copilot review comments in commit 019bb87:
|
Summary
scripts/fetch-nitrox-packages.cjsto theprepackhook: fetches all component package files fromProvarTesting/factPackages@main, regeneratesNITROX_COMPONENT_CATALOG.md, and writesNITROX_CATALOG_SOURCE.jsonwith the commit SHAGITHUB_TOKEN/GH_TOKENis set or the fetch fails; logs a warning and always exits 0 (release never blocked)provar://nitrox/catalog-sourceMCP resource (served fromNITROX_CATALOG_SOURCE.json) so consumers can verify whichfactPackagescommit is bundleddocs/NITROX_CATALOG_SOURCE.jsoncommitted as a default (null SHA) that gets overwritten on each successful release builddocs/mcp.mdupdated to document the auto-refresh mechanism and the new resourceJira
https://provartesting.atlassian.net/browse/PDX-463
Test plan
yarn compilepassesyarn test:onlypasses (941 tests, +3 newreadCatalogSourcetests)node scripts/mcp-smoke.cjspasses (54/54)yarn lintpasses (0 errors)Changes
scripts/fetch-nitrox-packages.cjs: new release-time fetch scriptdocs/NITROX_CATALOG_SOURCE.json: new default version file (null SHA)package.json:prepacknow runs fetch beforesf-prepack; compile copies source JSON tolib/mcp/docs/src/mcp/server.ts: addsprovar://nitrox/catalog-sourceresource + exportsreadCatalogSourcehelpertest/unit/mcp/server.test.ts: 3 new unit tests forreadCatalogSourcedocs/mcp.md: updatedprovar://nitrox/component-catalogsection; addedprovar://nitrox/catalog-sourceentry