from pathlib import Path from meine_app.package import InputPackageDraft, TextSection, freitext_sections, save_package from meine_app.projects import discover_projects, normalize_project_path, project_management_dir from meine_app.session_context import ( SESSION_CONTEXT_JSON, SESSION_CONTEXT_MD, build_session_context_markdown, clipboard_preamble, deploy_session_context_to_project, ) def test_discover_projects_finds_dirs(tmp_path: Path): (tmp_path / "HAI").mkdir() (tmp_path / "HAI" / "Projek-Managment").mkdir() (tmp_path / "other-file").write_text("x", encoding="utf-8") projects = discover_projects(tmp_path) assert len(projects) == 1 assert projects[0].name == "HAI" assert projects[0].has_projek_managment is True def test_build_session_context_markdown_splits_text_sections(): draft = InputPackageDraft( name="Mixed Input", text_sections=[ TextSection("E-Mail / Copy-Paste", "Mail-Inhalt"), TextSection("Eigene Notizen", "Meine Anweisung"), ], ) md = build_session_context_markdown(draft) assert "## E-Mail / Copy-Paste" in md assert "Mail-Inhalt" in md assert "## Eigene Notizen" in md assert "Meine Anweisung" in md assert "## Text\n" not in md def test_build_session_context_markdown_includes_brief(): draft = InputPackageDraft( name="Auth Fix", project_path="/home/smlflg/Projekte/HAI", session_brief="Nur Login-Flow anfassen", text_sections=freitext_sections("Kontext hier"), links=["https://example.com"], ) md = build_session_context_markdown(draft, packet_id="pkg-1") assert "Session Context Package" in md assert "Nur Login-Flow anfassen" in md assert "https://example.com" in md assert "Kontext hier" in md def test_clipboard_preamble(): draft = InputPackageDraft(session_brief="Scope klein halten") text = clipboard_preamble(draft) assert "relevante Kontext" in text assert "Scope klein halten" in text def test_deploy_session_context_to_project(tmp_path: Path): project = tmp_path / "DemoProjekt" project.mkdir() notes = tmp_path / "notes.md" notes.write_text("Details", encoding="utf-8") pkg_dir = save_package( InputPackageDraft( name="Demo Session", project_path=str(project), session_brief="Nur lesen", text_sections=freitext_sections("Hauptkontext"), text_file_paths=[notes], ), tmp_path / "packets", ) md_path, json_path = deploy_session_context_to_project(project, pkg_dir) assert md_path == project_management_dir(project) / SESSION_CONTEXT_MD assert json_path.name == SESSION_CONTEXT_JSON assert "Hauptkontext" in md_path.read_text(encoding="utf-8") assert normalize_project_path(str(project)) == project.resolve()