app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

history-cursor.test.ts (1454B)


      1 import { test, expect } from 'vitest';
      2 import { outerHistoryPlan } from '../../src/lib/messaging/history-cursor.ts';
      3 test('latest window has no inner-time cursor and overlap covers two-day backdate plus five minutes', () => {
      4   const p = outerHistoryPlan(1000000);
      5   expect(p.latest).toEqual({});
      6   expect(p.overlap).toEqual({ since: 826900 });
      7   expect(p.historyComplete).toBe(false);
      8   expect(p.olderRecoveryRequired).toBe(true);
      9 });
     10 test('previous outer check widens reconnect overlap instead of using latest inner time', () =>
     11   expect(outerHistoryPlan(1000000, 900000).overlap).toEqual({ since: 726900 }));
     12 test('backward clock change uses earlier actual clock instead of future persisted check', () =>
     13   expect(outerHistoryPlan(900000, 1000000).overlap).toEqual({ since: 726900 }));
     14 test('early clock clamps overlap at zero without negative Nostr time', () =>
     15   expect(outerHistoryPlan(100).overlap).toEqual({ since: 0 }));
     16 test('noninteger negative nonfinite and forged object clocks or hints reject', () => {
     17   for (const t of [-1, 1.5, Infinity, NaN, {}, '100']) {
     18     expect(() => outerHistoryPlan(t)).toThrow();
     19     expect(() => outerHistoryPlan(1000000, t)).toThrow();
     20   }
     21 });
     22 test('immutable detached plan cannot narrow later overlap', () => {
     23   const p = outerHistoryPlan(1000000);
     24   expect(Object.isFrozen(p)).toBe(true);
     25   expect(Object.isFrozen(p.overlap)).toBe(true);
     26   expect(outerHistoryPlan(1000000).overlap.since).toBe(826900);
     27 });