-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from slackhq/sg-add-more-workflow
Sg add more workflow
- Loading branch information
Showing
5 changed files
with
262 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { converWithAST } from './support/ast-transformations/run-ast-transformations'; | ||
import { getReactCompDom } from './support/enzyme-helper/get-dom-enzyme'; | ||
import { generatePrompt } from './support/prompt-generation/generate-prompt'; | ||
import { extractCodeContentToFile } from './support/code-extractor/extract-code'; | ||
import { runTestAndAnalyze } from './support/enzyme-helper/run-test-analysis'; | ||
import { | ||
setJestBinaryPath, | ||
setOutputResultsPath, | ||
configureLogLevel, | ||
} from './support/config'; | ||
|
||
// Define the function type for LLM call | ||
export type LLMCallFunction = (prompt: string) => Promise<string>; | ||
|
||
export const convertTestFiles = async ({ | ||
filePaths, | ||
logLevel, | ||
jestBinaryPath, | ||
outputResultsPath, | ||
testId, | ||
llmCallFunction, | ||
extendPrompt, | ||
}: { | ||
filePaths: string[]; | ||
logLevel?: string; | ||
jestBinaryPath: string; | ||
outputResultsPath: string; | ||
testId: string; | ||
llmCallFunction: LLMCallFunction; | ||
extendPrompt?: string[]; | ||
}): Promise<void> => { | ||
// Set log level | ||
if (logLevel) { | ||
configureLogLevel(logLevel); | ||
} | ||
|
||
// Set host project jest bin path | ||
setJestBinaryPath(jestBinaryPath); | ||
|
||
// Set host project results output path | ||
setOutputResultsPath(outputResultsPath); | ||
|
||
for (const filePath of filePaths) { | ||
// Get AST conversion | ||
const astConvertedCode = converWithAST(filePath, testId); | ||
|
||
// Get React Component DOM tree for each test case | ||
const reactCompDom = await getReactCompDom(filePath); | ||
|
||
// Generate the prompt | ||
const prompt = generatePrompt( | ||
filePath, | ||
'data-test', | ||
astConvertedCode, | ||
reactCompDom, | ||
extendPrompt, | ||
); | ||
|
||
// Call the API with a custom LLM method | ||
const LLMResponse = await llmCallFunction(prompt); | ||
|
||
// Extract generated code | ||
const convertedFilePath = extractCodeContentToFile(LLMResponse); | ||
|
||
// Run the file and analyze the failures | ||
await runTestAndAnalyze(convertedFilePath); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.