Skip to content

Add import validation graders for checking required and allowed imports#32

Open
ironm00n wants to merge 2 commits intomasterfrom
claude/explore-codebase-imports-TD1R1
Open

Add import validation graders for checking required and allowed imports#32
ironm00n wants to merge 2 commits intomasterfrom
claude/explore-codebase-imports-TD1R1

Conversation

@ironm00n
Copy link
Copy Markdown
Member

@ironm00n ironm00n commented Mar 6, 2026

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 name
    • check-import-allowlist(): Validates that all imports are from an allowed list of modules
    • fmt-import-required() and fmt-import-allowlist(): Format violations into user-friendly markdown messages
    • mk-import-required() and mk-import-allowlist(): Factory functions to create guard checkers
    • Helper functions to parse imports and extract module/binding names from AST nodes
  • Comprehensive test coverage (pkgs/core/tests/graders/imports.arr):

    • Tests for finding imports with correct/incorrect bindings
    • Tests for missing imports
    • Tests for allowlist enforcement (all allowed, some forbidden, all forbidden)
    • Smoke tests for error formatting
  • Test fixtures:

    • has-imports.arr: Sample file with tables and image imports
    • no-imports.arr: Sample file with no imports
  • Integration: Updated main grader modules to export the new import validators

Implementation Details

  • Uses AST parsing via CA.parse-path() to extract import statements from student code
  • Handles multiple import forms: s-import, s-include, and s-import-fields
  • Distinguishes between module names (what's imported) and binding names (the as alias)
  • Provides detailed error messages with markdown formatting for different failure modes

https://claude.ai/code/session_01YaEjXHmaz22DdT6ntNxQP9

@ironm00n ironm00n force-pushed the claude/explore-codebase-imports-TD1R1 branch from 7ecc176 to eefb9f5 Compare March 27, 2026 05:03
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>
@ironm00n ironm00n force-pushed the claude/explore-codebase-imports-TD1R1 branch from eefb9f5 to ea02b75 Compare March 27, 2026 05:05
@ironm00n
Copy link
Copy Markdown
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>
@ironm00n ironm00n force-pushed the claude/explore-codebase-imports-TD1R1 branch from ea02b75 to 3c91510 Compare March 27, 2026 05:12
@ds26gte
Copy link
Copy Markdown

ds26gte commented Mar 27, 2026

Could you add an example use in pkgs/gradescope/examples, perhaps even in the existing tower example?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants