From 6ad57a61838989022123ae5858f05539f2c3463e Mon Sep 17 00:00:00 2001 From: "qwen.ai[bot]" Date: Sat, 28 Nov 2026 10:54:45 +0000 Subject: [PATCH 1/3] task snapshot c64f3898-a47f-4644-9934-922eb8586144 --- internal/contract/types.go | 12 ++- internal/contract/validator.go | 24 +++++- internal/contract/validator_test.go | 54 ++++++++++++ internal/engines/postgres/checks.go | 57 ++++++++++++- .../engines/postgres/checks_extra_test.go | 85 +++++++++++++++++++ internal/report/report.go | 17 ++-- internal/report/template.html | 2 + internal/workflow/run.go | 55 +++++++----- 8 files changed, 268 insertions(+), 38 deletions(-) create mode 100644 internal/engines/postgres/checks_extra_test.go diff --git a/internal/contract/types.go b/internal/contract/types.go index 06be205..ae4ce59 100644 --- a/internal/contract/types.go +++ b/internal/contract/types.go @@ -48,13 +48,19 @@ type Check struct { Type string `yaml:"type"` Query string `yaml:"query"` Expect CheckExpect `yaml:"expect"` + // OnFail controls what happens when this check fails: "fail" + // (default) marks the drill FAIL, "warn" downgrades it to a + // WARNING only. Useful for advisory checks like row-count + // sanity bounds that should not block a recovery verification. + OnFail string `yaml:"on_fail,omitempty"` } // CheckExpect describes the expected outcome of a check. type CheckExpect struct { - Value any `yaml:"value,omitempty"` - Type string `yaml:"type,omitempty"` - GreaterThan *int `yaml:"greater_than,omitempty"` + Value any `yaml:"value,omitempty"` + GreaterThan *int `yaml:"greater_than,omitempty"` + LessThan *int `yaml:"less_than,omitempty"` + MinLength *int `yaml:"min_length,omitempty"` } // Isolation describes network and sandbox isolation requirements. diff --git a/internal/contract/validator.go b/internal/contract/validator.go index 663783d..df09b83 100644 --- a/internal/contract/validator.go +++ b/internal/contract/validator.go @@ -125,11 +125,27 @@ func validateCheck(c Check) error { if strings.TrimSpace(c.Query) == "" { return errors.New("check query is required") } - if c.Expect.Value == nil && c.Expect.GreaterThan == nil { - return errors.New("check expect must define either value or greater_than") + expectFields := 0 + for _, set := range []bool{ + c.Expect.Value != nil, + c.Expect.GreaterThan != nil, + c.Expect.LessThan != nil, + c.Expect.MinLength != nil, + } { + if set { + expectFields++ + } + } + if expectFields == 0 { + return errors.New("check expect must define at least one of: value, greater_than, less_than, min_length") + } + if expectFields > 1 { + return errors.New("check expect fields are mutually exclusive (define only one)") } - if c.Expect.Value != nil && c.Expect.GreaterThan != nil { - return errors.New("check expect cannot define both value and greater_than") + switch c.OnFail { + case "", "fail", "warn": + default: + return fmt.Errorf("check on_fail must be \"fail\" or \"warn\", got %q", c.OnFail) } return nil } diff --git a/internal/contract/validator_test.go b/internal/contract/validator_test.go index 3a6b29c..3e625dd 100644 --- a/internal/contract/validator_test.go +++ b/internal/contract/validator_test.go @@ -149,3 +149,57 @@ func TestValidate_CleanupAlwaysFalse(t *testing.T) { t.Fatal("expected error for cleanup.always=false") } } + +func TestValidate_CheckWithLessThan(t *testing.T) { +c := validContract() +c.Test.Checks[0].Expect.Value = nil +lt := 100 +c.Test.Checks[0].Expect.LessThan = < +if err := c.Validate(); err != nil { +t.Fatalf("unexpected error: %v", err) +} +} + +func TestValidate_CheckWithMinLength(t *testing.T) { +c := validContract() +c.Test.Checks[0].Expect.Value = nil +ml := 10 +c.Test.Checks[0].Expect.MinLength = &ml +if err := c.Validate(); err != nil { +t.Fatalf("unexpected error: %v", err) +} +} + +func TestValidate_CheckNoExpectation(t *testing.T) { +c := validContract() +c.Test.Checks[0].Expect = CheckExpect{} +if err := c.Validate(); err == nil { +t.Fatal("expected error for check with no expectation") +} +} + +func TestValidate_CheckThreeExpects(t *testing.T) { +c := validContract() +n := 5 +c.Test.Checks[0].Expect.GreaterThan = &n +c.Test.Checks[0].Expect.LessThan = &n +if err := c.Validate(); err == nil { +t.Fatal("expected error for check with multiple expectations") +} +} + +func TestValidate_CheckOnFailWarn(t *testing.T) { +c := validContract() +c.Test.Checks[0].OnFail = "warn" +if err := c.Validate(); err != nil { +t.Fatalf("unexpected error: %v", err) +} +} + +func TestValidate_CheckOnFailInvalid(t *testing.T) { +c := validContract() +c.Test.Checks[0].OnFail = "ignore" +if err := c.Validate(); err == nil { +t.Fatal("expected error for invalid on_fail value") +} +} diff --git a/internal/engines/postgres/checks.go b/internal/engines/postgres/checks.go index 4ac7162..efffa95 100644 --- a/internal/engines/postgres/checks.go +++ b/internal/engines/postgres/checks.go @@ -59,10 +59,16 @@ func runCheck(ctx context.Context, cli *client.Client, c *sandbox.Container, chk result.Actual = actual if chk.Expect.Value != nil { - return evaluateValue(result, chk.Expect.Value, actual), nil + return applyOnFail(evaluateValue(result, chk.Expect.Value, actual), chk), nil } if chk.Expect.GreaterThan != nil { - return evaluateGreaterThan(result, *chk.Expect.GreaterThan, actual), nil + return applyOnFail(evaluateGreaterThan(result, *chk.Expect.GreaterThan, actual), chk), nil + } + if chk.Expect.LessThan != nil { + return applyOnFail(evaluateLessThan(result, *chk.Expect.LessThan, actual), chk), nil + } + if chk.Expect.MinLength != nil { + return applyOnFail(evaluateMinLength(result, *chk.Expect.MinLength, actual), chk), nil } result.Status = "FAIL" @@ -70,6 +76,16 @@ func runCheck(ctx context.Context, cli *client.Client, c *sandbox.Container, chk return result, nil } +// applyOnFail downgrades a FAIL to WARNING when the contract marks +// the check as advisory (on_fail: warn). The error message is kept +// so the report still shows exactly what mismatched. +func applyOnFail(r engines.CheckResult, chk contract.Check) engines.CheckResult { + if r.Status == "FAIL" && chk.OnFail == "warn" { + r.Status = "WARNING" + } + return r +} + // evaluateValue compares the actual result as a string against the // expected value. func evaluateValue(result engines.CheckResult, expected any, actual string) engines.CheckResult { @@ -102,6 +118,43 @@ func evaluateGreaterThan(result engines.CheckResult, threshold int, actual strin return result } +// evaluateLessThan parses actual as an integer and compares. +func evaluateLessThan(result engines.CheckResult, threshold int, actual string) engines.CheckResult { + result.Expected = fmt.Sprintf("< %d", threshold) + n, err := strconv.Atoi(actual) + if err != nil { + result.Status = "FAIL" + result.Err = fmt.Errorf("expected integer result, got %q", actual) + return result + } + if n < threshold { + result.Status = "PASS" + } else { + result.Status = "FAIL" + result.Err = fmt.Errorf("expected value < %d, got %d", threshold, n) + } + return result +} + +// evaluateMinLength checks that the returned text is at least the +// given number of characters long. Useful for verifying a column +// actually contains non-trivial data (e.g. a JSON payload). +func evaluateMinLength(result engines.CheckResult, minLen int, actual string) engines.CheckResult { + result.Expected = fmt.Sprintf("len >= %d", minLen) + if minLen < 0 { + result.Status = "FAIL" + result.Err = fmt.Errorf("min_length must not be negative, got %d", minLen) + return result + } + if len(actual) >= minLen { + result.Status = "PASS" + } else { + result.Status = "FAIL" + result.Err = fmt.Errorf("expected length >= %d, got %d", minLen, len(actual)) + } + return result +} + // buildPSQLArgs returns the argument vector for psql. // Extracted for unit testing. // diff --git a/internal/engines/postgres/checks_extra_test.go b/internal/engines/postgres/checks_extra_test.go new file mode 100644 index 0000000..b1adf93 --- /dev/null +++ b/internal/engines/postgres/checks_extra_test.go @@ -0,0 +1,85 @@ +package postgres + +import ( + "strings" + "testing" + + "github.com/techdev-lab/restorelab/internal/contract" + "github.com/techdev-lab/restorelab/internal/engines" +) + + +func TestEvaluateLessThan(t *testing.T) { + cases := []struct { + name string + thr int + actual string + want string + wantErr bool + }{ + {"below", 10, "3", "PASS", false}, + {"equal is fail", 10, "10", "FAIL", true}, + {"above", 10, "11", "FAIL", true}, + {"non-integer", 10, "abc", "FAIL", true}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + r := evaluateLessThan(engines.CheckResult{}, tc.thr, tc.actual) + if r.Status != tc.want { + t.Errorf("status = %s, want %s", r.Status, tc.want) + } + if (r.Err != nil) != tc.wantErr { + t.Errorf("err = %v, wantErr = %v", r.Err, tc.wantErr) + } + if !strings.HasPrefix(r.Expected, "< ") { + t.Errorf("expected label %q, want prefix \"< \"", r.Expected) + } + }) + } +} + +func TestEvaluateMinLength(t *testing.T) { + cases := []struct { + name string + minLen int + actual string + want string + }{ + {"long enough", 5, "hello world", "PASS"}, + {"exact", 5, "hello", "PASS"}, + {"too short", 5, "hey", "FAIL"}, + {"zero min always passes", 0, "", "PASS"}, + {"negative min fails", -1, "anything", "FAIL"}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + r := evaluateMinLength(engines.CheckResult{}, tc.minLen, tc.actual) + if r.Status != tc.want { + t.Errorf("status = %s, want %s", r.Status, tc.want) + } + }) + } +} + +func TestApplyOnFail(t *testing.T) { + failed := engines.CheckResult{Status: "FAIL", Err: errDummy{}} + + if got := applyOnFail(failed, contract.Check{OnFail: "warn"}); got.Status != "WARNING" { + t.Errorf("on_fail=warn: status = %s, want WARNING", got.Status) + } + if got := applyOnFail(failed, contract.Check{OnFail: "fail"}); got.Status != "FAIL" { + t.Errorf("on_fail=fail: status = %s, want FAIL", got.Status) + } + if got := applyOnFail(failed, contract.Check{}); got.Status != "FAIL" { + t.Errorf("on_fail unset: status = %s, want FAIL", got.Status) + } + + passed := engines.CheckResult{Status: "PASS"} + if got := applyOnFail(passed, contract.Check{OnFail: "warn"}); got.Status != "PASS" { + t.Errorf("passing check must stay PASS, got %s", got.Status) + } +} + +type errDummy struct{} + +func (errDummy) Error() string { return "dummy" } diff --git a/internal/report/report.go b/internal/report/report.go index 1b561fa..b4c22dd 100644 --- a/internal/report/report.go +++ b/internal/report/report.go @@ -11,8 +11,10 @@ import ( "time" ) -// CurrentVersion is the report schema version. -const CurrentVersion = "1.0" +// CurrentVersion is the report schema version. 1.1 adds +// duration_ms to check results; all pre-existing fields are +// unchanged, so older consumers can still parse new reports. +const CurrentVersion = "1.1" // Status is the categorical outcome of a stage or check. type Status string @@ -36,11 +38,12 @@ type Stage struct { // Check is one SQL validation result. type Check struct { - Name string `json:"name"` - Status Status `json:"status"` - Expected string `json:"expected,omitempty"` - Actual string `json:"actual,omitempty"` - Error string `json:"error,omitempty"` + Name string `json:"name"` + Status Status `json:"status"` + Expected string `json:"expected,omitempty"` + Actual string `json:"actual,omitempty"` + Error string `json:"error,omitempty"` + DurationMS int64 `json:"duration_ms"` } // Report is the complete outcome of a single recovery drill. diff --git a/internal/report/template.html b/internal/report/template.html index cd87224..e8cfc80 100644 --- a/internal/report/template.html +++ b/internal/report/template.html @@ -165,6 +165,7 @@

Checks

Status Expected Actual + Duration Notes @@ -175,6 +176,7 @@

Checks

{{.Status}} {{or .Expected "-"}} {{or .Actual "-"}} + {{formatDuration .DurationMS}} {{if .Error}}{{.Error}}{{end}} {{end}} diff --git a/internal/workflow/run.go b/internal/workflow/run.go index aa95077..ba15226 100644 --- a/internal/workflow/run.go +++ b/internal/workflow/run.go @@ -11,7 +11,6 @@ import ( "context" "crypto/rand" "encoding/hex" - "errors" "fmt" "log/slog" "os" @@ -126,6 +125,20 @@ func (r *Runner) Run(ctx context.Context, c *contract.Contract, contractPath str rep = report.New(runID, c.Name, contractPath) rep.ScopeNotes = report.DefaultScopeNotes() + // Drill-wide timeout: limits.timeout from the contract bounds + // the entire restore + validation sequence. The root context + // in main.go only guards against a runaway process; this is + // the operator-configured budget for one drill. A cancelled + // context surfaces as a failure on whichever stage was in + // progress, and the deferred cleanup still runs with a fresh + // background context. + drillCtx := ctx + if d, err := contract.ParseDuration(c.Limits.Timeout); err == nil && d > 0 { + var cancel context.CancelFunc + drillCtx, cancel = context.WithTimeout(ctx, d) + defer cancel() + } + // Extract image digest from the contract's image reference // for the report (the validator already requires @sha256:). if idx := strings.Index(c.Test.Image, "@"); idx >= 0 { @@ -158,7 +171,7 @@ func (r *Runner) Run(ctx context.Context, c *contract.Contract, contractPath str // === Preflight === start := time.Now() checker := preflight.New(c) - results := checker.RunAll(ctx) + results := checker.RunAll(drillCtx) if preflight.HasFailures(results) { rep.AddStage(report.Stage{ Name: "preflight", @@ -205,7 +218,7 @@ func (r *Runner) Run(ctx context.Context, c *contract.Contract, contractPath str // === Metadata (best effort) === start = time.Now() - if meta, err := provider.GetSnapshotMetadata(ctx, c.Source); err != nil { + if meta, err := provider.GetSnapshotMetadata(drillCtx, c.Source); err != nil { rep.AddStage(report.Stage{ Name: "restic-metadata", Status: report.StatusWarning, @@ -232,7 +245,7 @@ func (r *Runner) Run(ctx context.Context, c *contract.Contract, contractPath str // === Restic restore === start = time.Now() restoreDir := filepath.Join(workDir, "artifact") - artifactPath, err := provider.RestoreArtifact(ctx, c.Source, restoreDir) + artifactPath, err := provider.RestoreArtifact(drillCtx, c.Source, restoreDir) if err != nil { rep.AddStage(report.Stage{ Name: "restic-restore", @@ -314,7 +327,7 @@ func (r *Runner) Run(ctx context.Context, c *contract.Contract, contractPath str // container built from the same pinned image, with no network, // no volume, and a read-only bind mount of the artifact. start = time.Now() - if err := sandbox.InspectArchive(ctx, r.CLI, sandbox.InspectConfig{ + if err := sandbox.InspectArchive(drillCtx, r.CLI, sandbox.InspectConfig{ Image: c.Test.Image, RunID: runID, ArtifactPath: artifactPath, @@ -360,7 +373,7 @@ func (r *Runner) Run(ctx context.Context, c *contract.Contract, contractPath str // === Network === start = time.Now() - netID, err := sandbox.CreateInternalNetwork(ctx, r.CLI, runID) + netID, err := sandbox.CreateInternalNetwork(drillCtx, r.CLI, runID) if err != nil { rep.AddStage(report.Stage{ Name: "sandbox-network", @@ -381,7 +394,7 @@ func (r *Runner) Run(ctx context.Context, c *contract.Contract, contractPath str // === Volume === start = time.Now() - volName, err := sandbox.CreatePGDataVolume(ctx, r.CLI, runID) + volName, err := sandbox.CreatePGDataVolume(drillCtx, r.CLI, runID) if err != nil { rep.AddStage(report.Stage{ Name: "sandbox-volume", @@ -415,7 +428,7 @@ func (r *Runner) Run(ctx context.Context, c *contract.Contract, contractPath str Memory: memory, PidsLimit: int64(c.Limits.Pids), } - ctr, err := sandbox.CreatePostgresContainer(ctx, r.CLI, cfg) + ctr, err := sandbox.CreatePostgresContainer(drillCtx, r.CLI, cfg) if err != nil { rep.AddStage(report.Stage{ Name: "sandbox-container", @@ -436,7 +449,7 @@ func (r *Runner) Run(ctx context.Context, c *contract.Contract, contractPath str // === Start container === start = time.Now() - if err := sandbox.StartContainer(ctx, r.CLI, ctr); err != nil { + if err := sandbox.StartContainer(drillCtx, r.CLI, ctr); err != nil { rep.AddStage(report.Stage{ Name: "sandbox-start", Status: report.StatusFail, @@ -459,7 +472,7 @@ func (r *Runner) Run(ctx context.Context, c *contract.Contract, contractPath str // privileged mode, no-new-privileges, minimal capabilities, // and resource limits set. start = time.Now() - auditResults, err := sandbox.AuditContainer(ctx, r.CLI, ctr.ID, cfg.NetworkName) + auditResults, err := sandbox.AuditContainer(drillCtx, r.CLI, ctr.ID, cfg.NetworkName) if err != nil { rep.AddStage(report.Stage{ Name: "container-isolation", @@ -493,7 +506,7 @@ func (r *Runner) Run(ctx context.Context, c *contract.Contract, contractPath str // === Readiness === start = time.Now() - if err := engine.WaitUntilReady(ctx, ctr, c.Test.Username, c.Test.Database); err != nil { + if err := engine.WaitUntilReady(drillCtx, ctr, c.Test.Username, c.Test.Database); err != nil { rep.AddStage(report.Stage{ Name: "postgres-ready", Status: report.StatusFail, @@ -511,7 +524,7 @@ func (r *Runner) Run(ctx context.Context, c *contract.Contract, contractPath str // Query server_version for the report (best effort; failure is // non-fatal, the report just leaves the field empty). - if res, err := postgres.ExecInContainer(ctx, r.CLI, ctr.ID, + if res, err := postgres.ExecInContainer(drillCtx, r.CLI, ctr.ID, []string{"psql", "-U", c.Test.Username, "-d", c.Test.Database, "-tA", "-c", "SHOW server_version"}, 10*time.Second); err == nil && res.ExitCode == 0 { @@ -520,7 +533,7 @@ func (r *Runner) Run(ctx context.Context, c *contract.Contract, contractPath str // === pg_restore === start = time.Now() - if err := engine.Restore(ctx, ctr, ctr.ArtifactPathInContainer, c.Test); err != nil { + if err := engine.Restore(drillCtx, ctr, ctr.ArtifactPathInContainer, c.Test); err != nil { rep.AddStage(report.Stage{ Name: "pg-restore", Status: report.StatusFail, @@ -539,19 +552,17 @@ func (r *Runner) Run(ctx context.Context, c *contract.Contract, contractPath str // === SQL checks === for _, chk := range c.Test.Checks { start = time.Now() - res, _ := engine.RunCheck(ctx, ctr, chk, c.Test) + res, _ := engine.RunCheck(drillCtx, ctr, chk, c.Test) rep.AddCheck(report.Check{ - Name: res.Name, - Status: report.Status(res.Status), - Expected: res.Expected, - Actual: res.Actual, - Error: errString(res.Err), + Name: res.Name, + Status: report.Status(res.Status), + Expected: res.Expected, + Actual: res.Actual, + Error: errString(res.Err), + DurationMS: time.Since(start).Milliseconds(), }) - _ = start } return rep } -// ErrNotImplemented is a sentinel for future use. -var ErrNotImplemented = errors.New("not implemented") From f30cc285382c91d1caf82b398e3f109b9cfe2bd7 Mon Sep 17 00:00:00 2001 From: "qwen.ai[bot]" Date: Sat, 28 Nov 2026 11:04:54 +0000 Subject: [PATCH 2/3] style: gofmt formatting for updated files --- internal/contract/validator_test.go | 72 +++++++++---------- .../engines/postgres/checks_extra_test.go | 1 - internal/workflow/run.go | 1 - 3 files changed, 36 insertions(+), 38 deletions(-) diff --git a/internal/contract/validator_test.go b/internal/contract/validator_test.go index 3e625dd..3c90bf0 100644 --- a/internal/contract/validator_test.go +++ b/internal/contract/validator_test.go @@ -151,55 +151,55 @@ func TestValidate_CleanupAlwaysFalse(t *testing.T) { } func TestValidate_CheckWithLessThan(t *testing.T) { -c := validContract() -c.Test.Checks[0].Expect.Value = nil -lt := 100 -c.Test.Checks[0].Expect.LessThan = < -if err := c.Validate(); err != nil { -t.Fatalf("unexpected error: %v", err) -} + c := validContract() + c.Test.Checks[0].Expect.Value = nil + lt := 100 + c.Test.Checks[0].Expect.LessThan = < + if err := c.Validate(); err != nil { + t.Fatalf("unexpected error: %v", err) + } } func TestValidate_CheckWithMinLength(t *testing.T) { -c := validContract() -c.Test.Checks[0].Expect.Value = nil -ml := 10 -c.Test.Checks[0].Expect.MinLength = &ml -if err := c.Validate(); err != nil { -t.Fatalf("unexpected error: %v", err) -} + c := validContract() + c.Test.Checks[0].Expect.Value = nil + ml := 10 + c.Test.Checks[0].Expect.MinLength = &ml + if err := c.Validate(); err != nil { + t.Fatalf("unexpected error: %v", err) + } } func TestValidate_CheckNoExpectation(t *testing.T) { -c := validContract() -c.Test.Checks[0].Expect = CheckExpect{} -if err := c.Validate(); err == nil { -t.Fatal("expected error for check with no expectation") -} + c := validContract() + c.Test.Checks[0].Expect = CheckExpect{} + if err := c.Validate(); err == nil { + t.Fatal("expected error for check with no expectation") + } } func TestValidate_CheckThreeExpects(t *testing.T) { -c := validContract() -n := 5 -c.Test.Checks[0].Expect.GreaterThan = &n -c.Test.Checks[0].Expect.LessThan = &n -if err := c.Validate(); err == nil { -t.Fatal("expected error for check with multiple expectations") -} + c := validContract() + n := 5 + c.Test.Checks[0].Expect.GreaterThan = &n + c.Test.Checks[0].Expect.LessThan = &n + if err := c.Validate(); err == nil { + t.Fatal("expected error for check with multiple expectations") + } } func TestValidate_CheckOnFailWarn(t *testing.T) { -c := validContract() -c.Test.Checks[0].OnFail = "warn" -if err := c.Validate(); err != nil { -t.Fatalf("unexpected error: %v", err) -} + c := validContract() + c.Test.Checks[0].OnFail = "warn" + if err := c.Validate(); err != nil { + t.Fatalf("unexpected error: %v", err) + } } func TestValidate_CheckOnFailInvalid(t *testing.T) { -c := validContract() -c.Test.Checks[0].OnFail = "ignore" -if err := c.Validate(); err == nil { -t.Fatal("expected error for invalid on_fail value") -} + c := validContract() + c.Test.Checks[0].OnFail = "ignore" + if err := c.Validate(); err == nil { + t.Fatal("expected error for invalid on_fail value") + } } diff --git a/internal/engines/postgres/checks_extra_test.go b/internal/engines/postgres/checks_extra_test.go index b1adf93..d4d655a 100644 --- a/internal/engines/postgres/checks_extra_test.go +++ b/internal/engines/postgres/checks_extra_test.go @@ -8,7 +8,6 @@ import ( "github.com/techdev-lab/restorelab/internal/engines" ) - func TestEvaluateLessThan(t *testing.T) { cases := []struct { name string diff --git a/internal/workflow/run.go b/internal/workflow/run.go index ba15226..9efe9d6 100644 --- a/internal/workflow/run.go +++ b/internal/workflow/run.go @@ -565,4 +565,3 @@ func (r *Runner) Run(ctx context.Context, c *contract.Contract, contractPath str return rep } - From 62410a9c74c46d6efb944132bb3e4fd3c225741c Mon Sep 17 00:00:00 2001 From: "qwen.ai[bot]" Date: Sat, 28 Nov 2026 11:06:03 +0000 Subject: [PATCH 3/3] fix: remove dead expect.type from examples; docs: document v0.2 check features (less_than, min_length, on_fail, drill timeout, per-check durations) --- README.md | 36 +++++++++++++++++++++++ examples/postgres-restic.yaml | 1 - examples/real-world/immich-real-test.yaml | 4 +-- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7b47d8e..31873c3 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,42 @@ Not supported in v0.1.0: Borg, PBS, Duplicati / MySQL, MariaDB, SQLite / Kuberne Anything not in the supported list is deliberately deferred to ROADMAP.md and will not enter v0.1.0. +## SQL checks in the contract + +Each check runs a read-only query against the restored sandbox +database and compares the result to an expectation. Exactly one +expectation field per check: + +| Field | Meaning | +|----------------|------------------------------------------------------| +| `value` | actual must equal the expected value (string compare) | +| `greater_than` | actual integer must be strictly greater | +| `less_than` | actual integer must be strictly less | +| `min_length` | returned text must be at least N characters long | + +Optional `on_fail: warn` downgrades a failing check to a WARNING +instead of a hard FAIL — useful for advisory sanity bounds (e.g. +an approximate row count) that should not block an otherwise +successful recovery verification. + +```yaml +checks: + - name: asset_row_count + type: sql + query: "SELECT count(*) FROM asset" + expect: { greater_than: 100000 } + + - name: orphaned_files_bound + type: sql + query: "SELECT count(*) FROM file WHERE asset_id IS NULL" + expect: { less_than: 10 } + on_fail: warn +``` + +The drill-wide `limits.timeout` bounds the whole restore + +validation sequence; every stage and every SQL check records its +duration in the JSON and HTML reports. + ## Quick start Install directly (requires Go 1.22+): diff --git a/examples/postgres-restic.yaml b/examples/postgres-restic.yaml index 6edcafb..9f68ea9 100644 --- a/examples/postgres-restic.yaml +++ b/examples/postgres-restic.yaml @@ -44,7 +44,6 @@ test: WHERE nspname NOT LIKE 'pg_%' AND nspname <> 'information_schema' expect: - type: integer greater_than: 0 isolation: diff --git a/examples/real-world/immich-real-test.yaml b/examples/real-world/immich-real-test.yaml index b16184a..4669de0 100644 --- a/examples/real-world/immich-real-test.yaml +++ b/examples/real-world/immich-real-test.yaml @@ -36,11 +36,11 @@ test: SELECT count(*) FROM pg_namespace WHERE nspname NOT LIKE 'pg_%' AND nspname <> 'information_schema' - expect: { type: integer, greater_than: 0 } + expect: { greater_than: 0 } - name: asset_row_count type: sql query: "SELECT count(*) FROM asset" - expect: { type: integer, greater_than: 100000 } + expect: { greater_than: 100000 } isolation: network: internal