feat(02-02): record manifest route cases and report coverage
Drive ordered route cases through RecordFlow, resume in batches of 15, and print recorded/passing/failing/unrecorded coverage. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"git.golem15.com/golem15/summercms/bonfire"
|
||||
@@ -35,6 +36,13 @@ func parityRecordCommand() bonfire.Command {
|
||||
{Name: "output", Description: "Destination fixture path"},
|
||||
{Name: "rules", Description: "Committed YAML capture rules"},
|
||||
{Name: "vars", Description: "Private mode-0600 variable store outside fixtures"},
|
||||
{Name: "manifest", Description: "Route manifest path"},
|
||||
{Name: "fixtures", Description: "Fixture directory for manifest recording"},
|
||||
{Name: "update", Description: "Overwrite existing fixtures (true/false)"},
|
||||
{Name: "next-batch", Description: "Max unrecorded routes to record (max 15)"},
|
||||
{Name: "resume", Description: "Skip valid existing fixtures (true/false)"},
|
||||
{Name: "allow-incomplete", Description: "Permit unfinished cases (true/false)"},
|
||||
{Name: "require-recorded", Description: "Require a fixture for every case (true/false)"},
|
||||
},
|
||||
Run: runParityRecord,
|
||||
}
|
||||
@@ -45,9 +53,12 @@ func parityReplayCommand() bonfire.Command {
|
||||
Name: "parity:replay",
|
||||
Description: "Replay recorded fixtures against an HTTP backend",
|
||||
Flags: []bonfire.Flag{
|
||||
{Name: "fixtures", Description: "Recorded YAML fixture path"},
|
||||
{Name: "fixtures", Description: "Recorded YAML fixture path or directory"},
|
||||
{Name: "target", Description: "Base URL of the HTTP backend"},
|
||||
{Name: "vars", Description: "Private mode-0600 variable store"},
|
||||
{Name: "manifest", Description: "Route manifest path"},
|
||||
{Name: "self-check", Description: "Fail on any recorded mismatch (true/false)"},
|
||||
{Name: "require-recorded", Description: "Fail unrecorded required cases (true/false)"},
|
||||
},
|
||||
Run: runParityReplay,
|
||||
}
|
||||
@@ -86,6 +97,9 @@ func runParityProxy(ctx context.Context, in bonfire.Input, out bonfire.Output) e
|
||||
}
|
||||
|
||||
func runParityRecord(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
|
||||
if man, ok := in.Flag("manifest"); ok && strings.TrimSpace(man) != "" {
|
||||
return runParityRecordManifest(ctx, in, out, strings.TrimSpace(man))
|
||||
}
|
||||
specPath, err := requireFlag(in, "spec", "parity:record")
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -103,19 +117,8 @@ func runParityRecord(ctx context.Context, in bonfire.Input, out bonfire.Output)
|
||||
return err
|
||||
}
|
||||
cfg := tide.RecordConfig{Target: target}
|
||||
if rulesPath, ok := in.Flag("rules"); ok && strings.TrimSpace(rulesPath) != "" {
|
||||
rules, err := tide.LoadRules(rulesPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg.Rules = rules
|
||||
}
|
||||
if varsPath, ok := in.Flag("vars"); ok && strings.TrimSpace(varsPath) != "" {
|
||||
store, err := tide.OpenStore(varsPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg.Store = store
|
||||
if err := attachRulesAndVars(in, &cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
flow, err := tide.RecordFlow(ctx, spec, cfg)
|
||||
if err != nil {
|
||||
@@ -128,20 +131,71 @@ func runParityRecord(ctx context.Context, in bonfire.Input, out bonfire.Output)
|
||||
return nil
|
||||
}
|
||||
|
||||
func runParityReplay(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
|
||||
path, err := requireFlag(in, "fixtures", "parity:replay")
|
||||
func runParityRecordManifest(ctx context.Context, in bonfire.Input, out bonfire.Output, manPath string) error {
|
||||
target, err := requireFlag(in, "target", "parity:record")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fixtures, err := requireFlag(in, "fixtures", "parity:record")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m, err := tide.LoadManifest(manPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mode := tide.ModeAllowIncomplete
|
||||
if flagBool(in, "require-recorded") {
|
||||
mode = tide.ModeRequireRecorded
|
||||
}
|
||||
if err := tide.ValidateManifest(m, fixtures, mode); err != nil && mode == tide.ModeRequireRecorded {
|
||||
return err
|
||||
}
|
||||
if err := tide.ValidateManifest(m, fixtures, tide.ModeAllowIncomplete); err != nil {
|
||||
return err
|
||||
}
|
||||
batch, err := tide.ParseNextBatch(flagValue(in, "next-batch"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg := tide.ManifestConfig{
|
||||
Target: target,
|
||||
Fixtures: fixtures,
|
||||
Update: flagBool(in, "update"),
|
||||
Resume: flagBool(in, "resume"),
|
||||
NextBatch: batch,
|
||||
Mode: mode,
|
||||
}
|
||||
if err := attachManifestStore(in, &cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
cov, err := tide.RecordManifest(ctx, m, cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
out.Table(tide.CoverageHeaders(), cov.CoverageRows())
|
||||
out.Success(cov.SummaryLine())
|
||||
out.Info(cov.ResumeLine())
|
||||
return nil
|
||||
}
|
||||
|
||||
func runParityReplay(ctx context.Context, in bonfire.Input, out bonfire.Output) error {
|
||||
target, err := requireFlag(in, "target", "parity:replay")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if man, ok := in.Flag("manifest"); ok && strings.TrimSpace(man) != "" {
|
||||
return runParityReplayManifest(ctx, in, out, strings.TrimSpace(man), target)
|
||||
}
|
||||
path, err := requireFlag(in, "fixtures", "parity:replay")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
flow, err := tide.LoadFlow(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg := tide.ReplayConfig{Target: target}
|
||||
cfg := tide.ReplayConfig{Target: target, BaseDir: filepath.Dir(path)}
|
||||
if varsPath, ok := in.Flag("vars"); ok && strings.TrimSpace(varsPath) != "" {
|
||||
store, err := tide.OpenStore(varsPath)
|
||||
if err != nil {
|
||||
@@ -159,6 +213,90 @@ func runParityReplay(ctx context.Context, in bonfire.Input, out bonfire.Output)
|
||||
return nil
|
||||
}
|
||||
|
||||
func runParityReplayManifest(ctx context.Context, in bonfire.Input, out bonfire.Output, manPath, target string) error {
|
||||
fixtures, err := requireFlag(in, "fixtures", "parity:replay")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m, err := tide.LoadManifest(manPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg := tide.ManifestConfig{
|
||||
Target: target,
|
||||
Fixtures: fixtures,
|
||||
SelfCheck: flagBool(in, "self-check"),
|
||||
Mode: tide.ModeAllowIncomplete,
|
||||
}
|
||||
if flagBool(in, "require-recorded") {
|
||||
cfg.Mode = tide.ModeRequireRecorded
|
||||
}
|
||||
if err := attachManifestStore(in, &cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
cov, err := tide.ReplayManifest(ctx, m, cfg)
|
||||
for _, d := range cov.Diffs {
|
||||
out.Error(d)
|
||||
}
|
||||
out.Table(tide.CoverageHeaders(), cov.CoverageRows())
|
||||
out.Info(cov.SummaryLine())
|
||||
return err
|
||||
}
|
||||
|
||||
func attachRulesAndVars(in bonfire.Input, cfg *tide.RecordConfig) error {
|
||||
if rulesPath, ok := in.Flag("rules"); ok && strings.TrimSpace(rulesPath) != "" {
|
||||
rules, err := tide.LoadRules(rulesPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg.Rules = rules
|
||||
}
|
||||
if varsPath, ok := in.Flag("vars"); ok && strings.TrimSpace(varsPath) != "" {
|
||||
store, err := tide.OpenStore(varsPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg.Store = store
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func attachManifestStore(in bonfire.Input, cfg *tide.ManifestConfig) error {
|
||||
if rulesPath, ok := in.Flag("rules"); ok && strings.TrimSpace(rulesPath) != "" {
|
||||
rules, err := tide.LoadRules(rulesPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg.Rules = rules
|
||||
}
|
||||
if varsPath, ok := in.Flag("vars"); ok && strings.TrimSpace(varsPath) != "" {
|
||||
store, err := tide.OpenStore(varsPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cfg.Store = store
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func flagBool(in bonfire.Input, name string) bool {
|
||||
v, ok := in.Flag(name)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
switch strings.ToLower(strings.TrimSpace(v)) {
|
||||
case "", "true", "1", "yes":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func flagValue(in bonfire.Input, name string) string {
|
||||
v, _ := in.Flag(name)
|
||||
return strings.TrimSpace(v)
|
||||
}
|
||||
|
||||
func requireFlag(in bonfire.Input, name, cmd string) (string, error) {
|
||||
v, ok := in.Flag(name)
|
||||
v = strings.TrimSpace(v)
|
||||
|
||||
Reference in New Issue
Block a user