From dd5e2a14ce1b90dd9a87c0db45011e63e423c4f3 Mon Sep 17 00:00:00 2001 From: Yushan Lin Date: Sun, 19 Jul 2026 22:26:38 -0700 Subject: [PATCH 1/2] feat(entity): add entity types for target graph and changed targets Co-Authored-By: Claude Sonnet 5 --- entity/BUILD.bazel | 2 ++ entity/changed_targets.go | 17 +++++++++++++++++ entity/optimized_target.go | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 entity/changed_targets.go create mode 100644 entity/optimized_target.go diff --git a/entity/BUILD.bazel b/entity/BUILD.bazel index deff8984..58de4a19 100644 --- a/entity/BUILD.bazel +++ b/entity/BUILD.bazel @@ -4,7 +4,9 @@ go_library( name = "entity", srcs = [ "build_description.go", + "changed_targets.go", "computation_strategy.go", + "optimized_target.go", "target_graph.go", ], importpath = "github.com/uber/tango/entity", diff --git a/entity/changed_targets.go b/entity/changed_targets.go new file mode 100644 index 00000000..cfe19317 --- /dev/null +++ b/entity/changed_targets.go @@ -0,0 +1,17 @@ +package entity + +// ChangedTarget represents a target that differs between two revisions. +type ChangedTarget struct { + ChangeType int32 `json:"change_type"` + OldTarget *OptimizedTarget `json:"old_target,omitempty"` + NewTarget *OptimizedTarget `json:"new_target,omitempty"` + Distance int32 `json:"distance"` +} + +// GetChangedTargetsResponse is one piece of a streamed changed-targets +// result — either a batch of changed targets or a metadata mapping. +// Exactly one field is non-nil. +type GetChangedTargetsResponse struct { + ChangedTargets []ChangedTarget `json:"changed_targets"` + Metadata *Metadata `json:"metadata,omitempty"` +} diff --git a/entity/optimized_target.go b/entity/optimized_target.go new file mode 100644 index 00000000..36308ff9 --- /dev/null +++ b/entity/optimized_target.go @@ -0,0 +1,34 @@ +package entity + +// OptimizedTarget is the compact, ID-mapped representation of a target used +// for streaming and storage. String fields are replaced with int32 IDs that +// reference the accompanying Metadata maps. +type OptimizedTarget struct { + ID int32 `json:"id"` + Hash string `json:"hash"` + DirectDependencies []int32 `json:"direct_dependencies"` + RuleType int32 `json:"rule_type"` + Tags []int32 `json:"tags"` + Root bool `json:"root"` + External bool `json:"external"` + Attributes map[int32]int32 `json:"attributes"` +} + +// Metadata holds the ID-to-string mappings that accompany a set of +// OptimizedTarget entries. Consumers merge metadata across chunks before +// resolving IDs. +type Metadata struct { + TargetIDMapping map[int32]string `json:"target_id_mapping"` + RuleTypeMapping map[int32]string `json:"rule_type_mapping"` + TagMapping map[int32]string `json:"tag_mapping"` + AttributeNameMapping map[int32]string `json:"attribute_name_mapping"` + AttributeStringValueMapping map[int32]string `json:"attribute_string_value_mapping"` +} + +// GetTargetGraphResponse is one piece of a streamed target graph — either a +// batch of ID-mapped targets or a metadata mapping. Exactly one field is +// non-nil. +type GetTargetGraphResponse struct { + Targets []OptimizedTarget `json:"targets"` + Metadata *Metadata `json:"metadata,omitempty"` +} From 2da70209daff5cfef632821ba6a39cb5b9cc229a Mon Sep 17 00:00:00 2001 From: Yushan Lin Date: Mon, 20 Jul 2026 09:35:05 -0700 Subject: [PATCH 2/2] feat(entity): add ChangeType enum mirroring proto ChangeType Add entity.ChangeType as a typed enum with Invalid/New/Deleted/Changed values matching the proto definition. Update ChangedTarget.ChangeType from int32 to the new type. Co-Authored-By: Claude Sonnet 5 --- entity/BUILD.bazel | 1 + entity/change_type.go | 25 +++++++++++++++++++++++++ entity/changed_targets.go | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 entity/change_type.go diff --git a/entity/BUILD.bazel b/entity/BUILD.bazel index 58de4a19..3e9b3a9a 100644 --- a/entity/BUILD.bazel +++ b/entity/BUILD.bazel @@ -4,6 +4,7 @@ go_library( name = "entity", srcs = [ "build_description.go", + "change_type.go", "changed_targets.go", "computation_strategy.go", "optimized_target.go", diff --git a/entity/change_type.go b/entity/change_type.go new file mode 100644 index 00000000..7cf7f76c --- /dev/null +++ b/entity/change_type.go @@ -0,0 +1,25 @@ +package entity + +// ChangeType classifies how a target differs between two revisions. +type ChangeType int + +const ( + ChangeTypeInvalid ChangeType = iota + ChangeTypeNew + ChangeTypeDeleted + ChangeTypeChanged +) + +// String returns the enum name, matching the proto enum string representation. +func (c ChangeType) String() string { + switch c { + case ChangeTypeNew: + return "CHANGE_TYPE_NEW" + case ChangeTypeDeleted: + return "CHANGE_TYPE_DELETED" + case ChangeTypeChanged: + return "CHANGE_TYPE_CHANGED" + default: + return "CHANGE_TYPE_INVALID" + } +} diff --git a/entity/changed_targets.go b/entity/changed_targets.go index cfe19317..0fa33533 100644 --- a/entity/changed_targets.go +++ b/entity/changed_targets.go @@ -2,7 +2,7 @@ package entity // ChangedTarget represents a target that differs between two revisions. type ChangedTarget struct { - ChangeType int32 `json:"change_type"` + ChangeType ChangeType `json:"change_type"` OldTarget *OptimizedTarget `json:"old_target,omitempty"` NewTarget *OptimizedTarget `json:"new_target,omitempty"` Distance int32 `json:"distance"`