diff --git a/docs/recipes/authoring.md b/docs/recipes/authoring.md index fb96573212..a85427236e 100644 --- a/docs/recipes/authoring.md +++ b/docs/recipes/authoring.md @@ -82,7 +82,7 @@ The rule families live in `src/autoskillit/recipe/rules_*.py` (28 files): | `rules_features.py` | Feature-flag gating rules: steps that reference features not declared in `requires_packs` | | `rules_fixing.py` | Fixing/Rectify workflow rules: rectify loops missing a terminal success route | | `rules_graph.py` | Step graph reachability and cycle detection | -| `rules_inputs.py` | Ingredient/version validation — required ingredients are present, types are correct | +| `rules_inputs.py` | Ingredient/version validation — required ingredients are present, types are correct; `typed-skill-input-undeclared-source` checks dynamic typed inputs. Capture `type: integer` means canonical ASCII decimal text. | | `rules_isolation.py` | Workspace isolation breaches: `source-isolation-violation` and `git-mutation-on-source` | | `rules_merge.py` | `merge_worktree` routing completeness — every `MergeFailedStep` value must have a route | | `rules_packs.py` | Unknown pack names in `requires_packs`; packs required by dispatched skill categories or by direct tool steps' food-truck visibility missing from `requires_packs` | @@ -97,6 +97,13 @@ The rule families live in `src/autoskillit/recipe/rules_*.py` (28 files): The semantic-rule catalog is defined by the rule modules under `recipe/rules/`. +`typed-skill-input-undeclared-source` is an advisory warning about producer +declarations. Runtime admission checks the input's actual value independently: +integer skill inputs accept JSON integers (excluding booleans), or canonical ASCII +decimal text from exact context or ingredient references, even without an integer +producer declaration. Malformed text is rejected regardless of the declaration. +A capture declared `type: integer` also validates its output when it is captured. + ## Contract cards Every skill referenced by a recipe carries a **contract card** in diff --git a/src/autoskillit/core/__init__.pyi b/src/autoskillit/core/__init__.pyi index 0fc010f873..e9445cf3b8 100644 --- a/src/autoskillit/core/__init__.pyi +++ b/src/autoskillit/core/__init__.pyi @@ -514,6 +514,7 @@ from .types import BROKER_AUTHORITY_STATUSES as BROKER_AUTHORITY_STATUSES from .types import CALLER_SOVEREIGN_INGREDIENTS as CALLER_SOVEREIGN_INGREDIENTS from .types import CAMPAIGN_ID_ENV_VAR as CAMPAIGN_ID_ENV_VAR from .types import CANONICAL_ACCOUNTING_FIELDS as CANONICAL_ACCOUNTING_FIELDS +from .types import CANONICAL_INTEGER_DIGITS as CANONICAL_INTEGER_DIGITS from .types import CANONICAL_LAUNCH_DIGEST_FIELDS as CANONICAL_LAUNCH_DIGEST_FIELDS from .types import CAPTURE_VALID_VALUE_TYPES as CAPTURE_VALID_VALUE_TYPES from .types import CATEGORY_TAGS as CATEGORY_TAGS @@ -1444,6 +1445,7 @@ from .types import extract_skill_name as extract_skill_name from .types import fleet_error as fleet_error from .types import group_by_pair as group_by_pair from .types import hookdef_session_scope as hookdef_session_scope +from .types import is_canonical_integer_text as is_canonical_integer_text from .types import is_canonical_plugin_artifact_digest as is_canonical_plugin_artifact_digest from .types import ( is_canonical_plugin_artifact_incarnation_id as is_canonical_plugin_artifact_incarnation_id, diff --git a/src/autoskillit/core/types/recipe/_type_capture.py b/src/autoskillit/core/types/recipe/_type_capture.py index 79f23a507f..9acfaab27b 100644 --- a/src/autoskillit/core/types/recipe/_type_capture.py +++ b/src/autoskillit/core/types/recipe/_type_capture.py @@ -10,15 +10,24 @@ from typing import Literal, TypeGuard __all__ = [ + "CANONICAL_INTEGER_DIGITS", "CAPTURE_VALID_VALUE_TYPES", "CaptureEntrySpec", "CaptureValueType", "CaptureValueTypeError", "is_capture_value_type", + "is_canonical_integer_text", "resolve_payload_field", ] _RESULT_REF_RE = re.compile(r"^\$\{\{\s*result\.([\w-]+)\s*\}\}$") +CANONICAL_INTEGER_DIGITS = 19 +_CANONICAL_INTEGER_TEXT = re.compile(rf"0|-?[1-9][0-9]{{0,{CANONICAL_INTEGER_DIGITS - 1}}}") + + +def is_canonical_integer_text(value: str) -> bool: + """Return whether text is an ASCII decimal integer within the wire digit limit.""" + return _CANONICAL_INTEGER_TEXT.fullmatch(value) is not None def resolve_payload_field(entry: CaptureEntrySpec) -> str | None: @@ -36,9 +45,9 @@ def resolve_payload_field(entry: CaptureEntrySpec) -> str | None: return m.group(1) if m else None -CAPTURE_VALID_VALUE_TYPES = frozenset({"path", "url", "string", "optional_string"}) +CAPTURE_VALID_VALUE_TYPES = frozenset({"path", "url", "string", "optional_string", "integer"}) -CaptureValueType = Literal["path", "url", "string", "optional_string"] +CaptureValueType = Literal["path", "url", "string", "optional_string", "integer"] def is_capture_value_type(value: str) -> TypeGuard[CaptureValueType]: @@ -53,11 +62,12 @@ class CaptureEntrySpec: Attributes: from_: The ``${{ result. }}`` template string — what was previously the plain string value in the ``dict[str, str]`` capture spec. - value_type: One of ``path``, ``url``, ``string``, ``optional_string``. + value_type: A declared capture type. ``integer`` means canonical ASCII + decimal text decoded by integer skill inputs. """ from_: str - value_type: Literal["path", "url", "string", "optional_string"] + value_type: CaptureValueType def __post_init__(self) -> None: if not self.from_ or not self.from_.strip(): diff --git a/src/autoskillit/core/types/recipe/_type_recipe_binding.py b/src/autoskillit/core/types/recipe/_type_recipe_binding.py index ef74f8ccd5..9fd98e6648 100644 --- a/src/autoskillit/core/types/recipe/_type_recipe_binding.py +++ b/src/autoskillit/core/types/recipe/_type_recipe_binding.py @@ -349,6 +349,10 @@ def absent(cls, name: str) -> BoundValue: def is_present(self) -> bool: return self.state is BoundValueState.PRESENT + @property + def is_dynamic(self) -> bool: + return bool(self.context_dependencies or self.input_dependencies) + class BindingFailureCode(StrEnum): UNKNOWN_TOOL = "unknown_tool" diff --git a/src/autoskillit/fleet/_capture.py b/src/autoskillit/fleet/_capture.py index 9ea385f5a0..adf1de9cfe 100644 --- a/src/autoskillit/fleet/_capture.py +++ b/src/autoskillit/fleet/_capture.py @@ -11,6 +11,7 @@ CaptureValueType, CaptureValueTypeError, get_logger, + is_canonical_integer_text, is_capture_value_type, resolve_payload_field, ) @@ -58,6 +59,15 @@ def _validate_capture_value(key: str, value: str, declared_type: str) -> None: Raises CaptureValueTypeError if validation fails. """ + if declared_type == "integer": + if not is_canonical_integer_text(value): + raise CaptureValueTypeError( + key=key, + value=value, + declared_type=declared_type, + reason="integer value must be canonical ASCII decimal text", + ) + return if declared_type == "optional_string": return if declared_type not in ("path", "string", "url"): diff --git a/src/autoskillit/recipe/_binding.py b/src/autoskillit/recipe/_binding.py index 7f0f6a4a87..b0e762e0dc 100644 --- a/src/autoskillit/recipe/_binding.py +++ b/src/autoskillit/recipe/_binding.py @@ -285,7 +285,7 @@ def _compile_tool_parameters( ) value = _bound_value(param.name, declared, resolved) mcp_kwargs.append(value) - unresolved = bool(value.context_dependencies or value.input_dependencies) + unresolved = value.is_dynamic if not unresolved and not _wire_value_is_valid(resolved, param): failures.append( _failure( @@ -565,10 +565,6 @@ def bind_recipe( return RecipeBindingProjection(invocations) -def _is_dynamic_binding(value: BoundValue) -> bool: - return bool(value.context_dependencies or value.input_dependencies) - - def _undeclared_runtime_param_message(tool_def: ToolDef, undeclared_names: list[str]) -> str: """Denial text for undeclared non-empty runtime tool parameters. @@ -712,17 +708,17 @@ def _bind_runtime_skill_values( "recipe_execution_contract_mismatch", f"compiled skill input {value.name!r} is absent from the runtime contract", ) - if not input_def.accepts(actual): + admitted = input_def.admit_runtime_wire(actual, value) + if admitted is None: raise RuntimeBindingError( - "recipe_execution_input_type", - f"runtime skill input {value.name!r} expects {input_def.type!r}", + "recipe_execution_input_type", input_def.wire_mismatch_message(actual, value) ) - if not _is_dynamic_binding(value) and actual != value.effective_value: + if not value.is_dynamic and admitted != value.effective_value: raise RuntimeBindingError( "recipe_execution_static_input_mismatch", f"static skill input {value.name!r} differs from the template", ) - bound_inputs.append((value.name, actual)) + bound_inputs.append((value.name, admitted)) return tuple(bound_inputs) @@ -738,7 +734,7 @@ def _validate_runtime_mcp_values( f"compiled tool parameter {value.name!r} is absent", ) actual = actual_mcp_kwargs[value.name] - if not _is_dynamic_binding(value) and actual != value.effective_value: + if not value.is_dynamic and actual != value.effective_value: raise RuntimeBindingError( "recipe_execution_static_tool_mismatch", f"static tool parameter {value.name!r} differs from the template", diff --git a/src/autoskillit/recipe/_binding_input.py b/src/autoskillit/recipe/_binding_input.py index 01db0a2bcb..14e54e208f 100644 --- a/src/autoskillit/recipe/_binding_input.py +++ b/src/autoskillit/recipe/_binding_input.py @@ -370,7 +370,7 @@ def _inline_skill_inputs( bound_declared, bound_effective = pair value = _bound_value(input_def.name, bound_declared, bound_effective) bound.append(value) - unresolved = bool(value.context_dependencies or value.input_dependencies) + unresolved = value.is_dynamic if not unresolved and not _skill_value_is_valid(bound_effective, input_def): failures.append( _failure( @@ -476,7 +476,7 @@ def _structured_skill_inputs( optional_context_refs=optional_context_refs, ) bound.append(value) - unresolved = bool(value.context_dependencies or value.input_dependencies) + unresolved = value.is_dynamic if not unresolved and not _skill_value_is_valid(resolved, input_def): failures.append( _failure( diff --git a/src/autoskillit/recipe/contracts/_contracts_types.py b/src/autoskillit/recipe/contracts/_contracts_types.py index dc6d43fe3b..aa4208a9d3 100644 --- a/src/autoskillit/recipe/contracts/_contracts_types.py +++ b/src/autoskillit/recipe/contracts/_contracts_types.py @@ -8,10 +8,14 @@ import regex as re from autoskillit.core import ( + CANONICAL_INTEGER_DIGITS, EXTERNAL_EFFECT_CHOICES, VALID_EXTERNAL_EFFECTS, BoundScalar, + BoundValue, + BoundValueOrigin, PreflightKind, + is_canonical_integer_text, ) _CONTEXT_REF_RE = re.compile(r"\$\{\{\s*context\.([A-Za-z_]\w*)\s*\}\}") @@ -20,6 +24,11 @@ RESULT_CAPTURE_RE = re.compile(r"\$\{\{\s*result\.([\w-]+)\s*\}\}") +_TEXT_INPUT_TYPES = frozenset({"str", "string", "optional_string"}) +_PATH_INPUT_TYPES = frozenset({"file_path", "file_path_list", "directory_path"}) +_EXACT_REFERENCE_ORIGINS = frozenset({BoundValueOrigin.CONTEXT, BoundValueOrigin.RECIPE_INPUT}) + + @dataclasses.dataclass(frozen=True, slots=True) class SkillInput: name: str @@ -46,14 +55,7 @@ def has_absence_value(self) -> bool: def accepts(self, value: object) -> bool: normalized = self.type - if normalized in { - "str", - "string", - "optional_string", - "file_path", - "file_path_list", - "directory_path", - }: + if normalized in _TEXT_INPUT_TYPES | _PATH_INPUT_TYPES: return isinstance(value, str) if normalized == "integer": return isinstance(value, int) and not isinstance(value, bool) @@ -63,6 +65,42 @@ def accepts(self, value: object) -> bool: return isinstance(value, bool) return False + def admit_runtime_wire(self, value: BoundScalar, bound: BoundValue) -> BoundScalar | None: + """Return the bound value, or None when the declared type rejects its wire form.""" + if self.accepts(value): + return value + if bound.origin not in _EXACT_REFERENCE_ORIGINS: + return None + if self.type == "integer": + if isinstance(value, str) and is_canonical_integer_text(value): + return int(value) + return None + if self.type not in _TEXT_INPUT_TYPES or not isinstance(value, int): + return None + if isinstance(value, bool): + text = "true" if value else "false" + elif abs(value) < 10**CANONICAL_INTEGER_DIGITS: + text = str(value) + else: + return None + return None if text == bound.absence_value else text + + def wire_mismatch_message(self, value: BoundScalar, bound: BoundValue) -> str: + message = ( + f"runtime skill input {self.name!r} expects {self.type!r}; " + f"received {type(value).__name__}" + ) + if self.type == "integer": + message += "; send a JSON integer" + if bound.origin in _EXACT_REFERENCE_ORIGINS: + message += ( + " or canonical ASCII decimal text" + f" (e.g. '31'; at most {CANONICAL_INTEGER_DIGITS} digits)" + ) + elif self.type in _TEXT_INPUT_TYPES: + message += "; send a JSON string" + return message + @dataclasses.dataclass class SkillOutput: diff --git a/src/autoskillit/recipe/rules/rules_inputs.py b/src/autoskillit/recipe/rules/rules_inputs.py index f024441d1b..b0e5f94030 100644 --- a/src/autoskillit/recipe/rules/rules_inputs.py +++ b/src/autoskillit/recipe/rules/rules_inputs.py @@ -2,6 +2,8 @@ from __future__ import annotations +from collections.abc import Iterator + import regex as re from packaging.version import Version @@ -11,17 +13,20 @@ CONFIG_AUTHORITY_KEYS, SKILL_TOOLS, BindingFailureCode, + BoundValue, BoundValueOrigin, Severity, get_logger, ) from autoskillit.recipe._analysis import ValidationContext, bfs_reachable from autoskillit.recipe.contracts import ( + SkillInput, get_skill_contract, load_bundled_manifest, ) from autoskillit.recipe.io import iter_steps_with_context from autoskillit.recipe.registry import RuleFinding, make_finding, semantic_rule +from autoskillit.recipe.schema import Recipe logger = get_logger(__name__) @@ -130,6 +135,84 @@ def _check_invalid_skill_invocation_binding( return findings +def _typed_dynamic_inputs( + ctx: ValidationContext, step_name: str +) -> Iterator[tuple[BoundValue, SkillInput]]: + if ctx.recipe.steps[step_name].tool not in SKILL_TOOLS: + return + invocation = ctx.binding_projection.for_step(step_name) + if invocation is None or invocation.skill_name is None: + return + contract = get_skill_contract(invocation.skill_name, load_bundled_manifest()) + if contract is None: + return + for input_def in contract.inputs: + bound = invocation.skill_input(input_def.name) + if ( + bound is not None + and bound.is_present + and bound.is_dynamic + and input_def.type in {"integer", "boolean", "bool"} + ): + yield bound, input_def + + +def _has_declared_integer_source(recipe: Recipe, bound: BoundValue, input_def: SkillInput) -> bool: + if input_def.type != "integer": + return False + if bound.origin is BoundValueOrigin.RECIPE_INPUT: + ingredient = recipe.ingredients.get(bound.input_dependencies[0]) + return ingredient is not None and ingredient.type == "integer" + if bound.origin is BoundValueOrigin.CONTEXT: + variable = bound.context_dependencies[0] + producers = [ + step + for step in recipe.steps.values() + if variable in step.capture or variable in step.capture_list + ] + return bool(producers) and all( + variable in step.capture and step.capture[variable].value_type == "integer" + for step in producers + ) + return False + + +@semantic_rule( + name="typed-skill-input-undeclared-source", + description="Dynamic integer skill inputs need declared sources; booleans need literals.", + severity=Severity.WARNING, +) +def _check_typed_skill_input_sources(ctx: ValidationContext) -> list[RuleFinding]: + findings: list[RuleFinding] = [] + for step_name in sorted(ctx.recipe.steps): + for bound, input_def in _typed_dynamic_inputs(ctx, step_name): + if _has_declared_integer_source(ctx.recipe, bound, input_def): + continue + if input_def.type == "integer": + reason = "has no supported declared integer source" + remedy = ( + "Bind an exact ${{ context.X }} whose producers declare " + "scalar capture type: integer (capture_list does not qualify), " + "or an exact ${{ inputs.X }} with ingredient type: integer; " + "interpolated templates do not qualify." + ) + else: + reason = "uses an unsupported dynamic boolean source" + remedy = "Bind a boolean literal; no boolean producer declaration is supported." + findings.append( + make_finding( + rule_name="typed-skill-input-undeclared-source", + step_name=step_name, + message=( + f"Step {step_name!r} input {bound.name!r} from " + f"{bound.declared_value!r} {reason}." + ), + remedy=remedy, + ) + ) + return findings + + @semantic_rule( name="missing-recommended-input", description="Skill steps should provide recommended inputs for full-quality output.", diff --git a/src/autoskillit/recipes/diagrams/implementation-groups.md b/src/autoskillit/recipes/diagrams/implementation-groups.md index a27c592d97..ae5711701b 100644 --- a/src/autoskillit/recipes/diagrams/implementation-groups.md +++ b/src/autoskillit/recipes/diagrams/implementation-groups.md @@ -1,4 +1,4 @@ - + ## implementation-groups diff --git a/src/autoskillit/recipes/diagrams/implementation.md b/src/autoskillit/recipes/diagrams/implementation.md index d9702f0ea7..81e1ef70f2 100644 --- a/src/autoskillit/recipes/diagrams/implementation.md +++ b/src/autoskillit/recipes/diagrams/implementation.md @@ -1,4 +1,4 @@ - + ## implementation diff --git a/src/autoskillit/recipes/diagrams/merge-prs.md b/src/autoskillit/recipes/diagrams/merge-prs.md index ad26f866bb..7c7f32948c 100644 --- a/src/autoskillit/recipes/diagrams/merge-prs.md +++ b/src/autoskillit/recipes/diagrams/merge-prs.md @@ -1,4 +1,4 @@ - + ## merge-prs Merge multiple PRs into an integration branch with conflict resolution and CI gates. diff --git a/src/autoskillit/recipes/diagrams/remediation.md b/src/autoskillit/recipes/diagrams/remediation.md index 4c75301410..6a141b3c6a 100644 --- a/src/autoskillit/recipes/diagrams/remediation.md +++ b/src/autoskillit/recipes/diagrams/remediation.md @@ -1,4 +1,4 @@ - + ## remediation diff --git a/src/autoskillit/recipes/diagrams/research.md b/src/autoskillit/recipes/diagrams/research.md index 3d3602b97e..9ef3b7c438 100644 --- a/src/autoskillit/recipes/diagrams/research.md +++ b/src/autoskillit/recipes/diagrams/research.md @@ -1,4 +1,4 @@ - + ## research diff --git a/src/autoskillit/recipes/implementation-groups.json b/src/autoskillit/recipes/implementation-groups.json index e4fc4c3e66..1b6ec50933 100644 --- a/src/autoskillit/recipes/implementation-groups.json +++ b/src/autoskillit/recipes/implementation-groups.json @@ -1537,14 +1537,17 @@ "step_name": "extract_pr_number" }, "capture": { - "pr_number": "${{ result.stdout | trim }}" + "pr_number": { + "from": "${{ result.stdout | trim }}", + "type": "integer" + } }, "on_success": "capture_review_repository", "on_failure": "release_issue_failure", "optional": true, "skip_when_false": "inputs.open_pr", "on_skip": "release_issue_success", - "note": "Extracts the integer PR number from compose-pr's verified pr_url. pr_number is required by the queue finale steps (enqueue_to_queue, wait_for_queue).\n" + "note": "Captures the PR number as canonical ASCII decimal text, declared `type: integer`. Integer skill inputs decode it server-side; MCP and run_python consumers convert it at their own typed boundaries. Required by review_pr, resolve_review, enqueue_to_queue and wait_for_queue.\n" }, "capture_review_repository": { "tool": "run_cmd", diff --git a/src/autoskillit/recipes/implementation-groups.yaml b/src/autoskillit/recipes/implementation-groups.yaml index d6ca459019..7f40203fbc 100644 --- a/src/autoskillit/recipes/implementation-groups.yaml +++ b/src/autoskillit/recipes/implementation-groups.yaml @@ -1272,16 +1272,19 @@ steps: cwd: ${{ context.work_dir }} step_name: extract_pr_number capture: - pr_number: "${{ result.stdout | trim }}" + pr_number: + from: ${{ result.stdout | trim }} + type: integer on_success: capture_review_repository on_failure: release_issue_failure optional: true skip_when_false: inputs.open_pr on_skip: release_issue_success note: > - Extracts the integer PR number from compose-pr's verified pr_url. - pr_number is required by the queue finale steps (enqueue_to_queue, wait_for_queue). - + Captures the PR number as canonical ASCII decimal text, declared `type: integer`. + Integer skill inputs decode it server-side; MCP and run_python consumers + convert it at their own typed boundaries. + Required by review_pr, resolve_review, enqueue_to_queue and wait_for_queue. capture_review_repository: tool: run_cmd with: diff --git a/src/autoskillit/recipes/implementation.json b/src/autoskillit/recipes/implementation.json index f70aaf7dce..1260ce6eef 100644 --- a/src/autoskillit/recipes/implementation.json +++ b/src/autoskillit/recipes/implementation.json @@ -1825,14 +1825,17 @@ "step_name": "extract_pr_number" }, "capture": { - "pr_number": "${{ result.stdout | trim }}" + "pr_number": { + "from": "${{ result.stdout | trim }}", + "type": "integer" + } }, "on_success": "capture_review_repository", "on_failure": "release_issue_failure", "optional": true, "skip_when_false": "inputs.open_pr", "on_skip": "release_issue_success", - "note": "Extracts the PR number as a string for downstream steps. pr_number is required by the queue finale steps (enable_auto_merge, wait_for_queue).\n" + "note": "Captures the PR number as canonical ASCII decimal text, declared `type: integer`. Integer skill inputs decode it server-side; MCP and run_python consumers convert it at their own typed boundaries. Required by review_pr, resolve_review, enqueue_to_queue and wait_for_queue.\n" }, "capture_review_repository": { "tool": "run_cmd", diff --git a/src/autoskillit/recipes/implementation.yaml b/src/autoskillit/recipes/implementation.yaml index bf7e05f5eb..aa06d6d792 100644 --- a/src/autoskillit/recipes/implementation.yaml +++ b/src/autoskillit/recipes/implementation.yaml @@ -1477,16 +1477,19 @@ steps: cwd: ${{ context.work_dir }} step_name: extract_pr_number capture: - pr_number: ${{ result.stdout | trim }} + pr_number: + from: ${{ result.stdout | trim }} + type: integer on_success: capture_review_repository on_failure: release_issue_failure optional: true skip_when_false: inputs.open_pr on_skip: release_issue_success - note: 'Extracts the PR number as a string for downstream steps. pr_number is required - by the queue finale steps (enable_auto_merge, wait_for_queue). - - ' + note: > + Captures the PR number as canonical ASCII decimal text, declared `type: integer`. + Integer skill inputs decode it server-side; MCP and run_python consumers + convert it at their own typed boundaries. + Required by review_pr, resolve_review, enqueue_to_queue and wait_for_queue. capture_review_repository: tool: run_cmd with: diff --git a/src/autoskillit/recipes/merge-prs.json b/src/autoskillit/recipes/merge-prs.json index 08de98b8b8..20752178b6 100644 --- a/src/autoskillit/recipes/merge-prs.json +++ b/src/autoskillit/recipes/merge-prs.json @@ -1881,11 +1881,14 @@ "poll_interval": "15" }, "capture": { - "review_pr_number": "${{ result.pr_number }}" + "review_pr_number": { + "from": "${{ result.pr_number }}", + "type": "integer" + } }, "on_success": "capture_review_repository", "on_failure": "register_clone_failure", - "note": "Extracts the review PR number from context.pr_url and polls GitHub until the mergeable field is no longer UNKNOWN (GitHub computes this asynchronously after PR creation). Polls up to 12 times with 15-second intervals (3 minutes maximum). Captures review_pr_number for use by check_mergeability and check_mergeability_post_rebase.\n" + "note": "Extracts the review PR number from context.pr_url and polls GitHub until the mergeable field is no longer UNKNOWN. Polls up to 12 times with 15-second intervals (3 minutes maximum). Captures the PR number as canonical ASCII decimal text, declared `type: integer`. Integer skill inputs decode it server-side; MCP and run_python consumers convert it at their own typed boundaries. Required by check_mergeability, review_pr_integration and resolve_review_integration.\n" }, "capture_review_repository": { "tool": "run_cmd", diff --git a/src/autoskillit/recipes/merge-prs.yaml b/src/autoskillit/recipes/merge-prs.yaml index 5bdddb152f..bdc44ad3fc 100644 --- a/src/autoskillit/recipes/merge-prs.yaml +++ b/src/autoskillit/recipes/merge-prs.yaml @@ -1616,14 +1616,19 @@ steps: max_polls: '12' poll_interval: '15' capture: - review_pr_number: ${{ result.pr_number }} + review_pr_number: + from: ${{ result.pr_number }} + type: integer on_success: capture_review_repository on_failure: register_clone_failure - note: 'Extracts the review PR number from context.pr_url and polls GitHub until the mergeable field is no longer UNKNOWN - (GitHub computes this asynchronously after PR creation). Polls up to 12 times with 15-second intervals (3 minutes maximum). - Captures review_pr_number for use by check_mergeability and check_mergeability_post_rebase. - - ' + note: > + Extracts the review PR number from context.pr_url and polls GitHub until the + mergeable field is no longer UNKNOWN. Polls up to 12 times with 15-second + intervals (3 minutes maximum). + Captures the PR number as canonical ASCII decimal text, declared `type: integer`. + Integer skill inputs decode it server-side; MCP and run_python consumers + convert it at their own typed boundaries. + Required by check_mergeability, review_pr_integration and resolve_review_integration. capture_review_repository: tool: run_cmd with: diff --git a/src/autoskillit/recipes/remediation.json b/src/autoskillit/recipes/remediation.json index e35a3617ac..6c6ef8cd58 100644 --- a/src/autoskillit/recipes/remediation.json +++ b/src/autoskillit/recipes/remediation.json @@ -2362,14 +2362,17 @@ "step_name": "extract_pr_number" }, "capture": { - "pr_number": "${{ result.stdout | trim }}" + "pr_number": { + "from": "${{ result.stdout | trim }}", + "type": "integer" + } }, "on_success": "capture_review_repository", "on_failure": "release_issue_failure", "optional": true, "skip_when_false": "inputs.open_pr", "on_skip": "release_issue_success", - "note": "Extract the PR number; queue steps require it." + "note": "Captures the PR number as canonical ASCII decimal text, declared `type: integer`. Integer skill inputs decode it server-side; MCP and run_python consumers convert it at their own typed boundaries. Required by review_pr, resolve_review, enqueue_to_queue and wait_for_queue.\n" }, "capture_review_repository": { "tool": "run_cmd", diff --git a/src/autoskillit/recipes/remediation.yaml b/src/autoskillit/recipes/remediation.yaml index a3994759df..36b387505c 100644 --- a/src/autoskillit/recipes/remediation.yaml +++ b/src/autoskillit/recipes/remediation.yaml @@ -1782,13 +1782,19 @@ steps: cwd: ${{ context.work_dir }} step_name: extract_pr_number capture: - pr_number: ${{ result.stdout | trim }} + pr_number: + from: ${{ result.stdout | trim }} + type: integer on_success: capture_review_repository on_failure: release_issue_failure optional: true skip_when_false: inputs.open_pr on_skip: release_issue_success - note: 'Extract the PR number; queue steps require it.' + note: > + Captures the PR number as canonical ASCII decimal text, declared `type: integer`. + Integer skill inputs decode it server-side; MCP and run_python consumers + convert it at their own typed boundaries. + Required by review_pr, resolve_review, enqueue_to_queue and wait_for_queue. capture_review_repository: tool: run_cmd with: diff --git a/src/autoskillit/recipes/research-review.json b/src/autoskillit/recipes/research-review.json index ffa2efa959..71c12f425e 100644 --- a/src/autoskillit/recipes/research-review.json +++ b/src/autoskillit/recipes/research-review.json @@ -196,11 +196,14 @@ "step_name": "extract_pr_number" }, "capture": { - "pr_number": "${{ result.stdout | trim }}" + "pr_number": { + "from": "${{ result.stdout | trim }}", + "type": "integer" + } }, "on_success": "capture_review_repository", "on_failure": "escalate_stop", - "note": "Extracts the PR number from the PR URL for use by annotate_pr_diff. Review publication is fail-closed when the authoritative PR identity cannot be captured.\n" + "note": "Captures the PR number as canonical ASCII decimal text, declared `type: integer`. Integer skill inputs decode it server-side; MCP and run_python consumers convert it at their own typed boundaries. Required by annotate_pr_diff, review_research_pr and audit_claims.\n" }, "capture_review_repository": { "tool": "run_cmd", diff --git a/src/autoskillit/recipes/research-review.yaml b/src/autoskillit/recipes/research-review.yaml index 9ceaa9c749..0ff85031b1 100644 --- a/src/autoskillit/recipes/research-review.yaml +++ b/src/autoskillit/recipes/research-review.yaml @@ -185,14 +185,16 @@ steps: cwd: ${{ inputs.worktree_path }} step_name: extract_pr_number capture: - pr_number: ${{ result.stdout | trim }} + pr_number: + from: ${{ result.stdout | trim }} + type: integer on_success: capture_review_repository on_failure: escalate_stop note: > - Extracts the PR number from the PR URL for use by annotate_pr_diff. - Review publication is fail-closed when the authoritative PR identity - cannot be captured. - + Captures the PR number as canonical ASCII decimal text, declared `type: integer`. + Integer skill inputs decode it server-side; MCP and run_python consumers + convert it at their own typed boundaries. + Required by annotate_pr_diff, review_research_pr and audit_claims. capture_review_repository: tool: run_cmd with: diff --git a/src/autoskillit/recipes/research.json b/src/autoskillit/recipes/research.json index 22c0d5f70c..24dd7bd927 100644 --- a/src/autoskillit/recipes/research.json +++ b/src/autoskillit/recipes/research.json @@ -1452,10 +1452,14 @@ "step_name": "extract_pr_number" }, "capture": { - "pr_number": "${{ result.stdout | trim }}" + "pr_number": { + "from": "${{ result.stdout | trim }}", + "type": "integer" + } }, "on_success": "capture_review_repository", - "on_failure": "escalate_stop" + "on_failure": "escalate_stop", + "note": "Captures the PR number as canonical ASCII decimal text, declared `type: integer`. Integer skill inputs decode it server-side; MCP and run_python consumers convert it at their own typed boundaries. Required by annotate_pr_diff, review_research_pr and audit_claims.\n" }, "capture_review_repository": { "tool": "run_cmd", diff --git a/src/autoskillit/recipes/research.yaml b/src/autoskillit/recipes/research.yaml index af097f32da..c47a133599 100644 --- a/src/autoskillit/recipes/research.yaml +++ b/src/autoskillit/recipes/research.yaml @@ -1229,9 +1229,16 @@ steps: cwd: "${{ context.worktree_path }}" step_name: extract_pr_number capture: - pr_number: "${{ result.stdout | trim }}" + pr_number: + from: ${{ result.stdout | trim }} + type: integer on_success: capture_review_repository on_failure: escalate_stop + note: > + Captures the PR number as canonical ASCII decimal text, declared `type: integer`. + Integer skill inputs decode it server-side; MCP and run_python consumers + convert it at their own typed boundaries. + Required by annotate_pr_diff, review_research_pr and audit_claims. capture_review_repository: tool: run_cmd diff --git a/tests/core/test_capture.py b/tests/core/test_capture.py index b08ae0a691..f690fda43d 100644 --- a/tests/core/test_capture.py +++ b/tests/core/test_capture.py @@ -59,6 +59,12 @@ def test_value_type_is_required() -> None: CaptureEntrySpec(from_="${{ result.x }}") +def test_capture_entry_spec_accepts_integer_value_type() -> None: + entry = CaptureEntrySpec(from_="${{ result.stdout | trim }}", value_type="integer") + + assert entry.value_type == "integer" + + def test_valid_value_types_match_the_literal() -> None: assert CAPTURE_VALID_VALUE_TYPES == frozenset(get_args(CaptureValueType)) @@ -69,4 +75,4 @@ def test_is_capture_value_type_accepts_declared_types(value: str) -> None: def test_is_capture_value_type_rejects_unknown_type() -> None: - assert not is_capture_value_type("integer") + assert is_capture_value_type("unknown") is False diff --git a/tests/fleet/test_campaign_capture.py b/tests/fleet/test_campaign_capture.py index ca2bcc27ff..1d7d2a9901 100644 --- a/tests/fleet/test_campaign_capture.py +++ b/tests/fleet/test_campaign_capture.py @@ -715,6 +715,28 @@ def test_hyphenated_field_name_round_trip(self) -> None: # --------------------------------------------------------------------------- +@pytest.mark.parametrize("value", ["31", 31]) +def test_extract_integer_capture_accepts_canonical_text_and_native_integer(value): + from autoskillit.fleet._capture import _extract_captures + + capture_spec = {"n": CaptureEntrySpec(from_="${{ result.n }}", value_type="integer")} + + assert _extract_captures(capture_spec, {"n": value}) == {"n": "31"} + + +@pytest.mark.parametrize("value", ["031", True]) +def test_extract_integer_capture_rejects_noncanonical_values(value): + from autoskillit.core import CaptureValueTypeError + from autoskillit.fleet._capture import _extract_captures + + capture_spec = {"n": CaptureEntrySpec(from_="${{ result.n }}", value_type="integer")} + + with pytest.raises(CaptureValueTypeError) as exc_info: + _extract_captures(capture_spec, {"n": value}) + assert exc_info.value.declared_type == "integer" + assert exc_info.value.key == "n" + + def test_extract_path_type_rejects_empty_string(): """A path-type capture with an empty-string value must raise CaptureValueTypeError.""" from autoskillit.core import CaptureValueTypeError diff --git a/tests/infra/test_pretty_output_recipe.py b/tests/infra/test_pretty_output_recipe.py index c1850867c4..871d17f306 100644 --- a/tests/infra/test_pretty_output_recipe.py +++ b/tests/infra/test_pretty_output_recipe.py @@ -1375,9 +1375,9 @@ def test_pretty_output_recipe_grid_preserves_semantics_and_budgets(tmp_path, mon f"ingredients_only=both; actual={measured_modes!r}; limit=all registry modes" ) assert maxima == { - "get_recipe_section": (187_151, "remediation", "all_truthy"), - "load_recipe": (187_151, "remediation", "all_truthy"), - "open_kitchen": (187_205, "remediation", "all_truthy"), + "get_recipe_section": (187_443, "remediation", "all_truthy"), + "load_recipe": (187_443, "remediation", "all_truthy"), + "open_kitchen": (187_497, "remediation", "all_truthy"), }, ( "property=canonical baseline maxima; recipe=all; mode=all; tool=all; " f"ingredients_only=both; actual={maxima!r}; limit=measured current baseline" diff --git a/tests/recipe/test_bundled_recipes_review_pr.py b/tests/recipe/test_bundled_recipes_review_pr.py index 079eb1b4d4..33b7d15f15 100644 --- a/tests/recipe/test_bundled_recipes_review_pr.py +++ b/tests/recipe/test_bundled_recipes_review_pr.py @@ -215,6 +215,18 @@ def test_implementation_groups_has_ci_watch() -> None: assert "re_push" in recipe.steps +@pytest.mark.parametrize( + "recipe_name", + ["implementation", "implementation-groups", "remediation", "research", "research-review"], +) +def test_extract_pr_number_declares_integer(recipe_name: str) -> None: + recipe = load_recipe(builtin_recipes_dir() / f"{recipe_name}.yaml") + + capture = recipe.steps["extract_pr_number"].capture["pr_number"] + assert capture.value_type == "integer" + assert capture.from_ == "${{ result.stdout | trim }}" + + def test_merge_prs_review_pr_integration_includes_diff_metrics_path() -> None: recipe = load_recipe(builtin_recipes_dir() / "merge-prs.yaml") step = recipe.steps["review_pr_integration"] diff --git a/tests/recipe/test_bundled_typed_skill_handoffs.py b/tests/recipe/test_bundled_typed_skill_handoffs.py new file mode 100644 index 0000000000..97e3d79a37 --- /dev/null +++ b/tests/recipe/test_bundled_typed_skill_handoffs.py @@ -0,0 +1,266 @@ +"""Runtime binding tests for producer text passed to typed skill inputs.""" + +from __future__ import annotations + +from pathlib import Path +from typing import Any, NamedTuple + +import pytest + +from autoskillit.core import ( + BoundValueOrigin, + BoundValueState, + InvocationTemplate, + RecipeSource, + compute_invocation_template_digest, + compute_tool_contract_identity, + get_tool_def, +) +from autoskillit.recipe import ( + RuntimeBindingError, + bind_recipe, + bind_runtime_skill_invocation, + compute_skill_contract_identity, + get_skill_contract, + load_bundled_manifest, +) +from autoskillit.recipe.io import load_recipe +from tests._tracked_recipes import tracked_recipe_paths + +pytestmark = [pytest.mark.layer("recipe"), pytest.mark.medium] + +_ROOT = Path(__file__).resolve().parents[2] +_RECIPES_DIR = _ROOT / "src" / "autoskillit" / "recipes" +_BUNDLED_MANIFEST = load_bundled_manifest() + + +class _HandoffCase(NamedTuple): + recipe: Any + step_key: str + execution_id: str + template: InvocationTemplate + input_name: str + + +def _mcp_value(invocation: Any, name: str) -> Any: + matches = [value for value in invocation.mcp_kwargs if value.name == name] + assert len(matches) == 1, f"expected one compiled MCP kwarg named {name!r}" + value = matches[0] + assert value.state is BoundValueState.PRESENT + return value.effective_value + + +def _build_template( + recipe: Any, step_key: str, invocation: Any, manifest: dict[str, Any] +) -> tuple[str, InvocationTemplate]: + execution_id = f"typed-handoff-{recipe.name}-{step_key}" + tool_def = get_tool_def(invocation.tool_name) + assert tool_def is not None + tool_identity = compute_tool_contract_identity(tool_def) + assert invocation.skill_name is not None + skill_identity = compute_skill_contract_identity(invocation.skill_name, manifest=manifest) + template_digest = compute_invocation_template_digest( + execution_id=execution_id, + recipe_name=recipe.name, + content_hash=recipe.content_hash, + composite_hash=recipe.content_hash, + invocation=invocation, + tool_contract_identity=tool_identity, + skill_contract_identity=skill_identity, + ) + return execution_id, InvocationTemplate( + invocation=invocation, + tool_contract_identity=tool_identity, + skill_contract_identity=skill_identity, + template_digest=template_digest, + ) + + +def _present_dynamic_context_integer_inputs( + invocation: Any, manifest: dict[str, Any] +) -> list[Any]: + assert invocation.skill_name is not None + contract = get_skill_contract(invocation.skill_name, manifest) + assert contract is not None + input_defs = {input_def.name: input_def for input_def in contract.inputs} + return [ + value + for value in invocation.skill_inputs + if value.state is BoundValueState.PRESENT + and value.origin is BoundValueOrigin.CONTEXT + and value.is_dynamic + and input_defs[value.name].type == "integer" + ] + + +def _handoff_cases_for_recipe(recipe: Any, manifest: dict[str, Any]) -> list[_HandoffCase]: + projection = bind_recipe(recipe, manifest=manifest) + cases = [] + for step_key, invocation in projection.invocations.items(): + if invocation.tool_name != "run_skill" or not invocation.attested: + continue + integer_inputs = _present_dynamic_context_integer_inputs(invocation, manifest) + if not integer_inputs: + continue + execution_id, template = _build_template(recipe, step_key, invocation, manifest) + cases.extend( + _HandoffCase(recipe, step_key, execution_id, template, value.name) + for value in integer_inputs + ) + return cases + + +def _integer_handoff_cases() -> list[_HandoffCase]: + cases = [] + for path in tracked_recipe_paths(_ROOT, source=RecipeSource.BUILTIN): + cases.extend(_handoff_cases_for_recipe(load_recipe(path), _BUNDLED_MANIFEST)) + return cases + + +_HANDOFF_CASES = _integer_handoff_cases() + + +def _native_sample(input_def: Any) -> str | int | bool: + for sample in ("fixture", 1, False): + if input_def.accepts(sample): + return sample + raise AssertionError(f"no native sample for skill input {input_def.name!r}") + + +def _runtime_skill_inputs( + case: _HandoffCase, overrides: dict[str, str | int | bool] +) -> dict[str, Any]: + invocation = case.template.invocation + assert invocation.skill_name is not None + contract = get_skill_contract(invocation.skill_name, _BUNDLED_MANIFEST) + assert contract is not None + input_defs = {input_def.name: input_def for input_def in contract.inputs} + skill_inputs = {} + for value in invocation.skill_inputs: + if value.state is not BoundValueState.PRESENT: + continue + if value.name in overrides: + actual = overrides[value.name] + elif value.is_dynamic: + actual = ( + value.absence_value + if value.absence_value is not None + else _native_sample(input_defs[value.name]) + ) + else: + actual = value.effective_value + skill_inputs[value.name] = actual + return skill_inputs + + +def _actual_mcp_kwargs(case: _HandoffCase) -> dict[str, Any]: + invocation = case.template.invocation + actual_mcp_kwargs = {} + for value in invocation.mcp_kwargs: + if value.state is not BoundValueState.PRESENT: + continue + actual_mcp_kwargs[value.name] = "fixture" if value.is_dynamic else value.effective_value + step_name = _mcp_value(invocation, "step_name") + assert isinstance(step_name, str) + actual_mcp_kwargs["step_name"] = step_name + actual_mcp_kwargs["recipe_execution_id"] = case.execution_id + actual_mcp_kwargs["invocation_template_digest"] = case.template.template_digest + return actual_mcp_kwargs + + +def _bind(case: _HandoffCase, skill_inputs: dict[str, Any]) -> tuple[tuple[str, Any], ...]: + invocation = case.template.invocation + skill_command = _mcp_value(invocation, "skill_command") + step_name = _mcp_value(invocation, "step_name") + assert isinstance(skill_command, str) + assert isinstance(step_name, str) + return bind_runtime_skill_invocation( + case.template, + execution_id=case.execution_id, + step_name=step_name, + skill_command=skill_command, + skill_inputs=skill_inputs, + actual_mcp_kwargs=_actual_mcp_kwargs(case), + ) + + +def _producer_expression(recipe: Any, variable: str) -> tuple[str, list[str]]: + expressions = [] + for step in recipe.steps.values(): + for captures in (step.capture, step.capture_list): + if variable in captures: + expressions.append(captures[variable].from_) + assert len(expressions) == 1, ( + f"{recipe.name}: expected one capture/capture_list producer for {variable!r}, " + f"found {len(expressions)}" + ) + expression = expressions[0] + assert isinstance(expression, str) + filters = [part.strip() for part in expression.removesuffix("}}").split("|")[1:]] + assert all(filter_name == "trim" for filter_name in filters), ( + f"{recipe.name}: unsupported producer filter in {expression!r}" + ) + return expression, filters + + +def _producer_text(recipe: Any, variable: str) -> str: + expression, filters = _producer_expression(recipe, variable) + emitted = "31\n" if "result.stdout" in expression else "31" + if "trim" in filters: + emitted = emitted.strip() + return emitted + + +@pytest.mark.parametrize( + "case", + _HANDOFF_CASES, + ids=lambda case: f"{case.recipe.name}:{case.step_key}:{case.input_name}", +) +def test_integer_handoffs_bind_producer_text(case: _HandoffCase) -> None: + bound_input = case.template.invocation.skill_input(case.input_name) + assert bound_input is not None + producer_text = _producer_text(case.recipe, bound_input.context_dependencies[0]) + bound = _bind(case, _runtime_skill_inputs(case, {case.input_name: producer_text})) + native = _bind(case, _runtime_skill_inputs(case, {case.input_name: 31})) + + assert dict(bound)[case.input_name] == 31 + assert dict(bound) == dict(native) + malformed = _runtime_skill_inputs(case, {case.input_name: "031"}) + with pytest.raises(RuntimeBindingError) as exc_info: + _bind(case, malformed) + assert exc_info.value.code == "recipe_execution_input_type" + + +def test_issue_named_integer_handoffs_are_covered() -> None: + actual_pairs = {(case.recipe.name, case.step_key) for case in _HANDOFF_CASES} + expected_pairs = { + ("implementation", "review_pr"), + ("implementation", "resolve_review"), + ("implementation-groups", "review_pr"), + ("implementation-groups", "resolve_review"), + ("remediation", "review_pr"), + ("remediation", "resolve_review"), + } + assert expected_pairs <= actual_pairs + for recipe_name in ("research", "research-review", "merge-prs"): + assert any(name == recipe_name for name, _step in actual_pairs), recipe_name + + +def test_reverse_direction_text_inputs_render_canonically() -> None: + manifest = _BUNDLED_MANIFEST + recipe = load_recipe(_RECIPES_DIR / "implementation.yaml") + invocation = bind_recipe(recipe, manifest=manifest).for_step("prepare_pr") + execution_id, template = _build_template(recipe, "prepare_pr", invocation, manifest) + case = _HandoffCase(recipe, "prepare_pr", execution_id, template, "closing_issue") + values = {value.name: value for value in invocation.skill_inputs} + assert values["closing_issue"].absence_value == "" + assert values["arch_lenses"].origin is BoundValueOrigin.RECIPE_INPUT + + closing_issue = _bind(case, _runtime_skill_inputs(case, {"closing_issue": 1})) + assert dict(closing_issue)["closing_issue"] == "1" + for value, expected in ((False, "false"), (0, "0"), ("", "")): + closing_issue = _bind(case, _runtime_skill_inputs(case, {"closing_issue": value})) + assert dict(closing_issue)["closing_issue"] == expected + + arch_lenses = _bind(case, _runtime_skill_inputs(case, {"arch_lenses": False})) + assert dict(arch_lenses)["arch_lenses"] == "false" diff --git a/tests/recipe/test_contracts_types.py b/tests/recipe/test_contracts_types.py index 63891d5773..e495a55575 100644 --- a/tests/recipe/test_contracts_types.py +++ b/tests/recipe/test_contracts_types.py @@ -8,11 +8,239 @@ import pytest +from autoskillit.core import BoundValue, BoundValueOrigin, BoundValueState from autoskillit.recipe._contracts_types import SkillContract, SkillInput, SkillOutput pytestmark = [pytest.mark.layer("recipe"), pytest.mark.small] +def _bound_value( + name: str, + origin: BoundValueOrigin, + *, + dependency: str | None = None, + declared_value: object = None, + absence_value: str | int | bool | None = None, +) -> BoundValue: + if origin is BoundValueOrigin.CONTEXT: + assert dependency is not None + declared_value = "${{ context." + dependency + " }}" + context_dependencies = (dependency,) + input_dependencies = () + template_dependencies = () + elif origin is BoundValueOrigin.RECIPE_INPUT: + assert dependency is not None + declared_value = "${{ inputs." + dependency + " }}" + context_dependencies = () + input_dependencies = (dependency,) + template_dependencies = () + elif origin is BoundValueOrigin.TEMPLATE: + assert dependency is not None + if declared_value is None: + declared_value = "n-${{ context." + dependency + " }}" + context_dependencies = (dependency,) + input_dependencies = () + template_dependencies = () + else: + context_dependencies = () + input_dependencies = () + template_dependencies = () + + return BoundValue( + name=name, + declared_value=declared_value, + effective_value=declared_value, + state=BoundValueState.PRESENT, + origin=origin, + context_dependencies=context_dependencies, + input_dependencies=input_dependencies, + template_dependencies=template_dependencies, + absence_value=absence_value, + ) + + +_WIRE_CASES = [ + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, 31, 31), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, "31", 31), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, "0", 0), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, "-5", -5), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, "9" * 19, int("9" * 19)), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, "031", None), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, "+31", None), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, " 31", None), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, "31 ", None), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, "31\n", None), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, "3_1", None), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, "31.0", None), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, "", None), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, "-0", None), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, "٣١", None), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, '"31"', None), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, "9" * 20, None), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, True, None), + ("integer", BoundValueOrigin.CONTEXT, "n", None, None, False, None), + ("integer", BoundValueOrigin.LITERAL, None, 31, None, 31, 31), + ("integer", BoundValueOrigin.LITERAL, None, 31, None, "31", None), + ("integer", BoundValueOrigin.TEMPLATE, "n", "n-${{ context.n }}", None, 31, 31), + ("integer", BoundValueOrigin.TEMPLATE, "n", "n-${{ context.n }}", None, "31", None), + ("boolean", BoundValueOrigin.CONTEXT, "enabled", None, None, True, True), + ("boolean", BoundValueOrigin.CONTEXT, "enabled", None, None, False, False), + ("boolean", BoundValueOrigin.CONTEXT, "enabled", None, None, "true", None), + ("boolean", BoundValueOrigin.CONTEXT, "enabled", None, None, "false", None), + ("boolean", BoundValueOrigin.CONTEXT, "enabled", None, None, 1, None), + ("boolean", BoundValueOrigin.CONTEXT, "enabled", None, None, 0, None), + ("string", BoundValueOrigin.CONTEXT, "label", None, None, "x", "x"), + ("string", BoundValueOrigin.CONTEXT, "label", None, None, "", ""), + ("string", BoundValueOrigin.CONTEXT, "label", None, None, 7, "7"), + ("string", BoundValueOrigin.CONTEXT, "label", None, None, -3, "-3"), + ("string", BoundValueOrigin.CONTEXT, "label", None, None, True, "true"), + ("string", BoundValueOrigin.CONTEXT, "label", None, None, False, "false"), + ("string", BoundValueOrigin.CONTEXT, "label", None, None, 0, "0"), + ("string", BoundValueOrigin.RECIPE_INPUT, "label", None, None, False, "false"), + ("string", BoundValueOrigin.CONTEXT, "label", None, "", 1, "1"), + ("string", BoundValueOrigin.CONTEXT, "label", None, "", True, "true"), + ("string", BoundValueOrigin.CONTEXT, "label", None, "", "", ""), + ("string", BoundValueOrigin.CONTEXT, "label", None, "", False, "false"), + ("string", BoundValueOrigin.CONTEXT, "label", None, "", 0, "0"), + ( + "string", + BoundValueOrigin.TEMPLATE, + "n", + "review-pr:${{ context.n }}", + None, + "review-pr:3", + "review-pr:3", + ), + ("string", BoundValueOrigin.TEMPLATE, "n", "review-pr:${{ context.n }}", None, 3, None), + ("string", BoundValueOrigin.TEMPLATE, "n", "review-pr:${{ context.n }}", None, True, None), + ("string", BoundValueOrigin.LITERAL, None, "x", None, "x", "x"), + ("string", BoundValueOrigin.LITERAL, None, "x", None, 7, None), + ("file_path", BoundValueOrigin.CONTEXT, "path", None, None, "/a/b", "/a/b"), + ("file_path", BoundValueOrigin.CONTEXT, "path", None, None, 1, None), + ("file_path", BoundValueOrigin.CONTEXT, "path", None, None, True, None), +] + + +@pytest.mark.parametrize( + ( + "input_type", + "origin", + "dependency", + "declared_value", + "absence_value", + "wire", + "expected", + ), + _WIRE_CASES, +) +def test_skill_input_admits_only_declared_type_wire_values( + input_type: str, + origin: BoundValueOrigin, + dependency: str | None, + declared_value: object, + absence_value: str | None, + wire: object, + expected: object, +) -> None: + skill_input = SkillInput( + name="value", + type=input_type, + required=absence_value is None, + absence_value=absence_value, + ) + bound = _bound_value( + "value", + origin, + dependency=dependency, + declared_value=declared_value, + absence_value=absence_value, + ) + + admitted = skill_input.admit_runtime_wire(wire, bound) + if expected is None: + assert admitted is None + else: + assert admitted == expected + + +@pytest.mark.parametrize( + "wire", + [pytest.param(10**19, id="19-digits"), pytest.param(10**5000, id="5000-digits")], +) +def test_skill_input_string_rejects_oversized_integer_without_raising(wire: int) -> None: + skill_input = SkillInput(name="label", type="string", required=True) + bound = _bound_value("label", BoundValueOrigin.CONTEXT, dependency="label") + + assert skill_input.admit_runtime_wire(wire, bound) is None + + +@pytest.mark.parametrize( + ("wire", "bound_absence_value", "expected"), + [ + (False, None, "false"), + (0, None, "0"), + (False, "", "false"), + (0, "", "0"), + (False, "false", None), + (0, "0", None), + ], +) +def test_skill_input_string_absence_policy_uses_bound_value_advertisement( + wire: object, + bound_absence_value: str | None, + expected: str | None, +) -> None: + skill_input = SkillInput("label", "string", False, absence_value="") + bound = _bound_value( + "label", + BoundValueOrigin.CONTEXT, + dependency="label", + absence_value=bound_absence_value, + ) + + admitted = skill_input.admit_runtime_wire(wire, bound) + if expected is None: + assert admitted is None + else: + assert admitted == expected + + +def test_skill_input_wire_mismatch_messages_explain_expected_wire_shape() -> None: + exact_integer = _bound_value("n", BoundValueOrigin.CONTEXT, dependency="n") + assert SkillInput("n", "integer", True).wire_mismatch_message("31x", exact_integer) == ( + "runtime skill input 'n' expects 'integer'; received str; send a JSON integer or " + "canonical ASCII decimal text (e.g. '31'; at most 19 digits)" + ) + + static_integer = _bound_value("n", BoundValueOrigin.LITERAL, declared_value=31) + assert ( + SkillInput("n", "integer", True) + .wire_mismatch_message("31", static_integer) + .endswith("; send a JSON integer") + ) + + text_bound = _bound_value("label", BoundValueOrigin.CONTEXT, dependency="label") + assert ( + SkillInput("label", "string", True) + .wire_mismatch_message(10**19, text_bound) + .endswith("; send a JSON string") + ) + + optional_text = SkillInput("label", "string", False, absence_value="") + advertised_absence = _bound_value( + "label", + BoundValueOrigin.CONTEXT, + dependency="label", + absence_value="", + ) + assert "absence" not in optional_text.wire_mismatch_message(False, advertised_absence) + + +def test_skill_input_accepts_stays_strict_for_declared_types() -> None: + assert SkillInput("n", "integer", True).accepts("31") is False + assert SkillInput("b", "boolean", True).accepts("false") is False + + def test_skill_input_validates_explicit_absence_value() -> None: optional = SkillInput(name="note", type="string", required=False, absence_value="") assert optional.has_absence_value diff --git a/tests/recipe/test_implementation.py b/tests/recipe/test_implementation.py index 0960868a94..086d99ab2c 100644 --- a/tests/recipe/test_implementation.py +++ b/tests/recipe/test_implementation.py @@ -25,7 +25,7 @@ RECIPE_PATH = builtin_recipes_dir() / "implementation.yaml" _PRE_DELIVERY_STRUCTURE_SHA256 = ( - "sha256:24ad979ece45a53faacb877bb334dd02cddbe727ba74f00632e48a7923aac081" + "sha256:4f235276cd2d6793985ee55a3489c160de93df64437e600d9f5b89c97479bc12" ) _CHECKPOINT_HANDLER_TABLE = { diff --git a/tests/recipe/test_merge_prs.py b/tests/recipe/test_merge_prs.py index c8979f18b0..179d2aa62f 100644 --- a/tests/recipe/test_merge_prs.py +++ b/tests/recipe/test_merge_prs.py @@ -412,6 +412,9 @@ def test_pmp_wait_for_mergeability_captures_review_pr_number(recipe) -> None: """B3: wait_for_review_pr_mergeability must capture review_pr_number.""" step = recipe.steps["wait_for_review_pr_mergeability"] assert "review_pr_number" in step.capture + capture = step.capture["review_pr_number"] + assert capture.value_type == "integer" + assert capture.from_ == "${{ result.pr_number }}" def test_pmp_wait_for_mergeability_routes_through_repository_capture(recipe) -> None: diff --git a/tests/recipe/test_remediation_recipe.py b/tests/recipe/test_remediation_recipe.py index e36e6aa562..905f066d9a 100644 --- a/tests/recipe/test_remediation_recipe.py +++ b/tests/recipe/test_remediation_recipe.py @@ -22,7 +22,7 @@ Path(__file__).parent.parent.parent / "src" / "autoskillit" / "recipes" / "remediation.yaml" ) _PRE_DELIVERY_STRUCTURE_SHA256 = ( - "sha256:4d09d769f7d414fa230e22b6ef576629a4767bd46c5879584735301cd1ab8a0b" + "sha256:0273b0d1575fc7c760c0984f22aa0cc5979a3685ddaabe00326f1d9b4b908001" ) diff --git a/tests/recipe/test_rules_inputs.py b/tests/recipe/test_rules_inputs.py index 42499484c7..90fa062b33 100644 --- a/tests/recipe/test_rules_inputs.py +++ b/tests/recipe/test_rules_inputs.py @@ -7,7 +7,11 @@ import pytest +import autoskillit.recipe._binding as _patch_recipe_binding +import autoskillit.recipe.rules.rules_inputs as _patch_rules_inputs from autoskillit.core import RECIPE_TERMINAL_TARGETS, Severity +from autoskillit.core.types import CaptureEntrySpec, CaptureValueType +from autoskillit.recipe import bind_recipe from autoskillit.recipe.registry import run_semantic_rules from autoskillit.recipe.schema import ( Recipe, @@ -34,6 +38,235 @@ def _make_recipe_with_skill_step(skill_command: str) -> Recipe: ) +_TYPED_INPUT_TEST_MANIFEST = { + "skills": { + "typed-input-fixture": { + "inputs": [ + {"name": "n", "type": "integer"}, + {"name": "flag", "type": "boolean"}, + {"name": "s", "type": "string"}, + ], + "outputs": [], + } + } +} + + +def _patch_typed_input_manifest(monkeypatch: pytest.MonkeyPatch) -> None: + def manifest_loader() -> dict[str, object]: + return _TYPED_INPUT_TEST_MANIFEST + + monkeypatch.setattr(_patch_recipe_binding, "load_bundled_manifest", manifest_loader) + monkeypatch.setattr(_patch_rules_inputs, "load_bundled_manifest", manifest_loader) + + +def _make_typed_input_recipe( + input_name: str, + source: str | int | bool, + *, + capture_types: tuple[CaptureValueType | None, ...] = (), + capture_list_types: tuple[CaptureValueType | None, ...] = (), + ingredient: RecipeIngredient | None = None, + skill_command: str = "/autoskillit:typed-input-fixture", +) -> Recipe: + steps: dict[str, RecipeStep] = {} + capture_expression = "${{ result.stdout | trim }}" + for index, value_type in enumerate(capture_types): + capture = ( + capture_expression + if value_type is None + else CaptureEntrySpec(from_=capture_expression, value_type=value_type) + ) + steps[f"producer_{index}"] = RecipeStep( + tool="run_cmd", + with_args={"command": "true"}, + capture={input_name: capture}, + ) + for index, value_type in enumerate(capture_list_types): + capture = ( + capture_expression + if value_type is None + else CaptureEntrySpec(from_=capture_expression, value_type=value_type) + ) + steps[f"list_producer_{index}"] = RecipeStep( + tool="run_cmd", + with_args={"command": "true"}, + retries=0, + capture_list={input_name: capture}, + ) + steps["consume"] = RecipeStep( + tool="run_skill", + with_args={ + "skill_command": skill_command, + "skill_inputs": {input_name: source}, + }, + ) + ingredients = {} if ingredient is None else {input_name: ingredient} + return Recipe( + name="typed-input-rule-test", + description="Synthetic recipe for typed skill input rule tests", + ingredients=ingredients, + steps=steps, + ) + + +@pytest.mark.parametrize( + ( + "input_name", + "source", + "capture_types", + "capture_list_types", + "ingredient", + "remedy_kind", + ), + [ + pytest.param("n", "${{ context.n }}", (), (), None, "integer", id="no-context-producer"), + pytest.param( + "n", "${{ context.n }}", (None,), (), None, "integer", id="shorthand-capture" + ), + pytest.param( + "n", + "pr-${{ context.n }}", + ("integer",), + (), + None, + "integer", + id="interpolated-context", + ), + pytest.param( + "n", + "${{ inputs.n }}", + (), + (), + RecipeIngredient(description="Untyped integer input"), + "integer", + id="untyped-ingredient", + ), + pytest.param( + "n", "${{ inputs.missing }}", (), (), None, "integer", id="missing-ingredient" + ), + pytest.param( + "n", + "${{ context.n }}", + (), + ("integer",), + None, + "integer", + id="capture-list", + ), + pytest.param("flag", "${{ context.flag }}", (), (), None, "boolean", id="dynamic-boolean"), + pytest.param( + "n", + "${{ context.n }}", + ("integer", None), + (), + None, + "integer", + id="mixed-producers", + ), + ], +) +def test_dynamic_typed_skill_inputs_require_declared_sources( + monkeypatch: pytest.MonkeyPatch, + input_name: str, + source: str | int | bool, + capture_types: tuple[CaptureValueType | None, ...], + capture_list_types: tuple[CaptureValueType | None, ...], + ingredient: RecipeIngredient | None, + remedy_kind: str, +) -> None: + _patch_typed_input_manifest(monkeypatch) + recipe = _make_typed_input_recipe( + input_name, + source, + capture_types=capture_types, + capture_list_types=capture_list_types, + ingredient=ingredient, + ) + + invocation = bind_recipe(recipe).for_step("consume") + assert invocation is not None + bound_input = invocation.skill_input(input_name) + assert bound_input is not None + assert bound_input.is_present + assert bound_input.is_dynamic + + findings = [ + finding + for finding in run_semantic_rules(recipe) + if finding.rule == "typed-skill-input-undeclared-source" + ] + + assert len(findings) == 1 + finding = findings[0] + assert finding.severity == Severity.WARNING + assert finding.step_name == "consume" + assert input_name in finding.message + assert str(source) in finding.message + assert finding.remedy is not None + if remedy_kind == "integer": + assert "integer" in finding.remedy.lower() + assert "capture" in finding.remedy.lower() or "ingredient" in finding.remedy.lower() + if capture_list_types: + assert "scalar capture" in finding.remedy + assert "capture_list does not qualify" in finding.remedy + else: + assert "literal" in finding.remedy.lower() + assert "boolean" in finding.remedy.lower() or "bool" in finding.remedy.lower() + assert "type: boolean" not in finding.remedy.lower() + assert finding.to_dict()["remedy"] == finding.remedy + + +@pytest.mark.parametrize( + ("input_name", "source", "capture_types", "ingredient", "skill_command"), + [ + pytest.param("n", "${{ context.n }}", ("integer",), None, None, id="typed-capture"), + pytest.param( + "n", + "${{ inputs.n }}", + (), + RecipeIngredient(description="Integer input", type="integer"), + None, + id="typed-ingredient", + ), + pytest.param("s", "${{ context.anything }}", (), None, None, id="string-input"), + pytest.param("n", 3, (), None, None, id="literal-integer"), + pytest.param( + "n", + "${{ context.n }}", + (), + None, + "the orchestrator selects the skill", + id="unresolved-skill", + ), + ], +) +def test_dynamic_typed_skill_inputs_allow_declared_or_out_of_scope_sources( + monkeypatch: pytest.MonkeyPatch, + input_name: str, + source: str | int | bool, + capture_types: tuple[CaptureValueType | None, ...], + ingredient: RecipeIngredient | None, + skill_command: str | None, +) -> None: + _patch_typed_input_manifest(monkeypatch) + recipe = _make_typed_input_recipe( + input_name, + source, + capture_types=capture_types, + ingredient=ingredient, + skill_command=skill_command or "/autoskillit:typed-input-fixture", + ) + + findings = [ + finding + for finding in run_semantic_rules(recipe) + if finding.rule == "typed-skill-input-undeclared-source" + ] + + assert findings == [] + + def test_missing_recommended_input_fires_warning_when_not_passed(): """A skill with recommended=True inputs should produce a WARNING when the recipe step's skill_command does not contain `name=` for them.""" diff --git a/tests/recipe/test_rules_registry.py b/tests/recipe/test_rules_registry.py index 6aec5f5a8b..1726d7c97e 100644 --- a/tests/recipe/test_rules_registry.py +++ b/tests/recipe/test_rules_registry.py @@ -5,7 +5,7 @@ import autoskillit.recipe.registry as _patch_recipe_registry from autoskillit.core.types import Severity from autoskillit.recipe.io import builtin_recipes_dir, load_recipe -from autoskillit.recipe.validator import RuleFinding, run_semantic_rules +from autoskillit.recipe.validator import _RULE_REGISTRY, RuleFinding, run_semantic_rules from tests.recipe.conftest import _make_workflow pytestmark = [pytest.mark.layer("recipe"), pytest.mark.small] @@ -106,3 +106,13 @@ def test_bundled_workflows_pass_semantic_rules() -> None: assert undeclared_findings == [], ( f"Recipe '{wf.name}' has undeclared-capture-key findings: " + repr(undeclared_findings) ) + + +def test_bundled_recipes_have_no_typed_skill_input_findings() -> None: + rule_name = "typed-skill-input-undeclared-source" + assert any(rule.name == rule_name for rule in _RULE_REGISTRY) + + for path in sorted(builtin_recipes_dir().glob("*.yaml")): + recipe = load_recipe(path) + findings = [finding for finding in run_semantic_rules(recipe) if finding.rule == rule_name] + assert findings == [], f"Recipe '{recipe.name}' has {rule_name} findings: {findings}" diff --git a/tests/recipe/test_runtime_skill_invocation_binding.py b/tests/recipe/test_runtime_skill_invocation_binding.py index bf64cd6b9b..b2364c3f5b 100644 --- a/tests/recipe/test_runtime_skill_invocation_binding.py +++ b/tests/recipe/test_runtime_skill_invocation_binding.py @@ -11,9 +11,11 @@ from __future__ import annotations from collections.abc import Mapping +from typing import Any, cast import pytest +import autoskillit.recipe._binding as _binding from autoskillit.core import ( BoundScalar, InvocationTemplate, @@ -46,13 +48,34 @@ } } } +_TYPED_MANIFEST: dict[str, Any] = { + "skills": { + "typed-skill": { + "inputs": [ + {"name": "count", "type": "integer", "required": True}, + {"name": "enabled", "type": "boolean", "required": True}, + {"name": "where", "type": "file_path", "required": True}, + { + "name": "label", + "type": "string", + "required": False, + "absence_value": "", + }, + {"name": "tag", "type": "string", "required": True}, + ] + } + } +} _EXECUTION_ID = "exec-1" _STEP_NAME = "verify" +_DEFAULT = object() def _template( *, optional_context_refs: list[str] | None = None, + skill_name: str = "dry-walkthrough", + manifest: dict[str, Any] | None = None, **extra_with_args: object, ) -> InvocationTemplate: """Build a compiled InvocationTemplate the way the production initialization @@ -62,7 +85,7 @@ def _template( name=_STEP_NAME, tool="run_skill", with_args={ - "skill_command": "/autoskillit:dry-walkthrough", + "skill_command": f"/autoskillit:{skill_name}", "cwd": "/repo", "skill_inputs": {"plan_path": "/tmp/plan.md"}, "step_name": _STEP_NAME, @@ -70,13 +93,15 @@ def _template( }, optional_context_refs=optional_context_refs or [], ) - invocation = bind_step_invocation(_STEP_NAME, step, manifest=_MANIFEST) + invocation = bind_step_invocation( + _STEP_NAME, step, manifest=manifest if manifest is not None else _MANIFEST + ) assert invocation.is_valid, invocation.failures assert invocation.skill_name is not None tool_def = get_tool_def("run_skill") assert tool_def is not None tool_identity = compute_tool_contract_identity(tool_def) - skill_identity = compute_skill_contract_identity(invocation.skill_name) + skill_identity = compute_skill_contract_identity(invocation.skill_name, manifest=manifest) digest = compute_invocation_template_digest( execution_id=_EXECUTION_ID, recipe_name="test-recipe", @@ -97,7 +122,7 @@ def _template( def _bind( template: InvocationTemplate, *, - skill_inputs: Mapping[str, BoundScalar] | None = None, + skill_inputs: Mapping[str, BoundScalar] | None | object = _DEFAULT, **overrides: BoundScalar, ): """Bind against ``template``, matching production's shape: the caller @@ -107,18 +132,24 @@ def _bind( are always compiled (every ``_template()`` step declares them); pass extra kwargs to override or to supply values for anything else under test.""" + assert template.invocation.skill_name is not None + skill_command = f"/autoskillit:{template.invocation.skill_name}" actual_mcp_kwargs: dict[str, BoundScalar] = { - "skill_command": "/autoskillit:dry-walkthrough", + "skill_command": skill_command, "cwd": "/repo", "step_name": _STEP_NAME, } actual_mcp_kwargs.update(overrides) + if skill_inputs is _DEFAULT: + runtime_skill_inputs: Mapping[str, BoundScalar] | None = {"plan_path": "/tmp/plan.md"} + else: + runtime_skill_inputs = cast(Mapping[str, BoundScalar] | None, skill_inputs) return bind_runtime_skill_invocation( template, execution_id=_EXECUTION_ID, step_name=_STEP_NAME, - skill_command="/autoskillit:dry-walkthrough", - skill_inputs=skill_inputs or {"plan_path": "/tmp/plan.md"}, + skill_command=skill_command, + skill_inputs=runtime_skill_inputs, actual_mcp_kwargs=actual_mcp_kwargs, ) @@ -133,6 +164,37 @@ def _template_with_absence_value() -> InvocationTemplate: ) +def _typed_template( + monkeypatch: pytest.MonkeyPatch, + *, + static_count: bool = False, +) -> InvocationTemplate: + monkeypatch.setattr(_binding, "load_bundled_manifest", lambda: _TYPED_MANIFEST) + skill_inputs = { + "count": 3 if static_count else "${{ context.count }}", + "enabled": "${{ context.enabled }}", + "where": "${{ context.where }}", + "label": "${{ context.label }}", + "tag": "tag-${{ context.n }}", + } + return _template( + optional_context_refs=["label"], + skill_name="typed-skill", + manifest=_TYPED_MANIFEST, + skill_inputs=skill_inputs, + ) + + +def _typed_skill_inputs() -> dict[str, BoundScalar]: + return { + "count": 3, + "enabled": True, + "where": "/repo", + "label": "", + "tag": "tag-3", + } + + @pytest.mark.parametrize( "skill_inputs", [ @@ -168,6 +230,85 @@ def test_runtime_binding_admits_explicit_advertised_default_without_auto_fill() assert bound == (("plan_path", "/tmp/plan.md"), ("audit_cycle_path", "")) +@pytest.mark.parametrize( + ("input_name", "wire", "expected"), + [ + ("count", "3", 3), + ("count", 3, 3), + ("label", 1, "1"), + ("label", True, "true"), + ("label", False, "false"), + ("label", 0, "0"), + ], +) +def test_runtime_binding_decodes_declared_type_canonical_text( + monkeypatch: pytest.MonkeyPatch, + input_name: str, + wire: BoundScalar, + expected: BoundScalar, +) -> None: + template = _typed_template(monkeypatch) + skill_inputs = _typed_skill_inputs() + skill_inputs[input_name] = wire + + bound = dict(_bind(template, skill_inputs=skill_inputs)) + + assert bound[input_name] == expected + + +@pytest.mark.parametrize( + ("input_name", "input_type", "wire"), + [ + ("count", "integer", "03"), + ("count", "integer", " 3"), + ("count", "integer", "+3"), + ("count", "integer", "3.0"), + ("count", "integer", '"3"'), + ("count", "integer", True), + ("enabled", "boolean", "false"), + ("enabled", "boolean", "true"), + ("enabled", "boolean", 0), + ("where", "file_path", 1), + ("where", "file_path", True), + ("tag", "string", 3), + ("tag", "string", True), + ], +) +def test_runtime_binding_rejects_noncanonical_wire_scalar( + monkeypatch: pytest.MonkeyPatch, + input_name: str, + input_type: str, + wire: BoundScalar, +) -> None: + template = _typed_template(monkeypatch) + skill_inputs = _typed_skill_inputs() + skill_inputs[input_name] = wire + + with pytest.raises(RuntimeBindingError) as excinfo: + _bind(template, skill_inputs=skill_inputs) + + assert excinfo.value.code == "recipe_execution_input_type" + assert f"runtime skill input '{input_name}' expects '{input_type}'" in str(excinfo.value) + assert "; received" in str(excinfo.value) + + +def test_runtime_binding_static_typed_literal_stays_strict( + monkeypatch: pytest.MonkeyPatch, +) -> None: + template = _typed_template(monkeypatch, static_count=True) + skill_inputs = _typed_skill_inputs() + skill_inputs["count"] = "3" + + with pytest.raises(RuntimeBindingError) as excinfo: + _bind(template, skill_inputs=skill_inputs) + assert excinfo.value.code == "recipe_execution_input_type" + + skill_inputs["count"] = 4 + with pytest.raises(RuntimeBindingError) as excinfo: + _bind(template, skill_inputs=skill_inputs) + assert excinfo.value.code == "recipe_execution_static_input_mismatch" + + def test_undeclared_non_empty_value_is_denied() -> None: """(a) characterization — passes today; unaffected by #4402.""" template = _template() diff --git a/tests/server/test_recipe_execution_receipt_completeness.py b/tests/server/test_recipe_execution_receipt_completeness.py index d3bca0d190..87ac652408 100644 --- a/tests/server/test_recipe_execution_receipt_completeness.py +++ b/tests/server/test_recipe_execution_receipt_completeness.py @@ -12,14 +12,17 @@ PACK_REGISTRY, FinalizedRecipeProjection, build_recipe_execution_credential, + compute_runtime_binding_digest, ) from autoskillit.recipe import get_skill_contract, load_bundled_manifest from autoskillit.server.recipe._recipe_execution import ( bind_attested_runtime_invocation, + build_bound_child_prompt, get_recipe_execution, ) from tests.server._recipe_fixture_parameters import ( IMPLEMENTATION_OVERRIDES, + IMPLEMENTATION_READY_PARAMETERS, RESEARCH_OVERRIDES, ) @@ -271,3 +274,87 @@ async def test_wrong_execution_id_rejection_names_the_call( ready.receipt["initialization_id"], "recipe_execution_id_mismatch", ) + + +@pytest.mark.parametrize("tool_ctx_ready_recipe", IMPLEMENTATION_READY_PARAMETERS, indirect=True) +async def test_attested_review_binds_producer_text_pr_number(tool_ctx_ready_recipe) -> None: + ready = tool_ctx_ready_recipe + installed = get_recipe_execution(ready.tool_ctx) + assert installed is not None + + step_name = "review_pr" + template = installed.snapshot.templates[step_name] + invocation = template.invocation + assert invocation.skill_name is not None + contract = get_skill_contract(invocation.skill_name, load_bundled_manifest()) + assert contract is not None + input_defs = {input_def.name: input_def for input_def in contract.inputs} + skill_inputs = {} + for value in invocation.skill_inputs: + if not value.is_present: + continue + if value.name == "pr_number": + assert value.is_dynamic + actual = "31" + else: + actual = value.effective_value + if not input_defs[value.name].accepts(actual): + assert value.is_dynamic + actual = next( + sample + for sample in ("fixture", 1, False) + if input_defs[value.name].accepts(sample) + ) + skill_inputs[value.name] = actual + + credential = ready.credential + actual_mcp_kwargs = { + **{value.name: value.effective_value for value in invocation.mcp_kwargs}, + "step_name": step_name, + "recipe_execution_id": credential["execution_id"], + "invocation_template_digest": credential["invocation_template_digests"][step_name], + } + skill_command = _skill_command(ready.tool_ctx, step_name) + bound_from_text, admitted_template = bind_attested_runtime_invocation( + installed, + execution_id=credential["execution_id"], + step_name=step_name, + template_digest=credential["invocation_template_digests"][step_name], + skill_command=skill_command, + skill_inputs=skill_inputs, + actual_mcp_kwargs=actual_mcp_kwargs, + ) + assert admitted_template is template + assert ("pr_number", 31) in bound_from_text + + native_skill_inputs = {**skill_inputs, "pr_number": 31} + bound_from_native, _ = bind_attested_runtime_invocation( + installed, + execution_id=credential["execution_id"], + step_name=step_name, + template_digest=credential["invocation_template_digests"][step_name], + skill_command=skill_command, + skill_inputs=native_skill_inputs, + actual_mcp_kwargs=actual_mcp_kwargs, + ) + assert compute_runtime_binding_digest( + execution_id=credential["execution_id"], + step_name=step_name, + template_digest=template.template_digest, + bound_inputs=bound_from_text, + actual_mcp_kwargs=actual_mcp_kwargs, + preflight=None, + ) == compute_runtime_binding_digest( + execution_id=credential["execution_id"], + step_name=step_name, + template_digest=template.template_digest, + bound_inputs=bound_from_native, + actual_mcp_kwargs=actual_mcp_kwargs, + preflight=None, + ) + + prompt = build_bound_child_prompt(skill_command, bound_from_text, preflight=None) + marker = "AUTOSKILLIT_BOUND_INVOCATION_V1\n" + assert marker in prompt + payload = json.loads(prompt.split(marker, 1)[1]) + assert {"name": "pr_number", "value": 31} in payload["skill_inputs"]