* refactor: multi-channel infrastructure with explicit channel/is_group tracking - Add channels[] array and findChannel() routing in index.ts, replacing hardcoded whatsapp.* calls with channel-agnostic callbacks - Add channel TEXT and is_group INTEGER columns to chats table with COALESCE upsert to protect existing values from null overwrites - is_group defaults to 0 (safe: unknown chats excluded from groups) - WhatsApp passes explicit channel='whatsapp' and isGroup to onChatMetadata - getAvailableGroups filters on is_group instead of JID pattern matching - findChannel logs warnings instead of silently dropping unroutable JIDs - Migration backfills channel/is_group from JID patterns for existing DBs Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: skills engine v0.1 — deterministic skill packages with rerere resolution Three-way merge engine for applying skill packages on top of a core codebase. Skills declare which files they add/modify, and the engine uses git merge-file for conflict detection with git rerere for automatic resolution of previously-seen conflicts. Key components: - apply: three-way merge with backup/rollback safety net - replay: clean-slate replay for uninstall and rebase - update: core version updates with deletion detection - rebase: bake applied skills into base (one-way) - manifest: validation with path traversal protection - resolution-cache: pre-computed rerere resolutions - structured: npm deps, env vars, docker-compose merging - CI: per-skill test matrix with conflict detection 151 unit tests covering merge, rerere, backup, replay, uninstall, update, rebase, structured ops, and edge cases. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: add Discord and Telegram skill packages Skill packages for adding Discord and Telegram channels to NanoClaw. Each package includes: - Channel implementation (add/src/channels/) - Three-way merge targets for index.ts, config.ts, routing.test.ts - Intent docs explaining merge invariants - Standalone integration tests - manifest.yaml with dependency/conflict declarations Applied via: npx tsx scripts/apply-skill.ts .claude/skills/add-discord These are inert until applied — no runtime impact. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * remove unused docs (skills-system-status, implementation-guide) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
93 lines
2.7 KiB
TypeScript
93 lines
2.7 KiB
TypeScript
import fs from 'fs';
|
|
import path from 'path';
|
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
|
|
import { applySkill } from '../apply.js';
|
|
import {
|
|
cleanup,
|
|
createMinimalState,
|
|
createSkillPackage,
|
|
createTempDir,
|
|
initGitRepo,
|
|
setupNanoclawDir,
|
|
} from './test-helpers.js';
|
|
|
|
describe('apply', () => {
|
|
let tmpDir: string;
|
|
const originalCwd = process.cwd();
|
|
|
|
beforeEach(() => {
|
|
tmpDir = createTempDir();
|
|
setupNanoclawDir(tmpDir);
|
|
createMinimalState(tmpDir);
|
|
initGitRepo(tmpDir);
|
|
process.chdir(tmpDir);
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.chdir(originalCwd);
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
it('rejects when min_skills_system_version is too high', async () => {
|
|
const skillDir = createSkillPackage(tmpDir, {
|
|
skill: 'future-skill',
|
|
version: '1.0.0',
|
|
core_version: '1.0.0',
|
|
adds: [],
|
|
modifies: [],
|
|
min_skills_system_version: '99.0.0',
|
|
});
|
|
|
|
const result = await applySkill(skillDir);
|
|
expect(result.success).toBe(false);
|
|
expect(result.error).toContain('99.0.0');
|
|
});
|
|
|
|
it('executes post_apply commands on success', async () => {
|
|
const markerFile = path.join(tmpDir, 'post-apply-marker.txt');
|
|
const skillDir = createSkillPackage(tmpDir, {
|
|
skill: 'post-test',
|
|
version: '1.0.0',
|
|
core_version: '1.0.0',
|
|
adds: ['src/newfile.ts'],
|
|
modifies: [],
|
|
addFiles: { 'src/newfile.ts': 'export const x = 1;' },
|
|
post_apply: [`echo "applied" > "${markerFile}"`],
|
|
});
|
|
|
|
const result = await applySkill(skillDir);
|
|
expect(result.success).toBe(true);
|
|
expect(fs.existsSync(markerFile)).toBe(true);
|
|
expect(fs.readFileSync(markerFile, 'utf-8').trim()).toBe('applied');
|
|
});
|
|
|
|
it('rolls back on post_apply failure', async () => {
|
|
fs.mkdirSync(path.join(tmpDir, 'src'), { recursive: true });
|
|
const existingFile = path.join(tmpDir, 'src/existing.ts');
|
|
fs.writeFileSync(existingFile, 'original content');
|
|
|
|
// Set up base for the modified file
|
|
const baseDir = path.join(tmpDir, '.nanoclaw', 'base', 'src');
|
|
fs.mkdirSync(baseDir, { recursive: true });
|
|
fs.writeFileSync(path.join(baseDir, 'existing.ts'), 'original content');
|
|
|
|
const skillDir = createSkillPackage(tmpDir, {
|
|
skill: 'bad-post',
|
|
version: '1.0.0',
|
|
core_version: '1.0.0',
|
|
adds: ['src/added.ts'],
|
|
modifies: [],
|
|
addFiles: { 'src/added.ts': 'new file' },
|
|
post_apply: ['false'], // always fails
|
|
});
|
|
|
|
const result = await applySkill(skillDir);
|
|
expect(result.success).toBe(false);
|
|
expect(result.error).toContain('post_apply');
|
|
|
|
// Added file should be cleaned up
|
|
expect(fs.existsSync(path.join(tmpDir, 'src/added.ts'))).toBe(false);
|
|
});
|
|
});
|