Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions scripts/workflow-audit.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import { tempDir, workflowRunBlock } from './lint-kit.mjs';
const workflow = readFileSync(new URL('../.github/workflows/workflow-audit.yaml', import.meta.url), 'utf8');
const auditBlock = workflowRunBlock(workflow, 'Audit workflow file changes');
const classifier = auditBlock.slice(auditBlock.indexOf('is_tend_regen() {'), auditBlock.indexOf('\nREPORT=$(mktemp)'));
// The shipped window, not a copy: a typed-out list drifts as paths are added.
const windowLines = ['WINDOW', 'WINDOW_NON_WORKFLOW'].map(name => {
const line = auditBlock.match(new RegExp(`^${name}=.*$`, 'm'))?.[0];
assert.ok(line, `missing ${name}= in the audit step`);
return line;
}).join('\n');
const original = '# Generated by tend 0.1.24. Regenerate with: uvx tend@latest init\noriginal\n';
const generated = original.replace('original', 'generated');

Expand Down Expand Up @@ -63,8 +69,7 @@ login="\${BASH_REMATCH[1]}"
if [[ " \${ADMINS:-} " = *" $login "* ]]; then echo admin; else echo write; fi
`, { mode: 0o755 });
const classify = (sha, extraEnv = {}, fn = 'is_tend_regen') => spawnSync('bash', ['-c', `set -euo pipefail
WINDOW=(.github/workflows/ .config/tend.yaml .github/audit/ .vscode/)
WINDOW_NON_WORKFLOW=("\${WINDOW[@]:1}")
${windowLines}
${classifier}
prepare_activity
${fn} "$1"
Expand Down Expand Up @@ -115,6 +120,13 @@ test('reports a config change even when its workflows reproduce', t => {
assert.equal(f.classify(f.commit()).status, 1);
});

test('refuses a regeneration that also edits a non-workflow window path', t => {
const f = fixture(t);
f.write('scripts/md-unwrap.mjs', 'changed\n');
f.write('.github/workflows/tend-review.yaml', generated);
assert.equal(f.classify(f.commit()).status, 1);
});

const ZERO = '0'.repeat(40);

function mergeFixture(t) {
Expand Down
Loading