2267 lines
95 KiB
TypeScript
2267 lines
95 KiB
TypeScript
/**
|
|
* 9D-1/9D-2/9D-7: Tauri configuration tests.
|
|
*
|
|
* Validates tauri.conf.json, Cargo.toml, lib.rs, and build scripts
|
|
* are properly configured for production desktop builds.
|
|
*/
|
|
import { beforeEach, describe, it, expect } from 'vitest';
|
|
import fs from 'node:fs';
|
|
import { createHash } from 'node:crypto';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { execFile, spawnSync } from 'node:child_process';
|
|
import { pathToFileURL } from 'node:url';
|
|
import Database from 'better-sqlite3';
|
|
import { parse as parseYaml } from 'yaml';
|
|
|
|
const ROOT = path.resolve(import.meta.dirname, '..', '..', '..');
|
|
const TAURI_DIR = path.join(ROOT, 'app', 'src-tauri');
|
|
const WINDOWS_1252_EXTRA_CODEPOINTS = new Set([
|
|
0x20ac, 0x201a, 0x0192, 0x201e, 0x2026, 0x2020, 0x2021, 0x02c6, 0x2030,
|
|
0x0160, 0x2039, 0x0152, 0x017d, 0x2018, 0x2019, 0x201c, 0x201d, 0x2022,
|
|
0x2013, 0x2014, 0x02dc, 0x2122, 0x0161, 0x203a, 0x0153, 0x017e, 0x0178,
|
|
]);
|
|
// Declared dependencies the staged runtime never loads: onnxruntime-web (the
|
|
// browser backend of Transformers.js) and chromium-bidi, which Puppeteer loads
|
|
// only for WebDriver BiDi sessions; whatsapp-web.js drives Chrome over CDP.
|
|
const STAGED_DEPENDENCY_ALLOWLIST = new Set(['onnxruntime-web', 'chromium-bidi']);
|
|
const FIRST_PARTY_RUNTIME_ENTRIES = new Set([
|
|
'dist',
|
|
'LICENSE',
|
|
'LICENSE.md',
|
|
'LICENSE.txt',
|
|
'NOTICE',
|
|
'NOTICE.md',
|
|
'NOTICE.txt',
|
|
'package.json',
|
|
]);
|
|
const SOURCE_ARTIFACT_PATTERN = /(?:\.map|\.(?:[cm]?ts|tsx)|\.tsbuildinfo)$/i;
|
|
|
|
beforeEach(async () => {
|
|
// Let Vitest acknowledge the previous task update before the next test enters
|
|
// a synchronous Windows child-process probe that can occupy the worker thread.
|
|
await new Promise<void>((resolve) => setImmediate(resolve));
|
|
});
|
|
|
|
function powershellProbeExecutable() {
|
|
const configuredPwsh = process.env.WAGGLE_PWSH7_PATH;
|
|
const powerShellMajor = (executable: string) => {
|
|
const result = spawnSync(
|
|
executable,
|
|
['-NoLogo', '-NoProfile', '-Command', '$PSVersionTable.PSVersion.Major'],
|
|
{ encoding: 'utf-8', timeout: 10_000, windowsHide: true },
|
|
);
|
|
const major = Number.parseInt(result.stdout?.trim() ?? '', 10);
|
|
return result.status === 0 && Number.isInteger(major) ? major : undefined;
|
|
};
|
|
const requirePowerShell7 = (executable: string) => {
|
|
if ((powerShellMajor(executable) ?? 0) < 7) {
|
|
throw new Error('PowerShell 7 required Windows release-workflow probes');
|
|
}
|
|
return executable;
|
|
};
|
|
if (configuredPwsh) {
|
|
if (!fs.existsSync(configuredPwsh)) {
|
|
throw new Error('Configured PowerShell 7 probe executable is missing');
|
|
}
|
|
return requirePowerShell7(configuredPwsh);
|
|
}
|
|
const pwshCandidates = [
|
|
path.join(
|
|
process.env.ProgramFiles ?? 'C:\\Program Files',
|
|
'PowerShell',
|
|
'7',
|
|
'pwsh.exe',
|
|
),
|
|
process.env.LOCALAPPDATA
|
|
? path.join(process.env.LOCALAPPDATA, 'Microsoft', 'WindowsApps', 'pwsh.exe')
|
|
: undefined,
|
|
];
|
|
for (const pwsh of pwshCandidates) {
|
|
// Windows Store app execution aliases report false through fs.existsSync,
|
|
// so probe the executable rather than treating metadata access as authority.
|
|
if (pwsh && (powerShellMajor(pwsh) ?? 0) >= 7) return pwsh;
|
|
}
|
|
if (process.env.WAGGLE_REQUIRE_PWSH7 === '1') {
|
|
throw new Error('PowerShell 7 is required for Windows release-workflow probes');
|
|
}
|
|
return path.join(
|
|
process.env.SystemRoot ?? 'C:\\Windows',
|
|
'System32',
|
|
'WindowsPowerShell',
|
|
'v1.0',
|
|
'powershell.exe',
|
|
);
|
|
}
|
|
|
|
function isWindows1252PathSafe(value: string) {
|
|
for (const char of value) {
|
|
const code = char.codePointAt(0) ?? 0;
|
|
if (code <= 0x7f || (code >= 0xa0 && code <= 0xff)) continue;
|
|
if (WINDOWS_1252_EXTRA_CODEPOINTS.has(code)) continue;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
function listFiles(dir: string) {
|
|
const files: string[] = [];
|
|
const stack = [dir];
|
|
while (stack.length > 0) {
|
|
const current = stack.pop()!;
|
|
for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
|
|
const full = path.join(current, entry.name);
|
|
if (entry.isDirectory()) stack.push(full);
|
|
else if (entry.isFile()) files.push(full);
|
|
}
|
|
}
|
|
return files;
|
|
}
|
|
|
|
function listPackageDirs(nodeModulesDir: string) {
|
|
if (!fs.existsSync(nodeModulesDir)) return [];
|
|
const packageDirs: string[] = [];
|
|
const stack = [nodeModulesDir];
|
|
while (stack.length > 0) {
|
|
const current = stack.pop()!;
|
|
for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
|
|
if (!entry.isDirectory()) continue;
|
|
const full = path.join(current, entry.name);
|
|
if (fs.existsSync(path.join(full, 'package.json'))) {
|
|
packageDirs.push(full);
|
|
}
|
|
stack.push(full);
|
|
}
|
|
}
|
|
return packageDirs;
|
|
}
|
|
|
|
function resolveWithinStagedResources(fromPackageDir: string, dep: string, resourcesDir: string) {
|
|
let current = fromPackageDir;
|
|
for (;;) {
|
|
const candidate = path.join(current, 'node_modules', ...dep.split('/'), 'package.json');
|
|
if (fs.existsSync(candidate)) return true;
|
|
if (path.resolve(current) === path.resolve(resourcesDir)) return false;
|
|
const parent = path.dirname(current);
|
|
if (parent === current) return false;
|
|
current = parent;
|
|
}
|
|
}
|
|
|
|
function localWorkspacePackageNames() {
|
|
const names = new Set<string>();
|
|
for (const workspaceRoot of ['packages', 'apps'].map((entry) => path.join(ROOT, entry))) {
|
|
if (!fs.existsSync(workspaceRoot)) continue;
|
|
for (const entry of fs.readdirSync(workspaceRoot, { withFileTypes: true })) {
|
|
if (!entry.isDirectory()) continue;
|
|
try {
|
|
const manifest = JSON.parse(
|
|
fs.readFileSync(path.join(workspaceRoot, entry.name, 'package.json'), 'utf-8'),
|
|
) as { name?: unknown };
|
|
if (typeof manifest.name === 'string') names.add(manifest.name);
|
|
} catch {
|
|
// Non-package workspace directories are irrelevant to staged runtime checks.
|
|
}
|
|
}
|
|
}
|
|
return names;
|
|
}
|
|
|
|
describe('Tauri Production Configuration', () => {
|
|
it('pins Tauri-rewritten manifests and generated schemas to LF across platforms', () => {
|
|
const trackedPaths = [
|
|
'app/src-tauri/Cargo.toml',
|
|
'app/src-tauri/gen/schemas/windows-schema.json',
|
|
'app/src-tauri/gen/schemas/desktop-schema.json',
|
|
];
|
|
const result = spawnSync('git', ['check-attr', '-z', 'text', 'eol', '--', ...trackedPaths], {
|
|
cwd: ROOT,
|
|
encoding: 'utf-8',
|
|
windowsHide: true,
|
|
});
|
|
|
|
expect(result.error).toBeUndefined();
|
|
expect(result.status).toBe(0);
|
|
const fields = result.stdout.split('\0').filter(Boolean);
|
|
const effectiveAttributes = new Map<string, string>();
|
|
for (let index = 0; index < fields.length; index += 3) {
|
|
effectiveAttributes.set(`${fields[index]}:${fields[index + 1]}`, fields[index + 2]);
|
|
}
|
|
for (const trackedPath of trackedPaths) {
|
|
expect(effectiveAttributes.get(`${trackedPath}:text`)).toBe('set');
|
|
expect(effectiveAttributes.get(`${trackedPath}:eol`)).toBe('lf');
|
|
}
|
|
});
|
|
|
|
it('tauri.conf.json exists and has valid version', () => {
|
|
const conf = JSON.parse(fs.readFileSync(path.join(TAURI_DIR, 'tauri.conf.json'), 'utf-8'));
|
|
expect(conf.productName).toBe('Waggle');
|
|
expect(conf.version).toMatch(/^\d+\.\d+\.\d+$/);
|
|
// Canonical bundle identifier — Egzakta-branded for code signing
|
|
// + App Store / Mac notarization. Set in tauri.conf.json. Don't
|
|
// change without coordinating with the signing cert subject.
|
|
expect(conf.identifier).toBe('com.egzakta.waggle');
|
|
});
|
|
|
|
it('tauri.conf.json has bundle targets configured', () => {
|
|
const conf = JSON.parse(fs.readFileSync(path.join(TAURI_DIR, 'tauri.conf.json'), 'utf-8'));
|
|
// targets: "all" builds for the current platform (NSIS on Windows, DMG on macOS, etc.)
|
|
expect(conf.bundle.targets).toBe('all');
|
|
expect(conf.bundle.active).toBe(true);
|
|
});
|
|
|
|
it('tauri.conf.json bundles resources directory', () => {
|
|
const conf = JSON.parse(fs.readFileSync(path.join(TAURI_DIR, 'tauri.conf.json'), 'utf-8'));
|
|
expect(conf.bundle.resources).toContain('resources/*');
|
|
// UF-066: the bundled SDK reads these next to service.js.
|
|
expect(conf.bundle.resources).toContain('resources/capability-packs/*');
|
|
expect(conf.bundle.resources).toContain('resources/starter-skills/*');
|
|
});
|
|
|
|
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];
|
|
expect(win.title).toBe('Waggle');
|
|
expect(win.create).toBe(false);
|
|
expect(win.width).toBe(1200);
|
|
expect(win.height).toBe(800);
|
|
expect(win.minWidth).toBe(800);
|
|
expect(win.minHeight).toBe(600);
|
|
expect(win.resizable).toBe(true);
|
|
|
|
// The shipped app never opens a WebView debugging port.
|
|
const lib = fs.readFileSync(path.join(TAURI_DIR, 'src', 'lib.rs'), 'utf-8');
|
|
expect(lib).toContain('WebviewWindowBuilder::from_config');
|
|
expect(lib).not.toContain('remote-debugging-port');
|
|
});
|
|
|
|
it('tauri.conf.json has the auto-updater intentionally disabled for v1', () => {
|
|
// The updater plugin config was removed because release.yml published
|
|
// latest.json with EMPTY signatures — with a pubkey present, every client
|
|
// update would fail signature verification (a broken update channel). It
|
|
// stays disabled until updater signing is provisioned (TAURI_SIGNING_PRIVATE_KEY
|
|
// + createUpdaterArtifacts + a real-signature manifest generator).
|
|
const conf = JSON.parse(fs.readFileSync(path.join(TAURI_DIR, 'tauri.conf.json'), 'utf-8'));
|
|
expect(conf.plugins?.updater).toBeUndefined();
|
|
});
|
|
|
|
it('creates exactly one tray icon from Rust so the context menu is always attached', () => {
|
|
const conf = JSON.parse(fs.readFileSync(path.join(TAURI_DIR, 'tauri.conf.json'), 'utf-8'));
|
|
expect(conf.app.trayIcon).toBeUndefined();
|
|
|
|
const tray = fs.readFileSync(path.join(TAURI_DIR, 'src', 'tray.rs'), 'utf-8');
|
|
expect(tray).toContain('TrayIconBuilder::new()');
|
|
expect(tray).toContain('.menu(&menu)');
|
|
});
|
|
|
|
it('tray menu exposes only implemented desktop actions', () => {
|
|
const tray = fs.readFileSync(path.join(TAURI_DIR, 'src', 'tray.rs'), 'utf-8');
|
|
expect(tray).toContain('"Open Waggle"');
|
|
expect(tray).toContain('"Settings"');
|
|
expect(tray).toContain('"Quit Waggle"');
|
|
expect(tray).toContain('app.exit(0)');
|
|
expect(tray).toContain('.show_menu_on_left_click(false)');
|
|
expect(tray).toContain('button: MouseButton::Left');
|
|
expect(tray).toContain('button_state: MouseButtonState::Up');
|
|
expect(tray).toContain('"waggle://navigate"');
|
|
expect(tray).toContain('"/settings"');
|
|
|
|
expect(tray).not.toContain('"Pause Agents"');
|
|
expect(tray).not.toContain('"About Waggle"');
|
|
expect(tray).not.toContain('"waggle://pause-agents"');
|
|
expect(tray).not.toContain('"waggle://quit"');
|
|
expect(tray).not.toContain('"/about"');
|
|
});
|
|
|
|
it('packaged Windows sidecar stays hidden and writes bounded diagnostics', () => {
|
|
const service = fs.readFileSync(path.join(TAURI_DIR, 'src', 'service.rs'), 'utf-8');
|
|
|
|
expect(service).toContain('const CREATE_NO_WINDOW: u32 = 0x08000000');
|
|
expect(service).toContain('command.creation_flags(CREATE_NO_WINDOW)');
|
|
expect(service).toContain('service.log');
|
|
expect(service).toContain('MAX_SERVICE_LOG_BYTES');
|
|
expect(service).toContain('rotate_service_log');
|
|
});
|
|
|
|
it('preserves detached user sessions while IPC-supervising owned service runtimes', () => {
|
|
const service = fs.readFileSync(path.join(TAURI_DIR, 'src', 'service.rs'), 'utf-8');
|
|
const lifecycle = fs.readFileSync(
|
|
path.join(ROOT, 'packages', 'server', 'src', 'local', 'lifecycle.ts'),
|
|
'utf-8',
|
|
);
|
|
|
|
expect(service).toContain('JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK');
|
|
expect(lifecycle).toContain('spawnSidecarOwnedProcess');
|
|
expect(lifecycle).not.toMatch(/litellmProcess\s*=\s*spawn\(/);
|
|
});
|
|
|
|
it('web app mounts the Tauri desktop navigation bridge', () => {
|
|
const app = fs.readFileSync(path.join(ROOT, 'apps', 'web', 'src', 'App.tsx'), 'utf-8');
|
|
expect(app).toContain('listenDesktopNavigation');
|
|
expect(app).toContain('listenDesktopShellEvents');
|
|
expect(app).toContain('<TauriDesktopEventBridge />');
|
|
});
|
|
|
|
it('tauri.conf.json has CSP that allows localhost connections', () => {
|
|
const conf = JSON.parse(fs.readFileSync(path.join(TAURI_DIR, 'tauri.conf.json'), 'utf-8'));
|
|
const csp = conf.app.security.csp;
|
|
expect(csp).toContain('http://localhost:*');
|
|
expect(csp).toContain('ws://localhost:*');
|
|
});
|
|
|
|
it('desktop startup remains visible when the app bundle cannot mount', () => {
|
|
const main = fs.readFileSync(
|
|
path.join(ROOT, 'apps', 'web', 'src', 'main.tsx'),
|
|
'utf-8',
|
|
);
|
|
const css = fs.readFileSync(
|
|
path.join(ROOT, 'apps', 'web', 'src', 'index.css'),
|
|
'utf-8',
|
|
);
|
|
const appEntry = fs.readFileSync(
|
|
path.join(ROOT, 'apps', 'web', 'src', 'app-entry.tsx'),
|
|
'utf-8',
|
|
);
|
|
|
|
expect(main).toContain("document.getElementById('root')");
|
|
expect(main).toContain('Starting Waggle');
|
|
expect(main).toContain("startup.dataset.waggleStartup = 'loading'");
|
|
expect(main).toContain("import('./app-entry')");
|
|
expect(main).toContain('.catch((error) =>');
|
|
expect(main).toContain('Waggle could not start');
|
|
expect(appEntry).toContain("dataset.waggleUiReady = 'ready'");
|
|
expect(css).not.toMatch(/@import\s+(?:url\()?['"]?https?:\/\//i);
|
|
});
|
|
|
|
it('desktop CSP permits only the local Tauri IPC bridge', () => {
|
|
const conf = JSON.parse(fs.readFileSync(path.join(TAURI_DIR, 'tauri.conf.json'), 'utf-8'));
|
|
const csp = conf.app.security.csp;
|
|
|
|
expect(csp).toContain('ipc:');
|
|
expect(csp).toContain('http://ipc.localhost');
|
|
expect(csp).not.toContain('https://fonts.googleapis.com');
|
|
});
|
|
|
|
it('Cargo.toml has no updater plugin while the updater is disabled', () => {
|
|
const cargo = fs.readFileSync(path.join(TAURI_DIR, 'Cargo.toml'), 'utf-8');
|
|
expect(cargo).not.toContain('tauri-plugin-updater');
|
|
expect(cargo).toContain('tauri-plugin-notification');
|
|
expect(cargo).toContain('tauri-plugin-single-instance');
|
|
});
|
|
|
|
it('capabilities do not expose updater commands while updater config is disabled', () => {
|
|
const caps = JSON.parse(
|
|
fs.readFileSync(path.join(TAURI_DIR, 'capabilities', 'default.json'), 'utf-8'),
|
|
);
|
|
expect(caps.permissions).not.toContain('updater:default');
|
|
});
|
|
|
|
it('does not configure unit-only Tauri plugins as objects', () => {
|
|
// Regression: the packaged debug exe panicked during startup when
|
|
// `plugins.dialog` was `{ open, save }`; tauri-plugin-dialog expects no
|
|
// config payload when initialized with `tauri_plugin_dialog::init()`.
|
|
const conf = JSON.parse(fs.readFileSync(path.join(TAURI_DIR, 'tauri.conf.json'), 'utf-8'));
|
|
expect(conf.plugins?.dialog).toBeUndefined();
|
|
});
|
|
|
|
it('lib.rs does not initialize updater while config is disabled', () => {
|
|
// Regression: registering tauri-plugin-updater without plugins.updater
|
|
// config deserializes as null and panics before the desktop UI starts.
|
|
const lib = fs.readFileSync(path.join(TAURI_DIR, 'src', 'lib.rs'), 'utf-8');
|
|
expect(lib).not.toContain('tauri_plugin_updater::Builder::new().build()');
|
|
expect(lib).not.toContain('.updater()');
|
|
});
|
|
|
|
it('NSIS installer template never deletes profile data', () => {
|
|
const nsis = fs.readFileSync(path.join(TAURI_DIR, 'nsis', 'installer.nsi'), 'utf-8');
|
|
const conf = JSON.parse(fs.readFileSync(path.join(TAURI_DIR, 'tauri.conf.json'), 'utf-8'));
|
|
expect(nsis).toContain('NSIS_HOOK_PREINSTALL');
|
|
// Data erasure is an authenticated, confirmation-phrase-gated in-app flow.
|
|
// The package uninstaller must never recursively delete the real profile.
|
|
expect(nsis).not.toContain('NSIS_HOOK_POSTUNINSTALL');
|
|
expect(nsis).toContain('NSIS_HOOK_PREUNINSTALL');
|
|
expect(nsis).toMatch(/StrCpy\s+\$DeleteAppDataCheckboxState\s+0/);
|
|
expect(nsis).not.toMatch(
|
|
/\b(?:RMDir|Delete)\b[^\r\n]*(?:\$PROFILE[\\/]+\.waggle|\.waggle)/i,
|
|
);
|
|
expect(conf.bundle.windows.nsis.installerHooks).toBe('nsis/installer.nsi');
|
|
expect(conf.bundle.windows.nsis.installMode).toBe('currentUser');
|
|
// Tauri owns shortcuts and normal/silent launch behavior. Duplicating those
|
|
// in POSTINSTALL caused double launches and made repair certificates racy.
|
|
expect(nsis).not.toContain('NSIS_HOOK_POSTINSTALL');
|
|
expect(nsis).not.toContain('CreateShortcut');
|
|
expect(nsis).not.toMatch(/\bExec\s+['"]/);
|
|
});
|
|
|
|
it('icon.ico exists', () => {
|
|
expect(fs.existsSync(path.join(TAURI_DIR, 'icons', 'icon.ico'))).toBe(true);
|
|
});
|
|
|
|
it('build-sidecar script exists', () => {
|
|
const script = path.join(ROOT, 'scripts', 'build-sidecar.mjs');
|
|
expect(fs.existsSync(script)).toBe(true);
|
|
const content = fs.readFileSync(script, 'utf-8');
|
|
expect(content).toContain('esbuild');
|
|
expect(content).toContain('service.ts');
|
|
expect(content).toContain('resources/service.js');
|
|
expect(content).toContain('sourcemap: false');
|
|
expect(content).toContain('fs.rmSync(sourceMapFile, { force: true })');
|
|
expect(content).toContain("path.join(root, 'packages', 'marketplace', 'marketplace.db')");
|
|
expect(content).not.toContain("'marketplace', 'seed', 'marketplace.db'");
|
|
expect(content).toContain('Required marketplace database is missing');
|
|
// Workspace packages compile from src/ through their `source` export (P2.1).
|
|
expect(content).toContain("conditions: ['source']");
|
|
|
|
const serverIndex = fs.readFileSync(
|
|
path.join(ROOT, 'packages', 'server', 'src', 'local', 'index.ts'),
|
|
'utf-8',
|
|
);
|
|
expect(serverIndex).toContain("path.resolve(__dirname, 'marketplace.db')");
|
|
});
|
|
|
|
it('build-sidecar source condition resolves the agent env helper subpath from src', async () => {
|
|
const esbuild = await import('esbuild');
|
|
const result = await esbuild.build({
|
|
stdin: {
|
|
contents: "import { buildExternalProcessEnv } from '@waggle/agent/external-process-env'; export const env = buildExternalProcessEnv({ PATH: 'fixture' });",
|
|
loader: 'ts',
|
|
resolveDir: ROOT,
|
|
sourcefile: 'sidecar-agent-subpath-probe.ts',
|
|
},
|
|
absWorkingDir: ROOT,
|
|
bundle: true,
|
|
platform: 'node',
|
|
target: 'node20',
|
|
format: 'esm',
|
|
write: false,
|
|
logLevel: 'silent',
|
|
conditions: ['source'],
|
|
metafile: true,
|
|
});
|
|
|
|
expect(result.errors).toEqual([]);
|
|
expect(result.outputFiles[0]?.text).toContain('buildExternalProcessEnv');
|
|
expect(Object.keys(result.metafile?.inputs ?? {})).toContain(
|
|
'packages/agent/src/external-process-env.ts',
|
|
);
|
|
});
|
|
|
|
it('build-sidecar provenance follows transitive tsconfig inheritance', () => {
|
|
const fixtureRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-sidecar-tsconfig-'));
|
|
const writeRelative = (relative: string, content: string | Buffer) => {
|
|
const target = path.join(fixtureRoot, ...relative.split('/'));
|
|
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
fs.writeFileSync(target, content);
|
|
return target;
|
|
};
|
|
const runResult = (command: string, args: string[]) => spawnSync(command, args, {
|
|
cwd: fixtureRoot,
|
|
env: {
|
|
...process.env,
|
|
TEMP: fixtureRoot,
|
|
TMP: fixtureRoot,
|
|
TMPDIR: fixtureRoot,
|
|
},
|
|
encoding: 'utf8',
|
|
timeout: 60_000,
|
|
windowsHide: true,
|
|
});
|
|
const run = (command: string, args: string[]) => {
|
|
const result = runResult(command, args);
|
|
expect(result.status, result.stderr || result.stdout).toBe(0);
|
|
return result;
|
|
};
|
|
|
|
try {
|
|
fs.mkdirSync(path.join(fixtureRoot, 'scripts'), { recursive: true });
|
|
fs.copyFileSync(
|
|
path.join(ROOT, 'scripts', 'build-sidecar.mjs'),
|
|
path.join(fixtureRoot, 'scripts', 'build-sidecar.mjs'),
|
|
);
|
|
const trackedFiles = new Map<string, string>([
|
|
['package-lock.json', '{"lockfileVersion":3}\n'],
|
|
['package.json', '{"name":"sidecar-tsconfig-fixture","private":true}\n'],
|
|
['packages/marketplace/marketplace.db', 'fixture database'],
|
|
['packages/sdk/src/capability-packs/research-workflow.json', '{"id":"research-workflow"}\n'],
|
|
['packages/sdk/src/starter-skills/brainstorm.md', '# Brainstorm\n'],
|
|
['packages/server/package.json', '{"name":"@waggle/server"}\n'],
|
|
['packages/server/src/local/service.ts', 'export const fixture = true;\n'],
|
|
['packages/server/tsconfig.json', '{"extends":"../../tsconfig.base"}\n'],
|
|
['tsconfig.base.json', '{"extends":["./tsconfig.shared"]}\n'],
|
|
['tsconfig.shared.json', '{"compilerOptions":{"target":"ES2022"}}\n'],
|
|
]);
|
|
for (const [relative, content] of trackedFiles) writeRelative(relative, content);
|
|
writeRelative(
|
|
'node_modules/esbuild/package.json',
|
|
JSON.stringify({ name: 'esbuild', version: '0.0.0', type: 'module', exports: './index.js' }),
|
|
);
|
|
writeRelative(
|
|
'node_modules/esbuild/index.js',
|
|
[
|
|
"import fs from 'node:fs';",
|
|
"import path from 'node:path';",
|
|
'export async function build(options) {',
|
|
' fs.mkdirSync(path.dirname(options.outfile), { recursive: true });',
|
|
" fs.writeFileSync(options.outfile, 'fixture bundle\\n');",
|
|
' return {',
|
|
' errors: [],',
|
|
' warnings: [],',
|
|
" metafile: { inputs: { 'packages/server/src/local/service.ts': { bytes: 29, imports: [] } } },",
|
|
' };',
|
|
'}',
|
|
'',
|
|
].join('\n'),
|
|
);
|
|
writeRelative(
|
|
'node_modules/typescript/package.json',
|
|
JSON.stringify({ name: 'typescript', version: '0.0.0', type: 'module', exports: './index.js' }),
|
|
);
|
|
writeRelative(
|
|
'node_modules/typescript/index.js',
|
|
[
|
|
'export default {',
|
|
' parseConfigFileTextToJson(_file, text) {',
|
|
' try { return { config: JSON.parse(text) }; }',
|
|
' catch (error) { return { error }; }',
|
|
' },',
|
|
'};',
|
|
'',
|
|
].join('\n'),
|
|
);
|
|
|
|
run('git', ['init']);
|
|
run('git', ['config', 'user.email', 'sidecar-tsconfig@waggle.invalid']);
|
|
run('git', ['config', 'user.name', 'Waggle Fixture']);
|
|
run('git', ['add', '--', 'scripts/build-sidecar.mjs', ...trackedFiles.keys()]);
|
|
run('git', ['commit', '-m', 'fixture']);
|
|
run(process.execPath, ['scripts/build-sidecar.mjs']);
|
|
|
|
const service = fs.readFileSync(
|
|
path.join(fixtureRoot, 'app', 'src-tauri', 'resources', 'service.js'),
|
|
);
|
|
const lineEnd = service.indexOf(0x0a);
|
|
const prefix = '// Waggle-Sidecar-Provenance: ';
|
|
const firstLine = service.subarray(0, lineEnd).toString('utf8');
|
|
expect(firstLine.startsWith(prefix)).toBe(true);
|
|
const manifest = JSON.parse(
|
|
Buffer.from(firstLine.slice(prefix.length), 'base64').toString('utf8'),
|
|
) as { sourceInputs: Array<{ path: string }> };
|
|
const sourcePaths = manifest.sourceInputs.map((input) => input.path);
|
|
expect(sourcePaths).toEqual(
|
|
expect.arrayContaining([
|
|
'packages/server/tsconfig.json',
|
|
'tsconfig.base.json',
|
|
'tsconfig.shared.json',
|
|
]),
|
|
);
|
|
const marketplacePath = path.join(
|
|
fixtureRoot,
|
|
'packages',
|
|
'marketplace',
|
|
'marketplace.db',
|
|
);
|
|
const marketplaceResourcePath = path.join(
|
|
fixtureRoot,
|
|
'app',
|
|
'src-tauri',
|
|
'resources',
|
|
'marketplace.db',
|
|
);
|
|
const committedMarketplace = Buffer.from(
|
|
trackedFiles.get('packages/marketplace/marketplace.db')!,
|
|
);
|
|
expect(fs.readFileSync(marketplaceResourcePath)).toEqual(committedMarketplace);
|
|
// UF-066: the SDK reads packs and starter skills next to service.js.
|
|
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);
|
|
|
|
fs.writeFileSync(marketplacePath, 'dirty worktree database');
|
|
const dirtyMarketplaceResult = runResult(
|
|
process.execPath,
|
|
['scripts/build-sidecar.mjs'],
|
|
);
|
|
expect(
|
|
dirtyMarketplaceResult.status,
|
|
dirtyMarketplaceResult.stderr || dirtyMarketplaceResult.stdout,
|
|
).toBe(1);
|
|
expect(dirtyMarketplaceResult.stderr).toContain(
|
|
'canonical marketplace database does not match exact source revision',
|
|
);
|
|
expect(fs.readFileSync(marketplaceResourcePath)).toEqual(committedMarketplace);
|
|
expect(
|
|
fs.readdirSync(path.dirname(marketplaceResourcePath))
|
|
.filter((name) => name.startsWith('marketplace.db.stage-')),
|
|
).toEqual([]);
|
|
|
|
// A source archive has no .git: the build still succeeds, records no
|
|
// revision and ships the database it finds on disk.
|
|
fs.rmSync(path.join(fixtureRoot, '.git'), { recursive: true, force: true });
|
|
run(process.execPath, ['scripts/build-sidecar.mjs']);
|
|
const archiveService = fs.readFileSync(
|
|
path.join(fixtureRoot, 'app', 'src-tauri', 'resources', 'service.js'),
|
|
);
|
|
const archiveLine = archiveService
|
|
.subarray(0, archiveService.indexOf(0x0a))
|
|
.toString('utf8');
|
|
const archiveManifest = JSON.parse(
|
|
Buffer.from(archiveLine.slice(prefix.length), 'base64').toString('utf8'),
|
|
) as { sourceRevision: string | null };
|
|
expect(archiveManifest.sourceRevision).toBeNull();
|
|
expect(fs.readFileSync(marketplaceResourcePath, 'utf8')).toBe('dirty worktree database');
|
|
} finally {
|
|
fs.rmSync(fixtureRoot, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
it('D12: the bundled sidecar is generated at build time, never tracked', () => {
|
|
// beforeBuildCommand regenerates the bundle on EVERY build path — including
|
|
// a raw `npx tauri build` that bypasses the npm scripts and CI steps. A
|
|
// tracked copy goes stale silently; a binary shipping an old server is a
|
|
// release-stopping defect class (UX-Refactor P4 / D12 ruling).
|
|
const conf = JSON.parse(fs.readFileSync(path.join(TAURI_DIR, 'tauri.conf.json'), 'utf-8'));
|
|
expect(conf.build.beforeBuildCommand).toContain('build-sidecar.mjs');
|
|
|
|
const gitignore = fs.readFileSync(path.join(ROOT, '.gitignore'), 'utf-8');
|
|
expect(gitignore).toContain('app/src-tauri/resources/service.js');
|
|
expect(gitignore).not.toContain('app/src-tauri/resources/service.js.map');
|
|
});
|
|
|
|
it('bundle-node pins the supported desktop Node release used by CI', () => {
|
|
const script = fs.readFileSync(path.join(ROOT, 'scripts', 'bundle-node.mjs'), 'utf-8');
|
|
expect(script).toContain("const DESKTOP_NODE_VERSION = '22.23.2'");
|
|
expect(script).toContain('const NODE_VERSION = DESKTOP_NODE_VERSION');
|
|
expect(script).toContain("const SAFE_NPM_IP_ADDRESS_VERSION = '10.4.0'");
|
|
expect(script).toContain('Hardened bundled npm with ip-address');
|
|
expect(script).not.toContain('process.versions.node;');
|
|
|
|
const workflow = fs.readFileSync(
|
|
path.join(ROOT, '.github', 'workflows', 'release.yml'),
|
|
'utf-8',
|
|
);
|
|
expect(workflow.match(/node-version: 22\.23\.2/g)).toHaveLength(1);
|
|
expect(workflow).not.toMatch(/node-version: 20(?:\s|$)/);
|
|
});
|
|
|
|
it('desktop builds verify the selected Node ABI before staging native resources', () => {
|
|
const manifest = JSON.parse(
|
|
fs.readFileSync(path.join(ROOT, 'app', 'package.json'), 'utf-8'),
|
|
) as { scripts?: Record<string, string> };
|
|
for (const scriptName of [
|
|
'tauri:build',
|
|
'tauri:build:local',
|
|
'tauri:build:win',
|
|
'tauri:build:mac:arm64',
|
|
'tauri:build:mac:x64',
|
|
'tauri:build:linux',
|
|
]) {
|
|
const command = manifest.scripts?.[scriptName] ?? '';
|
|
expect(command.indexOf('bundle-node.mjs'), scriptName).toBeGreaterThanOrEqual(0);
|
|
expect(command.indexOf('bundle-node.mjs'), scriptName).toBeLessThan(
|
|
command.indexOf('build-sidecar.mjs'),
|
|
);
|
|
expect(command.indexOf('bundle-node.mjs'), scriptName).toBeLessThan(
|
|
command.indexOf('bundle-native-deps.mjs'),
|
|
);
|
|
}
|
|
|
|
const script = fs.readFileSync(path.join(ROOT, 'scripts', 'bundle-node.mjs'), 'utf-8');
|
|
const probeIndex = script.indexOf('assertNativeRuntimeCompatible();');
|
|
const mutationIndex = script.indexOf('fs.copyFileSync(nodeSource, destBinary)');
|
|
const stagedRuntimeMutationIndex = script.indexOf(
|
|
'fs.rmSync(stagedRuntimeDir, { recursive: true, force: true })',
|
|
);
|
|
expect(probeIndex).toBeGreaterThanOrEqual(0);
|
|
expect(mutationIndex).toBeGreaterThan(probeIndex);
|
|
expect(stagedRuntimeMutationIndex).toBeGreaterThan(probeIndex);
|
|
expect(script).toContain("const database = new Database(':memory:')");
|
|
expect(script).toContain('SELECT 1 AS ok');
|
|
expect(script).toContain('native ABI compatibility probe failed');
|
|
});
|
|
|
|
it('pins patched transitive dependency versions used by desktop builds', () => {
|
|
const manifest = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf-8')) as {
|
|
engines?: { node?: string };
|
|
overrides?: Record<string, string | Record<string, string>>;
|
|
dependencies?: Record<string, string>;
|
|
};
|
|
const lockfile = JSON.parse(
|
|
fs.readFileSync(path.join(ROOT, 'package-lock.json'), 'utf-8'),
|
|
) as {
|
|
packages: Record<string, { version?: string }>;
|
|
};
|
|
const expectedOverrides = {
|
|
'@fastify/static': '>=10.1.2 <11',
|
|
'brace-expansion@1': '1.1.18',
|
|
'brace-expansion@2': '2.1.4',
|
|
'brace-expansion@5': '5.0.9',
|
|
'fast-uri': '3.1.5',
|
|
'ip-address': '10.4.0',
|
|
'find-my-way': '9.7.0',
|
|
'js-yaml': '4.3.1',
|
|
'better-sqlite3': '12.6.2',
|
|
'@huggingface/transformers': { sharp: '0.35.3' },
|
|
};
|
|
|
|
expect(manifest.engines?.node).toBe('^20.19.0 || >=22.12.0');
|
|
expect(manifest.overrides).toMatchObject(expectedOverrides);
|
|
expect(manifest.dependencies).toMatchObject({
|
|
'@huggingface/transformers': '3.8.1',
|
|
sharp: '0.35.3',
|
|
});
|
|
|
|
// The installer (packages/launcher) ships no server dependencies: it
|
|
// downloads the staged sidecar payload instead.
|
|
const fastifyStaticRanges = ['server'].map((workspace) => {
|
|
const workspaceManifest = JSON.parse(fs.readFileSync(
|
|
path.join(ROOT, 'packages', workspace, 'package.json'),
|
|
'utf-8',
|
|
)) as { dependencies?: Record<string, string> };
|
|
return workspaceManifest.dependencies?.['@fastify/static'];
|
|
});
|
|
expect(new Set(fastifyStaticRanges)).toEqual(new Set(['^10.1.2']));
|
|
|
|
const betterSqliteRanges = [
|
|
'core',
|
|
'marketplace',
|
|
'server',
|
|
].map((workspace) => {
|
|
const workspaceManifest = JSON.parse(fs.readFileSync(
|
|
path.join(ROOT, 'packages', workspace, 'package.json'),
|
|
'utf-8',
|
|
)) as { dependencies?: Record<string, string> };
|
|
return workspaceManifest.dependencies?.['better-sqlite3'];
|
|
});
|
|
expect(new Set(betterSqliteRanges)).toEqual(new Set(['^12.6.2']));
|
|
|
|
const versionsFor = (packageName: string) => {
|
|
const matching = Object.entries(lockfile.packages)
|
|
.filter(([packagePath]) => packagePath.endsWith(`node_modules/${packageName}`));
|
|
expect(matching.length).toBeGreaterThan(0);
|
|
for (const [, metadata] of matching) {
|
|
expect(metadata.version).toEqual(expect.any(String));
|
|
}
|
|
return new Set(matching.map(([, metadata]) => metadata.version!));
|
|
};
|
|
|
|
expect(versionsFor('@fastify/static')).toEqual(new Set(['10.1.2']));
|
|
expect(versionsFor('brace-expansion')).toEqual(new Set(['1.1.18', '2.1.4', '5.0.9']));
|
|
expect(versionsFor('fast-uri')).toEqual(new Set(['3.1.5']));
|
|
expect(versionsFor('ip-address')).toEqual(new Set(['10.4.0']));
|
|
expect(versionsFor('find-my-way')).toEqual(new Set(['9.7.0']));
|
|
expect(versionsFor('js-yaml')).toEqual(new Set(['4.3.1']));
|
|
expect(versionsFor('sharp')).toEqual(new Set(['0.35.3']));
|
|
expect(versionsFor('better-sqlite3')).toEqual(new Set(['12.6.2']));
|
|
const sharpBindings = Object.entries(lockfile.packages)
|
|
.filter(([packagePath]) => (
|
|
/node_modules\/@img\/sharp-(?!libvips-)[^/]+$/.test(packagePath)
|
|
));
|
|
expect(sharpBindings.length).toBeGreaterThan(0);
|
|
expect(new Set(sharpBindings.map(([, metadata]) => metadata.version))).toEqual(
|
|
new Set(['0.35.3']),
|
|
);
|
|
});
|
|
|
|
it('rejects unsafe staged dependency versions without native runtime setup', () => {
|
|
const fixture = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-dependency-floor-'));
|
|
const checker = path.join(ROOT, 'scripts', 'check-sidecar-resources.mjs');
|
|
const writeManifest = (relative: string, name?: string, version?: string) => {
|
|
const packageDir = path.join(fixture, ...relative.split('/'));
|
|
fs.mkdirSync(packageDir, { recursive: true });
|
|
fs.writeFileSync(
|
|
path.join(packageDir, 'package.json'),
|
|
JSON.stringify({ name, version }),
|
|
'utf-8',
|
|
);
|
|
return packageDir;
|
|
};
|
|
const run = () => spawnSync(
|
|
process.execPath,
|
|
[checker, '--dependency-versions-only', fixture],
|
|
{ encoding: 'utf-8', windowsHide: true },
|
|
);
|
|
const bundledBrace = [
|
|
'waggle-node-runtime',
|
|
'node_modules',
|
|
'npm',
|
|
'node_modules',
|
|
'brace-expansion',
|
|
].join('/');
|
|
|
|
try {
|
|
writeManifest('brace-expansion', 'brace-expansion', '5.0.9');
|
|
writeManifest('fast-uri', 'fast-uri', '3.1.5');
|
|
writeManifest('ip-address', 'ip-address', '10.4.0');
|
|
writeManifest('better-sqlite3', 'better-sqlite3', '12.9.0');
|
|
writeManifest('sharp', 'sharp', '0.35.3');
|
|
writeManifest(bundledBrace, 'brace-expansion', '2.1.4');
|
|
expect(run().status).toBe(0);
|
|
writeManifest('better-sqlite3', 'better-sqlite3', '12.6.2');
|
|
expect(run().status).toBe(0);
|
|
writeManifest('better-sqlite3', 'better-sqlite3', '12.9.0');
|
|
|
|
writeManifest('better-sqlite3', 'better-sqlite3', '11.10.0');
|
|
const legacyBetterSqlite = run();
|
|
expect(legacyBetterSqlite.status).toBe(1);
|
|
expect(legacyBetterSqlite.stderr).toContain('better-sqlite3@11.10.0');
|
|
|
|
writeManifest('better-sqlite3', 'better-sqlite3', '12.6.1');
|
|
expect(run().status).toBe(1);
|
|
writeManifest('better-sqlite3', 'better-sqlite3', '13.0.0');
|
|
expect(run().status).toBe(1);
|
|
writeManifest('better-sqlite3', 'not-better-sqlite3', '12.9.0');
|
|
const spoofedBetterSqlite = run();
|
|
expect(spoofedBetterSqlite.status).toBe(1);
|
|
expect(spoofedBetterSqlite.stderr).toContain('must identify as better-sqlite3');
|
|
writeManifest('better-sqlite3', 'better-sqlite3');
|
|
const missingBetterSqliteVersion = run();
|
|
expect(missingBetterSqliteVersion.status).toBe(1);
|
|
expect(missingBetterSqliteVersion.stderr).toContain('required version: >=12.6.2 <13');
|
|
for (const invalidVersion of [
|
|
'12.07.0',
|
|
'12.9007199254740992.0',
|
|
'12.6.2-beta.1',
|
|
'12.6.2+build.1',
|
|
]) {
|
|
writeManifest('better-sqlite3', 'better-sqlite3', invalidVersion);
|
|
const invalidBetterSqlite = run();
|
|
expect(
|
|
invalidBetterSqlite.status,
|
|
`${invalidVersion}: ${invalidBetterSqlite.stderr}`,
|
|
).toBe(1);
|
|
}
|
|
fs.rmSync(path.join(fixture, 'better-sqlite3'), { recursive: true, force: true });
|
|
writeManifest('Better-SQLite3', 'not-better-sqlite3', '12.9.0');
|
|
const uppercaseDirectBetterSqlite = run();
|
|
expect(uppercaseDirectBetterSqlite.status).toBe(1);
|
|
expect(uppercaseDirectBetterSqlite.stderr).toContain('must identify as better-sqlite3');
|
|
fs.rmSync(path.join(fixture, 'Better-SQLite3'), { recursive: true, force: true });
|
|
writeManifest(
|
|
'vendor/node_modules/Better-SQLite3',
|
|
'not-better-sqlite3',
|
|
'12.9.0',
|
|
);
|
|
const uppercaseNestedBetterSqlite = run();
|
|
expect(uppercaseNestedBetterSqlite.status).toBe(1);
|
|
expect(uppercaseNestedBetterSqlite.stderr).toContain('must identify as better-sqlite3');
|
|
fs.rmSync(path.join(fixture, 'vendor'), { recursive: true, force: true });
|
|
writeManifest('better-sqlite3', 'better-sqlite3', '12.9.0');
|
|
|
|
writeManifest(bundledBrace, 'brace-expansion', '2.1.2');
|
|
const vulnerableNpm = run();
|
|
expect(vulnerableNpm.status).toBe(1);
|
|
expect(vulnerableNpm.stderr).toContain('must be exactly 2.1.4');
|
|
writeManifest(bundledBrace, 'brace-expansion', '2.1.4');
|
|
|
|
writeManifest('brace-expansion', 'brace-expansion', '5.0.7');
|
|
const vulnerableStagedBrace = run();
|
|
expect(vulnerableStagedBrace.status).toBe(1);
|
|
expect(vulnerableStagedBrace.stderr).toContain('brace-expansion@5.0.7');
|
|
writeManifest('brace-expansion', 'brace-expansion', '5.0.9');
|
|
|
|
writeManifest('fast-uri', 'fast-uri', '3.1.4');
|
|
const vulnerableFastUri = run();
|
|
expect(vulnerableFastUri.status).toBe(1);
|
|
expect(vulnerableFastUri.stderr).toContain('fast-uri@3.1.4');
|
|
writeManifest('fast-uri', 'fast-uri', '3.1.5');
|
|
|
|
writeManifest('ip-address', 'ip-address', '10.2.0');
|
|
const vulnerableIpAddress = run();
|
|
expect(vulnerableIpAddress.status).toBe(1);
|
|
expect(vulnerableIpAddress.stderr).toContain('ip-address@10.2.0');
|
|
writeManifest('ip-address', 'ip-address', '10.4.0');
|
|
|
|
writeManifest('sharp', 'sharp', '0.34.5');
|
|
const vulnerableSharp = run();
|
|
expect(vulnerableSharp.status).toBe(1);
|
|
expect(vulnerableSharp.stderr).toContain('sharp@0.34.5');
|
|
writeManifest('sharp', 'sharp', '0.35.3');
|
|
|
|
// Puppeteer (WhatsApp, ADR-0005) parses its config with js-yaml at runtime.
|
|
writeManifest('vendor/node_modules/js-yaml', 'js-yaml', '4.3.0');
|
|
const stagedYamlParser = run();
|
|
expect(stagedYamlParser.stderr).not.toContain('js-yaml');
|
|
fs.rmSync(path.join(fixture, 'vendor'), { recursive: true, force: true });
|
|
|
|
fs.rmSync(
|
|
path.join(fixture, ...bundledBrace.split('/')),
|
|
{ recursive: true, force: true },
|
|
);
|
|
const missingBundledBrace = run();
|
|
expect(missingBundledBrace.status).toBe(1);
|
|
expect(missingBundledBrace.stderr).toContain('found missing');
|
|
} finally {
|
|
fs.rmSync(fixture, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
it('sidecar resource preflight uses bundled runtime probes instead of checker-host ABI', () => {
|
|
const script = fs.readFileSync(
|
|
path.join(ROOT, 'scripts', 'check-sidecar-resources.mjs'),
|
|
'utf-8',
|
|
);
|
|
expect(script).not.toContain('const currentAbi = process.versions.modules');
|
|
expect(script).not.toContain('does not match current Node ABI');
|
|
expect(script).toContain('execFileSync(nodePath');
|
|
expect(script).toContain('const database = new Database');
|
|
expect(script).toContain('SELECT 1 AS ok');
|
|
// No SQLite extension is loaded since the legacy memory engine left (P1.5).
|
|
expect(script).not.toContain('vec_version');
|
|
expect(script).toContain('const onnx = require(process.argv[3])');
|
|
expect(script).toContain('const { RawImage } = require(process.argv[1])');
|
|
expect(script).toContain('image.toSharp().resize(1, 1).png().toBuffer()');
|
|
expect(script).toContain('Buffer.from([137,80,78,71,13,10,26,10])');
|
|
expect(script).toContain('sharp.versions?.emscripten');
|
|
expect(script).toContain('if (process.argv[3]) require(process.argv[3])');
|
|
expect(script).toContain('process.arch !== process.argv[2]');
|
|
});
|
|
|
|
it.runIf(process.platform === 'win32')(
|
|
'Sharp 0.35.3 works through the Transformers RawImage consumer',
|
|
() => {
|
|
const probe = [
|
|
'const { RawImage } = require("@huggingface/transformers");',
|
|
'const sharp = require("sharp");',
|
|
'if (sharp.versions?.emscripten) throw new Error("Sharp fell back to WASM");',
|
|
'const image = new RawImage(',
|
|
'Uint8Array.from([255,0,0,255,0,255,0,255,0,0,255,255,255,255,255,255]),',
|
|
'2,2,4);',
|
|
'void (async () => {',
|
|
'const buffer = await image.toSharp().resize(1,1).png().toBuffer();',
|
|
'const signature = Buffer.from([137,80,78,71,13,10,26,10]);',
|
|
'if (!buffer.subarray(0,8).equals(signature)) throw new Error("invalid PNG");',
|
|
'process.stdout.write(JSON.stringify({ bytes: buffer.length }));',
|
|
'})().catch((error) => { console.error(error); process.exit(1); });',
|
|
].join('');
|
|
const result = spawnSync(process.execPath, ['-e', probe], {
|
|
cwd: ROOT,
|
|
encoding: 'utf-8',
|
|
timeout: 30_000,
|
|
windowsHide: true,
|
|
});
|
|
|
|
expect(result.status, result.stderr).toBe(0);
|
|
expect(JSON.parse(result.stdout)).toMatchObject({
|
|
bytes: expect.any(Number),
|
|
});
|
|
},
|
|
);
|
|
|
|
it('native bundling is fatal on missing payloads and validates target Mach-O architecture', () => {
|
|
const script = fs.readFileSync(
|
|
path.join(ROOT, 'scripts', 'bundle-native-deps.mjs'),
|
|
'utf-8',
|
|
);
|
|
expect(script).toContain("execFileSync('/usr/bin/lipo'");
|
|
expect(script).toContain('required native dependency');
|
|
expect(script).not.toContain('sqlite-vec');
|
|
expect(script).not.toContain("arch === 'arm64' ? 'aarch64'");
|
|
});
|
|
|
|
it.runIf(process.platform === 'win32')(
|
|
'sidecar resource preflight rejects missing Windows runtimes and sidecar source artifacts',
|
|
async () => {
|
|
const fixtureRoot = fs.mkdtempSync(
|
|
path.join(os.tmpdir(), 'waggle-sidecar-preflight-'),
|
|
);
|
|
const fixtureScripts = path.join(fixtureRoot, 'scripts');
|
|
const fixtureResources = path.join(fixtureRoot, 'app', 'src-tauri', 'resources');
|
|
const fixtureChecker = path.join(fixtureScripts, 'check-sidecar-resources.mjs');
|
|
const requiredNativeFiles = [
|
|
'better_sqlite3.node',
|
|
'onnxruntime/onnxruntime_binding.node',
|
|
];
|
|
const stagedRuntimeFiles = [
|
|
'waggle-test-runtime/dist/index.js',
|
|
];
|
|
const writeFixtureFile = (base: string, relative: string, content = '') => {
|
|
const target = path.join(base, ...relative.split('/'));
|
|
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
fs.writeFileSync(target, content, 'utf-8');
|
|
return target;
|
|
};
|
|
const runFixtureGit = (args: string[]) => {
|
|
const result = spawnSync('git', args, {
|
|
cwd: fixtureRoot,
|
|
encoding: 'utf-8',
|
|
timeout: 30_000,
|
|
windowsHide: true,
|
|
});
|
|
expect(result.status, result.stderr || result.stdout).toBe(0);
|
|
return result.stdout.trim();
|
|
};
|
|
|
|
try {
|
|
fs.mkdirSync(fixtureScripts, { recursive: true });
|
|
fs.mkdirSync(fixtureResources, { recursive: true });
|
|
fs.copyFileSync(
|
|
path.join(ROOT, 'scripts', 'check-sidecar-resources.mjs'),
|
|
fixtureChecker,
|
|
);
|
|
const fixtureNode = path.join(fixtureResources, 'node.exe');
|
|
// A hardlink shares the running Vitest executable's Windows image lock,
|
|
// so fixture cleanup cannot delete it until the parent test process exits.
|
|
fs.copyFileSync(process.execPath, fixtureNode);
|
|
let fixtureSourceRevision = 'a'.repeat(40);
|
|
const fixtureSourceContents = new Map<string, string>([
|
|
['package-lock.json', '{"lockfileVersion":3}\n'],
|
|
['package.json', '{"name":"waggle-sidecar-fixture"}\n'],
|
|
['packages/server/package.json', '{"name":"@waggle/server"}\n'],
|
|
['packages/server/src/local/service.ts', 'export const fixture = true;\n'],
|
|
['packages/server/tsconfig.json', '{"extends":"../../tsconfig.base.json"}\n'],
|
|
['scripts/build-sidecar.mjs', 'export {};\n'],
|
|
['tsconfig.base.json', '{"compilerOptions":{"target":"ES2022"}}\n'],
|
|
]);
|
|
for (const [relative, content] of fixtureSourceContents) {
|
|
writeFixtureFile(fixtureRoot, relative, content);
|
|
}
|
|
const fixtureSourceInputs = [...fixtureSourceContents.entries()]
|
|
.map(([relative, content]) => ({
|
|
path: relative,
|
|
sha256: createHash('sha256').update(content).digest('hex'),
|
|
}))
|
|
.sort((left, right) => left.path < right.path ? -1 : left.path > right.path ? 1 : 0);
|
|
const fixtureServicePayload = Buffer.from('console.log("sidecar");\n', 'utf8');
|
|
const fixtureServiceProvenance = {
|
|
schemaVersion: 1,
|
|
sourceRevision: fixtureSourceRevision,
|
|
entryPoint: 'packages/server/src/local/service.ts',
|
|
sourceInputs: fixtureSourceInputs,
|
|
bundlePayload: {
|
|
sizeBytes: fixtureServicePayload.byteLength,
|
|
sha256: createHash('sha256').update(fixtureServicePayload).digest('hex'),
|
|
},
|
|
};
|
|
let certifiedFixtureService = Buffer.concat([
|
|
Buffer.from(
|
|
`// Waggle-Sidecar-Provenance: ${Buffer.from(JSON.stringify(fixtureServiceProvenance)).toString('base64')}\n`,
|
|
'utf8',
|
|
),
|
|
fixtureServicePayload,
|
|
]);
|
|
const fixtureServicePath = path.join(fixtureResources, 'service.js');
|
|
fs.writeFileSync(fixtureServicePath, certifiedFixtureService);
|
|
const fixtureMarketplaceSource = path.join(
|
|
fixtureRoot,
|
|
'packages',
|
|
'marketplace',
|
|
'marketplace.db',
|
|
);
|
|
fs.mkdirSync(path.dirname(fixtureMarketplaceSource), { recursive: true });
|
|
const fixtureMarketplace = new Database(fixtureMarketplaceSource);
|
|
fixtureMarketplace.pragma('journal_mode = WAL');
|
|
fixtureMarketplace.exec(`
|
|
CREATE TABLE sources (id INTEGER PRIMARY KEY, name TEXT NOT NULL);
|
|
CREATE TABLE packages (id INTEGER PRIMARY KEY, source_id INTEGER, name TEXT NOT NULL);
|
|
INSERT INTO sources (id, name) VALUES (1, 'mcp_registry');
|
|
INSERT INTO packages (id, source_id, name) VALUES (1, 1, 'memory');
|
|
`);
|
|
fixtureMarketplace.pragma('wal_checkpoint(TRUNCATE)');
|
|
fixtureMarketplace.close();
|
|
const fixtureMarketplaceResource = path.join(fixtureResources, 'marketplace.db');
|
|
fs.copyFileSync(fixtureMarketplaceSource, fixtureMarketplaceResource);
|
|
runFixtureGit(['init']);
|
|
runFixtureGit(['config', 'user.email', 'sidecar-preflight@waggle.invalid']);
|
|
runFixtureGit(['config', 'user.name', 'Waggle Fixture']);
|
|
runFixtureGit([
|
|
'add',
|
|
'--',
|
|
'scripts/check-sidecar-resources.mjs',
|
|
...fixtureSourceContents.keys(),
|
|
'packages/marketplace/marketplace.db',
|
|
]);
|
|
runFixtureGit(['commit', '-m', 'fixture']);
|
|
fixtureSourceRevision = runFixtureGit(['rev-parse', 'HEAD']).toLowerCase();
|
|
fixtureServiceProvenance.sourceRevision = fixtureSourceRevision;
|
|
certifiedFixtureService = Buffer.concat([
|
|
Buffer.from(
|
|
`// Waggle-Sidecar-Provenance: ${Buffer.from(JSON.stringify(fixtureServiceProvenance)).toString('base64')}\n`,
|
|
'utf8',
|
|
),
|
|
fixtureServicePayload,
|
|
]);
|
|
fs.writeFileSync(fixtureServicePath, certifiedFixtureService);
|
|
const fixtureNpmVersion = '0.0.0-fixture';
|
|
const fixtureNpmRuntimeRoot = 'node_modules/waggle-node-runtime';
|
|
const fixtureNpmCli = `process.stdout.write(${JSON.stringify(fixtureNpmVersion)} + '\\n');\n`;
|
|
const fixtureNpmWrapper = (cli: 'npm' | 'npx') => [
|
|
'@ECHO OFF',
|
|
'SETLOCAL',
|
|
'SET "NODE_EXE=%~dp0\\..\\..\\..\\node.exe"',
|
|
`SET "NPM_CLI_JS=%~dp0\\..\\node_modules\\npm\\bin\\${cli}-cli.js"`,
|
|
'"%NODE_EXE%" "%NPM_CLI_JS%" %*',
|
|
'EXIT /B %ERRORLEVEL%',
|
|
'',
|
|
].join('\r\n');
|
|
writeFixtureFile(
|
|
fixtureResources,
|
|
`${fixtureNpmRuntimeRoot}/package.json`,
|
|
JSON.stringify({
|
|
name: 'waggle-node-runtime',
|
|
private: true,
|
|
version: process.versions.node,
|
|
}),
|
|
);
|
|
writeFixtureFile(fixtureResources, `${fixtureNpmRuntimeRoot}/NODE-LICENSE`, 'Node license');
|
|
writeFixtureFile(
|
|
fixtureResources,
|
|
`${fixtureNpmRuntimeRoot}/node_modules/npm/package.json`,
|
|
JSON.stringify({ name: 'npm', version: fixtureNpmVersion }),
|
|
);
|
|
writeFixtureFile(
|
|
fixtureResources,
|
|
`${fixtureNpmRuntimeRoot}/node_modules/npm/node_modules/brace-expansion/package.json`,
|
|
JSON.stringify({ name: 'brace-expansion', version: '2.1.4' }),
|
|
);
|
|
writeFixtureFile(
|
|
fixtureResources,
|
|
`${fixtureNpmRuntimeRoot}/node_modules/npm/LICENSE`,
|
|
'npm license',
|
|
);
|
|
writeFixtureFile(
|
|
fixtureResources,
|
|
`${fixtureNpmRuntimeRoot}/node_modules/npm/bin/npm-cli.js`,
|
|
fixtureNpmCli,
|
|
);
|
|
writeFixtureFile(
|
|
fixtureResources,
|
|
`${fixtureNpmRuntimeRoot}/node_modules/npm/bin/npx-cli.js`,
|
|
fixtureNpmCli,
|
|
);
|
|
writeFixtureFile(
|
|
fixtureResources,
|
|
`${fixtureNpmRuntimeRoot}/bin/npm.cmd`,
|
|
fixtureNpmWrapper('npm'),
|
|
);
|
|
writeFixtureFile(
|
|
fixtureResources,
|
|
`${fixtureNpmRuntimeRoot}/bin/npx.cmd`,
|
|
fixtureNpmWrapper('npx'),
|
|
);
|
|
|
|
const installedBetterSqlite = path.join(ROOT, 'node_modules', 'better-sqlite3');
|
|
const fixtureBetterSqlite = path.join(fixtureResources, 'node_modules', 'better-sqlite3');
|
|
fs.mkdirSync(path.dirname(fixtureBetterSqlite), { recursive: true });
|
|
fs.cpSync(installedBetterSqlite, fixtureBetterSqlite, { recursive: true });
|
|
for (const packageName of ['bindings', 'file-uri-to-path']) {
|
|
fs.cpSync(
|
|
path.join(ROOT, 'node_modules', packageName),
|
|
path.join(fixtureResources, 'node_modules', packageName),
|
|
{ recursive: true },
|
|
);
|
|
}
|
|
const installedBinding = path.join(installedBetterSqlite, 'build', 'Release', 'better_sqlite3.node');
|
|
const installedOnnx = path.join(ROOT, 'node_modules', 'onnxruntime-node');
|
|
const fixtureOnnx = path.join(fixtureResources, 'node_modules', 'onnxruntime-node');
|
|
fs.mkdirSync(fixtureOnnx, { recursive: true });
|
|
fs.copyFileSync(path.join(installedOnnx, 'package.json'), path.join(fixtureOnnx, 'package.json'));
|
|
fs.cpSync(path.join(installedOnnx, 'dist'), path.join(fixtureOnnx, 'dist'), { recursive: true });
|
|
const installedOnnxBin = path.join(installedOnnx, 'bin', 'napi-v3', 'win32', 'x64');
|
|
const fixtureOnnxBin = path.join(fixtureOnnx, 'bin', 'napi-v3', 'win32', 'x64');
|
|
fs.cpSync(installedOnnxBin, fixtureOnnxBin, { recursive: true });
|
|
fs.cpSync(
|
|
path.join(ROOT, 'node_modules', 'onnxruntime-common'),
|
|
path.join(fixtureResources, 'node_modules', 'onnxruntime-common'),
|
|
{ recursive: true },
|
|
);
|
|
const installedOnnxBinding = path.join(installedOnnxBin, 'onnxruntime_binding.node');
|
|
const fixtureTransformers = path.join(
|
|
fixtureResources,
|
|
'node_modules',
|
|
'@huggingface',
|
|
'transformers',
|
|
);
|
|
writeFixtureFile(
|
|
path.join(fixtureResources, 'node_modules'),
|
|
'sharp/package.json',
|
|
JSON.stringify({ name: 'sharp', version: '0.35.3', main: 'index.cjs' }),
|
|
);
|
|
writeFixtureFile(
|
|
path.join(fixtureResources, 'node_modules'),
|
|
'sharp/index.cjs',
|
|
'module.exports = { versions: { sharp: "0.35.3", vips: "8.18.3" } };',
|
|
);
|
|
writeFixtureFile(
|
|
path.join(fixtureResources, 'node_modules'),
|
|
'@img/sharp-win32-x64/package.json',
|
|
JSON.stringify({ name: '@img/sharp-win32-x64', version: '0.35.3' }),
|
|
);
|
|
fs.cpSync(
|
|
path.join(ROOT, 'node_modules', '@img', 'sharp-win32-x64', 'lib'),
|
|
path.join(
|
|
fixtureResources,
|
|
'node_modules',
|
|
'@img',
|
|
'sharp-win32-x64',
|
|
'lib',
|
|
),
|
|
{ recursive: true },
|
|
);
|
|
const stagedSharpBinding = path.join(
|
|
fixtureResources,
|
|
'node_modules',
|
|
'@img',
|
|
'sharp-win32-x64',
|
|
'lib',
|
|
'sharp-win32-x64-0.35.3.node',
|
|
);
|
|
writeFixtureFile(
|
|
path.join(fixtureResources, 'node_modules'),
|
|
'@huggingface/transformers/package.json',
|
|
JSON.stringify({ name: '@huggingface/transformers', version: '3.8.1' }),
|
|
);
|
|
writeFixtureFile(
|
|
path.join(fixtureResources, 'node_modules'),
|
|
'@huggingface/transformers/dist/transformers.node.cjs',
|
|
[
|
|
'class RawImage {',
|
|
'toSharp() {',
|
|
'return {',
|
|
'resize() { return this; },',
|
|
'png() { return this; },',
|
|
'async toBuffer() {',
|
|
'return Buffer.from([137,80,78,71,13,10,26,10,0]);',
|
|
'},',
|
|
'};',
|
|
'}',
|
|
'}',
|
|
'module.exports = { RawImage };',
|
|
].join(''),
|
|
);
|
|
|
|
for (const entry of requiredNativeFiles) {
|
|
const target = writeFixtureFile(path.join(fixtureResources, 'native'), entry);
|
|
if (entry === 'better_sqlite3.node') fs.copyFileSync(installedBinding, target);
|
|
if (entry === 'onnxruntime/onnxruntime_binding.node') fs.copyFileSync(installedOnnxBinding, target);
|
|
}
|
|
for (const entry of stagedRuntimeFiles) {
|
|
writeFixtureFile(
|
|
path.join(fixtureResources, 'node_modules'),
|
|
entry,
|
|
entry.endsWith('package.json') ? '{}' : '',
|
|
);
|
|
}
|
|
const stagedPackageNames = new Set(stagedRuntimeFiles.map((entry) => {
|
|
const parts = entry.split('/');
|
|
return entry.startsWith('@') ? `${parts[0]}/${parts[1]}` : parts[0];
|
|
}));
|
|
for (const name of stagedPackageNames) {
|
|
writeFixtureFile(
|
|
path.join(fixtureResources, 'node_modules'),
|
|
`${name}/package.json`,
|
|
JSON.stringify({ name }),
|
|
);
|
|
}
|
|
writeFixtureFile(
|
|
fixtureRoot,
|
|
'packages/test-runtime/package.json',
|
|
JSON.stringify({ name: 'waggle-test-runtime' }),
|
|
);
|
|
writeFixtureFile(
|
|
path.join(fixtureResources, 'node_modules'),
|
|
'waggle-test-runtime/package.json',
|
|
JSON.stringify({ name: 'waggle-test-runtime', main: 'dist/index.js' }),
|
|
);
|
|
const coreManifestPath = path.join(
|
|
fixtureResources,
|
|
'node_modules',
|
|
'@waggle',
|
|
'core',
|
|
'package.json',
|
|
);
|
|
const coreDistEntry = path.join(
|
|
fixtureResources,
|
|
'node_modules',
|
|
'@waggle',
|
|
'core',
|
|
'dist',
|
|
'index.js',
|
|
);
|
|
const writeCoreManifest = (main: string, exports?: Record<string, unknown>) => {
|
|
fs.writeFileSync(
|
|
coreManifestPath,
|
|
JSON.stringify({
|
|
name: '@waggle/core',
|
|
main,
|
|
...(exports === undefined ? {} : { exports }),
|
|
}),
|
|
'utf-8',
|
|
);
|
|
};
|
|
writeCoreManifest('dist/index.js');
|
|
|
|
const runChecker = async (
|
|
{
|
|
runtimeProbe = 'none',
|
|
expectedSourceRevision = fixtureSourceRevision,
|
|
}: {
|
|
runtimeProbe?: 'none' | 'all' | 'marketplace' | 'native' | 'image';
|
|
expectedSourceRevision?: string;
|
|
} = {},
|
|
) => {
|
|
const hiddenFiles: Array<{ hidden: string; target: string }> = [];
|
|
const hideFixtureFile = (target: string) => {
|
|
const hidden = `${target}.fixture-disabled`;
|
|
fs.renameSync(target, hidden);
|
|
hiddenFiles.push({ hidden, target });
|
|
};
|
|
try {
|
|
// Structural rejection cases should not repeat unrelated native, npm,
|
|
// marketplace, and image probes. Probe-specific cases keep the bundled
|
|
// runtime but hide inputs for every other expensive probe.
|
|
if (runtimeProbe === 'none') {
|
|
hideFixtureFile(fixtureNode);
|
|
} else if (runtimeProbe !== 'all') {
|
|
hideFixtureFile(path.join(
|
|
fixtureResources,
|
|
...`${fixtureNpmRuntimeRoot}/package.json`.split('/'),
|
|
));
|
|
if (runtimeProbe !== 'marketplace') hideFixtureFile(fixtureMarketplaceResource);
|
|
if (runtimeProbe !== 'native') {
|
|
hideFixtureFile(path.join(fixtureOnnx, 'package.json'));
|
|
}
|
|
if (runtimeProbe !== 'image') hideFixtureFile(stagedSharpBinding);
|
|
}
|
|
const result = await new Promise<{
|
|
status: number | null;
|
|
stdout: string;
|
|
stderr: string;
|
|
error?: Error;
|
|
}>((resolve) => {
|
|
execFile(
|
|
process.execPath,
|
|
[fixtureChecker, '--expected-source-revision', expectedSourceRevision],
|
|
{
|
|
encoding: 'utf-8',
|
|
timeout: 60_000,
|
|
windowsHide: true,
|
|
},
|
|
(error, stdout, stderr) => {
|
|
if (!error) {
|
|
resolve({ status: 0, stdout, stderr });
|
|
return;
|
|
}
|
|
if (
|
|
typeof error.code === 'number'
|
|
&& !error.killed
|
|
&& (error.signal === null || error.signal === undefined)
|
|
) {
|
|
resolve({ status: error.code, stdout, stderr });
|
|
return;
|
|
}
|
|
resolve({ status: null, stdout, stderr, error });
|
|
},
|
|
);
|
|
});
|
|
if (result.error) throw result.error;
|
|
return result;
|
|
} finally {
|
|
for (const file of hiddenFiles.reverse()) {
|
|
fs.renameSync(file.hidden, file.target);
|
|
}
|
|
}
|
|
};
|
|
|
|
const fixtureMarketplaceBeforeProbe = fs.readFileSync(fixtureMarketplaceResource);
|
|
const baselineResult = await runChecker({ runtimeProbe: 'all' });
|
|
expect(
|
|
baselineResult.status,
|
|
baselineResult.stderr || baselineResult.stdout,
|
|
).toBe(0);
|
|
expect(fs.readFileSync(fixtureMarketplaceResource)).toEqual(fixtureMarketplaceBeforeProbe);
|
|
|
|
fs.appendFileSync(fixtureMarketplaceSource, 'dirty worktree database');
|
|
fs.copyFileSync(fixtureMarketplaceSource, fixtureMarketplaceResource);
|
|
const dirtyMarketplaceResult = await runChecker();
|
|
expect(dirtyMarketplaceResult.status).toBe(1);
|
|
expect(dirtyMarketplaceResult.stderr).toContain(
|
|
'canonical marketplace database does not match exact source revision',
|
|
);
|
|
fs.writeFileSync(fixtureMarketplaceSource, fixtureMarketplaceBeforeProbe);
|
|
fs.writeFileSync(fixtureMarketplaceResource, fixtureMarketplaceBeforeProbe);
|
|
|
|
fs.appendFileSync(fixtureServicePath, '// stale payload\n');
|
|
const staleServiceResult = await runChecker();
|
|
expect(staleServiceResult.status).toBe(1);
|
|
expect(staleServiceResult.stderr).toContain(
|
|
'resources/service.js payload does not match embedded provenance',
|
|
);
|
|
fs.writeFileSync(fixtureServicePath, certifiedFixtureService);
|
|
|
|
const fixtureEntryPoint = path.join(
|
|
fixtureRoot,
|
|
'packages',
|
|
'server',
|
|
'src',
|
|
'local',
|
|
'service.ts',
|
|
);
|
|
fs.appendFileSync(fixtureEntryPoint, '// stale source\n');
|
|
const staleSourceResult = await runChecker();
|
|
expect(staleSourceResult.status).toBe(1);
|
|
expect(staleSourceResult.stderr).toContain(
|
|
'resources/service.js source input hash does not match current source',
|
|
);
|
|
fs.writeFileSync(
|
|
fixtureEntryPoint,
|
|
fixtureSourceContents.get('packages/server/src/local/service.ts')!,
|
|
'utf8',
|
|
);
|
|
|
|
const fixtureTsconfig = path.join(fixtureRoot, 'packages', 'server', 'tsconfig.json');
|
|
fs.appendFileSync(fixtureTsconfig, '// stale transform config\n');
|
|
const staleConfigResult = await runChecker();
|
|
expect(staleConfigResult.status).toBe(1);
|
|
expect(staleConfigResult.stderr).toContain(
|
|
'resources/service.js source input hash does not match current source',
|
|
);
|
|
fs.writeFileSync(
|
|
fixtureTsconfig,
|
|
fixtureSourceContents.get('packages/server/tsconfig.json')!,
|
|
'utf8',
|
|
);
|
|
|
|
const staleRevisionResult = await runChecker({
|
|
expectedSourceRevision: 'b'.repeat(40),
|
|
});
|
|
expect(staleRevisionResult.status).toBe(1);
|
|
expect(staleRevisionResult.stderr).toContain(
|
|
'resources/service.js source revision does not match expected revision',
|
|
);
|
|
const nestedResourceDb = path.join(
|
|
fixtureResources,
|
|
'node_modules',
|
|
'fixture-package',
|
|
'state',
|
|
'cache.DB',
|
|
);
|
|
fs.mkdirSync(path.dirname(nestedResourceDb), { recursive: true });
|
|
const staleSidecars: Array<{
|
|
path: string;
|
|
label: string;
|
|
diagnostic: string;
|
|
suffix: string;
|
|
}> = [];
|
|
for (const target of [
|
|
{
|
|
path: fixtureMarketplaceResource,
|
|
label: 'resources/marketplace.db',
|
|
diagnostic: 'must not be packaged',
|
|
},
|
|
{
|
|
path: fixtureMarketplaceSource,
|
|
label: 'packages/marketplace/marketplace.db',
|
|
diagnostic: 'must not be present while staging',
|
|
},
|
|
{
|
|
path: nestedResourceDb,
|
|
label: 'resources/node_modules/fixture-package/state/cache.DB',
|
|
diagnostic: 'must not be packaged',
|
|
},
|
|
]) {
|
|
for (const suffix of ['-wal', '-shm', '-journal']) {
|
|
expect(fs.existsSync(`${target.path}${suffix}`)).toBe(false);
|
|
fs.writeFileSync(`${target.path}${suffix}`, 'stale SQLite sidecar');
|
|
staleSidecars.push({ ...target, suffix });
|
|
}
|
|
}
|
|
const staleSidecarResult = await runChecker();
|
|
expect(staleSidecarResult.status).toBe(1);
|
|
for (const target of staleSidecars) {
|
|
expect(staleSidecarResult.stderr).toContain(
|
|
`${target.label}${target.suffix} ${target.diagnostic}`,
|
|
);
|
|
fs.rmSync(`${target.path}${target.suffix}`);
|
|
}
|
|
|
|
const fixtureMarketplaceContent = fs.readFileSync(fixtureMarketplaceResource);
|
|
fs.rmSync(fixtureMarketplaceResource);
|
|
const missingMarketplaceResult = await runChecker();
|
|
expect(missingMarketplaceResult.status).toBe(1);
|
|
expect(missingMarketplaceResult.stderr).toContain('resources/marketplace.db');
|
|
fs.writeFileSync(fixtureMarketplaceResource, fixtureMarketplaceContent);
|
|
|
|
fs.appendFileSync(fixtureMarketplaceResource, 'tampered');
|
|
const mismatchedMarketplaceResult = await runChecker();
|
|
expect(mismatchedMarketplaceResult.status).toBe(1);
|
|
expect(mismatchedMarketplaceResult.stderr).toContain(
|
|
'resources/marketplace.db does not match the canonical marketplace database',
|
|
);
|
|
fs.writeFileSync(fixtureMarketplaceResource, fixtureMarketplaceContent);
|
|
|
|
const fixtureMarketplaceSourceContent = fs.readFileSync(fixtureMarketplaceSource);
|
|
fs.writeFileSync(fixtureMarketplaceSource, 'not a SQLite database');
|
|
fs.writeFileSync(fixtureMarketplaceResource, 'not a SQLite database');
|
|
const invalidMarketplaceResult = await runChecker({ runtimeProbe: 'marketplace' });
|
|
expect(invalidMarketplaceResult.status).toBe(1);
|
|
expect(invalidMarketplaceResult.stderr).toContain(
|
|
'resources/marketplace.db failed its SQLite integrity/schema probe',
|
|
);
|
|
fs.writeFileSync(fixtureMarketplaceSource, fixtureMarketplaceSourceContent);
|
|
fs.writeFileSync(fixtureMarketplaceResource, fixtureMarketplaceContent);
|
|
|
|
const fixtureNpmRuntimeManifest = path.join(
|
|
fixtureResources,
|
|
...`${fixtureNpmRuntimeRoot}/package.json`.split('/'),
|
|
);
|
|
const fixtureNpmRuntimeManifestContent = fs.readFileSync(fixtureNpmRuntimeManifest);
|
|
fs.rmSync(fixtureNpmRuntimeManifest);
|
|
const missingNpmRuntimeResult = await runChecker();
|
|
expect(missingNpmRuntimeResult.status).toBe(1);
|
|
expect(missingNpmRuntimeResult.stderr).toContain(
|
|
'resources/node_modules/waggle-node-runtime/package.json',
|
|
);
|
|
fs.writeFileSync(fixtureNpmRuntimeManifest, fixtureNpmRuntimeManifestContent);
|
|
|
|
const stagedBinding = path.join(
|
|
fixtureBetterSqlite,
|
|
'build',
|
|
'Release',
|
|
'better_sqlite3.node',
|
|
);
|
|
const stagedOnnxBinding = path.join(fixtureOnnxBin, 'onnxruntime_binding.node');
|
|
for (const target of [stagedBinding, stagedOnnxBinding]) {
|
|
const original = fs.readFileSync(target);
|
|
fs.writeFileSync(target, 'not a native payload');
|
|
const invalidRuntimeResult = await runChecker({ runtimeProbe: 'native' });
|
|
expect(invalidRuntimeResult.status).toBe(1);
|
|
expect(invalidRuntimeResult.stderr).toContain('resources native runtime probe failed');
|
|
fs.writeFileSync(target, original);
|
|
}
|
|
const stagedSharpBindingContent = fs.readFileSync(stagedSharpBinding);
|
|
fs.writeFileSync(stagedSharpBinding, 'not a native payload');
|
|
const invalidImageRuntimeResult = await runChecker({ runtimeProbe: 'image' });
|
|
expect(invalidImageRuntimeResult.status).toBe(1);
|
|
expect(invalidImageRuntimeResult.stderr).toContain('resources image runtime probe failed');
|
|
fs.writeFileSync(stagedSharpBinding, stagedSharpBindingContent);
|
|
|
|
const imageDependencyTargets = [
|
|
{
|
|
manifest: path.join(fixtureResources, 'node_modules', 'sharp', 'package.json'),
|
|
diagnostic: 'resources/node_modules/sharp',
|
|
},
|
|
{
|
|
manifest: path.join(fixtureTransformers, 'package.json'),
|
|
diagnostic: 'resources/node_modules/@huggingface/transformers',
|
|
},
|
|
].map((target) => ({
|
|
...target,
|
|
content: fs.readFileSync(target.manifest),
|
|
}));
|
|
for (const target of imageDependencyTargets) {
|
|
fs.rmSync(target.manifest);
|
|
}
|
|
const missingImageDependencyResult = await runChecker();
|
|
expect(missingImageDependencyResult.status).toBe(1);
|
|
for (const target of imageDependencyTargets) {
|
|
expect(missingImageDependencyResult.stderr).toContain(target.diagnostic);
|
|
fs.writeFileSync(target.manifest, target.content);
|
|
}
|
|
|
|
const missingNativeTargets = requiredNativeFiles.map((entry) => {
|
|
const target = path.join(
|
|
fixtureResources,
|
|
'native',
|
|
...entry.split('/'),
|
|
);
|
|
return { entry, target, original: fs.readFileSync(target) };
|
|
});
|
|
for (const target of missingNativeTargets) {
|
|
fs.rmSync(target.target);
|
|
}
|
|
const missingNativeResult = await runChecker();
|
|
expect(missingNativeResult.status).toBe(1);
|
|
for (const target of missingNativeTargets) {
|
|
expect(missingNativeResult.stderr).toContain(`resources/native/${target.entry}`);
|
|
fs.writeFileSync(target.target, target.original);
|
|
}
|
|
|
|
const serviceMapPath = writeFixtureFile(
|
|
fixtureResources,
|
|
'service.js.map',
|
|
JSON.stringify({ sourcesContent: ['private TypeScript source'] }),
|
|
);
|
|
writeFixtureFile(
|
|
path.join(fixtureResources, 'node_modules'),
|
|
'@waggle/core/src/private.ts',
|
|
'export const privateSource = true;\n',
|
|
);
|
|
const coreSourceDir = path.join(
|
|
fixtureResources,
|
|
'node_modules',
|
|
'@waggle',
|
|
'core',
|
|
'src',
|
|
);
|
|
writeFixtureFile(
|
|
path.join(fixtureResources, 'node_modules'),
|
|
'waggle-test-runtime/src/private.ts',
|
|
'export const privateSource = true;\n',
|
|
);
|
|
const unscopedSourceDir = path.join(
|
|
fixtureResources,
|
|
'node_modules',
|
|
'waggle-test-runtime',
|
|
'src',
|
|
);
|
|
writeFixtureFile(
|
|
path.join(fixtureResources, 'node_modules'),
|
|
'vendor/node_modules/@waggle/shared/package.json',
|
|
JSON.stringify({ name: '@waggle/shared' }),
|
|
);
|
|
writeFixtureFile(
|
|
path.join(fixtureResources, 'node_modules'),
|
|
'vendor/node_modules/@waggle/shared/src/private.ts',
|
|
'export const privateSource = true;\n',
|
|
);
|
|
const nestedVendorDir = path.join(
|
|
fixtureResources,
|
|
'node_modules',
|
|
'vendor',
|
|
);
|
|
const firstPartyReadme = writeFixtureFile(
|
|
path.join(fixtureResources, 'node_modules'),
|
|
'@waggle/core/README.md',
|
|
'internal package documentation\n',
|
|
);
|
|
const disallowedPayloadResult = await runChecker();
|
|
expect(disallowedPayloadResult.status).toBe(1);
|
|
for (const diagnostic of [
|
|
'resources/service.js.map must not be packaged',
|
|
'resources/node_modules/@waggle/core/src/private.ts must not be packaged',
|
|
'resources/node_modules/waggle-test-runtime/src/private.ts must not be packaged',
|
|
'resources/node_modules/vendor/node_modules/@waggle/shared/src/private.ts must not be packaged',
|
|
'resources/node_modules/@waggle/core/README.md is not a runtime package entry',
|
|
]) {
|
|
expect(disallowedPayloadResult.stderr).toContain(diagnostic);
|
|
}
|
|
fs.rmSync(serviceMapPath);
|
|
fs.rmSync(coreSourceDir, { recursive: true });
|
|
fs.rmSync(unscopedSourceDir, { recursive: true });
|
|
fs.rmSync(nestedVendorDir, { recursive: true });
|
|
fs.rmSync(firstPartyReadme);
|
|
|
|
writeFixtureFile(
|
|
path.join(fixtureResources, 'node_modules'),
|
|
'@waggle/missing-manifest/dist/index.js',
|
|
'export {};\n',
|
|
);
|
|
const missingManifestDir = path.join(
|
|
fixtureResources,
|
|
'node_modules',
|
|
'@waggle',
|
|
'missing-manifest',
|
|
);
|
|
writeFixtureFile(
|
|
path.join(fixtureResources, 'node_modules'),
|
|
'@waggle/malformed-manifest/package.json',
|
|
'{',
|
|
);
|
|
const malformedManifestDir = path.join(
|
|
fixtureResources,
|
|
'node_modules',
|
|
'@waggle',
|
|
'malformed-manifest',
|
|
);
|
|
const invalidManifestResult = await runChecker();
|
|
expect(invalidManifestResult.status).toBe(1);
|
|
expect(invalidManifestResult.stderr).toContain(
|
|
'resources/node_modules/@waggle/missing-manifest/package.json is missing or invalid',
|
|
);
|
|
expect(invalidManifestResult.stderr).toContain(
|
|
'resources/node_modules/@waggle/malformed-manifest/package.json is missing or invalid',
|
|
);
|
|
fs.rmSync(missingManifestDir, { recursive: true });
|
|
fs.rmSync(malformedManifestDir, { recursive: true });
|
|
|
|
writeCoreManifest('dist/../package.json');
|
|
const traversalTargetResult = await runChecker();
|
|
expect(traversalTargetResult.status).toBe(1);
|
|
expect(traversalTargetResult.stderr).toContain(
|
|
'has an invalid or missing runtime target: dist/../package.json',
|
|
);
|
|
|
|
const runtimeDirectory = path.join(
|
|
fixtureResources,
|
|
'node_modules',
|
|
'@waggle',
|
|
'core',
|
|
'dist',
|
|
'runtime-directory',
|
|
);
|
|
fs.mkdirSync(runtimeDirectory, { recursive: true });
|
|
writeCoreManifest('dist/runtime-directory');
|
|
const directoryTargetResult = await runChecker();
|
|
expect(directoryTargetResult.status).toBe(1);
|
|
expect(directoryTargetResult.stderr).toContain(
|
|
'has an invalid or missing runtime target: dist/runtime-directory',
|
|
);
|
|
fs.rmSync(runtimeDirectory, { recursive: true });
|
|
|
|
const coreDistDir = path.dirname(coreDistEntry);
|
|
const outsideDistDir = path.join(fixtureRoot, 'outside-runtime-dist');
|
|
writeFixtureFile(outsideDistDir, 'index.js', 'export {};\n');
|
|
fs.rmSync(coreDistDir, { recursive: true });
|
|
fs.symlinkSync(outsideDistDir, coreDistDir, 'junction');
|
|
writeCoreManifest('dist/index.js');
|
|
const junctionTargetResult = await runChecker();
|
|
expect(junctionTargetResult.status).toBe(1);
|
|
expect(junctionTargetResult.stderr).toContain(
|
|
'has an invalid or missing runtime target: dist/index.js',
|
|
);
|
|
fs.rmSync(coreDistDir, { recursive: true });
|
|
fs.mkdirSync(coreDistDir, { recursive: true });
|
|
fs.writeFileSync(coreDistEntry, 'export {};\n', 'utf-8');
|
|
|
|
writeCoreManifest('dist/index.js', {
|
|
'.': {
|
|
types: './dist/index.d.ts',
|
|
import: './dist/index.js',
|
|
},
|
|
});
|
|
expect((await runChecker({ runtimeProbe: 'all' })).status).toBe(0);
|
|
|
|
fs.writeFileSync(
|
|
coreDistEntry,
|
|
'export {};\n//# sourceMappingURL=index.js.map\n',
|
|
'utf-8',
|
|
);
|
|
fs.writeFileSync(
|
|
path.join(fixtureResources, 'service.js'),
|
|
'console.log("sidecar");\n//# sourceMappingURL=data:application/json;base64,e30=\n',
|
|
'utf-8',
|
|
);
|
|
const inlineMapResult = await runChecker();
|
|
expect(inlineMapResult.status).toBe(1);
|
|
expect(inlineMapResult.stderr).toContain(
|
|
'resources/node_modules/@waggle/core/dist/index.js contains a sourceMappingURL directive',
|
|
);
|
|
expect(inlineMapResult.stderr).toContain(
|
|
'resources/service.js contains a sourceMappingURL directive',
|
|
);
|
|
} finally {
|
|
fs.rmSync(fixtureRoot, { recursive: true, force: true });
|
|
}
|
|
},
|
|
180_000,
|
|
);
|
|
|
|
it('staged sidecar resources have Windows MSI codepage-safe relative paths', () => {
|
|
// WiX 3 links the en-US MSI with codepage 1252. Dependency test fixtures
|
|
// with paths such as "snowman" Unicode names must be pruned before MSI
|
|
// bundling or light.exe fails after the Rust build has already succeeded.
|
|
const resources = path.join(TAURI_DIR, 'resources');
|
|
const unsafe = listFiles(resources)
|
|
.map((file) => path.relative(resources, file))
|
|
.filter((file) => !isWindows1252PathSafe(file));
|
|
|
|
expect(unsafe).toEqual([]);
|
|
});
|
|
|
|
it('staged sidecar node_modules is self-contained after MSI extraction', () => {
|
|
// Running from app/src-tauri/resources can accidentally resolve missing
|
|
// packages from the repo root node_modules. The installed MSI layout cannot.
|
|
const resources = path.join(TAURI_DIR, 'resources');
|
|
const nodeModules = path.join(resources, 'node_modules');
|
|
const missing: string[] = [];
|
|
|
|
for (const packageDir of listPackageDirs(nodeModules)) {
|
|
const manifest = JSON.parse(
|
|
fs.readFileSync(path.join(packageDir, 'package.json'), 'utf-8'),
|
|
) as { name?: string; dependencies?: Record<string, string> };
|
|
for (const dep of Object.keys(manifest.dependencies ?? {})) {
|
|
if (STAGED_DEPENDENCY_ALLOWLIST.has(dep)) continue;
|
|
if (!resolveWithinStagedResources(packageDir, dep, resources)) {
|
|
missing.push(`${path.relative(nodeModules, packageDir)} -> ${dep}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
expect(missing).toEqual([]);
|
|
});
|
|
|
|
it('stages the patched archive parser required by dynamic sidecar imports', () => {
|
|
const stageScript = fs.readFileSync(
|
|
path.join(ROOT, 'scripts', 'stage-sidecar-deps.mjs'),
|
|
'utf-8',
|
|
);
|
|
expect(stageScript).toContain("const DYNAMIC_RUNTIME_ROOTS = new Set(['adm-zip']);");
|
|
expect(stageScript).toContain('adm-zip runtime root must be version 0.6.0 or newer');
|
|
|
|
const stagedManifest = path.join(
|
|
TAURI_DIR,
|
|
'resources',
|
|
'node_modules',
|
|
'adm-zip',
|
|
'package.json',
|
|
);
|
|
if (!fs.existsSync(path.join(TAURI_DIR, 'resources', 'node_modules'))) return;
|
|
|
|
expect(fs.existsSync(stagedManifest)).toBe(true);
|
|
const { version } = JSON.parse(fs.readFileSync(stagedManifest, 'utf-8')) as {
|
|
version: string;
|
|
};
|
|
const [major, minor] = version.split('.').map(Number);
|
|
expect(major > 0 || minor >= 6).toBe(true);
|
|
});
|
|
|
|
it.runIf(fs.existsSync(path.join(TAURI_DIR, 'resources', 'node_modules')))(
|
|
'stages only runtime payloads for first-party packages',
|
|
() => {
|
|
const resources = path.join(TAURI_DIR, 'resources');
|
|
const nodeModules = path.join(resources, 'node_modules');
|
|
const firstPartyRoot = path.join(resources, 'node_modules', '@waggle');
|
|
const firstPartyPackageDirs = new Set<string>();
|
|
const workspacePackageNames = localWorkspacePackageNames();
|
|
const unexpected: string[] = [];
|
|
|
|
if (fs.existsSync(firstPartyRoot)) {
|
|
for (const packageEntry of fs.readdirSync(firstPartyRoot, { withFileTypes: true })) {
|
|
if (packageEntry.isDirectory()) {
|
|
firstPartyPackageDirs.add(path.join(firstPartyRoot, packageEntry.name));
|
|
}
|
|
}
|
|
}
|
|
for (const name of workspacePackageNames) {
|
|
const directPackageDir = path.join(nodeModules, ...name.split('/'));
|
|
if (fs.existsSync(directPackageDir)) firstPartyPackageDirs.add(directPackageDir);
|
|
}
|
|
for (const packageDir of listPackageDirs(nodeModules)) {
|
|
try {
|
|
const manifest = JSON.parse(
|
|
fs.readFileSync(path.join(packageDir, 'package.json'), 'utf-8'),
|
|
) as { name?: unknown };
|
|
if (
|
|
typeof manifest.name === 'string'
|
|
&& (manifest.name.startsWith('@waggle/') || workspacePackageNames.has(manifest.name))
|
|
) {
|
|
firstPartyPackageDirs.add(packageDir);
|
|
}
|
|
} catch {
|
|
// The executable checker reports malformed first-party manifests.
|
|
}
|
|
}
|
|
|
|
for (const packageDir of firstPartyPackageDirs) {
|
|
for (const entry of fs.readdirSync(packageDir, { withFileTypes: true })) {
|
|
if (!FIRST_PARTY_RUNTIME_ENTRIES.has(entry.name)) {
|
|
unexpected.push(path.relative(resources, path.join(packageDir, entry.name)));
|
|
}
|
|
}
|
|
for (const file of listFiles(packageDir)) {
|
|
if (SOURCE_ARTIFACT_PATTERN.test(file)) {
|
|
unexpected.push(path.relative(resources, file));
|
|
}
|
|
if (
|
|
/\.(?:[cm]?js)$/i.test(file)
|
|
&& /(?:\/\/|\/\*)[#@]\s*sourceMappingURL\s*=/.test(fs.readFileSync(file, 'utf-8'))
|
|
) {
|
|
unexpected.push(`${path.relative(resources, file)} -> sourceMappingURL`);
|
|
}
|
|
}
|
|
}
|
|
|
|
expect(unexpected).toEqual([]);
|
|
},
|
|
);
|
|
});
|
|
|
|
describe('CI/CD Configuration', () => {
|
|
it('bounds the broad root Vitest lane to two workers', () => {
|
|
const workflow = parseYaml(
|
|
fs.readFileSync(path.join(ROOT, '.github', 'workflows', 'ci.yml'), 'utf-8'),
|
|
) as {
|
|
jobs?: Record<string, { steps?: Array<{ name?: string; run?: string }> }>;
|
|
};
|
|
const steps = workflow.jobs?.test?.steps ?? [];
|
|
const matches = steps.filter(
|
|
(step) => step.name === 'Unit tests — packages + cross-cutting (root vitest)',
|
|
);
|
|
expect(matches).toHaveLength(1);
|
|
const run = matches[0]?.run ?? '';
|
|
const workerValues = [
|
|
...run.matchAll(/--maxWorkers(?:=|\s+)([^\s\\]+)/g),
|
|
].map((match) => match[1]);
|
|
expect(workerValues).toEqual(['2']);
|
|
expect(run).not.toContain('--no-file-parallelism');
|
|
expect(run).not.toMatch(/--fileParallelism(?:=|\s+)false\b/);
|
|
});
|
|
|
|
it('clean-checkout CI resolves vendored PPTX and uses the locked dependency graph', () => {
|
|
const rootPackage = JSON.parse(
|
|
fs.readFileSync(path.join(ROOT, 'package.json'), 'utf-8'),
|
|
) as { dependencies?: Record<string, string> };
|
|
const agentPackage = JSON.parse(
|
|
fs.readFileSync(path.join(ROOT, 'packages', 'agent', 'package.json'), 'utf-8'),
|
|
) as {
|
|
dependencies?: Record<string, string>;
|
|
devDependencies?: Record<string, string>;
|
|
bundledDependencies?: string[];
|
|
scripts?: Record<string, string>;
|
|
};
|
|
const packageLock = JSON.parse(
|
|
fs.readFileSync(path.join(ROOT, 'package-lock.json'), 'utf-8'),
|
|
) as {
|
|
packages?: Record<
|
|
string,
|
|
{
|
|
dependencies?: Record<string, string>;
|
|
devDependencies?: Record<string, string>;
|
|
resolved?: string;
|
|
link?: boolean;
|
|
version?: string;
|
|
dev?: boolean;
|
|
}
|
|
>;
|
|
};
|
|
const vendorPackage = JSON.parse(
|
|
fs.readFileSync(path.join(ROOT, 'vendor', 'pptxgenjs', 'package.json'), 'utf-8'),
|
|
) as { name?: string; version?: string };
|
|
const vaultTests = fs.readFileSync(
|
|
path.join(ROOT, 'packages', 'core', 'tests', 'vault.test.ts'),
|
|
'utf-8',
|
|
);
|
|
|
|
expect(rootPackage.dependencies?.pptxgenjs).toBeUndefined();
|
|
expect(packageLock.packages?.['']?.dependencies?.pptxgenjs).toBeUndefined();
|
|
expect(packageLock.packages?.['node_modules/pptxgenjs']).toBeUndefined();
|
|
expect(agentPackage.dependencies?.pptxgenjs).toBeUndefined();
|
|
expect(agentPackage.dependencies?.jszip).toBe('^3.10.1');
|
|
expect(agentPackage.devDependencies?.pptxgenjs).toBe('file:../../vendor/pptxgenjs');
|
|
expect(agentPackage.bundledDependencies).toBeUndefined();
|
|
expect(agentPackage.scripts).toMatchObject({
|
|
build: 'tsc --build --force && node ../../scripts/stage-agent-pptx-runtime.mjs',
|
|
prepack: 'tsc --build --force && node ../../scripts/stage-agent-pptx-runtime.mjs',
|
|
});
|
|
expect(packageLock.packages?.['packages/agent']).toMatchObject({
|
|
dependencies: { jszip: '^3.10.1' },
|
|
devDependencies: { pptxgenjs: 'file:../../vendor/pptxgenjs' },
|
|
});
|
|
expect(packageLock.packages?.['packages/agent']?.dependencies?.pptxgenjs).toBeUndefined();
|
|
expect(packageLock.packages?.['packages/agent']?.devDependencies?.pptxgenjs).toBe(
|
|
'file:../../vendor/pptxgenjs',
|
|
);
|
|
expect(packageLock.packages?.['packages/agent/node_modules/pptxgenjs']).toMatchObject({
|
|
resolved: 'vendor/pptxgenjs',
|
|
link: true,
|
|
});
|
|
expect(packageLock.packages?.['vendor/pptxgenjs']).toMatchObject({
|
|
version: vendorPackage.version,
|
|
dev: true,
|
|
});
|
|
expect(vendorPackage).toMatchObject({ name: 'pptxgenjs', version: '4.0.1-waggle.0' });
|
|
|
|
expect(vaultTests).toMatch(
|
|
/removes a pre-existing explicit Everyone allow ACE[\s\S]*?node_modules\/vite-node\/vite-node\.mjs[\s\S]*?'--config'[\s\S]*?probePath[\s\S]*?\r?\n\s*210_000,\r?\n\s*\);/,
|
|
);
|
|
expect(vaultTests).not.toContain("'--script'");
|
|
});
|
|
|
|
it.runIf(process.platform === 'win32')(
|
|
'PowerShell 7 workflow override rejects Windows PowerShell 5.1',
|
|
() => {
|
|
const previousPath = process.env.WAGGLE_PWSH7_PATH;
|
|
const previousRequirement = process.env.WAGGLE_REQUIRE_PWSH7;
|
|
try {
|
|
process.env.WAGGLE_REQUIRE_PWSH7 = '1';
|
|
process.env.WAGGLE_PWSH7_PATH = path.join(
|
|
process.env.SystemRoot ?? 'C:\\Windows',
|
|
'System32',
|
|
'WindowsPowerShell',
|
|
'v1.0',
|
|
'powershell.exe',
|
|
);
|
|
expect(() => powershellProbeExecutable()).toThrow(
|
|
'PowerShell 7 required Windows release-workflow probes',
|
|
);
|
|
} finally {
|
|
if (previousPath === undefined) delete process.env.WAGGLE_PWSH7_PATH;
|
|
else process.env.WAGGLE_PWSH7_PATH = previousPath;
|
|
if (previousRequirement === undefined) delete process.env.WAGGLE_REQUIRE_PWSH7;
|
|
else process.env.WAGGLE_REQUIRE_PWSH7 = previousRequirement;
|
|
}
|
|
},
|
|
);
|
|
|
|
it('accepts Tauri generated NSIS hook dispatch while binding the exact custom include', () => {
|
|
const hookPath = path.join(TAURI_DIR, 'nsis', 'installer.nsi');
|
|
const generatedFixture = [
|
|
`!include "${hookPath}"`,
|
|
'!ifmacrodef NSIS_HOOK_POSTUNINSTALL',
|
|
' !insertmacro NSIS_HOOK_POSTUNINSTALL',
|
|
'!endif',
|
|
'!ifmacrodef NSIS_HOOK_PREUNINSTALL',
|
|
' !insertmacro NSIS_HOOK_PREUNINSTALL',
|
|
'!endif',
|
|
].join('\n');
|
|
const includes = [...generatedFixture.matchAll(/^\s*!include\s+"([^"]+)"\s*$/gim)]
|
|
.map((match) => path.resolve(match[1]));
|
|
|
|
expect(generatedFixture).toContain('!ifmacrodef NSIS_HOOK_POSTUNINSTALL');
|
|
expect(generatedFixture).toContain('!ifmacrodef NSIS_HOOK_PREUNINSTALL');
|
|
expect(includes.filter((candidate) => candidate.toLowerCase() === hookPath.toLowerCase()))
|
|
.toHaveLength(1);
|
|
});
|
|
});
|
|
|
|
describe('Release workflow (release.yml)', () => {
|
|
type Step = { name?: string; uses?: string; if?: string; run?: string; env?: Record<string, string> };
|
|
type Job = {
|
|
'runs-on'?: string;
|
|
needs?: string;
|
|
if?: string;
|
|
permissions?: Record<string, string>;
|
|
env?: Record<string, string>;
|
|
strategy?: { matrix?: { include?: Array<Record<string, string>> } };
|
|
steps?: Step[];
|
|
};
|
|
const WORKFLOW_PATH = path.join(ROOT, '.github', 'workflows', 'release.yml');
|
|
const text = fs.readFileSync(WORKFLOW_PATH, 'utf-8');
|
|
const workflow = parseYaml(text) as {
|
|
on?: {
|
|
push?: { tags?: string[]; branches?: string[] };
|
|
pull_request?: { paths?: string[] };
|
|
workflow_dispatch?: unknown;
|
|
};
|
|
permissions?: Record<string, string>;
|
|
jobs?: Record<string, Job>;
|
|
};
|
|
const build = workflow.jobs?.build ?? {};
|
|
const steps = build.steps ?? [];
|
|
const stepIndex = (name: string) => {
|
|
const index = steps.findIndex((step) => step.name === name);
|
|
expect(index, name).toBeGreaterThanOrEqual(0);
|
|
return index;
|
|
};
|
|
|
|
it('builds the four release targets on runners of the matching architecture', () => {
|
|
expect(build.strategy?.matrix?.include).toEqual([
|
|
{ runner: 'windows-latest', rust_target: 'x86_64-pc-windows-msvc', release_target: 'windows-x64', arch: 'x64', bundles: 'nsis,msi' },
|
|
{ runner: 'macos-15', rust_target: 'aarch64-apple-darwin', release_target: 'macos-arm64', arch: 'arm64', bundles: 'app,dmg' },
|
|
{ runner: 'macos-15-intel', rust_target: 'x86_64-apple-darwin', release_target: 'macos-x64', arch: 'x64', bundles: 'app,dmg' },
|
|
{ runner: 'ubuntu-22.04', rust_target: 'x86_64-unknown-linux-gnu', release_target: 'linux-x64', arch: 'x64', bundles: 'deb,appimage' },
|
|
]);
|
|
expect(build['runs-on']).toBe('${{ matrix.runner }}');
|
|
expect(build.env?.TARGET_ARCH).toBe('${{ matrix.arch }}');
|
|
expect(steps[stepIndex('Verify runner architecture')].run).toContain('process.env.TARGET_ARCH');
|
|
expect(steps[stepIndex('Install Linux system packages')].run).toContain('libwebkit2gtk-4.1-dev');
|
|
});
|
|
|
|
it('runs on version tags, desktop pull requests and manual dispatch, replacing the PR build', () => {
|
|
expect(workflow.on?.push?.tags).toEqual(['v*']);
|
|
expect(workflow.on?.push?.branches).toBeUndefined();
|
|
expect(workflow.on?.pull_request?.paths).toEqual(expect.arrayContaining([
|
|
'app/**', 'apps/web/**', 'packages/**', 'scripts/**', 'package.json', 'package-lock.json',
|
|
]));
|
|
expect(workflow.on).toHaveProperty('workflow_dispatch');
|
|
expect(fs.readdirSync(path.join(ROOT, '.github', 'workflows')).sort()).toEqual(['ci.yml', 'release.yml']);
|
|
});
|
|
|
|
it('stages, checks and archives the sidecar, and smoke-tests it on every target', () => {
|
|
const order = [
|
|
'Install dependencies',
|
|
'Build packages',
|
|
'Build installer',
|
|
'Bundle Node.js runtime',
|
|
'Build sidecar',
|
|
'Bundle native dependencies',
|
|
'Stage sidecar dependencies',
|
|
'Check sidecar resources',
|
|
'Build web UI',
|
|
'Build server archive',
|
|
'Installer smoke test',
|
|
'Build desktop app',
|
|
'Desktop smoke test (Windows)',
|
|
'Collect installers',
|
|
'Upload build outputs',
|
|
].map(stepIndex);
|
|
expect(order).toEqual([...order].sort((left, right) => left - right));
|
|
for (const name of ['Check sidecar resources', 'Build server archive', 'Installer smoke test', 'Upload build outputs']) {
|
|
expect(steps[stepIndex(name)].if, name).toBeUndefined();
|
|
}
|
|
expect(steps[stepIndex('Build server archive')].run).toBe('node scripts/build-server-archive.mjs');
|
|
expect(steps[stepIndex('Installer smoke test')].run).toBe('node scripts/release-smoke.mjs installer');
|
|
|
|
// Every system builds its installers and runs the packaged app once.
|
|
const builds = steps.filter((step) => step.name?.startsWith('Build desktop app'));
|
|
expect(builds.map((step) => step.if).sort()).toEqual(["runner.os != 'macOS'", "runner.os == 'macOS'"]);
|
|
for (const step of builds) {
|
|
expect(step.run).toContain('node node_modules/@tauri-apps/cli/tauri.js build --target ${{ matrix.rust_target }}');
|
|
expect(step.run).toContain('--bundles "${{ matrix.bundles }}"');
|
|
}
|
|
const smokes = steps.filter((step) => step.name?.startsWith('Desktop smoke test'));
|
|
expect(smokes.map((step) => step.if)).toEqual([
|
|
"runner.os == 'Windows'",
|
|
"runner.os == 'macOS'",
|
|
"runner.os == 'Linux'",
|
|
]);
|
|
for (const step of smokes) expect(step.run).toContain('node scripts/release-smoke.mjs desktop --app');
|
|
expect(smokes[2].run).toContain('xvfb-run');
|
|
|
|
const upload = steps[stepIndex('Upload build outputs')] as Step & { with?: Record<string, string> };
|
|
expect(upload.with?.name).toBe('waggle-${{ matrix.release_target }}');
|
|
expect(upload.with?.path).toBe('artifacts/');
|
|
expect(upload.with?.['if-no-files-found']).toBe('error');
|
|
});
|
|
|
|
it('signs nothing and uses no secret but GITHUB_TOKEN', () => {
|
|
const secrets = [...text.matchAll(/secrets\.([A-Za-z0-9_]+)/g)].map((match) => match[1]);
|
|
expect(new Set(secrets)).toEqual(new Set(['GITHUB_TOKEN']));
|
|
const code = text.split('\n').filter((line) => !line.trim().startsWith('#')).join('\n');
|
|
expect(code).not.toMatch(/azure|id-token|attest|notari[sz]|signtool|TAURI_SIGNING|TAURI_PRIVATE_KEY|APPLE_|certificate|\.pfx|codesign/i);
|
|
// The only signature is macOS's ad-hoc one, which takes no identity.
|
|
expect([...text.matchAll(/"signingIdentity":"([^"]*)"/g)].map((match) => match[1])).toEqual(['-']);
|
|
expect(workflow.permissions).toEqual({ contents: 'read' });
|
|
expect(build.permissions).toBeUndefined();
|
|
});
|
|
|
|
it('publishes only for pushed v* tags, and only as a draft with SHA256SUMS', () => {
|
|
const publish = workflow.jobs?.publish ?? {};
|
|
expect(publish.needs).toBe('build');
|
|
expect(publish.if).toBe("github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')");
|
|
expect(publish.permissions).toEqual({ contents: 'write' });
|
|
const publishSteps = publish.steps ?? [];
|
|
const sums = publishSteps.findIndex((step) => step.name === 'Write SHA256SUMS');
|
|
const create = publishSteps.findIndex((step) => step.name === 'Create draft release');
|
|
expect(sums).toBeGreaterThanOrEqual(0);
|
|
expect(create).toBeGreaterThan(sums);
|
|
expect(publishSteps[sums].run).toContain('sha256sum');
|
|
expect(publishSteps[create].run).toMatch(/^gh release create "\$TAG" release\/\* --draft /);
|
|
expect(publishSteps[create].env?.GH_TOKEN).toBe('${{ secrets.GITHUB_TOKEN }}');
|
|
expect([...text.matchAll(/gh release/g)]).toHaveLength(1);
|
|
});
|
|
|
|
it('pins every action to a full commit SHA', () => {
|
|
const actionRefs = [...text.matchAll(/uses:\s+[^@\s]+@([^\s#]+)/g)].map((match) => match[1]);
|
|
expect(actionRefs.length).toBeGreaterThan(0);
|
|
for (const actionRef of actionRefs) expect(actionRef).toMatch(/^[0-9a-f]{40}$/);
|
|
});
|
|
|
|
it('local build scripts stage the sidecar before tauri build on every system', () => {
|
|
const manifest = JSON.parse(
|
|
fs.readFileSync(path.join(ROOT, 'app', 'package.json'), 'utf-8'),
|
|
) as { scripts: Record<string, string> };
|
|
const targets = {
|
|
'tauri:build:win': 'x86_64-pc-windows-msvc',
|
|
'tauri:build:mac:arm64': 'aarch64-apple-darwin',
|
|
'tauri:build:mac:x64': 'x86_64-apple-darwin',
|
|
'tauri:build:linux': 'x86_64-unknown-linux-gnu',
|
|
};
|
|
for (const [name, triple] of Object.entries(targets)) {
|
|
const command = manifest.scripts[name] ?? '';
|
|
expect(command.indexOf('stage-sidecar-deps.mjs'), name).toBeGreaterThanOrEqual(0);
|
|
expect(command.indexOf('npx tauri build'), name).toBeGreaterThan(command.indexOf('stage-sidecar-deps.mjs'));
|
|
expect(command, name).toContain(`--target ${triple}`);
|
|
}
|
|
expect(Object.keys(manifest.scripts).filter((name) => /sign/.test(name))).toEqual([]);
|
|
const conf = JSON.parse(fs.readFileSync(path.join(TAURI_DIR, 'tauri.conf.json'), 'utf-8'));
|
|
expect(conf.build.beforeBuildCommand).toContain('check-sidecar-resources.mjs');
|
|
});
|
|
});
|
|
|
|
describe('Playwright Visual Regression Setup', () => {
|
|
it('playwright.config.ts exists', () => {
|
|
const conf = path.join(ROOT, 'playwright.config.ts');
|
|
expect(fs.existsSync(conf)).toBe(true);
|
|
const content = fs.readFileSync(conf, 'utf-8');
|
|
expect(content).toContain('maxDiffPixelRatio');
|
|
expect(content).toContain('localhost:3333');
|
|
expect(content).not.toContain('npx tsx packages/server/src/local/start.ts');
|
|
});
|
|
|
|
it('starts the E2E server with the same Node runtime without shadowing external tool PATH', () => {
|
|
const conf = path.join(ROOT, 'playwright.config.ts');
|
|
const tsxCli = path.join(ROOT, 'node_modules', 'tsx', 'dist', 'cli.mjs');
|
|
const probeSource = `
|
|
(async () => {
|
|
process.execPath = process.env.WAGGLE_PROBE_NODE_EXEC;
|
|
const { default: config } = await import(${JSON.stringify(pathToFileURL(conf).href)});
|
|
const webServer = Array.isArray(config.webServer)
|
|
? config.webServer[0]
|
|
: config.webServer;
|
|
const pathKey = Object.keys(webServer.env)
|
|
.find((key) => key.toLowerCase() === 'path');
|
|
console.log(JSON.stringify({
|
|
command: webServer.command,
|
|
reuseExistingServer: webServer.reuseExistingServer,
|
|
timeout: webServer.timeout,
|
|
nodeValue: webServer.env.WAGGLE_E2E_NODE_EXEC,
|
|
pathValue: webServer.env[pathKey],
|
|
secretValue: webServer.env.WAGGLE_PROBE_AMBIENT_API_KEY,
|
|
}));
|
|
})();
|
|
`;
|
|
const adversarialNodePaths = process.platform === 'win32'
|
|
? [
|
|
process.execPath,
|
|
'C:\\Program Files\\Node %PATH% & safe\\node.exe',
|
|
'C:\\Node (QA) !bang!\\node.exe',
|
|
]
|
|
: [
|
|
process.execPath,
|
|
'/opt/Node $HOME `touch nope` & safe/node',
|
|
'/opt/Node (QA) !bang!/node',
|
|
];
|
|
|
|
for (const nodePath of adversarialNodePaths) {
|
|
const result = spawnSync(
|
|
process.execPath,
|
|
[tsxCli, '--eval', probeSource],
|
|
{
|
|
cwd: ROOT,
|
|
encoding: 'utf-8',
|
|
env: {
|
|
...process.env,
|
|
WAGGLE_E2E_SKIP_LITELLM: '1',
|
|
WAGGLE_E2E_REUSE_EXISTING_SERVER: '0',
|
|
WAGGLE_PROBE_NODE_EXEC: nodePath,
|
|
WAGGLE_PROBE_AMBIENT_API_KEY: 'must-not-enter-playwright-config',
|
|
},
|
|
timeout: 30_000,
|
|
windowsHide: true,
|
|
},
|
|
);
|
|
|
|
expect(result.status, result.stderr || result.stdout).toBe(0);
|
|
const output = result.stdout.trim().split(/\r?\n/).at(-1);
|
|
const webServer = JSON.parse(output ?? '{}') as {
|
|
command?: string;
|
|
reuseExistingServer?: boolean;
|
|
timeout?: number;
|
|
nodeValue?: string;
|
|
pathValue?: string;
|
|
secretValue?: string;
|
|
};
|
|
const nodeReference = process.platform === 'win32'
|
|
? '"%WAGGLE_E2E_NODE_EXEC%"'
|
|
: '"$WAGGLE_E2E_NODE_EXEC"';
|
|
expect(webServer.command).toBe(
|
|
`npm run build:all && ${nodeReference} `
|
|
+ 'node_modules/tsx/dist/cli.mjs --conditions=source packages/server/src/local/start.ts --skip-litellm',
|
|
);
|
|
expect(webServer.command).not.toContain(nodePath);
|
|
expect(webServer.reuseExistingServer).toBe(false);
|
|
expect(webServer.timeout).toBe(600_000);
|
|
expect(webServer.nodeValue).toBe(nodePath);
|
|
expect(webServer.pathValue).toBeUndefined();
|
|
expect(webServer.secretValue).toBeUndefined();
|
|
}
|
|
});
|
|
|
|
it('visual test spec exists with 14 test cases (7 views x 2 themes)', () => {
|
|
const spec = path.join(ROOT, 'tests', 'visual', 'views.spec.ts');
|
|
expect(fs.existsSync(spec)).toBe(true);
|
|
const content = fs.readFileSync(spec, 'utf-8');
|
|
expect(content).toContain('Dark Mode');
|
|
expect(content).toContain('Light Mode');
|
|
// 7 views defined
|
|
expect(content).toContain('chat');
|
|
expect(content).toContain('memory');
|
|
expect(content).toContain('events');
|
|
expect(content).toContain('capabilities');
|
|
expect(content).toContain('cockpit');
|
|
expect(content).toContain('mission-control');
|
|
expect(content).toContain('settings');
|
|
});
|
|
});
|