From bfef470420adcb211a30c046df62ea3c09e9151f Mon Sep 17 00:00:00 2001 From: Thomas Sudeep Benardo <36351384+be-thomas@users.noreply.github.com> Date: Mon, 26 Oct 2026 19:55:17 +0530 Subject: [PATCH 1/2] Report what the corpus proves, not its Terraform versions The README summary charted fixtures by their minimum Terraform version, which says nothing about whether anything converts. Measure the pipeline instead: parse every fixture, run both emitters over every graph that parsed, and report how many reach the IR, how many produce AWS CDK and Pulumi TypeScript, and how many of those need no warnings at all. status.json gains an emit section (schema 2) holding per-target module, emitted, failed, clean and warning counts. The README block becomes an outcome table with percentage bars, and the version distribution stays in the JSON without a chart. An emitter that succeeds with no files counts as a failure, and the badge turns red when either emitter fails. --- README.md | 25 ++- cmd/openiac-conformance/main.go | 6 +- conformance/status.json | 18 +- docs/CONFORMANCE.md | 36 ++- internal/conformance/status/status.go | 245 ++++++++++++--------- internal/conformance/status/status_test.go | 126 +++++++++-- 6 files changed, 306 insertions(+), 150 deletions(-) diff --git a/README.md b/README.md index 14aafb4..d2f5c7b 100644 --- a/README.md +++ b/README.md @@ -341,18 +341,23 @@ tree, its lock and the generated attribution on every pull request. [![conformance](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fbe-thomas%2FOpenIaC%2Fmain%2Fconformance%2Fbadge.json&style=flat-square)](conformance/status.json) -```mermaid -xychart-beta - title "Fixtures by minimum Terraform version" - x-axis ["1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "1.10", "1.11"] - y-axis "Fixtures" 0 --> 500 - bar [477, 34, 4, 168, 1, 117, 15, 3, 6, 9, 6, 13] -``` +**853 / 853 modules — 100% — reach the IR and emit both AWS CDK and Pulumi TypeScript.** + +| Outcome | Modules | Share | +|:--|--:|:--| +| Parsed to the universal IR | 853 | ████████████████████ 100% | +| IR → AWS CDK TypeScript | 853 | ████████████████████ 100% | +| IR → Pulumi TypeScript | 853 | ████████████████████ 100% | +| IR → AWS CDK, no warnings | 27 | ▏ 3% | +| IR → Pulumi, no warnings | 31 | ▏ 4% | -Every one of the 853 modules parses into schema `0.2` IR. The chart groups each -module by the oldest Terraform release its configuration needs; the exact -distribution is in [`conformance/status.json`](conformance/status.json), which +Every one of the 853 modules parses into schema `0.2` IR and produces non-empty +AWS CDK and Pulumi TypeScript. The last two rows are the honest part: only 27 +and 31 of them convert with no warnings at all, because an unmapped resource or +an unsupported block is reported rather than dropped. Exact counts, including +each module's minimum Terraform version, are in +[`conformance/status.json`](conformance/status.json), which `make conformance-status` regenerates and CI checks. ```bash diff --git a/cmd/openiac-conformance/main.go b/cmd/openiac-conformance/main.go index 70dbc18..712b252 100644 --- a/cmd/openiac-conformance/main.go +++ b/cmd/openiac-conformance/main.go @@ -244,7 +244,8 @@ func runStatus(args []string) error { if len(stale) > 0 { return fmt.Errorf("%s is stale: run `make conformance-status` and commit the result", strings.Join(stale, ", ")) } - fmt.Printf("status: %d/%d modules parse, summary current\n", report.Parse.Parsed, report.Parse.Modules) + fmt.Printf("status: %d/%d modules parse, %d/%d emit CDK, %d/%d emit Pulumi, summary current\n", + report.Parse.Parsed, report.Parse.Modules, report.Emit.CDK.Emitted, report.Emit.CDK.Modules, report.Emit.Pulumi.Emitted, report.Emit.Pulumi.Modules) return nil } @@ -263,7 +264,8 @@ func runStatus(args []string) error { if err := os.WriteFile(*readmePath, []byte(updated), 0o644); err != nil { return err } - fmt.Printf("status: %d/%d modules parse\n", report.Parse.Parsed, report.Parse.Modules) + fmt.Printf("status: %d/%d modules parse, %d/%d emit CDK, %d/%d emit Pulumi\n", + report.Parse.Parsed, report.Parse.Modules, report.Emit.CDK.Emitted, report.Emit.CDK.Modules, report.Emit.Pulumi.Emitted, report.Emit.Pulumi.Modules) fmt.Println(report.Markdown()) return nil } diff --git a/conformance/status.json b/conformance/status.json index facf3c1..1a486d6 100644 --- a/conformance/status.json +++ b/conformance/status.json @@ -1,5 +1,5 @@ { - "schema": 1, + "schema": 2, "corpus": { "fixtures": 853, "files": 6471, @@ -11,6 +11,22 @@ "parsed": 853, "failed": 0 }, + "emit": { + "cdk": { + "modules": 853, + "emitted": 853, + "failed": 0, + "clean": 27, + "warnings": 10669 + }, + "pulumi": { + "modules": 853, + "emitted": 853, + "failed": 0, + "clean": 31, + "warnings": 11774 + } + }, "min_versions": { "1.0.0": 468, "1.0.11": 3, diff --git a/docs/CONFORMANCE.md b/docs/CONFORMANCE.md index 812a01a..190bb5e 100644 --- a/docs/CONFORMANCE.md +++ b/docs/CONFORMANCE.md @@ -150,25 +150,43 @@ therefore fails verification instead of silently drifting. Provider, CloudFormation and Pulumi schemas are dependencies rather than source: they are pinned by lockfile and cached outside the tree. -### Parse summary +### Outcome summary -`openiac-conformance status` parses every fixture and writes three committed -files: [`status.json`](../conformance/status.json) holds the corpus size, the -parse counts and the minimum-version distribution, +`openiac-conformance status` parses every fixture, runs both emitters over every +graph that parsed, and writes three committed files: +[`status.json`](../conformance/status.json) holds the corpus size, the parse +counts, each emitter's results and the minimum-version distribution, [`badge.json`](../conformance/badge.json) is the shields.io endpoint the README -renders as a badge, and the chart between the `conformance:summary` markers in -the [`README`](../README.md) is regenerated in place. CI runs `status -check`, -so the summary cannot drift from the corpus without failing a pull request. +renders as a badge, and the outcome table between the `conformance:summary` +markers in the [`README`](../README.md) is regenerated in place. CI runs +`status -check`, so the summary cannot drift from the corpus without failing a +pull request. ```bash -make conformance-status # re-parse the corpus and rewrite all three +make conformance-status # re-parse, re-emit and rewrite all three make conformance-status-check # fail when the committed summary is stale ``` +The report separates three questions the corpus answers, because they fail +differently: + +| Field | Question | A regression means | +|:--|:--|:--| +| `parse.parsed` | Did the parser turn this module into IR? | The parser rejects valid Terraform | +| `emit..emitted` | Did the emitter produce non-empty TypeScript? | The emitter crashes or emits nothing | +| `emit..clean` | Did it do so without a warning? | Nothing broken — the module needs a human, which is the documented behaviour for unmapped constructs | + +`emitted + failed` partitions the modules each emitter was run on, and `clean` +is a subset of `emitted`. A module that fails to parse is never handed to an +emitter, so the two denominators differ when parsing regresses. Every emitted +module is expected to be non-empty: an emitter that succeeds with no file is +counted as a failure. + The minimum version is the oldest Terraform release a fixture needs, derived from its `required_version` constraint and the language features it uses (see [TERRAFORM-VERSIONS.md](TERRAFORM-VERSIONS.md)); it measures parse coverage, not -conversion completeness. +conversion completeness, and is kept in `status.json` rather than rendered in +the README. ### Sources diff --git a/internal/conformance/status/status.go b/internal/conformance/status/status.go index 8cfc81c..fa61501 100644 --- a/internal/conformance/status/status.go +++ b/internal/conformance/status/status.go @@ -1,5 +1,5 @@ -// Package status summarises how the parser handles the committed conformance -// corpus. +// Package status summarises how the parser and emitters handle the committed +// conformance corpus. // // The report is committed as conformance/status.json and rendered in the // README, so a reader can see what the corpus actually proves without running @@ -13,20 +13,23 @@ import ( "os" "path/filepath" "sort" - "strconv" "strings" + "github.com/be-thomas/openiac/pkg/emitters" + "github.com/be-thomas/openiac/pkg/engine" hclparser "github.com/be-thomas/openiac/pkg/parsers/hcl" ) -// Schema is the report format version. -const Schema = 1 +// Schema is the report format version. Version 2 added the emit counts. +const Schema = 2 -// Report is the committed snapshot of corpus size and parse results. +// Report is the committed snapshot of corpus size, parse results and what each +// emitter produced. type Report struct { Schema int `json:"schema"` Corpus Corpus `json:"corpus"` Parse Parse `json:"parse"` + Emit Emit `json:"emit"` MinVersions map[string]int `json:"min_versions"` } @@ -46,6 +49,24 @@ type Parse struct { Failures []string `json:"failures,omitempty"` } +// Emit counts what each emitter produced for the modules that parsed. +type Emit struct { + CDK EmitTarget `json:"cdk"` + Pulumi EmitTarget `json:"pulumi"` +} + +// EmitTarget is one emitter's result over the corpus. Emitted and Failed +// partition Modules, and Clean is a subset of Emitted: a module can compile but +// still need a human, which is what a warning means. +type EmitTarget struct { + Modules int `json:"modules"` + Emitted int `json:"emitted"` + Failed int `json:"failed"` + Clean int `json:"clean"` + Warnings int `json:"warnings"` + Failures []string `json:"failures,omitempty"` +} + // Badge is the shields.io endpoint document rendered in the README. type Badge struct { SchemaVersion int `json:"schemaVersion"` @@ -68,8 +89,9 @@ type lock struct { TreeSHA256 string `json:"treeSha256"` } -// Compute parses every fixture input under fixturesDir. It reads the lock for -// the aggregate sizes but never writes anything. +// Compute parses every fixture input under fixturesDir and runs both emitters +// over every graph that parsed. It reads the lock for the aggregate sizes but +// never writes anything. func Compute(fixturesDir, lockPath string) (Report, error) { report := Report{Schema: Schema, MinVersions: map[string]int{}} @@ -93,21 +115,69 @@ func Compute(fixturesDir, lockPath string) (Report, error) { return report, err } report.Parse.Modules = len(inputs) + + targets := []struct { + target engine.Target + stats *EmitTarget + }{ + {engine.TargetCDK, &report.Emit.CDK}, + {engine.TargetPulumi, &report.Emit.Pulumi}, + } + for _, dir := range inputs { graph, err := hclparser.ParseDir(dir) if err != nil { report.Parse.Failed++ - if len(report.Parse.Failures) < maxFailures { - report.Parse.Failures = append(report.Parse.Failures, fmt.Sprintf("%s: %v", filepath.ToSlash(trim(fixturesDir, dir)), err)) - } + addFailure(&report.Parse.Failures, fixturesDir, dir, err) continue } report.Parse.Parsed++ report.MinVersions[graph.MinVersion]++ + + for _, t := range targets { + t.stats.Modules++ + results, err := engine.Convert(graph, []engine.Target{t.target}, emitters.Options{}) + if err == nil && len(results) == 0 { + err = fmt.Errorf("%s emitter returned no result", t.target) + } + if err == nil && !hasContent(results[0].Files) { + err = fmt.Errorf("%s emitter produced no files", t.target) + } + if err != nil { + t.stats.Failed++ + addFailure(&t.stats.Failures, fixturesDir, dir, err) + continue + } + t.stats.Emitted++ + warnings := results[0].Warnings + t.stats.Warnings += len(warnings) + if len(warnings) == 0 { + t.stats.Clean++ + } + } } return report, nil } +// addFailure records a capped, repository-relative failure message. +func addFailure(failures *[]string, root, dir string, err error) { + if len(*failures) >= maxFailures { + return + } + *failures = append(*failures, fmt.Sprintf("%s: %v", filepath.ToSlash(trim(root, dir)), err)) +} + +// hasContent reports whether an emitter produced any non-empty file. An emitter +// that "succeeds" with nothing to show has not converted the module. +func hasContent(files []emitters.File) bool { + for _, file := range files { + if len(file.Content) > 0 { + return true + } + } + return false +} + // fixtureInputs lists every fixture module root in deterministic order. func fixtureInputs(root string) ([]string, error) { var inputs []string @@ -146,128 +216,83 @@ func (r Report) Badge() Badge { Message: fmt.Sprintf("%d / %d modules", r.Parse.Parsed, r.Parse.Modules), Color: "brightgreen", } - if r.Parse.Failed > 0 { + if r.Parse.Failed > 0 || r.Emit.CDK.Failed > 0 || r.Emit.Pulumi.Failed > 0 { badge.Color = "red" } return badge } -// VersionRows returns the minimum Terraform versions present, oldest first, -// with the fixture count for each. -func (r Report) VersionRows() []VersionCount { - return sortedRows(r.MinVersions) -} - -// MinorRows aggregates the distribution by MAJOR.MINOR, which is the -// resolution that reads well in a chart: patch releases come from individual -// modules' required_version pins, not from language differences. -func (r Report) MinorRows() []VersionCount { - counts := make(map[string]int, len(r.MinVersions)) - for version, count := range r.MinVersions { - counts[minor(version)] += count - } - return sortedRows(counts) +// Total is the denominator for every outcome: a module that fails before an +// emitter runs still counts against it. +func (r Report) Total() int { + return r.Parse.Modules } -func sortedRows(counts map[string]int) []VersionCount { - rows := make([]VersionCount, 0, len(counts)) - for version, count := range counts { - rows = append(rows, VersionCount{Version: version, Fixtures: count}) - } - sort.Slice(rows, func(i, j int) bool { return lessVersion(rows[i].Version, rows[j].Version) }) - return rows +// Outcome is one row of the generated summary. +type Outcome struct { + Label string + Count int } -// minor reduces "1.10.2" to "1.10". -func minor(version string) string { - parts := strings.Split(version, ".") - if len(parts) < 2 { - return version +// Outcomes lists what the corpus proves in pipeline order: the module reached +// the IR, then each emitter, then whether that output still needed a human. The +// same module counts in several rows, so the rows are not a partition. +func (r Report) Outcomes() []Outcome { + return []Outcome{ + {"Parsed to the universal IR", r.Parse.Parsed}, + {"IR → AWS CDK TypeScript", r.Emit.CDK.Emitted}, + {"IR → Pulumi TypeScript", r.Emit.Pulumi.Emitted}, + {"IR → AWS CDK, no warnings", r.Emit.CDK.Clean}, + {"IR → Pulumi, no warnings", r.Emit.Pulumi.Clean}, } - return parts[0] + "." + parts[1] -} - -// VersionCount is one row of the minimum-version distribution. -type VersionCount struct { - Version string - Fixtures int } -// lessVersion orders dotted version strings numerically, then as text so the -// order is total even for unexpected values. -func lessVersion(a, b string) bool { - as := strings.Split(a, ".") - bs := strings.Split(b, ".") - for i := 0; i < len(as) && i < len(bs); i++ { - an, aerr := strconv.Atoi(as[i]) - bn, berr := strconv.Atoi(bs[i]) - if aerr == nil && berr == nil { - if an != bn { - return an < bn - } - continue - } - if as[i] != bs[i] { - return as[i] < bs[i] - } - } - return len(as) < len(bs) -} - -// Markdown renders the distribution as a table with inline bars, for the README -// and for `openiac-conformance status`. +// Markdown renders the outcomes as a table with inline bars, for the README and +// for `openiac-conformance status`. func (r Report) Markdown() string { + total := r.Total() var b strings.Builder - b.WriteString("| Minimum Terraform | Fixtures | Share |\n") + b.WriteString("| Outcome | Modules | Share |\n") b.WriteString("|:--|--:|:--|\n") - total := r.Parse.Parsed - for _, row := range r.MinorRows() { - share := 0 - if total > 0 { - share = row.Fixtures * 100 / total - } - bar := strings.Repeat("█", share/2) - if bar == "" && row.Fixtures > 0 { - bar = "▏" - } - fmt.Fprintf(&b, "| `%s` | %d | %s %d%% |\n", row.Version, row.Fixtures, bar, share) + for _, row := range r.Outcomes() { + fmt.Fprintf(&b, "| %s | %d | %s |\n", row.Label, row.Count, share(row.Count, total)) } return b.String() } -// Mermaid renders the distribution as a GitHub-renderable bar chart. -func (r Report) Mermaid() string { - rows := r.MinorRows() - labels := make([]string, 0, len(rows)) - bars := make([]string, 0, len(rows)) - max := 0 - for _, row := range rows { - labels = append(labels, fmt.Sprintf("%q", row.Version)) - bars = append(bars, fmt.Sprintf("%d", row.Fixtures)) - if row.Fixtures > max { - max = row.Fixtures - } +// share is the percentage with a bar whose length is the percentage: 20 cells +// for 100%, at least one for any non-zero count. +func share(count, total int) string { + if count <= 0 || total <= 0 { + return "0%" } - var b strings.Builder - b.WriteString("```mermaid\nxychart-beta\n") - b.WriteString(" title \"Fixtures by minimum Terraform version\"\n") - fmt.Fprintf(&b, " x-axis [%s]\n", strings.Join(labels, ", ")) - fmt.Fprintf(&b, " y-axis \"Fixtures\" 0 --> %d\n", axisMax(max)) - fmt.Fprintf(&b, " bar [%s]\n", strings.Join(bars, ", ")) - b.WriteString("```\n") - return b.String() + pct := percent(count, total) + cells := pct / 5 + if cells == 0 { + return fmt.Sprintf("▏ %d%%", pct) + } + return fmt.Sprintf("%s %d%%", strings.Repeat("█", cells), pct) +} + +// percent rounds to the nearest whole percentage so 27/853 reads as 3%, not 0%. +func percent(count, total int) int { + if total <= 0 { + return 0 + } + return (count*100 + total/2) / total } -// axisMax rounds the chart's y-axis up to a readable bound. -func axisMax(max int) int { - if max <= 0 { - return 10 +// headline states the result in one sentence above the table. +func (r Report) headline() string { + total := r.Total() + if total == 0 { + return "_The corpus is empty._" } - step := 10 - for step*10 < max { - step *= 10 + if r.Parse.Parsed == total && r.Emit.CDK.Emitted == total && r.Emit.Pulumi.Emitted == total { + return fmt.Sprintf("**%d / %d modules — 100%% — reach the IR and emit both AWS CDK and Pulumi TypeScript.**", total, total) } - return (max/step + 1) * step + return fmt.Sprintf("**%d / %d modules reach the IR, %d / %d reach AWS CDK and %d / %d reach Pulumi.**", + r.Parse.Parsed, total, r.Emit.CDK.Emitted, total, r.Emit.Pulumi.Emitted, total) } // Section markers delimit the generated block in README.md. @@ -279,7 +304,7 @@ const ( // Section renders the generated README block, markers included and without a // trailing newline: the document keeps the one after the closing marker. func (r Report) Section() string { - return SectionStart + "\n" + r.Mermaid() + SectionEnd + return SectionStart + "\n" + r.headline() + "\n\n" + r.Markdown() + SectionEnd } // ExtractSection returns the marked block of document. diff --git a/internal/conformance/status/status_test.go b/internal/conformance/status/status_test.go index dc68994..90324dd 100644 --- a/internal/conformance/status/status_test.go +++ b/internal/conformance/status/status_test.go @@ -25,6 +25,14 @@ func TestComputeCountsParsedModules(t *testing.T) { if report.Parse.Modules != 1 || report.Parse.Parsed != 1 || report.Parse.Failed != 0 { t.Fatalf("parse = %+v, want 1/1 with no failures", report.Parse) } + for name, target := range map[string]status.EmitTarget{"cdk": report.Emit.CDK, "pulumi": report.Emit.Pulumi} { + if target.Modules != 1 || target.Emitted != 1 || target.Failed != 0 { + t.Errorf("%s emit = %+v, want 1/1 with no failures", name, target) + } + if target.Clean != 1 || target.Warnings != 0 { + t.Errorf("%s clean = %d with %d warnings, want a warning-free module", name, target.Clean, target.Warnings) + } + } if got := report.MinVersions["1.0.0"]; got != 1 { t.Errorf("min_versions[1.0.0] = %d, want 1 (%v)", got, report.MinVersions) } @@ -36,6 +44,33 @@ func TestComputeCountsParsedModules(t *testing.T) { } } +// A module that emits with a warning still counts as emitted, but not as clean: +// the warning is what tells a reader a human is needed. +func TestComputeSeparatesEmittedFromClean(t *testing.T) { + root := t.TempDir() + fixtures := filepath.Join(root, "fixtures") + writeModule(t, fixtures, "registry/aws/scaled/1.0.0/input", `resource "aws_instance" "web" { + count = 2 + ami = "ami-0123456789abcdef0" + instance_type = "t3.micro" +} +`) + lock := writeLock(t, root, `{"fixtureCount":1,"fileCount":1,"totalBytes":1,"treeSha256":"abc"}`) + + report, err := status.Compute(fixtures, lock) + if err != nil { + t.Fatalf("Compute: %v", err) + } + for name, target := range map[string]status.EmitTarget{"cdk": report.Emit.CDK, "pulumi": report.Emit.Pulumi} { + if target.Emitted != 1 { + t.Fatalf("%s emitted = %d, want 1", name, target.Emitted) + } + if target.Clean != 0 || target.Warnings == 0 { + t.Errorf("%s clean = %d with %d warnings, want a warned module", name, target.Clean, target.Warnings) + } + } +} + func TestComputeReportsFailures(t *testing.T) { root := t.TempDir() fixtures := filepath.Join(root, "fixtures") @@ -52,42 +87,94 @@ func TestComputeReportsFailures(t *testing.T) { if len(report.Parse.Failures) != 1 || !strings.Contains(report.Parse.Failures[0], "broken/1.0.0/input") { t.Errorf("failures = %v, want the fixture path", report.Parse.Failures) } + // A module that never parsed was never handed to an emitter. + if report.Emit.CDK.Modules != 0 || report.Emit.Pulumi.Modules != 0 { + t.Errorf("emit = %+v, want no attempts for an unparsed module", report.Emit) + } if got := report.Badge().Color; got != "red" { t.Errorf("badge color = %q, want red", got) } } -func TestMinorRowsAggregateAndSort(t *testing.T) { +func TestBadgeIsRedWhenAnEmitterFails(t *testing.T) { report := status.Report{ - Parse: status.Parse{Modules: 6, Parsed: 6}, - MinVersions: map[string]int{ - "1.10.0": 2, - "1.9.0": 1, - "1.0.0": 3, + Parse: status.Parse{Modules: 3, Parsed: 3}, + Emit: status.Emit{CDK: status.EmitTarget{Modules: 3, Emitted: 2, Failed: 1}}, + } + if got := report.Badge().Color; got != "red" { + t.Errorf("badge color = %q, want red", got) + } +} + +func TestOutcomesRenderPipelineOrder(t *testing.T) { + report := status.Report{ + Parse: status.Parse{Modules: 100, Parsed: 100}, + Emit: status.Emit{ + CDK: status.EmitTarget{Modules: 100, Emitted: 98, Failed: 2, Clean: 25, Warnings: 300}, + Pulumi: status.EmitTarget{Modules: 100, Emitted: 100, Clean: 2, Warnings: 120}, }, } - rows := report.MinorRows() - want := []status.VersionCount{{Version: "1.0", Fixtures: 3}, {Version: "1.9", Fixtures: 1}, {Version: "1.10", Fixtures: 2}} - if len(rows) != len(want) { - t.Fatalf("rows = %v, want %v", rows, want) + want := []status.Outcome{ + {Label: "Parsed to the universal IR", Count: 100}, + {Label: "IR → AWS CDK TypeScript", Count: 98}, + {Label: "IR → Pulumi TypeScript", Count: 100}, + {Label: "IR → AWS CDK, no warnings", Count: 25}, + {Label: "IR → Pulumi, no warnings", Count: 2}, + } + got := report.Outcomes() + if len(got) != len(want) { + t.Fatalf("outcomes = %v, want %v", got, want) } for i := range want { - if rows[i] != want[i] { - t.Fatalf("rows = %v, want %v", rows, want) + if got[i] != want[i] { + t.Fatalf("outcomes = %v, want %v", got, want) } } - chart := report.Mermaid() - for _, token := range []string{`x-axis ["1.0", "1.9", "1.10"]`, "bar [3, 1, 2]", "y-axis \"Fixtures\" 0 --> 10"} { - if !strings.Contains(chart, token) { - t.Errorf("chart missing %q:\n%s", token, chart) + table := report.Markdown() + for _, row := range []string{ + "| Parsed to the universal IR | 100 | ████████████████████ 100% |", + "| IR → AWS CDK TypeScript | 98 | ███████████████████ 98% |", + "| IR → AWS CDK, no warnings | 25 | █████ 25% |", + "| IR → Pulumi, no warnings | 2 | ▏ 2% |", + } { + if !strings.Contains(table, row) { + t.Errorf("table missing %q:\n%s", row, table) } } + if strings.Contains(table, "Terraform") { + t.Errorf("table still describes the version distribution:\n%s", table) + } +} + +func TestSectionHeadline(t *testing.T) { + full := status.Report{ + Parse: status.Parse{Modules: 2, Parsed: 2}, + Emit: status.Emit{ + CDK: status.EmitTarget{Modules: 2, Emitted: 2}, + Pulumi: status.EmitTarget{Modules: 2, Emitted: 2}, + }, + } + if want := "**2 / 2 modules — 100% — reach the IR and emit both AWS CDK and Pulumi TypeScript.**"; !strings.Contains(full.Section(), want) { + t.Errorf("section missing %q:\n%s", want, full.Section()) + } + + partial := status.Report{ + Parse: status.Parse{Modules: 4, Parsed: 3}, + Emit: status.Emit{ + CDK: status.EmitTarget{Modules: 3, Emitted: 2}, + Pulumi: status.EmitTarget{Modules: 3, Emitted: 3}, + }, + } + if want := "**3 / 4 modules reach the IR, 2 / 4 reach AWS CDK and 3 / 4 reach Pulumi.**"; !strings.Contains(partial.Section(), want) { + t.Errorf("section missing %q:\n%s", want, partial.Section()) + } } func TestSectionRoundTrip(t *testing.T) { report := status.Report{ Parse: status.Parse{Modules: 2, Parsed: 2}, + Emit: status.Emit{CDK: status.EmitTarget{Modules: 2, Emitted: 2}, Pulumi: status.EmitTarget{Modules: 2, Emitted: 2}}, MinVersions: map[string]int{"1.0.0": 1, "1.5.0": 1}, } header := "# Title\n\nIntro.\n\n" @@ -101,10 +188,13 @@ func TestSectionRoundTrip(t *testing.T) { if section != report.Section() { t.Fatalf("ExtractSection = %q, want the generated section", section) } + if !strings.HasSuffix(section, status.SectionEnd) { + t.Errorf("section does not end with the closing marker:\n%s", section) + } updated := status.Report{ - Parse: status.Parse{Modules: 2, Parsed: 2}, - MinVersions: map[string]int{"1.0.0": 2}, + Parse: status.Parse{Modules: 2, Parsed: 2}, + Emit: status.Emit{CDK: status.EmitTarget{Modules: 2, Emitted: 1}, Pulumi: status.EmitTarget{Modules: 2, Emitted: 2}}, } replaced, err := status.ReplaceSection(document, updated.Section()) if err != nil { From 0921fdc57e925e7921cb0a24394e9f7f5b3ecb83 Mon Sep 17 00:00:00 2001 From: Thomas Sudeep Benardo <36351384+be-thomas@users.noreply.github.com> Date: Mon, 26 Oct 2026 20:33:24 +0530 Subject: [PATCH 2/2] Clamp partial shares and keep failure paths relative A stage that converted 852 of 853 modules rounded up to 100% and drew a full bar beside the failed module; one module of 853 rounded down to nothing. Percentages now clamp to 1-99 for a partial result. Failure messages quoted the path they were given, so an absolute -out put a checkout-specific path in the committed report and made the staleness check depend on where the tree lives. The fixtures root is now trimmed from the message as well as from the location. The emitter-failure branch of Compute had no test. A dependency cycle parses but fails in both emitters, which now covers the partitioning, the recorded failure and the red badge; the badge test also covers a Pulumi-only failure. --- README.md | 2 +- internal/conformance/status/status.go | 35 +++++++- internal/conformance/status/status_test.go | 99 +++++++++++++++++++++- 3 files changed, 127 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d2f5c7b..1b28d34 100644 --- a/README.md +++ b/README.md @@ -356,7 +356,7 @@ Every one of the 853 modules parses into schema `0.2` IR and produces non-empty AWS CDK and Pulumi TypeScript. The last two rows are the honest part: only 27 and 31 of them convert with no warnings at all, because an unmapped resource or an unsupported block is reported rather than dropped. Exact counts, including -each module's minimum Terraform version, are in +the distribution of each module's minimum Terraform version, are in [`conformance/status.json`](conformance/status.json), which `make conformance-status` regenerates and CI checks. diff --git a/internal/conformance/status/status.go b/internal/conformance/status/status.go index fa61501..a8ca737 100644 --- a/internal/conformance/status/status.go +++ b/internal/conformance/status/status.go @@ -159,12 +159,27 @@ func Compute(fixturesDir, lockPath string) (Report, error) { return report, nil } -// addFailure records a capped, repository-relative failure message. +// addFailure records a capped failure message with the fixture path relative to +// the fixtures root. The error itself usually quotes the paths it was given, so +// they are trimmed too: an absolute -out would otherwise put a checkout-specific +// path in the committed report and make -check depend on where the tree lives. func addFailure(failures *[]string, root, dir string, err error) { if len(*failures) >= maxFailures { return } - *failures = append(*failures, fmt.Sprintf("%s: %v", filepath.ToSlash(trim(root, dir)), err)) + *failures = append(*failures, fmt.Sprintf("%s: %s", filepath.ToSlash(trim(root, dir)), relativize(err.Error(), root))) +} + +// relativize drops the fixtures root from a message. Both separator forms are +// handled so the report stays portable across platforms. +func relativize(message, root string) string { + if root == "" { + return message + } + for _, prefix := range []string{filepath.ToSlash(root) + "/", root + string(filepath.Separator)} { + message = strings.ReplaceAll(message, prefix, "") + } + return message } // hasContent reports whether an emitter produced any non-empty file. An emitter @@ -275,11 +290,23 @@ func share(count, total int) string { } // percent rounds to the nearest whole percentage so 27/853 reads as 3%, not 0%. +// A partial result is clamped to 1–99: rounding 852/853 to 100% would print a +// full bar beside a failed module, and 1/853 must not read as nothing at all. func percent(count, total int) int { - if total <= 0 { + if count <= 0 || total <= 0 { return 0 } - return (count*100 + total/2) / total + if count >= total { + return 100 + } + pct := (count*100 + total/2) / total + if pct < 1 { + return 1 + } + if pct > 99 { + return 99 + } + return pct } // headline states the result in one sentence above the table. diff --git a/internal/conformance/status/status_test.go b/internal/conformance/status/status_test.go index 90324dd..80c138f 100644 --- a/internal/conformance/status/status_test.go +++ b/internal/conformance/status/status_test.go @@ -96,16 +96,82 @@ func TestComputeReportsFailures(t *testing.T) { } } -func TestBadgeIsRedWhenAnEmitterFails(t *testing.T) { - report := status.Report{ - Parse: status.Parse{Modules: 3, Parsed: 3}, - Emit: status.Emit{CDK: status.EmitTarget{Modules: 3, Emitted: 2, Failed: 1}}, +func TestComputeReportsEmitterFailures(t *testing.T) { + root := t.TempDir() + fixtures := filepath.Join(root, "fixtures") + writeModule(t, fixtures, "registry/aws/cycle/1.0.0/input", `resource "aws_s3_bucket" "a" { + bucket = aws_s3_bucket.b.id +} + +resource "aws_s3_bucket" "b" { + bucket = aws_s3_bucket.a.id +} +`) + lock := writeLock(t, root, `{"fixtureCount":1,"fileCount":1,"totalBytes":1,"treeSha256":"abc"}`) + + report, err := status.Compute(fixtures, lock) + if err != nil { + t.Fatalf("Compute: %v", err) + } + // The cycle only appears when the graph is ordered for an emitter, so the + // module parses and fails downstream: the emitter branch is reachable. + if report.Parse.Parsed != 1 || report.Parse.Failed != 0 { + t.Fatalf("parse = %+v, want the cyclic module to parse", report.Parse) + } + for name, target := range map[string]status.EmitTarget{"cdk": report.Emit.CDK, "pulumi": report.Emit.Pulumi} { + if target.Modules != 1 || target.Emitted != 0 || target.Failed != 1 { + t.Fatalf("%s emit = %+v, want one failed module", name, target) + } + if target.Emitted+target.Failed != target.Modules { + t.Errorf("%s emitted + failed = %d, want the module count %d", name, target.Emitted+target.Failed, target.Modules) + } + if len(target.Failures) != 1 || !strings.Contains(target.Failures[0], "cycle") { + t.Errorf("%s failures = %v, want the dependency cycle", name, target.Failures) + } } if got := report.Badge().Color; got != "red" { t.Errorf("badge color = %q, want red", got) } } +// The fixtures root can be absolute (-out is a path flag), but the committed +// report must not be: -check would then fail on a tree checked out elsewhere. +func TestComputeKeepsFailurePathsRelative(t *testing.T) { + root := t.TempDir() + fixtures := filepath.Join(root, "fixtures") + writeModule(t, fixtures, "registry/aws/broken/1.0.0/input", "resource \"aws_s3_bucket\" {\n") + lock := writeLock(t, root, `{"fixtureCount":1,"fileCount":1,"totalBytes":1,"treeSha256":"abc"}`) + + report, err := status.Compute(fixtures, lock) + if err != nil { + t.Fatalf("Compute: %v", err) + } + if len(report.Parse.Failures) != 1 { + t.Fatalf("failures = %v, want exactly one", report.Parse.Failures) + } + failure := report.Parse.Failures[0] + if strings.Contains(failure, root) { + t.Errorf("failure quotes the absolute fixtures root: %s", failure) + } + if !strings.HasPrefix(failure, "registry/aws/broken/1.0.0/input: ") { + t.Errorf("failure = %q, want it to start with the relative fixture path", failure) + } +} + +func TestBadgeIsRedWhenAnEmitterFails(t *testing.T) { + ok := status.EmitTarget{Modules: 3, Emitted: 3} + failing := status.EmitTarget{Modules: 3, Emitted: 2, Failed: 1} + for name, emit := range map[string]status.Emit{ + "cdk": {CDK: failing, Pulumi: ok}, + "pulumi": {CDK: ok, Pulumi: failing}, + } { + report := status.Report{Parse: status.Parse{Modules: 3, Parsed: 3}, Emit: emit} + if got := report.Badge().Color; got != "red" { + t.Errorf("%s: badge color = %q, want red", name, got) + } + } +} + func TestOutcomesRenderPipelineOrder(t *testing.T) { report := status.Report{ Parse: status.Parse{Modules: 100, Parsed: 100}, @@ -147,6 +213,31 @@ func TestOutcomesRenderPipelineOrder(t *testing.T) { } } +func TestMarkdownNeverRoundsPastAPartialResult(t *testing.T) { + report := status.Report{ + Parse: status.Parse{Modules: 853, Parsed: 853}, + Emit: status.Emit{ + CDK: status.EmitTarget{Modules: 853, Emitted: 852, Failed: 1, Clean: 1}, + Pulumi: status.EmitTarget{Modules: 853, Emitted: 853, Clean: 0}, + }, + } + table := report.Markdown() + for _, row := range []string{ + // 852 of 853 must not read as a finished stage with a full bar. + "| IR → AWS CDK TypeScript | 852 | ███████████████████ 99% |", + // One module is a real result, not nothing. + "| IR → AWS CDK, no warnings | 1 | ▏ 1% |", + "| IR → Pulumi, no warnings | 0 | 0% |", + } { + if !strings.Contains(table, row) { + t.Errorf("table missing %q:\n%s", row, table) + } + } + if strings.Contains(table, "852 | ████████████████████ 100%") { + t.Errorf("a partial corpus still renders as complete:\n%s", table) + } +} + func TestSectionHeadline(t *testing.T) { full := status.Report{ Parse: status.Parse{Modules: 2, Parsed: 2},