Skip to content

feat(analyzers): extract C# timeouts from attributes, cancellation sources, waits and delay races (spec 014 phase 1) - #191

Merged
adrian-xping merged 2 commits into
feat/spec-014-csharp-timeout-extractionfrom
phase/spec-014-csharp-timeout-extraction/1-engine
Dec 4, 2026
Merged

adrian-xping merged 2 commits into
feat/spec-014-csharp-timeout-extractionfrom
phase/spec-014-csharp-timeout-extraction/1-engine

Conversation

@adrian-xping

Copy link
Copy Markdown
Contributor

Spec 014 (docs/specs/core/014-csharp-timeout-extraction.md), phase 1: Engine and calls.

Spec 014 phase 1. New Xping.Analyzers.CSharp/Timeouts/: timeouts.json (14 rows: xUnit Timeout =, NUnit Timeout/CancelAfter/MaxTime, MSTest Timeout, CancellationTokenSource, CancelAfter, WaitAsync, Wait, WaitOne, Task.WaitAll/WaitAny, WaitHandle.WaitAll/WaitAny), TimeoutPatterns (load + §4.4 validation), TimeValues (§5 fold and §5.2 name lookup) and TimeoutExtractor (§3, §4.3 binding, §6.2 NUnit class attributes, §7.3 ifUnknown, §7.4 delay races, §11 spans). CSharpTestAnalyzer fills timeouts; LocalScope now records declared types and whether a name is declared at all; AssertionFile gains same-file member lookup. Eight fixture folders under samples/timeouts/ (slow-runner, framework-attributes, cancellation, waits, delay-race, values, not-limits, preprocessor) with reviewed expected.json, plus the §13 phase-1 tests and a timeout part in FactsFixtureTests (§12.2: problem1-timeout and catalog match without correction).

Notes

  • Phase 2 work (§8 elapsed/completion, §9 polling, §10 helpers, §8.5 expected.resolved, TimeoutFact.Subject) is left out and marked TODO(spec) in TimeoutExtractor and CSharpTestAnalyzer.
  • §5.2 member lookup: one 'step' is an enclosing class together with its partial parts and same-file bases (as Spec 013 §12.1 collects them). Two candidates in one step are unresolved, so a property overridden in a same-file derived class is unresolved for that reason as well as for being virtual/override.
  • 'Never assigned in the file' for fields and auto-properties is checked by the written name's last identifier anywhere in the tree (assignments, ++/--, ref/out, object-initializer members). That's conservative: a same-named local or another type's member being written also makes the field unresolved.
  • §4.4's overlap rule compares framework literally, as the spec says: a framework-less row and an nunit row with the same kind/member/arity aren't refused. No such pair is in the table.
  • Validation also refuses an unknown on value and unknown top-level fields, which fall under §4.4's 'a field or value is unknown'.
  • §6.2 class attributes are read from the type declaration that contains the test method; attributes on other partial parts of the same class are not read.
  • Task.Delay in a race binds only (limit) and (limit, cancellationToken|timeProvider), per §7.4; the .NET 8 three-argument overload gives no fact.
  • The framework-attributes fixture puts xUnit, NUnit and MSTest tests in one file without NUnit/MSTest usings, because a using NUnit.Framework would turn xUnit [Theory] into NUnit (Spec 012 §4.3). The file has a comment saying so.

Spec updated: no

Phase row
Phase Branch suffix Covers Tests Depends on
1. Engine and calls 1-engine §3–§7, §11: the table and loader, folding, same-file constants, framework attributes, cancellation, waits, delay races; the slow-runner, framework-attributes, cancellation, waits, delay-race, values, not-limits, preprocessor folders; §12.2. All but elapsed, completion, polling and helpers. — (Spec 012)

Opened by spec-runner.

…urces, waits and delay races (spec 014 phase 1)

Adds the embedded timeout pattern table with its loader and validation, the value folder
(literals, TimeSpan forms, arithmetic, same-file locals, fields and properties), and the
extractor for framework attributes (xUnit, NUnit incl. class attributes, MSTest),
CancellationTokenSource/CancelAfter, WaitAsync/Wait/WaitOne/WaitAll/WaitAny and Task.WhenAny
delay races. CSharpTestAnalyzer now fills `timeouts`. Fixtures under samples/timeouts/.

Spec-Runner: spec=014 phase=1 step=implement
@adrian-xping

Copy link
Copy Markdown
Contributor Author

spec-runner review, phase 1, round 1

Finding Severity Where Summary Decision Reason
R1-1 nit src/Xping.Analyzers.CSharp/Timeouts/TimeoutExtractor.cs:189 Delay races are emitted per WhenAny reference, not per Task.Delay. §7.4 says "One fact per such Task.Delay", but WhenAny() resolves a delay local through scope.Unchanged at every WhenAny argument that names it. So one Task.Delay that two WhenAny calls use, or that appears twice in one WhenAny, gives several facts with the same span. fix Real. Spec 014 §7.4 says one fact per Task.Delay. WhenAny() emits a fact at every WhenAny argument that resolves to the same Task.Delay node, so shared or repeated delays give duplicate facts. Dedupe by the Task.Delay node across the whole Extract call.
R1-2 nit src/Xping.Analyzers.CSharp/Timeouts/TimeoutExtractor.cs:266 With ifUnknown: skip, Judge returns no fact for any unfolded argument and never checks the argument's declared type. The last paragraph of §7.3 says a declared type written as TimeSpan, int, long or double makes the argument a limit (folded or unresolved) "whatever its name". That paragraph sits under §7.3 as a whole, not only the token bullet, and skip exists only because the argument might be a task. The code applies the declared-type check only on the Token path (IsToken). fix Real. The closing paragraph of §7.3 applies to every ifUnknown mode, but Judge applies the declared-type check only on the token path, so with skip a TimeSpan/int/long/double-typed argument that doesn't fold gives no fact. Check for a declared limit type before the Skip early-return so it yields an unresolved fact.

… skip argument is unresolved (spec 014 phase 1)

Spec-Runner: spec=014 phase=1 step=fix-1
@adrian-xping

Copy link
Copy Markdown
Contributor Author

spec-runner review, phase 1, round 2

No findings.

@adrian-xping
adrian-xping merged commit 9be4135 into feat/spec-014-csharp-timeout-extraction Dec 4, 2026
3 checks passed
@adrian-xping
adrian-xping deleted the phase/spec-014-csharp-timeout-extraction/1-engine branch December 4, 2026 00:19
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