mjpsm/activity-generation-v1.3-api
0
1from fastapi.testclient import TestClient2 3from app.main import create_app4from tests.fakes import FakeModelService5from tests.test_generate import ACTIVITY, REQUEST6 7 8SIMILAR_ACTIVITY = {9 "activity_title": "Check the failing input!",10 "activity_description": "Investigate the input that produced the unexpected result.",11 "activity_instructions": "Run the failing input again and identify where the result changes.",12}13 14DIFFERENT_ACTIVITY = {15 "activity_title": "Trace One Unexpected Result",16 "activity_description": "Look closely at one input that did not behave as expected.",17 "activity_instructions": "Follow one failing value through the function and note where its behavior changes.",18}19 20 21def test_generate_pair_retries_similar_candidate_b():22 fake = FakeModelService([ACTIVITY, SIMILAR_ACTIVITY, DIFFERENT_ACTIVITY])23 app = create_app(fake, load_model_on_start=False)24 25 with TestClient(app) as client:26 response = client.post("/generate-pair", json=REQUEST)27 28 body = response.json()29 assert response.status_code == 20030 assert body["candidate_a"] == ACTIVITY31 assert body["candidate_b"] == DIFFERENT_ACTIVITY32 assert body["pair_quality"] == {33 "generation_attempts": 3,34 "similarity_warning": False,35 }36 assert body["usage"]["input_tokens"] == 30037 assert body["usage"]["output_tokens"] == 9038 assert body["generation"]["temperature"] == 0.739 assert body["generation"]["top_p"] == 0.940 assert all(policy.do_sample for policy in fake.policies)41 42 43def test_generate_pair_returns_best_available_pair_with_warning():44 fake = FakeModelService([ACTIVITY, SIMILAR_ACTIVITY, SIMILAR_ACTIVITY, SIMILAR_ACTIVITY])45 app = create_app(fake, load_model_on_start=False)46 47 with TestClient(app) as client:48 response = client.post("/generate-pair", json=REQUEST)49 50 body = response.json()51 assert response.status_code == 20052 assert body["pair_quality"]["generation_attempts"] == 453 assert body["pair_quality"]["similarity_warning"] is True54 