jrrribeiro commited on
Commit
b0f5b8d
·
1 Parent(s): 178fe29

feat(cli): add verify-project dry-run diagnostics

Browse files
README.md CHANGED
@@ -127,6 +127,7 @@ Available commands:
127
  - `init-dataset`: creates the initial local dataset folder structure.
128
  - `build-index`: builds a confidence-sorted index from `detections.jsonl`.
129
  - `verify-project`: verifies project config and required local scaffold files.
 
130
 
131
  Example flow:
132
 
@@ -153,6 +154,12 @@ python -m src.cli.project_cli verify-project \
153
  --projects-file docs/spaces/projects.sample.json \
154
  --dataset-root data/projects \
155
  --slug amazonia-2026
 
 
 
 
 
 
156
  ```
157
 
158
  ## Repository Structure
 
127
  - `init-dataset`: creates the initial local dataset folder structure.
128
  - `build-index`: builds a confidence-sorted index from `detections.jsonl`.
129
  - `verify-project`: verifies project config and required local scaffold files.
130
+ - Use `--dry-run` to print findings without failing the command exit code.
131
 
132
  Example flow:
133
 
 
154
  --projects-file docs/spaces/projects.sample.json \
155
  --dataset-root data/projects \
156
  --slug amazonia-2026
157
+
158
+ python -m src.cli.project_cli verify-project \
159
+ --projects-file docs/spaces/projects.sample.json \
160
+ --dataset-root data/projects \
161
+ --slug amazonia-2026 \
162
+ --dry-run
163
  ```
164
 
165
  ## Repository Structure
src/cli/project_cli.py CHANGED
@@ -242,17 +242,16 @@ def cmd_verify_project(args: argparse.Namespace) -> int:
242
  projects_file = Path(args.projects_file)
243
  projects = _as_project_list(_load_json(projects_file, []), projects_file)
244
 
 
 
245
  if not _project_exists(projects, args.slug):
246
- print(f"ERROR: project '{args.slug}' not found in {projects_file}")
247
- return EXIT_VALIDATION_ERROR
248
 
249
  project_root = Path(args.dataset_root) / args.slug
250
- missing: list[str] = []
251
-
252
  for dirname in DEFAULT_DATASET_DIRS:
253
  expected = project_root / dirname
254
  if not expected.exists():
255
- missing.append(str(expected))
256
 
257
  required_files = [
258
  project_root / "detections" / "detections.jsonl",
@@ -261,12 +260,18 @@ def cmd_verify_project(args: argparse.Namespace) -> int:
261
  ]
262
  for required in required_files:
263
  if not required.exists():
264
- missing.append(str(required))
265
-
266
- if missing:
267
- print("ERROR: project verification failed; missing paths:")
268
- for item in missing:
 
 
 
269
  print(f" - {item}")
 
 
 
270
  return EXIT_VALIDATION_ERROR
271
 
272
  print(f"OK: project '{args.slug}' verified")
@@ -305,6 +310,11 @@ def build_parser() -> argparse.ArgumentParser:
305
  verify_project.add_argument("--projects-file", required=True)
306
  verify_project.add_argument("--dataset-root", required=True)
307
  verify_project.add_argument("--slug", required=True)
 
 
 
 
 
308
  verify_project.set_defaults(func=cmd_verify_project)
309
 
310
  return parser
 
242
  projects_file = Path(args.projects_file)
243
  projects = _as_project_list(_load_json(projects_file, []), projects_file)
244
 
245
+ findings: list[str] = []
246
+
247
  if not _project_exists(projects, args.slug):
248
+ findings.append(f"project '{args.slug}' not found in {projects_file}")
 
249
 
250
  project_root = Path(args.dataset_root) / args.slug
 
 
251
  for dirname in DEFAULT_DATASET_DIRS:
252
  expected = project_root / dirname
253
  if not expected.exists():
254
+ findings.append(f"missing path: {expected}")
255
 
256
  required_files = [
257
  project_root / "detections" / "detections.jsonl",
 
260
  ]
261
  for required in required_files:
262
  if not required.exists():
263
+ findings.append(f"missing path: {required}")
264
+
265
+ if findings:
266
+ if args.dry_run:
267
+ print("DRY-RUN: project verification found issues:")
268
+ else:
269
+ print("ERROR: project verification failed:")
270
+ for item in findings:
271
  print(f" - {item}")
272
+ if args.dry_run:
273
+ print("DRY-RUN: completed without failing exit code")
274
+ return EXIT_OK
275
  return EXIT_VALIDATION_ERROR
276
 
277
  print(f"OK: project '{args.slug}' verified")
 
310
  verify_project.add_argument("--projects-file", required=True)
311
  verify_project.add_argument("--dataset-root", required=True)
312
  verify_project.add_argument("--slug", required=True)
313
+ verify_project.add_argument(
314
+ "--dry-run",
315
+ action="store_true",
316
+ help="Print verification findings without returning a failure exit code",
317
+ )
318
  verify_project.set_defaults(func=cmd_verify_project)
319
 
320
  return parser
tests/unit/test_project_cli.py CHANGED
@@ -285,3 +285,64 @@ def test_verify_project_rejects_invalid_projects_schema(tmp_path: Path, capsys:
285
  captured = capsys.readouterr()
286
  assert exit_code == 1
287
  assert "Expected list" in captured.out
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
  captured = capsys.readouterr()
286
  assert exit_code == 1
287
  assert "Expected list" in captured.out
288
+
289
+
290
+ def test_verify_project_dry_run_returns_ok_with_findings(
291
+ tmp_path: Path, capsys: pytest.CaptureFixture[str]
292
+ ) -> None:
293
+ projects_file = tmp_path / "projects.json"
294
+ projects_file.write_text(
295
+ json.dumps(
296
+ [
297
+ {
298
+ "project_slug": "p6",
299
+ "name": "Project 6",
300
+ "dataset_repo_id": "org/p6",
301
+ "active": True,
302
+ }
303
+ ]
304
+ ),
305
+ encoding="utf-8",
306
+ )
307
+
308
+ exit_code = main(
309
+ [
310
+ "verify-project",
311
+ "--projects-file",
312
+ str(projects_file),
313
+ "--dataset-root",
314
+ str(tmp_path / "datasets"),
315
+ "--slug",
316
+ "p6",
317
+ "--dry-run",
318
+ ]
319
+ )
320
+
321
+ captured = capsys.readouterr()
322
+ assert exit_code == 0
323
+ assert "DRY-RUN" in captured.out
324
+ assert "missing path" in captured.out
325
+
326
+
327
+ def test_verify_project_dry_run_still_validates_schema(
328
+ tmp_path: Path, capsys: pytest.CaptureFixture[str]
329
+ ) -> None:
330
+ projects_file = tmp_path / "projects.json"
331
+ projects_file.write_text("{bad-json", encoding="utf-8")
332
+
333
+ exit_code = main(
334
+ [
335
+ "verify-project",
336
+ "--projects-file",
337
+ str(projects_file),
338
+ "--dataset-root",
339
+ str(tmp_path / "datasets"),
340
+ "--slug",
341
+ "p6",
342
+ "--dry-run",
343
+ ]
344
+ )
345
+
346
+ captured = capsys.readouterr()
347
+ assert exit_code == 1
348
+ assert "Invalid JSON" in captured.out