|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * The Layer 0 verdict ladder (ADR-0095 D1 / ADR-0131 D8), rung by rung — in |
| 5 | + * particular the rung an external object reaches when it states no |
| 6 | + * organization scope under a walled posture (ADR-0015 §10): the wall DENIES, |
| 7 | + * it does not stand down. |
| 8 | + */ |
| 9 | + |
| 10 | +import { describe, it, expect } from 'vitest'; |
| 11 | +import { computeTenantLayer0Verdict, type TenantLayer0Input } from './tenant-layer0-verdict.js'; |
| 12 | + |
| 13 | +const member = (over: Partial<TenantLayer0Input> = {}): TenantLayer0Input => ({ |
| 14 | + tenancyPosture: 'isolated', |
| 15 | + organizationId: 'org-1', |
| 16 | + objectHasOrgIdField: true, |
| 17 | + tenancyDisabled: false, |
| 18 | + posturePermitsCrossTenant: false, |
| 19 | + isPlatformAdmin: false, |
| 20 | + ...over, |
| 21 | +}); |
| 22 | + |
| 23 | +describe('computeTenantLayer0Verdict — an external object that states no organization scope', () => { |
| 24 | + it('under `isolated` the wall denies: no provable scope, no row', () => { |
| 25 | + expect(computeTenantLayer0Verdict(member({ externalOrganizationScopeUndeclared: true, objectHasOrgIdField: false }))) |
| 26 | + .toEqual({ kind: 'deny' }); |
| 27 | + }); |
| 28 | + |
| 29 | + it('under `group` the wall denies too — the union predicate has no column to name', () => { |
| 30 | + expect(computeTenantLayer0Verdict(member({ |
| 31 | + tenancyPosture: 'group', accessibleOrgIds: ['org-1', 'org-2'], |
| 32 | + externalOrganizationScopeUndeclared: true, objectHasOrgIdField: false, |
| 33 | + }))).toEqual({ kind: 'deny' }); |
| 34 | + }); |
| 35 | + |
| 36 | + it('the denial precedes the platform-admin crossing: an undeclared object is a configuration defect, not a posture', () => { |
| 37 | + expect(computeTenantLayer0Verdict(member({ |
| 38 | + externalOrganizationScopeUndeclared: true, objectHasOrgIdField: false, |
| 39 | + isPlatformAdmin: true, posturePermitsCrossTenant: true, |
| 40 | + }))).toEqual({ kind: 'deny' }); |
| 41 | + }); |
| 42 | + |
| 43 | + it('a declared opt-out (`tenancy.enabled: false`) still contributes nothing — the object is shared by every organization', () => { |
| 44 | + expect(computeTenantLayer0Verdict(member({ tenancyDisabled: true, externalOrganizationScopeUndeclared: false, objectHasOrgIdField: false }))) |
| 45 | + .toEqual({ kind: 'none' }); |
| 46 | + }); |
| 47 | + |
| 48 | + it('a declared `organization_id` keeps the wall', () => { |
| 49 | + expect(computeTenantLayer0Verdict(member({ externalOrganizationScopeUndeclared: false }))) |
| 50 | + .toEqual({ kind: 'organization', organizationId: 'org-1' }); |
| 51 | + }); |
| 52 | + |
| 53 | + it('CONTROL: under `single` nothing is read — an undeclared object answers `none` like every other', () => { |
| 54 | + expect(computeTenantLayer0Verdict(member({ tenancyPosture: 'single', externalOrganizationScopeUndeclared: true, objectHasOrgIdField: false }))) |
| 55 | + .toEqual({ kind: 'none' }); |
| 56 | + }); |
| 57 | + |
| 58 | + it('CONTROL: the flag omitted reads as every caller before it — a column-less object answers `none`', () => { |
| 59 | + expect(computeTenantLayer0Verdict(member({ objectHasOrgIdField: false }))).toEqual({ kind: 'none' }); |
| 60 | + }); |
| 61 | +}); |
0 commit comments