Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { mkdtempSync, rmSync, writeFileSync, readFileSync, mkdirSync, existsSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
import migration from './065-writers-room-continue-prompt.js';
const STAGE = 'writers-room-continue';
const readJson = (path) => JSON.parse(readFileSync(path, 'utf-8'));
describe('migration 065 — seed Writers Room live-continuation prompt', () => {
let rootDir;
let installedStagesDir;
let installedConfigPath;
beforeEach(() => {
rootDir = mkdtempSync(join(tmpdir(), 'migration-065-'));
const refStagesDir = join(rootDir, 'data.reference', 'prompts', 'stages');
mkdirSync(refStagesDir, { recursive: true });
writeFileSync(join(refStagesDir, `${STAGE}.md`), `# ${STAGE}\n\nbody\n`);
const refConfig = { stages: { [STAGE]: { name: STAGE, model: 'quick', returnsJson: true, variables: [] } } };
writeFileSync(join(rootDir, 'data.reference', 'prompts', 'stage-config.json'), JSON.stringify(refConfig, null, 2) + '\n');
installedStagesDir = join(rootDir, 'data', 'prompts', 'stages');
installedConfigPath = join(rootDir, 'data', 'prompts', 'stage-config.json');
});
afterEach(() => {
rmSync(rootDir, { recursive: true, force: true });
});
it('seeds the prompt file + stage-config entry on a fresh install', async () => {
await migration.up({ rootDir });
expect(existsSync(join(installedStagesDir, `${STAGE}.md`))).toBe(true);
expect(readJson(installedConfigPath).stages[STAGE]).toBeTruthy();
});
it('merges into an existing stage-config without clobbering other stages', async () => {
mkdirSync(installedStagesDir, { recursive: true });
writeFileSync(installedConfigPath, JSON.stringify({ stages: { 'pipeline-prose': { name: 'Prose' }, [STAGE]: { name: 'CUSTOM', model: 'my-model' } } }, null, 2) + '\n');
await migration.up({ rootDir });
const config = readJson(installedConfigPath);
expect(config.stages['pipeline-prose']).toEqual({ name: 'Prose' });
expect(config.stages[STAGE]).toEqual({ name: 'CUSTOM', model: 'my-model' });
});
it('is idempotent and preserves a user-customized installed prompt', async () => {
mkdirSync(installedStagesDir, { recursive: true });
const customPath = join(installedStagesDir, `${STAGE}.md`);
writeFileSync(customPath, '# CUSTOM continuation\n');
await migration.up({ rootDir });
expect(readFileSync(customPath, 'utf-8')).toContain('CUSTOM');
// Second run is a clean no-op.
await migration.up({ rootDir });
expect(readFileSync(customPath, 'utf-8')).toContain('CUSTOM');
expect(readJson(installedConfigPath).stages[STAGE]).toBeTruthy();
});
});