# -*- coding: utf-8 -*-
"""
TDD 测试：自定义 slash 命令应出现在补全菜单
验证：用户在 ~/.abyss/commands/ 下放的 .md 文件能被 / 补全识别
"""
import sys
import tempfile
from pathlib import Path

sys.path.insert(0, r'd:\agent cli\abyss\src')

from abyss.ansi_menu import get_command_completions, register_custom_commands


def test_custom_command_appears_in_completion():
    """注册自定义命令后，/c 应能补全到 /ceshi"""
    register_custom_commands(["ceshi"])
    results = get_command_completions("/c")
    names = [r[0] for r in results]
    assert "/ceshi" in names


def test_custom_command_empty_list_no_error():
    """空列表注册不应报错"""
    register_custom_commands([])
    results = get_command_completions("/zzz")
    assert results == []


def test_custom_and_builtin_coexist():
    """自定义命令和内置命令应同时出现"""
    register_custom_commands(["ceshi"])
    results = get_command_completions("/")
    names = [r[0] for r in results]
    assert "/help" in names
    assert "/ceshi" in names


if __name__ == "__main__":
    test_custom_command_appears_in_completion()
    print("  ✓ test_custom_command_appears_in_completion")
    test_custom_command_empty_list_no_error()
    print("  ✓ test_custom_command_empty_list_no_error")
    test_custom_and_builtin_coexist()
    print("  ✓ test_custom_and_builtin_coexist")
    print("OK: 全部通过")
