refactor(js): extract HumanActionOptions type, fix frame check/uncheck error handling, align SOCKS5 log level

- Extract HumanActionOptions type alias to replace ~40 inline copies
- Frame check/uncheck: let isChecked errors propagate instead of silently clicking non-checkbox elements
- SOCKS5 credential log: console.debug → console.info (parity with Python logger.info)
- Add contributors to README
This commit is contained in:
CloakHQ
2026-05-11 00:23:31 +02:00
parent 80d9f7c14e
commit 0d41a4f023
7 changed files with 77 additions and 85 deletions
+17 -26
View File
@@ -47,7 +47,7 @@
*/
import type { Browser, Page, Frame, CDPSession, ElementHandle, BrowserContext } from 'puppeteer-core';
import type { HumanConfig } from '../human/config.js';
import type { HumanConfig, HumanActionOptions } from '../human/config.js';
import { resolveConfig, mergeConfig, rand, randRange, sleep } from '../human/config.js';
import { RawMouse, RawKeyboard, humanMove, humanClick, clickTarget, humanIdle } from '../human/mouse.js';
import { humanType } from './keyboard.js';
@@ -331,14 +331,12 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
};
// ==== click (with clickCount support for dblclick) ====
const humanClickFn = async (selector: string, options?: Partial<HumanConfig> & ({
const humanClickFn = async (selector: string, options?: HumanActionOptions & {
button?: 'left' | 'right' | 'middle' | 'back' | 'forward';
clickCount?: number;
count?: number;
delay?: number;
human_config?: Partial<HumanConfig>;
timeout?: number;
})) => {
}) => {
await ensureCursorInit();
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
if (callCfg.idle_between_actions) {
@@ -366,7 +364,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
};
// ==== hover ====
const humanHoverFn = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const humanHoverFn = async (selector: string, options?: HumanActionOptions) => {
await ensureCursorInit();
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
if (callCfg.idle_between_actions) {
@@ -382,11 +380,9 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
};
// ==== type ====
const humanTypeFn = async (selector: string, text: string, options?: Partial<HumanConfig> & ({
const humanTypeFn = async (selector: string, text: string, options?: HumanActionOptions & {
delay?: number;
human_config?: Partial<HumanConfig>;
timeout?: number;
})) => {
}) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
await sleep(randRange(callCfg.field_switch_delay));
await humanClickFn(selector, options);
@@ -410,7 +406,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
};
// ==== tap ====
const humanTapFn = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const humanTapFn = async (selector: string, options?: HumanActionOptions) => {
await humanClickFn(selector, options);
};
@@ -671,13 +667,12 @@ function patchSingleElementHandle(
};
// --- el.click() ---
(el as any).click = async (options?: Partial<HumanConfig> & ({
(el as any).click = async (options?: HumanActionOptions & {
button?: 'left' | 'right' | 'middle' | 'back' | 'forward';
clickCount?: number;
count?: number;
delay?: number;
human_config?: Partial<HumanConfig>;
})) => {
}) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
const info = await moveToElement(callCfg);
if (!info) return origElClick(options);
@@ -701,7 +696,7 @@ function patchSingleElementHandle(
};
// --- el.type() ---
(el as any).type = async (text: string, options?: Partial<HumanConfig> & ({ delay?: number; human_config?: Partial<HumanConfig> })) => {
(el as any).type = async (text: string, options?: HumanActionOptions & { delay?: number }) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
const info = await moveToElement(callCfg);
if (!info) return origElType(text, options);
@@ -718,7 +713,7 @@ function patchSingleElementHandle(
// page.click(). Only patched when the underlying ElementHandle exposes
// ``scrollIntoView`` (Puppeteer v22+).
if (origElScrollIntoView) {
(el as any).scrollIntoView = async (options?: Partial<HumanConfig> & { human_config?: Partial<HumanConfig> }) => {
(el as any).scrollIntoView = async (options?: HumanActionOptions) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
await (page as any)._ensureCursorInit();
try {
@@ -870,26 +865,22 @@ function patchSingleFrame(
const origFrameSelect = frame.select.bind(frame);
(frame as any).click = async (selector: string, options?: Partial<HumanConfig> & ({
(frame as any).click = async (selector: string, options?: HumanActionOptions & {
button?: 'left' | 'right' | 'middle' | 'back' | 'forward';
clickCount?: number;
count?: number;
delay?: number;
human_config?: Partial<HumanConfig>;
timeout?: number;
})) => {
}) => {
await (page as any).click(selector, options);
};
(frame as any).hover = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
(frame as any).hover = async (selector: string, options?: HumanActionOptions) => {
await (page as any).hover(selector, options);
};
(frame as any).type = async (selector: string, text: string, options?: Partial<HumanConfig> & ({
(frame as any).type = async (selector: string, text: string, options?: HumanActionOptions & {
delay?: number;
human_config?: Partial<HumanConfig>;
timeout?: number;
})) => {
}) => {
await (page as any).type(selector, text, options);
};
@@ -903,7 +894,7 @@ function patchSingleFrame(
await (page as any).focus(selector);
};
(frame as any).tap = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
(frame as any).tap = async (selector: string, options?: HumanActionOptions) => {
await (page as any).click(selector, options);
};
+5
View File
@@ -70,6 +70,11 @@ export interface HumanConfig {
export type HumanPreset = 'default' | 'careful';
export type HumanActionOptions = Partial<HumanConfig> & {
timeout?: number;
human_config?: Partial<HumanConfig>;
};
// ---------------------------------------------------------------------------
// Default preset
// ---------------------------------------------------------------------------
+12 -22
View File
@@ -17,7 +17,7 @@
*/
import type { Page, Frame, ElementHandle, CDPSession } from 'playwright-core';
import type { HumanConfig } from './config.js';
import type { HumanConfig, HumanActionOptions } from './config.js';
import { rand, randRange, sleep, mergeConfig } from './config.js';
import { RawMouse, RawKeyboard, humanMove, humanClick, clickTarget, humanIdle } from './mouse.js';
import { humanType } from './keyboard.js';
@@ -179,18 +179,16 @@ export function patchSingleElementHandle(
};
// --- el.click() ---
(el as any).click = async (options?: Partial<HumanConfig> & ({
(el as any).click = async (options?: HumanActionOptions & {
button?: 'left' | 'right' | 'middle';
clickCount?: number;
delay?: number;
force?: boolean;
human_config?: Partial<HumanConfig>;
modifiers?: Array<'Alt' | 'Control' | 'ControlOrMeta' | 'Meta' | 'Shift'>;
noWaitAfter?: boolean;
position?: { x: number; y: number };
timeout?: number;
trial?: boolean;
})) => {
}) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
const info = await moveToElement(callCfg);
if (!info) return origElClick(options);
@@ -198,17 +196,15 @@ export function patchSingleElementHandle(
};
// --- el.dblclick() ---
(el as any).dblclick = async (options?: Partial<HumanConfig> & ({
(el as any).dblclick = async (options?: HumanActionOptions & {
button?: 'left' | 'right' | 'middle';
delay?: number;
force?: boolean;
human_config?: Partial<HumanConfig>;
modifiers?: Array<'Alt' | 'Control' | 'ControlOrMeta' | 'Meta' | 'Shift'>;
noWaitAfter?: boolean;
position?: { x: number; y: number };
timeout?: number;
trial?: boolean;
})) => {
}) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
const info = await moveToElement(callCfg);
if (!info) return origElDblclick(options);
@@ -218,14 +214,12 @@ export function patchSingleElementHandle(
};
// --- el.hover() ---
(el as any).hover = async (options?: Partial<HumanConfig> & ({
(el as any).hover = async (options?: HumanActionOptions & {
force?: boolean;
human_config?: Partial<HumanConfig>;
modifiers?: Array<'Alt' | 'Control' | 'ControlOrMeta' | 'Meta' | 'Shift'>;
position?: { x: number; y: number };
timeout?: number;
trial?: boolean;
})) => {
}) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
const info = await moveToElement(callCfg);
if (!info) return origElHover(options);
@@ -233,12 +227,10 @@ export function patchSingleElementHandle(
};
// --- el.type() ---
(el as any).type = async (text: string, options?: Partial<HumanConfig> & ({
(el as any).type = async (text: string, options?: HumanActionOptions & {
delay?: number;
human_config?: Partial<HumanConfig>;
noWaitAfter?: boolean;
timeout?: number;
})) => {
}) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
const info = await moveToElement(callCfg);
if (!info) return origElType(text, options);
@@ -250,12 +242,10 @@ export function patchSingleElementHandle(
};
// --- el.fill() ---
(el as any).fill = async (value: string, options?: Partial<HumanConfig> & ({
(el as any).fill = async (value: string, options?: HumanActionOptions & {
force?: boolean;
human_config?: Partial<HumanConfig>;
noWaitAfter?: boolean;
timeout?: number;
})) => {
}) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
const info = await moveToElement(callCfg);
if (!info) return origElFill(value, options);
@@ -374,7 +364,7 @@ export function patchSingleElementHandle(
// wheel sequence used by page.click() etc. Falls back to the native
// method if the element is detached or scrolling fails.
if (origElScrollIntoViewIfNeeded) {
(el as any).scrollIntoViewIfNeeded = async (options?: Partial<HumanConfig> & ({ human_config?: Partial<HumanConfig>; timeout?: number })) => {
(el as any).scrollIntoViewIfNeeded = async (options?: HumanActionOptions) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
const ensureCursorInit = (page as any)._ensureCursorInit;
if (ensureCursorInit) await ensureCursorInit();
+32 -28
View File
@@ -23,7 +23,7 @@
*/
import type { Browser, BrowserContext, Page, Frame, CDPSession } from 'playwright-core';
import { HumanConfig, resolveConfig, mergeConfig, rand, randRange, sleep } from './config.js';
import { HumanConfig, HumanActionOptions, resolveConfig, mergeConfig, rand, randRange, sleep } from './config.js';
import { RawMouse, RawKeyboard, humanMove, humanClick, clickTarget, humanIdle } from './mouse.js';
import { humanType } from './keyboard.js';
import { scrollToElement, humanScrollIntoView } from './scroll.js';
@@ -307,7 +307,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
};
// --- click ---
const humanClickFn = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const humanClickFn = async (selector: string, options?: HumanActionOptions) => {
await ensureCursorInit();
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
if (callCfg.idle_between_actions) {
@@ -325,7 +325,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
};
// --- dblclick ---
const humanDblclickFn = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const humanDblclickFn = async (selector: string, options?: HumanActionOptions) => {
await ensureCursorInit();
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
if (callCfg.idle_between_actions) {
@@ -346,7 +346,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
};
// --- hover ---
const humanHoverFn = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const humanHoverFn = async (selector: string, options?: HumanActionOptions) => {
await ensureCursorInit();
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
if (callCfg.idle_between_actions) {
@@ -362,7 +362,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
};
// --- type ---
const humanTypeFn = async (selector: string, text: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const humanTypeFn = async (selector: string, text: string, options?: HumanActionOptions) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
await sleep(randRange(callCfg.field_switch_delay));
await humanClickFn(selector, options);
@@ -372,7 +372,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
};
// --- fill (clears existing content first) ---
const humanFillFn = async (selector: string, value: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const humanFillFn = async (selector: string, value: string, options?: HumanActionOptions) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
await sleep(randRange(callCfg.field_switch_delay));
await humanClickFn(selector, options);
@@ -386,7 +386,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
};
// --- clear ---
const humanClearFn = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const humanClearFn = async (selector: string, options?: HumanActionOptions) => {
if (!await isSelectorFocused(stealth, page, selector)) {
await humanClickFn(selector, options);
}
@@ -397,7 +397,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
};
// --- check ---
const humanCheckFn = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const humanCheckFn = async (selector: string, options?: HumanActionOptions) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
if (callCfg.idle_between_actions) {
await humanIdle(raw, cursor.x, cursor.y, callCfg);
@@ -409,7 +409,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
};
// --- uncheck ---
const humanUncheckFn = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const humanUncheckFn = async (selector: string, options?: HumanActionOptions) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
if (callCfg.idle_between_actions) {
await humanIdle(raw, cursor.x, cursor.y, callCfg);
@@ -421,14 +421,14 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
};
// --- selectOption ---
const humanSelectOptionFn = async (selector: string, values: any, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const humanSelectOptionFn = async (selector: string, values: any, options?: HumanActionOptions) => {
await humanHoverFn(selector, options);
await sleep(rand(100, 300));
return originals.selectOption(selector, values, options);
};
// --- press (checks focus first — avoids redundant mouse moves) ---
const humanPressFn = async (selector: string, key: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const humanPressFn = async (selector: string, key: string, options?: HumanActionOptions) => {
if (!await isSelectorFocused(stealth, page, selector)) {
await humanClickFn(selector, options);
}
@@ -437,7 +437,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
};
// --- pressSequentially ---
const humanPressSequentiallyFn = async (selector: string, text: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const humanPressSequentiallyFn = async (selector: string, text: string, options?: HumanActionOptions) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
if (!await isSelectorFocused(stealth, page, selector)) {
await humanClickFn(selector, options);
@@ -448,7 +448,7 @@ function patchPage(page: Page, cfg: HumanConfig, cursor: CursorState): void {
};
// --- tap ---
const humanTapFn = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const humanTapFn = async (selector: string, options?: HumanActionOptions) => {
await humanClickFn(selector, options);
};
@@ -593,7 +593,7 @@ function patchSingleFrame(
const origFrameTap = (frame as any).tap?.bind(frame);
const origFrameDragAndDrop = frame.dragAndDrop.bind(frame);
const moveToFrameSelector = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> }), inputBias = false) => {
const moveToFrameSelector = async (selector: string, options?: HumanActionOptions, inputBias = false) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
if (callCfg.idle_between_actions) {
await humanIdle(raw, cursor.x, cursor.y, callCfg);
@@ -614,7 +614,7 @@ function patchSingleFrame(
return { callCfg, isInput };
};
const frameClick = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const frameClick = async (selector: string, options?: HumanActionOptions) => {
const moved = await moveToFrameSelector(selector, options);
if (!moved) return origFrameClick(selector, options);
await humanClick(raw, moved.isInput, moved.callCfg);
@@ -622,14 +622,14 @@ function patchSingleFrame(
const getFrameCdp = async () => stealth.getCdpSession().catch(() => null);
const frameHover = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const frameHover = async (selector: string, options?: HumanActionOptions) => {
const moved = await moveToFrameSelector(selector, options, false);
if (!moved) return origFrameHover(selector, options);
};
(frame as any).click = frameClick;
(frame as any).dblclick = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
(frame as any).dblclick = async (selector: string, options?: HumanActionOptions) => {
const moved = await moveToFrameSelector(selector, options);
if (!moved) return origFrameDblclick(selector, options);
await raw.down({ clickCount: 2 });
@@ -639,7 +639,7 @@ function patchSingleFrame(
(frame as any).hover = frameHover;
(frame as any).type = async (selector: string, text: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
(frame as any).type = async (selector: string, text: string, options?: HumanActionOptions) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
await sleep(randRange(callCfg.field_switch_delay));
await frameClick(selector, options);
@@ -648,7 +648,7 @@ function patchSingleFrame(
await humanType(page, rawKb, text, callCfg, cdp).catch(() => origFrameType(selector, text, options));
};
(frame as any).fill = async (selector: string, value: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
(frame as any).fill = async (selector: string, value: string, options?: HumanActionOptions) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
await sleep(randRange(callCfg.field_switch_delay));
await frameClick(selector, options);
@@ -661,23 +661,27 @@ function patchSingleFrame(
await humanType(page, rawKb, value, callCfg, cdp).catch(() => origFrameFill(selector, value, options));
};
(frame as any).check = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const checked = await firstFrameLocator(frame, selector).isChecked?.().catch(() => false) ?? false;
(frame as any).check = async (selector: string, options?: HumanActionOptions) => {
const locator = firstFrameLocator(frame, selector);
if (typeof locator.isChecked !== 'function') return origFrameCheck(selector, options);
const checked = await locator.isChecked();
if (!checked) await frameClick(selector, options).catch(() => origFrameCheck(selector, options));
};
(frame as any).uncheck = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
const checked = await firstFrameLocator(frame, selector).isChecked?.().catch(() => true) ?? true;
(frame as any).uncheck = async (selector: string, options?: HumanActionOptions) => {
const locator = firstFrameLocator(frame, selector);
if (typeof locator.isChecked !== 'function') return origFrameUncheck(selector, options);
const checked = await locator.isChecked();
if (checked) await frameClick(selector, options).catch(() => origFrameUncheck(selector, options));
};
(frame as any).selectOption = async (selector: string, values: any, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
(frame as any).selectOption = async (selector: string, values: any, options?: HumanActionOptions) => {
await frameHover(selector, options);
await sleep(rand(100, 300));
return origFrameSelectOption(selector, values, options);
};
(frame as any).press = async (selector: string, key: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
(frame as any).press = async (selector: string, key: string, options?: HumanActionOptions) => {
if (!await isFrameSelectorFocused(frame, selector)) {
await frameClick(selector, options);
}
@@ -685,7 +689,7 @@ function patchSingleFrame(
await originals.keyboardPress(key);
};
(frame as any).pressSequentially = async (selector: string, text: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
(frame as any).pressSequentially = async (selector: string, text: string, options?: HumanActionOptions) => {
const callCfg = mergeConfig(cfg, options?.human_config ?? options);
if (!await isFrameSelectorFocused(frame, selector)) {
await frameClick(selector, options);
@@ -695,11 +699,11 @@ function patchSingleFrame(
await humanType(page, rawKb, text, callCfg, cdp).catch(() => origFramePressSequentially?.(selector, text, options));
};
(frame as any).tap = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
(frame as any).tap = async (selector: string, options?: HumanActionOptions) => {
await frameClick(selector, options).catch(() => origFrameTap?.(selector, options));
};
(frame as any).clear = async (selector: string, options?: Partial<HumanConfig> & ({ timeout?: number; human_config?: Partial<HumanConfig> })) => {
(frame as any).clear = async (selector: string, options?: HumanActionOptions) => {
if (!await isFrameSelectorFocused(frame, selector)) {
await frameClick(selector, options);
}
+1 -1
View File
@@ -143,7 +143,7 @@ export function normalizeSocksStringUrl(urlStr: string): string {
const credsChanged = encUser !== rawUserEnc
|| (hasPassword ? encPass !== rawPassEnc : false);
if (credsChanged) {
console.debug(
console.info(
"[cloakbrowser] Auto URL-encoded SOCKS5 proxy credentials (special " +
"characters detected). Pre-encode the URL to suppress this notice.",
);
+7 -7
View File
@@ -263,10 +263,10 @@ describe("resolveProxyConfig", () => {
expect(proxyArgs).toEqual(["--proxy-server=socks5://user:a%40b%40c@host:1080"]);
});
// Visibility for #157: when wrapper actually rewrites the URL, surface a
// debug log so users debugging silent SOCKS5 fallback can see what happened.
it("logs debug message when SOCKS5 credentials get re-encoded", () => {
const debugSpy = vi.spyOn(console, "debug").mockImplementation(() => {});
// Visibility for #157: when wrapper actually rewrites the URL, surface an
// info log so users debugging silent SOCKS5 fallback can see what happened.
it("logs info message when SOCKS5 credentials get re-encoded", () => {
const debugSpy = vi.spyOn(console, "info").mockImplementation(() => {});
try {
resolveProxyConfig("socks5://user:pass=123@host:1080");
expect(debugSpy).toHaveBeenCalledWith(
@@ -282,7 +282,7 @@ describe("resolveProxyConfig", () => {
});
it("stays silent when SOCKS5 URL is already encoded (no log spam)", () => {
const debugSpy = vi.spyOn(console, "debug").mockImplementation(() => {});
const debugSpy = vi.spyOn(console, "info").mockImplementation(() => {});
try {
resolveProxyConfig("socks5://user:pass%3D123@host:1080");
const reencodedCalls = debugSpy.mock.calls
@@ -295,7 +295,7 @@ describe("resolveProxyConfig", () => {
});
it("stays silent when SOCKS5 URL has no credentials", () => {
const debugSpy = vi.spyOn(console, "debug").mockImplementation(() => {});
const debugSpy = vi.spyOn(console, "info").mockImplementation(() => {});
try {
resolveProxyConfig("socks5://host:1080");
const reencodedCalls = debugSpy.mock.calls
@@ -310,7 +310,7 @@ describe("resolveProxyConfig", () => {
it("stays silent when only host case differs (no credential rewrite)", () => {
// Parity with Python: log condition must track credential changes, not
// cosmetic URL-string differences (regression for Copilot's PR #209 review).
const debugSpy = vi.spyOn(console, "debug").mockImplementation(() => {});
const debugSpy = vi.spyOn(console, "info").mockImplementation(() => {});
try {
resolveProxyConfig("socks5://USER:pass@HOST.com:1080");
const reencodedCalls = debugSpy.mock.calls