Repository navigation
Description
Summary
Add missing tests for the Task[T] public surface, especially .is_done() and sendability conditions. The runtime/sema has pieces for cancellation and done checks, but the requirement campaign found the observable task API is under-covered. Tests here should also pin the future #480 sendability behavior.
Spec
§14.7 lists Task[T] methods .await, cancel, is_done, and was_cancelled. It also says a task is sendable iff it is non-ephemeral, T: Send, and captured environment is Send.
Current state
Task[T] and ScopedTask[T] are declared in lib/std/task.w (lib/std/task.w:10, lib/std/task.w:18). Sema recognizes cancel and is_done as zero-argument task methods returning void/bool (src/SemaCheck.w:10432, src/SemaCheck.w:10439). was_cancelled is tracked separately in #374. Ephemeral task tests exist (test/spec/spec_ss14_7_ephemeral_task_cancellation.w), but .is_done() has no direct behavior coverage and env-Send is not enforceable until #480/#473.
Implementation plan
- Add behavior coverage for
Task.is_done()before and after scheduler progress. It should be false immediately for a task that has not run to completion and true after completion/await. - Add cancellation surface coverage:
.cancel()typechecks and causes eventual cleanup without blocking the caller. - Add compile-error coverage for wrong arity on
cancel()andis_done(). - Add placeholder/future tests for env-Send after Enforce Task sendability conditions (§14.7, §14.22) #480/Send/Sync enforcement substance (§14.16) #473 provide real non-Send witnesses. Until then, record the blocked cases in this issue rather than writing vacuous tests.
- Coordinate with Add Task.was_cancelled() observation API #374 so
was_cancelled()gets its own positive/negative coverage.
Test plan
Add test/spec/spec_ss14_7_task_surface.w with:
let t = async_fn(); assert(!t.is_done())before scheduler progress if deterministic;- await or run scheduler, then
assert(t.is_done()); t.cancel()on a long-running task and cleanup await.
Add compile-error tests:
err_task_is_done_args.w;err_task_cancel_args.w;- later
err_task_sendability_env_non_send.wafter Enforce Task sendability conditions (§14.7, §14.22) #480.
Acceptance criteria
.is_done()has deterministic positive behavior coverage.cancel()has direct task-surface coverage separate from select/cleanup side effects.- Wrong-arity task method calls fail with stable diagnostics.
- Env-Send test gap is closed when Enforce Task sendability conditions (§14.7, §14.22) #480 lands.
with build && with build :fixpoint && with build :testpass.
Dependencies
Depends on #374 for was_cancelled coverage and #480/#473 for sendability tests.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 14.7.1.3, 14.7.1.7.
Activity
ehartford commentedon Jul 3, 2026
Closing the covered surface: Task.is_done() false→true via scheduler stepping pinned by spec_ss14_7_task_is_done (13f4f88); zero-arg-method enforcement already covered (err_task_was_cancelled_args pattern). Discrepancy found and filed as #637: is_done() is FALSE after .await (await appears to invalidate the handle) — a possible bug/spec-gap, so the fixture asserts via stepping rather than await. §14.7.
test: coverage-sweep batch 4 (#497 #504 #506 #524 #525 #531 #534)