diff --git a/.github/workflows/ci-merge.yml b/.github/workflows/ci-merge.yml index 72d0add0e..833eef3a4 100644 --- a/.github/workflows/ci-merge.yml +++ b/.github/workflows/ci-merge.yml @@ -18,8 +18,10 @@ jobs: test -f docs/contributing.md test -f README.md test -d src/inferrsi/harness - test -d src/inferrsi/model - test -d src/inferrsi/infra + test -d src/inferrsi/apps/host + test -d src/inferrsi/apps/integrations/anthropic + test ! -e src/inferrsi/model + test ! -e src/inferrsi/infra test -d evidence/_template/plan - uses: actions/setup-python@v5 with: diff --git a/.github/workflows/ci-ready.yml b/.github/workflows/ci-ready.yml index 9ee681676..cd2c01b6d 100644 --- a/.github/workflows/ci-ready.yml +++ b/.github/workflows/ci-ready.yml @@ -180,11 +180,13 @@ jobs: if counts != {"tests": len(nodes), "errors": 0, "failures": 0, "skipped": 0}: raise SystemExit("every selected host node must run and pass") - name: Test the Harness artifact-primitive and writer nodes on Windows - # #412 R2: Harness owns copies of the Infra digest, hash, file lock and atomic - # writer. On Windows the lock is an msvcrt byte range that even denies a read of - # the locked byte, which no Linux job can show. macOS uses the same fcntl lock as - # the Linux jobs, so only Windows runs these nodes. Runs even if the step above - # failed, so both results are recorded. + # #412 R2: Harness owns copies of the digest, hash, file lock and atomic writer. + # #498 slices 3b and 5 gave Apps and Benchmark their own copies and removed Infra, + # so these nodes now compare the Harness copy with the Apps copy. On Windows the + # lock is an msvcrt byte range that even denies a read of the locked byte, which no + # Linux job can show. macOS uses the same fcntl lock as the Linux jobs, so only + # Windows runs these nodes. Runs even if the step above failed, so both results are + # recorded. if: ${{ !cancelled() && runner.os == 'Windows' }} shell: python env: @@ -196,12 +198,13 @@ jobs: import xml.etree.ElementTree as ET nodes = [ - "tests/test_skill_evaluation.py::test_harness_artifact_primitives_match_infra_bytes_and_semantics", - "tests/test_skill_evaluation.py::test_harness_owned_writes_and_digests_match_infra_bytes", - "tests/test_legacy_run_split.py::test_harness_writer_bytes_equal_the_infra_writer", + "tests/test_skill_evaluation.py::test_harness_artifact_primitives_match_apps_bytes_and_semantics", + "tests/test_skill_evaluation.py::test_harness_owned_writes_and_digests_match_apps_bytes", + "tests/test_legacy_run_split.py::test_harness_writer_bytes_equal_the_apps_writer", "tests/test_legacy_run_split.py::test_harness_writer_rejects_nan_and_leaves_no_file", - "tests/test_legacy_run_split.py::test_sampling_sha256_matches_the_infra_hasher", + "tests/test_legacy_run_split.py::test_sampling_sha256_matches_the_apps_hasher", "tests/test_optimization_session.py::test_runtime_identity_covers_migrated_process_domain_and_not_removed_executor", + "tests/test_session_lock_across_processes.py", "tests/test_agent_sessions.py", ] results = os.environ["RESULTS"] diff --git a/CHANGELOG.md b/CHANGELOG.md index fec80adce..3cfc341e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,29 @@ ### Changed +- The `inferrsi.infra` and `inferrsi.model` packages are removed (Refs #498, slices 3b, 4 + and 5). There is no forwarding module or alias, and the import gate fails any import of + either package name, with or without a file behind it. + - `inferrsi.infra.artifacts` is now `inferrsi.apps.artifacts`. Apps owns this copy with + the same function source as the Harness and Benchmark copies, and + `tests/test_artifact_helper_copies.py` keeps the three equal. `apps/delivery/`, the + tools, the examples and the tests import it. The Apps copy and `harness/artifact_primitives.py` + use the same `.session.lock` file lock, so a Harness writer and an Apps export exclude + each other across processes. + - `inferrsi.model.anthropic_agent`, `anthropic_edit_agent` and `request_guard` are now + `inferrsi.apps.integrations.anthropic.*`. Only the two path-valued `SOURCE` constants + changed. `tools/skill_eval_compare.py` hashes the new files as controllers, so a new + comparison plan binds them; an existing plan keeps its recorded identities. The + Messages worker still loads its adjacent `request_guard.py` by file location. + - The optimization session's runtime identity no longer hashes `infra/artifacts.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, as for the serving move. + - The package now holds exactly `apps`, `benchmark`, `contracts`, `harness`, `knowledge` + and `resources`. `tests/test_package_root_inventory.py` fails a returning `infra/` or + `model/`, a new sibling package and a missing one. + - The Windows host job now compares the Harness copy with the Apps copy and runs the + cross-process lock test. - Apps workflow implementations now live in `apps/workflows/`: campaign capture, task launching, paired benchmark comparison, improvement and skill evaluation. The previous Apps imports retain explicit compatibility exports. New optimization diff --git a/docs/architecture.md b/docs/architecture.md index 0ea517ba0..5a231374d 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -97,10 +97,10 @@ 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 | 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 | +| Apps | CLI, host bindings (source identity, device discovery/qualification, environment facts), artifact digests and JSON writes, provider integrations | Model constants, campaign gates or performance verdicts | -Dependencies flow from entrypoints to Harness. Harness reaches no Infra or Model -module, and Infra does not import Model or Harness. None +Dependencies flow from entrypoints to Harness. #498 removed the Infra and Model +packages, so Harness reaches neither. None of these shared packages imports a campaign from `examples/`. Environment inspection follows that direction. `apps/host/inspection.py` is the @@ -279,8 +279,11 @@ src/inferrsi/ 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/ - artifacts.py Hashing and evidence writes + artifacts.py Apps-owned hashing, file lock and evidence writes + integrations/anthropic/ + anthropic_agent.py Bounded direct Messages agent with frozen cost reservations + anthropic_edit_agent.py Bounded edit-and-check protocol + request_guard.py Request authorization broker, loaded by file location data/ repo_packs/ Contribution descriptors and versioned tuning knowledge knowledge_packs/ Dependency and peer knowledge, preserving existing tiers diff --git a/docs/local-skill-evaluation.md b/docs/local-skill-evaluation.md index fae594063..d592660ae 100644 --- a/docs/local-skill-evaluation.md +++ b/docs/local-skill-evaluation.md @@ -59,7 +59,7 @@ without silently changing its contract: ```python from inferrsi.benchmark.skill_eval_engineering import REQUEST -from inferrsi.infra.artifacts import write_json +from inferrsi.apps.artifacts import write_json write_json("cases.json", [{ "id": "serving-response-v1", "split": "development", diff --git a/docs/module-layout.md b/docs/module-layout.md index 3edb8ca37..a1b613efb 100644 --- a/docs/module-layout.md +++ b/docs/module-layout.md @@ -197,7 +197,8 @@ Several flat modules remain shared seams until their slice starts. | `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 | | `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/artifacts.py` | Apps's own file digests, file lock and JSON evidence writes | #498 slices 3b and 5 gave Apps this copy and deleted `infra/`; `tests/test_artifact_helper_copies.py` keeps it equal to the Harness and Benchmark copies | +| `apps/integrations/anthropic/` (`anthropic_agent.py`, `anthropic_edit_agent.py`, `request_guard.py`) | The bounded Anthropic Messages agent, its edit-and-check protocol and the request authorization broker | #498 slice 4 moved them from `model/` with no forwarder or alias; only the path-valued `SOURCE` constants changed. The worker loads `request_guard.py` by file location, so it must ship next to the agent | | `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 | diff --git a/examples/qwen21_turbo_b300.py b/examples/qwen21_turbo_b300.py index db31f6ca2..ab9cb2904 100644 --- a/examples/qwen21_turbo_b300.py +++ b/examples/qwen21_turbo_b300.py @@ -1,6 +1,6 @@ """Frozen 720p-class Qwen-Image-2.1-Turbo online B300 campaign. -Uses the stdlib InferRSI infrastructure package for source/device/process +Uses the stdlib InferRSI host, serving and artifact modules for source/device/process ownership. New campaigns must freeze fresh helper hashes and references. """ import argparse @@ -22,7 +22,7 @@ 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 +from inferrsi.apps import artifacts MODEL = "Qwen/Qwen-Image-2.1-Turbo" REVISION = "d65dbc9a7e8f6b5479e33dee6030eaab2a906509" diff --git a/examples/qwen21_turbo_quality.py b/examples/qwen21_turbo_quality.py index 457a1f48d..a258bc972 100644 --- a/examples/qwen21_turbo_quality.py +++ b/examples/qwen21_turbo_quality.py @@ -6,7 +6,7 @@ from pathlib import Path import sys -from inferrsi.infra import artifacts as lifecycle +from inferrsi.apps import artifacts as lifecycle def load(path): diff --git a/src/inferrsi/infra/artifacts.py b/src/inferrsi/apps/artifacts.py similarity index 91% rename from src/inferrsi/infra/artifacts.py rename to src/inferrsi/apps/artifacts.py index 44d113096..5690afdd8 100644 --- a/src/inferrsi/infra/artifacts.py +++ b/src/inferrsi/apps/artifacts.py @@ -1,4 +1,6 @@ -"""Deterministic digests and JSON evidence, without model dependencies.""" +# Apps-owned file digests, file locks and JSON evidence writes. The function bodies equal +# those in the other cores' copies; tests/test_artifact_helper_copies.py keeps them equal. +# Apps imports no other inferrsi module here. import hashlib import json diff --git a/src/inferrsi/apps/delivery/__init__.py b/src/inferrsi/apps/delivery/__init__.py index 959492d14..bcd8d5eac 100644 --- a/src/inferrsi/apps/delivery/__init__.py +++ b/src/inferrsi/apps/delivery/__init__.py @@ -9,7 +9,7 @@ from tempfile import TemporaryDirectory from ... import __version__ -from ...infra.artifacts import file_lock +from ..artifacts import file_lock from ..storage import archive from . import adapters from .projection import iterative diff --git a/src/inferrsi/apps/delivery/projection.py b/src/inferrsi/apps/delivery/projection.py index b9e01c6c4..701bc95fa 100644 --- a/src/inferrsi/apps/delivery/projection.py +++ b/src/inferrsi/apps/delivery/projection.py @@ -3,7 +3,7 @@ import re from ...harness.usage import normalize_usage -from ...infra.artifacts import digest +from ..artifacts import digest from .schema import gap, number, timestamp diff --git a/src/inferrsi/apps/delivery/snapshot.py b/src/inferrsi/apps/delivery/snapshot.py index ea4ce422c..f641c91db 100644 --- a/src/inferrsi/apps/delivery/snapshot.py +++ b/src/inferrsi/apps/delivery/snapshot.py @@ -6,7 +6,7 @@ from pathlib import Path, PurePosixPath from ...harness import candidates -from ...infra.artifacts import sha256 +from ..artifacts import sha256 from .schema import decode MAX_DOCUMENT_BYTES = 8 * 1024 * 1024 diff --git a/src/inferrsi/apps/integrations/__init__.py b/src/inferrsi/apps/integrations/__init__.py new file mode 100644 index 000000000..3b2169b30 --- /dev/null +++ b/src/inferrsi/apps/integrations/__init__.py @@ -0,0 +1 @@ +"""Apps integrations with external systems. The initializer imports nothing.""" diff --git a/src/inferrsi/apps/integrations/anthropic/__init__.py b/src/inferrsi/apps/integrations/anthropic/__init__.py new file mode 100644 index 000000000..37ff23bf9 --- /dev/null +++ b/src/inferrsi/apps/integrations/anthropic/__init__.py @@ -0,0 +1,4 @@ +"""Anthropic provider adapters and their request authorization. + +The initializer imports nothing. +""" diff --git a/src/inferrsi/model/anthropic_agent.py b/src/inferrsi/apps/integrations/anthropic/anthropic_agent.py similarity index 99% rename from src/inferrsi/model/anthropic_agent.py rename to src/inferrsi/apps/integrations/anthropic/anthropic_agent.py index 2a47e499e..d5671bd07 100644 --- a/src/inferrsi/model/anthropic_agent.py +++ b/src/inferrsi/apps/integrations/anthropic/anthropic_agent.py @@ -20,7 +20,7 @@ EDIT_KIND = "anthropic-messages-edit-check-v1" FULL_CONTEXT_MAX_REQUEST = 262144 ENDPOINT = "https://yibuapi.com/v1/messages" -SOURCE = "src/inferrsi/model/anthropic_agent.py" +SOURCE = "src/inferrsi/apps/integrations/anthropic/anthropic_agent.py" MAX_RESPONSE = 1024 * 1024 # Full context bound from https://platform.claude.com/docs/en/models/opus-5-5/overview MODEL_CONTEXT = {"claude-opus-5-5": 1000000} diff --git a/src/inferrsi/model/anthropic_edit_agent.py b/src/inferrsi/apps/integrations/anthropic/anthropic_edit_agent.py similarity index 100% rename from src/inferrsi/model/anthropic_edit_agent.py rename to src/inferrsi/apps/integrations/anthropic/anthropic_edit_agent.py diff --git a/src/inferrsi/model/request_guard.py b/src/inferrsi/apps/integrations/anthropic/request_guard.py similarity index 99% rename from src/inferrsi/model/request_guard.py rename to src/inferrsi/apps/integrations/anthropic/request_guard.py index 6fcf9d2c8..0781f82ed 100644 --- a/src/inferrsi/model/request_guard.py +++ b/src/inferrsi/apps/integrations/anthropic/request_guard.py @@ -19,7 +19,7 @@ from contextlib import contextmanager from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer -SOURCE = "src/inferrsi/model/request_guard.py" +SOURCE = "src/inferrsi/apps/integrations/anthropic/request_guard.py" ENV_KEYS = ("SKILL_EVAL_GATE_PORT", "SKILL_EVAL_GATE_TOKEN", "SKILL_EVAL_GATE_CONTEXT") diff --git a/src/inferrsi/contracts/__init__.py b/src/inferrsi/contracts/__init__.py index 16469adc6..3fb26f99c 100644 --- a/src/inferrsi/contracts/__init__.py +++ b/src/inferrsi/contracts/__init__.py @@ -2,7 +2,7 @@ ``RunSpec`` is the only name this initializer re-exports. Import the canonical encoder from ``contracts.json_v1`` and the verdict types from ``contracts.claim``. -No module here imports a core, Apps, Infra or Model module, or does I/O on import. +No module here imports a core or Apps module, or does I/O on import. """ from .runspec import RunSpec diff --git a/src/inferrsi/harness/artifact_primitives.py b/src/inferrsi/harness/artifact_primitives.py index 9a91652f7..ef7c26983 100644 --- a/src/inferrsi/harness/artifact_primitives.py +++ b/src/inferrsi/harness/artifact_primitives.py @@ -1,6 +1,7 @@ # Harness-owned digest, file hash and file lock. Each function body equals the one in -# infra.artifacts, so digests, hashes and lock files are byte-identical and the two locks -# exclude each other on the same path; Harness does not import that module here. +# inferrsi.apps.artifacts, so digests, hashes and lock files are byte-identical and the two +# locks exclude each other on the same path; Harness does not import that module here. +# tests/test_artifact_helper_copies.py keeps the copies equal. import hashlib import json diff --git a/src/inferrsi/harness/atomic_json.py b/src/inferrsi/harness/atomic_json.py index 056b7ee2c..788feeffd 100644 --- a/src/inferrsi/harness/atomic_json.py +++ b/src/inferrsi/harness/atomic_json.py @@ -1,5 +1,5 @@ # Harness-owned atomic JSON evidence writes. The bytes equal those written by -# infra.artifacts.atomic_write_json; Harness does not import that module here. +# inferrsi.apps.artifacts.atomic_write_json; Harness does not import that module here. import json import os diff --git a/src/inferrsi/harness/input_binding.py b/src/inferrsi/harness/input_binding.py index 0f22dba65..9ea05c85e 100644 --- a/src/inferrsi/harness/input_binding.py +++ b/src/inferrsi/harness/input_binding.py @@ -8,7 +8,7 @@ from typing import BinaryIO # H input capture and byte-equivalent copies. H owns these digests and writes and never -# imports infra.artifacts. A source is read once into a snapshot; every later copy comes +# imports inferrsi.apps.artifacts. A source is read once into a snapshot; every later copy comes # from that snapshot, never again from the mutable source. _CHUNK = 1024 * 1024 # Schema ``Path``: relative and slash-separated; no '.'/'..' segment, backslash, colon, diff --git a/src/inferrsi/harness/optimization_session.py b/src/inferrsi/harness/optimization_session.py index 8bbcb2979..5983ae1ab 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", - "harness/serving/server.py", "infra/artifacts.py", "harness/scenarios/external.py", + "harness/serving/server.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/infra/README.md b/src/inferrsi/infra/README.md deleted file mode 100644 index 65f042404..000000000 --- a/src/inferrsi/infra/README.md +++ /dev/null @@ -1,10 +0,0 @@ -# Infrastructure - -`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, 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 deleted file mode 100644 index 607949bcf..000000000 --- a/src/inferrsi/infra/__init__.py +++ /dev/null @@ -1 +0,0 @@ -"""Infrastructure plane: shared artifact digests and JSON evidence writes.""" diff --git a/src/inferrsi/model/README.md b/src/inferrsi/model/README.md deleted file mode 100644 index 40c7eadeb..000000000 --- a/src/inferrsi/model/README.md +++ /dev/null @@ -1,54 +0,0 @@ -# Model - -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 -new modules serve new campaigns. - -See [the architecture and compatibility boundary](../../../docs/architecture.md). - -## Bounded edit/check protocol - -`anthropic_edit_agent.run_edit_agent` is a separate fixed-tool protocol, not a -general coding agent and not the existing read/submit adapter. A trusted caller -supplies an explicit `EditPlan`, staged-file manifest, request allocation, -pre-send authorization, transport, visible check/benchmark callbacks and revision -storage. The only write tool replaces `candidate.py`; there is no shell, arbitrary -command, model-selected workload, discovery or default live transport. - -The worker retains every candidate revision through the trusted storage callback, -returns the exact final source snapshot, and records bounded, typed public check -and measurement receipts bound to plan, attempt, arm and source revision. A write -invalidates both receipts. Unknown provider usage or uncertain transport stops -the shared request allocation without refund. Structured feedback permits only -frozen public check IDs and selected finite benchmark fields, not raw logs, -private paths, hidden-grader diagnostics or oracle/reference code. - -Integration must supply the actual security and spending boundaries: - -- Run the trusted provider worker under `execute_command` with the same absolute - deadline passed to the protocol. Python deadline checks reject late results; - they cannot interrupt a blocked transport/callback. Every tool must inherit - this deadline; a nested `run_experiment` cannot extend it. -- Execute candidate bytes only in the qualified, network-free artifact sandbox, - with no credentials, full repository, undeclared knowledge or hidden oracle. - A callback is trusted host code, not a sandbox. No host-execution fallback. -- Compose visible measurement from the existing `run_experiment`/`evaluate` - path. Validate full candidate output independently before accepting host timing. - Final hidden grading is separate and occurs only after immutable submission. -- Reserve and claim the whole frozen cost in the existing durable PR/daily - ledgers, bind one immutable campaign/attempt, and check live authorization - before each send. `RequestSlots` adds nonrenewable per-arm in-process limits; - it neither creates a durable claim nor makes restarts safe by itself. -- Freeze exact implementation, callback/dependency hashes, qualification receipt, - exposed files, model/provider/pricing, byte/tool/request/time limits and budget - before calls. Use `frozen_identity` for offline protocol identity. Its callback - hash must cover transitive sandbox, executor, checker and workload dependencies. - -`tests/test_anthropic_edit_agent.py` uses scripted callbacks and transport. It -does not execute candidate code, qualify a sandbox, make model calls or establish -optimization efficacy. There is no paid-launch CLI in this module. diff --git a/src/inferrsi/model/__init__.py b/src/inferrsi/model/__init__.py deleted file mode 100644 index 5b87c8196..000000000 --- a/src/inferrsi/model/__init__.py +++ /dev/null @@ -1,5 +0,0 @@ -"""Model plane: the Anthropic provider adapters and their request authorization. - -The metric contract and the quality validators are in ``inferrsi.benchmark``; the -serving request clients are in ``inferrsi.harness.serving``. -""" diff --git a/tests/_gate_policy_support.py b/tests/_gate_policy_support.py index d82ab2c0c..92227c6c7 100644 --- a/tests/_gate_policy_support.py +++ b/tests/_gate_policy_support.py @@ -96,15 +96,10 @@ # ``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", "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", -}) +# Slices 3b, 4 and 5 moved the artifact helpers to ``inferrsi.apps.artifacts`` and the +# provider modules to ``inferrsi.apps.integrations.anthropic``, and deleted both packages, +# so the two package names are retired as a whole. +RETIRED_MODULES = frozenset({"inferrsi.infra", "inferrsi.model"}) # #412 R1, permanent: the one importer of the neutral data leaf outside # ``inferrsi.knowledge``, with the only name it may bind (D020: Infra reads one pack # description and reaches no Knowledge or Harness). This is not a manifest diff --git a/tests/check_installed.py b/tests/check_installed.py index 58bb4e996..8781d1bc2 100644 --- a/tests/check_installed.py +++ b/tests/check_installed.py @@ -842,11 +842,15 @@ def _inventory(root, prefix): 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"): +# slice 3a moved the host bindings to inferrsi.apps.host, and slices 3b, 4 and 5 moved the +# artifact helpers to inferrsi.apps.artifacts and the provider modules to +# inferrsi.apps.integrations.anthropic. Both packages are gone from the wheel. +for retired in ("inferrsi.infra", "inferrsi.infra.artifacts", "inferrsi.infra.processes", + "inferrsi.infra.http", "inferrsi.infra.campaign", "inferrsi.infra.commands", + "inferrsi.infra.inspection", "inferrsi.infra.environment", + "inferrsi.infra.platforms", "inferrsi.infra.targets", "inferrsi.model", + "inferrsi.model.anthropic_agent", "inferrsi.model.anthropic_edit_agent", + "inferrsi.model.request_guard"): assert find_spec(retired) is None, retired try: import_module(retired) @@ -854,12 +858,35 @@ def _inventory(root, prefix): pass else: raise AssertionError(f"retired module {retired} must not import") +assert not {child.name for child in files("inferrsi").iterdir()} & {"infra", "model"} 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"): + "inferrsi.apps.host.targets", "inferrsi.apps.artifacts", + "inferrsi.apps.integrations.anthropic.anthropic_agent", + "inferrsi.apps.integrations.anthropic.anthropic_edit_agent", + "inferrsi.apps.integrations.anthropic.request_guard"): assert find_spec(canonical) is not None, canonical +# The Messages worker runs under ``python -I`` and loads its adjacent trusted guard by file +# location, not through the package, so the guard must ship next to the agent. This offline +# probe loads the agent from the wheel the way the worker does, with no provider call. +guard_probe = ( + "import sys\n" + "from pathlib import Path\n" + "import inferrsi.apps.integrations.anthropic.anthropic_agent as agent\n" + "guard = Path(agent.__file__).with_name('request_guard.py')\n" + "assert guard.is_file(), guard\n" + "assert agent._guard['authorize_request'] and agent._guard['gate_environment']\n" + "assert agent.SOURCE.endswith('apps/integrations/anthropic/anthropic_agent.py'), agent.SOURCE\n" + "assert not [n for n in sys.modules if n.startswith(('inferrsi.infra', 'inferrsi.model'))]\n" +) +with tempfile.TemporaryDirectory(prefix="inferrsi-provider-") as provider_cwd: + provider = subprocess.run( + [sys.executable, "-I", "-B", "-c", guard_probe], capture_output=True, text=True, + check=False, cwd=provider_cwd, + ) +assert provider.returncode == 0, provider.stderr # 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 = ( diff --git a/tests/fixtures/harness_improvement_demo.py b/tests/fixtures/harness_improvement_demo.py index 49b3b8cd5..152e8115f 100644 --- a/tests/fixtures/harness_improvement_demo.py +++ b/tests/fixtures/harness_improvement_demo.py @@ -7,7 +7,7 @@ import tempfile from pathlib import Path -from inferrsi.infra.artifacts import write_json +from inferrsi.apps.artifacts import write_json from tests.fixtures.skill_eval_compare_support import DATA, ROOT, source_repo from tools import skill_eval_compare as compare from tools import skill_eval_improve as improve diff --git a/tests/fixtures/skill_eval_compare_support.py b/tests/fixtures/skill_eval_compare_support.py index 09061e75b..fb2add4d4 100644 --- a/tests/fixtures/skill_eval_compare_support.py +++ b/tests/fixtures/skill_eval_compare_support.py @@ -4,7 +4,7 @@ import sys from pathlib import Path -from inferrsi.infra.artifacts import sha256, write_json +from inferrsi.apps.artifacts import sha256, write_json ROOT = Path(__file__).resolve().parents[2] DATA = json.loads((ROOT / "tests/fixtures/skill_eval_grading.json").read_text(encoding="utf-8")) diff --git a/tests/fixtures/skill_eval_pr_support.py b/tests/fixtures/skill_eval_pr_support.py index 01afce2bf..f6572ae70 100644 --- a/tests/fixtures/skill_eval_pr_support.py +++ b/tests/fixtures/skill_eval_pr_support.py @@ -3,7 +3,7 @@ import zipfile from urllib.parse import parse_qs, urlsplit -from inferrsi.infra.artifacts import write_json +from inferrsi.apps.artifacts import write_json from tests.fixtures.skill_eval_compare_support import configuration, git from tools import skill_eval_compare as compare from tools import skill_eval_pr as integration diff --git a/tests/test_anthropic_agent.py b/tests/test_anthropic_agent.py index be63f3569..35ae87df3 100644 --- a/tests/test_anthropic_agent.py +++ b/tests/test_anthropic_agent.py @@ -6,10 +6,10 @@ import pytest +from inferrsi.apps.artifacts import sha256, write_json +from inferrsi.apps.integrations.anthropic import anthropic_agent as agent from inferrsi.apps.workflows import skill_evaluation as evaluation from inferrsi.harness import skill_evaluation as harness -from inferrsi.infra.artifacts import sha256, write_json -from inferrsi.model import anthropic_agent as agent from tests.fixtures.skill_eval_compare_support import configuration from tools import skill_eval_compare as compare from tools.skill_eval_pilot import SCHEMA diff --git a/tests/test_anthropic_edit_agent.py b/tests/test_anthropic_edit_agent.py index 145cd6a31..bd8725b36 100644 --- a/tests/test_anthropic_edit_agent.py +++ b/tests/test_anthropic_edit_agent.py @@ -6,8 +6,8 @@ import pytest -from inferrsi.model import anthropic_agent as provider -from inferrsi.model import anthropic_edit_agent as edit +from inferrsi.apps.integrations.anthropic import anthropic_agent as provider +from inferrsi.apps.integrations.anthropic import anthropic_edit_agent as edit MODEL = "claude-opus-5-5" PLAN_HASH = "a" * 64 diff --git a/tests/test_anthropic_full_context.py b/tests/test_anthropic_full_context.py index 3ad24cff7..222928f2f 100644 --- a/tests/test_anthropic_full_context.py +++ b/tests/test_anthropic_full_context.py @@ -6,7 +6,7 @@ import unittest from pathlib import Path -from inferrsi.model import anthropic_agent as agent +from inferrsi.apps.integrations.anthropic import anthropic_agent as agent class FullContextTests(unittest.TestCase): diff --git a/tests/test_apps_module_migrations.py b/tests/test_apps_module_migrations.py index 4582c3ca5..701f12ac3 100644 --- a/tests/test_apps_module_migrations.py +++ b/tests/test_apps_module_migrations.py @@ -179,7 +179,7 @@ def test_cold_storage_imports_do_not_load_handoff_or_probe_modules(): import importlib, importlib.abc, json, sys, warnings blocked = ('inferrsi.apps.handoff', 'inferrsi.apps.api', 'inferrsi.apps.bridge', 'inferrsi.apps.context_provider', 'inferrsi.apps.candidate_provider', - 'inferrsi.infra', 'inferrsi.knowledge', 'inferrsi.benchmark', + 'inferrsi.apps.host', 'inferrsi.knowledge', 'inferrsi.benchmark', 'inferrsi.harness.api', 'inferrsi.harness.run_store') class Block(importlib.abc.MetaPathFinder): def find_spec(self, name, path=None, target=None): @@ -231,7 +231,7 @@ def test_cold_handoff_and_workflow_imports_do_not_read_data_probe_or_launch_serv blocked = ('inferrsi.apps.api', 'inferrsi.harness.api', 'inferrsi.harness.run_store', 'inferrsi.harness.generation', 'torch', 'numpy', 'PIL', 'vllm') if sys.argv[2] == 'handoff': - blocked += ('inferrsi.infra', 'inferrsi.benchmark', 'inferrsi.model') + blocked += ('inferrsi.apps.host', 'inferrsi.benchmark', 'inferrsi.apps.integrations') class Block(importlib.abc.MetaPathFinder): def find_spec(self, name, path=None, target=None): if any(name == item or name.startswith(item + '.') for item in blocked): diff --git a/tests/test_artifact_helper_copies.py b/tests/test_artifact_helper_copies.py index 321d9d260..f04a37f61 100644 --- a/tests/test_artifact_helper_copies.py +++ b/tests/test_artifact_helper_copies.py @@ -10,14 +10,16 @@ import pytest -# Each helper name and the modules that hold a copy. #498 slice 5 drops ``infra`` here -# when it deletes the package; a later slice adds the Apps copy. +# Each helper name and the modules that hold a copy. #498 slice 3b added the Apps copy +# and slice 5 deleted the Infra one, so Harness, Benchmark and Apps hold the three. COPIES = { - "sha256": ("inferrsi.infra.artifacts", "inferrsi.harness.artifact_primitives", + "sha256": ("inferrsi.apps.artifacts", "inferrsi.harness.artifact_primitives", "inferrsi.benchmark.artifacts"), - "write_json": ("inferrsi.infra.artifacts", "inferrsi.benchmark.artifacts"), - "atomic_write_json": ("inferrsi.infra.artifacts", "inferrsi.harness.atomic_json", + "write_json": ("inferrsi.apps.artifacts", "inferrsi.benchmark.artifacts"), + "atomic_write_json": ("inferrsi.apps.artifacts", "inferrsi.harness.atomic_json", "inferrsi.benchmark.artifacts"), + "digest": ("inferrsi.apps.artifacts", "inferrsi.harness.artifact_primitives"), + "file_lock": ("inferrsi.apps.artifacts", "inferrsi.harness.artifact_primitives"), } CONSTANTS = ("REPLACE_ATTEMPTS", "REPLACE_DELAY_SECONDS") VALUE = {"b": [1.5, None, True, 1e-07, 1e16], "a": "非 ASCII", "nested": {"z": 0.1 + 0.2}} diff --git a/tests/test_campaign_trace.py b/tests/test_campaign_trace.py index 4ed60cb3e..3223c8cac 100644 --- a/tests/test_campaign_trace.py +++ b/tests/test_campaign_trace.py @@ -5,8 +5,8 @@ import pytest +from inferrsi.apps.integrations.anthropic import anthropic_agent as agent from inferrsi.harness.records.campaign_trace import CampaignTrace -from inferrsi.model import anthropic_agent as agent def test_correlated_full_context_trace_keeps_existing_metrics(tmp_path): diff --git a/tests/test_first_wave_isolation_policy.py b/tests/test_first_wave_isolation_policy.py index 23e93be8a..f02bede5f 100644 --- a/tests/test_first_wave_isolation_policy.py +++ b/tests/test_first_wave_isolation_policy.py @@ -101,7 +101,6 @@ def _k01_tree() -> dict[str, str]: "from ..resources import repository_packs\nfrom . import _source_snapshot\n" ), "knowledge/knowledge_operations.py": "from inferrsi.contracts import json_v1\n", - "infra/__init__.py": "", "apps/host/__init__.py": "", "apps/host/inspection.py": "from ...resources.repository_packs import repository_pack\n", "harness/__init__.py": "", @@ -1198,6 +1197,10 @@ def test_core_submodule_walk_includes_own_package_init(self) -> None: report = _report({"catalog.py": _shell("inferrsi.catalog"), **changes}) self.assertIn(expected, report.violations, report.violations) + # This test is about the Harness edge rule. The synthetic Infra and Model packages it + # builds are retired names since #498, which test_target_module_import_gate.py covers, so + # the retirement rule is switched off here and nothing else changes. + @mock.patch.object(support, "RETIRED_MODULES", frozenset()) def test_returning_skill_evaluation_infra_edge_fails(self) -> None: # #410 counterexample: S01 removed skill_evaluation -> infra.artifacts. # Adding it back is reported hit by hit and keeps isolation false. @@ -1231,6 +1234,10 @@ def test_returning_skill_evaluation_infra_edge_fails(self) -> None: ) self.assertFalse(report.isolation_complete) + # This test is about the Harness edge rule. The synthetic Infra and Model packages it + # builds are retired names since #498, which test_target_module_import_gate.py covers, so + # the retirement rule is switched off here and nothing else changes. + @mock.patch.object(support, "RETIRED_MODULES", frozenset()) def test_returning_r2_harness_infra_edges_fail(self) -> None: # #412 R2 removed infra.artifacts from six Harness modules. Putting one edge back, # relative or absolute, top-level or inside a function, reports both the package diff --git a/tests/test_flare_adapter.py b/tests/test_flare_adapter.py index 8467e1483..368c98bc1 100644 --- a/tests/test_flare_adapter.py +++ b/tests/test_flare_adapter.py @@ -122,7 +122,8 @@ def test_the_old_flare_cli_path_is_gone(packet, tmp_path): env={**os.environ, "PYTHONPATH": str(source)}, ) assert result.returncode == 1 - assert "No module named 'inferrsi.model.validators'" in result.stderr + # Since #498 the whole inferrsi.model package is gone, so Python stops at its parent. + assert "No module named 'inferrsi.model'" in result.stderr assert not (tmp_path / "receipt.json").exists() diff --git a/tests/test_goal_checkpoint.py b/tests/test_goal_checkpoint.py index 2cff24f16..ff844df8c 100644 --- a/tests/test_goal_checkpoint.py +++ b/tests/test_goal_checkpoint.py @@ -5,7 +5,7 @@ import pytest -from inferrsi.infra.artifacts import sha256, write_json +from inferrsi.apps.artifacts import sha256, write_json from tests.fixtures.skill_eval_compare_support import FixedOutputClient, configuration from tools import goal_checkpoint as checkpoint from tools import skill_eval_compare as compare diff --git a/tests/test_image_modules.py b/tests/test_image_modules.py index 35cbf0b89..a378bf129 100644 --- a/tests/test_image_modules.py +++ b/tests/test_image_modules.py @@ -7,10 +7,10 @@ import pytest +from inferrsi.apps.artifacts import sha256 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 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 a24746227..76004ee74 100644 --- a/tests/test_inspection.py +++ b/tests/test_inspection.py @@ -16,11 +16,11 @@ import pytest from inferrsi.apps import inspection as host_inspection +from inferrsi.apps.artifacts import atomic_write_json 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.artifacts import atomic_write_json ROCM_INFO = ( "=====================\n" diff --git a/tests/test_knowledge_compatibility_shells.py b/tests/test_knowledge_compatibility_shells.py index 099f311c7..747959672 100644 --- a/tests/test_knowledge_compatibility_shells.py +++ b/tests/test_knowledge_compatibility_shells.py @@ -234,7 +234,8 @@ def test_manifest_restates_the_exact_gate_importer_rules(): assert moved["retired_permanent_importers"]["importers"][0]["import_line"] == ( MANIFEST["infra_inspection_rewrite"]["canonical_import"] ) - assert "inferrsi.infra.inspection" in support.RETIRED_MODULES + assert any(support._matches("inferrsi.infra.inspection", name) + for name 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"] diff --git a/tests/test_legacy_run_split.py b/tests/test_legacy_run_split.py index 6c2595e7e..686b0c683 100644 --- a/tests/test_legacy_run_split.py +++ b/tests/test_legacy_run_split.py @@ -13,6 +13,7 @@ import pytest +from inferrsi.apps import artifacts from inferrsi.apps.host import targets from inferrsi.apps.legacy import evaluation as legacy_evaluation from inferrsi.apps.legacy import reporting as legacy_reporting @@ -22,14 +23,11 @@ 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 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", -} +# Harness reaches no Infra or Model module any more: #498 removed both packages. +PROCESS_DOMAIN: set[str] = set() def _outside(module: str, *prefixes: str) -> set[str]: @@ -154,14 +152,14 @@ def reject(document, key): {"文本": "未转义 ✓", "nested": {"path": "C:\\runs\\a", "quote": "\"", "line": "a\nb"}}, {"float": 1e-308, "large": 1e308, "negative": -0.0}, ]) -def test_harness_writer_bytes_equal_the_infra_writer(tmp_path, value): +def test_harness_writer_bytes_equal_the_apps_writer(tmp_path, value): atomic_json.atomic_write_json(tmp_path / "harness.json", value) artifacts.atomic_write_json(tmp_path / "infra.json", value) assert (tmp_path / "harness.json").read_bytes() == (tmp_path / "infra.json").read_bytes() assert sorted(path.name for path in tmp_path.iterdir()) == ["harness.json", "infra.json"] -def test_sampling_sha256_matches_the_infra_hasher(tmp_path): +def test_sampling_sha256_matches_the_apps_hasher(tmp_path): path = tmp_path / "artifact.bin" path.write_bytes(b"inferrsi-b01-sampling-pin") assert sampling._sha256(path) == artifacts.sha256(path) diff --git a/tests/test_module_boundaries.py b/tests/test_module_boundaries.py index 6cdd298dc..b22b67eb1 100644 --- a/tests/test_module_boundaries.py +++ b/tests/test_module_boundaries.py @@ -101,7 +101,7 @@ def test_cuda_qualification_accepts_campaign_supplied_count_and_sku(monkeypatch) def test_shared_layers_do_not_import_campaigns_or_reverse_dependencies(): root = Path(__file__).resolve().parents[1] / "src/inferrsi" - for plane in ("infra", "model", "harness"): + for plane in ("apps/host", "apps/integrations", "harness"): for path in (root / plane).rglob("*.py"): package = ".".join(("inferrsi", *path.relative_to(root).parts[:-1])) for node in ast.walk(ast.parse(path.read_text(encoding="utf-8"))): @@ -119,12 +119,11 @@ def test_shared_layers_do_not_import_campaigns_or_reverse_dependencies(): for name in names: assert "examples" not in name.split("."), (path, name) assert "ltx25" not in name and "qwen21" not in name, (path, name) - if plane == "infra": - assert not name.startswith(("inferrsi.harness", "inferrsi.model")), ( - path, - name, - ) - if plane == "model": + if plane == "apps/host": + assert not name.startswith( + ("inferrsi.harness", "inferrsi.knowledge", "inferrsi.benchmark")), ( + path, name) + if plane == "apps/integrations": assert not name.startswith("inferrsi.harness"), (path, name) diff --git a/tests/test_package_root_inventory.py b/tests/test_package_root_inventory.py index a2bc065df..cd336bdfe 100644 --- a/tests/test_package_root_inventory.py +++ b/tests/test_package_root_inventory.py @@ -276,3 +276,87 @@ def unexpected(name: str) -> str: assert inventory_errors(root_files(tmp_path)) == [ f"missing root file {PACKAGE}/__main__.py: shrink ROOT_FILES in the PR that removes it" ] + + +# #498 slice 5: the package holds exactly these six directories. Infra and Model are gone, +# and a new sibling package or a returning old one fails here, with or without a file in it. +PACKAGE_DIRECTORIES = frozenset( + {"apps", "benchmark", "contracts", "harness", "knowledge", "resources"} +) +RETIRED_DIRECTORIES = frozenset({"infra", "model"}) + + +def directory_errors(found: set[str], expected: frozenset[str] = PACKAGE_DIRECTORIES) -> list[str]: + errors = [ + f"unexpected package directory {PACKAGE}/{name}: a new package needs its own review" + for name in sorted(found - expected) + ] + errors += [f"missing package directory {PACKAGE}/{name}" for name in sorted(expected - found)] + errors += [ + f"retired package directory {PACKAGE}/{name} returned: it was removed by #498" + for name in sorted(found & RETIRED_DIRECTORIES) + ] + return errors + + +def package_directories(repo: Path) -> set[str]: + """Top-level package directories that hold a tracked or non-ignored Python file.""" + output = subprocess.run( + ["git", "-C", str(repo), "ls-files", "-z", "--cached", "--others", + "--exclude-standard", "--", f":(glob){PACKAGE}/*/**"], + check=True, capture_output=True, + ).stdout + names = {name.split("/")[2] for name in output.decode("utf-8").split("\0") if name} + return names + + +def test_the_package_holds_exactly_the_six_directories() -> None: + assert len(PACKAGE_DIRECTORIES) == 6 + assert not PACKAGE_DIRECTORIES & RETIRED_DIRECTORIES + on_disk = { + path.name for path in (REPO / PACKAGE).iterdir() + if path.is_dir() and any(path.rglob("*.py")) + } + assert directory_errors(on_disk) == [] + + +def test_tracked_directories_match_the_inventory() -> None: + if not (REPO / ".git").exists(): + pytest.skip("Git metadata is required for the tracked-file inventory") + assert directory_errors(package_directories(REPO)) == [] + + +@pytest.mark.parametrize("name", sorted(RETIRED_DIRECTORIES)) +def test_a_retired_directory_is_rejected_even_when_it_is_empty_of_modules(name: str) -> None: + found = set(PACKAGE_DIRECTORIES) | {name} + assert any(f"{name} returned" in error for error in directory_errors(found)) + + +@pytest.mark.parametrize("name", ["tools", "plugins", "model_zoo", "infra_extra"]) +def test_a_new_sibling_package_is_rejected(name: str) -> None: + errors = directory_errors(set(PACKAGE_DIRECTORIES) | {name}) + assert errors == [ + f"unexpected package directory {PACKAGE}/{name}: a new package needs its own review" + ] + + +def test_a_missing_directory_is_reported() -> None: + errors = directory_errors(set(PACKAGE_DIRECTORIES) - {"resources"}) + assert errors == [f"missing package directory {PACKAGE}/resources"] + + +def test_the_directory_view_reports_a_new_package_before_it_is_staged(tmp_path: Path) -> None: + repo = tmp_path / "repo" + (repo / PACKAGE / "apps").mkdir(parents=True) + (repo / PACKAGE / "apps" / "a.py").write_text("", encoding="utf-8") + subprocess.run(["git", "init", "-q", str(repo)], check=True) + assert package_directories(repo) == {"apps"} + (repo / PACKAGE / "model").mkdir() + (repo / PACKAGE / "model" / "__init__.py").write_text("", encoding="utf-8") + assert package_directories(repo) == {"apps", "model"} + # Generated bytecode never counts, ignored or not tracked. + (repo / ".gitignore").write_text("__pycache__/\n", encoding="utf-8") + cache = repo / PACKAGE / "cache_only" / "__pycache__" + cache.mkdir(parents=True) + (cache / "x.pyc").write_bytes(b"") + assert "cache_only" not in package_directories(repo) diff --git a/tests/test_project_service_reuse.py b/tests/test_project_service_reuse.py index d55b0791d..954f7087c 100644 --- a/tests/test_project_service_reuse.py +++ b/tests/test_project_service_reuse.py @@ -9,11 +9,11 @@ import pytest +from inferrsi.apps import artifacts from inferrsi.apps.cli import main from inferrsi.apps.cli.arguments import parser from inferrsi.harness import artifact_primitives, optimization, project_service from inferrsi.harness.records import evidence, knowledge_capture -from inferrsi.infra import artifacts from inferrsi.knowledge import knowledge_operations diff --git a/tests/test_repository_packs_facade.py b/tests/test_repository_packs_facade.py index 70ff5c054..c9d378cd2 100644 --- a/tests/test_repository_packs_facade.py +++ b/tests/test_repository_packs_facade.py @@ -37,7 +37,7 @@ 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.infra", "inferrsi.apps", +CORES = ("inferrsi.harness", "inferrsi.knowledge", "inferrsi.apps", "inferrsi.benchmark", "inferrsi.contracts") # Every other inferrsi import is refused, so the facade works only if it needs none. BLOCKED = """ diff --git a/tests/test_request_guard.py b/tests/test_request_guard.py index 6f1df430b..420d192a8 100644 --- a/tests/test_request_guard.py +++ b/tests/test_request_guard.py @@ -7,8 +7,8 @@ import pytest -from inferrsi.model import anthropic_agent as agent -from inferrsi.model import request_guard as guard +from inferrsi.apps.integrations.anthropic import anthropic_agent as agent +from inferrsi.apps.integrations.anthropic import request_guard as guard def request(env, *, token=None, context=None, identity="a" * 64): diff --git a/tests/test_request_guard_deadline.py b/tests/test_request_guard_deadline.py index b5c27fd29..87dd40891 100644 --- a/tests/test_request_guard_deadline.py +++ b/tests/test_request_guard_deadline.py @@ -6,8 +6,8 @@ import unittest from unittest.mock import patch -from inferrsi.model import anthropic_agent as agent -from inferrsi.model import request_guard as guard +from inferrsi.apps.integrations.anthropic import anthropic_agent as agent +from inferrsi.apps.integrations.anthropic import request_guard as guard class AuthorizationDeadlineTests(unittest.TestCase): diff --git a/tests/test_result_delivery.py b/tests/test_result_delivery.py index 6f56a4d91..4b7f78f8c 100644 --- a/tests/test_result_delivery.py +++ b/tests/test_result_delivery.py @@ -5,6 +5,7 @@ import pytest from inferrsi.apps import delivery +from inferrsi.apps.artifacts import atomic_write_json, sha256 from inferrsi.apps.cli import main from inferrsi.apps.delivery.projection import metric from inferrsi.apps.delivery.schema import decode, validate_result @@ -12,7 +13,6 @@ from inferrsi.apps.storage import archive from inferrsi.apps.storage.result import preparation_result from inferrsi.harness import optimization -from inferrsi.infra.artifacts import atomic_write_json, sha256 def make_campaign(tmp_path, *, scores=(5,), final=True, final_verdict="PASS", usage=False): diff --git a/tests/test_session_lock_across_processes.py b/tests/test_session_lock_across_processes.py new file mode 100644 index 000000000..7bea9a57a --- /dev/null +++ b/tests/test_session_lock_across_processes.py @@ -0,0 +1,148 @@ +"""The Harness and Apps session locks exclude each other across real processes. + +Harness writers hold ``/.session.lock`` through ``harness.artifact_primitives``. +An Apps export holds it through ``apps.artifacts``. Each side has its own copy of the lock +code, so per-copy parity tests can pass while the pair fails to exclude. These tests start a +separate process for each holder, so they cover the actual writer and reader on Windows +(msvcrt byte range) and POSIX (flock) alike. #498 slice 3b; the busy-writer mapping of #494 +stays a separate assertion in tests/test_result_delivery.py. +""" + +import json +import subprocess +import sys +import time +from pathlib import Path + +import pytest + +from inferrsi.apps import artifacts as apps_artifacts +from inferrsi.apps import delivery +from inferrsi.harness import artifact_primitives as harness_artifacts + +SRC = str(Path(__file__).resolve().parents[1] / "src") + +# A child process takes the named lock, reports it, then waits for a release file. +HOLDER = """ +import sys +import time +from pathlib import Path + +sys.path.insert(0, sys.argv[1]) +side, lock, ready, release = sys.argv[2], Path(sys.argv[3]), Path(sys.argv[4]), Path(sys.argv[5]) +if side == "harness": + from inferrsi.harness.artifact_primitives import file_lock +else: + from inferrsi.apps.artifacts import file_lock +with file_lock(lock): + ready.write_text("held", encoding="utf-8") + deadline = time.monotonic() + 60 + while not release.exists() and time.monotonic() < deadline: + time.sleep(0.02) +""" + +# A child process tries the named lock once without blocking and reports the outcome. +PROBE = """ +import json +import sys +from pathlib import Path + +sys.path.insert(0, sys.argv[1]) +side, lock = sys.argv[2], Path(sys.argv[3]) +if side == "harness": + from inferrsi.harness.artifact_primitives import file_lock +else: + from inferrsi.apps.artifacts import file_lock +try: + with file_lock(lock): + outcome = {"acquired": True} +except OSError as error: + outcome = {"acquired": False, "error": type(error).__name__} +print(json.dumps(outcome)) +""" + + +def _wait_for(path: Path, process: subprocess.Popen) -> None: + deadline = time.monotonic() + 30 + while not path.exists(): + assert process.poll() is None, process.communicate() + assert time.monotonic() < deadline, "the holder never took the lock" + time.sleep(0.02) + + +def _probe(side: str, lock: Path) -> dict: + result = subprocess.run( + [sys.executable, "-I", "-c", PROBE, SRC, side, str(lock)], + capture_output=True, text=True, check=True, timeout=60, + ) + return json.loads(result.stdout) + + +@pytest.fixture +def hold(tmp_path): + """Start a process that holds the lock of the given side until released.""" + started = [] + + def start(side: str, lock: Path): + ready, release = tmp_path / f"{side}.ready", tmp_path / f"{side}.release" + process = subprocess.Popen( + [sys.executable, "-I", "-c", HOLDER, SRC, side, str(lock), str(ready), str(release)], + stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, + ) + started.append((process, release)) + _wait_for(ready, process) + return release + + yield start + for process, release in started: + release.write_text("done", encoding="utf-8") + process.communicate(timeout=60) + + +@pytest.mark.parametrize("holder, contender", [("harness", "apps"), ("apps", "harness")]) +def test_a_held_lock_excludes_the_other_copy_in_another_process(tmp_path, hold, holder, contender): + lock = tmp_path / ".session.lock" + release = hold(holder, lock) + blocked = _probe(contender, lock) + assert blocked["acquired"] is False, blocked + release.write_text("done", encoding="utf-8") + deadline = time.monotonic() + 30 + while True: + outcome = _probe(contender, lock) + if outcome["acquired"]: + break + assert time.monotonic() < deadline, "the lock was never released" + time.sleep(0.05) + assert outcome == {"acquired": True} + + +def _campaign(root: Path) -> Path: + root.mkdir() + (root / "state.json").write_text(json.dumps({"started_at": 1.0}), encoding="utf-8") + return root + + +def test_an_apps_reader_is_refused_while_a_harness_process_holds_the_session(tmp_path, hold): + # The actual writer and reader pair: a Harness process holds the session lock, and the + # Apps copy of the lock, which `delivery.project` takes, cannot be taken by another + # process until it is released. The retryable `SnapshotBusy` mapping of that refusal is + # #494 and stays a separate assertion in tests/test_result_delivery.py; this test needs + # only the contention itself, which is a PermissionError on Windows (msvcrt) and a + # BlockingIOError on POSIX (flock). + root = _campaign(tmp_path / "campaign") + lock = root / ".session.lock" + release = hold("harness", lock) + assert _probe("apps", lock)["acquired"] is False + release.write_text("done", encoding="utf-8") + deadline = time.monotonic() + 30 + while not _probe("apps", lock)["acquired"]: + assert time.monotonic() < deadline, "the Harness holder never released" + time.sleep(0.05) + # Released: the whole export now succeeds against a managed session or fails for a + # reason other than the lock, never as a busy writer. + with pytest.raises(ValueError) as outcome: + delivery.project(root, export_id="released") + assert "writer is active" not in str(outcome.value) + with apps_artifacts.file_lock(lock), pytest.raises(OSError): + with harness_artifacts.file_lock(lock): + pass diff --git a/tests/test_sias_layout.py b/tests/test_sias_layout.py index 752c6b971..141f6ac2f 100644 --- a/tests/test_sias_layout.py +++ b/tests/test_sias_layout.py @@ -3,8 +3,8 @@ def test_sias_subpackages_import() -> None: importlib.import_module("inferrsi.harness") - importlib.import_module("inferrsi.model") - importlib.import_module("inferrsi.infra") + importlib.import_module("inferrsi.apps.host") + importlib.import_module("inferrsi.apps.integrations.anthropic") def test_harness_exports_verdict() -> None: diff --git a/tests/test_skill_eval_auto.py b/tests/test_skill_eval_auto.py index 810649649..dee10d19b 100644 --- a/tests/test_skill_eval_auto.py +++ b/tests/test_skill_eval_auto.py @@ -6,7 +6,7 @@ import pytest import yaml -from inferrsi.model import anthropic_agent as agent +from inferrsi.apps.integrations.anthropic import anthropic_agent as agent from tools import skill_eval_auto as auto from tools import skill_eval_pr as pr from tools.skill_eval_budget import BudgetError @@ -228,7 +228,7 @@ def broker(check, max_requests, *, context): checks.append(check) yield {"SKILL_EVAL_GUARD_TEST": "offline-only"} - monkeypatch.setitem(sys.modules, "inferrsi.model.request_guard", + monkeypatch.setitem(sys.modules, "inferrsi.apps.integrations.anthropic.request_guard", types.SimpleNamespace(authorization_broker=broker)) def launch(command, *, env, cwd, check): diff --git a/tests/test_skill_eval_auto_daily.py b/tests/test_skill_eval_auto_daily.py index c2eda0042..18fd2c0b8 100644 --- a/tests/test_skill_eval_auto_daily.py +++ b/tests/test_skill_eval_auto_daily.py @@ -77,7 +77,7 @@ def execute(self, run=42): stack.enter_context(patch.object(auto.pr, "execution_id", return_value="offline")) stack.enter_context(patch.dict(auto.os.environ, {"SKILL_EVAL_YIBUAPI_KEY": "offline-fixture"})) - stack.enter_context(patch("inferrsi.model.request_guard.authorization_broker", + stack.enter_context(patch("inferrsi.apps.integrations.anthropic.request_guard.authorization_broker", self.broker)) auto.controlled_execute(Mock(), self.output, run_id=run, attempt=1, launch=self.launch) diff --git a/tests/test_skill_eval_compare.py b/tests/test_skill_eval_compare.py index 7f98a7d9f..d6f73df64 100644 --- a/tests/test_skill_eval_compare.py +++ b/tests/test_skill_eval_compare.py @@ -9,7 +9,7 @@ import pytest -from inferrsi.infra.artifacts import sha256, write_json +from inferrsi.apps.artifacts import sha256, write_json from inferrsi.knowledge.knowledge_operations import KnowledgeReader, RevisionConflict from tests.fixtures.skill_eval_compare_support import ( DATA, @@ -1010,7 +1010,8 @@ def test_changed_runtime_controllers_reject_execution_and_report_without_calls(t module.report(output) saved = (output / "report.json").read_bytes(), (output / "report.md").read_bytes() assert "src/inferrsi/harness/local_process.py" in module.CONTROLLERS - assert "src/inferrsi/infra/artifacts.py" in module.CONTROLLERS + assert "src/inferrsi/apps/artifacts.py" in module.CONTROLLERS + assert "src/inferrsi/apps/integrations/anthropic/request_guard.py" in module.CONTROLLERS assert "tools/skill_eval_artifact_guidance.py" in module.CONTROLLERS # Each owner of the split trial path is frozen: composed entry, rules and host. for owner in ("apps/workflows", "benchmark", "harness"): diff --git a/tests/test_skill_eval_deployment.py b/tests/test_skill_eval_deployment.py index 728837105..fd621b745 100644 --- a/tests/test_skill_eval_deployment.py +++ b/tests/test_skill_eval_deployment.py @@ -7,7 +7,7 @@ import pytest -from inferrsi.model import anthropic_agent as agent +from inferrsi.apps.integrations.anthropic import anthropic_agent as agent from tools import skill_eval_auto as auto from tools import skill_eval_pr as pr from tools.skill_eval_budget import Binding, BudgetError, Genesis, Ledger, reserve diff --git a/tests/test_skill_eval_diagnostic.py b/tests/test_skill_eval_diagnostic.py index b652f2a38..44734ebfc 100644 --- a/tests/test_skill_eval_diagnostic.py +++ b/tests/test_skill_eval_diagnostic.py @@ -7,8 +7,8 @@ import unittest from pathlib import Path +from inferrsi.apps.artifacts import sha256, write_json from inferrsi.benchmark import skill_eval_diagnostic as diagnostic -from inferrsi.infra.artifacts import sha256, write_json from tests.fixtures.skill_eval_compare_support import FixedOutputClient, configuration, git from tools import skill_eval_compare as compare diff --git a/tests/test_skill_eval_feedback.py b/tests/test_skill_eval_feedback.py index 0e041e167..fa5a07d07 100644 --- a/tests/test_skill_eval_feedback.py +++ b/tests/test_skill_eval_feedback.py @@ -6,8 +6,8 @@ from pathlib import Path from unittest.mock import Mock, patch +from inferrsi.apps.artifacts import sha256, write_json from inferrsi.benchmark import skill_eval_diagnostic as diagnostic -from inferrsi.infra.artifacts import sha256, write_json from tests.fixtures.skill_eval_compare_support import FixedOutputClient from tests.fixtures.skill_eval_pr_support import approval, setup from tools import skill_eval_feedback as feedback diff --git a/tests/test_skill_eval_generation.py b/tests/test_skill_eval_generation.py index 872e840c0..3e5200631 100644 --- a/tests/test_skill_eval_generation.py +++ b/tests/test_skill_eval_generation.py @@ -6,13 +6,13 @@ import pytest +from inferrsi.apps.artifacts import sha256, write_json +from inferrsi.apps.integrations.anthropic import anthropic_agent as agent from inferrsi.apps.workflows import skill_eval_engineering as artifact_check from inferrsi.apps.workflows import skill_evaluation as evaluation from inferrsi.benchmark import skill_eval_engineering as engineering from inferrsi.harness import artifact_sandbox as sandbox from inferrsi.harness import skill_evaluation as harness -from inferrsi.infra.artifacts import sha256, write_json -from inferrsi.model import anthropic_agent as agent from tests.fixtures.skill_eval_compare_support import configuration from tools import skill_eval_compare as compare diff --git a/tests/test_skill_eval_historical_job.py b/tests/test_skill_eval_historical_job.py index adc030ffd..1a06c5a15 100644 --- a/tests/test_skill_eval_historical_job.py +++ b/tests/test_skill_eval_historical_job.py @@ -8,7 +8,7 @@ import pytest import yaml -from inferrsi.infra.artifacts import sha256, write_json +from inferrsi.apps.artifacts import sha256, write_json from tools import skill_eval_historical_job as job diff --git a/tests/test_skill_eval_local.py b/tests/test_skill_eval_local.py index 2afbf54b6..7f64fd873 100644 --- a/tests/test_skill_eval_local.py +++ b/tests/test_skill_eval_local.py @@ -3,10 +3,10 @@ import pytest +from inferrsi.apps.artifacts import sha256, write_json from inferrsi.apps.workflows import skill_eval_engineering as artifact_check from inferrsi.benchmark import skill_eval_engineering as engineering from inferrsi.harness import artifact_sandbox as sandbox -from inferrsi.infra.artifacts import sha256, write_json from tests.fixtures.skill_eval_compare_support import configuration from tools import skill_eval_compare as compare from tools import skill_eval_local as local diff --git a/tests/test_skill_eval_local_cli.py b/tests/test_skill_eval_local_cli.py index 0eb98df3d..a0366c8c5 100644 --- a/tests/test_skill_eval_local_cli.py +++ b/tests/test_skill_eval_local_cli.py @@ -11,10 +11,10 @@ import pytest +from inferrsi.apps.artifacts import sha256, write_json from inferrsi.apps.workflows import skill_eval_engineering as artifact_check from inferrsi.benchmark import skill_eval_engineering as engineering from inferrsi.harness import artifact_sandbox as sandbox -from inferrsi.infra.artifacts import sha256, write_json from tests.fixtures.skill_eval_compare_support import configuration from tools import skill_eval_compare as compare diff --git a/tests/test_skill_eval_pipeline.py b/tests/test_skill_eval_pipeline.py index 3ebb4a188..995c627c1 100644 --- a/tests/test_skill_eval_pipeline.py +++ b/tests/test_skill_eval_pipeline.py @@ -8,8 +8,8 @@ import pytest +from inferrsi.apps.artifacts import atomic_write_json, sha256 from inferrsi.apps.workflows.skill_evaluation import run_trial, summarize -from inferrsi.infra.artifacts import atomic_write_json, sha256 from tools import skill_eval_pilot ROOT = Path(__file__).resolve().parents[1] diff --git a/tests/test_skill_eval_planned_guidance.py b/tests/test_skill_eval_planned_guidance.py index a58712be3..301914150 100644 --- a/tests/test_skill_eval_planned_guidance.py +++ b/tests/test_skill_eval_planned_guidance.py @@ -8,7 +8,7 @@ import pytest -from inferrsi.infra.artifacts import write_json +from inferrsi.apps.artifacts import write_json from tests.fixtures.skill_eval_compare_support import git from tests.fixtures.skill_eval_pr_support import setup from tests.test_skill_eval_pr_summary import visible diff --git a/tests/test_skill_eval_planning_boundaries.py b/tests/test_skill_eval_planning_boundaries.py index a2f3ac4c1..50f8905a0 100644 --- a/tests/test_skill_eval_planning_boundaries.py +++ b/tests/test_skill_eval_planning_boundaries.py @@ -7,7 +7,7 @@ import pytest -from inferrsi.infra.artifacts import write_json +from inferrsi.apps.artifacts import write_json from tests.fixtures.skill_eval_compare_support import git from tests.fixtures.skill_eval_pr_support import SimulatedGitHub, setup from tests.test_skill_eval_pr import dispatch_event diff --git a/tests/test_skill_eval_pr.py b/tests/test_skill_eval_pr.py index d6cd20509..c9afcf76e 100644 --- a/tests/test_skill_eval_pr.py +++ b/tests/test_skill_eval_pr.py @@ -11,7 +11,7 @@ import pytest import yaml -from inferrsi.infra.artifacts import sha256, write_json +from inferrsi.apps.artifacts import sha256, write_json from tests.fixtures.skill_eval_compare_support import ROOT, FixedOutputClient, git from tests.fixtures.skill_eval_pr_support import ( SimulatedGitHub, diff --git a/tests/test_skill_eval_pr_diagnostic.py b/tests/test_skill_eval_pr_diagnostic.py index 9afefd551..ed72ba2d9 100644 --- a/tests/test_skill_eval_pr_diagnostic.py +++ b/tests/test_skill_eval_pr_diagnostic.py @@ -3,8 +3,8 @@ import unittest from pathlib import Path +from inferrsi.apps.artifacts import write_json from inferrsi.benchmark import skill_eval_diagnostic as diagnostic -from inferrsi.infra.artifacts import write_json from tests.fixtures.skill_eval_compare_support import FixedOutputClient from tests.fixtures.skill_eval_pr_support import setup from tests.test_skill_eval_diagnostic import CASES, answer diff --git a/tests/test_skill_eval_retention.py b/tests/test_skill_eval_retention.py index f07c550fc..2dd4840ab 100644 --- a/tests/test_skill_eval_retention.py +++ b/tests/test_skill_eval_retention.py @@ -5,7 +5,7 @@ import pytest -from inferrsi.infra.artifacts import write_json +from inferrsi.apps.artifacts import write_json from tests import test_skill_eval_auto as auto_tests from tests.fixtures.skill_eval_compare_support import FixedOutputClient from tests.fixtures.skill_eval_pr_support import SimulatedGitHub, approval, setup diff --git a/tests/test_skill_eval_review_guidance.py b/tests/test_skill_eval_review_guidance.py index a1f9e9e1d..c1e16b530 100644 --- a/tests/test_skill_eval_review_guidance.py +++ b/tests/test_skill_eval_review_guidance.py @@ -5,7 +5,7 @@ import pytest -from inferrsi.infra.artifacts import sha256, write_json +from inferrsi.apps.artifacts import sha256, write_json from tests.fixtures.skill_eval_compare_support import FixedOutputClient from tests.fixtures.skill_eval_pr_support import SimulatedGitHub, approval, setup from tools import skill_eval_pr as integration diff --git a/tests/test_skill_evaluation.py b/tests/test_skill_evaluation.py index 5944038a2..501a8d287 100644 --- a/tests/test_skill_evaluation.py +++ b/tests/test_skill_evaluation.py @@ -298,9 +298,9 @@ def verdict(execution, trace, output, checks): assert not hasattr(host, name) -def test_harness_owned_writes_and_digests_match_infra_bytes(tmp_path): +def test_harness_owned_writes_and_digests_match_apps_bytes(tmp_path): + from inferrsi.apps import artifacts from inferrsi.harness import atomic_json, input_binding - from inferrsi.infra import artifacts value = {"b": [1.5, None, True, 1e-07, 1e16], "a": "非 ASCII", "nested": {"z": 0.1 + 0.2}} atomic_json.atomic_write_json(tmp_path / "harness.json", value) @@ -315,14 +315,14 @@ def test_harness_owned_writes_and_digests_match_infra_bytes(tmp_path): assert not (tmp_path / "nan.json").exists() -def test_harness_artifact_primitives_match_infra_bytes_and_semantics(tmp_path): +def test_harness_artifact_primitives_match_apps_bytes_and_semantics(tmp_path): # #412 R2: the six Harness modules now use these copies. Same source, same bytes, # same failures, and the two file locks exclude each other on one path. import ast import inspect + from inferrsi.apps import artifacts as infra from inferrsi.harness import artifact_primitives as harness - from inferrsi.infra import artifacts as infra for name in ("digest", "sha256", "file_lock"): assert inspect.getsource(getattr(harness, name)) == inspect.getsource( diff --git a/tests/test_target_module_import_gate.py b/tests/test_target_module_import_gate.py index 9d0864a16..e9ece509d 100644 --- a/tests/test_target_module_import_gate.py +++ b/tests/test_target_module_import_gate.py @@ -233,11 +233,20 @@ def test_retired_model_files_fail_when_they_return(tmp_path, relative): report.violations) -def test_the_model_paths_that_remain_are_not_retired(tmp_path): +def test_the_modules_that_replaced_the_retired_packages_are_not_retired(tmp_path): + # #498 retired the whole Infra and Model packages. Every module that took over from + # them must stay importable by name under the new owner. report = _report(tmp_path, { - "benchmark/runner.py": "from inferrsi.model import request_guard\n", - "apps/runner.py": "from inferrsi.infra.artifacts import sha256\n", + "apps/artifacts.py": "VALUE = 1\n", + "apps/integrations/__init__.py": "", + "apps/integrations/anthropic/__init__.py": "", + "apps/integrations/anthropic/request_guard.py": "VALUE = 1\n", + "apps/runner.py": ( + "from inferrsi.apps.artifacts import sha256\n" + "from inferrsi.apps.integrations.anthropic import request_guard\n" + ), "harness/runner.py": "from inferrsi.harness.serving.image import ImageProtocol\n", + "benchmark/runner.py": "from inferrsi.benchmark.metrics import read_metric\n", }) assert not [item for item in report.violations if "retired module" in item] diff --git a/tests/test_template_layout.py b/tests/test_template_layout.py index dfa93c531..c51cb6107 100644 --- a/tests/test_template_layout.py +++ b/tests/test_template_layout.py @@ -13,8 +13,9 @@ def test_evidence_template_segments() -> None: def test_sias_readmes() -> None: pkg = REPO_ROOT / "src" / "inferrsi" - for plane in ("harness", "model", "infra"): - assert (pkg / plane / "README.md").is_file() + # #498 removed the model and infra planes; harness keeps its README. + assert (pkg / "harness" / "README.md").is_file() + assert not (pkg / "model").exists() and not (pkg / "infra").exists() def test_maintained_documentation_links_resolve() -> None: diff --git a/tests/test_yibuapi_runtime.py b/tests/test_yibuapi_runtime.py index 5620457e5..c23f10234 100644 --- a/tests/test_yibuapi_runtime.py +++ b/tests/test_yibuapi_runtime.py @@ -7,9 +7,9 @@ import pytest import yaml +from inferrsi.apps.artifacts import write_json +from inferrsi.apps.integrations.anthropic import anthropic_agent as agent from inferrsi.harness import skill_evaluation as harness -from inferrsi.infra.artifacts import write_json -from inferrsi.model import anthropic_agent as agent from tests.fixtures.skill_eval_compare_support import DATA from tests.fixtures.skill_eval_pr_support import SimulatedGitHub, approval, setup from tests.test_anthropic_agent import ANSWER, MODEL, SCHEMA_SMALL, read, submit diff --git a/tools/goal_checkpoint.py b/tools/goal_checkpoint.py index c4a6cef6a..ca673dbbe 100644 --- a/tools/goal_checkpoint.py +++ b/tools/goal_checkpoint.py @@ -8,7 +8,7 @@ from pathlib import Path from typing import Literal -from inferrsi.infra.artifacts import digest, sha256 +from inferrsi.apps.artifacts import digest, sha256 from tools.skill_eval_compare import CONTROLLERS, ROLES, ROOT, read_report Action = Literal[ diff --git a/tools/skill_eval_auto.py b/tools/skill_eval_auto.py index 9abcfa7f1..3b6508046 100644 --- a/tools/skill_eval_auto.py +++ b/tools/skill_eval_auto.py @@ -11,7 +11,7 @@ from pathlib import Path from urllib.parse import quote -from inferrsi.infra.artifacts import write_json +from inferrsi.apps.artifacts import write_json from tools import skill_eval_pr as pr from tools.skill_eval_budget import ( Binding, @@ -208,7 +208,7 @@ def status(api, plan, config): def controlled_execute(api, output, *, config_path=CONFIG, run_id, attempt, launch=None): - from inferrsi.model.request_guard import authorization_broker + from inferrsi.apps.integrations.anthropic.request_guard import authorization_broker plan = pr.compare.read_json(output / "pr-plan.json") config = configuration(config_path) diff --git a/tools/skill_eval_cloud_export.py b/tools/skill_eval_cloud_export.py index 23df49f0a..176551d85 100644 --- a/tools/skill_eval_cloud_export.py +++ b/tools/skill_eval_cloud_export.py @@ -4,9 +4,9 @@ import json from pathlib import Path +from inferrsi.apps.artifacts import sha256 from inferrsi.benchmark import skill_eval_engineering as engineering from inferrsi.harness import artifact_sandbox -from inferrsi.infra.artifacts import sha256 from tools import skill_eval_compare as compare diff --git a/tools/skill_eval_compare.py b/tools/skill_eval_compare.py index 43b312f68..d622ce0a4 100644 --- a/tools/skill_eval_compare.py +++ b/tools/skill_eval_compare.py @@ -12,6 +12,15 @@ from dataclasses import replace from pathlib import Path +from inferrsi.apps.artifacts import atomic_write_json, sha256, write_json +from inferrsi.apps.integrations.anthropic.anthropic_agent import ( + FULL_CONTEXT_KIND, + AnthropicAgentClient, + validate_schema, + validate_spec, +) +from inferrsi.apps.integrations.anthropic.anthropic_agent import SOURCE as AGENT_SOURCE +from inferrsi.apps.integrations.anthropic.request_guard import SOURCE as GUARD_SOURCE from inferrsi.apps.workflows import skill_eval_engineering as artifact_check from inferrsi.apps.workflows.skill_evaluation import export_bundle, run_trial, summarize from inferrsi.benchmark import skill_eval_diagnostic as diagnostic @@ -19,16 +28,7 @@ from inferrsi.harness import artifact_sandbox from inferrsi.harness.skill_evaluation import CodexClient from inferrsi.harness.usage import normalize_usage -from inferrsi.infra.artifacts import atomic_write_json, sha256, write_json from inferrsi.knowledge.knowledge_operations import KnowledgeReader, safe_path -from inferrsi.model.anthropic_agent import ( - FULL_CONTEXT_KIND, - AnthropicAgentClient, - validate_schema, - validate_spec, -) -from inferrsi.model.anthropic_agent import SOURCE as AGENT_SOURCE -from inferrsi.model.request_guard import SOURCE as GUARD_SOURCE from tools import skill_eval_artifact_guidance as artifact_guidance from tools.skill_eval_pilot import PROMPT, SCHEMA, observed_tokens from tools.skill_eval_snapshot import selected_snapshot @@ -47,7 +47,7 @@ "src/inferrsi/harness/skill_evaluation.py", "src/inferrsi/harness/artifact_sandbox.py", "tools/skill_eval_snapshot.py", "src/inferrsi/harness/local_process.py", "src/inferrsi/harness/atomic_json.py", - "src/inferrsi/harness/input_binding.py", "src/inferrsi/infra/artifacts.py") + "src/inferrsi/harness/input_binding.py", "src/inferrsi/apps/artifacts.py") EVIDENCE = ("execution.json", "agent/stdout.log", "agent/stderr.log", "verification/result.json", "verification/stdout.log", "verification/stderr.log") NUMBER = (int, float) diff --git a/tools/skill_eval_historical_accounting.py b/tools/skill_eval_historical_accounting.py index c952f31dc..4d1109582 100644 --- a/tools/skill_eval_historical_accounting.py +++ b/tools/skill_eval_historical_accounting.py @@ -15,7 +15,7 @@ from decimal import Decimal from pathlib import Path -from inferrsi.model.request_guard import authorization_broker +from inferrsi.apps.integrations.anthropic.request_guard import authorization_broker from tools import skill_eval_auto as auto from tools import skill_eval_compare as compare from tools import skill_eval_pr as pr diff --git a/tools/skill_eval_historical_job.py b/tools/skill_eval_historical_job.py index 9172a05b4..6ca33d0a8 100644 --- a/tools/skill_eval_historical_job.py +++ b/tools/skill_eval_historical_job.py @@ -11,9 +11,9 @@ import urllib.request from pathlib import Path +from inferrsi.apps.artifacts import sha256, write_json from inferrsi.benchmark import skill_eval_engineering as engineering from inferrsi.harness import artifact_sandbox -from inferrsi.infra.artifacts import sha256, write_json from tools import skill_eval_auto as auto from tools import skill_eval_compare as compare from tools import skill_eval_historical_accounting as accounting diff --git a/tools/skill_eval_improve.py b/tools/skill_eval_improve.py index b1a6098e3..eddc999bf 100644 --- a/tools/skill_eval_improve.py +++ b/tools/skill_eval_improve.py @@ -12,6 +12,7 @@ import time from pathlib import Path +from inferrsi.apps.artifacts import sha256, write_json from inferrsi.apps.workflows.improvement import ( assessment, choose, @@ -21,7 +22,6 @@ from inferrsi.benchmark.improvement import SelectionPolicy from inferrsi.harness.skill_evaluation import CodexClient from inferrsi.harness.usage import usage_totals -from inferrsi.infra.artifacts import sha256, write_json from inferrsi.knowledge.knowledge_operations import KnowledgeReader, safe_path from tools import skill_eval_compare as compare diff --git a/tools/skill_eval_local.py b/tools/skill_eval_local.py index 46967643d..8a5a74a4a 100644 --- a/tools/skill_eval_local.py +++ b/tools/skill_eval_local.py @@ -12,11 +12,11 @@ import stat from pathlib import Path +from inferrsi.apps.artifacts import sha256, write_json from inferrsi.apps.workflows import skill_eval_engineering as artifact_check from inferrsi.benchmark import skill_eval_engineering as engineering from inferrsi.harness import artifact_sandbox from inferrsi.harness.usage import normalize_usage -from inferrsi.infra.artifacts import sha256, write_json def _selection(output, authorization, task_id, condition, repeat, current_head): diff --git a/tools/skill_eval_pilot.py b/tools/skill_eval_pilot.py index 579b121c1..844b96cd4 100644 --- a/tools/skill_eval_pilot.py +++ b/tools/skill_eval_pilot.py @@ -7,10 +7,10 @@ import time from pathlib import Path +from inferrsi.apps.artifacts import sha256, write_json from inferrsi.apps.workflows.skill_evaluation import export_bundle, run_trial, summarize from inferrsi.harness.skill_evaluation import CodexClient from inferrsi.harness.usage import normalize_usage -from inferrsi.infra.artifacts import sha256, write_json from inferrsi.knowledge.knowledge_operations import KnowledgeReader ROOT = Path(__file__).resolve().parents[1] diff --git a/tools/skill_eval_pr.py b/tools/skill_eval_pr.py index a28463817..b1c862bcc 100644 --- a/tools/skill_eval_pr.py +++ b/tools/skill_eval_pr.py @@ -14,8 +14,8 @@ from pathlib import Path, PurePosixPath from urllib.error import HTTPError -from inferrsi.infra.artifacts import sha256, write_json -from inferrsi.model.anthropic_agent import money, reservation +from inferrsi.apps.artifacts import sha256, write_json +from inferrsi.apps.integrations.anthropic.anthropic_agent import money, reservation from tools import skill_eval_compare as compare from tools.check_knowledge_model_policy import GitHubHTTPError from tools.skill_eval_feedback import (