genblaze-cli 0.3.2__tar.gz → 0.3.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,7 +54,12 @@ ehthumbs.db
54
54
  !.env.example
55
55
  *.pem
56
56
  *.key
57
- credentials.json
57
+ credentials*
58
+ *.credentials
59
+ *_rsa
60
+ *.p12
61
+ *.pfx
62
+ *.keystore
58
63
 
59
64
  # Jupyter
60
65
  .ipynb_checkpoints/
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: genblaze-cli
3
- Version: 0.3.2
3
+ Version: 0.3.5
4
4
  Summary: CLI for genblaze manifest operations
5
5
  Project-URL: Homepage, https://github.com/backblaze-labs/genblaze
6
6
  Project-URL: Documentation, https://github.com/backblaze-labs/genblaze#readme
@@ -12,21 +12,20 @@ License-Expression: MIT
12
12
  Keywords: ai,c2pa-ready,cli,command-line,genai,genblaze,manifest,media,pipeline,provenance
13
13
  Classifier: Development Status :: 3 - Alpha
14
14
  Classifier: Environment :: Console
15
- Classifier: License :: OSI Approved :: MIT License
16
15
  Classifier: Programming Language :: Python :: 3.11
17
16
  Classifier: Programming Language :: Python :: 3.12
18
17
  Classifier: Programming Language :: Python :: 3.13
19
18
  Classifier: Topic :: Multimedia
20
19
  Classifier: Topic :: Software Development :: Libraries
21
20
  Requires-Python: >=3.11
22
- Requires-Dist: click>=8.0
23
- Requires-Dist: genblaze-core<0.4,>=0.3.4
21
+ Requires-Dist: click<9,>=8.0
22
+ Requires-Dist: genblaze-core<0.4,>=0.3.7
24
23
  Provides-Extra: dev
25
24
  Requires-Dist: pillow>=10.0; extra == 'dev'
26
25
  Requires-Dist: pytest>=7.0; extra == 'dev'
27
26
  Description-Content-Type: text/markdown
28
27
 
29
- <!-- last_verified: 2026-04-22 -->
28
+ <!-- last_verified: 2026-07-21 -->
30
29
  # genblaze-cli
31
30
 
32
31
  **Command-line toolkit for inspecting, verifying, and indexing genblaze AI-generated-media provenance manifests.**
@@ -58,6 +57,7 @@ genblaze extract video.mp4 # Extract embedded manifest → stdout
58
57
  genblaze extract video.mp4 -o m.json # …or to a file
59
58
 
60
59
  genblaze verify video.mp4 # Verify manifest hash + output sha256 declarations
60
+ genblaze verify video.mp4 --fetch # …and re-hash the actual asset bytes
61
61
  genblaze verify manifest.json # Or verify a standalone manifest file
62
62
 
63
63
  genblaze replay manifest.json # Show what a replay would do (dry run)
@@ -65,7 +65,7 @@ genblaze replay manifest.json # Show what a replay would do (dry run
65
65
  genblaze index manifest.json -o data/ # Index into partitioned Parquet tables
66
66
  ```
67
67
 
68
- Exit codes are non-zero on verification failure — safe to drop into CI pipelines, release checks, or content-moderation workflows. The command does not fetch remote asset URLs; consumers that dereference `asset.url` must hash those bytes separately and compare them with the manifest's `asset.sha256`.
68
+ Exit codes are non-zero on verification failure; safe to drop into CI pipelines, release checks, or content-moderation workflows. By default verify checks the manifest only; `--fetch` also downloads each output asset (through the same SSRF-hardened transfer path the pipeline uses) and compares its bytes against the declared sha256. Local pipelines that wrote assets outside the system temp directories (e.g. `output_dir=./out`) can admit them with `--allowed-root <dir>`.
69
69
 
70
70
  ## Typical flow
71
71
 
@@ -1,4 +1,4 @@
1
- <!-- last_verified: 2026-04-22 -->
1
+ <!-- last_verified: 2026-07-21 -->
2
2
  # genblaze-cli
3
3
 
4
4
  **Command-line toolkit for inspecting, verifying, and indexing genblaze AI-generated-media provenance manifests.**
@@ -30,6 +30,7 @@ genblaze extract video.mp4 # Extract embedded manifest → stdout
30
30
  genblaze extract video.mp4 -o m.json # …or to a file
31
31
 
32
32
  genblaze verify video.mp4 # Verify manifest hash + output sha256 declarations
33
+ genblaze verify video.mp4 --fetch # …and re-hash the actual asset bytes
33
34
  genblaze verify manifest.json # Or verify a standalone manifest file
34
35
 
35
36
  genblaze replay manifest.json # Show what a replay would do (dry run)
@@ -37,7 +38,7 @@ genblaze replay manifest.json # Show what a replay would do (dry run
37
38
  genblaze index manifest.json -o data/ # Index into partitioned Parquet tables
38
39
  ```
39
40
 
40
- Exit codes are non-zero on verification failure — safe to drop into CI pipelines, release checks, or content-moderation workflows. The command does not fetch remote asset URLs; consumers that dereference `asset.url` must hash those bytes separately and compare them with the manifest's `asset.sha256`.
41
+ Exit codes are non-zero on verification failure; safe to drop into CI pipelines, release checks, or content-moderation workflows. By default verify checks the manifest only; `--fetch` also downloads each output asset (through the same SSRF-hardened transfer path the pipeline uses) and compares its bytes against the declared sha256. Local pipelines that wrote assets outside the system temp directories (e.g. `output_dir=./out`) can admit them with `--allowed-root <dir>`.
41
42
 
42
43
  ## Typical flow
43
44
 
@@ -20,14 +20,25 @@ def _manifest_json_for_display(manifest: Manifest) -> str:
20
20
 
21
21
 
22
22
  @click.command()
23
- @click.argument("file", type=click.Path(exists=True, path_type=Path))
23
+ @click.argument("file", type=click.Path(exists=True, dir_okay=False, path_type=Path))
24
24
  @click.option("--format", "fmt", type=click.Choice(["json", "summary"]), default="json")
25
- def extract(file: Path, fmt: str) -> None:
25
+ @click.option(
26
+ "-o",
27
+ "--output",
28
+ type=click.Path(path_type=Path),
29
+ default=None,
30
+ help="Write extracted manifest JSON to this file instead of stdout.",
31
+ )
32
+ def extract(file: Path, fmt: str, output: Path | None) -> None:
26
33
  """Extract and display the genblaze manifest from a media file."""
27
34
  try:
28
35
  manifest = extract_manifest(file)
29
36
  if fmt == "json":
30
- click.echo(_manifest_json_for_display(manifest))
37
+ json_str = _manifest_json_for_display(manifest)
38
+ if output is not None:
39
+ output.write_text(json_str, encoding="utf-8")
40
+ else:
41
+ click.echo(json_str)
31
42
  else:
32
43
  report = manifest.verification_report()
33
44
  click.echo(f"Run ID: {manifest.run.run_id}")
@@ -35,6 +46,9 @@ def extract(file: Path, fmt: str) -> None:
35
46
  click.echo(f"Hash: {manifest.canonical_hash}")
36
47
  click.echo(f"Hash OK: {report.hash_ok}")
37
48
  click.echo(f"Output sha256: {len(report.unverified_sha256_ids)} missing or malformed")
49
+ # Itemize metadata too, so a False `Verified:` line always has a
50
+ # visible reason (report.ok folds in invalid_metadata_ids, #149).
51
+ click.echo(f"Output metadata: {len(report.invalid_metadata_ids)} out of spec")
38
52
  click.echo(f"Verified: {report.ok} (asset bytes were not fetched or compared)")
39
53
  except Exception as exc:
40
54
  raise click.ClickException(f"{type(exc).__name__}: {exc}") from exc
@@ -7,7 +7,7 @@ import click
7
7
 
8
8
 
9
9
  @click.command()
10
- @click.argument("manifest_file", type=click.Path(exists=True, path_type=Path))
10
+ @click.argument("manifest_file", type=click.Path(exists=True, dir_okay=False, path_type=Path))
11
11
  @click.option(
12
12
  "--output",
13
13
  "-o",
@@ -2,12 +2,16 @@
2
2
 
3
3
  import json
4
4
  from pathlib import Path
5
+ from typing import TYPE_CHECKING
5
6
 
6
7
  import click
7
8
  from genblaze_core.models.enums import PromptVisibility, RunStatus
8
9
 
10
+ if TYPE_CHECKING:
11
+ from genblaze_core.providers.base import BaseProvider
9
12
 
10
- def _load_provider(provider_name: str, allowed: tuple[str, ...] | None):
13
+
14
+ def _load_provider(provider_name: str, allowed: tuple[str, ...] | None) -> "BaseProvider":
11
15
  """Load a provider by name using entry point discovery.
12
16
 
13
17
  If allowed is set, reject providers not in the allowlist.
@@ -77,7 +81,7 @@ _UNREPLAYABLE_FIELDS = [
77
81
 
78
82
 
79
83
  @click.command()
80
- @click.argument("manifest_file", type=click.Path(exists=True, path_type=Path))
84
+ @click.argument("manifest_file", type=click.Path(exists=True, dir_okay=False, path_type=Path))
81
85
  @click.option("--dry-run/--no-dry-run", default=True, help="Preview without executing.")
82
86
  @click.option(
83
87
  "--allow-provider",
@@ -142,9 +146,13 @@ def replay(
142
146
 
143
147
  # Safety: when no allowlist is provided, confirm each unique provider.
144
148
  # A hostile manifest could reference any installed provider and execute
145
- # paid API calls on the user's credentials without consent.
149
+ # paid API calls on the user's credentials without consent. Steps with no
150
+ # provider (INGEST/IMPORT, see the loop below) don't invoke one, so they're
151
+ # excluded here rather than flowing `None` into sorted() (issue #43).
146
152
  if allowed is None:
147
- unique_providers = sorted({step.provider for step in run.steps})
153
+ unique_providers = sorted(
154
+ {step.provider for step in run.steps if step.provider is not None}
155
+ )
148
156
  click.echo(
149
157
  "No --allow-provider allowlist set. Confirm each provider before execution:",
150
158
  err=True,
@@ -165,7 +173,7 @@ def replay(
165
173
  # Cache providers by name to avoid re-instantiating
166
174
  from genblaze_core.pipeline import Pipeline
167
175
 
168
- providers: dict[str, object] = {}
176
+ providers: dict[str, BaseProvider] = {}
169
177
  pipe = Pipeline(
170
178
  run.name,
171
179
  tenant_id=run.tenant_id,
@@ -177,6 +185,17 @@ def replay(
177
185
  _reserved = {"model", "prompt", "modality", "step_type", "seed", "negative_prompt"}
178
186
 
179
187
  for step_idx, step in enumerate(run.steps):
188
+ # A None provider (only valid for INGEST/IMPORT steps, see Step's
189
+ # own validator) has no upstream service to re-invoke here — replay
190
+ # only supports Pipeline.step()-shaped generative steps. Without this
191
+ # guard, None flowed into a dict[str, ...] key and _load_provider's
192
+ # str parameter, raising a confusing TypeError instead (issue #43).
193
+ if step.provider is None:
194
+ raise click.ClickException(
195
+ f"Step {step_idx + 1} (step_type={step.step_type}) has no provider; "
196
+ "replay does not support re-executing provider-less steps "
197
+ "(e.g. INGEST/IMPORT)."
198
+ )
180
199
  if step.provider not in providers:
181
200
  providers[step.provider] = _load_provider(step.provider, allowed)
182
201
 
@@ -0,0 +1,211 @@
1
+ """Verify command — check manifest hash and output sha256 coverage."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import hashlib
6
+ import re
7
+ from pathlib import Path
8
+ from typing import TYPE_CHECKING
9
+ from urllib.parse import urlsplit, urlunsplit
10
+ from urllib.request import url2pathname
11
+
12
+ import click
13
+
14
+ from genblaze_cli.manifest_io import extract_manifest
15
+
16
+ if TYPE_CHECKING:
17
+ from genblaze_core.models.manifest import Manifest
18
+
19
+ # 256 KB chunks; matches the transfer layer's streaming granularity.
20
+ _FETCH_CHUNK = 256 * 1024
21
+
22
+ # A presigned URL's query string is a bearer credential for that object (#75);
23
+ # it must never be echoed in CLI output or error messages.
24
+ _URL_QUERY_RE = re.compile(r"https?://\S+?\?\S+")
25
+
26
+
27
+ def _redact_url(url: str) -> str:
28
+ parsed = urlsplit(url)
29
+ if parsed.query:
30
+ return urlunsplit(parsed._replace(query="REDACTED"))
31
+ return url
32
+
33
+
34
+ def _redact_text(text: str) -> str:
35
+ return _URL_QUERY_RE.sub(lambda m: _redact_url(m.group(0)), text)
36
+
37
+
38
+ def _hash_url_bytes(url: str, extra_roots: tuple[Path, ...] = ()) -> tuple[str, int]:
39
+ """Stream the bytes at ``url`` and return ``(sha256_hex, size)``.
40
+
41
+ ``https://`` URLs go through the transfer layer's SSRF-pinned stream;
42
+ every redirect hop is re-validated against the SSRF blocklist and DNS
43
+ pinned, because a manifest is untrusted input and ``asset.url`` can point
44
+ anywhere. ``file://`` paths must resolve under the same allowed roots the
45
+ storage and ffmpeg paths accept, plus any ``extra_roots`` the caller
46
+ explicitly opted into (mirroring ``_read_local_file``'s ``extra_roots``
47
+ semantics; pipelines run with ``output_dir=`` write assets outside the
48
+ temp-dir allowlist). Bytes are hashed as they arrive; a whole asset is
49
+ never held in memory.
50
+ """
51
+ scheme = urlsplit(url).scheme
52
+ if scheme == "https":
53
+ from genblaze_core.exceptions import StorageError
54
+ from genblaze_core.storage.transfer import (
55
+ _DEFAULT_DOWNLOAD_TIMEOUT,
56
+ _DEFAULT_MAX_DOWNLOAD_BYTES,
57
+ _http_get_stream,
58
+ )
59
+
60
+ digest = hashlib.sha256()
61
+ size = 0
62
+ resp = _http_get_stream(url, timeout=_DEFAULT_DOWNLOAD_TIMEOUT)
63
+ try:
64
+ while chunk := resp.read(_FETCH_CHUNK):
65
+ digest.update(chunk)
66
+ size += len(chunk)
67
+ if size > _DEFAULT_MAX_DOWNLOAD_BYTES:
68
+ # Same exception type and message shape as the transfer
69
+ # layer's own cap, so callers see one error taxonomy.
70
+ raise StorageError(
71
+ f"Download exceeds {_DEFAULT_MAX_DOWNLOAD_BYTES} byte limit"
72
+ )
73
+ finally:
74
+ resp.release_conn()
75
+ return digest.hexdigest(), size
76
+ if scheme == "file":
77
+ from genblaze_core._utils import ALLOWED_FILE_ROOTS
78
+
79
+ allowed = (*ALLOWED_FILE_ROOTS, *(r.resolve() for r in extra_roots))
80
+ resolved = Path(url2pathname(urlsplit(url).path)).resolve()
81
+ if not any(resolved.is_relative_to(root) for root in allowed):
82
+ raise ValueError(f"file:// path outside allowed roots: {resolved}")
83
+ digest = hashlib.sha256()
84
+ size = 0
85
+ with resolved.open("rb") as fh:
86
+ while chunk := fh.read(_FETCH_CHUNK):
87
+ digest.update(chunk)
88
+ size += len(chunk)
89
+ return digest.hexdigest(), size
90
+ raise ValueError(f"unsupported URL scheme {scheme!r} (https:// or file:// only)")
91
+
92
+
93
+ def _fetch_and_compare(
94
+ manifest: Manifest, extra_roots: tuple[Path, ...] = ()
95
+ ) -> tuple[int, list[str]]:
96
+ """Fetch every output asset and compare bytes against the manifest.
97
+
98
+ Returns ``(asset_count, failures)``. An asset that cannot be fetched is a
99
+ failure, not a skip. ``--fetch`` promises byte verification, so an
100
+ unverifiable asset must not contribute to an OK verdict. One asset
101
+ failing does not stop the rest: a corrupt asset and an unreachable one
102
+ should both surface in a single pass.
103
+ """
104
+ count = 0
105
+ failures: list[str] = []
106
+ for step in manifest.run.steps:
107
+ for asset in step.assets:
108
+ count += 1
109
+ label = f"asset {asset.asset_id[:8]} ({_redact_url(asset.url)})"
110
+ try:
111
+ digest, size = _hash_url_bytes(asset.url, extra_roots)
112
+ except Exception as exc:
113
+ failures.append(f"{label}: fetch failed: {_redact_text(str(exc))}")
114
+ continue
115
+ if digest != asset.sha256:
116
+ failures.append(
117
+ f"{label}: sha256 mismatch: manifest declares {asset.sha256}, "
118
+ f"fetched bytes hash to {digest}"
119
+ )
120
+ elif asset.size_bytes is not None and size != asset.size_bytes:
121
+ failures.append(
122
+ f"{label}: size mismatch: manifest declares "
123
+ f"{asset.size_bytes} bytes, fetched {size}"
124
+ )
125
+ return count, failures
126
+
127
+
128
+ @click.command()
129
+ @click.argument("file", type=click.Path(exists=True, dir_okay=False, path_type=Path))
130
+ @click.option(
131
+ "--hash-only",
132
+ is_flag=True,
133
+ help="Only verify canonical_hash; skip output sha256 and asset-metadata checks.",
134
+ )
135
+ @click.option(
136
+ "--fetch",
137
+ is_flag=True,
138
+ help="Also download each output asset and compare its bytes to the declared sha256.",
139
+ )
140
+ @click.option(
141
+ "--allowed-root",
142
+ "allowed_roots",
143
+ multiple=True,
144
+ type=click.Path(exists=True, file_okay=False, path_type=Path),
145
+ help=(
146
+ "With --fetch: additionally trust file:// assets under this directory "
147
+ "(repeatable). By default only the system temp directories are allowed; "
148
+ "pipelines run with output_dir= write assets elsewhere."
149
+ ),
150
+ )
151
+ def verify(file: Path, hash_only: bool, fetch: bool, allowed_roots: tuple[Path, ...]) -> None:
152
+ """Verify an embedded, sidecar, or standalone genblaze manifest."""
153
+ if fetch and hash_only:
154
+ raise click.UsageError("--fetch and --hash-only are mutually exclusive.")
155
+ if allowed_roots and not fetch:
156
+ raise click.UsageError("--allowed-root requires --fetch.")
157
+ try:
158
+ manifest = extract_manifest(file)
159
+ report = manifest.verification_report()
160
+ if not report.hash_ok:
161
+ click.echo("FAIL: manifest hash mismatch.", err=True)
162
+ raise click.exceptions.Exit(1)
163
+ if hash_only:
164
+ click.echo("OK: manifest hash verified. Asset bytes were not fetched or compared.")
165
+ return
166
+ if report.unverified_sha256_ids:
167
+ click.echo(
168
+ f"FAIL: {len(report.unverified_sha256_ids)} output asset(s) "
169
+ "missing or malformed sha256.",
170
+ err=True,
171
+ )
172
+ raise click.exceptions.Exit(1)
173
+ # Out-of-spec numeric/media_type metadata (e.g. width=0) is tolerated on
174
+ # load by parse_manifest() but fails verify() (#149); surface it here so
175
+ # the CLI verdict matches Manifest.verify()/report.ok instead of a stale
176
+ # "OK" that only checked sha256.
177
+ if report.invalid_metadata_ids:
178
+ click.echo(
179
+ f"FAIL: {len(report.invalid_metadata_ids)} output asset(s) "
180
+ "carry out-of-spec numeric/media_type metadata "
181
+ "(e.g. width=0, or a malformed media_type).",
182
+ err=True,
183
+ )
184
+ raise click.exceptions.Exit(1)
185
+ if fetch:
186
+ count, failures = _fetch_and_compare(manifest, allowed_roots)
187
+ if failures:
188
+ for line in failures:
189
+ click.echo(f"FAIL: {line}", err=True)
190
+ raise click.exceptions.Exit(1)
191
+ if count == 0:
192
+ # Distinguish "nothing to check" from "checked and matched":
193
+ # a vacuous OK must not read like a byte-verification pass.
194
+ click.echo("OK: manifest hash verified; no output assets to fetch.")
195
+ return
196
+ click.echo(
197
+ f"OK: manifest hash verified; {count} output asset(s) "
198
+ "fetched and matched their declared sha256."
199
+ )
200
+ return
201
+ click.echo(
202
+ "OK: manifest hash verified; all output assets declare sha256 and "
203
+ "carry in-spec metadata. Asset bytes were not fetched or compared; "
204
+ "add --fetch to verify the media itself."
205
+ )
206
+ except click.exceptions.Exit:
207
+ raise
208
+ except Exception as exc:
209
+ # Prefix with exception type so "PermissionError: ..." and
210
+ # "EmbeddingError: ..." are distinguishable at a glance.
211
+ raise click.ClickException(f"{type(exc).__name__}: {exc}") from exc
@@ -9,7 +9,7 @@ from genblaze_cli.commands.verify import verify
9
9
 
10
10
 
11
11
  @click.group()
12
- @click.version_option(package_name="genblaze-cli")
12
+ @click.version_option(package_name="genblaze-cli", prog_name="genblaze-cli")
13
13
  def cli() -> None:
14
14
  """genblaze — media generation manifest toolkit."""
15
15
 
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "genblaze-cli"
7
- version = "0.3.2"
7
+ version = "0.3.5"
8
8
  description = "CLI for genblaze manifest operations"
9
9
  authors = [{name = "Jeronimo De Leon", email = "jdeleon@backblaze.com"}]
10
10
  readme = "README.md"
@@ -12,7 +12,6 @@ requires-python = ">=3.11"
12
12
  license = "MIT"
13
13
  classifiers = [
14
14
  "Development Status :: 3 - Alpha",
15
- "License :: OSI Approved :: MIT License",
16
15
  "Environment :: Console",
17
16
  "Programming Language :: Python :: 3.11",
18
17
  "Programming Language :: Python :: 3.12",
@@ -23,8 +22,10 @@ classifiers = [
23
22
  keywords = ["genblaze", "ai", "media", "manifest", "provenance", "c2pa-ready", "genai", "pipeline", "cli", "command-line"]
24
23
 
25
24
  dependencies = [
26
- "genblaze-core>=0.3.4,<0.4",
27
- "click>=8.0",
25
+ "genblaze-core>=0.3.7,<0.4",
26
+ # <9: bounded-major convention (#61) — caps below the next major so a
27
+ # future click release can't silently break the CLI at resolve time.
28
+ "click>=8.0,<9",
28
29
  ]
29
30
 
30
31
  [project.urls]
@@ -6,6 +6,7 @@ import json
6
6
  import tomllib
7
7
  from pathlib import Path
8
8
 
9
+ import pytest
9
10
  from click.testing import CliRunner
10
11
  from genblaze_cli.main import cli
11
12
  from genblaze_core._utils import MAX_MANIFEST_BYTES
@@ -13,8 +14,10 @@ from genblaze_core.builders import RunBuilder, StepBuilder
13
14
  from genblaze_core.canonical.json import canonical_json
14
15
  from genblaze_core.media.png import PngHandler
15
16
  from genblaze_core.models.asset import Asset
16
- from genblaze_core.models.enums import Modality, ProviderErrorCode, StepStatus
17
+ from genblaze_core.models.enums import Modality, ProviderErrorCode, StepStatus, StepType
17
18
  from genblaze_core.models.manifest import Manifest
19
+ from genblaze_core.models.run import Run
20
+ from genblaze_core.models.step import Step
18
21
  from genblaze_core.testing import MockProvider
19
22
  from PIL import Image
20
23
 
@@ -55,6 +58,28 @@ def _create_url_only_manifest(*, schema_version: str | None = None) -> Manifest:
55
58
  return manifest
56
59
 
57
60
 
61
+ def _url_only_manifest_with_bad_metadata() -> Manifest:
62
+ """A hash-valid, sha256-valid manifest whose sole output asset carries an
63
+ out-of-spec dimension (width=0) — the shape parse_manifest() tolerates on
64
+ load but verify() must reject (#149). Injected via object.__setattr__ to
65
+ bypass construction validation, mirroring a foreign-authored manifest."""
66
+ manifest = _create_url_only_manifest()
67
+ asset = manifest.run.steps[0].assets[0]
68
+ object.__setattr__(asset, "sha256", "a" * 64) # valid, so only metadata fails
69
+ object.__setattr__(asset, "width", 0)
70
+ manifest.compute_hash()
71
+ return manifest
72
+
73
+
74
+ def _combined_output(result) -> str:
75
+ """CLI stdout+stderr, robust across Click versions. Click >=8.2 captures
76
+ stderr separately; 8.1.x mixes it into output and raises on ``.stderr``."""
77
+ try:
78
+ return result.output + result.stderr
79
+ except ValueError:
80
+ return result.output
81
+
82
+
58
83
  def test_extract_json(tmp_path: Path) -> None:
59
84
  png = _create_embedded_png(tmp_path)
60
85
  runner = CliRunner()
@@ -91,6 +116,7 @@ def test_extract_summary(tmp_path: Path) -> None:
91
116
  assert "Run ID:" in result.output
92
117
  assert "Hash OK:" in result.output
93
118
  assert "Output sha256:" in result.output
119
+ assert "Output metadata:" in result.output
94
120
  assert "Verified:" in result.output
95
121
 
96
122
 
@@ -241,6 +267,75 @@ def test_verify_rejects_malformed_output_sha256(tmp_path: Path) -> None:
241
267
  assert "1 output asset(s) missing or malformed sha256" in combined
242
268
 
243
269
 
270
+ def test_verify_rejects_out_of_spec_asset_metadata(tmp_path: Path) -> None:
271
+ """#149/#155: a manifest with a valid hash and valid sha256 but out-of-spec
272
+ asset metadata (e.g. width=0, which parse_manifest() tolerates on load) must
273
+ fail `verify`, so the CLI verdict agrees with Manifest.verify()/report.ok
274
+ rather than reporting OK because only sha256 was checked."""
275
+ manifest = _url_only_manifest_with_bad_metadata()
276
+ # Assert the model layer first so this pins the boundary even in a Click
277
+ # build where CLI output parsing behaves differently.
278
+ assert not manifest.verify()
279
+
280
+ png_path = tmp_path / "bad-metadata.png"
281
+ Image.new("RGBA", (1, 1), (255, 0, 0, 255)).save(png_path)
282
+ png_path.with_suffix(png_path.suffix + ".genblaze.json").write_text(
283
+ manifest.to_canonical_json(),
284
+ encoding="utf-8",
285
+ )
286
+
287
+ runner = CliRunner()
288
+ result = runner.invoke(cli, ["verify", str(png_path)])
289
+ combined = _combined_output(result)
290
+
291
+ assert result.exit_code != 0
292
+ assert "out-of-spec" in combined
293
+ # Prove it's the metadata boundary, not a sha256 or hash failure.
294
+ assert "missing or malformed sha256" not in combined
295
+ assert "hash mismatch" not in combined
296
+
297
+
298
+ def test_verify_hash_only_skips_metadata_check(tmp_path: Path) -> None:
299
+ """--hash-only must short-circuit before the metadata check: an out-of-spec
300
+ manifest whose hash still matches exits 0 (metadata lives inside the hash
301
+ payload, so hash-only stays an honest integrity-only claim). Pins the check
302
+ order so a refactor can't move the metadata guard ahead of the early return."""
303
+ manifest = _url_only_manifest_with_bad_metadata()
304
+ png_path = tmp_path / "bad-metadata-hash-only.png"
305
+ Image.new("RGBA", (1, 1), (255, 0, 0, 255)).save(png_path)
306
+ png_path.with_suffix(png_path.suffix + ".genblaze.json").write_text(
307
+ manifest.to_canonical_json(),
308
+ encoding="utf-8",
309
+ )
310
+
311
+ runner = CliRunner()
312
+ result = runner.invoke(cli, ["verify", "--hash-only", str(png_path)])
313
+
314
+ assert result.exit_code == 0
315
+ assert "manifest hash verified" in result.output
316
+
317
+
318
+ def test_extract_summary_surfaces_out_of_spec_metadata(tmp_path: Path) -> None:
319
+ """#149/#155: `extract --format summary` itemizes invalid metadata so a
320
+ `Verified: False` verdict always has a visible reason and agrees with
321
+ `verify` (mirrors the sha256 parity test)."""
322
+ manifest = _url_only_manifest_with_bad_metadata()
323
+ png_path = tmp_path / "bad-metadata-extract.png"
324
+ Image.new("RGBA", (1, 1), (255, 0, 0, 255)).save(png_path)
325
+ png_path.with_suffix(png_path.suffix + ".genblaze.json").write_text(
326
+ manifest.to_canonical_json(),
327
+ encoding="utf-8",
328
+ )
329
+
330
+ runner = CliRunner()
331
+ result = runner.invoke(cli, ["extract", "--format", "summary", str(png_path)])
332
+
333
+ assert result.exit_code == 0
334
+ assert "Output sha256: 0 missing or malformed" in result.output
335
+ assert "Output metadata: 1 out of spec" in result.output
336
+ assert "Verified: False" in result.output
337
+
338
+
244
339
  def test_verify_reports_legacy_unverified_assets(tmp_path: Path) -> None:
245
340
  manifest = _create_url_only_manifest(schema_version="1.5")
246
341
  png_path = tmp_path / "legacy-url-only.png"
@@ -431,6 +526,30 @@ def test_replay_aborts_when_no_allowlist_and_declined(tmp_path: Path) -> None:
431
526
  assert "Aborted" in result.output or "Execute with provider" in result.output
432
527
 
433
528
 
529
+ def test_replay_reports_clear_error_for_providerless_step(tmp_path: Path) -> None:
530
+ """A provider-less step (INGEST/IMPORT, valid per Step's own model) must
531
+ produce a clear ClickException on replay --no-dry-run, not a TypeError
532
+ from None flowing into sorted()/dict keys/_load_provider (issue #43)."""
533
+ step = Step(
534
+ provider=None,
535
+ model="rss",
536
+ step_type=StepType.INGEST,
537
+ status=StepStatus.SUCCEEDED,
538
+ assets=[Asset(url="https://example.com/a.png", media_type="image/png")],
539
+ )
540
+ run = Run(name="ingest-test", steps=[step])
541
+ manifest = Manifest.from_run(run)
542
+ manifest_path = tmp_path / "ingest.json"
543
+ manifest_path.write_text(manifest.to_canonical_json(), encoding="utf-8")
544
+
545
+ runner = CliRunner()
546
+ result = runner.invoke(cli, ["replay", str(manifest_path), "--no-dry-run"])
547
+
548
+ assert result.exit_code != 0
549
+ assert "TypeError" not in result.output
550
+ assert "no provider" in result.output.lower()
551
+
552
+
434
553
  def test_replay_no_dry_run_exits_nonzero_when_run_fails(tmp_path: Path, monkeypatch) -> None:
435
554
  """A replayed failed run must not look successful to automation."""
436
555
 
@@ -471,5 +590,76 @@ def test_index(tmp_path: Path) -> None:
471
590
  result = runner.invoke(cli, ["index", str(manifest_path), "-o", str(out_dir)])
472
591
  assert result.exit_code == 0
473
592
  assert "Indexed" in result.output
474
- parquet_files = list(out_dir.rglob("*.parquet"))
475
- assert len(parquet_files) > 0
593
+
594
+
595
+ # --- Issue #64: directories rejected with a clear error; non-object JSON is
596
+ # handled consistently across index/replay ---
597
+
598
+
599
+ @pytest.mark.parametrize("command", ["extract", "verify", "index", "replay"])
600
+ def test_commands_reject_directory_with_clear_error(tmp_path: Path, command: str) -> None:
601
+ """A directory argument must fail with click's own actionable error
602
+ instead of leaking a confusing downstream error (e.g. EmbeddingError or
603
+ [Errno 21] Is a directory)."""
604
+ runner = CliRunner()
605
+ result = runner.invoke(cli, [command, str(tmp_path)])
606
+ assert result.exit_code != 0
607
+ assert "is a directory" in result.output.lower()
608
+
609
+
610
+ @pytest.mark.parametrize("command", ["index", "replay"])
611
+ def test_non_object_manifest_json_gives_consistent_clean_error(
612
+ tmp_path: Path, command: str
613
+ ) -> None:
614
+ """A top-level JSON array (valid JSON, invalid manifest shape) must fail
615
+ with the same clean error for both index and replay, not an internal
616
+ AttributeError leaked from parse_manifest's dict-only .get() call."""
617
+ array_path = tmp_path / "not-a-manifest.json"
618
+ array_path.write_text("[1, 2, 3]", encoding="utf-8")
619
+
620
+ runner = CliRunner()
621
+ result = runner.invoke(cli, [command, str(array_path)])
622
+
623
+ assert result.exit_code != 0
624
+ assert "must be a JSON object" in result.output
625
+ assert "AttributeError" not in result.output
626
+ assert "'list' object has no attribute 'get'" not in result.output
627
+
628
+
629
+ # --- Fix B: extract -o / --output ---
630
+
631
+
632
+ def test_extract_output_flag_writes_file(tmp_path: Path) -> None:
633
+ """-o writes manifest JSON to file; stdout is empty."""
634
+ png = _create_embedded_png(tmp_path)
635
+ out_file = tmp_path / "manifest.json"
636
+ runner = CliRunner()
637
+ result = runner.invoke(cli, ["extract", str(png), "-o", str(out_file)])
638
+ assert result.exit_code == 0, result.output
639
+ # Output goes to file, not stdout
640
+ assert result.output.strip() == ""
641
+ assert out_file.exists()
642
+ data = json.loads(out_file.read_text(encoding="utf-8"))
643
+ assert "canonical_hash" in data
644
+ assert "run" in data
645
+
646
+
647
+ def test_extract_output_flag_stdout_default(tmp_path: Path) -> None:
648
+ """Without -o, JSON goes to stdout (backward compat)."""
649
+ png = _create_embedded_png(tmp_path)
650
+ runner = CliRunner()
651
+ result = runner.invoke(cli, ["extract", str(png)])
652
+ assert result.exit_code == 0
653
+ data = json.loads(result.output)
654
+ assert "canonical_hash" in data
655
+
656
+
657
+ # --- Fix C: --version label ---
658
+
659
+
660
+ def test_version_label_shows_cli_package() -> None:
661
+ """--version must say 'genblaze-cli' not the umbrella package name."""
662
+ runner = CliRunner()
663
+ result = runner.invoke(cli, ["--version"])
664
+ assert result.exit_code == 0
665
+ assert "genblaze-cli" in result.output
@@ -0,0 +1,312 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+
5
+ import pytest
6
+ from click.testing import CliRunner
7
+ from genblaze_cli.main import cli
8
+ from genblaze_core.builders import RunBuilder, StepBuilder
9
+ from genblaze_core.models.asset import Asset
10
+ from genblaze_core.models.enums import StepStatus
11
+ from genblaze_core.models.manifest import Manifest
12
+
13
+
14
+ def _create_fetch_manifest(tmp_path: Path, data: bytes = b"genblaze bytes") -> tuple[Path, Path]:
15
+ """Manifest JSON + on-disk file:// asset whose sha256/size are byte-bound."""
16
+ asset_path = tmp_path / "asset.bin"
17
+ asset_path.write_bytes(data)
18
+ step = StepBuilder("test", "test-model").prompt("hello").build()
19
+ step.status = StepStatus.SUCCEEDED
20
+ asset = Asset(url=asset_path.as_uri(), media_type="image/png")
21
+ asset.set_hash(data)
22
+ step.assets = [asset]
23
+ run = RunBuilder("fetch-test").add_step(step).build()
24
+ manifest = Manifest.from_run(run)
25
+ manifest_path = tmp_path / "manifest.json"
26
+ manifest_path.write_text(manifest.to_canonical_json(), encoding="utf-8")
27
+ return manifest_path, asset_path
28
+
29
+
30
+ def test_verify_fetch_matching_bytes(tmp_path: Path) -> None:
31
+ manifest_path, _ = _create_fetch_manifest(tmp_path)
32
+
33
+ runner = CliRunner()
34
+ result = runner.invoke(cli, ["verify", "--fetch", str(manifest_path)])
35
+
36
+ assert result.exit_code == 0, result.output
37
+ assert "1 output asset(s) fetched and matched their declared sha256" in result.output
38
+
39
+
40
+ def test_verify_fetch_detects_tampered_bytes(tmp_path: Path) -> None:
41
+ manifest_path, asset_path = _create_fetch_manifest(tmp_path)
42
+ asset_path.write_bytes(b"tampered after the manifest was written")
43
+
44
+ runner = CliRunner()
45
+ result = runner.invoke(cli, ["verify", "--fetch", str(manifest_path)])
46
+ combined = result.output + getattr(result, "stderr", "")
47
+
48
+ assert result.exit_code != 0
49
+ assert "sha256 mismatch" in combined
50
+
51
+
52
+ def test_verify_fetch_detects_size_mismatch(tmp_path: Path) -> None:
53
+ """Correct digest but wrong declared size_bytes must fail --fetch."""
54
+ data = b"genblaze bytes"
55
+ asset_path = tmp_path / "asset.bin"
56
+ asset_path.write_bytes(data)
57
+ step = StepBuilder("test", "test-model").prompt("hello").build()
58
+ step.status = StepStatus.SUCCEEDED
59
+ asset = Asset(url=asset_path.as_uri(), media_type="image/png")
60
+ asset.set_hash(data)
61
+ asset.size_bytes = len(data) + 1
62
+ step.assets = [asset]
63
+ run = RunBuilder("fetch-size").add_step(step).build()
64
+ manifest_path = tmp_path / "manifest.json"
65
+ manifest_path.write_text(Manifest.from_run(run).to_canonical_json(), encoding="utf-8")
66
+
67
+ runner = CliRunner()
68
+ result = runner.invoke(cli, ["verify", "--fetch", str(manifest_path)])
69
+ combined = result.output + getattr(result, "stderr", "")
70
+
71
+ assert result.exit_code != 0
72
+ assert "size mismatch" in combined
73
+
74
+
75
+ def test_verify_fetch_reports_every_failing_asset(tmp_path: Path) -> None:
76
+ """One bad asset must not stop verification of the rest."""
77
+ tampered = tmp_path / "tampered.bin"
78
+ tampered.write_bytes(b"original")
79
+ missing = tmp_path / "missing.bin"
80
+ missing.write_bytes(b"will be deleted")
81
+ step = StepBuilder("test", "test-model").prompt("hello").build()
82
+ step.status = StepStatus.SUCCEEDED
83
+ assets = []
84
+ for path in (tampered, missing):
85
+ asset = Asset(url=path.as_uri(), media_type="image/png")
86
+ asset.set_hash(path.read_bytes())
87
+ assets.append(asset)
88
+ step.assets = assets
89
+ run = RunBuilder("fetch-multi").add_step(step).build()
90
+ manifest_path = tmp_path / "manifest.json"
91
+ manifest_path.write_text(Manifest.from_run(run).to_canonical_json(), encoding="utf-8")
92
+ tampered.write_bytes(b"changed")
93
+ missing.unlink()
94
+
95
+ runner = CliRunner()
96
+ result = runner.invoke(cli, ["verify", "--fetch", str(manifest_path)])
97
+ combined = result.output + getattr(result, "stderr", "")
98
+
99
+ assert result.exit_code != 0
100
+ assert "sha256 mismatch" in combined
101
+ assert "fetch failed" in combined
102
+
103
+
104
+ def test_verify_fetch_rejects_hash_only_combo(tmp_path: Path) -> None:
105
+ manifest_path, _ = _create_fetch_manifest(tmp_path)
106
+
107
+ runner = CliRunner()
108
+ result = runner.invoke(cli, ["verify", "--fetch", "--hash-only", str(manifest_path)])
109
+ combined = result.output + getattr(result, "stderr", "")
110
+
111
+ assert result.exit_code != 0
112
+ assert "mutually exclusive" in combined
113
+
114
+
115
+ def test_verify_fetch_https_streams_through_pinned_transfer(
116
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
117
+ ) -> None:
118
+ """https assets must go through transfer's SSRF-pinned stream, chunked, and
119
+ release the connection afterwards."""
120
+ data = b"remote asset bytes" * 1024
121
+ step = StepBuilder("test", "test-model").prompt("hello").build()
122
+ step.status = StepStatus.SUCCEEDED
123
+ asset = Asset(url="https://cdn.example.com/output.png", media_type="image/png")
124
+ asset.set_hash(data)
125
+ step.assets = [asset]
126
+ run = RunBuilder("fetch-https").add_step(step).build()
127
+ manifest_path = tmp_path / "manifest.json"
128
+ manifest_path.write_text(Manifest.from_run(run).to_canonical_json(), encoding="utf-8")
129
+
130
+ released = {"called": False}
131
+
132
+ class _FakeResp:
133
+ def __init__(self) -> None:
134
+ self._buf = data
135
+
136
+ def read(self, size: int) -> bytes:
137
+ chunk, self._buf = self._buf[:size], self._buf[size:]
138
+ return chunk
139
+
140
+ def release_conn(self) -> None:
141
+ released["called"] = True
142
+
143
+ monkeypatch.setattr(
144
+ "genblaze_core.storage.transfer._http_get_stream",
145
+ lambda url, *, timeout: _FakeResp(),
146
+ )
147
+
148
+ runner = CliRunner()
149
+ result = runner.invoke(cli, ["verify", "--fetch", str(manifest_path)])
150
+
151
+ assert result.exit_code == 0, result.output
152
+ assert "fetched and matched" in result.output
153
+ assert released["called"]
154
+
155
+
156
+ def test_verify_fetch_redacts_presigned_query(
157
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
158
+ ) -> None:
159
+ """A presigned query string is a bearer credential; it must not survive
160
+ into CLI output even when the transfer layer's error message echoes it."""
161
+ from genblaze_core.exceptions import StorageError
162
+
163
+ url = "https://cdn.example.com/output.png?X-Amz-Signature=SECRETSIG"
164
+ step = StepBuilder("test", "test-model").prompt("hello").build()
165
+ step.status = StepStatus.SUCCEEDED
166
+ asset = Asset(url=url, media_type="image/png")
167
+ asset.set_hash(b"whatever")
168
+ step.assets = [asset]
169
+ run = RunBuilder("fetch-redact").add_step(step).build()
170
+ manifest_path = tmp_path / "manifest.json"
171
+ manifest_path.write_text(Manifest.from_run(run).to_canonical_json(), encoding="utf-8")
172
+
173
+ def _raise(url: str, *, timeout: float) -> None:
174
+ raise StorageError(f"HTTP 403 downloading {url}")
175
+
176
+ monkeypatch.setattr("genblaze_core.storage.transfer._http_get_stream", _raise)
177
+
178
+ runner = CliRunner()
179
+ result = runner.invoke(cli, ["verify", "--fetch", str(manifest_path)])
180
+ combined = result.output + getattr(result, "stderr", "")
181
+
182
+ assert result.exit_code != 0
183
+ assert "SECRETSIG" not in combined
184
+ assert "REDACTED" in combined
185
+
186
+
187
+ def test_verify_fetch_rejects_file_url_outside_allowed_roots(tmp_path: Path) -> None:
188
+ step = StepBuilder("test", "test-model").prompt("hello").build()
189
+ step.status = StepStatus.SUCCEEDED
190
+ asset = Asset(url="file:///etc/hosts", media_type="image/png")
191
+ asset.sha256 = "f" * 64
192
+ step.assets = [asset]
193
+ run = RunBuilder("fetch-roots").add_step(step).build()
194
+ manifest_path = tmp_path / "manifest.json"
195
+ manifest_path.write_text(Manifest.from_run(run).to_canonical_json(), encoding="utf-8")
196
+
197
+ runner = CliRunner()
198
+ result = runner.invoke(cli, ["verify", "--fetch", str(manifest_path)])
199
+ combined = result.output + getattr(result, "stderr", "")
200
+
201
+ assert result.exit_code != 0
202
+ assert "outside allowed roots" in combined
203
+
204
+
205
+ def test_verify_default_message_points_to_fetch(tmp_path: Path) -> None:
206
+ """The default OK verdict must route users to --fetch instead of
207
+ dead-ending at 'bytes were not compared'."""
208
+ manifest_path, _ = _create_fetch_manifest(tmp_path)
209
+
210
+ runner = CliRunner()
211
+ result = runner.invoke(cli, ["verify", str(manifest_path)])
212
+
213
+ assert result.exit_code == 0
214
+ assert "add --fetch" in result.output
215
+
216
+
217
+ def test_verify_fetch_blocks_ssrf_urls_via_real_transfer_guard(tmp_path: Path) -> None:
218
+ """No mocking: --fetch must route through core's real SSRF guard.
219
+
220
+ localhost and the cloud-metadata IP are rejected by resolve_ssrf before any
221
+ connection is opened, so this exercises the genuine security path offline.
222
+ If anyone ever swaps the hardened fetch for a naive HTTP client, this test
223
+ starts making real network calls and fails.
224
+ """
225
+ step = StepBuilder("test", "test-model").prompt("hello").build()
226
+ step.status = StepStatus.SUCCEEDED
227
+ assets = []
228
+ for url in ("https://localhost/asset.png", "https://169.254.169.254/latest/meta-data"):
229
+ asset = Asset(url=url, media_type="image/png")
230
+ asset.sha256 = "f" * 64
231
+ assets.append(asset)
232
+ step.assets = assets
233
+ run = RunBuilder("fetch-ssrf").add_step(step).build()
234
+ manifest_path = tmp_path / "manifest.json"
235
+ manifest_path.write_text(Manifest.from_run(run).to_canonical_json(), encoding="utf-8")
236
+
237
+ runner = CliRunner()
238
+ result = runner.invoke(cli, ["verify", "--fetch", str(manifest_path)])
239
+ # result.output is the mixed stream on every click version (stderr raises
240
+ # on click<8.2; on >=8.2 output+stderr would double-count these lines).
241
+ combined = result.output
242
+
243
+ assert result.exit_code != 0
244
+ # Both assets must surface as fetch failures in a single pass.
245
+ assert combined.count("fetch failed") == 2
246
+ # And the failures must come from the SSRF guard, not a connection attempt.
247
+ assert "not allowed" in combined
248
+
249
+
250
+ def test_verify_fetch_allowed_root_admits_file_outside_default_roots(
251
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
252
+ ) -> None:
253
+ """--allowed-root extends the file:// allowlist, mirroring the transfer
254
+ layer's extra_roots semantics for pipelines run with output_dir=."""
255
+ manifest_path, _ = _create_fetch_manifest(tmp_path)
256
+ # Simulate a root outside the temp-dir allowlist: with no default roots,
257
+ # tmp_path is only reachable via --allowed-root.
258
+ monkeypatch.setattr("genblaze_core._utils.ALLOWED_FILE_ROOTS", ())
259
+
260
+ runner = CliRunner()
261
+ result = runner.invoke(
262
+ cli, ["verify", "--fetch", "--allowed-root", str(tmp_path), str(manifest_path)]
263
+ )
264
+
265
+ assert result.exit_code == 0, result.output
266
+ assert "fetched and matched" in result.output
267
+
268
+
269
+ def test_verify_fetch_allowed_root_requires_fetch(tmp_path: Path) -> None:
270
+ manifest_path, _ = _create_fetch_manifest(tmp_path)
271
+
272
+ runner = CliRunner()
273
+ result = runner.invoke(cli, ["verify", "--allowed-root", str(tmp_path), str(manifest_path)])
274
+ combined = result.output + getattr(result, "stderr", "")
275
+
276
+ assert result.exit_code != 0
277
+ assert "requires --fetch" in combined
278
+
279
+
280
+ def test_verify_fetch_no_output_assets_reports_nothing_to_fetch(tmp_path: Path) -> None:
281
+ """Zero output assets must not print a vacuous 'fetched and matched' OK."""
282
+ step = StepBuilder("test", "test-model").prompt("hello").build()
283
+ step.status = StepStatus.SUCCEEDED
284
+ step.assets = []
285
+ run = RunBuilder("fetch-empty").add_step(step).build()
286
+ manifest_path = tmp_path / "manifest.json"
287
+ manifest_path.write_text(Manifest.from_run(run).to_canonical_json(), encoding="utf-8")
288
+
289
+ runner = CliRunner()
290
+ result = runner.invoke(cli, ["verify", "--fetch", str(manifest_path)])
291
+
292
+ assert result.exit_code == 0, result.output
293
+ assert "no output assets to fetch" in result.output
294
+
295
+
296
+ def test_verify_fetch_rejects_http_scheme(tmp_path: Path) -> None:
297
+ """Plain http:// is rejected; https-only, same policy as the transfer layer."""
298
+ step = StepBuilder("test", "test-model").prompt("hello").build()
299
+ step.status = StepStatus.SUCCEEDED
300
+ asset = Asset(url="http://cdn.example.com/output.png", media_type="image/png")
301
+ asset.sha256 = "f" * 64
302
+ step.assets = [asset]
303
+ run = RunBuilder("fetch-http").add_step(step).build()
304
+ manifest_path = tmp_path / "manifest.json"
305
+ manifest_path.write_text(Manifest.from_run(run).to_canonical_json(), encoding="utf-8")
306
+
307
+ runner = CliRunner()
308
+ result = runner.invoke(cli, ["verify", "--fetch", str(manifest_path)])
309
+ combined = result.output + getattr(result, "stderr", "")
310
+
311
+ assert result.exit_code != 0
312
+ assert "unsupported URL scheme" in combined
@@ -1,44 +0,0 @@
1
- """Verify command — check manifest hash and output sha256 coverage."""
2
-
3
- from pathlib import Path
4
-
5
- import click
6
-
7
- from genblaze_cli.manifest_io import extract_manifest
8
-
9
-
10
- @click.command()
11
- @click.argument("file", type=click.Path(exists=True, path_type=Path))
12
- @click.option(
13
- "--hash-only",
14
- is_flag=True,
15
- help="Only verify canonical_hash; do not require output sha256 declarations.",
16
- )
17
- def verify(file: Path, hash_only: bool) -> None:
18
- """Verify an embedded, sidecar, or standalone genblaze manifest."""
19
- try:
20
- manifest = extract_manifest(file)
21
- report = manifest.verification_report()
22
- if not report.hash_ok:
23
- click.echo("FAIL: manifest hash mismatch.", err=True)
24
- raise click.exceptions.Exit(1)
25
- if hash_only:
26
- click.echo("OK: manifest hash verified. Asset bytes were not fetched or compared.")
27
- return
28
- if report.unverified_sha256_ids:
29
- click.echo(
30
- f"FAIL: {len(report.unverified_sha256_ids)} output asset(s) "
31
- "missing or malformed sha256.",
32
- err=True,
33
- )
34
- raise click.exceptions.Exit(1)
35
- click.echo(
36
- "OK: manifest hash verified; all output assets declare sha256. "
37
- "Asset bytes were not fetched or compared."
38
- )
39
- except click.exceptions.Exit:
40
- raise
41
- except Exception as exc:
42
- # Prefix with exception type so "PermissionError: ..." and
43
- # "EmbeddingError: ..." are distinguishable at a glance.
44
- raise click.ClickException(f"{type(exc).__name__}: {exc}") from exc