Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f23a655
test: identify canonical JSON consumers by qualified scope
Trecek Oct 22, 2026
69b6f2d
test: always select whole-source infra scanners
Trecek Oct 22, 2026
e8ada51
test: replace sibling guard line anchors with counted scope identity
Trecek Oct 22, 2026
6878c38
test: count ambient environment exceptions by qualified scope
Trecek Oct 22, 2026
8dd3fa4
fix(review): share AST helpers across test packages
Trecek Oct 22, 2026
4716b19
fix(review): share registry count comparison across scanners
Trecek Oct 22, 2026
1364335
fix(review): reuse shared scope names in git reference scanner
Trecek Oct 22, 2026
7b69176
fix(review): remove unused git inventory path constants
Trecek Oct 22, 2026
93f4276
fix(review): explain repeated git inventory identities
Trecek Oct 22, 2026
acf5036
fix(review): remove duplicate ambient registry checks
Trecek Oct 22, 2026
98267ee
fix(review): report malformed dynamic read count overrides clearly
Trecek Oct 22, 2026
7e736db
fix(review): release ambient scanner AST caches after each test
Trecek Oct 22, 2026
f2f9007
fix(review): reuse canonical JSON scanner root constants
Trecek Oct 22, 2026
03e79be
fix(review): remove tautological allowlist assertions
Trecek Oct 22, 2026
96ba548
fix(review): bind install registry counts to named scopes
Trecek Oct 22, 2026
6d494e6
fix(review): fail install scanner on unparseable source
Trecek Oct 22, 2026
d772ca9
fix(review): remove redundant install scanner assertion
Trecek Oct 22, 2026
7615b2e
fix(review): avoid pinning evolving test selection set sizes
Trecek Oct 22, 2026
a6f4213
fix(review): detect and always select hook source scanners
Trecek Oct 22, 2026
cde2875
fix(review): register the actual recipe installation function
Trecek Oct 22, 2026
32e5b8a
fix(review): always select the write target source scanner
Trecek Oct 22, 2026
77f0eeb
fix: measure completion deferral with a monotonic clock
Trecek Oct 22, 2026
01086c4
fix(review): refresh the corrected install registry digest snapshot
Trecek Oct 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ class ExecutionInstallSiteDef(NamedTuple):
{
"inline_delivery": ExecutionInstallSiteDef(
installer_module="src/autoskillit/server/recipe/_recipe_delivery/_completion.py",
installer_symbol="complete_finalized_recipe_response",
installer_symbol="_activate_recipe_initialization",
delivering_module="src/autoskillit/server/recipe/_recipe_artifact.py",
delivering_symbol="build_canonical_recipe_artifact_payload",
delivery_surface="open_kitchen",
Expand Down
80 changes: 50 additions & 30 deletions tests/_ambient_env_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,124 +953,144 @@ class AmbientEnvDisposition:


DYNAMIC_READ_EXEMPTIONS: dict[str, str] = {
"execution/evidence/reader/_contract.py:146": (
("execution/evidence/reader/_contract.py::evidence_reader_provider_environment"): (
"Dict/generator-comprehension key bound by `for name in _PROVIDER_ENV`; this scanner does"
"not trace comprehension-bound names back through their iterable's members."
),
"server/lifecycle/_guards.py:418": (
("server/lifecycle/_guards.py::_profile_to_env"): (
"`profile.api_key_env` is a per-provider-profile instance attribute resolved at runtime"
"from config, not a module-level constant this AST scanner can resolve."
),
"server/lifecycle/_lifespan/_session_boots.py:524": (
("server/lifecycle/_lifespan/_session_boots.py::_evidence_reader_auto_gate_boot"): (
"Dict-comprehension key bound by `for name in EVIDENCE_READER_ENV_FORWARD_VARS`; the three"
"forwarded names are already captured directly via that collection's own R4 scan."
),
"server/lifecycle/_session_type.py:49": (
"server/lifecycle/_session_type.py::_evidence_reader_binding_state": (
"Set-comprehension key bound by `for key in EVIDENCE_READER_ENV_FORWARD_VARS`; the"
"forwarded names are already captured directly via that collection's own R4 scan."
),
"server/lifecycle/_session_type.py:54": (
"\n\n"
"Generator-expression key bound by `for key in EVIDENCE_READER_ENV_FORWARD_VARS`; the"
"forwarded names are already captured directly via that collection's own R4 scan."
),
"server/lifecycle/_session_type.py:61": (
("server/lifecycle/_session_type.py::_has_explorer_binding_env"): (
"Dict-comprehension key bound by `for key in _EXPLORER_BINDING_ENV_KEYS`; the four"
"explorer-binding names are already captured directly via that collection's own R4 scan."
),
"server/tools/tools_evidence_reader.py:174": (
("server/tools/tools_evidence_reader.py::_private_environment"): (
"Dict-comprehension key bound by `for name in EVIDENCE_READER_ENV_FORWARD_VARS`; the three"
"forwarded names are already captured directly via that collection's own R4 scan."
),
"server/tools/tools_execution/_candidate_policy.py:191": (
("server/tools/tools_execution/_candidate_policy.py::resolve_candidate_policy"): (
"`definition.api_key_env` is a per-provider-profile instance attribute resolved at "
"runtime from config, not a module-level constant this AST scanner can resolve."
),
"server/tools/tools_execution/_run_skill_prepare.py:123": (
("server/tools/tools_execution/_run_skill_prepare.py::_resolve_provider_binding"): (
"`definition.api_key_env` is a per-provider-profile instance attribute resolved at "
"runtime from the persisted launch contract, not a statically resolvable name."
),
}

DYNAMIC_READ_EXEMPTION_COUNTS: dict[str, int] = {
"execution/evidence/reader/_contract.py::evidence_reader_provider_environment": 2,
"server/lifecycle/_session_type.py::_evidence_reader_binding_state": 2,
"server/tools/tools_evidence_reader.py::_private_environment": 2,
}

FORWARDING_SITES: dict[str, str] = {
"cli/install/_marketplace.py:358": (
("cli/install/_marketplace.py::install"): (
"Unfiltered dict(os.environ) snapshot (`ambient_env`) used as the base for an"
"install/publish subprocess env; intentional wholesale forward for a maintenance-style"
"operation."
),
"cli/app.py:315": (
("cli/app.py::install"): (
"Bare os.environ passed as `child_env` to the maintenance installer, which itself applies"
"an explicit allowlist (build_maintenance_env) before spawning; unfiltered by design here."
),
"cli/session/_session_launch.py:161": (
("cli/session/_session_launch.py::prepare_interactive_launch"): (
"Unfiltered dict(os.environ) used only to probe an exact executable path before the real"
"session env is sealed by build_agent_env elsewhere; not the launched child's env."
),
"cli/update/_transaction.py:440": (
("cli/update/_transaction.py::run_update_transaction"): (
"Unfiltered dict(os.environ if base_env is None else base_env) snapshot captured for"
"update-transaction diagnostics/rollback comparison, not for a spawned child process."
),
"cli/update/_update_checks_source.py:190": (
("cli/update/_update_checks_source.py::_git_ls_remote_sha"): (
"Bare os.environ passed as `env=` to a read-only `git ls-remote` probe subprocess;"
"unfiltered wholesale forward for a local diagnostic command."
),
"execution/backends/_codex_probes.py:411": (
("execution/backends/_codex_probes.py::_validate_generated_codex_home"): (
"Unfiltered dict(os.environ) base for the global-Codex-home MCP-inventory validation"
"probe subprocess, with CODEX_RESERVED_HOME_ENV_VARS overridden to the source home."
),
"execution/backends/claude.py:341": (
("execution/backends/claude.py::ClaudeCodeBackend._prepare_interactive_environment"): (
"Excludes _INTERACTIVE_ENV_EXCLUSIONS (TERM/NO_COLOR headless-hardening keys) when"
"building the interactive Claude Code base env."
),
"execution/backends/_claude/session_commands.py:108": (
(
"execution/backends/_claude/session_commands.py::"
"ClaudeSessionCommandMixin._skill_session_environment_inputs"
): (
"Excludes _HEADLESS_EXCLUSIVE_VARS before build_agent_env layers extras back in for a"
"headless Claude Code skill-session launch."
),
"execution/backends/_claude/session_commands.py:326": (
(
"execution/backends/_claude/session_commands.py::"
"ClaudeSessionCommandMixin.build_food_truck_cmd"
): (
"Excludes _HEADLESS_EXCLUSIVE_VARS before build_agent_env layers extras back in for a"
"headless Claude Code food-truck orchestrator-session launch."
),
"execution/backends/_codex/headless_commands.py:65": (
(
"execution/backends/_codex/headless_commands.py::"
"CodexOrdinaryHeadlessCommandMixin.build_headless_cmd"
): (
"Excludes _HEADLESS_EXCLUSIVE_VARS before build_env layers extras back in for a headless"
" Codex generic-prompt launch; the finalized generated home is layered by the caller."
),
"execution/backends/_codex/session_commands.py:176": (
(
"execution/backends/_codex/session_commands.py::CodexCommandMixin."
"_prepare_skill_session_environment"
): (
"Excludes _HEADLESS_EXCLUSIVE_VARS before build_env layers extras back in for a headless"
"Codex skill-session launch."
),
"execution/backends/_codex/session_commands.py:494": (
("execution/backends/_codex/session_commands.py::CodexCommandMixin.build_food_truck_cmd"): (
"Excludes _HEADLESS_EXCLUSIVE_VARS before build_env layers extras back in for a headless"
"Codex food-truck orchestrator-session launch."
),
"execution/backends/_codex/session_commands.py:194": (
(
"execution/backends/_codex/session_commands.py::CodexCommandMixin."
"_prepare_interactive_environment"
): (
"Excludes _HEADLESS_EXCLUSIVE_VARS before extras merge for a Codex interactive-session"
"launch base env."
),
"execution/backends/_codex/session_commands.py:707": (
("execution/backends/_codex/session_commands.py::CodexCommandMixin.build_resume_cmd"): (
"Excludes _HEADLESS_EXCLUSIVE_VARS before build_env layers extras back in for a headless"
"Codex resume-session launch."
),
"execution/merge_queue/_merge_queue_group_ci.py:109": (
("execution/merge_queue/_merge_queue_group_ci.py::_query_merge_group_ci"): (
"Unfiltered {**os.environ} base for a local `gh run list` CI-status probe subprocess;"
"GH_TOKEN is the only key ever added on top."
),
"execution/runtime/testing.py:50": (
("execution/runtime/testing.py::build_sanitized_env"): (
"Excludes AUTOSKILLIT_PRIVATE_ENV_VARS before handing the sanitized env to a user-code"
"`pytest` subprocess spawned by test_check."
),
"exploration/snapshot/_capture.py:92": (
("exploration/snapshot/_capture.py::_git"): (
"Unfiltered dict(os.environ) base for a local read-only `git` subprocess (snapshot"
"diffing); only GIT_OPTIONAL_LOCKS is added on top."
),
"hooks/_capture_spawn.py:298": (
("hooks/_capture_spawn.py::_scrubbed_user_environment"): (
"dict(os.environ) followed by an explicit per-key .pop() loop over"
"PROTECTED_CAPTURE_ENV_VARS; the exclusion happens outside the single expression this"
"scanner inspects."
),
"hooks/_dispatch.py:84": (
("hooks/_dispatch.py::main"): (
"Unfiltered dict(os.environ) base for a same-host hook-script subprocess; only"
"PYTHONDONTWRITEBYTECODE is added on top."
),
"smoke_utils/_cross_interpreter_upgrade.py:337": (
("smoke_utils/_cross_interpreter_upgrade.py::run_cross_interpreter_upgrade_smoke"): (
"Unfiltered dict(os.environ) base for a smoke-test cross-interpreter upgrade subprocess"
"sandboxed to a scratch HOME/XDG tree overridden immediately after."
),
Expand Down
49 changes: 46 additions & 3 deletions tests/contracts/_ast_helpers.py → tests/_ast_helpers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
"""Shared AST helpers for call-site extraction tests."""
"""Shared AST helpers for call-site extraction tests across test packages."""

from __future__ import annotations

import ast
from collections import Counter
from collections.abc import Iterable
from collections.abc import Iterable, Mapping
from pathlib import Path
from typing import TypeVar

MODULE_SCOPE = "<module>"
_K = TypeVar("_K")


def count_differences(
expected: Mapping[_K, int], observed: Mapping[_K, int]
) -> list[tuple[_K, int, int]]:
"""Return mismatched registry keys with their expected and observed counts."""
return [
(key, expected.get(key, 0), observed.get(key, 0))
for key in sorted(expected.keys() | observed.keys(), key=str)
if expected.get(key, 0) != observed.get(key, 0)
]


def call_name(node: ast.Call) -> str | None:
Expand All @@ -17,6 +32,27 @@ def call_name(node: ast.Call) -> str | None:
return None


def scope_qualnames(tree: ast.AST) -> dict[ast.AST, str]:
"""Map nodes to their enclosing named-definition AST chain.

Scopes are ``ClassDef``/``FunctionDef``/``AsyncFunctionDef`` nodes joined with ``."``
(``Outer.method``); a def or class node maps to its own qualname, and nodes outside
every def and class map to ``MODULE_SCOPE``. Definition headers inherit that
definition's key, including decorators, defaults, annotations and class bases.
This describes AST ancestry, not Python execution scopes. Keys omit runtime
``__qualname__``'s ``<locals>`` component: a nested function is ``outer.inner``.
"""
owners: dict[ast.AST, str] = {}
stack: list[tuple[ast.AST, str]] = [(tree, MODULE_SCOPE)]
while stack:
node, scope = stack.pop()
if isinstance(node, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)):
scope = node.name if scope == MODULE_SCOPE else f"{scope}.{node.name}"
owners[node] = scope
stack.extend((child, scope) for child in ast.iter_child_nodes(node))
return owners


def callers_by_function(
src_root: Path,
*,
Expand Down Expand Up @@ -59,4 +95,11 @@ def count_callers(src_root: Path, symbol: str) -> int:
return sum(callers_by_function(src_root, symbol=symbol).values())


__all__: Iterable[str] = ("call_name", "callers_by_function", "count_callers")
__all__: Iterable[str] = (
"MODULE_SCOPE",
"call_name",
"callers_by_function",
"count_callers",
"count_differences",
"scope_qualnames",
)
9 changes: 9 additions & 0 deletions tests/_test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,13 @@ class SourceMapRejection(enum.StrEnum):
# skip the test and let a drift pass silently. test_docker_image.py
# likewise compares the Dockerfile's pins with code constants under src/, which no infra
# trigger covers.
# Whole-source-tree scanners read src/ by path, so neither an import edge nor coverage
# selects them; tests/arch/test_infra_source_scanner_selection.py requires every such
# infra or hooks scanner to be listed.
_INFRA_UNCONDITIONAL_FILES: frozenset[str] = frozenset(
{
"test_docker_image.py",
"test_canonical_json_producer_convention.py",
"test_manifest_completeness.py",
"test_manifest_directory_completeness.py",
"test_guard_coverage.py",
Expand All @@ -211,6 +215,8 @@ class SourceMapRejection(enum.StrEnum):
"test_plugin_source_ratchets.py",
"test_lint_gate_selection.py",
"test_typecheck_gate.py",
"test_schema_read_convention.py",
"test_session_ttl_single_source.py",
}
)

Expand All @@ -221,6 +227,9 @@ class SourceMapRejection(enum.StrEnum):
"test_hook_executability.py",
"test_hook_registration_coverage.py",
"test_hook_registry.py",
"test_hook_scope_authority.py",
"test_join_enforcement_wiring.py",
"test_write_target_scan_authority.py",
}
)

Expand Down
12 changes: 12 additions & 0 deletions tests/arch/_acceptance_policy_surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ class PolicyRelaxationApproval:


POLICY_SURFACES: tuple[PolicySurface, ...] = (
PolicySurface(
"tests/infra/test_schema_version_convention.py",
"_LEGACY_JSON_WRITE_COUNTS",
"int_map",
default=0,
),
PolicySurface(
"tests/_ambient_env_surface.py",
"DYNAMIC_READ_EXEMPTION_COUNTS",
"int_map",
default=1,
),
PolicySurface(
"tests/arch/_subpackage_isolation_line_limits.py",
"_LINE_LIMIT_EXEMPTIONS",
Expand Down
2 changes: 1 addition & 1 deletion tests/arch/test_admission_evidence_explicit_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import pytest

from tests.contracts._ast_helpers import call_name
from tests._ast_helpers import call_name

pytestmark = [pytest.mark.layer("arch"), pytest.mark.medium]

Expand Down
Loading
Loading