From fe34b75b5a2eb44c7603124abb2fef3f169183ad Mon Sep 17 00:00:00 2001 From: GUOGUO Date: Tue, 17 Nov 2026 00:57:29 +0800 Subject: [PATCH 1/2] refactor(apps): move the MindIE adapter into Apps and retire four root files (M1) Move root mindie_project.py, mindie_context.py and mindie_mcp.py to apps/mindie/{project,context,mcp}.py and _mindie_read_worker.py to apps/mindie/read_worker.py. Apart from the imports that name their neighbours and the package version in mcp.py, the code is unchanged. Update the CLI, tests, the installed-wheel checker, the gate and the docs, and delete all four root files with no forwarding shell, sys.modules alias or import fallback. apps/mindie/__init__.py imports nothing. The tracked package root now holds exactly __init__.py and __main__.py. Refs #452 Agent-assisted-by: Claude Code / claude-opus-5-5 [effort=xhigh] (author) Signed-off-by: GUOGUO --- CHANGELOG.md | 34 ++++++ docs/architecture.md | 22 ++-- docs/module-layout.md | 57 +++++++--- src/inferrsi/apps/cli/__init__.py | 4 +- src/inferrsi/apps/mindie/__init__.py | 5 + .../mindie/context.py} | 2 +- .../{mindie_mcp.py => apps/mindie/mcp.py} | 6 +- .../mindie/project.py} | 6 +- .../mindie/read_worker.py} | 0 tests/_gate_policy_support.py | 12 +- tests/check_installed.py | 56 +++++++++- tests/test_campaign_record_injection.py | 12 +- tests/test_first_wave_isolation_policy.py | 17 ++- tests/test_mindie_context.py | 2 +- tests/test_mindie_project.py | 3 +- tests/test_mindie_runtime.py | 6 +- tests/test_package_root_inventory.py | 104 ++++++++++-------- tests/test_target_module_import_gate.py | 19 ++-- 18 files changed, 261 insertions(+), 106 deletions(-) create mode 100644 src/inferrsi/apps/mindie/__init__.py rename src/inferrsi/{mindie_context.py => apps/mindie/context.py} (99%) rename src/inferrsi/{mindie_mcp.py => apps/mindie/mcp.py} (97%) rename src/inferrsi/{mindie_project.py => apps/mindie/project.py} (98%) rename src/inferrsi/{_mindie_read_worker.py => apps/mindie/read_worker.py} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec44465ed..8412f0e02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,40 @@ ### Changed +- The local MindIE adapter moves into the Apps package and its four root files + are removed (Refs #452, M1), with no forwarding shell, `sys.modules` alias or + import fallback: + - `inferrsi.mindie_project` → `inferrsi.apps.mindie.project` + - `inferrsi.mindie_context` → `inferrsi.apps.mindie.context` + - `inferrsi.mindie_mcp` → `inferrsi.apps.mindie.mcp` + - `src/inferrsi/_mindie_read_worker.py` → + `src/inferrsi/apps/mindie/read_worker.py`, a standalone file that is run by + path and never imported + - The four files move with their code unchanged apart from the imports that + name their neighbours (`.context`, `.project`, `.mcp`) and the package + version, which `mcp.py` now reads with `from ... import __version__`. + `apps/mindie/__init__.py` imports nothing and does not re-export the + version. The `inferrsi mindie` and `inferrsi campaign import-mindie` + commands, the Codex configuration and the MCP server name are unchanged. + - The worker keeps its boundary: it starts with `-I -B` in a private working + directory, with a 20 second limit and a 2 MiB cap, opens SQLite read-only, + imports only the standard library at the top level and imports + `mindie_knowledge` inside `read()`. It is not standard-library-only overall. + The grant file, its explicit opt-in and the recorded read receipts are + unchanged, as is the OBS layout. + - Importing `inferrsi.mindie_project`, `inferrsi.mindie_context` or + `inferrsi.mindie_mcp` now raises `ModuleNotFoundError`, in external Python + code as well as in this repository, and a pickle that names an object by + one of these paths no longer loads. Callers import from + `inferrsi.apps.mindie`. Frozen evidence is not rewritten. + - The tracked package root shrinks from six files to the final two, + `__init__.py` and `__main__.py`. The four paths join `RETIRED_ROOT_MODULES` + in the gate, so a root file that returns under any of them fails, and the + installed-wheel checker verifies that the adapter and worker ship under + `apps/mindie/`. + - Isolation is still incomplete: the 12 Harness hits into Infra (R2, #412) + and the five runtime resource loaders (R3, #412) remain. + - The campaign chart renderer and the single-task launcher move into the Apps package and the two root modules are removed (Refs #408, A2), with no forwarding shell, `sys.modules` alias or import fallback. Both files move diff --git a/docs/architecture.md b/docs/architecture.md index 5c42ee2eb..4a14f0400 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -192,6 +192,11 @@ src/inferrsi/ apps/ evidence_layout.py Create the plan/results/patch/validator evidence directories campaign.py Knowledge values connected to Harness campaign records + mindie/ + project.py Opt-in per-checkout grant, the worker launch and the recorded read + context.py Export supplied MindIE reads into a caller-reviewed campaign trace + mcp.py Stdio MCP for the two approved local MindIE reads + read_worker.py Standalone worker run by the approved MindIE interpreter views/ summary_chart.py Stdlib SVG gain chart (chain/branch) and report figure spec optimization_chart.py Managed optimization objective/token curves and final result @@ -271,19 +276,20 @@ examples/ Current Qwen runner, image validator and v4 adapter tests/fixtures/legacy/ Frozen historical validation dependencies for regressions ``` -The package root holds exactly six tracked files at this stage: `__init__.py`, -`__main__.py`, `mindie_context.py`, `mindie_mcp.py`, `mindie_project.py` and -`_mindie_read_worker.py`. #408 A2 moved the chart renderer to +The package root holds exactly two tracked files: `__init__.py` and `__main__.py`. +#452 M1 moved the MindIE adapter to `apps/mindie/` (`project.py`, `context.py`, +`mcp.py` and the standalone `read_worker.py`) and deleted root `mindie_project.py`, +`mindie_context.py`, `mindie_mcp.py` and `_mindie_read_worker.py` with no forwarding +shell or alias. #408 A2 moved the chart renderer to `apps/views/summary_chart.py` and the task launcher to `apps/benchmark_operations.py` -and deleted root `summary_chart.py` and `benchmark_operations.py` with no forwarding -shell or alias. #408 A1 moved the CLI and its parser to `apps/cli/` -and deleted root `cli.py` and `arguments.py` the same way; +and deleted root `summary_chart.py` and `benchmark_operations.py` the same way. #408 A1 moved the CLI and its parser to `apps/cli/` +and deleted root `cli.py` and `arguments.py`; `__main__.py` and the console script call `inferrsi.apps.cli:main`. #412 R1 deleted eleven root modules with no forwarding shell or alias: the seven Knowledge shells, whose code is in `knowledge/`; the three old-run forwarders `evaluation.py`, `execution.py` and `reporting.py`, whose code is in `apps/legacy/`; and `inspection.py`, whose -host binding is `apps/inspection.py`. The final two-file root (`__init__.py` -and `__main__.py`) waits for the M1 (#452) move. +host binding is `apps/inspection.py`. The build-generated `_version.py` is ignored +wheel metadata, not a tracked root file. [module-layout.md](module-layout.md#retired-root-modules) maps each retired path to its replacement and lists what still keeps the isolation gate false. diff --git a/docs/module-layout.md b/docs/module-layout.md index 28ddfcbf2..b658cc039 100644 --- a/docs/module-layout.md +++ b/docs/module-layout.md @@ -41,22 +41,22 @@ nothing. Neither package is a fourth core. C2 (#451) moved these out of root `_repo_pack_data.py` and `evidence_paths.py` and deleted both root files, with no forwarding shell or alias. -The flat package root is retired in stages. -`tests/test_package_root_inventory.py` pins the root to an exact file set: 23 -tracked files after C1, 21 after C2, 10 after R1 (#412), 8 after A1 (#408) and 6 -after A2 (#408). The six are `__init__.py`, `__main__.py`, -`_mindie_read_worker.py`, `mindie_context.py`, `mindie_mcp.py` and -`mindie_project.py`. A2 moved root `summary_chart.py` to +The flat package root is retired. `tests/test_package_root_inventory.py` pins the +root to an exact file set: 23 tracked files after C1, 21 after C2, 10 after R1 +(#412), 8 after A1 (#408), 6 after A2 (#408) and the final two after M1 (#452). +The two are `__init__.py` and `__main__.py`. M1 moved root `mindie_project.py`, +`mindie_context.py`, `mindie_mcp.py` and `_mindie_read_worker.py` to +`apps/mindie/project.py`, `context.py`, `mcp.py` and `read_worker.py` and deleted +the four root files with no forwarding shell or alias. A2 moved root +`summary_chart.py` to `apps/views/summary_chart.py` and root `benchmark_operations.py` to -`apps/benchmark_operations.py` and deleted both root files with no forwarding -shell or alias. A1 moved root `cli.py` and +`apps/benchmark_operations.py` and deleted both root files the same way. A1 moved root `cli.py` and `arguments.py` to `apps/cli/__init__.py` and `apps/cli/arguments.py` and -deleted both root files the same way. The last removal PR shrinks the set in -the same change: M1 (#452) moves the four MindIE files. The guard does -not assert the final two-file root (`__init__.py` and `__main__.py`) early, -and the build-generated `_version.py` is ignored wheel metadata, not a tracked -root file. [Retired root modules](#retired-root-modules) lists the eleven -paths that R1 removed, the two that A1 removed and the two that A2 removed. +deleted both root files. A new root file now fails the guard, so a later module +belongs in a subpackage. The build-generated `_version.py` is ignored wheel +metadata, not a tracked root file. [Retired root modules](#retired-root-modules) +lists the eleven paths that R1 removed, the two that A1 removed, the two that A2 +removed and the four that M1 removed. The current `src/inferrsi/harness/` tree is a mixed implementation. Its presence is not the target Harness boundary and is not evidence that the four @@ -120,6 +120,7 @@ Several flat modules remain shared seams until their slice starts. | `knowledge/knowledge_operations.py`, `knowledge/knowledge_store.py`, `knowledge/catalog.py`, `knowledge/research.py`, `knowledge/skill_catalog.py`, `knowledge/_skill_selection.py`, `knowledge/_source_snapshot.py` | The seven Knowledge implementations, moved by K01 | Interfaces unchanged; the same-named root shells were deleted by R1 | | `harness/records/` | Campaign manifests, traces, logs, profile captures and delivered-context captures | Imports no Knowledge or Apps module; `apps/campaign.py` supplies the backend names, the selection default and the context projection | | `apps/views/`, `apps/campaign.py` | Dashboard views, templates and the Knowledge-to-records connection | Apps path still follows the #371 proposal | +| `apps/mindie/` (`project.py`, `context.py`, `mcp.py`, `read_worker.py`) | The local MindIE adapter: project grant, stdio MCP, context export and the read worker | M1 (#452) moved the four root MindIE files here; no Harness, Knowledge or Infra module names MindIE, and the initializer imports nothing | | `harness/` | Mixed legacy tree, not target isolation | Not redefined | | `harness/runner.py`, `harness/scenarios/external.py`, `harness/atomic_json.py` | Old run execution facts and Harness-owned JSON writes | Ports injected; no Model edge, and no Infra edge except the local process executor | | `benchmark/legacy_run_v0.py`, `benchmark/sampling.py` | Old run gates and metric validation; image/video sample collection | Imports only `model/protocols/metrics`; owns its rule inputs and verdict labels | @@ -492,10 +493,6 @@ The `inferrsi` console script and `python -m inferrsi` call unchanged. A test replaces a CLI name such as `_knowledge_reader` or `files` on `inferrsi.apps.cli`. -The root now holds the six files listed under -[Target modules](#target-modules). The final two-file root waits for the -M1 (#452) move. - A2 (#408) deleted two more root modules the same way: | Retired root module | Canonical module | @@ -508,6 +505,30 @@ A2 (#408) deleted two more root modules the same way: the SVG and Markdown bytes it writes are unchanged. The dashboard, the HTML report and the CLI `benchmarks run` command import the canonical modules. +M1 (#452) deleted the four root MindIE files the same way: + +| Retired root module | Canonical module or file | +| --- | --- | +| `inferrsi.mindie_project` | `inferrsi.apps.mindie.project` | +| `inferrsi.mindie_context` | `inferrsi.apps.mindie.context` | +| `inferrsi.mindie_mcp` | `inferrsi.apps.mindie.mcp` | +| `inferrsi._mindie_read_worker` | `src/inferrsi/apps/mindie/read_worker.py`, a file run by path and not imported | + +The four files moved with their code unchanged except the imports that name +their neighbours and the package version. `apps/mindie/__init__.py` imports +nothing and does not re-export `__version__`; `mcp.py` reads it with +`from ... import __version__`. The worker is still started as +`python -I -B read_worker.py` with a private working directory, a 20 second limit +and a 2 MiB cap, opens SQLite read-only, imports only the standard library at +the top level and takes `mindie_knowledge` inside `read()`. It is not described +as standard-library-only overall. The grant file, its explicit opt-in, the +recorded read receipts and the OBS layout are unchanged. The `inferrsi mindie` +and `inferrsi campaign import-mindie` commands, the Codex configuration in +[codex-plugin.md](codex-plugin.md) and the MCP server name are unchanged. + +The root now holds exactly the two files `__init__.py` and `__main__.py`. The +build-generated `_version.py` is separate wheel metadata. + ## Old `run` exit codes Frozen from diff --git a/src/inferrsi/apps/cli/__init__.py b/src/inferrsi/apps/cli/__init__.py index f909faf95..613dba41e 100644 --- a/src/inferrsi/apps/cli/__init__.py +++ b/src/inferrsi/apps/cli/__init__.py @@ -157,7 +157,7 @@ def main(argv: list[str] | None = None) -> int: args = argument_parser.parse_args(argv) try: if args.command == "mindie": - from ...mindie_project import dispatch + from ..mindie.project import dispatch result = dispatch(args) if result is not None: @@ -408,7 +408,7 @@ def main(argv: list[str] | None = None) -> int: if args.command == "campaign": if args.campaign_action == "import-mindie": - from ...mindie_context import export_context + from ..mindie.context import export_context path = export_context( args.directory, context_id=args.id, query_input=args.query_input, diff --git a/src/inferrsi/apps/mindie/__init__.py b/src/inferrsi/apps/mindie/__init__.py new file mode 100644 index 000000000..d4511e2ae --- /dev/null +++ b/src/inferrsi/apps/mindie/__init__.py @@ -0,0 +1,5 @@ +"""The local MindIE adapter: project grant, stdio MCP, context export and the read worker. + +This initializer imports nothing. The worker file runs under the approved MindIE +interpreter and must stay loadable without this package. +""" diff --git a/src/inferrsi/mindie_context.py b/src/inferrsi/apps/mindie/context.py similarity index 99% rename from src/inferrsi/mindie_context.py rename to src/inferrsi/apps/mindie/context.py index bedc25c46..7f5377f5c 100644 --- a/src/inferrsi/mindie_context.py +++ b/src/inferrsi/apps/mindie/context.py @@ -2,7 +2,7 @@ This CLI host adapter never activates MindIE, reads a session or calls a model. Retained responses establish supplied bytes, not their authenticity or consumption. -It stays with the current flat CLI; it does not instantiate the proposed Apps package. +It lives in the Apps package with the rest of the MindIE adapter. """ from __future__ import annotations diff --git a/src/inferrsi/mindie_mcp.py b/src/inferrsi/apps/mindie/mcp.py similarity index 97% rename from src/inferrsi/mindie_mcp.py rename to src/inferrsi/apps/mindie/mcp.py index 8493e9cab..681a3055a 100644 --- a/src/inferrsi/mindie_mcp.py +++ b/src/inferrsi/apps/mindie/mcp.py @@ -4,9 +4,9 @@ import re import sys -from . import __version__ -from .mindie_context import MAX_BYTES, _invalid_constant, _object -from .mindie_project import call, describe +from ... import __version__ +from .context import MAX_BYTES, _invalid_constant, _object +from .project import call, describe _PROTOCOL = "2025-11-25" _SUPPORTED = {"2024-11-05", "2025-03-26", "2025-06-18", _PROTOCOL} diff --git a/src/inferrsi/mindie_project.py b/src/inferrsi/apps/mindie/project.py similarity index 98% rename from src/inferrsi/mindie_project.py rename to src/inferrsi/apps/mindie/project.py index 092120d14..8a7fb091a 100644 --- a/src/inferrsi/mindie_project.py +++ b/src/inferrsi/apps/mindie/project.py @@ -10,11 +10,11 @@ import tempfile from pathlib import Path -from .mindie_context import MAX_BYTES, _parse +from .context import MAX_BYTES, _parse _SCHEMA = "inferrsi-mindie-project/1" _DOMAIN = re.compile(r"[a-z][a-z0-9-]{0,63}") -_WORKER = Path(__file__).with_name("_mindie_read_worker.py") +_WORKER = Path(__file__).with_name("read_worker.py") _REF_ID = r"[A-Za-z0-9_.-]+@[1-9][0-9]*" _SEARCH_FIELDS = {"query", "conditions", "limit", "token_budget", "include_unknown"} _EXPLAIN_FIELDS = {"refs", "conditions", "known_refs", "token_budget"} @@ -241,7 +241,7 @@ def dispatch(args) -> dict | None: if args.mindie_action == "describe": return describe() if args.mindie_action == "serve": - from .mindie_mcp import serve + from .mcp import serve serve() return None diff --git a/src/inferrsi/_mindie_read_worker.py b/src/inferrsi/apps/mindie/read_worker.py similarity index 100% rename from src/inferrsi/_mindie_read_worker.py rename to src/inferrsi/apps/mindie/read_worker.py diff --git a/tests/_gate_policy_support.py b/tests/_gate_policy_support.py index 884547e2b..1eb2f021d 100644 --- a/tests/_gate_policy_support.py +++ b/tests/_gate_policy_support.py @@ -70,7 +70,17 @@ # implementations are ``inferrsi.apps.views.summary_chart`` and # ``inferrsi.apps.benchmark_operations``. RETIRED_BY_A2 = frozenset({"inferrsi.summary_chart", "inferrsi.benchmark_operations"}) -RETIRED_ROOT_MODULES = RETIRED_BY_R1 | RETIRED_BY_A1 | RETIRED_BY_A2 +# #452 M1 deleted the four root MindIE files the same way. The adapter is the +# ``inferrsi.apps.mindie`` package: ``project``, ``context``, ``mcp`` and ``read_worker``. +RETIRED_BY_M1 = frozenset( + { + "inferrsi.mindie_project", + "inferrsi.mindie_context", + "inferrsi.mindie_mcp", + "inferrsi._mindie_read_worker", + } +) +RETIRED_ROOT_MODULES = RETIRED_BY_R1 | RETIRED_BY_A1 | RETIRED_BY_A2 | RETIRED_BY_M1 # #412 R1, permanent: the one importer of the neutral data leaf outside # ``inferrsi.knowledge``, with the only name it may bind (D020: Infra reads one pack # description and reaches no Knowledge or Harness). This is not a manifest diff --git a/tests/check_installed.py b/tests/check_installed.py index 2329898fe..6d11f1a19 100644 --- a/tests/check_installed.py +++ b/tests/check_installed.py @@ -647,13 +647,12 @@ def _inventory(root, prefix): else: raise AssertionError(f"retired module inferrsi.{retired} must not import") assert not installed_root & {f"{name}.py" for name in r1_retired} -assert installed_root - {"_version.py"} == { - "__init__.py", "__main__.py", "_mindie_read_worker.py", - "mindie_context.py", "mindie_mcp.py", "mindie_project.py", -}, sorted(installed_root) +assert installed_root - {"_version.py"} == {"__init__.py", "__main__.py"}, sorted(installed_root) # #408 A1: the CLI and its parser ship only as inferrsi.apps.cli; neither root name imports. # #408 A2: the chart renderer and the task launcher ship only under inferrsi.apps. -for a1_retired in ("cli", "arguments", "summary_chart", "benchmark_operations"): +# #452 M1: the MindIE adapter ships only as inferrsi.apps.mindie. +for a1_retired in ("cli", "arguments", "summary_chart", "benchmark_operations", + "mindie_project", "mindie_context", "mindie_mcp", "_mindie_read_worker"): assert find_spec(f"inferrsi.{a1_retired}") is None, a1_retired assert f"inferrsi.{a1_retired}" not in sys.modules, a1_retired try: @@ -663,7 +662,9 @@ def _inventory(root, prefix): else: raise AssertionError(f"retired module inferrsi.{a1_retired} must not import") assert main.__module__ == "inferrsi.apps.cli" -for canonical in ("inferrsi.apps.views.summary_chart", "inferrsi.apps.benchmark_operations"): +for canonical in ("inferrsi.apps.views.summary_chart", "inferrsi.apps.benchmark_operations", + "inferrsi.apps.mindie.project", "inferrsi.apps.mindie.context", + "inferrsi.apps.mindie.mcp", "inferrsi.apps.mindie.read_worker"): assert find_spec(canonical) is not None, canonical assert import_module("inferrsi.apps.views.summary_chart").main.__module__ == ( "inferrsi.apps.views.summary_chart" @@ -689,3 +690,46 @@ def _inventory(root, prefix): [sys.executable, "-I", "-c", facade_probe], capture_output=True, text=True, check=False, ) assert facade.returncode == 0, facade.stderr +# #452 M1: the MindIE adapter ships in the wheel. A fresh isolated interpreter imports the +# package initializer with no core loaded and without a re-exported version, then imports +# the stdio MCP module through its absolute package path. +mindie_probe = ( + "import sys\n" + "import inferrsi.apps.mindie as adapter\n" + "loaded = {name for name in sys.modules if name.split('.')[0] == 'inferrsi'}\n" + "allowed = {'inferrsi', 'inferrsi._version', 'inferrsi.apps', 'inferrsi.apps.mindie'}\n" + "assert loaded <= allowed, sorted(loaded - allowed)\n" + "assert not hasattr(adapter, '__version__')\n" + "from inferrsi.apps.mindie import mcp\n" + "import inferrsi\n" + "reply = mcp._reply('initialize', {'protocolVersion': '2025-11-25'})\n" + "assert reply['serverInfo']['version'] == inferrsi.__version__, reply\n" + "assert mcp.__file__.startswith(adapter.__path__[0]), mcp.__file__\n" +) +mindie = subprocess.run( + [sys.executable, "-I", "-B", "-c", mindie_probe], capture_output=True, text=True, check=False, +) +assert mindie.returncode == 0, mindie.stderr +# The worker ships as a plain file beside the adapter. It is started by file path under +# ``-I -B`` with no package context, so it must load without a package-relative import. +worker_file = files("inferrsi").joinpath("apps", "mindie", "read_worker.py") +assert worker_file.is_file() +with as_file(worker_file) as worker_path: + worker_probe = ( + "import ast, runpy, sys\n" + f"path = {str(worker_path)!r}\n" + "tree = ast.parse(open(path, encoding='utf-8').read())\n" + "top = [node for node in tree.body if isinstance(node, (ast.Import, ast.ImportFrom))]\n" + "assert all(not (isinstance(node, ast.ImportFrom) and node.level) for node in top)\n" + "assert all((node.module if isinstance(node, ast.ImportFrom) else node.names[0].name)\n" + " .split('.')[0] in sys.stdlib_module_names for node in top)\n" + "namespace = runpy.run_path(path, run_name='not_main')\n" + "assert callable(namespace['read'])\n" + "assert not [name for name in sys.modules if name.split('.')[0] in\n" + " ('inferrsi', 'mindie_knowledge')]\n" + ) + worker = subprocess.run( + [sys.executable, "-I", "-B", "-c", worker_probe], capture_output=True, text=True, + check=False, + ) +assert worker.returncode == 0, worker.stderr diff --git a/tests/test_campaign_record_injection.py b/tests/test_campaign_record_injection.py index d6de80323..eca883bd9 100644 --- a/tests/test_campaign_record_injection.py +++ b/tests/test_campaign_record_injection.py @@ -18,6 +18,7 @@ REPO, RETIRED_BY_A1, RETIRED_BY_A2, + RETIRED_BY_M1, RETIRED_BY_R1, RETIRED_ROOT_MODULES, ROOT, @@ -367,18 +368,21 @@ def _record_modules(): def test_harness_records_load_no_knowledge_or_apps_module(): # #412 R1 retired eleven root modules, #408 A1 retired the root CLI and its parser, - # and #408 A2 retired the root chart renderer and task launcher. None of those fifteen - # names may be loaded either. + # #408 A2 retired the root chart renderer and task launcher, and #452 M1 retired the four + # root MindIE files. None of those nineteen names may be loaded either. assert len(RETIRED_BY_R1) == 11 assert RETIRED_BY_A1 == {"inferrsi.cli", "inferrsi.arguments"} assert RETIRED_BY_A2 == {"inferrsi.summary_chart", "inferrsi.benchmark_operations"} + assert len(RETIRED_BY_M1) == 4 assert not RETIRED_BY_R1 & RETIRED_BY_A1 assert not (RETIRED_BY_R1 | RETIRED_BY_A1) & RETIRED_BY_A2 - assert RETIRED_ROOT_MODULES == RETIRED_BY_R1 | RETIRED_BY_A1 | RETIRED_BY_A2 + assert not (RETIRED_BY_R1 | RETIRED_BY_A1 | RETIRED_BY_A2) & RETIRED_BY_M1 + assert RETIRED_ROOT_MODULES == RETIRED_BY_R1 | RETIRED_BY_A1 | RETIRED_BY_A2 | RETIRED_BY_M1 leaves = sorted(RETIRED_ROOT_MODULES) - assert len(leaves) == 15 + assert len(leaves) == 19 assert {"inferrsi.cli", "inferrsi.arguments"} <= set(leaves) assert RETIRED_BY_A2 <= set(leaves) + assert RETIRED_BY_M1 <= set(leaves) script = ( "import importlib, sys\n" f"for name in {_record_modules()!r}:\n" diff --git a/tests/test_first_wave_isolation_policy.py b/tests/test_first_wave_isolation_policy.py index 6d3854e3f..c6f01c271 100644 --- a/tests/test_first_wave_isolation_policy.py +++ b/tests/test_first_wave_isolation_policy.py @@ -421,7 +421,8 @@ def test_another_importer_fails(self) -> None: "benchmark/probe.py", "apps/main.py", "apps/inspection.py", "model/probe.py", "cli.py", "arguments.py", "apps/cli/__init__.py", "apps/cli/arguments.py", "benchmark_operations.py", "apps/benchmark_operations.py", "summary_chart.py", - "apps/views/summary_chart.py", "helper.py", "catalog.py", + "apps/views/summary_chart.py", "mindie_project.py", "apps/mindie/project.py", + "_mindie_read_worker.py", "apps/mindie/read_worker.py", "helper.py", "catalog.py", "_repo_pack_data.py", ) for path in paths: @@ -485,18 +486,26 @@ def test_hidden_routes_around_the_rule_fail(self) -> None: class RetiredRootModuleTest(unittest.TestCase): - """#412 R1 and #408 A1, A2: the fifteen deleted root modules cannot return, as any file.""" + """#412 R1 and #408 A1, A2 and #452 M1: the nineteen deleted root modules cannot return.""" def test_the_retired_set_is_the_exact_eleven_and_absent_from_the_tree(self) -> None: self.assertEqual(support.RETIRED_BY_A1, {"inferrsi.cli", "inferrsi.arguments"}) self.assertEqual( support.RETIRED_BY_A2, {"inferrsi.summary_chart", "inferrsi.benchmark_operations"} ) + self.assertEqual( + support.RETIRED_BY_M1, + { + "inferrsi.mindie_project", "inferrsi.mindie_context", "inferrsi.mindie_mcp", + "inferrsi._mindie_read_worker", + }, + ) self.assertEqual( support.RETIRED_ROOT_MODULES, - support.RETIRED_BY_R1 | support.RETIRED_BY_A1 | support.RETIRED_BY_A2, + support.RETIRED_BY_R1 | support.RETIRED_BY_A1 | support.RETIRED_BY_A2 + | support.RETIRED_BY_M1, ) - self.assertEqual(len(support.RETIRED_ROOT_MODULES), 15) + self.assertEqual(len(support.RETIRED_ROOT_MODULES), 19) self.assertEqual( support.RETIRED_BY_R1, { diff --git a/tests/test_mindie_context.py b/tests/test_mindie_context.py index 9477026be..5b8d67bd8 100644 --- a/tests/test_mindie_context.py +++ b/tests/test_mindie_context.py @@ -9,9 +9,9 @@ import pytest from inferrsi.apps.cli import main +from inferrsi.apps.mindie.context import export_context from inferrsi.apps.views.dashboard_data import load_dashboard from inferrsi.harness.records.campaign_records import create_campaign -from inferrsi.mindie_context import export_context REF = "mindie://vllm-ascend/units/unit-precision@2" PREMISE = "mindie://vllm-ascend/units/unit-fp32@1" diff --git a/tests/test_mindie_project.py b/tests/test_mindie_project.py index 8c9f3895f..05d3b99e2 100644 --- a/tests/test_mindie_project.py +++ b/tests/test_mindie_project.py @@ -2,8 +2,9 @@ import json from pathlib import Path -from inferrsi import mindie_mcp, mindie_project from inferrsi.apps.cli import main +from inferrsi.apps.mindie import mcp as mindie_mcp +from inferrsi.apps.mindie import project as mindie_project def test_project_enable_discover_read_and_revoke(tmp_path, monkeypatch, capsys): diff --git a/tests/test_mindie_runtime.py b/tests/test_mindie_runtime.py index b95a86e0b..1e8560766 100644 --- a/tests/test_mindie_runtime.py +++ b/tests/test_mindie_runtime.py @@ -11,8 +11,8 @@ import pytest -from inferrsi import mindie_project -from inferrsi.mindie_context import MAX_BYTES +from inferrsi.apps.mindie import project as mindie_project +from inferrsi.apps.mindie.context import MAX_BYTES @pytest.fixture @@ -236,7 +236,7 @@ def test_mcp_stdio_round_trip(reader, tmp_path, monkeypatch, oversized_line): wire += "\n" if oversized_line != "eof": wire += '{"jsonrpc":"2.0","id":7,"method":"ping"}\n' - source = str(Path(mindie_project.__file__).resolve().parents[1]) + source = str(Path(mindie_project.__file__).resolve().parents[3]) process = subprocess.run( [sys.executable, "-I", "-B", "-c", f"import sys; sys.path.insert(0, {source!r}); " "from inferrsi.apps.cli import main; raise SystemExit(main(['mindie', 'serve']))"], diff --git a/tests/test_package_root_inventory.py b/tests/test_package_root_inventory.py index 810451d34..8f8002056 100644 --- a/tests/test_package_root_inventory.py +++ b/tests/test_package_root_inventory.py @@ -1,14 +1,13 @@ """Exact inventory of the files directly under ``src/inferrsi/``. -Set by #451 C1, C2, #412 R1 and #408 A1, A2. The flat package root is being retired. -This guard pins the root to the exact file -set left after A2 and rejects any other root file. The last removal PR (M1) -shrinks ``ROOT_FILES`` in the same change, until only ``__init__.py`` and -``__main__.py`` remain. It does not assert that final state early. +Set by #451 C1, C2, #412 R1 and #408 A1, A2 and #452 M1. The flat package root is +retired. This guard pins the root to the exact two files that remain, ``__init__.py`` +and ``__main__.py``, and rejects any other root file. """ from __future__ import annotations +import ast import subprocess from pathlib import Path @@ -17,9 +16,11 @@ REPO = Path(__file__).resolve().parents[1] PACKAGE = "src/inferrsi" # The 27 tracked root files before C1, minus the four that C1 moved into contracts/, -# the two that C2 moved into resources/, contracts/ and apps/, and the eleven that R1 +# the two that C2 moved into resources/, contracts/ and apps/, the eleven that R1 # retired: seven Knowledge shells, three old-run forwarders and the root inspection -# binding, whose implementations are in knowledge/ and apps/. +# binding, whose implementations are in knowledge/ and apps/, the two that A1 moved +# into apps/cli/, the two that A2 moved into apps/ and the four that M1 moved into +# apps/mindie/. RETIRED_BY_C1 = frozenset({"_json_v1.py", "claim.py", "contracts.py", "runspec.py"}) RETIRED_BY_C2 = frozenset({"_repo_pack_data.py", "evidence_paths.py"}) RETIRED_BY_R1 = frozenset( @@ -42,17 +43,14 @@ # A2 (#408) moved the chart renderer to apps/views/ and the task launcher to apps/, and # deleted both root files. RETIRED_BY_A2 = frozenset({"benchmark_operations.py", "summary_chart.py"}) -RETIRED = RETIRED_BY_C1 | RETIRED_BY_C2 | RETIRED_BY_R1 | RETIRED_BY_A1 | RETIRED_BY_A2 -ROOT_FILES = frozenset( - { - "__init__.py", - "__main__.py", - "_mindie_read_worker.py", - "mindie_context.py", - "mindie_mcp.py", - "mindie_project.py", - } +# M1 (#452) moved the MindIE adapter to apps/mindie/ and deleted the four root files. +RETIRED_BY_M1 = frozenset( + {"_mindie_read_worker.py", "mindie_context.py", "mindie_mcp.py", "mindie_project.py"} ) +RETIRED = ( + RETIRED_BY_C1 | RETIRED_BY_C2 | RETIRED_BY_R1 | RETIRED_BY_A1 | RETIRED_BY_A2 | RETIRED_BY_M1 +) +ROOT_FILES = frozenset({"__init__.py", "__main__.py"}) # setuptools-scm writes this file at build time. It is gitignored wheel metadata and is # never a tracked root file. GENERATED = "_version.py" @@ -90,26 +88,36 @@ def root_files(repo: Path) -> set[str]: return present - _listed(repo, "--deleted") -def test_inventory_is_the_exact_post_a2_set() -> None: - assert len(ROOT_FILES) == 6 +def test_inventory_is_the_exact_final_two_file_root() -> None: + assert len(ROOT_FILES) == 2 assert len(RETIRED_BY_C1) == 4 and len(RETIRED_BY_C2) == 2 and len(RETIRED_BY_R1) == 11 assert RETIRED_BY_A1 == {"arguments.py", "cli.py"} assert RETIRED_BY_A2 == {"benchmark_operations.py", "summary_chart.py"} + assert RETIRED_BY_M1 == { + "_mindie_read_worker.py", "mindie_context.py", "mindie_mcp.py", "mindie_project.py", + } assert not ROOT_FILES & RETIRED - assert len(RETIRED) == 21 - # 27 before C1, 23 after C1, 21 after C2, 10 after R1, 8 after A1, 6 after A2. + assert len(RETIRED) == 25 + # 27 before C1, 23 after C1, 21 after C2, 10 after R1, 8 after A1, 6 after A2, 2 after M1. assert len(ROOT_FILES | RETIRED) == 27 - assert len(ROOT_FILES | RETIRED_BY_C2 | RETIRED_BY_R1 | RETIRED_BY_A1 | RETIRED_BY_A2) == 23 - assert len(ROOT_FILES | RETIRED_BY_R1 | RETIRED_BY_A1 | RETIRED_BY_A2) == 21 - assert len(ROOT_FILES | RETIRED_BY_A1 | RETIRED_BY_A2) == 10 - assert len(ROOT_FILES | RETIRED_BY_A2) == 8 + assert len( + ROOT_FILES | RETIRED_BY_C2 | RETIRED_BY_R1 | RETIRED_BY_A1 | RETIRED_BY_A2 | RETIRED_BY_M1 + ) == 23 + assert len(ROOT_FILES | RETIRED_BY_R1 | RETIRED_BY_A1 | RETIRED_BY_A2 | RETIRED_BY_M1) == 21 + assert len(ROOT_FILES | RETIRED_BY_A1 | RETIRED_BY_A2 | RETIRED_BY_M1) == 10 + assert len(ROOT_FILES | RETIRED_BY_A2 | RETIRED_BY_M1) == 8 + assert len(ROOT_FILES | RETIRED_BY_M1) == 6 assert GENERATED not in ROOT_FILES - assert {"__init__.py", "__main__.py"} <= ROOT_FILES - # The final two-file root waits for the M1 move; it is not asserted here. - # These four are its move targets and stay until then. - assert ROOT_FILES - {"__init__.py", "__main__.py"} == { - "_mindie_read_worker.py", "mindie_context.py", "mindie_mcp.py", "mindie_project.py", - } + assert ROOT_FILES == {"__init__.py", "__main__.py"} + # M1 moved its four files; the implementation is the apps/mindie package. + for name in ("project.py", "context.py", "mcp.py", "read_worker.py"): + assert (REPO / PACKAGE / "apps" / "mindie" / name).is_file(), name + # The package initializer stays import-free, so importing it loads no core and + # does not re-export the package version. + initializer = ast.parse((REPO / PACKAGE / "apps" / "mindie" / "__init__.py").read_text( + encoding="utf-8")) + assert not [node for node in ast.walk(initializer) + if isinstance(node, (ast.Import, ast.ImportFrom))] # A2 moved its two files into Apps. assert (REPO / PACKAGE / "apps" / "benchmark_operations.py").is_file() assert (REPO / PACKAGE / "apps" / "views" / "summary_chart.py").is_file() @@ -159,21 +167,29 @@ def test_an_added_root_file_is_rejected(name: str) -> None: def test_a_removed_root_file_must_shrink_the_inventory() -> None: - worker = "_mindie_read_worker.py" - assert inventory_errors(set(ROOT_FILES) - {worker}) == [ - f"missing root file {PACKAGE}/{worker}: shrink ROOT_FILES in the PR that removes it" + # M1 itself: the 6-file set it started from no longer matches the 2-file root, and + # keeping any of the four old files beside the apps/mindie package is rejected. + after_a2 = ROOT_FILES | RETIRED_BY_M1 + assert inventory_errors(set(ROOT_FILES), after_a2) == [ + f"missing root file {PACKAGE}/{name}: shrink ROOT_FILES in the PR that removes it" + for name in sorted(RETIRED_BY_M1) + ] + assert inventory_errors(set(after_a2)) == [ + f"unexpected root file {PACKAGE}/{name}: a new module belongs in a subpackage" + for name in sorted(RETIRED_BY_M1) ] - # A later removal PR passes once it shrinks the expected set with the files. - smaller = ROOT_FILES - {worker, "mindie_context.py", "mindie_mcp.py", "mindie_project.py"} - assert inventory_errors(set(smaller), smaller) == [] - # A2 itself: the 8-file set it started from no longer matches the 6-file root, and - # keeping either old file beside its moved module is rejected. - after_a1 = ROOT_FILES | RETIRED_BY_A2 - assert inventory_errors(set(ROOT_FILES), after_a1) == [ + for name in sorted(RETIRED_BY_M1): + assert inventory_errors(set(ROOT_FILES) | {name}) == [ + f"unexpected root file {PACKAGE}/{name}: a new module belongs in a subpackage" + ] + # A2 itself: the 8-file set it started from no longer matched its 6-file root, and + # keeping either old file beside its moved module was rejected. + after_a1 = after_a2 | RETIRED_BY_A2 + assert inventory_errors(set(after_a2), after_a1) == [ f"missing root file {PACKAGE}/{name}: shrink ROOT_FILES in the PR that removes it" for name in sorted(RETIRED_BY_A2) ] - assert inventory_errors(set(after_a1)) == [ + assert inventory_errors(set(after_a1), after_a2) == [ f"unexpected root file {PACKAGE}/{name}: a new module belongs in a subpackage" for name in sorted(RETIRED_BY_A2) ] @@ -255,7 +271,7 @@ def unexpected(name: str) -> str: (root / "runspec.py").write_text("", encoding="utf-8") assert inventory_errors(root_files(tmp_path)) == [unexpected("runspec.py")] (root / "runspec.py").unlink() - (root / "mindie_mcp.py").unlink() + (root / "__main__.py").unlink() assert inventory_errors(root_files(tmp_path)) == [ - f"missing root file {PACKAGE}/mindie_mcp.py: shrink ROOT_FILES in the PR that removes it" + f"missing root file {PACKAGE}/__main__.py: shrink ROOT_FILES in the PR that removes it" ] diff --git a/tests/test_target_module_import_gate.py b/tests/test_target_module_import_gate.py index bafcdff94..b76aace20 100644 --- a/tests/test_target_module_import_gate.py +++ b/tests/test_target_module_import_gate.py @@ -74,14 +74,18 @@ def test_no_new_cross_core_imports(self) -> None: self.assertEqual(allowed, frozenset()) self.assertEqual(cross_core_violations(allowed=allowed), []) self.assertFalse(hasattr(support, "LEGACY_RUN_FORWARDERS")) - # #408 A1 and A2: the CLI, its parser and the task launcher are under apps/, Apps by - # first path segment. With the last move the exact flat-entry listing is gone, so no - # root file is read as Apps and none of the old root files exists. + # #408 A1 and A2 and #452 M1: the CLI, its parser, the task launcher and the MindIE + # adapter are under apps/, Apps by first path segment. With the A2 move the exact + # flat-entry listing is gone, so no root file is read as Apps and none of the old + # root files exists. self.assertFalse(hasattr(support, "APPLICATION_ENTRIES")) - for retired in ("cli.py", "arguments.py", "benchmark_operations.py", "summary_chart.py"): + for retired in ("cli.py", "arguments.py", "benchmark_operations.py", "summary_chart.py", + "mindie_project.py", "mindie_context.py", "mindie_mcp.py", + "_mindie_read_worker.py"): self.assertFalse((ROOT / retired).exists(), retired) for moved in ("cli/__init__.py", "cli/arguments.py", "benchmark_operations.py", - "views/summary_chart.py"): + "views/summary_chart.py", "mindie/project.py", "mindie/context.py", + "mindie/mcp.py", "mindie/read_worker.py"): self.assertTrue((ROOT / "apps" / moved).is_file(), moved) def test_first_wave_policy_holds_on_current_tree(self) -> None: @@ -101,13 +105,14 @@ def test_clean_scan_is_not_isolation(self) -> None: "_repo_pack_data.py", "evidence_paths.py"): self.assertFalse((ROOT / retired).exists(), retired) # #412 R1: the eleven retired root modules are gone, with no package in their place. - # #408 A1 and A2 each retired two more. + # #408 A1 and A2 each retired two more, and #452 M1 retired four. self.assertEqual(len(support.RETIRED_BY_R1), 11) self.assertEqual(support.RETIRED_BY_A1, {"inferrsi.cli", "inferrsi.arguments"}) self.assertEqual( support.RETIRED_BY_A2, {"inferrsi.summary_chart", "inferrsi.benchmark_operations"} ) - self.assertEqual(len(support.RETIRED_ROOT_MODULES), 15) + self.assertEqual(len(support.RETIRED_BY_M1), 4) + self.assertEqual(len(support.RETIRED_ROOT_MODULES), 19) for module in support.RETIRED_ROOT_MODULES: name = module.removeprefix("inferrsi.") self.assertFalse((ROOT / f"{name}.py").exists(), name) From 5d2e9508ab1a7823f9c236e257bd897596f3f8cf Mon Sep 17 00:00:00 2001 From: GUOGUO Date: Tue, 17 Nov 2026 13:08:08 +0800 Subject: [PATCH 2/2] test(installed): launch the installed MindIE worker through the adapter (M1) The installed-wheel checker now also calls the installed adapter's _worker() from a temporary cwd with a synthetic grant whose engine file does not exist. That uses the real _WORKER lookup and the python -I -B entry point, and asserts the worker's fixed structured rejection, without a live MindIE dependency. Refs #452 Agent-assisted-by: Claude Code / claude-opus-5-5 [effort=xhigh] (author) Signed-off-by: GUOGUO --- CHANGELOG.md | 3 ++- tests/check_installed.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8412f0e02..906a29413 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,7 +34,8 @@ `__init__.py` and `__main__.py`. The four paths join `RETIRED_ROOT_MODULES` in the gate, so a root file that returns under any of them fails, and the installed-wheel checker verifies that the adapter and worker ship under - `apps/mindie/`. + `apps/mindie/` and that the installed adapter starts the installed worker by + file path and gets its structured rejection for an unavailable catalog. - Isolation is still incomplete: the 12 Harness hits into Infra (R2, #412) and the five runtime resource loaders (R3, #412) remain. diff --git a/tests/check_installed.py b/tests/check_installed.py index 6d11f1a19..bd54f51e5 100644 --- a/tests/check_installed.py +++ b/tests/check_installed.py @@ -5,6 +5,7 @@ import os import subprocess import sys +import tempfile from importlib import import_module from importlib.resources import as_file, files from importlib.util import find_spec @@ -733,3 +734,33 @@ def _inventory(root, prefix): check=False, ) assert worker.returncode == 0, worker.stderr +# The installed adapter launches that worker through its own ``_WORKER`` lookup and the +# real ``python -I -B `` entry. From a temporary cwd, with a synthetic grant whose +# engine file does not exist and no MindIE library, the read must end in the worker's +# fixed structured rejection, not a missing-file or non-JSON failure. +launch_probe = ( + "import json, sys\n" + "from pathlib import Path\n" + "import inferrsi.apps.mindie as adapter\n" + "from inferrsi.apps.mindie import project\n" + "assert project._WORKER == Path(adapter.__path__[0]) / 'read_worker.py', project._WORKER\n" + "assert project._WORKER.is_file()\n" + "grant = {'python': sys.executable, 'engine': str(Path.cwd() / 'missing-engine.json'),\n" + " 'domain': 'probe'}\n" + "try:\n" + " project._worker(grant, 'describe', b'{}')\n" + "except project.ReadFailure as exc:\n" + " failure = exc\n" + "else:\n" + " raise AssertionError('the synthetic read must be rejected')\n" + "expected = 'The local MindIE catalog is unavailable'\n" + "assert str(failure) == expected, str(failure)\n" + "assert failure.exit_code == 1, failure.exit_code\n" + "assert json.loads(failure.response) == {'isError': True, 'error': expected}\n" +) +with tempfile.TemporaryDirectory(prefix="inferrsi-mindie-launch-") as launch_cwd: + launch = subprocess.run( + [sys.executable, "-I", "-B", "-c", launch_probe], capture_output=True, text=True, + check=False, cwd=launch_cwd, + ) +assert launch.returncode == 0, launch.stderr