forked from wangziqi/gongxue-base
chore: require real data api benchmark evidence
This commit is contained in:
@@ -12,6 +12,21 @@ function isoNow() {
|
||||
return new Date().toISOString();
|
||||
}
|
||||
|
||||
function sampleSummaryValue(expectedValue) {
|
||||
if (!expectedValue || typeof expectedValue !== 'object' || Array.isArray(expectedValue)) return expectedValue;
|
||||
if (Object.prototype.hasOwnProperty.call(expectedValue, 'eq')) return expectedValue.eq;
|
||||
if (Object.prototype.hasOwnProperty.call(expectedValue, 'oneOf')) return expectedValue.oneOf?.[0];
|
||||
if (Object.prototype.hasOwnProperty.call(expectedValue, 'lte')) return expectedValue.lte;
|
||||
if (Object.prototype.hasOwnProperty.call(expectedValue, 'lt')) return Number(expectedValue.lt) - 1;
|
||||
if (Object.prototype.hasOwnProperty.call(expectedValue, 'gte')) return expectedValue.gte;
|
||||
if (Object.prototype.hasOwnProperty.call(expectedValue, 'gt')) return Number(expectedValue.gt) + 1;
|
||||
return expectedValue;
|
||||
}
|
||||
|
||||
function sampleSummary(summarySpec) {
|
||||
return Object.fromEntries(Object.entries(summarySpec || {}).map(([key, value]) => [key, sampleSummaryValue(value)]));
|
||||
}
|
||||
|
||||
function createEvidence(tempDir, overrides = {}) {
|
||||
const artifactDir = path.join(tempDir, 'launch-artifacts');
|
||||
fs.mkdirSync(artifactDir, { recursive: true });
|
||||
@@ -25,7 +40,7 @@ function createEvidence(tempDir, overrides = {}) {
|
||||
command: `npm run ${spec.commandIncludes} -- recorded-for-launch-gate`,
|
||||
completedAt: isoNow(),
|
||||
artifact,
|
||||
summary: { ...spec.summary },
|
||||
summary: sampleSummary(spec.summary),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -105,6 +120,18 @@ assert.ok(
|
||||
'migration profile mismatch should be reported as a blocker',
|
||||
);
|
||||
|
||||
const slowBenchmark = runGate(tempDir => {
|
||||
const evidence = createEvidence(tempDir);
|
||||
const item = evidence.checks.find(check => check.id === 'performance.api-real-data-read');
|
||||
item.summary.p95Ms = 301;
|
||||
return evidence;
|
||||
});
|
||||
assert.notEqual(slowBenchmark.status, 0, 'slow API benchmark should fail launch gate');
|
||||
assert.ok(
|
||||
slowBenchmark.payload.checks?.some(item => item.id === 'check.performance.api-real-data-read.summary' && item.status === 'blocker'),
|
||||
'slow API benchmark should be reported as a blocker',
|
||||
);
|
||||
|
||||
const missingBusinessSampling = runGate(tempDir => {
|
||||
const evidence = createEvidence(tempDir);
|
||||
evidence.checks = evidence.checks.filter(item => item.id !== 'migration.pb-import-sample');
|
||||
|
||||
Reference in New Issue
Block a user