Skip to content

Pin down what the diff command does today with tests - #67

Merged
Mpdreamz merged 1 commit into
mainfrom
tests
Nov 14, 2026
Merged

Mpdreamz merged 1 commit into
mainfrom
tests

Conversation

@Mpdreamz

Copy link
Copy Markdown
Contributor

The repository gets its first tests: they run the built tool on assemblies compiled from C# source, keep what diff prints and returns as snapshots, and check CsCheck properties over generated APIs. mise run test and CI's build job run them.

Prompt summary: The tool is being dusted off: a new comparison engine, subcommands per source, first releases that do not fail, and pull request comments and labels. Every one of those steps changes code the diff command depends on, so the first step is a test suite that shows what diff does today, wrong answers included.

Why

There are no tests. The only checks are the native-AOT smoke test and the build diffing its own previous release. A change to the engine, an exporter or the CLI can change what other builds parse without anything failing.

What

Fixtures compiled from source

A test describes an old and a new version of a small library as C# source. Roslyn compiles both into old/Lib.dll and new/Lib.dll, deterministically, so the output is the same on every run. The tests start the net11.0 build of the tool as a process, the way the action, the container and other builds call it. That keeps them valid when the engine behind the CLI is replaced.

Characterization snapshots

DiffCommandTests diffs eleven named kinds of change in every format, records the exit code for each --prevent-change level, and covers eight failure paths. Nullean.Snapshots keeps the results in .snapshots/. They record today's behaviour, including known bugs such as #56, where Markdown reports a deleted member as added. A later fix changes the snapshot on purpose.

Properties over generated APIs

CsCheck generates small APIs and checks three properties: an API diffed with itself has no changes, removing anything public is Major, and swapping old and new turns additions into removals. A fourth property, that only adding is Minor, is skipped with a link to #58.

Build, mise and CI

./build.sh test builds and runs the tests, ci composes it, and mise run test calls it. CI's build job runs it on every trigger except a release, where main's run on the commit already ran it. global.json selects Microsoft.Testing.Platform as the dotnet test runner.

Verify

mise run test

To see that the tests can fail, break the engine and run them again: every snapshot of a removal changes, and the removal property fails.

sed -i '' 's/if (Diff.IsBreakingChange)/if (false)/; s/if (anyDeleted || anyModified)/if (false)/' src/assembly-differ/AssemblyComparison.cs
mise run test
git checkout -- src

Out of scope: The snapshots show bugs this pull request leaves alone, each for its own fix: an unchanged API fails --prevent-change patch with exit code 4, the github-comment format reports 0 breaking change(s) next to changes it marks breaking, and the README's claim that a provider spec without diff is read as a command name is wrong, because diff is the default command.

Risk: Nullean.Snapshots 0.12.1 brings Nullean.ScopedFileSystem 0.7.1, which throws TypeLoadException when it loads. Directory.Packages.props pins 0.7.2 until a Nullean.Snapshots release depends on it.

🤖 Generated with Claude Code

There were no tests, so nothing showed what a change to the engine, the
exporters or the CLI does to their output. The tests run the built tool on
assemblies compiled from C# source and keep its output as snapshots; CsCheck
properties cover generated APIs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Mpdreamz Mpdreamz added the chore Internal change, no user-visible effect (patch) label Nov 13, 2026
@Mpdreamz
Mpdreamz merged commit a0f61d3 into main Nov 14, 2026
7 checks passed
@Mpdreamz
Mpdreamz deleted the tests branch November 14, 2026 07:08
Mpdreamz added a commit that referenced this pull request Nov 14, 2026
…#68)

The comparison now runs on a port of JustAssembly onto
System.Reflection.Metadata, so `src/assembly-differ/lib` and its eight
vendored dlls are gone. Every report comes out exactly as before.

**Prompt summary:** The tool is being dusted off: new subcommands, first
releases that do not fail, and pull request comments and labels. This
step replaces the engine first, so that later fixes land on code that
can be built and changed. The hidden `diff` command must keep behaving
the same, so the old engine's output is the specification.

## Why
The dlls in `lib` came from the unmerged `public-types` branch of
[nullean/JustAssembly](https://github.com/nullean/JustAssembly), an
archived fork. They were built in 2020 for .NET Framework 4.5 and no
source in any branch rebuilds them. They also bring a fork of Mono.Cecil
and a 1 MB decompiler that the comparison only used to format names.

## What

#### A port, not a rewrite
`Engine/` reproduces JustAssembly's comparers: the same sorted merge,
the same order of checks and the same visibility rules. It reads
metadata with System.Reflection.Metadata and decodes signatures into a
small type tree. That tree renders the way Mono.Cecil spells a type,
which orders members and names attribute constructors, and the way
JustDecompile's C# writer does, which the reports show. JustAssembly's
quirks stay, because changing a report is a change to the contract. A
type that became less visible is still reported as more visible, since
JustAssembly subtracted byte-backed enum values and the result wrapped
around. Nested types are still named `.Name`.

#### A corpus written by the old engine
The first commit adds a generator for old and new versions of a library.
It covers classes, structs, interfaces, enums and delegates, generics
with variance, nested types, by-ref parameters, indexers, events,
operators, explicit implementations, attributes and every accessibility.
400 seeds are checked to compile. The old engine's output for 100 of
them, in every format, is snapshotted before the engine changes. The new
engine reproduces all 100.

#### Comparing with another build
`ReferenceTests` runs this build and another one on further generated
versions and requires the same output in every format. It runs only when
`ASSEMBLY_DIFFER_REFERENCE` names the other build's dll. Against the
build from [#67](#67),
3000 seeds came out the same. With the visibility quirk removed on
purpose, 24 of 300 failed.

#### Real packages
Both builds diffed seven real package upgrades from nuget.org in `xml`
and `github-comment`, with the same output: Proc, NuGet.Versioning,
Newtonsoft.Json, System.Text.Json,
Microsoft.Extensions.DependencyInjection.Abstractions, CsCheck and
System.Collections.Immutable. The native-AOT build publishes without
trimming or AOT warnings, and `./build.sh smokeaot` passes.

## Verify
```bash
mise run test
# compare with the build from main, on 1000 generated versions
git worktree add /tmp/ad-main origin/main && (cd /tmp/ad-main && dotnet build src/assembly-differ -c Release -f net11.0)
ASSEMBLY_DIFFER_REFERENCE=/tmp/ad-main/src/assembly-differ/bin/Release/net11.0/assembly-differ.dll ASSEMBLY_DIFFER_SEEDS=1000 \
  dotnet test --project tests/assembly-differ.Tests -c Release --treenode-filter '/*/*/ReferenceTests/*'
```

**Out of scope:** The engine lives in the tool's assembly and its types
are public, because the exporters are. A separate library package comes
with the snapshot package, after the API settles. The tool's own API
diff against its last release reports `Major`, because that assembly's
public types moved. It is a tool, not a library, so nothing references
them.

**Stack:** 2 of the dusting-off series, on top of
[#67](#67).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Mpdreamz added a commit that referenced this pull request Nov 14, 2026
…88)

The tests use Nullean.Snapshots 0.12.2, and the workaround pin on
Nullean.ScopedFileSystem is gone, because 0.12.2 depends on the fixed
0.7.2 itself.

**Prompt summary:** Nullean.Snapshots was released with the
ScopedFileSystem fix, so the pin added in
[#67](#67) can go.

## What

#### The bump
`Nullean.Snapshots.AwesomeAssertions` and `Nullean.Snapshots.TUnit` move
from 0.12.1 to 0.12.2. `Nullean.ScopedFileSystem` leaves
`Directory.Packages.props` and the test project, and it still resolves
to 0.7.2 through Nullean.Snapshots.

`assembly-differ upgrades` in this repository listed these two as the
only updates, with 0 breaking changes in what the tests use.

## Verify
```bash
mise run test
dotnet list tests/assembly-differ.Tests package --include-transitive | grep ScopedFileSystem   # 0.7.2
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Internal change, no user-visible effect (patch)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant