Skip to content

Fix three bugs in the frozen rule violation stores - #528

Draft
alexanderlinne wants to merge 3 commits into
mainfrom
fix/frozen-rule-stores
Draft

alexanderlinne wants to merge 3 commits into
mainfrom
fix/frozen-rule-stores

Conversation

@alexanderlinne

@alexanderlinne alexanderlinne commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Why

This is the first of three PRs on frozen rules. #529 stops the loader from sharing members between types with the same full name, and #531 tells frozen types and members apart by assembly. This PR fixes three bugs in the violation stores that came up along the way:

  • XmlViolationStore read from the path passed to its constructor, but always wrote to the default ../../../ArchUnitNET/Storage/FrozenRules.xml. A custom XML path was never written, and the default file was written instead.
  • JsonViolationStore and XmlViolationStore caught every exception while loading and returned an empty store, which the next write then persisted. A single merge conflict marker or typo in a store file silently un-froze every rule in it, and the file was overwritten with only the rule that was just evaluated.
  • TargetFrameworkRules identified assemblies by Assembly.FullName, which includes Version=, Culture= and PublicKeyToken=. A frozen target-framework rule therefore broke on every version bump.

What changes

Custom XML path. XmlViolationStore.StoreCurrentViolations writes to the configured path.

Malformed stores. Both stores treat only FileNotFoundException and DirectoryNotFoundException as an empty store. Parse errors and other IOExceptions now propagate, and the file is left untouched.

Target-framework rules. TargetFrameworkRules uses Assembly.Name, the simple name set in ArchBuilder, as identifier.

Tests. A new helper, TempStoreDirectory, provides throwaway store files, so that the new tests don't touch the checked-in Storage/FrozenRules.* files. FreezeTests covers that a custom XML path is written to, that malformed JSON and XML stores throw and stay unchanged, that a store in a missing directory is created, and that a frozen target-framework rule stores no version.

Behaviour changes

  • A custom XmlViolationStore path is now written to. Previously the default path was written instead, so check whether your default FrozenRules.xml contains rules that belong in the custom file.
  • A malformed store file now fails the test instead of being silently reset. The same applies to I/O errors while reading it: if several test classes freeze rules into the same store file in parallel, a sharing violation that was swallowed before (losing entries) now fails the test. Use separate store files per test class, or disable parallelization for those tests.
  • Frozen target-framework rules (TargetFrameworkRules.ShouldBeDotNet…) now store the simple assembly name. Existing entries hold the full assembly name, so these rules report their violations after the upgrade until they are re-frozen by deleting the rule's entry from the store. From then on they survive version bumps.

StoreCurrentViolations wrote to the default storage path instead of the path passed to the constructor, so a custom XML store was read from but never written to. Add a regression test using a temporary store directory.

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
LoadStorage caught every exception and returned an empty store, which the next write then persisted, so a single malformed or locked file silently un-froze all rules. Only a missing file or directory now counts as an empty store; parse errors and IO errors propagate.

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
Assembly.FullName includes Version, Culture and PublicKeyToken, so a frozen target framework rule stopped matching on every assembly version bump. Assembly.Name is the simple name set in ArchBuilder and is stable.

Signed-off-by: Alexander Linne <alexander.linne@tngtech.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.02%. Comparing base (c4687d1) to head (983b9b5).

Files with missing lines Patch % Lines
ArchUnitNET/Library/Rules/TargetFrameworkRules.cs 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #528      +/-   ##
==========================================
+ Coverage   86.50%   87.02%   +0.52%     
==========================================
  Files         261      261              
  Lines       12691    12691              
  Branches     1232     1232              
==========================================
+ Hits        10978    11044      +66     
+ Misses       1366     1300      -66     
  Partials      347      347              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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