closeCancelsTheJobTheInstanceOwnsInTheGivenScope

AutoCloseable.close cancels the job the instance owns inside the scope it was given — the observable form of "ScopedCloseable.ownJob is cancelled on close".

The suite cannot name ScopedCloseable.ownJob: it is protected, so a different module has no handle on it. What it can name is the set of children the instance put into the scope create was handed, which for a conforming ScopedCloseable is exactly that job — the constructor makes it a structural child of the parent scope's Job and launches everything else beneath it.

Why this is not closeStopsAllBackgroundJobs again. That property quantifies over what the binding reports; this one quantifies over what the instance structurally owns. The gap between them is where a coroutine launched into the caller's scope instead of ScopedCloseable.scope hides: AutoCloseable.close cancels only ScopedCloseable.ownJob, so such a coroutine survives the close, and it survives silently as long as backgroundJobsOf does not list it.

The children are captured before the close, and that is the whole reason this test is not itself vacuous. A job leaves its parent's Job.children once it completes, so reading them after the cancel would very often be a none { } over an empty sequence — green by absence, which is the defect this suite was audited for. Captured first and asserted non-empty, the quantifier has something to quantify over.

The capture is a snapshot, and what that does and does not expose it to. It is not a race: this suite closes on a single-threaded virtual-time dispatcher, from the test body, after the capture — there is no second closer, so the lock-free Job.children traversal has nothing mutating underneath it. (A genuinely concurrent close() is a different property with a different mechanism, and it lives in :kuilt-core's real-threaded ScopedCloseableCloseOnceCapabilityConcurrencyTest, which cannot be a subclass here — :kuilt-conformance depends on :kuilt-core, so the reverse edge would be a cycle.)

What the snapshot genuinely cannot see is a coroutine attached to the caller's scope after construction — a coordinator that launches lazily on first use rather than in its constructor escapes this assertion, because there was nothing to capture when the capture happened. That residual is inherent to the shape rather than an oversight of it: capturing after the close instead is strictly worse, since it reintroduces exactly the green-by- absence hole this test exists to close.