Skip to content

Tests: task surface coverage (§14) #531

Closed

Description

@ehartford

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

  1. 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.
  2. Add cancellation surface coverage: .cancel() typechecks and causes eventual cleanup without blocking the caller.
  3. Add compile-error coverage for wrong arity on cancel() and is_done().
  4. 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.
  5. 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:

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 :test pass.

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

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions