Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default defineConfig([
"no-self-compare": "error",
"no-unassigned-vars": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/explicit-function-return-type": "error",
},
},
globalIgnores([
Expand Down
23 changes: 18 additions & 5 deletions scripts/accuracy/generateTestSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,24 @@ interface BaselineRunInfo {
createdOn: string;
}

interface TestSummary {
totalPrompts: number;
totalModels: number;
responsesWithZeroAccuracy: ModelResponse[];
responsesWith75Accuracy: ModelResponse[];
responsesWith100Accuracy: ModelResponse[];
averageAccuracy: number;
responsesImproved: number;
responsesRegressed: number;
reportGeneratedOn: string;
resultCreatedOn: string;
}

function populateTemplate(template: string, data: Record<string, string>): string {
return template.replace(/\{\{(\w+)\}\}/g, (_, key: string) => data[key] ?? "");
}

function formatRunStatus(status: AccuracyRunStatuses) {
function formatRunStatus(status: AccuracyRunStatuses): string {
const statusClasses = ["chip", "run-status"];
if (status === "done") {
statusClasses.push("perfect");
Expand Down Expand Up @@ -107,7 +120,7 @@ function formatBaselineAccuracy(response: PromptAndModelResponse): string {
return `<span class="accuracy-comparison">${formatAccuracy(response.baselineToolAccuracy)}</span>`;
}

function getTestSummary(comparableResult: ComparableAccuracyResult) {
function getTestSummary(comparableResult: ComparableAccuracyResult): TestSummary {
const responses = comparableResult.promptAndModelResponses;
return {
totalPrompts: new Set(responses.map((r) => r.prompt)).size,
Expand All @@ -130,7 +143,7 @@ function getTestSummary(comparableResult: ComparableAccuracyResult) {

async function generateHtmlReport(
comparableResult: ComparableAccuracyResult,
testSummary: ReturnType<typeof getTestSummary>,
testSummary: TestSummary,
baselineInfo: BaselineRunInfo | null
): Promise<string> {
const responses = comparableResult.promptAndModelResponses;
Expand Down Expand Up @@ -193,7 +206,7 @@ async function generateHtmlReport(

function generateMarkdownBrief(
comparableResult: ComparableAccuracyResult,
testSummary: ReturnType<typeof getTestSummary>,
testSummary: TestSummary,
baselineInfo: BaselineRunInfo | null
): string {
const markdownTexts = [
Expand Down Expand Up @@ -243,7 +256,7 @@ function generateMarkdownBrief(
return markdownTexts.join("\n");
}

async function generateTestSummary() {
async function generateTestSummary(): Promise<void> {
const storage = getAccuracyResultStorage();
try {
const baselineCommit = process.env.MDB_ACCURACY_BASELINE_COMMIT;
Expand Down
5 changes: 3 additions & 2 deletions scripts/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function findObjectFromRef<T>(obj: T | OpenAPIV3_1.ReferenceObject, openapi: Ope
return foundObj as T;
}

async function main() {
async function main(): Promise<void> {
const { spec, file } = argv(process.argv.slice(2));

if (!spec || !file) {
Expand Down Expand Up @@ -92,7 +92,8 @@ async function main() {
const operationOutput = operations
.map((operation) => {
const { operationId, method, path, requiredParams, hasResponseBody } = operation;
return `async ${operationId}(options${requiredParams ? "" : "?"}: FetchOptions<operations["${operationId}"]>) {
return `// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async ${operationId}(options${requiredParams ? "" : "?"}: FetchOptions<operations["${operationId}"]>) {
const { ${hasResponseBody ? `data, ` : ``}error, response } = await this.client.${method}("${path}", options);
if (error) {
throw ApiClientError.fromError(response, error);
Expand Down
4 changes: 2 additions & 2 deletions scripts/filter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OpenAPIV3_1 } from "openapi-types";

async function readStdin() {
async function readStdin(): Promise<string> {
return new Promise<string>((resolve, reject) => {
let data = "";
process.stdin.setEncoding("utf8");
Expand Down Expand Up @@ -63,7 +63,7 @@ function filterOpenapi(openapi: OpenAPIV3_1.Document): OpenAPIV3_1.Document {
return { ...openapi, paths: filteredPaths };
}

async function main() {
async function main(): Promise<void> {
const openapiText = await readStdin();
const openapi = JSON.parse(openapiText) as OpenAPIV3_1.Document;
const filteredOpenapi = filterOpenapi(openapi);
Expand Down
2 changes: 1 addition & 1 deletion src/common/atlas/accessListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export async function makeCurrentIpAccessListEntry(
apiClient: ApiClient,
projectId: string,
comment: string = DEFAULT_ACCESS_LIST_COMMENT
) {
): Promise<{ groupId: string; ipAddress: string; comment: string }> {
const { currentIpv4Address } = await apiClient.getIpInfo();
return {
groupId: projectId,
Expand Down
27 changes: 24 additions & 3 deletions src/common/atlas/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class ApiClient {
);
}

private getAccessToken = async () => {
private getAccessToken = async (): Promise<string | undefined> => {
if (!this.hasCredentials()) {
return undefined;
}
Expand Down Expand Up @@ -145,7 +145,7 @@ export class ApiClient {
// the username and password (for example, encodes `_` to %5F, which is wrong).
return {
client: { client_id: clientId },
clientAuth: (_as, client, _body, headers) => {
clientAuth: (_as, client, _body, headers): void => {
const credentials = Buffer.from(`${clientId}:${clientSecret}`).toString("base64");
headers.set("Authorization", `Basic ${credentials}`);
},
Expand Down Expand Up @@ -305,6 +305,7 @@ export class ApiClient {
}

// DO NOT EDIT. This is auto-generated code.
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listClustersForAllProjects(options?: FetchOptions<operations["listClustersForAllProjects"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/clusters", options);
if (error) {
Expand All @@ -313,6 +314,7 @@ export class ApiClient {
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listProjects(options?: FetchOptions<operations["listProjects"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/groups", options);
if (error) {
Expand All @@ -321,6 +323,7 @@ export class ApiClient {
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async createProject(options: FetchOptions<operations["createProject"]>) {
const { data, error, response } = await this.client.POST("/api/atlas/v2/groups", options);
if (error) {
Expand All @@ -329,13 +332,15 @@ export class ApiClient {
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async deleteProject(options: FetchOptions<operations["deleteProject"]>) {
const { error, response } = await this.client.DELETE("/api/atlas/v2/groups/{groupId}", options);
if (error) {
throw ApiClientError.fromError(response, error);
}
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async getProject(options: FetchOptions<operations["getProject"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/groups/{groupId}", options);
if (error) {
Expand All @@ -344,6 +349,7 @@ export class ApiClient {
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listProjectIpAccessLists(options: FetchOptions<operations["listProjectIpAccessLists"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/groups/{groupId}/accessList", options);
if (error) {
Expand All @@ -352,6 +358,7 @@ export class ApiClient {
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async createProjectIpAccessList(options: FetchOptions<operations["createProjectIpAccessList"]>) {
const { data, error, response } = await this.client.POST("/api/atlas/v2/groups/{groupId}/accessList", options);
if (error) {
Expand All @@ -360,6 +367,7 @@ export class ApiClient {
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async deleteProjectIpAccessList(options: FetchOptions<operations["deleteProjectIpAccessList"]>) {
const { error, response } = await this.client.DELETE(
"/api/atlas/v2/groups/{groupId}/accessList/{entryValue}",
Expand All @@ -370,6 +378,7 @@ export class ApiClient {
}
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listAlerts(options: FetchOptions<operations["listAlerts"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/groups/{groupId}/alerts", options);
if (error) {
Expand All @@ -378,6 +387,7 @@ export class ApiClient {
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listClusters(options: FetchOptions<operations["listClusters"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/groups/{groupId}/clusters", options);
if (error) {
Expand All @@ -386,6 +396,7 @@ export class ApiClient {
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async createCluster(options: FetchOptions<operations["createCluster"]>) {
const { data, error, response } = await this.client.POST("/api/atlas/v2/groups/{groupId}/clusters", options);
if (error) {
Expand All @@ -394,6 +405,7 @@ export class ApiClient {
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async deleteCluster(options: FetchOptions<operations["deleteCluster"]>) {
const { error, response } = await this.client.DELETE(
"/api/atlas/v2/groups/{groupId}/clusters/{clusterName}",
Expand All @@ -404,18 +416,19 @@ export class ApiClient {
}
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async getCluster(options: FetchOptions<operations["getCluster"]>) {
const { data, error, response } = await this.client.GET(
"/api/atlas/v2/groups/{groupId}/clusters/{clusterName}",
options
);

if (error) {
throw ApiClientError.fromError(response, error);
}
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listDatabaseUsers(options: FetchOptions<operations["listDatabaseUsers"]>) {
const { data, error, response } = await this.client.GET(
"/api/atlas/v2/groups/{groupId}/databaseUsers",
Expand All @@ -427,6 +440,7 @@ export class ApiClient {
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async createDatabaseUser(options: FetchOptions<operations["createDatabaseUser"]>) {
const { data, error, response } = await this.client.POST(
"/api/atlas/v2/groups/{groupId}/databaseUsers",
Expand All @@ -438,6 +452,7 @@ export class ApiClient {
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async deleteDatabaseUser(options: FetchOptions<operations["deleteDatabaseUser"]>) {
const { error, response } = await this.client.DELETE(
"/api/atlas/v2/groups/{groupId}/databaseUsers/{databaseName}/{username}",
Expand All @@ -448,6 +463,7 @@ export class ApiClient {
}
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listFlexClusters(options: FetchOptions<operations["listFlexClusters"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/groups/{groupId}/flexClusters", options);
if (error) {
Expand All @@ -456,6 +472,7 @@ export class ApiClient {
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async createFlexCluster(options: FetchOptions<operations["createFlexCluster"]>) {
const { data, error, response } = await this.client.POST(
"/api/atlas/v2/groups/{groupId}/flexClusters",
Expand All @@ -467,6 +484,7 @@ export class ApiClient {
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async deleteFlexCluster(options: FetchOptions<operations["deleteFlexCluster"]>) {
const { error, response } = await this.client.DELETE(
"/api/atlas/v2/groups/{groupId}/flexClusters/{name}",
Expand All @@ -477,6 +495,7 @@ export class ApiClient {
}
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async getFlexCluster(options: FetchOptions<operations["getFlexCluster"]>) {
const { data, error, response } = await this.client.GET(
"/api/atlas/v2/groups/{groupId}/flexClusters/{name}",
Expand All @@ -488,6 +507,7 @@ export class ApiClient {
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listOrganizations(options?: FetchOptions<operations["listOrganizations"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/orgs", options);
if (error) {
Expand All @@ -496,6 +516,7 @@ export class ApiClient {
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listOrganizationProjects(options: FetchOptions<operations["listOrganizationProjects"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/orgs/{orgId}/groups", options);
if (error) {
Expand Down
Loading
Loading