Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions cmd/wippy/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/wippyai/runtime/cmd/internal/shutdown"
embedpkg "github.com/wippyai/runtime/service/fs/embed"
supervisorpkg "github.com/wippyai/runtime/system/supervisor"
lua "github.com/wippyai/go-lua"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
Expand Down Expand Up @@ -289,6 +290,9 @@ func runWithUseCase(cmd *cobra.Command, args []string, useCase string) error {
waitForShutdownSignal(sigChan, logger, nil)

exitCode := shutdown.Perform(ctx, loader, logger, silentLogs)
if lua.CoverageEnabled() {
dumpCoverage()
}
Comment on lines 292 to +295
if exitCode != 0 {
_ = logger.Sync()
os.Exit(exitCode)
Expand All @@ -297,6 +301,33 @@ func runWithUseCase(cmd *cobra.Command, args []string, useCase string) error {
return nil
}

// dumpCoverage writes an LCOV tracefile when WIPPY_COVERAGE is set. It runs both
// on a clean exit (return nil) and before os.Exit on a failing run, so coverage
// is captured even when tests fail. Configured via env:
//
// WIPPY_COVERAGE_FILE output path (default: coverage.info)
// WIPPY_COVERAGE_FILTER substring the source name must contain (default: all)
func dumpCoverage() {
prefix := os.Getenv("WIPPY_COVERAGE_FILTER")
filter := func(src string) bool {
return prefix == "" || strings.Contains(src, prefix)
}
path := os.Getenv("WIPPY_COVERAGE_FILE")
if path == "" {
path = "coverage.info"
}
if err := lua.WriteCoverageLCOV(path, filter); err != nil {
fmt.Fprintf(os.Stderr, "coverage: write failed: %v\n", err)
return
}
lf, lh := lua.CoverageSummary(filter)
pct := 0.0
if lf > 0 {
pct = float64(lh) / float64(lf) * 100
}
fmt.Fprintf(os.Stderr, "coverage: %d/%d lines (%.1f%%) filter=%q -> %s\n", lh, lf, pct, prefix, path)
}

// loadRuntimeConfig resolves the effective runtime configuration for run-like
// commands by merging:
// 1) config file/defaults,
Expand Down