diff --git a/CHANGELOG.md b/CHANGELOG.md index cb5d95528..57c896ff8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,8 @@ history. ### Fixed +- `comfy build push --dry-run` now runs the push's registry-pin check, so a pin the builder cannot place fails the dry run with the push's own `build_registry_pin_missing` error instead of passing it. A version the registry has Flagged was the common case: the dry run passed, and the push was refused only after the plan had been disclosed. The check asks the builder's snapshot importer to place each public pack, a read that writes nothing, and the dry run still uploads and saves nothing. The `--json` payload of a push and a dry run carries `public_pins_checked`, the number of public pins the builder placed (0 when the spec has none and the builder was not asked), so a script can tell a checked pin set from a spec with nothing to check. A spec that pins a public pack now needs sign-in for its dry run (`build_not_signed_in` otherwise); a spec whose packs are all local still sends no request. Push and dry run also refuse when the registry did not answer for a pack (the importer's `unverifiedPins`), instead of treating the unchecked pin as resolved; refuse with `build_spec_invalid`, before sending anything, a `repository` that is not a public GitHub address (`https://github.com//`, `git@github.com:/.git` or `ssh://git@github.com//`), so one that carries a user name or token, does not parse, or names another host never leaves the machine; and report a builder response that times out or drops mid-body as `build_builder_error` instead of an internal error. + - Parallel build and deploy requests rejected on an old access token now adopt a peer's refreshed token under the shared refresh lock instead of rotating it again. Each rejected request retries at most once. If session recovery still fails while a refreshable sign-in remains stored, the watch reports that the remote work may continue instead of telling you to sign in again. `comfy build release create --watch`, `comfy deploy up`, `promote`, `rollback` and `comfy deploy status --watch` now end with the new code `watch_auth_lost` and exit code 75, as `deploy_watch_lost` does. Its hint names the command that reads the release or deployment again. A 401 before anything was accepted, on a workspace API key, or when no refreshable sign-in remains still reports `build_not_signed_in` or `deploy_not_signed_in`. - `comfy update` no longer dies with a `FileNotFoundError` traceback when the diff --git a/comfy_cli/command/build.py b/comfy_cli/command/build.py index 147ff225c..16421a736 100644 --- a/comfy_cli/command/build.py +++ b/comfy_cli/command/build.py @@ -1879,6 +1879,97 @@ def _write_spec(renderer, path: Path, spec: dict) -> None: raise typer.Exit(code=1) from error +def _repository_is_sendable(repository: str) -> bool: + """Whether the pin check may send this ``repository``: only a public GitHub + form that ``_canonical_github_repository`` recognizes (``https://github.com/org/repo``, + ``git@github.com:org/repo.git`` or ``ssh://git@github.com/org/repo``), with no + user name other than ssh's ``git`` and no password, query or fragment. + + Anything else is refused before the request, because the builder fetches + public GitHub repositories only and refuses the rest after receipt, by which + point a token in the string has left the machine. That includes a URL that + does not parse (``https://TOKEN@[github.com/org/repo``) and a scp-style + address with a token for its user (``TOKEN@github.com:org/repo.git``): a + string that cannot be recognized as safe is not sent.""" + return _canonical_github_repository(repository) is not None + + +def _refuse_unsendable_repositories(renderer, public_nodes: list[dict], spec_file: Path) -> None: + """Refuse with ``build_spec_invalid`` a public pack whose ``repository`` is not a + recognized public GitHub address. It reads the spec only, so a dry run runs it + before it asks for sign-in: a bad address gets the same answer signed in or out.""" + unsendable = sorted( + str(node.get("name") or node.get("id") or "-") + for node in public_nodes + if node.get("repository") is not None + and not (isinstance(node["repository"], str) and _repository_is_sendable(node["repository"])) + ) + if unsendable: + renderer.error( + code="build_spec_invalid", + message="these custom nodes name a repository that is not a public GitHub address without credentials, " + "so it is never sent: " + ", ".join(unsendable), + hint="write the repository as https://github.com// or git@github.com:/.git, " + "with no user name or token; the builder fetches public GitHub repositories only", + details={"path": str(spec_file)}, + ) + raise typer.Exit(code=1) + + +def _require_public_pins(renderer, client, public_nodes: list[dict], spec_file: Path) -> None: + """Ask the builder's importer to place every public pack, and refuse with + ``build_registry_pin_missing`` naming each identity it could not place: a + registry version it does not publish (a Flagged one among them), or a + repository it cannot normalize. A pack the registry never answered about + (``report.unverifiedPins``) is refused the same way: unchecked is not placed. + + The importer reads the snapshot and writes nothing, which is what lets + ``push --dry-run`` make the same call and refuse the same way. A lookup that + itself fails exits through ``_builder_call`` rather than passing the pins. + A ``repository`` that is not a recognized public GitHub address is refused + before anything is sent; that covers one that does not parse and one that + carries a user name or token.""" + _refuse_unsendable_repositories(renderer, public_nodes, spec_file) + imported = _builder_call( + renderer, + lambda: client.resolve_snapshot(snapshot_from_definition({"customNodes": public_nodes})), + ) + checked = (imported.get("definition") or {}).get("customNodes") or [] + try: + missing = public_node_identities(public_nodes) - public_node_identities( + public_node_projection({"customNodes": checked}) + ) + except BuildSpecInvalidError as error: + renderer.error(code=error.code, message=str(error), details={"path": str(spec_file)}) + raise typer.Exit(code=1) from error + if missing: + labels = sorted(f"{identity.kind}:{identity.value}@{identity.version or '-'}" for identity in missing) + renderer.error( + code="build_registry_pin_missing", + message="the builder could not resolve these custom node identities: " + ", ".join(labels), + hint="edit the spec to name a published registry version or normalized repository, or remove the node", + ) + raise typer.Exit(code=1) + # The importer keeps a pack the registry did not answer for in the definition, + # so the identity check above passes it; the report is the only place that says + # nothing confirmed it. + report = imported.get("report") if isinstance(imported, dict) else None + unverified = report.get("unverifiedPins") if isinstance(report, dict) else None + if unverified: + names = ( + sorted(_from_server(name) for name in unverified) + if isinstance(unverified, list) + else [_unrenderable("unverifiedPins", unverified)] + ) + renderer.error( + code="build_registry_pin_missing", + message="the registry did not answer for these custom nodes, so their pins were not checked: " + + ", ".join(names), + hint="retry when the Comfy Registry is reachable; nothing was uploaded or saved", + ) + raise typer.Exit(code=1) + + @app.command("push", help="Push the local comfy-build spec to the builder.") @tracking.track_command("build") def push_cmd( @@ -1912,7 +2003,13 @@ def push_cmd( help="With --release, cut the release even though the save warned about a model link.", ), ] = False, - dry_run: Annotated[bool, typer.Option("--dry-run", help="Compute uploads locally; send no HTTP requests.")] = False, + dry_run: Annotated[ + bool, + typer.Option( + "--dry-run", + help="Compute uploads locally and check public custom node pins with the builder; upload and save nothing.", + ), + ] = False, models_dir: Annotated[ str | None, typer.Option("--models-dir", help="Models folder used to resolve model localPath values."), @@ -1927,7 +2024,7 @@ def push_cmd( if release and dry_run: renderer.error( code="build_missing_input", - message="--release cuts a release from a real push, and --dry-run sends nothing.", + message="--release cuts a release from a real push, and --dry-run saves nothing.", hint="drop --dry-run to cut the release, or drop --release to preview the push", details={"conflict": ["--release", "--dry-run"]}, ) @@ -2008,15 +2105,32 @@ def push_cmd( if reported: payload["skipped_symlinks"] = reported if dry_run: + # The pin check is the one question a dry run asks the builder: it is a + # read, it costs nothing, and it is the refusal a push otherwise meets + # only after the plan was disclosed. A spec without a public pin asks + # nothing, so it needs no sign-in. + public_nodes = public_node_projection(preparation.definition) + if public_nodes: + _refuse_unsendable_repositories(renderer, public_nodes, paths.spec_file) + _require_public_pins(renderer, _builder_client(renderer, builder_url), public_nodes, paths.spec_file) + payload["public_pins_checked"] = len(public_nodes) # The envelope is the whole answer and prints nothing in pretty mode, so a # person gets the real push's opening line and word that nothing moved. # "Already held" is what the spec records; the builder, never asked, # may hold more. if renderer.is_pretty(): renderer.info(plan_line(len(uploads), payload["upload_bytes"], already_held_count(preparation))) - renderer.info( - "--dry-run: nothing was sent; the builder may already hold more of these than the spec records." - ) + if public_nodes: + count = len(public_nodes) + renderer.info(f"The builder resolved {count} public custom node pin{'' if count == 1 else 's'}.") + renderer.info( + "--dry-run: nothing was uploaded or saved; the builder may already hold more of these " + "than the spec records." + ) + else: + renderer.info( + "--dry-run: nothing was sent; the builder may already hold more of these than the spec records." + ) if _has_models(spec): renderer.info(f"--dry-run reads no folder list from the builder, so {_FOLDER_CASE_UNCHECKED}.") renderer.emit(payload, command="build push", changed=False) @@ -2033,26 +2147,8 @@ def push_cmd( public_nodes = public_node_projection(preparation.definition) if public_nodes: - imported = _builder_call( - renderer, - lambda: client.resolve_snapshot(snapshot_from_definition({"customNodes": public_nodes})), - ) - checked = (imported.get("definition") or {}).get("customNodes") or [] - try: - missing = public_node_identities(public_nodes) - public_node_identities( - public_node_projection({"customNodes": checked}) - ) - except BuildSpecInvalidError as error: - renderer.error(code=error.code, message=str(error), details={"path": str(paths.spec_file)}) - raise typer.Exit(code=1) from error - if missing: - labels = sorted(f"{identity.kind}:{identity.value}@{identity.version or '-'}" for identity in missing) - renderer.error( - code="build_registry_pin_missing", - message="the builder could not resolve these custom node identities: " + ", ".join(labels), - hint="edit the spec to name a published registry version or normalized repository, or remove the node", - ) - raise typer.Exit(code=1) + _require_public_pins(renderer, client, public_nodes, paths.spec_file) + payload["public_pins_checked"] = len(public_nodes) # Said before the first byte moves, and said even when nothing will: a # multi-GB upload is otherwise silent until it ends, and "0 files" is @@ -2799,6 +2895,12 @@ def _builder_call( except (urllib.error.URLError, requests.RequestException, KeyError) as e: _report_builder_error(renderer, e, subject, hint, models) raise typer.Exit(code=1) from e + # A response body that stalls past the timeout or drops mid-read is raised by + # ``resp.read`` (``http.read_capped``), outside urllib's ``URLError`` wrapping of + # the request itself. Report it as the same transport failure, not a traceback. + except (TimeoutError, ConnectionError, http.client.IncompleteRead) as e: + _report_builder_error(renderer, urllib.error.URLError(e), subject, hint, models) + raise typer.Exit(code=1) from e except ValueError as e: renderer.error(code="build_missing_input", message=str(e)) raise typer.Exit(code=1) from e diff --git a/comfy_cli/error_codes.py b/comfy_cli/error_codes.py index 66ed508aa..e44534e32 100644 --- a/comfy_cli/error_codes.py +++ b/comfy_cli/error_codes.py @@ -1451,7 +1451,11 @@ class ErrorCode: "build_registry_pin_missing", "`comfy build push` sent its identity-keyed public-node subset to the builder's snapshot importer, " "which could not vouch for one or more pins. Pushing anyway would save a definition that cannot " - "reconstruct every requested public node.", + "reconstruct every requested public node. `push --dry-run` makes the same read-only check and " + "refuses the same way, uploading and saving nothing. A version the registry has Flagged " + "is refused here too, though the message does not say so. A pack the registry never answered for " + "(the importer's `report.unverifiedPins`) is refused with this code as well: unchecked is not placed, " + "and a retry once the registry answers can pass.", "edit the spec to name a published registry version or normalized repository, or remove the node", ), ErrorCode( diff --git a/comfy_cli/schemas/build_push.json b/comfy_cli/schemas/build_push.json index bf8526ad7..a496bc37c 100644 --- a/comfy_cli/schemas/build_push.json +++ b/comfy_cli/schemas/build_push.json @@ -12,7 +12,8 @@ "upload_count", "upload_bytes", "uploaded", - "deduped" + "deduped", + "public_pins_checked" ], "additionalProperties": false, "properties": { @@ -25,6 +26,7 @@ "upload_bytes": {"type": "integer", "minimum": 0}, "uploaded": {"description": "Blobs whose bytes were transferred. Never exceeds `upload_count`: the builder answers with an id it already holds, and no upload URL, when the workspace already stored those exact bytes.", "type": "integer", "minimum": 0}, "deduped": {"description": "Blobs the builder already held, so `upload_count` was planned but not transferred. Always `upload_count - uploaded`.", "type": "integer", "minimum": 0}, + "public_pins_checked": {"description": "How many public custom nodes (registry versions and GitHub repositories) the builder placed in the pin check, on a push and a dry run alike. 0 when the spec has none; the builder was then not asked. A pin it cannot place fails the command with `build_registry_pin_missing`, so every pin counted here passed.", "type": "integer", "minimum": 0}, "folder_case_checked": { "description": "Present only when the spec has models. False when no usable folder list was read from the builder (`--dry-run`; a read that failed or named no folder), so a case variant of a folder (`Loras` for `loras`) passed unchecked; the builder refuses it at the release.", "type": "boolean" diff --git a/comfy_cli/skills/comfy-build-failures/SKILL.md b/comfy_cli/skills/comfy-build-failures/SKILL.md index 02bb12b51..304b818bc 100644 --- a/comfy_cli/skills/comfy-build-failures/SKILL.md +++ b/comfy_cli/skills/comfy-build-failures/SKILL.md @@ -101,9 +101,15 @@ can take (a model's `sourceUri`, a node's `registryVersion` or `repository`), fi - `must set exactly one of sourceUri or blobId` — an entry has both or neither. - `resolves to a duplicate node directory` — two entries claim one folder, so one of them goes. -- `build_registry_pin_missing` — the builder could not place a public pack. - The message names each identity; correct the `registryVersion` against a - registry search, or remove the pack. +- `build_registry_pin_missing` — the builder could not place a public pack, or + the registry never answered for it (its `unverifiedPins`; retry later). + `push --dry-run` refuses the same way, before anything is uploaded or saved. + The message names each identity but not why. A version the registry has + Flagged lands here: check its `status` at + `https://api.comfy.org/nodes//versions`, and pin a version that is not + `NodeVersionStatusFlagged`, or the pack's `repository` and a commit `gitRef`. + Otherwise correct the `registryVersion` against a registry search, or remove + the pack. - `build_spec_stale` — the remote moved under you, or `--id` names a Build the spec's `syncedRevision` does not belong to. See *Revising*. diff --git a/comfy_cli/skills/comfy-build/SKILL.md b/comfy_cli/skills/comfy-build/SKILL.md index 57758174a..9acd5a889 100644 --- a/comfy_cli/skills/comfy-build/SKILL.md +++ b/comfy_cli/skills/comfy-build/SKILL.md @@ -117,10 +117,14 @@ comfy build validate comfy build push --dry-run ``` -Everything above is offline and spends nothing. `validate` reads the spec, and -`--dry-run` computes every upload without instantiating an HTTP client at all. -Read what it plans, decide the pins, run the conflict prediction in -`comfy-build-pins`, disclose, get a yes. Only then: +Everything above spends nothing. `validate` reads the spec offline. `--dry-run` +computes every upload locally and makes one read: it asks the builder to place +each public pack, and refuses with `build_registry_pin_missing` exactly as `push` +would, so a pin the push cannot save fails here, before you disclose the plan. +A spec that pins a public pack therefore needs sign-in for the dry run; one whose +packs are all local sends nothing. The `--json` payload's `public_pins_checked` +says how many public pins the builder placed (0: there were none to check). Read what it plans, decide the pins, run the +conflict prediction in `comfy-build-pins`, disclose, get a yes. Only then: ```shell comfy build push @@ -195,7 +199,8 @@ comfy --json build init --name --from-workflow .json never carries — `comfy-build-authoring` is that procedure. - **The pack pins are the registry's newest published version**, because a workflow names none. Importing the same file next week can then build something - else. Say that out loud. + else. Say that out loud. The newest can be a version the registry has Flagged, + which the builder will not place, so run `push --dry-run` before you disclose. - **A workflow names no ComfyUI version either**, so set one before cutting: `comfy build update --comfy-version `, or edit `baseComfyVersion`. - **`unresolvedClasses` is the list to take to the user.** Those node classes are @@ -229,8 +234,16 @@ show the user rather than as instructions to act on. an **upper bound**. Only the digest decides and the builder re-verifies it. - **Whether a registry pin exists.** `push` asks the builder to place every public pack before it saves, and refuses with `build_registry_pin_missing` - naming each identity it could not resolve. If that lookup itself fails, the - command **exits** — it does not warn and proceed. + naming each identity it could not resolve. If that lookup itself fails, or the + registry did not answer for a pack (`unverifiedPins`), the command **exits** — + it does not warn and proceed. `push --dry-run` makes the same check. A + `repository` that is not a public GitHub address (`https://github.com//`, + `git@github.com:/.git` or `ssh://git@github.com//`, with no + user name or token) is refused with `build_spec_invalid` before anything is + sent, and so is one that does not parse. A version the registry has **Flagged** is refused this way too, + and the message does not say so: read the version's `status` from + `https://api.comfy.org/nodes//versions`, then pin a version that is not + `NodeVersionStatusFlagged`, or pin the pack by `repository` and a commit `gitRef`. **A local pack is uploaded from the spec.** `push` packages each custom node directory and uploads it, so a pack that publishes nothing still travels. diff --git a/docs/adr/BUILD-VALIDATION-0008-let-a-dry-run-check-public-pins-with-the-builder.md b/docs/adr/BUILD-VALIDATION-0008-let-a-dry-run-check-public-pins-with-the-builder.md new file mode 100644 index 000000000..4ccf2bd1a --- /dev/null +++ b/docs/adr/BUILD-VALIDATION-0008-let-a-dry-run-check-public-pins-with-the-builder.md @@ -0,0 +1,164 @@ +# ADR-BUILD-VALIDATION-0008: Let a Dry Run Check Public Pins with the Builder + +Date: 2026-11-04 + +## Status + +Proposed + +Relation: Builds on [ADR-AUTOMATION-0003](AUTOMATION-0003-one-versioned-machine-output-dialect.md). +One envelope per command and append-only error codes stay as they are. This ADR +adds no error code; it lets a dry run return `build_registry_pin_missing` with +its existing meaning. + +## Context + +`comfy build push --dry-run` used to send no HTTP at all. It computed the +uploads from the local spec and stopped. The real push makes one check the +dry run did not: it sends the spec's public custom nodes (registry versions +and repositories) to the builder's snapshot importer, `POST +/v1/snapshots/resolve`, and refuses with `build_registry_pin_missing` when the +importer cannot place one of them. That is the only place that knows what the +Comfy Registry actually publishes and how a repository normalizes. + +So a dry run could pass while the push of the same spec failed. The common +case was a registry version the registry has Flagged: the dry run said +"looks good", the push showed its plan, and was then refused. A dry run that +passes something the push will refuse is not a preview. + +Making the dry run ask the builder changes what `--dry-run` promises: from "no +network, no sign-in" to "may make one authenticated read". That is a +command-level side-effect contract that scripts and agents rely on, so it is +recorded here. + +## Decision + +`comfy build push --dry-run` may make exactly one builder request, and only +for the pin check: + +- **When.** Only if the spec has at least one public custom node, meaning an + entry that is not `source: local` and names a `registryVersion` or a + `repository` (`public_node_projection`). A spec whose packs are all local + sends no request and needs no sign-in, as before. +- **What is sent.** Only the public-node projection, wrapped as a snapshot. + Local packs, models, files, workflow content and upload plans are never sent. + Each `repository` must be a public GitHub address the CLI recognizes + (`https://github.com//`, `git@github.com:/.git` or + `ssh://git@github.com//`), with no user name other than ssh's + `git`, no password, query or fragment. Any other `repository` is refused + locally with `build_spec_invalid` and never sent: one that carries a token, + one that does not parse (`https://TOKEN@[github.com/org/repo`), and a + scp-style one with a token for its user (`TOKEN@github.com:org/repo.git`). + The builder fetches public GitHub repositories only and would refuse the + rest after receipt, when a token in the string has already left the + machine. +- **Which call.** `resolve_snapshot`, the snapshot importer. It is a read: it + returns a definition and a report, and writes nothing on the builder. The dry + run makes no other builder call. It creates no blobs, uploads nothing, saves + no build and cuts no release. It does not rewrite the local spec either. +- **Sign-in.** The request goes through the same authenticated builder client + as a push (`_builder_client`): an injected token, a Cloud token or API key + from the environment, or the stored sign-in. With none of these, a dry run + with public pins fails with `build_not_signed_in`. The repository address + check reads only the spec and runs before sign-in is asked for, so a bad + address gets `build_spec_invalid` signed in or out. +- **Parity with push.** Push and dry run share one function, + `_require_public_pins`. They send the same payload, compare the same + identities, and refuse with the same `build_registry_pin_missing` code, + message and hint. A spec the dry run passes on this check is one the push + passes on this check, against the same builder state. +- **The payload says the check ran.** Push and dry run both put + `public_pins_checked` in the `--json` payload: how many public pins the + builder placed, and 0 when the spec has none and the builder was not asked. + A script or agent reads it to tell a checked pin set from one with nothing + to check, which the exit code alone cannot say. +- **Failure is terminal.** If the lookup itself fails (network, 5xx, refused + credential, or a response body that times out or drops mid-read), the dry + run exits through `_builder_call` with the same error a push would get. It + never treats an unanswered check as a pass: an answer whose report lists + `unverifiedPins` (packs the registry never answered about, which the + importer keeps in the definition unchecked) is refused with + `build_registry_pin_missing`, by push and dry run alike. +- **No invented reasons.** The importer does not say why it could not place a + pin. The CLI names the identities and does not claim "Flagged" or any other + registry status. + +The help text says "check public custom node pins with the builder; upload and +save nothing", and the `--release` / `--dry-run` conflict says the dry run +"saves nothing" instead of "sends nothing". + +## Alternatives considered + +- **Keep the dry run offline.** It keeps the old promise, but the dry run keeps + passing specs the push refuses, which is the bug. +- **Check pins only with a flag (`--dry-run --check-pins`).** Rejected because + the default dry run would still give the wrong answer, and the people and + agents who need the check are the ones who will not know to ask for it. +- **Warn instead of refusing.** Rejected because the push refuses, and a + preview that is softer than the real thing gets ignored. +- **Ask the public registry directly, without sign-in.** Rejected because it + would be a second implementation of what the importer decides. Repository + normalization and which versions the builder can place live in the builder, + and the two would drift. +- **Fall back to passing when the lookup fails.** Rejected because "could not + check" is not "checked and fine". + +## What we reject + +- Any dry-run builder call that writes: blob creation, uploads, saves, + releases, or any endpoint not documented as read-only. +- Sending anything beyond the public-node projection on a dry run. +- A builder request, or a sign-in requirement, for a spec with no public pins. +- A second copy of the pin check that can drift from the push's. +- Treating a failed or unanswered lookup as a pass. + +## Consequences + +### Positive + +- A dry run now fails on the pin the push would refuse, with the push's own + code, before anyone acts on the plan. +- One function owns the check, so push and dry run cannot drift. +- All-local specs keep a zero-request, no-sign-in dry run. + +### Negative + +- A dry run on a spec with public pins now needs sign-in and network. A CI job + that ran `--dry-run` with no credential will fail with `build_not_signed_in` + until it sets `COMFY_CLOUD_API_KEY` or drops the public pins. +- The dry run now depends on the builder being up for those specs. +- `build_registry_pin_missing` can now come from a dry run. Its meaning is + unchanged, so this stays within ADR-AUTOMATION-0003's rule that error codes + are never repurposed. + +### Known limits + +- The answer is only as fresh as the builder's view when the dry run ran. A + registry change between the dry run and the push can still make the push + refuse. +- The dry run still reads no folder list from the builder, so it does not + check model folder case. That stays as it was. + +## Validation + +- `tests/comfy_cli/command/test_build_push.py`: a dry run refuses a Flagged pin + with the push's own error; it sends only the public pins to the importer and + makes no other call; a failed lookup, a stalled response body, or a report + with `unverifiedPins` exits instead of passing; a repository that carries a + token, does not parse, or is scp-style with a token user is refused before + any request; the pretty + output says the pins were checked and nothing was uploaded or saved. +- `tests/comfy_cli/command/test_build_auth_matrix.py` and + `build_auth_support.py`: a dry run with public pins needs a credential, and + one with only local packs sends nothing. + +## Revisit triggers + +- The builder exposes a public, unauthenticated pin-check endpoint. The dry run + could then drop the sign-in requirement. +- The importer starts returning a reason per pin it could not place. The + refusal could then name it. +- Users report CI breakage from the new sign-in requirement often enough that + an offline mode is worth adding back as an explicit option. +- The dry run needs a second builder read (for example the folder list). That + widens this boundary and needs its own decision. diff --git a/tests/comfy_cli/command/build_auth_support.py b/tests/comfy_cli/command/build_auth_support.py index fb4f02706..a726741ae 100644 --- a/tests/comfy_cli/command/build_auth_support.py +++ b/tests/comfy_cli/command/build_auth_support.py @@ -27,7 +27,6 @@ # Keyed on the URL *path* so a route carrying query parameters (`?cursor=`, # `?os=&gpu=`) still matches. _ROUTES: dict[tuple[str, str], tuple[int, JsonObject]] = { - ("POST", "/v1/snapshots/resolve"): (200, {"definition": _EMPTY_DEFINITION, "report": {}}), ("POST", "/v1/builds"): (201, {"id": BUILD_ID, "updatedAt": REVISION}), ("GET", "/v1/builds"): (200, {"builds": [{"id": BUILD_ID, "name": "Matrix"}]}), ("GET", f"/v1/builds/{BUILD_ID}"): ( @@ -99,6 +98,8 @@ def __call__( path = urlsplit(url).path if (method, path) == ("POST", "/v1/models/resolve"): return 200, {"results": _resolved_filenames(body)} + if (method, path) == ("POST", "/v1/snapshots/resolve"): + return 200, {"definition": {"models": [], "customNodes": _placed_nodes(body)}, "report": {}} route = _ROUTES.get((method, path)) if route is None: pytest.fail(f"unexpected Builder call: {method} {url}") @@ -113,6 +114,24 @@ def _resolved_filenames(body: JsonObject | None) -> list[JsonValue]: return [{"filename": filename, "candidates": []} for filename in filenames] +def _placed_nodes(body: JsonObject | None) -> list[JsonValue]: + """Every pack the snapshot names, placed as asked: the importer vouches for + each pin, so a push or dry run that sends one gets past its pin check.""" + assert body is not None + snapshot = body["snapshot"] + assert isinstance(snapshot, dict) + placed: list[JsonValue] = [] + for entry in snapshot.get("snapshots") or []: + assert isinstance(entry, dict) + for node in entry.get("customNodes") or []: + assert isinstance(node, dict) + if node["type"] == "cnr": + placed.append({"name": node["dirName"], "id": node["id"], "registryVersion": node["version"]}) + else: + placed.append({"name": node["dirName"], "repository": node["url"]}) + return placed + + def write_snapshot(root: Path) -> Path: path = root / "snapshot.json" path.write_text(json.dumps({"customNodes": [], "pipPackages": {}, "pythonVersion": "3.12"}), encoding="utf-8") diff --git a/tests/comfy_cli/command/test_build_auth_matrix.py b/tests/comfy_cli/command/test_build_auth_matrix.py index fca091c29..003a50015 100644 --- a/tests/comfy_cli/command/test_build_auth_matrix.py +++ b/tests/comfy_cli/command/test_build_auth_matrix.py @@ -53,6 +53,7 @@ class FixtureKind(Enum): VALIDATE_REMOTE_LOOKUP = "validate --remote (lookupable)" PUSH = "push" PUSH_DRY_RUN = "push --dry-run" + PUSH_DRY_RUN_PINNED = "push --dry-run (public pins)" PULL = "pull" STATUS = "status" LS = "ls" @@ -95,7 +96,10 @@ class BuildAuthCase: BuildAuthCase(FixtureKind.VALIDATE_REMOTE_ZERO, "validate", True, _ZERO_PLUS, 1), BuildAuthCase(FixtureKind.VALIDATE_REMOTE_LOOKUP, "validate", True, _ZERO_PLUS, 2), BuildAuthCase(FixtureKind.PUSH, "push", True, _ONE_PLUS), + # A dry run asks the builder only to place the spec's public pins, the read the + # push makes before it saves, so a spec without one stays signed out and silent. BuildAuthCase(FixtureKind.PUSH_DRY_RUN, "push", False, _ZERO), + BuildAuthCase(FixtureKind.PUSH_DRY_RUN_PINNED, "push", True, _ONE_PLUS, 1), BuildAuthCase(FixtureKind.PULL, "pull", True, _ONE_PLUS), BuildAuthCase(FixtureKind.STATUS, "status", True, _ONE_PLUS), BuildAuthCase(FixtureKind.LS, "ls", True, _ONE_PLUS), @@ -165,6 +169,15 @@ def _prepare(kind: FixtureKind, root: Path) -> list[str]: case FixtureKind.PUSH_DRY_RUN: write_spec(root, models=[], nodes=[]) return ["build", "push", "--dry-run", str(root)] + case FixtureKind.PUSH_DRY_RUN_PINNED: + write_spec( + root, + models=[], + nodes=[ + {"name": "registry-node", "id": "registry-node", "registryVersion": "1.0.0", "source": "registry"} + ], + ) + return ["build", "push", "--dry-run", str(root)] case FixtureKind.PULL: write_spec(root, models=[], nodes=[]) return ["build", "pull", "-y", "--id", BUILD_ID, str(root)] diff --git a/tests/comfy_cli/command/test_build_push.py b/tests/comfy_cli/command/test_build_push.py index 29d065995..3de3c72b3 100644 --- a/tests/comfy_cli/command/test_build_push.py +++ b/tests/comfy_cli/command/test_build_push.py @@ -61,6 +61,7 @@ def _schema(name: str) -> JsonObject: def test_dry_run_is_signed_out_and_zero_http(workspace: Path, monkeypatch: pytest.MonkeyPatch) -> None: + """Only a public pin needs the builder, so a spec without one asks it nothing.""" # Given path = write_spec(workspace) before = path.read_bytes() @@ -76,6 +77,7 @@ def test_dry_run_is_signed_out_and_zero_http(workspace: Path, monkeypatch: pytes assert data["dry_run"] is True assert data["upload_count"] == 2 assert data["upload_bytes"] == len(b"MODEL") + node_size + assert data["public_pins_checked"] == 0 assert path.read_bytes() == before @@ -277,13 +279,13 @@ def test_pin_gate_normalizes_equivalent_repository_identities(workspace: Path, m { "name": "repo-node", "source": "git", - "repository": "git@Example.COM:Owner/Repo.git", + "repository": "git@GitHub.COM:Owner/Repo.git", "gitRef": "main", } ], ) client = RecordingBuilder() - client.checked_nodes = [{"name": "repo-node", "repository": "https://example.com/Owner/Repo/"}] + client.checked_nodes = [{"name": "repo-node", "repository": "https://github.com/Owner/Repo/"}] _install_client(monkeypatch, client) # When @@ -294,6 +296,299 @@ def test_pin_gate_normalizes_equivalent_repository_identities(workspace: Path, m assert len(client.snapshots) == 1 +#: A pin to a version the registry has Flagged. The builder's importer cannot +#: place it, so the push refuses it. +_FLAGGED_PIN: JsonObject = { + "name": "ComfyUI-DepthAnythingV3", + "id": "ComfyUI-DepthAnythingV3", + "registryVersion": "0.1.19", + "source": "registry", +} + +_REGISTRY_PIN: JsonObject = { + "name": "registry-node", + "id": "registry-node", + "registryVersion": "1.0.0", + "source": "registry", +} + + +class _FlaggedImporter(RecordingBuilder): + """The importer's answer for a Flagged version, in the shape the live builder + sends: the pack is left out of the definition and named in the report.""" + + def resolve_snapshot(self, snapshot: JsonObject) -> JsonObject: + super().resolve_snapshot(snapshot) + return { + "definition": {}, + "report": {"notInRegistry": [_FLAGGED_PIN["id"]], "unresolvedNodes": [_FLAGGED_PIN["id"]]}, + } + + +def test_a_dry_run_refuses_a_flagged_pin_with_the_push_s_own_error( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + """A dry run is the free check before disclosing and spending, so it must + refuse a pin the builder cannot place the way the push does, not pass it.""" + # Given + pushed_root = make_workspace(tmp_path / "push") + write_spec(pushed_root, models=[], nodes=[_FLAGGED_PIN]) + pushed = _FlaggedImporter() + _install_client(monkeypatch, pushed) + push = invoke_push(pushed_root) + + dry_root = make_workspace(tmp_path / "dry-run") + spec = write_spec(dry_root, models=[], nodes=[_FLAGGED_PIN]) + before = spec.read_bytes() + dry = _FlaggedImporter() + _install_client(monkeypatch, dry) + + # When + result = invoke_push(dry_root, "--dry-run") + + # Then + assert (push.exit_code, result.exit_code) == (1, 1) + error = envelope(result)["error"] + assert error == envelope(push)["error"] + assert error["code"] == "build_registry_pin_missing" + assert "registry:ComfyUI-DepthAnythingV3@0.1.19" in error["message"] + assert [call["method"] for call in dry.calls] == ["resolve_snapshot"] + assert spec.read_bytes() == before + + +def test_a_dry_run_asks_the_builder_only_to_place_its_public_pins( + workspace: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + # Given + path = write_spec(workspace, nodes=[local_node(), _REGISTRY_PIN]) + before = path.read_bytes() + client = RecordingBuilder() + _install_client(monkeypatch, client) + + # When + result = invoke_push(workspace, "--dry-run") + + # Then + assert result.exit_code == 0, result.stderr + assert [call["method"] for call in client.calls] == ["resolve_snapshot"] + sent = client.snapshots[0]["snapshots"][0]["customNodes"] + assert [(node["id"], node["version"]) for node in sent] == [("registry-node", "1.0.0")] + data = envelope(result)["data"] + assert (data["dry_run"], data["upload_count"], data["uploaded"]) == (True, 2, 0) + assert data["public_pins_checked"] == 1 + jsonschema.Draft202012Validator(_schema("build_push.json")).validate(data) + assert path.read_bytes() == before + + +def test_a_real_push_reports_how_many_public_pins_the_builder_placed( + workspace: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + """A dry run and a push carry the same count, so a script reading either can + tell a checked pin set from a spec that had none to check.""" + # Given + write_spec(workspace, models=[], nodes=[local_node(), _REGISTRY_PIN]) + _install_client(monkeypatch, RecordingBuilder()) + + # When + result = invoke_push(workspace) + + # Then + assert result.exit_code == 0, result.stderr + data = envelope(result)["data"] + assert (data["dry_run"], data["public_pins_checked"]) == (False, 1) + jsonschema.Draft202012Validator(_schema("build_push.json")).validate(data) + + +def test_a_dry_run_whose_pin_lookup_fails_exits_rather_than_passing( + workspace: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + # Given + write_spec(workspace, models=[], nodes=[_REGISTRY_PIN]) + client = RecordingBuilder() + + def unreachable(snapshot: JsonObject) -> JsonObject: + raise urllib.error.URLError("connection refused") + + monkeypatch.setattr(client, "resolve_snapshot", unreachable) + _install_client(monkeypatch, client) + + # When + result = invoke_push(workspace, "--dry-run") + + # Then + assert result.exit_code == 1 + assert envelope(result)["error"]["code"] == "build_builder_error" + + +@pytest.mark.parametrize( + "failure", + [TimeoutError("The read operation timed out"), ConnectionResetError(54, "reset"), http.client.IncompleteRead(b"{")], + ids=["timeout", "reset", "incomplete"], +) +def test_a_pin_lookup_whose_response_body_fails_is_a_transport_error( + workspace: Path, monkeypatch: pytest.MonkeyPatch, failure: Exception +) -> None: + """``read_capped`` raises these from ``resp.read``, past urllib's URLError + wrapping, so they reach ``_builder_call`` bare.""" + # Given + write_spec(workspace, models=[], nodes=[_REGISTRY_PIN]) + client = RecordingBuilder() + + def stalled(snapshot: JsonObject) -> JsonObject: + raise failure + + monkeypatch.setattr(client, "resolve_snapshot", stalled) + _install_client(monkeypatch, client) + + # When + result = invoke_push(workspace, "--dry-run") + + # Then + assert result.exit_code == 1 + assert envelope(result)["error"]["code"] == "build_builder_error" + + +class _UnansweredImporter(RecordingBuilder): + """The registry did not answer: the importer keeps the pin in the definition + unchanged and names it in ``report.unverifiedPins``, with HTTP 200.""" + + def resolve_snapshot(self, snapshot: JsonObject) -> JsonObject: + answer = super().resolve_snapshot(snapshot) + return {**answer, "report": {"unverifiedPins": [_REGISTRY_PIN["id"]]}} + + +def test_unverified_pins_are_refused_by_push_and_dry_run_alike(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: + # Given + pushed_root = make_workspace(tmp_path / "push") + write_spec(pushed_root, models=[], nodes=[_REGISTRY_PIN]) + pushed = _UnansweredImporter() + _install_client(monkeypatch, pushed) + push = invoke_push(pushed_root) + + dry_root = make_workspace(tmp_path / "dry-run") + write_spec(dry_root, models=[], nodes=[_REGISTRY_PIN]) + dry = _UnansweredImporter() + _install_client(monkeypatch, dry) + + # When + result = invoke_push(dry_root, "--dry-run", agentic=False) + dry_json = invoke_push(dry_root, "--dry-run") + + # Then + assert (push.exit_code, result.exit_code, dry_json.exit_code) == (1, 1, 1) + error = envelope(dry_json)["error"] + assert error == envelope(push)["error"] + assert error["code"] == "build_registry_pin_missing" + assert "registry-node" in error["message"] and "not checked" in error["message"] + assert _calls(pushed, "create_build") == [] + assert "The builder resolved" not in result.stdout + + +@pytest.mark.parametrize( + "repository", + [ + "https://ghp_TOKENSECRET@github.com/org/repo", + "https://x-access-token:ghp_TOKENSECRET@github.com/org/repo", + # Does not parse (unmatched bracket): a parse failure is a refusal, not "no credentials". + "https://ghp_TOKENSECRET@[github.com/org/repo", + # scp-style, so there is no URL authority to read a user name from. + "ghp_TOKENSECRET@github.com:org/repo.git", + ], +) +@pytest.mark.parametrize("dry_run", [True, False]) +def test_a_repository_url_with_credentials_is_refused_before_any_request( + workspace: Path, monkeypatch: pytest.MonkeyPatch, repository: str, dry_run: bool +) -> None: + # Given + node = {"name": "private-node", "source": "git", "repository": repository, "gitRef": "main"} + write_spec(workspace, models=[], nodes=[node]) + client = RecordingBuilder() + _install_client(monkeypatch, client) + + # When + result = invoke_push(workspace, *(["--dry-run"] if dry_run else [])) + + # Then + assert result.exit_code == 1 + error = envelope(result)["error"] + assert error["code"] == "build_spec_invalid" + assert "private-node" in error["message"] + assert client.calls == [] + assert "ghp_TOKENSECRET" not in result.output + + +def test_a_signed_out_dry_run_refuses_a_credentialed_repository_before_asking_for_sign_in( + workspace: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + """The address check reads only the spec, so a signed-out dry run gets + ``build_spec_invalid`` for it, as a signed-in one does, not ``build_not_signed_in``.""" + # Given + node = {"name": "private-node", "source": "git", "repository": "https://ghp_TOKENSECRET@github.com/org/repo"} + write_spec(workspace, models=[], nodes=[{**node, "gitRef": "main"}]) + monkeypatch.setattr(build, "_builder_client", lambda *args, **kwargs: pytest.fail("constructed Builder client")) + + # When + result = invoke_push(workspace, "--dry-run") + + # Then + assert result.exit_code == 1 + error = envelope(result)["error"] + assert error["code"] == "build_spec_invalid" + assert "private-node" in error["message"] + assert "ghp_TOKENSECRET" not in result.output + + +@pytest.mark.parametrize( + "repository", + [ + "https://github.com/org/repo", + "https://github.com/org/repo.git", + "https://github.com/org/repo/", + "git@github.com:org/repo.git", + "ssh://git@github.com/org/repo", + ], +) +def test_a_public_github_repository_is_sendable(repository: str) -> None: + assert build._repository_is_sendable(repository) + + +@pytest.mark.parametrize( + "repository", + [ + "https://user@github.com/org/repo", + "https://user:TOKEN@github.com/org/repo", + "https://TOKEN@[github.com/org/repo", + "TOKEN@github.com:org/repo.git", + "ssh://git:TOKEN@github.com/org/repo", + "git@github.com:TOKEN@org/repo.git", + "https://github.com/org/repo?token=TOKEN", + "https://github.com/org/repo#TOKEN", + "https://github.com:8443/org/repo", + "http://github.com/org/repo", + "https://example.com/org/repo", + "https://github.com/org", + ], +) +def test_a_repository_that_is_not_a_public_github_address_is_not_sendable(repository: str) -> None: + assert not build._repository_is_sendable(repository) + + +def test_a_dry_run_tells_a_person_it_checked_the_public_pins(workspace: Path, monkeypatch: pytest.MonkeyPatch) -> None: + # Given + write_spec(workspace, nodes=[local_node(), _REGISTRY_PIN]) + _install_client(monkeypatch, RecordingBuilder()) + + # When + result = invoke_push(workspace, "--dry-run", agentic=False) + + # Then + assert result.exit_code == 0, result.output + text = " ".join(result.stdout.split()) + assert "The builder resolved 1 public custom node pin." in text + assert "nothing was uploaded or saved" in text + assert "nothing was sent" not in text + + def test_a_skipped_symlink_is_named_on_stderr_and_carried_in_the_payload( workspace: Path, monkeypatch: pytest.MonkeyPatch ) -> None: