Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/scripts/inspect-packed-nupkgs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ main() {
# generation lives inside the existing Compono.Generators (packed only into Compono.nupkg),
# reached transitively through this package's Compono dependency, not a second analyzer DLL.
extra_paths=$'build/Compono.Logging.props\nbuildTransitive/Compono.Logging.props'
elif [ "$pkg" = "Compono.Metrics" ]; then
# build/ + buildTransitive/ Compono.Metrics.props: defaults ComponoMetricsOwnsMeterFactory to
# true (ADR-0072 Amendment 5), so Compono.Generators never emits a TestDoubles double for
# IMeterFactory - same shape as Compono.Logging above, no analyzer DLL of its own.
extra_paths=$'build/Compono.Metrics.props\nbuildTransitive/Compono.Metrics.props'
fi
if [ "$pkg" = "Compono.XunitV3.Aot" ]; then
# net9.0+ only - matches xUnit v3's own Native AOT floor (ADR-0066/RESEARCH-0032); no
Expand Down
34 changes: 34 additions & 0 deletions docs/adr/0055-compono-logging-testing-support-package.md
Original file line number Diff line number Diff line change
Expand Up @@ -1686,3 +1686,37 @@ dependency) is unchanged. `UseLogging()`, `CapturingLogger`/`CapturingLogger<T>`
and their per-logger capture are unchanged apart from carrying `Category`.
Implementation is tracked in
[PLAN-0072](../plans/0072-compono-logging-host-wide-log-capture-and-dotnet-11-ga-impl-plan.md).

## Amendment 7 (2026-11-11): category-prefix filters `InCategoryPrefix` / `NotInCategoryPrefix`

**Status:** Accepted (maintainer decision, 2026-11-11).

The #161 follow-up ([RESEARCH-0040](../research/0040-issue-161-1-4-dogfood-follow-up.md)
finding 5) reported that host-level guards filter by category prefix,
typically negated ("no `Error` outside `MyApp.Jobs.*`"). Today that needs
`Matching(e => !e.Category.StartsWith(...))`, because `InCategory` is an
exact match.

**Decision.** `LogVerificationBuilder` gains two named filters:

```csharp
public LogVerificationBuilder InCategoryPrefix(string prefix); // Category starts with prefix
public LogVerificationBuilder NotInCategoryPrefix(string prefix); // Category does not start with prefix
```

- `StringComparison.Ordinal` (case-sensitive), matching `InCategory`.
- The prefix is literal, with no implicit `.` separator.
`InCategoryPrefix("MyApp.Jobs")` also matches `MyApp.JobsLegacy`. The
docs show a trailing dot (`"MyApp.Jobs."`) for namespace-boundary intent.
- `null` throws `ArgumentNullException`, like `InCategory`. An empty prefix
isn't special-cased: `InCategoryPrefix("")` matches every entry and
`NotInCategoryPrefix("")` matches none.
- Both compose with the existing AND-only chain and appear in failure
descriptions (`category starting with "..."`,
`category not starting with "..."`).
- `InCategory` is unchanged. There's no general negation combinator.
`Matching` stays the escape hatch.

Both work on `CapturingLogger` verification and on `LogCollector`
verification, because they share the builder. Plain string comparison, so
AOT-safe.
94 changes: 94 additions & 0 deletions docs/adr/0072-compono-metrics-testing-support-package.md
Original file line number Diff line number Diff line change
Expand Up @@ -722,3 +722,97 @@ where it reads naturally). Example:
`Expected exactly 1 call(s) to instrument "shop.orders.placed" (long) with
tag region = "eu" and value 1, but received 0.` No public API changed, and
core `CallVerifier` is untouched.

## Amendment 5 (2026-11-11): Compono.Metrics owns `IMeterFactory` — excluded from `Compono.TestDoubles` generation

**Status:** Accepted (maintainer decision, 2026-11-11). **This amendment
explicitly supersedes the "Precedence and misuse" sentence *"No generator
exclusion is added."*** Everything else in that section stands, including
first-registered-wins against `UseNSubstitute()`.

### What dogfooding found

The #161 follow-up ([RESEARCH-0040](../research/0040-issue-161-1-4-dogfood-follow-up.md)
finding 1) migrated a 231-test suite with `ComponoGeneratedTestDoubles=true`.
A shared base profile called `UseGeneratedTestDoubles()` before
`UseMetrics()`. `Compono.Generators` emits a double for every interface it
reaches, so it had generated one for the SUT's `IMeterFactory`, and
`GeneratedTestDoubleProvider` won stage 6. 28 tests failed on measurement
assertions. Separately, `UseMetrics()`'s remarks and the misuse exception
named only `UseNSubstitute()`, never `UseGeneratedTestDoubles()`.

### Decision

Follow [ADR-0055](0055-compono-logging-testing-support-package.md)
Amendment 4's ownership precedent. When `Compono.Metrics` is referenced,
`System.Diagnostics.Metrics.IMeterFactory` is a **Metrics-owned
abstraction**, and `Compono.Generators` never generates a
`Compono.TestDoubles` double for it.

- **Signal:** a new MSBuild property, `ComponoMetricsOwnsMeterFactory`.
`Compono.Metrics`'s packed `build/` and `buildTransitive/` props default
it to `true` when it's unset, and core `Compono.props` declares it
`CompilerVisibleProperty`. That's the same split `ComponoGeneratedLogging`
uses (ADR-0055 Amendment 3). Package or type presence isn't the signal,
per Amendment 3's rejection of symbol-presence gating. A consumer can set
it to `false` to get a generated `IMeterFactory` double back.
- **Mechanism:** the existing `TransitiveClosureWalker.TryRecordTestDouble`
exclusion check that already skips Logging-owned types. When the flag is
on, it also skips the type `IMeterFactory` resolves to. Nothing else in
discovery changes. If the type can't be resolved, the flag has no effect.
- **Unchanged:** stage-6 first-registered-wins (ADR-0024/ADR-0043), core
composition, and provider precedence. `UseMetrics()` must still come
before `UseNSubstitute()` or any other catch-all stage-6 provider. That
guidance stays in the remarks, the misuse message, and the docs, which
now also name `UseGeneratedTestDoubles()` and explain that, with
`Compono.Metrics` referenced, order against it doesn't matter.

### Tradeoff (accepted)

With `Compono.Metrics` referenced, a composer that calls
`UseGeneratedTestDoubles()` but **not** `UseMetrics()` gets no
`IMeterFactory` double. The request falls through to any later stage-6
provider, or composition fails with the standard "no provider could
satisfy" `CompositionException`. Referencing a metrics-testing package
without calling `UseMetrics()` is almost always a mistake, and a loud
failure beats a silently uncapturing double. Opting out is one property.

### Verification

Generator tests cover flag on, flag off, a sibling interface still being
doubled, and the flag having no effect when the type can't be resolved.
`Compono.Metrics.Tests` runtime tests (real generated doubles enabled)
cover both registration orders with `UseGeneratedTestDoubles()` and the
referenced-without-`UseMetrics()` case. Tracked in
[PLAN-0075](../plans/0075-issue-161-1-4-dogfood-follow-up-impl-plan.md).

## Amendment 6 (2026-11-11): disposal patterns clarified per test engine — no ownership change

**Status:** Accepted (maintainer decision, 2026-11-11). This is a
clarification only. "Composition stays non-owning", "No new ownership API
is added", and the "Automatic disposal by composition" non-goal are
unchanged, and [ADR-0022](0022-compono-xunit-package-design.md)
Amendment 4 stands.

"Disposal patterns" pattern 1 prescribes `using var _ = meters;` in every
`[Compose]`-family test and says Compono doesn't rely on framework disposal
"either way". RESEARCH-0040 finding 3 checked this empirically on xUnit
v3 4.0.1 (JIT): xUnit itself disposes every `IDisposable`/`IAsyncDisposable`
test-method argument after the test case, once per argument slot
(RESEARCH-0038 §2.4, ADR-0070 contract item 12). A `[Shared] IMeterFactory`
parameter is the SUT's instance, so on `Compono.XunitV3` xUnit already
disposes it and the `using` line is redundant (harmless, because
`Dispose()` is idempotent). xUnit's AOT core doesn't dispose arguments. TUnit,
NUnit, and MSTest weren't re-tested here. TUnit's root-argument disposal is
already documented separately in
[ADR-0040](0040-compono-tunit-package-design.md) ("Diagnostics, disposal,
and seed observability") and in the `Compono.TUnit` package guide. This
amendment relies on that documented contract and doesn't re-verify it.

The documented guidance is now per engine: on `Compono.XunitV3` the
`using` line is optional. It's also optional on `Compono.TUnit`, per ADR-0040's
documented root-argument disposal. Keep it on `Compono.XunitV3.Aot`,
`Compono.NUnit`, `Compono.MSTest`, and `Composer.Create` tests. Compono still registers
nothing for disposal (`ComposeAttributeDisposalTests` still guards that),
and xUnit's argument disposal remains xUnit's behavior, not a Compono
contract.
6 changes: 6 additions & 0 deletions docs/cookbook/vary-composed-configuration-per-theory-row.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ parameter) and no xUnit `TypeHelper` conversion. Null is allowed only for a
nullable value type or a `?`-annotated reference. Put the row values first in
the parameter list; composed parameters follow.

**Need the row's `TConfig` in the test body?** Don't repeat its values as
extra row elements. Have the profile register the config it already
receives, `builder.Register(() => config)`, and add a composed `TConfig`
parameter after the row values. It resolves to that row's own instance.
See [Reading the row's `TConfig`](../packages/compono-xunitv3.md#per-row-configuration).

**`[Shared]` still works.** Mark a parameter `[Shared]` and, when a row
supplies a value at that position, that value becomes the single instance
every other parameter in the row resolving that type receives; otherwise
Expand Down
19 changes: 17 additions & 2 deletions docs/how-to/assert-nothing-logged-at-error-across-a-host.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,30 @@ or a short name.
`InCategory` never matches by prefix, unlike the host's own `AddFilter`
and `Logging:LogLevel:*` rules. A category string that matches nothing
makes `Never()` pass without checking anything. To cover a whole
namespace, match the prefix explicitly:
namespace, use `InCategoryPrefix`, or `NotInCategoryPrefix` to check
everything *outside* it:

```csharp
logs.Verify()
.AtLevelOrAbove(LogLevel.Error)
.Matching(entry => entry.Category.StartsWith("MyApp.Payments.", StringComparison.Ordinal))
.InCategoryPrefix("MyApp.Payments.")
.Never();

// The common host guard: nothing at Error or above outside your own code.
logs.Verify()
.AtLevelOrAbove(LogLevel.Error)
.NotInCategoryPrefix("MyApp.Jobs.")
.Never();
```

`InCategoryPrefix`/`NotInCategoryPrefix` are ordinal and case-sensitive like
`InCategory`, and the prefix is **literal**: no namespace separator is
added. `InCategoryPrefix("MyApp.Jobs")` also matches `MyApp.JobsLegacy`, so
end the prefix with `.` to mean "beneath this namespace". `"MyApp.Jobs."`
doesn't match the bare `MyApp.Jobs` category itself. Use `.Matching(...)` for
anything else, such as several namespaces at once
([ADR-0055 Amendment 7](../adr/0055-compono-logging-testing-support-package.md)).

## What the host may not capture

Compono never changes the host's own filter rules. The default host
Expand Down
64 changes: 64 additions & 0 deletions docs/how-to/use-profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,70 @@ for the full shape and
[Migrating from AutoFixture](../migrating-from-autofixture.md#migrate-a-parameterized-custom-autodataattribute)
for the AutoFixture pattern this replaces.

## A profile whose constructor takes runtime objects

`[Compose<TProfile, TConfig>]` arguments must be attribute constants. A
profile that needs runtime objects, such as interceptors, a configured
client, or an in-memory log, can't get them from an attribute. There are
two patterns, and both work on `Compono.XunitV3` and `Compono.XunitV3.Aot`.

**1. A parameterless wrapper profile per variant.** Name each variant once,
then use it like any other profile. The wrapper builds the arguments and
applies the real profile with `AddProfile(instance)`:

```csharp
public sealed class DbProfile(AuditInterceptor? interceptor) : ICompositionProfile
{
public void Configure(CompositionBuilder builder) =>
builder.Register(() => new OrderRepository(interceptor));
}

public sealed class AuditedDbProfile : ICompositionProfile
{
public void Configure(CompositionBuilder builder)
{
var log = new AuditLog();
builder.Register(() => log); // so the test can assert on it
builder.AddProfile(new DbProfile(new AuditInterceptor(log)));
}
}

[Theory, Compose<AuditedDbProfile>]
public void SavingIsAudited(OrderRepository sut, AuditLog log)
{
sut.Save("42");
Assert.Equal(["saved 42"], log.Entries);
}
```

Prefer this over adding a parameterless constructor to `DbProfile` itself.
The variant gets its own name, and `DbProfile` keeps one constructor.

**2. A single-row `[ComposeData<TProfile, TConfig>]`.** When the arguments
are data (built in a static member rather than per variant), put them in a
`TConfig` and supply one row:

```csharp
public sealed record AuditConfig(AuditInterceptor Interceptor);

public static TheoryData<AuditConfig> Audited =>
new() { new AuditConfig(new AuditInterceptor(new AuditLog())) };

[Theory]
[ComposeData<ConfiguredDbProfile, AuditConfig>(nameof(Audited))]
public void SavingIsAudited(OrderRepository sut, AuditLog log) { /* ... */ }
```

The test is a one-row theory. Both patterns are exercised by
`DocumentedRecipeTests` in `test/Compono.XunitV3.Tests` and
`test/Compono.XunitV3.Aot.Tests`. A dedicated "profile factory member"
attribute property isn't offered. It's deferred until these patterns prove
inadequate
([RESEARCH-0040](../research/0040-issue-161-1-4-dogfood-follow-up.md)
finding 6). Runtime values from an xUnit fixture can also be read inside a
profile with `TestContext.Current.RequireFixture<TFixture>()`; see the
[`Compono.XunitV3` Package Guide](../packages/compono-xunitv3.md).

## Combining more than one profile

```csharp
Expand Down
Loading
Loading