-
Notifications
You must be signed in to change notification settings - Fork 107
fix(run): add explicit UTF-8 encoding to prompt file operations (#604) #648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -325,6 +325,61 @@ def test_compile_file_not_found(self, mock_exists): | |
| with pytest.raises(FileNotFoundError, match="Prompt file 'nonexistent.prompt.md' not found"): | ||
| self.compiler.compile("nonexistent.prompt.md", {}) | ||
|
|
||
| def test_compile_utf8_content_with_cjk_characters(self): | ||
| """Test that prompt files with non-ASCII characters compile correctly. | ||
|
|
||
| Regression test for #604: UnicodeDecodeError on Windows CP950 | ||
| when .prompt.md contains CJK or other non-ASCII characters. | ||
| """ | ||
| tmp_dir = tempfile.mkdtemp() | ||
| try: | ||
| prompt_dir = Path(tmp_dir) | ||
|
Comment on lines
+334
to
+336
|
||
| prompt_path = prompt_dir / "i18n.prompt.md" | ||
| cjk_content = ( | ||
| "---\n" | ||
| "description: 国際化テスト\n" | ||
| "---\n" | ||
| "\n" | ||
| "你好世界!こんにちは ${input:name}!\n" | ||
| "Ünïcödé résumé naïve café" | ||
| ) | ||
|
Comment on lines
+338
to
+345
|
||
| prompt_path.write_text(cjk_content, encoding="utf-8") | ||
|
|
||
| compiler = PromptCompiler() | ||
| compiler.compiled_dir = prompt_dir / ".compiled" | ||
|
|
||
| result_path = compiler.compile( | ||
| str(prompt_path), {"name": "ユーザー"} | ||
| ) | ||
|
|
||
| compiled = Path(result_path).read_text(encoding="utf-8") | ||
| assert "你好世界!こんにちは ユーザー!" in compiled | ||
| assert "Ünïcödé résumé naïve café" in compiled | ||
| # Frontmatter must be stripped | ||
| assert "---" not in compiled | ||
| finally: | ||
| shutil.rmtree(tmp_dir) | ||
|
|
||
| def test_compile_utf8_content_without_frontmatter(self): | ||
| """Test non-ASCII prompt without frontmatter compiles correctly.""" | ||
| tmp_dir = tempfile.mkdtemp() | ||
| try: | ||
| prompt_dir = Path(tmp_dir) | ||
| prompt_path = prompt_dir / "simple_cjk.prompt.md" | ||
| prompt_path.write_text( | ||
| "Привет ${input:who}! 🚀", encoding="utf-8" | ||
| ) | ||
|
Comment on lines
+369
to
+371
|
||
|
|
||
| compiler = PromptCompiler() | ||
| compiler.compiled_dir = prompt_dir / ".compiled" | ||
|
|
||
| result_path = compiler.compile(str(prompt_path), {"who": "мир"}) | ||
|
|
||
| compiled = Path(result_path).read_text(encoding="utf-8") | ||
| assert compiled == "Привет мир! 🚀" | ||
| finally: | ||
| shutil.rmtree(tmp_dir) | ||
|
|
||
|
|
||
| class TestPromptCompilerDependencyDiscovery: | ||
| """Test PromptCompiler dependency discovery functionality.""" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changelog entries are expected to end with the PR number (e.g., '(#648)') rather than the linked issue number. Please update this line to reference the PR ID, and optionally mention the issue in the text (e.g., 'Fixes #604') if desired.