Add project registration proposal preview
This commit is contained in:
@@ -4,6 +4,7 @@ import json
|
||||
|
||||
import atocore.config as config
|
||||
from atocore.projects.registry import (
|
||||
build_project_registration_proposal,
|
||||
get_registered_project,
|
||||
get_project_registry_template,
|
||||
list_registered_projects,
|
||||
@@ -208,3 +209,87 @@ def test_project_registry_rejects_alias_collision(tmp_path, monkeypatch):
|
||||
raise AssertionError("Expected project registry collision to raise")
|
||||
finally:
|
||||
config.settings = original_settings
|
||||
|
||||
|
||||
def test_project_registration_proposal_normalizes_and_resolves_paths(tmp_path, monkeypatch):
|
||||
vault_dir = tmp_path / "vault"
|
||||
drive_dir = tmp_path / "drive"
|
||||
config_dir = tmp_path / "config"
|
||||
staged = vault_dir / "incoming" / "projects" / "p07-example"
|
||||
staged.mkdir(parents=True)
|
||||
drive_dir.mkdir()
|
||||
config_dir.mkdir()
|
||||
registry_path = config_dir / "project-registry.json"
|
||||
registry_path.write_text(json.dumps({"projects": []}), encoding="utf-8")
|
||||
|
||||
monkeypatch.setenv("ATOCORE_VAULT_SOURCE_DIR", str(vault_dir))
|
||||
monkeypatch.setenv("ATOCORE_DRIVE_SOURCE_DIR", str(drive_dir))
|
||||
monkeypatch.setenv("ATOCORE_PROJECT_REGISTRY_PATH", str(registry_path))
|
||||
|
||||
original_settings = config.settings
|
||||
try:
|
||||
config.settings = config.Settings()
|
||||
proposal = build_project_registration_proposal(
|
||||
project_id="p07-example",
|
||||
aliases=["p07", "example-project", "p07"],
|
||||
description="Example project",
|
||||
ingest_roots=[
|
||||
{
|
||||
"source": "vault",
|
||||
"subpath": "incoming/projects/p07-example",
|
||||
"label": "Primary docs",
|
||||
}
|
||||
],
|
||||
)
|
||||
finally:
|
||||
config.settings = original_settings
|
||||
|
||||
assert proposal["project"]["aliases"] == ["p07", "example-project"]
|
||||
assert proposal["resolved_ingest_roots"][0]["exists"] is True
|
||||
assert proposal["valid"] is True
|
||||
|
||||
|
||||
def test_project_registration_proposal_reports_collisions(tmp_path, monkeypatch):
|
||||
vault_dir = tmp_path / "vault"
|
||||
drive_dir = tmp_path / "drive"
|
||||
config_dir = tmp_path / "config"
|
||||
vault_dir.mkdir()
|
||||
drive_dir.mkdir()
|
||||
config_dir.mkdir()
|
||||
registry_path = config_dir / "project-registry.json"
|
||||
registry_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"projects": [
|
||||
{
|
||||
"id": "p05-interferometer",
|
||||
"aliases": ["p05", "interferometer"],
|
||||
"ingest_roots": [
|
||||
{"source": "vault", "subpath": "incoming/projects/p05-interferometer"}
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
monkeypatch.setenv("ATOCORE_VAULT_SOURCE_DIR", str(vault_dir))
|
||||
monkeypatch.setenv("ATOCORE_DRIVE_SOURCE_DIR", str(drive_dir))
|
||||
monkeypatch.setenv("ATOCORE_PROJECT_REGISTRY_PATH", str(registry_path))
|
||||
|
||||
original_settings = config.settings
|
||||
try:
|
||||
config.settings = config.Settings()
|
||||
proposal = build_project_registration_proposal(
|
||||
project_id="p08-example",
|
||||
aliases=["interferometer"],
|
||||
ingest_roots=[
|
||||
{"source": "vault", "subpath": "incoming/projects/p08-example"}
|
||||
],
|
||||
)
|
||||
finally:
|
||||
config.settings = original_settings
|
||||
|
||||
assert proposal["valid"] is False
|
||||
assert proposal["collisions"][0]["existing_project"] == "p05-interferometer"
|
||||
|
||||
Reference in New Issue
Block a user