Skip to content

Commit 73d03ae

Browse files
committed
add E2E
1 parent 3ca6fad commit 73d03ae

File tree

6 files changed

+149
-0
lines changed

6 files changed

+149
-0
lines changed

.github/workflows/e2e-async.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: E2E - Async Optimization
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**' # Trigger for all paths
7+
8+
workflow_dispatch:
9+
10+
jobs:
11+
async-optimization:
12+
# Dynamically determine if environment is needed only when workflow files change and contributor is external
13+
environment: ${{ (github.event_name == 'workflow_dispatch' || (contains(toJSON(github.event.pull_request.files.*.filename), '.github/workflows/') && github.event.pull_request.user.login != 'misrasaurabh1' && github.event.pull_request.user.login != 'KRRT7')) && 'external-trusted-contributors' || '' }}
14+
15+
runs-on: ubuntu-latest
16+
env:
17+
CODEFLASH_AIS_SERVER: prod
18+
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
19+
CODEFLASH_API_KEY: ${{ secrets.CODEFLASH_API_KEY }}
20+
COLUMNS: 110
21+
MAX_RETRIES: 3
22+
RETRY_DELAY: 5
23+
EXPECTED_IMPROVEMENT_PCT: 10
24+
CODEFLASH_END_TO_END: 1
25+
steps:
26+
- name: 🛎️ Checkout
27+
uses: actions/checkout@v4
28+
with:
29+
ref: ${{ github.event.pull_request.head.ref }}
30+
repository: ${{ github.event.pull_request.head.repo.full_name }}
31+
fetch-depth: 0
32+
token: ${{ secrets.GITHUB_TOKEN }}
33+
- name: Validate PR
34+
run: |
35+
# Check for any workflow changes
36+
if git diff --name-only "${{ github.event.pull_request.base.sha }}" "${{ github.event.pull_request.head.sha }}" | grep -q "^.github/workflows/"; then
37+
echo "⚠️ Workflow changes detected."
38+
39+
# Get the PR author
40+
AUTHOR="${{ github.event.pull_request.user.login }}"
41+
echo "PR Author: $AUTHOR"
42+
43+
# Allowlist check
44+
if [[ "$AUTHOR" == "misrasaurabh1" || "$AUTHOR" == "KRRT7" ]]; then
45+
echo "✅ Authorized user ($AUTHOR). Proceeding."
46+
elif [[ "${{ github.event.pull_request.state }}" == "open" ]]; then
47+
echo "✅ PR triggered by 'pull_request_target' and is open. Assuming protection rules are in place. Proceeding."
48+
else
49+
echo "⛔ Unauthorized user ($AUTHOR) attempting to modify workflows. Exiting."
50+
exit 1
51+
fi
52+
else
53+
echo "✅ No workflow file changes detected. Proceeding."
54+
fi
55+
56+
- name: Set up Python 3.11 for CLI
57+
uses: astral-sh/setup-uv@v5
58+
with:
59+
python-version: 3.11.6
60+
61+
- name: Install dependencies (CLI)
62+
run: |
63+
uv sync
64+
65+
- name: Run Codeflash to optimize async code
66+
id: optimize_code
67+
run: |
68+
uv run python tests/scripts/end_to_end_test_async.py
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[tool.codeflash]
2+
disable-telemetry = true
3+
formatter-cmds = ["ruff check --exit-zero --fix $file", "ruff format $file"]
4+
module-root = "."
5+
test-framework = "pytest"
6+
tests-root = "tests"

code_to_optimize/code_directories/async_e2e/tests/__init__.py

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
from workload import process_data_list
3+
4+
5+
@pytest.mark.asyncio
6+
async def test_process_data_list():
7+
data = [1, 2, 3]
8+
result = await process_data_list(data)
9+
expected = [12, 14, 16] # (1*2+10), (2*2+10), (3*2+10)
10+
assert result == expected
11+
12+
13+
@pytest.mark.asyncio
14+
async def test_process_data_list_empty():
15+
result = await process_data_list([])
16+
assert result == []
17+
18+
19+
@pytest.mark.asyncio
20+
async def test_process_data_list_single():
21+
result = await process_data_list([5])
22+
assert result == [20] # 5*2+10
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import asyncio
2+
3+
from codeflash.code_utils.codeflash_wrap_decorator import \
4+
codeflash_behavior_async
5+
6+
7+
@codeflash_behavior_async
8+
async def process_data_list(data_list):
9+
results = []
10+
11+
for item in data_list:
12+
await asyncio.sleep(0.1)
13+
processed = item * 2 + 10
14+
results.append(processed)
15+
16+
return results
17+
18+
19+
async def main():
20+
data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
21+
result = await process_data_list(data)
22+
print(f"Processed {len(result)} items: {result}")
23+
24+
25+
if __name__ == "__main__":
26+
asyncio.run(main())
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import os
2+
import pathlib
3+
4+
from end_to_end_test_utilities import CoverageExpectation, TestConfig, run_codeflash_command, run_with_retries
5+
6+
7+
def run_test(expected_improvement_pct: int) -> bool:
8+
config = TestConfig(
9+
file_path="workload.py",
10+
expected_unit_tests=1,
11+
min_improvement_x=0.1,
12+
coverage_expectations=[
13+
CoverageExpectation(
14+
function_name="process_data_list",
15+
expected_coverage=100.0,
16+
expected_lines=[5, 7, 8, 9, 10, 12],
17+
)
18+
],
19+
)
20+
cwd = (
21+
pathlib.Path(__file__).parent.parent.parent / "code_to_optimize" / "code_directories" / "async_e2e"
22+
).resolve()
23+
return run_codeflash_command(cwd, config, expected_improvement_pct)
24+
25+
26+
if __name__ == "__main__":
27+
exit(run_with_retries(run_test, int(os.getenv("EXPECTED_IMPROVEMENT_PCT", 10))))

0 commit comments

Comments
 (0)