Skip to content

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

2.6 KB
Raw Blame
import { describe, it, expect, vi, beforeEach } from 'vitest';

vi.mock('./apiCore.js', () => ({
  request: vi.fn(),
  queryString: (params = {}) => {
    const query = new URLSearchParams();
    for (const [key, value] of Object.entries(params)) {
      if (value !== undefined && value !== null && value !== '') query.set(key, String(value));
    }
    const encoded = query.toString();
    return encoded ? `?${encoded}` : '';
  },
}));

let request;
let getReviewQueue;
let resolveReviewQueueItem;

beforeEach(async () => {
  vi.resetModules();
  ({ request } = await import('./apiCore.js'));
  ({ getReviewQueue, resolveReviewQueueItem } = await import('./apiReview.js'));
  request.mockReset();
});

describe('getReviewQueue', () => {
  it('encodes the Actions view with pagination while preserving request options', async () => {
    request.mockResolvedValue({ items: [] });

    await getReviewQueue({ view: 'today', limit: 25, cursor: 'snapshot/page', silent: true });

    expect(request).toHaveBeenCalledWith('/review/queue?view=today&limit=25&cursor=snapshot%2Fpage', { silent: true });
  });

  it('encodes pagination in the query while preserving request options', async () => {
    request.mockResolvedValue({ items: [] });

    await getReviewQueue({ limit: 25, cursor: 'snapshot/page', silent: true });

    expect(request).toHaveBeenCalledWith('/review/queue?limit=25&cursor=snapshot%2Fpage', { silent: true });
  });

  it('keeps the legacy options-only call query-free', async () => {
    request.mockResolvedValue({ items: [] });

    await getReviewQueue({ silent: true });

    expect(request).toHaveBeenCalledWith('/review/queue', { silent: true });
  });
});

describe('resolveReviewQueueItem', () => {
  it('keeps source operations in the body and transport options separate', async () => {
    request.mockResolvedValue({ resolved: true });

    await resolveReviewQueueItem('memory:memory-1', { operation: 'approve', silent: true });

    expect(request).toHaveBeenCalledWith('/review/queue/resolve', {
      method: 'POST',
      body: JSON.stringify({ id: 'memory:memory-1', operation: 'approve' }),
      silent: true,
    });
  });

  it('keeps feedback rating input in the mutation body', async () => {
    request.mockResolvedValue({ resolved: true });

    await resolveReviewQueueItem('feedback:agent-1', {
      operation: 'rate', rating: 'negative', comment: 'Needs a follow-up', silent: true,
    });

    expect(request).toHaveBeenCalledWith('/review/queue/resolve', {
      method: 'POST',
      body: JSON.stringify({
        id: 'feedback:agent-1', operation: 'rate', rating: 'negative', comment: 'Needs a follow-up',
      }),
      silent: true,
    });
  });
});