fix(phobos): correct copy helper quoting - #152
Conversation
📝 WalkthroughWalkthroughThe Phobos copy tool now assigns ChangesPhobos shell contract
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: Caution Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (1 error)
✅ Passed checks (7 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/test/java/de/tum/cit/ase/ares/api/phobos/PhobosShellContractTest.java`:
- Around line 61-65: Update PhobosShellContractTest to avoid eval and
shell-source interpolation: parse the TARGET_DIR assignment from copyTool
directly in Java, and invoke Bash through ProcessBuilder with copyTool passed as
an argument rather than embedded in quoted command strings. Preserve the
existing syntax validation and parsed-value assertions while ensuring checkout
paths and fixture contents cannot execute shell syntax.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: edf587b3-032b-408a-a45b-f38dd62315ce
📒 Files selected for processing (2)
src/main/resources/de/tum/cit/ase/ares/api/templates/phobos/PhobosCopyTool.shsrc/test/java/de/tum/cit/ase/ares/api/phobos/PhobosShellContractTest.java
📜 Review details
⏰ Context from checks skipped due to timeout. (2)
- GitHub Check: Analyse Java
- GitHub Check: Build
🧰 Additional context used
📓 Path-based instructions (3)
**/*
⚙️ CodeRabbit configuration file
Dogmatically check all reviewed files for current British English in prose, comments, JavaDoc, documentation, workflow names, step names, issue/PR text, labels, user-facing messages, and review suggestions. Flag American spellings and grammar such as behavior, color, initialize, authorization, canceled, and program when they are natural-language text. Do not flag programming-language syntax, dependency coordinates, API names, class names, method names, package names, paths, URLs, quoted external identifiers, or other literals where American English is required by the technology.
Files:
src/main/resources/de/tum/cit/ase/ares/api/templates/phobos/PhobosCopyTool.shsrc/test/java/de/tum/cit/ase/ares/api/phobos/PhobosShellContractTest.java
**/*Test.java
📄 CodeRabbit inference engine (AGENTS.md)
**/*Test.java: A sandboxed test JVM must never spin up its own server (echo server, socket listener, etc.) to test incoming or outgoing connections
Outgoing-connection tests must connect to an external echo server at a configurable endpoint running as a separate process or CI service on the loopback at port 25565, exercising only the student's client behaviour
If the external echo server is not reachable, the test must skip (using JUnit Assumptions.abort) rather than fail
An Ares SecurityException on an explicitly allowed connection is always a real failure and must propagate (never skipped)
Do not hard-code a self-hosted listener as the connection counterpart; use an external echo service to avoid in-JVM BindException/thread/lifecycle flakiness
Files:
src/test/java/de/tum/cit/ase/ares/api/phobos/PhobosShellContractTest.java
src/test/java/**/*.java
⚙️ CodeRabbit configuration file
Require tests to distinguish fixture failures from sandbox failures. Network tests must not start in-process listeners inside the sandbox; external fixtures may be skipped when absent, but explicit Ares SecurityException failures must propagate.
Files:
src/test/java/de/tum/cit/ase/ares/api/phobos/PhobosShellContractTest.java
🔇 Additional comments (1)
src/main/resources/de/tum/cit/ase/ares/api/templates/phobos/PhobosCopyTool.sh (1)
5-5: LGTM!
|
@coderabbitai review |
✅ Action performedReview finished.
|
Claudia-Anthropica
left a comment
There was a problem hiding this comment.
@ShudongCai The template now uses ASCII double quotes for the intended target path, and the regression test safely validates the exact assignment and Bash syntax without executing fixture content. The prior shell-boundary concern is resolved, and all captured CI checks succeeded on this head.
|
The pull request template now bounds each section: 500 characters for Summary, 1000 for This description was written before those limits and exceeds 1 of them, so I have 1. Problem, as it read before (1119 characters, limit 1000)Observed under any configuration that generates a Phobos exercise (the script is a static template resource, so no Java version, build tool, AOP mode or architecture mode changes the defect). TARGET_DIR=“/var/tmp/opt/core”Bash does not treat The root cause sits in the build-integration layer: this script is copied verbatim into generated exercise artifacts ( |
Summary
Correct the
PhobosCopyTool.shtemplate so its target-directory assignment uses ASCII double quotes instead of Unicode curly quotation marks, and pin the fix with a regression test. Without this, the copy step in every generated Phobos exercise fails. (Audit finding I-002.)Linked issues
None. I-002 comes from an internal audit report, not a GitHub issue.
1. Problem
Observed under any configuration that generates a Phobos exercise: the script is a static
template resource, so no Java version, build tool, AOP mode or architecture mode changes it.
PhobosCopyTool.shassigned the target directory with curly quotation marks:Bash does not treat
“(U+201C) and”(U+201D) as quoting operators, so they stay in thevalue.
TARGET_DIRresolves to“/var/tmp/opt/core”, and the followingcp -v SpecificExercise.cfg "$TARGET_DIR/"copies into a directory that does not exist andfails; under
set -ethat aborts the script.The fault sits in plugging Ares into the build: the script is copied verbatim into generated
exercises (
PhobosCopyFiles.csvtoJavaWriter), so it reaches every generated exerciserather than staying in the template. Ares neither let forbidden code through nor failed a
correct submission; a setup step failed, which breaks a correct exercise before any
submission is judged.
2. Improvement from the user's perspective
An instructor generating a Phobos exercise gets a copy step that works:
SpecificExercise.cfgis copied into/var/tmp/opt/core/as intended, instead of the exercise breaking at thecpinto a non-existent“/var/tmp/opt/core”directory.3. Improvement from the maintainer's perspective
The authoritative template is now pinned by
PhobosShellContractTest.copyToolAssignsTargetDirectoryWithAsciiQuotes, which parses the assignment in Java and rejects any reappearance of the curly quotation marks, so this class of typo cannot silently return. The check is deliberately self-contained: it never executes the fixture and never interpolates its path into a shell command (it reads the file, matches the assignment with a regex, and validates syntax by feeding the content tobash -non stdin).4. Testing manual
Prerequisites
bashonPATH(the test shells out tobash -n). No exercise repository, policy file or echo server is needed: the fixture is the packaged template resourcesrc/main/resources/de/tum/cit/ase/ares/api/templates/phobos/PhobosCopyTool.sh.Steps
mvn -o test -Dtest=PhobosShellContractTest -f pom.xmlPhobosCopyTool.shand confirm the assignment readsTARGET_DIR="/var/tmp/opt/core".Expected result
copyToolAssignsTargetDirectoryWithAsciiQuotespasses: the script contains no“/”, contains exactly oneTARGET_DIR=assignment, that assignment matches^TARGET_DIR="(/var/tmp/opt/core)"$, andbash -non the script content exits 0.Negative case (what must still be rejected)
TARGET_DIR=line) makes the test fail: theassertFalseon U+201C/U+201D, the exactly-one-assignmentassertEquals(1, ...), and the anchored regex each reject the broken form. The test was confirmed to fail against the original curly-quote script before the fix.Modes exercised
No mode-specific behaviour changed.
5. Test case coverage regarding this PR
No production Java code changed. The corrected artefact is the shell-script template resource
PhobosCopyTool.sh; the only Java added is the regression testPhobosShellContractTest, which pins that resource. There is therefore no production class with Instruction/Branch/Line/Method coverage to report.Breaking changes and migration
None. The public API under
de.tum.cit.ase.ares.api, the security policy file format, the generated security test code and the minimum JDK/Maven/Gradle versions are all unchanged. The only behavioural change is that the copy step in a newly generated exercise now succeeds where it previously failed.Checklist
Review progress