forked from longtao.wu/droboticflow
105 lines
4.9 KiB
Python
105 lines
4.9 KiB
Python
#!/usr/bin/env python3
|
|
"""Prepare and track the internal test lane using only local files.
|
|
|
|
No command in this entry point deploys, accesses MongoDB, reads BOS, or changes
|
|
customer records. Prepared manifests and plans require separate review.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
|
|
REPO = Path(__file__).resolve().parent.parent
|
|
if str(REPO) not in sys.path:
|
|
sys.path.insert(0, str(REPO))
|
|
|
|
from scripts.internal_test_lane.lifecycle import Lane, LaneError, _check_no_symlink, _read_json # noqa: E402
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--root", type=Path, default=REPO / "local-data" / "internal-test-lane", help="private local lane root")
|
|
sub = parser.add_subparsers(dest="command", required=True)
|
|
|
|
verify = sub.add_parser("verify-config", help="validate a dedicated environment config and print safe derived names")
|
|
verify.add_argument("--config", type=Path, required=True)
|
|
|
|
importer = sub.add_parser("import-bundle", help="verify six locally approved samples and copy immutable originals")
|
|
importer.add_argument("--bundle", type=Path, required=True)
|
|
|
|
prepared = sub.add_parser("prepare", help="render a batch package and offline seed plan")
|
|
prepared.add_argument("--batch", required=True)
|
|
prepared.add_argument("--import-id", required=True)
|
|
prepared.add_argument("--config", type=Path, required=True)
|
|
|
|
creds = sub.add_parser("credentials", help="generate private test-only credentials and a Secret manifest")
|
|
creds.add_argument("--config", type=Path, required=True)
|
|
creds.add_argument("--out", type=Path, required=True)
|
|
|
|
sub.add_parser("status", help="list local imports and batches without claiming remote success")
|
|
|
|
evidence = sub.add_parser("record-evidence", help="import a reviewed local seed or HTTP workflow report without querying its target")
|
|
evidence.add_argument("--batch", required=True)
|
|
evidence.add_argument("--evidence", type=Path, required=True, help="reviewer, target and version binding JSON")
|
|
evidence.add_argument("--plan", type=Path, required=True, help="actual approved execution plan JSON")
|
|
evidence.add_argument("--result", type=Path, required=True, help="Go apply or HTTP workflow result JSON")
|
|
|
|
archive = sub.add_parser("archive", help="record operator evidence that a batch is complete, stopped, and detached")
|
|
archive.add_argument("--batch", required=True)
|
|
archive.add_argument("--evidence", type=Path, required=True)
|
|
|
|
cleanup = sub.add_parser("cleanup-plan", help="preview local files eligible for explicit cleanup")
|
|
cleanup.add_argument("--batch", required=True)
|
|
|
|
clean = sub.add_parser("clean", help="remove only previewed owned local files of an old archived batch")
|
|
clean.add_argument("--batch", required=True)
|
|
clean.add_argument("--confirm", required=True, help="confirmSha256 from cleanup-plan")
|
|
|
|
args = parser.parse_args(argv)
|
|
lane = Lane(args.root)
|
|
try:
|
|
if args.command == "verify-config":
|
|
from scripts.internal_test_lane.environment import validate_config
|
|
config = validate_config(_read_json(args.config))
|
|
result = {key: config[key] for key in ("batchId", "namespace", "databaseName", "resourcePrefix", "credentialsSecretName", "mongoServiceName", "workspacePvcName", "mongoPvcName")}
|
|
elif args.command == "import-bundle":
|
|
result = lane.import_bundle(args.bundle)
|
|
elif args.command == "prepare":
|
|
result = lane.prepare(args.batch, args.import_id, args.config, REPO)
|
|
elif args.command == "credentials":
|
|
from scripts.internal_test_lane.credentials import generate_credentials
|
|
output = Path(os.path.abspath(args.out))
|
|
root = lane.root
|
|
_check_no_symlink(output)
|
|
if output != root and root not in output.parents:
|
|
raise LaneError("credential output directory must be inside the private lane root")
|
|
with lane.locked():
|
|
result = generate_credentials(_read_json(args.config), output)
|
|
elif args.command == "status":
|
|
result = lane.status()
|
|
elif args.command == "record-evidence":
|
|
result = lane.record_evidence(args.batch, args.evidence, args.plan, args.result)
|
|
elif args.command == "archive":
|
|
result = lane.archive(args.batch, args.evidence)
|
|
elif args.command == "cleanup-plan":
|
|
result = lane.cleanup_plan(args.batch)
|
|
elif args.command == "clean":
|
|
result = lane.clean(args.batch, args.confirm)
|
|
else:
|
|
parser.error("unknown command")
|
|
return 2
|
|
except (LaneError, ValueError, OSError) as exc:
|
|
print(f"refused: {exc}", file=sys.stderr)
|
|
return 2
|
|
print(json.dumps(result, indent=2, sort_keys=True))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|