MCPcopy Create free account
hub / github.com/promptfoo/promptfoo / processExecutableFile

Function processExecutableFile

src/prompts/processors/executable.ts:118–155  ·  view source on GitHub ↗
(
  filePath: string,
  prompt: Partial<Prompt>,
  _functionName?: string,
)

Source from the content-addressed store, hash-verified

116 * @returns Array of prompts generated from the executable.
117 */
118export async function processExecutableFile(
119 filePath: string,
120 prompt: Partial<Prompt>,
121 _functionName?: string,
122): Promise<Prompt[]> {
123 // For display purposes, try to read the file if it exists and is a text file
124 let rawContent = filePath;
125 const scriptParts = parseScriptParts(filePath);
126 const firstPart = scriptParts[0];
127
128 if (firstPart) {
129 try {
130 const stats = await fsStat(firstPart);
131 if (stats.isFile() && stats.size < 1024 * 100) {
132 // Only read files < 100KB
133 const content = await readFile(firstPart, 'utf-8');
134 // Check if it's likely a text file
135 if (!/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/.test(content.substring(0, 1000))) {
136 rawContent = content;
137 }
138 }
139 } catch (_e) {
140 // Ignore errors, use the path as raw content
141 }
142 }
143
144 const label = prompt.label ?? filePath;
145
146 return [
147 {
148 raw: rawContent,
149 label,
150 function: (context) =>
151 executablePromptFunction(filePath, { ...context, config: prompt.config }),
152 config: prompt.config,
153 },
154 ];
155}

Callers 2

executable.test.tsFile · 0.90
processPromptFunction · 0.90

Calls 3

parseScriptPartsFunction · 0.90
executablePromptFunctionFunction · 0.85
readFileFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…