Add import validation graders for checking required and allowed imports#32
Open
Add import validation graders for checking required and allowed imports#32
Conversation
7ecc176 to
eefb9f5
Compare
Add two new guards for checking student imports: - mk-import-required: verifies a specific module is imported, optionally with a required alias name - mk-import-allowlist: restricts which modules students can import, blocking any unlisted modules Both guards share internal helpers for parsing and extracting import metadata from the AST. Includes unit tests and test fixtures. Co-authored-by: IRONM00N <me@ironmoon.dev>
eefb9f5 to
ea02b75
Compare
Member
Author
|
@ds26gte Let me know if this seems good, or if you were wanting anything else. |
Demonstrates the key use case: a wheat test depends on the student having a particular import (`import image as I`). The DAG is: wf → import-required → fn-def → wheat Includes example student file, wheat implementation, and npm script. Co-authored-by: IRONM00N <me@ironmoon.dev>
ea02b75 to
3c91510
Compare
|
Could you add an example use in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds two new grading guards for validating student imports: one to ensure required modules are imported with correct bindings, and another to enforce an allowlist of permitted imports.
Key Changes
New grader module (
pkgs/core/src/graders/imports.arr):ImportRequiredBlock: Data type for tracking import requirement violations (parser errors, missing imports, wrong bindings)ImportAllowlistBlock: Data type for tracking import allowlist violations (parser errors, forbidden imports)check-import-required(): Validates that a specific module is imported with an optional expected binding namecheck-import-allowlist(): Validates that all imports are from an allowed list of modulesfmt-import-required()andfmt-import-allowlist(): Format violations into user-friendly markdown messagesmk-import-required()andmk-import-allowlist(): Factory functions to create guard checkersComprehensive test coverage (
pkgs/core/tests/graders/imports.arr):Test fixtures:
has-imports.arr: Sample file withtablesandimageimportsno-imports.arr: Sample file with no importsIntegration: Updated main grader modules to export the new import validators
Implementation Details
CA.parse-path()to extract import statements from student codes-import,s-include, ands-import-fieldsasalias)https://claude.ai/code/session_01YaEjXHmaz22DdT6ntNxQP9