import { describe, expect, it } from 'bun:test'
import { ScheduleTool } from './index.js'

describe('ScheduleTool concurrency and permissions', () => {
  it('list 只读可并发，create/delete 必须串行', () => {
    expect(ScheduleTool.isConcurrencySafe({ action: 'list' })).toBe(true)
    expect(
      ScheduleTool.isConcurrencySafe({
        action: 'create',
        prompt: 'hi',
        delayMinutes: 1,
      }),
    ).toBe(false)
    expect(
      ScheduleTool.isConcurrencySafe({
        action: 'delete',
        id: 'abc',
      }),
    ).toBe(false)
  })

  it('create/delete 直接 allow，避免并行 ask 导致 permission 超时', async () => {
    const createResult = await ScheduleTool.checkPermissions({
      action: 'create',
      prompt: '对用户说 hi',
      delayMinutes: 1,
    })
    expect(createResult.behavior).toBe('allow')

    const deleteResult = await ScheduleTool.checkPermissions({
      action: 'delete',
      id: 'task1',
    })
    expect(deleteResult.behavior).toBe('allow')
  })
})
