diff --git a/.gitattributes b/.gitattributes index 154103b64..70d020059 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,6 +4,8 @@ # Preserve recorded evidence and historical validator bytes across checkouts. /evidence/** -text /tests/fixtures/legacy/** -text +# A session started by an older runtime keeps its exact bytes; its plan pins file hashes. +/tests/fixtures/optimization-session/pre-infra-removal-session/** -text # Reusable guidance is editable text, not a frozen evidence bundle. /evidence/README.md text eol=lf /evidence/_template/** text eol=lf 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..b73e3be7a 100644 --- a/.github/workflows/ci-ready.yml +++ b/.github/workflows/ci-ready.yml @@ -33,7 +33,7 @@ jobs: "$RUNNER_TEMP/wheel-env/bin/python" -m pip install "${wheels[0]}[skills]" cp tests/check_installed.py "$RUNNER_TEMP/check_installed.py" cd "$RUNNER_TEMP" - env -u PYTHONPATH INFERRSI_CHECKOUT_RESOURCES="$GITHUB_WORKSPACE/src/inferrsi" "$RUNNER_TEMP/wheel-env/bin/python" -I check_installed.py + env -u PYTHONPATH INFERRSI_CHECKOUT_RESOURCES="$GITHUB_WORKSPACE/src/inferrsi" INFERRSI_SESSION_LOCK_PROBE="$GITHUB_WORKSPACE/tests/session_lock_probe.py" INFERRSI_PRE_INFRA_SESSION="$GITHUB_WORKSPACE/tests/fixtures/optimization-session/pre-infra-removal-session" "$RUNNER_TEMP/wheel-env/bin/python" -I check_installed.py full-check: strategy: @@ -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"] @@ -239,7 +242,16 @@ jobs: # Children never see PYTHONPATH, and the checker compares with this absolute path. environment = {key: value for key, value in os.environ.items() if key != "PYTHONPATH"} environment["INFERRSI_CHECKOUT_RESOURCES"] = str(workspace / "src" / "inferrsi") - + # #498: the installed-wheel check drives a real session lock from this probe, on + # Windows and macOS as well as Linux. + environment["INFERRSI_SESSION_LOCK_PROBE"] = str( + workspace / "tests" / "session_lock_probe.py" + ) + # #498 slice 5: a session that main planned before infra/artifacts.py left the + # runtime identity must be refused by the installed wheel without any change. + environment["INFERRSI_PRE_INFRA_SESSION"] = str( + workspace / "tests/fixtures/optimization-session/pre-infra-removal-session" + ) def run(*command, cwd=work): command = [str(part) for part in command] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2f4e79a80..451f73eb4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -106,7 +106,7 @@ jobs: "$RUNNER_TEMP/wheel-env/bin/python" -m pip install "${wheels[0]}[skills]" cp tests/check_installed.py tools/check_release.py "$RUNNER_TEMP/" cd "$RUNNER_TEMP" - env -u PYTHONPATH INFERRSI_CHECKOUT_RESOURCES="$GITHUB_WORKSPACE/src/inferrsi" "$RUNNER_TEMP/wheel-env/bin/python" -I check_installed.py + env -u PYTHONPATH INFERRSI_CHECKOUT_RESOURCES="$GITHUB_WORKSPACE/src/inferrsi" INFERRSI_SESSION_LOCK_PROBE="$GITHUB_WORKSPACE/tests/session_lock_probe.py" INFERRSI_PRE_INFRA_SESSION="$GITHUB_WORKSPACE/tests/fixtures/optimization-session/pre-infra-removal-session" "$RUNNER_TEMP/wheel-env/bin/python" -I check_installed.py env -u PYTHONPATH "$RUNNER_TEMP/wheel-env/bin/python" -I check_release.py \ installed --tag "$RELEASE_TAG" - name: Build and validate the installable host plugin ZIPs diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e539b6a9..98c25c554 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. - Plugins built from a source checkout without `--release-version` now report `0.0.0+source` as their own version instead of `0.1.0` (Codex, WorkSwarm) or `0.0.0` (DSH) (Refs #511). This covers the template version, `plugin_version` in diff --git a/docs/architecture.md b/docs/architecture.md index 1ed3273bc..f76b1c113 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 @@ -220,6 +220,11 @@ src/inferrsi/ __init__.py CannbotChannel implementation and channel result adaptation project.py Opt-in checkout/interpreter grant and read-only operations read_worker.py Standalone worker run by the approved Cannbot interpreter + 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 + artifacts.py Apps-owned hashing, file lock and evidence writes mindie/ project.py Opt-in per-checkout grant, the worker launch and the recorded read context.py Export supplied MindIE reads into a caller-reviewed campaign trace @@ -284,8 +289,6 @@ 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 knowledge/data/skill_library/ Registered skills, engineering records, configuration and compiled inputs harness/data/repo_packs/ Execution target descriptors examples/ Current Qwen runner, image validator and v4 adapter 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 c1e7b97ae..6c88dab4a 100644 --- a/docs/module-layout.md +++ b/docs/module-layout.md @@ -223,7 +223,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/pyproject.toml b/pyproject.toml index daa1e5d20..a4d5a16d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,8 +62,12 @@ addopts = "-q" [tool.ruff] line-length = 100 target-version = "py310" -# Immutable historical snapshots retain their original formatting. -extend-exclude = ["tests/fixtures/legacy"] +# Immutable historical snapshots retain their original formatting. The pre-removal session +# is a whole session written by an older runtime; its plan pins the hashes of these files. +extend-exclude = [ + "tests/fixtures/legacy", + "tests/fixtures/optimization-session/pre-infra-removal-session", +] [tool.ruff.lint] select = ["E", "F", "I"] 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/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 7549495f8..32287e221 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 49ea01e31..844b4d6de 100644 --- a/tests/check_installed.py +++ b/tests/check_installed.py @@ -4,6 +4,7 @@ import json import os import pickle +import shutil import subprocess import sys import tempfile @@ -859,18 +860,33 @@ def _inventory(root, prefix): check=False, cwd=launch_cwd, ) assert launch.returncode == 0, launch.stderr +def assert_not_importable(name): + """A retired module has no spec and does not import. + + ``find_spec`` on a submodule of a missing package raises ``ModuleNotFoundError`` about the + parent instead of returning ``None``. Both outcomes mean the module is absent, and the + raised error must name the missing top part of the path, never some other module. + """ + try: + spec = find_spec(name) + except ModuleNotFoundError as error: + assert error.name is not None and name.startswith(error.name), (name, error) + else: + assert spec is None, name + try: + import_module(name) + except ModuleNotFoundError as error: + assert error.name is not None and name.startswith(error.name), (name, error) + else: + raise AssertionError(f"retired module {name} must not import") + + # #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. # 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) - except ModuleNotFoundError: - pass - else: - raise AssertionError(f"retired module {retired} must not import") + assert_not_importable(retired) for canonical in ("inferrsi.benchmark.metrics", "inferrsi.benchmark.artifacts", "inferrsi.benchmark.validators.flare", "inferrsi.benchmark.validators.image"): assert find_spec(canonical) is not None, canonical @@ -883,27 +899,92 @@ def _inventory(root, prefix): text=True, check=False, cwd=cli_cwd, ) 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 + # Since #498 the whole inferrsi.model package is gone, so Python stops at its parent. + assert "No module named 'inferrsi.model'" 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") +# 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_not_importable(retired) +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 +# #498 slice 3b: a Harness process holds a real session's lock while the Apps export of that +# session runs from the installed wheel. The export must be refused, and the same export must +# publish after the holder releases. The probe source is the one the test suite runs against +# the checkout (tests/session_lock_probe.py); the wheel check receives it through the +# environment so this file still copies on its own. +# #498: every caller passes the checkout probe, so a missing variable fails here. +lock_probe = os.environ["INFERRSI_SESSION_LOCK_PROBE"] +with tempfile.TemporaryDirectory(prefix="inferrsi-session-lock-") as lock_cwd: + script = Path(lock_cwd) / "session_lock_probe.py" + script.write_text(Path(lock_probe).read_text(encoding="utf-8"), encoding="utf-8") + work = Path(lock_cwd) / "work" + work.mkdir() + locked = subprocess.run( + [sys.executable, "-I", "-B", str(script), str(work)], capture_output=True, + text=True, check=False, cwd=lock_cwd, + ) +assert locked.returncode == 0, locked.stderr +observed = json.loads(locked.stdout.strip().splitlines()[-1]) +assert observed["busy_status"] != "published" and observed["busy_published"] is False, observed +assert observed["released_status"] == "published", observed +assert observed["released_kind"] == "progress", observed +# #498 slice 5: a real session that main planned before infra/artifacts.py left the runtime +# identity. The installed wheel must refuse it before status or recover dispatches and leave +# every file of the session as it was. +with tempfile.TemporaryDirectory(prefix="inferrsi-pre-infra-") as pre_work: + pre_session = Path(pre_work) / "session" + shutil.copytree(os.environ["INFERRSI_PRE_INFRA_SESSION"], pre_session) + + def session_bytes(): + return {path.relative_to(pre_session).as_posix(): path.read_bytes() + for path in sorted(pre_session.rglob("*")) if path.is_file()} + + pre_before = session_bytes() + assert "infra/artifacts.py" in json.loads(pre_before["plan.json"])["runtime_identity"] + for action in ("status", "recover"): + refused = subprocess.run( + [sys.executable, "-I", "-m", "inferrsi", "benchmarks", "session", action, + "--session", str(pre_session)], + capture_output=True, text=True, check=False, cwd=pre_work, + ) + assert refused.returncode == 2, (action, refused.returncode, refused.stderr) + assert "Optimization runtime changed" in refused.stderr, (action, refused.stderr) + assert session_bytes() == pre_before +# 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/optimization-session/README.md b/tests/fixtures/optimization-session/README.md new file mode 100644 index 000000000..ea09a5121 --- /dev/null +++ b/tests/fixtures/optimization-session/README.md @@ -0,0 +1,43 @@ +# Optimization session fixtures + +`pre-infra-removal-session/` is a session that `main` `6bdc86ee` started and interrupted with its own +installed runtime, with no edits. Its coordinator stopped after the candidate's child finished, so +the session holds a completed execution receipt for a round that is not settled: + +- `state.json` has `rounds: []` and a `pending` round, and the round directory has a completed + `execution/execution.json` (`returncode` 0) and a `measurement/result.json`. +- `calls.log` shows that the candidate ran once. +- `plan.json` records the runtime identity of that commit, which includes `infra/artifacts.py`. + +The runtime of #498 slice 5 no longer hashes that file, so it refuses this session for `status` and +`recover` before any operation runs and leaves every file unchanged. `tests/test_optimization_session.py` +checks this against the checkout, and `tests/check_installed.py` checks it against the installed +wheel. Neither can run the old runtime: that needs the old commit installed in its own environment. + +## Paired-wheel check on this same session + +Checked by hand on the H200 host on 2026-11-20 (CPU only, Python 3.12). Old wheel = `main` +`6bdc86ee`, new wheel = the merge of `main` `6bdc86ee` into the slice-5 branch (`c5051f8`; only tests +changed afterwards). Each wheel was built from its commit's own tree and installed in a clean virtual +environment. The session below was started by the old wheel, so the new wheel never saw it before. + +1. The old wheel ran `benchmarks session start`, `diagnose` and one `round` that was interrupted after + the child completed (exit 130). `calls.log` was `2`. Its 14 files are this directory. +2. On a copy, the new wheel exited 2 for `status` and for `recover` with "Optimization runtime + changed, use its frozen runtime to resume", and the SHA-256 of all 14 files was the same after. +3. On the same copy, the old wheel exited 0 for `recover`. `status` then reported `completed_rounds` 1, + and `calls.log` was still `2`, so recovery used the receipt and did not run the candidate again. + +To redo it for a later runtime change: build and install the old and the new wheel in separate +environments, start the session with the old one (the synthetic task of +`tests/test_optimization_session.py`, `--rounds 3 --max-minutes 5 --evaluation-timeout-seconds 15 +--python python`, run from a neutral directory so no host path enters the plan), stop its coordinator +after the child completes, remove the empty `.session.lock`, and keep everything else. + +To resume such a session, use the runtime that started it: the same commit, installed. + +`.gitattributes` marks the directory `-text` because `plan.json` pins file hashes, and `pyproject.toml` +excludes it from ruff for the same reason. + +`pre-serving-runtime-identity.json` holds the runtime identity of `main` at `25df477`, from before +#498 slice 2. It is used by a test that swaps it into a freshly started session. diff --git a/tests/fixtures/optimization-session/pre-infra-removal-session/calls.log b/tests/fixtures/optimization-session/pre-infra-removal-session/calls.log new file mode 100644 index 000000000..0cfbf0888 --- /dev/null +++ b/tests/fixtures/optimization-session/pre-infra-removal-session/calls.log @@ -0,0 +1 @@ +2 diff --git a/tests/fixtures/optimization-session/pre-infra-removal-session/campaign.json b/tests/fixtures/optimization-session/pre-infra-removal-session/campaign.json new file mode 100644 index 000000000..6a0b5d4f3 --- /dev/null +++ b/tests/fixtures/optimization-session/pre-infra-removal-session/campaign.json @@ -0,0 +1,6 @@ +{ + "campaign_id": "session", + "managed_optimization": true, + "plan_digest": "8ac62beb565a8a299aa919b7fca32ef6a61cd531a9df6ad46301b4c5c578d906", + "task": "test-work" +} diff --git a/tests/fixtures/optimization-session/pre-infra-removal-session/frozen/TASK.md b/tests/fixtures/optimization-session/pre-infra-removal-session/frozen/TASK.md new file mode 100644 index 000000000..35c8bfc46 --- /dev/null +++ b/tests/fixtures/optimization-session/pre-infra-removal-session/frozen/TASK.md @@ -0,0 +1 @@ +Synthetic protocol control diff --git a/tests/fixtures/optimization-session/pre-infra-removal-session/frozen/baseline.py b/tests/fixtures/optimization-session/pre-infra-removal-session/frozen/baseline.py new file mode 100644 index 000000000..431fac18e --- /dev/null +++ b/tests/fixtures/optimization-session/pre-infra-removal-session/frozen/baseline.py @@ -0,0 +1 @@ +FACTOR = 1 diff --git a/tests/fixtures/optimization-session/pre-infra-removal-session/frozen/benchmark.py b/tests/fixtures/optimization-session/pre-infra-removal-session/frozen/benchmark.py new file mode 100644 index 000000000..fa9794659 --- /dev/null +++ b/tests/fixtures/optimization-session/pre-infra-removal-session/frozen/benchmark.py @@ -0,0 +1,11 @@ +import json, runpy, sys +from pathlib import Path +value = runpy.run_path(sys.argv[1])['FACTOR'] +output = Path(sys.argv[2]) +output.mkdir() +with Path('calls.log').open('a') as stream: + stream.write(str(value) + '\n') +status = 'completed' if value > 0 else 'candidate_failure' +result = {'status': status, 'verdict': 'PASS' if value > 0 else 'FAIL', + 'score': value if value > 0 else None} +(output / 'result.json').write_text(json.dumps(result)) diff --git a/tests/fixtures/optimization-session/pre-infra-removal-session/frozen/optimization.py b/tests/fixtures/optimization-session/pre-infra-removal-session/frozen/optimization.py new file mode 100644 index 000000000..c730a6261 --- /dev/null +++ b/tests/fixtures/optimization-session/pre-infra-removal-session/frozen/optimization.py @@ -0,0 +1,8 @@ +import json +def validate_arguments(args): + assert not args + return {} +def arguments(candidate, output, settings): + return [str(candidate), str(output)] +def assess(directory, settings, execution): + return json.loads((directory / 'measurement/result.json').read_text()) diff --git a/tests/fixtures/optimization-session/pre-infra-removal-session/plan.json b/tests/fixtures/optimization-session/pre-infra-removal-session/plan.json new file mode 100644 index 000000000..5edaa1d9b --- /dev/null +++ b/tests/fixtures/optimization-session/pre-infra-removal-session/plan.json @@ -0,0 +1,51 @@ +{ + "schema_version": 2, + "condition": "synthetic-current-agent", + "round_limit": 3, + "max_seconds": 300.0, + "round_mode": "exact", + "final_reserve_seconds": 15.0, + "knowledge_allowed": true, + "evaluation_timeout_seconds": 15.0, + "evaluation_prefix": [], + "python": "python", + "runtime_identity": { + "harness/optimization_session.py": "10ee31b662f3b851a4961ce34c904aa830d95ea5f5495f6df328bf8b59f08477", + "harness/optimization.py": "826d34b35237fdf7112ec3c6a54bc973f22bea61cdb297489e5496bf08177408", + "harness/local_process.py": "ee230f73df879bcbb818448942f14c5fedce7b1c7fd60ce5e4daa38cc67a65be", + "harness/serving/server.py": "2ca1984373423b190b13523fa76ce760e74cc851bbd29b0e532d8d7e92e62c8d", + "infra/artifacts.py": "272f43056086078d05fe777cc08f73b85224468c1ede037ecd72c45747f25095", + "harness/scenarios/external.py": "94ab0dc77596961b8094d93a95cc4a4764178b324f6703c22ab0f78ed0497189", + "harness/atomic_json.py": "87d7b2c4ae881ee9bb64653fcea2fdad9abae5f1a50e6b9adead954a9b0799b0", + "harness/artifact_primitives.py": "6208a775f484d6b3b233bb823b29ef569ff55f94297b176682300208b01c45b9", + "harness/usage.py": "bcb8a35f83e683c1e3343c2438214ad89f35eeb4dd940eccfd54b3489bb70855", + "harness/agent_sessions.py": "491fbf71e03b0c2aef332765fe2c7d7d7d8cf67bd9b96b9a50a2816ccb741573", + "harness/task_protocol.py": "9c9ef100c264b5e596e29b322905f5442228bae711bd2249010e99fde58b6533", + "harness/protocol_child.py": "2cfd5848e711cedeef181981ec6fa2be453ee061f57c32f74954c82625528c95", + "harness/candidates.py": "49aad5645c65516093c7e14514f1bd7ec25d25ee082e6188f552ec415f86698a", + "harness/project.py": "48c1ee5f89bc5a95cedba23be91fb17ebce05f9f75ba954c4bbe3e2310d4f0dd", + "harness/records/knowledge_capture.py": "6a5501d9fdc6bbdc523dc98e59722eae297069a7ad6c024c9d3c7c8f38a42a22", + "apps/workflows/campaign.py": "26b3767357f028929248a69615b6524f1186c30eb47f963114614eeff2f26289", + "knowledge/context_projection.py": "ef89a0b2ecddbb0460573edc65a8b5ef704989e03d3d2fa615ca529ef0debe2a" + }, + "task": "test-work", + "task_source": "benchmark", + "candidate_kind": "file", + "candidate_name": "candidate.py", + "baseline_path": "frozen/baseline.py", + "working_candidate": "work/candidate.py", + "selection": { + "direction": "maximize", + "initial_score": 1.0, + "metric": "speedup" + }, + "evaluation_settings": {}, + "frozen_files": { + "TASK.md": "1045d0e6f05105ea7f990b60fd6669a394aadbd561a7ed40cb7c0954c23ff7dc", + "baseline.py": "d9df1aa140b5050625fe8e130ec631cc25c4a11f732e369c5d018021cfc3e315", + "optimization.py": "5471859e242258a4080decdbf30acde554c68c6b9b559a73fd5a5f788721f816", + "benchmark.py": "6dbbd0c7b2934c3165daed8aa25dcd438b90642d80dff0df602c6bdada0a77c2" + }, + "diagnosis_required": true, + "baseline_sha256": "d9df1aa140b5050625fe8e130ec631cc25c4a11f732e369c5d018021cfc3e315" +} diff --git a/tests/fixtures/optimization-session/pre-infra-removal-session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/candidate.py b/tests/fixtures/optimization-session/pre-infra-removal-session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/candidate.py new file mode 100644 index 000000000..5456c24cd --- /dev/null +++ b/tests/fixtures/optimization-session/pre-infra-removal-session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/candidate.py @@ -0,0 +1 @@ +FACTOR = 2 diff --git a/tests/fixtures/optimization-session/pre-infra-removal-session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/execution/execution.json b/tests/fixtures/optimization-session/pre-infra-removal-session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/execution/execution.json new file mode 100644 index 000000000..47c9ea3a3 --- /dev/null +++ b/tests/fixtures/optimization-session/pre-infra-removal-session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/execution/execution.json @@ -0,0 +1,20 @@ +{ + "status": "completed", + "argv": [ + "python", + "/tmp/pre/venv/lib/python3.12/site-packages/inferrsi/harness/optimization_session.py", + "/tmp/pre/session/frozen/benchmark.py", + "/tmp/pre/session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/candidate.py", + "/tmp/pre/session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/measurement" + ], + "cwd": "/tmp/pre/session", + "returncode": 0, + "result_path": "/tmp/pre/session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/execution/result.json", + "stdout_path": "/tmp/pre/session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/execution/stdout.log", + "stderr_path": "/tmp/pre/session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/execution/stderr.log", + "metric": null, + "metric_error": null, + "pid": 4114821, + "process_group_id": 4114821, + "elapsed_seconds": 0.06838125362992287 +} diff --git a/tests/fixtures/optimization-session/pre-infra-removal-session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/execution/stderr.log b/tests/fixtures/optimization-session/pre-infra-removal-session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/execution/stderr.log new file mode 100644 index 000000000..e69de29bb diff --git a/tests/fixtures/optimization-session/pre-infra-removal-session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/execution/stdout.log b/tests/fixtures/optimization-session/pre-infra-removal-session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/execution/stdout.log new file mode 100644 index 000000000..e69de29bb diff --git a/tests/fixtures/optimization-session/pre-infra-removal-session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/measurement/result.json b/tests/fixtures/optimization-session/pre-infra-removal-session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/measurement/result.json new file mode 100644 index 000000000..a43af2955 --- /dev/null +++ b/tests/fixtures/optimization-session/pre-infra-removal-session/rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3/measurement/result.json @@ -0,0 +1 @@ +{"status": "completed", "verdict": "PASS", "score": 2} \ No newline at end of file diff --git a/tests/fixtures/optimization-session/pre-infra-removal-session/state.json b/tests/fixtures/optimization-session/pre-infra-removal-session/state.json new file mode 100644 index 000000000..c1c14cbd3 --- /dev/null +++ b/tests/fixtures/optimization-session/pre-infra-removal-session/state.json @@ -0,0 +1,42 @@ +{ + "schema_version": 1, + "plan_digest": "8ac62beb565a8a299aa919b7fca32ef6a61cd531a9df6ad46301b4c5c578d906", + "started_at": 1795209032.1252496, + "deadline": 1795209332.1252496, + "state": "active", + "rounds": [], + "contexts": [], + "pending": { + "kind": "round", + "path": "rounds/round-01/attempt-c8293054fed14a4789d192d1f43787c3", + "candidate_id": "candidate-001", + "hypothesis": "two-runtime check", + "strategy": null, + "knowledge_refs": null, + "observations": { + "usage": null, + "tool_calls": null, + "usage_source": null + }, + "diagnosis_id": "diagnosis-9185af7f00374964917c6766eff97182", + "candidate_sha256": "fbeb82c034590c6bce50e163f9beee6a813443950b7b76e10d48bdac31890dc5", + "contexts": [], + "started_at": 1795209032.3816621 + }, + "final": null, + "best": { + "path": "frozen/baseline.py", + "sha256": "d9df1aa140b5050625fe8e130ec631cc25c4a11f732e369c5d018021cfc3e315", + "score": 1.0, + "kind": "baseline" + }, + "diagnoses": [ + { + "id": "diagnosis-9185af7f00374964917c6766eff97182", + "bottleneck": "Reference operation", + "measurement_summary": "Synthetic workload: reference operation took 4 ms.", + "reference_epoch": null, + "recorded_at": 1795209032.2557719 + } + ] +} diff --git a/tests/fixtures/optimization-session/pre-infra-removal-session/work/candidate.py b/tests/fixtures/optimization-session/pre-infra-removal-session/work/candidate.py new file mode 100644 index 000000000..5456c24cd --- /dev/null +++ b/tests/fixtures/optimization-session/pre-infra-removal-session/work/candidate.py @@ -0,0 +1 @@ +FACTOR = 2 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/session_lock_probe.py b/tests/session_lock_probe.py new file mode 100644 index 000000000..d7279ad31 --- /dev/null +++ b/tests/session_lock_probe.py @@ -0,0 +1,136 @@ +"""Hold a real optimization session's lock from a separate Harness process, then export it. + +Run by tests/test_session_lock_across_processes.py once per interpreter: against the +checkout in the test run, and against an installed wheel in tests/check_installed.py. It +builds a valid managed session that is not final, starts a child process that +holds ``/.session.lock`` through ``harness.optimization``'s own lock, and exports the +session through the Apps ``export_bundle`` from this process. While the child holds the lock +the export must be refused and publish nothing; after it releases, the same export must +publish a bundle whose ``export.kind`` is ``progress``. + +Usage: session_lock_probe.py . Prints one JSON line with the observed outcomes. +""" + +import json +import subprocess +import sys +import time +from pathlib import Path + +import inferrsi +from inferrsi.apps import delivery +from inferrsi.apps.artifacts import atomic_write_json, sha256 +from inferrsi.harness import optimization + +# The child runs with -I and imports inferrsi from the same location as this process. +HOLDER = """ +import sys +import time +from pathlib import Path + +sys.path.insert(0, sys.argv[4]) +from inferrsi.harness.optimization import _locked + +root, ready, release = Path(sys.argv[1]), Path(sys.argv[2]), Path(sys.argv[3]) +with _locked(root): + ready.write_text("held", encoding="utf-8") + deadline = time.monotonic() + 60 + while not release.exists() and time.monotonic() < deadline: + time.sleep(0.02) +""" + + +def make_session(root: Path) -> None: + frozen = root / "frozen" + frozen.mkdir(parents=True) + (frozen / "baseline.py").write_text("10", encoding="utf-8") + (frozen / "TASK.md").write_text("Synthetic lock probe; no accelerator claim", encoding="utf-8") + plan = { + "schema_version": 2, "task": "synthetic", "task_source": "project", "condition": "test", + "candidate_kind": "file", "candidate_name": "candidate.py", + "baseline_path": "frozen/baseline.py", "working_candidate": "candidate.py", + "round_mode": "exact", "round_limit": 2, "max_seconds": 600, "final_reserve_seconds": 60, + "selection": {"direction": "minimize", "metric": "latency", "initial_score": 10}, + "evaluation_settings": {"metric_key": "latency", "metric_unit": "ms", + "scope": "synthetic", "direction": "minimize", "repetitions": 2}, + "frozen_files": {p.name: sha256(p) for p in frozen.iterdir()}, + } + optimization.initialize(root, plan) + # A round needs recorded bottleneck evidence first. The file sits beside the session + # root, as in tests/diagnosis_support.py, which an installed wheel does not ship. + evidence = root.with_name(root.name + "-measurement.txt") + evidence.write_text("Synthetic workload: reference operation took 4 ms.", encoding="utf-8") + optimization.record_diagnosis(root, "Reference operation", evidence) + + def execute(root, directory, plan, deadline): + (directory / "execution").mkdir() + execution = {"status": "completed", "returncode": 0, "elapsed_seconds": 1} + atomic_write_json(directory / "execution/execution.json", execution) + atomic_write_json(directory / "measurement.json", + {"synthetic_value": float((directory / "candidate.py").read_text())}) + return execution + + def assess(root, directory, plan, execution): + value = json.loads((directory / "measurement.json").read_text())["synthetic_value"] + verdict = "PASS" if value < 10 else "FAIL" + return { + "status": "completed", "score": value, "baseline_score": 10, "verdict": verdict, + "eligible": verdict == "PASS", "quality_passed": True, "speedup": 10 / value, + "scope": "synthetic", "claim_id": "synthetic-primary", + "reason": "Synthetic fixture assessment", + "metrics": {"name": "latency", "unit": "ms", "direction": "minimize", "baseline": 10, + "candidate": value, "samples": {"baseline": [10, 10], + "candidate": [value, value]}}, + "evidence_files": {"measurement.json": sha256(directory / "measurement.json")}, + } + + candidate = root / "candidate.py" + candidate.write_text("5", encoding="utf-8") + optimization.evaluate_round(root, candidate=candidate, hypothesis="Synthetic score 5", + usage=None, execute=execute, assess=assess) + # No final round: the session stays active, so its export is a progress export. + + +def main(work: Path) -> dict: + # The Apps export refuses a path that crosses a symbolic link, and macOS temporary + # directories sit under /var, a link to /private/var, so use the resolved path. + work = work.resolve() + root = work / "campaign" + make_session(root) + ready, release = work / "held", work / "release" + holder = subprocess.Popen( + [sys.executable, "-I", "-c", HOLDER, str(root), str(ready), str(release), + str(Path(inferrsi.__file__).resolve().parents[1])], + stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, + ) + try: + deadline = time.monotonic() + 30 + while not ready.exists(): + assert holder.poll() is None, holder.communicate() + assert time.monotonic() < deadline, "the Harness holder never took the lock" + time.sleep(0.02) + # Windows reports contention as PermissionError (#494); POSIX raises BlockingIOError, + # which Apps maps to SnapshotBusy. Either way the export must not publish. + busy = delivery.export_bundle(root, work / "busy", export_id="busy") + busy_published = (work / "busy").exists() + finally: + release.write_text("done", encoding="utf-8") + holder.communicate(timeout=60) + released = None + deadline = time.monotonic() + 30 + while True: + released = delivery.export_bundle(root, work / "released", export_id="released") + if released["status"] == "published" or time.monotonic() > deadline: + break + time.sleep(0.1) + published = released["status"] == "published" + return { + "busy_status": busy["status"], "busy_published": busy_published, + "released_status": released["status"], + "released_kind": delivery.read_bundle(work / "released")["export"]["kind"] + if published else None, + } + + +if __name__ == "__main__": + print(json.dumps(main(Path(sys.argv[1])))) 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 47ba6768e..7dffce05b 100644 --- a/tests/test_apps_module_migrations.py +++ b/tests/test_apps_module_migrations.py @@ -249,7 +249,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): @@ -301,7 +301,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..70b790638 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 @@ -1287,6 +1294,10 @@ def test_overall_true_only_when_every_trigger_is_cleared(self) -> None: self.assertTrue(report.new_core_closure_isolated) self.assertTrue(report.isolation_complete) + # Three triggers build synthetic Infra and Model packages. Those are retired names since + # #498, which test_target_module_import_gate.py covers, so the retirement rule is + # switched off here and the trigger counts stay about the Harness edge and the others. + @mock.patch.object(support, "RETIRED_MODULES", frozenset()) def test_each_trigger_alone_keeps_overall_false(self) -> None: triggers = ( ("absent: knowledge/", {"knowledge/__init__.py": None, "knowledge/catalog.py": None}, 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..418548dc5 100644 --- a/tests/test_module_boundaries.py +++ b/tests/test_module_boundaries.py @@ -101,7 +101,9 @@ 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"): + # The Anthropic providers came from the retired model/ package and keep its rule: no + # Harness import. Other integrations, such as Cannbot, are Apps code and may use Harness. + for plane in ("apps/host", "apps/integrations/anthropic", "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 +121,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/anthropic": assert not name.startswith("inferrsi.harness"), (path, name) diff --git a/tests/test_optimization_session.py b/tests/test_optimization_session.py index c4d207c57..0abbff5d9 100644 --- a/tests/test_optimization_session.py +++ b/tests/test_optimization_session.py @@ -3,6 +3,7 @@ import hashlib import json import os +import shutil import subprocess import sys from pathlib import Path @@ -835,6 +836,39 @@ def test_a_plan_from_before_the_serving_move_is_refused_and_left_unchanged(sessi assert path.read_bytes() == before +PRE_INFRA_REMOVAL = (Path(__file__).resolve().parent / "fixtures" / "optimization-session" + / "pre-infra-removal-session") + + +def _session_bytes(root): + return {path.relative_to(root).as_posix(): path.read_bytes() + for path in sorted(root.rglob("*")) if path.is_file()} + + +def test_a_session_planned_before_the_infra_removal_is_refused_and_left_unchanged( + tmp_path, capsys, +): + # #498 slice 5. The fixture is a session that main 6bdc86ee started with its own runtime, + # unedited (see optimization-session/README.md). Its coordinator was interrupted after + # the candidate's child finished, so it holds a completed execution receipt for a round + # that is not settled, and its plan.json still names infra/artifacts.py. The runtime + # without Infra refuses it before status or recover dispatches, and no file changes. + session = tmp_path / "session" + shutil.copytree(PRE_INFRA_REMOVAL, session) + before = _session_bytes(session) + state = json.loads(before["state.json"]) + assert state["rounds"] == [] and state["pending"]["kind"] == "round" + receipt = json.loads(before[state["pending"]["path"] + "/execution/execution.json"]) + assert receipt["status"] == "completed" and receipt["returncode"] == 0 + assert before["calls.log"] == b"2\n" + assert "infra/artifacts.py" in json.loads(before["plan.json"])["runtime_identity"] + assert not any(name.startswith("infra/") for name in optimization_session._runtime_identity()) + for action in ("status", "recover"): + output = _refused(session, capsys, action) + assert "Optimization runtime changed" in output.out + output.err, action + assert _session_bytes(session) == before + + def test_changed_installed_server_bytes_refuse_an_untouched_plan( session, capsys, monkeypatch, tmp_path, ): 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 1bb3dbd97..1eaf92050 100644 --- a/tests/test_project_service_reuse.py +++ b/tests/test_project_service_reuse.py @@ -10,11 +10,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 from tests.diagnosis_support import diagnosis_args 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 3a6613b51..6c939597c 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 from tests.diagnosis_support import diagnosis_evidence diff --git a/tests/test_session_lock_across_processes.py b/tests/test_session_lock_across_processes.py new file mode 100644 index 000000000..f1df51016 --- /dev/null +++ b/tests/test_session_lock_across_processes.py @@ -0,0 +1,135 @@ +"""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. + +``tests/session_lock_probe.py`` drives the real pair with a valid managed session: a Harness +process holds the lock and the Apps ``export_bundle`` of that session is refused, then the +same export publishes after release. The probe runs here against the checkout and in +``tests/check_installed.py`` against the installed wheel. The exception type that Windows +raises for contention is #494 and stays a separate assertion in tests/test_result_delivery.py. +""" + +import json +import os +import subprocess +import sys +import time +from pathlib import Path + +import pytest + +SRC = str(Path(__file__).resolve().parents[1] / "src") +PROBE_SCRIPT = Path(__file__).with_name("session_lock_probe.py") + +# 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 test_an_apps_export_of_a_valid_session_is_refused_while_a_harness_process_holds_it(tmp_path): + # The actual writer and reader pair on a real session, run from the checkout. + (tmp_path / "work").mkdir() + # Not -I: the probe imports inferrsi from the checkout through PYTHONPATH. + result = subprocess.run( + [sys.executable, "-B", str(PROBE_SCRIPT), str(tmp_path / "work")], + capture_output=True, text=True, check=False, timeout=300, + env={**os.environ, "PYTHONPATH": SRC, "PYTHONIOENCODING": "utf-8"}, + ) + assert result.returncode == 0, result.stderr + outcome = json.loads(result.stdout.strip().splitlines()[-1]) + assert outcome["busy_status"] != "published" and outcome["busy_published"] is False, outcome + assert outcome["released_status"] == "published", outcome + assert outcome["released_kind"] == "progress", outcome 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 670fd9f2b..c0973307f 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 aa11c8b63..a9a6b8c98 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 a3320a6b6..31ce3be21 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 (