Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use separate API for wingman #6

Merged
merged 4 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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")
};
Expand Down
27 changes: 24 additions & 3 deletions src/__tests__/wingman.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 } from "../utils";

import { getFlyCIUrl, getWingmanUrl } from "../utils";
jest.mock("@actions/core", () => ({
getInput: jest.fn(),
}));
jest.mock("@actions/tool-cache");
jest.mock("@actions/exec");

Expand All @@ -20,6 +23,7 @@ describe("WingmanClient", () => {
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);
Expand Down Expand Up @@ -75,13 +79,30 @@ 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"),
}),
});
});

it("when wingman url input is set should use it", async () => {
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",
}),
});
});

it("when wingman execution exits with 0 exit code should return the output file path", async () => {
mockExec.mockResolvedValueOnce(0);

Expand Down
3 changes: 3 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ 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;

return `${url}${path}`;
};

export const getWingmanUrl = () => core.getInput("wingman-url") || WINGMAN_URL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a unit test for the scenario when the URL is passed as input?


const getOidcToken = () => core.getIDToken(getFlyCIUrl());

export const getAccessToken = async () => {
Expand Down
4 changes: 2 additions & 2 deletions src/wingman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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"),
};
Expand Down