Skip to content

Add data_files setting and tests_dir fixture - #37

Merged
eliotwrobson merged 4 commits into
mainfrom
claude/data-files
Nov 10, 2026
Merged

eliotwrobson merged 4 commits into
mainfrom
claude/data-files

Conversation

@eliotwrobson

Copy link
Copy Markdown
Collaborator

Lets workspace questions keep data files in tests/ and read them by relative path, e.g. np.loadtxt("pagerank_large.txt") in PageRank's leading code and notebook.

  • ConfigObject(data_files=["pagerank_large.txt"]): the sandbox starts in a new folder in /tmp that holds root-owned, read-only copies of the listed files at their relative paths. It's opt-in and works with sandbox, module_sandbox (.py and .ipynb) and workspace_sandbox, since the notebook questions don't use workspace_mode. Entries must be relative paths without ... A missing file makes the submission ungradable, like helper_modules. Without the setting, the starting folder doesn't change. The folder isn't on the import path.
  • tests_dir fixture: returns the tests folder (get_datadir), so tests can do np.loadtxt(tests_dir / "pagerank_large.txt").
  • run.sh: now runs chown -R root:root and chmod -R go-w on /grade/run. In a Docker test where the host files had ag's uid, student code could overwrite /grade/run/test_student/pagerank_large.txt by absolute path, which changed what tests_dir reads. This fixes that. It needs an image rebuild.

Docker test (full image + this wheel, job copied into the container): a notebook loading the file in leading code and in a #grade cell got full credit on both tests. A wrong matrix failed only that test. A missing file made the submission ungradable with the config message. As ag, writes to the copy, to its folder and to the original all raised PermissionError, even with the originals owned by uid 1000. Docker Desktop bind mounts on macOS don't enforce file permissions, so the job has to be copied into the container to test this.

🤖 Generated with Claude Code

eliotwrobson and others added 4 commits November 9, 2026 17:56
ConfigObject(data_files=[...]) copies the listed tests-folder files into a
new read-only folder that the sandbox starts in, so leading code and student
code can read them by relative path, as in a Jupyter workspace. A missing
listed file makes the submission ungradable. The tests_dir fixture gives
tests the tests folder for reading the originals.

run.sh now makes the merged run folder root-owned and not writable by
group or others, so student code can't change files that tests read later
when the host's file owner has ag's uid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Use PurePosixPath so "/" is the separator on every OS and "." and repeated
"/" parts are normalized, and compare normalized paths for duplicates. Keep
rejecting backslashes and Windows drives, which would be a separator or an
anchor on Windows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Build them from stat flags instead of octal literals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Call the folder named after the test module the tests folder everywhere,
to match the tests_dir fixture, and fix get_tests_dir's docstring, which
described a 'data' directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eliotwrobson
eliotwrobson marked this pull request as ready for review November 10, 2026 15:07
@eliotwrobson
eliotwrobson merged commit fb0b3e6 into main Nov 10, 2026
5 checks passed
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.

1 participant