Skip to content

feat(analyzers): read elapsed-time bounds, completion checks, polling and helper timeouts in C# (spec 014 phase 2) - #192

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

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

Conversation

@adrian-xping

Copy link
Copy Markdown
Contributor

Spec 014 (docs/specs/core/014-csharp-timeout-extraction.md), phase 2: Assertions and helpers.

Phase 2 of Spec 014. Spec 013's assertion extractor now exposes an internal hook (TimeoutHooks.cs): the same-file helpers it followed, with each parameter's argument, and per recognized assertion its upper-bound arguments, !-pushed condition comparisons and NUnit constraint. The timeout extractor uses it to emit elapsedAssertion timeouts for upper bounds on elapsed subjects (Elapsed, ElapsedMilliseconds, Total*/Ticks, GetElapsedTime, FA ExecutionTime[Of], unchanged locals; ElapsedTicks and unit mismatches unresolved), with the assertion's span and the elapsed root as subject so §8.4 can pair them with XP001's bound. Completion checks (FA CompleteWithin[Async], Shouldly Should.CompleteIn) and FA NotThrowAfter[Async] are new table rows; NUnit .After(n) with unit links is read from the constraint in NUnit tests. Followed helpers' bodies are scanned once per call site, with parameters folded as the caller's arguments (unmapped ones unresolved). TimeoutFact gains an optional Subject. New fixtures: samples/timeouts/elapsed, completion, polling, helpers; catalog gains one elapsed test for timeout.subject.

Notes

  • §8.5 (expected.resolved) is not built: ExpectedValue.Resolved doesn't exist yet (Spec 085 phase 1). Marked TODO(spec) in TimeoutExtractor and CSharpTestAnalyzer; the §8.5 tests from §13 are not added.
  • Spec 014 §10 updated: no 'holds something' parameter was added to the shared resolver. Spec 013's extractor already follows every directly called one-candidate same-file helper whatever it holds, so the timeout side just reads the helpers Spec 013 followed. Spec 013 §16's as-built note says the same.
  • Helper substitution for timeouts happens at fold time (FoldScope maps a helper parameter to its call's argument, folded in the caller's scope), not by rewriting syntax, so names stay attached to the tree and fields in the caller's class still resolve. Assertion-side subject text still goes through Spec 013's substitution, so an elapsed subject in a helper is written in the caller's terms (sw.ElapsedMilliseconds).
  • Spec 014 §8.1 widened slightly: .TotalX and .Ticks are read on any elapsed duration form (for example Stopwatch.GetElapsedTime(start).TotalMilliseconds), not only on <x>.Elapsed. Spec table updated.
  • Rows with source elapsedAssertion or polling take the whole call as their span (Spec 014 §11's 'inside an assertion' row), matching Spec 013's span for the unrecognized assertion on the same call.
  • NUnit polling is read from the constraint even when Spec 013 can't read the rest of the constraint (the hook passes the constraint before the reading's null check).
  • Spec 003's catalog row updated to mention the elapsedAssertion timeout with subject; the new catalog test's valueOrigin (realCall) is hand-written, as Spec 016 owns that field.

Spec updated: yes

Phase row
Phase Branch suffix Covers Tests Depends on
2. Assertions and helpers 2-assertions §8–§10 (§8.5 once ExpectedValue.Resolved exists, Spec 085 phase 1; else a TODO(spec)): elapsed subjects through Spec 013's hook, completion rows, NUnit and FluentAssertions polling, helpers; the elapsed, completion, polling, helpers folders. The rest. 1 (Spec 013 merged into main)

Opened by spec-runner.

… and helper timeouts in C# (spec 014 phase 2)

Spec 013's extractor hands Spec 014 the helpers it followed and, per recognized
assertion, its upper bounds, condition comparisons and NUnit constraint. The
timeout extractor reads elapsed upper bounds (§8.1-§8.2) with the assertion's
span and the elapsed root as subject, completion checks (§8.3), NUnit .After(n)
and FluentAssertions NotThrowAfter polling (§9), and helper limits once per call
site with parameters folded as the caller's arguments (§10). TimeoutFact gains
an optional Subject. §8.5 stays a TODO(spec) until Spec 085 adds
ExpectedValue.Resolved.

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

Copy link
Copy Markdown
Contributor Author

spec-runner review, phase 2, round 1

Finding Severity Where Summary Decision Reason
R1-1 important src/Xping.Analyzers.CSharp/Timeouts/TimeValues.cs:379 A helper parameter always folds as the call site's argument, even when the helper writes to it again. TimeValues.Name checks FoldScope.IsParameter before the locals, so it never consults LocalScope._written. A test local or a test parameter that is written again is unresolved (§5.2), but a helper parameter that is written again still reads as the caller's value. Spec 013 §12.2 and Spec 014 §10 only map a parameter to its argument, and §5.2 treats a name written again as unknown. fix Confirmed. TimeValues.Name (TimeValues.cs:367) returns the call-site argument for a helper parameter before it checks whether the helper writes the parameter again. LocalScope._written already records such writes, but only Unchanged() reads it, and that is never reached for helper parameters. Spec 014 §5.2 treats a name that is written again as unresolved, and §10 only maps a parameter to its argument. This is in phase 2's scope (§10 helpers). Fix: expose a Written(name) on LocalScope, return Unresolved in the IsParameter branch when the helper's scope has the parameter written, and add a test next to AnUnmappedHelperParameterMakesTheTimeoutUnresolved.

…ved (spec 014 phase 2)

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

Copy link
Copy Markdown
Contributor Author

spec-runner review, phase 2, round 2

No findings.

@adrian-xping
adrian-xping merged commit 4697e46 into feat/spec-014-csharp-timeout-extraction Dec 4, 2026
@adrian-xping
adrian-xping deleted the phase/spec-014-csharp-timeout-extraction/2-assertions branch December 4, 2026 00:44
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