diff --git a/.claude/skills/mr-sparkle-dotnet/SKILL.md b/.claude/skills/mr-sparkle-dotnet/SKILL.md index f888c5b0..64d641bd 100644 --- a/.claude/skills/mr-sparkle-dotnet/SKILL.md +++ b/.claude/skills/mr-sparkle-dotnet/SKILL.md @@ -12,6 +12,8 @@ user-invocable: true # Mr. Sparkle: .NET Overlay +**Precondition.** This skill runs against the sibling `dotnet-reference` checkout, which owns `scripts/internal/cr-target.sh`. When that file is absent, stop and report the skill as unavailable in this project. + Adds the .NET-specific work to a `mr-sparkle` run. This skill reviews only. It never edits code. It supplies four things that the core `mr-sparkle` skill cannot assume: repo diff scoping, a tool-driven analyzer lens, the repo review rubrics, and the removable-package check. diff --git a/.claude/skills/mr-sparkle/SKILL.md b/.claude/skills/mr-sparkle/SKILL.md index 866cf388..37e4f4c7 100644 --- a/.claude/skills/mr-sparkle/SKILL.md +++ b/.claude/skills/mr-sparkle/SKILL.md @@ -14,6 +14,8 @@ user-invocable: true # Mr. Sparkle +**Precondition.** This skill runs against the sibling `dotnet-reference` checkout, which owns `scripts/internal/cr-target.sh`. When that file is absent, stop and report the skill as unavailable in this project. + Run every available reviewer on one target, then merge the findings into one report. A defender pass drops the claims that the code does not support. **Review only.** This skill never edits code, runs no fix, and posts no PR comment. It writes two kinds of artifact: the report, and a plan directory for findings at High or above. To apply findings, use `/review-apply`. diff --git a/benchmarks/E128.Benchmarks/CoreBenchmarks.cs b/benchmarks/E128.Benchmarks/CoreBenchmarks.cs index 71fe9283..77b3b4fa 100644 --- a/benchmarks/E128.Benchmarks/CoreBenchmarks.cs +++ b/benchmarks/E128.Benchmarks/CoreBenchmarks.cs @@ -60,7 +60,7 @@ public Task GreetAndSaveAsync() } [Benchmark] - public Task> GetRecentTenAsync() + public ValueTask> GetRecentTenAsync() { return _repository.GetRecentAsync(RecentCount, CancellationToken.None); } diff --git a/benchmarks/E128.Benchmarks/FixedGreetingRepository.cs b/benchmarks/E128.Benchmarks/FixedGreetingRepository.cs index 73c2ad9e..6ff7ef58 100644 --- a/benchmarks/E128.Benchmarks/FixedGreetingRepository.cs +++ b/benchmarks/E128.Benchmarks/FixedGreetingRepository.cs @@ -13,17 +13,17 @@ namespace E128.Benchmarks; /// internal sealed class FixedGreetingRepository(IReadOnlyList greetings) : IGreetingRepository { - public Task SaveAsync(Greeting greeting, CancellationToken cancellationToken) + public ValueTask SaveAsync(Greeting greeting, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(greeting); - return Task.CompletedTask; + return ValueTask.CompletedTask; } - public Task> GetRecentAsync(int count, CancellationToken cancellationToken) + public ValueTask> GetRecentAsync(int count, CancellationToken cancellationToken) { ArgumentOutOfRangeException.ThrowIfNegative(count); - return Task.FromResult(greetings); + return ValueTask.FromResult(greetings); } } diff --git a/lode/dotnet/analyzer-candidates/index.md b/lode/dotnet/analyzer-candidates/index.md index 7c4bf66a..6278421b 100644 --- a/lode/dotnet/analyzer-candidates/index.md +++ b/lode/dotnet/analyzer-candidates/index.md @@ -143,3 +143,24 @@ Nushell or Markdown capture stays in the pugworks ledger. > **Pattern**: When a language or runtime band lands, audit the installed E128 rule set for rules the new mechanism makes redundant and record each for removal > **Why**: A rule that guards a shape the new API removes becomes permanent noise. The net11 band replaces the hand-rolled process capture, so E128160 guards a shape that cannot be written once Process.RunAndCaptureText is adopted. The audit keeps the rule set shrinking as the platform grows. > **Source**: `correction 2026-11-13T12:09:27Z`, occurrence 1 of 3 + +### Captured: A disposal analyzer must not flag a process-global instance that the owning library disposes at exit (1/3): score pending +> **Key**: `a-disposal-analyzer-must-not-flag-a-process-global-instance` +> **Class**: `design`, **Lang**: `cs`, **File**: `src/Pug.Rendering.XenoAtom/XenoAtomTerminal.cs` +> **Pattern**: IDISP004 must not fire on a deliberately discarded long-lived singleton handed back by a library factory +> **Why**: `XenoAtom.Terminal.Terminal.Initialize` returns the process-global `TerminalInstance`, and the library disposes it at process exit. The caller has no lifetime to own, and disposing it would tear down the terminal it just configured. The pragma is the correct answer today, so the rule adds a false positive on every global-instance factory. +> **Source**: `session friction 2026-11-14T17:51:00Z`, occurrence 1 of 3 + +### Captured: S109 and S2339 leave a small public constant table unbuildable (1/3): score pending +> **Key**: `s109-and-s2339-leave-a-small-public-constant-table-unbuildable` +> **Class**: `design`, **Lang**: `cs`, **File**: `src/Pug.Core/Results/ExitCodes.cs` +> **Pattern**: A value with an inherent number, such as a process exit code, must be expressible once in a public table +> **Why**: S109 wants each literal behind a named constant, S2339 forbids a public `const` member, and neither accepts the other's answer. The workaround is a private const per value behind a public static property, which doubles the type for no behavior. Either S109 should skip a member whose declaration is the name, or S2339 should allow a const on a table type. +> **Source**: `session friction 2026-11-14T18:20:00Z`, occurrence 1 of 3 + +### Captured: E128184 must follow a temp directory into the method that deletes it (1/3): score pending +> **Key**: `e128184-must-follow-a-temp-directory-into-the-method-that-delet` +> **Class**: `design`, **Lang**: `cs`, **File**: `src/Harvest/Commands/ReadCommand.cs` +> **Pattern**: A recursive delete of a directory built from `Path.GetTempPath()` stays sound when the deletion moves into a helper +> **Why**: E128184 matches the delete call against a path created in the same method body, so extracting the cleanup into `DeleteTempDirectory(writer, tempDir)` reports a false positive on the package-private producer of that path. The rule should accept a `DirectoryInfo` that carries the temp-root provenance, or at least a helper in the same type. +> **Source**: `session friction 2026-11-14T18:22:00Z`, occurrence 1 of 3 diff --git a/lode/dotnet/performance.md b/lode/dotnet/performance.md index 23a56903..3a3d4a1a 100644 --- a/lode/dotnet/performance.md +++ b/lode/dotnet/performance.md @@ -1,5 +1,5 @@ # .NET Performance -*Updated: 2026-11-11T03:20:00Z* +*Updated: 2026-11-15T17:35:31Z* Performance guidance for the app projects. The source is the BlazingFastDotnet notes (`github.com/EgorBo/BlazingFastDotnet`). The notes warn that some advice @@ -27,8 +27,8 @@ it into a project file. It sets these: a test project, and not a benchmark project. One conditional group in `Directory.Build.targets` covers the three application projects. That file loads after the project body, so the role markers are set when the condition - runs. The analyzer assemblies and the `net10.0` leg stay off the switch. A - method that keeps `[AsyncStateMachine]` is not using runtime async. + runs. The analyzer assemblies stay off the switch. A method that keeps + `[AsyncStateMachine]` is not using runtime async. The three runtime projects set `IsAotCompatible` true. The property turns on the trim and AOT analyzers and marks the assembly trimmable. The web project @@ -171,6 +171,10 @@ from the end of the list, so the cost follows the requested count and not the stored count. Remove the guard only after a different structure replaces the shared list. See [test-patterns.md](test-patterns.md). +`IGreetingRepository` returns `ValueTask`, because every in-memory operation +completes synchronously. A read then allocates only the result array, and a +save allocates nothing. A caller awaits the result once, or passes it on. + An earlier read sorted a full copy of the list on every call. At 50,000 stored greetings that read allocated 1.9 GB per second and reached 1,655 requests per second. The current read allocates 0.11 GB per second and reaches 7,278 diff --git a/plans/review-2026-11-14-general/general-context.md b/plans/review-2026-11-14-general/general-context.md new file mode 100644 index 00000000..cf013f01 --- /dev/null +++ b/plans/review-2026-11-14-general/general-context.md @@ -0,0 +1,73 @@ +# Review Context: days 2 Union Review + +*Updated: 2026-11-14T00:42:34Z* + +## Diff Summary + +Base `be24a59`, head `b70fb1c`, 16 commits, 140 files, 8044 insertions, 2701 deletions. +The diff was delivered as 17 slices of 40KB or less at file boundaries. + +## Vectors Run + +| Vector | Result | +| ------ | ------ | +| `scripts/build.sh` | exit 0, 0 warnings, 0 errors | +| `scripts/diagnostics.sh --group` | no diagnostics | +| `scripts/violation-scan.sh` | 4 hits, all analyzer source fixtures | +| `scripts/suppression-scan.sh --json` | test-only pragmas, pre-existing | +| `scripts/analyzer-stats.sh --json` | rule inventory only | +| `scripts/deps-graph.sh --orphans --json` | two pins, both classified | +| `scripts/nuget-heat-map.sh --json` | 13 packages, no finding | +| `scripts/internal/mechanical-diff.sh --json` | no mechanical files | +| Roslyn navigator | MCP server not queried, no result | + +## Reviewers Run + +| Reviewer | Coverage | Outcome | +| -------- | -------- | ------- | +| security-reviewer | slices 2, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 | 1 High, 4 Medium, 10 Low | +| code-reviewer | slices 1 through 17 | 9 High, 21 Medium, 40 Low | +| adversarial-review | three attackers over slices 1-17, one defender | 4 High, 5 Medium, 8 Low | +| code-review | full range, effort high | 10 findings, no severity split | +| ponytail-review | main-context lean pass | 6 lean findings | +| mr-sparkle-dotnet | build, diagnostics, suppressions, packages | no gate breach | +| code-reviewer slice 7 | docs and config | 1 Medium, 4 Low | + +## Dedup Report + +The defender pass validated the 13 merged Critical and High findings. + +| Merged from | Reviewers | Result | +| ----------- | --------- | ------ | +| Nested fix drops outer `*` | 3 | CONFIRMED High | +| Class not expanded in atom comparison | 2 | CONFIRMED High | +| Start-info local never binds | 4 | CONFIRMED High | +| Compression stream in `Compress` mode | 2 | CONFIRMED High | +| Identifier-text bound detection | 4 | CONFIRMED High | +| `ContentLength` guard fails open | 2 | CONFIRMED High | +| Guarded catch-all treated as exhaustive | 4 | CONFIRMED High | +| `this.p1` and `this.p2` share a root | 2 | Downgraded Medium | +| `{1,}` rewrite leaves the diagnostic | 2 | Downgraded Medium | +| `Position` assignment counts as a read | 1 | Downgraded Medium | +| Type-wide `MaxResponseContentBufferSize` | 2 | Downgraded Medium | +| Tests bypass the shared runner | 2 | Downgraded Medium | +| Target-typed `new(...)` missed | 3 | Downgraded Medium | + +Dropped findings: none. + +A late High finding was missing from the defender batch: `lode/dotnet/release-tracking.md:170`. +The main context confirmed it against source. `AnalyzerReleases.Shipped.md` carries release +3.1.0 with E128227, and `E128.Analyzers.csproj` pins version 3.1.0, while the table ends at +3.0.0. Confirmed High. + +## Notes + +- `scripts/internal/cr-target.sh` reports 15 untracked files that do not exist on disk. The + file list is otherwise correct. Treat the untracked array as unreliable. +- Build clean lowers unconfirmed Medium and Low compliance findings to advisory. +- Tests were not run during the review. The adversarial functionality attacker ran the + shipping-script suite (30 of 30 cases) and the union-switch tests (7 of 7). +- The three adversarial attackers ran as subagents. Their defender was folded into the single + merged defender pass. + +Related: [plan](general-plan.md), [tasks](general-tasks.md). diff --git a/plans/review-2026-11-14-general/general-plan.md b/plans/review-2026-11-14-general/general-plan.md new file mode 100644 index 00000000..a45954b2 --- /dev/null +++ b/plans/review-2026-11-14-general/general-plan.md @@ -0,0 +1,70 @@ +# Review Plan: days 2 Union Review + +*Updated: 2026-11-14T00:42:34Z* + +Target: commits newer than 2 days (base `be24a59`, head `b70fb1c`), 140 files, 16 commits. +Verdict: Resolved. All 8 High findings fixed on `fix/review-2026-11-14-general`. +`scripts/check.sh` green: shell, format, build, 2992 tests (2987 passed, 3 fixed at the +gate, 2 skipped). The 3 gate failures came from `HttpContentHeadersTypeName` resolving +`System.Net.Http.HttpContentHeaders` instead of `System.Net.Http.Headers.HttpContentHeaders`, +which left the ContentLength bound undetected. One-line fix in +`HttpBodyReadWithoutSizeBoundAnalyzer.cs`. +The Medium findings are advisory and stay unapplied. + +## Findings + +| # | Severity | File | Problem | +| - | -------- | ---- | ------- | +| 1 | High | `src/E128.Analyzers.CodeFixers/Reliability/GeneratedRegexNestedCodeFixProvider.cs:53` | Single-atom fix drops the outer `*`, so `(a+)*` becomes `(a+)` and stops matching the empty string. | +| 2 | High | `src/E128.Analyzers/Reliability/GeneratedRegexHelpers.cs:289` | Atom comparison does not expand character classes, so `(?:/[^\s:"']+)+` is exempted and stays exponential. | +| 3 | High | `src/E128.Analyzers/Reliability/HandRolledProcessCaptureAnalyzer.cs:156` | `FlagBinds` never reaches `LocalLinksToProcess`, so a start-info local set after creation never binds. | +| 4 | High | `src/E128.Analyzers/Performance/ReadOnlyMemoryStreamAnalyzer.cs:57-66,232-234` | Compression streams count as read-only consumers in `Compress` mode. | +| 5 | High | `src/E128.Analyzers/Security/HttpBodyReadWithoutSizeBoundAnalyzer.cs:142-157` | Bound detection matches identifier text, not a bounding call or an ordering. | +| 6 | High | `src/E128.Analyzers/README.md:3274-3286` | Documented `ContentLength` guard fails open on a chunked response. | +| 7 | High | `src/E128.Analyzers/Design/UnionSwitchDiscardArmAnalyzer.cs:124-147` | A `when`-guarded discard counts as a catch-all, and the fix produces a non-exhaustive switch. | +| 8 | High | `lode/dotnet/release-tracking.md:170` | The release-to-rule table ends at 3.0.0, but the head commit ships 3.1.0 with E128227. | + +## Phases + +### Phase 1: GeneratedRegex correctness + +Fix findings 1 and 2. Restore language preservation in the nested-quantifier fix. Expand +class contents in the atom comparison, or record the limit in the rule contract. Update the +slash test and the README claim in the same change. + +### Phase 2: E128223 process binding + +Fix finding 3. Route a start-info local receiver through `LocalLinksToProcess`. Add tests for +the post-creation assignment and for `process.StartInfo = psi`. + +### Phase 3: Performance rules + +Fix finding 4. Require `CompressionMode.Decompress` for the compression wrapper types. + +### Phase 4: E128227 size bound + +Fix findings 5 and 6. Accept only a resolved `LoadIntoBufferAsync(long)` overload, or a +null-safe pre-read comparison. Replace the documented remediation and update the test that +locks the weak shape in. + +### Phase 5: E128220 catch-all + +Fix finding 7. Treat a guarded discard or var arm as not exhaustive. Add a test for +`_ when cond =>`. + +### Phase 6: Release record + +Fix finding 8. Add the 3.1.0 row with E128227 and bump the file timestamp. + +## Medium Findings + +Six findings were lowered to Medium by the defender pass: + +- `ProcessLaunchScope.cs:19-32`: `this.p1` and `this.p2` share one root symbol. +- `GeneratedRegexNestedCodeFixProvider.cs:58-60`: `{1,}` rewrite leaves E128014 firing. +- `ReadOnlyMemoryStreamAnalyzer.cs:55,208-218`: a `Position` assignment counts as a read. +- `HttpBodyReadWithoutSizeBoundAnalyzer.cs:47,149-150`: `MaxResponseContentBufferSize` is trusted across the type. +- `tests/E128.Analyzers.Tests/*`: eight test classes bypass the shared runner. +- `ComparerSetConstructionAnalyzer.cs:62` and `ReadOnlyMemoryStreamAnalyzer.cs:102`: target-typed `new(...)` is missed. + +Related: [tasks](general-tasks.md), [context](general-context.md). diff --git a/plans/review-2026-11-14-general/general-tasks.md b/plans/review-2026-11-14-general/general-tasks.md new file mode 100644 index 00000000..f0ee3d3c --- /dev/null +++ b/plans/review-2026-11-14-general/general-tasks.md @@ -0,0 +1,14 @@ +# Review Tasks: days 2 Union Review + +*Updated: 2026-11-14T00:42:34Z* + +- [x] `src/E128.Analyzers.CodeFixers/Reliability/GeneratedRegexNestedCodeFixProvider.cs:53` Removing the outer `*` changes the pattern language for the single-atom body. Fix: strip the quantifier only when the outer is `+` or the inner is `*`; add a `(a+)*` test. Severity: High. Source: security-reviewer, code-reviewer, adversarial-review. +- [x] `src/E128.Analyzers/Reliability/GeneratedRegexHelpers.cs:289` The atom comparison does not expand character classes, so a catastrophic group is exempted. Fix: expand class contents in the comparison, or state the limit in the README and fix the slash test. Severity: High. Source: adversarial-review, code-reviewer. +- [x] `src/E128.Analyzers/Reliability/HandRolledProcessCaptureAnalyzer.cs:156` A start-info local set after creation never binds, because `FlagBinds` never calls `LocalLinksToProcess`. Fix: route a local receiver through `LocalLinksToProcess`; add assignment-shape tests. Severity: High. Source: code-reviewer, security-reviewer, adversarial-review, code-review. +- [x] `src/E128.Analyzers/Performance/ReadOnlyMemoryStreamAnalyzer.cs:57-66,232-234` Compression streams count as read-only consumers in `Compress` mode. Fix: require the `CompressionMode.Decompress` argument for the three wrapper types. Severity: High. Source: code-reviewer, security-reviewer. +- [x] `src/E128.Analyzers/Security/HttpBodyReadWithoutSizeBoundAnalyzer.cs:142-157` Bound detection matches identifier text, so a parameterless `LoadIntoBufferAsync()` or an unrelated `ContentLength` silences the rule. Fix: resolve the invocation symbol and require the capped overload or a null-safe comparison before the read. Severity: High. Source: code-reviewer, security-reviewer, adversarial-review, code-review. +- [x] `src/E128.Analyzers/README.md:3274-3286` The documented `ContentLength` guard fails open on a chunked response. Fix: document a real bound and update `Silent_WhenContentLengthIsCheckedFirst`. Severity: High. Source: adversarial-review, security-reviewer. +- [x] `src/E128.Analyzers/Design/UnionSwitchDiscardArmAnalyzer.cs:124-147` A `when`-guarded discard counts as a catch-all, and the fix creates a non-exhaustive switch. Fix: treat a guarded arm as not exhaustive; add a `_ when cond =>` test. Severity: High. Source: security-reviewer, adversarial-review, code-review, code-reviewer. +- [x] `lode/dotnet/release-tracking.md:170` The release table ends at 3.0.0, but the head commit ships 3.1.0 with E128227. Fix: add the 3.1.0 row and bump the timestamp. Severity: High. Source: code-reviewer. + +Related: [plan](general-plan.md), [context](general-context.md). diff --git a/src/E128.Reference.Core/Repositories/IGreetingRepository.cs b/src/E128.Reference.Core/Repositories/IGreetingRepository.cs index 3f3a5c62..9cc11c38 100644 --- a/src/E128.Reference.Core/Repositories/IGreetingRepository.cs +++ b/src/E128.Reference.Core/Repositories/IGreetingRepository.cs @@ -10,7 +10,7 @@ namespace E128.Reference.Core.Repositories; /// public interface IGreetingRepository { - Task SaveAsync(Greeting greeting, CancellationToken cancellationToken); + ValueTask SaveAsync(Greeting greeting, CancellationToken cancellationToken); - Task> GetRecentAsync(int count, CancellationToken cancellationToken); + ValueTask> GetRecentAsync(int count, CancellationToken cancellationToken); } diff --git a/src/E128.Reference.Core/Repositories/InMemoryGreetingRepository.cs b/src/E128.Reference.Core/Repositories/InMemoryGreetingRepository.cs index bd42141e..9b377844 100644 --- a/src/E128.Reference.Core/Repositories/InMemoryGreetingRepository.cs +++ b/src/E128.Reference.Core/Repositories/InMemoryGreetingRepository.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Threading; using System.Threading.Tasks; using E128.Reference.Core.Models; @@ -16,7 +15,7 @@ public sealed class InMemoryGreetingRepository : IGreetingRepository private readonly Lock _gate = new(); private readonly List _greetings = []; - public Task SaveAsync(Greeting greeting, CancellationToken cancellationToken) + public ValueTask SaveAsync(Greeting greeting, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(greeting); @@ -25,23 +24,30 @@ public Task SaveAsync(Greeting greeting, CancellationToken cancellationToken) _greetings.Add(greeting); } - return Task.CompletedTask; + return ValueTask.CompletedTask; } - public Task> GetRecentAsync(int count, CancellationToken cancellationToken) + public ValueTask> GetRecentAsync(int count, CancellationToken cancellationToken) { Greeting[] recent; lock (_gate) { - recent = - [ - .. _greetings - .OrderByDescending(static greeting => greeting.CreatedAt) - .Take(count) - ]; + // Recency follows save order. GreetingService stamps CreatedAt at save time, + // so save order and timestamp order agree. + // The JIT cannot hoist a field read across the indexer call, so bind the + // list and its last index once. + var greetings = _greetings; + var last = greetings.Count - 1; + var take = Math.Clamp(count, 0, last + 1); + recent = new Greeting[take]; + + for (var i = 0; i < take; i++) + { + recent[i] = greetings[last - i]; + } } - return Task.FromResult>(recent); + return ValueTask.FromResult>(recent); } } diff --git a/tests/E128.Reference.Core.Tests/InMemoryGreetingRepositoryTests.cs b/tests/E128.Reference.Core.Tests/InMemoryGreetingRepositoryTests.cs index 1bfa831a..e625585c 100644 --- a/tests/E128.Reference.Core.Tests/InMemoryGreetingRepositoryTests.cs +++ b/tests/E128.Reference.Core.Tests/InMemoryGreetingRepositoryTests.cs @@ -18,9 +18,10 @@ public sealed class InMemoryGreetingRepositoryTests [Fact] [Trait("Category", "CI")] - public Task SaveAsync_Throws_WhenGreetingIsNull() + public async Task SaveAsync_Throws_WhenGreetingIsNull() { - return Assert.ThrowsAsync(() => _repository.SaveAsync(null!, TestContext.Current.CancellationToken)); + _ = await Assert.ThrowsAsync( + async () => await _repository.SaveAsync(null!, TestContext.Current.CancellationToken)); } [Fact] @@ -110,7 +111,7 @@ Thread StartThread(Action body) for (var i = 0; i < perWriter; i++) { var save = _repository.SaveAsync(new Greeting("msg", "X", BaseTime), TestContext.Current.CancellationToken); - Assert.True(save.IsCompletedSuccessfully); + Assert.True(save.AsTask().IsCompletedSuccessfully); } })) .ToArray(); @@ -120,7 +121,7 @@ Thread StartThread(Action body) for (var i = 0; i < 200; i++) { var read = _repository.GetRecentAsync(10, TestContext.Current.CancellationToken); - Assert.True(read.IsCompletedSuccessfully); + Assert.True(read.AsTask().IsCompletedSuccessfully); } });