MCPcopy Create free account
hub / github.com/NVIDIA/SOL-ExecBench / SourceFile

Class SourceFile

src/sol_execbench/core/data/solution.py:80–113  ·  view source on GitHub ↗

A single source code file in a solution implementation. Represents a source code file with its relative path and complete content. The file content is validated for syntax correctness based on the file extension.

Source from the content-addressed store, hash-verified

78
79
80class SourceFile(BaseModelWithDocstrings):
81 """A single source code file in a solution implementation.
82
83 Represents a source code file with its relative path and complete content.
84 The file content is validated for syntax correctness based on the file extension.
85 """
86
87 path: NonEmptyString
88 """The relative path of the file, including its name and extension (e.g., 'src/kernel.cu',
89 'main.py'). When compiling the solution, a temporary solution source directory will be
90 created, and the file will be placed according to this path. The path should not contain
91 parent directory traversal ("..")."""
92 content: NonEmptyString
93 """The complete text content of the source file."""
94
95 @model_validator(mode="after")
96 def _validate_source_path(self) -> "SourceFile":
97 """Validate source path for security.
98
99 Raises
100 ------
101 ValueError
102 If the path contains security issues (absolute paths or path traversal).
103 """
104 src_path = Path(self.path)
105 if src_path.is_absolute():
106 raise ValueError(
107 f"Invalid source path (absolute path not allowed): {self.path}"
108 )
109 if ".." in src_path.parts:
110 raise ValueError(
111 f"Invalid source path (parent directory traversal not allowed): {self.path}"
112 )
113 return self
114
115
116

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected