Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | 2x 5x 5x 5x 5x 35x 35x 5x 35x 35x 5x 4x 21x 3x 21x 3x 21x 21x 21x 21x 3x 3x 3x 3x 21x 54x 102x 6x 6x 6x 6x 6x 6x 6x 36x 141x 36x 36x 36x 36x 36x 36x 36x 1x 35x 35x 30x 30x 30x 5x 5x 35x 5x 35x 6x 6x 6x 6x 6x 6x 6x 6x 5x 5x 5x 5x 84x 21x 84x 21x 84x 5x 5x | import fs from 'fs-extra';
import path from 'node:path';
import { CORE_CSS_ARTIFACTS } from './core-css-artifacts.js';
import {
classifyCoreCssArtifacts,
hashCoreCss,
normalizeCoreCssStamp,
validateCoreCssArtifactSet,
} from './core-css-classifier.js';
import generateCoreCss from './generate-core-css.js';
import {
buildReport,
compareAllFiles,
writeHtmlDiffFiles,
writeReportFiles,
} from '../validation/compare-output-core.js';
import { compareFiles, findFiles } from '../validation/lib/file-utils.js';
import {
generateHtmlDiff,
generateIndexHtml,
generateTextReport,
} from '../validation/lib/html-report.js';
import cssAnalyzer from '../validation/plugins/css-analyzer.js';
const SCHEMA_VERSION = 1;
function createUniqueReportDir(reportRoot, timestamp, sourceSha) {
fs.ensureDirSync(reportRoot);
const prefix = `${timestamp.toISOString().replace(/[:.]/g, '-')}_${sourceSha.slice(0, 12)}_`;
return fs.mkdtempSync(path.join(reportRoot, prefix));
}
function writeArtifactSet(root, artifacts, pathKey) {
for (const artifact of artifacts) {
fs.outputFileSync(path.join(root, artifact[pathKey]), artifact.content);
}
}
function readCandidateArtifacts(candidateDir) {
const expectedPaths = new Set(CORE_CSS_ARTIFACTS.map(({ candidatePath }) => candidatePath));
const actualPaths = findFiles(candidateDir);
const missing = [...expectedPaths].filter((file) => !actualPaths.includes(file));
const extra = actualPaths.filter((file) => !expectedPaths.has(file));
if (missing.length > 0) throw new Error(`Candidate output is missing: ${missing.join(', ')}`);
if (extra.length > 0) throw new Error(`Candidate output has unexpected files: ${extra.join(', ')}`);
return CORE_CSS_ARTIFACTS.map((artifact) => ({
id: artifact.id,
path: artifact.gitcorePath,
content: fs.readFileSync(path.join(candidateDir, artifact.candidatePath)),
}));
}
function createStampNormalizer(baselineDir) {
const artifactByPath = new Map(
CORE_CSS_ARTIFACTS.map((artifact) => [path.join(baselineDir, artifact.gitcorePath), artifact]),
);
return (baseline, current, baselinePath) => {
const artifact = artifactByPath.get(baselinePath);
Iif (!artifact) return null;
return {
baseline: normalizeCoreCssStamp(Buffer.from(baseline), artifact.id).toString('utf8'),
current: normalizeCoreCssStamp(Buffer.from(current), artifact.id).toString('utf8'),
};
};
}
function writeComparisonReport({ reportDir, baselineDir, candidateDir, timestamp, sourceSha }) {
const allFiles = new Set(CORE_CSS_ARTIFACTS.map(({ gitcorePath }) => gitcorePath));
const { results, counts } = compareAllFiles({
allFiles,
baselineFilesDir: baselineDir,
sourceDir: candidateDir,
compareFiles,
beforeCompareHooks: [createStampNormalizer(baselineDir)],
afterCompareHooks: [cssAnalyzer.afterCompare],
log: () => {},
});
const report = buildReport({
name: 'Core CSS release preparation',
timestamp,
shortSha: sourceSha.slice(0, 12),
baselineDir,
sourceDir: candidateDir,
results,
counts,
});
writeReportFiles({ reportDir, report, generateTextReport, generateIndexHtml });
writeHtmlDiffFiles({
filesWithDiffs: results.filter(({ status }) => status !== 'identical'),
reportDir,
name: report.name,
generateHtmlDiff,
log: () => {},
});
}
function assertNonEmpty(value, label) {
Iif (typeof value !== 'string' || value.length === 0) {
throw new Error(`Baseline provenance ${label} must be nonempty`);
}
}
function assertSize(value, label) {
Iif (!Number.isSafeInteger(value) || value < 0) {
throw new Error(`Baseline provenance ${label} must be a nonnegative safe integer`);
}
}
function validateBaselineProvenance(baseline, baselineById) {
Iif (!baseline || typeof baseline !== 'object') {
throw new Error('Baseline provenance is required');
}
assertNonEmpty(baseline.repo, 'repo');
assertNonEmpty(baseline.target, 'target');
assertNonEmpty(baseline.baseSha, 'baseSha');
Iif (!Array.isArray(baseline.artifacts) || baseline.artifacts.length !== CORE_CSS_ARTIFACTS.length) {
throw new Error(`Baseline provenance must contain exactly ${CORE_CSS_ARTIFACTS.length} artifacts`);
}
const provenanceById = new Map();
for (const provenance of baseline.artifacts) {
Iif (provenanceById.has(provenance.id)) {
throw new Error(`Baseline provenance has duplicate artifact id: ${provenance.id}`);
}
const manifest = CORE_CSS_ARTIFACTS.find(({ id }) => id === provenance.id);
Iif (!manifest) throw new Error(`Baseline provenance has unexpected artifact: ${provenance.id}`);
Iif (provenance.path !== manifest.gitcorePath || provenance.storage !== manifest.storage) {
throw new Error(`Baseline provenance manifest mismatch for ${provenance.id}`);
}
assertNonEmpty(provenance.gitBlobSha, `${provenance.id}.gitBlobSha`);
assertSize(provenance.gitBlobSize, `${provenance.id}.gitBlobSize`);
assertSize(provenance.apiSize, `${provenance.id}.apiSize`);
const artifact = baselineById.get(provenance.id);
if (provenance.apiSize !== artifact.content.length) {
throw new Error(`Baseline provenance apiSize mismatch for ${provenance.id}`);
}
const baselineSha256 = hashCoreCss(artifact.content);
if (manifest.storage === 'lfs') {
Iif (!/^[a-f0-9]{64}$/.test(provenance.lfsOid || '')) {
throw new Error(`Baseline provenance lfsOid is required for ${provenance.id}`);
}
assertSize(provenance.lfsSize, `${provenance.id}.lfsSize`);
Iif (
provenance.lfsOid !== baselineSha256 ||
provenance.lfsSize !== artifact.content.length ||
provenance.lfsSize !== provenance.apiSize
) {
throw new Error(`Baseline provenance LFS mismatch for ${provenance.id}`);
}
} else {
Iif (provenance.lfsOid !== undefined || provenance.lfsSize !== undefined) {
throw new Error(`Baseline provenance LFS fields are invalid for ${provenance.id}`);
}
Iif (provenance.gitBlobSize !== artifact.content.length) {
throw new Error(`Baseline provenance gitBlobSize mismatch for ${provenance.id}`);
}
}
provenanceById.set(provenance.id, provenance);
}
return {
repo: baseline.repo,
target: baseline.target,
baseSha: baseline.baseSha,
artifacts: CORE_CSS_ARTIFACTS.map(({ id }) => ({ ...provenanceById.get(id) })),
};
}
export async function prepareCoreCssRelease({
baselineArtifacts,
baseline,
distPath,
reportRoot,
version,
sourceSha,
now = () => new Date(),
generateFn = generateCoreCss,
}) {
const baselineById = validateCoreCssArtifactSet(baselineArtifacts, 'baseline artifact set');
const validatedBaseline = validateBaselineProvenance(baseline, baselineById);
const timestamp = now();
const reportDir = createUniqueReportDir(reportRoot, timestamp, sourceSha);
const baselineDir = path.join(reportDir, 'baseline');
const candidateDir = path.join(reportDir, 'candidate');
writeArtifactSet(baselineDir, [...baselineById.values()], 'path');
const metadata = await generateFn({
distPath,
distCorePath: candidateDir,
buildInfo: { version, SHA: sourceSha },
silent: true,
});
const candidateArtifacts = readCandidateArtifacts(candidateDir);
const classification = classifyCoreCssArtifacts(baselineArtifacts, candidateArtifacts);
writeComparisonReport({ reportDir, baselineDir, candidateDir, timestamp, sourceSha });
const result = {
schemaVersion: SCHEMA_VERSION,
version,
sourceSha,
parserVersion: metadata.parserVersion,
verdict: classification.verdict,
reportDir,
baseline: validatedBaseline,
artifacts: classification.artifacts.map((artifact) => {
const manifest = CORE_CSS_ARTIFACTS.find(({ id }) => id === artifact.id);
const baseline = baselineById.get(artifact.id).content;
const candidate = candidateArtifacts.find(({ id }) => id === artifact.id).content;
return {
...artifact,
storage: manifest.storage,
...validatedBaseline.artifacts.find(({ id }) => id === artifact.id),
baselineSize: baseline.length,
candidateSize: candidate.length,
};
}),
};
fs.writeJsonSync(path.join(reportDir, 'result.json'), result, { spaces: 2 });
return result;
}
export default prepareCoreCssRelease;
|