Authoring lint: required checks, undeclared outcomes, delivery claims, loop limits, silent guards, boilerplate

This commit is contained in:
2026-11-04 13:04:11 +00:00
parent fa6c0864db
commit 37e941bbba
16 changed files with 745 additions and 44 deletions
+37
View File
@@ -0,0 +1,37 @@
package stage
import "testing"
func TestChecksNoneDeclaration(t *testing.T) {
for name, tc := range map[string]struct {
checks string
delivery bool
ok bool
}{
"none on mutating stage": {checks: "none: read-only review", ok: true},
"none case insensitive": {checks: "None: focused tests only", ok: true},
"none without reason": {checks: "none:"},
"none with extra lines": {checks: "none: reason\ngo test ./..."},
"none on delivery stage": {checks: "none: trust me", delivery: true},
"commands on non-delivery": {checks: "go test ./..."},
"commands on delivery": {checks: "go test ./...", delivery: true, ok: true},
} {
t.Run(name, func(t *testing.T) {
def := modelDefinition()
def.Blocks["checks"] = tc.checks
if tc.delivery {
def.Configs["delivery"] = "true"
}
_, err := (ModelStage{}).Spec(def)
if (err == nil) != tc.ok {
t.Fatalf("Spec(%q) error = %v, want ok=%v", tc.checks, err, tc.ok)
}
})
}
def := modelDefinition()
def.Configs["delivery"] = "true"
def.Blocks["checks"] = "none: skip"
if _, err := DeliveryChecks(def); err == nil {
t.Fatal("delivery gate would run none: as a command")
}
}
+2 -2
View File
@@ -104,8 +104,8 @@ func (ModelStage) Spec(def Definition) (ModelSpec, error) {
if def.Configs["delivery"] == "true" && backend != "opencode" {
return ModelSpec{}, fmt.Errorf("delivery is supported only by the opencode harness")
}
if _, present := def.Blocks["checks"]; present && def.Configs["delivery"] != "true" {
return ModelSpec{}, fmt.Errorf("checks block is supported only by delivery stages")
if err := ValidateChecksBlock(def); err != nil {
return ModelSpec{}, err
}
if backend == "pi" {
tools, _, _ := ToolNames(def)
+42
View File
@@ -72,6 +72,9 @@ func DeliveryChecks(def Definition) ([]string, error) {
if text == "" {
return nil, fmt.Errorf("delivery stages require a nonempty checks block")
}
if _, none := ChecksNone(text); none {
return nil, fmt.Errorf("delivery stages run their checks before landing; list the check commands instead of none")
}
var checks []string
for _, line := range strings.Split(text, "\n") {
check := strings.TrimSpace(line)
@@ -89,6 +92,45 @@ func DeliveryChecks(def Definition) ([]string, error) {
return checks, nil
}
// ChecksNone reports whether a checks block uses the explicit
// "none: <reason>" form. It matches on the leading none: alone, so a malformed
// declaration (no reason, extra lines) is rejected rather than run as a command.
func ChecksNone(text string) (reason string, ok bool) {
text = strings.TrimSpace(text)
if !strings.HasPrefix(strings.ToLower(text), "none:") {
return "", false
}
return strings.TrimSpace(text[len("none:"):]), true
}
// ValidateChecksBlock is the checks syntax shared by stored and new
// definitions. Only a delivery stage executes commands (the server's delivery
// gate); every other stage may declare only "none: <reason>", so a listed
// command is never accepted and then silently left unexecuted.
func ValidateChecksBlock(def Definition) error {
text, present := def.Blocks["checks"]
if !present {
return nil
}
if reason, none := ChecksNone(text); none {
if strings.Contains(strings.TrimSpace(text), "\n") {
return fmt.Errorf("checks none must be a single line: none: <reason>")
}
if len(reason) < 3 || len(reason) > 300 {
return fmt.Errorf("checks none needs a short reason (3-300 bytes), for example \"none: read-only review\"")
}
if def.Configs["delivery"] == "true" {
return fmt.Errorf("delivery stages run their checks before landing; list the check commands instead of none")
}
return nil
}
if def.Configs["delivery"] != "true" {
return fmt.Errorf("checks commands run only on delivery stages (delivery=true); write \"none: <reason>\" here and declare the commands on the delivery stage")
}
_, err := DeliveryChecks(def)
return err
}
// ToolNames validates model-stage permissions, not general graph semantics.
// A present empty block explicitly denies all tools.
func ToolNames(def Definition) ([]string, bool, error) {