From a604bd46425b549ad060b6397c0a8a9a60542fba Mon Sep 17 00:00:00 2001 From: Shanmukh-l33t Date: Sun, 22 Nov 2026 15:15:25 +0000 Subject: [PATCH] Preserve label id in typed list_label output MinimalLabel carried only name, color and description, so the typed ListLabelsOutput decode silently dropped the id that list_label emits (a GraphQL node id string). Typed output now round-trips the legacy payload, and get_label keeps the id as well since it decodes into the same struct. Adds TestListLabelsOutputPreservesLabelID covering a legacy payload with an id and one without, and refreshes the get_label and list_label tool snapshots for the new output schema field. --- 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 | 24 +++++++++++++++++++-- 4 files changed, 31 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..3e22973d16 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"]) @@ -598,6 +598,26 @@ func TestTypedGovernanceLabelRetainsIFCMetadata(t *testing.T) { } } +func TestListLabelsOutputPreservesLabelID(t *testing.T) { + t.Parallel() + + legacy := []byte(`{"labels":[{"id":"MDExOlB1bGxSZXBvc2l0b3J5TGFiZWwx","name":"bug","color":"ff0000","description":"desc"}],"totalCount":1,"pageInfo":{"hasNextPage":false,"hasPreviousPage":false}}`) + output, err := decodeGovernanceJSON[ListLabelsOutput](legacy, nil) + require.NoError(t, err) + require.Len(t, output.Labels, 1) + + encoded, err := json.Marshal(output) + require.NoError(t, err) + assert.JSONEq(t, string(legacy), string(encoded)) + + // A payload without an id still decodes. + withoutID := []byte(`{"labels":[{"name":"bug","color":"ff0000","description":"desc"}],"totalCount":1,"pageInfo":{"hasNextPage":false,"hasPreviousPage":false}}`) + output, err = decodeGovernanceJSON[ListLabelsOutput](withoutID, nil) + require.NoError(t, err) + require.Len(t, output.Labels, 1) + assert.Equal(t, "bug", output.Labels[0].Name) +} + func TestTypedGetLabelToolsetVariant(t *testing.T) { issuesTool := GetLabel(translations.NullTranslationHelper) labelsTool := GetLabelForLabelsToolset(translations.NullTranslationHelper)