fix: 放宽NapCat验证码日志读取超时

This commit is contained in:
sunlei 2026-06-13 13:40:22 +08:00
parent 292946657c
commit 2c3d2abd95
2 changed files with 33 additions and 1 deletions

View File

@ -492,7 +492,7 @@ docker inspect --format '{{range .Config.Env}}{{println .}}{{end}}' "$NAME"
[...this.getSshArgs(), 'sh -s'],
script,
undefined,
this.getRuntimeCheckTimeoutMs(),
this.getCaptchaLogReadTimeoutMs(),
);
return this.toolsService.extractNapcatCaptchaUrl(result.stdout) || null;
} catch {
@ -1281,6 +1281,10 @@ ${accountRunFlag}${passwordRunFlag} -p "$PORT:6099" \\
return Number.isFinite(timeoutMs) && timeoutMs > 0 ? timeoutMs : 5000;
}
private getCaptchaLogReadTimeoutMs() {
return Math.max(this.getRuntimeCheckTimeoutMs(), 15000);
}
private sh(value: string) {
return `'${`${value}`.replace(/'/g, `'\\''`)}'`;
}

View File

@ -61,4 +61,32 @@ describe('QqbotNapcatContainerService captcha logs', () => {
'https://ti.qq.com/safe/tools/captcha/sms-verify-login?uin=10001&sid=abc',
);
});
it('uses a longer timeout for captcha log reads than the quick runtime check', async () => {
const service = new QqbotNapcatContainerService(
{
get: jest.fn((key: string) =>
key === 'QQBOT_NAPCAT_CONTAINER_MODE' ? 'ssh' : '',
),
} as any,
{ update: jest.fn() } as any,
{} as any,
new ToolsService(),
);
const runProcess = jest.spyOn(service as any, 'runProcess').mockResolvedValue({
stderr: '',
stdout:
'需要验证码, proofWaterUrl: https://ti.qq.com/safe/tools/captcha/sms-verify-login?uin=10001\n',
});
await service.detectRuntimeCaptchaUrl(
{
id: 'container-1',
name: 'napcat-10001',
} as any,
Date.now(),
);
expect(runProcess.mock.calls[0]?.[4]).toBeGreaterThanOrEqual(15000);
});
});