-
Notifications
You must be signed in to change notification settings - Fork 0
Make backend Vercel-safe (no import-time writes) #29
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
Merged
gitgrahamdunn
merged 1 commit into
main
from
codex/make-backend-vercel-safe-no-import-time-writes
Feb 18, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,5 @@ | ||
| """Vercel entrypoint for FastAPI app.""" | ||
|
|
||
| from importlib import import_module | ||
| from app.main import app | ||
|
|
||
| _TRIED_IMPORTS = ( | ||
| "app.main", | ||
| "main", | ||
| "app.server", | ||
| "server", | ||
| ) | ||
|
|
||
|
|
||
| for _module_path in _TRIED_IMPORTS: | ||
| try: | ||
| app = import_module(_module_path).app | ||
| break | ||
| except (ImportError, AttributeError): | ||
| continue | ||
| else: | ||
| tried = ", ".join(f"{module}.app" for module in _TRIED_IMPORTS) | ||
| raise ImportError( | ||
| f"Could not import FastAPI app. Tried: {tried}" | ||
| ) | ||
| __all__ = ["app"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import importlib | ||
| import pathlib | ||
| import sys | ||
|
|
||
|
|
||
| def test_backend_imports_without_mkdir_calls(monkeypatch): | ||
| mkdir_calls: list[pathlib.Path] = [] | ||
| original_mkdir = pathlib.Path.mkdir | ||
|
|
||
| def tracking_mkdir(self, *args, **kwargs): | ||
| mkdir_calls.append(self) | ||
| return original_mkdir(self, *args, **kwargs) | ||
|
|
||
| monkeypatch.setattr(pathlib.Path, "mkdir", tracking_mkdir) | ||
|
|
||
| target_modules = [ | ||
| "app.config", | ||
| "app.db", | ||
| "app.routers.documents", | ||
| "app.routers.projects", | ||
| "app.routers.health", | ||
| "app.main", | ||
| ] | ||
| for module in target_modules: | ||
| sys.modules.pop(module, None) | ||
|
|
||
| importlib.import_module("app.main") | ||
|
|
||
| assert mkdir_calls == [] | ||
|
|
||
|
|
||
| def test_default_storage_dir_targets_tmp(monkeypatch): | ||
| monkeypatch.delenv("DATA_DIR", raising=False) | ||
| monkeypatch.delenv("STORAGE_DIR", raising=False) | ||
|
|
||
| import app.config as config | ||
|
|
||
| assert str(config.get_storage_dir(ensure_exists=False)).startswith("/tmp/") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
run_runtime_storage_check()marks a directory as writable usingpath.is_dir(), which only confirms existence/type and will still betruefor read-only mounts. In deployments that setDATA_DIR,STORAGE_DIR, orWORKING_STORAGE_DIRto an existing but non-writable directory,/health/storageandhealth_infocan report healthy storage even though uploads will fail later with permission errors. This should validate real write access (for example viaos.access(..., os.W_OK)or a temp-file probe) before reportingwritable: true.Useful? React with 👍 / 👎.