GEN2-005: govern identity resolution and version bindings
CI / test (push) Failing after 38s

This commit is contained in:
m
2026-08-29 02:20:02 +03:00
parent 301dbdcfb2
commit 8a8e571905
4 changed files with 90 additions and 1 deletions
+30
View File
@@ -0,0 +1,30 @@
package domain_test
import (
"testing"
"git.cin.su/m/Assistant/contracts/world"
"git.cin.su/m/Assistant/modules/world/domain"
)
func TestResolveCandidatesDoesNotAutoMergeAmbiguousPeopleOrSystems(t *testing.T) {
decision, candidates := domain.ResolveCandidates([]world.IdentityResolutionCandidate{
{ObjectRef: world.SemanticReference{OwnerNamespace: "world", SemanticKind: "person", StableID: "ivan-telegram"}, Confidence: 800},
{ObjectRef: world.SemanticReference{OwnerNamespace: "world", SemanticKind: "person", StableID: "ivan-crm"}, Confidence: 800},
}, 700)
if decision != world.ResolutionUnresolved || len(candidates) != 2 {
t.Fatalf("ambiguous result = %s, %#v", decision, candidates)
}
}
func TestVersionAndEnvironmentReferencesAreTyped(t *testing.T) {
version := world.SemanticReference{OwnerNamespace: "world", SemanticKind: "version", StableID: "unf-3"}
binding := world.VersionBinding{SubjectRef: world.SemanticReference{OwnerNamespace: "world", SemanticKind: "database", StableID: "company-a-unf"}, VersionRef: version, MatchMode: world.VersionExact}
if err := binding.Validate(); err != nil {
t.Fatal(err)
}
environment := world.EnvironmentReference{EnvironmentRef: world.SemanticReference{OwnerNamespace: "world", SemanticKind: "environment", StableID: "company-a-prod"}, VersionRef: &version}
if err := environment.Validate(); err != nil {
t.Fatal(err)
}
}
+17
View File
@@ -2,6 +2,8 @@ package domain
import "git.cin.su/m/Assistant/contracts/world"
import "sort"
func ValidateObject(value world.WorldObject) error { return value.Validate() }
func ValidateKindDefinition(value world.WorldObjectKindDefinition) error { return value.Validate() }
@@ -15,3 +17,18 @@ func ValidateRelationDefinition(value world.RelationDefinition) error { return v
func ValidateResolution(value world.IdentityResolutionDecisionRecord) error { return value.Validate() }
func ValidateLineage(value world.WorldLineage) error { return value.Validate() }
// ResolveCandidates deliberately refuses to merge an ambiguous result. A
// caller may persist the returned UNRESOLVED decision and later re-evaluate it
// with additional evidence.
func ResolveCandidates(candidates []world.IdentityResolutionCandidate, minimumConfidence int64) (world.ResolutionDecision, []world.IdentityResolutionCandidate) {
ordered := append([]world.IdentityResolutionCandidate(nil), candidates...)
sort.SliceStable(ordered, func(i, j int) bool { return ordered[i].Confidence > ordered[j].Confidence })
if len(ordered) == 0 || ordered[0].Confidence < minimumConfidence {
return world.ResolutionUnresolved, ordered
}
if len(ordered) > 1 && ordered[0].Confidence == ordered[1].Confidence {
return world.ResolutionUnresolved, ordered
}
return world.ResolutionSame, ordered[:1]
}