app

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

effect-ownership.test.ts (2439B)


      1 import { describe, expect, it } from 'vitest';
      2 import { makeFixture } from '../e2e/harness/approved-signing.ts';
      3 import {
      4   runCapturedPublicEffect,
      5   publicEffectSnapshot,
      6   type PublicEffectLease
      7 } from '../../src/lib/runtime/effect-ownership.ts';
      8 import type { PublicQuotaRepository } from '../../src/lib/persistence/quota.ts';
      9 describe('owned effect admission boundaries', () => {
     10   it('keeps genuine browser-only capture unavailable in SSR without invoking work', async () => {
     11     const f = makeFixture();
     12     let calls = 0;
     13     try {
     14       const result = await runCapturedPublicEffect(
     15         {} as PublicQuotaRepository,
     16         f.record,
     17         f.id,
     18         { owner: f.owner, session: Symbol(), current: () => true },
     19         'reviewed_captured_operation',
     20         () => {
     21           calls++;
     22           return Promise.resolve('forbidden');
     23         }
     24       );
     25       expect(result.status).toBe('unavailable');
     26       expect(calls).toBe(0);
     27     } finally {
     28       f.close();
     29     }
     30   });
     31   it('rejects unreviewed or forged and cross-ID capture before invoking effects', async () => {
     32     const f = makeFixture();
     33     let calls = 0;
     34     try {
     35       const context = {
     36           owner: f.owner,
     37           session: Symbol(),
     38           current: () => true
     39         },
     40         work = () => {
     41           calls++;
     42           return Promise.resolve();
     43         };
     44       expect(
     45         (
     46           await runCapturedPublicEffect(
     47             {} as PublicQuotaRepository,
     48             f.record,
     49             f.id,
     50             context,
     51             undefined,
     52             work
     53           )
     54         ).status
     55       ).toBe('invalid');
     56       expect(
     57         (
     58           await runCapturedPublicEffect(
     59             {} as PublicQuotaRepository,
     60             {} as never,
     61             f.id,
     62             context,
     63             'reviewed_captured_operation',
     64             work
     65           )
     66         ).status
     67       ).toBe('invalid');
     68       expect(
     69         (
     70           await runCapturedPublicEffect(
     71             {} as PublicQuotaRepository,
     72             f.record,
     73             crypto.randomUUID(),
     74             context,
     75             'reviewed_captured_operation',
     76             work
     77           )
     78         ).status
     79       ).toBe('invalid');
     80       expect(calls).toBe(0);
     81     } finally {
     82       f.close();
     83     }
     84   });
     85   it('fabricated ownership leases have no capability or mutable snapshot', () => {
     86     expect(publicEffectSnapshot({} as PublicEffectLease)).toBeUndefined();
     87   });
     88 });