fix: treat Nix files as readable uploads (#2249)

This commit is contained in:
ooovenenoso
2026-06-04 06:06:24 -04:00
committed by GitHub
parent 68eeb7841c
commit e163384015
3 changed files with 27 additions and 6 deletions

View File

@@ -20,7 +20,7 @@ def _is_text_file(path: str) -> bool:
"""Check if file has text extension."""
return any(
path.lower().endswith(ext)
for ext in (".txt", ".py", ".html", ".htm", ".md", ".json", ".csv", ".log", ".js")
for ext in (".txt", ".py", ".html", ".htm", ".md", ".json", ".csv", ".log", ".js", ".nix")
)
@@ -29,7 +29,8 @@ def _process_text_file(path: str) -> str:
language_map = {
".py": "python", ".js": "javascript", ".html": "html", ".css": "css",
".json": "json", ".md": "markdown", ".txt": "text", ".csv": "csv",
".log": "log", ".sh": "bash", ".yml": "yaml", ".yaml": "yaml",
".log": "log", ".sh": "bash", ".bash": "bash", ".nix": "nix",
".yml": "yaml", ".yaml": "yaml",
".xml": "xml", ".sql": "sql", ".cpp": "cpp", ".c": "c",
".java": "java", ".go": "go", ".rs": "rust", ".php": "php",
".rb": "ruby", ".ts": "typescript", ".jsx": "javascript", ".tsx": "typescript",
@@ -91,8 +92,8 @@ def _process_text_file(path: str) -> str:
header += f"[Type: {language}, Lines: {line_count}, Size: {size_str} bytes]"
code_extensions = {
".py", ".js", ".html", ".css", ".json", ".md", ".sh", ".yml", ".yaml",
".xml", ".sql", ".cpp", ".c", ".java", ".go", ".rs", ".php", ".rb",
".py", ".js", ".html", ".css", ".json", ".md", ".sh", ".bash", ".nix",
".yml", ".yaml", ".xml", ".sql", ".cpp", ".c", ".java", ".go", ".rs", ".php", ".rb",
".ts", ".jsx", ".tsx",
}
if ext in code_extensions:

View File

@@ -176,7 +176,7 @@ class UploadHandler:
'.pdf', '.docx', '.xlsx', '.pptx', '.xls', '.epub',
'.txt', '.py', '.js', '.html', '.htm',
'.css', '.json', '.md', '.csv', '.log', '.xml', '.yml',
'.yaml', '.sql', '.sh', '.bash', '.c', '.cpp', '.h',
'.yaml', '.nix', '.sql', '.sh', '.bash', '.c', '.cpp', '.h',
'.java', '.go', '.rs', '.php', '.rb', '.ts', '.jsx', '.tsx'
}
document_mime_types = {

View File

@@ -0,0 +1,20 @@
from src.document_processor import _is_text_file, _process_text_file
from src.upload_handler import UploadHandler
def test_nix_files_are_treated_as_readable_documents(tmp_path):
handler = UploadHandler(str(tmp_path), str(tmp_path / "uploads"))
assert handler.is_document_file("configuration.nix")
assert _is_text_file("configuration.nix")
def test_nix_file_processing_includes_content_in_code_block(tmp_path):
nix_file = tmp_path / "configuration.nix"
nix_file.write_text("{ pkgs, ... }:\n{\n services.openssh.enable = true;\n}\n", encoding="utf-8")
rendered = _process_text_file(str(nix_file))
assert "[Type: nix" in rendered
assert "```nix" in rendered
assert "services.openssh.enable = true;" in rendered