test: scaffold WP7-05 candidate UI gate
Dada P0-A isolated Windows CI / validate-and-package (push) Failing after 2m18s
Dada P0-A isolated Windows CI / validate-and-package (push) Failing after 2m18s
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import fs from 'node:fs';
|
||||
|
||||
export const REQUIRED_COVERAGE_UNITS = Object.freeze([
|
||||
'support-gate', 'user-auth', 'workspace', 'current-task', 'projects',
|
||||
'project-detail', 'editor', 'export', 'credits', 'settings',
|
||||
'preview-user-variant', 'admin-auth', 'admin-overview', 'admin-users',
|
||||
'admin-invites', 'admin-models', 'admin-assets', 'admin-preview',
|
||||
'admin-generations', 'admin-services-storage', 'admin-audit', 'system-ui',
|
||||
]);
|
||||
|
||||
const REQUIRED_VIEWPORTS = Object.freeze([
|
||||
{ width: 1920, height: 1080, deviceScaleFactor: 1, zoom: 100 },
|
||||
{ width: 1920, height: 1080, deviceScaleFactor: 1, zoom: 200 },
|
||||
]);
|
||||
|
||||
function blocked(code, details = {}) {
|
||||
return { status: 'externally_blocked', code, ...details };
|
||||
}
|
||||
|
||||
export function loadCandidateRecord(path) {
|
||||
if (!path || !fs.existsSync(path)) return blocked('candidate_record_missing');
|
||||
try {
|
||||
const record = JSON.parse(fs.readFileSync(path, 'utf8'));
|
||||
if (!Array.isArray(record.browsers) || record.browsers.length !== 2) {
|
||||
return blocked('candidate_browser_record_incomplete');
|
||||
}
|
||||
const names = new Set(record.browsers.map((browser) => browser.name));
|
||||
if (names.size !== 2 || !names.has('Chrome') || !names.has('Edge')) {
|
||||
return blocked('candidate_browser_pair_invalid');
|
||||
}
|
||||
if (record.windows?.build == null || !record.artifact?.sha256 || !record.fixed_port) {
|
||||
return blocked('candidate_identity_incomplete');
|
||||
}
|
||||
if (record.browsers.some((browser) => !browser.full_version || !browser.major)) {
|
||||
return blocked('candidate_full_version_missing');
|
||||
}
|
||||
return { status: 'ready', record };
|
||||
} catch {
|
||||
return blocked('candidate_record_invalid');
|
||||
}
|
||||
}
|
||||
|
||||
export function validateCoverageEvidence(evidence) {
|
||||
if (!evidence || !Array.isArray(evidence.coverage_units)) {
|
||||
return blocked('coverage_evidence_missing');
|
||||
}
|
||||
const actual = new Set(evidence.coverage_units.map((unit) => unit.page_id));
|
||||
const missing = REQUIRED_COVERAGE_UNITS.filter((unit) => !actual.has(unit));
|
||||
if (missing.length) return blocked('coverage_units_incomplete', { missing });
|
||||
const viewportKeys = new Set((evidence.viewports ?? []).map((viewport) => JSON.stringify(viewport)));
|
||||
const missingViewports = REQUIRED_VIEWPORTS.filter((viewport) => !viewportKeys.has(JSON.stringify(viewport)));
|
||||
if (missingViewports.length) return blocked('candidate_viewports_incomplete', { missingViewports });
|
||||
return { status: 'ready' };
|
||||
}
|
||||
|
||||
export function runWp705Gate({ candidatePath, evidence, dependencies = {} }) {
|
||||
const candidate = loadCandidateRecord(candidatePath);
|
||||
if (candidate.status !== 'ready') return candidate;
|
||||
const coverage = validateCoverageEvidence(evidence);
|
||||
if (coverage.status !== 'ready') return coverage;
|
||||
const externalBlockers = Object.entries(dependencies)
|
||||
.filter(([, status]) => status === 'externally_blocked')
|
||||
.map(([task]) => task);
|
||||
if (externalBlockers.length) return blocked('upstream_external_blocked', { externalBlockers });
|
||||
return { status: 'ready_for_execution' };
|
||||
}
|
||||
Reference in New Issue
Block a user