// @vitest-environment node import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest'; import { createIsolatedPgLiquidDb, destroyIsolatedPgLiquidDb, joinProgram, resetLiquidSchema, type PgLiquidTestDb, } from '../helpers/pg-liquid-test-helpers.js'; describe('integration: ontology closure', () => { let db: PgLiquidTestDb; beforeAll(async () => { db = await createIsolatedPgLiquidDb('pg_liquid_itest_ontology'); }); beforeEach(async () => { await resetLiquidSchema(db.sql); }); afterAll(async () => { await destroyIsolatedPgLiquidDb(db); }); it('derives transitive class ancestry', async () => { const program = joinProgram([ 'Edge("class/BudgetPreference", "food/subclass_of", "class/LifestyleFactor").', 'Edge("class/LifestyleFactor", "food/subclass_of", "class/Thing").', 'ClassAncestor(child_class, parent_class) :- Edge(child_class, "food/subclass_of", parent_class).', 'ClassAncestor(child_class, ancestor_class) :-', ' Edge(child_class, "food/subclass_of", parent_class),', ' ClassAncestor(parent_class, ancestor_class).', 'ClassAncestor("class/BudgetPreference", ancestor_class)?', ]); const rows = await db.sql>` select ancestor_class from liquid.query(${program}) as t(ancestor_class text) order by ancestor_class `; const ancestors = rows.map((row) => row.ancestor_class); expect(ancestors).toContain('class/LifestyleFactor'); expect(ancestors).toContain('class/Thing'); }); });