-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into spec-file-support
- Loading branch information
Showing
17 changed files
with
410 additions
and
119 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,9 @@ | ||
export function addNumbers(a: any, b: any): number { | ||
// Validate that both inputs are numbers | ||
if (typeof a !== 'number' || typeof b !== 'number') { | ||
throw new Error('Both arguments must be numbers'); | ||
} | ||
|
||
// Return the sum of the two numbers | ||
return a + b; | ||
} |
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,21 @@ | ||
import * as fs from 'fs/promises'; | ||
import * as path from 'path'; | ||
import { fileExists } from './file-exists'; | ||
|
||
/** | ||
* Find package.json file in the given directory or any | ||
* parent directory. | ||
*/ | ||
export async function findPackageJson( | ||
directory = process.cwd() | ||
): Promise<string | null> { | ||
let currentDirectory = directory; | ||
while (currentDirectory !== '/') { | ||
const packageJsonPath = path.join(currentDirectory, 'package.json'); | ||
if (await fileExists(packageJsonPath)) { | ||
return fs.readFile(packageJsonPath, 'utf-8'); | ||
} | ||
currentDirectory = path.dirname(currentDirectory); | ||
} | ||
return null; | ||
} |
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,48 @@ | ||
import dedent from 'dedent'; | ||
import { findPackageJson } from './find-package-json'; | ||
import { getSimpleCompletion } from './llm'; | ||
import { removeBackticks } from './remove-backticks'; | ||
|
||
export async function getTestCommand({ | ||
testFilePath, | ||
}: { | ||
testFilePath: string; | ||
}) { | ||
const defaultTestCommand = `npm test -- ${ | ||
testFilePath.split('/').pop()!.split('.')[0] | ||
}`; | ||
|
||
const packageJson = await findPackageJson(); | ||
if (!packageJson) { | ||
return defaultTestCommand; | ||
} | ||
|
||
const suggestion = removeBackticks( | ||
await getSimpleCompletion({ | ||
messages: [ | ||
{ | ||
role: 'system', | ||
content: | ||
'You take a prompt and return a single line shell command and nothing else', | ||
}, | ||
{ | ||
role: 'user', | ||
content: dedent` | ||
Here is my package.json. I want to run a single command to run the tests (e.g. "npm run test"). The tests should not run in watch mode, they should | ||
exit once completed. Bonus points if the command only runs this specific test \`${testFilePath}\` such as \`npm test -- ${ | ||
testFilePath.split('/').pop()!.split('.')[0] | ||
}\`. | ||
<package-json> | ||
${packageJson} | ||
</package-json> | ||
If there are no testing libraryes in the package.json, \`npx vitest ...\` is a good option. | ||
`, | ||
}, | ||
], | ||
}) | ||
); | ||
|
||
return suggestion || defaultTestCommand; | ||
} |
Oops, something went wrong.