Skip to content

Commit

Permalink
Improve test handling, file ops, and enhance prompts, update version
Browse files Browse the repository at this point in the history
Update test handling, modify file operations, enhance prompts

summary of diff --git  a/v3/aidda/aidda.go b/v3/aidda/aidda.go

- Include test results in the .aidda/test file instead of the prompt file
- Add a new variable `testFn` to store the test file directory and name
- Ensure creation of an ignore file if it does not exist
- Implement logic to either include test results in the prompt or clear the test file based on modification times of the test file and input files
- Modify `runTest` function to write test results directly to the test file instead of appending to the prompt file
- Adjust `getChanges` function to accept `testResults` as an argument for inclusion in the prompt
- Include test results in the prompt if applicable, enhancing the information given to the user

Update version in grokker.go from 3.0.17 to 3.0.18

summary of diff --git  a/v3/core/grokker.go b/v3/core/grokker.go

- Update version from 3.0.17 to 3.0.18 in grokker.go
  • Loading branch information
stevegt committed Jul 16, 2024
1 parent d7d4a68 commit 505775f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
52 changes: 44 additions & 8 deletions v3/aidda/aidda.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
- run 'git difftool' with vscode as in https://www.roboleary.net/vscode/2020/09/15/vscode-git.html
- open diff tool in editor so user can selectively choose and edit changes
- run go test -v
- include test results in the prompt file
- include test results in the .aidda/test file
*/

func Do(g *core.Grokker, args ...string) (err error) {
Expand All @@ -51,6 +51,7 @@ func Do(g *core.Grokker, args ...string) (err error) {
// generate filenames
promptFn := Spf("%s/prompt", dir)
ignoreFn := Spf("%s/ignore", dir)
testFn := Spf("%s/test", dir)

// ensure there is an ignore file
err = ensureIgnoreFile(ignoreFn)
Expand All @@ -60,6 +61,38 @@ func Do(g *core.Grokker, args ...string) (err error) {
_, err = NewPrompt(promptFn)
Ck(err)

// if the test file is newer than any input files, then include
// the test results in the prompt, otherwise clear the test file
testResults := ""
testStat, err := os.Stat(testFn)
if os.IsNotExist(err) {
err = nil
} else {
Ck(err)
// get the list of input files
p, err := getPrompt(promptFn)
Ck(err)
inFns := p.In
// check if the test file is newer than any input files
for _, fn := range inFns {
inStat, err := os.Stat(fn)
Ck(err)
if testStat.ModTime().After(inStat.ModTime()) {
// include the test results in the prompt
buf, err := ioutil.ReadFile(testFn)
Ck(err)
testResults = string(buf)
break
}
}
}
if len(testResults) == 0 {
// clear the test file
Pl("Clearing test file")
err = ioutil.WriteFile(testFn, []byte{}, 0644)
Ck(err)
}

for i := 0; i < len(args); i++ {
cmd := args[i]
Pl("aidda: running subcommand", cmd)
Expand All @@ -74,13 +107,13 @@ func Do(g *core.Grokker, args ...string) (err error) {
p, err := getPrompt(promptFn)
Ck(err)
// spew.Dump(p)
err = getChanges(g, p)
err = getChanges(g, p, testResults)
Ck(err)
case "diff":
err = runDiff()
Ck(err)
case "test":
err = runTest(promptFn)
err = runTest(testFn)
Ck(err)
default:
PrintUsageAndExit()
Expand Down Expand Up @@ -224,15 +257,15 @@ func ask(question, deflt string, others ...string) (response string, err error)
}
}

func runTest(promptFn string) (err error) {
func runTest(fn string) (err error) {
defer Return(&err)
Pf("Running tests\n")

// run go test -v
stdout, stderr, _, _ := RunTee("go test -v")

// append test results to the prompt file
fh, err := os.OpenFile(promptFn, os.O_APPEND|os.O_WRONLY, 0644)
// write test results to the file
fh, err := os.Create(fn)
Ck(err)
_, err = fh.WriteString(Spf("\n\nstdout:\n%s\n\nstderr:%s\n\n", stdout, stderr))
Ck(err)
Expand All @@ -252,10 +285,13 @@ func runDiff() (err error) {
return err
}

func getChanges(g *core.Grokker, p *Prompt) (err error) {
func getChanges(g *core.Grokker, p *Prompt, testResults string) (err error) {
defer Return(&err)

prompt := p.Txt
if len(testResults) > 0 {
Pl("Including test results in prompt")
}
prompt := Spf("%s\n\n%s", p.Txt, testResults)
inFns := p.In
outFns := p.Out
var outFls []core.FileLang
Expand Down
2 changes: 1 addition & 1 deletion v3/core/grokker.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (
const (
// See the "Semantic Versioning" section of the README for
// information on API and db stability and versioning.
Version = "3.0.17"
Version = "3.0.18"
)

type Grokker struct {
Expand Down

0 comments on commit 505775f

Please sign in to comment.