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.
This commit is contained in:
shumeiko.it
2026-11-04 10:24:35 +01:00
parent 0acaa1cf29
commit 9ac6b9f0d4
6 changed files with 112 additions and 2 deletions

3
.gitignore vendored
View File

@@ -66,6 +66,9 @@ app/src-tauri/resources/native/
# Copied from packages/sdk/src by scripts/build-sidecar.mjs
app/src-tauri/resources/capability-packs/
app/src-tauri/resources/starter-skills/
# Copied from the repository root by scripts/build-sidecar.mjs
app/src-tauri/resources/LICENSE
app/src-tauri/resources/THIRD_PARTY_NOTICES.md
# D12: the bundled sidecar is generated by scripts/build-sidecar.mjs on every
# build path (npm tauri:build*, CI, and the tauri.conf.json beforeBuildCommand
# hook). A committed copy goes stale silently — a binary shipping an old server

View File

@@ -218,6 +218,16 @@ describe('Tauri Production Configuration', () => {
expect(conf.bundle.resources).toContain('resources/starter-skills/*');
});
it('bundles LICENSE and THIRD_PARTY_NOTICES.md next to service.js, untracked (UF-059)', () => {
// `resources/*` covers the top-level files build-sidecar.mjs copies there.
const conf = JSON.parse(fs.readFileSync(path.join(TAURI_DIR, 'tauri.conf.json'), 'utf-8'));
expect(conf.bundle.resources).toContain('resources/*');
for (const name of ['LICENSE', 'THIRD_PARTY_NOTICES.md']) {
const ignored = spawnSync('git', ['check-ignore', '-q', `app/src-tauri/resources/${name}`], { cwd: ROOT });
expect(ignored.status, `${name} copy is not ignored`).toBe(0);
}
});
it('tauri.conf.json has correct window settings', () => {
const conf = JSON.parse(fs.readFileSync(path.join(TAURI_DIR, 'tauri.conf.json'), 'utf-8'));
const win = conf.app.windows[0];
@@ -479,6 +489,8 @@ describe('Tauri Production Configuration', () => {
path.join(fixtureRoot, 'scripts', 'build-sidecar.mjs'),
);
const trackedFiles = new Map<string, string>([
['LICENSE', 'MIT License\n'],
['THIRD_PARTY_NOTICES.md', '# Third-party notices\n'],
['package-lock.json', '{"lockfileVersion":3}\n'],
['package.json', '{"name":"sidecar-tsconfig-fixture","private":true}\n'],
['packages/marketplace/marketplace.db', 'fixture database'],
@@ -575,6 +587,10 @@ describe('Tauri Production Configuration', () => {
const resourcesRoot = path.join(fixtureRoot, 'app', 'src-tauri', 'resources');
expect(fs.existsSync(path.join(resourcesRoot, 'capability-packs', 'research-workflow.json'))).toBe(true);
expect(fs.existsSync(path.join(resourcesRoot, 'starter-skills', 'brainstorm.md'))).toBe(true);
// UF-059: the license and the notices ship next to service.js.
for (const name of ['LICENSE', 'THIRD_PARTY_NOTICES.md']) {
expect(fs.readFileSync(path.join(resourcesRoot, name), 'utf8')).toBe(trackedFiles.get(name));
}
fs.writeFileSync(marketplacePath, 'dirty worktree database');
const dirtyMarketplaceResult = runResult(

View File

@@ -4,8 +4,8 @@
*
* The archive holds the same sidecar payload the desktop app ships, staged by
* bundle-node, build-sidecar, bundle-native-deps and stage-sidecar-deps into
* app/src-tauri/resources, plus the built web UI under web/ and a
* manifest.json. Run it after those steps and the web build, on the system
* app/src-tauri/resources (with LICENSE and THIRD_PARTY_NOTICES.md next to
* service.js), plus the built web UI under web/ and a manifest.json. Run it after those steps and the web build, on the system
* the archive is for.
*
* Usage:
@@ -78,6 +78,9 @@ try {
requireFile(path.join(options.resources, nodeName), stageHint);
requireFile(path.join(options.resources, 'service.js'), stageHint);
requireFile(path.join(options.resources, 'node_modules'), stageHint);
// The license and the third-party notices must ship with the archive.
requireFile(path.join(options.resources, 'LICENSE'), stageHint);
requireFile(path.join(options.resources, 'THIRD_PARTY_NOTICES.md'), stageHint);
requireFile(path.join(options.web, 'index.html'), 'Build the web UI first: cd apps/web && npx vite build');
let nodeVersion = options.nodeVersion;

View File

@@ -0,0 +1,75 @@
/**
* 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);
});
});

View File

@@ -27,6 +27,7 @@ const marketplaceDbRelative = 'packages/marketplace/marketplace.db';
const marketplaceDb = path.join(root, 'packages', 'marketplace', 'marketplace.db');
const marketplaceResource = path.join(resourcesDir, 'marketplace.db');
const provenancePrefix = '// Waggle-Sidecar-Provenance: ';
const LEGAL_FILES = ['LICENSE', 'THIRD_PARTY_NOTICES.md'];
const buildScriptRelative = 'scripts/build-sidecar.mjs';
const entryPointRelative = 'packages/server/src/local/service.ts';
@@ -312,6 +313,16 @@ try {
for (const file of files) fs.copyFileSync(path.join(source, file), path.join(target, file));
console.log(`[build-sidecar] Copied ${files.length} ${name} files`);
}
// The license and the third-party notices travel with every installer and
// with the server archive, which packs this folder (build-server-archive.mjs).
// The sidecar serves them to the UI from here (routes/legal.ts).
for (const name of LEGAL_FILES) {
const source = path.join(root, name);
if (!fs.existsSync(source)) throw new Error(`Required ${name} is missing at the repository root`);
fs.copyFileSync(source, path.join(resourcesDir, name));
}
console.log(`[build-sidecar] Copied ${LEGAL_FILES.join(' and ')}`);
} catch (err) {
console.error('[build-sidecar] Build failed:', err.message);
process.exit(1);

View File

@@ -74,6 +74,8 @@ describe('release smoke tests', () => {
if (process.platform === 'win32') fs.copyFileSync(process.execPath, runtime);
else fs.symlinkSync(process.execPath, runtime);
write(path.join(resources, 'service.js'), healthServer('process.env.WAGGLE_PORT'));
write(path.join(resources, 'LICENSE'), 'MIT License\n');
write(path.join(resources, 'THIRD_PARTY_NOTICES.md'), '# Third-party notices\n');
write(
path.join(resources, 'node_modules', 'better-sqlite3', 'index.js'),
'module.exports = class { prepare() { return { get: () => ({ 1: 1 }) }; } };\n',