this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

internal/cuetxtar: simplify regression guard for @test(eq) mismatches

Previously, CUE_UPDATE=1 on a failing @test(eq) would annotate it with
skip:<ver> and diff="..." to keep the test passing while tracking the
discrepancy. This was confusing and overloaded CUE_UPDATE=1.

New semantics:
- CUE_UPDATE=1 + failure: the test just fails (no modification)
- CUE_UPDATE=force + failure: annotates with skip:<ver> only (no diff=)
- CUE_UPDATE=1 + skip:<ver> now passes: removes the skip annotation

Remove the unused diff= annotation format and the CUE_UPDATE=diff mode
reference from the handleErrorsTxtSection comment.

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: I1175f547d44a144698d7c4f27a0c830b782ddd9a
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1234943
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+21 -30
+11 -11
doc/specs/inline-test-attributes/spec.md
··· 609 609 --- 610 610 611 611 ### Requirement: Regression guard for failing `eq` assertions 612 - When `CUE_UPDATE=1` is set and an `eq` assertion **fails** (genuine mismatch), the runner SHALL NOT silently overwrite the expected value. Instead it SHALL annotate the attribute with `skip:<version>` and `diff="..."` arguments that record the discrepancy without changing the nominal expected value. The test is then effectively skipped for that version. 612 + When `CUE_UPDATE=1` is set and an `eq` assertion **fails** (genuine mismatch), the runner SHALL fail the test. It SHALL NOT silently overwrite or skip the expected value. 613 613 614 - `CUE_UPDATE=force` (`CUE_UPDATE=force` env value) SHALL overwrite the expected value unconditionally, regardless of whether it was passing before. 614 + `CUE_UPDATE=force` SHALL annotate the attribute with `skip:<version>` to mark the discrepancy and let the test pass while the difference is tracked. The nominal expected value is preserved; only the skip marker is added. 615 615 616 - When a previously-failing (skip-annotated) assertion now passes again under `CUE_UPDATE=1`, the runner SHALL remove the stale `skip:` and `diff=` arguments, restoring the plain `@test(eq, <expr>)` form. 616 + When a `skip`-annotated assertion now passes again under `CUE_UPDATE=1`, the runner SHALL remove the stale `skip:` argument, restoring the plain `@test(eq, <expr>)` form. 617 617 618 - #### Scenario: Record failing assertion as regression guard 618 + #### Scenario: Failing assertion is an error under CUE_UPDATE=1 619 619 - **WHEN** `@test(eq, 42)` fails because the value is `43` and `CUE_UPDATE=1` is set 620 - - **THEN** the attribute is rewritten to `@test(eq, 42, skip:v3, diff="got 43; want 42")` in the source file 621 - 622 - #### Scenario: Remove stale skip on recovery 623 - - **WHEN** `@test(eq, 42, skip:v3, diff="got 43; want 42")` now passes and `CUE_UPDATE=1` is set 624 - - **THEN** the `skip:v3` and `diff=` arguments are removed, leaving `@test(eq, 42)` 620 + - **THEN** the test fails; the source file is NOT modified 625 621 626 - #### Scenario: Force overwrite with CUE_UPDATE=force 622 + #### Scenario: Mark failing assertion with CUE_UPDATE=force 627 623 - **WHEN** `@test(eq, 42)` fails because the value is `43` and `CUE_UPDATE=force` is set 628 - - **THEN** the attribute is rewritten to `@test(eq, 43)` unconditionally 624 + - **THEN** the attribute is rewritten to `@test(eq, 42, skip:v3)` so the test is skipped for that version 625 + 626 + #### Scenario: Remove stale skip on recovery 627 + - **WHEN** `@test(eq, 42, skip:v3)` now passes and `CUE_UPDATE=1` is set 628 + - **THEN** the `skip:v3` argument is removed, leaving `@test(eq, 42)` 629 629 630 630 --- 631 631
+7 -16
internal/cuetxtar/inline.go
··· 707 707 // handleErrorsTxtSection manages the out/errors.txt documentary section. 708 708 // The section is only processed if it already exists in the archive: 709 709 // - CUE_UPDATE=1: updates the section with current error output 710 - // - CUE_UPDATE=diff: fails if the section is stale, showing a diff 711 710 // - otherwise: silently skips any difference 712 711 func (r *inlineRunner) handleErrorsTxtSection(val cue.Value) { 713 712 const sectionName = "out/errors.txt" ··· 1119 1118 return 1120 1119 } 1121 1120 1122 - // Detect stale-skip: a prior regression guard annotated this attr with 1123 - // skip:<ver> and diff="...". 1121 + // Detect stale-skip: a prior CUE_UPDATE=force annotated this attr with 1122 + // skip:<ver> to mark a known discrepancy. 1124 1123 _, hasSkip := attrHasSkip(pa.raw) 1125 1124 1126 1125 cmpErr := (&cmpCtx{baseLine: 0}).astCmp(cue.Path{}, expr, val) 1127 1126 if cmpErr == nil { 1128 1127 // Assertion passes via AST comparison. 1129 1128 if hasSkip && cuetest.UpdateGoldenFiles { 1130 - // Stale-skip cleanup (task 11.7): the assertion now passes; strip 1131 - // the skip and diff args, restoring the plain @test(eq, <expr>). 1129 + // Stale-skip cleanup: the assertion now passes; strip skip, 1130 + // restoring the plain @test(eq, <expr>). 1132 1131 r.enqueueInlineFill(pa, "@test(eq, "+exprStr+")") 1133 1132 } 1134 1133 return ··· 1136 1135 1137 1136 // Comparison failed — genuine mismatch. 1138 1137 if cuetest.ForceUpdateGoldenFiles { 1139 - // Force overwrite (task 11.4): replace expected with actual. 1140 - r.enqueueInlineFill(pa, "@test(eq, "+r.formatValue(val)+")") 1141 - return 1142 - } 1143 - if cuetest.UpdateGoldenFiles && !hasSkip { 1144 - // Regression guard (tasks 11.2-11.3): annotate with skip:<ver>+diff 1145 - // so the test keeps passing under CUE_UPDATE without silent overwrite. 1146 - got := r.formatValue(val) 1147 - diffStr := fmt.Sprintf("got %s; want %s", got, exprStr) 1148 - escaped := strings.ReplaceAll(diffStr, `"`, `\"`) 1138 + // CUE_UPDATE=force: annotate with skip:<ver> so the test keeps passing 1139 + // while the discrepancy is tracked, without silently overwriting. 1149 1140 ver := r.versionName() 1150 1141 if ver == "" { 1151 1142 ver = "unknown" 1152 1143 } 1153 - r.enqueueInlineFill(pa, fmt.Sprintf(`@test(eq, %s, skip:%s, diff="%s")`, exprStr, ver, escaped)) 1144 + r.enqueueInlineFill(pa, fmt.Sprintf(`@test(eq, %s, skip:%s)`, exprStr, ver)) 1154 1145 return 1155 1146 } 1156 1147 // Report the failure (unless already annotated with a skip).
+3 -3
internal/cuetxtar/writeback.go
··· 30 30 "cuelang.org/go/cue" 31 31 ) 32 32 33 - // ── inline fill / diff-annotate write-back ───────────────────────────────────── 33 + // ── inline fill write-back ───────────────────────────────────────────────────── 34 34 35 35 // inlineFillWrite records a byte-level replacement of a @test attribute in a 36 36 // .cue archive file. Used for three operations: 37 37 // - fill: @test() → @test(eq, <value>) or @test(err, ...) 38 38 // - force: @test(eq, old) → @test(eq, <actual>) 39 - // - diff-annotate: @test(eq, old) → @test(eq, old, skip:<ver>, diff="...") 40 - // - stale-skip: @test(eq, old, skip:<ver>, diff="...") → @test(eq, old) 39 + // - force-skip: @test(eq, old) → @test(eq, old, skip:<ver>) [CUE_UPDATE=force only] 40 + // - stale-skip: @test(eq, old, skip:<ver>) → @test(eq, old) [CUE_UPDATE=1] 41 41 type inlineFillWrite struct { 42 42 fileName string // archive .cue file name, e.g. "in.cue" 43 43 attrOffset int // byte offset of the @ in the original file data