Skip to content

Add unit tests for lib/extract-subagent-ids.ts #327

@NiveditJain

Description

@NiveditJain

lib/extract-subagent-ids.ts exports an extractSubagentIds(fileContent: string): string[] that scans newline-delimited JSON for toolUseResult.agentId values on user-type entries, deduplicates them, and returns the result. It has no unit test.

  1. Create __tests__/lib/extract-subagent-ids.test.ts — model it on __tests__/lib/format-duration.test.ts.
  2. Import: import { extractSubagentIds } from "@/lib/extract-subagent-ids";
  3. Cover: (a) happy path with two valid user entries → both ids returned and deduped, (b) malformed JSON line is skipped silently, (c) type !== "user" entries are ignored, (d) non-hex agentId strings are rejected (regex /^[a-f0-9]+$/), (e) missing toolUseResult is ignored, (f) empty input returns [].
  4. Run bun run test:run and confirm all cases pass.

Out of scope: changing extract-subagent-ids.ts itself.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions