Skip to content

Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.

Fix/inputs.json (#714)

Thomas Hebrard7de85942c1b3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5fa782fc3..50d3a5759 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,19 @@
# Changelog
+## [Unreleased]
+
+### Added
+
+- **`pipelex run bundle` command** — New CLI subcommand to run a pipeline from a `.mthds` bundle file or pipeline directory. Supports auto-detection of `bundle.mthds`, `inputs.json`, and library directories. Available in both `pipelex` and `pipelex-agent` CLIs.
+- **`mthds run bundle` command** — New command in the mthds-js CLI for running bundles, with support for both pipelex and API runners. Agent passthrough (`mthds-agent pipelex run bundle`) also added.
+- **Inputs path resolution** — Relative file paths (e.g., `"url": "data/invoice.pdf"`) inside `inputs.json` are now resolved relative to the inputs file's parent directory, making bundle directories self-contained and portable. Applies to both user and agent CLIs. Handles HTTP, data:, pipelex-storage://, and absolute paths by leaving them unchanged.
+
+### Changed
+
+- **`pipelex run pipe` simplified to code-only** — The `pipe` subcommand now accepts only a pipe code as its positional argument. File paths and directories are no longer accepted; a helpful error message directs users to `pipelex run bundle` instead. The `--pipe` and `--bundle` options have been removed.
+- **`mthds run pipe` simplified to code-only** — The mthds-js `pipe` subcommand now treats its argument strictly as a pipe code. Bundle detection logic moved to `mthds run bundle`.
+- **`PipelexRunner.execute()` updated** — The mthds-js pipelex runner now uses explicit `run bundle <path>` and `run pipe <code>` subcommands instead of the old `run <target>` form.
+
## [v0.18.1] - 2026-02-25
### Fixed
diff --git a/pipelex/cli/agent_cli/commands/run/app.py b/pipelex/cli/agent_cli/commands/run/app.py
index 219c36536..64b2ecc02 100644
--- a/pipelex/cli/agent_cli/commands/run/app.py
+++ b/pipelex/cli/agent_cli/commands/run/app.py
@@ -4,6 +4,7 @@ from __future__ import annotations
import typer
+from pipelex.cli.agent_cli.commands.run.bundle_cmd import run_bundle_cmd
from pipelex.cli.agent_cli.commands.run.method_cmd import run_method_cmd
from pipelex.cli.agent_cli.commands.run.pipe_cmd import run_pipe_cmd
@@ -13,4 +14,5 @@ run_app = typer.Typer(
)
run_app.command(name="method", help="Execute a pipeline for an installed method")(run_method_cmd)
-run_app.command(name="pipe", help="Execute a pipeline by pipe code or bundle path")(run_pipe_cmd)
+run_app.command(name="pipe", help="Execute a pipeline by pipe code")(run_pipe_cmd)
+run_app.command(name="bundle", help="Execute a pipeline from a bundle file or directory")(run_bundle_cmd)
diff --git a/pipelex/cli/agent_cli/commands/run/bundle_cmd.py b/pipelex/cli/agent_cli/commands/run/bundle_cmd.py
new file mode 100644
index 000000000..e58dd08b1
--- /dev/null
+++ b/pipelex/cli/agent_cli/commands/run/bundle_cmd.py
@@ -0,0 +1,229 @@
+"""Agent CLI run bundle command - execute a pipeline from a bundle file or directory."""
+
+from __future__ import annotations
+
+import asyncio
+from pathlib import Path
+from typing import Annotated, Any
+
+import typer
+from mthds.runners.types import RunnerType
+
+from pipelex.builder.conventions import DEFAULT_BUNDLE_FILE_NAME, DEFAULT_INPUTS_FILE_NAME
+from pipelex.cli.agent_cli.commands.agent_cli_factory import make_pipelex_for_agent_cli
+from pipelex.cli.agent_cli.commands.agent_output import agent_error, agent_success
+from pipelex.cli.agent_cli.commands.run._run_core import run_pipeline_core
+from pipelex.cli.agent_cli.commands.run._run_core_api import run_pipeline_core_api
+from pipelex.cli.agent_cli.commands.run.stdin_resolver import parse_cli_inputs
+from pipelex.core.interpreter.exceptions import MthdsDecodeError, PipelexInterpreterError
+from pipelex.core.interpreter.helpers import MTHDS_EXTENSION, is_pipelex_file
+from pipelex.core.interpreter.interpreter import PipelexInterpreter
+from pipelex.core.pipes.exceptions import PipeOperatorModelChoiceError
+from pipelex.pipe_operators.exceptions import PipeOperatorModelAvailabilityError
+from pipelex.pipelex import Pipelex
+from pipelex.pipeline.exceptions import PipelineExecutionError
+
+
+def run_bundle_cmd(
+ ctx: typer.Context,
+ path: Annotated[
+ str,
+ typer.Argument(help="Path to a .mthds bundle file or a pipeline directory"),
+ ],
+ pipe: Annotated[
+ str | None,
+ typer.Option("--pipe", help="Pipe code to run (overrides bundle's main_pipe)"),
+ ] = None,
+ inputs: Annotated[
+ str | None,
+ typer.Option("--inputs", "-i", help="Path to JSON file with inputs or inline JSON"),
+ ] = None,
+ dry_run: Annotated[
+ bool,
+ typer.Option("--dry-run", help="Run pipeline in dry mode (no actual inference calls)"),
+ ] = False,
+ mock_inputs: Annotated[
+ bool,
+ typer.Option("--mock-inputs", help="Generate mock data for missing required inputs (requires --dry-run)"),
+ ] = False,
+ graph: Annotated[
+ bool,
+ typer.Option("--graph/--no-graph", help="Generate execution graph visualizations (saved alongside output)"),
+ ] = True,
+ library_dir: Annotated[
+ list[str] | None,
+ typer.Option("--library-dir", "-L", help="Directory to search for pipe definitions (.mthds files)"),
+ ] = None,
+ with_memory: Annotated[
+ bool,
+ typer.Option("--with-memory", help="Include full working memory in output (for piping to another method)"),
+ ] = False,
+) -> None:
+ """Execute a pipeline from a bundle file (.mthds) or pipeline directory.
+
+ Outputs JSON to stdout on success, JSON to stderr on error with exit code 1.
+ Graph visualizations are generated by default; use --no-graph to disable.
+
+ Examples:
+ pipelex-agent run bundle pipelex-wip/pipeline_01/
+ pipelex-agent run bundle my_bundle.mthds --pipe my_pipe
+ pipelex-agent run bundle pipeline_01/ --dry-run --mock-inputs
+ pipelex-agent run bundle pipeline_01/ --no-graph
+ """
+ # Validate --mock-inputs requires --dry-run
+ if mock_inputs and not dry_run:
+ agent_error("--mock-inputs requires --dry-run", "ArgumentError")
+
+ pipe_code: str | None = pipe
+ bundle_path: str | None = None
+ auto_inputs_path: str | None = None
+ target_path = Path(path)
+
+ if target_path.is_dir():
+ # Directory mode: auto-detect bundle, inputs, and library dir
+ bundle_file = target_path / DEFAULT_BUNDLE_FILE_NAME
+ if bundle_file.is_file():
+ bundle_path = str(bundle_file)
+ else:
+ mthds_files = list(target_path.glob(f"*{MTHDS_EXTENSION}"))
+ if len(mthds_files) == 0:
+ agent_error(f"No .mthds bundle file found in directory '{path}'", "FileNotFoundError")
+ if len(mthds_files) > 1:
+ mthds_names = ", ".join(mthds_file.name for mthds_file in mthds_files)
+ agent_error(
+ f"Multiple .mthds files found in '{path}' ({mthds_names}) and no '{DEFAULT_BUNDLE_FILE_NAME}'. "
+ f"Pass the .mthds file directly instead.",
+ "ArgumentError",
+ )
+ bundle_path = str(mthds_files[0])
+
+ # Auto-detect inputs file (used as low-priority fallback)
+ inputs_file = target_path / DEFAULT_INPUTS_FILE_NAME
+ auto_inputs_path = str(inputs_file) if inputs_file.is_file() else None
+
+ # Add directory as library dir (prepend to user-supplied list)
+ target_dir_str = str(target_path)
+ if library_dir is None:
+ library_dir = [target_dir_str]
+ elif target_dir_str not in library_dir:
+ library_dir = [target_dir_str, *library_dir]
+
+ elif is_pipelex_file(target_path):
+ bundle_path = path
+ else:
+ agent_error(
+ f"'{path}' is not a .mthds file or directory. Use 'run pipe <code>' for pipe codes, or 'run bundle <path>' for .mthds files/directories.",
+ "ArgumentError",
+ )
+
+ # Load MTHDS content from bundle
+ mthds_content: str | None = None
+ if bundle_path:
+ try:
+ mthds_content = Path(bundle_path).read_text(encoding="utf-8")
+ if not pipe_code:
+ bundle_blueprint = PipelexInterpreter.make_pipelex_bundle_blueprint(mthds_content=mthds_content)
+ main_pipe_code = bundle_blueprint.main_pipe
+ if not main_pipe_code:
+ agent_error(
+ f"Bundle '{bundle_path}' does not declare a main_pipe. Specify a pipe code with --pipe.",
+ "BundleError",
+ )
+ pipe_code = main_pipe_code
+ except FileNotFoundError as exc:
+ agent_error(f"Bundle file not found: {bundle_path}", "FileNotFoundError", cause=exc)
+ except (OSError, UnicodeDecodeError) as exc:
+ agent_error(f"Failed to read bundle file '{bundle_path}': {exc}", type(exc).__name__, cause=exc)
+ except (PipelexInterpreterError, MthdsDecodeError) as exc:
+ agent_error(f"Failed to parse bundle '{bundle_path}': {exc}", type(exc).__name__, cause=exc)
+
+ # Load inputs: --inputs flag takes priority, then stdin fallback, then auto-detected
+ pipeline_inputs: dict[str, Any] | None = parse_cli_inputs(inputs_arg=inputs, stdin_fallback=True, auto_inputs_path=auto_inputs_path)
+
+ runner_type: RunnerType = ctx.obj["runner"]
+
+ match runner_type:
+ case RunnerType.API:
+ # Validate unsupported flags for API runner
+ if dry_run:
+ agent_error("--dry-run is not supported with --runner api", "ArgumentError")
+ if mock_inputs:
+ agent_error("--mock-inputs is not supported with --runner api", "ArgumentError")
+
+ from mthds.client.exceptions import ClientAuthenticationError, PipelineRequestError # noqa: PLC0415
+
+ try:
+ result = asyncio.run(
+ run_pipeline_core_api(
+ pipe_code=pipe_code, # type: ignore[arg-type]
+ mthds_content=mthds_content,
+ inputs=pipeline_inputs,
+ with_memory=with_memory,
+ )
+ )
+ agent_success(result)
+
+ except ClientAuthenticationError as exc:
+ agent_error(str(exc), "ClientAuthenticationError", cause=exc)
+
+ except PipelineRequestError as exc:
+ agent_error(str(exc), "PipelineRequestError", cause=exc)
+
+ except Exception as exc:
+ agent_error(str(exc), type(exc).__name__, cause=exc)
+
+ case RunnerType.PIPELEX:
+ make_pipelex_for_agent_cli(log_level=ctx.obj["log_level"])
+
+ try:
+ result = asyncio.run(
+ run_pipeline_core(
+ pipe_code=pipe_code, # type: ignore[arg-type]
+ mthds_content=mthds_content,
+ bundle_uri=bundle_path,
+ inputs=pipeline_inputs,
+ dry_run=dry_run,
+ mock_inputs=mock_inputs,
+ library_dirs=library_dir,
+ graph=graph,
+ with_memory=with_memory,
+ )
+ )
+ agent_success(result)
+
+ except PipelineExecutionError as exc:
+ extra_fields: dict[str, Any] = {
+ "pipe_code": exc.pipe_code,
+ "pipe_stack": exc.pipe_stack,
+ }
+ if exc.__cause__:
+ extra_fields["cause_type"] = type(exc.__cause__).__name__
+ extra_fields["cause_message"] = str(exc.__cause__)
+ agent_error(exc.message, "PipelineExecutionError", cause=exc, **extra_fields)
+
+ except PipeOperatorModelChoiceError as exc:
+ agent_error(
+ exc.message,
+ "PipeOperatorModelChoiceError",
+ cause=exc,
+ pipe_code=exc.pipe_code,
+ model_type=str(exc.model_type),
+ model_choice=str(exc.model_choice),
+ )
+
+ except PipeOperatorModelAvailabilityError as exc:
+ availability_extra: dict[str, Any] = {
+ "pipe_code": exc.pipe_code,
+ "model_handle": exc.model_handle,
+ }
+ if exc.fallback_list:
+ availability_extra["fallback_list"] = exc.fallback_list
+ if exc.pipe_stack:
+ availability_extra["pipe_stack"] = exc.pipe_stack
+ agent_error(exc.message, "PipeOperatorModelAvailabilityError", cause=exc, **availability_extra)
+
+ except Exception as exc:
+ agent_error(str(exc), type(exc).__name__, cause=exc)
+
+ finally:
+ Pipelex.teardown_if_needed()
diff --git a/pipelex/cli/agent_cli/commands/run/pipe_cmd.py b/pipelex/cli/agent_cli/commands/run/pipe_cmd.py
index 656cb2a16..31042caa2 100644
--- a/pipelex/cli/agent_cli/commands/run/pipe_cmd.py
+++ b/pipelex/cli/agent_cli/commands/run/pipe_cmd.py
@@ -1,4 +1,4 @@
-"""Agent CLI run pipe command - execute a pipeline by pipe code or bundle path."""
+"""Agent CLI run pipe command - execute a pipeline by pipe code."""
from __future__ import annotations
@@ -9,16 +9,13 @@ from typing import Annotated, Any
import typer
from mthds.runners.types import RunnerType
-from pipelex.builder.conventions import DEFAULT_BUNDLE_FILE_NAME, DEFAULT_INPUTS_FILE_NAME
from pipelex.cli.agent_cli.commands.agent_cli_factory import make_pipelex_for_agent_cli
from pipelex.cli.agent_cli.commands.agent_output import agent_error, agent_success
from pipelex.cli.agent_cli.commands.run._run_core import run_pipeline_core
from pipelex.cli.agent_cli.commands.run._run_core_api import run_pipeline_core_api
from pipelex.cli.agent_cli.commands.run.stdin_resolver import parse_cli_inputs
from pipelex.cli.method_resolver import resolve_pipe_from_exports
-from pipelex.core.interpreter.exceptions import MthdsDecodeError, PipelexInterpreterError
from pipelex.core.interpreter.helpers import MTHDS_EXTENSION, is_pipelex_file
-from pipelex.core.interpreter.interpreter import PipelexInterpreter
from pipelex.core.pipes.exceptions import PipeOperatorModelChoiceError
from pipelex.pipe_operators.exceptions import PipeOperatorModelAvailabilityError
from pipelex.pipelex import Pipelex
@@ -27,18 +24,10 @@ from pipelex.pipeline.exceptions import PipelineExecutionError
def run_pipe_cmd(
ctx: typer.Context,
- target: Annotated[
- str | None,
- typer.Argument(help="Pipe code or bundle file path (auto-detected)"),
- ] = None,
- pipe: Annotated[
- str | None,
- typer.Option("--pipe", help="Pipe code to run"),
- ] = None,
- bundle: Annotated[
- str | None,
- typer.Option("--bundle", help="Bundle file path (.mthds)"),
- ] = None,
+ pipe_code: Annotated[
+ str,
+ typer.Argument(help="Pipe code to run"),
+ ],
inputs: Annotated[
str | None,
typer.Option("--inputs", "-i", help="Path to JSON file with inputs or inline JSON"),
@@ -64,121 +53,40 @@ def run_pipe_cmd(
typer.Option("--with-memory", help="Include full working memory in output (for piping to another method)"),
] = False,
) -> None:
- """Execute a pipeline by pipe code or bundle path and output JSON results.
+ """Execute a pipeline by pipe code and output JSON results.
Outputs JSON to stdout on success, JSON to stderr on error with exit code 1.
Graph visualizations are generated by default; use --no-graph to disable.
Examples:
- pipelex-agent run pipe pipelex-wip/pipeline_01/
- pipelex-agent run pipe my_bundle.mthds --pipe my_pipe
+ pipelex-agent run pipe my_pipe
+ pipelex-agent run pipe my_pipe --inputs data.json
pipelex-agent run pipe my_pipe --dry-run --mock-inputs
- pipelex-agent run pipe pipelex-wip/pipeline_01/ --no-graph
+ pipelex-agent run pipe my_pipe --no-graph
"""
- # Validate that at least one target is provided
- provided_options = sum([target is not None, pipe is not None, bundle is not None])
- if provided_options == 0:
- agent_error("No pipe code or bundle file specified", "ArgumentError")
+ # Helpful error if the user passes a path instead of a pipe code
+ target_path = Path(pipe_code)
+ if target_path.is_dir() or is_pipelex_file(target_path) or pipe_code.endswith(MTHDS_EXTENSION):
+ agent_error(
+ f"'{pipe_code}' looks like a file path or directory. "
+ f"Use 'run bundle {pipe_code}' for bundles/directories, or 'run pipe <code>' for pipe codes.",
+ "ArgumentError",
+ )
# Validate --mock-inputs requires --dry-run
if mock_inputs and not dry_run:
agent_error("--mock-inputs requires --dry-run", "ArgumentError")
- # Determine pipe_code and bundle_path from arguments
- pipe_code: str | None = None
- bundle_path: str | None = None
- auto_inputs_path: str | None = None
-
- if target:
- target_path = Path(target)
- if target_path.is_dir():
- # Directory mode: auto-detect bundle, inputs, and library dir
- if bundle:
- agent_error("Cannot use --bundle when passing a pipeline directory as target", "ArgumentError")
-
- # Find .mthds: try default name first, then fall back to single .mthds
- bundle_file = target_path / DEFAULT_BUNDLE_FILE_NAME
- if bundle_file.is_file():
- bundle_path = str(bundle_file)
- else:
- mthds_files = list(target_path.glob(f"*{MTHDS_EXTENSION}"))
- if len(mthds_files) == 0:
- agent_error(f"No .mthds bundle file found in directory '{target}'", "FileNotFoundError")
- if len(mthds_files) > 1:
- mthds_names = ", ".join(mthds_file.name for mthds_file in mthds_files)
- agent_error(
- f"Multiple .mthds files found in '{target}' ({mthds_names}) and no '{DEFAULT_BUNDLE_FILE_NAME}'. "
- f"Pass the .mthds file directly instead.",
- "ArgumentError",
- )
- bundle_path = str(mthds_files[0])
-
- # Auto-detect inputs file (used as low-priority fallback)
- inputs_file = target_path / DEFAULT_INPUTS_FILE_NAME
- auto_inputs_path = str(inputs_file) if inputs_file.is_file() else None
-
- # Add directory as library dir (prepend to user-supplied list)
- target_dir_str = str(target_path)
- if library_dir is None:
- library_dir = [target_dir_str]
- elif target_dir_str not in library_dir:
- library_dir = [target_dir_str, *library_dir]
-
- # Consume --pipe if provided
- if pipe:
- pipe_code = pipe
- pipe = None # prevent double-assignment below
-
- elif is_pipelex_file(target_path):
- bundle_path = target
- if bundle:
- agent_error("Cannot use --bundle if already passing a bundle file as positional argument", "ArgumentError")
- else:
- pipe_code = target
- if pipe:
- agent_error("Cannot use --pipe if already passing a pipe code as positional argument", "ArgumentError")
-
- if bundle:
- bundle_path = bundle
-
- if pipe:
- pipe_code = pipe
-
- if not pipe_code and not bundle_path:
- agent_error("No pipe code or bundle file specified", "ArgumentError")
-
# Check installed methods' exports for additional library dirs
- if pipe_code and not bundle_path:
- export_dirs = resolve_pipe_from_exports(pipe_code)
- if export_dirs:
- if library_dir is None:
- library_dir = export_dirs
- else:
- library_dir = [*export_dirs, *library_dir]
-
- # Load MTHDS content from bundle if provided
- mthds_content: str | None = None
- if bundle_path:
- try:
- mthds_content = Path(bundle_path).read_text(encoding="utf-8")
- if not pipe_code:
- bundle_blueprint = PipelexInterpreter.make_pipelex_bundle_blueprint(mthds_content=mthds_content)
- main_pipe_code = bundle_blueprint.main_pipe
- if not main_pipe_code:
- agent_error(
- f"Bundle '{bundle_path}' does not declare a main_pipe. Specify a pipe code with --pipe.",
- "BundleError",
- )
- pipe_code = main_pipe_code
- except FileNotFoundError as exc:
- agent_error(f"Bundle file not found: {bundle_path}", "FileNotFoundError", cause=exc)
- except (OSError, UnicodeDecodeError) as exc:
- agent_error(f"Failed to read bundle file '{bundle_path}': {exc}", type(exc).__name__, cause=exc)
- except (PipelexInterpreterError, MthdsDecodeError) as exc:
- agent_error(f"Failed to parse bundle '{bundle_path}': {exc}", type(exc).__name__, cause=exc)
+ export_dirs = resolve_pipe_from_exports(pipe_code)
+ if export_dirs:
+ if library_dir is None:
+ library_dir = export_dirs
+ else:
+ library_dir = [*export_dirs, *library_dir]
# Load inputs: --inputs flag takes priority, then stdin fallback
- pipeline_inputs: dict[str, Any] | None = parse_cli_inputs(inputs_arg=inputs, stdin_fallback=True, auto_inputs_path=auto_inputs_path)
+ pipeline_inputs: dict[str, Any] | None = parse_cli_inputs(inputs_arg=inputs, stdin_fallback=True)
runner_type: RunnerType = ctx.obj["runner"]
@@ -195,8 +103,8 @@ def run_pipe_cmd(
try:
result = asyncio.run(
run_pipeline_core_api(
- pipe_code=pipe_code, # type: ignore[arg-type]
- mthds_content=mthds_content,
+ pipe_code=pipe_code,
+ mthds_content=None,
inputs=pipeline_inputs,
with_memory=with_memory,
)
@@ -218,9 +126,9 @@ def run_pipe_cmd(
try:
result = asyncio.run(
run_pipeline_core(
- pipe_code=pipe_code, # type: ignore[arg-type]
- mthds_content=mthds_content,
- bundle_uri=bundle_path,
+ pipe_code=pipe_code,
+ mthds_content=None,
+ bundle_uri=None,
inputs=pipeline_inputs,
dry_run=dry_run,
mock_inputs=mock_inputs,
diff --git a/pipelex/cli/agent_cli/commands/run/stdin_resolver.py b/pipelex/cli/agent_cli/commands/run/stdin_resolver.py
index 03ca59ce8..76e422bca 100644
--- a/pipelex/cli/agent_cli/commands/run/stdin_resolver.py
+++ b/pipelex/cli/agent_cli/commands/run/stdin_resolver.py
@@ -4,9 +4,11 @@ from __future__ import annotations
import json
import sys
+from pathlib import Path
from typing import Any, cast
from pipelex.cli.agent_cli.commands.agent_output import agent_error
+from pipelex.cli.commands.run._inputs_path_resolver import resolve_inputs_paths
from pipelex.tools.misc.json_utils import JsonTypeError, load_json_dict_from_path
WORKING_MEMORY_KEY = "working_memory"
@@ -165,7 +167,10 @@ def _parse_inputs_arg(inputs_arg: str) -> dict[str, Any] | None:
agent_error(f"Failed to parse inline JSON inputs: {exc}", "JSONDecodeError", cause=exc)
else:
try:
- return load_json_dict_from_path(inputs_arg)
+ loaded = load_json_dict_from_path(inputs_arg)
+ # Resolve relative url paths against the inputs file's parent directory
+ base_dir = Path(inputs_arg).parent.resolve()
+ return resolve_inputs_paths(loaded, base_dir)
except FileNotFoundError as exc:
agent_error(f"Input file not found: {inputs_arg}", "FileNotFoundError", cause=exc)
except JsonTypeError as exc:
diff --git a/pipelex/cli/commands/run/_inputs_path_resolver.py b/pipelex/cli/commands/run/_inputs_path_resolver.py
new file mode 100644
index 000000000..6fee8c3dc
--- /dev/null
+++ b/pipelex/cli/commands/run/_inputs_path_resolver.py
@@ -0,0 +1,85 @@
+"""Resolve relative file paths inside pipeline inputs relative to a base directory.
+
+When inputs are loaded from a JSON file (e.g. ``inputs.json`` inside a bundle
+directory), any relative ``url`` values should be resolved relative to that
+file's parent directory — not relative to the process CWD. This module
+provides the logic to walk an inputs dict and prepend a base directory to
+relative local paths.
+"""
+
+from __future__ import annotations
+
+from pathlib import Path
+from typing import Any, cast
+
+from pipelex.tools.uri.resolved_uri import ResolvedLocalPath
+from pipelex.tools.uri.uri_resolver import resolve_uri
+
+
+def is_relative_local_path(uri: str) -> bool:
+ """Check whether *uri* is a relative local file path.
+
+ Uses :func:`resolve_uri` to classify the URI. Returns ``True`` only when
+ the URI resolves to a :class:`ResolvedLocalPath` **and** the path is not
+ absolute.
+
+ Args:
+ uri: The URI string to check.
+
+ Returns:
+ ``True`` if *uri* is a relative local path, ``False`` otherwise.
+ """
+ resolved = resolve_uri(uri)
+ if not isinstance(resolved, ResolvedLocalPath):
+ return False
+ return not Path(resolved.path).is_absolute()
+
+
+def resolve_url_in_value(value: Any, base_dir: Path) -> Any:
+ """Recursively walk a JSON-like value and resolve relative ``url`` fields.
+
+ When a ``dict`` contains a ``"url"`` key whose value is a relative local
+ path, the path is prepended with *base_dir* so that it becomes absolute.
+
+ Args:
+ value: An arbitrary JSON-decoded value (dict, list, str, etc.).
+ base_dir: The directory against which relative paths are resolved.
+
+ Returns:
+ The value with relative ``url`` entries resolved.
+ """
+ if isinstance(value, dict):
+ value_dict = cast("dict[str, Any]", value)
+ result: dict[str, Any] = {}
+ for key, val in value_dict.items():
+ if key == "url" and isinstance(val, str) and is_relative_local_path(val):
+ result[key] = str(base_dir / val)
+ else:
+ result[key] = resolve_url_in_value(val, base_dir)
+ return result
+
+ if isinstance(value, list):
+ value_list = cast("list[Any]", value)
+ return [resolve_url_in_value(item, base_dir) for item in value_list]
+
+ return value
+
+
+def resolve_inputs_paths(inputs_dict: dict[str, Any], base_dir: Path) -> dict[str, Any]:
+ """Resolve relative ``url`` paths in a pipeline inputs dict.
+
+ Entry point that applies :func:`resolve_url_in_value` to each top-level
+ value in *inputs_dict*.
+
+ Args:
+ inputs_dict: The parsed pipeline inputs dictionary.
+ base_dir: The directory to resolve relative paths against (typically
+ the parent directory of the ``inputs.json`` file).
+
+ Returns:
+ A new dict with all relative ``url`` values resolved to absolute paths.
+ """
+ resolved: dict[str, Any] = {}
+ for key, value in inputs_dict.items():
+ resolved[key] = resolve_url_in_value(value, base_dir)
+ return resolved
diff --git a/pipelex/cli/commands/run/_run_core.py b/pipelex/cli/commands/run/_run_core.py
index 05cfea31b..30e1f88f3 100644
--- a/pipelex/cli/commands/run/_run_core.py
+++ b/pipelex/cli/commands/run/_run_core.py
@@ -10,6 +10,7 @@ from posthog import tag
from pipelex import log
from pipelex.base_exceptions import PipelexError
from pipelex.cli.cli_factory import make_pipelex_for_cli
+from pipelex.cli.commands.run._inputs_path_resolver import resolve_inputs_paths
from pipelex.cli.error_handlers import (
ErrorContext,
handle_model_availability_error,
@@ -94,6 +95,9 @@ async def _execute_run(
else:
try:
pipeline_inputs = load_json_dict_from_path(inputs)
+ # Resolve relative url paths against the inputs file's parent directory
+ base_dir = Path(inputs).parent.resolve()
+ pipeline_inputs = resolve_inputs_paths(pipeline_inputs, base_dir)
typer.echo(f"Loaded inputs from: {inputs}")
except FileNotFoundError as file_not_found_exc:
typer.secho(f"Failed to load input file '{inputs}': file not found", fg=typer.colors.RED, err=True)
diff --git a/pipelex/cli/commands/run/app.py b/pipelex/cli/commands/run/app.py
index 94a99eced..a7090b0ff 100644
--- a/pipelex/cli/commands/run/app.py
+++ b/pipelex/cli/commands/run/app.py
@@ -1,9 +1,11 @@
import typer
+from pipelex.cli.commands.run.bundle_cmd import run_bundle_cmd
from pipelex.cli.commands.run.method_cmd import run_method_cmd
from pipelex.cli.commands.run.pipe_cmd import run_pipe_cmd
-run_app = typer.Typer(help="Run a method or pipe", no_args_is_help=True)
+run_app = typer.Typer(help="Run a method, pipe, or bundle", no_args_is_help=True)
run_app.command("method", help="Run an installed method by name")(run_method_cmd)
-run_app.command("pipe", help="Run a pipe by code, bundle file (.mthds), or pipeline directory")(run_pipe_cmd)
+run_app.command("pipe", help="Run a pipe by code")(run_pipe_cmd)
+run_app.command("bundle", help="Run a pipeline from a bundle file (.mthds) or directory")(run_bundle_cmd)
diff --git a/pipelex/cli/commands/run/bundle_cmd.py b/pipelex/cli/commands/run/bundle_cmd.py
new file mode 100644
index 000000000..33971145a
--- /dev/null
+++ b/pipelex/cli/commands/run/bundle_cmd.py
@@ -0,0 +1,163 @@
+from __future__ import annotations
+
+from pathlib import Path
+from typing import Annotated
+
+import typer
+
+from pipelex.builder.conventions import DEFAULT_BUNDLE_FILE_NAME, DEFAULT_INPUTS_FILE_NAME
+from pipelex.cli.commands.run._run_core import COMMAND, execute_run
+from pipelex.core.interpreter.helpers import MTHDS_EXTENSION, is_pipelex_file
+
+
+def run_bundle_cmd(
+ path: Annotated[
+ str,
+ typer.Argument(help="Path to a .mthds bundle file or a pipeline directory"),
+ ],
+ pipe: Annotated[
+ str | None,
+ typer.Option("--pipe", help="Pipe code to run (overrides bundle's main_pipe)"),
+ ] = None,
+ inputs: Annotated[
+ str | None,
+ typer.Option("--inputs", "-i", help="Path to JSON file with inputs"),
+ ] = None,
+ save_working_memory: Annotated[
+ bool,
+ typer.Option("--save-working-memory/--no-save-working-memory", help="Save working memory to JSON file"),
+ ] = True,
+ working_memory_path: Annotated[
+ str | None,
+ typer.Option("--working-memory-path", help="Custom path to save working memory JSON"),
+ ] = None,
+ save_main_stuff: Annotated[
+ bool,
+ typer.Option("--save-main-stuff/--no-save-main-stuff", help="Save main_stuff in JSON and Markdown formats"),
+ ] = True,
+ no_pretty_print: Annotated[
+ bool,
+ typer.Option("--no-pretty-print", help="Skip pretty printing the main_stuff"),
+ ] = False,
+ graph: Annotated[
+ bool | None,
+ typer.Option(
+ "--graph/--no-graph",
+ help="Override config: enable or disable execution graph outputs (JSON, Mermaid, HTML)",
+ ),
+ ] = None,
+ graph_full_data: Annotated[
+ bool | None,
+ typer.Option(
+ "--graph-full-data/--graph-no-data",
+ help="Override config: include or exclude full serialized data in graph",
+ ),
+ ] = None,
+ output_dir: Annotated[
+ str,
+ typer.Option("--output-dir", "-o", help="Base directory for all outputs (working memory, main_stuff, graphs)"),
+ ] = "results",
+ dry_run: Annotated[
+ bool,
+ typer.Option("--dry-run", help="Run pipeline in dry mode (no actual inference calls)"),
+ ] = False,
+ mock_inputs: Annotated[
+ bool,
+ typer.Option("--mock-inputs", help="Generate mock data for missing required inputs (requires --dry-run)"),
+ ] = False,
+ library_dir: Annotated[
+ list[str] | None,
+ typer.Option("--library-dir", "-L", help="Directory to search for pipe definitions (.mthds files). Can be specified multiple times."),
+ ] = None,
+) -> None:
+ """Run a pipeline from a bundle file (.mthds) or pipeline directory.
+
+ Examples:
+ pipelex run bundle pipeline_01/
+ pipelex run bundle pipeline_01/ --pipe my_pipe
+ pipelex run bundle my_bundle.mthds
+ pipelex run bundle my_bundle.mthds --pipe my_pipe --inputs data.json
+ pipelex run bundle pipeline_01/ --dry-run
+ """
+ # Validate --mock-inputs requires --dry-run
+ if mock_inputs and not dry_run:
+ typer.secho(
+ "Failed to run: --mock-inputs requires --dry-run",
+ fg=typer.colors.RED,
+ err=True,
+ )
+ raise typer.Exit(1)
+
+ pipe_code: str | None = pipe
+ bundle_path: str | None = None
+ target_path = Path(path)
+
+ if target_path.is_dir():
+ # Directory mode: auto-detect bundle and inputs
+ bundle_file = target_path / DEFAULT_BUNDLE_FILE_NAME
+ if bundle_file.is_file():
+ bundle_path = str(bundle_file)
+ else:
+ mthds_files = list(target_path.glob(f"*{MTHDS_EXTENSION}"))
+ if len(mthds_files) == 0:
+ typer.secho(
+ f"Failed to run: no .mthds bundle file found in directory '{path}'",
+ fg=typer.colors.RED,
+ err=True,
+ )
+ raise typer.Exit(1)
+ if len(mthds_files) > 1:
+ mthds_names = ", ".join(mthds_file.name for mthds_file in mthds_files)
+ typer.secho(
+ f"Failed to run: multiple .mthds files found in '{path}' ({mthds_names}) "
+ f"and no '{DEFAULT_BUNDLE_FILE_NAME}'. "
+ f"Pass the .mthds file directly, e.g.: pipelex run bundle {target_path / mthds_files[0].name}",
+ fg=typer.colors.RED,
+ err=True,
+ )
+ raise typer.Exit(1)
+ bundle_path = str(mthds_files[0])
+
+ # Auto-detect inputs if --inputs not explicitly provided
+ inputs_file = target_path / DEFAULT_INPUTS_FILE_NAME
+ if not inputs and inputs_file.is_file():
+ inputs = str(inputs_file)
+ typer.echo(f"Auto-detected inputs: {inputs}")
+
+ # Add directory as library dir
+ target_dir_str = str(target_path)
+ if library_dir is None:
+ library_dir = [target_dir_str]
+ elif target_dir_str not in library_dir:
+ library_dir = [target_dir_str, *library_dir]
+
+ typer.echo(f"Auto-detected bundle: {bundle_path}")
+
+ elif is_pipelex_file(target_path):
+ bundle_path = path
+ else:
+ typer.secho(
+ f"Failed to run: '{path}' is not a .mthds file or directory.\n"
+ f" To run a pipe by code, use: pipelex run pipe <code>\n"
+ f" To run a bundle, pass a .mthds file or directory: pipelex run bundle <path>",
+ fg=typer.colors.RED,
+ err=True,
+ )
+ raise typer.Exit(1)
+
+ execute_run(
+ pipe_code=pipe_code,
+ bundle_path=bundle_path,
+ inputs=inputs,
+ save_working_memory=save_working_memory,
+ working_memory_path=working_memory_path,
+ save_main_stuff=save_main_stuff,
+ no_pretty_print=no_pretty_print,
+ graph=graph,
+ graph_full_data=graph_full_data,
+ output_dir=output_dir,
+ dry_run=dry_run,
+ mock_inputs=mock_inputs,
+ library_dir=library_dir,
+ telemetry_command_label=f"{COMMAND} bundle",
+ )
diff --git a/pipelex/cli/commands/run/pipe_cmd.py b/pipelex/cli/commands/run/pipe_cmd.py
index 237d1af01..fdf37b611 100644
--- a/pipelex/cli/commands/run/pipe_cmd.py
+++ b/pipelex/cli/commands/run/pipe_cmd.py
@@ -3,28 +3,18 @@ from __future__ import annotations
from pathlib import Path
from typing import Annotated
-import click
import typer
-from pipelex.builder.conventions import DEFAULT_BUNDLE_FILE_NAME, DEFAULT_INPUTS_FILE_NAME
from pipelex.cli.commands.run._run_core import COMMAND, execute_run
from pipelex.cli.method_resolver import resolve_pipe_from_exports
from pipelex.core.interpreter.helpers import MTHDS_EXTENSION, is_pipelex_file
def run_pipe_cmd(
- target: Annotated[
- str | None,
- typer.Argument(help="Pipe code, bundle file path (.mthds), or pipeline directory (auto-detected)"),
- ] = None,
- pipe: Annotated[
- str | None,
- typer.Option("--pipe", help="Pipe code to run, can be omitted if you specify a bundle (.mthds) that declares a main pipe"),
- ] = None,
- bundle: Annotated[
- str | None,
- typer.Option("--bundle", help="Bundle file path (.mthds) - runs its main_pipe unless you specify a pipe code"),
- ] = None,
+ pipe_code: Annotated[
+ str,
+ typer.Argument(help="Pipe code to run"),
+ ],
inputs: Annotated[
str | None,
typer.Option("--inputs", "-i", help="Path to JSON file with inputs"),
@@ -76,25 +66,24 @@ def run_pipe_cmd(
typer.Option("--library-dir", "-L", help="Directory to search for pipe definitions (.mthds files). Can be specified multiple times."),
] = None,
) -> None:
- """Run a pipe by code, bundle file (.mthds), or pipeline directory.
+ """Run a pipe by code.
Examples:
pipelex run pipe my_pipe
- pipelex run pipe --bundle my_bundle.mthds
- pipelex run pipe --bundle my_bundle.mthds --pipe my_pipe
- pipelex run pipe --pipe my_pipe --inputs data.json
- pipelex run pipe my_bundle.mthds --inputs data.json
- pipelex run pipe pipeline_01/
- pipelex run pipe pipeline_01/ --pipe my_pipe
+ pipelex run pipe my_pipe --inputs data.json
pipelex run pipe my_pipe --dry-run
pipelex run pipe my_pipe --dry-run --mock-inputs
"""
- # Validate mutual exclusivity
- provided_options = sum([target is not None, pipe is not None, bundle is not None])
- if provided_options == 0:
- ctx: click.Context = click.get_current_context()
- typer.echo(ctx.get_help())
- raise typer.Exit(0)
+ # Helpful error if the user passes a path instead of a pipe code
+ target_path = Path(pipe_code)
+ if target_path.is_dir() or is_pipelex_file(target_path) or pipe_code.endswith(MTHDS_EXTENSION):
+ typer.secho(
+ f"Failed to run: '{pipe_code}' looks like a file path or directory.\n"
+ f" To run from a bundle or directory, use: pipelex run bundle {pipe_code}",
+ fg=typer.colors.RED,
+ err=True,
+ )
+ raise typer.Exit(1)
# Validate --mock-inputs requires --dry-run
if mock_inputs and not dry_run:
@@ -105,108 +94,17 @@ def run_pipe_cmd(
)
raise typer.Exit(1)
- pipe_code: str | None = None
- bundle_path: str | None = None
-
- # Determine source
- if target:
- target_path = Path(target)
- if target_path.is_dir():
- # Directory mode: auto-detect bundle and inputs
- if bundle:
- typer.secho(
- "Failed to run: cannot use option --bundle when passing a pipeline directory as target",
- fg=typer.colors.RED,
- err=True,
- )
- raise typer.Exit(1)
-
- bundle_file = target_path / DEFAULT_BUNDLE_FILE_NAME
- if bundle_file.is_file():
- bundle_path = str(bundle_file)
- else:
- mthds_files = list(target_path.glob(f"*{MTHDS_EXTENSION}"))
- if len(mthds_files) == 0:
- typer.secho(
- f"Failed to run: no .mthds bundle file found in directory '{target}'",
- fg=typer.colors.RED,
- err=True,
- )
- raise typer.Exit(1)
- if len(mthds_files) > 1:
- mthds_names = ", ".join(mthds_file.name for mthds_file in mthds_files)
- typer.secho(
- f"Failed to run: multiple .mthds files found in '{target}' ({mthds_names}) "
- f"and no '{DEFAULT_BUNDLE_FILE_NAME}'. "
- f"Pass the .mthds file directly, e.g.: pipelex run pipe {target_path / mthds_files[0].name}",
- fg=typer.colors.RED,
- err=True,
- )
- raise typer.Exit(1)
- bundle_path = str(mthds_files[0])
-
- # Auto-detect inputs if --inputs not explicitly provided
- inputs_file = target_path / DEFAULT_INPUTS_FILE_NAME
- if not inputs and inputs_file.is_file():
- inputs = str(inputs_file)
- typer.echo(f"Auto-detected inputs: {inputs}")
-
- # Add directory as library dir
- target_dir_str = str(target_path)
- if library_dir is None:
- library_dir = [target_dir_str]
- elif target_dir_str not in library_dir:
- library_dir = [target_dir_str, *library_dir]
-
- if pipe:
- pipe_code = pipe
- pipe = None
-
- typer.echo(f"Auto-detected bundle: {bundle_path}")
-
- elif is_pipelex_file(target_path):
- bundle_path = target
- if bundle:
- typer.secho(
- "Failed to run: cannot use option --bundle if you're already passing a bundle file (.mthds) as positional argument",
- fg=typer.colors.RED,
- err=True,
- )
- raise typer.Exit(1)
+ # Check installed methods' exports for additional library dirs
+ extra_dirs = resolve_pipe_from_exports(pipe_code)
+ if extra_dirs:
+ if library_dir is None:
+ library_dir = extra_dirs
else:
- pipe_code = target
- if pipe:
- typer.secho(
- "Failed to run: cannot use option --pipe if you're already passing a pipe code as positional argument",
- fg=typer.colors.RED,
- err=True,
- )
- raise typer.Exit(1)
-
- if bundle:
- assert not bundle_path, "bundle_path should be None at this stage if --bundle is provided"
- bundle_path = bundle
-
- if pipe:
- assert not pipe_code, "pipe_code should be None at this stage if --pipe is provided"
- pipe_code = pipe
-
- if not pipe_code and not bundle_path:
- typer.secho("Failed to run: no pipe code or bundle file specified", fg=typer.colors.RED, err=True)
- raise typer.Exit(1)
-
- # If running a bare pipe code, check installed methods' exports for additional library dirs
- if pipe_code and not bundle_path:
- extra_dirs = resolve_pipe_from_exports(pipe_code)
- if extra_dirs:
- if library_dir is None:
- library_dir = extra_dirs
- else:
- library_dir = [*extra_dirs, *library_dir]
+ library_dir = [*extra_dirs, *library_dir]
execute_run(
pipe_code=pipe_code,
- bundle_path=bundle_path,
+ bundle_path=None,
inputs=inputs,
save_working_memory=save_working_memory,
working_memory_path=working_memory_path,
diff --git a/tests/unit/pipelex/cli/test_inputs_path_resolver.py b/tests/unit/pipelex/cli/test_inputs_path_resolver.py
new file mode 100644
index 000000000..1e87edaf6
--- /dev/null
+++ b/tests/unit/pipelex/cli/test_inputs_path_resolver.py
@@ -0,0 +1,248 @@
+"""Unit tests for _inputs_path_resolver: resolve relative url paths in pipeline inputs."""
+
+from __future__ import annotations
+
+from pathlib import Path
+from typing import Any, ClassVar
+
+import pytest
+
+from pipelex.cli.commands.run._inputs_path_resolver import is_relative_local_path, resolve_inputs_paths, resolve_url_in_value # noqa: PLC2701
+
+
+class _IsRelativeLocalPathCases:
+ RELATIVE_FILE = ("data/invoice.pdf", True)
+ RELATIVE_NESTED = ("subdir/another/file.txt", True)
+ BARE_FILENAME = ("invoice.pdf", True)
+ ABSOLUTE_PATH = ("/home/user/data/invoice.pdf", False)
+ HTTP_URL = ("https://example.com/file.pdf", False)
+ HTTPS_URL = ("https://cdn.example.com/doc.pdf", False)
+ DATA_URL = ("data:application/pdf;base64,AAAA", False)
+ PIPELEX_STORAGE = ("pipelex-storage://bucket/file.pdf", False)
+ FILE_URI = ("file:///home/user/file.pdf", False)
+
+
+class _ResolveInputsPathsCases:
+ """Parametrized test data for resolve_inputs_paths."""
+
+ BASE_DIR: ClassVar[Path] = Path("/bundles/my_pipeline")
+
+ RELATIVE_URL_IN_CONTENT: ClassVar[tuple[str, dict[str, Any], dict[str, Any]]] = (
+ "relative url in content dict is resolved",
+ {
+ "source_doc": {
+ "concept": "native.Document",
+ "content": {"url": "data/invoice.pdf"},
+ },
+ },
+ {
+ "source_doc": {
+ "concept": "native.Document",
+ "content": {"url": "/bundles/my_pipeline/data/invoice.pdf"},
+ },
+ },
+ )
+
+ RELATIVE_URLS_IN_LIST: ClassVar[tuple[str, dict[str, Any], dict[str, Any]]] = (
+ "relative urls in content list are resolved",
+ {
+ "docs": {
+ "concept": "native.Document",
+ "content": [
+ {"url": "data/f1.pdf"},
+ {"url": "data/f2.pdf"},
+ ],
+ },
+ },
+ {
+ "docs": {
+ "concept": "native.Document",
+ "content": [
+ {"url": "/bundles/my_pipeline/data/f1.pdf"},
+ {"url": "/bundles/my_pipeline/data/f2.pdf"},
+ ],
+ },
+ },
+ )
+
+ ABSOLUTE_PATH_UNCHANGED: ClassVar[tuple[str, dict[str, Any], dict[str, Any]]] = (
+ "absolute paths are left unchanged",
+ {
+ "source_doc": {
+ "concept": "native.Document",
+ "content": {"url": "/absolute/path/file.pdf"},
+ },
+ },
+ {
+ "source_doc": {
+ "concept": "native.Document",
+ "content": {"url": "/absolute/path/file.pdf"},
+ },
+ },
+ )
+
+ HTTP_URL_UNCHANGED: ClassVar[tuple[str, dict[str, Any], dict[str, Any]]] = (
+ "http urls are left unchanged",
+ {
+ "source_doc": {
+ "concept": "native.Document",
+ "content": {"url": "https://example.com/file.pdf"},
+ },
+ },
+ {
+ "source_doc": {
+ "concept": "native.Document",
+ "content": {"url": "https://example.com/file.pdf"},
+ },
+ },
+ )
+
+ DATA_URL_UNCHANGED: ClassVar[tuple[str, dict[str, Any], dict[str, Any]]] = (
+ "data: urls are left unchanged",
+ {
+ "source_doc": {
+ "concept": "native.Document",
+ "content": {"url": "data:application/pdf;base64,AAAA"},
+ },
+ },
+ {
+ "source_doc": {
+ "concept": "native.Document",
+ "content": {"url": "data:application/pdf;base64,AAAA"},
+ },
+ },
+ )
+
+ PIPELEX_STORAGE_UNCHANGED: ClassVar[tuple[str, dict[str, Any], dict[str, Any]]] = (
+ "pipelex-storage urls are left unchanged",
+ {
+ "source_doc": {
+ "concept": "native.Document",
+ "content": {"url": "pipelex-storage://bucket/file.pdf"},
+ },
+ },
+ {
+ "source_doc": {
+ "concept": "native.Document",
+ "content": {"url": "pipelex-storage://bucket/file.pdf"},
+ },
+ },
+ )
+
+ PLAIN_TEXT_UNCHANGED: ClassVar[tuple[str, dict[str, Any], dict[str, Any]]] = (
+ "plain text inputs are left unchanged",
+ {
+ "topic": {
+ "concept": "native.Text",
+ "content": {"body": "summarize this document"},
+ },
+ },
+ {
+ "topic": {
+ "concept": "native.Text",
+ "content": {"body": "summarize this document"},
+ },
+ },
+ )
+
+ NESTED_URL_RESOLVED: ClassVar[tuple[str, dict[str, Any], dict[str, Any]]] = (
+ "nested structured content urls are resolved",
+ {
+ "complex": {
+ "concept": "native.Document",
+ "content": {
+ "metadata": {"title": "Report"},
+ "attachments": [
+ {"url": "data/attachment.pdf", "label": "att1"},
+ ],
+ },
+ },
+ },
+ {
+ "complex": {
+ "concept": "native.Document",
+ "content": {
+ "metadata": {"title": "Report"},
+ "attachments": [
+ {"url": "/bundles/my_pipeline/data/attachment.pdf", "label": "att1"},
+ ],
+ },
+ },
+ },
+ )
+
+ EMPTY_DICT: ClassVar[tuple[str, dict[str, Any], dict[str, Any]]] = (
+ "empty dict returns empty dict",
+ {},
+ {},
+ )
+
+ NO_URL_KEYS: ClassVar[tuple[str, dict[str, Any], dict[str, Any]]] = (
+ "dict without url keys is unchanged",
+ {
+ "config": {
+ "key": "value",
+ "nested": {"a": 1, "b": 2},
+ },
+ },
+ {
+ "config": {
+ "key": "value",
+ "nested": {"a": 1, "b": 2},
+ },
+ },
+ )
+
+
+class TestInputsPathResolver:
+ """Tests for is_relative_local_path, resolve_url_in_value, and resolve_inputs_paths."""
+
+ # ---- is_relative_local_path ----
+
+ @pytest.mark.parametrize(
+ ("uri", "expected"),
+ [
+ _IsRelativeLocalPathCases.RELATIVE_FILE,
+ _IsRelativeLocalPathCases.RELATIVE_NESTED,
+ _IsRelativeLocalPathCases.BARE_FILENAME,
+ _IsRelativeLocalPathCases.ABSOLUTE_PATH,
+ _IsRelativeLocalPathCases.HTTP_URL,
+ _IsRelativeLocalPathCases.HTTPS_URL,
+ _IsRelativeLocalPathCases.DATA_URL,
+ _IsRelativeLocalPathCases.PIPELEX_STORAGE,
+ _IsRelativeLocalPathCases.FILE_URI,
+ ],
+ )
+ def test_is_relative_local_path(self, uri: str, expected: bool) -> None:
+ """Correctly classifies URIs as relative local paths or not."""
+ assert is_relative_local_path(uri) == expected
+
+ # ---- resolve_url_in_value ----
+
+ def test_resolve_url_in_value_string_passthrough(self) -> None:
+ """Non-dict, non-list values pass through unchanged."""
+ assert resolve_url_in_value("hello", Path("/base")) == "hello"
+ assert resolve_url_in_value(42, Path("/base")) == 42
+ assert resolve_url_in_value(None, Path("/base")) is None
+
+ # ---- resolve_inputs_paths ----
+
+ @pytest.mark.parametrize(
+ ("topic", "inputs_dict", "expected"),
+ [
+ _ResolveInputsPathsCases.RELATIVE_URL_IN_CONTENT,
+ _ResolveInputsPathsCases.RELATIVE_URLS_IN_LIST,
+ _ResolveInputsPathsCases.ABSOLUTE_PATH_UNCHANGED,
+ _ResolveInputsPathsCases.HTTP_URL_UNCHANGED,
+ _ResolveInputsPathsCases.DATA_URL_UNCHANGED,
+ _ResolveInputsPathsCases.PIPELEX_STORAGE_UNCHANGED,
+ _ResolveInputsPathsCases.PLAIN_TEXT_UNCHANGED,
+ _ResolveInputsPathsCases.NESTED_URL_RESOLVED,
+ _ResolveInputsPathsCases.EMPTY_DICT,
+ _ResolveInputsPathsCases.NO_URL_KEYS,
+ ],
+ )
+ def test_resolve_inputs_paths(self, topic: str, inputs_dict: dict[str, Any], expected: dict[str, Any]) -> None: # noqa: ARG002
+ """Resolves relative url paths in various input structures."""
+ result = resolve_inputs_paths(inputs_dict, _ResolveInputsPathsCases.BASE_DIR)
+ assert result == expected