summaryrefslogtreecommitdiff
path: root/server/tests/step_test.py
blob: a9132dd3b589c0302c3a6d4508348ad51f627e20 (plain)
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
import pytest
from continuedev.core.config import ContinueConfig
from continuedev.core.steps import UserInputStep
from continuedev.headless import start_headless_session
from continuedev.models.filesystem import Range, RangeInFileWithContents
from continuedev.plugins.steps.chat import SimpleChatStep
from continuedev.plugins.steps.main import EditHighlightedCodeStep
from continuedev.plugins.steps.on_traceback import DefaultOnTracebackStep
from util.prompts import dotenv_test_pair, tokyo_test_pair

TEST_CONFIG = ContinueConfig()


@pytest.mark.asyncio
async def test_step():
    pytest.skip("TODO: too slow")
    session = await start_headless_session(config=TEST_CONFIG)

    await session.autopilot.run_from_step(UserInputStep(user_input=tokyo_test_pair[0]))

    full_state = await session.autopilot.get_full_state()

    assert isinstance(full_state.history.timeline[-1].step, SimpleChatStep)

    assert not full_state.history.timeline[-1].step.hide

    assert (
        full_state.history.timeline[-1].step.description.strip().lower()
        == tokyo_test_pair[1]
    )

    await session.autopilot.cleanup()


@pytest.mark.asyncio
async def test_traceback_step():
    pytest.skip("TODO: too slow")
    session = await start_headless_session(config=TEST_CONFIG)

    await session.autopilot.run_from_step(
        DefaultOnTracebackStep(output=dotenv_test_pair[0])
    )

    full_state = await session.autopilot.get_full_state()
    assert dotenv_test_pair[1] in full_state.history.timeline[-1].step.description

    await session.autopilot.cleanup()


@pytest.mark.asyncio
async def test_edit_step():
    pytest.skip("TODO: too slow")
    session = await start_headless_session(config=TEST_CONFIG)

    range_in_file = RangeInFileWithContents(
        filepath=__file__, range=Range.from_shorthand(0, 0, 0, 0), contents=""
    )

    await session.autopilot.handle_highlighted_code(range_in_files=[range_in_file])

    await session.autopilot.run_from_step(
        EditHighlightedCodeStep(user_input="Don't edit this code")
    )

    full_state = await session.autopilot.get_full_state()
    assert isinstance(full_state.history.timeline[-1].step.description, str)

    await session.autopilot.cleanup()