Skip to content

Package hardening: layout, changelogs, convention tests, CI/CD, and two audit fixes - #1

Merged
CaffeinatedCoder merged 11 commits into
mainfrom
chore/package-hardening
Aug 15, 2026
Merged

CaffeinatedCoder merged 11 commits into
mainfrom
chore/package-hardening

Conversation

@CaffeinatedCoder

Copy link
Copy Markdown
Owner

Applies the hygiene playbook from EFCore.ComplexIndexes to this repository, then runs the domain audit it prescribes. 11 commits, each independently reviewable.

Structure and packaging

  • Shipping projects moved to src/, tests to test/, via git mv so history is preserved. Test count unchanged across the move.
  • Root CHANGELOG.md covering all nine releases, plus one per package — filtered by git diff --name-only between tags rather than by guesswork, which is why the EF packages carry explicit version-alignment entries.
  • The core and EF packages previously packed the 1021-line root README as their NuGet page. Each now ships its own, verified by reading it back out of the .nupkg.
  • Source Link, snupkg symbols, and ContinuousIntegrationBuild gated on CI so local step-into debugging still works.

Convention tests (new project, 31 tests)

Checks that compile and pack cleanly and only fail once a consumer installs the package: changelog consistency, packaging metadata, the value-set contracts from CLAUDE.md asserted behaviourally, EF mapping parity, and the release wiring. Everything is discovered — projects by globbing src/, types by reflection — so a new package or type needs no edit here.

Every one was proven by seeding the defect it claims to catch. Two were vacuous when first written and are noted in the commits: the mapping parity tests iterated an empty list because the range unions are abstract records, and the CanonicalOrder rule passed with the rule deleted because the probe values did not distinguish ordinal from culture ordering. Both classes now carry a floor assertion on how many types they discover.

CI/CD

  • dotnet.yml: unit and convention suites across ubuntu/windows/macos, integration on Linux with CI=true, and a pack job where packing is itself a check.
  • release.yml: tag verified against Directory.Build.props rather than driving it, verify/publish split so nothing unattended holds id-token, Trusted Publishing via OIDC gated on the nuget environment.
  • scripts/publish-nuget.sh deleted — one publishing path, with a test asserting a second does not come back.
  • SBOMs generated per package with no --exclude-filter: nothing here is PrivateAssets=all, so the graph matches the nuspecs. Verified 0/2/16/21 components against each.

Policy, docs and skills

SECURITY.md scoped to where this library actually sits — unlike the sibling project it runs in the request path and parses untrusted input by design. CONTRIBUTING.md leading with the quality bar. Two Claude skills: verify-the-guard and value-semantics-review.

Two bugs the audit found

Both were documented as correct, which is why reading the code did not catch them.

  1. Count over a union reached through Remove counted shared elements twice. The refusal that keeps Count off a concatenated array_cat matched only the outermost call, and array_remove preserves canonical form rather than establishing it. Confirmed against live PostgreSQL: {a,c} ∪ {a,b} stored as {a,c,a,b} answered 4 where the in-memory expression is 3. A doc comment claimed array_remove "composes safely with Count and equality" unconditionally; it holds only for an already-canonical operand.

  2. ⚠️ A null range now reads back as null instead of throwing. A null Int32Range? serialized to {"Seats":null} and threw on the way back in — the package could not read a document it had just written. HandleNull is removed, matching what RangeSet and the value sets always did. Behaviour change: a non-nullable-annotated property fed an explicit null now receives null rather than throwing. null and "empty" stay distinct, with a test pinning it.

Reverting either fix fails exactly its own guards and nothing else.

Not done

The release workflow has never executed. Once this merges, release.yml is on the default branch and can be dispatched with dry_run to rehearse verify end to end without minting a token.

Suite: 970 passing, live-PostgreSQL layer included.

🤖 Generated with Claude Code

CaffeinatedCoder and others added 11 commits August 15, 2026 18:11
Flat layout with nine sibling directories gave no signal about which
projects ship and which only verify. Shipping projects now live under
src/, test projects under test/, with matching solution folders.

Moved with git mv so history is preserved. Directory.Build.props stays
at the root and continues to apply to both trees. Test ProjectReference
paths gain a ../../src/ prefix; sibling references within src/ are
unchanged. The two packages that pack the root README needed their
relative path re-anchored — that one would have failed the pack loudly
rather than shipping a package without a README.

Also records the rule this move exists to protect in CLAUDE.md: locate
the repo root by walking up to the .slnx marker, never by a positional
../../, so the next move cannot silently retarget a test.

.gitignore grew the IDE, OS, and test-output entries that were being
carried in .git/info/exclude, where they only ever protected one
machine.

Test count unchanged: 932 passing, integration layer included.

Co-Authored-By: Claude Opus 5 <[email protected]>
Version history lived only in the README's "What's new" sections — six
of them, inside a 1021-line document, with nothing for 1.0.0 through
3.0.0 beyond the migration notes. There was no artifact a test could
check a release against, so nothing stopped a version shipping with no
record of what changed in it.

CHANGELOG.md at the root covers all nine releases with their tag dates.
Each package gets its own, filtered to the entries that affect it — the
filtering is derived from `git diff --name-only` between tags, not from
guesswork, which is why the EF packages carry explicit
version-alignment entries for releases where only their tests changed.
All four packages share one Version property and release together, so
every package changelog documents every shipped version; that keeps the
invariant a test can assert simple.

The README's "What's new" sections stay as narrative — the changelog is
the record.

Co-Authored-By: Claude Opus 5 <[email protected]>
Both packed ../README.md — 1021 lines covering all four packages. A
reader landing on the core package's NuGet page got the EF Core plugin,
the NodaTime satellites and the migration notes for versions they may
never have used; a reader landing on the EF page got the same document
again, with its own section a third of the way down.

Each now ships a README scoped to what that package actually contains,
matching the shape the two NodaTime packages already used, and links to
the root README for the complete guide.

Verified by packing and reading each README back out of the .nupkg
rather than trusting PackageReadmeFile: 143 / 120 / 82 / 184 lines, one
per package, each starting with its own package name.

Co-Authored-By: Claude Opus 5 <[email protected]>
A consumer stepping into this code previously landed in decompiled IL,
and had no way to confirm a published package was built from the commit
it claims. Both are the due-diligence questions a commercial consumer
asks before taking a dependency.

- IncludeSymbols + SymbolPackageFormat=snupkg: four .snupkg files now
  pack alongside the packages, and `dotnet nuget push` uploads them
  automatically, so the publish script needs no change.
- PublishRepositoryUrl + EmbedUntrackedSources: Source Link ships in
  the SDK, so no PackageReference is involved. Verified in the packed
  .nuspec, which now carries
  <repository type="git" url="…" branch="…" commit="…">.
- RepositoryType=git, which the repository element needs to be
  well-formed.
- ContinuousIntegrationBuild conditioned on CI only. It normalizes
  source paths for a reproducible build — correct for a published
  package, and it breaks local step-into debugging. Verified both ways:
  empty locally, true under CI=true.

Co-Authored-By: Claude Opus 5 <[email protected]>
Checks that are invisible at compile time and only fail once a consumer
installs the package. 24 tests, all discovery-driven — the shipping
projects come from globbing src/, the range and set types from
reflection — so adding a package or a type needs no edit here.

- Changelog: the shipped version is documented at the root and in every
  package's changelog, no file runs ahead of the Version property,
  per-package versions are a subset of the root's, sections newest-first.
- Packaging: every package declares a PackageReadmeFile, packs a README
  from its own directory rather than a shared one, carries a Description
  and tags, and the shared props ship symbols and Source Link with
  ContinuousIntegrationBuild gated on CI.
- Value set contracts: three of the load-bearing rules in CLAUDE.md,
  asserted behaviourally rather than by reflecting on the hooks. A set
  that normalizes in From without overriding NormalizeElement, or
  overrides CanonicalComparer without CanonicalOrder, fails to find an
  element it was built from; one whose element type System.Text.Json
  cannot serialize writes objects instead of scalars. All three are
  silent in production — nothing throws.
- Mapping parity: every range and set type in both shipping assemblies
  resolves through IRelationalTypeMappingSource, and plain arrays keep
  their native provider mapping.

Both discovery-driven classes carry a floor assertion on how many types
they find. That is not defensive padding: the mapping parity tests were
passing while iterating an empty list, because the range unions are
abstract records and the predicate filtered abstract types out. The
guard caught it on its first run.

Co-Authored-By: Claude Opus 5 <[email protected]>
Seeding the defect the contract tests claim to catch found one of them
vacuous: removing StringSet's CanonicalOrder override left
EverySetType_FindsAnElementItWasBuiltFrom passing.

Two causes, both in the test:

- The string probes were "beta", "Alpha", "gamma delta", which ordinal
  and culture comparison order identically. Binary-searching the
  ordinal-sorted array with the default culture comparer therefore still
  found every element. "Zebra" and "apple" split the two orders — 'Z'
  (90) precedes 'a' (97) ordinally, while a culture comparison puts
  apple first.
- TextKey, the wrapper element the StringSet<T> arity is closed over,
  implemented IComparable ordinally. That is not what the generators
  emit, and it made the element agree with the canonical order by
  accident. It now compares culture-sensitively, which is the hazard
  StringSet<T>'s ordinal CanonicalComparer exists to override.

Both seeds now fail with the intended message. Verified across all 15
seeded defects: version bumped without a changelog entry, a changelog
ahead of the Version property, sections out of order, a deleted package
changelog, a package version absent from the root, a package packing
the shared root README, a removed PackageReadmeFile, a removed
Description, removed IncludeSymbols, an unconditional
ContinuousIntegrationBuild, LocalDateSet dropping NormalizeElement,
StringSet and StringSet<T> dropping CanonicalOrder, YearMonthSet
dropping ElementJsonConverter, and TimeSet left unregistered with the
EF plugin. Each failed exactly the test that claims it, and only that
test.

Suite back to baseline: 956 passing.

Co-Authored-By: Claude Opus 5 <[email protected]>
CLAUDE.md and docs/testing.md described a five-project test suite that
no longer matches the repository. Both now cover the conventions
project, including the two things about it that are easy to undo by
accident: the discovery floors exist because the mapping parity tests
were once passing over an empty list, and the probe values exist
because ordinal-vs-culture-identical ones let a rule pass while broken.

The workflow section gains the rule the rest of this work was verified
under: prove a fix by reverting it and confirming the test fails. A
test that passes with and without the fix is not a regression test, and
one written against broken code can assert nothing at all without
looking any different.

Also documents the NU5026 trap in the pack command — GeneratePackageOnBuild
makes a bare `dotnet pack` race the compile.

Co-Authored-By: Claude Opus 5 <[email protected]>
Publishing was a local script holding a nuget.org API key on one
machine. It now runs in GitHub Actions with no stored credential at
all: GitHub signs a short-lived OIDC token proving which workflow in
which repository is running, nuget.org validates it against a policy
configured there and issues a key valid for one hour.

release.yml is split into two jobs so the approval gate lands in the
right place. `verify` resolves the version by MSBuild evaluation,
checks the pushed tag against it, runs the full suite with CI=true,
packs, generates SBOMs and uploads — with contents:read and
deliberately no id-token permission, so nothing that runs unattended is
able to mint a publishing token. `publish` needs verify, is gated on the
`nuget` environment, and pushes the artifacts verify produced rather
than repacking them. A reviewer is therefore asked only after the suite
has passed, and the artifact published is the one that was tested.

The tag is checked against Directory.Build.props rather than driving
it, so a mistyped tag fails before anything ships. Because the full
suite gates the release, the changelog convention tests block a version
nothing documents.

dotnet.yml grows the unit suites across ubuntu/windows/macos — the
conventions project does real path work, which is where separator
handling differs — the integration suite on Linux with CI=true, and a
pack job where packing is itself a check: it reads each README back out
of the .nupkg rather than trusting the property that declared it.

SBOMs are generated per package with no --exclude-filter, unlike the
sibling repository this pattern comes from. Nothing here is referenced
with PrivateAssets=all, so every component in the graph is one a
consumer actually receives. Verified against each nuspec before
committing: 0 components for the core package (it has no dependencies),
2 for the NodaTime satellite, 16 and 21 for the EF packages, every
direct dependency present and no toolchain leakage.

scripts/publish-nuget.sh is deleted. Two publishing paths drift, and
the one that drifts is the one that skips a check.

Co-Authored-By: Claude Opus 5 <[email protected]>
The provenance work of the last two commits answers questions nobody
could find the answer to: there was no security contact, no disclosure
process, and nothing saying what this package considers its own defect
versus the caller's.

SECURITY.md is scoped to where this library actually sits, which is not
where the sibling repository this pattern comes from sits. That one has
no runtime presence in the request path; this one does — every type
implements IParsable over PostgreSQL literal syntax and ships JSON
converters intended for ASP.NET Core, so untrusted input reaches it by
design, and the EF plugin writes element text into SQL literals with
quote-doubling. In scope: escaping failures at that boundary, a
membership answer that is silently wrong where the set was carrying a
permission list, parsing DoS, supply-chain integrity. Out of scope:
upstream vulnerabilities, anything that fails loudly, and the caller's
own authorization logic. Every factual claim was checked against the
source before writing it — including that no PrivateAssets=all
reference exists, which is why the SBOMs match the nuspecs.

CONTRIBUTING.md leads with the quality bar rather than the setup, and
names this package's characteristic failure: a value that looks right,
compares equal to itself, round-trips without error, and means
something else.

Two skills make the judgement-shaped parts reusable:

- verify-the-guard — the counterfactual rule, written around this
  repository's own vacuous tests: the mapping parity tests that
  iterated an empty list because the range unions are abstract records,
  and the CanonicalOrder rule that passed with the rule removed because
  the probes did not distinguish ordinal from culture ordering. It also
  records that `git checkout -- .` does not undo a `git mv`, which made
  four seeded defects fail for the wrong reason.
- value-semantics-review — the domain lens: both sides of the wire,
  canonical form on every construction path, the probe-comparability
  rule, ordinal versus culture, JSON as a second wire format,
  registration parity, and what may compose on a non-canonical Union.

Co-Authored-By: Claude Opus 5 <[email protected]>
Union translates to array_cat, which concatenates rather than
deduplicating, so Count over a server-computed union has always been
refused rather than answered. The refusal matched only the outermost
call:

    expression is SqlFunctionExpression { Name: "array_cat" }

array_remove preserves canonical form rather than establishing it — a
sorted, deduplicated array stays sorted and deduplicated once an element
is dropped, but a concatenation stays a concatenation. So
Tags.Union(Other).Remove(x).Count presented array_remove to the check,
did not match, and reached cardinality over the concatenation.

Confirmed against live PostgreSQL rather than reasoned about: with
Tags={a,c} and Other={a,b}, the stored expression is {a,c,a,b} and the
server answered Count=4, where the in-memory expression is {a,b,c} — 3.
A Where on that count filtered on a number quietly too large; a Select
returned it to the caller.

The check now looks through canonicality-preserving wrappers, so the
expression is refused in a predicate and falls back to client
evaluation in a projection — where it materializes the arrays and
answers 3.

Two regression tests, one per layer, plus two that pin the refusal not
overreaching: Remove over a plain column still translates, and IsEmpty
over a removed union stays translated because it remains
duplicate-insensitive. Reverting the fix fails exactly the two guards
and neither of the two over-correction pins.

Also corrects the doc comment that claimed array_remove "composes
safely with Count and equality" unconditionally. It does so only for an
operand that was already canonical — which is what this bug was.

Co-Authored-By: Claude Opus 5 <[email protected]>
A null Int32Range? property serialized to {"Seats":null} and threw
JsonException on the way back in, so the package could not read a
document it had just written — an ASP.NET Core API could return a body
it was unable to accept, and a client clearing an optional field got a
400 for sending back what it had just been given.

The cause was HandleNull => true on RangeJsonConverter and
RangeVariantJsonConverter, added so Read could see the null token and
reject it with a directed message. The justification recorded there —
"so that null is never silently confused with the empty range" — does
not survive contact: reading null yields null, never the empty range,
so the confusion it guarded against is not one the obvious behaviour
creates. RangeSet and the value sets never declared HandleNull and have
always round-tripped null correctly; the range converters now match
them.

The cost is real and stated rather than buried: a non-nullable-annotated
range property fed an explicit null now receives null instead of
throwing. That is what every other reference-typed property in a model
already does, and it is the trade for the package being able to read its
own output. Malformed literals are still rejected, and null and "empty"
remain distinct wire forms.

Verified across all seven shapes that reach the converters — BCL ranges,
a variant-typed declaration, RangeSet, the value sets, and the NodaTime
ranges through the satellite's own registration — writing null and
reading it back, with populated values still round-tripping equal.

Five regression tests, including the two that previously pinned the
rejection, now inverted, and one asserting null and "empty" stay
distinct so the original concern keeps a guard. Reverting the source
change fails exactly those five.

Two README statements asserting the old behaviour were false as of this
commit and are corrected.

Co-Authored-By: Claude Opus 5 <[email protected]>
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.

1 participant