diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d50cfec3..d1006d76c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,53 @@ ### Changed +- The host bindings move from `inferrsi.infra` to the new `inferrsi.apps.host` + package (Refs #498, slice 3a). There is no forwarding module or alias, and the + import gate fails any import of an old path. + - `inferrsi.infra.commands`, `inspection`, `environment`, `platforms` and + `targets` are now `inferrsi.apps.host.commands`, `inspection`, `environment`, + `platforms` and `targets`. Only one import line changes, in `inspection.py`, + which reads the neutral data leaf one package level deeper. + - The permanent neutral-leaf importer rule now names + `inferrsi.apps.host.inspection`. It moved with its file in the same change, + and `inferrsi.infra.inspection` is retired, so no window admits two importers. + `technical_leaf.permanent_importers` in `docs/legacy-knowledge-manifest.json` + names the new module. The A1 state is kept unchanged in `revision_history`, and + every leaf lock is unchanged. The move needs the same formal architecture review + as the rule. + - The `apps/host/` package keeps Infra's limit: the gate fails any path from it to + a Knowledge, Harness or Benchmark module. + - `inferrsi.infra` now holds only `artifacts.py`. +- The `inferrsi.infra.campaign` import facade is removed (Refs #498, slice 3c). It + only re-exported Infra helpers, and its one caller is the example campaign. + There is no forwarding module or alias, and the import gate fails any import of + the old path. + - `examples/qwen21_turbo_b300.py` imports `inferrsi.infra.artifacts`, + `inferrsi.infra.environment` and `inferrsi.infra.targets` directly. + - `helper_hashes` moves into that example unchanged. It hashes every Python file + of the installed package, so a record made after this change no longer lists + `inferrsi/infra/campaign.py`. Every other path it binds is unchanged, and + existing records are not rewritten. +- The serving helpers move from `inferrsi.infra` and `inferrsi.model` to the new + `inferrsi.harness.serving` package (Refs #498, slice 2). There is no forwarding + module or alias, and the import gate fails any import of an old path. + - `inferrsi.infra.processes` is now `inferrsi.harness.serving.server`, + `inferrsi.infra.http` is now `inferrsi.harness.serving.http`, and + `inferrsi.model.protocols.image` is now `inferrsi.harness.serving.image`. + The emptied `inferrsi.model.protocols` package is removed. The server helpers + keep their Linux-only process-group contract. + - The package initializer imports nothing, so importing the HTTP or image client + does not load the server helpers. + - `inferrsi.infra.campaign` no longer re-exports `launch_server` and + `stop_server`. The example campaign imports them from + `inferrsi.harness.serving.server`. + - The optimization session's runtime identity now hashes + `harness/serving/server.py` in place of `infra/processes.py`. A session planned + before this change is refused before `status`, `recover` or any other operation + runs, and its plan is not changed. Resume such a session with the runtime that + planned it: install the wheel or source of the commit it was started from, and + run the same `inferrsi benchmarks session` command there. + - Pickled objects that name an old module path no longer load. - `docs/contracts/schemas/contract-v1.schema.json` validates more strictly (Refs #497). Eleven `pattern` values ended with `$`, which in Python `re`, and so in `jsonschema`, also matches before one trailing LF: `"att-1\n"` passed `Id`. They now diff --git a/docs/architecture.md b/docs/architecture.md index d92b8eed6..73058570d 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -96,19 +96,20 @@ interfaces; existing CLI commands remain supported. | --- | --- | --- | | Entry and knowledge | CLI arguments, immutable RunSpec, cited knowledge/context export | Model execution or automatic source editing | | Harness | AB/BA order, deadlines, source checks, scenario composition, evidence, performance adjudication and reporting | Device-specific conditions, request schemas or kernel dispatch | -| Model | Request payloads and output decoding | Scheduling, worker lifetime, hardware selection, metric contracts or quality checks | -| Infra | Repository identity, device discovery/qualification, process ownership, HTTP transport, storage and artifacts | Model constants, campaign gates or performance verdicts | +| Model | Anthropic provider adapters and their request authorization | Scheduling, worker lifetime, hardware selection, request payloads, metric contracts or quality checks | +| Infra | Repository identity, device discovery/qualification, storage and artifacts | Model constants, campaign gates or performance verdicts | -Dependencies flow from entrypoints to Harness, from scenarios to Model/Infra, -and from Model to Infra utilities. Infra does not import Model or Harness. None +Dependencies flow from entrypoints to Harness. Harness reaches no Infra or Model +module, and Infra does not import Model or Harness. None of these shared packages imports a campaign from `examples/`. -Environment inspection follows that direction. `infra/inspection.py` is the +Environment inspection follows that direction. `apps/host/inspection.py` is the facts API: it takes the command probe and the repository snapshot as ports. `apps/inspection.py` binds those ports to this host with -`infra.commands.probe_command` and `infra.targets.repository_identity`, and the -CLI calls that composition. Infra reaches no Apps, Knowledge, Harness or -Benchmark module and is not a fourth core. `infra/inspection.py` reads a +`apps.host.commands.probe_command` and `apps.host.targets.repository_identity`, +and the CLI calls that composition. The `apps/host/` package moved from Infra in +#498 slice 3a and keeps its limit: it reaches no Knowledge, Harness or Benchmark +module. `apps/host/inspection.py` reads a repository-pack description through the neutral `resources.repository_packs` leaf, under the one permanent importer rule in [module-layout.md](module-layout.md#permanent-neutral-leaf-importer-rule-proposed). @@ -186,6 +187,12 @@ src/inferrsi/ skill_eval_engineering.py Composed artifact check: task rules around sandbox replay improvement.py Composed assessment, selection, rerun and holdout acceptance inspection.py Environment inspection bound to the host probe and Git identity + host/ + inspection.py Environment inspection facts API; command and snapshot ports + commands.py Bounded read-only probes + environment.py Dependency versions and storage checks + platforms/ Backend discovery registry; CUDA qualification + targets/git.py Repository identity and source snapshots legacy/ run.py Old run composed from Harness, Benchmark and the report evaluation.py Old evaluate entry: RunSpec to the Benchmark gates @@ -269,19 +276,12 @@ src/inferrsi/ runner.py One AB/BA loop; execute/snapshot/assess/report ports injected scenarios/ external.py External command trials; metric validation injected - model/ - protocols/ + serving/ + server.py Supervised Linux serving workers and their group cleanup + http.py Timed JSON POST transport image.py OpenAI-style image payload and PNG response protocol infra/ - processes.py Supervised Linux serving workers and their group cleanup - targets/git.py Repository identity and source snapshots - platforms/ Backend discovery registry; CUDA qualification - inspection.py Environment inspection facts API; command and snapshot ports - commands.py Bounded read-only probes - environment.py Dependency versions and storage checks - http.py HTTP POST/download timing artifacts.py Hashing and evidence writes - campaign.py Legacy runner utility facade; transitive helper hashes data/ repo_packs/ Contribution descriptors and versioned tuning knowledge knowledge_packs/ Dependency and peer knowledge, preserving existing tiers @@ -311,9 +311,9 @@ path to its replacement and lists what still keeps the isolation gate false. | Add | Main extension locations | Required qualification | | --- | --- | --- | -| Model or scenario | `model/protocols`, `benchmark/metrics.py`, `benchmark/validators`, `harness/scenarios` | Frozen request and metric contract; model-specific quality coverage | -| Repository | `infra/targets`, a composed scenario, `data/repo_packs` | Stable source identity; command/result contract; environment isolation | -| Hardware | `infra/platforms` | Device selection, process exclusivity and independent backend/model evidence; a backend is registered in `infra/platforms/__init__.py` and its probe command is defined in the implementing module under `infra/platforms/`, not in package data | +| Model or scenario | `harness/serving`, `benchmark/metrics.py`, `benchmark/validators`, `harness/scenarios` | Frozen request and metric contract; model-specific quality coverage | +| Repository | `apps/host/targets`, a composed scenario, `data/repo_packs` | Stable source identity; command/result contract; environment isolation | +| Hardware | `apps/host/platforms` | Device selection, process exclusivity and independent backend/model evidence; a backend is registered in `apps/host/platforms/__init__.py` and its probe command is defined in the implementing module under `apps/host/platforms/`, not in package data | The acceptance rule is: **a new model or hardware adapter must reuse the common AB/BA loop, process cleanup and performance adjudication.** The extension @@ -390,7 +390,7 @@ the default control package continues to require only the standard library. ### Add a platform or repository -Register a device probe in `infra.platforms.PLATFORM_PROBES`; supply the selected +Register a device probe in `apps.host.platforms.PLATFORM_PROBES`; supply the selected IDs, device model and bounded command runner. A new backend name additionally needs an entry in `knowledge.catalog.BACKENDS`, which supplies the CLI `--backend` choices and the accepted knowledge and skill backends; no package-data descriptor is @@ -407,7 +407,7 @@ change the AB/BA algorithm, process cleanup or evaluator. ## Compatibility and historical evidence -The supervised server helpers (`infra.processes.launch_server` / `stop_server`) +The supervised server helpers (`harness.serving.server.launch_server` / `stop_server`) require Linux with a readable `/proc` process table. They reject other platforms before launch; missing or inaccessible process enumeration raises an error rather than reporting successful cleanup. Workers must remain in their owned process diff --git a/docs/contributing.md b/docs/contributing.md index a892e2082..70ba27723 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -35,10 +35,11 @@ policy does not renormalize existing blobs or authorize edits to frozen files. Nightly checks cover Linux and Windows checkouts with `core.autocrlf` set to `false`, `true` and `input`. -Use `harness/scenarios`, `model/protocols` and `benchmark/validators` for new models, -`infra/targets` with `data/repo_packs` for repositories, and `infra/platforms` for -hardware. A backend is registered in `infra/platforms/__init__.py`; its probe -command is defined in the implementing module under `infra/platforms/`. That +Use `harness/scenarios`, `harness/serving` and `benchmark/validators` for new models, +`apps/host/targets` with `data/repo_packs` for repositories, and +`apps/host/platforms` for hardware. A backend is registered in +`apps/host/platforms/__init__.py`; its probe command is defined in the +implementing module under `apps/host/platforms/`. That module owns the command name and the discovery boundary. Reuse the common AB/BA loop, cleanup and adjudication. See [extension contracts](architecture.md#where-to-extend). diff --git a/docs/legacy-knowledge-manifest.json b/docs/legacy-knowledge-manifest.json index 93a06e0d8..c3407528d 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. 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", + "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 (its importer moved to apps.host.inspection in #498 slice 3a) 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": "9b81c9ba1d4d1f7d45bd039a7c02ac2f01859426", "revision_history": [ { "base_commit": "0da7e2f960cd4ec994ae8eddea5b71023c5379ca", @@ -287,6 +287,31 @@ "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." } + }, + { + "base_commit": "aaa17a5dd333449d15fb052bb09b2012d55f2327", + "stage": "A1", + "superseded_by": "#498 slice 3a host-move revision at 9b81c9ba1d4d1f7d45bd039a7c02ac2f01859426", + "reason": "#498 slice 3a moves src/inferrsi/infra/inspection.py to src/inferrsi/apps/host/inspection.py together with commands.py, environment.py, platforms/ and targets/, with no forwarding module or alias. The permanent leaf importer moves with its file in the same change: the gate admits exactly inferrsi.apps.host.inspection with the same one name, and inferrsi.infra.inspection is retired, so no window admits two importers. The import line gains one relative level for the deeper package. The host modules keep Infra's limit and reach no Knowledge, Harness or Benchmark module. Every leaf lock is unchanged.", + "retired_permanent_importers": { + "stage": "R1", + "issue": "#412", + "rule": "Outside inferrsi.knowledge, exactly the listed module may import the leaf. It binds only its listed name, with the plain module-level from-import recorded as import_line. Any other importer, any other name, an alias, the leaf imported as a module object, an import below module level, a sys.modules use or a dynamic import fails the gate. An inferrsi.resources prefix allows nothing, and the leaf's one parent initializer stays import-free.", + "importers": [ + { + "importer": "inferrsi.infra.inspection", + "file": "src/inferrsi/infra/inspection.py", + "names": [ + "repository_pack" + ], + "import_line": "from ..resources.repository_packs import repository_pack", + "note": "D020. Infra reads one pack description directly, never through Knowledge or Harness. This is the edge that was the ninth compatibility pair." + } + ], + "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." + } } ], "compatibility_pairs": [], @@ -349,18 +374,24 @@ "rule": "Outside inferrsi.knowledge, exactly the listed module may import the leaf. It binds only its listed name, with the plain module-level from-import recorded as import_line. Any other importer, any other name, an alias, the leaf imported as a module object, an import below module level, a sys.modules use or a dynamic import fails the gate. An inferrsi.resources prefix allows nothing, and the leaf's one parent initializer stays import-free.", "importers": [ { - "importer": "inferrsi.infra.inspection", - "file": "src/inferrsi/infra/inspection.py", + "importer": "inferrsi.apps.host.inspection", + "file": "src/inferrsi/apps/host/inspection.py", "names": [ "repository_pack" ], - "import_line": "from ..resources.repository_packs import repository_pack", - "note": "D020. Infra reads one pack description directly, never through Knowledge or Harness. This is the edge that was the ninth compatibility pair." + "import_line": "from ...resources.repository_packs import repository_pack", + "note": "D020. The host inspection facts API reads one pack description directly, never through Knowledge or Harness. This is the edge that was the ninth compatibility pair. #498 slice 3a moved it from inferrsi.infra.inspection with its file." } ], "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." + "review": "This rule requires formal architecture review. The implementer does not self-approve it, and passing tests are not that review.", + "relocated": { + "stage": "#498 slice 3a", + "from": "inferrsi.infra.inspection", + "to": "inferrsi.apps.host.inspection", + "review": "The move changes which module the rule names, so it requires the same formal architecture review as the rule itself. Passing tests are not that review." + } } }, "infra_inspection_rewrite": { diff --git a/docs/module-layout.md b/docs/module-layout.md index 9c794f251..38a72e716 100644 --- a/docs/module-layout.md +++ b/docs/module-layout.md @@ -163,10 +163,12 @@ Several flat modules remain shared seams until their slice starts. | `harness/` | Mixed legacy tree, not target isolation | Not redefined | | `harness/runner.py`, `harness/scenarios/external.py`, `harness/atomic_json.py` | Old run execution facts and Harness-owned JSON writes | Ports injected; no Model edge, and no Infra edge except the local process executor | | `benchmark/legacy_run_v0.py`, `benchmark/sampling.py` | Old run gates and metric validation; image/video sample collection | Imports only `benchmark/metrics.py`; owns its rule inputs and verdict labels | -| `apps/legacy/` | Old run composition, old `evaluate` entry and HTML report | Supplies the Git source snapshot from `infra/targets`; remains in Apps | -| `apps/inspection.py` | Prepared-environment inspection bound to this host | Binds the `infra/inspection.py` facts API to `infra.commands.probe_command` and `infra.targets.repository_identity`; replaces root `inspection.py`, which R1 deleted with the three old-run root forwarders | +| `apps/legacy/` | Old run composition, old `evaluate` entry and HTML report | Supplies the Git source snapshot from `apps/host/targets`; remains in Apps | +| `apps/inspection.py` | Prepared-environment inspection bound to this host | Binds the `apps/host/inspection.py` facts API to `apps.host.commands.probe_command` and `apps.host.targets.repository_identity`; replaces root `inspection.py`, which R1 deleted with the three old-run root forwarders | | `benchmark/metrics.py`, `benchmark/validators/`, `benchmark/artifacts.py` | The metric contract, the Flare and image quality checks, and Benchmark's own file digests and JSON writes | #498 slice 1 moved the first two from `model/protocols/metrics.py` and `model/validators/`, with no forwarder or alias; the gate fails any import of the old paths | -| `infra/` | Seams used by the current tree, including the `infra/inspection.py` facts API | Not a fourth core; reaches no Knowledge, Harness, Benchmark or Apps module | +| `harness/serving/` (`server.py`, `http.py`, `image.py`) | Supervised serving processes, the timed JSON transport and the image request client | #498 slice 2 moved them from `infra/processes.py`, `infra/http.py` and `model/protocols/image.py` with no forwarder or alias; the initializer imports nothing, and the gate fails any import of the old paths | +| `apps/host/` (`inspection.py`, `commands.py`, `environment.py`, `platforms/`, `targets/`) | The host environment facts API, bounded probes, dependency facts, device discovery and source identity | #498 slice 3a moved them from Infra with no forwarder or alias; the package keeps Infra's limit and reaches no Knowledge, Harness or Benchmark module; `inspection.py` is the permanent leaf importer | +| `infra/` | `artifacts.py`, the shared file digests and JSON writes, until #498 slice 5 | Not a fourth core; reaches no Knowledge, Harness, Benchmark or Apps module | | `apps/views/summary_chart.py` | Stdlib SVG gain chart and report figure spec | A2 (#408) moved root `summary_chart.py` here; the renderer, its specification checks and its `main` are unchanged, and `tools/campaign_summary_chart.py` calls it | | `contracts/` (`runspec.py`, `json_v1.py`, `claim.py`, `evidence.py`) | Technical-only contracts: RunSpec, canonical JSON, verdict vocabulary, evidence segment and path rules | Exact module set; the initializer re-exports only `RunSpec`; not a fourth core | | `apps/storage/evidence_layout.py` | Evidence directory creation over the `contracts/evidence.py` path rules | The `mkdir` half of former root `evidence_paths.py`; host I/O stays in Apps | @@ -457,10 +459,13 @@ Outside `inferrsi.knowledge`, exactly one module may import | Importer | Bound name | Exact import line | | --- | --- | --- | -| `inferrsi.infra.inspection` | `repository_pack` | `from ..resources.repository_packs import repository_pack` | +| `inferrsi.apps.host.inspection` | `repository_pack` | `from ...resources.repository_packs import repository_pack` | -This is D020's direct read: Infra gets one pack description without reaching -Knowledge or Harness. The rule is `LEAF_IMPORTERS` in +This is D020's direct read: the host facts API gets one pack description +without reaching Knowledge or Harness. #498 slice 3a moved the importer from +`inferrsi.infra.inspection` with its file, in one change: the old name is +retired and is never admitted beside the new one, and the move needs the same +formal architecture review as the rule. The rule is `LEAF_IMPORTERS` in `tests/_gate_policy_support.py`, restated as `technical_leaf.permanent_importers` in the manifest. `tests/test_knowledge_compatibility_shells.py` requires the two to match, and @@ -471,8 +476,8 @@ retire, because the importer is not a shell. The rule covers that one importer, target, name and shape, and nothing wider: - Any other module outside Knowledge that imports the leaf fails as a second - importer. That includes another `infra` module, `infra/__init__.py`, an Apps, - Harness or Benchmark module and any root file. + importer. That includes another `apps.host` module, `apps/host/__init__.py`, + another Apps module, a Harness, Benchmark or Infra module and any root file. - In the declared importer, another leaf name, an alias, a star import, the leaf imported as a module object, an import below module level, a `sys.modules` use and a dynamic import each fail. @@ -488,7 +493,7 @@ The rule covers that one importer, target, name and shape, and nothing wider: `tests/test_first_wave_isolation_policy.py` holds these negative controls. One 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 +`apps.host.inspection` edge, so the edge passes by the rule and not by a relaxed scan. One temporary entry sat beside the rule from R1 until A1 (#408) and was never @@ -530,10 +535,10 @@ R1 (#412) deleted these eleven root modules with no forwarding shell, Root `inspection.py` was not an alias. It bound the Infra facts API to the host, and `apps/inspection.py` now holds that binding: `_command` is -`infra.commands.probe_command` and `repository_identity` is -`infra.targets.repository_identity`, both read from the module on each call, -so a test replaces either name there. `infra/inspection.py` is unchanged and -imports no Apps module. Root `execution.py` defined the two-argument +`apps.host.commands.probe_command` and `repository_identity` is +`apps.host.targets.repository_identity`, both read from the module on each call, +so a test replaces either name there. `apps/host/inspection.py`, moved from +Infra by #498 slice 3a, imports no Apps module outside `apps/host/`. Root `execution.py` defined the two-argument `run_experiment`; `apps.legacy.run.run_experiment` is that entry, and an omitted `execute` or `snapshot` port is read from the module when the run starts. diff --git a/examples/qwen21_turbo_b300.py b/examples/qwen21_turbo_b300.py index 681e8d1c9..db31f6ca2 100644 --- a/examples/qwen21_turbo_b300.py +++ b/examples/qwen21_turbo_b300.py @@ -16,10 +16,13 @@ import time import urllib.request +import inferrsi from inferrsi.benchmark.sampling import collect_samples -from inferrsi.model.protocols.image import ImageProtocol -from inferrsi.infra import campaign as lifecycle -from inferrsi.infra.platforms.cuda import qualify_devices +from inferrsi.harness.serving.image import ImageProtocol +from inferrsi.harness.serving.server import launch_server, stop_server +from inferrsi.apps.host import environment, targets +from inferrsi.apps.host.platforms.cuda import qualify_devices +from inferrsi.infra import artifacts MODEL = "Qwen/Qwen-Image-2.1-Turbo" REVISION = "d65dbc9a7e8f6b5479e33dee6030eaab2a906509" @@ -44,6 +47,17 @@ PROTECTED_METHODS = {'__init__', 'prepare_timesteps', 'prepare_latents', '_pack_latents', '_unpack_latents'} +def helper_hashes(): + """Freeze transitive package implementation for new campaign references.""" + # Moved from the retired inferrsi.infra.campaign; this example is its only caller. The + # root is the same installed package directory, so the hashed file set is unchanged. + root = Path(inferrsi.__file__).resolve().parent + return { + "inferrsi/" + str(path.relative_to(root)): artifacts.sha256(path) + for path in sorted(root.rglob("*.py")) + } + + def protocol(diagnostic=False, profile_steps=2, held_out=False): if not 1 <= profile_steps <= 8: raise ValueError('Profile steps must be 1..8') @@ -62,18 +76,18 @@ def protocol(diagnostic=False, profile_steps=2, held_out=False): def protected_sources(source): - result = {p: lifecycle.sha256(source / p) for p in PROTECTED_FILES} + result = {p: artifacts.sha256(source / p) for p in PROTECTED_FILES} relative = 'vllm_omni/diffusion/models/qwen_image_21/pipeline_qwen_image_21.py' tree = ast.parse((source / relative).read_text()) for node in tree.body: if isinstance(node, ast.FunctionDef) and node.name in {'get_qwen_image_21_pre_process_func', 'get_qwen_image_21_post_process_func'}: - result[relative + ':' + node.name] = lifecycle.digest(ast.dump(node, include_attributes=False)) + result[relative + ':' + node.name] = artifacts.digest(ast.dump(node, include_attributes=False)) for node in tree.body: if isinstance(node, ast.ClassDef) and node.name == 'QwenImage21Pipeline': found = set() for method in node.body: if isinstance(method, (ast.FunctionDef, ast.AsyncFunctionDef)) and method.name in PROTECTED_METHODS: - result[relative + ':' + method.name] = lifecycle.digest(ast.dump(method, include_attributes=False)) + result[relative + ':' + method.name] = artifacts.digest(ast.dump(method, include_attributes=False)) found.add(method.name) if found != PROTECTED_METHODS: raise ValueError('Protected pipeline method missing') @@ -84,7 +98,7 @@ def protected_sources(source): def dependencies(): - versions = lifecycle.semantic_dependency_versions(lifecycle.dependency_versions()) + versions = environment.semantic_dependency_versions(environment.dependency_versions()) for name in ['Pillow', 'numpy', 'scikit-image', 'flash-attn-4', 'nvidia-cutlass-dsl', 'kernels']: versions[name] = importlib.metadata.version(name) return versions @@ -102,14 +116,14 @@ def model_assets(model, cache): stat = (model/item['path']).stat() if (stat.st_size, stat.st_mtime_ns) != (item['bytes'], item['mtime_ns']): raise ValueError('Model asset changed after SHA256 freeze') - if lifecycle.sha256(model/item['path']) != item.get('sha256'): + if artifacts.sha256(model/item['path']) != item.get('sha256'): raise ValueError(f"Model asset SHA256 mismatch: {item['path']}") - return lifecycle.sha256(manifest) + return artifacts.sha256(manifest) def guards(): paths = [Path(__file__), Path(__file__).with_name('qwen21_turbo_quality.py')] - return {**lifecycle.helper_hashes(), **{p.name: lifecycle.sha256(p) for p in paths}} + return {**helper_hashes(), **{p.name: artifacts.sha256(p) for p in paths}} def preflight(): @@ -137,7 +151,7 @@ def run(args): media = output.parent/'media' media.mkdir() settings = protocol(args.diagnostic, args.profile_steps, args.held_out) - before = lifecycle.source_snapshot(source) + before = targets.source_snapshot(source) frozen = protected_sources(source) frozen_guards = guards() versions = dependencies() @@ -152,7 +166,7 @@ def run(args): argv += ['--profiler-config', json.dumps({'profiler':'torch','torch_profiler_dir':str(output.parent/'torch-profile'), 'torch_profiler_record_shapes':True,'torch_profiler_with_stack':True}), '--enable-diffusion-pipeline-profiler'] - record = {'status':'running','protocol':settings,'protocol_sha256':lifecycle.digest(settings), + record = {'status':'running','protocol':settings,'protocol_sha256':artifacts.digest(settings), 'diagnostic':args.diagnostic,'parallel':{'tp':args.tp,'ulysses':args.ulysses,'vae':1,'cfg':1,'ring':1}, 'source_before':before,'protected_sources':frozen,'guard_hashes':frozen_guards, 'dependency_versions':versions,'model_assets_sha256':asset_hash, @@ -174,7 +188,7 @@ def run(args): env[key] = str(cache/folder) preparation_start = time.monotonic() with (output.parent/'server.log').open('wb') as log: - process, ownership = lifecycle.launch_server(argv,source,env,log) + process, ownership = launch_server(argv,source,env,log) record['server_process'] = ownership deadline = time.monotonic()+args.startup_timeout while True: @@ -210,7 +224,7 @@ def before_measure(): try: if process is not None: try: - record['server_cleanup'] = lifecycle.stop_server(process, ownership, 20) + record['server_cleanup'] = stop_server(process, ownership, 20) if record['server_cleanup']['remaining_pids']: final_errors.append('Owned processes remain') except Exception as error: @@ -218,7 +232,7 @@ def before_measure(): final_errors.append(f'Cleanup failed: {error}') record['source_integrity'] = {'verified': False} probes = [ - ('source', lambda: lifecycle.source_snapshot(source), before), + ('source', lambda: targets.source_snapshot(source), before), ('protected_sources', lambda: protected_sources(source), frozen), ('guards', guards, frozen_guards), ('dependencies', dependencies, versions), @@ -245,7 +259,7 @@ def before_measure(): record.update(status='failed', error='; '.join(final_errors)) finally: # Failed cleanup or verification must never erase the trial record. - lifecycle.write_json(output, record) + artifacts.write_json(output, record) return record diff --git a/src/inferrsi/apps/host/__init__.py b/src/inferrsi/apps/host/__init__.py new file mode 100644 index 000000000..40c3ea82e --- /dev/null +++ b/src/inferrsi/apps/host/__init__.py @@ -0,0 +1,8 @@ +"""Apps host bindings: command probes, environment and device facts, and source +identity for this host. + +``targets`` fingerprints source and ``platforms`` discovers and qualifies devices. +Device counts, SKUs and campaign settings are supplied by callers. Discovery does +not establish backend/model compatibility; qualification requires independent +evidence. The initializer imports nothing. +""" diff --git a/src/inferrsi/infra/commands.py b/src/inferrsi/apps/host/commands.py similarity index 100% rename from src/inferrsi/infra/commands.py rename to src/inferrsi/apps/host/commands.py diff --git a/src/inferrsi/infra/environment.py b/src/inferrsi/apps/host/environment.py similarity index 100% rename from src/inferrsi/infra/environment.py rename to src/inferrsi/apps/host/environment.py diff --git a/src/inferrsi/infra/inspection.py b/src/inferrsi/apps/host/inspection.py similarity index 97% rename from src/inferrsi/infra/inspection.py rename to src/inferrsi/apps/host/inspection.py index 20b3d8473..1726a355d 100644 --- a/src/inferrsi/infra/inspection.py +++ b/src/inferrsi/apps/host/inspection.py @@ -7,7 +7,7 @@ from collections.abc import Callable from pathlib import Path -from ..resources.repository_packs import repository_pack +from ...resources.repository_packs import repository_pack from .commands import probe_command from .platforms import inspect_device from .targets import repository_identity diff --git a/src/inferrsi/infra/platforms/__init__.py b/src/inferrsi/apps/host/platforms/__init__.py similarity index 100% rename from src/inferrsi/infra/platforms/__init__.py rename to src/inferrsi/apps/host/platforms/__init__.py diff --git a/src/inferrsi/infra/platforms/cuda.py b/src/inferrsi/apps/host/platforms/cuda.py similarity index 100% rename from src/inferrsi/infra/platforms/cuda.py rename to src/inferrsi/apps/host/platforms/cuda.py diff --git a/src/inferrsi/infra/platforms/mlx.py b/src/inferrsi/apps/host/platforms/mlx.py similarity index 100% rename from src/inferrsi/infra/platforms/mlx.py rename to src/inferrsi/apps/host/platforms/mlx.py diff --git a/src/inferrsi/infra/targets/__init__.py b/src/inferrsi/apps/host/targets/__init__.py similarity index 100% rename from src/inferrsi/infra/targets/__init__.py rename to src/inferrsi/apps/host/targets/__init__.py diff --git a/src/inferrsi/infra/targets/git.py b/src/inferrsi/apps/host/targets/git.py similarity index 100% rename from src/inferrsi/infra/targets/git.py rename to src/inferrsi/apps/host/targets/git.py diff --git a/src/inferrsi/apps/inspection.py b/src/inferrsi/apps/inspection.py index 100544770..47a643342 100644 --- a/src/inferrsi/apps/inspection.py +++ b/src/inferrsi/apps/inspection.py @@ -1,13 +1,14 @@ """Prepared-environment inspection bound to this host. -``infra.inspection.inspect_environment`` is the facts API: it takes the command -probe and the repository snapshot as ports. This composition supplies the real -host probe and the Git repository identity. Infra imports nothing from here. +``apps.host.inspection.inspect_environment`` is the facts API: it takes the +command probe and the repository snapshot as ports. This composition supplies the +real host probe and the Git repository identity. The host package imports nothing +from here. """ -from ..infra.commands import probe_command as _command -from ..infra.inspection import inspect_environment as _inspect_environment -from ..infra.targets import repository_identity +from .host.commands import probe_command as _command +from .host.inspection import inspect_environment as _inspect_environment +from .host.targets import repository_identity def inspect_environment( diff --git a/src/inferrsi/apps/legacy/run.py b/src/inferrsi/apps/legacy/run.py index 2a52fb639..36136d058 100644 --- a/src/inferrsi/apps/legacy/run.py +++ b/src/inferrsi/apps/legacy/run.py @@ -5,12 +5,12 @@ from functools import partial from pathlib import Path +from inferrsi.apps.host.targets import repository_identity from inferrsi.benchmark.legacy_run_v0 import evaluate as _evaluate from inferrsi.benchmark.legacy_run_v0 import read_metric, trial_metric from inferrsi.contracts import RunSpec from inferrsi.harness.runner import run_experiment as _run_experiment from inferrsi.harness.scenarios.external import execute_trial as _execute_trial -from inferrsi.infra.targets import repository_identity from .evaluation import run_rules from .reporting import write_report diff --git a/src/inferrsi/harness/optimization_session.py b/src/inferrsi/harness/optimization_session.py index 9030624cd..e8e5308bb 100644 --- a/src/inferrsi/harness/optimization_session.py +++ b/src/inferrsi/harness/optimization_session.py @@ -116,7 +116,7 @@ def _runtime_identity(): root = Path(str(files("inferrsi"))) names = ("harness/optimization_session.py", "harness/optimization.py", "harness/local_process.py", - "infra/processes.py", "infra/artifacts.py", "harness/scenarios/external.py", + "harness/serving/server.py", "infra/artifacts.py", "harness/scenarios/external.py", "harness/atomic_json.py", "harness/artifact_primitives.py", "harness/usage.py", "harness/agent_sessions.py", "harness/task_protocol.py", "harness/protocol_child.py", diff --git a/src/inferrsi/harness/serving/__init__.py b/src/inferrsi/harness/serving/__init__.py new file mode 100644 index 000000000..8a0ee50d5 --- /dev/null +++ b/src/inferrsi/harness/serving/__init__.py @@ -0,0 +1,5 @@ +"""Harness serving: start a supervised server process and send it requests. + +The initializer imports nothing, so importing the HTTP or image client does not load +the server process helpers. +""" diff --git a/src/inferrsi/infra/http.py b/src/inferrsi/harness/serving/http.py similarity index 100% rename from src/inferrsi/infra/http.py rename to src/inferrsi/harness/serving/http.py diff --git a/src/inferrsi/model/protocols/image.py b/src/inferrsi/harness/serving/image.py similarity index 98% rename from src/inferrsi/model/protocols/image.py rename to src/inferrsi/harness/serving/image.py index 2fd313e84..d950f2e68 100644 --- a/src/inferrsi/model/protocols/image.py +++ b/src/inferrsi/harness/serving/image.py @@ -5,7 +5,7 @@ from dataclasses import dataclass, field from pathlib import Path -from ...infra.http import post_json +from .http import post_json @dataclass(frozen=True) diff --git a/src/inferrsi/infra/processes.py b/src/inferrsi/harness/serving/server.py similarity index 100% rename from src/inferrsi/infra/processes.py rename to src/inferrsi/harness/serving/server.py diff --git a/src/inferrsi/infra/README.md b/src/inferrsi/infra/README.md index d1a3c0370..65f042404 100644 --- a/src/inferrsi/infra/README.md +++ b/src/inferrsi/infra/README.md @@ -1,13 +1,10 @@ # Infrastructure -`processes.py` owns supervised Linux serving workers and their cleanup. Local -command execution, deadlines and process-tree cleanup live in -`harness.local_process`. -`targets/` fingerprints source; `platforms/` discovers and qualifies devices. -Transport, artifact writes and environment probes are shared utilities. +`artifacts.py` holds the shared file digests and JSON evidence writes until #498 +slice 5 retires this package. The serving helpers moved to +`inferrsi.harness.serving` (slice 2). The host probes, platform discovery, source +identity and environment facts moved to `inferrsi.apps.host` (slice 3a). -Infra does not import Harness, Model or campaign examples. Device counts, SKUs -and campaign settings are supplied by callers. Discovery does not establish -backend/model compatibility; qualification requires independent evidence. +Infra does not import Harness, Model, Apps or campaign examples. See [the architecture and extension contracts](../../../docs/architecture.md). diff --git a/src/inferrsi/infra/__init__.py b/src/inferrsi/infra/__init__.py index 3e96c5ad5..607949bcf 100644 --- a/src/inferrsi/infra/__init__.py +++ b/src/inferrsi/infra/__init__.py @@ -1 +1 @@ -"""Infrastructure plane: source identity, devices, transport and owned processes.""" +"""Infrastructure plane: shared artifact digests and JSON evidence writes.""" diff --git a/src/inferrsi/infra/campaign.py b/src/inferrsi/infra/campaign.py deleted file mode 100644 index c610d4f32..000000000 --- a/src/inferrsi/infra/campaign.py +++ /dev/null @@ -1,34 +0,0 @@ -"""Compatibility imports for campaign scripts using the shared infrastructure. - -New integrations can import the owning modules directly. This module contains -no model recipe, request protocol, accelerator choice, or quality threshold. -""" - -from pathlib import Path - -from .artifacts import digest, sha256, write_json -from .environment import dependency_versions, semantic_dependency_versions, storage_locations -from .processes import launch_server, stop_server -from .targets import source_snapshot - -__all__ = [ - "digest", - "sha256", - "write_json", - "dependency_versions", - "semantic_dependency_versions", - "storage_locations", - "launch_server", - "stop_server", - "source_snapshot", - "helper_hashes", -] - - -def helper_hashes() -> dict[str, str]: - """Freeze transitive package implementation for new campaign references.""" - root = Path(__file__).resolve().parents[1] - return { - "inferrsi/" + str(path.relative_to(root)): sha256(path) - for path in sorted(root.rglob("*.py")) - } diff --git a/src/inferrsi/model/README.md b/src/inferrsi/model/README.md index fd1080a7b..40c7eadeb 100644 --- a/src/inferrsi/model/README.md +++ b/src/inferrsi/model/README.md @@ -1,9 +1,9 @@ # Model -`protocols/` defines request contracts. The metric contract and the output -quality checks moved to `inferrsi.benchmark.metrics` and -`inferrsi.benchmark.validators` (#498 slice 1). The image validator's optional -dependencies are available through `inferrsi[image]`. +The metric contract and the output quality checks moved to +`inferrsi.benchmark.metrics` and `inferrsi.benchmark.validators` (#498 slice 1). +The image request protocol moved to `inferrsi.harness.serving.image` (#498 slice 2). +The image validator's optional dependencies are available through `inferrsi[image]`. Model/revision pins and numeric acceptance gates stay in campaign plans. Frozen historical snapshots remain in `tests/fixtures/legacy/`; current examples and diff --git a/src/inferrsi/model/__init__.py b/src/inferrsi/model/__init__.py index c12658ce2..5b87c8196 100644 --- a/src/inferrsi/model/__init__.py +++ b/src/inferrsi/model/__init__.py @@ -1,4 +1,5 @@ -"""Model plane: request protocols and the Anthropic provider adapters. +"""Model plane: the Anthropic provider adapters and their request authorization. -The metric contract and the quality validators are in ``inferrsi.benchmark``. +The metric contract and the quality validators are in ``inferrsi.benchmark``; the +serving request clients are in ``inferrsi.harness.serving``. """ diff --git a/src/inferrsi/model/protocols/__init__.py b/src/inferrsi/model/protocols/__init__.py deleted file mode 100644 index 3f5e7886c..000000000 --- a/src/inferrsi/model/protocols/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Explicit request/result contracts for new campaigns; no frozen model defaults.""" diff --git a/tests/_gate_policy_support.py b/tests/_gate_policy_support.py index fe959a664..49f127732 100644 --- a/tests/_gate_policy_support.py +++ b/tests/_gate_policy_support.py @@ -89,11 +89,21 @@ } ) RETIRED_ROOT_MODULES = RETIRED_BY_R1 | RETIRED_BY_A1 | RETIRED_BY_A2 | RETIRED_BY_M1 -# #498 slice 1 moved these packages and modules out of ``inferrsi.model``, with no -# forwarder or alias: ``inferrsi.benchmark.metrics`` and ``inferrsi.benchmark.validators``. +# #498 retired these paths with no forwarder or alias. Slice 1 moved the metric contract +# and the validators to ``inferrsi.benchmark.metrics`` and ``inferrsi.benchmark.validators``. +# Slice 2 moved the server helpers, the HTTP transport and the image request client to +# ``inferrsi.harness.serving`` and removed the emptied ``inferrsi.model.protocols``. # Each name covers everything below it. A file under one fails, and so does any import # that names one, even when its target is absent. -RETIRED_MODULES = frozenset({"inferrsi.model.protocols.metrics", "inferrsi.model.validators"}) +RETIRED_MODULES = frozenset({ + "inferrsi.model.protocols", "inferrsi.model.validators", + "inferrsi.infra.processes", "inferrsi.infra.http", + # Slice 3c deleted the campaign facade; the example imports the owning modules. + "inferrsi.infra.campaign", + # Slice 3a moved the host bindings to ``inferrsi.apps.host``. + "inferrsi.infra.commands", "inferrsi.infra.inspection", "inferrsi.infra.environment", + "inferrsi.infra.platforms", "inferrsi.infra.targets", +}) # #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 @@ -104,8 +114,12 @@ # or a dynamic import fails. No ``inferrsi.resources.`` prefix is ever allowed. # ``technical_leaf.permanent_importers`` in the manifest restates this rule and # records that it needs formal architecture review. +# #498 slice 3a moved that importer from ``inferrsi.infra.inspection`` to +# ``inferrsi.apps.host.inspection`` with its file, in one change: the old name is retired +# and is not admitted beside the new one. The host module still reaches no Knowledge or +# Harness module. LEAF_IMPORTERS = { - "inferrsi.infra.inspection": frozenset({"repository_pack"}), + "inferrsi.apps.host.inspection": frozenset({"repository_pack"}), } # #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: @@ -852,6 +866,21 @@ def h_entry_forbidden(node: str) -> bool: if _matches(name, "inferrsi.infra") for v in _closure_violations(name, graph, lambda node: _core_of(node) is not None) ] + # #498 slice 3a: the host bindings moved here from Infra keep its limit. They, and the + # permanent leaf importer among them, reach no Knowledge, Harness or Benchmark module + # and no Apps module outside the host package; the Apps rule already refuses an old + # root leaf. + host = [ + v + for name in modules + if _matches(name, "inferrsi.apps.host") + for v in _closure_violations( + name, graph, + lambda node: _core_of(node) in ("knowledge", "harness", "benchmark") + or (_core_of(node) == "apps" and node != "inferrsi.apps" + and not _matches(node, "inferrsi.apps.host")), + ) + ] # Non-entry harness modules follow the same rule on the same full graph. # They add violations without counting toward the new-core result. @@ -862,7 +891,7 @@ def h_entry_forbidden(node: str) -> bool: if _core_of(name) == "harness" and name not in declared for message in _closure_violations(name, graph, h_entry_forbidden) ] - violations += new_core + infra + harness_extra + violations += new_core + infra + host + harness_extra blockers = [] for name in (*NEW_CORES, "harness"): diff --git a/tests/check_installed.py b/tests/check_installed.py index 7f4977d53..6f41e49a5 100644 --- a/tests/check_installed.py +++ b/tests/check_installed.py @@ -694,9 +694,9 @@ def _inventory(root, prefix): "inferrsi.apps.views.summary_chart" ) host_inspection = import_module("inferrsi.apps.inspection") -assert host_inspection._command is import_module("inferrsi.infra.commands").probe_command +assert host_inspection._command is import_module("inferrsi.apps.host.commands").probe_command assert host_inspection.repository_identity is ( - import_module("inferrsi.infra.targets").repository_identity + import_module("inferrsi.apps.host.targets").repository_identity ) 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 @@ -789,7 +789,9 @@ def _inventory(root, prefix): assert launch.returncode == 0, launch.stderr # #498 slice 1: the metric contract and the quality validators ship only under # inferrsi.benchmark. The old inferrsi.model paths are not in the wheel and have no alias. -for retired in ("inferrsi.model.protocols.metrics", "inferrsi.model.validators"): +# Slice 2 removed the emptied inferrsi.model.protocols package, so it stands for +# inferrsi.model.protocols.metrics here. +for retired in ("inferrsi.model.protocols", "inferrsi.model.validators"): assert find_spec(retired) is None, retired try: import_module(retired) @@ -810,3 +812,40 @@ def _inventory(root, prefix): ) assert flare_cli.returncode == code, (module, flare_cli.returncode, flare_cli.stderr) assert "No module named 'inferrsi.model.validators'" in flare_cli.stderr, flare_cli.stderr +# #498 slice 2: the serving helpers ship only under inferrsi.harness.serving, with no +# forwarder for the old Infra and Model paths. Slice 3c deleted the infra.campaign facade, +# and slice 3a moved the host bindings to inferrsi.apps.host. +for retired in ("inferrsi.infra.processes", "inferrsi.infra.http", "inferrsi.infra.campaign", + "inferrsi.infra.commands", "inferrsi.infra.inspection", + "inferrsi.infra.environment", "inferrsi.infra.platforms", + "inferrsi.infra.targets"): + assert find_spec(retired) is None, retired + try: + import_module(retired) + except ModuleNotFoundError: + pass + else: + raise AssertionError(f"retired module {retired} must not import") +for canonical in ("inferrsi.harness.serving", "inferrsi.harness.serving.server", + "inferrsi.harness.serving.http", "inferrsi.harness.serving.image", + "inferrsi.apps.host.commands", "inferrsi.apps.host.inspection", + "inferrsi.apps.host.environment", "inferrsi.apps.host.platforms", + "inferrsi.apps.host.targets"): + assert find_spec(canonical) is not None, canonical +# A fresh isolated interpreter imports the image client without loading the server +# process helpers or any Infra or Model module: the package initializer imports nothing. +serving_probe = ( + "import sys\n" + "from inferrsi.harness.serving.image import ImageProtocol\n" + "loaded = {name for name in sys.modules if name.startswith('inferrsi.')}\n" + "serving = {name for name in loaded if name.startswith('inferrsi.harness.serving')}\n" + "assert serving == {'inferrsi.harness.serving', 'inferrsi.harness.serving.image',\n" + " 'inferrsi.harness.serving.http'}, sorted(serving)\n" + "assert not [n for n in loaded if n.startswith(('inferrsi.infra', 'inferrsi.model'))]\n" +) +with tempfile.TemporaryDirectory(prefix="inferrsi-serving-") as serving_cwd: + serving = subprocess.run( + [sys.executable, "-I", "-B", "-c", serving_probe], capture_output=True, text=True, + check=False, cwd=serving_cwd, + ) +assert serving.returncode == 0, serving.stderr diff --git a/tests/fixtures/optimization-session/pre-serving-runtime-identity.json b/tests/fixtures/optimization-session/pre-serving-runtime-identity.json new file mode 100644 index 000000000..6b99b95b8 --- /dev/null +++ b/tests/fixtures/optimization-session/pre-serving-runtime-identity.json @@ -0,0 +1,22 @@ +{ + "runtime_identity": { + "apps/campaign.py": "070d9c57e9c0412e26d9b221d32ca5aba84cd4796cd76cba1ab8fcfac1f0c892", + "harness/agent_sessions.py": "491fbf71e03b0c2aef332765fe2c7d7d7d8cf67bd9b96b9a50a2816ccb741573", + "harness/artifact_primitives.py": "6208a775f484d6b3b233bb823b29ef569ff55f94297b176682300208b01c45b9", + "harness/atomic_json.py": "87d7b2c4ae881ee9bb64653fcea2fdad9abae5f1a50e6b9adead954a9b0799b0", + "harness/candidates.py": "42e74461b5a55f4b421895f5509668121833bbe0693430f1626a44db5d4f35f4", + "harness/local_process.py": "b955fc74b9bd6771c683f9e16827352cb3b9781110ca5713ea3ef63a228bade4", + "harness/optimization.py": "a98cd0c6216d650f292368edcd304d9b40d352a1ec3d31ba8b7ae5eaaa822283", + "harness/optimization_session.py": "27750dab8d1b01ac08e698485433f1d895bdcad2ab381dd7f2b56b0cc1578d50", + "harness/project.py": "48c1ee5f89bc5a95cedba23be91fb17ebce05f9f75ba954c4bbe3e2310d4f0dd", + "harness/protocol_child.py": "2cfd5848e711cedeef181981ec6fa2be453ee061f57c32f74954c82625528c95", + "harness/records/knowledge_capture.py": "4a1969bfaf412d08909fafe978a5e5e30d9e33cd63da80192ad9356ec2d1af7a", + "harness/scenarios/external.py": "94ab0dc77596961b8094d93a95cc4a4764178b324f6703c22ab0f78ed0497189", + "harness/task_protocol.py": "9c9ef100c264b5e596e29b322905f5442228bae711bd2249010e99fde58b6533", + "harness/usage.py": "bcb8a35f83e683c1e3343c2438214ad89f35eeb4dd940eccfd54b3489bb70855", + "infra/artifacts.py": "272f43056086078d05fe777cc08f73b85224468c1ede037ecd72c45747f25095", + "infra/processes.py": "2ca1984373423b190b13523fa76ce760e74cc851bbd29b0e532d8d7e92e62c8d", + "knowledge/context_projection.py": "ef89a0b2ecddbb0460573edc65a8b5ef704989e03d3d2fa615ca529ef0debe2a" + }, + "source_commit": "25df4772e4e4a82033f5acd8d5e13e164f8467dd" +} diff --git a/tests/test_first_wave_isolation_policy.py b/tests/test_first_wave_isolation_policy.py index 4b938ecc6..23e93be8a 100644 --- a/tests/test_first_wave_isolation_policy.py +++ b/tests/test_first_wave_isolation_policy.py @@ -102,7 +102,8 @@ def _k01_tree() -> dict[str, str]: ), "knowledge/knowledge_operations.py": "from inferrsi.contracts import json_v1\n", "infra/__init__.py": "", - "infra/inspection.py": "from ..resources.repository_packs import repository_pack\n", + "apps/host/__init__.py": "", + "apps/host/inspection.py": "from ...resources.repository_packs import repository_pack\n", "harness/__init__.py": "", "harness/api.py": "VALUE = 1\n", "benchmark/__init__.py": "", @@ -116,8 +117,9 @@ def _k01_tree() -> dict[str, str]: return files -# The one declared importer of the data leaf, as the real tree writes it. -INSPECTION = "from ..resources.repository_packs import repository_pack\n" +# The one declared importer of the data leaf, as the real tree writes it. #498 slice 3a +# moved it from infra/inspection.py to apps/host/inspection.py. +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. @@ -250,9 +252,9 @@ def test_second_importer_fails(self) -> None: "evaluation.py imports inferrsi.knowledge", ), ( - "infra/inspection.py", + "apps/host/inspection.py", "from inferrsi.knowledge.catalog import REPO_TYPES\n", - "infra/inspection.py imports inferrsi.knowledge", + "inferrsi.apps.host.inspection reaches inferrsi.knowledge", ), ( "evaluation.py", @@ -279,24 +281,24 @@ def test_second_importer_fails(self) -> None: report = _report({path: source}, manifest=manifest, base=base) self.assertTrue(_violated(report, expected), report.violations) - def test_only_declared_infra_importer_may_use_the_leaf(self) -> None: - # D020: infra -> the data leaf passes, and only infra.inspection is - # the declared infra importer of that leaf. + def test_only_declared_host_importer_may_use_the_leaf(self) -> None: + # D020: host inspection -> the data leaf passes, and only apps.host.inspection is + # the declared importer of that leaf (#498 slice 3a moved it from Infra). report = _report({}) self.assertEqual(report.violations, ()) - infra_leaf = { + host_leaf = { importer for importer in support.LEAF_IMPORTERS - if importer.startswith("inferrsi.infra") + if importer.startswith("inferrsi.apps.host") } - self.assertEqual(infra_leaf, {"inferrsi.infra.inspection"}) + self.assertEqual(host_leaf, {"inferrsi.apps.host.inspection"}) report = _report( - {"infra/other.py": "from ..resources.repository_packs import REPO_TYPES\n"} + {"apps/host/other.py": "from ...resources.repository_packs import REPO_TYPES\n"} ) self.assertTrue( _violated( report, - "inferrsi.infra.other is a second importer of " + "inferrsi.apps.host.other is a second importer of " "inferrsi.resources.repository_packs", ), report.violations, @@ -351,15 +353,17 @@ class PermanentLeafImporterTest(unittest.TestCase): def test_the_rule_is_one_importer_and_one_name_and_not_a_pair(self) -> None: self.assertEqual( support.LEAF_IMPORTERS, - {"inferrsi.infra.inspection": frozenset({"repository_pack"})}, + {"inferrsi.apps.host.inspection": frozenset({"repository_pack"})}, ) # #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. + # No Knowledge, Harness or Benchmark module is declared, and no prefix. #498 slice + # 3a moved the one importer into the Apps host package, which keeps Infra's limit. for importer in support.LEAF_IMPORTERS: - self.assertIsNone(support._core_of(importer), importer) + self.assertTrue(importer.startswith("inferrsi.apps.host."), importer) + self.assertNotIn(support._core_of(importer), ("knowledge", "harness", "benchmark")) self.assertNotIn("*", importer) def test_the_permanent_rule_alone_does_not_block(self) -> None: @@ -389,7 +393,7 @@ def test_the_edge_is_admitted_by_the_rule_and_not_by_an_erased_scan(self) -> Non with mock.patch.dict(support.LEAF_IMPORTERS, clear=True): report = _report({}) self.assertTrue( - _violated(report, f"inferrsi.infra.inspection is a second importer of {LEAF}"), + _violated(report, f"inferrsi.apps.host.inspection is a second importer of {LEAF}"), report.violations, ) # The root parser that A1 deleted is refused on every count if it returns, and @@ -438,7 +442,7 @@ def test_another_importer_fails(self) -> None: def test_declared_importer_shape_is_exact(self) -> None: declared = ( - ("infra/inspection.py", "inferrsi.infra.inspection", INSPECTION, + ("apps/host/inspection.py", "inferrsi.apps.host.inspection", INSPECTION, "repository_pack", "REPO_TYPES"), ) for path, module, line, name, other in declared: @@ -589,12 +593,12 @@ def test_old_leaf_keeping_a_body_beside_its_k_module_fails(self) -> None: report = _staged( { "catalog.py": "def search_knowledge():\n return []\n", - "infra/inspection.py": "from ..catalog import search_knowledge\n", + "apps/host/inspection.py": "from ...catalog import search_knowledge\n", } ) self.assertTrue(_violated(report, "inferrsi.catalog has a function or class body")) self.assertTrue( - _violated(report, "inferrsi.infra.inspection reaches inferrsi.knowledge.catalog") + _violated(report, "inferrsi.apps.host.inspection reaches inferrsi.knowledge.catalog") ) @@ -686,7 +690,7 @@ def test_leaf_parent_initializer_must_stay_import_free(self) -> None: def test_core_import_in_the_leaf_parent_fails_every_closure_that_loads_it(self) -> None: report = _report({"resources/__init__.py": "from ..harness import api\n"}) - for importer in ("inferrsi.infra.inspection", "inferrsi.knowledge.catalog"): + for importer in ("inferrsi.apps.host.inspection", "inferrsi.knowledge.catalog"): with self.subTest(importer=importer): self.assertTrue( _violated(report, f"{importer} reaches inferrsi.harness"), report.violations @@ -720,16 +724,16 @@ def test_retired_root_leaf_is_outside_the_knowledge_closure(self) -> None: report.violations, ) - def test_infra_through_root_catalog_fails(self) -> None: + def test_host_inspection_through_root_catalog_fails(self) -> None: report = _report( { "catalog.py": _shell("inferrsi.catalog"), - "infra/inspection.py": "from ..catalog import repository_pack\n", + "apps/host/inspection.py": "from ...catalog import repository_pack\n", } ) self.assertIn( - "inferrsi.infra.inspection reaches inferrsi.knowledge.catalog: " - "inferrsi.infra.inspection -> inferrsi.catalog -> inferrsi.knowledge.catalog", + "inferrsi.apps.host.inspection reaches inferrsi.knowledge.catalog: " + "inferrsi.apps.host.inspection -> inferrsi.catalog -> inferrsi.knowledge.catalog", report.violations, ) @@ -748,7 +752,7 @@ def test_undeclared_dynamic_edge_fails_closed(self) -> None: source = "import importlib\n\n\ndef load():\n return importlib.import_module('x')\n" for path, module in ( ("knowledge/research.py", "inferrsi.knowledge.research"), - ("infra/inspection.py", "inferrsi.infra.inspection"), + ("apps/host/inspection.py", "inferrsi.apps.host.inspection"), ): with self.subTest(path=path): report = _report({path: source}) @@ -879,8 +883,8 @@ def test_contract_modules_import_no_inferrsi_module(self) -> None: ), ( "contracts/runspec.py", - "from inferrsi.infra import inspection\n", - "inferrsi.contracts.runspec imports inferrsi.infra.inspection", + "from inferrsi.infra import artifacts\n", + "inferrsi.contracts.runspec imports inferrsi.infra", ), ( "contracts/claim.py", @@ -1232,7 +1236,7 @@ def test_returning_r2_harness_infra_edges_fail(self) -> None: # relative or absolute, top-level or inside a function, reports both the package # and the module edge; reaching another infra module or model also counts. infra = {"infra/__init__.py": "", "infra/artifacts.py": "VALUE = 1\n", - "infra/processes.py": "VALUE = 1\n", "model/__init__.py": "", + "infra/other.py": "VALUE = 1\n", "model/__init__.py": "", "model/metrics.py": "VALUE = 1\n"} primitives = {"harness/artifact_primitives.py": "VALUE = 1\n", "harness/atomic_json.py": "VALUE = 1\n"} @@ -1248,7 +1252,8 @@ def test_returning_r2_harness_infra_edges_fail(self) -> None: ("from ..infra.artifacts import VALUE\n", "inferrsi.infra.artifacts"), ("def late():\n from inferrsi.infra.artifacts import VALUE\n", "inferrsi.infra.artifacts"), - ("from ..infra import processes\n", "inferrsi.infra.processes"), + # #498 retired infra.processes and infra.commands; other is a synthetic Infra module. + ("from ..infra import other\n", "inferrsi.infra.other"), ("from inferrsi.model import metrics\n", "inferrsi.model.metrics"), ) for name in modules: diff --git a/tests/test_image_modules.py b/tests/test_image_modules.py index 63cf1763d..35cbf0b89 100644 --- a/tests/test_image_modules.py +++ b/tests/test_image_modules.py @@ -9,8 +9,8 @@ from inferrsi.benchmark.sampling import collect_samples from inferrsi.benchmark.validators.image import ImageQualityGate, compare_images +from inferrsi.harness.serving.image import ImageProtocol from inferrsi.infra.artifacts import sha256 -from inferrsi.model.protocols.image import ImageProtocol def test_image_protocol_and_sample_collection_use_real_http(tmp_path): diff --git a/tests/test_inspection.py b/tests/test_inspection.py index 13b7a8e90..a24746227 100644 --- a/tests/test_inspection.py +++ b/tests/test_inspection.py @@ -16,10 +16,10 @@ import pytest from inferrsi.apps import inspection as host_inspection +from inferrsi.apps.host import commands, targets +from inferrsi.apps.host import inspection as facts from inferrsi.apps.inspection import inspect_environment from inferrsi.apps.legacy.reporting import write_report -from inferrsi.infra import commands, targets -from inferrsi.infra import inspection as facts from inferrsi.infra.artifacts import atomic_write_json ROCM_INFO = ( @@ -220,7 +220,7 @@ def test_real_python_reports_requested_versions(self): def test_hostname_is_not_captured_in_environment_or_report(tmp_path): hostname = "private-host.example.invalid" - with patch("inferrsi.infra.inspection.platform.node", return_value=hostname) as node: + with patch("inferrsi.apps.host.inspection.platform.node", return_value=hostname) as node: environment = InspectionTests().inspect_cuda("0, GPU-test, Synthetic GPU, 999.0\n") node.assert_not_called() assert "hostname" not in environment["host"] @@ -321,7 +321,7 @@ def test_probe_results_are_recorded_as_the_port_returned_them(monkeypatch): assert result["compatibility"] == "unverified" -def test_retired_root_inspection_is_gone_and_infra_loads_no_apps(): +def test_retired_root_inspection_is_gone_and_host_facts_load_no_core(): assert importlib.util.find_spec("inferrsi.inspection") is None with pytest.raises(ModuleNotFoundError): importlib.import_module("inferrsi.inspection") @@ -331,11 +331,15 @@ def test_retired_root_inspection_is_gone_and_infra_loads_no_apps(): assert pickle.loads(pickle.dumps(inspect_environment)) is inspect_environment script = ( "import sys\n" - "import inferrsi.infra.inspection\n" - "cores = ('inferrsi.apps', 'inferrsi.knowledge', 'inferrsi.harness',\n" - " 'inferrsi.benchmark')\n" + # #498 slice 3a: the facts API lives in apps/host and still loads no core module + # and no Apps module outside its own package. + "import inferrsi.apps.host.inspection\n" + "cores = ('inferrsi.knowledge', 'inferrsi.harness', 'inferrsi.benchmark')\n" "loaded = [name for name in sys.modules if name.startswith(cores)]\n" "assert not loaded, loaded\n" + "apps = [name for name in sys.modules if name.startswith('inferrsi.apps.')\n" + " and not name.startswith('inferrsi.apps.host')]\n" + "assert not apps, apps\n" # The retired root binding reached the snapshot through the old run. The # canonical one loads no Benchmark module and no old-run composition. "import inferrsi.apps.inspection\n" diff --git a/tests/test_knowledge_compatibility_shells.py b/tests/test_knowledge_compatibility_shells.py index c6482a8a2..0ef3a4443 100644 --- a/tests/test_knowledge_compatibility_shells.py +++ b/tests/test_knowledge_compatibility_shells.py @@ -32,7 +32,8 @@ 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] +# #498 slice 3a appended the A1 record after it. +R1_RECORD = next(item for item in HISTORY if item["stage"] == "R1") LEAF_NAMES = RETIRED["retired_catalog_two_routes"]["neutral_leaf_export"]["symbols"] MOVED = [item for item in RETIRED["retired_compatibility_pairs"] if "exports" in item] @@ -64,7 +65,7 @@ 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 R1_RECORD["stage"] == "R1" and HISTORY[-2] is RETIRED + assert HISTORY.index(R1_RECORD) == HISTORY.index(RETIRED) + 1 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"]] @@ -186,18 +187,25 @@ def test_relocated_leaf_shape_matches_the_relocked_manifest_exactly(): ] -def test_infra_inspection_imports_the_leaf_by_the_recorded_line(): +def test_host_inspection_imports_the_leaf_by_the_recorded_line(): + # The K01/C2 rewrite record is history: it names the Infra file that #498 slice 3a + # moved to apps/host. The moved file binds the same name one package level deeper. rewrite = MANIFEST["infra_inspection_rewrite"] - lines = (REPO / rewrite["module"]).read_text(encoding="utf-8").splitlines() - assert lines[9] == rewrite["canonical_import"] + assert rewrite["module"] == "src/inferrsi/infra/inspection.py" + assert not (REPO / rewrite["module"]).exists() assert rewrite["canonical_import"] == "from ..resources.repository_packs import repository_pack" + importer = LEAF["permanent_importers"]["importers"][0] + lines = (REPO / importer["file"]).read_text(encoding="utf-8").splitlines() + assert lines[9] == importer["import_line"] == "from ." + rewrite["canonical_import"][5:] assert not [line for line in lines if "_repo_pack_data" in line or "catalog" in line] +def _section_importers(section: dict) -> dict[str, frozenset[str]]: + return {item["importer"]: frozenset(item["names"]) for item in section["importers"]} + + def _declared(section: str) -> dict[str, frozenset[str]]: - return { - item["importer"]: frozenset(item["names"]) for item in LEAF[section]["importers"] - } + return _section_importers(LEAF[section]) def test_manifest_restates_the_exact_gate_importer_rules(): @@ -205,8 +213,24 @@ def test_manifest_restates_the_exact_gate_importer_rules(): permanent = LEAF["permanent_importers"] temporary = R1_RECORD["retired_temporary_importers"] assert _declared("permanent_importers") == LEAF_IMPORTERS == { + "inferrsi.apps.host.inspection": frozenset({"repository_pack"}), + } + # #498 slice 3a moved the importer with its file. The A1 state is kept unchanged in + # the history, and the old module is retired, so it is not admitted beside the new one. + moved = HISTORY[-1] + assert moved["stage"] == "A1" + assert moved["base_commit"] == "aaa17a5dd333449d15fb052bb09b2012d55f2327" + assert MANIFEST["base_commit"] in moved["superseded_by"] + assert _section_importers(moved["retired_permanent_importers"]) == { "inferrsi.infra.inspection": frozenset({"repository_pack"}), } + assert moved["retired_permanent_importers"]["importers"][0]["import_line"] == ( + MANIFEST["infra_inspection_rewrite"]["canonical_import"] + ) + assert "inferrsi.infra.inspection" in support.RETIRED_MODULES + assert permanent["relocated"]["from"] == "inferrsi.infra.inspection" + assert permanent["relocated"]["to"] == "inferrsi.apps.host.inspection" + assert "requires the same formal architecture review" in permanent["relocated"]["review"] # #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 @@ -217,7 +241,7 @@ def test_manifest_restates_the_exact_gate_importer_rules(): assert not (REPO / temporary["importers"][0]["file"]).exists() assert MANIFEST["compatibility_pairs"] == [] assert permanent["importers"][0]["import_line"] == ( - MANIFEST["infra_inspection_rewrite"]["canonical_import"] + "from ...resources.repository_packs import repository_pack" ) # The review requirement is recorded for both, never an approval. for section in (permanent, temporary): @@ -263,18 +287,18 @@ def _fresh(script: str) -> None: assert result.returncode == 0, result.stderr -def test_package_init_and_infra_inspection_load_no_knowledge_body(): +def test_package_init_and_host_inspection_load_no_knowledge_body(): _fresh( "import sys\n" "import inferrsi.knowledge\n" "assert not [m for m in sys.modules if m.startswith('inferrsi.knowledge.')]\n" - "import inferrsi.infra.inspection\n" + "import inferrsi.apps.host.inspection\n" "assert 'inferrsi.catalog' not in sys.modules\n" "assert not [m for m in sys.modules if m.startswith('inferrsi.knowledge.')]\n" "assert 'inferrsi.resources.repository_packs' in sys.modules\n" "assert 'inferrsi._repo_pack_data' not in sys.modules\n" # Reading a Harness-owned pack never loads Harness. - "from inferrsi.infra.inspection import repository_pack\n" + "from inferrsi.apps.host.inspection import repository_pack\n" "assert repository_pack('vllm')['id'] == 'vllm'\n" "assert not [m for m in sys.modules if m.startswith('inferrsi.harness')]\n" ) diff --git a/tests/test_legacy_run_split.py b/tests/test_legacy_run_split.py index 313ff4a77..6c2595e7e 100644 --- a/tests/test_legacy_run_split.py +++ b/tests/test_legacy_run_split.py @@ -13,6 +13,7 @@ import pytest +from inferrsi.apps.host import targets from inferrsi.apps.legacy import evaluation as legacy_evaluation from inferrsi.apps.legacy import reporting as legacy_reporting from inferrsi.apps.legacy import run as legacy_run @@ -21,14 +22,13 @@ from inferrsi.harness import atomic_json from inferrsi.harness.runner import run_experiment from inferrsi.harness.scenarios.external import execute_trial -from inferrsi.infra import artifacts, targets +from inferrsi.infra import artifacts from tests._gate_policy_support import ROOT, _scan, _walk GRAPH = _scan(ROOT, frozenset()) # The local process domain that Harness still borrows until it owns that code. PROCESS_DOMAIN = { "inferrsi.infra", "inferrsi.infra.executors", "inferrsi.infra.executors.local", - "inferrsi.infra.processes", } diff --git a/tests/test_mlx_discovery.py b/tests/test_mlx_discovery.py index f3b9282fc..3a76a61b7 100644 --- a/tests/test_mlx_discovery.py +++ b/tests/test_mlx_discovery.py @@ -6,10 +6,10 @@ import pytest from inferrsi.apps.cli import main -from inferrsi.infra.commands import probe_command -from inferrsi.infra.platforms import inspect_device -from inferrsi.infra.platforms import mlx as mlx_platform -from inferrsi.infra.platforms.mlx import _parse_sysctl_info +from inferrsi.apps.host.commands import probe_command +from inferrsi.apps.host.platforms import inspect_device +from inferrsi.apps.host.platforms import mlx as mlx_platform +from inferrsi.apps.host.platforms.mlx import _parse_sysctl_info from inferrsi.knowledge.catalog import get_knowledge, search_knowledge from inferrsi.knowledge.knowledge_operations import KnowledgeReader from inferrsi.resources.repository_packs import REPO_TYPES diff --git a/tests/test_module_boundaries.py b/tests/test_module_boundaries.py index 45a8b9ab4..6cdd298dc 100644 --- a/tests/test_module_boundaries.py +++ b/tests/test_module_boundaries.py @@ -10,11 +10,11 @@ import pytest +from inferrsi.apps.host.platforms import PLATFORM_PROBES, inspect_device +from inferrsi.apps.host.platforms.cuda import qualify_devices from inferrsi.apps.legacy.run import execute_trial, run_experiment from inferrsi.benchmark.metrics import read_metric from inferrsi.contracts import RunSpec -from inferrsi.infra.platforms import PLATFORM_PROBES, inspect_device -from inferrsi.infra.platforms.cuda import qualify_devices def test_new_scenario_target_and_backend_share_abba_and_verdict(tmp_path): @@ -90,11 +90,11 @@ def test_cuda_qualification_accepts_campaign_supplied_count_and_sku(monkeypatch) monkeypatch.setenv("CUDA_VISIBLE_DEVICES", "GPU-fixture") device = subprocess.CompletedProcess([], 0, "0, GPU-fixture, NVIDIA H100 SXM, driver\n", "") empty = subprocess.CompletedProcess([], 0, "", "") - with patch("inferrsi.infra.platforms.cuda.subprocess.run", side_effect=[device, empty]): + with patch("inferrsi.apps.host.platforms.cuda.subprocess.run", side_effect=[device, empty]): selected = qualify_devices(count=1, device_model="H100") assert selected[0]["uuid"] == "GPU-fixture" busy = subprocess.CompletedProcess([], 0, "GPU-fixture, 123, other-work\n", "") - with patch("inferrsi.infra.platforms.cuda.subprocess.run", side_effect=[device, busy]): + with patch("inferrsi.apps.host.platforms.cuda.subprocess.run", side_effect=[device, busy]): with pytest.raises(ValueError, match="already has a compute process"): qualify_devices(count=1, device_model="H100") diff --git a/tests/test_optimization_session.py b/tests/test_optimization_session.py index a37836ff0..86a172850 100644 --- a/tests/test_optimization_session.py +++ b/tests/test_optimization_session.py @@ -1,6 +1,7 @@ """Run the current-Agent protocol using real child processes and synthetic work.""" import json +from pathlib import Path import pytest @@ -451,7 +452,6 @@ def collect(self, query, **options): def test_runtime_identity_covers_migrated_process_domain_and_not_removed_executor() -> None: from importlib.resources import files - from pathlib import Path identity = optimization_session._runtime_identity() root = Path(str(files("inferrsi"))) @@ -463,3 +463,67 @@ def test_runtime_identity_covers_migrated_process_domain_and_not_removed_executo assert "infra/executors/local.py" not in identity for name in identity: assert (root / name).is_file(), name + # #498 slice 2: the server helpers moved to harness/serving/server.py. A new plan binds + # that canonical file by its installed bytes, and the old Infra path is gone. + import hashlib + + assert "infra/processes.py" not in identity + server = (root / "harness/serving/server.py").read_bytes() + assert identity["harness/serving/server.py"] == hashlib.sha256(server).hexdigest() + + +PRE_SERVING = (Path(__file__).resolve().parent / "fixtures" / "optimization-session" + / "pre-serving-runtime-identity.json") + + +def _refused(session, capsys, action): + # The CLI reports the refusal as a usage error: argparse exits with status 2. + with pytest.raises(SystemExit) as stopped: + main(["benchmarks", "session", action, "--session", str(session)]) + assert stopped.value.code == 2 + return capsys.readouterr() + + +def test_a_plan_from_before_the_serving_move_is_refused_and_left_unchanged(session, capsys): + # #498 slice 2. The fixture holds the runtime identity that main at its source commit + # records, computed from that commit's own file bytes, so it names infra/processes.py. + # The new runtime refuses such a plan before status or recover dispatches, and keeps the + # plan bytes; resume it with the runtime that planned it (CHANGELOG). + pinned = json.loads(PRE_SERVING.read_text(encoding="utf-8"))["runtime_identity"] + assert "infra/processes.py" in pinned and "harness/serving/server.py" not in pinned + path = session / "plan.json" + plan = json.loads(path.read_text(encoding="utf-8")) + plan["runtime_identity"] = pinned + path.write_text(json.dumps(plan), encoding="utf-8") + before = path.read_bytes() + capsys.readouterr() + for action in ("status", "recover"): + output = _refused(session, capsys, action) + assert "Optimization runtime changed" in output.out + output.err, action + assert path.read_bytes() == before + + +def test_changed_installed_server_bytes_refuse_an_untouched_plan( + session, capsys, monkeypatch, tmp_path, +): + # Review of bf65c76: change the installed server, not the plan. A disposable copy of + # the identity files stands in for the installation; the plan from start is untouched. + import shutil + from importlib.resources import files + + installed = Path(str(files("inferrsi"))) + copy = tmp_path / "install" / "inferrsi" + for name in optimization_session._runtime_identity(): + (copy / name).parent.mkdir(parents=True, exist_ok=True) + shutil.copyfile(installed / name, copy / name) + monkeypatch.setattr(optimization_session, "files", lambda package: copy) + path = session / "plan.json" + before = path.read_bytes() + capsys.readouterr() + assert main(["benchmarks", "session", "status", "--session", str(session)]) == 0 + server = copy / "harness/serving/server.py" + server.write_bytes(server.read_bytes() + b"\n# changed canonical bytes\n") + capsys.readouterr() + output = _refused(session, capsys, "status") + assert "Optimization runtime changed" in output.out + output.err + assert path.read_bytes() == before diff --git a/tests/test_qwen21_artifact_ownership.py b/tests/test_qwen21_artifact_ownership.py index d81a974a1..d6eb3eae6 100644 --- a/tests/test_qwen21_artifact_ownership.py +++ b/tests/test_qwen21_artifact_ownership.py @@ -46,7 +46,7 @@ def manifest(self, name): "id": prompt["id"], "group": 1, "path": str(path), - "sha256": campaign.lifecycle.sha256(path), + "sha256": campaign.artifacts.sha256(path), } ) first = directory / "first.png" @@ -56,7 +56,7 @@ def manifest(self, name): "diagnostic": False, "source_integrity": {"verified": True}, "protocol": protocol, - "protocol_sha256": campaign.lifecycle.digest(protocol), + "protocol_sha256": campaign.artifacts.digest(protocol), "protected_sources": {}, "guard_hashes": {}, "dependency_versions": {}, @@ -66,7 +66,7 @@ def manifest(self, name): "artifacts": artifacts, "first_request": { "path": str(first), - "sha256": campaign.lifecycle.sha256(first), + "sha256": campaign.artifacts.sha256(first), "seed": 10042, }, } diff --git a/tests/test_qwen21_turbo_campaign.py b/tests/test_qwen21_turbo_campaign.py index de64856a4..1b414a6e1 100644 --- a/tests/test_qwen21_turbo_campaign.py +++ b/tests/test_qwen21_turbo_campaign.py @@ -81,7 +81,7 @@ def test_final_source_probe_failure_still_writes_failed_manifest(self): ) with ( patch.object( - campaign.lifecycle, + campaign.targets, "source_snapshot", side_effect=[{"snapshot_hash": "fixed"}, OSError("source probe unavailable")], ), @@ -145,7 +145,7 @@ def test_precreated_runner_directory_preserves_failure_evidence(self): ) with ( patch.object( - campaign.lifecycle, "source_snapshot", return_value={"snapshot_hash": "fixed"} + campaign.targets, "source_snapshot", return_value={"snapshot_hash": "fixed"} ), patch.object(campaign, "protected_sources", return_value={"method": "fixed"}), patch.object(campaign, "guards", return_value={"guard": "fixed"}), @@ -164,7 +164,7 @@ def test_native_schedule_and_diagnostic_are_distinct(self): short = campaign.protocol(True, 2) self.assertEqual(len(full["sigmas"]), 8) self.assertEqual(short["sigmas"], [1.0, 0.414568]) - self.assertNotEqual(campaign.lifecycle.digest(full), campaign.lifecycle.digest(short)) + self.assertNotEqual(campaign.artifacts.digest(full), campaign.artifacts.digest(short)) self.assertEqual((full["width"], full["height"]), (1280, 704)) self.assertEqual(full["true_cfg_scale"], 1.0) with self.assertRaises(ValueError): @@ -209,7 +209,7 @@ def test_diagnostic_failed_source_drift_and_digest_tampering_cannot_pass(self): "diagnostic": False, "source_integrity": {"verified": True}, "protocol": campaign.protocol(), - "protocol_sha256": campaign.lifecycle.digest(campaign.protocol()), + "protocol_sha256": campaign.artifacts.digest(campaign.protocol()), } with tempfile.TemporaryDirectory() as temp: path = Path(temp) / "result.json" @@ -242,7 +242,7 @@ def test_asset_stat_or_file_coverage_change_is_rejected(self): "path": "weight.bin", "bytes": st.st_size, "mtime_ns": st.st_mtime_ns, - "sha256": campaign.lifecycle.sha256(weight), + "sha256": campaign.artifacts.sha256(weight), } ], } diff --git a/tests/test_repository_packs_facade.py b/tests/test_repository_packs_facade.py index 7b6de3461..70ff5c054 100644 --- a/tests/test_repository_packs_facade.py +++ b/tests/test_repository_packs_facade.py @@ -24,7 +24,7 @@ import inferrsi.resources as resources from inferrsi.apps.cli import arguments -from inferrsi.infra import inspection +from inferrsi.apps.host import inspection from inferrsi.knowledge import catalog as knowledge_catalog from inferrsi.resources import repository_packs from tests.test_contracts_package import IO_CONTROL, IO_PROBE diff --git a/tests/test_runtime.py b/tests/test_runtime.py index 090c70a27..1b0dca63d 100644 --- a/tests/test_runtime.py +++ b/tests/test_runtime.py @@ -12,12 +12,12 @@ from types import SimpleNamespace from unittest.mock import patch +from inferrsi.apps.host.environment import storage_locations from inferrsi.apps.legacy.evaluation import _summary, evaluate from inferrsi.apps.legacy.reporting import write_report from inferrsi.apps.legacy.run import execute_trial, repository_identity, run_experiment from inferrsi.apps.legacy.run import run_experiment as run_with_adapters from inferrsi.contracts import RunSpec -from inferrsi.infra.environment import storage_locations def benchmark(value: object) -> tuple[str, ...]: @@ -426,7 +426,7 @@ def test_identical_symlink_recreation_keeps_the_directory_digest(self): # Two links to the same target must hash the same regardless of the order # the filesystem happens to enumerate them in. Unlinking and recreating a # link with an identical target is not a source change. - from inferrsi.infra.targets.git import _directory_digest + from inferrsi.apps.host.targets.git import _directory_digest nested = self.repo / "nested" nested.mkdir() @@ -448,7 +448,7 @@ def test_identical_symlink_recreation_keeps_the_directory_digest(self): def test_directory_symlink_retarget_changes_directory_digest(self): # os.walk does not descend symlinked directories, so an unrecorded link # let a dependency swap leave the nested-repository hash unchanged. - from inferrsi.infra.targets.git import _directory_digest + from inferrsi.apps.host.targets.git import _directory_digest nested = self.repo / "nested" (nested / "package").mkdir(parents=True) diff --git a/tests/test_server_processes.py b/tests/test_server_processes.py index 4224b7c41..b71c3c6c9 100644 --- a/tests/test_server_processes.py +++ b/tests/test_server_processes.py @@ -10,7 +10,7 @@ import pytest -from inferrsi.infra import processes +from inferrsi.harness.serving import server as processes @pytest.mark.parametrize("platform", ["win32", "darwin"]) @@ -67,7 +67,7 @@ def test_cleanup_after_leader_exit_preserves_unrelated_process(tmp_path, supervi # The helper runs in its own group, as it would inside the trial executor. helper = """ import json, os, sys -from inferrsi.infra.processes import launch_server, stop_server +from inferrsi.harness.serving.server import launch_server, stop_server with open(sys.argv[3], 'wb') as log: process, owner = launch_server([sys.executable, sys.argv[1], sys.argv[2]], '.', os.environ.copy(), log) diff --git a/tests/test_target_module_import_gate.py b/tests/test_target_module_import_gate.py index a6b417da8..b0cb0da0f 100644 --- a/tests/test_target_module_import_gate.py +++ b/tests/test_target_module_import_gate.py @@ -168,8 +168,28 @@ def test_by_path_loading_is_admitted_nowhere_else(tmp_path, relative): "inferrsi.model.validators.image"), ("apps/runner.py", "from inferrsi.model.validators.flare import main\n", "inferrsi.model.validators.flare"), - ("model/protocols/image.py", "from .metrics import read_metric\n", + ("model/request_guard.py", "from .protocols.metrics import read_metric\n", "inferrsi.model.protocols.metrics"), + # #498 slice 2: the serving modules moved to inferrsi.harness.serving. + ("benchmark/runner.py", "from inferrsi.infra.processes import launch_server\n", + "inferrsi.infra.processes"), + ("apps/runner.py", "from inferrsi.infra import http\n", "inferrsi.infra.http"), + ("harness/runner.py", "from ..model.protocols.image import ImageProtocol\n", + "inferrsi.model.protocols.image"), + ("apps/runner.py", "import inferrsi.model.protocols\n", "inferrsi.model.protocols"), + # #498 slice 3c: the campaign facade is gone. + ("apps/runner.py", "from inferrsi.infra import campaign as lifecycle\n", + "inferrsi.infra.campaign"), + ("benchmark/runner.py", "from inferrsi.infra.campaign import helper_hashes\n", + "inferrsi.infra.campaign"), + # #498 slice 3a: the host bindings moved to inferrsi.apps.host. + ("apps/runner.py", "from inferrsi.infra.inspection import inspect_environment\n", + "inferrsi.infra.inspection"), + ("benchmark/runner.py", "from inferrsi.infra import targets\n", "inferrsi.infra.targets"), + ("apps/runner.py", "import inferrsi.infra.platforms.cuda\n", "inferrsi.infra.platforms.cuda"), + ("apps/runner.py", "from ..infra.environment import storage_locations\n", + "inferrsi.infra.environment"), + ("apps/runner.py", "from ..infra.commands import probe_command\n", "inferrsi.infra.commands"), ]) def test_retired_model_paths_fail_to_import(tmp_path, importer, source, target): report = _report(tmp_path, {importer: source}) @@ -197,6 +217,14 @@ def test_retired_model_paths_fail_from_a_package_initializer(tmp_path, importer, "model/protocols/metrics.py", "model/validators/__init__.py", "model/validators/flare.py", + "model/protocols/__init__.py", + "model/protocols/image.py", + "infra/processes.py", + "infra/http.py", + "infra/campaign.py", + "infra/inspection.py", + "infra/platforms/__init__.py", + "infra/targets/git.py", ]) def test_retired_model_files_fail_when_they_return(tmp_path, relative): report = _report(tmp_path, {relative: "VALUE = 1\n"}) @@ -206,8 +234,9 @@ def test_retired_model_files_fail_when_they_return(tmp_path, relative): def test_the_model_paths_that_remain_are_not_retired(tmp_path): report = _report(tmp_path, { - "benchmark/runner.py": "from inferrsi.model.protocols import image\n", - "apps/runner.py": "from inferrsi.model.protocols.image import ImageProtocol\n", + "benchmark/runner.py": "from inferrsi.model import request_guard\n", + "apps/runner.py": "from inferrsi.infra.artifacts import sha256\n", + "harness/runner.py": "from inferrsi.harness.serving.image import ImageProtocol\n", }) assert not [item for item in report.violations if "retired module" in item]