test: establish architecture extraction gates - #30
Conversation
|
cursor review |
PR Review — Loreframe StudioRisk: medium Automated review from Findings
Changed files
CONTRIBUTING checklist
Posted by the repo PR review workflow. Re-runs on each push to the PR. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: WGP scanner skips dynamic imports
- The WGP wall now flags importlib.import_module("wgp") and import("wgp") and names the existing first-party call in app/shared/api.py so the allowlist cannot stay green while that dependency remains or grows.
Or push these changes by commenting:
@cursor push 3b18e861f5
Preview (3b18e861f5)
diff --git a/tests/test_architecture_contracts.py b/tests/test_architecture_contracts.py
--- a/tests/test_architecture_contracts.py
+++ b/tests/test_architecture_contracts.py
@@ -25,6 +25,7 @@
("app/services/model3d_service.py", "_active_profile", "import wgp"),
("app/services/model3d_service.py", "_minimax_api_key", "import wgp"),
("app/services/model3d_service.py", "_services", "import wgp"),
+ ("app/shared/api.py", "WanGPSession._ensure_runtime", "importlib.import_module('wgp')"),
("app/shared/magic_mask.py", "_ensure_sam3_assets", "import wgp"),
("app/shared/magic_mask.py", "_video_to_numpy", "from wgp import get_resampled_video"),
}
@@ -40,6 +41,23 @@
)
+def _is_dynamic_wgp_import(node: ast.AST) -> bool:
+ if not isinstance(node, ast.Call) or not node.args:
+ return False
+ name = node.args[0]
+ if not isinstance(name, ast.Constant) or name.value != "wgp":
+ return False
+ func = node.func
+ if isinstance(func, ast.Name) and func.id in {"import_module", "__import__"}:
+ return True
+ return (
+ isinstance(func, ast.Attribute)
+ and func.attr == "import_module"
+ and isinstance(func.value, ast.Name)
+ and func.value.id == "importlib"
+ )
+
+
def _wgp_imports() -> set[tuple[str, str, str]]:
found = set()
for path in (ROOT / "app").rglob("*.py"):
@@ -54,6 +72,7 @@
for node in ast.walk(tree):
is_wgp = isinstance(node, ast.Import) and any(alias.name == "wgp" for alias in node.names)
is_wgp = is_wgp or isinstance(node, ast.ImportFrom) and node.module == "wgp"
+ is_wgp = is_wgp or _is_dynamic_wgp_import(node)
if not is_wgp:
continue
scopes = []You can send follow-ups to the cloud agent here.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 0fe366b. Configure here.
| for node in ast.walk(tree): | ||
| is_wgp = isinstance(node, ast.Import) and any(alias.name == "wgp" for alias in node.names) | ||
| is_wgp = is_wgp or isinstance(node, ast.ImportFrom) and node.module == "wgp" | ||
| if not is_wgp: |
There was a problem hiding this comment.
WGP scanner skips dynamic imports
Medium Severity
The WanGP wall only treats import wgp and from wgp import ... as imports, so the existing first-party importlib.import_module("wgp") call is never named. The allowlist can stay green while that dependency remains or while more dynamic imports are added.
Reviewed by Cursor Bugbot for commit 0fe366b. Configure here.
The first-party allowlist only scanned import/from statements, so
importlib.import_module("wgp") in WanGPSession._ensure_runtime stayed
invisible. Detect static loaders and record the existing site.
Co-authored-by: THEINAOG <IAnMove@users.noreply.github.com>



Note
Low Risk
Test and documentation only; no application or API behavior changes.
Overview
Adds static architecture contracts for the HocusPocus refactor plan: no runtime imports of
_launch_runtime, FastAPI, or WanGP.scripts/architecture_contracts.pyAST-parses launch wiring and emits two reviewed fixtures:route_table.json(method, path, ordinal, and source for every route, with mountedapp/routers/*factories expanded at eachapi.include_routersite) andarchitecture_wire_inventory.json(Python/UI tests tied to_launch_runtimeoruseStore.ts, each labeledbehavior,symbol_importable,architecture_rule, orfragile_source). The script fails if fixtures are stale;--writerefreshes them after an intentional move.tests/test_architecture_contracts.pylocks those fixtures in pytest and adds a WanGP (wgp) import allowlist over first-partyapp/code (vendor trees excluded): new imports fail; the list is meant to shrink only during the WanGP boundary work.docs/development/ARCHITECTURE_FOUNDATION.mddocuments how to run and update the gates.Reviewed by Cursor Bugbot for commit 0fe366b. Configure here.