Skip to content

Commit 9825c0e

Browse files
committed
test(cloud): isolate managed-policy reader from host config
1 parent bfde4b5 commit 9825c0e

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

‎__tests__/hooks/cloud-managed-policies.test.ts‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @vitest-environment node
2-
import { afterEach, describe, expect, it } from "vitest";
2+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
33
import { createHash } from "node:crypto";
44
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
55
import { tmpdir } from "node:os";
@@ -11,6 +11,14 @@ import {
1111
import { cloudPoliciesDir } from "../../src/hooks/fp-home";
1212

1313
const 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

1523
function 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

3543
afterEach(() => {
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

4150
describe("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

Comments
 (0)