Adopt location registry durable contract

This commit is contained in:
2026-08-05 19:05:42 +00:00
parent 2f61118e78
commit c006b163d5
41 changed files with 196 additions and 196 deletions

View File

@@ -21,7 +21,7 @@ const (
type Options struct{}
type Validator struct{}
var _ contracts.TypedValidator[dnd.LocationList] = (*Validator)(nil)
var _ contracts.TypedValidator[dnd.LocationRegistry] = (*Validator)(nil)
var _ pipeline.CheckpointFingerprintProvider = (*Validator)(nil)
func New(Options) *Validator { return &Validator{} }
@@ -33,7 +33,7 @@ func (v *Validator) CheckpointFingerprints() []pipeline.CheckpointFingerprint {
return []pipeline.CheckpointFingerprint{{Name: "policy", Value: policy}}
}
func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationRequest[dnd.LocationList]) (contracts.ValidationResult, error) {
func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationRequest[dnd.LocationRegistry]) (contracts.ValidationResult, error) {
issues := issuesFor(req.Value)
if len(issues) > 0 {
return rejection(diagnostics.Aggregate("invalid location shape", issues)), nil
@@ -41,7 +41,7 @@ func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationReq
return contracts.ValidationResult{Approved: true}, nil
}
func Validate(value dnd.LocationList) error {
func Validate(value dnd.LocationRegistry) error {
issues := issuesFor(value)
if len(issues) == 0 {
return nil
@@ -49,7 +49,7 @@ func Validate(value dnd.LocationList) error {
return fmt.Errorf("%s", diagnostics.Aggregate("invalid location shape", issues))
}
func issuesFor(value dnd.LocationList) []string {
func issuesFor(value dnd.LocationRegistry) []string {
if value.Locations == nil {
return []string{"locations must be present"}
}
@@ -74,7 +74,7 @@ func Spec() pipeline.ValidatorSpec {
}
func Register(registry *pipeline.ValidatorRegistry) error {
return pipeline.RegisterTypedValidatorBuilder(registry, dnd.LocationListKind, Spec(), validateOptions, func(request pipeline.BuildRequest) (contracts.TypedValidator[dnd.LocationList], error) {
return pipeline.RegisterTypedValidatorBuilder(registry, dnd.LocationRegistryKind, Spec(), validateOptions, func(request pipeline.BuildRequest) (contracts.TypedValidator[dnd.LocationRegistry], error) {
options, err := DecodeOptions(request.Options)
if err != nil {
return nil, err

View File

@@ -14,7 +14,7 @@ import (
)
func TestValidatorRejectsMissingRequiredFieldsWithoutMutation(t *testing.T) {
value := dnd.LocationList{Locations: []dnd.Location{{Name: strings.Repeat("火", 220), SourceRefs: []source.SourceRef{}}}}
value := dnd.LocationRegistry{Locations: []dnd.Location{{Name: strings.Repeat("火", 220), SourceRefs: []source.SourceRef{}}}}
before := value
result, err := New(Options{}).Validate(context.Background(), requestWithValue(value))
if err != nil || result.Approved || result.ReasonCode != ReasonCode || !strings.Contains(result.Message, "id must not be empty") || !strings.Contains(result.Message, "source_refs must not be empty") {
@@ -23,14 +23,14 @@ func TestValidatorRejectsMissingRequiredFieldsWithoutMutation(t *testing.T) {
if len(result.Message) > 4096 || !utf8.ValidString(result.Message) || !reflect.DeepEqual(value, before) {
t.Fatalf("Validate() produced unsafe diagnostics or mutated value: %#v", value)
}
result, err = New(Options{}).Validate(context.Background(), requestWithValue(dnd.LocationList{}))
result, err = New(Options{}).Validate(context.Background(), requestWithValue(dnd.LocationRegistry{}))
if err != nil || result.Approved || !strings.Contains(result.Message, "locations must be present") {
t.Fatalf("missing locations = %#v, %v; want rejection", result, err)
}
}
func TestValidatorApprovesAndRegisters(t *testing.T) {
result, err := New(Options{}).Validate(context.Background(), requestWithValue(validLocationList()))
result, err := New(Options{}).Validate(context.Background(), requestWithValue(validLocationRegistry()))
if err != nil || !result.Approved {
t.Fatalf("Validate() = %#v, %v; want approval", result, err)
}
@@ -49,10 +49,10 @@ func TestValidatorApprovesAndRegisters(t *testing.T) {
}
}
func requestWithValue(value dnd.LocationList) contracts.TypedValidationRequest[dnd.LocationList] {
return contracts.TypedValidationRequest[dnd.LocationList]{Value: value}
func requestWithValue(value dnd.LocationRegistry) contracts.TypedValidationRequest[dnd.LocationRegistry] {
return contracts.TypedValidationRequest[dnd.LocationRegistry]{Value: value}
}
func validLocationList() dnd.LocationList {
return dnd.LocationList{Locations: []dnd.Location{{ID: "candidate", Name: "Moon Gate", SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 1, EndUnitID: 1}}}}}
func validLocationRegistry() dnd.LocationRegistry {
return dnd.LocationRegistry{Locations: []dnd.Location{{ID: "candidate", Name: "Moon Gate", SourceRefs: []source.SourceRef{{SourceID: "session", StartUnitID: 1, EndUnitID: 1}}}}}
}