inspect_project(project_path: Path, *, scope: str, no_network: bool, json_output: bool = False) -> AuditReport
Inspect only the named scope; never open shared resources or run a turn.
--no-network avoids importing the project entirely. A normal inspection
invokes adopter import, build_agent and scoped composition, whose custom
code may perform I/O; the framework cannot promise those calls are pure.
Source code in src/symfonic/diagnostics/native_cli.py
| def inspect_project(
project_path: Path,
*,
scope: str,
no_network: bool,
json_output: bool = False,
) -> AuditReport:
"""Inspect only the named scope; never open shared resources or run a turn.
``--no-network`` avoids importing the project entirely. A normal inspection
invokes adopter import, ``build_agent`` and scoped composition, whose custom
code may perform I/O; the framework cannot promise those calls are pure.
"""
if no_network:
return AuditReport(
[
_unknown(
"native.composition",
"Project import and scoped composition skipped by --no-network.",
),
*_legacy_unknowns(),
_unknown("postgres_dsn.probe", "Network probe skipped by --no-network."),
]
)
root = str(project_path.resolve())
previous_cwd = Path.cwd()
previous = {
name: module
for name, module in sys.modules.items()
if name == "app" or name.startswith("app.")
}
for name in previous:
del sys.modules[name]
previous_path = sys.path[:]
sys.path.insert(0, root)
try:
os.chdir(root)
output = redirect_stdout(io.StringIO()) if json_output else nullcontext()
errors = redirect_stderr(io.StringIO()) if json_output else nullcontext()
with output, errors:
return asyncio.run(_inspect_scoped(scope, json_output=json_output))
except (Exception, SystemExit) as exc: # noqa: BLE001 -- opaque project boundary
return AuditReport(
[
CheckResult(
"native.composition",
Severity.ERROR,
f"Project import or scoped composition failed ({type(exc).__name__}).",
"Check app.setup.agent.build_agent() and the requested --scope.",
),
]
)
finally:
os.chdir(previous_cwd)
sys.path[:] = previous_path
for name in [key for key in sys.modules if key == "app" or key.startswith("app.")]:
del sys.modules[name]
sys.modules.update(previous)
|