Files
nanoclaw/skills-engine/__tests__/test-helpers.ts
Gabi Simons 11c201088b refactor: CI optimization, logging improvements, and codebase formatting (#456)
* fix(db): remove unique constraint on folder to support multi-channel agents

* ci: implement automated skill drift detection and self-healing PRs

* fix: align registration logic with Gavriel's feedback and fix build/test issues from Daniel Mi

* style: conform to prettier standards for CI validation

* test: fix branch naming inconsistency in CI (master vs main)

* fix(ci): robust module resolution by removing file extensions in scripts

* refactor(ci): simplify skill validation by removing redundant combination tests

* style: conform skills-engine to prettier, unify logging in index.ts and cleanup unused imports

* refactor: extract multi-channel DB changes to separate branch

Move channel column, folder suffix logic, and related migrations
to feat/multi-channel-db-v2 for independent review. This PR now
contains only CI/CD optimizations, Prettier formatting, and
logging improvements.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-25 23:13:36 +02:00

109 lines
3.3 KiB
TypeScript

import { execSync } from 'child_process';
import fs from 'fs';
import os from 'os';
import path from 'path';
import { stringify } from 'yaml';
export function createTempDir(): string {
return fs.mkdtempSync(path.join(os.tmpdir(), 'nanoclaw-test-'));
}
export function setupNanoclawDir(tmpDir: string): void {
fs.mkdirSync(path.join(tmpDir, '.nanoclaw', 'base', 'src'), {
recursive: true,
});
fs.mkdirSync(path.join(tmpDir, '.nanoclaw', 'backup'), { recursive: true });
}
export function writeState(tmpDir: string, state: any): void {
const statePath = path.join(tmpDir, '.nanoclaw', 'state.yaml');
fs.writeFileSync(statePath, stringify(state), 'utf-8');
}
export function createMinimalState(tmpDir: string): void {
writeState(tmpDir, {
skills_system_version: '0.1.0',
core_version: '1.0.0',
applied_skills: [],
});
}
export function createSkillPackage(
tmpDir: string,
opts: {
skill?: string;
version?: string;
core_version?: string;
adds?: string[];
modifies?: string[];
addFiles?: Record<string, string>;
modifyFiles?: Record<string, string>;
conflicts?: string[];
depends?: string[];
test?: string;
structured?: any;
file_ops?: any[];
post_apply?: string[];
min_skills_system_version?: string;
dirName?: string;
},
): string {
const skillDir = path.join(tmpDir, opts.dirName ?? 'skill-pkg');
fs.mkdirSync(skillDir, { recursive: true });
const manifest: Record<string, unknown> = {
skill: opts.skill ?? 'test-skill',
version: opts.version ?? '1.0.0',
description: 'Test skill',
core_version: opts.core_version ?? '1.0.0',
adds: opts.adds ?? [],
modifies: opts.modifies ?? [],
conflicts: opts.conflicts ?? [],
depends: opts.depends ?? [],
test: opts.test,
structured: opts.structured,
file_ops: opts.file_ops,
};
if (opts.post_apply) manifest.post_apply = opts.post_apply;
if (opts.min_skills_system_version)
manifest.min_skills_system_version = opts.min_skills_system_version;
fs.writeFileSync(path.join(skillDir, 'manifest.yaml'), stringify(manifest));
if (opts.addFiles) {
const addDir = path.join(skillDir, 'add');
for (const [relPath, content] of Object.entries(opts.addFiles)) {
const fullPath = path.join(addDir, relPath);
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
fs.writeFileSync(fullPath, content);
}
}
if (opts.modifyFiles) {
const modDir = path.join(skillDir, 'modify');
for (const [relPath, content] of Object.entries(opts.modifyFiles)) {
const fullPath = path.join(modDir, relPath);
fs.mkdirSync(path.dirname(fullPath), { recursive: true });
fs.writeFileSync(fullPath, content);
}
}
return skillDir;
}
export function initGitRepo(dir: string): void {
execSync('git init', { cwd: dir, stdio: 'pipe' });
execSync('git config user.email "test@test.com"', {
cwd: dir,
stdio: 'pipe',
});
execSync('git config user.name "Test"', { cwd: dir, stdio: 'pipe' });
execSync('git config rerere.enabled true', { cwd: dir, stdio: 'pipe' });
fs.writeFileSync(path.join(dir, '.gitignore'), 'node_modules\n');
execSync('git add -A && git commit -m "init"', { cwd: dir, stdio: 'pipe' });
}
export function cleanup(dir: string): void {
fs.rmSync(dir, { recursive: true, force: true });
}