Skip to content

Commit

Permalink
feat: mask apiKey in prompt and add async functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gowoons committed Aug 1, 2023
1 parent 4d287ff commit cc95720
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/configure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const configure = async () => {
type: "input",
name: "apiKey",
message: "Please input your OpenAI API key:",
mask: "*",
},
]);

Expand Down
2 changes: 1 addition & 1 deletion src/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const test = async ({ ci, model }: ReviewArgs) => {
const maxPromptLength = getMaxPromptLength(model);

// Fetch the test cases.
const testCases = loadTestCases(path.join(__dirname, "cases"));
const testCases = await loadTestCases(path.join(__dirname, "cases"));

// Load the code snippets for the test cases. Generate them if they don't exist or are outdated.
const testCasesWithSnippets = await loadOrGenerateCodeSnippets(
Expand Down
18 changes: 12 additions & 6 deletions src/test/load/loadTestCases.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readFileSync, readdirSync } from "fs";
import { readFile, readdir } from "fs/promises";
import path from "path";
import { TestCase } from "../types";
import { logger } from "../../common/utils/logger";
Expand All @@ -8,9 +8,9 @@ import { logger } from "../../common/utils/logger";
* @param testCasePath The path to the JSON test case file.
* @returns The test case.
*/
const loadTestCase = (testCasePath: string): TestCase => {
const loadTestCase = async (testCasePath: string): Promise<TestCase> => {
try {
const fileData = readFileSync(testCasePath, "utf8");
const fileData = await readFile(testCasePath, "utf8");
return JSON.parse(fileData) as TestCase;
} catch (error) {
logger.error(`Error loading test case: ${testCasePath}`);
Expand All @@ -23,13 +23,19 @@ const loadTestCase = (testCasePath: string): TestCase => {
* @param testCasesDir The directory containing the test cases.
* @returns The test cases.
*/
export const loadTestCases = (testCasesDir: string): TestCase[] => {
export const loadTestCases = async (
testCasesDir: string
): Promise<TestCase[]> => {
try {
const testFiles = readdirSync(testCasesDir).filter((file) =>
const testFiles = (await readdir(testCasesDir)).filter((file) =>
file.endsWith(".json")
);

return testFiles.map((file) => loadTestCase(path.join(testCasesDir, file)));
return Promise.all(
testFiles.map(
async (file) => await loadTestCase(path.join(testCasesDir, file))
)
);
} catch (error) {
logger.error(`Error loading test cases from: ${testCasesDir}`);
throw error;
Expand Down

0 comments on commit cc95720

Please sign in to comment.