File size: 2,776 Bytes
b4ac377
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.

"""Tests for the openenv skills command."""

import os
from pathlib import Path

from openenv.cli.__main__ import app
from typer.testing import CliRunner

runner = CliRunner()


def test_skills_add_installs_local_skill(tmp_path: Path) -> None:
    """openenv skills add installs to project .agents/skills by default."""
    old_cwd = os.getcwd()
    try:
        os.chdir(tmp_path)
        result = runner.invoke(app, ["skills", "add"])
    finally:
        os.chdir(old_cwd)

    assert result.exit_code == 0
    skill_md = tmp_path / ".agents" / "skills" / "openenv-cli" / "SKILL.md"
    assert skill_md.exists()
    assert "openenv" in skill_md.read_text().lower()


def test_skills_add_rejects_dest_with_agent_flags(tmp_path: Path) -> None:
    """--dest cannot be combined with assistant/global flags."""
    result = runner.invoke(
        app,
        ["skills", "add", "--dest", str(tmp_path), "--claude"],
    )

    assert result.exit_code == 1
    assert "--dest cannot be combined" in result.output


def test_skills_add_requires_force_when_target_exists(tmp_path: Path) -> None:
    """Existing destination requires --force to overwrite."""
    existing = tmp_path / "skills" / "openenv-cli"
    existing.mkdir(parents=True)
    (existing / "SKILL.md").write_text("old")

    result = runner.invoke(app, ["skills", "add", "--dest", str(tmp_path / "skills")])
    assert result.exit_code == 1
    assert "--force" in result.output


def test_skills_add_force_overwrites_existing(tmp_path: Path) -> None:
    """--force overwrites existing skill content."""
    existing = tmp_path / "skills" / "openenv-cli"
    existing.mkdir(parents=True)
    skill_md = existing / "SKILL.md"
    skill_md.write_text("old")

    result = runner.invoke(
        app,
        ["skills", "add", "--dest", str(tmp_path / "skills"), "--force"],
    )

    assert result.exit_code == 0
    assert skill_md.read_text() != "old"


def test_skills_add_creates_agent_symlink(tmp_path: Path) -> None:
    """Assistant flag creates a symlink to the central skill location."""
    old_cwd = os.getcwd()
    try:
        os.chdir(tmp_path)
        result = runner.invoke(app, ["skills", "add", "--claude"])
    finally:
        os.chdir(old_cwd)

    assert result.exit_code == 0
    link_path = tmp_path / ".claude" / "skills" / "openenv-cli"
    target_path = tmp_path / ".agents" / "skills" / "openenv-cli"
    assert link_path.is_symlink()
    assert link_path.resolve() == target_path.resolve()