The run page mixed English stage events and agent summaries into the Chinese console. Messages are now written in Simplified Chinese at their source (control plane, dispatcher, worker, POC build), keeping commands, SHAs, branches and error codes verbatim; raw runtime errors get a Chinese prefix. The agent prompt asks for the plan, summary and questions in Chinese. File-change parsing accepts old and new messages, and the event label table covers every event kind written. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
97 lines
3.5 KiB
TypeScript
97 lines
3.5 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
||
import { repeat } from '../src/patience.js';
|
||
import { verifyHttpPatiently } from '../src/deploy.js';
|
||
import type { ReleaseManifest } from '../src/types.js';
|
||
|
||
describe('repeating what a flaky link or a settling target can fail', () => {
|
||
it('repeats a failing attempt until it passes, telling about each repeat', async () => {
|
||
const notices: string[] = [];
|
||
let calls = 0;
|
||
const value = await repeat(
|
||
async () => {
|
||
if (++calls < 3) throw new Error(`no answer ${calls}`);
|
||
return 'done';
|
||
},
|
||
{ attempts: 3, delayMs: 1, onRetry: notice => notices.push(notice) },
|
||
{ describe: error => (error as Error).message },
|
||
);
|
||
expect(value).toBe('done');
|
||
expect(notices).toEqual([
|
||
'no answer 1;1 秒后重试(第 2 次,共 3 次)',
|
||
'no answer 2;1 秒后重试(第 3 次,共 3 次)',
|
||
]);
|
||
});
|
||
it('gives up after the last attempt, or at once on a failure it may not repeat', async () => {
|
||
let calls = 0;
|
||
const down = async () => {
|
||
calls++;
|
||
throw new Error('down');
|
||
};
|
||
await expect(repeat(down, { attempts: 3, delayMs: 1 }, { describe: () => 'down' })).rejects.toThrow('down');
|
||
expect(calls).toBe(3);
|
||
calls = 0;
|
||
await expect(
|
||
repeat(down, { attempts: 3, delayMs: 1 }, { describe: () => 'down', retryable: () => false }),
|
||
).rejects.toThrow('down');
|
||
expect(calls).toBe(1);
|
||
});
|
||
it('is not stopped by a notice that cannot be delivered', async () => {
|
||
let calls = 0;
|
||
const value = await repeat(
|
||
async () => {
|
||
if (++calls < 2) throw new Error('blip');
|
||
return calls;
|
||
},
|
||
{
|
||
attempts: 2,
|
||
delayMs: 1,
|
||
onRetry: () => {
|
||
throw new Error('timeline unavailable');
|
||
},
|
||
},
|
||
{ describe: () => 'blip' },
|
||
);
|
||
expect(value).toBe(2);
|
||
});
|
||
it('repeats HTTP checks until they pass, and reports the last failure when they never do', async () => {
|
||
const release: ReleaseManifest = {
|
||
schemaVersion: 1,
|
||
id: 'release',
|
||
tenantId: 'tenant',
|
||
environmentId: 'env',
|
||
sourceCommit: 'a'.repeat(40),
|
||
image: `registry.example/web@sha256:${'b'.repeat(64)}`,
|
||
containerPort: 3000,
|
||
healthPath: '/health',
|
||
smokeChecks: [{ path: '/catalog', expectedStatus: 200 }],
|
||
};
|
||
let health = 0;
|
||
// The first health check meets a dropped connection, the second a target still starting.
|
||
const settling: typeof fetch = async url => {
|
||
if (new URL(String(url)).pathname === '/health' && ++health === 1) throw new TypeError('fetch failed');
|
||
return new Response('ok', { status: health === 2 ? 503 : 200 });
|
||
};
|
||
const patience = { attempts: 3, delayMs: 1 };
|
||
expect(await verifyHttpPatiently(release, 'https://app.example.test/', settling, patience)).toMatchObject({
|
||
passed: true,
|
||
});
|
||
expect(health).toBe(3);
|
||
let calls = 0;
|
||
const broken: typeof fetch = async () => {
|
||
calls++;
|
||
return new Response('', { status: 503 });
|
||
};
|
||
expect(await verifyHttpPatiently(release, 'https://app.example.test/', broken, patience)).toEqual({
|
||
passed: false,
|
||
checks: [],
|
||
reason: 'Health returned 503',
|
||
});
|
||
expect(calls).toBe(patience.attempts);
|
||
// A target address that is not a web address cannot get better.
|
||
await expect(verifyHttpPatiently(release, 'ftp://app.example.test/', broken, patience)).rejects.toMatchObject({
|
||
code: 'INVALID_HEALTH_URL',
|
||
});
|
||
expect(calls).toBe(patience.attempts);
|
||
});
|
||
});
|