Skip to content

Grader: file-contains

Property Value
Determinism static
Cost low
Reference reference-free
Temporal scope trajectory-level
Score kind code
graders:
- type: file-contains
config:
path: "add.test.js"
value: "expect"
Field Type Required Description
path string Yes File path (or glob) to check
value string Yes Text that must appear in the file
negate boolean No When true, passes when the value is NOT found

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

graders:
- type: file-not-contains
config:
path: "*.csproj"
value: "packages.config"

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

  1. Finds files matching path in the workspace using glob
  2. Reads each matching file as UTF-8
  3. Checks if the file contains value (case-sensitive)

Glob patterns match regular files, including dotfiles and files inside dot-directories. Directories, symlinks, and other special entries are not matched.

Passes when the value is found in at least one readable matching file. In negated mode, it passes only when every matching file is readable and none contains the value, or when no files match. Fails otherwise. If unreadable matching files prevent a conclusive result, both normal and negated modes fail.

If a matching file can’t be read (for example, because access is denied or it was removed after matching), it is skipped and noted in the evidence string. If a later readable file matches, the evidence includes the earlier skipped files. If no readable file contains the value but any candidate was unreadable, the result is indeterminate: both normal and negated modes fail because presence or absence cannot be proven. In that case, the evidence lists the unreadable files and states what could not be proven. Binary files are NOT skipped — readFile("utf-8") returns mojibake for binary content, which simply won’t match most substrings.

✔ 'expect' found in add.test.js
✘ 'expect' NOT found in add.test.js
✘ No files matching 'add.test.js' found
✔ 'expect' found in add.test.js (skipped 1 unreadable file: obj/Debug/app.dll)
✘ Indeterminate: 'expect' not found in any readable file matching '*.txt'; 1 unreadable file: skip.txt. Cannot prove absence.