/ mervelas / src / services / tools / toolOrchestration.test.ts
Swadhin Biswas feat: implement mervelas cli engine, built-in tools, and reactive UI · 4/3/2026
0358986
34 lines · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { afterEach, expect, test } from 'bun:test'
import {
  DEFAULT_MAX_TOOL_USE_CONCURRENCY,
  getMaxToolUseConcurrency,
} from './toolConcurrency.js'

const ORIGINAL_CONCURRENCY = process.env.CLAUDE_CODE_MAX_TOOL_USE_CONCURRENCY

afterEach(() => {
  if (ORIGINAL_CONCURRENCY === undefined) {
    delete process.env.CLAUDE_CODE_MAX_TOOL_USE_CONCURRENCY
  } else {
    process.env.CLAUDE_CODE_MAX_TOOL_USE_CONCURRENCY = ORIGINAL_CONCURRENCY
  }
})

test('defaults tool concurrency to a bounded budget', () => {
  delete process.env.CLAUDE_CODE_MAX_TOOL_USE_CONCURRENCY
  expect(getMaxToolUseConcurrency()).toBe(DEFAULT_MAX_TOOL_USE_CONCURRENCY)
})

test('allows an explicit positive concurrency override', () => {
  process.env.CLAUDE_CODE_MAX_TOOL_USE_CONCURRENCY = '7'
  expect(getMaxToolUseConcurrency()).toBe(7)
})

test('ignores invalid concurrency overrides', () => {
  process.env.CLAUDE_CODE_MAX_TOOL_USE_CONCURRENCY = '0'
  expect(getMaxToolUseConcurrency()).toBe(DEFAULT_MAX_TOOL_USE_CONCURRENCY)

  process.env.CLAUDE_CODE_MAX_TOOL_USE_CONCURRENCY = 'not-a-number'
  expect(getMaxToolUseConcurrency()).toBe(DEFAULT_MAX_TOOL_USE_CONCURRENCY)
})