-
Notifications
You must be signed in to change notification settings - Fork 132
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
Refactor: Remove file validation and add sample scripts #778
Changes from 2 commits
738dfda
2aa65ba
b98083f
6f3f351
c05ef93
3f331e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -282,18 +282,23 @@ | |
*/ | ||
export async function writeFileEdits( | ||
fileEdits: Record<string, FileUpdate>, // Contains the edits to be applied to files | ||
options?: TraceOptions | ||
options?: { applyEdits?: boolean } & TraceOptions | ||
) { | ||
const { trace } = options || {} | ||
const { applyEdits, trace } = options || {} | ||
// Iterate over each file edit entry | ||
for (const fileEdit of Object.entries(fileEdits || {})) { | ||
// Destructure the filename, before content, after content, and validation from the entry | ||
const [fn, { before, after, validation }] = fileEdit | ||
|
||
if (!applyEdits && !validation?.valid) { | ||
Check failure on line 293 in packages/core/src/fileedits.ts GitHub Actions / build
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The condition
|
||
// path not validated | ||
continue | ||
} | ||
|
||
// Skip writing if the edit is invalid and applyEdits is false | ||
if (validation?.valid === false) { | ||
if (validation?.error) { | ||
trace.detailsFenced( | ||
`skipping ${fn}, invalid`, | ||
`skipping ${fn}, invalid schema`, | ||
validation.error, | ||
"text" | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
genaiscript.d.ts -diff merge=ours linguist-generated |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# auto-generated | ||
genaiscript.d.ts | ||
tsconfig.json | ||
jsconfig.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { editTest } from "./fileedittest.mts" | ||
script({ | ||
model: "large", | ||
title: "system.diff test", | ||
files: "src/edits/fib.ts", | ||
system: ["system", "system.changelog"], | ||
}) | ||
|
||
editTest() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { editTest } from "./fileedittest.mts" | ||
script({ | ||
model: "large", | ||
title: "system.diff test", | ||
files: "src/edits/fib.ts", | ||
system: ["system", "system.diff"], | ||
}) | ||
|
||
editTest() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
script({ | ||
model: "large", | ||
title: "system.files test", | ||
files: "src/edits/fib.*", | ||
system: ["system", "system.files"], | ||
tests: [ | ||
{ | ||
files: "src/edits/fib.ts", | ||
}, | ||
{ | ||
files: "src/edits/fib.cpp", | ||
}, | ||
{ | ||
files: "src/edits/fib.cs", | ||
}, | ||
{ | ||
files: "src/edits/fib.go", | ||
}, | ||
{ | ||
files: "src/edits/fib.java", | ||
}, | ||
{ | ||
files: "src/edits/fib.js", | ||
}, | ||
{ | ||
files: "src/edits/fib.kt", | ||
}, | ||
{ | ||
files: "src/edits/fib.py", | ||
}, | ||
{ | ||
files: "src/edits/fib.swift", | ||
}, | ||
], | ||
}) | ||
import { editTest } from "./fileedittest.mts" | ||
editTest() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
script({ | ||
files: "src/edits/fib.ts", | ||
}) | ||
$`Generation 1 variations of the SNIPPET in various programming languages and save them in files. | ||
|
||
- there should be lines with comments | ||
- there should be a function with a TODO comment and a BODY comment | ||
` | ||
def("FILE", env.files) | ||
defFileOutput("src/edits/*") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include <iostream> | ||
|
||
int fibonacci(int n) { | ||
// TODO: implement fibonacci algorithm | ||
return 0; // BODY | ||
} // this one needs to go | ||
// another comment |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
public class Fibonacci { | ||
public static int fibonacci(int n) { | ||
// TODO: implement fibonacci algorithm | ||
return 0; // BODY | ||
} // this one needs to go | ||
// another comment | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
func fibonacci(n int) int { | ||
// TODO: implement fibonacci algorithm | ||
return 0 // BODY | ||
} // this one needs to go | ||
// another comment |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
public class Fibonacci { | ||
public static int fibonacci(int n) { | ||
// TODO: implement fibonacci algorithm | ||
return 0; // BODY | ||
} // this one needs to go | ||
// another comment | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function fibonacci(n) { | ||
// TODO: implement fibonacci algorithm | ||
return 0; // BODY | ||
} // this one needs to go | ||
// another comment |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
fun fibonacci(n: Int): Int { | ||
// TODO: implement fibonacci algorithm | ||
return 0 // BODY | ||
} // this one needs to go | ||
// another comment |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
function fibonacci($n) { | ||
// TODO: implement fibonacci algorithm | ||
return 0; // BODY | ||
} // this one needs to go | ||
// another comment | ||
?> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def fibonacci(n): | ||
# TODO: implement fibonacci algorithm | ||
return 0 # BODY | ||
# this one needs to go | ||
# another comment |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def fibonacci(n) | ||
# TODO: implement fibonacci algorithm | ||
return 0 # BODY | ||
end # this one needs to go | ||
# another comment |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
func fibonacci(_ n: Int) -> Int { | ||
// TODO: implement fibonacci algorithm | ||
return 0 // BODY | ||
} // this one needs to go | ||
// another comment |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function fibonacci(n: number): number { | ||
// TODO: implement fibonacci algorithm | ||
return 0 // BODY | ||
} // this one needs to go | ||
// another comment | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export function editTest() { | ||
def("FILE", env.files) | ||
|
||
$`- Implement the functions with TODO. | ||
- Remove all comments. | ||
` | ||
|
||
defOutputProcessor((output) => { | ||
const { fileEdits } = output | ||
//console.log(YAML.stringify(fileEdits)) | ||
const res = fileEdits[Object.keys(fileEdits)[0]].after | ||
if (/^\s*\/\/.*$/.test(res)) | ||
throw new Error("some comments were not removed") | ||
if (res.includes("// BODY")) | ||
throw new Error("the // BODY comment was not removed") | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
result.fileEdits
andapplyEdits
are not checked before callingwriteFileEdits
. This could lead to unexpected behavior ifresult.fileEdits
is undefined orapplyEdits
is false.