import { evaluateGitShellPolicy } from "@rakazo/core"; import { describe, expect, it, vi } from "vitest"; import { githubIntegrationEnvironmentForRun } from "./deployment-github-token.js"; import { githubBrokerBaseUrl } from "./github-broker-client.js"; describe("home Chief GitHub broker integration", () => { it("exposes broker env without raw GitHub tokens when integration is set", () => { vi.stubEnv("SANDBOX_SUPERVISOR_TOKEN", "test-supervisor-token-test-32chars"); vi.stubEnv("SANDBOX_GITHUB_BROKER_URL", "http://supervisor:7091/internal/github-broker"); const env = githubIntegrationEnvironmentForRun({ runId: "run-home", githubToken: "ghp_integration_only", }); expect(env.GITHUB_TOKEN).toBeUndefined(); expect(env.GH_TOKEN).toBeUndefined(); expect(env.RAKAZO_GITHUB_BROKER_RUN_TOKEN).toMatch(/^rgb1\./); vi.unstubAllEnvs(); }); it("points computers at the host when the supervisor listens on loopback", () => { vi.stubEnv("SANDBOX_GITHUB_BROKER_URL", ""); vi.stubEnv("SANDBOX_SUPERVISOR_URL", "http://127.0.0.1:7091"); expect(githubBrokerBaseUrl()).toBe("http://host.docker.internal:7091/internal/github-broker"); vi.stubEnv("SANDBOX_SUPERVISOR_URL", "http://supervisor:7091/"); expect(githubBrokerBaseUrl()).toBe("http://supervisor:7091/internal/github-broker"); vi.unstubAllEnvs(); }); it("refuses push to the default branch even when approval was granted", () => { const decision = evaluateGitShellPolicy({ command: "git push origin main", defaultBranch: "main", gitPushApprovedThisRun: true, }); expect(decision.action).toBe("block"); }); it("requires approval before the first push in a run", () => { const decision = evaluateGitShellPolicy({ command: "git push origin feature/login", defaultBranch: "main", gitPushApprovedThisRun: false, }); expect(decision.action).toBe("require_approval"); }); });