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

2.0 KB
Raw Blame
import { afterAll, describe, expect, it, mock } from 'bun:test';
import { stripVTControlCharacters } from 'util';
import * as realMuseCodeInstallerModule from '../../src/services/integrations/MuseCodeHooksInstaller.js';

// bun test runs every file in one process, and mock.restore() does not undo a
// module mock: put the real installer back after this file.
const realMuseCodeInstallerSnapshot = { ...realMuseCodeInstallerModule };

let installResult = 0;

// The mocked install writes nothing, so the real ~/.config/muse is never touched.
mock.module('../../src/services/integrations/MuseCodeHooksInstaller.js', () => ({
  ...realMuseCodeInstallerSnapshot,
  installMuseCode: () => installResult,
}));

// Dynamic imports keep the module mock registered before install.ts (and its
// lazy MuseCodeHooksInstaller import) is evaluated.
const { makeIDETask } = await import('../../src/npx-cli/commands/install.js');
const { createInstallSummary } = await import('../../src/npx-cli/install/error-reporter.js');

describe('Muse Code install task', () => {
  afterAll(() => {
    mock.module('../../src/services/integrations/MuseCodeHooksInstaller.js', () => realMuseCodeInstallerSnapshot);
  });

  it('records an installer failure as a failed IDE, not OK', async () => {
    installResult = 1;
    const summary = createInstallSummary();

    const descriptor = makeIDETask('muse-code', summary);
    expect(descriptor).not.toBeNull();
    const line = stripVTControlCharacters(await descriptor!.task(() => {}));

    expect(line).toContain('FAIL');
    expect(line).not.toContain('OK');
    expect(summary.failedIDEs).toEqual(['muse-code']);
  });

  it('reports OK with no failure when the installer succeeds', async () => {
    installResult = 0;
    const summary = createInstallSummary();

    const line = stripVTControlCharacters(await makeIDETask('muse-code', summary)!.task(() => {}));

    expect(line).toContain('OK');
    expect(summary.failedIDEs).toEqual([]);
    expect(summary.warnings).toEqual([]);
  });
});