Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
17fda2e
testing dynamic branch var and pr trigger
Schiiss Jun 2, 2025
94b2015
fixing trigger
Schiiss Jun 2, 2025
dba8c3a
fixing env var refs
Schiiss Jun 2, 2025
dc467e9
testing hard coded branch
Schiiss Jun 2, 2025
fb7ecb0
updating dynamic branch
Schiiss Jun 2, 2025
7dc82cd
checking in test change
Schiiss Jun 2, 2025
aa489b6
checking in test change
Schiiss Jun 2, 2025
bb3a7b8
making changes to tests again
Schiiss Jun 2, 2025
b5efaa6
add addition file
david-hurley Jun 3, 2025
41fd014
parse commit_id from full logs
david-hurley Jun 3, 2025
3b5b99a
slight change to prompt
david-hurley Jun 3, 2025
d16af8b
hard coding branch
Schiiss Jun 4, 2025
62a3d67
minor fixes
Schiiss Jun 4, 2025
5cd3032
hard coding url
Schiiss Jun 4, 2025
dc7c161
hard coding model
Schiiss Jun 4, 2025
5296191
testing env vars
Schiiss Jun 4, 2025
90884bc
creating env file
Schiiss Jun 4, 2025
75339c3
updating env var refs
Schiiss Jun 4, 2025
b1ca8e8
updating env var refs
Schiiss Jun 4, 2025
cf9f376
updating env var refs
Schiiss Jun 4, 2025
e461484
updating env var refs
Schiiss Jun 4, 2025
9234cff
updating env var refs
Schiiss Jun 4, 2025
a3bc556
updating env var refs
Schiiss Jun 4, 2025
d2b498a
updating env var refs
Schiiss Jun 4, 2025
9d03c88
updating env var refs
Schiiss Jun 4, 2025
fea3b93
refactor code
david-hurley Jun 5, 2025
f7ab56f
add .env-example
david-hurley Jun 5, 2025
90f132e
add some keys
david-hurley Jun 5, 2025
7d74e42
Update README.md
david-hurley Jun 5, 2025
d0e5526
Update README.md
david-hurley Jun 5, 2025
8ff1e8d
minor README updates
Jun 5, 2025
61771bc
fixing dagger args
Jun 5, 2025
6c66c2a
fixing flag formatting
Jun 5, 2025
bf6178a
fixing function call name
Jun 5, 2025
1b71ef9
fixing flags
Jun 5, 2025
3cc0c0b
idk whats happening
Jun 5, 2025
8ee21d2
idk whats happening
Jun 5, 2025
42b76f1
Update README.md
david-hurley Jun 5, 2025
d0a519d
Update README.md
david-hurley Jun 5, 2025
f6e6e99
updating daggerr command
Jun 5, 2025
8775f54
updating daggerr command
Jun 5, 2025
603882b
README cleanup
Jun 6, 2025
236b7f5
README cleanup
Jun 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 34 additions & 20 deletions .github/workflows/dagger_hackathon.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,51 @@
name: dagger_hackathon # Name of the workflow
name: dagger_hackathon

on:
push:
branches:
- feature/dagger-hackathon-line-extraction
pull_request:
branches: [main]
types: [opened, synchronize, reopened]

jobs:
dagger-plan:
runs-on: ubuntu-latest # Define the runner environment
dagger-run-unit-tests:
runs-on: ubuntu-latest

env:
GITHUB_TOKEN: ${{ secrets.DAGGER_HACKATHON_GITHUB_TOKEN }}
OPENAI_AZURE_VERSION: "2024-12-01-preview"
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
OPENAI_MODEL: "gpt-4o"
OPENAI_BASE_URL: "https://vdfvdf.openai.azure.com/"
CURRENT_BRANCH: ${{ github.head_ref }}

steps:
- name: Checkout repository # Fetch the repository code
- name: Checkout repo
uses: actions/checkout@v4

- name: Install Dagger CLI # Download and install the Dagger CLI
- name: Install Dagger CLI
run: |
curl -fsSL https://dl.dagger.io/dagger/install.sh | BIN_DIR=$HOME/.local/bin sh
echo "$HOME/.local/bin" >> $GITHUB_PATH # Add Dagger to the system PATH
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Run Dagger plan
- name: Create .env file
working-directory: docs/dagger/dagger-hackathon/
run: |
dagger call debug-unit-test-agent --directory-arg="." \
--github-token="GITHUB_TOKEN" \
--github-branch=feature/dagger-hackathon-line-extraction \
--github-repo=codetocloudorg/platform-engineering \
--azure-model="gpt-4o" \
--azure-endpoint="https://vdfvdf.openai.azure.com/" \
--azure-api-key="OPENAI_API_KEY"
cat <<EOF > .env
OPENAI_BASE_URL=https://vdfvdf.openai.azure.com/
OPENAI_MODEL=gpt-4o
OPENAI_API_KEY=${OPENAI_API_KEY}
OPENAI_AZURE_VERSION=2024-12-01-preview
GITHUB_TOKEN=${GITHUB_TOKEN}
EOF

- name: Dagger Run Unit Tests
working-directory: docs/dagger/dagger-hackathon/
env:
DAGGER_SECRET_GITHUB_TOKEN: ${{ secrets.DAGGER_HACKATHON_GITHUB_TOKEN }}
run: |
export AZURE_OPENAI_API_KEY="${OPENAI_API_KEY}"
export AZURE_OPENAI_ENDPOINT="https://vdfvdf.openai.azure.com/"
dagger call \
--source="." \
--github_branch="${CURRENT_BRANCH}" \
--github_repo="codetocloudorg/platform-engineering" \
--github_token=DAGGER_SECRET_GITHUB_TOKEN \
--azure_api_key="OPENAI_API_KEY" \
--azure_endpoint="https://vdfvdf.openai.azure.com/" \
fix-my-tests-agent
4 changes: 4 additions & 0 deletions docs/dagger/dagger-hackathon/.env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
OPENAI_BASE_URL=""
OPENAI_MODEL="gpt-4o"
OPENAI_API_KEY=""
OPENAI_AZURE_VERSION="2024-12-01-preview"
195 changes: 181 additions & 14 deletions docs/dagger/dagger-hackathon/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 🧑‍💻 Dagger Hackathon: June 18th, 2025

Welcome to the Dagger hackathon hosted by the CNCF and Code to Cloud! By the end of this hack, you will have a good understanding of how to use Dagger and the various use cases it can help support.
Welcome to the Dagger hackathon hosted by the [CNCF](https://community.cncf.io/cloud-native-calgary/) and [Code to Cloud](https://www.codetocloud.io/)! By the end of this hack, you will have a good understanding of how to use Dagger and the various use cases it can help support.

## 🎯 Expected Outcomes

Expand All @@ -10,36 +10,203 @@ Welcome to the Dagger hackathon hosted by the CNCF and Code to Cloud! By the end

✅ Dagger pipeline triggers LLM workflow if tests fail

✅ LLM provides feedback on why tests could be failing in a PR
✅ LLM provides code suggestion to fix failing unit tests

✅ Code suggestion is added to PR

## ✅ Prerequisites

There are two options for this hackathon. We highly recommend the first option to avoid dependency issues.

### 1️⃣ Option 1: Github Codespace

See Getting Started

### 2️⃣ Option 2: Local

<img src="./assets/one_does_not_simply_meme.jpg" alt="anakin" width="400"/>

Make sure to follow the prerequisites defined [here](../README.md) in the main Dagger README.

## 🔨 Implementation
## 🔨 Getting Started

---

### ✅ Step 1: Create a Dagger Cloud Account

- [Register for a account](https://dagger.io/cloud)
- Under settings, create a `DAGGER_CLOUD_TOKEN` and copy the secret password somewhere temporary

> **Note:** This will be used to enable logging on the Dagger pipeline. Logs can be viewed in [Dagger Cloud](https://dagger.io/cloud) after step 5.

---

### ✅ Step 2: Fork This Repository

- Create a fork of this repository to your personal GitHub account
If you already have a fork, either rebase to this repository or, if you don't have any work you want to keep, just delete and recreate.

- In the UI, create a new feature branch off `main`

---

### ✅ Step 2: Setup Codespace *(if you are setting up locally skip to Step 3)*

- In the GitHub UI, change to the newly created feature branch
- Create a codespace on the feature branch

<img width="908" alt="image" src="https://github.com/user-attachments/assets/6d98a55a-207f-4389-b976-582fc3dec983" />

- This will auto-open VS Code in browser. If you don't want to work from here and have the VS Code app installed, you can close this and open it in the app

![image](https://github.com/user-attachments/assets/6b6b0702-b083-4e33-8868-675bfd6e5fc9)

---

### ✅ Step 3: Setup Locally *(if you did Step 2 then skip to Step 4)*

#### 🔧 Install required prerequisites

- Python 3.11+
- [Docker Desktop](https://www.docker.com/products/docker-desktop/) or another container runtime (e.g. Colima on macOS and Linux)
- [Dagger CLI](https://docs.dagger.io/install/)

#### 🔧 Additional Setup

- Start your container runtime
- Clone the forked repository locally and switch to the newly created feature branch

---

### ✅ Step 4: Break Some Code and Open A PR

<img src="./assets/anakin_meme.webp" alt="anakin" width="400"/>

Now that we have all of our prerequisites setup, **this is where the fun begins!**

The below steps will take you through making a breaking change to a file in our application which will set us up in the next step to have our agent try and troubleshoot it.

All the code for the below can be found [here](./dagger-hackathon-pipeline/).
- Open a terminal
- Create an environment variable for `DAGGER_CLOUD_TOKEN`, e.g.
```bash
export DAGGER_CLOUD_TOKEN="XXX"
```
- Change directory into `docs/dagger/dagger-hackathon/`
- Open the file `docs/dagger/dagger-hackathon/src/addition.py` and break the function
For example, modify to: `return a + b * 4`
- Run the unittests
```bash
python -m unittest discover tests -v
```
and confirm it fails
- Push the modified `addition.py` to your new feature branch
- In the GitHub UI, open a PR on the feature branch and compare to `main`

Make sure you have the repo cloned and you are in the `docs\dagger\dagger-hackathon-pipeline` directory:
---

```bash
# Clone the repository from GitHub
git clone https://github.com/codetocloudorg/platform-engineering.git
### ✅ Step 5: Run The Fix My Tests Agent

# Change directory to the Dagger hackathon pipeline documentation folder
cd ./docs/dagger/dagger-hackathon-pipeline
<img src="./assets/spongebob_meme.jpg" alt="spongebob" width="400"/>

- Rename `docs/dagger/dagger-hackathon/.env-example` to `.env`
- Populate the placeholder keys with real values (we will provide for Hackathon day)
- Create environment variables for `GITHUB_TOKEN`, `AZURE_API_KEY`, `AZURE_API_ENDPOINT`
A GitHub Token can be created in GitHub under Settings → Developer Settings → Create a classic token
Example:
```bash
export GITHUB_TOKEN="XXX"
```

- Put in your values and run in CLI:
```bash
dagger call \
--source="." \
--github_branch="BRANCH-NAME" \
--github_repo="USERNAME/REPO-NAME" \
--github_token="GITHUB_TOKEN" \
--azure_api_key="AZURE_API_KEY" \
--azure_endpoint="AZURE_API_ENDPOINT" \
fix-my-tests-agent
```

> **💡 Tip:** This will be used to enable logging on the Dagger pipeline. Logs can be viewed in [Dagger Cloud](https://dagger.io/cloud) after step 5.

- If you see an error, it might be that the Agent has hallucinated — try again
You can also debug via the Dagger Traces in Dagger Cloud

> **💡 Tip:** There is a prompt located at `docs\dagger\dagger-hackathon\dagger-hackathon-pipeline\debug_unit_test_prompt.md` that greatly influences the LLMs behavior. Make some changes to the prompt and see how it influences the results!

---

### ✅ Step 6: Explore Dagger Traces

<img src="./assets/fry_meme.jpg" alt="fry" width="400"/>

Being able to navigate and explore logs in Dagger Cloud is a great skill to have to be able to effectively troubleshoot and build pipelines in Dagger. Now that we have ran our first command in Dagger, lets jump into the logs to see what happened.

- Navigate to [Dagger Cloud](https://dagger.io/cloud)
- You should see your trace(s)

![image](./assets/dagger_cloud.png)

- Select a trace and explore the logs
- If all has gone well, you should see something like this at the bottom of the trace detailing the problematic file, line number, and fix for the failing unit test.

![image](./assets/agent_final_output.png)

---

### ✅ Step 7: Confirm The Agent Fixed the Code

<img src="./assets/pikachu_meme.jpg" alt="fry" width="400"/>

- If the Agent finished successfully, you should see something like below in the CLI
```
AgentResponse(pr_metadata=PrMetadataResult(pr_number='1', commit_id='c4293304b9fdccf2022e7e15e09e5b1604cecf04'), pr_suggestions=GitHubPrSuggestionResult(body='```suggestion\nreturn a + b\n```', comment_url='https://github.com/david-hurley/platform-engineering/pull/1#discussion_r2127910154'))
```
- Click the PR URL and see if there is a suggested code change

---

### ✅ Step 8: Trigger GitHub Action

- Delete the comment the Agent left on the PR in Step 6
- [Create GitHub secrets](https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#creating-secrets-for-a-repository) for everything in `.env` and name them `DAGGER_HACKATHON_GITHUB_TOKEN` and `OPENAI_API_KEY` for the GitHub token and Azure OpenAI API key respectively.
- Make sure to update your GitHub Action to trigger on a pull request instead of a manual trigger.

Update the trigger from this:

```yaml
on:
workflow_dispatch:
```

To this:
```yaml
on:
pull_request:
branches: [main]
types: [opened, synchronize, reopened]
```

### Step 1: Create a Feature Branch
- Push your changes to Git and navigate back to your forked repo to see the GitHub Action running

![image](./assets/run_unit_tests.png)

---

### ✅ Step 9: Extend the Agent

The last step is to extend the Dagger agent to actually make the code fix itself and push the changes to the PR for the human to review. That way there is still a human-in-the-loop to validate the AI output.

### 🤖 Step 2: Select your LLM Provider
---

### Step 3: Create a PR
## ⚠️ Gotchas and Future Improvements

### Step 4: Run the Dagger Function
- The agent can sometimes return incorrect paths to the file with breaking changes, incorrect line number of the breaking change, or incorrect fix (e.g. too verbose)
- Current state of this does not work with multi-line code changes or multiple breaking changes.
Only supports **1 breaking change on 1 line**
- The way commit ID is retrieved is not robust — if a breaking change is pushed to a branch with an open PR and it is commit ID A, and then another file is pushed (commit ID B),
the code is setup to grab the **latest commit ID**, not the one with the breaking change
This may result in failure (i.e. no diff)
- The agent leaves a comment on the PR as the idenity of whoever generated to token. In other words, if you leverage your GitHub token in the above steps, then the agent will leave a comment on the PR as you. This ideally should be a generic account in the future.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Instructions
You are a Python testing expert.

Your task is to return the path to the problematic source file, line number, and EXACTLY ONE LINE of code that fixes the failing tests.

The final reply must include these details, do not try and modify any files.
- When you return the path, make sure you give the full path to the file: docs/dagger/dagger-hackathon (e.g.: docs/dagger/dagger-hackathon/src/addition.py).
- Think hard about the line number, it should be the line number of the bug code in the file specified by the path that is failing.
- Check that the line number exists in the file and that the proposed change is meant for that line.

**Return ONLY the path to the problematic source file (e.g.: docs/dagger/dagger-hackathon), line number that failing code is happneing on, and EXACTLY ONE LINE of code that fixes the failing tests. Nothing else.**

## Test Results
{{.test_results}}

## Example Output:
Path: docs/dagger/dagger-hackathon/src/subtraction.py Line number: 7 Code to fix the issue: return a - b
Loading
Loading