From 9ac6b9f0d4c13d8e833256928afc201d667a316d Mon Sep 17 00:00:00 2001 From: "shumeiko.it" Date: Wed, 4 Nov 2026 10:24:35 +0100 Subject: [PATCH] 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. --- .gitignore | 3 + packages/server/tests/tauri-config.test.ts | 16 +++++ scripts/build-server-archive.mjs | 7 +- scripts/build-server-archive.test.ts | 75 ++++++++++++++++++++++ scripts/build-sidecar.mjs | 11 ++++ scripts/release-smoke.test.ts | 2 + 6 files changed, 112 insertions(+), 2 deletions(-) create mode 100644 scripts/build-server-archive.test.ts diff --git a/.gitignore b/.gitignore index aa98f84..2ba6649 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/packages/server/tests/tauri-config.test.ts b/packages/server/tests/tauri-config.test.ts index 3e2a5ed..3cc728a 100644 --- a/packages/server/tests/tauri-config.test.ts +++ b/packages/server/tests/tauri-config.test.ts @@ -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([ + ['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( diff --git a/scripts/build-server-archive.mjs b/scripts/build-server-archive.mjs index 02f93d6..baaaedf 100644 --- a/scripts/build-server-archive.mjs +++ b/scripts/build-server-archive.mjs @@ -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; diff --git a/scripts/build-server-archive.test.ts b/scripts/build-server-archive.test.ts new file mode 100644 index 0000000..ec69a8a --- /dev/null +++ b/scripts/build-server-archive.test.ts @@ -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 = { + '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'), ''); + 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); + }); +}); diff --git a/scripts/build-sidecar.mjs b/scripts/build-sidecar.mjs index 64a0e52..58398c1 100644 --- a/scripts/build-sidecar.mjs +++ b/scripts/build-sidecar.mjs @@ -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); diff --git a/scripts/release-smoke.test.ts b/scripts/release-smoke.test.ts index 2d31387..a4badcf 100644 --- a/scripts/release-smoke.test.ts +++ b/scripts/release-smoke.test.ts @@ -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',