app

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

decryption-queue.test.ts (2292B)


      1 import { beforeAll, describe, expect, it } from 'vitest';
      2 import { planDecryptBatch } from '../../src/lib/messaging/inbox-state.ts';
      3 import { PRIVATE_DECRYPTION_BUDGETS } from '../../src/lib/config/budgets.ts';
      4 const ids = (n: number) =>
      5   Array.from({ length: n }, (_, i) => i.toString(16).padStart(64, '0'));
      6 beforeAll(() => {
      7   expect(planDecryptBatch).toBeTypeOf('function');
      8 });
      9 describe('explicit envelope decryption work plan', () => {
     10   it('holds the21st for another explicit action', () => {
     11     const input = ids(21);
     12     expect(planDecryptBatch(input)).toEqual({
     13       selected: input.slice(0, 20),
     14       remaining: 1
     15     });
     16   });
     17   it('keeps the approved20-envelope maximum for every large queue', () => {
     18     expect(PRIVATE_DECRYPTION_BUDGETS.envelopesPerAction).toBe(20);
     19     expect(planDecryptBatch(ids(2000)).selected).toHaveLength(20);
     20     expect(planDecryptBatch(ids(2000)).remaining).toBe(1980);
     21   });
     22   it('preserves opaque stored-ID order instead of inner message or author sorting', () => {
     23     const input = ids(21).reverse();
     24     expect(planDecryptBatch(input).selected).toEqual(input.slice(0, 20));
     25   });
     26   it('does not schedule the same persisted outer ID twice', () => {
     27     const input = ids(21);
     28     expect(planDecryptBatch([input[0], ...input])).toEqual(
     29       planDecryptBatch(input)
     30     );
     31   });
     32   it('clones a frozen caller queue without mutation or aliases', () => {
     33     const input = Object.freeze(ids(21));
     34     const next = planDecryptBatch(input);
     35     next.selected[0] = 'a'.repeat(64);
     36     expect(input[0]).toBe('0'.repeat(64));
     37     expect(planDecryptBatch(input).remaining).toBe(1);
     38   });
     39   it('does not invent work for an empty queue', () => {
     40     expect(planDecryptBatch([])).toEqual({ selected: [], remaining: 0 });
     41   });
     42   it('refuses malformed and uppercase ciphertext identities before selecting work', () => {
     43     for (const value of ['wrong', 'A'.repeat(64), '0'.repeat(63)])
     44       expect(() => planDecryptBatch([value])).toThrow();
     45   });
     46   it('refuses an over-capacity queue without eviction or limit reset', () => {
     47     expect(() => planDecryptBatch(ids(2001))).toThrow();
     48   });
     49   it('does not truncate unsupported IDs after an otherwise complete batch', () => {
     50     expect(() => planDecryptBatch([...ids(20), 'wrong'])).toThrow();
     51   });
     52 });