Skip to content

Grader: file-exists

PropertyValue
Determinismstatic
Costlow
Portabilityt1-universal
Referencereference-free
Temporal scopetrajectory-level
Score kindcode
graders:
- type: file-exists
config:
path: "add.test.js"
FieldTypeRequiredDescription
pathstringYesFile path or glob pattern to match in the workspace
negatebooleanNoWhen true, passes when NO files match

Use file-not-exists as a shorthand for negate: true:

graders:
- type: file-not-exists
config:
path: "*.tmp"

This is equivalent to type: file-exists with negate: true.

Uses Node.js glob() to search the trajectory’s workDir for files matching the pattern.

Passes when at least one file matches (or NO files match if negated). Fails otherwise.

Supports standard glob patterns:

  • "add.test.js" — exact file
  • "*.test.js" — all test files
  • "src/**/*.ts" — recursive TypeScript files
  • "output/*.{json,txt}" — multiple extensions
✔ Files matching 'add.test.js' found: add.test.js
✔ Files matching '*.test.js' found: add.test.js, utils.test.js
✘ No files matching 'add.test.js' found
async grade(input: GraderInput): Promise<GraderResult> {
await assertWorkDirAccessible(input.trajectory.workDir);
const matchIter = glob(input.config.path, {
withFileTypes: false,
cwd: input.trajectory.workDir,
});
const matches = [];
for await (const item of matchIter) {
matches.push(item);
}
const passed = matches.length > 0;
return {
name: this.metadata.name,
kind: "code",
passed,
score: passed ? 1 : 0,
evidence: passed
? `Files matching '${input.config.path}' found: ${matches.join(", ")}`
: `No files matching '${input.config.path}' found`,
label: passed ? "correct" : "incorrect",
};
}