import { resolveServiceDetailsRef } from "./utils.js";
import { isTestbotEnabled } from "./featureFlags.js";
// Capture and restore the original env var so these tests don't pollute other
// test suites or a developer's shell environment where the var may already be set.
let originalTestbotEnv;
beforeAll(() => { originalTestbotEnv = process.env.SKYRAMP_FEATURE_TESTBOT; });
afterAll(() => {
    if (originalTestbotEnv === undefined) {
        delete process.env.SKYRAMP_FEATURE_TESTBOT;
    }
    else {
        process.env.SKYRAMP_FEATURE_TESTBOT = originalTestbotEnv;
    }
});
describe("isTestbotEnabled", () => {
    afterEach(() => {
        delete process.env.SKYRAMP_FEATURE_TESTBOT;
    });
    it('returns true when SKYRAMP_FEATURE_TESTBOT is "1"', () => {
        process.env.SKYRAMP_FEATURE_TESTBOT = "1";
        expect(isTestbotEnabled()).toBe(true);
    });
    it("returns false when SKYRAMP_FEATURE_TESTBOT is unset", () => {
        expect(isTestbotEnabled()).toBe(false);
    });
    it('returns false when SKYRAMP_FEATURE_TESTBOT is "0"', () => {
        process.env.SKYRAMP_FEATURE_TESTBOT = "0";
        expect(isTestbotEnabled()).toBe(false);
    });
    it('returns false when SKYRAMP_FEATURE_TESTBOT is "true"', () => {
        process.env.SKYRAMP_FEATURE_TESTBOT = "true";
        expect(isTestbotEnabled()).toBe(false);
    });
});
describe("resolveServiceDetailsRef", () => {
    afterEach(() => {
        delete process.env.SKYRAMP_FEATURE_TESTBOT;
    });
    describe("testbot mode (SKYRAMP_FEATURE_TESTBOT=1)", () => {
        beforeEach(() => {
            process.env.SKYRAMP_FEATURE_TESTBOT = "1";
        });
        it("returns <services> block reference for testDirRef", () => {
            expect(resolveServiceDetailsRef().testDirRef).toContain("<test_directory>");
            expect(resolveServiceDetailsRef().testDirRef).toContain("<services>");
        });
        it("returns <services> block reference for frontendTestDirRef", () => {
            expect(resolveServiceDetailsRef().frontendTestDirRef).toContain("<test_directory>");
            expect(resolveServiceDetailsRef().frontendTestDirRef).toContain("<services>");
        });
        it("returns <services> block reference for authSourceRef", () => {
            expect(resolveServiceDetailsRef().authSourceRef).toContain("<services>");
        });
        it("returns <services> block reference for baseUrlRef", () => {
            expect(resolveServiceDetailsRef().baseUrlRef).toContain("<base_url>");
        });
        it("does NOT reference workspace.yml in any field", () => {
            const refs = resolveServiceDetailsRef();
            for (const val of Object.values(refs)) {
                expect(val).not.toContain("workspace.yml");
            }
        });
    });
    describe("MCP mode (SKYRAMP_FEATURE_TESTBOT unset)", () => {
        it("returns workspace.yml reference for testDirRef", () => {
            expect(resolveServiceDetailsRef().testDirRef).toContain("workspace.yml");
        });
        it("returns workspace.yml reference for frontendTestDirRef", () => {
            expect(resolveServiceDetailsRef().frontendTestDirRef).toContain("workspace.yml");
        });
        it("returns workspace.yml reference for authSourceRef", () => {
            expect(resolveServiceDetailsRef().authSourceRef).toContain("workspace.yml");
        });
        it("does NOT reference <services> in any field", () => {
            const refs = resolveServiceDetailsRef();
            for (const val of Object.values(refs)) {
                expect(val).not.toContain("<services>");
            }
        });
    });
});
