This commit is contained in:
1 parent
4db3f45164
commit
d25c04cdd2
175 files changed
+56243
-15
No files matched your search
@@ -0,0 +1,74 @@
|
||||
"""Install the explicitly labeled two-project test registry for disposable work."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import secrets
|
||||
from pathlib import Path
|
||||
|
||||
from gewu.application.paths import reject_symlink_components
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--replace", action="store_true")
|
||||
arguments = parser.parse_args()
|
||||
data_root = Path(os.environ.get("GEWU_DATA_ROOT", "./.data/gewu")).expanduser().absolute()
|
||||
reject_symlink_components(data_root)
|
||||
control_root = data_root / "control"
|
||||
reject_symlink_components(control_root)
|
||||
control_root.mkdir(parents=True, exist_ok=True, mode=0o700)
|
||||
control_root.chmod(0o700)
|
||||
destination = control_root / "registry.json"
|
||||
if destination.exists() and not arguments.replace:
|
||||
raise SystemExit("Registry exists; pass --replace only to deliberately reset it")
|
||||
|
||||
fixture_path = (
|
||||
Path(__file__).resolve().parents[1] / "schema" / "fixtures" / "pilot-projects.json"
|
||||
)
|
||||
|
||||
def reject_duplicate_keys(pairs: list[tuple[str, object]]) -> dict[str, object]:
|
||||
result: dict[str, object] = {}
|
||||
for key, value in pairs:
|
||||
if key in result:
|
||||
raise ValueError("Test fixture has duplicate JSON keys")
|
||||
result[key] = value
|
||||
return result
|
||||
|
||||
fixture = json.loads(
|
||||
fixture_path.read_text(encoding="utf-8"), object_pairs_hook=reject_duplicate_keys
|
||||
)
|
||||
project_fields = {
|
||||
"project_id",
|
||||
"title",
|
||||
"status",
|
||||
"north_star",
|
||||
"key_questions",
|
||||
"autonomy_policy_id",
|
||||
}
|
||||
projects = []
|
||||
for item in fixture["projects"]:
|
||||
project = {key: value for key, value in item.items() if key in project_fields}
|
||||
projects.append(project)
|
||||
config = {
|
||||
"schema_version": 1,
|
||||
"projects": projects,
|
||||
"policies": fixture["test_policies"],
|
||||
}
|
||||
temporary = control_root / f".{secrets.token_hex(12)}.tmp"
|
||||
try:
|
||||
with temporary.open("x", encoding="utf-8") as stream:
|
||||
json.dump(config, stream, ensure_ascii=False, allow_nan=False, indent=2)
|
||||
stream.flush()
|
||||
os.fsync(stream.fileno())
|
||||
os.chmod(temporary, 0o600)
|
||||
os.replace(temporary, destination)
|
||||
finally:
|
||||
temporary.unlink(missing_ok=True)
|
||||
print("Installed disposable fixture projects and test-only acceptance policies.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user