diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f3d950e0..526d713d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,20 @@ history. ### Added +- `comfy deploy run --allow-upload ` (repeatable) uploads a local file + the deployment lacks only if its hash is listed; any other file fails with + `deploy_asset_missing` and is not sent. A file Cloud already holds is reused + by hash with no copy. A file it must upload is copied once to a private + temporary file, checked against the approved hash and sent from that copy, + so a file rewritten in between cannot send bytes nobody approved. A temp + folder without room for the whole file is refused before any byte is + copied, with `deploy_asset_upload_failed`. That file is not uploaded; + approved files before it may already be, and a retry reuses them. The + `--allow-upload` refusal, and the one from + `--no-upload`, now lists every such file in `details.missing[]` (absolute + `local_path`, `bytes`, `hash`) rather than stopping at the first, so a person + can approve the exact files the scanner picked. When two asset folders hold + files of the same name, this shows which one it picked. - `comfy workflow check --where cloud` says whether Comfy Cloud runs a workflow with no custom build. Signed in, it reads Cloud's node list and your uploaded models, and answers `covered`, `covered_with_remaps` (a model sits in diff --git a/comfy_cli/command/deploy.py b/comfy_cli/command/deploy.py index f675d0d2c..c9d9f60cb 100644 --- a/comfy_cli/command/deploy.py +++ b/comfy_cli/command/deploy.py @@ -128,6 +128,14 @@ def run_cmd( list[Path] | None, typer.Option("--asset-root", help="Extra directory workflow inputs may name files inside. Repeatable."), ] = None, + allow_upload: Annotated[ + list[str] | None, + typer.Option( + "--allow-upload", + help="Upload a missing local file only if its hash is this one (a `--no-upload` refusal's " + "`details.missing[].hash`). Repeatable. Any other missing file fails with deploy_asset_missing.", + ), + ] = None, ) -> None: _deploy_run.run_deploy( ctx, @@ -140,6 +148,7 @@ def run_cmd( timeout, no_upload, tuple(asset_root or ()), + frozenset(allow_upload) if allow_upload else None, ), ) diff --git a/comfy_cli/command/deploy_run.py b/comfy_cli/command/deploy_run.py index 2e1486a30..0239da968 100644 --- a/comfy_cli/command/deploy_run.py +++ b/comfy_cli/command/deploy_run.py @@ -68,6 +68,7 @@ class DeployRunRequest: timeout: float | None no_upload: bool asset_roots: tuple[Path, ...] = () + allowed_uploads: frozenset[str] | None = None @dataclass(frozen=True, slots=True) @@ -248,7 +249,12 @@ def run_deploy(ctx: typer.Context, request: DeployRunRequest) -> None: data_target = Target(kind="cloud", base_url=endpoint_origin, path_prefix="/api/v2", auth_token=data_credential) assets = resolve_assets( plan, - AssetResolveContext(DeployAssetClient(endpoint_origin, token), renderer, not request.no_upload), + AssetResolveContext( + DeployAssetClient(endpoint_origin, token), + renderer, + not request.no_upload, + request.allowed_uploads, + ), ) submitted = DeployJobClient(endpoint_origin, token.current()).submit_job( JobSubmitRequest(assets.workflow, str(uuid.uuid4()), deployment_id, partner_credential), diff --git a/comfy_cli/command/deploy_run_assets.py b/comfy_cli/command/deploy_run_assets.py index e8d3b4479..30dc4b852 100644 --- a/comfy_cli/command/deploy_run_assets.py +++ b/comfy_cli/command/deploy_run_assets.py @@ -12,8 +12,14 @@ from comfy_cli.command.build_spec import JsonObject, JsonValue from comfy_cli.command.deploy_types import server_shape_error -from comfy_cli.command.deploy_workflow import WorkflowAssetPlan, materialize_workflow_assets -from comfy_cli.deploy_assets import AssetResolveRequest, AssetResolveResult, DeployAssetClient +from comfy_cli.command.deploy_workflow import WorkflowAsset, WorkflowAssetPlan, materialize_workflow_assets +from comfy_cli.deploy_api_errors import DeployAPIError +from comfy_cli.deploy_assets import ( + AssetResolveRequest, + AssetResolveResult, + DeployAssetClient, + DeployAssetMissingError, +) from comfy_cli.output.renderer import Renderer @@ -60,31 +66,81 @@ class AssetResolveContext: client: DeployAssetClient renderer: Renderer upload_enabled: bool + allowed_hashes: frozenset[str] | None = None + + +def _missing_error(missing: list[JsonValue]) -> DeployAPIError: + """One refusal naming every file the run may not upload. + + It lists them all, not just the first, so ``details.missing`` is the whole + upload plan: each absolute ``local_path`` the scanner picked, its ``bytes`` + and its ``hash``. ``file_path`` and ``hash`` still name the first, as before. + """ + first = missing[0] + assert isinstance(first, dict) + count = len(missing) + return DeployAPIError( + code="deploy_asset_missing", + message=f"{count} local file{'' if count == 1 else 's'} the deployment does not have may not be uploaded", + details={"file_path": first["file_path"], "hash": first["hash"], "missing": missing}, + ) def resolve_assets(plan: WorkflowAssetPlan, context: AssetResolveContext) -> ResolvedAssets: asset_ids: dict[str, str] = {} - results: list[AssetResolveResult] = [] - disclosed: list[DisclosedAsset] = [] - for asset in plan.assets: + results: dict[int, tuple[AssetResolveResult, DisclosedAsset]] = {} + missing: list[JsonValue] = [] + # With --allow-upload, every file's approval is settled before the first + # upload: the first pass only probes, so a refused file fails the run + # before an approved one is sent and left unused on the deployment. + approved = context.allowed_hashes if context.upload_enabled else None + to_upload: list[tuple[int, WorkflowAsset, int]] = [] + + def record(index: int, asset: WorkflowAsset, size: int, result: AssetResolveResult) -> None: + asset_id = result.asset.get("id") + if not isinstance(asset_id, str) or not asset_id: + raise server_shape_error("the data plane returned an asset without an id") + asset_ids[asset.marker] = asset_id + # An upload reports the bytes it sent: an approved file can be replaced + # by other approved bytes between the probe and the upload. + sent = result.bytes if result.uploaded else size + results[index] = (result, DisclosedAsset(asset.local_path, asset.file_path, sent, bool(result.uploaded))) + + for index, asset in enumerate(plan.assets): size = asset.local_path.stat().st_size if context.renderer.is_pretty(): # Announced BEFORE the call, not after: a disclosure the user only # reads once the bytes are already gone is not a disclosure. context.renderer.info(f"Sending workflow asset {asset.local_path} ({size} bytes)") - result = context.client.resolve_asset( - AssetResolveRequest(asset.local_path, asset.file_path, context.upload_enabled) - ) - asset_id = result.asset.get("id") - if not isinstance(asset_id, str) or not asset_id: - raise server_shape_error("the data plane returned an asset without an id") - asset_ids[asset.marker] = asset_id - results.append(result) - disclosed.append(DisclosedAsset(asset.local_path, asset.file_path, size, bool(result.uploaded))) + upload_now = context.upload_enabled and approved is None + try: + result = context.client.resolve_asset( + AssetResolveRequest(asset.local_path, asset.file_path, upload_now, context.allowed_hashes) + ) + except DeployAssetMissingError as error: + if approved is not None and error.details["hash"] in approved: + to_upload.append((index, asset, size)) + continue + # Keep going, so the refusal names every file, not only the first. + missing.append(error.details) + continue + record(index, asset, size, result) + if missing: + raise _missing_error(missing) + for index, asset, size in to_upload: + try: + result = context.client.resolve_asset( + AssetResolveRequest(asset.local_path, asset.file_path, True, context.allowed_hashes) + ) + except DeployAssetMissingError as error: + # The file changed after the first pass and no longer has an approved hash. + raise _missing_error([error.details]) from error + record(index, asset, size, result) + ordered = [results[index] for index in sorted(results)] return ResolvedAssets( workflow=materialize_workflow_assets(plan, asset_ids), - uploaded=sum(result.uploaded for result in results), - deduped=sum(result.deduped for result in results), - bytes=sum(result.bytes for result in results), - files=tuple(disclosed), + uploaded=sum(result.uploaded for result, _ in ordered), + deduped=sum(result.deduped for result, _ in ordered), + bytes=sum(result.bytes for result, _ in ordered), + files=tuple(disclosed for _, disclosed in ordered), ) diff --git a/comfy_cli/deploy_assets.py b/comfy_cli/deploy_assets.py index c29e88ef6..209b30573 100644 --- a/comfy_cli/deploy_assets.py +++ b/comfy_cli/deploy_assets.py @@ -2,14 +2,18 @@ from __future__ import annotations +import errno import json import mimetypes import os +import shutil +import tempfile import urllib.error import urllib.parse import urllib.request import uuid from collections.abc import Iterator +from contextlib import contextmanager, suppress from dataclasses import dataclass, replace from pathlib import Path from typing import BinaryIO, Final @@ -51,9 +55,43 @@ @dataclass(frozen=True, slots=True) class AssetResolveRequest: + """One local file to turn into a data-plane asset. + + ``allowed_hashes`` is ``--allow-upload``: when set, a file the deployment + does not already hold is uploaded only if its hash is listed. A person + approves the exact files a ``--no-upload`` refusal listed, by hash, so a + same-named file from another root, or a file edited since, is refused + rather than sent. An approved upload reads one private snapshot, checked + against the approved hash, so a file rewritten during the probe or the + upload cannot send bytes nobody approved. + """ + local_path: Path file_path: str upload_enabled: bool = True + allowed_hashes: frozenset[str] | None = None + + +class DeployAssetMissingError(DeployAPIError): + """A file the deployment lacks, which this run may not upload. + + ``details`` names it in full (the absolute ``local_path``, its ``bytes`` + and ``hash``) so a refusal can serve as the exact upload plan to approve. + """ + + def __init__(self, request: AssetResolveRequest, expected_hash: str, size: int) -> None: + # ``local_path`` is always the file the scanner picked, never a snapshot. + reason = "uploads are disabled" if not request.upload_enabled else "its hash is not one --allow-upload names" + super().__init__( + code="deploy_asset_missing", + message=f"the asset is not already present and {reason}", + details={ + "file_path": request.file_path, + "hash": expected_hash, + "local_path": str(request.local_path), + "bytes": size, + }, + ) @dataclass(frozen=True, slots=True) @@ -240,15 +278,25 @@ def resolve_asset(self, request: AssetResolveRequest) -> AssetResolveResult: raise _invalid_response("mint", status) def _resolve_miss(self, request: AssetResolveRequest, expected_hash: str) -> AssetResolveResult: - if not request.upload_enabled: - raise DeployAPIError( - code="deploy_asset_missing", - message="the asset is not already present and uploads are disabled", - details={"file_path": request.file_path, "hash": expected_hash}, - ) + approved = request.allowed_hashes is None or expected_hash in request.allowed_hashes + if not request.upload_enabled or not approved: + raise DeployAssetMissingError(request, expected_hash, request.local_path.stat().st_size) + if request.allowed_hashes is None: + return self._upload(request, request.local_path, expected_hash) + # An approval binds bytes, not a path: the path can be rewritten after + # the hash above. Copy it once, check the copy, and send only the copy. + # The copy is made only here, on a miss, so a file Cloud already holds + # never needs temporary disk space. + with _snapshot(request) as snapshot: + snapshot_hash = blake3_file(snapshot) + if snapshot_hash != expected_hash: + raise DeployAssetMissingError(request, snapshot_hash, snapshot.stat().st_size) + return self._upload(request, snapshot, snapshot_hash) + + def _upload(self, request: AssetResolveRequest, source: Path, expected_hash: str) -> AssetResolveResult: # The handle stays open across the urlopen because urllib consumes the # body iterator lazily, after the request is built. - with request.local_path.open("rb") as file: + with source.open("rb") as file: upload, file_size = _multipart_request(self.target, request, expected_hash, file) try: with no_redirect_urlopen(upload, timeout=_UPLOAD_TIMEOUT) as response: @@ -269,3 +317,73 @@ def _resolve_miss(self, request: AssetResolveRequest, expected_hash: str) -> Ass if status in {200, 201} and isinstance(parsed, dict): return AssetResolveResult(asset=parsed, uploaded=1, deduped=0, bytes=file_size) raise _invalid_response("upload", status) + + +_SNAPSHOT_PREFIX = "comfy-cli-asset-" + + +def _snapshot_error(request: AssetResolveRequest, error: OSError) -> DeployAPIError: + """The copy could not be made (a full disk, say): a local failure, not the server's.""" + reason = error.strerror or str(error) + # Not ``tempfile.gettempdir()``: when no temp folder is usable, asking again + # raises the same error and this report never reaches the person. + copy = str(error.filename) if error.filename else "" + temp_dir = os.path.dirname(copy) if os.path.basename(copy).startswith(_SNAPSHOT_PREFIX) else tempfile.tempdir + return DeployAPIError( + code="deploy_asset_upload_failed", + message=f"could not copy {request.local_path} to a private temporary file to upload it: {reason}", + details={ + "file_path": request.file_path, + "local_path": str(request.local_path), + "temp_dir": temp_dir, + "reason": reason, + }, + hint=( + "this file was not uploaded, but approved files before it may already be on Comfy Cloud, and a " + "retry reuses them; free space in `details.temp_dir` or set TMPDIR to a folder with room, then retry" + ), + ) + + +def _require_free_space(snapshot: str, size: int) -> None: + """Refuse before copying when the temp folder cannot hold the whole file. + + The copy is as large as the file. Checking first fails a large file at once, + rather than after it has filled the disk. A folder that fills up during the + copy still fails the write, which reports the same way. A folder whose free + space cannot be read is not checked. + """ + try: + free = shutil.disk_usage(os.path.dirname(snapshot)).free + except OSError: + return + if free < size: + raise OSError(errno.ENOSPC, f"the copy needs {size:,} bytes and {free:,} are free", snapshot) + + +@contextmanager +def _snapshot(request: AssetResolveRequest) -> Iterator[Path]: + """A private copy of the request's file in the system temp folder, removed on every exit. + + ``mkstemp`` creates it readable by this user only. The ``comfy-cli-`` prefix + names the tool that left it, should a crash skip the ``finally``. A folder + without room for the whole file is refused before any byte is copied. A + failure to make the copy is reported as such, naming the file; an error + raised while the copy is in use passes through unchanged. + """ + try: + descriptor, name = tempfile.mkstemp(prefix=_SNAPSHOT_PREFIX) + except OSError as error: + raise _snapshot_error(request, error) from error + snapshot = Path(name) + try: + try: + with os.fdopen(descriptor, "wb") as copy, request.local_path.open("rb") as original: + _require_free_space(name, os.fstat(original.fileno()).st_size) + shutil.copyfileobj(original, copy, UPLOAD_CHUNK_BYTES) + except OSError as error: + raise _snapshot_error(request, error) from error + yield snapshot + finally: + with suppress(OSError): + snapshot.unlink(missing_ok=True) diff --git a/comfy_cli/error_codes.py b/comfy_cli/error_codes.py index 1e2590361..162466b12 100644 --- a/comfy_cli/error_codes.py +++ b/comfy_cli/error_codes.py @@ -2022,15 +2022,21 @@ class ErrorCode: ErrorCode( "deploy_asset_missing", "An input the run needs is not an asset this account can reach. Either a v2 asset hash probe found " - "no blob the caller may mint from while uploads were disabled (`details.file_path` and `details.hash` " - "identify it), or the submitted workflow referenced an asset id the account cannot mint, which the " - "server reports as `missing_asset` in `details.server_code`.", - "remove `--no-upload` to permit a streamed upload, or upload the input before retrying", + "no blob the caller may mint from while uploads were disabled by `--no-upload` or not allowed by " + "`--allow-upload` (`details.missing[]` names every such file with its absolute `local_path`, `bytes` " + "and `hash`; `details.file_path` and `details.hash` repeat the first), or the submitted workflow " + "referenced an asset id the account cannot mint, which the server reports as `missing_asset` in " + "`details.server_code`.", + "approve the files in `details.missing[]` and rerun with `--allow-upload ` for each, remove " + "`--no-upload` to permit any upload, or upload the input before retrying", ), ErrorCode( "deploy_asset_upload_failed", "A v2 multipart asset upload failed or the server rejected its `expected_hash`. A hash mismatch " - "mints no asset and reports `hash_mismatch` in `details.server_code`.", + "mints no asset and reports `hash_mismatch` in `details.server_code`. With `--allow-upload`, it also " + "covers a private temporary copy of the file that could not be made (a full disk, say): " + "`details.local_path` names the file and `details.temp_dir` the folder. That file was not uploaded; " + "approved files before it may already be, and a retry reuses them.", "verify the local file is stable and readable, then retry the upload", ), # --- knowledge ----------------------------------------------------------- diff --git a/comfy_cli/skills/comfy-deploy-failures/SKILL.md b/comfy_cli/skills/comfy-deploy-failures/SKILL.md index f0f68c1dc..732511700 100644 --- a/comfy_cli/skills/comfy-deploy-failures/SKILL.md +++ b/comfy_cli/skills/comfy-deploy-failures/SKILL.md @@ -69,8 +69,8 @@ argument you pass. | `deploy_workflow_too_large` | Over the 10 MB a deployment accepts; the job was not submitted | Move large inline data (embedded images, long text) out of the workflow, resubmit | | `deploy_workflow_asset_outside_root` | A local input resolves outside every allowed root | Move it under `models/`, `input/`, `output/`, or pass `--asset-root ` | | `deploy_workflow_asset_marker_reserved` | The workflow already claims a `local-asset:` id | Remove that reserved id | -| `deploy_asset_missing` | An asset needs uploading and `--no-upload` was set | Drop `--no-upload`, or pre-upload it | -| `deploy_asset_upload_failed` | Upload failed or the hash moved mid-read | Confirm the file is stable, retry | +| `deploy_asset_missing` | An asset needs uploading and `--no-upload` was set, or its hash is not one `--allow-upload` names | `details.missing[]` lists each file: `local_path`, `bytes`, `hash`. Rerun with `--allow-upload ` per approved file, drop `--no-upload`, or pre-upload it | +| `deploy_asset_upload_failed` | Upload failed or the hash moved mid-read, or with `--allow-upload` the private temporary copy of the file could not be made (a full disk, say; `details.temp_dir` names the folder; that file was not uploaded, though approved files before it may be, and a retry reuses them) | Confirm the file is stable, retry. For a failed copy, free space in `details.temp_dir` or set `TMPDIR` to a folder with room, then retry | | `deploy_rate_limited` | Queue full or rate limited | Wait for capacity | | `deploy_idempotency_reuse` | That idempotency key was already used | The earlier submit landed; say so rather than resubmitting | | `deploy_job_submit_unknown` | Submit timed out and the job **may exist** | **Do not auto-resubmit.** The CLI cannot look the job up — ask the user | diff --git a/comfy_cli/skills/comfy-deploy/SKILL.md b/comfy_cli/skills/comfy-deploy/SKILL.md index df9b5dbab..7772bbe32 100644 --- a/comfy_cli/skills/comfy-deploy/SKILL.md +++ b/comfy_cli/skills/comfy-deploy/SKILL.md @@ -329,6 +329,7 @@ comfy deploy cancel [PATH] [--deployment ] comfy deploy run [PATH] --workflow .json [--output-dir outputs] [--timeout ] [--no-wait] [--no-upload] [--asset-root ] + [--allow-upload ...] ``` - **API format only.** A UI-format export (the one with `nodes` and `links`) is @@ -354,6 +355,9 @@ comfy deploy run [PATH] --workflow .json `uploaded`/`deduped`/`bytes` totals never name a filename. A user who is about to send files off their machine is owed that list. `--no-upload` turns a needed upload into `deploy_asset_missing` instead, for when nothing may leave the box. + Its `details.missing[]` lists every file it would have sent: the absolute + `local_path`, `bytes` and `hash`. `--allow-upload ` (repeatable) then + uploads only those exact files; any other file fails the same way. - **It waits and downloads by default.** Outputs land in `./outputs/` unless `--output-dir` says otherwise, and each is reported with its `node_id`, `name`, `type` and `path`. `--no-wait` returns the job id immediately instead. diff --git a/comfy_cli/tracking.py b/comfy_cli/tracking.py index 5cbf83743..09342ca89 100644 --- a/comfy_cli/tracking.py +++ b/comfy_cli/tracking.py @@ -125,6 +125,8 @@ def _resolve_posthog_token() -> str: # `workflow add-node --text`: a note body is verbatim user content, like # `--prompt` — analytics only learns that the option was supplied. "text", + # `deploy run --allow-upload` names the hashes of a person's own files. + "allow_upload", # `model upload --workspace` names a Comfy Cloud workspace, which can # identify a customer; `--expected-sha256` names one of their files. # The kwarg is `workspace_id`, not `workspace`, so `deploy --workspace` diff --git a/tests/comfy_cli/command/test_deploy_run.py b/tests/comfy_cli/command/test_deploy_run.py index c67768daf..ebd8e82cc 100644 --- a/tests/comfy_cli/command/test_deploy_run.py +++ b/tests/comfy_cli/command/test_deploy_run.py @@ -1,7 +1,11 @@ from __future__ import annotations import copy +import http.client +import io import json +import urllib.error +import urllib.request from pathlib import Path from types import SimpleNamespace @@ -15,12 +19,13 @@ from comfy_cli import deploy_jobs from comfy_cli.cmdline import app -from comfy_cli.command import deploy, deploy_run +from comfy_cli.command import deploy, deploy_run, deploy_workflow from comfy_cli.command.build_spec import JsonObject, JsonValue from comfy_cli.deploy_assets import AssetResolveRequest, AssetResolveResult from comfy_cli.deploy_events import JobWatchResult from comfy_cli.deploy_jobs import JobSubmitRequest from comfy_cli.discovery import COMMAND_SCHEMAS +from comfy_cli.hashing import blake3_file from comfy_cli.target import Target SCHEMAS_DIR = Path(__file__).parent.parent.parent.parent / "comfy_cli" / "schemas" @@ -189,6 +194,7 @@ def test_deploy_run_is_registered_with_the_complete_option_surface() -> None: "--timeout", "--no-upload", "--asset-root", + "--allow-upload", } <= option_names("run") @@ -697,3 +703,267 @@ def interrupted_watch(*_args, **_kwargs): assert result.exit_code == 130, result.stdout assert cancels == ["cloud-secret"] assert envelope_error(result)["details"] == {"job_id": "job-1", "cancel_requested": True} + + +# --- the upload plan a person approves --------------------------------------- + + +def two_portraits(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> tuple[Path, Path, Path]: + """A Build folder (the cwd) and the tracked workspace each hold a different + `portrait.png`. The Build folder also holds `customer.csv`, which a custom + node names as `input/customer.csv`. Returns the Build folder, the workspace + and the API workflow.""" + build = tmp_path / "build" + (build / "input").mkdir(parents=True) + (build / "comfy-build.yaml").write_text("schema: build-spec/1\n", encoding="utf-8") + (build / "input" / "portrait.png").write_bytes(b"build portrait") + (build / "input" / "customer.csv").write_bytes(b"name,email\n") + workspace = tmp_path / "workspace" + (workspace / "input").mkdir(parents=True) + (workspace / "input" / "portrait.png").write_bytes(b"workspace portrait") + + class TrackedWorkspace: + workspace_path = str(workspace) + + monkeypatch.setattr(deploy_workflow, "WorkspaceManager", TrackedWorkspace) + monkeypatch.chdir(build) + workflow = tmp_path / "api.json" + workflow.write_text( + json.dumps( + { + "1": {"class_type": "LoadImage", "inputs": {"image": "portrait.png"}}, + "2": {"class_type": "CustomerLookup", "inputs": {"table": "input/customer.csv"}}, + } + ), + encoding="utf-8", + ) + return build, workspace, workflow + + +def deployment_holds_nothing(monkeypatch: pytest.MonkeyPatch, job_client: FakeJobClient) -> list[str]: + """Run against the real asset client, whose every hash probe misses. + + Returns the names of the files it uploads; each upload answers with a new asset. + """ + control = FakeControl("https://dep-id.run.comfy.app") + monkeypatch.setattr(deploy_run, "_command_clients", lambda: (FakeBuilder(), control)) + monkeypatch.setattr(deploy_run, "DeployJobClient", lambda *_args, **_kwargs: job_client) + + def probe(url: str, *_args, **_kwargs): + raise urllib.error.HTTPError(url, 404, "not found", http.client.HTTPMessage(), io.BytesIO(b"")) + + uploaded: list[str] = [] + + class Created: + status = 201 + + def __init__(self, request: urllib.request.Request) -> None: + body = request.data + assert body is not None and not isinstance(body, bytes) + chunks = b"".join(body) # type: ignore[arg-type] + uploaded.append(chunks.split(b'filename="', 1)[1].split(b'"', 1)[0].decode()) + self._body = io.BytesIO(json.dumps({"id": f"asset-{len(uploaded)}"}).encode()) + + def __enter__(self) -> Created: + return self + + def __exit__(self, *_args) -> None: + return None + + def read(self, amount: int = -1) -> bytes: + return self._body.read(amount) + + monkeypatch.setattr("comfy_cli.deploy_assets.request_json", probe) + monkeypatch.setattr("comfy_cli.deploy_assets.no_redirect_urlopen", lambda request, *, timeout: Created(request)) + return uploaded + + +def test_a_no_upload_refusal_lists_the_file_the_scanner_picked_by_full_path( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + """Given two different `portrait.png` files, When a `--no-upload` run refuses, + Then it lists every file it would send, with the full path it picked: the + Build folder's `portrait.png`, not the workspace's, and the custom node's + `customer.csv`. This list is what a person approves.""" + # Given + build, _workspace, workflow = two_portraits(tmp_path, monkeypatch) + job_client = FakeJobClient(job()) + uploaded = deployment_holds_nothing(monkeypatch, job_client) + portrait = (build / "input" / "portrait.png").resolve() + customers = (build / "input" / "customer.csv").resolve() + + # When + result = invoke(workflow, "--deployment", "dep-id", "--no-upload") + + # Then + assert result.exit_code == 1, result.stdout + error = envelope_error(result) + assert error["code"] == "deploy_asset_missing" + details = error["details"] + assert isinstance(details, dict) + assert details["missing"] == [ + {"file_path": "portrait.png", "hash": blake3_file(portrait), "local_path": str(portrait), "bytes": 14}, + {"file_path": "customer.csv", "hash": blake3_file(customers), "local_path": str(customers), "bytes": 11}, + ] + assert uploaded == [] + assert job_client.requests == [] + + +def test_allow_upload_sends_only_the_approved_bytes(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: + """Given a person approved the workspace's `portrait.png`, When the run picks + the Build folder's one instead, Then nothing is uploaded and the refusal + names the file it picked. Approving the listed hashes uploads exactly those.""" + # Given + build, workspace, workflow = two_portraits(tmp_path, monkeypatch) + job_client = FakeJobClient(job()) + uploaded = deployment_holds_nothing(monkeypatch, job_client) + portrait = (build / "input" / "portrait.png").resolve() + customers = (build / "input" / "customer.csv").resolve() + wrong = blake3_file(workspace / "input" / "portrait.png") + + # When the approval names the other portrait + refused = invoke(workflow, "--deployment", "dep-id", "--no-wait", "--allow-upload", wrong) + + # Then + assert refused.exit_code == 1, refused.stdout + details = envelope_error(refused)["details"] + assert isinstance(details, dict) + missing = details["missing"] + assert isinstance(missing, list) + assert [entry["local_path"] for entry in missing if isinstance(entry, dict)] == [str(portrait), str(customers)] + assert uploaded == [] + assert job_client.requests == [] + + # When the approval names the plan the refusal listed + allowed = invoke( + workflow, + "--deployment", + "dep-id", + "--no-wait", + "--allow-upload", + blake3_file(portrait), + "--allow-upload", + blake3_file(customers), + ) + + # Then + assert allowed.exit_code == 0, allowed.stdout + assert uploaded == ["portrait.png", "customer.csv"] + assets = envelope_data(allowed)["assets"] + assert isinstance(assets, dict) + files = assets["files"] + assert isinstance(files, list) + assert [entry["local_path"] for entry in files if isinstance(entry, dict)] == [str(portrait), str(customers)] + assert len(job_client.requests) == 1 + + +def test_a_refused_later_file_fails_the_run_before_an_earlier_approved_one_is_sent( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + """Given a person approved only the first of two missing files, When the + second is refused, Then the run fails before anything is uploaded, so the + deployment is not left holding an approved file no job uses.""" + # Given + build, _workspace, workflow = two_portraits(tmp_path, monkeypatch) + job_client = FakeJobClient(job()) + uploaded = deployment_holds_nothing(monkeypatch, job_client) + portrait = (build / "input" / "portrait.png").resolve() + customers = (build / "input" / "customer.csv").resolve() + + # When + result = invoke(workflow, "--deployment", "dep-id", "--no-wait", "--allow-upload", blake3_file(portrait)) + + # Then + assert result.exit_code == 1, result.stdout + error = envelope_error(result) + assert error["code"] == "deploy_asset_missing" + details = error["details"] + assert isinstance(details, dict) + missing = details["missing"] + assert isinstance(missing, list) + assert [entry["local_path"] for entry in missing if isinstance(entry, dict)] == [str(customers)] + assert uploaded == [] + assert job_client.requests == [] + + +def test_a_failed_copy_of_a_later_file_does_not_claim_nothing_was_uploaded( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + """Given two approved files, When the first uploads and the temp folder has + no room left to copy the second, Then the run fails naming the second file, + and the hint does not tell the person nothing was uploaded.""" + # Given + build, _workspace, workflow = two_portraits(tmp_path, monkeypatch) + job_client = FakeJobClient(job()) + uploaded = deployment_holds_nothing(monkeypatch, job_client) + portrait = (build / "input" / "portrait.png").resolve() + customers = (build / "input" / "customer.csv").resolve() + room = iter([100, 0]) + + def room_for_the_first_copy_only(_folder: str) -> SimpleNamespace: + free = next(room) + return SimpleNamespace(total=100, used=100 - free, free=free) + + monkeypatch.setattr("comfy_cli.deploy_assets.shutil.disk_usage", room_for_the_first_copy_only) + + # When + result = invoke( + workflow, + "--deployment", + "dep-id", + "--no-wait", + "--allow-upload", + blake3_file(portrait), + "--allow-upload", + blake3_file(customers), + ) + + # Then + assert result.exit_code == 1, result.stdout + error = envelope_error(result) + assert error["code"] == "deploy_asset_upload_failed" + details = error["details"] + assert isinstance(details, dict) + assert details["local_path"] == str(customers) + assert uploaded == ["portrait.png"] + hint = error["hint"] + assert isinstance(hint, str) + assert "nothing was uploaded" not in hint + assert "before it may already be on Comfy Cloud" in hint + assert job_client.requests == [] + + +def test_an_approved_upload_reports_the_bytes_it_sent(tmp_path: Path) -> None: + """Given an approved file that is replaced by other approved bytes after the + probe, When it uploads, Then `assets.files[].bytes` is what was sent, not + the size read before the probe.""" + from comfy_cli.command import deploy_run_assets + from comfy_cli.deploy_assets import DeployAssetMissingError + + # Given + portrait = tmp_path / "portrait.png" + portrait.write_bytes(b"abc") + plan = deploy_workflow.WorkflowAssetPlan( + workflow={"1": {"inputs": {"image": "marker-1"}}}, + assets=(deploy_workflow.WorkflowAsset("marker-1", portrait, "portrait.png"),), + ) + + class ProbeThenUpload: + def resolve_asset(self, request: AssetResolveRequest) -> AssetResolveResult: + if not request.upload_enabled: + raise DeployAssetMissingError(request, "hash-a", 3) + return AssetResolveResult(asset={"id": "asset-1"}, uploaded=1, deduped=0, bytes=7) + + context = deploy_run_assets.AssetResolveContext( + client=ProbeThenUpload(), # type: ignore[arg-type] + renderer=SimpleNamespace(is_pretty=lambda: False), # type: ignore[arg-type] + upload_enabled=True, + allowed_hashes=frozenset({"hash-a", "hash-b"}), + ) + + # When + resolved = deploy_run_assets.resolve_assets(plan, context) + + # Then + assert [file.bytes for file in resolved.files] == [7] + assert resolved.bytes == 7 diff --git a/tests/comfy_cli/skills/test_installer.py b/tests/comfy_cli/skills/test_installer.py index abdac55b6..b04ddb104 100644 --- a/tests/comfy_cli/skills/test_installer.py +++ b/tests/comfy_cli/skills/test_installer.py @@ -464,6 +464,21 @@ def test_comfy_deploy_skill_covers_the_deploy_group(): assert needle in text, f"comfy-deploy skill should mention {needle}" +def test_deploy_skills_describe_approved_uploads(): + """`deploy run --allow-upload` is in the usage block an agent copies from, + and the failure table names the other cause of `deploy_asset_upload_failed`: + the private temporary copy of an approved file could not be made.""" + usage = skill_content("comfy-deploy").split("## `comfy deploy run`", 1)[1].split("```", 2)[1] + assert "[--allow-upload ...]" in usage + row = next( + line + for line in skill_content("comfy-deploy-failures").splitlines() + if line.startswith("| `deploy_asset_upload_failed` |") + ) + assert "temporary copy" in row + assert "details.temp_dir" in row + + def test_build_and_deploy_skills_hand_off_to_each_other(): """Splitting one skill in two only works if each names the other. diff --git a/tests/comfy_cli/test_deploy_assets.py b/tests/comfy_cli/test_deploy_assets.py index 94849ab3f..6bd62cb05 100644 --- a/tests/comfy_cli/test_deploy_assets.py +++ b/tests/comfy_cli/test_deploy_assets.py @@ -1,12 +1,15 @@ from __future__ import annotations +import errno import http.client import io import json +import tempfile import urllib.error import urllib.request from collections.abc import Iterator from pathlib import Path +from types import SimpleNamespace from typing import Protocol, TypeAlias, runtime_checkable import pytest @@ -118,8 +121,12 @@ def _http_error(status: int, code: str) -> urllib.error.HTTPError: ) -def _request(path: Path, *, upload_enabled: bool = True) -> AssetResolveRequest: - return AssetResolveRequest(local_path=path, file_path="inputs/input.png", upload_enabled=upload_enabled) +def _request( + path: Path, *, upload_enabled: bool = True, allowed_hashes: frozenset[str] | None = None +) -> AssetResolveRequest: + return AssetResolveRequest( + local_path=path, file_path="inputs/input.png", upload_enabled=upload_enabled, allowed_hashes=allowed_hashes + ) def test_dedupe_hit_issues_head_then_from_hash_and_constructs_no_multipart(tmp_path, monkeypatch): @@ -246,3 +253,337 @@ def multipart_tripwire(*_args, **_kwargs): # Then assert exc_info.value.code == "deploy_asset_missing" assert events == [("HEAD", f"{_BASE_URL}/api/v2/assets/by-hash/{_HASH.replace(':', '%3A')}")] + + +def test_no_upload_miss_names_the_full_local_path_and_size(tmp_path, monkeypatch): + # Given + path = tmp_path / "input.png" + path.write_bytes(b"abc") + monkeypatch.setattr( + "comfy_cli.deploy_assets.request_json", + _JsonTransport([], _http_error(404, "blob_not_found")), + ) + + # When + with pytest.raises(DeployAPIError) as exc_info: + DeployAssetClient(_BASE_URL, "jwt-token").resolve_asset(_request(path, upload_enabled=False)) + + # Then + assert exc_info.value.details == { + "file_path": "inputs/input.png", + "hash": _HASH, + "local_path": str(path), + "bytes": 3, + } + + +def test_a_miss_whose_hash_was_not_allowed_is_refused_without_multipart(tmp_path, monkeypatch): + # Given a person approved other bytes than these + path = tmp_path / "input.png" + path.write_bytes(b"abc") + events: list[tuple[str, str]] = [] + monkeypatch.setattr( + "comfy_cli.deploy_assets.request_json", + _JsonTransport(events, _http_error(404, "blob_not_found")), + ) + + def multipart_tripwire(*_args, **_kwargs): + raise AssertionError("an unapproved file constructed a multipart request") + + monkeypatch.setattr("comfy_cli.deploy_assets._multipart_request", multipart_tripwire) + + # When + with pytest.raises(DeployAPIError) as exc_info: + DeployAssetClient(_BASE_URL, "jwt-token").resolve_asset( + _request(path, allowed_hashes=frozenset({"blake3:" + "0" * 64})) + ) + + # Then + assert exc_info.value.code == "deploy_asset_missing" + assert exc_info.value.details["local_path"] == str(path) + assert exc_info.value.details["hash"] == _HASH + assert events == [("HEAD", f"{_BASE_URL}/api/v2/assets/by-hash/{_HASH.replace(':', '%3A')}")] + + +def test_a_miss_whose_hash_was_allowed_still_uploads(tmp_path, monkeypatch): + # Given + path = tmp_path / "input.png" + path.write_bytes(b"abc") + events: list[tuple[str, str]] = [] + monkeypatch.setattr( + "comfy_cli.deploy_assets.request_json", + _JsonTransport(events, _http_error(404, "blob_not_found")), + ) + monkeypatch.setattr("comfy_cli.deploy_assets.no_redirect_urlopen", _MultipartTransport(events)) + + # When + result = DeployAssetClient(_BASE_URL, "jwt-token").resolve_asset(_request(path, allowed_hashes=frozenset({_HASH}))) + + # Then + assert events[-1] == ("POST", f"{_BASE_URL}/api/v2/assets") + assert (result.uploaded, result.deduped, result.bytes) == (1, 0, 3) + + +def test_an_approved_file_rewritten_during_the_probe_is_refused_with_the_new_hash(tmp_path, monkeypatch): + """Given an approved file, When it is rewritten while the hash probe is out, + Then the snapshot taken on the miss holds the new bytes, its hash is not the + approved one, nothing is sent, and the snapshot is gone.""" + # Given + path = tmp_path / "input.png" + path.write_bytes(b"abc") + private = tmp_path / "tmp" + private.mkdir() + monkeypatch.setattr(tempfile, "tempdir", str(private)) + + def probe_then_rewrite(url: str, *_args, **_kwargs): + path.write_bytes(b"replaced while the probe was out") + raise _http_error(404, "blob_not_found") + + def multipart_tripwire(*_args, **_kwargs): + raise AssertionError("rewritten bytes constructed a multipart request") + + monkeypatch.setattr("comfy_cli.deploy_assets.request_json", probe_then_rewrite) + monkeypatch.setattr("comfy_cli.deploy_assets._multipart_request", multipart_tripwire) + + # When + with pytest.raises(DeployAPIError) as exc_info: + DeployAssetClient(_BASE_URL, "jwt-token").resolve_asset(_request(path, allowed_hashes=frozenset({_HASH}))) + + # Then + assert exc_info.value.code == "deploy_asset_missing" + assert exc_info.value.details["hash"] != _HASH + assert exc_info.value.details["bytes"] == len(b"replaced while the probe was out") + assert list(private.iterdir()) == [] + + +def test_an_approved_file_rewritten_during_the_upload_sends_only_the_approved_bytes(tmp_path, monkeypatch): + """Given an approved file, When it is rewritten after the snapshot is taken, + Then the upload streams the approved bytes from the snapshot, never the new + ones, and the snapshot is gone afterwards.""" + # Given + path = tmp_path / "input.png" + path.write_bytes(b"abc") + private = tmp_path / "tmp" + private.mkdir() + monkeypatch.setattr(tempfile, "tempdir", str(private)) + events: list[tuple[str, str]] = [] + multipart = _MultipartTransport(events) + + def rewrite_then_send(request: urllib.request.Request, *, timeout: float) -> _Response: + path.write_bytes(b"replaced before the body was read") + return multipart(request, timeout=timeout) + + monkeypatch.setattr( + "comfy_cli.deploy_assets.request_json", + _JsonTransport(events, _http_error(404, "blob_not_found")), + ) + monkeypatch.setattr("comfy_cli.deploy_assets.no_redirect_urlopen", rewrite_then_send) + + # When + result = DeployAssetClient(_BASE_URL, "jwt-token").resolve_asset(_request(path, allowed_hashes=frozenset({_HASH}))) + + # Then + body = b"".join(multipart.chunks) + assert b"replaced before the body was read" not in body + assert b"\r\n\r\nabc\r\n--" in body + assert (result.uploaded, result.bytes) == (1, 3) + assert list(private.iterdir()) == [] + + +def test_an_asset_cloud_already_holds_makes_no_temporary_copy(tmp_path, monkeypatch): + """Given `--allow-upload`, When Cloud already holds the bytes, Then the asset + is minted from its hash and no temporary copy is made, so a large file needs + no temporary disk space.""" + # Given + path = tmp_path / "input.png" + path.write_bytes(b"abc") + monkeypatch.setattr("comfy_cli.deploy_assets.request_json", _JsonTransport([], (200, None), (201, _ASSET))) + + def mkstemp_tripwire(*_args, **_kwargs): + raise AssertionError("an asset Cloud already holds made a temporary copy") + + monkeypatch.setattr(tempfile, "mkstemp", mkstemp_tripwire) + + # When + result = DeployAssetClient(_BASE_URL, "jwt-token").resolve_asset(_request(path, allowed_hashes=frozenset({_HASH}))) + + # Then + assert (result.uploaded, result.deduped) == (0, 1) + + +def test_a_snapshot_that_cannot_be_written_is_a_local_error_naming_the_file(tmp_path, monkeypatch): + """Given an approved upload, When the temporary copy cannot be written (a + full disk), Then the error names the file and the temp folder, is not a + server error, nothing is sent, and the partial copy is gone.""" + # Given + path = tmp_path / "input.png" + path.write_bytes(b"abc") + private = tmp_path / "tmp" + private.mkdir() + monkeypatch.setattr(tempfile, "tempdir", str(private)) + monkeypatch.setattr( + "comfy_cli.deploy_assets.request_json", + _JsonTransport([], _http_error(404, "blob_not_found")), + ) + + def disk_full(*_args, **_kwargs): + raise OSError(errno.ENOSPC, "No space left on device") + + def multipart_tripwire(*_args, **_kwargs): + raise AssertionError("a failed snapshot constructed a multipart request") + + monkeypatch.setattr("comfy_cli.deploy_assets.shutil.copyfileobj", disk_full) + monkeypatch.setattr("comfy_cli.deploy_assets._multipart_request", multipart_tripwire) + + # When + with pytest.raises(DeployAPIError) as exc_info: + DeployAssetClient(_BASE_URL, "jwt-token").resolve_asset(_request(path, allowed_hashes=frozenset({_HASH}))) + + # Then + error = exc_info.value + assert error.code == "deploy_asset_upload_failed" + assert str(path) in str(error) + assert error.details["local_path"] == str(path) + assert error.details["temp_dir"] == str(private) + assert error.details["reason"] == "No space left on device" + assert list(private.iterdir()) == [] + + +def test_no_usable_temp_folder_is_still_reported_as_a_local_failure(tmp_path: Path, monkeypatch: pytest.MonkeyPatch): + """Given an approved upload Cloud lacks and no temp folder Python can use (a + full disk before one was ever chosen), When it is resolved, Then the error is + the local copy failure naming the file, not an OSError the run reports as a + server error.""" + # Given + path = tmp_path / "input.png" + path.write_bytes(b"abc") + monkeypatch.setattr(tempfile, "tempdir", None) + monkeypatch.setattr( + "comfy_cli.deploy_assets.request_json", + _JsonTransport([], _http_error(404, "blob_not_found")), + ) + + def no_temp_folder(*_args, **_kwargs): + raise FileNotFoundError(errno.ENOENT, "No usable temporary directory found") + + monkeypatch.setattr("comfy_cli.deploy_assets.tempfile.mkstemp", no_temp_folder) + monkeypatch.setattr("comfy_cli.deploy_assets.tempfile.gettempdir", no_temp_folder) + + # When + with pytest.raises(DeployAPIError) as exc_info: + DeployAssetClient(_BASE_URL, "jwt-token").resolve_asset(_request(path, allowed_hashes=frozenset({_HASH}))) + + # Then + error = exc_info.value + assert error.code == "deploy_asset_upload_failed" + assert error.details["local_path"] == str(path) + assert error.details["temp_dir"] is None + + +def test_a_temp_folder_without_room_for_the_copy_is_refused_before_copying(tmp_path, monkeypatch): + """Given an approved upload Cloud lacks, When the temp folder has less free + space than the file, Then no byte is copied, nothing is sent, the error is + the local copy failure naming the file, the folder and both sizes, and the + empty copy is gone.""" + # Given + path = tmp_path / "input.png" + path.write_bytes(b"abc") + private = tmp_path / "tmp" + private.mkdir() + monkeypatch.setattr(tempfile, "tempdir", str(private)) + monkeypatch.setattr( + "comfy_cli.deploy_assets.request_json", + _JsonTransport([], _http_error(404, "blob_not_found")), + ) + checked: list[str] = [] + + def two_bytes_free(folder: str) -> SimpleNamespace: + checked.append(folder) + return SimpleNamespace(total=100, used=98, free=2) + + def copy_tripwire(*_args, **_kwargs): + raise AssertionError("a temp folder without room started the copy") + + def multipart_tripwire(*_args, **_kwargs): + raise AssertionError("a refused copy constructed a multipart request") + + monkeypatch.setattr("comfy_cli.deploy_assets.shutil.disk_usage", two_bytes_free) + monkeypatch.setattr("comfy_cli.deploy_assets.shutil.copyfileobj", copy_tripwire) + monkeypatch.setattr("comfy_cli.deploy_assets._multipart_request", multipart_tripwire) + + # When + with pytest.raises(DeployAPIError) as exc_info: + DeployAssetClient(_BASE_URL, "jwt-token").resolve_asset(_request(path, allowed_hashes=frozenset({_HASH}))) + + # Then + error = exc_info.value + assert error.code == "deploy_asset_upload_failed" + assert str(path) in str(error) + assert checked == [str(private)] + assert error.details["local_path"] == str(path) + assert error.details["temp_dir"] == str(private) + assert error.details["reason"] == "the copy needs 3 bytes and 2 are free" + assert list(private.iterdir()) == [] + + +def test_a_temp_folder_whose_free_space_cannot_be_read_still_uploads(tmp_path, monkeypatch): + """Given an approved upload Cloud lacks, When the temp folder's free space + cannot be read, Then the copy is made and sent as before; a write that fails + still reports the local copy failure.""" + # Given + path = tmp_path / "input.png" + path.write_bytes(b"abc") + private = tmp_path / "tmp" + private.mkdir() + monkeypatch.setattr(tempfile, "tempdir", str(private)) + events: list[tuple[str, str]] = [] + monkeypatch.setattr( + "comfy_cli.deploy_assets.request_json", + _JsonTransport(events, _http_error(404, "blob_not_found")), + ) + monkeypatch.setattr("comfy_cli.deploy_assets.no_redirect_urlopen", _MultipartTransport(events)) + + def unreadable(_folder: str) -> SimpleNamespace: + raise OSError(errno.ENOSYS, "Function not implemented") + + monkeypatch.setattr("comfy_cli.deploy_assets.shutil.disk_usage", unreadable) + + # When + result = DeployAssetClient(_BASE_URL, "jwt-token").resolve_asset(_request(path, allowed_hashes=frozenset({_HASH}))) + + # Then + assert events[-1] == ("POST", f"{_BASE_URL}/api/v2/assets") + assert (result.uploaded, result.bytes) == (1, 3) + assert list(private.iterdir()) == [] + + +def test_an_approved_path_now_holding_other_bytes_is_refused_with_their_hash(tmp_path, monkeypatch): + """Given a hash approved for `abc`, When the file now holds other bytes, + Then nothing is sent, the refusal names the new hash so the person can be + asked again, and the snapshot is gone.""" + # Given + path = tmp_path / "input.png" + path.write_bytes(b"other bytes") + private = tmp_path / "tmp" + private.mkdir() + monkeypatch.setattr(tempfile, "tempdir", str(private)) + monkeypatch.setattr( + "comfy_cli.deploy_assets.request_json", + _JsonTransport([], _http_error(404, "blob_not_found")), + ) + + def multipart_tripwire(*_args, **_kwargs): + raise AssertionError("a file holding unapproved bytes constructed a multipart request") + + monkeypatch.setattr("comfy_cli.deploy_assets._multipart_request", multipart_tripwire) + + # When + with pytest.raises(DeployAPIError) as exc_info: + DeployAssetClient(_BASE_URL, "jwt-token").resolve_asset(_request(path, allowed_hashes=frozenset({_HASH}))) + + # Then + assert exc_info.value.code == "deploy_asset_missing" + assert exc_info.value.details["local_path"] == str(path) + assert exc_info.value.details["bytes"] == len(b"other bytes") + assert exc_info.value.details["hash"] != _HASH + assert list(private.iterdir()) == [] diff --git a/tests/comfy_cli/test_tracking.py b/tests/comfy_cli/test_tracking.py index 5f49d4b70..83eb30012 100644 --- a/tests/comfy_cli/test_tracking.py +++ b/tests/comfy_cli/test_tracking.py @@ -546,6 +546,20 @@ def context(repository, commit, file): assert "private" not in str(properties) assert "a-secret-sha" not in str(properties) + def test_deploy_run_allowed_upload_hashes_are_redacted(self, tracking_module): + tracking_module.config_manager.set(constants.CONFIG_KEY_ENABLE_TRACKING, "True") + + @tracking_module.track_command("deploy") + def run(allow_upload=None, no_upload=False): + return None + + run(allow_upload=["a-private-hash", "https://example.com/?token=private"], no_upload=True) + + _, _, properties = _first_track_call(tracking_module.provider) + assert properties["allow_upload"] == "" + assert properties["no_upload"] is True + assert "private" not in str(properties) + def test_model_upload_workspace_and_hash_are_redacted(self, tracking_module): tracking_module.config_manager.set(constants.CONFIG_KEY_ENABLE_TRACKING, "True")