mirror of
https://github.com/whyour/qinglong.git
synced 2026-09-23 03:18:09 +08:00
feat(ql3): expose cancellation availability summary
This commit is contained in:
@@ -163,6 +163,30 @@ function fixture(role = 'operator', options = {}) {
|
||||
) {
|
||||
return { rows: [], rowCount: 0 };
|
||||
}
|
||||
if (
|
||||
text.includes('FROM "ql3"."run_cancellation_dispatches" AS dispatch')
|
||||
) {
|
||||
return {
|
||||
rows: [
|
||||
{
|
||||
total: '5',
|
||||
pending: '1',
|
||||
leased: '1',
|
||||
retryWait: '1',
|
||||
dispatched: '1',
|
||||
blocked: '1',
|
||||
due: '1',
|
||||
expiredLease: '1',
|
||||
identityMismatch: '1',
|
||||
pidMismatch: '0',
|
||||
unsupported: '0',
|
||||
invalid: '0',
|
||||
oldestBlockedAtMs: String(NOW - 1_500),
|
||||
},
|
||||
],
|
||||
rowCount: 1,
|
||||
};
|
||||
}
|
||||
if (
|
||||
text.startsWith('SELECT attempt_id AS "attemptId"') &&
|
||||
text.includes('FROM "ql3"."run_cancellation_dispatches"') &&
|
||||
@@ -370,6 +394,37 @@ test('allows a viewer to inspect only low-sensitive cancellation state', async (
|
||||
assert.equal(audit.params[0], inspectRequest.auditEventId);
|
||||
});
|
||||
|
||||
test('allows a viewer to summarize Project cancellation availability atomically', async () => {
|
||||
const { calls, service } = fixture('viewer');
|
||||
const summaryRequest = {
|
||||
projectId: 'project-1',
|
||||
requestId: 'request-summary-1',
|
||||
auditEventId: '019f9500-0000-4000-8000-000000000061',
|
||||
failureAuditEventId: '019f9500-0000-4000-8000-000000000062',
|
||||
principal: request().principal,
|
||||
};
|
||||
const result = await service.summarizeCancellation(summaryRequest);
|
||||
assert.equal(result.assessment, 'attention_required');
|
||||
assert.equal(result.operatorAction, 'inspect');
|
||||
assert.equal(result.dispatches.blocked, 1);
|
||||
assert.equal(result.blockingResults.identityMismatch, 1);
|
||||
assert.equal(Object.hasOwn(result, 'runId'), false);
|
||||
assert.equal(JSON.stringify(result).includes('attemptId'), false);
|
||||
const aggregate = calls.find(({ sql }) =>
|
||||
sql.includes('FROM "ql3"."run_cancellation_dispatches" AS dispatch'),
|
||||
);
|
||||
assert.deepEqual(aggregate.params, ['project-1', NOW]);
|
||||
const audit = calls.find(
|
||||
({ sql, params }) =>
|
||||
sql.startsWith('INSERT INTO "ql3"."security_audit_events"') &&
|
||||
params[2] === 'run.cancellation.summary',
|
||||
);
|
||||
assert.equal(audit.params[0], summaryRequest.auditEventId);
|
||||
assert.ok(
|
||||
calls.indexOf(audit) < calls.findIndex(({ sql }) => sql === 'COMMIT'),
|
||||
);
|
||||
});
|
||||
|
||||
test('authorizes exact cancellation rearm and keeps the event identity server-side', async () => {
|
||||
const { calls, service } = fixture();
|
||||
const rearmRequest = {
|
||||
|
||||
@@ -132,6 +132,20 @@ const inspectCommand = normalizeClusterRunManagementCommand({
|
||||
},
|
||||
});
|
||||
|
||||
const summaryCommand = normalizeClusterRunManagementCommand({
|
||||
schemaVersion: 1,
|
||||
operation: 'run.cancellation.summary',
|
||||
request: {
|
||||
projectId: 'project-1',
|
||||
requestId: 'request-summary-1',
|
||||
auditEventId: '019f9400-0000-4000-8000-000000000051',
|
||||
failureAuditEventId: '019f9400-0000-4000-8000-000000000052',
|
||||
body: {
|
||||
schema: 'qinglong/run-cancellation-dispatch-summary-request@v1',
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const rearmCommand = normalizeClusterRunManagementCommand({
|
||||
schemaVersion: 1,
|
||||
operation: 'run.cancellation.rearm',
|
||||
@@ -310,6 +324,67 @@ test('validates a low-sensitive cancellation diagnostic and rejects capability l
|
||||
}
|
||||
});
|
||||
|
||||
test('validates the fixed low-sensitive Project cancellation summary', () => {
|
||||
const value = {
|
||||
schemaVersion: 1,
|
||||
operation: 'run.cancellation.summary',
|
||||
summary: {
|
||||
schema: 'qinglong/run-cancellation-dispatch-summary@v1',
|
||||
projectId: 'project-1',
|
||||
observedAtMs: 1_000_000,
|
||||
assessment: 'attention_required',
|
||||
operatorAction: 'inspect',
|
||||
dispatches: {
|
||||
total: 5,
|
||||
pending: 1,
|
||||
leased: 1,
|
||||
retryWait: 1,
|
||||
dispatched: 1,
|
||||
blocked: 1,
|
||||
},
|
||||
signals: { due: 1, expiredLease: 1 },
|
||||
blockingResults: {
|
||||
identityMismatch: 1,
|
||||
pidMismatch: 0,
|
||||
unsupported: 0,
|
||||
invalid: 0,
|
||||
},
|
||||
oldestBlockedAtMs: 999_200,
|
||||
},
|
||||
};
|
||||
assert.deepEqual(
|
||||
validateClusterRunManagementClientResult(value, summaryCommand),
|
||||
value,
|
||||
);
|
||||
for (const summary of [
|
||||
{ ...value.summary, projectId: 'project-2' },
|
||||
{ ...value.summary, assessment: 'clear' },
|
||||
{ ...value.summary, operatorAction: 'wait' },
|
||||
{
|
||||
...value.summary,
|
||||
dispatches: { ...value.summary.dispatches, total: 6 },
|
||||
},
|
||||
{
|
||||
...value.summary,
|
||||
blockingResults: {
|
||||
...value.summary.blockingResults,
|
||||
identityMismatch: 0,
|
||||
},
|
||||
},
|
||||
{ ...value.summary, oldestBlockedAtMs: 1_000_001 },
|
||||
{ ...value.summary, runId: 'run-1' },
|
||||
]) {
|
||||
assert.throws(
|
||||
() =>
|
||||
validateClusterRunManagementClientResult(
|
||||
{ ...value, summary },
|
||||
summaryCommand,
|
||||
),
|
||||
ClusterPluginPackageManagementClientRequestError,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('binds a rearm receipt to the exact dispatch version, result and delay fences', () => {
|
||||
const value = {
|
||||
schemaVersion: 1,
|
||||
|
||||
@@ -119,6 +119,31 @@ function diagnosticResult() {
|
||||
};
|
||||
}
|
||||
|
||||
function summaryResult() {
|
||||
return {
|
||||
projectId: 'project-1',
|
||||
observedAtMs: NOW,
|
||||
assessment: 'attention_required',
|
||||
operatorAction: 'inspect',
|
||||
dispatches: {
|
||||
total: 5,
|
||||
pending: 1,
|
||||
leased: 1,
|
||||
retryWait: 1,
|
||||
dispatched: 1,
|
||||
blocked: 1,
|
||||
},
|
||||
signals: { due: 1, expiredLease: 1 },
|
||||
blockingResults: {
|
||||
identityMismatch: 1,
|
||||
pidMismatch: 0,
|
||||
unsupported: 0,
|
||||
invalid: 0,
|
||||
},
|
||||
oldestBlockedAtMs: NOW - 800,
|
||||
};
|
||||
}
|
||||
|
||||
function rearmResult() {
|
||||
return {
|
||||
status: 'rearmed',
|
||||
@@ -153,6 +178,23 @@ function inspectCommand(overrides = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
function summaryCommand(overrides = {}) {
|
||||
return {
|
||||
schemaVersion: 1,
|
||||
operation: 'run.cancellation.summary',
|
||||
request: {
|
||||
projectId: 'project-1',
|
||||
requestId: 'request-summary-1',
|
||||
auditEventId: '019f9300-0000-4000-8000-000000000051',
|
||||
failureAuditEventId: '019f9300-0000-4000-8000-000000000052',
|
||||
body: {
|
||||
schema: 'qinglong/run-cancellation-dispatch-summary-request@v1',
|
||||
},
|
||||
...overrides,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function rearmCommand(overrides = {}) {
|
||||
return {
|
||||
schemaVersion: 1,
|
||||
@@ -187,6 +229,9 @@ test('routes one exact strong User retry and emits the shared response', async (
|
||||
async stop() {
|
||||
return stopResult();
|
||||
},
|
||||
async summarizeCancellation() {
|
||||
return summaryResult();
|
||||
},
|
||||
async inspectCancellation() {
|
||||
return diagnosticResult();
|
||||
},
|
||||
@@ -223,6 +268,9 @@ test('routes one exact strong User stop and emits the shared response', async ()
|
||||
calls.push(request);
|
||||
return stopResult();
|
||||
},
|
||||
async summarizeCancellation() {
|
||||
return summaryResult();
|
||||
},
|
||||
async inspectCancellation() {
|
||||
return diagnosticResult();
|
||||
},
|
||||
@@ -259,6 +307,9 @@ test('rejects weak or non-User identity before service authority', async () => {
|
||||
async stop() {
|
||||
return stopResult();
|
||||
},
|
||||
async summarizeCancellation() {
|
||||
return summaryResult();
|
||||
},
|
||||
async inspectCancellation() {
|
||||
return diagnosticResult();
|
||||
},
|
||||
@@ -290,6 +341,7 @@ test('routes bounded cancellation inspection without lease capability data', asy
|
||||
service: {
|
||||
async retry() { return retryResult(); },
|
||||
async stop() { return stopResult(); },
|
||||
async summarizeCancellation() { return summaryResult(); },
|
||||
async inspectCancellation(request) {
|
||||
calls.push(request);
|
||||
return diagnosticResult();
|
||||
@@ -313,6 +365,39 @@ test('routes bounded cancellation inspection without lease capability data', asy
|
||||
assert.equal(JSON.stringify(result).includes('leaseToken'), false);
|
||||
});
|
||||
|
||||
test('routes one Project-scoped cancellation summary without Run identity', async () => {
|
||||
const calls = [];
|
||||
const transport = createClusterRunManagementTransport({
|
||||
now: () => NOW,
|
||||
service: {
|
||||
async retry() { return retryResult(); },
|
||||
async stop() { return stopResult(); },
|
||||
async summarizeCancellation(request) {
|
||||
calls.push(request);
|
||||
return summaryResult();
|
||||
},
|
||||
async inspectCancellation() { return diagnosticResult(); },
|
||||
async rearmCancellation() { return rearmResult(); },
|
||||
},
|
||||
});
|
||||
const result = await transport.execute(summaryCommand(), {
|
||||
authenticate: async () => principal(),
|
||||
});
|
||||
assert.equal(calls.length, 1);
|
||||
assert.equal(calls[0].projectId, 'project-1');
|
||||
assert.equal(Object.hasOwn(calls[0], 'runId'), false);
|
||||
assert.deepEqual(result, {
|
||||
schemaVersion: 1,
|
||||
operation: 'run.cancellation.summary',
|
||||
summary: {
|
||||
schema: 'qinglong/run-cancellation-dispatch-summary@v1',
|
||||
...summaryResult(),
|
||||
},
|
||||
});
|
||||
assert.equal(JSON.stringify(result).includes('attemptId'), false);
|
||||
assert.equal(JSON.stringify(result).includes('leaseOwner'), false);
|
||||
});
|
||||
|
||||
test('routes an exact blocked cancellation rearm receipt', async () => {
|
||||
const calls = [];
|
||||
const transport = createClusterRunManagementTransport({
|
||||
@@ -320,6 +405,7 @@ test('routes an exact blocked cancellation rearm receipt', async () => {
|
||||
service: {
|
||||
async retry() { return retryResult(); },
|
||||
async stop() { return stopResult(); },
|
||||
async summarizeCancellation() { return summaryResult(); },
|
||||
async inspectCancellation() { return diagnosticResult(); },
|
||||
async rearmCancellation(request) {
|
||||
calls.push(request);
|
||||
|
||||
Reference in New Issue
Block a user