import { describe, expect, it } from 'vitest'; import type { EnvironmentObservation } from '../../src/domain/environment-context'; import { inferGpoEnvironmentContexts } from '../../server/gpo/gpo-environment-context'; function fact(property: string, value: string, subject = 'computer-information.domain-controllers', state = 'observed') { return { id: `synthetic-${property}-${value}`, property, originalValue: value, subject: { type: subject }, state } as EnvironmentObservation; } describe('GPO environment context evidence', () => { it('uses the DC operating system instead of domain or forest functional levels', () => { const contexts = inferGpoEnvironmentContexts([ fact('operating_system.name', 'Windows 2019'), fact('domain.functional_level', 'Windows Server 2016'), fact('forest.functional_level', 'Windows Server 2016') ]); expect(contexts).toHaveLength(1); expect(contexts[0]).toMatchObject({ productFamily: 'Windows Server', productVersion: '2019', role: 'Domain Controller', sourceObservationIds: ['synthetic-operating_system.name-Windows 2019'] }); }); it('does not infer roles from generic server inventory, functional levels or missing evidence', () => { expect(inferGpoEnvironmentContexts([ fact('domain.functional_level', 'Windows Server 2022'), fact('operating_system.name', 'Windows Server 2022', 'computer-information.operating-systems'), fact('operating_system.name', 'Windows Server 2022', 'computer-information.domain-controllers', 'unknown') ])).toEqual([]); }); });