Add unit tests for skill capabilities, skill planner, and UV setup

- Implement tests for random ID generation, ensuring preference for crypto.randomUUID.
- Create tests for runtime context capabilities, validating the injection of enabled skill capabilities.
- Add tests for skill capability parsing, including classification and command example extraction.
- Introduce tests for the skill planner, verifying tool call planning based on user requests and attachment requirements.
- Establish tests for UV setup, ensuring proper handling of Python installation scenarios and environment checks.
This commit is contained in:
DEV_DSW
2026-04-24 17:02:59 +08:00
parent e11a2296cc
commit 4c61e93c3e
42 changed files with 12560 additions and 224 deletions

View File

@@ -15,6 +15,83 @@ const fs = require('fs-extra');
const path = require('path');
const esbuild = require('esbuild');
const ARCH_NAME_MAP = {
0: 'ia32',
1: 'x64',
2: 'armv7l',
3: 'arm64',
4: 'universal',
};
const REQUIRED_RUNTIME_BINARIES = {
win32: ['uv.exe', 'node.exe'],
darwin: ['uv'],
linux: ['uv'],
};
function normalizePackArch(arch) {
if (typeof arch === 'string') {
return arch;
}
return ARCH_NAME_MAP[arch] || String(arch);
}
function normalizePlatformName(electronPlatformName) {
switch (electronPlatformName) {
case 'win':
return 'win32';
case 'mac':
return 'darwin';
default:
return electronPlatformName;
}
}
function resolveBundledRuntimeTarget(context) {
const platform = normalizePlatformName(context.electronPlatformName);
const arch = normalizePackArch(context.arch);
return `${platform}-${arch}`;
}
async function copyBundledRuntimeBinaries(context, overrides = {}) {
const target = resolveBundledRuntimeTarget(context);
const platform = normalizePlatformName(context.electronPlatformName);
const sourceRoot = overrides.sourceRoot || path.join(__dirname, '..', 'resources', 'bin', target);
const resourcesDir = overrides.resourcesDir || resolveResourcesDir(context);
const destRoot = overrides.destRoot || path.join(resourcesDir, 'bin');
const requiredFiles = overrides.requiredFiles || REQUIRED_RUNTIME_BINARIES[platform] || [];
if (!(await fs.pathExists(sourceRoot))) {
throw new Error(
`[after-pack] Missing bundled runtime directory for ${target}: ${sourceRoot}. ` +
`Run the bundled runtime preparation step before packaging.`,
);
}
await fs.ensureDir(destRoot);
const entries = await fs.readdir(sourceRoot, { withFileTypes: true });
for (const entry of entries) {
if (!entry.isFile()) {
continue;
}
await fs.copy(path.join(sourceRoot, entry.name), path.join(destRoot, entry.name), {
overwrite: true,
});
}
const missing = requiredFiles.filter((fileName) => !fs.existsSync(path.join(destRoot, fileName)));
if (missing.length > 0) {
throw new Error(
`[after-pack] Missing required bundled runtime binaries for ${target}: ${missing.join(', ')}.`,
);
}
console.log(`[after-pack] Copied bundled runtime binaries for ${target} -> ${destRoot}`);
}
/**
* Remove development artifacts from a directory (recursive).
* Removes: test directories, TypeScript definitions, source maps, docs, etc.
@@ -131,6 +208,8 @@ module.exports = async function afterPack(context) {
console.log(`Running afterPack hook for ${platform}-${arch}`);
console.log(`App output directory: ${appOutDir}`);
await copyBundledRuntimeBinaries(context, { resourcesDir });
// 1. Handle electron/scripts/ directory
const scriptsSrc = path.join(__dirname, '..', 'electron/scripts');
@@ -219,3 +298,10 @@ module.exports = async function afterPack(context) {
console.log('afterPack hook completed successfully');
};
module.exports.__test__ = {
normalizePackArch,
normalizePlatformName,
resolveBundledRuntimeTarget,
copyBundledRuntimeBinaries,
};