Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/upstream-alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ export function recordUpstreamAlert(url: string, error: unknown, viaProxy: boole
existing.count += 1;
existing.hint = hint;
if (code !== undefined) existing.code = code;
delete existing.skippedProxy;
delete existing.skippedSource;
Object.assign(existing, skippedFields);
return;
}
Expand Down
55 changes: 55 additions & 0 deletions tests/skipped-proxy-hint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,61 @@ test("recordUpstreamAlert: structured skipped fields ride along for the localize
assert.equal(a.hint, UPSTREAM_FAIL_HINTS["connect-refused"]);
});

for (const mode of ["explicit-direct", "auto", "host-bypass"] as const) {
test(`recordUpstreamAlert: ${mode} replaces an earlier skipped-proxy diagnosis`, () => {
_resetUpstreamAlertsForTest();
try {
const fallback = { biliPort: 42422, httpsProxy: ENV_PROXY, systemProxy: { enabled: false } };
const first = resolveProxyDecision({}, "", TARGET, { ...fallback, explicitDirect: true, defaultDirect: true });
const error = netError("UND_ERR_CONNECT_TIMEOUT", "connect timed out");
recordUpstreamAlert(TARGET, error, !!first.proxy, first.skippedProxy);
const firstSeen = getUpstreamAlerts()[0].firstSeen;
assert.ok(getUpstreamAlerts()[0].skippedProxy);

const next = mode === "auto"
? resolveProxyDecision({}, undefined, TARGET, fallback)
: resolveProxyDecision({}, "", TARGET, {
...fallback, explicitDirect: true, defaultDirect: mode === "host-bypass",
...(mode === "host-bypass" ? { noProxy: "relay.example.com" } : {}),
});
assert.equal(next.skippedProxy, undefined);
assert.equal(!!next.proxy, mode === "auto");
recordUpstreamAlert(TARGET, error, !!next.proxy, next.skippedProxy);

const alerts = getUpstreamAlerts();
assert.equal(alerts.length, 1);
const [current] = alerts;
assert.equal(current.count, 2);
assert.equal(current.firstSeen, firstSeen);
assert.equal(current.code, "UND_ERR_CONNECT_TIMEOUT");
assert.equal(current.hint, UPSTREAM_FAIL_HINTS["connect-timeout"]);
assert.equal(current.skippedProxy, undefined);
assert.equal(current.skippedSource, undefined);
assert.ok(!JSON.stringify(current).includes("7890"));
} finally {
_resetUpstreamAlertsForTest();
}
});
}

test("recordUpstreamAlert: a later skipped proxy replaces the old redacted endpoint and source", () => {
_resetUpstreamAlertsForTest();
try {
const error = netError("UND_ERR_CONNECT_TIMEOUT", "connect timed out");
recordUpstreamAlert(TARGET, error, false, { proxy: ENV_PROXY, source: "HTTPS_PROXY" });
recordUpstreamAlert(TARGET, error, false, { proxy: "http://new-user:new-password@127.0.0.1:7897", source: "windows-system" });
const [current] = getUpstreamAlerts();
assert.equal(current.count, 2);
assert.equal(current.skippedProxy, "http://***:***@127.0.0.1:7897");
assert.equal(current.skippedSource, "windows-system");
assert.ok(!JSON.stringify(current).includes("new-password"));
assert.ok(!JSON.stringify(current).includes("7890"));
assert.ok(current.hint.includes(current.skippedProxy));
} finally {
_resetUpstreamAlertsForTest();
}
});

test("loadOptions: defaultDirect tracks UNSET mode only (model path)", () => {
// unset mode + available env proxy → the full #2809 scenario end-to-end
withSandboxEnv(() => {}, () => {
Expand Down
26 changes: 26 additions & 0 deletions tests/upstream-alerts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,29 @@ test("#1682: banner renders active alerts, dismisses per instance, hides on reco
_resetUpstreamAlertsForTest();
}
});

test("banner drops the skipped-proxy advice when the latest failure did not skip a proxy", async () => {
_resetUpstreamAlertsForTest();
const url = "https://relay.example.com/v1/messages";
const error = netError("UND_ERR_CONNECT_TIMEOUT");
const deadPort = await freePort();
const { proxy, proxyPort } = await startProxyFor(deadPort, false);
const base = `http://127.0.0.1:${proxyPort}`;
try {
recordUpstreamAlert(url, error, false, { proxy: "http://127.0.0.1:7890", source: "HTTPS_PROXY" });
const first = await runWebClient(base, "#/overview", new Map());
await waitFor(() => first.els.get("alerts-banner")?.hidden === false, "initial skipped-proxy banner");
assert.match(first.els.get("alerts-banner")!.children[1].children[0].textContent, /127\.0\.0\.1:7890/);

recordUpstreamAlert(url, error, true);
const current = await runWebClient(base, "#/overview", new Map());
await waitFor(() => current.els.get("alerts-banner")?.hidden === false, "current failure banner");
const message = current.els.get("alerts-banner")!.children[1].children[0].textContent;
assert.match(message, /relay\.example\.com \(connect-timeout ×2/);
assert.ok(!message.includes("127.0.0.1:7890"));
assert.ok(!message.includes("HTTPS_PROXY"));
} finally {
await close(proxy);
_resetUpstreamAlertsForTest();
}
});
Loading