import { describe, it, expect, beforeEach, afterEach } from 'vitest' import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs' import { tmpdir } from 'node:os' import path from 'node:path' import { readSocleVersion, socleAtLeast, MIN_SOCLE_SUPPLIED_CODE_VERSION } from '../socle-version.js' describe('lib/socle-version', () => { let root: string beforeEach(() => { root = mkdtempSync(path.join(tmpdir(), 'ssver-')) }) afterEach(() => rmSync(root, { recursive: true, force: true })) it('reads the SmartStack PackageReference, Api project first', () => { const api = path.join(root, 'src', 'Demo.Api') const infra = path.join(root, 'src', 'Demo.Infrastructure') mkdirSync(api, { recursive: true }) mkdirSync(infra, { recursive: true }) writeFileSync(path.join(infra, 'Demo.Infrastructure.csproj'), '') writeFileSync(path.join(api, 'Demo.Api.csproj'), '') expect(readSocleVersion(root)).toBe('3.65.0') }) it('returns null on a project without the reference', () => { mkdirSync(path.join(root, 'src', 'X'), { recursive: true }) writeFileSync(path.join(root, 'src', 'X', 'X.csproj'), '') expect(readSocleVersion(root)).toBeNull() }) it('socleAtLeast compares numerically (never lexically) and treats null as below', () => { expect(socleAtLeast('3.65.0', '3.9.0')).toBe(true) expect(socleAtLeast('3.65.0', '3.65.0')).toBe(true) expect(socleAtLeast('3.64.9', '3.65.0')).toBe(false) expect(socleAtLeast(null, '0.0.1')).toBe(false) }) }) describe('MIN_SOCLE_SUPPLIED_CODE_VERSION — the supplied-on-create floor', () => { it('is pinned to the release that ships ISuppliedCodeGuard (3.66.0)', () => { expect(MIN_SOCLE_SUPPLIED_CODE_VERSION).toBe('3.66.0') expect(socleAtLeast('3.66.0', MIN_SOCLE_SUPPLIED_CODE_VERSION)).toBe(true) expect(socleAtLeast('3.65.9', MIN_SOCLE_SUPPLIED_CODE_VERSION)).toBe(false) }) })