Buckets:
| import hashlib | |
| import json | |
| import os | |
| from pathlib import Path | |
| import pytest | |
| from output_layout_migration import identity, plan, run_roots | |
| from output_relocation import apply, inside, relocate_path | |
| from rewrite_output_references import prefix_mapping, rewrite | |
| def test_backend_model_namespaces_are_discovered(tmp_path): | |
| root = tmp_path / 'output' | |
| run = root / 'bagel/thinkmorph-7b/thinkmorph/v1/runs/opd/20260101-000000_test' | |
| run.mkdir(parents=True) | |
| assert list(run_roots(root)) == [run] | |
| assert plan(root)['records'][0]['destination'] == 'thinkmorph-7b/thinkmorph/v1/runs/opd/20260101-000000_test' | |
| def test_native_thinkmorph_and_uniar_on_thinkmorph_are_distinct(tmp_path): | |
| root = tmp_path / 'output' | |
| for model, expected in [('UniAR-SFT', 'uniar-sft'), ('ThinkMorph-7B', 'thinkmorph-7b')]: | |
| run = root / 'thinkmorph/runs/eval' / f'20260101-000000_{model}' | |
| run.mkdir(parents=True) | |
| (run / 'arguments.json').write_text(json.dumps({'model_path': 'models/' + model})) | |
| assert identity(run, root)[0] == expected | |
| def test_mixed_model_bundle_stays_intact(tmp_path): | |
| run = tmp_path / 'cv_bench/20260101-000000_compare' | |
| (run / 'bagel').mkdir(parents=True) | |
| (run / 'anole').mkdir() | |
| assert identity(run, tmp_path)[0] == 'shared' | |
| def test_plan_does_not_guess_model_of_empty_run(tmp_path): | |
| (tmp_path / 'thinkmorph/runs/sft/20260101-000000_unknown').mkdir(parents=True) | |
| assert plan(tmp_path)['records'][0]['owner'] is None | |
| def test_relocation_preserves_payload_and_repairs_relative_links(tmp_path): | |
| root = tmp_path / 'experiments/output' | |
| source = root / 'dataset/runs/sft/20260101-000000_test' | |
| source.mkdir(parents=True) | |
| (source / 'weights.bin').write_bytes(b'checkpoint') | |
| snapshot = source / '_submission/source' | |
| snapshot.mkdir(parents=True) | |
| (snapshot / 'frozen.py').write_text('old_path = "unchanged"\n') | |
| external = tmp_path / 'base.bin' | |
| external.write_bytes(b'base') | |
| (source / 'base-link').symlink_to(os.path.relpath(external, source)) | |
| dest = 'uniar-sft/dataset/unversioned/runs/sft/20260101-000000_test' | |
| payload = {'output_root': str(root), 'records': [dict(source=str(source.relative_to(root)), destination=dest, owner='uniar-sft')]} | |
| audit = tmp_path / 'audit' | |
| audit.mkdir() | |
| p = audit / 'plan.json' | |
| p.write_text(json.dumps(payload)) | |
| inode = (source / 'weights.bin').stat().st_ino | |
| result = apply(p, hashlib.sha256(p.read_bytes()).hexdigest()) | |
| assert not source.exists() | |
| assert (root / dest / 'weights.bin').stat().st_ino == inode | |
| assert (root / dest / 'base-link').read_bytes() == b'base' | |
| assert (root / dest / '_submission/source/frozen.py').read_text() == 'old_path = "unchanged"\n' | |
| assert result['runs'] == 1 | |
| assert result['symlinks_repaired'] == 1 | |
| def test_relocation_path_matches_directory_boundaries(tmp_path): | |
| rows = [dict(source='old/run', destination='new/run')] | |
| assert relocate_path(tmp_path / 'old/run/file', tmp_path, rows) == tmp_path / 'new/run/file' | |
| assert relocate_path(tmp_path / 'old/runner/file', tmp_path, rows) == tmp_path / 'old/runner/file' | |
| with pytest.raises(ValueError): | |
| inside(tmp_path, '../outside') | |
| def test_live_reference_rewrite_handles_concatenated_python_literals(): | |
| mapping = {'experiments/output/thinkmorph/v1': 'experiments/output/uniar-sft/thinkmorph/v1'} | |
| text = 'value = ("experiments/output/thinkmorph/"\n "v1/runs/sft/example")\n' | |
| updated = rewrite(text, mapping, python=True) | |
| namespace = {} | |
| exec(updated, namespace) | |
| assert namespace['value'] == 'experiments/output/uniar-sft/thinkmorph/v1/runs/sft/example' | |
| assert rewrite(updated, mapping, python=True) == updated | |
| def test_live_reference_rewrite_does_not_guess_ambiguous_prefix(): | |
| mapping = prefix_mapping([ | |
| dict(source='thinkmorph/v1/runs/sft/run1', destination='uniar-sft/thinkmorph/v1/runs/sft/run1'), | |
| dict(source='thinkmorph/v1/runs/eval/run2', destination='thinkmorph-7b/thinkmorph/v1/runs/eval/run2'), | |
| ]) | |
| assert 'experiments/output/thinkmorph/v1' not in mapping | |
| assert 'experiments/output/thinkmorph/v1/runs/sft' in mapping | |
| assert rewrite('experiments/output/thinkmorph/v1/runs/sft_extra', mapping) == 'experiments/output/thinkmorph/v1/runs/sft_extra' | |
Xet Storage Details
- Size:
- 4.33 kB
- Xet hash:
- 3ab38f972a0f97fa9c07267cf0da0606868df4506acc832a15bf0399bd348f6f
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.