import assert from 'node:assert/strict'; import { readFile } from 'node:fs/promises'; import { resolve } from 'node:path'; import test from 'node:test'; async function source(relativePath: string): Promise { return readFile(resolve(process.cwd(), 'src', relativePath), 'utf8'); } test('D5.3.3 separates operational state from data quality and adds registry structures', async () => { const migration = await source('database/migrations/1787508000000-phase-d5-3-3-definitive-operational-model.ts'); assert.match(migration, /CREATE TYPE asset_operational_status/); assert.match(migration, /CREATE TABLE organization_profiles/); assert.match(migration, /CREATE TABLE organization_memberships/); assert.match(migration, /CREATE TABLE source_documents/); assert.match(migration, /CREATE TABLE asset_external_identifiers/); assert.match(migration, /CREATE TABLE area_legal_rights/); assert.match(migration, /CREATE TABLE area_legal_right_organizations/); assert.match(migration, /relation_role='OPERATOR'/); assert.match(migration, /organization cannot be inactivated while operational relations, assignments, memberships or legal participation are active/); }); test('D5.3.3 keeps physical hierarchy separate from legal and organizational relations', async () => { const bootstrap = await source('asset-master/asset-master-bootstrap.ts'); const registry = await source('asset-master/asset-registry.service.ts'); assert.match(bootstrap, /name: 'Área'/); assert.match(bootstrap, /name: 'Organización'/); assert.match(bootstrap, /text\('cuenca', 'Cuenca'/); assert.match(bootstrap, /text\('departamento', 'Departamento'/); assert.match(registry, /OrganizationKind\.UTE/); assert.match(registry, /AreaLegalRight/); assert.match(registry, /source_documents/); }); test('D5.3.3 only accepts OPERATOR relations for exclusive asset assignment', async () => { const assets = await source('asset-master/assets.service.ts'); const relations = await source('asset-master/asset-operational-relations.service.ts'); assert.match(assets, /relation_role = 'OPERATOR'/); assert.match(relations, /relation\.relation_role = 'OPERATOR'/); assert.match(relations, /relationRole/); });