Skip to content

Add unit tests for lib/resolve-subagent-path.ts #328

@NiveditJain

Description

@NiveditJain

lib/resolve-subagent-path.ts exports an async resolveSubagentPath(projectsPath, projectName, sessionId, agentId) that probes three candidate paths in priority order and returns the first one that exists, or null. It uses fs/promises#access. There is no unit test.

  1. Create __tests__/lib/resolve-subagent-path.test.ts — model it on __tests__/lib/paths.test.ts for the tmpdir setup pattern.
  2. Import: import { resolveSubagentPath } from "@/lib/resolve-subagent-path";
  3. Use os.tmpdir() + mkdtemp in a beforeEach to build a fresh fixture tree per test, and rm({ recursive: true, force: true }) in afterEach.
  4. Cover: (a) candidate 1 wins (file at <projectsPath>/<projectName>/agent-<id>.jsonl), (b) candidate 2 wins when 1 is missing, (c) candidate 3 wins when 1 and 2 are missing, (d) returns null when nothing exists, (e) a path-traversal agentId like ../escape is refused (the function uses relative() to detect escape).
  5. Run bun run test:run and confirm all cases pass.

Out of scope: changing resolve-subagent-path.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