* 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>
78 lines
2.6 KiB
TypeScript
78 lines
2.6 KiB
TypeScript
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
import fs from 'fs';
|
|
import path from 'path';
|
|
import { createBackup, restoreBackup, clearBackup } from '../backup.js';
|
|
import { createTempDir, setupNanoclawDir, cleanup } from './test-helpers.js';
|
|
|
|
describe('backup', () => {
|
|
let tmpDir: string;
|
|
const originalCwd = process.cwd();
|
|
|
|
beforeEach(() => {
|
|
tmpDir = createTempDir();
|
|
setupNanoclawDir(tmpDir);
|
|
process.chdir(tmpDir);
|
|
});
|
|
|
|
afterEach(() => {
|
|
process.chdir(originalCwd);
|
|
cleanup(tmpDir);
|
|
});
|
|
|
|
it('createBackup copies files and restoreBackup puts them back', () => {
|
|
fs.mkdirSync(path.join(tmpDir, 'src'), { recursive: true });
|
|
fs.writeFileSync(path.join(tmpDir, 'src', 'app.ts'), 'original content');
|
|
|
|
createBackup(['src/app.ts']);
|
|
|
|
fs.writeFileSync(path.join(tmpDir, 'src', 'app.ts'), 'modified content');
|
|
expect(fs.readFileSync(path.join(tmpDir, 'src', 'app.ts'), 'utf-8')).toBe('modified content');
|
|
|
|
restoreBackup();
|
|
expect(fs.readFileSync(path.join(tmpDir, 'src', 'app.ts'), 'utf-8')).toBe('original content');
|
|
});
|
|
|
|
it('createBackup skips missing files without error', () => {
|
|
expect(() => createBackup(['does-not-exist.ts'])).not.toThrow();
|
|
});
|
|
|
|
it('clearBackup removes backup directory', () => {
|
|
fs.mkdirSync(path.join(tmpDir, 'src'), { recursive: true });
|
|
fs.writeFileSync(path.join(tmpDir, 'src', 'app.ts'), 'content');
|
|
createBackup(['src/app.ts']);
|
|
|
|
const backupDir = path.join(tmpDir, '.nanoclaw', 'backup');
|
|
expect(fs.existsSync(backupDir)).toBe(true);
|
|
|
|
clearBackup();
|
|
expect(fs.existsSync(backupDir)).toBe(false);
|
|
});
|
|
|
|
it('createBackup writes tombstone for non-existent files', () => {
|
|
createBackup(['src/newfile.ts']);
|
|
|
|
const tombstone = path.join(tmpDir, '.nanoclaw', 'backup', 'src', 'newfile.ts.tombstone');
|
|
expect(fs.existsSync(tombstone)).toBe(true);
|
|
});
|
|
|
|
it('restoreBackup deletes files with tombstone markers', () => {
|
|
// Create backup first — file doesn't exist yet, so tombstone is written
|
|
createBackup(['src/added.ts']);
|
|
|
|
// Now the file gets created (simulating skill apply)
|
|
const filePath = path.join(tmpDir, 'src', 'added.ts');
|
|
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
fs.writeFileSync(filePath, 'new content');
|
|
expect(fs.existsSync(filePath)).toBe(true);
|
|
|
|
// Restore should delete the file (tombstone means it didn't exist before)
|
|
restoreBackup();
|
|
expect(fs.existsSync(filePath)).toBe(false);
|
|
});
|
|
|
|
it('restoreBackup is no-op when backup dir is empty or missing', () => {
|
|
clearBackup();
|
|
expect(() => restoreBackup()).not.toThrow();
|
|
});
|
|
});
|