testzeus-cli 0.0.32__tar.gz → 0.0.34__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.
Files changed (49) hide show
  1. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/PKG-INFO +2 -2
  2. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/pyproject.toml +2 -2
  3. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/cli.py +2 -0
  4. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/records.py +10 -1
  5. testzeus_cli-0.0.34/testzeus_cli/commands/test_blocks.py +464 -0
  6. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/tests.py +30 -49
  7. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/record-contract.json +4 -1
  8. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/record_contract.py +11 -0
  9. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/utils/client.py +2 -2
  10. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/LICENSE +0 -0
  11. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/README.md +0 -0
  12. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/__init__.py +0 -0
  13. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/agent-capabilities.json +0 -0
  14. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/agent_capabilities.py +0 -0
  15. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/auth.py +0 -0
  16. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/__init__.py +0 -0
  17. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/agent_harness.py +0 -0
  18. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/capabilities.py +0 -0
  19. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/connected_environments.py +0 -0
  20. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/daemon.py +0 -0
  21. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/device_pool.py +0 -0
  22. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/environments.py +0 -0
  23. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/hypermind_code_blocks.py +0 -0
  24. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/knowledge_bases.py +0 -0
  25. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/knowledge_documents.py +0 -0
  26. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/notification_channels.py +0 -0
  27. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/qa.py +0 -0
  28. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/tags.py +0 -0
  29. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/test_data.py +0 -0
  30. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/test_report_runs.py +0 -0
  31. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/test_report_schedules.py +0 -0
  32. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/test_run_groups.py +0 -0
  33. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/test_runs.py +0 -0
  34. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/test_suite_node_runs.py +0 -0
  35. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/test_suite_runs.py +0 -0
  36. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/test_suite_schedules.py +0 -0
  37. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/test_suites.py +0 -0
  38. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/tests_ai_generator.py +0 -0
  39. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/tests_authoring.py +0 -0
  40. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/commands/user_integrations.py +0 -0
  41. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/config.py +0 -0
  42. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/record_query.py +0 -0
  43. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/utils/__init__.py +0 -0
  44. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/utils/auth.py +0 -0
  45. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/utils/files.py +0 -0
  46. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/utils/formatters.py +0 -0
  47. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/utils/links.py +0 -0
  48. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/utils/profile.py +0 -0
  49. {testzeus_cli-0.0.32 → testzeus_cli-0.0.34}/testzeus_cli/utils/validators.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: testzeus-cli
3
- Version: 0.0.32
3
+ Version: 0.0.34
4
4
  Summary: Command-line interface for TestZeus testing platform
5
5
  License-File: LICENSE
6
6
  Author: Shriyansh Agnihotri
@@ -22,7 +22,7 @@ Requires-Dist: pocketbase (>=0.15.0,<0.16.0)
22
22
  Requires-Dist: pydantic (>=2.0.0,<3.0.0)
23
23
  Requires-Dist: pyyaml (>=6.0,<7.0)
24
24
  Requires-Dist: rich (>=13.3.1,<14.0.0)
25
- Requires-Dist: testzeus-sdk (>=0.0.27,<0.1.0)
25
+ Requires-Dist: testzeus-sdk (>=0.0.28,<0.1.0)
26
26
  Requires-Dist: toml (>=0.10.2,<0.11.0)
27
27
  Project-URL: Repository, https://github.com/test-zeus-ai/testzeus-cli
28
28
  Description-Content-Type: text/markdown
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [tool.poetry]
6
6
  name = "testzeus-cli"
7
- version = "0.0.32"
7
+ version = "0.0.34"
8
8
  description = "Command-line interface for TestZeus testing platform"
9
9
  authors = ["Shriyansh Agnihotri <shriyansh@testzeus.com>"]
10
10
  readme = "README.md"
@@ -22,7 +22,7 @@ pydantic = "^2.0.0"
22
22
  pyyaml = "^6.0"
23
23
  keyring = "^24.0.0"
24
24
  ipdb = "^0.13.13"
25
- testzeus-sdk = ">=0.0.27,<0.1.0"
25
+ testzeus-sdk = ">=0.0.28,<0.1.0"
26
26
  pocketbase = "^0.15.0"
27
27
  toml = "^0.10.2"
28
28
  aiohttp = "^3.14.1"
@@ -21,6 +21,7 @@ from testzeus_cli.commands.notification_channels import notification_channels_gr
21
21
  from testzeus_cli.commands.qa import qa_group
22
22
  from testzeus_cli.commands.records import records_group
23
23
  from testzeus_cli.commands.tags import tags_group
24
+ from testzeus_cli.commands.test_blocks import test_blocks_group
24
25
  from testzeus_cli.commands.test_data import test_data_group
25
26
  from testzeus_cli.commands.test_report_runs import test_report_runs_group
26
27
  from testzeus_cli.commands.test_report_schedules import test_report_schedules_group
@@ -81,6 +82,7 @@ cli.add_command(session_clear_command, name="session-clear")
81
82
  cli.add_command(session_status_command, name="session-status")
82
83
  cli.add_command(session_list_command, name="session-list")
83
84
  cli.add_command(tests_group)
85
+ cli.add_command(test_blocks_group)
84
86
  cli.add_command(capabilities_group)
85
87
  cli.add_command(qa_group)
86
88
  cli.add_command(records_group)
@@ -8,7 +8,10 @@ import click
8
8
  from testzeus_sdk import TestZeusClient
9
9
 
10
10
  from testzeus_cli.config import get_client_config
11
- from testzeus_cli.record_contract import PATCH_FIELDS, RESOURCES, describe_resources
11
+ from testzeus_cli.record_contract import (PATCH_FIELDS, RESOURCES,
12
+ TEST_BLOCKS_BUILDER_FIELDS,
13
+ describe_resources,
14
+ is_test_blocks_record)
12
15
  from testzeus_cli.record_query import query_records, validate_query
13
16
  from testzeus_cli.utils.auth import initialize_client_with_token
14
17
  from testzeus_cli.utils.formatters import format_output
@@ -77,6 +80,8 @@ def copy(ctx, resource, record_id, name):
77
80
  raise ValueError("Copy requires source ownership by the authenticated tenant")
78
81
  if source.get("is_deleted"):
79
82
  raise ValueError("Cannot copy a deleted record")
83
+ if resource == "tests" and is_test_blocks_record(source):
84
+ raise ValueError("Test Blocks tests keep their steps outside the test record, so they cannot be copied here; create one with 'testzeus test-blocks create'")
80
85
  payload = {key: source[key] for key in spec["copyFields"] if key in source}
81
86
  payload.update(name=name.strip(), tenant=tenant, modified_by=user)
82
87
  if "is_deleted" in spec["fields"]:
@@ -136,6 +141,10 @@ def patch_record(ctx, resource, record_id, changes, expected_updated):
136
141
  raise ValueError("Patch requires ownership by the authenticated tenant")
137
142
  if expected_updated is not None and source.get("updated") != expected_updated:
138
143
  raise ValueError("Record changed since it was read. Read it again before editing.")
144
+ if resource == "tests" and is_test_blocks_record(source) and set(data) & TEST_BLOCKS_BUILDER_FIELDS:
145
+ raise ValueError(
146
+ "Test Blocks tests change these fields through 'testzeus test-blocks config' (steps through add-step/update-step): " + ", ".join(sorted(set(data) & TEST_BLOCKS_BUILDER_FIELDS))
147
+ )
139
148
  result = await client.request("PATCH", endpoint, json_data={**data, "modified_by": user})
140
149
  return {"id": result["id"], "name": result.get("name"), "updated": result.get("updated"), "changedFields": list(data), "verified": {key: result.get(key) for key in data}}
141
150
 
@@ -0,0 +1,464 @@
1
+ """
2
+ Commands for authoring and running Test Blocks tests in TestZeus CLI.
3
+
4
+ A Test Blocks test is an ordered list of steps (browser Playwright code or
5
+ backend ``tz`` Python) instead of a Gherkin feature. A test only runs once
6
+ every step is verified, so the flow is: create -> add-step -> verify -> save -> run.
7
+ """
8
+
9
+ import asyncio
10
+ import json
11
+ import time
12
+ from pathlib import Path
13
+
14
+ import click
15
+
16
+ from testzeus_cli.utils.client import run_client_operation
17
+ from testzeus_cli.utils.formatters import format_output, print_message
18
+ from testzeus_cli.utils.validators import validate_id
19
+
20
+ STEP_TYPES = ["browser", "mobile", "backend", "soql", "apex", "http"]
21
+ RUNNABLE_VERIFICATION = ("verified", "inferred", "transcribed")
22
+ STEP_COLUMNS = ["position", "id", "label", "step_type", "verification", "assert"]
23
+
24
+
25
+ @click.group(name="test-blocks")
26
+ def test_blocks_group():
27
+ """Author, verify, and run Test Blocks tests"""
28
+ pass
29
+
30
+
31
+ def _manager(client):
32
+ manager = getattr(client, "test_blocks", None)
33
+ if manager is None:
34
+ raise click.ClickException("Test Blocks commands need testzeus-sdk>=0.0.28. Upgrade with: pip install -U testzeus-sdk")
35
+ return manager
36
+
37
+
38
+ def _run(ctx, operation):
39
+ try:
40
+ return run_client_operation(ctx, lambda client: operation(_manager(client)))
41
+ except click.ClickException:
42
+ raise
43
+ except Exception as exc:
44
+ raise click.ClickException(str(exc)) from exc
45
+
46
+
47
+ def _id(value, kind):
48
+ try:
49
+ return validate_id(value, kind)
50
+ except ValueError as exc:
51
+ raise click.BadParameter(str(exc)) from exc
52
+
53
+
54
+ def _chain(scope):
55
+ current = (scope or {}).get("entryBoxId")
56
+ following = {edge.get("from"): edge.get("to") for edge in (scope or {}).get("connections") or []}
57
+ ordered = []
58
+ while current and current not in ordered:
59
+ ordered.append(current)
60
+ current = following.get(current)
61
+ return ordered
62
+
63
+
64
+ def _box_map(scope, out):
65
+ if not isinstance(scope, dict):
66
+ return
67
+ for box in scope.get("boxes") or []:
68
+ if isinstance(box, dict) and box.get("id"):
69
+ out[box["id"]] = box
70
+ for key in ("whenTrue", "whenFalse", "body"):
71
+ _box_map(box.get(key), out)
72
+ for key in ("whenTrue", "whenFalse", "body", "teardown"):
73
+ _box_map(scope.get(key), out)
74
+
75
+
76
+ def _walk_ids(scope, seen):
77
+ ids = []
78
+ if not isinstance(scope, dict):
79
+ return ids
80
+ boxes = {}
81
+ _box_map(scope, boxes)
82
+ for step_id in _chain(scope):
83
+ if step_id in seen:
84
+ continue
85
+ seen.add(step_id)
86
+ ids.append(step_id)
87
+ box = boxes.get(step_id) or {}
88
+ for key in ("whenTrue", "whenFalse", "body"):
89
+ ids.extend(_walk_ids(box.get(key), seen))
90
+ ids.extend(_walk_ids(scope.get("teardown"), seen))
91
+ return ids
92
+
93
+
94
+ def _ordered_ids(graph):
95
+ return _chain((graph or {}).get("scope") or {})
96
+
97
+
98
+ def step_rows(payload):
99
+ """Steps in execution order as flat rows for table output, including nested If/loop/teardown scopes."""
100
+ by_id = {block.get("id"): block for block in payload.get("blocks") or []}
101
+ graph = payload.get("block_graph") or {}
102
+ seen = set()
103
+ ids = _walk_ids(graph.get("scope") or {}, seen)
104
+ ids.extend(_walk_ids(graph.get("teardown"), seen))
105
+ for block in payload.get("blocks") or []:
106
+ if block.get("id") and block["id"] not in seen:
107
+ ids.append(block["id"])
108
+ seen.add(block["id"])
109
+ rows = []
110
+ for position, step_id in enumerate(ids, start=1):
111
+ block = by_id.get(step_id)
112
+ if block is None:
113
+ continue
114
+ rows.append(
115
+ {
116
+ "position": position,
117
+ "id": step_id,
118
+ "label": block.get("label"),
119
+ "step_type": block.get("step_type") or "browser",
120
+ "verification": (block.get("implementation") or {}).get("verificationStatus") or "unverified",
121
+ "assert": bool((block.get("authoring") or {}).get("isAssert")),
122
+ "skipped": bool(block.get("skipped")),
123
+ }
124
+ )
125
+ return rows
126
+
127
+
128
+ def _failed_steps(payload, through=None):
129
+ rows = step_rows(payload)
130
+ if through:
131
+ ids = [row["id"] for row in rows]
132
+ if through in ids:
133
+ rows = rows[: ids.index(through) + 1]
134
+ return [row for row in rows if row["verification"] not in RUNNABLE_VERIFICATION and not row["skipped"]]
135
+
136
+
137
+ def _issue_text(issue):
138
+ title = str(issue.get("title") or "").strip()
139
+ why = str(issue.get("why") or "").strip()
140
+ next_step = str(issue.get("next") or "").strip()
141
+ message = str(issue.get("message") or "").strip()
142
+ parts = [part for part in (title, why, next_step) if part]
143
+ if parts:
144
+ return " ".join(parts)
145
+ return message or str(issue.get("code") or "This test isn't ready")
146
+
147
+
148
+ def _summary(payload):
149
+ validation = payload.get("validation") or {}
150
+ return {
151
+ "id": payload.get("id"),
152
+ "name": payload.get("name"),
153
+ "builder_status": payload.get("builder_status"),
154
+ "executor": payload.get("executor"),
155
+ "testing_type": payload.get("testing_type"),
156
+ "environment": payload.get("environment"),
157
+ "steps": len(step_rows(payload)),
158
+ "errors": [_issue_text(issue) for issue in validation.get("errors") or []],
159
+ }
160
+
161
+
162
+ def _print_test(ctx, payload):
163
+ if ctx.obj["FORMAT"] == "table":
164
+ format_output(_summary(payload), "table")
165
+ rows = step_rows(payload)
166
+ if rows:
167
+ format_output(rows, "table", columns=STEP_COLUMNS)
168
+ else:
169
+ format_output(payload, ctx.obj["FORMAT"])
170
+
171
+
172
+ def _read_source(source, source_file):
173
+ if source and source_file:
174
+ raise click.UsageError("Cannot use both --source and --source-file")
175
+ if source_file:
176
+ path = Path(source_file)
177
+ if not path.is_file():
178
+ raise click.BadParameter(f"Source file not found: {source_file}")
179
+ return path.read_text(encoding="utf-8")
180
+ return source
181
+
182
+
183
+ def _read_request(request, request_file):
184
+ if request and request_file:
185
+ raise click.UsageError("Cannot use both --request and --request-file")
186
+ raw = Path(request_file).read_text(encoding="utf-8") if request_file else request
187
+ if raw is None:
188
+ return None
189
+ try:
190
+ value = json.loads(raw)
191
+ except json.JSONDecodeError as exc:
192
+ raise click.BadParameter(f"Invalid JSON for --request: {exc}") from exc
193
+ if not isinstance(value, dict):
194
+ raise click.BadParameter("--request must be a JSON object")
195
+ return value
196
+
197
+
198
+ @test_blocks_group.command(name="create")
199
+ @click.option("--name", required=True, help="Test name")
200
+ @click.option("--testing-type", type=click.Choice(["web", "mobile"]), default="web", show_default=True)
201
+ @click.option("--environment", help="Environment ID")
202
+ @click.option("--data", multiple=True, help="Test data ID (repeatable)")
203
+ @click.option("--knowledge-base", multiple=True, help="Knowledge base ID (repeatable)")
204
+ @click.option("--idempotency-key", help="Retry-safe create key (same key returns the same test)")
205
+ @click.pass_context
206
+ def create(ctx, name, testing_type, environment, data, knowledge_base, idempotency_key):
207
+ """Create an empty Test Blocks test"""
208
+ payload = _run(
209
+ ctx,
210
+ lambda tb: tb.create(
211
+ name,
212
+ testing_type=testing_type,
213
+ environment=environment,
214
+ test_data=list(data) or None,
215
+ knowledge_base_id=list(knowledge_base) or None,
216
+ idempotency_key=idempotency_key,
217
+ ),
218
+ )
219
+ print_message(f"[green]Test Blocks test created with ID: {payload.get('id')}[/green]", ctx.obj["FORMAT"])
220
+ _print_test(ctx, payload)
221
+
222
+
223
+ @test_blocks_group.command(name="get")
224
+ @click.argument("test_id")
225
+ @click.pass_context
226
+ def get(ctx, test_id):
227
+ """Show a Test Blocks test with its steps in order"""
228
+ test_id = _id(test_id, "test")
229
+ _print_test(ctx, _run(ctx, lambda tb: tb.get(test_id)))
230
+
231
+
232
+ @test_blocks_group.command(name="steps")
233
+ @click.argument("test_id")
234
+ @click.pass_context
235
+ def steps(ctx, test_id):
236
+ """List steps in execution order (full step JSON with --format json)"""
237
+ test_id = _id(test_id, "test")
238
+ payload = _run(ctx, lambda tb: tb.get(test_id))
239
+ if ctx.obj["FORMAT"] == "table":
240
+ format_output(step_rows(payload), "table", columns=STEP_COLUMNS)
241
+ else:
242
+ by_id = {block.get("id"): block for block in payload.get("blocks") or []}
243
+ format_output([by_id[row["id"]] for row in step_rows(payload)], ctx.obj["FORMAT"])
244
+
245
+
246
+ def _step_options(func):
247
+ options = [
248
+ click.option("--instruction", help="Plain-language instruction for the step"),
249
+ click.option("--type", "step_type", type=click.Choice(STEP_TYPES), help="Step type (default: browser for web tests)"),
250
+ click.option("--source", help="Python step code (page/expect/tz for browser, tz for backend)"),
251
+ click.option("--source-file", type=click.Path(dir_okay=False), help="Read step code from a file"),
252
+ click.option("--request", help='Typed request JSON for soql/apex/http steps, e.g. {"query": "SELECT Id FROM Account", "outputName": "accounts"}'),
253
+ click.option("--request-file", type=click.Path(dir_okay=False), help="Read the typed request JSON from a file"),
254
+ click.option("--label", help="Step label (defaults to the instruction)"),
255
+ click.option("--target-org", help="Salesforce org key for soql/apex steps"),
256
+ ]
257
+ for option in reversed(options):
258
+ func = option(func)
259
+ return func
260
+
261
+
262
+ @test_blocks_group.command(name="add-step")
263
+ @click.argument("test_id")
264
+ @_step_options
265
+ @click.option("--assert", "is_assert", is_flag=True, help="Mark the step as an assertion")
266
+ @click.option("--after", "after_step_id", help="Insert after this step ID (default: append at the end)")
267
+ @click.option("--first", "prepend", is_flag=True, help="Insert as the first step")
268
+ @click.pass_context
269
+ def add_step(ctx, test_id, instruction, step_type, source, source_file, request, request_file, label, target_org, is_assert, after_step_id, prepend):
270
+ """Add a step. Without --source, code is generated from --instruction when the test is verified."""
271
+ test_id = _id(test_id, "test")
272
+ if after_step_id and prepend:
273
+ raise click.UsageError("Cannot use both --after and --first")
274
+ code = _read_source(source, source_file)
275
+ typed_request = _read_request(request, request_file)
276
+ if not instruction and not code and typed_request is None:
277
+ raise click.UsageError("Provide --instruction, --source/--source-file, or --request")
278
+ payload = _run(
279
+ ctx,
280
+ lambda tb: tb.add_step(
281
+ test_id,
282
+ instruction=instruction or "",
283
+ step_type=step_type,
284
+ source=code,
285
+ label=label,
286
+ after_step_id=_id(after_step_id, "step") if after_step_id else None,
287
+ request=typed_request,
288
+ is_assert=is_assert,
289
+ target_org=target_org,
290
+ prepend=prepend,
291
+ ),
292
+ )
293
+ print_message("[green]Step added[/green]", ctx.obj["FORMAT"])
294
+ _print_test(ctx, payload)
295
+
296
+
297
+ @test_blocks_group.command(name="update-step")
298
+ @click.argument("test_id")
299
+ @click.argument("step_id")
300
+ @_step_options
301
+ @click.option("--assert/--no-assert", "is_assert", default=None, help="Mark or unmark the step as an assertion")
302
+ @click.pass_context
303
+ def update_step(ctx, test_id, step_id, instruction, step_type, source, source_file, request, request_file, label, target_org, is_assert):
304
+ """Edit a step. Changing code marks it unverified; verify again before saving."""
305
+ test_id = _id(test_id, "test")
306
+ step_id = _id(step_id, "step")
307
+ code = _read_source(source, source_file)
308
+ typed_request = _read_request(request, request_file)
309
+ if all(value is None for value in (instruction, step_type, code, typed_request, label, target_org, is_assert)):
310
+ raise click.UsageError("Nothing to update")
311
+ payload = _run(
312
+ ctx,
313
+ lambda tb: tb.update_step(
314
+ test_id,
315
+ step_id,
316
+ instruction=instruction,
317
+ source=code,
318
+ label=label,
319
+ step_type=step_type,
320
+ request=typed_request,
321
+ is_assert=is_assert,
322
+ target_org=target_org,
323
+ ),
324
+ )
325
+ print_message("[green]Step updated[/green]", ctx.obj["FORMAT"])
326
+ _print_test(ctx, payload)
327
+
328
+
329
+ @test_blocks_group.command(name="delete-steps")
330
+ @click.argument("test_id")
331
+ @click.argument("step_ids", nargs=-1, required=True)
332
+ @click.confirmation_option(prompt="Delete these steps?")
333
+ @click.pass_context
334
+ def delete_steps(ctx, test_id, step_ids):
335
+ """Delete steps; the remaining steps are reconnected in order"""
336
+ test_id = _id(test_id, "test")
337
+ ids = [_id(step_id, "step") for step_id in step_ids]
338
+ payload = _run(ctx, lambda tb: tb.delete_steps(test_id, ids))
339
+ print_message(f"[green]Deleted {len(ids)} step(s)[/green]", ctx.obj["FORMAT"])
340
+ _print_test(ctx, payload)
341
+
342
+
343
+ @test_blocks_group.command(name="config")
344
+ @click.argument("test_id")
345
+ @click.option("--environment", help="Environment ID")
346
+ @click.option("--environment-url-key", help="Environment key holding the landing URL")
347
+ @click.option("--data", multiple=True, help="Test data ID (repeatable; replaces the current list)")
348
+ @click.option("--knowledge-base", multiple=True, help="Knowledge base ID (repeatable; replaces the current list)")
349
+ @click.option("--step-retry-count", type=click.IntRange(0, 5), help="Repair attempts per step during runs")
350
+ @click.option("--clear-data", is_flag=True, help="Detach all test data")
351
+ @click.option("--clear-knowledge-base", is_flag=True, help="Detach all knowledge bases")
352
+ @click.pass_context
353
+ def config(ctx, test_id, environment, environment_url_key, data, knowledge_base, step_retry_count, clear_data, clear_knowledge_base):
354
+ """Change a Test Blocks test's environment, test data, or knowledge bases"""
355
+ test_id = _id(test_id, "test")
356
+ if data and clear_data:
357
+ raise click.UsageError("Cannot use both --data and --clear-data")
358
+ if knowledge_base and clear_knowledge_base:
359
+ raise click.UsageError("Cannot use both --knowledge-base and --clear-knowledge-base")
360
+ if not any([environment, environment_url_key, data, knowledge_base, step_retry_count is not None, clear_data, clear_knowledge_base]):
361
+ raise click.UsageError("Nothing to update")
362
+ payload = _run(
363
+ ctx,
364
+ lambda tb: tb.update_config(
365
+ test_id,
366
+ environment=environment,
367
+ environment_url_key=environment_url_key,
368
+ test_data=[] if clear_data else (list(data) or None),
369
+ knowledge_base_id=[] if clear_knowledge_base else (list(knowledge_base) or None),
370
+ step_retry_count=step_retry_count,
371
+ ),
372
+ )
373
+ _print_test(ctx, payload)
374
+
375
+
376
+ @test_blocks_group.command(name="verify")
377
+ @click.argument("test_id")
378
+ @click.option("--through", "through_step_id", help="Run up to and including this step (default: all steps)")
379
+ @click.option("--wait/--no-wait", default=True, show_default=True, help="Wait for the run to finish")
380
+ @click.option("--timeout", default=900, type=int, show_default=True, help="Seconds to wait")
381
+ @click.pass_context
382
+ def verify(ctx, test_id, through_step_id, wait, timeout):
383
+ """Run steps in order so they are verified (a browser is leased when needed)"""
384
+ test_id = _id(test_id, "test")
385
+ through = _id(through_step_id, "step") if through_step_id else None
386
+
387
+ async def operation(tb):
388
+ started = await tb.verify(test_id, through_step_id=through)
389
+ if not wait or started.get("status") == "already_current":
390
+ return started
391
+ await tb.wait_for_verify(test_id, timeout=timeout)
392
+ return await tb.get(test_id)
393
+
394
+ result = _run(ctx, operation)
395
+ if "blocks" not in result:
396
+ format_output(result, ctx.obj["FORMAT"])
397
+ return
398
+ failed = _failed_steps(result, through)
399
+ _print_test(ctx, result)
400
+ if failed:
401
+ progress = result.get("authoringProgress") or {}
402
+ reason = progress.get("errorReason") or "see step authoring_progress for the failure"
403
+ raise click.ClickException(f"{len(failed)} step(s) not verified ({reason})")
404
+ print_message("[green]All steps verified. Run 'testzeus test-blocks save' next.[/green]", ctx.obj["FORMAT"])
405
+
406
+
407
+ @test_blocks_group.command(name="save")
408
+ @click.argument("test_id")
409
+ @click.pass_context
410
+ def save(ctx, test_id):
411
+ """Save the test; it becomes runnable (ready) only when every step is verified"""
412
+ test_id = _id(test_id, "test")
413
+ payload = _run(ctx, lambda tb: tb.save(test_id))
414
+ _print_test(ctx, payload)
415
+ if payload.get("builder_status") != "ready":
416
+ raise click.ClickException("Saved, but the test is not ready to run; fix the errors above and verify again")
417
+ print_message("[green]Saved and ready to run[/green]", ctx.obj["FORMAT"])
418
+
419
+
420
+ @test_blocks_group.command(name="run")
421
+ @click.argument("test_id")
422
+ @click.option("--key", help="Retry-safe live-run key (same key does not start a second run)")
423
+ @click.option("--wait/--no-wait", default=False, show_default=True, help="Wait for the run to finish")
424
+ @click.option("--timeout", default=900, type=int, show_default=True, help="Seconds to wait when --wait is set")
425
+ @click.pass_context
426
+ def live_run(ctx, test_id, key, wait, timeout):
427
+ """Start an official run of a saved, ready test"""
428
+ test_id = _id(test_id, "test")
429
+
430
+ async def operation(tb):
431
+ result = await tb.live_run(test_id, key=key)
432
+ run_id = result.get("test_run_id")
433
+ if not wait or not run_id:
434
+ return result
435
+ deadline = time.monotonic() + timeout
436
+ while True:
437
+ status = await tb.get_run_status(run_id)
438
+ state = str(status.get("status") or status.get("test_status") or "").lower()
439
+ if state in {"completed", "passed", "failed", "error", "cancelled", "canceled"}:
440
+ return status
441
+ if time.monotonic() >= deadline:
442
+ raise click.ClickException(f"Run {run_id} still {state or 'running'} after {timeout}s")
443
+ await asyncio.sleep(3)
444
+
445
+ result = _run(ctx, operation)
446
+ run_id = result.get("test_run_id") or result.get("id")
447
+ print_message(f"[green]Run queued: test run {run_id}[/green]", ctx.obj["FORMAT"])
448
+ format_output(result, ctx.obj["FORMAT"])
449
+ state = str(result.get("status") or result.get("test_status") or "").lower()
450
+ if wait and state in {"failed", "error"}:
451
+ raise click.ClickException(f"Run {run_id} {state}")
452
+
453
+
454
+ @test_blocks_group.command(name="run-status")
455
+ @click.argument("test_run_id")
456
+ @click.pass_context
457
+ def run_status(ctx, test_run_id):
458
+ """Show a test run's status, steps, and attachments"""
459
+ test_run_id = _id(test_run_id, "test run")
460
+ result = _run(ctx, lambda tb: tb.get_run_status(test_run_id))
461
+ format_output(result, ctx.obj["FORMAT"])
462
+ state = str(result.get("status") or result.get("test_status") or "").lower()
463
+ if state in {"failed", "error"}:
464
+ raise SystemExit(1)
@@ -4,17 +4,20 @@ Commands for managing tests in TestZeus CLI.
4
4
 
5
5
  import asyncio
6
6
  import json
7
- import click
8
7
  from pathlib import Path
9
- from rich.console import Console
10
8
 
9
+ import click
10
+ from rich.console import Console
11
11
  from testzeus_sdk import TestZeusClient
12
+
12
13
  from testzeus_cli.config import get_client_config
13
- from testzeus_cli.utils.formatters import format_output, print_message
14
- from testzeus_cli.utils.validators import validate_id, validate_tenant_ownership, parse_key_value_pairs
15
- from testzeus_cli.utils.client import run_client_operation
16
14
  from testzeus_cli.utils.auth import initialize_client_with_token
15
+ from testzeus_cli.utils.client import run_client_operation
16
+ from testzeus_cli.utils.formatters import format_output, print_message
17
+ from testzeus_cli.record_contract import TEST_BLOCKS_BUILDER_FIELDS, is_test_blocks_record
17
18
  from testzeus_cli.utils.links import print_platform_link
19
+ from testzeus_cli.utils.validators import (parse_key_value_pairs, validate_id,
20
+ validate_tenant_ownership)
18
21
 
19
22
  console = Console()
20
23
 
@@ -26,9 +29,7 @@ def tests_group():
26
29
 
27
30
 
28
31
  @tests_group.command(name="list")
29
- @click.option(
30
- "--filters", "-f", multiple=True, help="Filter results (format: key=value)"
31
- )
32
+ @click.option("--filters", "-f", multiple=True, help="Filter results (format: key=value)")
32
33
  @click.option("--sort", default="-updated", show_default=True, help="Sort by field")
33
34
  @click.option("--expand", help="Expand related entities")
34
35
  @click.option("--page", default=1, type=int, show_default=True, help="Page number")
@@ -40,16 +41,14 @@ def list_tests(ctx, filters, sort, expand, page, per_page):
40
41
  filter_dict = parse_key_value_pairs(filters) if filters else {}
41
42
 
42
43
  async def _list_tests(client: TestZeusClient):
43
- return await client.tests.get_list(
44
- expand=expand, sort=sort, filters=filter_dict, page=page, per_page=per_page
45
- )
44
+ return await client.tests.get_list(expand=expand, sort=sort, filters=filter_dict, page=page, per_page=per_page)
46
45
 
47
46
  result = run_client_operation(ctx, _list_tests)
48
47
  print_platform_link(ctx, "tests")
49
48
  format_output(
50
49
  result,
51
50
  ctx.obj["FORMAT"],
52
- columns=["id", "name", "created", "updated", "modified_by", "environment", "test_data"],
51
+ columns=["id", "name", "executor", "created", "updated", "modified_by", "environment", "test_data"],
53
52
  )
54
53
 
55
54
 
@@ -61,9 +60,7 @@ def get_test(ctx, test_id, expand):
61
60
  """Get a single test by ID"""
62
61
 
63
62
  async def _run():
64
- config, token, _, _ = get_client_config(
65
- ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
66
- )
63
+ config, token, _, _ = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
67
64
  client = TestZeusClient(**config)
68
65
 
69
66
  test_id_validated = validate_id(test_id, "test")
@@ -167,9 +164,7 @@ def _resolve_json_input(
167
164
  @click.option("--tags", multiple=True, help="Tag IDs")
168
165
  @click.option("--environment", help="Environment ID (required for mobile tests)")
169
166
  @click.option("--hypermind-code-blocks", help="Comma-separated list of Hypermind code block IDs")
170
- @click.option(
171
- "--execution-mode", default="lenient", help="Execution mode (lenient, strict)"
172
- )
167
+ @click.option("--execution-mode", default="lenient", help="Execution mode (lenient, strict)")
173
168
  @click.option(
174
169
  "--testing-type",
175
170
  type=click.Choice(["web", "mobile"]),
@@ -196,15 +191,13 @@ def create_test(
196
191
  """Create a new test with feature content from text or file"""
197
192
 
198
193
  if not feature and not feature_file:
199
- raise click.UsageError("Either --feature or --feature-file is required")
194
+ raise click.UsageError("Either --feature or --feature-file is required. For step-based Test Blocks tests, use 'testzeus test-blocks create'")
200
195
 
201
196
  if feature and feature_file:
202
197
  raise click.UsageError("Cannot use both --feature and --feature-file")
203
198
 
204
199
  if testing_type == "mobile" and not environment:
205
- raise click.UsageError(
206
- "--environment is required when --testing-type is 'mobile'"
207
- )
200
+ raise click.UsageError("--environment is required when --testing-type is 'mobile'")
208
201
 
209
202
  # Process the feature content (from file or directly)
210
203
  feature_content = _read_feature_file(feature_file) if feature_file else feature
@@ -222,9 +215,7 @@ def create_test(
222
215
  )
223
216
 
224
217
  async def _run():
225
- config, token, stored_tenant_id, stored_user_id = get_client_config(
226
- ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
227
- )
218
+ config, token, stored_tenant_id, stored_user_id = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
228
219
  client = TestZeusClient(**config)
229
220
 
230
221
  # Prepare parameters
@@ -263,9 +254,7 @@ def create_test(
263
254
  else:
264
255
  await client.ensure_authenticated()
265
256
  if ctx.obj.get("VERBOSE"):
266
- console.print(
267
- f"[blue]Creating test with parameters: {test_data}[/blue]"
268
- )
257
+ console.print(f"[blue]Creating test with parameters: {test_data}[/blue]")
269
258
 
270
259
  new_test = await client.tests.create(test_data)
271
260
  return new_test.data
@@ -279,9 +268,7 @@ def create_test(
279
268
  @click.argument("test_id")
280
269
  @click.option("--name", help="New test name")
281
270
  @click.option("--feature", help="New test feature content as text")
282
- @click.option(
283
- "--feature-file", help="Path to file containing new feature content (text)"
284
- )
271
+ @click.option("--feature-file", help="Path to file containing new feature content (text)")
285
272
  @click.option("--test-params", help="Default test params as inline JSON")
286
273
  @click.option("--test-params-file", help="Path to JSON file containing default test params")
287
274
  @click.option("--output-schema", help="Output schema as inline JSON")
@@ -337,9 +324,7 @@ def update_test(
337
324
  )
338
325
 
339
326
  async def _run():
340
- config, token, stored_tenant_id, stored_user_id = get_client_config(
341
- ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
342
- )
327
+ config, token, stored_tenant_id, stored_user_id = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
343
328
  client = TestZeusClient(**config)
344
329
 
345
330
  test_id_validated = validate_id(test_id, "test")
@@ -392,15 +377,8 @@ def update_test(
392
377
 
393
378
  if testing_type:
394
379
  update_data["testing_type"] = testing_type
395
- if (
396
- testing_type == "mobile"
397
- and not environment
398
- and not test.data.get("environment")
399
- ):
400
- raise click.UsageError(
401
- "--environment is required when --testing-type is 'mobile' "
402
- "and the test has no environment assigned"
403
- )
380
+ if testing_type == "mobile" and not environment and not test.data.get("environment"):
381
+ raise click.UsageError("--environment is required when --testing-type is 'mobile' " "and the test has no environment assigned")
404
382
  has_updates = True
405
383
 
406
384
  if test_params_value is not None:
@@ -415,6 +393,13 @@ def update_test(
415
393
  print_message("[yellow]No updates provided[/yellow]", ctx.obj["FORMAT"])
416
394
  return None
417
395
 
396
+ blocked = set(update_data) & TEST_BLOCKS_BUILDER_FIELDS
397
+ if is_test_blocks_record(test.data) and blocked:
398
+ raise click.UsageError(
399
+ "Test Blocks tests change these fields through 'testzeus test-blocks config' "
400
+ "(steps through add-step/update-step): " + ", ".join(sorted(blocked))
401
+ )
402
+
418
403
  if ctx.obj.get("VERBOSE"):
419
404
  console.print(f"[blue]Updating test with: {update_data}[/blue]")
420
405
 
@@ -444,9 +429,7 @@ def get_test_input_params(ctx, test_id):
444
429
  """Get merged input params and defaults for a test."""
445
430
 
446
431
  async def _run():
447
- config, token, _, _ = get_client_config(
448
- ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
449
- )
432
+ config, token, _, _ = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
450
433
  client = TestZeusClient(**config)
451
434
 
452
435
  test_id_validated = validate_id(test_id, "test")
@@ -470,9 +453,7 @@ def get_dependent_suites(ctx, test_id):
470
453
  """Get test suites that depend on a test."""
471
454
 
472
455
  async def _run():
473
- config, token, _, _ = get_client_config(
474
- ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL")
475
- )
456
+ config, token, _, _ = get_client_config(ctx.obj["PROFILE"], api_url=ctx.obj.get("API_URL"))
476
457
  client = TestZeusClient(**config)
477
458
 
478
459
  test_id_validated = validate_id(test_id, "test")
@@ -17,7 +17,10 @@
17
17
  "testing_type": "string",
18
18
  "hypermind_code_blocks": "array",
19
19
  "knowledge_base_id": "array",
20
- "execution_mode": "string"
20
+ "execution_mode": "string",
21
+ "executor": "string",
22
+ "origin": "string",
23
+ "builder_status": "string"
21
24
  },
22
25
  "copyFields": [
23
26
  "description",
@@ -26,6 +26,9 @@ RESOURCES = {
26
26
  "hypermind_code_blocks": "array",
27
27
  "knowledge_base_id": "array",
28
28
  "execution_mode": "string",
29
+ "executor": "string",
30
+ "origin": "string",
31
+ "builder_status": "string",
29
32
  },
30
33
  "tests",
31
34
  ("description", "test_feature", "environment", "test_data", "tags", "testing_type", "hypermind_code_blocks", "knowledge_base_id", "execution_mode"),
@@ -79,6 +82,14 @@ PATCH_FIELDS = {
79
82
 
80
83
  OPERATORS = ("eq", "ne", "gt", "gte", "lt", "lte", "contains", "in", "is_null")
81
84
 
85
+ # A Test Blocks test has no test_feature, and its configuration is changed through the builder so dependent steps are re-checked.
86
+ TEST_BLOCKS_BUILDER_FIELDS = {"test_feature", "testing_type", "environment", "test_data", "knowledge_base_id", "hypermind_code_blocks"}
87
+
88
+
89
+ def is_test_blocks_record(record):
90
+ executor = str(record.get("executor") or "").strip().lower()
91
+ return executor in ("test_blocks", "test_builder") or str(record.get("authoring_mode") or "").strip().lower() == "box_graph"
92
+
82
93
 
83
94
  def describe_resources():
84
95
  return {
@@ -35,7 +35,7 @@ async def with_authenticated_client(
35
35
  Returns:
36
36
  The result of the operation
37
37
  """
38
- config, token, profile_tenant_id, _ = get_client_config(profile, api_url)
38
+ config, token, profile_tenant_id, profile_user_id = get_client_config(profile, api_url)
39
39
  if _auth_debug_enabled():
40
40
  logger.warning(
41
41
  "[AUTH_DEBUG] with_authenticated_client profile=%s base_url=%s token=%s api_url_override=%s",
@@ -49,7 +49,7 @@ async def with_authenticated_client(
49
49
  async with client:
50
50
  # Apply token from config if available
51
51
  if token:
52
- initialize_client_with_token(client, token, profile_tenant_id)
52
+ initialize_client_with_token(client, token, profile_tenant_id, profile_user_id)
53
53
  else:
54
54
  await client.ensure_authenticated()
55
55
 
File without changes
File without changes