mirror of
https://github.com/whyour/qinglong.git
synced 2026-09-23 11:53:48 +08:00
feat(ql3): surface bounded console run logs
This commit is contained in:
@@ -72,6 +72,10 @@ test('loads one bounded offline Console asset closure', () => {
|
||||
);
|
||||
assert.match(text, /authorization: `Bearer \$\{state\.token\}`/u);
|
||||
assert.match(text, /credentials: 'omit'/u);
|
||||
assert.match(text, /attempts\/\$\{attempt\.id\}\/log/u);
|
||||
assert.match(text, /const LOG_READ_BYTES = 32 \* 1024/u);
|
||||
assert.match(text, /new TextDecoder\('utf-8'\)/u);
|
||||
assert.match(text, /日志已按保留策略清理/u);
|
||||
}
|
||||
}
|
||||
assert.ok(totalBytes <= 192 * 1024);
|
||||
|
||||
@@ -33,12 +33,32 @@ function run(overrides = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
function attempt(overrides = {}) {
|
||||
return {
|
||||
id: 'attempt_123',
|
||||
runId: 'run_123',
|
||||
attempt: 2,
|
||||
status: 'running',
|
||||
executorType: 'local_process',
|
||||
executorHandle: 'private-executor-handle',
|
||||
logArtifactId: 'private-log-artifact-id',
|
||||
callbackSequence: 0,
|
||||
createdAtMs: 2_100,
|
||||
startedAtMs: 2_200,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
test('returns the shared bounded Run projection without secret-adjacent fields', async () => {
|
||||
const route = createLocalApiRunReadRoute({
|
||||
async findRunById(runId) {
|
||||
assert.equal(runId, 'run_123');
|
||||
return run({ version: 0 });
|
||||
},
|
||||
async findLatestAttemptByRunId(runId) {
|
||||
assert.equal(runId, 'run_123');
|
||||
return attempt();
|
||||
},
|
||||
});
|
||||
|
||||
const response = await route.handle({
|
||||
@@ -48,6 +68,14 @@ test('returns the shared bounded Run projection without secret-adjacent fields',
|
||||
assert.equal(response.statusCode, 200);
|
||||
assert.equal(response.body.run.projectId, 'prj_default');
|
||||
assert.equal(response.body.run.version, 0);
|
||||
assert.deepEqual(response.body.run.latestAttempt, {
|
||||
id: 'attempt_123',
|
||||
attempt: 2,
|
||||
status: 'running',
|
||||
logAvailable: true,
|
||||
createdAtMs: 2_100,
|
||||
startedAtMs: 2_200,
|
||||
});
|
||||
assert.equal(JSON.stringify(response).includes('private'), false);
|
||||
});
|
||||
|
||||
@@ -57,6 +85,9 @@ test('collapses absent and cross-project Runs and fails closed on repository err
|
||||
async findRunById() {
|
||||
return value;
|
||||
},
|
||||
async findLatestAttemptByRunId() {
|
||||
throw new Error('must not inspect Attempt for an absent Run');
|
||||
},
|
||||
});
|
||||
assert.deepEqual(
|
||||
await route.handle({ projectId: 'prj_default', runId: 'run_123' }),
|
||||
@@ -67,9 +98,45 @@ test('collapses absent and cross-project Runs and fails closed on repository err
|
||||
async findRunById() {
|
||||
throw new Error('database unavailable');
|
||||
},
|
||||
async findLatestAttemptByRunId() {
|
||||
throw new Error('database unavailable');
|
||||
},
|
||||
});
|
||||
assert.deepEqual(
|
||||
await unavailable.handle({ projectId: 'prj_default', runId: 'run_123' }),
|
||||
{ statusCode: 503, body: { code: 'run_query_unavailable' } },
|
||||
);
|
||||
});
|
||||
|
||||
test('returns null without an Attempt and fails closed on invalid Attempt projections', async () => {
|
||||
const withoutAttempt = createLocalApiRunReadRoute({
|
||||
async findRunById() {
|
||||
return run();
|
||||
},
|
||||
async findLatestAttemptByRunId() {
|
||||
return null;
|
||||
},
|
||||
});
|
||||
const response = await withoutAttempt.handle({
|
||||
projectId: 'prj_default',
|
||||
runId: 'run_123',
|
||||
});
|
||||
assert.equal(response.statusCode, 200);
|
||||
assert.equal(response.body.run.latestAttempt, null);
|
||||
|
||||
const invalidAttempt = createLocalApiRunReadRoute({
|
||||
async findRunById() {
|
||||
return run();
|
||||
},
|
||||
async findLatestAttemptByRunId() {
|
||||
return attempt({ runId: 'another_run' });
|
||||
},
|
||||
});
|
||||
assert.deepEqual(
|
||||
await invalidAttempt.handle({
|
||||
projectId: 'prj_default',
|
||||
runId: 'run_123',
|
||||
}),
|
||||
{ statusCode: 503, body: { code: 'run_query_unavailable' } },
|
||||
);
|
||||
});
|
||||
|
||||
@@ -448,6 +448,14 @@ test('serves an authenticated Run through one real SQLite authority and durable
|
||||
assert.equal(accepted.statusCode, 200);
|
||||
assert.equal(accepted.body.run.id, RUN_ID);
|
||||
assert.equal(accepted.body.run.projectId, 'default');
|
||||
assert.deepEqual(accepted.body.run.latestAttempt, {
|
||||
id: ATTEMPT_ID,
|
||||
attempt: 1,
|
||||
status: 'running',
|
||||
logAvailable: true,
|
||||
createdAtMs: NOW - 90,
|
||||
startedAtMs: NOW - 80,
|
||||
});
|
||||
assert.equal(JSON.stringify(accepted).includes('secret'), false);
|
||||
|
||||
const listed = await request(
|
||||
|
||||
Reference in New Issue
Block a user