From 8fac635bf03c0710b2e266bba4fc2728c063fad8 Mon Sep 17 00:00:00 2001 From: Simeon Babev Date: Wed, 7 Aug 2024 12:04:44 +0300 Subject: [PATCH 1/4] Use separate API for wingman --- src/__tests__/wingman.test.ts | 4 ++-- src/utils.ts | 3 +++ src/wingman.ts | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/__tests__/wingman.test.ts b/src/__tests__/wingman.test.ts index 057b4bb..7bf0c6a 100644 --- a/src/__tests__/wingman.test.ts +++ b/src/__tests__/wingman.test.ts @@ -6,7 +6,7 @@ import { downloadTool } from "@actions/tool-cache"; import { exec } from "@actions/exec"; import { WingmanClient } from "../wingman"; -import { getFlyCIUrl } from "../utils"; +import { getFlyCIUrl, getWingmanUrl } from "../utils"; jest.mock("@actions/tool-cache"); jest.mock("@actions/exec"); @@ -75,7 +75,7 @@ describe("WingmanClient", () => { expect(exec).toHaveBeenCalledExactlyOnceWith(path, [], { env: expect.objectContaining({ - LLM_SERVER_URL: getFlyCIUrl(), + LLM_SERVER_URL: getWingmanUrl(), LLM_API_KEY: accessToken, FLYCI_WINGMAN_OUTPUT_FILE: p.join(tmpPath, "wingman.json"), }), diff --git a/src/utils.ts b/src/utils.ts index 88eeb73..59562fa 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -5,6 +5,7 @@ import { HttpClient } from "@actions/http-client"; import { BearerCredentialHandler } from "@actions/http-client/lib/auth"; export const FLYCI_URL = "https://api.flyci.net"; +export const WINGMAN_URL = "https://wingman.flyci.net"; export const getFlyCIUrl = (path: string = "") => { const url = core.getInput("flyci-url") || FLYCI_URL; @@ -12,6 +13,8 @@ export const getFlyCIUrl = (path: string = "") => { return `${url}${path}`; }; +export const getWingmanUrl = () => core.getInput("wingman-url") || WINGMAN_URL; + const getOidcToken = () => core.getIDToken(getFlyCIUrl()); export const getAccessToken = async () => { diff --git a/src/wingman.ts b/src/wingman.ts index a8185b7..6b6fc25 100644 --- a/src/wingman.ts +++ b/src/wingman.ts @@ -6,7 +6,7 @@ import fs from "node:fs/promises"; import { exec } from "@actions/exec"; import { downloadTool } from "@actions/tool-cache"; -import { getFlyCIUrl, getTempDir } from "./utils"; +import { getFlyCIUrl, getTempDir, getWingmanUrl } from "./utils"; const getWingmanDestinationPath = (platform: string) => { return p.format({ @@ -43,7 +43,7 @@ export class WingmanClient { run = async () => { const env = { ...process.env, - LLM_SERVER_URL: getFlyCIUrl(), + LLM_SERVER_URL: getWingmanUrl(), LLM_API_KEY: this.accessToken, FLYCI_WINGMAN_OUTPUT_FILE: p.join(getTempDir(), "wingman.json"), }; From 41c2e111b2b565ab6597fd952eea7732c36c5258 Mon Sep 17 00:00:00 2001 From: Simeon Babev Date: Wed, 7 Aug 2024 17:08:32 +0300 Subject: [PATCH 2/4] Add test for the wingman url input --- dist/index.js | 4 +++- src/__tests__/wingman.test.ts | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index cd6d22e..4e757fa 100644 --- a/dist/index.js +++ b/dist/index.js @@ -22002,10 +22002,12 @@ var core = __toESM(require_core()); var import_http_client = __toESM(require_lib()); var import_auth = __toESM(require_auth()); var FLYCI_URL = "https://api.flyci.net"; +var WINGMAN_URL = "https://wingman.flyci.net"; var getFlyCIUrl = (path = "") => { const url = core.getInput("flyci-url") || FLYCI_URL; return `${url}${path}`; }; +var getWingmanUrl = () => core.getInput("wingman-url") || WINGMAN_URL; var getOidcToken = () => core.getIDToken(getFlyCIUrl()); var getAccessToken = async () => { const oidcToken = await getOidcToken(); @@ -22051,7 +22053,7 @@ var WingmanClient = class _WingmanClient { run = async () => { const env = { ...process.env, - LLM_SERVER_URL: getFlyCIUrl(), + LLM_SERVER_URL: getWingmanUrl(), LLM_API_KEY: this.accessToken, FLYCI_WINGMAN_OUTPUT_FILE: import_node_path.default.join(getTempDir(), "wingman.json") }; diff --git a/src/__tests__/wingman.test.ts b/src/__tests__/wingman.test.ts index 7bf0c6a..f50be03 100644 --- a/src/__tests__/wingman.test.ts +++ b/src/__tests__/wingman.test.ts @@ -15,6 +15,7 @@ jest.mock("node:fs/promises"); jest.mock("node:os"); describe("WingmanClient", () => { + const wingmanUrlEnv = "INPUT_WINGMAN_URL"; const tmpPath = "/tmp/path"; const path = "/path/to/wingman"; const accessToken = "secret-access-token"; @@ -66,6 +67,9 @@ describe("WingmanClient", () => { }); describe("run", () => { + afterEach(() => { + delete process.env[wingmanUrlEnv]; + }); it("when wingman execution exits with non-zero exit code should throw error", async () => { mockExec.mockResolvedValueOnce(1); @@ -82,6 +86,21 @@ describe("WingmanClient", () => { }); }); + it("when wingman url input is set should use it", async () => { + process.env[wingmanUrlEnv] = "mock-url"; + mockExec.mockResolvedValueOnce(0); + + const wingman = await downloadWingman(); + + await wingman.run(); + + expect(exec).toHaveBeenCalledExactlyOnceWith(path, [], { + env: expect.objectContaining({ + LLM_SERVER_URL: "mock-url", + }), + }); + }); + it("when wingman execution exits with 0 exit code should return the output file path", async () => { mockExec.mockResolvedValueOnce(0); From fd5b53ee973de5647ce2e11db24ea79bcd63843a Mon Sep 17 00:00:00 2001 From: Simeon Babev Date: Wed, 7 Aug 2024 17:25:30 +0300 Subject: [PATCH 3/4] Fix typo --- src/__tests__/wingman.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__tests__/wingman.test.ts b/src/__tests__/wingman.test.ts index f50be03..3fa79c5 100644 --- a/src/__tests__/wingman.test.ts +++ b/src/__tests__/wingman.test.ts @@ -15,7 +15,7 @@ jest.mock("node:fs/promises"); jest.mock("node:os"); describe("WingmanClient", () => { - const wingmanUrlEnv = "INPUT_WINGMAN_URL"; + const wingmanUrlEnv = "INPUT_WINGMAN-URL"; const tmpPath = "/tmp/path"; const path = "/path/to/wingman"; const accessToken = "secret-access-token"; From 001a38e3e2e7ae2abd3ee9cf63661324d449ed3f Mon Sep 17 00:00:00 2001 From: Simeon Babev Date: Thu, 8 Aug 2024 09:19:35 +0300 Subject: [PATCH 4/4] Use mock instead of the env variable --- src/__tests__/wingman.test.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/__tests__/wingman.test.ts b/src/__tests__/wingman.test.ts index 3fa79c5..8515d71 100644 --- a/src/__tests__/wingman.test.ts +++ b/src/__tests__/wingman.test.ts @@ -4,10 +4,13 @@ import fs from "node:fs/promises"; import { downloadTool } from "@actions/tool-cache"; import { exec } from "@actions/exec"; +import { getInput } from "@actions/core"; import { WingmanClient } from "../wingman"; import { getFlyCIUrl, getWingmanUrl } from "../utils"; - +jest.mock("@actions/core", () => ({ + getInput: jest.fn(), +})); jest.mock("@actions/tool-cache"); jest.mock("@actions/exec"); @@ -15,12 +18,12 @@ jest.mock("node:fs/promises"); jest.mock("node:os"); describe("WingmanClient", () => { - const wingmanUrlEnv = "INPUT_WINGMAN-URL"; const tmpPath = "/tmp/path"; const path = "/path/to/wingman"; const accessToken = "secret-access-token"; const mockDownloadTool = downloadTool as jest.Mock; const mockExec = exec as jest.Mock; + const mockGetInput = getInput as jest.Mock; const downloadWingman = async () => { mockDownloadTool.mockResolvedValueOnce(path); @@ -67,9 +70,6 @@ describe("WingmanClient", () => { }); describe("run", () => { - afterEach(() => { - delete process.env[wingmanUrlEnv]; - }); it("when wingman execution exits with non-zero exit code should throw error", async () => { mockExec.mockResolvedValueOnce(1); @@ -87,13 +87,15 @@ describe("WingmanClient", () => { }); it("when wingman url input is set should use it", async () => { - process.env[wingmanUrlEnv] = "mock-url"; + mockGetInput.mockReturnValue("mock-url"); + mockExec.mockResolvedValueOnce(0); const wingman = await downloadWingman(); await wingman.run(); + expect(mockGetInput).toHaveBeenNthCalledWith(2, "wingman-url"); expect(exec).toHaveBeenCalledExactlyOnceWith(path, [], { env: expect.objectContaining({ LLM_SERVER_URL: "mock-url",