Skip to content

Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More

1.4 KB
Raw Blame
import { expect, it } from 'bun:test';
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';

it('preserves application files when bun test inherits CLAUDE_MEM_DATA_DIR', () => {
  const applicationDir = mkdtempSync(join(tmpdir(), 'cmem-inherited-app-data-'));
  try {
    const backups = join(applicationDir, 'backups');
    mkdirSync(backups);
    const files = [
      join(backups, 'restore-pending.json'),
      join(backups, 'last-restore.json'),
      join(applicationDir, 'cmem-cap-probe.json'),
    ];
    const sentinel = JSON.stringify({ snapshot: 'claude-mem-user.db', requestedAt: 1 });
    for (const file of files) writeFileSync(file, sentinel);

    // This existing case expects an empty test root and cleans up its own restore markers.
    const child = Bun.spawnSync([process.execPath, 'test', '-t', 'does nothing when no restore is staged',
      './tests/backup/pending-restore.test.ts'], {
      cwd: join(import.meta.dir, '../..'),
      env: { ...process.env, CLAUDE_MEM_DATA_DIR: applicationDir },
      stdout: 'pipe', stderr: 'pipe',
    });
    expect(child.exitCode, child.stderr.toString()).toBe(0);
    expect(child.stderr.toString()).toContain('1 pass');
    for (const file of files) expect(readFileSync(file, 'utf8')).toBe(sentinel);
  } finally {
    rmSync(applicationDir, { recursive: true, force: true });
  }
});