feat(static_analysis): add AI algorithm tests (#332)#333
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds new AI-driven algorithm verification tests (sorting/search/graph) to the Static Analysis template, including configuration schema, translations, and unit tests.
Changes:
- Added
AiAlgorithmTestBase+ three concrete AI algorithm tests and registered them inStaticAnalysisTemplate. - Added EN/PT-BR translations for the new tests’ descriptions/params.
- Added unit tests covering registration, metadata, config validation, and prompt generation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| tests/unit/test_ai_algorithm_tests.py | Adds unit coverage for AI algorithm tests’ registration/config/prompt behavior. |
| autograder/translations/en.json | Adds English i18n strings for new AI algorithm tests. |
| autograder/translations/pt_br.json | Adds PT-BR i18n strings for new AI algorithm tests. |
| autograder/template_library/static_analysis.py | Introduces AI algorithm test classes/config and registers them in the static analysis template. |
| class AiAlgorithmConfig(BaseModel): | ||
| algorithm_name: str = Field(..., min_length=1) |
| files: Optional[List[SubmissionFile]], | ||
| **kwargs, | ||
| ) -> str: | ||
| algorithm_name = (kwargs.get("algorithm_name") or "").strip() |
| algo_label = algorithm_name or "Unknown algorithm" | ||
|
|
||
| return ( | ||
| f"You are verifying a {self.algorithm_family} algorithm implementation.\n" | ||
| f"Requested algorithm: {algo_label}.\n" |
| f"Use subject '{algo_label}'." | ||
| ) |
| class AiAlgorithmTestBase(AiTestFunction): | ||
| algorithm_family: str = "" | ||
| test_name: str = "" | ||
|
|
||
| @property | ||
| def name(self) -> str: | ||
| return self.test_name |
| def build_prompt( | ||
| self, | ||
| files: Optional[List[SubmissionFile]], | ||
| **kwargs, | ||
| ) -> str: | ||
| algorithm_name = (kwargs.get("algorithm_name") or "").strip() | ||
| file_names = ", ".join(f.filename for f in files) if files else "" | ||
|
|
||
| if file_names: | ||
| file_scope = f"Focus only on these files: {file_names}." | ||
| else: | ||
| file_scope = "No submission files were provided for this test." | ||
|
|
|
E2E via Dockerfile.api (FastAPI) with remote sandbox manager is running. I created three grading configs using Configs created
Scenarios
Logs
Conclusion Unrelated issue discovered
|
|
Reran E2E using Dockerfile.api in remote sandbox mode with a valid OpenAI key from Configs created
Scenarios (5, incl. 2 foggy)
Conclusion Note |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Context
While the autograder already supported basic static analysis (forbidden imports and keyword detection), it lacked the ability to verify complex algorithm implementations. Simple I/O matching or structural checks are often insufficient to distinguish between a faithful implementation of a specific algorithm (like Quick Sort) and a wrapper around a built-in library function.
Solution
This PR introduces AI-based algorithm verification tests to the Static Analysis template:
AiAlgorithmTestBaseand three specialized test functions:ai_sorting_algorithmai_search_algorithmai_graph_algorithmStaticAnalysisTemplate.GradingRequestAPI.Further clarifications
OPENAI_API_KEY.Related issues
Closes #332
Checklist