Add test for npm-registry-utils HTTP proxy support (Node.js 24+)#9902
Add test for npm-registry-utils HTTP proxy support (Node.js 24+)#9902
Conversation
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
| } | ||
|
|
||
| const registry = `https://registry.npmjs.org`; | ||
| const registry = process.env.TYPESPEC_NPM_REGISTRY_URL ?? `https://registry.npmjs.org`; |
There was a problem hiding this comment.
@copilot revert the change to a custom url, there is a separate PR taking care of that.
There was a problem hiding this comment.
Reverted in 63e6f85. The test now uses the real npm registry (HTTPS) through the proxy instead of a local mock registry.
| - "@typespec/compiler" | ||
| --- | ||
|
|
||
| Add e2e test to verify `fetchPackageManifest` from `npm-registry-utils` works through an HTTP proxy using Node.js 24's `--use-env-proxy` flag. |
There was a problem hiding this comment.
@copilot Is --use-env-proxy flag necessary? Local testing showed it worked without?
There was a problem hiding this comment.
Confirmed necessary in Node.js 24.13.1 — without --use-env-proxy, the HTTPS_PROXY env var is not respected by Node's native fetch and the proxy is bypassed. The flag is kept in 63e6f85.
…se real registry Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
commit: |
|
No changes needing a change description found. |
| tmpDir = await mkdtemp(join(tmpdir(), "typespec-proxy-test-")); | ||
|
|
||
| // Create a simple HTTP proxy that handles HTTPS CONNECT tunneling | ||
| proxyServer = createServer(); |
There was a problem hiding this comment.
@copilot the test doesn't seem to be testing proxy correctly. The test opassed on node 22 when it shouldn't have
There was a problem hiding this comment.
Fixed in 6475205. The root issue: the test was using the real npm registry (HTTPS), so the fetch succeeded even without going through the proxy — the proxy check was vacuous when the real registry was reachable directly.
The new approach uses a non-existent hostname (nonexistent-npm-registry.invalid) so the fetch can only succeed when routed through the proxy. The proxy's CONNECT handler intercepts the connection and tunnels it to a local mock npm registry (no internet). Without --use-env-proxy, the DNS lookup fails → exit code 1 → test fails. With --use-env-proxy + HTTP_PROXY, the proxy is used → mock manifest returned → test passes.
…st fails without proxy Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
| stderr: string; | ||
| } | ||
|
|
||
| function execAsync(command: string, args: string[], env: NodeJS.ProcessEnv): Promise<ExecResult> { |
There was a problem hiding this comment.
@copilot can this be done without being an e2e test?, the problem is we only run e2e test on the latest node
There was a problem hiding this comment.
Moved to test/package-manager/npm-registry-utils.test.ts in 7a5995a — it's now a regular test (.test.ts) that runs with pnpm test on all Node versions, not just the latest.
… Node versions Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
|
@copilot fix merge conflict with main branch |
…support Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
|
@copilot the conflict is still there, make sure this branch can be merged into main without any issues |
…ts in single file Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
The merge conflict is a git "add/add" conflict — both this branch and main independently added Our branch's version of the file (faabc79) already contains both test suites combined (3 tests pass). When resolving the merge conflict, the correct action is to accept our version of the file, which already includes both:
If you'd like me to try a different approach, please let me know — or if you can rebase this branch onto main and push, that would resolve the conflict cleanly. |
|
@copilot it is still not fixed... github reports run git pull origin main and fix the conflict.... |
…t.ts Both branches independently added the same test file. Our version already contains both test suites (proxy tests + TYPESPEC_NPM_REGISTRY tests), so we keep it and bring in all other changes from main. Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Co-authored-by: timotheeguerin <1031227+timotheeguerin@users.noreply.github.com>
Fixed in |
TYPESPEC_NPM_REGISTRY_URLenv var change innpm-registry-utils.tstest/package-manager/npm-registry-utils.test.ts)getNpmRegistry()function andTYPESPEC_NPM_REGISTRYenv var support from PR fix: Allow setting custom registry for tsp install #9803TYPESPEC_NPM_REGISTRYtests (from main's PR fix: Allow setting custom registry for tsp install #9803) with proxy tests into single test file to resolve add/add merge conflict6ca470a(main) as second parent — branch is mergeable into main without conflictsOriginal prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.