11// @vitest -environment node
2- import { afterEach , describe , expect , it } from "vitest" ;
2+ import { afterEach , beforeEach , describe , expect , it } from "vitest" ;
33import { createHash } from "node:crypto" ;
44import { existsSync , mkdirSync , mkdtempSync , readFileSync , rmSync , symlinkSync , writeFileSync } from "node:fs" ;
55import { tmpdir } from "node:os" ;
@@ -11,6 +11,14 @@ import {
1111import { cloudPoliciesDir } from "../../src/hooks/fp-home" ;
1212
1313const roots : string [ ] = [ ] ;
14+ let originalHome : string | undefined ;
15+
16+ beforeEach ( ( ) => {
17+ originalHome = process . env . FAILPROOFAI_HOME ;
18+ const home = mkdtempSync ( join ( tmpdir ( ) , "fpai-cloud-managed-home-" ) ) ;
19+ roots . push ( home ) ;
20+ process . env . FAILPROOFAI_HOME = home ;
21+ } ) ;
1422
1523function fixture ( policyBytes = Buffer . from ( "export default 'managed';\n" ) ) {
1624 const root = mkdtempSync ( join ( tmpdir ( ) , "fpai-cloud-managed-test-" ) ) ;
@@ -34,11 +42,18 @@ function fixture(policyBytes = Buffer.from("export default 'managed';\n")) {
3442
3543afterEach ( ( ) => {
3644 delete process . env . FAILPROOFAI_CLOUD_POLICY_DIR ;
37- delete process . env . FAILPROOFAI_HOME ;
45+ if ( originalHome === undefined ) delete process . env . FAILPROOFAI_HOME ;
46+ else process . env . FAILPROOFAI_HOME = originalHome ;
3847 for ( const root of roots . splice ( 0 ) ) rmSync ( root , { recursive : true , force : true } ) ;
3948} ) ;
4049
4150describe ( "cloud-managed policy active deployment" , ( ) => {
51+ it ( "ignores even an intact manifest after explicit OSS disconnect" , ( ) => {
52+ fixture ( ) ;
53+ writeFileSync ( join ( process . env . FAILPROOFAI_HOME ! , "config.json" ) , JSON . stringify ( { mode : { kind : "oss" } } ) ) ;
54+ expect ( readActiveCloudManagedPolicies ( ) ) . toEqual ( [ ] ) ;
55+ } ) ;
56+
4257 it ( "returns only hash-verified artifacts from active.json" , ( ) => {
4358 const { policyPath, sha256 } = fixture ( ) ;
4459 expect ( readActiveCloudManagedPolicies ( ) ) . toEqual ( [
0 commit comments