Migrate NPC registry durable contract
This commit is contained in:
@@ -22,7 +22,7 @@ const (
|
||||
type Options struct{}
|
||||
type Validator struct{}
|
||||
|
||||
var _ contracts.TypedValidator[dnd.NPCList] = (*Validator)(nil)
|
||||
var _ contracts.TypedValidator[dnd.NPCRegistry] = (*Validator)(nil)
|
||||
var _ pipeline.CheckpointFingerprintProvider = (*Validator)(nil)
|
||||
|
||||
func New(Options) *Validator { return &Validator{} }
|
||||
@@ -36,7 +36,7 @@ func (v *Validator) CheckpointFingerprints() []pipeline.CheckpointFingerprint {
|
||||
return []pipeline.CheckpointFingerprint{{Name: "policy", Value: policy}}
|
||||
}
|
||||
|
||||
func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationRequest[dnd.NPCList]) (contracts.ValidationResult, error) {
|
||||
func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationRequest[dnd.NPCRegistry]) (contracts.ValidationResult, error) {
|
||||
if err := npcshape.Validate(req.Value); err != nil {
|
||||
return contracts.ValidationResult{Approved: true}, nil
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func Spec() pipeline.ValidatorSpec {
|
||||
}
|
||||
|
||||
func Register(registry *pipeline.ValidatorRegistry) error {
|
||||
return pipeline.RegisterTypedValidatorBuilder(registry, dnd.NPCListKind, Spec(), validateOptions, func(request pipeline.BuildRequest) (contracts.TypedValidator[dnd.NPCList], error) {
|
||||
return pipeline.RegisterTypedValidatorBuilder(registry, dnd.NPCRegistryKind, Spec(), validateOptions, func(request pipeline.BuildRequest) (contracts.TypedValidator[dnd.NPCRegistry], error) {
|
||||
options, err := DecodeOptions(request.Options)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -43,13 +43,13 @@ func TestValidatorContractAndRegistration(t *testing.T) {
|
||||
|
||||
func TestValidatorDefersShapeAndRejectsIdentityIssues(t *testing.T) {
|
||||
validator := New(Options{})
|
||||
shapeInvalid := dnd.NPCList{NPCs: []dnd.NPC{{Name: "missing evidence"}}}
|
||||
shapeInvalid := dnd.NPCRegistry{NPCs: []dnd.NPC{{Name: "missing evidence"}}}
|
||||
result, err := validator.Validate(context.Background(), validationRequest(shapeInvalid))
|
||||
if err != nil || !result.Approved {
|
||||
t.Fatalf("shape-invalid result = %#v, error = %v, want deferred approval", result, err)
|
||||
}
|
||||
|
||||
value := validNPCList(2)
|
||||
value := validNPCRegistry(2)
|
||||
value.NPCs[0].ID = "not-an-id"
|
||||
value.NPCs[1].Name = value.NPCs[0].Name
|
||||
value.NPCs[1].ID = value.NPCs[0].ID
|
||||
@@ -65,7 +65,7 @@ func TestValidatorDefersShapeAndRejectsIdentityIssues(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidatorBoundsUnicodeDiagnostics(t *testing.T) {
|
||||
value := validNPCList(30)
|
||||
value := validNPCRegistry(30)
|
||||
for index := range value.NPCs {
|
||||
value.NPCs[index].ID = fmt.Sprintf("bad-%d", index)
|
||||
value.NPCs[index].Name = strings.Repeat("火", 140) + fmt.Sprintf("-%d", index)
|
||||
@@ -82,12 +82,12 @@ func TestValidatorBoundsUnicodeDiagnostics(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func validationRequest(value dnd.NPCList) contracts.TypedValidationRequest[dnd.NPCList] {
|
||||
return contracts.TypedValidationRequest[dnd.NPCList]{Value: value}
|
||||
func validationRequest(value dnd.NPCRegistry) contracts.TypedValidationRequest[dnd.NPCRegistry] {
|
||||
return contracts.TypedValidationRequest[dnd.NPCRegistry]{Value: value}
|
||||
}
|
||||
|
||||
func validNPCList(count int) dnd.NPCList {
|
||||
value := dnd.NPCList{NPCs: make([]dnd.NPC, count)}
|
||||
func validNPCRegistry(count int) dnd.NPCRegistry {
|
||||
value := dnd.NPCRegistry{NPCs: make([]dnd.NPC, count)}
|
||||
for index := range value.NPCs {
|
||||
name := fmt.Sprintf("NPC %d", index)
|
||||
value.NPCs[index] = dnd.NPC{ID: "npc:sha256:0000000000000000000000000000000000000000000000000000000000000000", Name: name, SourceRefs: []source.SourceRef{sourceRefForTest()}}
|
||||
|
||||
Reference in New Issue
Block a user