Skip to content

test: add regression test for parent_session_id task result routing #180

@randomm

Description

@randomm

Task Description

PR #179 (commit fbeb585ea) fixed the async task result delivery bug by adding parent_session_id to TaskMetadata and routing results via parent session ID. However, no regression test was added for this specific routing logic.

If someone swaps parent_session_id back to session_id in getAndClearCompletedTasks() or hasUndeliveredCompletedTasks(), no test would catch it.

What to Test

File: packages/opencode/test/session/async-tasks.test.ts (new file, or add to existing test)

  1. Result retrieval by parent session ID: Call trackBackgroundTask() with a child session ID as 3rd arg and parent_session_id set to a different parent ID in metadata. Then call getAndClearCompletedTasks(parentID) — should find the result. Call with getAndClearCompletedTasks(childID) — should NOT find it.

  2. hasUndeliveredCompletedTasks routing: Same setup — hasUndeliveredCompletedTasks(parentID) should return true, hasUndeliveredCompletedTasks(childID) should return false.

  3. Event bus parentSessionID: When task completes, the BackgroundTaskEvent.Completed event should have parentSessionID matching the parent_session_id from metadata, NOT session_id.

  4. Cleanup uses child session_id: cleanupSessionMaps(childID) should clean up the task. cleanupSessionMaps(parentID) should NOT clean up the child's task.

Key Files

  • packages/opencode/src/session/async-tasks.ts — functions under test
  • packages/opencode/test/tool/check_task.test.ts — existing task tests for reference

Quality Gates (Non-Negotiable)

  • TDD: Tests written to fail if routing reverts to session_id
  • Coverage: Cover all 4 scenarios above
  • Linting: All code passes project linting rules
  • Local Verification: bun test passes

Acceptance Criteria

  • New test file or test block that specifically validates parent_session_id routing
  • Tests fail if parent_session_id is swapped back to session_id in retrieval functions
  • All existing tests continue to pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions