File size: 1,767 Bytes
9d8bbd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d7d27a3
 
 
 
 
 
 
 
 
 
 
 
9d8bbd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import app


def test_chat_without_job_description_does_not_access_the_graph(monkeypatch):
    def graph_must_not_be_requested(_session_id):
        raise AssertionError("A model graph must not be accessed without a job description.")

    monkeypatch.setattr(app, "graph_for_session", graph_must_not_be_requested)

    result = list(app.stream_response(
        [{"role": "user", "content": "Tell me about my experience"}],
        " \n ",
        "thread-id",
        "session-id",
    ))

    assert len(result) == 1
    assert "Paste a job description" in result[0][-1]["content"]


def test_length_limit_error_explains_how_to_retry():
    from types import SimpleNamespace

    from openai import LengthFinishReasonError

    completion = SimpleNamespace(usage=None)
    detail = app.request_error_detail(LengthFinishReasonError(completion=completion))

    assert "ATS report exceeded" in detail
    assert "ATS_MAX_TOKENS" in detail


def test_upload_builds_a_per_session_graph(monkeypatch, tmp_path):
    markdown_file = tmp_path / "resume.md"
    markdown_file.write_text("# Resume", encoding="utf-8")
    build_calls = []
    monkeypatch.setattr(app, "convert_uploaded_documents", lambda _files: "# Profile")
    monkeypatch.setattr(
        app,
        "build_graph",
        lambda **kwargs: build_calls.append(kwargs) or "compiled-graph",
    )
    monkeypatch.setitem(app.SESSION_DATA, "upload-test-session", {})

    status = app.process_profile_upload(
        [str(markdown_file)], "upload-test-session"
    )

    assert "Profile ready" in status
    assert build_calls == [{
        "api_key": app.SETTINGS.openrouter_api_key,
        "profile_data": "# Profile",
    }]
    assert app.graph_for_session("upload-test-session") == "compiled-graph"