chore(#192): retire sdk release pipeline seam
This commit is contained in:
@@ -1,293 +0,0 @@
|
||||
/**
|
||||
* Regression test for bug #2966
|
||||
*
|
||||
* The release-sdk hotfix workflow's auto_cherry_pick loop aborts when a
|
||||
* `fix:`/`chore:` commit's patch is rooted in code that doesn't exist at
|
||||
* the hotfix's base tag (e.g. the surrounding block was added later in a
|
||||
* feat/refactor commit excluded by the filter). The conflict is
|
||||
* unresolvable — the patch literally cannot be applied to a tree that
|
||||
* lacks the surrounding infrastructure — but the workflow treats it as
|
||||
* an operator-resolvable conflict and exits.
|
||||
*
|
||||
* Fix: after `git cherry-pick` exits non-zero, inspect each unmerged
|
||||
* file's conflict markers. If every conflict block in every file has an
|
||||
* empty `<<<<<<< HEAD ... =======` HEAD section, run `git cherry-pick
|
||||
* --skip` and add the SHA to the skipped list with reason
|
||||
* "context absent at base". Else, fall through to the existing abort/
|
||||
* push-partial/error path.
|
||||
*
|
||||
* This test asserts both:
|
||||
* 1. Static — the auto_cherry_pick loop in release-sdk.yml carries the
|
||||
* context-missing detection (matching `git cherry-pick --skip` and
|
||||
* `context absent at base` semantics) so the no-source-grep static
|
||||
* check is still meaningful for future edits.
|
||||
* 2. Behavioral — using a synthetic git repo that reproduces the exact
|
||||
* shape of the failure on origin/main:
|
||||
* a. A patch whose target context doesn't exist at base produces
|
||||
* empty-HEAD conflict markers AND a non-zero exit from
|
||||
* cherry-pick. (Proves the bug premise.)
|
||||
* b. The `awk` predicate in the workflow correctly classifies the
|
||||
* empty-HEAD case as "context-missing" (skippable) and the
|
||||
* both-sides-have-content case as "real" (must abort).
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// allow-test-rule: source-text-is-the-product
|
||||
// release-sdk.yml IS the product for hotfix automation; GitHub Actions
|
||||
// executes the YAML's shell verbatim. The static check uses structured
|
||||
// extraction (extractStepRun) rather than raw-text grep, scoped to the
|
||||
// "Prepare hotfix branch" step's run block.
|
||||
|
||||
const { describe, test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
|
||||
const WORKFLOW_PATH = path.join(__dirname, '..', '.github', 'workflows', 'release-sdk.yml');
|
||||
|
||||
/**
|
||||
* Extract the `run:` literal block of a named step from a GitHub Actions
|
||||
* workflow using indentation-aware parsing — no raw-text grep across the
|
||||
* whole document. Walks lines once, recognises `- name:` step headers and
|
||||
* `run: |` literal-block markers, and returns the unindented script body.
|
||||
*
|
||||
* No YAML library is used; the repo has none in dependencies and adding
|
||||
* one for a single test isn't justified.
|
||||
*/
|
||||
function extractStepRun(workflowText, stepName) {
|
||||
// CRLF-tolerant split: Windows checkout (autocrlf=true) leaves trailing
|
||||
// \r on every line which downstream regex anchors don't tolerate.
|
||||
const lines = workflowText.split(/\r?\n/);
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const m = lines[i].match(/^(\s*)- name:\s*(.+?)\s*$/);
|
||||
if (!m || m[2] !== stepName) continue;
|
||||
const stepIndent = m[1].length;
|
||||
let j = i + 1;
|
||||
while (j < lines.length) {
|
||||
const peek = lines[j];
|
||||
if (/^\s*- /.test(peek)) {
|
||||
const peekIndent = peek.match(/^(\s*)/)[1].length;
|
||||
if (peekIndent <= stepIndent) break;
|
||||
}
|
||||
const runMatch = peek.match(/^(\s*)run:\s*\|(?:[+-])?\s*$/);
|
||||
if (runMatch) {
|
||||
const blockIndent = runMatch[1].length + 2;
|
||||
const body = [];
|
||||
for (let k = j + 1; k < lines.length; k++) {
|
||||
const bodyLine = lines[k];
|
||||
if (bodyLine.length === 0) {
|
||||
body.push('');
|
||||
continue;
|
||||
}
|
||||
const lead = bodyLine.match(/^(\s*)/)[1].length;
|
||||
if (lead < blockIndent && bodyLine.trim() !== '') break;
|
||||
body.push(bodyLine.slice(blockIndent));
|
||||
}
|
||||
return body.join('\n');
|
||||
}
|
||||
j++;
|
||||
}
|
||||
throw new Error(`step "${stepName}" found but no run: | block before step end`);
|
||||
}
|
||||
throw new Error(`step "${stepName}" not found in workflow`);
|
||||
}
|
||||
|
||||
function git(cwd, args) {
|
||||
// Force-disable signing inline — a developer's global gpgsign config
|
||||
// can't be allowed to fail commits in this throwaway repo. Also pin
|
||||
// merge.conflictStyle=merge so the cherry-pick reproducer below sees
|
||||
// the same marker shape the workflow guards against (diff3/zdiff3 in
|
||||
// the developer or CI runner's global config would inject `|||||||`
|
||||
// sections and break the empty-HEAD assertion).
|
||||
const inlineConfig = [
|
||||
'-c', 'commit.gpgsign=false',
|
||||
'-c', 'tag.gpgsign=false',
|
||||
'-c', 'gpg.format=openpgp',
|
||||
'-c', 'user.signingkey=',
|
||||
'-c', 'merge.conflictStyle=merge',
|
||||
];
|
||||
return spawnSync('git', [...inlineConfig, ...args], {
|
||||
cwd,
|
||||
encoding: 'utf8',
|
||||
env: { ...process.env, GIT_AUTHOR_NAME: 'test', GIT_AUTHOR_EMAIL: 't@t', GIT_COMMITTER_NAME: 'test', GIT_COMMITTER_EMAIL: 't@t' },
|
||||
});
|
||||
}
|
||||
|
||||
describe('bug-2966: release-sdk hotfix cherry-pick classifies context-missing vs real conflicts for skip-reason annotation', () => {
|
||||
test('Prepare hotfix branch step classifies and annotates context-missing conflicts', () => {
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
|
||||
// The loop must detect unmerged paths after a failed cherry-pick.
|
||||
assert.match(
|
||||
script,
|
||||
/git diff --name-only --diff-filter=U/,
|
||||
'auto_cherry_pick must read the unmerged path list after a failed cherry-pick to classify the conflict (#2966)'
|
||||
);
|
||||
// The empty-HEAD-section detector must be present.
|
||||
assert.match(
|
||||
script,
|
||||
/<<<<<<< /,
|
||||
'auto_cherry_pick must inspect conflict markers to classify context-missing vs real conflicts (#2966)'
|
||||
);
|
||||
// The skip path must call `git cherry-pick --skip` so the loop continues
|
||||
// past commits whose target context doesn't exist at the base tag.
|
||||
assert.match(
|
||||
script,
|
||||
/git cherry-pick --skip/,
|
||||
'auto_cherry_pick must invoke `git cherry-pick --skip` for context-missing conflicts so they don\'t brick the run (#2966)'
|
||||
);
|
||||
// The skipped list must annotate the reason so operators see it in the
|
||||
// run summary (not silently disappear).
|
||||
assert.match(
|
||||
script,
|
||||
/context absent at base/,
|
||||
'auto_cherry_pick must annotate skipped picks with "context absent at base" so the run summary surfaces them (#2966)'
|
||||
);
|
||||
// The cherry-pick must pin merge.conflictStyle=merge so the awk
|
||||
// classifier sees deterministic marker shapes regardless of the
|
||||
// runner's git config (diff3/zdiff3 would inject `||||||| ancestor`
|
||||
// lines into the HEAD section and misclassify context-missing
|
||||
// conflicts as real ones).
|
||||
assert.match(
|
||||
script,
|
||||
/git -c merge\.conflictStyle=merge cherry-pick/,
|
||||
'auto_cherry_pick must pin `merge.conflictStyle=merge` on the cherry-pick command so marker parsing is deterministic across runner git configs (#2966)'
|
||||
);
|
||||
});
|
||||
|
||||
test('cherry-pick of a patch whose target section is absent at base produces empty-HEAD conflict markers and exits non-zero', () => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'bug-2966-ctx-missing-'));
|
||||
try {
|
||||
assert.equal(git(tmp, ['init', '-q', '-b', 'main']).status, 0, 'git init');
|
||||
|
||||
// Base — file exists but does NOT contain the section the patch will modify.
|
||||
fs.mkdirSync(path.join(tmp, '.github', 'workflows'), { recursive: true });
|
||||
fs.writeFileSync(path.join(tmp, '.github/workflows/x.yml'), 'name: base\njobs:\n release:\n runs-on: ubuntu-latest\n');
|
||||
assert.equal(git(tmp, ['add', '.']).status, 0, 'git add base');
|
||||
assert.equal(git(tmp, ['commit', '-q', '-m', 'base']).status, 0, 'commit base');
|
||||
assert.equal(git(tmp, ['tag', 'v0.0.0']).status, 0, 'tag base');
|
||||
|
||||
// feat (excluded by fix/chore filter) — adds the prepare block.
|
||||
fs.writeFileSync(path.join(tmp, '.github/workflows/x.yml'),
|
||||
'name: base\njobs:\n prepare:\n run: |\n git cherry-pick -x "$SHA"\n release:\n runs-on: ubuntu-latest\n');
|
||||
assert.equal(git(tmp, ['commit', '-qam', 'feat: add prepare block']).status, 0, 'commit feat');
|
||||
|
||||
// fix — modifies the line inside the prepare block.
|
||||
const yaml = fs.readFileSync(path.join(tmp, '.github/workflows/x.yml'), 'utf8')
|
||||
.replace('git cherry-pick -x "$SHA"', 'git cherry-pick -x --allow-empty "$SHA"');
|
||||
fs.writeFileSync(path.join(tmp, '.github/workflows/x.yml'), yaml);
|
||||
assert.equal(git(tmp, ['commit', '-qam', 'fix: tweak cherry-pick']).status, 0, 'commit fix');
|
||||
const fixSha = git(tmp, ['rev-parse', 'HEAD']).stdout.trim();
|
||||
|
||||
// Cherry-pick fix onto v0.0.0 — must conflict because target context isn't there.
|
||||
assert.equal(git(tmp, ['checkout', '-q', '-b', 'hotfix', 'v0.0.0']).status, 0, 'checkout hotfix');
|
||||
const pick = git(tmp, ['cherry-pick', '-x', '--allow-empty', '--keep-redundant-commits', fixSha]);
|
||||
assert.notEqual(
|
||||
pick.status,
|
||||
0,
|
||||
'cherry-pick of a patch whose target section is absent at base MUST exit non-zero (the bug premise: workflow currently treats this as a real conflict and aborts) (#2966)'
|
||||
);
|
||||
|
||||
// Confirm conflict markers exist and the HEAD section is empty in every block.
|
||||
const conflicted = fs.readFileSync(path.join(tmp, '.github/workflows/x.yml'), 'utf8');
|
||||
assert.match(conflicted, /<<<<<<< /, 'conflict markers must be written to the file');
|
||||
// Every <<<<<<< HEAD ... ======= block must have empty HEAD content.
|
||||
const blocks = [];
|
||||
let inHead = false;
|
||||
let head = '';
|
||||
for (const rawLine of conflicted.split(/\r?\n/)) {
|
||||
// Strip residual \r so /^=======$/ matches even on CRLF content.
|
||||
const line = rawLine.replace(/\r$/, '');
|
||||
if (/^<<<<<<< /.test(line)) { inHead = true; head = ''; continue; }
|
||||
if (/^=======$/.test(line) && inHead) { inHead = false; continue; }
|
||||
if (/^>>>>>>> /.test(line)) { blocks.push(head); head = ''; continue; }
|
||||
if (inHead) head += line + '\n';
|
||||
}
|
||||
assert.ok(blocks.length > 0, 'expected at least one conflict marker block');
|
||||
for (const b of blocks) {
|
||||
assert.equal(b.trim(), '', `expected every HEAD section to be empty (context-missing signal), got: ${JSON.stringify(b)}`);
|
||||
}
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('the awk predicate from the workflow classifies empty-HEAD as skippable and non-empty-HEAD as real', () => {
|
||||
// Pull the awk script out of the deployed workflow so this test
|
||||
// exercises the exact predicate that runs in CI — not a copy.
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
const awkMatch = script.match(/awk '\r?\n([\s\S]+?)' "\$CONFLICTED"/);
|
||||
assert.ok(awkMatch, 'expected to find the conflict-classifying awk script in the workflow');
|
||||
const awkProgram = awkMatch[1];
|
||||
|
||||
function classify(conflictText) {
|
||||
const tmpFile = path.join(os.tmpdir(), `bug-2966-awk-${process.pid}-${Date.now()}-${Math.random()}.txt`);
|
||||
fs.writeFileSync(tmpFile, conflictText);
|
||||
try {
|
||||
const r = spawnSync('awk', [awkProgram, tmpFile], { encoding: 'utf8' });
|
||||
// Fail loudly on awk execution errors — silently consuming an
|
||||
// empty stdout from a crashed/missing awk would let context-missing
|
||||
// assertions falsely pass.
|
||||
assert.ok(!r.error, `awk failed to launch: ${r.error && r.error.message}`);
|
||||
assert.equal(r.status, 0, `awk predicate exited non-zero: ${r.stderr || '(no stderr)'}`);
|
||||
return r.stdout.trim();
|
||||
} finally {
|
||||
fs.rmSync(tmpFile, { force: true });
|
||||
}
|
||||
}
|
||||
|
||||
// Empty HEAD section → context-missing → no "real" emitted.
|
||||
const ctxMissing = [
|
||||
'unrelated line',
|
||||
'<<<<<<< HEAD',
|
||||
'=======',
|
||||
'patch wants this content',
|
||||
'and this',
|
||||
'>>>>>>> sha (msg)',
|
||||
'tail',
|
||||
].join('\n');
|
||||
assert.equal(classify(ctxMissing), '', 'awk must classify empty-HEAD blocks as context-missing (no "real" emitted) (#2966)');
|
||||
|
||||
// Non-empty HEAD section → real conflict.
|
||||
const realConflict = [
|
||||
'<<<<<<< HEAD',
|
||||
'VALUE=existing',
|
||||
'=======',
|
||||
'VALUE=patched',
|
||||
'>>>>>>> sha (msg)',
|
||||
].join('\n');
|
||||
assert.equal(classify(realConflict), 'real', 'awk must classify non-empty-HEAD blocks as real conflicts (#2966)');
|
||||
|
||||
// Mixed — first block empty-HEAD, second block real → real wins (overall classification).
|
||||
const mixed = [
|
||||
'<<<<<<< HEAD',
|
||||
'=======',
|
||||
'patch content',
|
||||
'>>>>>>> sha (msg)',
|
||||
'spacer',
|
||||
'<<<<<<< HEAD',
|
||||
'something existing',
|
||||
'=======',
|
||||
'something patched',
|
||||
'>>>>>>> sha (msg)',
|
||||
].join('\n');
|
||||
assert.equal(classify(mixed), 'real', 'awk must report "real" if any conflict block has non-empty HEAD content (#2966)');
|
||||
|
||||
// Whitespace-only HEAD section → context-missing (the awk predicate
|
||||
// treats blank/whitespace HEAD content the same as empty).
|
||||
const whitespaceHead = [
|
||||
'<<<<<<< HEAD',
|
||||
' ',
|
||||
'\t',
|
||||
'=======',
|
||||
'patch content',
|
||||
'>>>>>>> sha (msg)',
|
||||
].join('\n');
|
||||
assert.equal(classify(whitespaceHead), '', 'awk must classify whitespace-only HEAD blocks as context-missing (#2966)');
|
||||
});
|
||||
});
|
||||
@@ -1,295 +0,0 @@
|
||||
/**
|
||||
* Regression test for bug #2968
|
||||
*
|
||||
* Full-automation policy: any cherry-pick conflict in the release-sdk
|
||||
* hotfix loop — context-missing OR real merge conflict — must be
|
||||
* skipped, logged to the SKIPPED list with a classified reason, and
|
||||
* the loop continues. The hotfix run completes with whatever applies
|
||||
* cleanly; the SKIPPED list is the operator's post-hoc review queue.
|
||||
*
|
||||
* Pre-#2968 behavior: real conflicts (HEAD section non-empty)
|
||||
* triggered the abort/push-partial/error path, blocking every hotfix
|
||||
* run whose base tag had diverged from main. v1.39.1 hit this on
|
||||
* commit 0fb992d (run 25227493387) because v1.39.0 was tagged on the
|
||||
* `feat/hermes-runtime-2841` branch, which had restructured files that
|
||||
* pre-hermes fixes still patched against the old structure.
|
||||
*
|
||||
* This test asserts the workflow:
|
||||
* 1. No longer carries the abort-on-real-conflict control flow
|
||||
* (no `git cherry-pick --abort` followed by `exit 1` for picks
|
||||
* that have unmerged paths).
|
||||
* 2. Calls `git cherry-pick --skip` unconditionally on any
|
||||
* cherry-pick failure inside the auto_cherry_pick loop.
|
||||
* 3. Annotates the SKIPPED list with `merge conflict` for real
|
||||
* conflicts (so operators can find them in the run summary).
|
||||
* 4. Still records `context absent at base` for the empty-HEAD case
|
||||
* — the classifier's diagnostic value is preserved even though
|
||||
* the control flow no longer branches on it.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// allow-test-rule: source-text-is-the-product
|
||||
// release-sdk.yml IS the product for hotfix automation; the static
|
||||
// assertions extract the "Prepare hotfix branch" run block via
|
||||
// indentation-aware YAML parsing rather than raw-text grep across the
|
||||
// whole document.
|
||||
|
||||
const { describe, test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const WORKFLOW_PATH = path.join(__dirname, '..', '.github', 'workflows', 'release-sdk.yml');
|
||||
|
||||
function extractStepRun(workflowText, stepName) {
|
||||
const lines = workflowText.split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const m = lines[i].match(/^(\s*)- name:\s*(.+?)\s*$/);
|
||||
if (!m || m[2] !== stepName) continue;
|
||||
const stepIndent = m[1].length;
|
||||
let j = i + 1;
|
||||
while (j < lines.length) {
|
||||
const peek = lines[j];
|
||||
if (/^\s*- /.test(peek)) {
|
||||
const peekIndent = peek.match(/^(\s*)/)[1].length;
|
||||
if (peekIndent <= stepIndent) break;
|
||||
}
|
||||
const runMatch = peek.match(/^(\s*)run:\s*\|(?:[+-])?\s*$/);
|
||||
if (runMatch) {
|
||||
const blockIndent = runMatch[1].length + 2;
|
||||
const body = [];
|
||||
for (let k = j + 1; k < lines.length; k++) {
|
||||
const bodyLine = lines[k];
|
||||
if (bodyLine.length === 0) {
|
||||
body.push('');
|
||||
continue;
|
||||
}
|
||||
const lead = bodyLine.match(/^(\s*)/)[1].length;
|
||||
if (lead < blockIndent && bodyLine.trim() !== '') break;
|
||||
body.push(bodyLine.slice(blockIndent));
|
||||
}
|
||||
return body.join('\n');
|
||||
}
|
||||
j++;
|
||||
}
|
||||
throw new Error(`step "${stepName}" found but no run: | block before step end`);
|
||||
}
|
||||
throw new Error(`step "${stepName}" not found in workflow`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract just the body of the `if ! git ... cherry-pick ... ; then ... fi`
|
||||
* conditional inside the auto_cherry_pick loop, so assertions can target
|
||||
* the failure path without matching unrelated cherry-pick references
|
||||
* (e.g. the operator-recovery hint in `$GITHUB_STEP_SUMMARY` echoes).
|
||||
*
|
||||
* Walks bash `if`/`fi` nesting to find the matching `fi` for the failure
|
||||
* branch — naïve string matching wouldn't survive nested conditionals.
|
||||
*/
|
||||
function extractCherryPickFailureBlock(script) {
|
||||
const lines = script.split('\n');
|
||||
const startIdx = lines.findIndex(l => /if ! git[^\n]*cherry-pick[^\n]*"\$SHA"; then/.test(l));
|
||||
if (startIdx === -1) throw new Error('cherry-pick failure conditional not found in auto_cherry_pick loop');
|
||||
let depth = 1;
|
||||
for (let i = startIdx + 1; i < lines.length; i++) {
|
||||
if (/^\s*if[\s(]/.test(lines[i]) || /;\s*then\s*$/.test(lines[i])) depth++;
|
||||
if (/^\s*fi\s*$/.test(lines[i])) {
|
||||
depth--;
|
||||
if (depth === 0) return lines.slice(startIdx + 1, i).join('\n');
|
||||
}
|
||||
}
|
||||
throw new Error('matching `fi` for cherry-pick failure conditional not found');
|
||||
}
|
||||
|
||||
describe('bug-2968: release-sdk hotfix cherry-pick skips all conflicts (full automation)', () => {
|
||||
test('cherry-pick failure path no longer carries abort-on-real-conflict control flow', () => {
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
const failureBlock = extractCherryPickFailureBlock(script);
|
||||
|
||||
// The failure block must NOT call `git cherry-pick --abort` — that was
|
||||
// the pre-#2968 behavior on real conflicts. Skip-on-any-conflict means
|
||||
// we never abort; we always --skip.
|
||||
assert.doesNotMatch(
|
||||
failureBlock,
|
||||
/git cherry-pick --abort/,
|
||||
'auto_cherry_pick failure path must not call `git cherry-pick --abort` — full-automation policy is to skip all conflicts (#2968)'
|
||||
);
|
||||
// The failure block must NOT exit 1 — that bricked every hotfix on
|
||||
// a divergent base tag. The workflow continues past conflicts now.
|
||||
assert.doesNotMatch(
|
||||
failureBlock,
|
||||
/exit 1/,
|
||||
'auto_cherry_pick failure path must not `exit 1` on cherry-pick conflicts — full-automation policy is to log and continue (#2968)'
|
||||
);
|
||||
// The failure block must NOT push --force-with-lease — that was the
|
||||
// recovery-state push for operator-resolvable conflicts. With
|
||||
// skip-on-any-conflict there's no partial-pick state to preserve.
|
||||
assert.doesNotMatch(
|
||||
failureBlock,
|
||||
/git push --force-with-lease/,
|
||||
'auto_cherry_pick failure path must not push partial state — full-automation policy is to skip and continue, no recovery state needed (#2968)'
|
||||
);
|
||||
});
|
||||
|
||||
test('cherry-pick failure path always calls `git cherry-pick --skip` and appends to CONFLICT_SKIPPED', () => {
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
const failureBlock = extractCherryPickFailureBlock(script);
|
||||
|
||||
// All assertions on `failureBlock` are line-anchored (`^\s*...`, `m`
|
||||
// flag) so a comment that mentions a command — e.g. "Calling `--skip`
|
||||
// outside an in-progress cherry-pick exits non-zero" — can't satisfy
|
||||
// the assertion. Only executable shell lines count. CodeRabbit on
|
||||
// PR #2970.
|
||||
assert.match(
|
||||
failureBlock,
|
||||
/^\s*git cherry-pick --skip\b/m,
|
||||
'auto_cherry_pick failure path must call `git cherry-pick --skip` to clear cherry-pick state and continue the loop (#2968)'
|
||||
);
|
||||
// Conflict skips MUST go into a dedicated bucket — operators reviewing
|
||||
// the run summary need to find manual-review items without scanning
|
||||
// through policy-excluded feat/refactor/etc commits. Bug #2968.
|
||||
assert.match(
|
||||
failureBlock,
|
||||
/^\s*CONFLICT_SKIPPED="\$\{CONFLICT_SKIPPED\}/m,
|
||||
'auto_cherry_pick failure path must append to CONFLICT_SKIPPED (a separate bucket from POLICY_SKIPPED) so operators can find manual-review items in the run summary (#2968)'
|
||||
);
|
||||
assert.doesNotMatch(
|
||||
failureBlock,
|
||||
/^\s*SKIPPED="\$\{SKIPPED\}/m,
|
||||
'auto_cherry_pick failure path must NOT append to the legacy SKIPPED bucket — that buries manual-review conflicts under "feat/refactor/etc — not auto-included" (#2968)'
|
||||
);
|
||||
assert.match(
|
||||
failureBlock,
|
||||
/^\s*continue\s*$/m,
|
||||
'auto_cherry_pick failure path must `continue` the loop after skipping — full-automation policy is best-effort cherry-pick (#2968)'
|
||||
);
|
||||
});
|
||||
|
||||
test('merge commits are pre-skipped before cherry-pick is attempted', () => {
|
||||
// Cherry-picking a merge commit requires `-m <parent>` which the loop
|
||||
// can't choose automatically. Without it, `git cherry-pick <merge-sha>`
|
||||
// fails BEFORE entering cherry-pick state — no CHERRY_PICK_HEAD — so
|
||||
// the unconditional `--skip` would also fail and brick the loop.
|
||||
// The loop must detect parent count > 1 and skip with a distinct
|
||||
// reason BEFORE invoking cherry-pick. CodeRabbit on PR #2970.
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
|
||||
assert.match(
|
||||
script,
|
||||
/git rev-list --parents -n 1 "\$SHA"/,
|
||||
'auto_cherry_pick must inspect parent count before invoking cherry-pick — merge commits need `-m <parent>` and we can\'t pick the parent automatically (#2968)'
|
||||
);
|
||||
assert.match(
|
||||
script,
|
||||
/merge commit — manual -m parent selection required/,
|
||||
'auto_cherry_pick must annotate merge-commit skips with a distinct reason so operators understand why the pick wasn\'t attempted (#2968)'
|
||||
);
|
||||
});
|
||||
|
||||
test('classifier guards against unreadable / markerless unmerged paths', () => {
|
||||
// A degenerate unmerged file (missing, unreadable, or no conflict
|
||||
// markers) must NOT be misclassified as "context absent at base" — the
|
||||
// auto-skip path. Treat as real so the operator can investigate.
|
||||
// Also: `awk` runs under `set -e`; a non-zero exit on a missing file
|
||||
// would terminate the step. CodeRabbit on PR #2970.
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
const failureBlock = extractCherryPickFailureBlock(script);
|
||||
|
||||
// Readability check before invoking the marker classifier.
|
||||
assert.match(
|
||||
failureBlock,
|
||||
/\[\s*!\s*-r\s+"\$CONFLICTED"\s*\]/,
|
||||
'auto_cherry_pick must check `[ ! -r "$CONFLICTED" ]` before running the awk classifier so an unreadable unmerged path does not terminate the step under `set -e` (#2968)'
|
||||
);
|
||||
// Marker-presence check before invoking the marker classifier — a file
|
||||
// listed as unmerged but with no `<<<<<<< ` header is anomalous.
|
||||
assert.match(
|
||||
failureBlock,
|
||||
/grep -q '\^<<<<<<< '\s+"\$CONFLICTED"/,
|
||||
'auto_cherry_pick must verify `<<<<<<< ` markers exist in the file before running the awk classifier so a markerless unmerged file is not misclassified as context-missing (#2968)'
|
||||
);
|
||||
// The awk invocation must tolerate non-zero exits (e.g. via 2>/dev/null
|
||||
// and `|| echo "real"`) so a transient awk failure can't slip the file
|
||||
// into the auto-skip bucket.
|
||||
assert.match(
|
||||
failureBlock,
|
||||
/awk[\s\S]+?\|\|\s*echo\s+"real"/,
|
||||
'awk classifier must default to "real" on non-zero exit so transient awk failures do not auto-skip a real conflict (#2968)'
|
||||
);
|
||||
});
|
||||
|
||||
test('git cherry-pick --skip is guarded by CHERRY_PICK_HEAD existence', () => {
|
||||
// If cherry-pick fails for a reason that doesn't enter conflict state
|
||||
// (e.g. unreadable commit, ref problem), CHERRY_PICK_HEAD doesn't exist
|
||||
// and `git cherry-pick --skip` exits non-zero — bricking the loop.
|
||||
// The skip call must be guarded. CodeRabbit on PR #2970.
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
const failureBlock = extractCherryPickFailureBlock(script);
|
||||
|
||||
assert.match(
|
||||
failureBlock,
|
||||
/git rev-parse[^\n]*CHERRY_PICK_HEAD/,
|
||||
'auto_cherry_pick must check CHERRY_PICK_HEAD exists before calling `git cherry-pick --skip` — calling --skip outside an in-progress cherry-pick fails (#2968)'
|
||||
);
|
||||
});
|
||||
|
||||
test('run summary uses distinct sections for conflict skips vs policy skips', () => {
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
|
||||
// The summary must surface both buckets with distinct headings so
|
||||
// operators can act on the right one. Conflict skips are the review
|
||||
// queue; policy skips are informational.
|
||||
assert.match(
|
||||
script,
|
||||
/Skipped — cherry-pick conflict \(manual review\)/,
|
||||
'run summary must show conflict skips under a "manual review" heading distinct from policy skips (#2968)'
|
||||
);
|
||||
assert.match(
|
||||
script,
|
||||
/Not auto-included \(feat\/refactor\/docs\/etc\)/,
|
||||
'run summary must show policy skips under a heading that names the excluded categories — they are not failures (#2968)'
|
||||
);
|
||||
// Both buckets must be referenced when emitting the summary so a
|
||||
// future edit can't silently drop one section.
|
||||
assert.match(
|
||||
script,
|
||||
/\$CONFLICT_SKIPPED/,
|
||||
'run summary must echo $CONFLICT_SKIPPED so the manual-review queue actually appears (#2968)'
|
||||
);
|
||||
assert.match(
|
||||
script,
|
||||
/\$POLICY_SKIPPED/,
|
||||
'run summary must echo $POLICY_SKIPPED so policy-excluded commits remain visible to operators (#2968)'
|
||||
);
|
||||
});
|
||||
|
||||
test('skip reason annotates real merge conflicts distinctly from context-missing', () => {
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
const failureBlock = extractCherryPickFailureBlock(script);
|
||||
|
||||
// Operators must be able to find real conflicts in the run summary —
|
||||
// the "merge conflict" string is the discriminator.
|
||||
assert.match(
|
||||
failureBlock,
|
||||
/merge conflict/i,
|
||||
'auto_cherry_pick must annotate real-conflict skips with "merge conflict" so operators can find them in the run summary (#2968)'
|
||||
);
|
||||
// The empty-HEAD/context-missing classification (#2966) is preserved
|
||||
// — its diagnostic value (operator can tell the conflict was "fix
|
||||
// patched code that doesn't exist here" vs "fix patched code we
|
||||
// restructured") survives the policy change.
|
||||
assert.match(
|
||||
failureBlock,
|
||||
/context absent at base/,
|
||||
'auto_cherry_pick must still annotate context-missing skips distinctly from real merge conflicts so operators can distinguish the diagnostic (#2966 + #2968)'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,308 +0,0 @@
|
||||
/**
|
||||
* Regression test for bug #2980
|
||||
*
|
||||
* The release-sdk hotfix cherry-pick loop's `fix:`/`chore:` filter is
|
||||
* too broad: it picks anything with that conventional-commit type
|
||||
* regardless of whether the diff can affect the published npm package.
|
||||
* That caused two compounding problems:
|
||||
*
|
||||
* 1. CI-only fixes (release-sdk.yml, hotfix tooling) were cherry-picked
|
||||
* into hotfix branches even though they cannot change what ships.
|
||||
* 2. The subset of those CI-only fixes touching `.github/workflows/*`
|
||||
* caused the prepare job's `git push` to be rejected by GitHub —
|
||||
* the default GITHUB_TOKEN lacks the `workflow` scope:
|
||||
*
|
||||
* ! [remote rejected] hotfix/X.YY.Z -> hotfix/X.YY.Z
|
||||
* (refusing to allow a GitHub App to create or update workflow
|
||||
* ... without `workflows` permission)
|
||||
*
|
||||
* v1.39.1 hit this on PR #2977 (run 25232010071): #2977 cherry-
|
||||
* picked cleanly because earlier workflow-file fixes had been
|
||||
* skipped on conflict, then the push exploded.
|
||||
*
|
||||
* Fix (root cause): pre-pick guard that checks whether the candidate
|
||||
* commit's diff intersects the npm tarball's shipped paths (entries in
|
||||
* `package.json` `files` plus `package.json` itself). Non-shipping
|
||||
* commits are skipped with an informational summary entry; the
|
||||
* workflow-file rejection is now a non-issue because workflow files
|
||||
* are not in `files`.
|
||||
*
|
||||
* The shipped-paths classifier lives in
|
||||
* `scripts/diff-touches-shipped-paths.cjs` rather than inline in the
|
||||
* workflow YAML so its rules are unit-testable.
|
||||
*
|
||||
* This test covers two layers:
|
||||
* - Static workflow assertions (the loop calls the script before
|
||||
* attempting the pick, the result drives a NON_SHIPPED_SKIPPED
|
||||
* bucket, and the run summary surfaces it).
|
||||
* - Behavioral assertions on the classifier script itself (matches
|
||||
* `npm pack` semantics for `files` entries).
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// allow-test-rule: source-text-is-the-product
|
||||
// release-sdk.yml IS the product for hotfix automation; the static
|
||||
// assertions extract the "Prepare hotfix branch" run block via
|
||||
// indentation-aware YAML parsing rather than raw-text grep across the
|
||||
// whole document.
|
||||
|
||||
const { describe, test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
|
||||
const REPO_ROOT = path.join(__dirname, '..');
|
||||
const WORKFLOW_PATH = path.join(REPO_ROOT, '.github', 'workflows', 'release-sdk.yml');
|
||||
const CLASSIFIER_PATH = path.join(REPO_ROOT, 'scripts', 'diff-touches-shipped-paths.cjs');
|
||||
|
||||
function extractStepRun(workflowText, stepName) {
|
||||
const lines = workflowText.split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const m = lines[i].match(/^(\s*)- name:\s*(.+?)\s*$/);
|
||||
if (!m || m[2] !== stepName) continue;
|
||||
const stepIndent = m[1].length;
|
||||
let j = i + 1;
|
||||
while (j < lines.length) {
|
||||
const peek = lines[j];
|
||||
if (/^\s*- /.test(peek)) {
|
||||
const peekIndent = peek.match(/^(\s*)/)[1].length;
|
||||
if (peekIndent <= stepIndent) break;
|
||||
}
|
||||
const runMatch = peek.match(/^(\s*)run:\s*\|(?:[+-])?\s*$/);
|
||||
if (runMatch) {
|
||||
const blockIndent = runMatch[1].length + 2;
|
||||
const body = [];
|
||||
for (let k = j + 1; k < lines.length; k++) {
|
||||
const bodyLine = lines[k];
|
||||
if (bodyLine.length === 0) {
|
||||
body.push('');
|
||||
continue;
|
||||
}
|
||||
const lead = bodyLine.match(/^(\s*)/)[1].length;
|
||||
if (lead < blockIndent && bodyLine.trim() !== '') break;
|
||||
body.push(bodyLine.slice(blockIndent));
|
||||
}
|
||||
return body.join('\n');
|
||||
}
|
||||
j++;
|
||||
}
|
||||
throw new Error(`step "${stepName}" found but no run: | block before step end`);
|
||||
}
|
||||
throw new Error(`step "${stepName}" not found in workflow`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Slice the lines from the merge-commit pre-skip guard up to (but not
|
||||
* including) the cherry-pick attempt. Any new pre-pick guard MUST live
|
||||
* in this region to fire before the pick.
|
||||
*/
|
||||
function extractPrePickRegion(script) {
|
||||
const lines = script.split('\n');
|
||||
const startIdx = lines.findIndex(l => /merge commit — manual -m parent selection required/.test(l));
|
||||
if (startIdx === -1) throw new Error('merge-commit pre-skip guard not found — sentinel for pre-pick region');
|
||||
const endIdx = lines.findIndex((l, i) => i > startIdx && /git[^\n]*cherry-pick[^\n]*"\$SHA"/.test(l));
|
||||
if (endIdx === -1) throw new Error('cherry-pick attempt not found after merge-commit guard');
|
||||
return lines.slice(startIdx, endIdx).join('\n');
|
||||
}
|
||||
|
||||
describe('bug-2980: release-sdk hotfix only picks commits that touch shipped paths', () => {
|
||||
test('pre-pick guard runs the shipped-paths classifier before attempting the pick', () => {
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
const prePick = extractPrePickRegion(script);
|
||||
|
||||
// Must call the classifier script. Inline grep on `.github/workflows/`
|
||||
// would only catch the workflow-file subset of the bug — the broader
|
||||
// root cause is "any non-shipping commit in a hotfix is meaningless"
|
||||
// and the classifier encodes the precise `files`-whitelist rule.
|
||||
assert.match(
|
||||
prePick,
|
||||
/git diff-tree --no-commit-id --name-only -r "\$SHA"/,
|
||||
'pre-pick region must extract the candidate SHA\'s file list with `git diff-tree` so the classifier has accurate input (#2980)'
|
||||
);
|
||||
// After #2983 the classifier is invoked via the staged $CLASSIFIER
|
||||
// variable (not the in-tree path), to survive the working-tree swap
|
||||
// performed by `git checkout -b "$BRANCH" "$BASE_TAG"`. Either form
|
||||
// proves the classifier participates; the bug-2983 test enforces
|
||||
// the staged-path form specifically.
|
||||
assert.match(
|
||||
prePick,
|
||||
/node "\$CLASSIFIER"/,
|
||||
'pre-pick region must invoke `node "$CLASSIFIER"` (the staged classifier) — the in-tree path is unsafe after the base-tag checkout (#2980, #2983)'
|
||||
);
|
||||
// Skip-on-exit-1 dispatch: pre-#2983 used `if ! ... ; then skip`,
|
||||
// but that conflated classifier errors (exit 2+) with the
|
||||
// legitimate "not shipped" signal. Post-#2983 the dispatch is
|
||||
// explicit `case "$CLASSIFIER_RC" in 1) skip ;; *) error ;; esac`.
|
||||
// This test accepts the modern form; bug-2983 enforces it.
|
||||
assert.match(
|
||||
prePick,
|
||||
/case "\$CLASSIFIER_RC" in[\s\S]+?1\)[\s\S]+?continue/,
|
||||
'pre-pick region must skip on exit 1 via case-dispatch on $CLASSIFIER_RC — the post-#2983 shape that distinguishes "not shipped" from classifier errors (#2980, #2983)'
|
||||
);
|
||||
});
|
||||
|
||||
test('non-shipped skips land in NON_SHIPPED_SKIPPED, distinct from CONFLICT_SKIPPED and POLICY_SKIPPED', () => {
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
const prePick = extractPrePickRegion(script);
|
||||
|
||||
assert.match(
|
||||
prePick,
|
||||
/^\s*NON_SHIPPED_SKIPPED="\$\{NON_SHIPPED_SKIPPED\}/m,
|
||||
'non-shipped skip must append to NON_SHIPPED_SKIPPED — distinct from CONFLICT_SKIPPED (manual-review queue) and POLICY_SKIPPED (feat/refactor exclusions) (#2980)'
|
||||
);
|
||||
// The bucket must be initialized at the top of the loop alongside
|
||||
// the other two — so a future `set -u` doesn't silently break it.
|
||||
assert.match(
|
||||
script,
|
||||
/^\s*NON_SHIPPED_SKIPPED=""\s*$/m,
|
||||
'NON_SHIPPED_SKIPPED must be initialized to empty alongside POLICY_SKIPPED and CONFLICT_SKIPPED (#2980)'
|
||||
);
|
||||
});
|
||||
|
||||
test('non-shipped skip emits no ::warning:: — the change cannot affect the package', () => {
|
||||
// A non-shipped commit is by definition incapable of changing what
|
||||
// ships, so the skip needs no operator alert. The summary bucket is
|
||||
// informational; a yellow warning would imply remediation is
|
||||
// possible, which would mislead operators.
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
const prePick = extractPrePickRegion(script);
|
||||
|
||||
assert.doesNotMatch(
|
||||
prePick,
|
||||
/::warning::/,
|
||||
'non-shipped skip must NOT emit a ::warning:: — the commit cannot change what ships, so a warning would falsely imply remediation is needed (#2980)'
|
||||
);
|
||||
});
|
||||
|
||||
test('run summary surfaces NON_SHIPPED_SKIPPED in its own section, framed as informational', () => {
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
|
||||
assert.match(
|
||||
script,
|
||||
/if \[ -n "\$NON_SHIPPED_SKIPPED" \]/,
|
||||
'run summary must conditionally render the NON_SHIPPED_SKIPPED bucket so empty hotfixes don\'t print an empty section (#2980)'
|
||||
);
|
||||
// The header must NOT use "manual review" framing — that's the
|
||||
// CONFLICT_SKIPPED queue. Non-shipped skips need no manual action.
|
||||
assert.doesNotMatch(
|
||||
script,
|
||||
/Skipped — touches no shipped paths[^\n]*manual review/,
|
||||
'NON_SHIPPED_SKIPPED summary header must NOT imply manual review — non-shipping commits need no remediation (#2980)'
|
||||
);
|
||||
assert.match(
|
||||
script,
|
||||
/Skipped — touches no shipped paths[^\n]*informational/,
|
||||
'NON_SHIPPED_SKIPPED summary header must signal "informational" so operators don\'t mistake it for the manual-review queue (#2980)'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('bug-2980: scripts/diff-touches-shipped-paths.cjs classifier semantics', () => {
|
||||
function runClassifier(stdin, cwd) {
|
||||
return spawnSync('node', [CLASSIFIER_PATH], {
|
||||
cwd,
|
||||
input: stdin,
|
||||
encoding: 'utf8',
|
||||
});
|
||||
}
|
||||
|
||||
function makeFixtureRepo(filesArray) {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'bug-2980-'));
|
||||
fs.writeFileSync(
|
||||
path.join(tmp, 'package.json'),
|
||||
JSON.stringify({ name: 'fixture', version: '0.0.0', files: filesArray }, null, 2)
|
||||
);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
test('directory entry in `files` matches paths under that directory but not sibling prefixes', () => {
|
||||
const tmp = makeFixtureRepo(['bin', 'sdk/dist']);
|
||||
try {
|
||||
// bin/foo.js is shipped (under bin/).
|
||||
assert.equal(runClassifier('bin/foo.js\n', tmp).status, 0, 'bin/foo.js must be shipped');
|
||||
// bin alone (the directory entry itself) is shipped.
|
||||
assert.equal(runClassifier('bin\n', tmp).status, 0, 'bin (exact match) must be shipped');
|
||||
// binaries/foo.js must NOT match bin (prefix-without-slash bug).
|
||||
assert.equal(runClassifier('binaries/foo.js\n', tmp).status, 1, 'binaries/foo.js must NOT match bin/ — prefix without slash boundary is a classic bug');
|
||||
// sdk/dist/cli.js is shipped.
|
||||
assert.equal(runClassifier('sdk/dist/cli.js\n', tmp).status, 0, 'sdk/dist/cli.js must be shipped');
|
||||
// sdk/src/cli.ts is NOT shipped (only sdk/dist is in `files`).
|
||||
assert.equal(runClassifier('sdk/src/cli.ts\n', tmp).status, 1, 'sdk/src/cli.ts must NOT be shipped when only sdk/dist is whitelisted');
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('package.json is always shipped even when not in `files`', () => {
|
||||
// `npm pack` always includes package.json regardless of `files`. The
|
||||
// classifier must mirror that, so a version-bump-only commit isn't
|
||||
// wrongly skipped.
|
||||
const tmp = makeFixtureRepo([]);
|
||||
try {
|
||||
assert.equal(runClassifier('package.json\n', tmp).status, 0, 'package.json must be classified as shipped — `npm pack` always includes it');
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('package-lock.json is NOT shipped unless explicitly in `files`', () => {
|
||||
// `npm pack` does NOT include package-lock.json by default. A
|
||||
// lockfile-only commit can't change the published package's runtime
|
||||
// behavior (consumers resolve their own lockfile from `dependencies`).
|
||||
const tmp = makeFixtureRepo(['bin']);
|
||||
try {
|
||||
assert.equal(runClassifier('package-lock.json\n', tmp).status, 1, 'package-lock.json must NOT be classified as shipped when absent from `files` — `npm pack` excludes it by default');
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('mixed diff is shipped if ANY path is shipped', () => {
|
||||
// A commit that touches both a shipped file and an unrelated non-
|
||||
// shipped, non-push-blocking file must be classified as shipped — the
|
||||
// non-shipped paths are along for the ride, but the commit can still
|
||||
// affect what ships. Note: this fixture deliberately avoids
|
||||
// `.github/workflows/*`, which is push-blocking (#3621) and forces a
|
||||
// skip regardless of other shipped paths in the same bundle.
|
||||
const tmp = makeFixtureRepo(['bin']);
|
||||
try {
|
||||
const stdin = 'CHANGELOG.md\nbin/foo.js\nplanning/notes.md\n';
|
||||
assert.equal(runClassifier(stdin, tmp).status, 0, 'mixed diff with at least one shipped path must classify as shipped');
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('purely CI/test/docs commit is NOT shipped (the actual #2980 case)', () => {
|
||||
// The classic case: a fix(release-sdk): commit that touches only
|
||||
// .github/workflows/release-sdk.yml and a regression test under
|
||||
// tests/. Pre-#2980 the loop picked it; the cherry-pick succeeded;
|
||||
// the push then failed because of the workflow-file scope rule.
|
||||
// Post-#2980 the loop skips it pre-pick — the push problem and the
|
||||
// "meaningless pick" problem dissolve together.
|
||||
const tmp = makeFixtureRepo(['bin', 'commands', 'sdk/dist']);
|
||||
try {
|
||||
const stdin = '.github/workflows/release-sdk.yml\ntests/bug-2980-shipped-paths.test.cjs\nCHANGELOG.md\n';
|
||||
assert.equal(runClassifier(stdin, tmp).status, 1, 'CI-only commit (workflow + test + changelog) must classify as NOT shipped — the canonical #2980 case');
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('empty stdin classifies as not-shipped (defensive — empty diff means no candidate paths)', () => {
|
||||
const tmp = makeFixtureRepo(['bin']);
|
||||
try {
|
||||
assert.equal(runClassifier('', tmp).status, 1, 'empty stdin must classify as not-shipped — no paths can\'t intersect any whitelist');
|
||||
assert.equal(runClassifier('\n\n\n', tmp).status, 1, 'whitespace-only stdin must classify as not-shipped');
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,388 +0,0 @@
|
||||
/**
|
||||
* Regression test for bug #2983
|
||||
*
|
||||
* Two compounding bugs surfaced by CodeRabbit's post-merge review of
|
||||
* PR #2981 (which shipped #2980's shipped-paths cherry-pick filter):
|
||||
*
|
||||
* 1. Overloaded exit code: scripts/diff-touches-shipped-paths.cjs
|
||||
* used exit 1 for the legitimate classifier result "no shipped
|
||||
* paths." Node's default exit on uncaught throw is also 1, so any
|
||||
* classifier failure was indistinguishable from a normal skip.
|
||||
* The workflow's `if ! ... ; then skip` idiom would silently drop
|
||||
* a commit on tool failure.
|
||||
*
|
||||
* 2. Classifier missing at the base tag: the workflow runs
|
||||
* `git checkout -b "$BRANCH" "$BASE_TAG"` BEFORE the cherry-pick
|
||||
* loop, which replaces the working tree with the base tag's
|
||||
* contents. Base tags predating #2980 (notably v1.39.0, the most
|
||||
* likely next hotfix base) don't have
|
||||
* `scripts/diff-touches-shipped-paths.cjs` at all. `node <missing>`
|
||||
* exits non-zero → workflow treats as "not shipped" → every
|
||||
* commit gets silently dropped → empty hotfix branch published.
|
||||
* This is strictly worse than the original #2980 push-rejection,
|
||||
* which at least failed loudly.
|
||||
*
|
||||
* Fix:
|
||||
* - Script: distinct exit codes (0 = shipped, 1 = not shipped,
|
||||
* 2 = classifier error). All uncaught failure paths
|
||||
* (uncaughtException, unhandledRejection, fs/JSON errors) route
|
||||
* to exit 2.
|
||||
* - Workflow: stage the classifier into $RUNNER_TEMP at the top of
|
||||
* `Prepare hotfix branch` (before `git checkout -b "$BASE_TAG"`)
|
||||
* and reference $CLASSIFIER in the loop. Capture exit code via
|
||||
* ${PIPESTATUS[1]} and dispatch via case: 0 → proceed, 1 → skip
|
||||
* (NON_SHIPPED_SKIPPED), anything else → ::error:: + exit. The
|
||||
* workflow refuses to start if the classifier source is missing
|
||||
* in the dispatched ref.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// allow-test-rule: source-text-is-the-product
|
||||
// release-sdk.yml IS the product for hotfix automation; the static
|
||||
// assertions extract the "Prepare hotfix branch" run block via
|
||||
// indentation-aware YAML parsing rather than raw-text grep across the
|
||||
// whole document.
|
||||
|
||||
const { describe, test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
|
||||
const REPO_ROOT = path.join(__dirname, '..');
|
||||
const WORKFLOW_PATH = path.join(REPO_ROOT, '.github', 'workflows', 'release-sdk.yml');
|
||||
const CLASSIFIER_PATH = path.join(REPO_ROOT, 'scripts', 'diff-touches-shipped-paths.cjs');
|
||||
|
||||
function extractStepRun(workflowText, stepName) {
|
||||
const lines = workflowText.split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const m = lines[i].match(/^(\s*)- name:\s*(.+?)\s*$/);
|
||||
if (!m || m[2] !== stepName) continue;
|
||||
const stepIndent = m[1].length;
|
||||
let j = i + 1;
|
||||
while (j < lines.length) {
|
||||
const peek = lines[j];
|
||||
if (/^\s*- /.test(peek)) {
|
||||
const peekIndent = peek.match(/^(\s*)/)[1].length;
|
||||
if (peekIndent <= stepIndent) break;
|
||||
}
|
||||
const runMatch = peek.match(/^(\s*)run:\s*\|(?:[+-])?\s*$/);
|
||||
if (runMatch) {
|
||||
const blockIndent = runMatch[1].length + 2;
|
||||
const body = [];
|
||||
for (let k = j + 1; k < lines.length; k++) {
|
||||
const bodyLine = lines[k];
|
||||
if (bodyLine.length === 0) {
|
||||
body.push('');
|
||||
continue;
|
||||
}
|
||||
const lead = bodyLine.match(/^(\s*)/)[1].length;
|
||||
if (lead < blockIndent && bodyLine.trim() !== '') break;
|
||||
body.push(bodyLine.slice(blockIndent));
|
||||
}
|
||||
return body.join('\n');
|
||||
}
|
||||
j++;
|
||||
}
|
||||
throw new Error(`step "${stepName}" found but no run: | block before step end`);
|
||||
}
|
||||
throw new Error(`step "${stepName}" not found in workflow`);
|
||||
}
|
||||
|
||||
describe('bug-2983: shipped-paths classifier exit-code discipline', () => {
|
||||
function runClassifier({ stdin, cwd }) {
|
||||
return spawnSync('node', [CLASSIFIER_PATH], {
|
||||
cwd,
|
||||
input: stdin,
|
||||
encoding: 'utf8',
|
||||
});
|
||||
}
|
||||
|
||||
function makeFixtureRepo({ files, raw }) {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'bug-2983-'));
|
||||
if (raw !== undefined) {
|
||||
fs.writeFileSync(path.join(tmp, 'package.json'), raw);
|
||||
} else if (files !== undefined) {
|
||||
fs.writeFileSync(
|
||||
path.join(tmp, 'package.json'),
|
||||
JSON.stringify({ name: 'fixture', version: '0.0.0', files }, null, 2)
|
||||
);
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
test('exit 0 still means "at least one shipped path"', () => {
|
||||
const tmp = makeFixtureRepo({ files: ['bin'] });
|
||||
try {
|
||||
const r = runClassifier({ stdin: 'bin/foo.js\n', cwd: tmp });
|
||||
assert.equal(r.status, 0, `expected exit 0 for shipped path; stderr=${r.stderr}`);
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('exit 1 still means "no shipped paths" — preserved across the #2983 refactor', () => {
|
||||
const tmp = makeFixtureRepo({ files: ['bin'] });
|
||||
try {
|
||||
const r = runClassifier({ stdin: 'tests/foo.test.cjs\n.github/workflows/release-sdk.yml\n', cwd: tmp });
|
||||
assert.equal(r.status, 1, `expected exit 1 for non-shipping diff; stderr=${r.stderr}`);
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('exit 2 when package.json is missing — distinguishable from "not shipped"', () => {
|
||||
// Run in a temp dir with no package.json. Pre-#2983 this would
|
||||
// surface as exit 1 (Node default for uncaught throw), which the
|
||||
// workflow would have silently treated as "not shipped." Post-fix
|
||||
// it's exit 2, which the workflow MUST treat as a hard error.
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'bug-2983-no-pkg-'));
|
||||
try {
|
||||
const r = runClassifier({ stdin: 'bin/foo.js\n', cwd: tmp });
|
||||
assert.equal(r.status, 2, `expected exit 2 for missing package.json; got ${r.status}; stderr=${r.stderr}`);
|
||||
assert.match(r.stderr, /diff-touches-shipped-paths/, 'classifier error must be tagged in stderr so the workflow operator can find it');
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('exit 2 when package.json is malformed JSON', () => {
|
||||
const tmp = makeFixtureRepo({ raw: '{ this is not json' });
|
||||
try {
|
||||
const r = runClassifier({ stdin: 'bin/foo.js\n', cwd: tmp });
|
||||
assert.equal(r.status, 2, `expected exit 2 for malformed package.json; got ${r.status}; stderr=${r.stderr}`);
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('module exports the exit-code constants so workflow tests can reference them by name', () => {
|
||||
// Decoupling intent (EXIT_NOT_SHIPPED) from value (1) is what makes
|
||||
// a future "let's renumber" edit safe. Importers should reference
|
||||
// the constants, not the literals.
|
||||
const mod = require(CLASSIFIER_PATH);
|
||||
assert.equal(mod.EXIT_SHIPPED, 0, 'EXIT_SHIPPED must be 0');
|
||||
assert.equal(mod.EXIT_NOT_SHIPPED, 1, 'EXIT_NOT_SHIPPED must be 1');
|
||||
assert.equal(mod.EXIT_ERROR, 2, 'EXIT_ERROR must be 2 (distinct from 0 and 1)');
|
||||
});
|
||||
});
|
||||
|
||||
describe('bug-2983: workflow stages the classifier and dispatches on exit code', () => {
|
||||
test('classifier is staged into $RUNNER_TEMP before any working-tree-mutating git command', () => {
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
|
||||
// The staging cp must appear before `git checkout -b ... "$BASE_TAG"`
|
||||
// — that's the operation that overwrites the working tree with the
|
||||
// base tag's contents, which may not contain the classifier.
|
||||
const stageIdx = script.search(/cp "\$CLASSIFIER_SRC" "\$CLASSIFIER"/);
|
||||
const checkoutIdx = script.search(/git checkout -b "\$BRANCH" "\$BASE_TAG"/);
|
||||
assert.ok(
|
||||
stageIdx !== -1,
|
||||
'workflow must `cp` the classifier from its in-tree path to a stable location ($CLASSIFIER) before the working tree is swapped (#2983)'
|
||||
);
|
||||
assert.ok(
|
||||
checkoutIdx !== -1,
|
||||
'workflow must contain the base-tag checkout — sentinel that establishes the staging-must-precede ordering constraint'
|
||||
);
|
||||
assert.ok(
|
||||
stageIdx < checkoutIdx,
|
||||
`classifier staging must precede \`git checkout -b ... "$BASE_TAG"\` so the source file isn't already gone (#2983). Found stage at offset ${stageIdx}, checkout at ${checkoutIdx}.`
|
||||
);
|
||||
});
|
||||
|
||||
test('staging targets $RUNNER_TEMP — survives the working-tree swap and is auto-cleaned by the runner', () => {
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
|
||||
assert.match(
|
||||
script,
|
||||
/CLASSIFIER="\$\{RUNNER_TEMP\}\/diff-touches-shipped-paths\.cjs"/,
|
||||
'$CLASSIFIER must point at $RUNNER_TEMP — that path survives `git checkout` (lives outside the repo) and is cleaned automatically by the runner (#2983)'
|
||||
);
|
||||
});
|
||||
|
||||
test('workflow refuses to run if the classifier source is missing in the dispatched ref', () => {
|
||||
// Defense in depth: if a future edit reorders the steps so the
|
||||
// first checkout doesn't put the classifier on disk, the workflow
|
||||
// must fail loudly rather than skip every commit.
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
|
||||
assert.match(
|
||||
script,
|
||||
/if \[ ! -f "\$CLASSIFIER_SRC" \][\s\S]{0,200}::error::shipped-paths classifier not found/,
|
||||
'workflow must fail-fast if scripts/diff-touches-shipped-paths.cjs is missing in the dispatched ref (#2983)'
|
||||
);
|
||||
assert.match(
|
||||
script,
|
||||
/if \[ ! -f "\$CLASSIFIER" \][\s\S]{0,200}failed to stage classifier/,
|
||||
'workflow must fail-fast if cp didn\'t actually produce $CLASSIFIER (defense against silent cp failure on RUNNER_TEMP corner cases) (#2983)'
|
||||
);
|
||||
});
|
||||
|
||||
test('cherry-pick loop captures classifier exit code via $PIPESTATUS and dispatches on the value', () => {
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
|
||||
// The pre-#2983 form was `if ! ... | node ...; then skip; fi` which
|
||||
// collapses every non-zero exit (including missing-script and
|
||||
// uncaught-throw cases) into the skip path. The required new shape
|
||||
// is: run the pipeline, snapshot $PIPESTATUS into a local array
|
||||
// immediately, dispatch via case.
|
||||
//
|
||||
// CodeRabbit on PR #2984 caught a subtler bug in the first iteration
|
||||
// of this fix: `pipeline || true; RC=${PIPESTATUS[1]}` doesn't work
|
||||
// because `|| true` runs `true` as a one-command pipeline when the
|
||||
// pipeline fails (exit 1 or 2 — exactly the cases we care about),
|
||||
// overwriting PIPESTATUS to (0). The hardened form snapshots
|
||||
// PIPESTATUS into a local array on the line immediately after the
|
||||
// pipeline, with no intervening commands.
|
||||
assert.match(
|
||||
script,
|
||||
/PIPE_RC=\("\$\{PIPESTATUS\[@\]\}"\)/,
|
||||
'cherry-pick loop must snapshot the entire $PIPESTATUS array via `PIPE_RC=("${PIPESTATUS[@]}")` immediately after the classifier pipeline — `${PIPESTATUS[1]}` direct-read is unsafe under any subsequent simple command, and `|| true; ${PIPESTATUS[1]}` is broken because `|| true` runs `true` as its own pipeline on the failure paths (CodeRabbit on PR #2984)'
|
||||
);
|
||||
// The pipeline must run under `set +e` to allow the snapshot — at
|
||||
// the workflow's top-level `set -euo pipefail`, a non-zero exit
|
||||
// from the pipeline would otherwise terminate the step before the
|
||||
// snapshot line runs.
|
||||
assert.match(
|
||||
script,
|
||||
/set \+e[\s\S]{0,200}node "\$CLASSIFIER"[\s\S]{0,80}PIPE_RC=\("\$\{PIPESTATUS\[@\]\}"\)[\s\S]{0,40}set -e/,
|
||||
'classifier pipeline must be wrapped `set +e` ... pipeline ... `PIPE_RC=("${PIPESTATUS[@]}")` ... `set -e` — any other shape either misses the snapshot or terminates the step early (#2983, CodeRabbit on PR #2984)'
|
||||
);
|
||||
// Must NOT use the broken `pipeline || true; RC=${PIPESTATUS[1]}` form.
|
||||
// The `|| true` rewrites PIPESTATUS on the failure paths.
|
||||
assert.doesNotMatch(
|
||||
script,
|
||||
/node "\$CLASSIFIER"\s*\|\|\s*true\s*\n\s*CLASSIFIER_RC="\$\{PIPESTATUS\[1\]\}"/,
|
||||
'classifier pipeline must NOT use `|| true` followed by `${PIPESTATUS[1]}` — `|| true` runs `true` as a one-command pipeline on the failure paths and overwrites PIPESTATUS to (0), so PIPESTATUS[1] becomes unset (CodeRabbit on PR #2984)'
|
||||
);
|
||||
// Must NOT use the original `if ! ... | node ...; then` shape either.
|
||||
assert.doesNotMatch(
|
||||
script,
|
||||
/if ! git diff-tree[\s\S]{0,200}node[\s\S]{0,200}\.cjs[^|\n]*; then/,
|
||||
'cherry-pick loop must NOT use `if ! ... | node classifier; then skip` — that shape silently treats classifier errors as skips (#2983)'
|
||||
);
|
||||
// The case dispatch must explicitly handle 0, 1, and a default branch.
|
||||
assert.match(
|
||||
script,
|
||||
/case "\$CLASSIFIER_RC" in[\s\S]+?0\)[\s\S]+?1\)[\s\S]+?\*\)/,
|
||||
'case dispatch on $CLASSIFIER_RC must list 0, 1, and a default-error branch in that order so each is handled explicitly (#2983)'
|
||||
);
|
||||
});
|
||||
|
||||
test('git diff-tree failure is also fail-fast (not silently classified as not-shipped)', () => {
|
||||
// The new array-snapshot form gives us $DIFFTREE_RC for free.
|
||||
// git diff-tree is unlikely to fail on a known-good $SHA, but if
|
||||
// it does (e.g., $SHA is corrupt or fetch was incomplete), we must
|
||||
// not pipe partial/empty output into the classifier and call it
|
||||
// "not shipped." Fail-fast with ::error:: instead.
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
|
||||
assert.match(
|
||||
script,
|
||||
/DIFFTREE_RC="\$\{PIPE_RC\[0\]\}"/,
|
||||
'workflow must extract git diff-tree\'s exit from PIPE_RC[0] so a partial-pipeline failure can be distinguished from a clean classifier result (CodeRabbit on PR #2984)'
|
||||
);
|
||||
assert.match(
|
||||
script,
|
||||
/if \[ "\$DIFFTREE_RC" -ne 0 \][\s\S]{0,200}::error::git diff-tree failed/,
|
||||
'workflow must emit ::error:: and exit when git diff-tree itself fails — silently passing partial input to the classifier would defeat the whole point of #2983 (CodeRabbit on PR #2984)'
|
||||
);
|
||||
});
|
||||
|
||||
test('hotfix run summary no longer falsely advertises a merge-back PR', () => {
|
||||
// CodeRabbit on PR #2984: the Summary block still printed
|
||||
// "Merge-back PR opened against main" even though the merge-back
|
||||
// step was removed. Operators reading the summary would expect a PR
|
||||
// that was never opened. Replace with explicit non-action text so
|
||||
// the summary accurately describes what happened.
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
|
||||
assert.doesNotMatch(
|
||||
yaml,
|
||||
/echo "- Merge-back PR opened against main"/,
|
||||
'run summary must NOT advertise a merge-back PR — the step was removed in #2983 and the line is stale (CodeRabbit on PR #2984)'
|
||||
);
|
||||
assert.match(
|
||||
yaml,
|
||||
/No merge-back PR \(auto-picked commits are already on main\)/,
|
||||
'run summary must explicitly state that no merge-back PR exists, with the rationale, so operators understand it\'s intentional rather than missing (CodeRabbit on PR #2984)'
|
||||
);
|
||||
});
|
||||
|
||||
test('default-error branch fails the workflow with ::error:: rather than continuing', () => {
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
|
||||
// Must emit ::error:: AND exit non-zero. Either alone is
|
||||
// insufficient: ::error:: without exit just decorates the log;
|
||||
// exit without ::error:: hides the cause.
|
||||
assert.match(
|
||||
script,
|
||||
/\*\)[\s\S]+?::error::shipped-paths classifier failed[\s\S]+?exit "\$CLASSIFIER_RC"/,
|
||||
'classifier-error branch must emit ::error:: AND `exit "$CLASSIFIER_RC"` — silently continuing would defeat the whole point of #2983 (#2983)'
|
||||
);
|
||||
});
|
||||
|
||||
test('merge-back PR step is removed (auto-cherry-pick hotfix has nothing to merge back)', () => {
|
||||
// Auto-cherry-pick only picks commits already on main, so by
|
||||
// construction every code change on the hotfix branch is already
|
||||
// there. The only hotfix-branch-only commit is `chore: bump version
|
||||
// ... for hotfix`, which either no-ops or rewinds main's
|
||||
// in-progress version. The merge-back step was vestigial and was
|
||||
// additionally blocked by org policy ("GitHub Actions is not
|
||||
// permitted to create or approve pull requests"). Run 25232968975
|
||||
// was the trigger.
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
assert.doesNotMatch(
|
||||
yaml,
|
||||
/Open merge-back PR \(hotfix only\)/,
|
||||
'merge-back PR step must be removed — nothing to merge back when every commit is already on main (#2983)'
|
||||
);
|
||||
assert.doesNotMatch(
|
||||
yaml,
|
||||
/chore: merge hotfix v\$\{VERSION\} back to main/,
|
||||
'merge-back PR title must be gone — vestigial from a different release flow (#2983)'
|
||||
);
|
||||
// Job-level pull-requests permission was granted solely for the
|
||||
// merge-back step. Removing the step means revoking the permission
|
||||
// (least-privilege).
|
||||
assert.doesNotMatch(
|
||||
yaml,
|
||||
/pull-requests: write/,
|
||||
'release job must NOT request `pull-requests: write` after the merge-back removal — least-privilege requires dropping the unused scope (#2983)'
|
||||
);
|
||||
});
|
||||
|
||||
test('the staged path is what the loop invokes, not the in-tree path', () => {
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const script = extractStepRun(yaml, 'Prepare hotfix branch');
|
||||
|
||||
// Find the cherry-pick loop's classifier invocation and ensure it
|
||||
// references "$CLASSIFIER", not scripts/diff-touches-shipped-paths.cjs
|
||||
// directly. Allowing the in-tree path here would re-introduce the
|
||||
// base-tag-missing bug.
|
||||
const loopAnchor = script.indexOf('CANDIDATES=$(git cherry HEAD origin/main');
|
||||
assert.ok(loopAnchor !== -1, 'cherry-pick loop sentinel not found');
|
||||
// 8 KB window matching the bug-2964 test's bound (raised from 6 KB
|
||||
// when the PIPESTATUS-snapshot hardening on PR for #2984's CR
|
||||
// findings pushed the cherry-pick call further past the loop anchor).
|
||||
const window = script.slice(loopAnchor, loopAnchor + 8000);
|
||||
assert.match(
|
||||
window,
|
||||
/node "\$CLASSIFIER"/,
|
||||
'cherry-pick loop must invoke `node "$CLASSIFIER"` (the staged copy), not `node scripts/diff-touches-shipped-paths.cjs` (the in-tree path) — the in-tree path may have been replaced by `git checkout -b "$BASE_TAG"` (#2983)'
|
||||
);
|
||||
assert.doesNotMatch(
|
||||
window,
|
||||
/node scripts\/diff-touches-shipped-paths\.cjs/,
|
||||
'cherry-pick loop must NOT invoke `node scripts/diff-touches-shipped-paths.cjs` — base tags predating #2980 don\'t have that file in their tree (#2983)'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,140 +0,0 @@
|
||||
/**
|
||||
* Regression test for bug #2987
|
||||
*
|
||||
* The release-sdk workflow's `Dry-run publish validation` step ran
|
||||
* `npm publish --dry-run --tag "$TAG"` unconditionally. `npm publish
|
||||
* --dry-run` contacts the registry and exits 1 when the version is
|
||||
* already published:
|
||||
*
|
||||
* npm error You cannot publish over the previously published
|
||||
* versions: 1.39.1.
|
||||
*
|
||||
* The earlier `Detect prior publish (reconciliation mode)` step
|
||||
* already detects this case and sets
|
||||
* `steps.prior_publish.outputs.skip_publish=true` — and the real
|
||||
* publish step at line ~648 is gated on that. The dry-run validation
|
||||
* was missing the same gate, so re-runs of an already-published
|
||||
* hotfix (the operator's typical recovery path when a later step
|
||||
* like merge-back fails) blew up at the rehearsal before reaching
|
||||
* any of the reconciliation logic.
|
||||
*
|
||||
* Trigger run: 25233855236 — re-attempted v1.39.1 hotfix after the
|
||||
* prior run had landed v1.39.1 on npm.
|
||||
*
|
||||
* Fix: gate the dry-run validation step on
|
||||
* `steps.prior_publish.outputs.skip_publish != 'true'`, matching the
|
||||
* publish step.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// allow-test-rule: source-text-is-the-product
|
||||
// release-sdk.yml IS the product for hotfix automation; the assertions
|
||||
// extract the workflow text and check the step-level `if:` guard via
|
||||
// indentation-aware YAML parsing rather than raw-text grep.
|
||||
|
||||
const { describe, test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
const WORKFLOW_PATH = path.join(__dirname, '..', '.github', 'workflows', 'release-sdk.yml');
|
||||
|
||||
/**
|
||||
* Find a step by name and return the lines belonging to it (from the
|
||||
* `- name:` line up to but not including the next `- name:` at the
|
||||
* same indent or the next dedent-back-to-job).
|
||||
*/
|
||||
function extractStepBlock(workflowText, stepName) {
|
||||
const lines = workflowText.split('\n');
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const m = lines[i].match(/^(\s*)- name:\s*(.+?)\s*$/);
|
||||
if (!m || m[2] !== stepName) continue;
|
||||
const stepIndent = m[1].length;
|
||||
const start = i;
|
||||
let end = lines.length;
|
||||
for (let j = i + 1; j < lines.length; j++) {
|
||||
const peek = lines[j];
|
||||
if (peek.length === 0) continue;
|
||||
const lead = peek.match(/^(\s*)/)[1].length;
|
||||
// Next sibling step or dedent past step indent terminates this block.
|
||||
if (lead <= stepIndent && peek.trim().length > 0) {
|
||||
if (/^\s*- /.test(peek) || lead < stepIndent) {
|
||||
end = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return lines.slice(start, end).join('\n');
|
||||
}
|
||||
throw new Error(`step "${stepName}" not found in workflow`);
|
||||
}
|
||||
|
||||
describe('bug-2987: dry-run publish validation skips when reconciliation mode is active', () => {
|
||||
test('Dry-run publish validation step has an `if:` guard tied to skip_publish', () => {
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const block = extractStepBlock(yaml, 'Dry-run publish validation');
|
||||
|
||||
// The guard must reference steps.prior_publish.outputs.skip_publish
|
||||
// — the exact output set by the `Detect prior publish` step.
|
||||
// Loosely accepting any boolean expression here would risk a future
|
||||
// edit that gates on the wrong signal (e.g., inputs.dry_run, which
|
||||
// is the user-facing dry-run flag, not registry reconciliation).
|
||||
assert.match(
|
||||
block,
|
||||
/^\s*if:\s*\$\{\{\s*steps\.prior_publish\.outputs\.skip_publish\s*!=\s*'true'\s*\}\}\s*$/m,
|
||||
"Dry-run publish validation must be gated on `steps.prior_publish.outputs.skip_publish != 'true'` so reconciliation re-runs (version already on npm) don't fail at the rehearsal (#2987)"
|
||||
);
|
||||
});
|
||||
|
||||
test('the gate matches the actual publish step\'s gate (consistency with downstream skip)', () => {
|
||||
// The publish step ("Publish to npm (CC bundle, ...)" further
|
||||
// down) ALSO honors skip_publish. The rehearsal must honor it too;
|
||||
// otherwise reconciliation runs always fail at the rehearsal.
|
||||
// This test reads both gates and asserts the skip_publish
|
||||
// sub-expression is identical between them. It allows the publish
|
||||
// step to ALSO check inputs.dry_run (which it does, and which the
|
||||
// rehearsal correctly does NOT — the rehearsal is the dry-run).
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const dryRunBlock = extractStepBlock(yaml, 'Dry-run publish validation');
|
||||
const publishBlock = extractStepBlock(yaml, 'Publish to npm (CC bundle, SDK included as both loose tree and .tgz)');
|
||||
|
||||
const skipPattern = /steps\.prior_publish\.outputs\.skip_publish\s*!=\s*'true'/;
|
||||
assert.match(
|
||||
dryRunBlock,
|
||||
skipPattern,
|
||||
'Dry-run validation must check skip_publish (#2987)'
|
||||
);
|
||||
assert.match(
|
||||
publishBlock,
|
||||
skipPattern,
|
||||
'Publish step must check skip_publish (sentinel — if this fails the workflow has changed and the test\'s premise needs review)'
|
||||
);
|
||||
});
|
||||
|
||||
test('the workflow still runs the rehearsal in normal flows (gate is skip-only, not always-skip)', () => {
|
||||
// Defense against the wrong fix: someone could pass-through-fix
|
||||
// this by gating on `false` (always skip) which would silently
|
||||
// disable the rehearsal even on first publishes. The gate must
|
||||
// be specifically tied to the skip_publish signal, not a generic
|
||||
// `false` or `inputs.action == 'something'` discriminator.
|
||||
const yaml = fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
const block = extractStepBlock(yaml, 'Dry-run publish validation');
|
||||
|
||||
// The gate string itself must contain a comparison against 'true' —
|
||||
// i.e., it's an opt-out for the prior-publish case, not an
|
||||
// unconditional skip.
|
||||
const ifLine = block.split('\n').find((l) => /^\s*if:/.test(l));
|
||||
assert.ok(ifLine, 'Dry-run validation must have an `if:` line (#2987)');
|
||||
assert.match(
|
||||
ifLine,
|
||||
/skip_publish\s*!=\s*'true'/,
|
||||
'gate must be `skip_publish != true` (run when not skipping), not an unconditional skip — the rehearsal still has value on first publishes (#2987)'
|
||||
);
|
||||
assert.doesNotMatch(
|
||||
ifLine,
|
||||
/:\s*false\s*\}\}/,
|
||||
'gate must not be `if: false` — the rehearsal is meaningful when the version isn\'t yet on npm (#2987)'
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -1,217 +0,0 @@
|
||||
/**
|
||||
* Regression test for bug #3621
|
||||
*
|
||||
* The release-sdk hotfix cherry-pick loop's `fix:`/`chore:` prefix filter
|
||||
* and the shipped-paths classifier together excluded a test-fixture update
|
||||
* that was required to align CI with a cherry-picked production fix.
|
||||
*
|
||||
* Concrete failure shape (v1.42.3 hotfix, run 25949422676):
|
||||
* - Commit 36534059 fix(3562) was picked. It changed the installer to
|
||||
* materialize gsd-named SKILL.md files under the codex skills dir.
|
||||
* - Commit 08848df8 (docs(3562) prefix) was POLICY_SKIPPED by the prefix
|
||||
* filter. It bundled the matching test-fixture correction (removing an
|
||||
* "if (runtime === 'codex') return new Set()" short-circuit in
|
||||
* tests/install-minimal-all-runtimes.test.cjs).
|
||||
* - Result: hotfix branch has new production behavior + stale test
|
||||
* assertion → 3 tests fail.
|
||||
*
|
||||
* Two-part fix:
|
||||
* 1. release-sdk.yml prefix filter now includes test: commits.
|
||||
* 2. scripts/diff-touches-shipped-paths.cjs treats tests/-rooted paths
|
||||
* and sdk/src vitest specs (.test.ts / .spec.ts and friends) as
|
||||
* CI-gating-equivalent so a test: commit that touches only those
|
||||
* paths passes the shipped-paths gate.
|
||||
*
|
||||
* Without both halves the bundling failure mode persists.
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// allow-test-rule: source-text-is-the-product
|
||||
// release-sdk.yml IS the product for hotfix automation; this test reads
|
||||
// the workflow's prefix-filter regex line directly because the regex IS
|
||||
// the behavior contract — there is no runtime that consumes it.
|
||||
|
||||
const { describe, test } = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const os = require('node:os');
|
||||
const path = require('node:path');
|
||||
const { spawnSync } = require('node:child_process');
|
||||
|
||||
const REPO_ROOT = path.join(__dirname, '..');
|
||||
const WORKFLOW_PATH = path.join(REPO_ROOT, '.github', 'workflows', 'release-sdk.yml');
|
||||
const CLASSIFIER_PATH = path.join(REPO_ROOT, 'scripts', 'diff-touches-shipped-paths.cjs');
|
||||
const { isCiGating } = require('../scripts/diff-touches-shipped-paths.cjs');
|
||||
|
||||
function workflowText() {
|
||||
return fs.readFileSync(WORKFLOW_PATH, 'utf8');
|
||||
}
|
||||
|
||||
function runClassifier(stdin, cwd) {
|
||||
return spawnSync(process.execPath, [CLASSIFIER_PATH], {
|
||||
cwd,
|
||||
input: stdin,
|
||||
encoding: 'utf8',
|
||||
});
|
||||
}
|
||||
|
||||
function writeMinimalPkg(tmp, files) {
|
||||
fs.writeFileSync(
|
||||
path.join(tmp, 'package.json'),
|
||||
JSON.stringify({ name: 'test-pkg', version: '0.0.0', files }, null, 2),
|
||||
);
|
||||
}
|
||||
|
||||
describe('bug-3621: release-sdk hotfix accepts `test:` commits', () => {
|
||||
test('candidate-loop regex includes test: prefix alongside fix:/chore:', () => {
|
||||
const text = workflowText();
|
||||
// The regex must accept all three prefixes — fix, chore, test — with
|
||||
// optional (scope) and optional ! for breaking. Asserted by extracting
|
||||
// the literal regex line.
|
||||
const regexLine = text.split('\n').find((l) => l.includes("grep -qE '^(") && l.includes(')(\\([^)]+\\))?!?: '));
|
||||
assert.ok(regexLine, 'release-sdk.yml must contain the candidate-prefix regex line');
|
||||
assert.ok(
|
||||
/\^\(fix\|chore\|test\)/.test(regexLine),
|
||||
`prefix regex must include fix|chore|test (got: ${regexLine.trim()})`,
|
||||
);
|
||||
});
|
||||
|
||||
test('regex does NOT silently drop fix: or chore: while adding test:', () => {
|
||||
const text = workflowText();
|
||||
const regexLine = text.split('\n').find((l) => l.includes("grep -qE '^("));
|
||||
assert.ok(regexLine.includes('fix|chore|test'), 'must keep fix and chore as before');
|
||||
assert.ok(!regexLine.includes('feat|'), 'must NOT silently add feat: — features are not hotfix-eligible');
|
||||
assert.ok(!regexLine.includes('docs|'), 'must NOT silently add docs: — docs commits remain POLICY_SKIPPED');
|
||||
});
|
||||
});
|
||||
|
||||
describe('bug-3621: shipped-paths classifier treats test paths as CI-gating', () => {
|
||||
test('isCiGating recognizes tests/** as CI-gating', () => {
|
||||
assert.equal(isCiGating('tests/bug-foo.test.cjs'), true);
|
||||
assert.equal(isCiGating('tests/helpers.cjs'), true);
|
||||
assert.equal(isCiGating('tests/fixtures/adversarial/roadmap/duplicate-keys.md'), true);
|
||||
});
|
||||
|
||||
test('isCiGating recognizes sdk/src vitest specs as CI-gating', () => {
|
||||
assert.equal(isCiGating('sdk/src/query/init.test.ts'), true);
|
||||
assert.equal(isCiGating('sdk/src/query/init.spec.ts'), true);
|
||||
assert.equal(isCiGating('sdk/src/golden/golden.integration.test.ts'), true);
|
||||
});
|
||||
|
||||
test('isCiGating rejects non-test sdk/src paths (those ship via sdk/dist)', () => {
|
||||
assert.equal(isCiGating('sdk/src/query/init.ts'), false);
|
||||
assert.equal(isCiGating('sdk/src/config.ts'), false);
|
||||
});
|
||||
|
||||
test('isCiGating rejects paths that merely contain "test" in their name', () => {
|
||||
// Guard against /test/ false positives.
|
||||
assert.equal(isCiGating('docs/test-strategy.md'), false);
|
||||
assert.equal(isCiGating('bin/install-test-helper.js'), false);
|
||||
// .test.md is not a recognized spec extension here.
|
||||
assert.equal(isCiGating('docs/install.test.md'), false);
|
||||
});
|
||||
|
||||
test('classifier exits 0 for a test-only diff (the v1.42.3 case)', () => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'bug-3621-classifier-'));
|
||||
try {
|
||||
writeMinimalPkg(tmp, ['bin', 'sdk/dist']);
|
||||
const result = runClassifier('tests/install-minimal-all-runtimes.test.cjs\n', tmp);
|
||||
assert.equal(
|
||||
result.status,
|
||||
0,
|
||||
`tests/** path must classify as shipped-equivalent (status=${result.status}, stderr=${result.stderr})`,
|
||||
);
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('classifier exits 0 for a mixed test+docs diff (the v1.42.3 commit shape)', () => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'bug-3621-classifier-mixed-'));
|
||||
try {
|
||||
writeMinimalPkg(tmp, ['bin', 'sdk/dist']);
|
||||
const stdin = [
|
||||
'README.md',
|
||||
'docs/CONFIGURATION.md',
|
||||
'docs/USER-GUIDE.md',
|
||||
'tests/install-minimal-all-runtimes.test.cjs',
|
||||
'tests/installer-migration-install-integration.test.cjs',
|
||||
].join('\n') + '\n';
|
||||
const result = runClassifier(stdin, tmp);
|
||||
assert.equal(
|
||||
result.status,
|
||||
0,
|
||||
`mixed docs+test diff must classify as shipped-equivalent because at least one path is CI-gating (status=${result.status})`,
|
||||
);
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('classifier still exits 1 for a pure docs-only diff (no test paths)', () => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'bug-3621-classifier-docs-only-'));
|
||||
try {
|
||||
writeMinimalPkg(tmp, ['bin', 'sdk/dist']);
|
||||
const stdin = 'README.md\ndocs/CONFIGURATION.md\n';
|
||||
const result = runClassifier(stdin, tmp);
|
||||
assert.equal(
|
||||
result.status,
|
||||
1,
|
||||
`pure docs-only diff must remain NOT_SHIPPED — they aren't CI-gating either (status=${result.status})`,
|
||||
);
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('classifier still exits 0 for a normal shipped-path diff (pre-fix behavior preserved)', () => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'bug-3621-classifier-shipped-'));
|
||||
try {
|
||||
writeMinimalPkg(tmp, ['bin', 'sdk/dist']);
|
||||
const result = runClassifier('bin/install.js\n', tmp);
|
||||
assert.equal(result.status, 0, 'shipped-path classification must not regress');
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('classifier still exits 1 for CI-only workflow diffs (.github/** is neither shipped nor CI-gating)', () => {
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'bug-3621-classifier-ci-'));
|
||||
try {
|
||||
writeMinimalPkg(tmp, ['bin', 'sdk/dist']);
|
||||
const result = runClassifier('.github/workflows/release-sdk.yml\n', tmp);
|
||||
assert.equal(
|
||||
result.status,
|
||||
1,
|
||||
'workflow-only changes must remain NOT_SHIPPED — they\'d otherwise fail the push step (default GITHUB_TOKEN lacks workflow scope, #2980)',
|
||||
);
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
test('push-blocking guard wins: workflow + test bundle classifies as NOT_SHIPPED (preserves #2980)', () => {
|
||||
// The canonical #2980 case is a `fix(release-sdk):` commit touching
|
||||
// both the workflow file and its regression test. Under #3621 the test
|
||||
// path alone would otherwise satisfy the CI-gating check; the
|
||||
// .github/workflows/* push-blocker must still skip the whole commit.
|
||||
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'bug-3621-classifier-pushblock-'));
|
||||
try {
|
||||
writeMinimalPkg(tmp, ['bin', 'sdk/dist']);
|
||||
const stdin = [
|
||||
'.github/workflows/release-sdk.yml',
|
||||
'tests/bug-2980-hotfix-only-picks-shipping-changes.test.cjs',
|
||||
'CHANGELOG.md',
|
||||
].join('\n') + '\n';
|
||||
const result = runClassifier(stdin, tmp);
|
||||
assert.equal(
|
||||
result.status,
|
||||
1,
|
||||
'#2980 preservation: bundle with .github/workflows/* must skip regardless of test paths in the same commit',
|
||||
);
|
||||
} finally {
|
||||
fs.rmSync(tmp, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -150,30 +150,11 @@ describe('release-tarball-smoke', () => {
|
||||
assert.ok(typeof result.details.path === 'string' && result.details.path.length > 0);
|
||||
});
|
||||
|
||||
// ── Test E — SDK binary callable ──────────────────────────────────────────
|
||||
// Verifies that `gsd-sdk query state.json` exits 0 and returns parseable JSON.
|
||||
// This is the primary guard for SDK_BINARY_NOT_CALLABLE regressions.
|
||||
test('E: sdk binary callable — gsd-sdk query produces parseable JSON', () => {
|
||||
const result = runSmoke({
|
||||
tarballPath,
|
||||
installPrefix,
|
||||
expectedVersion: pkg.version,
|
||||
fixtureDir,
|
||||
lifecycleCommands: [], // skip lifecycle checks; isolate SDK check
|
||||
npmEnv: isolatedNpmEnv(),
|
||||
});
|
||||
|
||||
// If the binary can't be called, code would be SDK_BINARY_NOT_CALLABLE
|
||||
assert.notEqual(result.code, SMOKE.SDK_BINARY_NOT_CALLABLE);
|
||||
assert.equal(result.details.sdkQueryParsed, true);
|
||||
});
|
||||
|
||||
// ── Test F — workflow-body checks run (informational) ─────────────────────
|
||||
// ── Test E — workflow-body checks run (informational) ─────────────────────
|
||||
// Asserts that the workflow-body scanning machinery ran (structural assertion).
|
||||
// Does NOT assert colonLeakCount or missingFallbackCount are zero — they will
|
||||
// be non-zero against current main per #3668 and the /gsd: leak backlog.
|
||||
// When those issues are fixed, this test continues to pass unchanged.
|
||||
test('F: workflow-body checks run — scan counts are present integers', () => {
|
||||
// Does NOT assert colonLeakCount is zero — when those issues are fixed, this
|
||||
// test continues to pass unchanged.
|
||||
test('E: workflow-body checks run — scan counts are present integers', () => {
|
||||
const result = runSmoke({
|
||||
tarballPath,
|
||||
installPrefix,
|
||||
@@ -192,9 +173,5 @@ describe('release-tarball-smoke', () => {
|
||||
Number.isInteger(result.details.colonLeakCount),
|
||||
`expected colonLeakCount to be an integer, got ${result.details.colonLeakCount}`,
|
||||
);
|
||||
assert.ok(
|
||||
Number.isInteger(result.details.missingFallbackCount),
|
||||
`expected missingFallbackCount to be an integer, got ${result.details.missingFallbackCount}`,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user