From 4aefdf56afdffdb7a53908417ce519eff8c11a33 Mon Sep 17 00:00:00 2001 From: HankGrimm <3010919468@qq.com> Date: Tue, 24 Nov 2026 10:54:14 +0800 Subject: [PATCH] Retain label id in typed governance outputs MinimalLabel dropped the label's id on the typed get_label/list_label round-trip: it declared only name, color and description, so encoding/json silently ignored the legacy id field and re-encoding emitted no id. Add an ID field so the typed output preserves the label's GraphQL id. Fixes #3923 Co-Authored-By: Claude Code --- pkg/github/__toolsnaps__/get_label.snap | 4 ++++ pkg/github/__toolsnaps__/list_label.snap | 4 ++++ pkg/github/typed_governance_outputs.go | 1 + pkg/github/typed_governance_outputs_test.go | 18 ++++++++++++++++-- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pkg/github/__toolsnaps__/get_label.snap b/pkg/github/__toolsnaps__/get_label.snap index 6cd1ddb6aa..50a2081f5d 100644 --- a/pkg/github/__toolsnaps__/get_label.snap +++ b/pkg/github/__toolsnaps__/get_label.snap @@ -38,11 +38,15 @@ "description": { "type": "string" }, + "id": { + "type": "string" + }, "name": { "type": "string" } }, "required": [ + "id", "name", "color", "description" diff --git a/pkg/github/__toolsnaps__/list_label.snap b/pkg/github/__toolsnaps__/list_label.snap index 80e898b71b..e4c1665e9e 100644 --- a/pkg/github/__toolsnaps__/list_label.snap +++ b/pkg/github/__toolsnaps__/list_label.snap @@ -47,11 +47,15 @@ "description": { "type": "string" }, + "id": { + "type": "string" + }, "name": { "type": "string" } }, "required": [ + "id", "name", "color", "description" diff --git a/pkg/github/typed_governance_outputs.go b/pkg/github/typed_governance_outputs.go index 02952bac0b..d67e5daa2f 100644 --- a/pkg/github/typed_governance_outputs.go +++ b/pkg/github/typed_governance_outputs.go @@ -14,6 +14,7 @@ import ( ) type MinimalLabel struct { + ID string `json:"id"` Name string `json:"name"` Color string `json:"color" jsonschema:"Hex RGB without leading #."` Description string `json:"description"` diff --git a/pkg/github/typed_governance_outputs_test.go b/pkg/github/typed_governance_outputs_test.go index 094de91547..9bbc5bbc29 100644 --- a/pkg/github/typed_governance_outputs_test.go +++ b/pkg/github/typed_governance_outputs_test.go @@ -70,9 +70,9 @@ func assertGovernanceProjection(t *testing.T, tc governanceWireCase, output any) } switch tc.tool.Tool.Name { case "get_label": - assert.JSONEq(t, `{"name":"bug","color":"ff0000","description":"desc"}`, mustMarshalJSON(t, output)) + assert.JSONEq(t, `{"id":"L1","name":"bug","color":"ff0000","description":"desc"}`, mustMarshalJSON(t, output)) case "list_label": - assert.JSONEq(t, `{"labels":[{"name":"bug","color":"ff0000","description":"desc"}],"totalCount":1,"pageInfo":{"hasNextPage":false,"hasPreviousPage":false}}`, mustMarshalJSON(t, output)) + assert.JSONEq(t, `{"labels":[{"id":"L1","name":"bug","color":"ff0000","description":"desc"}],"totalCount":1,"pageInfo":{"hasNextPage":false,"hasPreviousPage":false}}`, mustMarshalJSON(t, output)) case "label_write": assert.Equal(t, tc.args["method"], object["method"]) assert.Equal(t, tc.text, object["message"]) @@ -346,6 +346,20 @@ func TestTypedGovernanceWireOutputs(t *testing.T) { } } +func TestListLabelsOutputRetainsID(t *testing.T) { + const legacy = `{"labels":[{"id":"LA_kwDOABcdEf","name":"bug","color":"ff0000","description":"desc"}],"totalCount":1,"pageInfo":{"hasNextPage":false,"hasPreviousPage":false}}` + + var out ListLabelsOutput + require.NoError(t, json.Unmarshal([]byte(legacy), &out)) + require.Len(t, out.Labels, 1) + assert.Equal(t, "LA_kwDOABcdEf", out.Labels[0].ID) + + // Round-trip: the id must survive a typed decode/re-encode. + b, err := json.Marshal(out) + require.NoError(t, err) + assert.Contains(t, string(b), `"id":"LA_kwDOABcdEf"`) +} + func TestRuleSuiteOutputFidelity(t *testing.T) { for _, sourceID := range []string{"null", "0", "7"} { for _, method := range []string{"get_rule_suite", "list_rule_suites"} {