/**
 * Domain Ownership Tests
 * Tests for memory domain ownership and validation
 */

import { describe, it, expect } from 'vitest'
import { isToolOwnedKey, isActionOwnedKey, isLLMOwnedKey, getKeyOwner } from '../domains'

describe('Memory Domain Ownership', () => {
  describe('isToolOwnedKey', () => {
    it('should identify tool-owned keys', () => {
      expect(isToolOwnedKey('notion-pages-cache')).toBe(true)
      expect(isToolOwnedKey('github-repo-cache')).toBe(true)
      expect(isToolOwnedKey('slack-channel-cache')).toBe(true)
    })

    it('should reject non-tool keys', () => {
      expect(isToolOwnedKey('customer_account')).toBe(false)
      expect(isToolOwnedKey('knowledge-map-state')).toBe(false)
      expect(isToolOwnedKey('random-key')).toBe(false)
    })
  })

  describe('isActionOwnedKey', () => {
    it('should identify action-owned keys', () => {
      expect(isActionOwnedKey('knowledge-map-state')).toBe(true)
    })

    it('should reject non-action keys', () => {
      expect(isActionOwnedKey('customer_account')).toBe(false)
      expect(isActionOwnedKey('notion-pages-cache')).toBe(false)
      expect(isActionOwnedKey('random-key')).toBe(false)
    })
  })

  describe('isLLMOwnedKey', () => {
    it('should identify LLM-owned keys (not tool or action owned)', () => {
      expect(isLLMOwnedKey('customer_account')).toBe(true)
      expect(isLLMOwnedKey('project_name')).toBe(true)
      expect(isLLMOwnedKey('original_request')).toBe(true)
      expect(isLLMOwnedKey('random-key')).toBe(true)
    })

    it('should reject tool-owned keys', () => {
      expect(isLLMOwnedKey('notion-pages-cache')).toBe(false)
      expect(isLLMOwnedKey('github-repo-cache')).toBe(false)
    })

    it('should reject action-owned keys', () => {
      expect(isLLMOwnedKey('knowledge-map-state')).toBe(false)
    })
  })

  describe('getKeyOwner', () => {
    it('should return "tool" for tool-owned keys', () => {
      expect(getKeyOwner('notion-pages-cache')).toBe('tool')
      expect(getKeyOwner('github-repo-cache')).toBe('tool')
      expect(getKeyOwner('slack-channel-cache')).toBe('tool')
    })

    it('should return "action" for action-owned keys', () => {
      expect(getKeyOwner('knowledge-map-state')).toBe('action')
    })

    it('should return "llm" for LLM-owned keys', () => {
      expect(getKeyOwner('customer_account')).toBe('llm')
      expect(getKeyOwner('project_name')).toBe('llm')
      expect(getKeyOwner('original_request')).toBe('llm')
      expect(getKeyOwner('random-key')).toBe('llm')
    })
  })
})
