Skip to content

CMP-4630: Fix stale ResultAfterRemediation carryover in assertion generator - #84

Merged
yuumasato merged 1 commit into
ComplianceAsCode:mainfrom
yuumasato:cmp-4630-assertion-carryover
Sep 2, 2026
Merged

CMP-4630: Fix stale ResultAfterRemediation carryover in assertion generator#84
yuumasato merged 1 commit into
ComplianceAsCode:mainfrom
yuumasato:cmp-4630-assertion-carryover

Conversation

@yuumasato

Copy link
Copy Markdown
Member

What

GenerateAssertionFileFromResults declared a single RuleTest struct outside the per-rule loop and mutated it in place. ResultAfterRemediation was only assigned when a rule's final result differed from its initial result, and it was never reset between iterations — so a rule whose result did not change inherited the previous rule's ResultAfterRemediation.

Because Go map iteration order is randomized, the corruption was nondeterministic. In practice it:

  • hid real regressions — rules that were FAIL before and after remediation were written out as PASS-after-remediation, and
  • invented false INCONSISTENT entries in the generated <profile>.yml assertion files.

Fix

  • Move the RuleTest declaration inside the loop so each rule gets a fresh struct.
  • Add helpers/utilities_test.go — a regression test that interleaves changed and unchanged rules (with many rules, to beat the randomized map order) and asserts unchanged rules carry no result_after_remediation while changed rules record exactly their own final result. It fails on the old code and passes on the fixed code.

CI wiring

There was previously no CI job running unit tests — the presubmits only run live-cluster e2e jobs (and verify runs golangci-lint). Mirroring compliance-operator, this PR adds:

  • TESTABLE_PKGS (packages that have test files, excluding vendor and the root e2e package) and a make test-unit target.

A companion openshift/release PR adds a non-cluster unit presubmit (make test-unit) so this regression test runs on every PR.

Test

$ make test-unit
ok  github.com/ComplianceAsCode/ocp4e2e/helpers
ok  github.com/ComplianceAsCode/ocp4e2e/resultparser

🤖 Generated with Claude Code

…erator

GenerateAssertionFileFromResults declared a single RuleTest struct outside
the per-rule loop and mutated it in place. ResultAfterRemediation was only
assigned when a rule's final result differed from its initial result, and it
was never reset between iterations, so a rule whose result did not change
inherited the previous rule's ResultAfterRemediation. Because Go map
iteration order is randomized, the corruption was nondeterministic: it hid
real regressions (FAIL->FAIL shown as PASS-after-remediation) and invented
false INCONSISTENT entries in the generated <profile>.yml assertion files.

Move the RuleTest declaration inside the loop so each rule gets a fresh
struct, and add a regression test that interleaves changed and unchanged
rules and asserts unchanged rules carry no result_after_remediation.

Also wire a non-cluster unit-test path, mirroring compliance-operator:
add TESTABLE_PKGS (packages with tests, excluding vendor and the root e2e
package) and a `make test-unit` target so the regression test can run in CI
without a live cluster.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@yuumasato

Copy link
Copy Markdown
Member Author

/test e2e-aws-openshift-platform-compliance

@yuumasato

Copy link
Copy Markdown
Member Author

I think the platform-compliance test has a race condition that needs to be addressed separately.

@taimurhafeez

Copy link
Copy Markdown
Collaborator

/retest-required

@taimurhafeez

Copy link
Copy Markdown
Collaborator

/test e2e-aws-openshift-node-compliance

@openshift-ci

openshift-ci Bot commented Sep 1, 2026

Copy link
Copy Markdown

@yuumasato: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-aws-openshift-platform-compliance 0145ba4 link true /test e2e-aws-openshift-platform-compliance
ci/prow/e2e-aws-openshift-node-compliance 0145ba4 link false /test e2e-aws-openshift-node-compliance

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@yuumasato

Copy link
Copy Markdown
Member Author

The platform-compliance test is being fixed here: #86

@yuumasato
yuumasato merged commit eee90a3 into ComplianceAsCode:main Sep 2, 2026
4 of 6 checks passed
@yuumasato
yuumasato deleted the cmp-4630-assertion-carryover branch September 2, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants