File size: 2,616 Bytes
04cd8c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
86
87
from pathlib import Path

import pytest

from meine_app.package import InputPackageDraft, freitext_sections
from meine_app.task_package import (
    build_ir_task_package_markdown,
    next_ir_id,
    write_ir_task_package,
)


def test_next_ir_id_from_queue(tmp_path: Path):
    (tmp_path / "IR-2026-0070-task-package.md").write_text("x", encoding="utf-8")
    seq = tmp_path / "ir_seq.json"

    assert next_ir_id(seq_path=seq, queue_dir=tmp_path) == "IR-2026-0071"


def test_build_ir_task_package_requires_profile(tmp_path: Path):
    pkg_dir = tmp_path / "packets" / "demo__pkg-20260101-120000"
    pkg_dir.mkdir(parents=True)

    with pytest.raises(ValueError, match="Zielagent"):
        build_ir_task_package_markdown(
            InputPackageDraft(name="Demo", text_sections=freitext_sections("x")),
            ir_id="IR-2026-0099",
            packet_path=pkg_dir,
        )


def test_build_ir_task_package_has_required_sections(tmp_path: Path):
    project = tmp_path / "meine-linux-app"
    project.mkdir()
    pkg_dir = tmp_path / "packets" / "demo__pkg-20260101-120000"
    pkg_dir.mkdir(parents=True)

    md = build_ir_task_package_markdown(
        InputPackageDraft(
            name="Auth Fix",
            project_path=str(project),
            session_brief="Nur Login-Flow",
            harness="opencode",
            profile="hai-agent",
        ),
        ir_id="IR-2026-0099",
        packet_path=pkg_dir,
    )

    assert "## Aufgabe" in md
    assert "## Kontext" in md
    assert "- Quelle: hai-intake" in md
    assert "## Grenzen" in md
    assert "## Zielagent" in md
    assert "`hai-agent`" in md
    assert "## Definition of Done für Zielagent" in md
    assert "Harness (Runtime): opencode" in md
    assert "project_id: meine-linux-app" in md


def test_write_ir_task_package_creates_file(tmp_path: Path):
    project = tmp_path / "DemoProjekt"
    project.mkdir()
    pkg_dir = tmp_path / "packets" / "demo__pkg-20260101-120000"
    pkg_dir.mkdir(parents=True)
    queue = tmp_path / "intake_queue"
    seq = tmp_path / "ir_seq.json"

    ir_id, task_path = write_ir_task_package(
        InputPackageDraft(
            name="Demo",
            project_path=str(project),
            session_brief="Scope klein",
            text_sections=freitext_sections("Kontext"),
            profile="uniagent",
        ),
        pkg_dir,
        seq_path=seq,
        queue_dir=queue,
    )

    assert task_path.is_file()
    assert ir_id == "IR-2026-0001"
    content = task_path.read_text(encoding="utf-8")
    assert "## Zielagent" in content
    assert "`uniagent`" in content