Spaces:
Runtime error
Runtime error
| from __future__ import annotations | |
| import importlib.util | |
| import json | |
| import sys | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| for candidate in (ROOT / 'src', ROOT): | |
| if str(candidate) not in sys.path: | |
| sys.path.insert(0, str(candidate)) | |
| from app_kit.tracing import write_trace_artifact | |
| def _load_share_module(): | |
| script_path = ROOT / 'scripts' / 'share_traces_to_hf_dataset.py' | |
| spec = importlib.util.spec_from_file_location('share_traces_to_hf_dataset', script_path) | |
| if spec is None or spec.loader is None: | |
| raise RuntimeError(f'Cannot import {script_path}') | |
| module = importlib.util.module_from_spec(spec) | |
| spec.loader.exec_module(module) | |
| return module | |
| def test_share_traces_materializes_schema_and_local_artifacts(tmp_path): | |
| repo_root = tmp_path / 'repo' | |
| artifact_dir = repo_root / 'artifacts' | |
| trace_path = write_trace_artifact( | |
| artifact_dir, | |
| { | |
| 'kind': 'eval', | |
| 'project': 'p1', | |
| 'pack_id': 'sample-pack', | |
| 'pack_path': 'data/demo_packs/sample-pack', | |
| 'result': {'parsed': 'output'}, | |
| 'model_name': 'test-model', | |
| }, | |
| ) | |
| assert trace_path.exists() | |
| module = _load_share_module() | |
| output_dir = module.default_output_dir( | |
| repo_root=repo_root, | |
| repo_name=ROOT.name, | |
| today='2026-06-10', | |
| ) | |
| materialized = module.materialize_dataset( | |
| traces_dir=artifact_dir / 'traces', | |
| output_dir=output_dir, | |
| repo_root=repo_root, | |
| repo_name=ROOT.name, | |
| today='2026-06-10', | |
| ) | |
| assert materialized['records_written'] == 1 | |
| assert materialized['output_dir'] == output_dir | |
| assert materialized['dataset_jsonl'].exists() | |
| assert materialized['metadata_json'].exists() | |
| row = json.loads(materialized['dataset_jsonl'].read_text(encoding='utf-8').strip()) | |
| assert {'timestamp', 'inputs', 'parsed_outputs', 'model_name'}.issubset(row) | |
| assert row['model_name'] == 'test-model' | |
| assert row['parsed_outputs'] == {'parsed': 'output'} | |
| metadata = json.loads(materialized['metadata_json'].read_text(encoding='utf-8')) | |
| assert metadata['repo_name'] == ROOT.name | |
| assert metadata['schema_fields'] == ['timestamp', 'inputs', 'parsed_outputs', 'model_name'] | |
| assert metadata['source_trace_count'] == 1 | |
| assert str(materialized['output_dir']).endswith(f"artifacts/verification/2026-06-10/sharing_is_caring/{ROOT.name}") | |