Files
waggle-os/scripts/build-server-archive.test.ts
shumeiko.it 9ac6b9f0d4 feat(licenses): ship LICENSE and the third-party notices with every installer
build-sidecar.mjs copies LICENSE and THIRD_PARTY_NOTICES.md from the
repository root next to service.js in app/src-tauri/resources, and fails
when either is missing. The resources/* glob of tauri.conf.json bundles
them into every desktop installer, and build-server-archive.mjs refuses a
payload without them, so the server archive carries them too. The copies
are ignored by git. Tests cover the copy, the archive and the ignore rule.
2026-11-04 10:24:35 +01:00

76 lines
2.7 KiB
TypeScript

/**
* scripts/build-server-archive.mjs packs the license and the third-party
* notices next to service.js, and refuses to pack a payload without them.
*/
import { spawnSync } from 'node:child_process';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { afterEach, describe, expect, it } from 'vitest';
const ROOT = path.resolve(import.meta.dirname, '..');
const SCRIPT = path.join(ROOT, 'scripts', 'build-server-archive.mjs');
const temps: string[] = [];
afterEach(() => {
for (const dir of temps.splice(0)) fs.rmSync(dir, { recursive: true, force: true });
});
function stagePayload(): { work: string; resources: string } {
const work = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-archive-legal-'));
temps.push(work);
const resources = path.join(work, 'resources');
const files: Record<string, string> = {
'node': '',
'node.exe': '',
'service.js': 'export {};\n',
'node_modules/.keep': '',
'LICENSE': 'MIT License\n',
'THIRD_PARTY_NOTICES.md': '# Third-party notices\n',
};
for (const [relative, content] of Object.entries(files)) {
const file = path.join(resources, relative);
fs.mkdirSync(path.dirname(file), { recursive: true });
fs.writeFileSync(file, content);
}
fs.mkdirSync(path.join(work, 'web'));
fs.writeFileSync(path.join(work, 'web', 'index.html'), '<!doctype html>');
return { work, resources };
}
function pack(work: string, resources: string) {
return spawnSync(
process.execPath,
[
SCRIPT,
'--resources', resources,
'--web', path.join(work, 'web'),
'--out', path.join(work, 'out'),
'--target', 'linux-x64',
'--node-version', '22.0.0',
],
{ encoding: 'utf8', windowsHide: true },
);
}
describe('build-server-archive legal files', () => {
it('packs LICENSE and THIRD_PARTY_NOTICES.md next to service.js', () => {
const { work, resources } = stagePayload();
const result = pack(work, resources);
expect(result.status, result.stderr).toBe(0);
const archive = fs.readdirSync(path.join(work, 'out')).find((name) => name.endsWith('.tar.gz'))!;
const listing = spawnSync('tar', ['-tzf', path.join(work, 'out', archive)], { encoding: 'utf8' });
expect(listing.status, listing.stderr).toBe(0);
const entries = listing.stdout.split(/\r?\n/).map((entry) => entry.replace(/^\.\//, ''));
expect(entries).toEqual(expect.arrayContaining(['service.js', 'LICENSE', 'THIRD_PARTY_NOTICES.md']));
});
it.each(['LICENSE', 'THIRD_PARTY_NOTICES.md'])('refuses a payload without %s', (name) => {
const { work, resources } = stagePayload();
fs.rmSync(path.join(resources, name));
const result = pack(work, resources);
expect(result.status).toBe(1);
expect(result.stderr).toContain(name);
});
});