From 516b36b0419d319f6316bc5f2ecb6ab0f797ab58 Mon Sep 17 00:00:00 2001 From: swapnil Date: Wed, 30 Sep 2026 00:39:55 -0700 Subject: [PATCH] tests: the hosted-service delete checks split into a registered and an unregistered service Symptom: tests/run.py csharp/unmodelled-entry-not-local failed two checks on 0.1.9: impact --delete on SweepWorker (a BackgroundService that Program adds with AddHostedService()) no longer printed "it extends / implements BackgroundService, which the graph does not contain", and --delete on SweepWorker.ExecuteAsync printed "NOT SAFE" instead of "NOT SAFE TO ASSUME". Cause: the C# framework-behavior pipelines rules now link an AddHostedService() site to T's hook overrides (callback_registered). The registration is a real dependent, so the answer is the stronger one: NOT SAFE, with Program.
$ listed as calling / registering ExecuteAsync. The library-base note is printed only when nothing in the graph uses the declaration, so it is correctly absent. The checks still described the service as an entry the graph does not model. Fix: the unmodelled-entry checks move to IdleWorker, a BackgroundService no registration in the graph names, which still gets NOT SAFE TO ASSUME and the library-base note. SweepWorker gets two checks for the modelled answer: NOT SAFE with the registration site, never NOT SAFE TO ASSUME or the dead-code verdict. No engine or query code changes. tests/run.py --lang csharp: 202 of 204 before, 206 of 206 after. graph/test/csharp/tools/pipelines-test.sh: ok. Co-authored-by: axiomcode-bot[bot] <334110751+axiomcode-bot[bot]@users.noreply.github.com> --- .../unmodelled-entry-not-local/case.json | 22 ++++++++++++++----- .../src/App/Workers.cs | 6 +++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/tests/cases/csharp/unmodelled-entry-not-local/case.json b/tests/cases/csharp/unmodelled-entry-not-local/case.json index 02c1e1b14..ff4ffef32 100644 --- a/tests/cases/csharp/unmodelled-entry-not-local/case.json +++ b/tests/cases/csharp/unmodelled-entry-not-local/case.json @@ -2,17 +2,29 @@ "lang": "csharp", "checks": [ { - "why": "--delete on a hosted service says a framework calls it, not the dead-code verdict (#1446)", - "run": ["impact", "SweepWorker", "--kind", "type", "--delete"], - "want": ["NOT SAFE", "it extends / implements BackgroundService, which the graph does not contain", "Program.
$ src/App/Program.cs:2 — ", "names it (METHOD_TYPE_ARGUMENT)"], + "why": "--delete on a hosted service the graph sees no registration for says a framework calls it, not the dead-code verdict (#1446)", + "run": ["impact", "IdleWorker", "--kind", "type", "--delete"], + "want": ["NOT SAFE TO ASSUME", "it extends / implements BackgroundService, which the graph does not contain"], "avoid": ["· nothing", "no dependent at any certainty in this graph. Before deleting"] }, { - "why": "--delete on the hosted service's method says the same (#1446)", - "run": ["impact", "SweepWorker.ExecuteAsync", "--delete"], + "why": "--delete on that hosted service's method says the same (#1446)", + "run": ["impact", "IdleWorker.ExecuteAsync", "--delete"], "want": ["NOT SAFE TO ASSUME", "a framework calls it"], "avoid": ["· nothing"] }, + { + "why": "a hosted service AddHostedService() registers: the registration is a dependent, so the verdict is NOT SAFE and names the site", + "run": ["impact", "SweepWorker", "--kind", "type", "--delete"], + "want": ["NOT SAFE — 1 callable(s) call or receive it", "Program.
$ src/App/Program.cs:2 — ", "names it (METHOD_TYPE_ARGUMENT)"], + "avoid": ["· nothing", "NOT SAFE TO ASSUME", "no dependent at any certainty in this graph. Before deleting"] + }, + { + "why": "the registered hosted service's method: the registration site hands it to the framework, so it is not dead code", + "run": ["impact", "SweepWorker.ExecuteAsync", "--delete"], + "want": ["NOT SAFE — 1 callable(s) call or receive it", "[registered] Program.
$ src/App/Program.cs:2"], + "avoid": ["· nothing", "NOT SAFE TO ASSUME"] + }, { "why": "control: a type nothing registers, with no library base, keeps the dead-code verdict", "run": ["impact", "Unused", "--kind", "type", "--delete"], diff --git a/tests/cases/csharp/unmodelled-entry-not-local/src/App/Workers.cs b/tests/cases/csharp/unmodelled-entry-not-local/src/App/Workers.cs index ef53495ea..c4996573f 100644 --- a/tests/cases/csharp/unmodelled-entry-not-local/src/App/Workers.cs +++ b/tests/cases/csharp/unmodelled-entry-not-local/src/App/Workers.cs @@ -19,3 +19,9 @@ public void OnOrder(string body) { } [Obsolete] public void Legacy() { } } + +// a hosted service no registration in the graph names +public sealed class IdleWorker : BackgroundService +{ + protected override Task ExecuteAsync(CancellationToken t) => Task.CompletedTask; +}