Files
waggle-os/packages/core/tests/license-headers.test.ts
shumeiko.it 0fef37ac53 chore(core): mark the files copied from hive-mind-core as Apache-2.0
The logger, injection scanner, ingress guard, WorkspaceManager, embedders,
recall helpers and execution traces came from @waggle/hive-mind-core
(Apache-2.0); awareness, identity and parts of WaggleDB were adapted from
it. They keep Apache-2.0: an SPDX header with the original copyright line
and the source file, packages/core/LICENSE.md listing them,
LICENSE-APACHE with the full text, and "MIT AND Apache-2.0" in
package.json. A test keeps the list and the headers in step. No code
changes.

Logs UF-069: the hive-mind-core LICENSE is an abridged Apache text.
2026-11-04 10:19:05 +01:00

52 lines
2.2 KiB
TypeScript

/**
* The Apache-2.0 files of @waggle/core (copied from @waggle/hive-mind-core)
* carry an SPDX header, and LICENSE.md lists exactly those files.
*/
import fs from 'node:fs';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
const PACKAGE_DIR = path.resolve(import.meta.dirname, '..');
const APACHE_HEADER = /^\/\/ SPDX-License-Identifier: Apache-2\.0\n\/\/ Copyright 2026 Marko Marković · Egzakta Group · waggle-os\.ai\n\/\/ (?:Parts copied|Copied) from @waggle\/hive-mind-core (\S+) (?:without changes|and changed for @waggle\/core)\.\n/;
function sourceFiles(dir: string): string[] {
return fs.readdirSync(path.join(PACKAGE_DIR, dir), { withFileTypes: true }).flatMap((entry) => {
const relative = `${dir}/${entry.name}`;
if (entry.isDirectory()) return sourceFiles(relative);
return /\.tsx?$/.test(entry.name) ? [relative] : [];
});
}
describe('@waggle/core license headers', () => {
const headed = new Map<string, string>();
for (const file of [...sourceFiles('src'), ...sourceFiles('tests')]) {
const text = fs.readFileSync(path.join(PACKAGE_DIR, file), 'utf8');
if (text.startsWith('// SPDX-License-Identifier')) {
const match = APACHE_HEADER.exec(text);
expect(match, `${file} has a malformed SPDX header`).not.toBeNull();
headed.set(file, match![1]);
}
}
const listed = new Map(
[...fs.readFileSync(path.join(PACKAGE_DIR, 'LICENSE.md'), 'utf8')
.matchAll(/^\| `([^`]+)` \| `([^`]+)` \|/gm)]
.map((match) => [match[1], match[2]]),
);
it('lists every Apache-2.0 file in LICENSE.md with the file it came from', () => {
expect(headed.size).toBeGreaterThan(0);
expect(Object.fromEntries(listed)).toEqual(Object.fromEntries(headed));
});
it('ships the full Apache-2.0 text next to the note', () => {
const text = fs.readFileSync(path.join(PACKAGE_DIR, 'LICENSE-APACHE'), 'utf8');
expect(text).toContain('TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION');
expect(text).toContain('END OF TERMS AND CONDITIONS');
});
it('declares both licenses in package.json', () => {
const manifest = JSON.parse(fs.readFileSync(path.join(PACKAGE_DIR, 'package.json'), 'utf8'));
expect(manifest.license).toBe('MIT AND Apache-2.0');
});
});