|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * The ADR-0131 D10 inventory's enumeration pin: every object of both #13564 |
| 5 | + * censuses, of the platform registry as it stands, and of the cloud supplement |
| 6 | + * carries exactly one fate and a citation. A platform object that lands |
| 7 | + * without an inventory row turns this red by name — the plan would refuse its |
| 8 | + * table on a real database, and this says so before any database does. |
| 9 | + */ |
| 10 | + |
| 11 | +import { describe, expect, it } from 'vitest'; |
| 12 | +import { CLOUD_PROVIDED_OBJECT_NAMES, PLATFORM_OBJECTS_BY_PACKAGE } from '@objectstack/spec/system'; |
| 13 | +import { |
| 14 | + ORGANIZATION_OWNERSHIP_FATES, |
| 15 | + ORGANIZATION_OWNERSHIP_INVENTORY, |
| 16 | + inventoryEntryFor, |
| 17 | +} from './organization-ownership-inventory.js'; |
| 18 | + |
| 19 | +/** |
| 20 | + * The first census's platform population — 59 carrying the column, 25 not — |
| 21 | + * as #13564 comment 5479883784 lists it (measured at `00d8f6541b`). Frozen: |
| 22 | + * it is a record of what was counted, not of the tree. |
| 23 | + */ |
| 24 | +const CENSUS_2026_08_31_PLATFORM_WITH_COLUMN = [ |
| 25 | + // accidental (7) + global (1) |
| 26 | + 'sys_file', 'sys_upload_session', 'sys_approval_request', 'sys_approval_action', 'sys_approval_approver', |
| 27 | + 'sys_automation_run', 'sys_notification_delivery', 'sys_permission_set', |
| 28 | + // load-bearing confirmed beyond the ledger |
| 29 | + 'sys_metadata', 'sys_view_definition', |
| 30 | + // split-verdict (7) |
| 31 | + 'sys_position', 'sys_business_unit', 'sys_business_unit_member', 'sys_user_position', |
| 32 | + 'sys_position_permission_set', 'sys_user_permission_set', 'sys_capability', |
| 33 | + // structural siblings (3) |
| 34 | + 'sys_metadata_audit', 'sys_metadata_commit', 'sys_metadata_history', |
| 35 | + // not individually examined (39) |
| 36 | + 'sys_activity', 'sys_approval_delegation', 'sys_approval_token', 'sys_attachment', |
| 37 | + 'sys_audience_binding_suggestion', 'sys_audit_log', 'sys_comment', 'sys_email', 'sys_email_template', |
| 38 | + 'sys_flow_dispatch', 'sys_http_delivery', 'sys_import_job', 'sys_inbox_message', 'sys_invitation', 'sys_job', |
| 39 | + 'sys_job_queue', 'sys_job_run', 'sys_member', 'sys_metadata_activation', 'sys_migration', 'sys_migration_journal', |
| 40 | + 'sys_notification', 'sys_notification_preference', 'sys_notification_receipt', 'sys_notification_subscription', |
| 41 | + 'sys_notification_template', 'sys_presence', 'sys_record_share', 'sys_report_schedule', 'sys_saved_report', |
| 42 | + 'sys_scim_connection_credential', 'sys_secret', 'sys_setting', 'sys_setting_audit', 'sys_share_link', |
| 43 | + 'sys_sharing_rule', 'sys_team', 'sys_user_preference', 'sys_webhook', |
| 44 | +] as const; |
| 45 | + |
| 46 | +const CENSUS_2026_08_31_PLATFORM_WITHOUT_COLUMN = [ |
| 47 | + 'sys_account', 'sys_api_key', 'sys_device_code', 'sys_jwks', 'sys_oauth_access_token', 'sys_oauth_application', |
| 48 | + 'sys_oauth_client_assertion', 'sys_oauth_client_resource', 'sys_oauth_consent', 'sys_oauth_refresh_token', |
| 49 | + 'sys_oauth_resource', 'sys_organization', 'sys_scim_connection_binding', 'sys_scim_group', 'sys_scim_group_member', |
| 50 | + 'sys_scim_identity_tombstone', 'sys_scim_projection_grant', 'sys_scim_subject', 'sys_scim_user', 'sys_session', |
| 51 | + 'sys_team_member', 'sys_two_factor', 'sys_user', 'sys_verification', 'sys_sso_provider', |
| 52 | +] as const; |
| 53 | + |
| 54 | +/** |
| 55 | + * The census's "28 non-platform objects" — it counted the 28 files; they |
| 56 | + * declare these 33 objects, read at the census commit and unchanged on `main`. |
| 57 | + */ |
| 58 | +const CENSUS_2026_08_31_EXAMPLES = [ |
| 59 | + 'blank_note', 'crm_account', 'crm_activity', 'crm_contact', 'crm_lead', 'crm_opportunity', |
| 60 | + 'crm_opportunity_line_item', 'dc_account', 'showcase_account', 'showcase_announcement', 'showcase_business_unit', |
| 61 | + 'showcase_cascade', 'showcase_category', 'showcase_client_brief', 'showcase_contact', 'showcase_expense_line', |
| 62 | + 'showcase_expense_report', 'showcase_ext_customer', 'showcase_ext_order', 'showcase_field_zoo', 'showcase_inquiry', |
| 63 | + 'showcase_invoice', 'showcase_invoice_line', 'showcase_preference', 'showcase_private_note', 'showcase_product', |
| 64 | + 'showcase_project', 'showcase_project_membership', 'showcase_semantic_zoo', 'showcase_semantic_zoo_legacy', |
| 65 | + 'showcase_task', 'showcase_team', 'todo_task', |
| 66 | +] as const; |
| 67 | + |
| 68 | +/** |
| 69 | + * #14570 and #15086, read in: each population's table has its own fate, citing |
| 70 | + * the record that read it in (a runtime string carries no tracker number). |
| 71 | + */ |
| 72 | +const READ_IN = { sys_business_unit_member: '6067123924', sys_business_unit: '5536478573' } as const; |
| 73 | + |
| 74 | +const unlisted = (names: readonly string[]): string[] => names.filter((name) => inventoryEntryFor(name) === undefined); |
| 75 | + |
| 76 | +describe('ADR-0131 D10 inventory — every censused object has one fate and a citation', () => { |
| 77 | + it('the first census: 59 + 25 platform objects', () => { |
| 78 | + expect(CENSUS_2026_08_31_PLATFORM_WITH_COLUMN).toHaveLength(59); |
| 79 | + expect(CENSUS_2026_08_31_PLATFORM_WITHOUT_COLUMN).toHaveLength(25); |
| 80 | + expect(unlisted([...CENSUS_2026_08_31_PLATFORM_WITH_COLUMN, ...CENSUS_2026_08_31_PLATFORM_WITHOUT_COLUMN])).toEqual([]); |
| 81 | + }); |
| 82 | + |
| 83 | + it('the first census: the example objects of its 28 files', () => { |
| 84 | + expect(unlisted(CENSUS_2026_08_31_EXAMPLES)).toEqual([]); |
| 85 | + }); |
| 86 | + |
| 87 | + it('the platform registry as it stands — a platform object without a row reds here, by name', () => { |
| 88 | + const registered = Object.values(PLATFORM_OBJECTS_BY_PACKAGE).flat(); |
| 89 | + expect(registered.length).toBeGreaterThan(80); |
| 90 | + expect(unlisted(registered)).toEqual([]); |
| 91 | + }); |
| 92 | + |
| 93 | + it('the cloud supplement: listed as cloud-carried, fate 4, never a guessed fate', () => { |
| 94 | + expect(CLOUD_PROVIDED_OBJECT_NAMES.length).toBeGreaterThan(0); |
| 95 | + expect(unlisted(CLOUD_PROVIDED_OBJECT_NAMES)).toEqual([]); |
| 96 | + for (const name of CLOUD_PROVIDED_OBJECT_NAMES) { |
| 97 | + expect(inventoryEntryFor(name), name).toMatchObject({ fate: 'report', cloudCarried: true }); |
| 98 | + } |
| 99 | + }); |
| 100 | + |
| 101 | + it('#14570 and #15086 are read in, each with its own fate and citation', () => { |
| 102 | + for (const [object, record] of Object.entries(READ_IN)) { |
| 103 | + const entry = inventoryEntryFor(object); |
| 104 | + expect(entry?.fate, object).toBe('attribution'); |
| 105 | + expect(entry?.citation, object).toContain(record); |
| 106 | + } |
| 107 | + }); |
| 108 | + |
| 109 | + it('one row per object, a fate from the four, a non-empty citation', () => { |
| 110 | + const seen = new Set<string>(); |
| 111 | + for (const entry of ORGANIZATION_OWNERSHIP_INVENTORY) { |
| 112 | + expect(seen.has(entry.object), `${entry.object} listed twice`).toBe(false); |
| 113 | + seen.add(entry.object); |
| 114 | + expect(ORGANIZATION_OWNERSHIP_FATES, entry.object).toContain(entry.fate); |
| 115 | + expect(entry.citation.trim().length, entry.object).toBeGreaterThan(20); |
| 116 | + expect(entry.census.length, entry.object).toBeGreaterThan(0); |
| 117 | + } |
| 118 | + }); |
| 119 | + |
| 120 | + it('each fate carries only the fields that fate reads', () => { |
| 121 | + for (const entry of ORGANIZATION_OWNERSHIP_INVENTORY) { |
| 122 | + if (entry.anchors) expect(entry.fate, `${entry.object}: anchors outside fate 3`).toBe('attribution'); |
| 123 | + if (entry.mirror) expect(entry.fate, `${entry.object}: a mirror selector outside fate 2`).toBe('mirror-deletion'); |
| 124 | + if (entry.notNullExempt || entry.cloudCarried) expect(entry.fate, entry.object).toBe('report'); |
| 125 | + if (entry.fate === 'attribution') expect(entry.anchors, `${entry.object}: fate 3 names its anchors`).toBeDefined(); |
| 126 | + } |
| 127 | + }); |
| 128 | + |
| 129 | + it('every parent and holder an anchor names is itself inventoried', () => { |
| 130 | + for (const entry of ORGANIZATION_OWNERSHIP_INVENTORY) { |
| 131 | + for (const anchor of entry.anchors ?? []) { |
| 132 | + const target = anchor.kind === 'parent' ? anchor.parentObject : anchor.kind === 'holder' ? anchor.holderObject : null; |
| 133 | + if (target) expect(inventoryEntryFor(target), `${entry.object} → ${target}`).toBeDefined(); |
| 134 | + } |
| 135 | + } |
| 136 | + }); |
| 137 | +}); |
0 commit comments