Compare commits

...
Author SHA1 Message Date
poli0981andClaude Fable 5.1 66388ec4f2 fix(capturehost): a candidate with no main module yet is unreadable, not absent — the resolver test's "visible" now means readable
TargetResolverTests.OneInstanceResolves went red on the hosted runner twice in one hour
(2026-09-04, on two unrelated PRs) with TargetNotRunning about a process the test had
just shown was enumerable. A freshly started process can be in GetProcessesByName's
snapshot before its image is mapped; Process.MainModule is then null, and CollectMatches
skipped it without counting it -- narrowing the set exactly the way its own comment says
"could not look" must not. The null-image case is now counted as unreadable, like a
process we lack the rights to read, so the honest answer at that instant is
TargetAmbiguous and never a false TargetNotRunning. WaitUntilAllVisible waits for
MainModule to be readable rather than for the process to appear, because that is the
state the positive cases are about; three consecutive local runs green.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-04 21:55:09 +07:00
3 changed files with 39 additions and 5 deletions

No files matched your search

+2
View File
@@ -260,6 +260,8 @@ GitHub release body, so a missing section will mean an empty release note.
### Fixed
- **A candidate with no main module yet is counted as unreadable, not dropped as absent.** `TargetResolverTests.OneInstanceResolves` went red on the hosted runner twice in one hour on 2026-09-04 with `TargetNotRunning` about a process the test had just shown was enumerable: a freshly started process can be in the snapshot before its image is mapped, `Process.MainModule` is then null, and the resolver skipped it without counting it — narrowing the set exactly the way its own comment says "could not look" must not. It is now counted like a process we lack the rights to read (so the answer is `TargetAmbiguous`, never a false `TargetNotRunning`), and the test's "visible" wait means readable, not merely enumerated.
- **Two review checklists were boxes that could not fail**, in `19_SAFETY` §Review checklist and in
the pull-request template: *"Is there a Tier-2 degradation path if the hook is unavailable?"*
Under a two-rung ladder the answer is always yes. Replaced with something falsifiable — does the
@@ -94,8 +94,19 @@ internal sealed class TargetResolver : ITargetResolver
// A process we cannot read is NOT a match — "could not look" must not widen the set —
// but it is counted below so it cannot narrow one either.
string? image = p.MainModule?.FileName;
if (image is not null
&& string.Equals(ExecutableIdentity.Normalise(image), normalisedExePath,
if (image is null)
{
// A process that is in the snapshot with NO main module yet -- it exists and has
// not finished mapping its image. Measured on the hosted runner 2026-09-04, twice
// in one hour, on a single freshly started instance: the resolver skipped it here
// without counting it and answered TargetNotRunning about a process it had just
// enumerated. "Could not look" must not narrow the set, and that includes this
// shape; it is counted like a process we lack the rights to read.
unreadable++;
continue;
}
if (string.Equals(ExecutableIdentity.Normalise(image), normalisedExePath,
StringComparison.OrdinalIgnoreCase))
{
matches.Add(p.Id);
@@ -61,14 +61,35 @@ public sealed class TargetResolverTests : IDisposable
SpinWait.SpinUntil(() =>
{
Process[] seen = Process.GetProcessesByName(name);
int count = seen.Length;
int count = 0;
foreach (Process p in seen)
{
p.Dispose();
try
{
// VISIBLE MEANS READABLE, not merely enumerated. A process can be in the
// snapshot before its image is mapped, with MainModule null -- measured on
// the hosted runner 2026-09-04 (OneInstanceResolves, twice in an hour): the
// count below reached 1 and the resolver then saw a candidate with no image.
// The resolver now counts that as unreadable rather than absent, so a test
// that resolved at that instant would read TargetAmbiguous -- still not the
// state under test. Wait for the state the case is about.
if (p.MainModule?.FileName is not null)
{
count++;
}
}
catch (Exception ex) when (ex is InvalidOperationException or System.ComponentModel.Win32Exception)
{
// Not readable yet; keep waiting.
}
finally
{
p.Dispose();
}
}
return count >= _children.Count;
}, TimeSpan.FromSeconds(10)).Should().BeTrue("every started instance must be enumerable before resolving");
}, TimeSpan.FromSeconds(10)).Should().BeTrue("every started instance must be enumerable AND readable before resolving");
}
private int? ResolveNow(out SessionEndReason reason)