diff --git a/.github/workflows/ci-ready.yml b/.github/workflows/ci-ready.yml index 80978887b..863608e63 100644 --- a/.github/workflows/ci-ready.yml +++ b/.github/workflows/ci-ready.yml @@ -98,3 +98,151 @@ jobs: env: PR_BODY: ${{ github.event.pull_request.body }} run: python3 tools/check_pr_references.py + + host-compatibility: + # GitHub-hosted Windows and macOS CPU evidence, separate from the Ubuntu jobs above: + # a pass on Linux is not a pass on these hosts. It runs only the eight plugin and DSH + # nodes that an earlier Windows run recorded as failing (63 passed, 8 failed), then an + # installed-wheel check. A pass here does not rewrite that record. No GPU, remote + # service or credential is used; the DSH node talks to the fake SSH server that its + # own check starts. One host at a time, one pytest process, no full suite. + strategy: + fail-fast: false + max-parallel: 1 + matrix: + os: [windows-latest, macos-latest] + runs-on: ${{ matrix.os }} + timeout-minutes: 30 + permissions: + contents: read + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + - uses: actions/setup-node@v4 + with: + node-version: "22" + - name: Install dev deps and the build frontend + run: python -m pip install -e ".[dev]" build + - name: Test the eight plugin and DSH host nodes + # Started from Python so both hosts receive identical node IDs; no shell rewrites + # "::" or "[...]". The checkout path is absolute and PYTHONPATH is not set. + shell: python + env: + RESULTS: ${{ runner.temp }}/host-compatibility-results.xml + run: | + import os + import shutil + import subprocess + import sys + import xml.etree.ElementTree as ET + + nodes = [ + "tests/test_codex_plugin.py::test_comparison_preview_execution_status_and_report[codex-fail-1-FAIL]", + "tests/test_codex_plugin.py::test_isolated_runtime_can_export_dashboard[workswarm]", + "tests/test_codex_plugin.py::test_comparison_preview_execution_status_and_report[workswarm-pass-0-PASS]", + "tests/test_codex_plugin.py::test_comparison_preview_execution_status_and_report[workswarm-fail-1-FAIL]", + "tests/test_codex_plugin.py::test_comparison_preview_execution_status_and_report[workswarm-missing-2-INCONCLUSIVE]", + "tests/test_codex_plugin.py::test_release_archive_is_installable_and_all_versions_match[codex]", + "tests/test_codex_plugin.py::test_release_archive_is_installable_and_all_versions_match[workswarm]", + "tests/test_dsh_plugin.py::test_remote_ssh_connection_and_scoped_operations", + ] + # The DSH node skips without Node.js, and every node needs Git or Python. + for tool in ("node", "git"): + path = shutil.which(tool) + if path is None: + raise SystemExit(tool + " is required by the selected nodes") + subprocess.run([path, "--version"], check=True) + results = os.environ["RESULTS"] + command = [sys.executable, "-m", "pytest", "-vv", "-rs", "-o", "addopts=", + "--junitxml=" + results, *nodes] + status = subprocess.run( + command, cwd=os.environ["GITHUB_WORKSPACE"], check=False + ).returncode + if status: + raise SystemExit(status) + # A skipped or deselected node is not a pass: all eight must have run. + suite = next(ET.parse(results).getroot().iter("testsuite")) + counts = {name: int(suite.get(name)) + for name in ("tests", "errors", "failures", "skipped")} + print(counts, flush=True) + if counts != {"tests": len(nodes), "errors": 0, "failures": 0, "skipped": 0}: + raise SystemExit("every selected host node must run and pass") + - name: Check a wheel built from the sdist in a fresh environment outside the checkout + # Runs even if a node above failed, so both results are recorded; either failure + # still fails the job. + if: ${{ !cancelled() }} + shell: python + run: | + import os + import shutil + import subprocess + import sys + from pathlib import Path + + workspace = Path(os.environ["GITHUB_WORKSPACE"]).resolve() + work = Path(os.environ["RUNNER_TEMP"]).resolve() / "host-wheel" + log = work.parent / "host-wheel.log" + assert work != workspace and workspace not in work.parents, work + work.mkdir() + # Children never see PYTHONPATH, and the checker compares with this absolute path. + environment = {key: value for key, value in os.environ.items() if key != "PYTHONPATH"} + environment["INFERRSI_CHECKOUT_RESOURCES"] = str(workspace / "src" / "inferrsi") + + + def run(*command, cwd=work): + command = [str(part) for part in command] + result = subprocess.run( + command, cwd=cwd, env=environment, capture_output=True, text=True, + encoding="utf-8", errors="replace", check=False, + ) + text = "$ " + " ".join(command) + "\n" + result.stdout + result.stderr + print(text, flush=True) + with log.open("a", encoding="utf-8") as stream: + stream.write(text) + if result.returncode: + raise SystemExit(f"exit {result.returncode}: {command[0]}") + return result.stdout + + + # python -m build writes the sdist and builds the wheel from that sdist. + dist = work / "dist" + run(sys.executable, "-m", "build", "--outdir", dist, cwd=workspace) + sdists, wheels = sorted(dist.glob("*.tar.gz")), sorted(dist.glob("*.whl")) + assert len(sdists) == 1 and len(wheels) == 1, (sdists, wheels) + venv = work / "env" + run(sys.executable, "-m", "venv", venv) + scripts = venv / ("Scripts" if os.name == "nt" else "bin") + python = scripts / ("python.exe" if os.name == "nt" else "python") + console = scripts / ("inferrsi.exe" if os.name == "nt" else "inferrsi") + run(python, "-m", "pip", "install", f"{wheels[0]}[skills]") + assert console.is_file(), console + shutil.copyfile(workspace / "tests" / "check_installed.py", work / "check_installed.py") + run(python, "-I", "check_installed.py") + # The package under test is the installed wheel, never the source checkout. + location = Path( + run(python, "-I", "-c", "import inferrsi; print(inferrsi.__file__)").strip() + ).resolve() + assert venv.resolve() in location.parents, location + assert workspace not in location.parents, location + installed = run( + python, "-I", "-c", "from importlib.metadata import version; print(version('inferrsi'))" + ) + # The console script and python -m inferrsi answer with the same bytes. + for arguments in (["--version"], ["benchmarks", "list"]): + module = run(python, "-I", "-m", "inferrsi", *arguments) + assert module.strip() and module == run(console, *arguments), arguments + if arguments == ["--version"]: + assert module == installed, (module, installed) + - name: Retain host results + if: always() + uses: actions/upload-artifact@v4 + with: + name: host-compatibility-${{ matrix.os }} + path: | + ${{ runner.temp }}/host-compatibility-results.xml + ${{ runner.temp }}/host-wheel.log + retention-days: 30 diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b1db2ba6..a18e9671c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,46 @@ ### Changed +- The CLI moves into the Apps package and the two root CLI modules are removed + (Refs #408, A1), with no forwarding shell, `sys.modules` alias or import + fallback: + - `inferrsi.cli` → `inferrsi.apps.cli` (`src/inferrsi/cli.py` → + `src/inferrsi/apps/cli/__init__.py`), which exposes the canonical `main` + - `inferrsi.arguments` → `inferrsi.apps.cli.arguments` + (`src/inferrsi/arguments.py` → `src/inferrsi/apps/cli/arguments.py`), which + holds `parser`, `make_spec` and `device_ids` + - The `inferrsi` console script names `inferrsi.apps.cli:main`, and + `python -m inferrsi` delegates to the same function. Commands, flags, exit + codes and stdout/stderr are unchanged. The shared Codex and WorkSwarm + launcher and the DSH remote bootstrap import the canonical modules. + - Importing `inferrsi.cli` or `inferrsi.arguments` now raises + `ModuleNotFoundError`, in external Python code as well as in this + repository, and a pickle that names an object by either path no longer + loads. Callers import `main` from `inferrsi.apps.cli` and the parser + helpers from `inferrsi.apps.cli.arguments`. Test injection points move + with the code: `inferrsi.cli._knowledge_reader` and `inferrsi.cli.files` + are the same names on `inferrsi.apps.cli`. Frozen evidence is not + rewritten. + - The tracked package root shrinks from ten files to eight. Besides + `__init__.py` and `__main__.py`, the six left (`summary_chart.py`, + `benchmark_operations.py` and the four MindIE files) wait for A2 (#408) and + M1 (#452). The gate's `APPLICATION_ENTRIES` lists only + `benchmark_operations.py`, and `inferrsi.cli` and `inferrsi.arguments` join + `RETIRED_ROOT_MODULES`, so a root file that returns under either name + fails. + - The temporary neutral-leaf entry for root `arguments.py` + (`technical_leaf.temporary_importers`, `TEMPORARY_LEAF_IMPORTERS`) and its + `temporary leaf importers` blocker are removed, and nothing replaces them. + The moved parser reads `REPO_TYPES` through `inferrsi.knowledge.catalog`, + which binds the one tuple object from + `inferrsi.resources.repository_packs`. An Apps module that imports the leaf + itself still fails as a second importer. The permanent + `inferrsi.infra.inspection` rule and the empty `compatibility_pairs` are + unchanged, and the manifest keeps the removed entry in `revision_history`. + This route for `REPO_TYPES` needs architecture review and is not + self-approved. + - Isolation is still incomplete: the 12 Harness hits into Infra (R2, #412) + and the five runtime resource loaders (R3, #412) remain. - Eleven legacy root modules are removed (Refs #412, R1). Their implementations already lived in `inferrsi.knowledge` and `inferrsi.apps`. The root files are deleted in the change that moves their last consumers, with no forwarding diff --git a/docs/architecture.md b/docs/architecture.md index f9931dc0a..0b050631c 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -6,8 +6,8 @@ Qwen-Image denoising and real-model Qwen3-TTS under packages. `inferrsi benchmarks run ...` launches the package's `benchmark.py`. Task-specific orchestration, sampling and assessment live inside each package. The task library owns its `index.json` registration. The existing -`benchmark/registry.py` discovers the resources. The existing `arguments.py`, -`cli.py` and `benchmark_operations.py` provide application assembly and launch. +`benchmark/registry.py` discovers the resources. The CLI package `apps/cli/` +and the existing `benchmark_operations.py` provide application assembly and launch. Each task retains its own protocol and task-specific code. The [current-Agent optimization session](optimization-benchmarks.md) assembles @@ -158,7 +158,7 @@ the comparator; the engine AB/BA path retains its independent acceptance contrac ```text src/inferrsi/ - cli.py, arguments.py Existing CLI + apps/cli/ CLI entry `main` and its argument parser benchmark_operations.py Resolve a task entry and launch it through Harness benchmark/ registry.py Generic task resource discovery @@ -271,15 +271,17 @@ examples/ Current Qwen runner, image validator and v4 adapter tests/fixtures/legacy/ Frozen historical validation dependencies for regressions ``` -The package root holds exactly ten tracked files at this stage: `__init__.py`, -`__main__.py`, `cli.py`, `arguments.py`, `benchmark_operations.py`, -`summary_chart.py`, `mindie_context.py`, `mindie_mcp.py`, `mindie_project.py` -and `_mindie_read_worker.py`. #412 R1 deleted eleven root modules with no +The package root holds exactly eight tracked files at this stage: `__init__.py`, +`__main__.py`, `benchmark_operations.py`, `summary_chart.py`, +`mindie_context.py`, `mindie_mcp.py`, `mindie_project.py` and +`_mindie_read_worker.py`. #408 A1 moved the CLI and its parser to `apps/cli/` +and deleted root `cli.py` and `arguments.py` with no forwarding shell or alias; +`__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 A1/A2 (#408) and M1 (#452) moves. +and `__main__.py`) waits for the A2 (#408) and M1 (#452) moves. [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/contracts/current-design.md b/docs/contracts/current-design.md index c39a10292..a9e2eccfe 100644 --- a/docs/contracts/current-design.md +++ b/docs/contracts/current-design.md @@ -32,7 +32,7 @@ Permitted shared technical leaves are only: - `inferrsi.contracts.json_v1` — the canonical encoder (D002); - `inferrsi.contracts.runspec` and `inferrsi.contracts.claim` — the existing RunSpec and Verdict technical types, with only RunSpec re-exported by the package initializer; - `inferrsi.contracts.evidence` — the existing evidence segment names and pure path rules; it reads and writes no filesystem state and is not re-exported by the package initializer; -- `inferrsi.resources.repository_packs` — the neutral raw pack-data reader and the existing static data enumeration (D020), formerly root `inferrsi._repo_pack_data`. Its parent initializer `resources/__init__.py` imports nothing. Outside Knowledge it has one permanent importer, `inferrsi.infra.inspection`, which binds only `repository_pack`; that exact rule is not a compatibility pair. Root `arguments.py` reads `REPO_TYPES` from it under a separate temporary entry that A1 (#408) removes. +- `inferrsi.resources.repository_packs` — the neutral raw pack-data reader and the existing static data enumeration (D020), formerly root `inferrsi._repo_pack_data`. Its parent initializer `resources/__init__.py` imports nothing. Outside Knowledge it has one permanent importer, `inferrsi.infra.inspection`, which binds only `repository_pack`; that exact rule is not a compatibility pair. A1 (#408) removed the separate temporary entry for root `arguments.py`: the moved parser `inferrsi.apps.cli.arguments` reads the same `REPO_TYPES` object through `inferrsi.knowledge.catalog` and does not import the leaf. The neutral leaf carries no target selection, task, scoring, scheduling, or public business DTO, and imports none of K/H/B/Apps. It still finds the Harness-owned `pack.json` through `files("inferrsi").joinpath("harness", "data", "repo_packs", ...)`, so reading it never imports Harness. Creating the evidence directories is host I/O and stays in Apps, in `inferrsi.apps.evidence_layout`; that module is not a shared leaf. The list is exact: a `contracts.` or `resources.` prefix admits no other module. @@ -143,7 +143,7 @@ Decision: see [`gate-policy-runstore-and-first-prs.md`](gate-policy-runstore-and Decision: old entry points, arguments, `Path`, stdout, stderr, and old run 0/1/2 stay byte-for-byte compatible. New Apps naming/envelope/exit mapping is fixed by D022, but K01/H01 do not implement a CLI. -Current reading: this covers the CLI commands and the `inferrsi` and `python -m inferrsi` entry points. It no longer covers old root Python module paths. The revised delivery decision in #412, #451 and #408 retires those paths without aliases, in the change that moves their last consumers. R1 (#412) removed the old-run root modules `evaluation`, `execution` and `reporting` together with root `inspection`; the old run is `inferrsi.apps.legacy` and the host inspection binding is `inferrsi.apps.inspection`. Root `cli.py` and `arguments.py` stay in place until A1 (#408), and R1 changed only their imports. +Current reading: this covers the CLI commands and the `inferrsi` and `python -m inferrsi` entry points. It no longer covers old root Python module paths. The revised delivery decision in #412, #451 and #408 retires those paths without aliases, in the change that moves their last consumers. R1 (#412) removed the old-run root modules `evaluation`, `execution` and `reporting` together with root `inspection`; the old run is `inferrsi.apps.legacy` and the host inspection binding is `inferrsi.apps.inspection`. A1 (#408) then moved root `cli.py` and `arguments.py` to `inferrsi.apps.cli` and `inferrsi.apps.cli.arguments` and deleted both root files; the console script and `python -m inferrsi` call `inferrsi.apps.cli:main`. ## D014 — events remain local, not a new shared event schema @@ -165,8 +165,8 @@ Current status after R1 (#412): - The seven root leaves are deleted, so `compatibility_pairs` in [`../legacy-knowledge-manifest.json`](../legacy-knowledge-manifest.json) is empty. The nine pair records stay in its `revision_history`, unchanged, as the record of this decision. - The former ninth pair, `infra.inspection` → `inferrsi.resources.repository_packs`, is a live import that no root deletion removes. It is now a permanent exact rule outside the allowlist: that one module binds the one name `repository_pack` with one plain module-level import. The leaf's bytes, SHA-256, allowed imports, shape and import-free parent initializer stay locked, and no `resources.` or `contracts.` prefix is allowed. -- Root `arguments.py` → the same leaf, for `REPO_TYPES`, is a separate temporary entry. It adds a blocker until A1 (#408) removes root `arguments.py`. -- `overall isolation_complete` is still false. That temporary entry, twelve `harness` → `inferrsi.infra` hits in six Harness modules (R2) and five declared runtime resource loaders (R3) remain. The package root holds ten tracked files; the final two-file root waits for A1/A2 (#408) and M1 (#452). +- Root `arguments.py` → the same leaf, for `REPO_TYPES`, was a separate temporary entry with its own blocker. A1 (#408) removed both with the root file, and no Apps importer of the leaf replaced them. +- `overall isolation_complete` is still false. A1 (#408) cleared that temporary entry; twelve `harness` → `inferrsi.infra` hits in six Harness modules (R2) and five declared runtime resource loaders (R3) remain. The package root holds eight tracked files; the final two-file root waits for A2 (#408) and M1 (#452). - The permanent rule and that manifest revision require formal architecture review. The implementer does not self-approve them, and passing tests are not that review. [`../module-layout.md`](../module-layout.md) has the exact rules and their negative controls. diff --git a/docs/legacy-knowledge-manifest.json b/docs/legacy-knowledge-manifest.json index b98ec7e32..93a06e0d8 100644 --- a/docs/legacy-knowledge-manifest.json +++ b/docs/legacy-knowledge-manifest.json @@ -1,7 +1,7 @@ { "$schema": "urn:inferrsi:docs:legacy-knowledge-manifest:v1", - "description": "First-wave Knowledge compatibility record and the neutral technical data leaf's locks. P0b froze the first revision at 0da7e2f960cd4ec994ae8eddea5b71023c5379ca, K01 re-recorded every leaf hash before the code move, K02 changed only the data leaf's locked file hash, and C2 (#451) moved that leaf byte for byte to inferrsi.resources.repository_packs. This R1 revision (#412) deletes the seven root Knowledge shells with their eight pairs, so compatibility_pairs is empty and the allowlist blocker is gone. The former ninth pair, infra.inspection -> the data leaf, is now the permanent exact rule in technical_leaf.permanent_importers, outside the allowlist. The nine retired pair records, with the old root leaf hashes and export lists, are kept unchanged under the last revision_history entry. The leaf's bytes and locked file hash are unchanged. Nothing here is a wildcard approval, and it changes only through formal review. Line references are at the base_commit recorded by the revision that wrote them; this revision re-records none of them.", - "base_commit": "5db1bc94042f386f0b4b35c3e6fe91598fef118f", + "description": "First-wave Knowledge compatibility record and the neutral technical data leaf's locks. P0b froze the first revision at 0da7e2f960cd4ec994ae8eddea5b71023c5379ca, K01 re-recorded every leaf hash before the code move, K02 changed only the data leaf's locked file hash, and C2 (#451) moved that leaf byte for byte to inferrsi.resources.repository_packs. The R1 revision (#412) deleted the seven root Knowledge shells with their eight pairs, so compatibility_pairs is empty and the allowlist blocker is gone. The former ninth pair, infra.inspection -> the data leaf, is now the permanent exact rule in technical_leaf.permanent_importers, outside the allowlist. The nine retired pair records, with the old root leaf hashes and export lists, are kept unchanged under the C2 revision_history entry, the record that R1 appended; it is no longer the last entry. The leaf's bytes and locked file hash are unchanged. Nothing here is a wildcard approval, and it changes only through formal review. Line references are at the base_commit recorded by the revision that wrote them; no later revision re-records them. This A1 revision (#408) removes technical_leaf.temporary_importers with root arguments.py: the moved Apps parser reads the same REPO_TYPES object through inferrsi.knowledge.catalog, no Apps importer of the leaf is declared, and the removed entry is kept unchanged as retired_temporary_importers under the last revision_history entry, the R1 record.", + "base_commit": "aaa17a5dd333449d15fb052bb09b2012d55f2327", "revision_history": [ { "base_commit": "0da7e2f960cd4ec994ae8eddea5b71023c5379ca", @@ -261,6 +261,32 @@ "note": "Root catalog also re-exports REPO_TYPES and repository_pack from the neutral data leaf" } } + }, + { + "base_commit": "5db1bc94042f386f0b4b35c3e6fe91598fef118f", + "stage": "R1", + "superseded_by": "A1 parser-move revision at aaa17a5dd333449d15fb052bb09b2012d55f2327", + "reason": "A1 (#408) moves root cli.py and arguments.py to inferrsi.apps.cli and deletes both root files in the same change, with no forwarding shell or alias. The moved parser binds REPO_TYPES through inferrsi.knowledge.catalog, which holds the leaf's one tuple object, and names no inferrsi.resources module, so technical_leaf.temporary_importers and its blocker are removed and no importer entry replaces it. compatibility_pairs stays empty, and the permanent infra.inspection rule and every leaf lock are unchanged.", + "retired_temporary_importers": { + "stage": "R1", + "issue": "#412", + "due": "A1 (#408)", + "rule": "Root catalog is retired, so the root CLI parser takes the one REPO_TYPES tuple from the leaf itself for its --repo-type choices. The entry is held to the same exact import shape as the permanent rule. It is not part of the permanent rule and it is not an allowance for Apps modules in general.", + "importers": [ + { + "importer": "inferrsi.arguments", + "file": "src/inferrsi/arguments.py", + "names": [ + "REPO_TYPES" + ], + "import_line": "from .resources.repository_packs import REPO_TYPES" + } + ], + "blocker": "While a listed module imports the leaf, first_wave_report() carries a 'temporary leaf importers' blocker, so isolation_complete stays false.", + "removal": "A1 deletes root arguments.py and removes this entry in the same change. How the moved parser reads REPO_TYPES is decided by that change's review, not here.", + "gate": "tests/_gate_policy_support.py TEMPORARY_LEAF_IMPORTERS holds the same importer and name.", + "review": "This entry requires formal architecture review. The implementer does not self-approve it, and passing tests are not that review." + } } ], "compatibility_pairs": [], @@ -335,26 +361,6 @@ "not_a_compatibility_pair": "The entry is not in compatibility_pairs and is never counted by the allowlist blocker. It does not retire with a shell, because the importer is not a shell.", "gate": "tests/_gate_policy_support.py LEAF_IMPORTERS holds the same importer and name. tests/test_knowledge_compatibility_shells.py requires the two to match exactly.", "review": "This rule requires formal architecture review. The implementer does not self-approve it, and passing tests are not that review." - }, - "temporary_importers": { - "stage": "R1", - "issue": "#412", - "due": "A1 (#408)", - "rule": "Root catalog is retired, so the root CLI parser takes the one REPO_TYPES tuple from the leaf itself for its --repo-type choices. The entry is held to the same exact import shape as the permanent rule. It is not part of the permanent rule and it is not an allowance for Apps modules in general.", - "importers": [ - { - "importer": "inferrsi.arguments", - "file": "src/inferrsi/arguments.py", - "names": [ - "REPO_TYPES" - ], - "import_line": "from .resources.repository_packs import REPO_TYPES" - } - ], - "blocker": "While a listed module imports the leaf, first_wave_report() carries a 'temporary leaf importers' blocker, so isolation_complete stays false.", - "removal": "A1 deletes root arguments.py and removes this entry in the same change. How the moved parser reads REPO_TYPES is decided by that change's review, not here.", - "gate": "tests/_gate_policy_support.py TEMPORARY_LEAF_IMPORTERS holds the same importer and name.", - "review": "This entry requires formal architecture review. The implementer does not self-approve it, and passing tests are not that review." } }, "infra_inspection_rewrite": { diff --git a/docs/module-layout.md b/docs/module-layout.md index 2cfae4992..e932bf176 100644 --- a/docs/module-layout.md +++ b/docs/module-layout.md @@ -5,7 +5,7 @@ Knowledge move (K01) is implemented: `src/inferrsi/knowledge/` holds the seven moved Knowledge bodies. R1 (#412) deleted the seven static root compatibility shells that K01 left, so those names import only from `inferrsi.knowledge`. The engineering task contribution now implements `benchmark/registry.py` -and `benchmark/tasks/`. The current flat `cli.py`, `arguments.py` and +and `benchmark/tasks/`. The CLI package `apps/cli/` and the flat `benchmark_operations.py` assemble this slice. The former `observability/` package is dissolved. Its campaign records, traces, logs and profile captures are in `harness/records/`, @@ -17,10 +17,10 @@ The old `run` chain is split by owner. Its gates are in `benchmark/legacy_run_v0.py`, its execution facts stay in `harness/`, and `apps/legacy/` composes them with the report. `apps/legacy/` is the path named by the confirmed split for this slice; that use does not accept #371. -`cli.py` imports the old run only inside its `run` command, so the other +`apps/cli/` imports the old run only inside its `run` command, so the other commands, including ordinary optimization, still load no Benchmark module. R1 deleted the three root forwarders of that chain (`evaluation.py`, -`execution.py` and `reporting.py`), and `cli.py` imports `apps/legacy/` itself. +`execution.py` and `reporting.py`), and the CLI imports `apps/legacy/` itself. ## Target modules @@ -43,16 +43,18 @@ 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 and 10 after R1 (#412). The ten are -`__init__.py`, `__main__.py`, `_mindie_read_worker.py`, `arguments.py`, -`benchmark_operations.py`, `cli.py`, `mindie_context.py`, `mindie_mcp.py`, -`mindie_project.py` and `summary_chart.py`. Each later removal PR shrinks that -set in the same change: A1 and A2 (#408) move the CLI, the chart and the +tracked files after C1, 21 after C2, 10 after R1 (#412) and 8 after A1 (#408). +The eight are `__init__.py`, `__main__.py`, `_mindie_read_worker.py`, +`benchmark_operations.py`, `mindie_context.py`, `mindie_mcp.py`, +`mindie_project.py` and `summary_chart.py`. A1 moved root `cli.py` and +`arguments.py` to `apps/cli/__init__.py` and `apps/cli/arguments.py` and +deleted both root files with no forwarding shell or alias. Each later removal +PR shrinks the set in the same change: A2 (#408) moves the chart and the benchmark launcher, and 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. +paths that R1 removed and the two that A1 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 @@ -104,7 +106,7 @@ Several flat modules remain shared seams until their slice starts. | Current path | Tentative reading | This slice | | --- | --- | --- | -| `cli.py`, `arguments.py`, `__main__.py` | Future Apps entry, after #371 | Not moved; R1 changed only the imports of `cli.py` and `arguments.py`, and A1 (#408) moves both | +| `apps/cli/` (`__init__.py`, `arguments.py`), root `__main__.py` | Apps CLI entry and its parser | A1 (#408) moved root `cli.py` and `arguments.py` here; the entry is `inferrsi.apps.cli:main`, and `__main__.py` only delegates to it | | `benchmark_operations.py` | Single-task application launcher | Resolves a task entry and invokes the Harness runner; ordinary projects do not use it | | `benchmark/registry.py`, `benchmark/tasks/` | Task discovery, definitions and specialized rules | Task-specific quality and measurement code stays with each task | | `harness/optimization_session.py`, `harness/project.py`, `harness/task_protocol.py` | Shared preparation, execution and retained-result assessment | CLI supplies task resources and knowledge access; ordinary project lifecycle does not import Benchmark | @@ -134,13 +136,13 @@ Several flat modules remain shared seams until their slice starts. `tests/test_target_module_import_gate.py` fails on a new import of `inferrsi.knowledge`, `inferrsi.benchmark`, or `inferrsi.apps` from anywhere except application assembly, and on Knowledge or Benchmark importing Harness. -Application assembly includes `inferrsi.apps` and the three current flat -entries `cli.py`, `arguments.py` and `benchmark_operations.py`, listed by exact -file name as `APPLICATION_ENTRIES` in `tests/_gate_policy_support.py`. -`arguments.py` joined that list in R1: the CLI parser names -`inferrsi.knowledge` itself now that the root shells are gone. The listing is -temporary. A1 (#408) moves `cli.py` and `arguments.py` into `apps/cli/` and -removes both entries, and A2 removes the last one. Other flat modules retain +Application assembly includes `inferrsi.apps` and the one remaining flat +entry `benchmark_operations.py`, listed by exact file name as +`APPLICATION_ENTRIES` in `tests/_gate_policy_support.py`. A1 (#408) moved +`cli.py` and `arguments.py` into `apps/cli/`, which is Apps by its first path +segment, and removed their two entries, so a root file that returns under +either name is not admitted. The listing is temporary: A2 removes the last +entry. Other flat modules retain the same restrictions. The gate checks Benchmark task scripts as well as module code. `from inferrsi import knowledge` counts as an import of that core. @@ -215,23 +217,23 @@ A clean result means no new cross-core import of those names. It does not mean the modules are isolated. Isolation stays false while any one of these holds: `knowledge/`, `benchmark/`, or `apps/` is absent or has no scannable module; the compatibility allowlist -is non-empty; a temporary neutral-leaf importer still imports the leaf; +is non-empty; `harness/**` still imports Model or Infra, directly or through another module; a declared runtime resource loader is present; or the scan reports a violation. The three packages may appear in stages. A clean graph for the new cores is reported separately as "new core business closure isolated" and never sets overall `isolation_complete` to true. -On the tree after R1, `first_wave_report()` has no violation and three -blockers, so `isolation_complete` is false and R1 does not claim otherwise: +On the tree after A1 (#408), `first_wave_report()` has no violation and two +blockers, so `isolation_complete` is false and A1 does not claim otherwise: | Blocker | Cause | Closed by | | --- | --- | --- | -| `temporary leaf importers: 1` | Root `arguments.py` reads `REPO_TYPES` from the neutral leaf | A1 (#408) | | `harness reaches model/infra` (12 hits) | `agent_sessions`, `candidates`, `optimization`, `optimization_session`, `project` and `task_protocol` each reach `inferrsi.infra` and `inferrsi.infra.artifacts` | R2 (#412) | | `runtime resource loaders: 5` | The five declared loaders in the table above | R3 (#412) | -R1 cleared the `allowlist` and `legacy run forwarders` blockers. The loaders +R1 cleared the `allowlist` and `legacy run forwarders` blockers, and A1 cleared +the `temporary leaf importers` blocker that R1 left for root `arguments.py`. The loaders also keep `new_core_closure_isolated` false. `knowledge-model-policy` stays the only required status. Until a separate @@ -278,13 +280,13 @@ when R1 deleted those files. The ninth row is not a root-file edge: it. It left the allowlist and is the [permanent rule below](#permanent-neutral-leaf-importer-rule-proposed). The manifest keeps all nine records and root `catalog`'s two routes, -unchanged, under its last `revision_history` entry as +unchanged, under the C2 entry of its `revision_history` as `retired_compatibility_pairs` and `retired_catalog_two_routes`. An import of the leaf from inside `inferrsi.knowledge`, for example from `inferrsi/knowledge/catalog.py`, is intra-closure and was never an exception. The leaf's own import rule and `REPO_TYPES` object identity govern it. `REPO_TYPES` is the same tuple object in the leaf, -`inferrsi.knowledge.catalog` and root `arguments.py`. +`inferrsi.knowledge.catalog` and the moved parser `inferrsi.apps.cli.arguments`. - **Shell shape.** No shell exists after R1. The rule is kept for a pair that review stages again, and `tests/test_first_wave_isolation_policy.py` still @@ -376,8 +378,9 @@ now empty and the allowlist blocker is gone. The C2 revision joined routes, each unchanged, including the old root leaf hashes that K01 recorded. `technical_leaf` keeps its module, file, locked `file_sha256`, allowed imports, two symbols, top-level shape, both fragments and the K02 and C2 revision -records. It gains `permanent_importers` and `temporary_importers`, described -in the next section. The K01, K02 and C2 paragraphs above stay as provenance +records. With R1 it gained `permanent_importers` and `temporary_importers`, described +in the next section; A1 (#408) removed the second and kept the removed record +in `revision_history`. The K01, K02 and C2 paragraphs above stay as provenance and describe the tree at their own revisions. This R1 manifest revision requires formal architecture review; the implementer does not self-approve it, and passing tests are not that review. @@ -423,20 +426,23 @@ of them removes the declaration and shows that the scan then rejects the `infra.inspection` edge, so the edge passes by the rule and not by a relaxed scan. -One temporary entry sits beside the rule and is not part of it. Root `catalog` -is gone, so root `arguments.py` binds `REPO_TYPES` with -`from .resources.repository_packs import REPO_TYPES` for the `--repo-type` -choices. It is `TEMPORARY_LEAF_IMPORTERS` in the gate and -`technical_leaf.temporary_importers` in the manifest, held to the same exact -shape. It names root `arguments.py` only: the parser at an Apps path, or any -other Apps module, is not covered. While it exists the report carries the -`temporary leaf importers` blocker. A1 (#408) deletes root `arguments.py` and -removes the entry in the same change; how the moved parser reads `REPO_TYPES` -is decided by that change's review. - -The permanent rule and the temporary entry are Proposed. Both require formal -architecture review. The implementer does not self-approve them, and passing -tests are not that review. +One temporary entry sat beside the rule from R1 until A1 (#408) and was never +part of it. Root `catalog` was gone, so root `arguments.py` bound `REPO_TYPES` +with `from .resources.repository_packs import REPO_TYPES` for the `--repo-type` +choices. It was `TEMPORARY_LEAF_IMPORTERS` in the gate and +`technical_leaf.temporary_importers` in the manifest, and the report carried a +`temporary leaf importers` blocker. A1 deleted root `arguments.py` and removed +the entry, the gate constant and the blocker in the same change. Nothing +replaced them. The moved parser `apps/cli/arguments.py` reads `REPO_TYPES` from +`inferrsi.knowledge.catalog`, which binds the one tuple object from the leaf. +The `--repo-type` choices are still that object, and the Apps parser imports no +`inferrsi.resources` module. An Apps module that imports the leaf itself fails +as a second importer, the moved parser included. The manifest keeps the removed +entry unchanged in `revision_history`. + +The permanent rule is Proposed and requires formal architecture review. So does +the A1 choice to read `REPO_TYPES` through Knowledge. The implementer does not +self-approve either, and passing tests are not that review. ## Retired root modules @@ -473,9 +479,21 @@ and a pickle that names a class or function by one no longer loads. Frozen evidence is not rewritten; a historical campaign replays with its original bundle. -The root now holds the ten files listed under +A1 (#408) deleted two more root modules the same way: + +| Retired root module | Canonical module | +| --- | --- | +| `inferrsi.cli` | `inferrsi.apps.cli` | +| `inferrsi.arguments` | `inferrsi.apps.cli.arguments` | + +The `inferrsi` console script and `python -m inferrsi` call +`inferrsi.apps.cli:main`, and every command, flag, exit code and output byte is +unchanged. A test replaces a CLI name such as `_knowledge_reader` or `files` on +`inferrsi.apps.cli`. + +The root now holds the eight files listed under [Target modules](#target-modules). The final two-file root waits for the -A1/A2 (#408) and M1 (#452) moves. +A2 (#408) and M1 (#452) moves. ## Old `run` exit codes diff --git a/plugins/inferrsi-dsh/remote.cjs b/plugins/inferrsi-dsh/remote.cjs index b3e053c25..deb600a57 100644 --- a/plugins/inferrsi-dsh/remote.cjs +++ b/plugins/inferrsi-dsh/remote.cjs @@ -48,7 +48,7 @@ try: names.add(name) archive.extractall(directory) sys.path.insert(0, directory) - from inferrsi.arguments import parser + from inferrsi.apps.cli.arguments import parser argument_parser = parser() def exact_options(current): current.allow_abbrev = False @@ -83,7 +83,7 @@ try: if (argv[1].startswith('-') or not script.startswith(root + '/') or not os.path.isfile(script)): raise ValueError('script outside repository') - from inferrsi.cli import main + from inferrsi.apps.cli import main sys.exit(main(payload['args'])) except KeyboardInterrupt: sys.exit(130) diff --git a/plugins/inferrsi/skills/inferrsi/scripts/inferrsi.py b/plugins/inferrsi/skills/inferrsi/scripts/inferrsi.py index f0aba0aef..4ec38f22a 100644 --- a/plugins/inferrsi/skills/inferrsi/scripts/inferrsi.py +++ b/plugins/inferrsi/skills/inferrsi/scripts/inferrsi.py @@ -64,7 +64,7 @@ def main() -> int: ) return 2 - from inferrsi.cli import main as cli_main + from inferrsi.apps.cli import main as cli_main return cli_main(args) diff --git a/pyproject.toml b/pyproject.toml index a61babc75..9877cbdb7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ requires-python = ">=3.10" dependencies = [] [project.scripts] -inferrsi = "inferrsi.cli:main" +inferrsi = "inferrsi.apps.cli:main" [project.urls] Repository = "https://github.com/InferMatrixLab/InferRSI" diff --git a/src/inferrsi/__main__.py b/src/inferrsi/__main__.py index eb53e2f31..d98509898 100644 --- a/src/inferrsi/__main__.py +++ b/src/inferrsi/__main__.py @@ -1,3 +1,3 @@ -from .cli import main +from .apps.cli import main raise SystemExit(main()) diff --git a/src/inferrsi/cli.py b/src/inferrsi/apps/cli/__init__.py similarity index 93% rename from src/inferrsi/cli.py rename to src/inferrsi/apps/cli/__init__.py index 5c2880b12..eb9b3d49c 100644 --- a/src/inferrsi/cli.py +++ b/src/inferrsi/apps/cli/__init__.py @@ -8,15 +8,15 @@ from importlib.resources import files from pathlib import Path -from .apps.campaign import capture_context, create_campaign -from .apps.inspection import inspect_environment -from .apps.knowledge import knowledge_reader -from .apps.knowledge import read as read_knowledge -from .apps.legacy.reporting import write_report +from ...knowledge.catalog import get_knowledge, search_knowledge +from ...knowledge.knowledge_operations import KnowledgeReader +from ...knowledge.research import research_knowledge +from ..campaign import capture_context, create_campaign +from ..inspection import inspect_environment +from ..knowledge import knowledge_reader +from ..knowledge import read as read_knowledge +from ..legacy.reporting import write_report from .arguments import device_ids, make_spec, parser -from .knowledge.catalog import get_knowledge, search_knowledge -from .knowledge.knowledge_operations import KnowledgeReader -from .knowledge.research import research_knowledge def _print(value: object) -> None: @@ -24,8 +24,8 @@ def _print(value: object) -> None: def _fixed_attempt_command(args) -> int: - from .apps.api import read_attempt_view - from .harness.errors import PublicError + from ...harness.errors import PublicError + from ..api import read_attempt_view if args.storage_config is None: raise ValueError("--record-ref requires --storage-config") @@ -59,11 +59,11 @@ def _fixed_attempt_command(args) -> int: if command in ("status", "trace"): _print(view) elif live: - from .apps.views.dashboard_live import serve_dashboard + from ..views.dashboard_live import serve_dashboard serve_dashboard(None, port=args.port if args.port is not None else 8765, fixed_attempt=view) else: - from .apps.views.dashboard import write_attempt_document + from ..views.dashboard import write_attempt_document _print({command: str(write_attempt_document(view, args.output, kind=command))}) return 0 @@ -157,14 +157,14 @@ 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: _print(result) return 0 if args.command == "agents": - from .harness import agent_sessions + from ...harness import agent_sessions if args.agent_action == "prepare": result = agent_sessions.prepare( @@ -187,11 +187,11 @@ def main(argv: list[str] | None = None) -> int: return 0 if args.command == "benchmarks": if args.benchmark_action == "session": - from .harness.optimization_session import session_command + from ...harness.optimization_session import session_command task_source = None if args.session_action == "start": - from .benchmark.registry import task_resources + from ...benchmark.registry import task_resources task_source = Path(str(task_resources(args.task))) result = session_command( @@ -203,10 +203,10 @@ def main(argv: list[str] | None = None) -> int: _print(result) return 2 if result.get("state") == "blocked" else 0 if args.benchmark_action == "run": - from .benchmark_operations import run_task + from ...benchmark_operations import run_task return run_task(args.task, args.arguments) - from .benchmark.registry import builtin_tasks, describe_task + from ...benchmark.registry import builtin_tasks, describe_task if args.benchmark_action == "list": _print(builtin_tasks()) @@ -216,7 +216,7 @@ def main(argv: list[str] | None = None) -> int: if args.command == "skills": # Optional dependencies load only for the skills command; the core # CLI stays independent of them. - from .knowledge.skill_catalog import ( + from ...knowledge.skill_catalog import ( get_skill, skill_instructions, skill_records, @@ -393,14 +393,14 @@ def main(argv: list[str] | None = None) -> int: if args.live: if args.output is not None: raise ValueError("--output cannot be used with --live") - from .apps.views.dashboard_live import serve_dashboard + from ..views.dashboard_live import serve_dashboard serve_dashboard(args.input, args.translations, port=args.port if args.port is not None else 8765) else: if args.port is not None: raise ValueError("--port requires --live") - from .apps.views.dashboard import write_dashboard + from ..views.dashboard import write_dashboard _print({"dashboard": str(write_dashboard(args.input, args.output, args.translations))}) @@ -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, @@ -419,7 +419,7 @@ def main(argv: list[str] | None = None) -> int: _print({"context_directory": str(path), "reviewed_by_caller": False}) return 0 if getattr(args, "session_action", None) is not None: - from .harness.optimization_session import session_command + from ...harness.optimization_session import session_command result = session_command( args, @@ -429,7 +429,7 @@ def main(argv: list[str] | None = None) -> int: ) _print(result) return 2 if result.get("state") == "blocked" else 0 - from .harness.records.campaign_records import ( + from ...harness.records.campaign_records import ( assemble_trace, record_candidate, record_decision, @@ -437,7 +437,7 @@ def main(argv: list[str] | None = None) -> int: ) if args.campaign_action == "attach-profile": - from .harness.records.profile_timeline import attach_profile + from ...harness.records.profile_timeline import attach_profile _print(attach_profile(args.directory, capture_id=args.id, source=args.source, review=args.review)) @@ -458,7 +458,7 @@ def main(argv: list[str] | None = None) -> int: "sha256": digest}) return 0 if args.campaign_action == "import-search": - from .apps.views.search_attribution import import_search + from ..views.search_attribution import import_search path = import_search(args.directory, number=args.round, trace=args.trace, lines=args.lines, knowledge_root=args.knowledge_root, @@ -468,7 +468,7 @@ def main(argv: list[str] | None = None) -> int: _print({"record": path.relative_to(args.directory.resolve()).as_posix()}) return 0 if args.campaign_action == "log": - from .harness.records.optimization_log import record_log + from ...harness.records.optimization_log import record_log path, digest = record_log(args.directory, args.file) _print({"log": path.name, "sha256": digest}) @@ -544,7 +544,7 @@ def main(argv: list[str] | None = None) -> int: # The old run loads its Benchmark gates. Import it here so that the # other commands, including ordinary optimization, never load Benchmark. - from .apps.legacy.run import run_experiment + from ..legacy.run import run_experiment directory = run_experiment(spec, environment) (directory / "args.json").write_text( diff --git a/src/inferrsi/arguments.py b/src/inferrsi/apps/cli/arguments.py similarity index 99% rename from src/inferrsi/arguments.py rename to src/inferrsi/apps/cli/arguments.py index 4d63775a5..786d5486e 100644 --- a/src/inferrsi/arguments.py +++ b/src/inferrsi/apps/cli/arguments.py @@ -7,11 +7,10 @@ import sys from pathlib import Path -from . import __version__ -from .contracts import RunSpec -from .knowledge._skill_selection import RELEVANCE_METHODS -from .knowledge.catalog import BACKENDS, KNOWLEDGE_REPOS, KNOWLEDGE_SCOPES -from .resources.repository_packs import REPO_TYPES +from ... import __version__ +from ...contracts import RunSpec +from ...knowledge._skill_selection import RELEVANCE_METHODS +from ...knowledge.catalog import BACKENDS, KNOWLEDGE_REPOS, KNOWLEDGE_SCOPES, REPO_TYPES def _fixed_attempt_args( diff --git a/tests/_gate_policy_support.py b/tests/_gate_policy_support.py index f09c433f1..794725267 100644 --- a/tests/_gate_policy_support.py +++ b/tests/_gate_policy_support.py @@ -1,4 +1,4 @@ -"""First-wave isolation gate helpers (P0b, revised through #412 R1). +"""First-wave isolation gate helpers (P0b, revised through #408 A1). Imported by the import-gate and isolation-policy tests. This is a test support module, not a runtime package. @@ -19,10 +19,21 @@ CORE_NAMES = ("knowledge", "harness", "benchmark", "apps") # Current application seams, until the Apps package migration. These are not # Knowledge compatibility shells and do not grant access to other flat modules. -# #412 R1 retired the root shells that ``arguments.py`` read its Knowledge choices -# through, so the CLI parser is listed beside the CLI it belongs to. A1 (#408) moves -# both files into ``apps/cli/`` and removes both entries. -APPLICATION_ENTRIES = ("cli.py", "arguments.py", "benchmark_operations.py") +# A1 (#408) moved the CLI and its parser into ``apps/cli/`` and removed their two +# entries. That package is Apps by its first path segment, so a root ``cli.py`` or +# ``arguments.py`` that returns is an unlisted flat module. A2 removes the last entry. +APPLICATION_ENTRIES = ("benchmark_operations.py",) +# #408 A1, permanent: ``python -m inferrsi`` runs root ``__main__.py``, which stays in +# the package root and hands over to the canonical Apps CLI. The gate admits that one +# statement and nothing wider: this exact root file, this exact target module and this +# exact name, bound by a plain module-level ``from import `` line. It is +# not an ``APPLICATION_ENTRIES`` listing, so the file is never treated as Apps. Every +# other import in it of Apps, Knowledge or Benchmark fails as in any flat module. So do +# an alias, a second name, a star import, the target imported as a module object, a +# module beside or below the target, and the same line below module level. No other +# file is covered, in the root or under a package. +MODULE_ENTRY = "__main__.py" +MODULE_ENTRY_DELEGATION = ("inferrsi.apps.cli", "main") # Reviewed execution boundaries: owner function (or module scope) and the exact # local spec variable. They execute task resources/candidate code, not a hidden # core compatibility import. Their presence keeps isolation incomplete. @@ -37,7 +48,7 @@ # old-run forwarders and the root inspection binding. None is registered any more. # A file that returns under one of these names is a violation by itself, and every # checked closure still treats the name as an old root leaf it may not reach. -RETIRED_ROOT_MODULES = frozenset( +RETIRED_BY_R1 = frozenset( { "inferrsi._skill_selection", "inferrsi._source_snapshot", @@ -52,6 +63,10 @@ "inferrsi.inspection", } ) +# #408 A1 deleted the root CLI and its parser the same way, with no forwarder or alias. +# The implementation is ``inferrsi.apps.cli`` and ``inferrsi.apps.cli.arguments``. +RETIRED_BY_A1 = frozenset({"inferrsi.cli", "inferrsi.arguments"}) +RETIRED_ROOT_MODULES = RETIRED_BY_R1 | RETIRED_BY_A1 # #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 @@ -65,15 +80,10 @@ LEAF_IMPORTERS = { "inferrsi.infra.inspection": frozenset({"repository_pack"}), } -# #412 R1, temporary and due in A1 (#408): root ``catalog`` is retired, so the root CLI -# parser takes the one REPO_TYPES tuple from the leaf itself. The entry is held to the -# same exact shape as the permanent rule and names one module and one name. It is not -# part of that rule and not an Apps-wide allowance. While a listed module imports the -# leaf, the report carries a ``temporary leaf importers`` blocker, so isolation cannot -# be reported complete on it. A1 deletes root ``arguments.py`` and removes this entry. -TEMPORARY_LEAF_IMPORTERS = { - "inferrsi.arguments": frozenset({"REPO_TYPES"}), -} +# #408 A1 removed the temporary entry that let root ``arguments.py`` bind REPO_TYPES from +# the leaf, together with its ``temporary leaf importers`` blocker. Nothing replaced it: +# the moved parser reads the same tuple object through ``inferrsi.knowledge.catalog``, +# and an Apps module that names the leaf fails as a second importer like any other. # New H entries: module paths whose closures count toward the new-core result. # H01 added ``run_store`` and ``errors``; H02 added the public ``api`` with # ``execution_service``, ``input_binding`` and ``local_process``. @@ -121,11 +131,35 @@ def _from_base(node: ast.ImportFrom, package: str) -> str: return ".".join(keep + ([node.module] if node.module else [])) -def _modules_in_source(source: str, package_parts: list[str]) -> list[str]: - """Resolve import targets, including ``from package import name`` forms.""" +def _is_entry_delegation(node: ast.stmt, package: str) -> bool: + """The module entry's one admitted statement, in its exact plain shape.""" + module, name = MODULE_ENTRY_DELEGATION + return ( + isinstance(node, ast.ImportFrom) + and _from_base(node, package) == module + and [(alias.name, alias.asname) for alias in node.names] == [(name, None)] + ) + + +def _modules_in_source( + source: str, package_parts: list[str], module_entry: bool = False +) -> list[str]: + """Resolve import targets, including ``from package import name`` forms. + + For the module entry only, its admitted delegation statement is left out where it + stands at module level. Every other import in that file is resolved as usual. + """ package = ".".join(package_parts) + tree = ast.parse(source) + admitted = { + id(node) + for node in tree.body + if module_entry and _is_entry_delegation(node, package) + } names: list[str] = [] - for node in ast.walk(ast.parse(source)): + for node in ast.walk(tree): + if id(node) in admitted: + continue if isinstance(node, ast.Import): names.extend(alias.name for alias in node.names) elif isinstance(node, ast.ImportFrom): @@ -156,6 +190,7 @@ def _imported_modules(path: Path, root: Path) -> list[str]: return _modules_in_source( path.read_text(encoding="utf-8"), ["inferrsi", *relative.parts[:-1]], + module_entry=relative.as_posix() == MODULE_ENTRY, ) @@ -188,6 +223,8 @@ def cross_core_violations( of ``inferrsi.knowledge``, ``inferrsi.benchmark``, or ``inferrsi.apps`` is forbidden, as is Knowledge or Benchmark importing Harness. ``allowed`` holds exact (importer module, target module) pairs; a prefix never counts. + The one other admission is the ``MODULE_ENTRY`` delegation statement: that + exact statement in that exact root file, and no other import in it. """ modules = _module_index(root) found: set[tuple[str, str]] = set() @@ -673,9 +710,9 @@ def first_wave_report( for name in modules if name in RETIRED_ROOT_MODULES and name not in sources ] - # Outside Knowledge the leaf has its one permanent importer, the temporary entry - # due in A1 and any staged pair that names it. Every other importer fails. - declared_importers = {**TEMPORARY_LEAF_IMPORTERS, **LEAF_IMPORTERS} + # Outside Knowledge the leaf has its one permanent importer and any staged pair + # that names it. Every other importer fails. + declared_importers = dict(LEAF_IMPORTERS) leaf_importers = {importer for importer, target in pairs if target == leaf} leaf_importers |= set(declared_importers) violations += [ @@ -774,12 +811,6 @@ def h_entry_forbidden(node: str) -> bool: # #412 R1 left the manifest with no pair. One that review stages again blocks. if pairs: blockers.append(f"allowlist: {len(pairs)} compatibility pairs") - temporary = [ - name for name in sorted(TEMPORARY_LEAF_IMPORTERS) - if leaf in graph.edges.get(name, ()) - ] - if temporary: - blockers.append(f"temporary leaf importers: {len(temporary)}") legacy = [ path for name in modules diff --git a/tests/check_installed.py b/tests/check_installed.py index 8672c273f..93102e98b 100644 --- a/tests/check_installed.py +++ b/tests/check_installed.py @@ -12,8 +12,8 @@ import inferrsi import inferrsi.harness +from inferrsi.apps.cli import main from inferrsi.benchmark.registry import builtin_tasks, describe_task, task_resources -from inferrsi.cli import main from inferrsi.contracts import RunSpec, claim, evidence, json_v1 from inferrsi.knowledge._source_snapshot import BUNDLE_LIBRARY, LIBRARY from inferrsi.knowledge.catalog import knowledge_records, search_knowledge @@ -594,7 +594,7 @@ def _inventory(root, prefix): # #451 C2: the neutral repository-pack facade and the evidence path rules ship at their # canonical paths. The two retired root modules are not in the wheel and have no alias. assert repository_packs.REPO_TYPES is REPO_TYPES and len(REPO_TYPES) == 7 -for consumer in ("inferrsi.knowledge.catalog", "inferrsi.arguments"): +for consumer in ("inferrsi.knowledge.catalog", "inferrsi.apps.cli.arguments"): assert import_module(consumer).REPO_TYPES is REPO_TYPES, consumer for repo_name in REPO_TYPES: packed = files("inferrsi").joinpath("harness", "data", "repo_packs", repo_name, "pack.json") @@ -648,16 +648,24 @@ def _inventory(root, prefix): 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", "arguments.py", - "benchmark_operations.py", "cli.py", "mindie_context.py", "mindie_mcp.py", - "mindie_project.py", "summary_chart.py", + "__init__.py", "__main__.py", "_mindie_read_worker.py", "benchmark_operations.py", + "mindie_context.py", "mindie_mcp.py", "mindie_project.py", "summary_chart.py", }, sorted(installed_root) +# #408 A1: the CLI and its parser ship only as inferrsi.apps.cli; neither root name imports. +for a1_retired in ("cli", "arguments"): + try: + import_module(f"inferrsi.{a1_retired}") + except ModuleNotFoundError: + pass + else: + raise AssertionError(f"retired module inferrsi.{a1_retired} must not import") +assert main.__module__ == "inferrsi.apps.cli" host_inspection = import_module("inferrsi.apps.inspection") assert host_inspection._command is import_module("inferrsi.infra.commands").probe_command assert host_inspection.repository_identity is ( import_module("inferrsi.infra.targets").repository_identity ) -assert import_module("inferrsi.arguments").REPO_TYPES is REPO_TYPES +assert import_module("inferrsi.apps.cli.arguments").REPO_TYPES is REPO_TYPES # A fresh isolated interpreter reads all seven packs with only the facade and its # import-free parent loaded: no Harness, Knowledge, Infra or Apps module. facade_probe = ( diff --git a/tests/test_agent_sessions.py b/tests/test_agent_sessions.py index dba26f166..c79c366e8 100644 --- a/tests/test_agent_sessions.py +++ b/tests/test_agent_sessions.py @@ -5,7 +5,7 @@ import pytest -from inferrsi.cli import main +from inferrsi.apps.cli import main from inferrsi.harness import agent_sessions diff --git a/tests/test_apps_assess.py b/tests/test_apps_assess.py index 7114ba63e..68da11127 100644 --- a/tests/test_apps_assess.py +++ b/tests/test_apps_assess.py @@ -15,8 +15,8 @@ from inferrsi.apps.api import EvaluationPort, read_attempt_view from inferrsi.apps.api import assess as run_assess from inferrsi.apps.artifact_reader import ArtifactReader +from inferrsi.apps.cli import main from inferrsi.apps.views.dashboard_live import DashboardServer -from inferrsi.cli import main from inferrsi.contracts.json_v1 import decode, encode from inferrsi.harness.errors import PublicError from inferrsi.harness.run_store import RunStore diff --git a/tests/test_benchmark_operations.py b/tests/test_benchmark_operations.py index 43820c22a..e38e0d439 100644 --- a/tests/test_benchmark_operations.py +++ b/tests/test_benchmark_operations.py @@ -5,8 +5,8 @@ import pytest from inferrsi import benchmark_operations +from inferrsi.apps.cli import main from inferrsi.benchmark import registry -from inferrsi.cli import main @pytest.fixture diff --git a/tests/test_campaign_record_injection.py b/tests/test_campaign_record_injection.py index 8842bfd75..b0957b4ee 100644 --- a/tests/test_campaign_record_injection.py +++ b/tests/test_campaign_record_injection.py @@ -16,6 +16,8 @@ from tests._gate_policy_support import ( NEW_H_ENTRIES, REPO, + RETIRED_BY_A1, + RETIRED_BY_R1, RETIRED_ROOT_MODULES, ROOT, first_wave_report, @@ -363,9 +365,15 @@ def _record_modules(): def test_harness_records_load_no_knowledge_or_apps_module(): - # #412 R1 retired the root shells; none of those names may be loaded either. + # #412 R1 retired eleven root modules and #408 A1 retired the root CLI and its parser. + # None of those thirteen names may be loaded either. + assert len(RETIRED_BY_R1) == 11 + assert RETIRED_BY_A1 == {"inferrsi.cli", "inferrsi.arguments"} + assert not RETIRED_BY_R1 & RETIRED_BY_A1 + assert RETIRED_ROOT_MODULES == RETIRED_BY_R1 | RETIRED_BY_A1 leaves = sorted(RETIRED_ROOT_MODULES) - assert len(leaves) == 11 + assert len(leaves) == 13 + assert {"inferrsi.cli", "inferrsi.arguments"} <= set(leaves) script = ( "import importlib, sys\n" f"for name in {_record_modules()!r}:\n" diff --git a/tests/test_campaign_records.py b/tests/test_campaign_records.py index 54389823d..3bae552cf 100644 --- a/tests/test_campaign_records.py +++ b/tests/test_campaign_records.py @@ -4,8 +4,8 @@ import pytest +from inferrsi.apps.cli import main from inferrsi.apps.views.dashboard_data import load_dashboard -from inferrsi.cli import main from inferrsi.harness.records.campaign_records import ( create_campaign, record_candidate, diff --git a/tests/test_cli_catalog.py b/tests/test_cli_catalog.py index f9649da13..962301bcb 100644 --- a/tests/test_cli_catalog.py +++ b/tests/test_cli_catalog.py @@ -13,8 +13,8 @@ import pytest -from inferrsi.arguments import make_spec, parser -from inferrsi.cli import main +from inferrsi.apps.cli import main +from inferrsi.apps.cli.arguments import make_spec, parser from inferrsi.knowledge import catalog as knowledge_catalog from inferrsi.knowledge.catalog import get_knowledge, knowledge_records, search_knowledge from inferrsi.resources.repository_packs import REPO_TYPES, repository_pack diff --git a/tests/test_collect_selection.py b/tests/test_collect_selection.py index 49cb5fde5..577923284 100644 --- a/tests/test_collect_selection.py +++ b/tests/test_collect_selection.py @@ -4,7 +4,7 @@ import pytest -from inferrsi.cli import main +from inferrsi.apps.cli import main from inferrsi.knowledge._skill_selection import lexical_score from inferrsi.knowledge.knowledge_operations import Bundle, KnowledgeReader, _hash, _json from inferrsi.knowledge.knowledge_store import KnowledgeStore diff --git a/tests/test_contracts_package.py b/tests/test_contracts_package.py index 533d419ff..b8644389e 100644 --- a/tests/test_contracts_package.py +++ b/tests/test_contracts_package.py @@ -21,7 +21,7 @@ import inferrsi.contracts as contracts import inferrsi.harness as harness -from inferrsi import arguments +from inferrsi.apps.cli import arguments from inferrsi.apps.legacy import evaluation as legacy_evaluation from inferrsi.apps.legacy import run as legacy_run from inferrsi.contracts import RunSpec, claim, json_v1, runspec diff --git a/tests/test_dashboard_live.py b/tests/test_dashboard_live.py index b65ededbb..e23fe0f37 100644 --- a/tests/test_dashboard_live.py +++ b/tests/test_dashboard_live.py @@ -14,10 +14,10 @@ import pytest +from inferrsi.apps.cli import main from inferrsi.apps.views import dashboard_live from inferrsi.apps.views.dashboard import write_dashboard from inferrsi.apps.views.dashboard_live import DashboardServer -from inferrsi.cli import main @pytest.fixture diff --git a/tests/test_engineering_benchmarks.py b/tests/test_engineering_benchmarks.py index 6572e6423..6436f7e21 100644 --- a/tests/test_engineering_benchmarks.py +++ b/tests/test_engineering_benchmarks.py @@ -8,8 +8,8 @@ import pytest +from inferrsi.apps.cli import main from inferrsi.benchmark.registry import builtin_tasks, describe_task, task_resources -from inferrsi.cli import main from inferrsi.harness import optimization_session EXPECTED = { @@ -90,7 +90,9 @@ def call(command, *, env): sys.executable, str(Path(optimization_session.__file__).resolve()), str(task_resources(name).joinpath("benchmark.py")), *arguments ] - assert (Path(env["PYTHONPATH"].split(os.pathsep)[0]) / "inferrsi" / "cli.py").is_file() + package = Path(env["PYTHONPATH"].split(os.pathsep)[0]) / "inferrsi" + assert (package / "apps" / "cli" / "__init__.py").is_file() + assert not (package / "cli.py").exists() assert env["PYTHONDONTWRITEBYTECODE"] == "1" return exit_code diff --git a/tests/test_first_wave_isolation_policy.py b/tests/test_first_wave_isolation_policy.py index b93261179..fdab48c00 100644 --- a/tests/test_first_wave_isolation_policy.py +++ b/tests/test_first_wave_isolation_policy.py @@ -22,7 +22,10 @@ LEAF = MANIFEST["technical_leaf"]["module"] # #412 R1 emptied the allowlist. The nine retired pair records stay in the manifest # history. Staging them again drives the staged-pair rules that the gate still holds. -RETIRED_PAIRS = MANIFEST["revision_history"][-1]["retired_compatibility_pairs"] +C2_RECORD = next( + item for item in MANIFEST["revision_history"] if "retired_compatibility_pairs" in item +) +RETIRED_PAIRS = C2_RECORD["retired_compatibility_pairs"] STAGED = {**MANIFEST, "compatibility_pairs": RETIRED_PAIRS} STAGED_PAIRS = exact_pairs(STAGED) SOURCES = shell_sources(STAGED) @@ -113,8 +116,11 @@ def _k01_tree() -> dict[str, str]: return files -# The two declared importers of the data leaf, as the real tree writes them. +# The one declared importer of the data leaf, as the real tree writes it. INSPECTION = "from ..resources.repository_packs import repository_pack\n" +# #408 A1: the moved CLI parser reads the tuple through Knowledge and names no leaf. +PARSER = "from ...knowledge.catalog import BACKENDS, REPO_TYPES\n" +# The root parser that A1 deleted, as R1 left it. It is refused if it returns. ARGUMENTS = ( "from .knowledge.catalog import BACKENDS\n" "from .resources.repository_packs import REPO_TYPES\n" @@ -122,13 +128,14 @@ def _k01_tree() -> dict[str, str]: def _r1_tree() -> dict[str, str]: - """The R1 shape: the K01 tree with no root shell, plus the root CLI parser.""" + """The post-A1 shape: the K01 tree with no root shell and the CLI under apps/cli.""" files = { relative: source for relative, source in _k01_tree().items() if f"inferrsi.{relative.removesuffix('.py')}" not in SOURCES } - files["arguments.py"] = ARGUMENTS + files["apps/cli/__init__.py"] = "from .arguments import parser\n" + files["apps/cli/arguments.py"] = PARSER return files @@ -184,7 +191,7 @@ def test_allowlist_is_empty_and_the_nine_retired_pairs_are_recorded(self) -> Non self.assertLess(set(SOURCES), support.RETIRED_ROOT_MODULES) self.assertEqual(LEAF, "inferrsi.resources.repository_packs") self.assertEqual( - MANIFEST["revision_history"][-1]["retired_catalog_two_routes"][ + C2_RECORD["retired_catalog_two_routes"][ "neutral_leaf_export" ]["target"], LEAF, @@ -279,7 +286,7 @@ def test_only_declared_infra_importer_may_use_the_leaf(self) -> None: self.assertEqual(report.violations, ()) infra_leaf = { importer - for importer in (*support.LEAF_IMPORTERS, *support.TEMPORARY_LEAF_IMPORTERS) + for importer in support.LEAF_IMPORTERS if importer.startswith("inferrsi.infra") } self.assertEqual(infra_leaf, {"inferrsi.infra.inspection"}) @@ -346,36 +353,34 @@ def test_the_rule_is_one_importer_and_one_name_and_not_a_pair(self) -> None: support.LEAF_IMPORTERS, {"inferrsi.infra.inspection": frozenset({"repository_pack"})}, ) - self.assertEqual( - support.TEMPORARY_LEAF_IMPORTERS, - {"inferrsi.arguments": frozenset({"REPO_TYPES"})}, - ) + # #408 A1 removed the temporary parser entry; the gate declares nothing else. + self.assertFalse(hasattr(support, "TEMPORARY_LEAF_IMPORTERS")) + self.assertNotIn("temporary_importers", MANIFEST["technical_leaf"]) self.assertEqual(MANIFEST["compatibility_pairs"], []) # No Knowledge, Harness, Benchmark or Apps module is declared, and no prefix. - for importer in (*support.LEAF_IMPORTERS, *support.TEMPORARY_LEAF_IMPORTERS): + for importer in support.LEAF_IMPORTERS: self.assertIsNone(support._core_of(importer), importer) self.assertNotIn("*", importer) def test_the_permanent_rule_alone_does_not_block(self) -> None: # The infra edge is admitted with nothing staged and adds no blocker. - report = _report({"arguments.py": None}) + report = _report({}) self.assertEqual(report.violations, ()) self.assertEqual(report.blockers, ()) self.assertTrue(report.isolation_complete) - def test_the_temporary_parser_entry_blocks_until_a1_removes_it(self) -> None: + def test_a1_removed_the_temporary_parser_entry_and_nothing_replaced_it(self) -> None: report = _report({}) self.assertEqual(report.violations, ()) - self.assertEqual(report.blockers, ("temporary leaf importers: 1",)) + self.assertEqual(report.blockers, ()) self.assertTrue(report.new_core_closure_isolated) - self.assertFalse(report.isolation_complete) - # The entry names root arguments.py only. The parser at an Apps path, or any - # other Apps module, is not covered by it. - for path in ("apps/cli/arguments.py", "apps/main.py", "cli.py"): + # The moved parser reads through Knowledge. Naming the leaf from the parser, the + # CLI package, another Apps module or a returning root file is a second importer. + for path in ("apps/cli/arguments.py", "apps/cli/__init__.py", "apps/main.py", + "cli.py", "arguments.py"): with self.subTest(path=path): moved = _report( - {"arguments.py": None, path: "from inferrsi.resources.repository_packs " - "import REPO_TYPES\n"} + {path: "from inferrsi.resources.repository_packs import REPO_TYPES\n"} ) self.assertTrue(_violated(moved, f"is a second importer of {LEAF}"), moved.violations) @@ -387,18 +392,23 @@ def test_the_edge_is_admitted_by_the_rule_and_not_by_an_erased_scan(self) -> Non _violated(report, f"inferrsi.infra.inspection is a second importer of {LEAF}"), report.violations, ) - with mock.patch.dict(support.TEMPORARY_LEAF_IMPORTERS, clear=True): - report = _report({}) - self.assertTrue( - _violated(report, f"inferrsi.arguments is a second importer of {LEAF}"), - report.violations, - ) + # The root parser that A1 deleted is refused on every count if it returns, and + # no blocker-only entry admits it any more. + report = _report({"arguments.py": ARGUMENTS}) + for expected in ( + f"inferrsi.arguments is a second importer of {LEAF}", + "inferrsi.arguments is a retired root module", + "arguments.py imports inferrsi.knowledge", + ): + self.assertTrue(_violated(report, expected), report.violations) + self.assertNotIn("temporary leaf importers", blocker_kinds(report)) + self.assertFalse(report.isolation_complete) def test_staging_the_infra_pair_again_blocks(self) -> None: pair = [item for item in RETIRED_PAIRS if item["importer"] == "infra.inspection"] self.assertEqual(len(pair), 1) report = _report( - {"arguments.py": None}, manifest={**MANIFEST, "compatibility_pairs": pair} + {}, manifest={**MANIFEST, "compatibility_pairs": pair} ) self.assertEqual(report.violations, ()) self.assertEqual(report.blockers, ("allowlist: 1 compatibility pairs",)) @@ -409,7 +419,8 @@ def test_another_importer_fails(self) -> None: "infra/other.py", "infra/inspection_helpers.py", "infra/__init__.py", "infra/platforms/__init__.py", "harness/api.py", "harness/runner.py", "benchmark/probe.py", "apps/main.py", "apps/inspection.py", "model/probe.py", - "cli.py", "benchmark_operations.py", "helper.py", "catalog.py", + "cli.py", "arguments.py", "apps/cli/__init__.py", "apps/cli/arguments.py", + "benchmark_operations.py", "helper.py", "catalog.py", "_repo_pack_data.py", ) for path in paths: @@ -427,9 +438,6 @@ def test_declared_importer_shape_is_exact(self) -> None: declared = ( ("infra/inspection.py", "inferrsi.infra.inspection", INSPECTION, "repository_pack", "REPO_TYPES"), - ("arguments.py", "inferrsi.arguments", - "from .resources.repository_packs import REPO_TYPES\n", - "REPO_TYPES", "repository_pack"), ) for path, module, line, name, other in declared: clean = _report({path: line, "resources/extra.py": None}) @@ -479,8 +487,12 @@ class RetiredRootModuleTest(unittest.TestCase): """#412 R1: the eleven deleted root modules cannot return, as any kind of file.""" 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_ROOT_MODULES, support.RETIRED_BY_R1 | support.RETIRED_BY_A1 + ) self.assertEqual( - support.RETIRED_ROOT_MODULES, + support.RETIRED_BY_R1, { "inferrsi._skill_selection", "inferrsi._source_snapshot", "inferrsi.catalog", "inferrsi.knowledge_operations", "inferrsi.knowledge_store", @@ -1219,7 +1231,6 @@ def test_each_trigger_alone_keeps_overall_false(self) -> None: ("absent: benchmark/", {"benchmark/__init__.py": None}, EMPTY_ALLOWLIST), ("absent: apps/", {"apps/__init__.py": None, "apps/main.py": None}, EMPTY_ALLOWLIST), ("allowlist: 9 compatibility pairs", {}, STAGED), - ("temporary leaf importers: 1", {"arguments.py": ARGUMENTS}, EMPTY_ALLOWLIST), ( "harness reaches model/infra: inferrsi.harness.skill_evaluation" " -> inferrsi.infra", @@ -1285,7 +1296,6 @@ def test_empty_package_directories_are_unscannable(self) -> None: def test_clean_new_core_graph_never_sets_overall_true(self) -> None: for report, kinds in ( (_staged({}), {"allowlist"}), - (_report({}), {"temporary leaf importers"}), ): with self.subTest(kinds=kinds): self.assertEqual(report.violations, ()) diff --git a/tests/test_h3_knowledge.py b/tests/test_h3_knowledge.py index 174670a4d..c93c2e45b 100644 --- a/tests/test_h3_knowledge.py +++ b/tests/test_h3_knowledge.py @@ -5,7 +5,7 @@ import re from pathlib import Path -from inferrsi.cli import main +from inferrsi.apps.cli import main from inferrsi.knowledge.catalog import get_knowledge, search_knowledge from inferrsi.knowledge.knowledge_operations import KnowledgeReader from inferrsi.knowledge.skill_catalog import get_skill, skill_metadata, skill_resource diff --git a/tests/test_knowledge_cli.py b/tests/test_knowledge_cli.py index b0e184145..fc5ad0008 100644 --- a/tests/test_knowledge_cli.py +++ b/tests/test_knowledge_cli.py @@ -8,7 +8,7 @@ import pytest -from inferrsi.cli import main +from inferrsi.apps.cli import main from inferrsi.knowledge.knowledge_operations import Bundle, KnowledgeReader from inferrsi.knowledge.knowledge_store import KnowledgeStore diff --git a/tests/test_knowledge_compatibility_shells.py b/tests/test_knowledge_compatibility_shells.py index a51b37408..dbd6c4825 100644 --- a/tests/test_knowledge_compatibility_shells.py +++ b/tests/test_knowledge_compatibility_shells.py @@ -15,12 +15,12 @@ import pytest +from tests import _gate_policy_support as support from tests._gate_policy_support import ( LEAF_IMPORTERS, REPO, RETIRED_ROOT_MODULES, ROOT, - TEMPORARY_LEAF_IMPORTERS, exact_pairs, first_wave_report, load_manifest, @@ -29,7 +29,10 @@ MANIFEST = load_manifest() LEAF = MANIFEST["technical_leaf"] # The nine pairs and the two root catalog routes as they stood before R1 retired them. -RETIRED = MANIFEST["revision_history"][-1] +HISTORY = MANIFEST["revision_history"] +RETIRED = next(item for item in HISTORY if "retired_compatibility_pairs" in item) +# #408 A1 appended the R1 record, which holds the temporary parser entry it removed. +R1_RECORD = HISTORY[-1] LEAF_NAMES = RETIRED["retired_catalog_two_routes"]["neutral_leaf_export"]["symbols"] MOVED = [item for item in RETIRED["retired_compatibility_pairs"] if "exports" in item] @@ -61,7 +64,12 @@ def test_retired_record_is_the_seven_shells_and_the_manifest_stages_nothing(): assert exact_pairs(MANIFEST) == frozenset() assert "catalog_two_routes" not in MANIFEST assert RETIRED["stage"] == "C2" - assert MANIFEST["base_commit"] in RETIRED["superseded_by"] + assert R1_RECORD["stage"] == "R1" and HISTORY[-2] is RETIRED + assert R1_RECORD["base_commit"] in RETIRED["superseded_by"] + # Every record names the base commit of the revision that superseded it. + bases = [item["base_commit"] for item in HISTORY[1:]] + [MANIFEST["base_commit"]] + for item, following in zip(HISTORY, bases): + assert following in item["superseded_by"], item["stage"] assert len(RETIRED["retired_compatibility_pairs"]) == 9 assert len(MOVED) == 7 assert {f"inferrsi.{item['importer']}" for item in MOVED} < RETIRED_ROOT_MODULES @@ -73,13 +81,13 @@ def test_retired_record_is_the_seven_shells_and_the_manifest_stages_nothing(): def test_one_repo_types_tuple_reaches_knowledge_and_the_parser_directly(): - from inferrsi import arguments + from inferrsi.apps.cli import arguments from inferrsi.knowledge import catalog as knowledge_catalog from inferrsi.resources import repository_packs assert knowledge_catalog.REPO_TYPES is repository_packs.REPO_TYPES - # Root catalog is retired, so the CLI parser binds the tuple from the leaf itself: - # still one object, never a copy. + # #408 A1: the Apps parser reads the tuple through the Knowledge catalog, which + # binds it from the leaf: still one object on every route, never a copy. assert arguments.REPO_TYPES is repository_packs.REPO_TYPES assert LEAF_NAMES == ["REPO_TYPES", "repository_pack"] assert not hasattr(arguments, "repository_pack") @@ -127,14 +135,14 @@ def test_c2_relock_moves_the_leaf_without_changing_a_byte(): assert "requires formal architecture review" in moved["review"] assert "does not self-approve" in moved["review"] # R1 appended the C2 record after the K02 one and rewrote neither. - k02, c2 = MANIFEST["revision_history"][-2:] + k02, c2 = HISTORY[2:4] assert (k02["stage"], c2["stage"]) == ("K02", "C2") assert k02["changed_technical_leaf"] == { "module": moved["old_module"], "file": moved["old_file"], } assert c2["base_commit"] in k02["superseded_by"] - assert MANIFEST["base_commit"] in c2["superseded_by"] - assert MANIFEST["base_commit"] != c2["base_commit"] + assert R1_RECORD["base_commit"] in c2["superseded_by"] + assert R1_RECORD["base_commit"] != c2["base_commit"] def _leaf_imports(tree: ast.Module) -> set[str]: @@ -194,13 +202,19 @@ def _declared(section: str) -> dict[str, frozenset[str]]: def test_manifest_restates_the_exact_gate_importer_rules(): # #412 R1: the permanent rule is one importer and one name, outside the allowlist. - permanent, temporary = LEAF["permanent_importers"], LEAF["temporary_importers"] + permanent = LEAF["permanent_importers"] + temporary = R1_RECORD["retired_temporary_importers"] assert _declared("permanent_importers") == LEAF_IMPORTERS == { "inferrsi.infra.inspection": frozenset({"repository_pack"}), } - assert _declared("temporary_importers") == TEMPORARY_LEAF_IMPORTERS == { - "inferrsi.arguments": frozenset({"REPO_TYPES"}), - } + # #408 A1 removed the temporary parser entry from the manifest and from the gate. + # The removed record is kept unchanged in the history, and nothing replaced it. + assert "temporary_importers" not in LEAF + assert not hasattr(support, "TEMPORARY_LEAF_IMPORTERS") + assert [(item["importer"], item["names"]) for item in temporary["importers"]] == [ + ("inferrsi.arguments", ["REPO_TYPES"]) + ] + assert not (REPO / temporary["importers"][0]["file"]).exists() assert MANIFEST["compatibility_pairs"] == [] assert permanent["importers"][0]["import_line"] == ( MANIFEST["infra_inspection_rewrite"]["canonical_import"] @@ -214,10 +228,10 @@ def test_manifest_restates_the_exact_gate_importer_rules(): assert temporary["due"] == "A1 (#408)" assert "temporary leaf importers" in temporary["blocker"] assert "not an allowance for Apps modules in general" in temporary["rule"] - assert "temporary leaf importers: 1" in first_wave_report().blockers + assert "temporary leaf importers" not in support.blocker_kinds(first_wave_report()) -@pytest.mark.parametrize("section", ["permanent_importers", "temporary_importers"]) +@pytest.mark.parametrize("section", ["permanent_importers"]) def test_each_declared_importer_binds_the_leaf_by_its_one_recorded_line(section): for item in LEAF[section]["importers"]: source = (REPO / item["file"]).read_text(encoding="utf-8") @@ -274,7 +288,6 @@ def test_knowledge_closure_is_clean_while_overall_stays_false(): report = first_wave_report() assert report.violations == () assert report.blockers == ( - "temporary leaf importers: 1", "harness reaches model/infra: inferrsi.harness.agent_sessions -> inferrsi.infra (12 hits)", "runtime resource loaders: 5", ) diff --git a/tests/test_knowledge_tiers.py b/tests/test_knowledge_tiers.py index 0d86edaab..e80ddb03c 100644 --- a/tests/test_knowledge_tiers.py +++ b/tests/test_knowledge_tiers.py @@ -6,8 +6,8 @@ import pytest -from inferrsi.arguments import parser -from inferrsi.cli import main +from inferrsi.apps.cli import main +from inferrsi.apps.cli.arguments import parser from inferrsi.knowledge import catalog as knowledge_catalog from inferrsi.knowledge.catalog import get_knowledge, search_knowledge from inferrsi.resources.repository_packs import repository_pack diff --git a/tests/test_legacy_run_forwarder_gate.py b/tests/test_legacy_run_forwarder_gate.py index 0c2435f25..965ecedbb 100644 --- a/tests/test_legacy_run_forwarder_gate.py +++ b/tests/test_legacy_run_forwarder_gate.py @@ -96,6 +96,6 @@ def test_real_tree_holds_no_forwarder_and_stays_incomplete(): assert not (support.ROOT / f"{name}.py").exists(), name # What is left belongs to R2 and R3, plus the parser entry due in A1. assert support.blocker_kinds(report) == { - "temporary leaf importers", "harness reaches model/infra", "runtime resource loaders", + "harness reaches model/infra", "runtime resource loaders", } assert not report.isolation_complete diff --git a/tests/test_legacy_run_split.py b/tests/test_legacy_run_split.py index 8b7136cb6..2d73f811a 100644 --- a/tests/test_legacy_run_split.py +++ b/tests/test_legacy_run_split.py @@ -327,7 +327,7 @@ def unavailable(*args, **kwargs): def test_cli_import_loads_no_benchmark_and_no_old_run_composition(): # Only the `run` command loads the old run and its Benchmark gates. code = ( - "import sys; sys.path.insert(0, sys.argv[1]); import inferrsi.cli; " + "import sys; sys.path.insert(0, sys.argv[1]); import inferrsi.apps.cli; " "print(sorted(name for name in sys.modules if name.startswith(('inferrsi.benchmark', " "'inferrsi.execution', 'inferrsi.evaluation', 'inferrsi.reporting', " "'inferrsi.inspection', 'inferrsi.apps.legacy.run', " diff --git a/tests/test_legacy_run_v0_frozen.py b/tests/test_legacy_run_v0_frozen.py index 4494e59b4..3ab2f3a94 100644 --- a/tests/test_legacy_run_v0_frozen.py +++ b/tests/test_legacy_run_v0_frozen.py @@ -2,7 +2,7 @@ # # The goldens in tests/fixtures/legacy_run_v0 were written by the chain as it # stood before evaluation moved to Benchmark and composition moved to Apps. Each -# scenario enters through the unchanged `inferrsi.cli` `run` command, so the +# scenario enters through the unchanged `inferrsi.apps.cli` `run` command, so the # same file compares the chain before and after that move. import contextlib @@ -17,7 +17,7 @@ import pytest -from inferrsi.cli import main +from inferrsi.apps.cli import main FIXTURES = Path(__file__).resolve().parent / "fixtures" GOLDENS = FIXTURES / "legacy_run_v0" diff --git a/tests/test_mindie_context.py b/tests/test_mindie_context.py index 24e7787fb..9477026be 100644 --- a/tests/test_mindie_context.py +++ b/tests/test_mindie_context.py @@ -8,8 +8,8 @@ import pytest +from inferrsi.apps.cli import main from inferrsi.apps.views.dashboard_data import load_dashboard -from inferrsi.cli import main from inferrsi.harness.records.campaign_records import create_campaign from inferrsi.mindie_context import export_context diff --git a/tests/test_mindie_project.py b/tests/test_mindie_project.py index 92977412d..8c9f3895f 100644 --- a/tests/test_mindie_project.py +++ b/tests/test_mindie_project.py @@ -3,7 +3,7 @@ from pathlib import Path from inferrsi import mindie_mcp, mindie_project -from inferrsi.cli import main +from inferrsi.apps.cli import main 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 6741d0751..b95a86e0b 100644 --- a/tests/test_mindie_runtime.py +++ b/tests/test_mindie_runtime.py @@ -239,7 +239,7 @@ def test_mcp_stdio_round_trip(reader, tmp_path, monkeypatch, oversized_line): source = str(Path(mindie_project.__file__).resolve().parents[1]) process = subprocess.run( [sys.executable, "-I", "-B", "-c", f"import sys; sys.path.insert(0, {source!r}); " - "from inferrsi.cli import main; raise SystemExit(main(['mindie', 'serve']))"], + "from inferrsi.apps.cli import main; raise SystemExit(main(['mindie', 'serve']))"], input=wire, text=True, capture_output=True, timeout=30, check=True, ) assert process.stderr == "" diff --git a/tests/test_mlx_discovery.py b/tests/test_mlx_discovery.py index 019447f90..d987ca4ea 100644 --- a/tests/test_mlx_discovery.py +++ b/tests/test_mlx_discovery.py @@ -5,7 +5,7 @@ import pytest -from inferrsi.cli import main +from inferrsi.apps.cli import main from inferrsi.infra.commands import probe_command from inferrsi.infra.platforms import inspect_device from inferrsi.infra.platforms.mlx import _parse_sysctl_info diff --git a/tests/test_module_boundaries.py b/tests/test_module_boundaries.py index 4834beb2c..0b1ab0ea8 100644 --- a/tests/test_module_boundaries.py +++ b/tests/test_module_boundaries.py @@ -133,7 +133,7 @@ def test_control_imports_need_no_inference_or_image_dependencies(): [ sys.executable, "-c", - "import sys; import inferrsi.cli; " + "import sys; import inferrsi.apps.cli; " "import inferrsi.model.validators.image; " "assert not {'torch', 'vllm', 'numpy', 'PIL', 'skimage'}.intersection(sys.modules)", ], diff --git a/tests/test_optimization_session.py b/tests/test_optimization_session.py index dc6f5987a..52bd3bbfc 100644 --- a/tests/test_optimization_session.py +++ b/tests/test_optimization_session.py @@ -4,8 +4,8 @@ import pytest +from inferrsi.apps.cli import main from inferrsi.benchmark import registry -from inferrsi.cli import main from inferrsi.harness import optimization_session from inferrsi.harness.optimization import _locked diff --git a/tests/test_optimization_story.py b/tests/test_optimization_story.py index 667aba66e..f4989d6d0 100644 --- a/tests/test_optimization_story.py +++ b/tests/test_optimization_story.py @@ -10,9 +10,9 @@ import pytest from inferrsi.apps.campaign import capture_context, verify_capture +from inferrsi.apps.cli import main from inferrsi.apps.views.dashboard import dashboard_snapshot, render_dashboard, write_dashboard from inferrsi.apps.views.dashboard_data import load_dashboard -from inferrsi.cli import main from inferrsi.harness.records.campaign_records import ( create_campaign, record_candidate, diff --git a/tests/test_optimization_trace.py b/tests/test_optimization_trace.py index 79fe8a753..f60eccb68 100644 --- a/tests/test_optimization_trace.py +++ b/tests/test_optimization_trace.py @@ -6,9 +6,9 @@ import pytest +from inferrsi.apps.cli import main from inferrsi.apps.views.dashboard import write_dashboard from inferrsi.apps.views.dashboard_data import load_dashboard -from inferrsi.cli import main from inferrsi.harness.records import campaign_records, optimization_trace from inferrsi.harness.records.campaign_records import create_campaign, record_candidate from inferrsi.harness.records.optimization_trace import ( diff --git a/tests/test_package_root_inventory.py b/tests/test_package_root_inventory.py index 2b8f78aa7..064d1207c 100644 --- a/tests/test_package_root_inventory.py +++ b/tests/test_package_root_inventory.py @@ -1,7 +1,7 @@ -"""Exact inventory of the files directly under ``src/inferrsi/`` (#451 C1, C2; #412 R1). +"""Exact inventory of the files directly under ``src/inferrsi/`` (#451 C1, C2; #412 R1; #408 A1). The flat package root is being retired. This guard pins the root to the exact file -set left after R1 and rejects any other root file. Each later removal PR (A1/A2, M1) +set left after A1 and rejects any other root file. Each later removal PR (A2, M1) shrinks ``ROOT_FILES`` in the same change, until only ``__init__.py`` and ``__main__.py`` remain. It does not assert that final state early. """ @@ -36,15 +36,15 @@ "inspection.py", } ) -RETIRED = RETIRED_BY_C1 | RETIRED_BY_C2 | RETIRED_BY_R1 +# A1 (#408) moved the CLI and its parser to apps/cli/ and deleted both root files. +RETIRED_BY_A1 = frozenset({"arguments.py", "cli.py"}) +RETIRED = RETIRED_BY_C1 | RETIRED_BY_C2 | RETIRED_BY_R1 | RETIRED_BY_A1 ROOT_FILES = frozenset( { "__init__.py", "__main__.py", "_mindie_read_worker.py", - "arguments.py", "benchmark_operations.py", - "cli.py", "mindie_context.py", "mindie_mcp.py", "mindie_project.py", @@ -88,22 +88,28 @@ def root_files(repo: Path) -> set[str]: return present - _listed(repo, "--deleted") -def test_inventory_is_the_exact_post_r1_set() -> None: - assert len(ROOT_FILES) == 10 +def test_inventory_is_the_exact_post_a1_set() -> None: + assert len(ROOT_FILES) == 8 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 not ROOT_FILES & RETIRED - assert len(RETIRED) == 17 - # 27 before C1, 23 after C1, 21 after C2, 10 after R1. + assert len(RETIRED) == 19 + # 27 before C1, 23 after C1, 21 after C2, 10 after R1, 8 after A1. assert len(ROOT_FILES | RETIRED) == 27 - assert len(ROOT_FILES | RETIRED_BY_C2 | RETIRED_BY_R1) == 23 - assert len(ROOT_FILES | RETIRED_BY_R1) == 21 + assert len(ROOT_FILES | RETIRED_BY_C2 | RETIRED_BY_R1 | RETIRED_BY_A1) == 23 + assert len(ROOT_FILES | RETIRED_BY_R1 | RETIRED_BY_A1) == 21 + assert len(ROOT_FILES | RETIRED_BY_A1) == 10 assert GENERATED not in ROOT_FILES assert {"__init__.py", "__main__.py"} <= ROOT_FILES - # The final two-file root waits for the A1/A2 and M1 moves; it is not asserted here. + # The final two-file root waits for the A2 and M1 moves; it is not asserted here. + # These six are their move targets and stay until then. assert ROOT_FILES - {"__init__.py", "__main__.py"} == { - "_mindie_read_worker.py", "arguments.py", "benchmark_operations.py", "cli.py", - "mindie_context.py", "mindie_mcp.py", "mindie_project.py", "summary_chart.py", + "_mindie_read_worker.py", "benchmark_operations.py", "mindie_context.py", + "mindie_mcp.py", "mindie_project.py", "summary_chart.py", } + # A1 moved its two files; the implementation is the apps/cli package. + for name in ("__init__.py", "arguments.py"): + assert (REPO / PACKAGE / "apps" / "cli" / name).is_file(), name # C2 moved its two files; it left nothing behind under either old name. assert (REPO / PACKAGE / "resources" / "repository_packs.py").is_file() assert (REPO / PACKAGE / "contracts" / "evidence.py").is_file() @@ -147,27 +153,39 @@ def test_an_added_root_file_is_rejected(name: str) -> None: def test_a_removed_root_file_must_shrink_the_inventory() -> None: - assert inventory_errors(set(ROOT_FILES) - {"cli.py"}) == [ - f"missing root file {PACKAGE}/cli.py: shrink ROOT_FILES in the PR that removes it" + chart = "summary_chart.py" + assert inventory_errors(set(ROOT_FILES) - {chart}) == [ + f"missing root file {PACKAGE}/{chart}: shrink ROOT_FILES in the PR that removes it" ] # A later removal PR passes once it shrinks the expected set with the files. - smaller = ROOT_FILES - {"cli.py", "arguments.py"} + smaller = ROOT_FILES - {chart, "benchmark_operations.py"} assert inventory_errors(set(smaller), smaller) == [] + # A1 itself: the 10-file set it started from no longer matches the 8-file root, and + # keeping either old file beside the moved package is rejected. + after_r1 = ROOT_FILES | RETIRED_BY_A1 + assert inventory_errors(set(ROOT_FILES), after_r1) == [ + f"missing root file {PACKAGE}/{name}: shrink ROOT_FILES in the PR that removes it" + for name in sorted(RETIRED_BY_A1) + ] + assert inventory_errors(set(after_r1)) == [ + f"unexpected root file {PACKAGE}/{name}: a new module belongs in a subpackage" + for name in sorted(RETIRED_BY_A1) + ] # C2 itself: the 23-file set it started from no longer matched its 21-file root. - after_c2 = ROOT_FILES | RETIRED_BY_R1 + after_c2 = after_r1 | RETIRED_BY_R1 before_c2 = after_c2 | RETIRED_BY_C2 assert inventory_errors(set(after_c2), before_c2) == [ f"missing root file {PACKAGE}/{name}: shrink ROOT_FILES in the PR that removes it" for name in sorted(RETIRED_BY_C2) ] # R1 itself: the 21-file set it started from no longer matches the 10-file root. - assert inventory_errors(set(ROOT_FILES), after_c2) == [ + assert inventory_errors(set(after_r1), after_c2) == [ f"missing root file {PACKAGE}/{name}: shrink ROOT_FILES in the PR that removes it" for name in sorted(RETIRED_BY_R1) ] # Keeping any old file beside its moved implementation is rejected, one by one # and all together. - assert inventory_errors(set(after_c2)) == [ + assert inventory_errors(set(after_c2), after_r1) == [ f"unexpected root file {PACKAGE}/{name}: a new module belongs in a subpackage" for name in sorted(RETIRED_BY_R1) ] @@ -220,7 +238,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 / "cli.py").unlink() + (root / "summary_chart.py").unlink() assert inventory_errors(root_files(tmp_path)) == [ - f"missing root file {PACKAGE}/cli.py: shrink ROOT_FILES in the PR that removes it" + f"missing root file {PACKAGE}/summary_chart.py: shrink ROOT_FILES in the PR that removes it" ] diff --git a/tests/test_project_optimization.py b/tests/test_project_optimization.py index 83df66362..eb9f312fc 100644 --- a/tests/test_project_optimization.py +++ b/tests/test_project_optimization.py @@ -7,8 +7,8 @@ import pytest +from inferrsi.apps.cli import main from inferrsi.apps.views.dashboard import dashboard_snapshot, render_dashboard -from inferrsi.cli import main from inferrsi.harness.optimization import read_records @@ -82,7 +82,7 @@ def find_spec(self, fullname, path=None, target=None): ): raise AssertionError('Ordinary optimization imported ' + fullname) sys.meta_path.insert(0, NoBenchmark()) -from inferrsi.cli import main +from inferrsi.apps.cli import main from inferrsi.harness.optimization import read_records config = json.loads(sys.stdin.read()) assert main(config['start']) == 0 diff --git a/tests/test_qwen3_tts_knowledge.py b/tests/test_qwen3_tts_knowledge.py index ac085c308..3134d86d4 100644 --- a/tests/test_qwen3_tts_knowledge.py +++ b/tests/test_qwen3_tts_knowledge.py @@ -2,7 +2,7 @@ import pytest -from inferrsi.cli import main +from inferrsi.apps.cli import main from inferrsi.knowledge.catalog import get_knowledge, search_knowledge from inferrsi.resources.repository_packs import repository_pack diff --git a/tests/test_raw_string_selection.py b/tests/test_raw_string_selection.py index b7d7e159f..aa8132365 100644 --- a/tests/test_raw_string_selection.py +++ b/tests/test_raw_string_selection.py @@ -6,7 +6,7 @@ import pytest -from inferrsi.cli import main +from inferrsi.apps.cli import main from inferrsi.knowledge._skill_selection import ( indexed_skill, lexical_score, @@ -201,7 +201,7 @@ def test_raw_method_keeps_fail_closed_index_validation(): def test_cli_and_store_delegate_the_explicit_method(monkeypatch, capsys, tmp_path): reader = synthetic_reader({"owner": {"title": "n"}}) - monkeypatch.setattr("inferrsi.cli._knowledge_reader", lambda args: reader) + monkeypatch.setattr("inferrsi.apps.cli._knowledge_reader", lambda args: reader) assert main(["collect", "--relevance", "n", "--relevance-method", RAW, "--json"]) == 0 assert json.loads(capsys.readouterr().out)["selection"]["method"] == RAW with pytest.raises(SystemExit): diff --git a/tests/test_repository_packs_facade.py b/tests/test_repository_packs_facade.py index 7b96d47b6..4ba246d14 100644 --- a/tests/test_repository_packs_facade.py +++ b/tests/test_repository_packs_facade.py @@ -23,7 +23,7 @@ import pytest import inferrsi.resources as resources -from inferrsi import arguments +from inferrsi.apps.cli import arguments from inferrsi.infra import inspection from inferrsi.knowledge import catalog as knowledge_catalog from inferrsi.resources import repository_packs @@ -37,8 +37,8 @@ FACADE_CLOSURE = {"inferrsi", "inferrsi.resources", "inferrsi.resources.repository_packs"} # The facade needs none of these. #412 R1 retired root catalog, so the CLI parser that # now reads the tuple directly stands in its place. -CORES = ("inferrsi.harness", "inferrsi.knowledge", "inferrsi.arguments", "inferrsi.infra", - "inferrsi.apps", "inferrsi.benchmark", "inferrsi.contracts") +CORES = ("inferrsi.harness", "inferrsi.knowledge", "inferrsi.infra", "inferrsi.apps", + "inferrsi.benchmark", "inferrsi.contracts") # Every other inferrsi import is refused, so the facade works only if it needs none. BLOCKED = """ import importlib.abc, json, sys @@ -115,8 +115,15 @@ def test_one_repo_types_object_reaches_every_consumer() -> None: # itself. It is the same object, read directly and never copied. assert arguments.REPO_TYPES is canonical assert importlib.util.find_spec("inferrsi.catalog") is None - source = (ROOT / "arguments.py").read_text(encoding="utf-8") - assert source.splitlines().count("from .resources.repository_packs import REPO_TYPES") == 1 + # #408 A1: the parser is in Apps and reads the tuple through the Knowledge catalog. + assert arguments.__name__ == "inferrsi.apps.cli.arguments" + assert importlib.util.find_spec("inferrsi.arguments") is None + assert not (ROOT / "arguments.py").exists() + source = (ROOT / "apps" / "cli" / "arguments.py").read_text(encoding="utf-8") + assert source.splitlines().count( + "from ...knowledge.catalog import BACKENDS, KNOWLEDGE_REPOS, KNOWLEDGE_SCOPES, REPO_TYPES" + ) == 1 + assert "repository_packs" not in source assert "repository_pack(" not in source and not hasattr(arguments, "repository_pack") assert inspection.repository_pack is repository_packs.repository_pack assert not hasattr(knowledge_catalog, "repository_pack") diff --git a/tests/test_research.py b/tests/test_research.py index 38d5f27f3..95ee1bce2 100644 --- a/tests/test_research.py +++ b/tests/test_research.py @@ -6,7 +6,7 @@ import pytest -from inferrsi.cli import main +from inferrsi.apps.cli import main from inferrsi.knowledge import catalog as knowledge_catalog from inferrsi.knowledge.catalog import get_knowledge, search_knowledge from inferrsi.knowledge.research import research_knowledge diff --git a/tests/test_search_attribution.py b/tests/test_search_attribution.py index 9637052a1..127d87c4c 100644 --- a/tests/test_search_attribution.py +++ b/tests/test_search_attribution.py @@ -5,8 +5,8 @@ import pytest from inferrsi.apps.campaign import create_campaign +from inferrsi.apps.cli import main from inferrsi.apps.views.search_attribution import import_search -from inferrsi.cli import main def command(corpus, cmd, output, event_id, exit_code=0): diff --git a/tests/test_skill_catalog.py b/tests/test_skill_catalog.py index 4faee0e51..c626ddcf0 100644 --- a/tests/test_skill_catalog.py +++ b/tests/test_skill_catalog.py @@ -3,7 +3,7 @@ import pytest -from inferrsi.cli import main +from inferrsi.apps.cli import main from inferrsi.knowledge.skill_catalog import ( get_skill, skill_directories, diff --git a/tests/test_skill_index.py b/tests/test_skill_index.py index fbd11fb01..7267ac07c 100644 --- a/tests/test_skill_index.py +++ b/tests/test_skill_index.py @@ -5,8 +5,8 @@ import pytest -from inferrsi.arguments import parser -from inferrsi.cli import main +from inferrsi.apps.cli import main +from inferrsi.apps.cli.arguments import parser from inferrsi.knowledge.catalog import search_knowledge from inferrsi.knowledge.knowledge_operations import KnowledgeReader from inferrsi.knowledge.skill_catalog import skill_metadata, skill_records diff --git a/tests/test_skill_library.py b/tests/test_skill_library.py index df82e0153..fb7d2bb9f 100644 --- a/tests/test_skill_library.py +++ b/tests/test_skill_library.py @@ -7,7 +7,7 @@ import pytest -from inferrsi.cli import main +from inferrsi.apps.cli import main from inferrsi.knowledge.catalog import get_knowledge, knowledge_records, search_knowledge PACKAGE = Path(__file__).resolve().parents[1] / "src/inferrsi" diff --git a/tests/test_skill_library_readers.py b/tests/test_skill_library_readers.py index a3dc6193e..c4fdcfee9 100644 --- a/tests/test_skill_library_readers.py +++ b/tests/test_skill_library_readers.py @@ -6,7 +6,7 @@ import pytest -from inferrsi.cli import main +from inferrsi.apps.cli import main from inferrsi.knowledge.knowledge_operations import IdentityError, KnowledgeReader, RevisionConflict from inferrsi.knowledge.skill_catalog import ( get_skill, @@ -199,7 +199,7 @@ def test_cli_defaults_to_installed_library_and_allows_custom_root(tmp_path, monk _index(library, {"installed": "hardware/cuda/installed"}) custom = tmp_path / "custom" _skill(custom, "local") - monkeypatch.setattr("inferrsi.cli.files", lambda name: package) + monkeypatch.setattr("inferrsi.apps.cli.files", lambda name: package) monkeypatch.chdir(tmp_path) assert main(["skills", "show", "installed"]) == 0 assert json.loads(capsys.readouterr().out)["name"] == "installed" diff --git a/tests/test_target_module_import_gate.py b/tests/test_target_module_import_gate.py index 64d9ba60c..41c9d1758 100644 --- a/tests/test_target_module_import_gate.py +++ b/tests/test_target_module_import_gate.py @@ -6,6 +6,7 @@ from __future__ import annotations +import ast import tempfile import unittest from pathlib import Path @@ -55,6 +56,17 @@ def test_resource_loader_declaration_does_not_cover_an_adjacent_module(tmp_path) assert any("dynamic import" in item for item in first_wave_report(tmp_path).violations) +def _scan_tree(files: dict[str, str]) -> list[str]: + """Cross-core violations of a synthetic package root holding only ``files``.""" + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + for relative, source in files.items(): + path = root / relative + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(source, encoding="utf-8") + return cross_core_violations(root) + + class TargetModuleImportGateTest(unittest.TestCase): def test_no_new_cross_core_imports(self) -> None: # #412 R1: nothing is allowlisted any more, and the tree is still clean. @@ -62,18 +74,21 @@ 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")) - # The root CLI parser now names Knowledge itself. Its exact application-entry - # listing is what admits that, and each listed file exists in the root, so an - # entry cannot outlive the file that A1 or A2 removes. - self.assertEqual( - support.APPLICATION_ENTRIES, ("cli.py", "arguments.py", "benchmark_operations.py") - ) + # #408 A1: the CLI and its parser are apps/cli/, Apps by first path segment, so + # their two exact entries are gone and neither root file exists. Each listed + # file exists in the root, so an entry cannot outlive the file that A2 removes. + self.assertEqual(support.APPLICATION_ENTRIES, ("benchmark_operations.py",)) for entry in support.APPLICATION_ENTRIES: self.assertTrue((ROOT / entry).is_file(), entry) - with mock.patch.object( - support, "APPLICATION_ENTRIES", ("cli.py", "benchmark_operations.py") - ): - self.assertEqual(cross_core_violations(), ["arguments.py imports inferrsi.knowledge"]) + for retired in ("cli.py", "arguments.py"): + self.assertFalse((ROOT / retired).exists(), retired) + for moved in ("__init__.py", "arguments.py"): + self.assertTrue((ROOT / "apps" / "cli" / moved).is_file(), moved) + # The listing is what admits the last flat entry: without it that file fails. + with mock.patch.object(support, "APPLICATION_ENTRIES", ()): + self.assertEqual( + cross_core_violations(), ["benchmark_operations.py imports inferrsi.benchmark"] + ) def test_first_wave_policy_holds_on_current_tree(self) -> None: self.assertEqual(first_wave_report().violations, ()) @@ -92,7 +107,9 @@ 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. - self.assertEqual(len(support.RETIRED_ROOT_MODULES), 11) + self.assertEqual(len(support.RETIRED_BY_R1), 11) + self.assertEqual(support.RETIRED_BY_A1, {"inferrsi.cli", "inferrsi.arguments"}) + self.assertEqual(len(support.RETIRED_ROOT_MODULES), 13) for module in support.RETIRED_ROOT_MODULES: name = module.removeprefix("inferrsi.") self.assertFalse((ROOT / f"{name}.py").exists(), name) @@ -138,7 +155,6 @@ def test_clean_scan_is_not_isolation(self) -> None: self.assertEqual( report.blockers, ( - "temporary leaf importers: 1", "harness reaches model/infra: inferrsi.harness.agent_sessions -> " "inferrsi.infra (12 hits)", "runtime resource loaders: 5", @@ -181,7 +197,11 @@ def test_real_tree_allows_apps_and_same_core_only(self) -> None: "knowledge/out.py": "import inferrsi.harness\n", "benchmark/edge.py": "from inferrsi.benchmark import edge\n", "benchmark/forbidden.py": "import inferrsi.harness\n", - "cli.py": "from inferrsi.benchmark.registry import builtin_tasks\n", + # #408 A1: the CLI package is Apps by path. A root file that returns + # under either old name is unlisted and fails like any other flat module. + "apps/cli/__init__.py": "from inferrsi.benchmark.registry import builtin_tasks\n", + "apps/cli/arguments.py": "from inferrsi.knowledge import catalog\n", + "cli.py": "from inferrsi.apps.cli import main\n", "arguments.py": "from inferrsi.knowledge import catalog\n", # The listing is the exact file name: a module beside it gains nothing. "arguments_extra.py": "from inferrsi.knowledge import catalog\n", @@ -196,14 +216,116 @@ def test_real_tree_allows_apps_and_same_core_only(self) -> None: self.assertEqual( violations, [ + "arguments.py imports inferrsi.knowledge", "arguments_extra.py imports inferrsi.knowledge", "benchmark/forbidden.py imports inferrsi.harness", + "cli.py imports inferrsi.apps", "harness/probe.py imports inferrsi.knowledge", "knowledge/out.py imports inferrsi.harness", "unowned.py imports inferrsi.benchmark", ], ) + def test_module_entry_admits_only_the_canonical_cli_delegation(self) -> None: + # #408 A1: ``python -m inferrsi`` runs root ``__main__.py``, which must stay in the + # root. The real file is the hand-over to the Apps CLI and nothing else. + entry = (ROOT / support.MODULE_ENTRY).read_text(encoding="utf-8") + self.assertEqual( + [ast.unparse(node) for node in ast.parse(entry).body], + ["from .apps.cli import main", "raise SystemExit(main())"], + ) + self.assertEqual(support.MODULE_ENTRY, "__main__.py") + self.assertEqual(support.MODULE_ENTRY_DELEGATION, ("inferrsi.apps.cli", "main")) + # It passes by its own exact rule and is never listed as an application entry. + self.assertNotIn(support.MODULE_ENTRY, support.APPLICATION_ENTRIES) + self.assertEqual(_scan_tree({"__main__.py": entry}), []) + self.assertEqual(_scan_tree({"__main__.py": "from inferrsi.apps.cli import main\n"}), []) + # Positive control: without the rule the same file is refused, so the statement + # passes by the rule and not by an erased scan. + refused = ["__main__.py imports inferrsi.apps"] + with mock.patch.object(support, "MODULE_ENTRY", "elsewhere.py"): + self.assertEqual(_scan_tree({"__main__.py": entry}), refused) + with mock.patch.object(support, "MODULE_ENTRY_DELEGATION", ("inferrsi.apps.cli", "run")): + self.assertEqual(_scan_tree({"__main__.py": entry}), refused) + with mock.patch.object(support, "MODULE_ENTRY_DELEGATION", ("inferrsi.apps", "cli")): + self.assertEqual(_scan_tree({"__main__.py": entry}), refused) + # The staged report carries the same result: the delegation adds no violation, + # and another shape is a violation that keeps isolation false. + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + (root / "__main__.py").write_text(entry, encoding="utf-8") + self.assertEqual(first_wave_report(root).violations, ()) + (root / "__main__.py").write_text("from .apps import cli\n", encoding="utf-8") + report = first_wave_report(root) + self.assertEqual(report.violations, tuple(refused)) + self.assertFalse(report.isolation_complete) + + def test_module_entry_rule_covers_no_other_shape_target_or_file(self) -> None: + line = "from .apps.cli import main\n" + cases = ( + # Another name, a second name, an alias or a star import from the target. + ("from .apps.cli import parser\n", "apps"), + ("from .apps.cli import main, parser\n", "apps"), + ("from .apps.cli import main as run\n", "apps"), + ("from .apps.cli import main as main\n", "apps"), + ("from .apps.cli import *\n", "apps"), + # The target as a module object, and the Apps package itself. + ("from .apps import cli\n", "apps"), + ("import inferrsi.apps.cli\n", "apps"), + ("import inferrsi.apps.cli as entry\n", "apps"), + ("import inferrsi.apps\n", "apps"), + ("from .apps import main\n", "apps"), + # A module below the target, a module beside it and a lookalike of it. + ("from .apps.cli.arguments import parser\n", "apps"), + ("from .apps.cli import arguments\n", "apps"), + ("from .apps.cli.main import main\n", "apps"), + ("from .apps.cli_extra import main\n", "apps"), + ("from .apps.inspection import main\n", "apps"), + ("from .apps.legacy.run import main\n", "apps"), + # The same line below module level, an import fallback included. + ("def run():\n from .apps.cli import main\n return main()\n", "apps"), + ("if True:\n from .apps.cli import main\n", "apps"), + ( + "try:\n from .apps.cli import main\nexcept ImportError:\n main = None\n", + "apps", + ), + # Beside the admitted line every other core import still fails. + (line + "from .apps.views import dashboard\n", "apps"), + (line + "from .apps.cli.arguments import parser\n", "apps"), + (line + "from .apps.cli import main as run\n", "apps"), + (line + "from .knowledge.catalog import BACKENDS\n", "knowledge"), + (line + "import inferrsi.benchmark\n", "benchmark"), + (line + "def late():\n from inferrsi.knowledge import catalog\n", "knowledge"), + # The same name in another core is not the target. + ("from .knowledge.cli import main\n", "knowledge"), + ("from .benchmark.cli import main\n", "benchmark"), + ) + for source, core in cases: + with self.subTest(source=source): + self.assertEqual( + _scan_tree({"__main__.py": source}), [f"__main__.py imports inferrsi.{core}"] + ) + # No other file is the module entry. A root file beside it, a returning root CLI + # shell and a ``__main__`` under any package fail with the very same statement. + absolute = "from inferrsi.apps.cli import main\n" + others = ( + "main.py", "__main__extra.py", "_main.py", "cli.py", "arguments.py", "helper.py", + "harness/__main__.py", "knowledge/__main__.py", "benchmark/__main__.py", + "model/__main__.py", "infra/__main__.py", "resources/__main__.py", + ) + for path in others: + with self.subTest(path=path): + self.assertEqual(_scan_tree({path: absolute}), [f"{path} imports inferrsi.apps"]) + # All of them at once, with the real entry beside them: only the entry passes. + entry = (ROOT / support.MODULE_ENTRY).read_text(encoding="utf-8") + together = {path: absolute for path in others} + self.assertEqual( + _scan_tree({"__main__.py": entry, **together}), + sorted(f"{path} imports inferrsi.apps" for path in others), + ) + # Apps itself never needed the rule. + self.assertEqual(_scan_tree({"apps/__main__.py": absolute}), []) + def test_layout_doc_states_the_same_limit(self) -> None: text = ( Path(__file__).resolve().parents[1] / "docs" / "module-layout.md" diff --git a/tests/test_trial_checks.py b/tests/test_trial_checks.py index 8b96c9e28..298a30e0b 100644 --- a/tests/test_trial_checks.py +++ b/tests/test_trial_checks.py @@ -7,9 +7,9 @@ import pytest +from inferrsi.apps.cli.arguments import make_spec, parser from inferrsi.apps.legacy.evaluation import evaluate from inferrsi.apps.legacy.run import run_experiment -from inferrsi.arguments import make_spec, parser from inferrsi.contracts import RunSpec from inferrsi.harness.scenarios.external import collect_trial_checks