group verb: compare launchTemplateData byte for byte (Astra r2)
No canonical form: only the direct userData element is cut by its byte span; any other difference, whitespace and layout included, or a malformed answer, refuses observation. Spec 7.1 updated (8a3d302).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+84
−62
docs/superpowers/specs/2026-11-09-group-roll-verb-design.md+6 −3internal/grouprollaws/group.go+38 −38internal/grouprollaws/group_test.go+39 −20internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv+1 −1
CI cancelled — superseded by a newer push — run details
diff --git a/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md b/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md| index a8ade12ff..78ea8b7fe 100644 |
| --- a/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md |
| +++ b/docs/superpowers/specs/2026-11-09-group-roll-verb-design.md |
| @@ -409,9 +409,12 @@ observation still describes the group. Rule: |
| network interfaces and security groups, the IAM instance profile, the |
| metadata options, the block devices, tags and every other field. The |
| comparison covers both the SDK's decoded fields and the answer's own |
| - `launchTemplateData` XML in a canonical form without `userData`, so a |
| - field the SDK does not know (and its decoder skips) still shows as a |
| - difference. The group's lifecycle hook is checked as before (`hook`), |
| + `launchTemplateData` XML byte for byte, with only its direct `userData` |
| + child element cut out by its byte span: no canonical form, so a field |
| + the SDK does not know (and its decoder skips), its whitespace or any |
| + layout difference refuses. A malformed answer, a second item or a |
| + second `userData` refuses too; the cost of a false refusal is the |
| + pin-back, as before. The group's lifecycle hook is checked as before (`hook`), |
| and the group ARN ties the record to this group. ASG-level settings |
| outside the launch template are not compared, as they never were for |
| the exact-template record. |
diff --git a/internal/grouprollaws/group.go b/internal/grouprollaws/group.go| index 290417d1b..45e06fe0c 100644 |
| --- a/internal/grouprollaws/group.go |
| +++ b/internal/grouprollaws/group.go |
| @@ -13,7 +13,6 @@ import ( |
| "math/rand/v2" |
| "net" |
| "regexp" |
| - "sort" |
| "strconv" |
| "strings" |
| "sync" |
| @@ -646,10 +645,10 @@ func (a *Adapter) TemplateRelease(ctx context.Context, tpl map[string]any) (stri |
| // TemplateData is one launch template version's data as the provider |
| // describes it, with UserData removed (spec §7.1): the evidence that two |
| // versions differ only in the release they boot. The SDK's decoder skips |
| -// XML elements it does not know (Astra r1), so the map carries, beside |
| -// the decoded fields, the answer's own launchTemplateData element in a |
| -// canonical form without userData ("LaunchTemplateDataXML"): a field this |
| -// SDK does not know still shows as a difference. |
| +// XML elements it does not know (Astra r1), so beside the decoded fields |
| +// the map carries the answer's own launchTemplateData element, byte for |
| +// byte with only its userData element cut ("LaunchTemplateDataXML"): any |
| +// other difference, a field this SDK does not know included, shows. |
| func (a *Adapter) TemplateData(ctx context.Context, tpl map[string]any) (map[string]any, error) { |
| version, ok := tpl["Version"].(string) |
| if tpl == nil || !ok { |
| @@ -680,7 +679,7 @@ func (a *Adapter) TemplateData(ctx context.Context, tpl map[string]any) (map[str |
| rows[0].LaunchTemplateData == nil { |
| return nil, malformed() |
| } |
| - canonical, ok := launchDataXML(body) |
| + exact, ok := launchDataXML(body) |
| if !ok { |
| return nil, malformed() |
| } |
| @@ -700,7 +699,7 @@ func (a *Adapter) TemplateData(ctx context.Context, tpl map[string]any) (map[str |
| return nil, malformed() |
| } |
| delete(m, "UserData") |
| - m["LaunchTemplateDataXML"] = canonical |
| + m["LaunchTemplateDataXML"] = exact |
| return m, nil |
| } |
| @@ -724,16 +723,20 @@ func captureBody(dst *[]byte) middleware.DeserializeMiddleware { |
| } |
| // launchDataXML is the single answered version's launchTemplateData |
| -// element, canonical: element local names, attributes sorted, text with |
| -// whitespace-only runs dropped, and its direct userData child removed. |
| -// Two versions that differ in any other element, known to this SDK or |
| -// not, give different strings. |
| +// element exactly as the provider sent it, byte for byte, with only its |
| +// direct userData child element cut out by its byte span (8a3d302, |
| +// 2026-11-11, after Astra r2): no canonical form, so any other difference |
| +// (a field this SDK does not know, its whitespace, CDATA, namespaces) |
| +// refuses. A second launchTemplateData, a second direct userData, or an |
| +// answer that is not well formed is not one ("", false). |
| func launchDataXML(body []byte) (string, bool) { |
| dec := xml.NewDecoder(bytes.NewReader(body)) |
| var path []string |
| - var b strings.Builder |
| - found, depth, skip := 0, 0, 0 |
| + found, depth := 0, 0 |
| + var start, end, udStart int64 = -1, -1, -1 |
| + var cuts [][2]int64 |
| for { |
| + before := dec.InputOffset() |
| tok, err := dec.Token() |
| if err == io.EOF { |
| break |
| @@ -746,25 +749,17 @@ func launchDataXML(body []byte) (string, bool) { |
| path = append(path, t.Name.Local) |
| if depth == 0 && strings.Join(path, "/") == "DescribeLaunchTemplateVersionsResponse/launchTemplateVersionSet/item/launchTemplateData" { |
| found++ |
| - depth = 1 |
| + depth, start = 1, dec.InputOffset() |
| continue |
| } |
| if depth > 0 { |
| depth++ |
| - if skip > 0 || (depth == 2 && t.Name.Local == "userData") { |
| - skip++ |
| - continue |
| - } |
| - attrs := make([]string, 0, len(t.Attr)) |
| - for _, a := range t.Attr { |
| - attrs = append(attrs, a.Name.Local+"="+strconv.Quote(a.Value)) |
| - } |
| - sort.Strings(attrs) |
| - b.WriteString("<" + t.Name.Local) |
| - for _, a := range attrs { |
| - b.WriteString(" " + a) |
| + if depth == 2 && t.Name.Local == "userData" { |
| + if len(cuts) > 0 || udStart >= 0 { |
| + return "", false |
| + } |
| + udStart = before |
| } |
| - b.WriteString(">") |
| } |
| case xml.EndElement: |
| if len(path) > 0 { |
| @@ -772,22 +767,27 @@ func launchDataXML(body []byte) (string, bool) { |
| } |
| if depth > 0 { |
| depth-- |
| - if depth == 0 { |
| - continue |
| + if depth == 1 && udStart >= 0 { |
| + cuts = append(cuts, [2]int64{udStart, dec.InputOffset()}) |
| + udStart = -1 |
| } |
| - if skip > 0 { |
| - skip-- |
| - continue |
| + if depth == 0 { |
| + end = before |
| } |
| - b.WriteString("</" + t.Name.Local + ">") |
| - } |
| - case xml.CharData: |
| - if depth > 1 && skip == 0 && strings.TrimSpace(string(t)) != "" { |
| - b.WriteString(strconv.Quote(string(t))) |
| } |
| } |
| } |
| - return b.String(), found == 1 |
| + if found != 1 || start < 0 || end < start || end > int64(len(body)) { |
| + return "", false |
| + } |
| + var b strings.Builder |
| + at := start |
| + for _, c := range cuts { |
| + b.Write(body[at:c[0]]) |
| + at = c[1] |
| + } |
| + b.Write(body[at:end]) |
| + return b.String(), true |
| } |
| func int32Of(n int) (int32, bool) { |
diff --git a/internal/grouprollaws/group_test.go b/internal/grouprollaws/group_test.go| index c742437f3..1ecd6a874 100644 |
| --- a/internal/grouprollaws/group_test.go |
| +++ b/internal/grouprollaws/group_test.go |
| @@ -594,42 +594,61 @@ func TestTemplateData(t *testing.T) { |
| } |
| } |
| -// A field this SDK does not know is skipped by its decoder, but it still |
| -// shows in TemplateData through the canonical launchTemplateData XML |
| -// (Astra r1): two versions differing only there are not equal. Layout |
| -// alone (whitespace between elements, attribute order) is not a |
| -// difference, and userData never is. |
| +// TemplateData's LaunchTemplateDataXML is the answer's launchTemplateData |
| +// exactly, only its direct userData element cut (Astra r1/r2): a field the |
| +// SDK does not know, its whitespace, CDATA or a layout difference all |
| +// show; the user data never does. A nested userData is kept. Two |
| +// answered versions, two userData elements or broken XML are malformed. |
| func TestTemplateDataUnknownField(t *testing.T) { |
| resp := func(version, data string) string { |
| return `<DescribeLaunchTemplateVersionsResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"><requestId>r</requestId><launchTemplateVersionSet><item><launchTemplateId>lt-0abc</launchTemplateId><versionNumber>` + |
| version + `</versionNumber><launchTemplateData>` + data + `</launchTemplateData></item></launchTemplateVersionSet></DescribeLaunchTemplateVersionsResponse>` |
| } |
| - get := func(version, data string) map[string]any { |
| + tpl := func(v string) map[string]any { |
| + return map[string]any{"LaunchTemplateId": "lt-0abc", "LaunchTemplateName": "carlos-dev", "Version": v} |
| + } |
| + get := func(version, data string) (map[string]any, error) { |
| + return testAdapter(t, newRecorder().on("DescribeLaunchTemplateVersions", resp(version, data))).TemplateData(ctx, tpl(version)) |
| + } |
| + must := func(version, data string) map[string]any { |
| t.Helper() |
| - d, err := testAdapter(t, newRecorder().on("DescribeLaunchTemplateVersions", resp(version, data))).TemplateData(ctx, |
| - map[string]any{"LaunchTemplateId": "lt-0abc", "LaunchTemplateName": "carlos-dev", "Version": version}) |
| + d, err := get(version, data) |
| if err != nil { |
| t.Fatal(err) |
| } |
| return d |
| } |
| - base := get("7", `<imageId>ami-0123</imageId><userData>QQ==</userData>`) |
| - same := get("8", "\n <imageId>ami-0123</imageId>\n <userData>Qg==</userData>\n") |
| - if !reflect.DeepEqual(base, same) { |
| - t.Fatalf("layout and user data only, yet %v != %v", base, same) |
| + base := must("7", `<imageId>ami-0123</imageId><userData>QQ==</userData><futureSetting></futureSetting>`) |
| + if got := base["LaunchTemplateDataXML"]; got != `<imageId>ami-0123</imageId><futureSetting></futureSetting>` { |
| + t.Fatalf("exact bytes %q", got) |
| + } |
| + if same := must("8", `<imageId>ami-0123</imageId><userData>Qg==</userData><futureSetting></futureSetting>`); !reflect.DeepEqual(base, same) { |
| + t.Fatalf("user data only, yet %v != %v", base, same) |
| } |
| - future := get("9", `<imageId>ami-0123</imageId><futureSetting>on</futureSetting><userData>QQ==</userData>`) |
| - if reflect.DeepEqual(base, future) { |
| - t.Fatalf("an unknown field went unseen: %v", future) |
| + for name, data := range map[string]string{ |
| + "unknown field": `<imageId>ami-0123</imageId><userData>QQ==</userData><futureSetting></futureSetting><other>x</other>`, |
| + "whitespace in a value": `<imageId>ami-0123</imageId><userData>QQ==</userData><futureSetting> </futureSetting>`, |
| + "cdata": `<imageId>ami-0123</imageId><userData>QQ==</userData><futureSetting><![CDATA[]]></futureSetting>`, |
| + "layout": "<imageId>ami-0123</imageId>\n<userData>QQ==</userData><futureSetting></futureSetting>", |
| + "nested userData": `<imageId>ami-0123</imageId><userData>QQ==</userData><futureSetting><userData>Q</userData></futureSetting>`, |
| + } { |
| + if d := must("9", data); reflect.DeepEqual(base, d) { |
| + t.Errorf("%s: no difference seen: %v", name, d["LaunchTemplateDataXML"]) |
| + } |
| } |
| - if base["LaunchTemplateDataXML"] != `<imageId>"ami-0123"</imageId>` { |
| - t.Fatalf("canonical %q", base["LaunchTemplateDataXML"]) |
| + for name, data := range map[string]string{ |
| + "two userData": `<imageId>ami-0123</imageId><userData>QQ==</userData><userData>QQ==</userData>`, |
| + } { |
| + if _, err := get("9", data); uncertainKey(t, err).Key != "api" { |
| + t.Errorf("%s: %v", name, err) |
| + } |
| } |
| - // Two answered versions, or none, is malformed. |
| two := strings.Replace(resp("7", `<imageId>a</imageId>`), "</launchTemplateVersionSet>", |
| `<item><launchTemplateData><imageId>b</imageId></launchTemplateData></item></launchTemplateVersionSet>`, 1) |
| - if _, err := testAdapter(t, newRecorder().on("DescribeLaunchTemplateVersions", two)).TemplateData(ctx, |
| - map[string]any{"LaunchTemplateId": "lt-0abc", "LaunchTemplateName": "carlos-dev", "Version": "7"}); uncertainKey(t, err).Key != "api" { |
| + if _, err := testAdapter(t, newRecorder().on("DescribeLaunchTemplateVersions", two)).TemplateData(ctx, tpl("7")); uncertainKey(t, err).Key != "api" { |
| t.Fatalf("two items: %v", err) |
| } |
| + if _, ok := launchDataXML([]byte(resp("7", `<imageId>a</imageId>`) + "<broken")); ok { |
| + t.Fatal("broken XML accepted") |
| + } |
| } |
diff --git a/internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv b/internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv| index 58ead0829..2bcecc5f1 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-group-observation-carry.tsv |
| @@ -7,4 +7,4 @@ internal/grouproll/engine.go Engine.preflight legacy accepted-legacy accepted-le |
| internal/grouproll/plan.go Engine.Plan legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads provider-observation.json from the operator's own 0700 state directory;rev3=census-ruling-group-verb-followups;basis=a missing or unreadable provider-observation.json is refused as observation instead of passing the read error through (same file, same read);rev3=census-ruling-group-observation-carry;basis=the same observation read and the same carry-over rule as preflight (two template_data provider reads); no new file read, nothing written file:Read@2300 e31735a42c7a49724f503b59406ced05c5e6d39038d8135b34c0ae463b36b415 |
| internal/grouprollaws/transport.go boundBody.HandleDeserialize legacy accepted-legacy accepted-legacy;rev3=census-ruling-group-roll-verb;basis=reads an AWS API answer body under the 4 MiB cap;rev3=census-ruling-group-observation-carry;basis=the same bounded read of the AWS answer; the buffered bytes are kept on a typed body (bufferedBody) so TemplateData can compare the raw launchTemplateData without a second read; no new read file:ReadAll@436 22970b4b6bdf5bd90b25183ee33b702ebfea6070781aa4bac9cd5f461fd17280 |
| @coverage internal/grouproll d0decee68f572b1fc022493d7721f5efdba74ddfe9b1438f78cf3aee716405c0 |
| -@coverage internal/grouprollaws 52b7cadf4843cdfd91a2fde8c2ac8db9ad5027c71c3cfb8c2cc135288d59928b |
| +@coverage internal/grouprollaws 13dc8722bbb49a68f075daaaa704ac6166236351d875f4b6dbd0cfb0c89f6b17 |