From cf243aa7b7fb96059dd0a85613d56c8b3f53788a Mon Sep 17 00:00:00 2001 From: ishandhanani Date: Mon, 2 Dec 2024 10:16:30 -0600 Subject: [PATCH 1/6] test(AgentService): update TranscriptionRequest test data --- services/AgentService/test_api.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/services/AgentService/test_api.py b/services/AgentService/test_api.py index 705028a..77708f0 100644 --- a/services/AgentService/test_api.py +++ b/services/AgentService/test_api.py @@ -13,31 +13,43 @@ def test_transcribe_api(): # Create a proper TranscriptionRequest pdf_metadata_1 = PDFMetadata( - filename="sample.pdf", markdown="Sample markdown content", summary="" + filename="sample.pdf", + type="target", + markdown="Sample markdown content", + summary="", ) pdf_metadata_2 = PDFMetadata( - filename="sample2.pdf", markdown="Sample markdown content 2", summary="" + filename="sample2.pdf", + type="context", + markdown="Sample markdown content 2", + summary="", ) pdf_metadata_3 = PDFMetadata( - filename="sample3.pdf", markdown="Sample markdown content 3", summary="" + filename="sample3.pdf", + type="context", + markdown="Sample markdown content 3", + summary="", ) request = TranscriptionRequest( # TranscriptionParams fields + userId="test-agent-service", name="Test Podcast", duration=2, # Duration in minutes + monologue=False, speaker_1_name="Host", speaker_2_name="Guest", voice_mapping={ - "speaker-1": "iP95p4xoKVk53GoZ742B", # Example voice ID - "speaker-2": "9BWtsMINqrJLrRacOk9x", # Example voice ID + "speaker-1": "iP95p4xoKVk53GoZ742B", + "speaker-2": "9BWtsMINqrJLrRacOk9x", }, - guide="Sample focus instructions", # Optional + guide="Sample focus instructions", # TranscriptionRequest specific fields pdf_metadata=[pdf_metadata_1, pdf_metadata_2, pdf_metadata_3], job_id="test-job-123", + vdb_task=False, ) # Send POST request From 12f43f6e32ecf5fedeb89b8a42d46643815f19f9 Mon Sep 17 00:00:00 2001 From: ishandhanani Date: Mon, 2 Dec 2024 10:29:23 -0600 Subject: [PATCH 2/6] test(ci): add service-specific tests to PR workflow --- .github/workflows/pr-test.yaml | 9 +++++++++ services/AgentService/test_api.py | 22 +++++++++++++++++++++- services/PDFService/test_api.py | 20 +++++++++++++++----- services/TTSService/test_api.py | 2 +- 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr-test.yaml b/.github/workflows/pr-test.yaml index 170d83c..35ecb6b 100644 --- a/.github/workflows/pr-test.yaml +++ b/.github/workflows/pr-test.yaml @@ -34,6 +34,15 @@ jobs: python -m pip install --upgrade pip pip install -r tests/requirements-test.txt # Make sure this file exists with your test dependencies + - name: Run Agent Service tests + run: python services/AgentService/test_api.py + + - name: Run PDFService tests + run: python services/PDFService/test_api.py + + - name: Run TTS Service tests + run: python services/TTSService/test_api.py + - name: Run monologue E2E tests run: python tests/test.py --monologue --target bofa-context.pdf --context citi-context.pdf diff --git a/services/AgentService/test_api.py b/services/AgentService/test_api.py index 77708f0..6d0a876 100644 --- a/services/AgentService/test_api.py +++ b/services/AgentService/test_api.py @@ -4,6 +4,7 @@ import time from shared.api_types import TranscriptionRequest from shared.pdf_types import PDFMetadata +from datetime import datetime def test_transcribe_api(): @@ -11,12 +12,24 @@ def test_transcribe_api(): BASE_URL = os.getenv("AGENT_SERVICE_URL", "http://localhost:8964") TRANSCRIBE_URL = f"{BASE_URL}/transcribe" + # class PDFMetadata(BaseModel): + # filename: str + # markdown: str = "" + # summary: str = "" + # status: ConversionStatus + # type: Union[Literal["target"], Literal["context"]] + # error: Optional[str] = None + # created_at: datetime = Field(default_factory=datetime.utcnow) + + # Create a proper TranscriptionRequest pdf_metadata_1 = PDFMetadata( filename="sample.pdf", type="target", markdown="Sample markdown content", summary="", + status="success", + created_at=datetime.utcnow() ) pdf_metadata_2 = PDFMetadata( @@ -24,6 +37,8 @@ def test_transcribe_api(): type="context", markdown="Sample markdown content 2", summary="", + status="success", + created_at=datetime.utcnow(), ) pdf_metadata_3 = PDFMetadata( @@ -31,6 +46,8 @@ def test_transcribe_api(): type="context", markdown="Sample markdown content 3", summary="", + status="success", + created_at=datetime.utcnow(), ) request = TranscriptionRequest( @@ -53,7 +70,10 @@ def test_transcribe_api(): ) # Send POST request - response = requests.post(TRANSCRIBE_URL, json=request.model_dump()) + response = requests.post( + TRANSCRIBE_URL, + json=request.model_dump(mode='json') + ) # Check if the request was successful assert ( diff --git a/services/PDFService/test_api.py b/services/PDFService/test_api.py index addea3a..f2c4e2f 100644 --- a/services/PDFService/test_api.py +++ b/services/PDFService/test_api.py @@ -73,7 +73,15 @@ def test_convert_pdf_endpoint(pdf_paths: List[str]) -> bool: print( f"\nUploading {len(files)} files for conversion: {', '.join(f.name for f in pdf_files)}..." ) - response = requests.post(f"{PDF_SERVICE_URL}/convert", files=files) + response = requests.post( + f"{PDF_SERVICE_URL}/convert", + files=files, + data={ + "types": ["context", "target"], # Hardcode types for the two files + "job_id": f"test-job-{int(time.time())}", + "vdb_task": False + } + ) if response.status_code != 202: print(f"Error: Request failed with status code {response.status_code}") @@ -190,9 +198,11 @@ def test_health_endpoint(): def main(): """Main entry point for the test script""" - if len(sys.argv) < 2: - print("Usage: python test_api.py [path_to_pdf_file2 ...]") - sys.exit(1) + # Hardcode two sample files + sample_files = [ + "samples/bofa-context.pdf", + "samples/citi-context.pdf" + ] print("Running PDF Service API tests...") @@ -201,7 +211,7 @@ def main(): sys.exit(1) print("\nTest 2: Valid PDF conversion") - if not test_convert_pdf_endpoint(sys.argv[1:]): + if not test_convert_pdf_endpoint(sample_files): sys.exit(1) print("\nTest 3: Invalid file handling") diff --git a/services/TTSService/test_api.py b/services/TTSService/test_api.py index a00e98b..9a290a2 100644 --- a/services/TTSService/test_api.py +++ b/services/TTSService/test_api.py @@ -51,7 +51,7 @@ def test_tts_api(): try: # Load sample JSON data - with open("sample.json", "r") as f: + with open("services/TTSService/sample.json", "r") as f: data = json.load(f) # Add job_id if not present From c70a5eed0f646cfa994aa872a4a1645fbdb3aac8 Mon Sep 17 00:00:00 2001 From: ishandhanani Date: Mon, 2 Dec 2024 10:30:37 -0600 Subject: [PATCH 3/6] ruff --- services/AgentService/test_api.py | 8 ++------ services/PDFService/test_api.py | 11 ++++------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/services/AgentService/test_api.py b/services/AgentService/test_api.py index 6d0a876..29cb73b 100644 --- a/services/AgentService/test_api.py +++ b/services/AgentService/test_api.py @@ -21,7 +21,6 @@ def test_transcribe_api(): # error: Optional[str] = None # created_at: datetime = Field(default_factory=datetime.utcnow) - # Create a proper TranscriptionRequest pdf_metadata_1 = PDFMetadata( filename="sample.pdf", @@ -29,7 +28,7 @@ def test_transcribe_api(): markdown="Sample markdown content", summary="", status="success", - created_at=datetime.utcnow() + created_at=datetime.utcnow(), ) pdf_metadata_2 = PDFMetadata( @@ -70,10 +69,7 @@ def test_transcribe_api(): ) # Send POST request - response = requests.post( - TRANSCRIBE_URL, - json=request.model_dump(mode='json') - ) + response = requests.post(TRANSCRIBE_URL, json=request.model_dump(mode="json")) # Check if the request was successful assert ( diff --git a/services/PDFService/test_api.py b/services/PDFService/test_api.py index f2c4e2f..5fd5865 100644 --- a/services/PDFService/test_api.py +++ b/services/PDFService/test_api.py @@ -74,13 +74,13 @@ def test_convert_pdf_endpoint(pdf_paths: List[str]) -> bool: f"\nUploading {len(files)} files for conversion: {', '.join(f.name for f in pdf_files)}..." ) response = requests.post( - f"{PDF_SERVICE_URL}/convert", + f"{PDF_SERVICE_URL}/convert", files=files, data={ "types": ["context", "target"], # Hardcode types for the two files "job_id": f"test-job-{int(time.time())}", - "vdb_task": False - } + "vdb_task": False, + }, ) if response.status_code != 202: @@ -199,10 +199,7 @@ def test_health_endpoint(): def main(): """Main entry point for the test script""" # Hardcode two sample files - sample_files = [ - "samples/bofa-context.pdf", - "samples/citi-context.pdf" - ] + sample_files = ["samples/bofa-context.pdf", "samples/citi-context.pdf"] print("Running PDF Service API tests...") From cac98761daa878781e50721bcccd64ad127b60e7 Mon Sep 17 00:00:00 2001 From: ishandhanani Date: Mon, 2 Dec 2024 10:36:42 -0600 Subject: [PATCH 4/6] test(ci): update test workflow and API tests --- .github/workflows/pr-test.yaml | 9 +++++++-- services/AgentService/test_api.py | 9 --------- services/PDFService/test_api.py | 15 +++++---------- tests/requirements-test.txt | 4 +++- 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/.github/workflows/pr-test.yaml b/.github/workflows/pr-test.yaml index 35ecb6b..9e47971 100644 --- a/.github/workflows/pr-test.yaml +++ b/.github/workflows/pr-test.yaml @@ -32,12 +32,17 @@ jobs: - name: Install test dependencies run: | python -m pip install --upgrade pip - pip install -r tests/requirements-test.txt # Make sure this file exists with your test dependencies + pip install -r tests/requirements-test.txt + + - name: Pip install shared package + run: | + cd shared + pip install . - name: Run Agent Service tests run: python services/AgentService/test_api.py - - name: Run PDFService tests + - name: Run PDF Service tests run: python services/PDFService/test_api.py - name: Run TTS Service tests diff --git a/services/AgentService/test_api.py b/services/AgentService/test_api.py index 29cb73b..85b4da3 100644 --- a/services/AgentService/test_api.py +++ b/services/AgentService/test_api.py @@ -12,15 +12,6 @@ def test_transcribe_api(): BASE_URL = os.getenv("AGENT_SERVICE_URL", "http://localhost:8964") TRANSCRIBE_URL = f"{BASE_URL}/transcribe" - # class PDFMetadata(BaseModel): - # filename: str - # markdown: str = "" - # summary: str = "" - # status: ConversionStatus - # type: Union[Literal["target"], Literal["context"]] - # error: Optional[str] = None - # created_at: datetime = Field(default_factory=datetime.utcnow) - # Create a proper TranscriptionRequest pdf_metadata_1 = PDFMetadata( filename="sample.pdf", diff --git a/services/PDFService/test_api.py b/services/PDFService/test_api.py index 5fd5865..a293aef 100644 --- a/services/PDFService/test_api.py +++ b/services/PDFService/test_api.py @@ -73,15 +73,7 @@ def test_convert_pdf_endpoint(pdf_paths: List[str]) -> bool: print( f"\nUploading {len(files)} files for conversion: {', '.join(f.name for f in pdf_files)}..." ) - response = requests.post( - f"{PDF_SERVICE_URL}/convert", - files=files, - data={ - "types": ["context", "target"], # Hardcode types for the two files - "job_id": f"test-job-{int(time.time())}", - "vdb_task": False, - }, - ) + response = requests.post(f"{PDF_SERVICE_URL}/convert", files=files) if response.status_code != 202: print(f"Error: Request failed with status code {response.status_code}") @@ -199,7 +191,10 @@ def test_health_endpoint(): def main(): """Main entry point for the test script""" # Hardcode two sample files - sample_files = ["samples/bofa-context.pdf", "samples/citi-context.pdf"] + sample_files = [ + "samples/bofa-context.pdf", + "samples/citi-context.pdf" + ] print("Running PDF Service API tests...") diff --git a/tests/requirements-test.txt b/tests/requirements-test.txt index 1ed21c7..340e51d 100644 --- a/tests/requirements-test.txt +++ b/tests/requirements-test.txt @@ -1,2 +1,4 @@ requests -websockets \ No newline at end of file +websockets +ujson +fastapi \ No newline at end of file From 919748370f4061c10c823c08094f634a241b90c6 Mon Sep 17 00:00:00 2001 From: ishandhanani Date: Mon, 2 Dec 2024 10:51:53 -0600 Subject: [PATCH 5/6] test(AgentService): update transcription request test case --- services/AgentService/test_api.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/services/AgentService/test_api.py b/services/AgentService/test_api.py index 85b4da3..300863a 100644 --- a/services/AgentService/test_api.py +++ b/services/AgentService/test_api.py @@ -31,30 +31,19 @@ def test_transcribe_api(): created_at=datetime.utcnow(), ) - pdf_metadata_3 = PDFMetadata( - filename="sample3.pdf", - type="context", - markdown="Sample markdown content 3", - summary="", - status="success", - created_at=datetime.utcnow(), - ) - request = TranscriptionRequest( # TranscriptionParams fields userId="test-agent-service", name="Test Podcast", duration=2, # Duration in minutes - monologue=False, + monologue=True, speaker_1_name="Host", - speaker_2_name="Guest", voice_mapping={ "speaker-1": "iP95p4xoKVk53GoZ742B", - "speaker-2": "9BWtsMINqrJLrRacOk9x", }, guide="Sample focus instructions", # TranscriptionRequest specific fields - pdf_metadata=[pdf_metadata_1, pdf_metadata_2, pdf_metadata_3], + pdf_metadata=[pdf_metadata_1, pdf_metadata_2], job_id="test-job-123", vdb_task=False, ) From d02362f95abaffc1f831fcb66ed0401fb40cd1ae Mon Sep 17 00:00:00 2001 From: ishandhanani Date: Mon, 2 Dec 2024 10:56:30 -0600 Subject: [PATCH 6/6] refactor(ci): implement matrix strategy for parallel test execution --- .github/workflows/pr-test.yaml | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/.github/workflows/pr-test.yaml b/.github/workflows/pr-test.yaml index 9e47971..5f44d9a 100644 --- a/.github/workflows/pr-test.yaml +++ b/.github/workflows/pr-test.yaml @@ -9,8 +9,21 @@ concurrency: cancel-in-progress: true jobs: - e2e-test: + test: runs-on: ubuntu-latest + strategy: + matrix: + test-group: + - name: "Agent Service" + command: "python services/AgentService/test_api.py" + - name: "PDF Service" + command: "python services/PDFService/test_api.py" + - name: "TTS Service" + command: "python services/TTSService/test_api.py" + - name: "Monologue E2E" + command: "python tests/test.py --monologue --target bofa-context.pdf --context citi-context.pdf" + - name: "Podcast E2E" + command: "python tests/test.py --target bofa-context.pdf --context citi-context.pdf" steps: - uses: actions/checkout@v4 @@ -39,17 +52,5 @@ jobs: cd shared pip install . - - name: Run Agent Service tests - run: python services/AgentService/test_api.py - - - name: Run PDF Service tests - run: python services/PDFService/test_api.py - - - name: Run TTS Service tests - run: python services/TTSService/test_api.py - - - name: Run monologue E2E tests - run: python tests/test.py --monologue --target bofa-context.pdf --context citi-context.pdf - - - name: Run podcast E2E tests - run: python tests/test.py --target bofa-context.pdf --context citi-context.pdf + - name: Run ${{ matrix.test-group.name }} tests + run: ${{ matrix.test-group.command }}