Files
msd-core/scripts/update-size-baseline.cjs
Rezolv 74d7bc8239 test(#1074): add additive per-file workflow size baseline guard (PR 1/3) (#1089)
* test(#1074): add additive per-file workflow size baseline guard (PR 1/3)

Introduces a committed per-file size baseline scheme alongside (not replacing)
the existing tier anti-creep tests. Green by construction — the baseline
records current sizes, so both schemes pass side by side during migration.

- scripts/lib/allowlist-ratchet.cjs: add assertFileBaseline (third pure helper,
  same injected-fail style) — per-file growth/shrink/add/remove diff vs baseline.
- scripts/workflow-size.cjs: single source of truth for LF-normalized byte
  counting (#683) + workflow enumeration, shared by the guard and the generator
  so they can never measure differently. Lives in scripts/ root (NOT scripts/lib/)
  because it is dev/CI-only tooling — scripts/lib/ is bundled into the installed
  runtime, scripts/ root is not, so this keeps it out of the shipped payload.
- scripts/update-size-baseline.cjs + npm run size:baseline: regenerate the
  snapshot (sorted keys, trailing newline, idempotent).
- tests/workflow-size-baseline.json: generated snapshot (88 workflows).
- tests/workflow-size-budget.test.cjs: import the shared counter (drops the
  duplicated local byteCount) and add the per-file baseline describe block.
- Tests for the helper, the shared module, and the generator (incl. round-trip
  and fault-injection cases).

Refs #1074. Part 1 of 3; PR 2 swaps enforcement, PR 3 covers the agent test.

* test(#1074): regenerate workflow baseline after Update-branch merge with next

The 'Update branch' merge (652a916b) pulled in next's update.md change (#1090)
without regenerating the snapshot, leaving the per-file baseline stale by one
file. Re-ran `npm run size:baseline` so the committed baseline matches the
merged workflow files.

Refs #1074.

---------

Co-authored-by: Tom Boucher <trekkie@nomorestars.com>
2026-06-11 23:59:56 -04:00

59 lines
2.0 KiB
JavaScript

#!/usr/bin/env node
'use strict';
/**
* @file update-size-baseline.cjs
*
* Regenerates the committed per-file workflow size baseline
* (`tests/workflow-size-baseline.json`) from the current workflow files.
*
* Run via `npm run size:baseline` whenever a workflow file legitimately grows
* or shrinks. Growth must still be justified in the PR; this script only
* records the new reality so the CI guard (issue #1074) can diff against it.
*
* Idempotent: running it twice with no file changes produces no diff.
*/
const fs = require('fs');
const path = require('path');
const { measureWorkflows, WORKFLOWS_DIR } = require('./workflow-size.cjs');
const BASELINE_PATH = path.join(__dirname, '..', 'tests', 'workflow-size-baseline.json');
/**
* Serialize a size map to the on-disk baseline format: keys sorted, 2-space
* indent, trailing newline (so the file is a stable, minimal-diff artifact).
*
* @param {Object<string, number>} sizes
* @returns {string}
*/
function serializeBaseline(sizes) {
const sorted = {};
for (const key of Object.keys(sizes).sort()) sorted[key] = sizes[key];
return JSON.stringify(sorted, null, 2) + '\n';
}
/**
* Write the baseline file from the measured workflow sizes.
*
* @param {object} [opts]
* @param {string} [opts.dir] - Workflows dir to measure (default canonical).
* @param {string} [opts.outPath] - Baseline file to write (default canonical).
* @returns {{ outPath: string, count: number, content: string }}
*/
function generateBaseline({ dir = WORKFLOWS_DIR, outPath = BASELINE_PATH } = {}) {
const sizes = measureWorkflows(dir);
const content = serializeBaseline(sizes);
fs.writeFileSync(outPath, content);
return { outPath, count: Object.keys(sizes).length, content };
}
if (require.main === module) {
const { outPath, count } = generateBaseline();
process.stdout.write(
`Wrote ${count} workflow sizes to ${path.relative(process.cwd(), outPath)}\n`
);
}
module.exports = { generateBaseline, serializeBaseline, BASELINE_PATH };