Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/prompts/processors/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ export function processYamlFile(filePath: string, prompt: Partial<Prompt>): Prom
// Recursively resolve any file:// references in the parsed structure
const resolved = maybeLoadConfigFromExternalFile(parsed);

// Convert back to JSON string
maybeParsed = JSON.stringify(resolved);
// Convert back to JSON while preserving the raw contents of empty YAML documents.
// JSON.stringify(undefined) returns undefined, but Prompt.raw must always be a string.
maybeParsed = JSON.stringify(resolved) ?? fileContents;
} catch (e) {
logger.debug(`Error parsing YAML file ${filePath}: ${e}`);
}
Expand Down
5 changes: 2 additions & 3 deletions test/prompts/processors/yaml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,8 @@ template: "{{ variable }} "
const result = processYamlFile(filePath, {});

expect(result).toHaveLength(1);
// Empty YAML parses to undefined; maybeLoadConfigFromExternalFile passes it
// through; JSON.stringify(undefined) is the literal string "undefined".
expect(result[0].raw).toBe(JSON.stringify(undefined));
expect(result[0].raw).toBe('');
expect(result[0].label).toBe(`${filePath}: `);
});
});
});