go-devops/cmd/dev/cmd_api_testgen_test.go
Snider 907c5fa64c fix(devops): address CodeRabbit findings on PR #2
15+ findings dispositioned. AX-6-conformant — no testify reintroduced.

Code fixes:
- cmd/dev/service.go: no-op now returns OK:true, unchecked prompt type assertion guarded
- cmd/workspace/config.go: relative parent traversal blocked + regression test, fmt.Errorf wrapping
- cmd/dev/cmd_issues.go + cmd_reviews.go: import ordering
- tests/cli/devops/main.go: raw WalkDir errors wrapped
- tests/cli/devops/Taskfile.yaml: strict shell flags
- cmd/vanity-import/Dockerfile + docs/development.md: Go 1.26 alignment
- locales/embed.go: missing dappco.re/go/i18n checksum

Test infra:
- New local test helpers in cmd/dev, cmd/setup, devkit, snapshot
- All testify usages already absent — local stdlib helpers preferred
  per AX-6 ban
- Test naming aligned (Test{Filename}_{Function}_{Good,Bad,Ugly} per AX-10)

Disposition replies (RESOLVED-COMMENT, no testify added):
- cmd/dev/cmd_apply_test.go, cmd/setup/cmd_ci_test.go, snapshot_test.go,
  devkit/coverage_test.go: CodeRabbit testify suggestions get reasoning
  reply per AX-6 ban; local helpers are convention.
- SonarCloud/GHAS: no PR checks/annotations found; code-scanning API
  returned no analysis, secret scanning disabled.

Verification: gofmt clean, git diff --check clean, no testify imports.
Targeted go vet + go test pass for cmd/workspace + devkit + snapshot.
Full go vet ./... blocked by pre-existing dappco.re/go/scm
codeberg.org/forgejo/go-sdk auth/replacement issue (out of scope).

Closes findings on https://github.com/dAppCore/go-devops/pull/2

Co-authored-by: Codex <noreply@openai.com>
2026-04-27 15:07:24 +01:00

114 lines
2.8 KiB
Go

package dev
import (
"os"
"path/filepath"
"strings"
"testing"
"dappco.re/go/io"
)
func TestRunTestGen_Good(t *testing.T) {
tmpDir := t.TempDir()
originalWD, err := os.Getwd()
mustNoError(t, err)
t.Cleanup(func() {
_ = os.Chdir(originalWD)
})
mustNoError(t, os.Chdir(tmpDir))
serviceDir := filepath.Join(tmpDir, "pkg", "demo")
mustNoError(t, io.Local.EnsureDir(serviceDir))
mustNoError(t, io.Local.Write(filepath.Join(serviceDir, "demo.go"), `package demo
type Example struct{}
const Answer = 42
var Value = Example{}
func Run() {}
`))
mustNoError(t, io.Local.Write(filepath.Join(serviceDir, "extra.go"), `package demo
type Another struct{}
func Extra() {}
`))
mustNoError(t, io.Local.Write(filepath.Join(serviceDir, "demo_test.go"), `package demo
func Ignored() {}
`))
mustNoError(t, runTestGen())
generatedPath := filepath.Join(tmpDir, "demo", "demo_test.go")
content, err := io.Local.Read(generatedPath)
mustNoError(t, err)
mustContains(t, content, `// Code generated by "core dev api test-gen"; DO NOT EDIT.`)
mustContains(t, content, `package demo`)
mustContains(t, content, `impl "dappco.re/go/cli/demo"`)
mustContains(t, content, `type _ = impl.Example`)
mustContains(t, content, `type _ = impl.Another`)
mustContains(t, content, `const _ = impl.Answer`)
mustContains(t, content, `var _ = impl.Value`)
mustContains(t, content, `var _ = impl.Run`)
mustContains(t, content, `var _ = impl.Extra`)
mustNotContains(t, content, `Ignored`)
}
func TestGeneratePublicAPITestFile_Good(t *testing.T) {
tmpDir := t.TempDir()
mustNoError(t, generatePublicAPITestFile(
filepath.Join(tmpDir, "demo"),
filepath.Join(tmpDir, "demo", "demo_test.go"),
"demo",
[]symbolInfo{
{Name: "Example", Kind: "type"},
{Name: "Answer", Kind: "const"},
},
))
content, err := io.Local.Read(filepath.Join(tmpDir, "demo", "demo_test.go"))
mustNoError(t, err)
mustTrue(t, strings.Contains(content, `type _ = impl.Example`))
mustTrue(t, strings.Contains(content, `const _ = impl.Answer`))
}
func TestGetExportedSymbols_MultiFile_Good(t *testing.T) {
tmpDir := t.TempDir()
serviceDir := filepath.Join(tmpDir, "demo")
mustNoError(t, io.Local.EnsureDir(serviceDir))
mustNoError(t, io.Local.Write(filepath.Join(serviceDir, "demo.go"), `package demo
type Example struct{}
const Answer = 42
`))
mustNoError(t, io.Local.Write(filepath.Join(serviceDir, "extra.go"), `package demo
var Value = Example{}
func Run() {}
`))
mustNoError(t, io.Local.Write(filepath.Join(serviceDir, "demo_test.go"), `package demo
type Ignored struct{}
`))
symbols, err := getExportedSymbols(serviceDir)
mustNoError(t, err)
want := []symbolInfo{
{Name: "Answer", Kind: "const"},
{Name: "Example", Kind: "type"},
{Name: "Run", Kind: "func"},
{Name: "Value", Kind: "var"},
}
mustDeepEqual(t, want, symbols)
}