gentle-pi 4.6.0 → 4.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -11
- package/assets/agents/gentle-ai-explore.md +1 -0
- package/assets/agents/gentle-ai-verify.md +5 -2
- package/assets/agents/gentle-ai-worker.md +3 -0
- package/assets/agents/jd-fix-agent.md +1 -0
- package/assets/agents/jd-judge-a.md +1 -0
- package/assets/agents/jd-judge-b.md +1 -0
- package/assets/design-canvas/canvas.css +13 -1
- package/assets/design-canvas/canvas.js +11 -2
- package/assets/install-wizard/wizard.js +1 -0
- package/assets/migrations/agent-body-history.json +16 -1
- package/assets/orchestrator-delegation-reference.md +4 -4
- package/assets/orchestrator-delegation.md +1 -1
- package/assets/orchestrator-full-delegation-card.md +65 -0
- package/assets/orchestrator-full-delegation.md +34 -0
- package/assets/orchestrator-memory.md +3 -3
- package/assets/orchestrator-prompts.md +1 -1
- package/assets/orchestrator-skills.md +1 -1
- package/assets/orchestrator-verification.md +7 -5
- package/assets/orchestrator.md +3 -3
- package/bin/gentle-shell.mjs +164 -56
- package/docs/agent-status.md +61 -0
- package/docs/bundled-install.md +7 -5
- package/docs/delegated-verification.md +29 -7
- package/docs/gentle-agents-activity.md +14 -0
- package/docs/gentle-shell.md +54 -16
- package/docs/install-wizard.md +1 -1
- package/docs/permission-modes.md +9 -4
- package/docs/readme-reference.md +75 -30
- package/docs/render-cache-performance.md +11 -1
- package/docs/review-coordinator.md +33 -0
- package/docs/review-request-context.md +19 -0
- package/docs/review-windows-acl.md +18 -0
- package/docs/voice.md +6 -3
- package/docs/yolo-mode.md +5 -5
- package/extensions/ask-user-choice.ts +1 -0
- package/extensions/ask-user-question.ts +1 -0
- package/extensions/child-safety.ts +3 -0
- package/extensions/gentle-agent-status.ts +99 -0
- package/extensions/gentle-agents.ts +326 -34
- package/extensions/gentle-ai.ts +1496 -454
- package/extensions/gentle-shell.ts +293 -63
- package/extensions/gentle-todo.ts +18 -2
- package/extensions/gentle-tps.ts +48 -0
- package/extensions/quiet-tools.ts +38 -8
- package/extensions/skill-registry.ts +175 -18
- package/extensions/startup-banner.ts +30 -3
- package/lib/agent-profile-pin.ts +3 -3
- package/lib/agent-profiles.ts +160 -2
- package/lib/agent-status.ts +105 -0
- package/lib/agents-config.ts +46 -0
- package/lib/agents-history.ts +24 -5
- package/lib/agents-messaging.ts +47 -5
- package/lib/agents-runner.ts +183 -12
- package/lib/auto-permission-runtime.ts +1 -1
- package/lib/bounded-writer-admission.ts +13 -1
- package/lib/card-content-policy.ts +8 -6
- package/lib/command-palette.ts +133 -17
- package/lib/context-backstop.ts +14 -5
- package/lib/destructive-command-guard.ts +48 -4
- package/lib/execution-surface-guard.ts +20 -0
- package/lib/exploration-budget.ts +4 -2
- package/lib/gentle-ai-binary.ts +1 -1
- package/lib/gentle-design.ts +3 -0
- package/lib/gentle-shell-bundled.ts +6 -19
- package/lib/gentle-shell-launcher.ts +43 -8
- package/lib/herdr-activity.ts +14 -2
- package/lib/herdr-busy.ts +45 -0
- package/lib/image-attachments.ts +33 -0
- package/lib/image-disk-cache.ts +137 -0
- package/lib/inprocess-reviewer.ts +270 -140
- package/lib/jobs-view.ts +198 -11
- package/lib/model-routing-authority.ts +22 -4
- package/lib/native-choice-list.ts +20 -2
- package/lib/native-review-cli.ts +96 -19
- package/lib/orchestrator-mode-policy.ts +105 -0
- package/lib/questionnaire/questionnaire-view.ts +105 -12
- package/lib/rdd-mode-control.ts +32 -0
- package/lib/reply-language-anchor.ts +104 -0
- package/lib/review-blocker.ts +92 -0
- package/lib/review-candidate-symlink-scan.ts +136 -0
- package/lib/review-candidate-view-owner.ts +81 -44
- package/lib/review-continuation-registry.ts +99 -0
- package/lib/review-coordinator.ts +163 -0
- package/lib/review-failure-facts.ts +49 -0
- package/lib/review-host-relay.ts +46 -10
- package/lib/review-integration-v2.ts +7 -1
- package/lib/review-relay-phase-timing.ts +45 -0
- package/lib/review-start-context.ts +17 -0
- package/lib/session-profile-freeze.ts +4 -2
- package/lib/shell-bar.ts +140 -58
- package/lib/shell-changes.ts +2 -0
- package/lib/shell-panel.ts +17 -3
- package/lib/shell-sidebar-layout.ts +112 -40
- package/lib/shell-sidebar.ts +7 -0
- package/lib/shell-todo.ts +10 -3
- package/lib/verifier-admission.ts +1 -1
- package/lib/visual-customization-policy.ts +36 -16
- package/lib/visual-customize-view.ts +216 -21
- package/lib/visual-layout-preview.ts +9 -5
- package/lib/visual-profiles.ts +2 -2
- package/lib/windows-session-transport.ts +53 -2
- package/lib/yolo-session-policy.ts +40 -15
- package/package.json +2 -1
- package/runtime/gentle-ai-binary.mjs +1 -1
- package/runtime/gentle-shell-bundled.mjs +6 -19
- package/runtime/gentle-shell-launcher.mjs +42 -7
- package/runtime/native-review-cli.mjs +93 -16
- package/runtime/review-integration-v2.mjs +7 -1
- package/scripts/build-full-delegation-card.mjs +175 -0
- package/scripts/bundled-install.mjs +38 -8
- package/scripts/download-progress.mjs +68 -0
- package/scripts/gentle-ai-installer.mjs +41 -18
- package/scripts/gentle-ai-proxy.mjs +294 -0
- package/scripts/install-gentle-ai.mjs +14 -1
- package/scripts/installer-preflight.mjs +5 -5
- package/scripts/installer-runner.mjs +27 -12
- package/scripts/installer-server.mjs +8 -7
- package/scripts/render-cache-host.mjs +72 -0
- package/scripts/render-cache-performance-worker.mjs +5 -4
- package/scripts/render-cache-performance.mjs +6 -1
- package/scripts/run-test-suite.mjs +40 -28
- package/scripts/verify-package-files.mjs +12 -2
- package/scripts/voice-worker.cjs +32 -6
- package/skills/design/SKILL.md +11 -8
- package/skills/gentle-ai/SKILL.md +2 -2
- package/skills/gentle-ui-design/SKILL.md +46 -0
- package/skills/gentle-ui-design/references/adaptive-interfaces.md +46 -0
- package/skills/gentle-ui-design/references/browse-and-compare.md +62 -0
- package/skills/gentle-ui-design/references/composition-and-feedback.md +56 -0
- package/skills/gentle-ui-design/references/task-and-content.md +60 -0
- package/skills/skill-registry/SKILL.md +4 -2
- package/skills/work-unit-commits/SKILL.md +6 -7
- package/tests/agent-home.test.ts +28 -9
- package/tests/agent-profiles-workflow.test.ts +163 -0
- package/tests/agent-risk-escalation.test.ts +1 -1
- package/tests/agent-status.test.ts +143 -0
- package/tests/agents-config.test.ts +96 -0
- package/tests/agents-history.test.ts +31 -0
- package/tests/agents-jobs-frames.test.ts +93 -0
- package/tests/agents-prompt-lifecycle-runtime.test.ts +376 -0
- package/tests/agents-runner-drain.test.ts +193 -0
- package/tests/agents-runner.test.ts +178 -2
- package/tests/append-system-prompt-route.test.ts +4 -1
- package/tests/ask-user-choice.test.ts +4 -3
- package/tests/ask-user-question.test.ts +97 -0
- package/tests/auto-permission-runtime.test.ts +1 -1
- package/tests/autonomous-guard.test.ts +346 -10
- package/tests/bounded-stop-contract.test.ts +43 -3
- package/tests/bridge-cost.test.ts +19 -4
- package/tests/bundled-install.test.ts +30 -5
- package/tests/card-content-policy.test.ts +3 -3
- package/tests/chained-pr-skill.test.ts +8 -6
- package/tests/child-safety.test.ts +11 -0
- package/tests/codegraph-tools.test.ts +11 -5
- package/tests/command-palette.test.ts +284 -1
- package/tests/delegate-for-reason-contract.test.ts +3 -3
- package/tests/design-canvas-assets.test.ts +185 -2
- package/tests/destructive-command-guard.test.ts +52 -0
- package/tests/download-progress.test.ts +71 -0
- package/tests/execution-surface-guard.test.ts +55 -0
- package/tests/fixtures/primary-session-prompt/gentleman.golden.md +9 -5
- package/tests/fixtures/proxy-tls/proxy.crt +19 -0
- package/tests/fixtures/proxy-tls/proxy.key +28 -0
- package/tests/fixtures/session-profile-v1/gentle-ai-reviewer.ts +89 -0
- package/tests/fixtures/session-profile-v1/replay.ts +53 -6
- package/tests/full-delegation-closure.test.ts +131 -0
- package/tests/full-delegation-notices.test.ts +76 -0
- package/tests/generic-agent-tools.test.ts +3 -3
- package/tests/gentle-agent-status.test.ts +74 -0
- package/tests/gentle-agents-child-jobs.test.ts +237 -0
- package/tests/gentle-agents.test.ts +1070 -12
- package/tests/gentle-ai-binary.test.ts +3 -1
- package/tests/gentle-ai-elapsed-store.test.ts +19 -0
- package/tests/gentle-ai-exploration-budget.test.ts +18 -2
- package/tests/gentle-ai-installer.test.ts +134 -51
- package/tests/gentle-ai-proxy.test.ts +434 -0
- package/tests/gentle-ai.test.ts +113 -38
- package/tests/gentle-design.test.ts +21 -0
- package/tests/gentle-herdr-activity.test.ts +9 -6
- package/tests/gentle-shell-bin.test.ts +123 -0
- package/tests/gentle-shell-bundled.test.ts +207 -31
- package/tests/gentle-shell-launcher.test.ts +77 -10
- package/tests/gentle-shell.test.ts +899 -59
- package/tests/gentle-todo.test.ts +19 -2
- package/tests/gentle-tps.test.ts +123 -0
- package/tests/gentle-ui-design-skill.test.ts +59 -0
- package/tests/herdr-busy.test.ts +59 -0
- package/tests/herdr-task-summary-policy.test.ts +8 -4
- package/tests/image-disk-cache.test.ts +163 -0
- package/tests/independent-recovery-delivery.test.ts +83 -0
- package/tests/inprocess-reviewer.test.ts +176 -4
- package/tests/installer-posix-bootstrap.test.ts +1 -1
- package/tests/installer-preflight.test.ts +5 -4
- package/tests/installer-runner.test.ts +79 -44
- package/tests/installer-server.test.ts +14 -11
- package/tests/jobs-view.test.ts +260 -6
- package/tests/modal-mouse-boundaries.test.ts +136 -0
- package/tests/model-routing-authority.test.ts +178 -2
- package/tests/native-choice-list.test.ts +77 -2
- package/tests/native-review-capability-contract.test.ts +7 -1
- package/tests/native-review-cli.test.ts +269 -1
- package/tests/no-self-pause-contract.test.ts +4 -1
- package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
- package/tests/orchestrator-budget.test.ts +7 -2
- package/tests/orchestrator-delegation-mode.test.ts +153 -0
- package/tests/orchestrator-mode-policy.test.ts +175 -0
- package/tests/orchestrator-prompt-budget.test.ts +3 -1
- package/tests/orchestrator-rdd-ownership.test.ts +2 -2
- package/tests/package-manifest.test.ts +11 -9
- package/tests/permission-allowlist.test.ts +202 -0
- package/tests/pi-update-launcher.test.ts +8 -0
- package/tests/pnpm-workspace-config.test.ts +58 -0
- package/tests/primary-session-prompt.test.ts +13 -0
- package/tests/profile-pin.test.ts +29 -2
- package/tests/profile-tier-footer.test.ts +5 -0
- package/tests/profiles-panel-delegation-mode.test.ts +422 -0
- package/tests/questionnaire-view.test.ts +115 -0
- package/tests/quiet-bash-runtime.test.ts +1 -1
- package/tests/quiet-tool-rendering.test.ts +48 -0
- package/tests/rdd-aware-verification-contract.test.ts +16 -11
- package/tests/rdd-customize.test.ts +287 -0
- package/tests/rdd-mode-cache.test.ts +450 -0
- package/tests/rdd-mode-control.test.ts +407 -0
- package/tests/rdd-mode-scope-regression.test.ts +137 -0
- package/tests/rdd-off-independent-regression.test.ts +69 -0
- package/tests/rdd-status-line.test.ts +18 -0
- package/tests/render-cache-performance.test.ts +171 -2
- package/tests/reply-language-anchor.test.ts +173 -0
- package/tests/review-agent-end-preflight.test.ts +1 -1
- package/tests/review-blocker.test.ts +193 -0
- package/tests/review-candidate-owner-retry.test.ts +1 -1
- package/tests/review-candidate-symlink-scan.test.ts +157 -0
- package/tests/review-candidate-view.test.ts +1 -1
- package/tests/review-candidate-windows-boundary.test.ts +131 -0
- package/tests/review-candidate-windows-probe.test.ts +63 -0
- package/tests/review-committed-restart-ack.test.ts +129 -0
- package/tests/review-continuation-registry.test.ts +76 -0
- package/tests/review-controller-native-routing.test.ts +261 -5
- package/tests/review-controller-workspace-root.test.ts +230 -3
- package/tests/review-controller.test.ts +96 -11
- package/tests/review-coordinator-runtime.test.ts +117 -0
- package/tests/review-coordinator.test.ts +195 -0
- package/tests/review-failure-facts.test.ts +87 -0
- package/tests/review-host-relay-routing.test.ts +258 -4
- package/tests/review-host-relay.test.ts +39 -0
- package/tests/review-integration-v2.test.ts +46 -3
- package/tests/review-json-arguments.test.ts +65 -10
- package/tests/review-last-event-closure.test.ts +68 -0
- package/tests/review-loadout-rdd-off-sdk.test.ts +65 -31
- package/tests/review-owner-identity.test.ts +60 -24
- package/tests/review-relay-phase-timing.test.ts +128 -0
- package/tests/review-relay-transport-agent.test.ts +12 -2
- package/tests/review-reviewer-evidence.test.ts +183 -0
- package/tests/review-risk-assessment.test.ts +74 -3
- package/tests/review-session-standing-permission-controller.test.ts +21 -1
- package/tests/review-start-context.test.ts +19 -0
- package/tests/review-tool-prose-budget.test.ts +121 -0
- package/tests/run-test-suite.test.ts +122 -1
- package/tests/runtime-harness.mjs +4 -1
- package/tests/sensitive-path-tools.test.ts +181 -5
- package/tests/session-profile-append-controller-pi.test.ts +60 -31
- package/tests/session-profile-binding.test.ts +19 -1
- package/tests/session-profile-disk-reader-pi.test.ts +58 -16
- package/tests/session-profile-v1-compat.test.ts +35 -1
- package/tests/shell-bar.test.ts +186 -42
- package/tests/shell-panel.test.ts +50 -22
- package/tests/shell-sidebar-fullscreen.test.ts +5 -5
- package/tests/shell-sidebar-layout.test.ts +294 -23
- package/tests/shell-sidebar-scroll-benchmark.test.ts +1 -1
- package/tests/shell-surface-transparent.test.ts +89 -0
- package/tests/shell-todo.test.ts +12 -0
- package/tests/skill-registry.test.ts +838 -5
- package/tests/startup-banner.test.ts +152 -1
- package/tests/startup-home-repo.test.ts +2 -0
- package/tests/support/review-coordinator-runtime.ts +69 -0
- package/tests/task-size-routing-contract.test.ts +5 -3
- package/tests/verifier-admission.test.ts +49 -0
- package/tests/verify-first-launch-contract.test.ts +78 -3
- package/tests/visual-customization-policy.test.ts +39 -6
- package/tests/visual-customize-view.test.ts +573 -9
- package/tests/visual-layout-preview.test.ts +15 -1
- package/tests/visual-profiles.test.ts +11 -0
- package/tests/voice-worker.test.ts +73 -2
- package/tests/windows-session-transport.test.ts +126 -0
- package/tests/work-continuity-contract.test.ts +28 -0
- package/tests/writer-feature-document-admission.test.ts +92 -0
- package/tests/yolo-customize.test.ts +27 -4
- package/tests/yolo-mode.test.ts +23 -18
- package/tests/yolo-session-policy.test.ts +270 -1
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { EventEmitter } from "node:events";
|
|
3
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { createServer, connect, type Socket } from "node:net";
|
|
6
|
+
import { tmpdir } from "node:os";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import { PassThrough } from "node:stream";
|
|
9
|
+
import test from "node:test";
|
|
10
|
+
import { createServer as createTlsServer } from "node:tls";
|
|
11
|
+
import { downloadGentleAiAsset } from "../scripts/gentle-ai-installer.mjs";
|
|
12
|
+
import { proxyTlsOptions, resolveProxyForTarget } from "../scripts/gentle-ai-proxy.mjs";
|
|
13
|
+
|
|
14
|
+
const TARGET = "https://release-assets.example.invalid/asset.tar.gz";
|
|
15
|
+
|
|
16
|
+
// A certificate that covers DNS:proxy.test, IP:127.0.0.1 and IP:::1, so the
|
|
17
|
+
// tunnel can be exercised against a real TLS proxy without a network.
|
|
18
|
+
const PROXY_CERT = readFileSync(new URL("./fixtures/proxy-tls/proxy.crt", import.meta.url));
|
|
19
|
+
const PROXY_KEY = readFileSync(new URL("./fixtures/proxy-tls/proxy.key", import.meta.url));
|
|
20
|
+
|
|
21
|
+
function pendingRequest() {
|
|
22
|
+
const pending = new EventEmitter() as EventEmitter & { destroy(error?: Error): void; setTimeout(): void };
|
|
23
|
+
pending.destroy = (error) => queueMicrotask(() => pending.emit("error", error));
|
|
24
|
+
pending.setTimeout = () => undefined;
|
|
25
|
+
return pending;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// A proxy that answers CONNECT with the given status and records the request
|
|
29
|
+
// head it received. A string sends an incomplete response before closing;
|
|
30
|
+
// null leaves the connection silent. No TLS origin is needed.
|
|
31
|
+
async function startProxyStub(status: number | string | null) {
|
|
32
|
+
const sockets: Socket[] = [];
|
|
33
|
+
const closed: Promise<void>[] = [];
|
|
34
|
+
let head = "";
|
|
35
|
+
let first: Buffer = Buffer.alloc(0);
|
|
36
|
+
const server = createServer((socket) => {
|
|
37
|
+
sockets.push(socket);
|
|
38
|
+
closed.push(new Promise((resolve) => socket.once("close", () => resolve())));
|
|
39
|
+
socket.on("data", (chunk) => {
|
|
40
|
+
if (first.length === 0) first = chunk;
|
|
41
|
+
if (head === "") head += chunk.toString("latin1");
|
|
42
|
+
});
|
|
43
|
+
if (status === null) return;
|
|
44
|
+
socket.write(typeof status === "string" ? status : `HTTP/1.1 ${status} ${status === 200 ? "Connection Established" : "Proxy Authentication Required"}\r\n\r\n`);
|
|
45
|
+
if (status !== 200) socket.end();
|
|
46
|
+
});
|
|
47
|
+
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
48
|
+
const address = server.address();
|
|
49
|
+
const port = typeof address === "object" && address !== null ? address.port : 0;
|
|
50
|
+
return {
|
|
51
|
+
port,
|
|
52
|
+
connections: () => sockets.length,
|
|
53
|
+
waitForClose: () => Promise.all(closed),
|
|
54
|
+
head: () => head,
|
|
55
|
+
firstBytes: () => first,
|
|
56
|
+
close: async () => {
|
|
57
|
+
for (const socket of sockets) socket.destroy();
|
|
58
|
+
await new Promise<void>((resolve) => server.close(() => resolve()));
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// A proxy that records what it is sent and then hangs up, so a channel that
|
|
64
|
+
// expects a TLS handshake can be observed before anything replies.
|
|
65
|
+
async function startSilentProxy() {
|
|
66
|
+
const sockets: Socket[] = [];
|
|
67
|
+
let first: Buffer = Buffer.alloc(0);
|
|
68
|
+
const server = createServer((socket) => {
|
|
69
|
+
sockets.push(socket);
|
|
70
|
+
socket.on("data", (chunk) => {
|
|
71
|
+
if (first.length === 0) first = chunk;
|
|
72
|
+
socket.destroy();
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
76
|
+
const address = server.address();
|
|
77
|
+
const port = typeof address === "object" && address !== null ? address.port : 0;
|
|
78
|
+
return {
|
|
79
|
+
port,
|
|
80
|
+
firstBytes: () => first,
|
|
81
|
+
close: async () => {
|
|
82
|
+
for (const socket of sockets) socket.destroy();
|
|
83
|
+
await new Promise<void>((resolve) => server.close(() => resolve()));
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// A proxy that speaks TLS with the fixture certificate and answers CONNECT
|
|
89
|
+
// with the given status. The handshake it observes and the CONNECT head it
|
|
90
|
+
// receives are both recorded.
|
|
91
|
+
async function startTlsProxyStub(status: number) {
|
|
92
|
+
const sockets: Socket[] = [];
|
|
93
|
+
let head = "";
|
|
94
|
+
let servername: string | false | undefined;
|
|
95
|
+
const server = createTlsServer({ cert: PROXY_CERT, key: PROXY_KEY }, (socket) => {
|
|
96
|
+
sockets.push(socket);
|
|
97
|
+
socket.on("error", () => {});
|
|
98
|
+
socket.on("data", (chunk) => {
|
|
99
|
+
if (head === "") head += chunk.toString("latin1");
|
|
100
|
+
socket.write(`HTTP/1.1 ${status} ${status === 200 ? "Connection Established" : "Proxy Authentication Required"}\r\n\r\n`);
|
|
101
|
+
if (status !== 200) socket.end();
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
server.on("secureConnection", (socket) => { servername = socket.servername; });
|
|
105
|
+
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
106
|
+
const address = server.address();
|
|
107
|
+
const port = typeof address === "object" && address !== null ? address.port : 0;
|
|
108
|
+
return {
|
|
109
|
+
port,
|
|
110
|
+
head: () => head,
|
|
111
|
+
servername: () => servername,
|
|
112
|
+
close: async () => {
|
|
113
|
+
for (const socket of sockets) socket.destroy();
|
|
114
|
+
await new Promise<void>((resolve) => server.close(() => resolve()));
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
test("the proxy is read from the environment the way every other HTTP client reads it", () => {
|
|
120
|
+
assert.equal(resolveProxyForTarget(TARGET, {}), undefined);
|
|
121
|
+
assert.equal(resolveProxyForTarget(TARGET, { HTTPS_PROXY: "http://proxy.invalid:3128" })?.href, "http://proxy.invalid:3128/");
|
|
122
|
+
assert.equal(resolveProxyForTarget(TARGET, { https_proxy: "http://proxy.invalid:3128" })?.href, "http://proxy.invalid:3128/");
|
|
123
|
+
// HTTP_PROXY is the fallback for an https target, and the only answer for an http one.
|
|
124
|
+
assert.equal(resolveProxyForTarget(TARGET, { HTTP_PROXY: "http://proxy.invalid:3128" })?.href, "http://proxy.invalid:3128/");
|
|
125
|
+
assert.equal(resolveProxyForTarget("http://example.invalid/asset", { HTTP_PROXY: "http://proxy.invalid:3128" })?.href, "http://proxy.invalid:3128/");
|
|
126
|
+
// HTTPS_PROXY wins over HTTP_PROXY for an https target.
|
|
127
|
+
assert.equal(resolveProxyForTarget(TARGET, { HTTPS_PROXY: "http://secure.invalid:3128", HTTP_PROXY: "http://plain.invalid:3128" })?.href, "http://secure.invalid:3128/");
|
|
128
|
+
// A value without a scheme is a host:port pair, not a URL with a strange scheme.
|
|
129
|
+
assert.equal(resolveProxyForTarget(TARGET, { HTTPS_PROXY: "proxy.invalid:3128" })?.href, "http://proxy.invalid:3128/");
|
|
130
|
+
// Credentials survive, because a proxy that needs them is a normal proxy.
|
|
131
|
+
assert.equal(resolveProxyForTarget(TARGET, { HTTPS_PROXY: "http://user:pass@proxy.invalid:3128" })?.username, "user");
|
|
132
|
+
// An unusable value is ignored rather than allowed to break a direct install.
|
|
133
|
+
assert.equal(resolveProxyForTarget(TARGET, { HTTPS_PROXY: "socks5://proxy.invalid:1080" }), undefined);
|
|
134
|
+
assert.equal(resolveProxyForTarget(TARGET, { HTTPS_PROXY: " " }), undefined);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
test("NO_PROXY keeps the listed hosts off the proxy", () => {
|
|
138
|
+
const proxy = { HTTPS_PROXY: "http://proxy.invalid:3128" };
|
|
139
|
+
assert.equal(resolveProxyForTarget(TARGET, { ...proxy, NO_PROXY: "release-assets.example.invalid" }), undefined);
|
|
140
|
+
assert.equal(resolveProxyForTarget(TARGET, { ...proxy, no_proxy: "release-assets.example.invalid" }), undefined);
|
|
141
|
+
// A leading dot covers the domain and its subdomains.
|
|
142
|
+
assert.equal(resolveProxyForTarget(TARGET, { ...proxy, NO_PROXY: ".example.invalid" }), undefined);
|
|
143
|
+
assert.equal(resolveProxyForTarget(TARGET, { ...proxy, NO_PROXY: "*.example.invalid" }), undefined);
|
|
144
|
+
// A bare domain is an exact match, so it does not silently cover the world.
|
|
145
|
+
assert.notEqual(resolveProxyForTarget(TARGET, { ...proxy, NO_PROXY: "example.invalid" }), undefined);
|
|
146
|
+
// Every host bypasses on a wildcard.
|
|
147
|
+
assert.equal(resolveProxyForTarget(TARGET, { ...proxy, NO_PROXY: "*" }), undefined);
|
|
148
|
+
// A listed port is part of the match.
|
|
149
|
+
assert.equal(resolveProxyForTarget(TARGET, { ...proxy, NO_PROXY: "release-assets.example.invalid:443" }), undefined);
|
|
150
|
+
assert.notEqual(resolveProxyForTarget(TARGET, { ...proxy, NO_PROXY: "release-assets.example.invalid:8443" }), undefined);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("an IPv6 proxy address reaches the proxy instead of failing to resolve", { timeout: 15_000 }, async (t) => {
|
|
154
|
+
// URL.hostname keeps the brackets of an IPv6 literal, and a socket address
|
|
155
|
+
// does not accept them, so the tunnel has to strip them before connecting.
|
|
156
|
+
const server = createServer((socket) => {
|
|
157
|
+
socket.on("error", () => {});
|
|
158
|
+
socket.on("data", () => socket.write("HTTP/1.1 407 Proxy Authentication Required\r\n\r\n"));
|
|
159
|
+
});
|
|
160
|
+
// A host without IPv6 has no loopback address to bind, so there is
|
|
161
|
+
// nothing to assert there. Every other error is a real failure.
|
|
162
|
+
let bound = false;
|
|
163
|
+
await new Promise<void>((resolve, reject) => {
|
|
164
|
+
server.once("error", reject);
|
|
165
|
+
server.listen({ host: "::1", port: 0 }, () => { bound = true; resolve(); });
|
|
166
|
+
}).catch((error: NodeJS.ErrnoException) => {
|
|
167
|
+
if (error.code !== "EADDRNOTAVAIL") throw error;
|
|
168
|
+
});
|
|
169
|
+
if (!bound) {
|
|
170
|
+
t.skip("IPv6 loopback is unavailable on this host");
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
t.after(() => new Promise<void>((resolve) => server.close(() => resolve())));
|
|
174
|
+
const address = server.address();
|
|
175
|
+
const port = typeof address === "object" && address !== null ? address.port : 0;
|
|
176
|
+
const directory = await mkdtemp(join(tmpdir(), "gentle-pi-proxy-ipv6-"));
|
|
177
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
178
|
+
// The proxy answered, so the failure has to be the refusal and not a
|
|
179
|
+
// lookup that never reached the address.
|
|
180
|
+
await assert.rejects(
|
|
181
|
+
() => downloadGentleAiAsset(TARGET, join(directory, "asset"), 1024, 0, { env: { HTTPS_PROXY: `http://[::1]:${port}` }, maxAttempts: 1, headerTimeoutMs: 1500 }),
|
|
182
|
+
/proxy refused the tunnel with status 407/,
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test("malformed percent-encoded proxy credentials are ignored", () => {
|
|
187
|
+
for (const credentials of ["user%:pass", "user:pass%GG", "user:%C3%28", ":pass%"]) {
|
|
188
|
+
const env = { HTTPS_PROXY: `http://${credentials}@proxy.invalid:3128` };
|
|
189
|
+
assert.equal(resolveProxyForTarget(TARGET, env), undefined);
|
|
190
|
+
assert.equal(resolveProxyForTarget(TARGET, { ...env, HTTP_PROXY: "http://fallback.invalid:3128" })?.hostname, "fallback.invalid");
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
for (const [name, response, protocol] of [
|
|
195
|
+
["silent", null, "http"],
|
|
196
|
+
["early-closed", "", "http"],
|
|
197
|
+
["truncated", "HTTP/1.1 200 Connection Established\r\n", "http"],
|
|
198
|
+
["silent TLS", null, "https"],
|
|
199
|
+
] as const) {
|
|
200
|
+
test(`${name} proxy rejects within the CONNECT deadline`, { timeout: 3000 }, async (t) => {
|
|
201
|
+
const proxy = await startProxyStub(response);
|
|
202
|
+
t.after(() => proxy.close());
|
|
203
|
+
const directory = await mkdtemp(join(tmpdir(), "gentle-pi-proxy-incomplete-"));
|
|
204
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
205
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
206
|
+
const deadline = new Promise<never>((_, reject) => { timer = setTimeout(() => reject(new Error("CONNECT did not settle within one second")), 1000); });
|
|
207
|
+
try {
|
|
208
|
+
await assert.rejects(Promise.race([
|
|
209
|
+
downloadGentleAiAsset(TARGET, join(directory, "asset"), 1024, 0, { env: { HTTPS_PROXY: `${protocol}://localhost:${proxy.port}` }, maxAttempts: 1, headerTimeoutMs: 50 }),
|
|
210
|
+
deadline,
|
|
211
|
+
]), { code: response === null ? "GENTLE_AI_DOWNLOAD_TIMEOUT" : "ECONNRESET" });
|
|
212
|
+
await Promise.race([proxy.waitForClose(), deadline]);
|
|
213
|
+
assert.equal(proxy.connections(), 1);
|
|
214
|
+
} finally {
|
|
215
|
+
clearTimeout(timer);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
test("an HTTPS proxy on an IP address is checked against the address and not sent as a server name", { timeout: 15_000 }, async (t) => {
|
|
221
|
+
// An IP address cannot be a server name, and a modern Node refuses the
|
|
222
|
+
// handshake outright when it is given one. The address goes in as the host
|
|
223
|
+
// instead, which is the name the certificate is checked against.
|
|
224
|
+
const proxy = await startProxyStub(407);
|
|
225
|
+
t.after(() => proxy.close());
|
|
226
|
+
const directory = await mkdtemp(join(tmpdir(), "gentle-pi-proxy-ip-host-"));
|
|
227
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
228
|
+
// The stub speaks plain TCP, so the TLS handshake against it fails. What
|
|
229
|
+
// matters here is that the failure arrives as a rejected download and not
|
|
230
|
+
// as an exception that escapes the tunnel and takes the install down.
|
|
231
|
+
const failures: unknown[] = [];
|
|
232
|
+
const onUncaught = (error: unknown) => { failures.push(error); };
|
|
233
|
+
process.on("uncaughtException", onUncaught);
|
|
234
|
+
try {
|
|
235
|
+
await assert.rejects(
|
|
236
|
+
() => downloadGentleAiAsset(TARGET, join(directory, "asset"), 1024, 0, { env: { HTTPS_PROXY: `https://127.0.0.1:${proxy.port}` }, maxAttempts: 1, headerTimeoutMs: 1500 }),
|
|
237
|
+
(error: NodeJS.ErrnoException) => error.code !== "ERR_INVALID_ARG_VALUE",
|
|
238
|
+
);
|
|
239
|
+
} finally {
|
|
240
|
+
process.off("uncaughtException", onUncaught);
|
|
241
|
+
}
|
|
242
|
+
assert.deepEqual(failures, [], "no exception escaped the tunnel");
|
|
243
|
+
// The address is the name the certificate is verified against, and no
|
|
244
|
+
// server name is sent with it.
|
|
245
|
+
assert.deepEqual(proxyTlsOptions(new URL("https://127.0.0.1:3128")), { host: "127.0.0.1" });
|
|
246
|
+
assert.deepEqual(proxyTlsOptions(new URL("https://[::1]:3128")), { host: "::1" });
|
|
247
|
+
// A hostname keeps its server name, so the proxy is still reached by name.
|
|
248
|
+
assert.deepEqual(proxyTlsOptions(new URL("https://proxy.invalid:3128")), { host: "proxy.invalid", servername: "proxy.invalid" });
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test("the tunnel applies the proxy host to the certificate check", { timeout: 15_000 }, async (t) => {
|
|
252
|
+
// The options are only worth anything if the tunnel hands them to the
|
|
253
|
+
// handshake, so this runs against a real TLS proxy whose certificate the
|
|
254
|
+
// download has to trust.
|
|
255
|
+
const proxy = await startTlsProxyStub(407);
|
|
256
|
+
t.after(() => proxy.close());
|
|
257
|
+
const directory = await mkdtemp(join(tmpdir(), "gentle-pi-proxy-tls-identity-"));
|
|
258
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
259
|
+
const ca = [PROXY_CERT];
|
|
260
|
+
await assert.rejects(
|
|
261
|
+
() => downloadGentleAiAsset(TARGET, join(directory, "asset"), 1024, 0, { env: { HTTPS_PROXY: `https://127.0.0.1:${proxy.port}` }, maxAttempts: 1, headerTimeoutMs: 1500, ca: [PROXY_CERT] }),
|
|
262
|
+
/proxy refused the tunnel with status 407/,
|
|
263
|
+
);
|
|
264
|
+
// The handshake completed, so the certificate was verified against the
|
|
265
|
+
// proxy address, and the CONNECT request reached the proxy.
|
|
266
|
+
assert.match(proxy.head(), /^CONNECT release-assets\.example\.invalid:443 HTTP\/1\.1\r\n/);
|
|
267
|
+
assert.equal(proxy.servername(), false, "an address is not sent as a server name");
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("the origin certificate is checked against the origin address", { timeout: 15_000 }, async (t) => {
|
|
271
|
+
// A request for an address leaves the server name empty. An empty server
|
|
272
|
+
// name would make the origin certificate be checked against "localhost",
|
|
273
|
+
// so the download has to fall back to the address it asked for.
|
|
274
|
+
const originSockets: Socket[] = [];
|
|
275
|
+
const origin = createTlsServer({ cert: PROXY_CERT, key: PROXY_KEY }, (socket) => {
|
|
276
|
+
originSockets.push(socket);
|
|
277
|
+
socket.on("error", () => {});
|
|
278
|
+
socket.on("data", () => {
|
|
279
|
+
socket.write("HTTP/1.1 200 OK\r\nContent-Length: 4\r\n\r\nbody");
|
|
280
|
+
socket.end();
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
await new Promise<void>((resolve) => origin.listen(0, "127.0.0.1", resolve));
|
|
284
|
+
t.after(() => new Promise<void>((resolve) => {
|
|
285
|
+
for (const socket of originSockets) socket.destroy();
|
|
286
|
+
origin.close(() => resolve());
|
|
287
|
+
}));
|
|
288
|
+
const originPort = (origin.address() as { port: number }).port;
|
|
289
|
+
|
|
290
|
+
// A proxy that opens the tunnel and pipes the bytes through.
|
|
291
|
+
const proxySockets: Socket[] = [];
|
|
292
|
+
const proxy = createServer((socket) => {
|
|
293
|
+
proxySockets.push(socket);
|
|
294
|
+
socket.on("error", () => {});
|
|
295
|
+
socket.once("data", (chunk) => {
|
|
296
|
+
const match = /^CONNECT 127\.0\.0\.1:(\d+) HTTP\/1\.1/.exec(chunk.toString("latin1"));
|
|
297
|
+
if (match === null) return;
|
|
298
|
+
const upstream = connect({ host: "127.0.0.1", port: Number(match[1]) });
|
|
299
|
+
upstream.on("error", () => {});
|
|
300
|
+
socket.write("HTTP/1.1 200 Connection Established\r\n\r\n");
|
|
301
|
+
upstream.pipe(socket);
|
|
302
|
+
socket.pipe(upstream);
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
await new Promise<void>((resolve) => proxy.listen(0, "127.0.0.1", resolve));
|
|
306
|
+
t.after(() => new Promise<void>((resolve) => {
|
|
307
|
+
for (const socket of proxySockets) socket.destroy();
|
|
308
|
+
proxy.close(() => resolve());
|
|
309
|
+
}));
|
|
310
|
+
const proxyPort = (proxy.address() as { port: number }).port;
|
|
311
|
+
|
|
312
|
+
const directory = await mkdtemp(join(tmpdir(), "gentle-pi-proxy-origin-identity-"));
|
|
313
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
314
|
+
const destination = join(directory, "asset");
|
|
315
|
+
// The certificate covers IP:127.0.0.1, so the download only succeeds when
|
|
316
|
+
// the origin is checked against the address and not against "localhost".
|
|
317
|
+
await downloadGentleAiAsset(`https://127.0.0.1:${originPort}/asset`, destination, 1024, 0, {
|
|
318
|
+
env: { HTTPS_PROXY: `http://127.0.0.1:${proxyPort}` },
|
|
319
|
+
maxAttempts: 1,
|
|
320
|
+
headerTimeoutMs: 1500,
|
|
321
|
+
ca: [PROXY_CERT],
|
|
322
|
+
});
|
|
323
|
+
assert.equal(readFileSync(destination, "utf8"), "body");
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
test("the release download carries a tunnel only when the environment names a proxy", async (t) => {
|
|
327
|
+
const directory = await mkdtemp(join(tmpdir(), "gentle-pi-proxy-wiring-"));
|
|
328
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
329
|
+
const seen: Array<Record<string, unknown>> = [];
|
|
330
|
+
const request = (_url: URL, options: unknown, callback: (response: PassThrough & { statusCode?: number; headers: Record<string, string> }) => void) => {
|
|
331
|
+
seen.push(options as Record<string, unknown>);
|
|
332
|
+
const response = Object.assign(new PassThrough(), { statusCode: 200, headers: {} });
|
|
333
|
+
queueMicrotask(() => { callback(response); response.end(); });
|
|
334
|
+
return pendingRequest();
|
|
335
|
+
};
|
|
336
|
+
await downloadGentleAiAsset(TARGET, join(directory, "direct"), 1024, 0, { request, env: {}, maxAttempts: 1 });
|
|
337
|
+
assert.equal(seen.length, 1);
|
|
338
|
+
assert.equal(seen[0].agent, undefined, "a direct download carries no agent");
|
|
339
|
+
await downloadGentleAiAsset(TARGET, join(directory, "proxied"), 1024, 0, { request, env: { HTTPS_PROXY: "http://proxy.invalid:3128" }, maxAttempts: 1 });
|
|
340
|
+
assert.equal(seen.length, 2);
|
|
341
|
+
assert.ok(seen[1].agent, "a proxied download carries the tunnel that reaches the proxy");
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
test("the tunnel asks the proxy to CONNECT to the origin host", async (t) => {
|
|
345
|
+
const proxy = await startProxyStub(200);
|
|
346
|
+
t.after(() => proxy.close());
|
|
347
|
+
const directory = await mkdtemp(join(tmpdir(), "gentle-pi-proxy-tunnel-"));
|
|
348
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
349
|
+
await assert.rejects(() => downloadGentleAiAsset(TARGET, join(directory, "asset"), 1024, 0, { env: { HTTPS_PROXY: `http://127.0.0.1:${proxy.port}` }, maxAttempts: 1, headerTimeoutMs: 1500 }));
|
|
350
|
+
assert.match(proxy.head(), /^CONNECT release-assets\.example\.invalid:443 HTTP\/1\.1\r\nHost: release-assets\.example\.invalid:443\r\n/);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
test("a proxy that refuses the tunnel fails with the status it returned", async (t) => {
|
|
354
|
+
const proxy = await startProxyStub(407);
|
|
355
|
+
t.after(() => proxy.close());
|
|
356
|
+
const directory = await mkdtemp(join(tmpdir(), "gentle-pi-proxy-refused-"));
|
|
357
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
358
|
+
await assert.rejects(
|
|
359
|
+
() => downloadGentleAiAsset(TARGET, join(directory, "asset"), 1024, 0, { env: { HTTPS_PROXY: `http://127.0.0.1:${proxy.port}` }, maxAttempts: 1, headerTimeoutMs: 1500 }),
|
|
360
|
+
/proxy refused the tunnel with status 407/,
|
|
361
|
+
);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
test("a proxy that is briefly overloaded is retried like any other transient failure", async (t) => {
|
|
365
|
+
const proxy = await startProxyStub(503);
|
|
366
|
+
t.after(() => proxy.close());
|
|
367
|
+
const directory = await mkdtemp(join(tmpdir(), "gentle-pi-proxy-transient-"));
|
|
368
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
369
|
+
await assert.rejects(
|
|
370
|
+
() => downloadGentleAiAsset(TARGET, join(directory, "asset"), 1024, 0, { env: { HTTPS_PROXY: `http://127.0.0.1:${proxy.port}` }, maxAttempts: 2, retryDelayMs: 0, headerTimeoutMs: 1500 }),
|
|
371
|
+
/proxy refused the tunnel with status 503/,
|
|
372
|
+
);
|
|
373
|
+
assert.equal(proxy.connections(), 2, "a transient refusal opens a second connection");
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
test("a proxy reached over TLS is spoken to over TLS, not in the clear", { timeout: 15_000 }, async (t) => {
|
|
377
|
+
const proxy = await startSilentProxy();
|
|
378
|
+
t.after(() => proxy.close());
|
|
379
|
+
const directory = await mkdtemp(join(tmpdir(), "gentle-pi-proxy-tls-"));
|
|
380
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
381
|
+
await assert.rejects(() => downloadGentleAiAsset(TARGET, join(directory, "asset"), 1024, 0, { env: { HTTPS_PROXY: `https://localhost:${proxy.port}` }, maxAttempts: 1, headerTimeoutMs: 1500 }));
|
|
382
|
+
// A TLS ClientHello starts with the handshake content type and a version,
|
|
383
|
+
// where the plaintext CONNECT request would start with its own verb.
|
|
384
|
+
assert.equal(proxy.firstBytes()[0], 0x16, "the first byte to the proxy is a TLS handshake");
|
|
385
|
+
assert.equal(proxy.firstBytes()[1], 0x03, "the first byte to the proxy is a TLS handshake");
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
test("the proxy handshake does not receive the origin client credentials", { timeout: 15_000 }, async (t) => {
|
|
389
|
+
// The client credentials are the identity of the origin. A proxy that asks
|
|
390
|
+
// for a client certificate must not be handed them, or the proxy learns
|
|
391
|
+
// who the origin is and can present that identity onwards.
|
|
392
|
+
let peerCommonName: string | null = null;
|
|
393
|
+
const proxy = createTlsServer({ cert: PROXY_CERT, key: PROXY_KEY, requestCert: true, rejectUnauthorized: false }, (socket) => {
|
|
394
|
+
const peer = socket.getPeerCertificate();
|
|
395
|
+
peerCommonName = peer && peer.subject && typeof peer.subject.CN === "string" ? peer.subject.CN : null;
|
|
396
|
+
socket.on("error", () => {});
|
|
397
|
+
socket.on("data", () => socket.write("HTTP/1.1 407 Proxy Authentication Required\r\n\r\n"));
|
|
398
|
+
});
|
|
399
|
+
await new Promise<void>((resolve) => proxy.listen(0, "127.0.0.1", resolve));
|
|
400
|
+
t.after(() => new Promise<void>((resolve) => proxy.close(() => resolve())));
|
|
401
|
+
const proxyPort = (proxy.address() as { port: number }).port;
|
|
402
|
+
const directory = await mkdtemp(join(tmpdir(), "gentle-pi-proxy-credentials-"));
|
|
403
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
404
|
+
await assert.rejects(
|
|
405
|
+
() => downloadGentleAiAsset(TARGET, join(directory, "asset"), 1024, 0, { env: { HTTPS_PROXY: `https://127.0.0.1:${proxyPort}` }, maxAttempts: 1, headerTimeoutMs: 1500, ca: [PROXY_CERT], cert: PROXY_CERT, key: PROXY_KEY }),
|
|
406
|
+
/proxy refused the tunnel with status 407/,
|
|
407
|
+
);
|
|
408
|
+
assert.equal(peerCommonName, null, "the proxy received no client certificate");
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
test("a redirect resolves the proxy for its destination", async (t) => {
|
|
412
|
+
const directory = await mkdtemp(join(tmpdir(), "gentle-pi-proxy-redirect-"));
|
|
413
|
+
t.after(() => rm(directory, { recursive: true, force: true }));
|
|
414
|
+
const seen: Array<{ url: URL; options: Record<string, unknown> }> = [];
|
|
415
|
+
const request = (url: URL, options: unknown, callback: (response: PassThrough & { statusCode?: number; headers: Record<string, string> }) => void) => {
|
|
416
|
+
seen.push({ url, options: options as Record<string, unknown> });
|
|
417
|
+
const response = Object.assign(new PassThrough(), seen.length === 1
|
|
418
|
+
? { statusCode: 302, headers: { location: "https://direct.example.invalid/asset.tar.gz" } }
|
|
419
|
+
: { statusCode: 200, headers: {} });
|
|
420
|
+
queueMicrotask(() => { callback(response); response.end(); });
|
|
421
|
+
return pendingRequest();
|
|
422
|
+
};
|
|
423
|
+
await downloadGentleAiAsset(TARGET, join(directory, "asset"), 1024, 1, {
|
|
424
|
+
request,
|
|
425
|
+
env: { HTTPS_PROXY: "http://proxy.invalid:3128", NO_PROXY: "direct.example.invalid" },
|
|
426
|
+
maxAttempts: 1,
|
|
427
|
+
});
|
|
428
|
+
// The first hop goes through the proxy.
|
|
429
|
+
assert.ok(seen[0].options.agent, "the first request carries the tunnel");
|
|
430
|
+
// The destination is exempt, so it must not carry the tunnel. Reusing the
|
|
431
|
+
// first agent would send an exempt destination through the proxy.
|
|
432
|
+
assert.equal(seen[1].url.hostname, "direct.example.invalid");
|
|
433
|
+
assert.equal(seen[1].options.agent, undefined, "an exempt destination carries no tunnel");
|
|
434
|
+
});
|