Spaces:
Sleeping
Sleeping
Download architect/readme_generator.py from refaelz/legacy-code-challenge: direct link, hf CLI and curl.
- Browser
- Download file 3.31 kB
-
https://huggingface.co/spaces/refaelz/legacy-code-challenge/resolve/main/architect/readme_generator.py
- Command line
-
hf download hf://spaces/refaelz/legacy-code-challenge/architect/readme_generator.py
-
curl -L -o readme_generator.py https://huggingface.co/spaces/refaelz/legacy-code-challenge/resolve/main/architect/readme_generator.py
3.31 kB
| import os | |
| from architect.state import ArchitectState | |
| def create_readme(state: ArchitectState) -> ArchitectState: | |
| num_bugs = state.get("num_bugs", 1) | |
| clone_path = state["clone_path"] | |
| repo_name = os.path.basename(clone_path) | |
| target_rel = os.path.relpath(state["target_file"], clone_path) | |
| bugs_str = "1 bug" if num_bugs == 1 else f"{num_bugs} bugs" | |
| refactoring_note = "" | |
| if state.get("refactoring_enabled", False): | |
| refactoring_note = ( | |
| "\n\n> **β οΈ Note:** The code has been intentionally obfuscated with " | |
| "confusing variable names and structure." | |
| ) | |
| readme_path = os.path.join(clone_path, "STUDENT_README.md") | |
| content = f"""\ | |
| # Legacy Code Challenge | |
| ## Your Mission | |
| You have just joined the team. Your tech lead hands you an urgent ticket: | |
| > **"Something broke in production β the tests are failing and we cannot ship. | |
| > Good luck. The original author left the company."** | |
| Your task: find and fix **{bugs_str}** hidden in `{target_rel}` β without breaking anything else.{refactoring_note} | |
| ### β οΈ Only modify `{target_rel}`. Do not touch any other file. | |
| --- | |
| ## How to Work | |
| You can edit the code in two ways: | |
| - **Built-in Code Editor** β use the **π» Code Editor** tab to browse and edit files | |
| directly in the challenge UI. Click **πΎ Save** to save your changes. | |
| - **Your local IDE** β open the file in VS Code, PyCharm, or any editor you prefer. | |
| Your saved changes are picked up automatically when you submit. | |
| To run the tests at any time, either: | |
| - Go to the **π§ͺ Test Results** tab in the challenge UI and click **βΆ Run Tests**. | |
| - Or To run the tests at any time, by: | |
| ```bash | |
| python {repo_name}\challenge_run.py | |
| ``` | |
| The test cases are also visible in the **π» Code Editor** tab β open `{repo_name}\challenge_run.py` | |
| to read them. | |
| --- | |
| ## Constraints - | |
| > ### β οΈ Read carefully β violations will affect your score. | |
| 1. **Only fix `{target_rel}`.** Do not change any other file. | |
| 2. **No renaming variables or parameters.** | |
| 3. **No splitting or merging functions.** Signatures must stay exactly as-is. | |
| 4. **No adding external imports.** | |
| 5. **Minimal fix only.** At most 1β3 lines changed per bug. | |
| 6. **Do not break existing behaviour.** | |
| --- | |
| ## AI Assistant | |
| On the right side of the challenge you have an **AI Assistant** you can chat with. | |
| It can help you understand the codebase, navigate the challenge UI, explain what a piece | |
| of code does, or point you in the right direction β but it will **not** give you the fix. | |
| > ### **β οΈ Using hints from the AI carries a scoring penalty, so use it wisely.** | |
| --- | |
| ## Submitting | |
| You can submit at any time using the **π Submit Fix** button. | |
| Running the tests first lets you verify whether you have found and fixed all the bugs. | |
| --- | |
| ## Scoring | |
| Your submission is evaluated automatically by an AI reviewer: | |
| - **Correctness** β did all the tests pass and were all bugs fixed? | |
| - **Minimality** β did you change only the lines that needed to change? | |
| - **Quality** β does your fix match the expected correct approach? | |
| --- | |
| # Good luck. | |
| # The codebase is yours now. | |
| """ | |
| with open(readme_path, "w", encoding="utf-8") as f: | |
| f.write(content) | |
| print(f"[readme] Written: {readme_path}") | |
| return state | |