Files
iptvnator/tools/release/build-release-notes.test.mjs
T
4grayandClaude Fable 5 dcd28c1334 feat(release): announcement formats, highlight cards, and draft verification
Extends the release tooling around the .changes notes pipeline:

- New optional `highlight:` frontmatter field marks a release's headline
  changes (max 80 chars, rejected on `type: internal`).
- `--format telegram` renders a paste-ready plain-text post guaranteed to
  fit the 4096-character limit (highlights lead, the rest collapses into a
  counter); `--format reddit` renders markdown with a suggested title line,
  a Highlights section, and a collapsed change list. Both are stdout dry
  runs and must run before `--consume`.
- The blog scaffold uses the highlight as a ready section heading instead
  of a TODO, and highlight notes without screenshots get their own section.
- `release:verify:draft` waits for the v* tag build via `gh run watch`,
  then checks draft status, the authored body, and the complete 27-asset
  set (verified against a real full matrix build). Read-only; publishing
  stays manual.
- `release:cards:generate` renders branded 1200x630 highlight cards (with
  a framed mock-server screenshot strip when the note names one, purely
  typographic otherwise) plus a release hero card into dist/, matching the
  website palette. Copying into the website tree stays a manual act.

Docs: .changes/README.md, release-notes and release-cut skills (both
copies byte-identical). No release note: release tooling only, no runtime
behavior change.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-25 00:28:44 +02:00

151 lines
4.6 KiB
JavaScript

/**
* CLI-level tests for build-release-notes.mjs.
*
* The script parses its arguments and runs on import, so these drive the real
* entry point in a subprocess rather than importing parseArgs directly.
*/
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import { after, describe, it } from 'node:test';
const workspaceRoot = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
'../..'
);
const CLI = path.join(workspaceRoot, 'tools/release/build-release-notes.mjs');
const tempDirs = [];
/** A notes directory holding one valid note, so runs have something to render. */
function makeNotesDir() {
const directory = mkdtempSync(path.join(tmpdir(), 'release-cli-'));
tempDirs.push(directory);
writeFileSync(
path.join(directory, 'playback-example.md'),
'---\ntype: feature\narea: playback\n---\n\nAn example note.\n',
'utf8'
);
return directory;
}
/**
* @returns {{ status: number, stdout: string, stderr: string }}
*/
function runCli(args) {
try {
const stdout = execFileSync(process.execPath, [CLI, ...args], {
cwd: workspaceRoot,
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'pipe'],
});
return { status: 0, stdout, stderr: '' };
} catch (error) {
return {
status: error.status ?? 1,
stdout: error.stdout ?? '',
stderr: error.stderr ?? '',
};
}
}
after(() => {
for (const directory of tempDirs) {
rmSync(directory, { recursive: true, force: true });
}
});
describe('build-release-notes CLI arguments', () => {
it('validates a notes directory', () => {
const result = runCli(['--validate', '--dir', makeNotesDir()]);
assert.equal(result.status, 0);
assert.match(result.stdout, /1 release note\(s\) valid\./);
});
it('ignores a bare `--` separator', () => {
// pnpm forwards `--` to the script instead of consuming it, so the
// npm-style `pnpm run release:notes:validate -- --dir x` reaches us
// with the separator still attached.
const result = runCli(['--validate', '--', '--dir', makeNotesDir()]);
assert.equal(result.status, 0);
assert.match(result.stdout, /1 release note\(s\) valid\./);
});
it('ignores a leading `--` separator', () => {
const result = runCli(['--', '--validate', '--dir', makeNotesDir()]);
assert.equal(result.status, 0);
assert.match(result.stdout, /1 release note\(s\) valid\./);
});
it('renders the github body with a version passed after `--`', () => {
const result = runCli([
'--format',
'github',
'--',
'--version',
'0.24.0',
'--dir',
makeNotesDir(),
]);
assert.equal(result.status, 0);
assert.match(result.stdout, /## Features/);
assert.match(result.stdout, /\*\*playback\*\* — An example note\./);
});
it('renders the telegram announcement to stdout', () => {
const result = runCli([
'--format',
'telegram',
'--version',
'0.24.0',
'--dir',
makeNotesDir(),
]);
assert.equal(result.status, 0);
assert.match(result.stdout, /🎉 IPTVnator v0\.24\.0 is out!/);
assert.match(result.stdout, /✨ An example note\./);
assert.match(result.stdout, /releases\/tag\/v0\.24\.0/);
});
it('renders the reddit announcement to stdout', () => {
const result = runCli([
'--format',
'reddit',
'--version',
'0.24.0',
'--dir',
makeNotesDir(),
]);
assert.equal(result.status, 0);
assert.match(result.stdout, /^Suggested title: IPTVnator v0\.24\.0/);
assert.match(result.stdout, /- \*\*playback\*\* — An example note\./);
});
it('still rejects a genuinely unknown argument', () => {
const result = runCli(['--validate', '--nope']);
assert.equal(result.status, 1);
assert.match(result.stderr, /unknown argument: --nope/);
});
it('still rejects a flag whose value is missing', () => {
const result = runCli(['--format']);
assert.equal(result.status, 1);
assert.match(result.stderr, /--format requires a value/);
});
});