✅ Add POC fixture discovery

This commit is contained in:
eust-w 2026-06-23 11:24:50 +08:00
parent 5f14f6db5d
commit 6c9eb10520
6 changed files with 637 additions and 0 deletions

View File

@ -74,6 +74,7 @@ Drobodata is a workflow orchestration platform for embodied AI and vision pipeli
- `npm run acceptance:object-storage`: browser-driven object-storage acceptance against a configured live storage connection; requires `OBJECT_STORAGE_CONNECTION_ID`, `OBJECT_STORAGE_CONNECTION_NAME`, or `OBJECT_STORAGE_BUCKET`
- `npm run acceptance:poc-operators`: run the POC Kubernetes Job that executes the deployed builtin operator modules with real files, video, MongoDB, BOS, and D-Cloud FAT calls when the required POC external credentials are configured
- `npm run acceptance:poc-readiness`: preflight POC deployment image, D-Cloud FAT secret, and real fixture manifest readiness as JSON without launching an acceptance Job or printing secret values
- `npm run acceptance:poc-fixtures:discover`: scan existing real fixture candidates on the shared POC `/workspace` PVC and optionally write a manifest when every required fixture and shell validation command is present
- `npm run acceptance:poc-fixtures`: copy caller-provided real POC acceptance fixture files/directories into the shared workspace PVC and write the fixture manifest consumed by `acceptance:poc-operators`; it does not generate mock, simulated, or hardcoded fixtures
- `npm run acceptance:xplatform`: X-platform operator-chain acceptance against an explicit real dataset; requires `XPLATFORM_SOURCE_PATH`, explicit `XPLATFORM_RULES_JSON`, all `XPLATFORM_MIN_*` counts, quality/slicing thresholds, and a storage connection selector when the source or upload path is `bos://...`; count and segment values must be exact safe positive integers
- `python3 scripts/wjzh_operator_regression.py --preflight-only`: preflight the production-style WJZH real-data operator regression against a live API; requires explicit `SOURCE_PATH`, `UPLOAD_ROOT_PREFIX`, storage connection selector, target video filenames, route/filter values, real Robotics dataset paths, incremental seed metadata, quality thresholds, video timing, and `SAMPLING_RULES_JSON`; integer timing values must be exact safe positive integers

View File

@ -260,6 +260,22 @@ The import endpoint validates full-acceptance consistency before it creates or u
Configure or refresh the POC real fixture manifest from local fixture files and directories:
```bash
DEPLOY_ENV=poc npm run acceptance:poc-fixtures:discover
```
`acceptance:poc-fixtures:discover` scans existing files and directories on the deployed POC shared `/workspace` PVC through the API Pod mount. It reports candidate `xplatform`, `csv`, `json`, `lerobot`, `rosbag`, and `model` paths, but it does not generate data, infer a shell validation command, or write a manifest unless `--write-manifest` is explicitly passed and `POC_ACCEPTANCE_SHELL_COMMAND` is configured. Historical `/workspace/acceptance/...` run output is excluded by default so prior generated or diagnostic evidence cannot be selected as final fixture input; set `POC_ACCEPTANCE_DISCOVERY_INCLUDE_ACCEPTANCE_OUTPUT=true` only when auditing old runs. Narrow scanning with `POC_ACCEPTANCE_DISCOVERY_ROOTS=/workspace/fixtures,/workspace/datasets` when the PVC contains large unrelated trees.
When discovery finds every real fixture and the shell validation command is known, write the manifest in place:
```bash
POC_ACCEPTANCE_DISCOVERY_ROOTS=/workspace/fixtures,/workspace/datasets \
POC_ACCEPTANCE_SHELL_COMMAND='python3 /workspace/fixtures/poc-operator-acceptance/shell_acceptance.py' \
DEPLOY_ENV=poc npm run acceptance:poc-fixtures:discover -- --write-manifest
```
If the real fixtures are still local to the machine running the command, copy them to the POC PVC and write the manifest with explicit paths:
```bash
POC_ACCEPTANCE_LOCAL_XPLATFORM_SOURCE_PATH=/path/to/xplatform-root \
POC_ACCEPTANCE_LOCAL_CSV_INPUT_PATH=/path/to/records.csv \

View File

@ -47,6 +47,7 @@
"acceptance:poc-operators": "./scripts/poc-operator-full-acceptance.sh",
"acceptance:poc-readiness": "./scripts/poc-acceptance-readiness.sh",
"acceptance:poc-fixtures": "./scripts/configure-poc-acceptance-fixtures.sh",
"acceptance:poc-fixtures:discover": "./scripts/poc-acceptance-fixture-discovery.sh",
"acceptance:object-storage": "node scripts/object-storage-acceptance.mjs",
"acceptance:xplatform": "python3 scripts/xplatform-live-acceptance.py"
},

View File

@ -0,0 +1,421 @@
#!/usr/bin/env python3
from __future__ import annotations
import argparse
import json
import os
import pathlib
import subprocess
from dataclasses import dataclass
from typing import Any
DEFAULT_NAMESPACE = "droboticflow"
DEFAULT_WORKSPACE = "/workspace"
DEFAULT_MANIFEST_PATH = "/workspace/fixtures/poc-operator-acceptance/poc-operator-acceptance.json"
DEFAULT_DISCOVERY_ROOTS = (
"/workspace/fixtures",
"/workspace/datasets",
"/workspace/source-data",
"/workspace/imports",
"/workspace/raw",
"/workspace",
)
JSON_READ_LIMIT_BYTES = 2 * 1024 * 1024
@dataclass(frozen=True)
class Candidate:
path: str
score: int
evidence: dict[str, Any]
def run_kubectl(args: list[str], *, input_text: str | None = None) -> subprocess.CompletedProcess[str]:
return subprocess.run(["kubectl", *args], input=input_text, text=True, capture_output=True, check=False)
def api_pod_name(namespace: str) -> str:
result = run_kubectl(["-n", namespace, "get", "pod", "-l", "app=droboticflow-api", "-o", "jsonpath={.items[0].metadata.name}"])
return result.stdout.strip() if result.returncode == 0 else ""
def workspace_path(value: str, workspace_mount: str) -> bool:
value = value.rstrip("/") or "/"
workspace_mount = workspace_mount.rstrip("/") or "/"
return value == workspace_mount or value.startswith(workspace_mount + "/")
def normalize_roots(raw: str, workspace_mount: str) -> list[str]:
values = [item.strip().rstrip("/") for item in raw.split(",") if item.strip()]
roots: list[str] = []
seen: set[str] = set()
for value in values:
if not value.startswith("/"):
raise SystemExit(f"discovery root must be absolute: {value}")
if not workspace_path(value, workspace_mount):
raise SystemExit(f"discovery root must point under {workspace_mount}: {value}")
if value not in seen:
roots.append(value)
seen.add(value)
return roots
def remote_shell(namespace: str, pod: str, script: str, args: list[str]) -> str:
result = run_kubectl(["-n", namespace, "exec", pod, "--", "sh", "-c", script, "--", *args])
if result.returncode != 0:
return ""
return result.stdout
def remote_text(namespace: str, pod: str, path: str, limit: int = JSON_READ_LIMIT_BYTES) -> str:
result = run_kubectl(
["-n", namespace, "exec", pod, "--", "sh", "-c", 'head -c "$2" "$1" 2>/dev/null', "--", path, str(limit)]
)
if result.returncode != 0:
return ""
return result.stdout
def write_remote_text(namespace: str, pod: str, path: str, text: str) -> bool:
result = run_kubectl(
[
"-n",
namespace,
"exec",
"-i",
pod,
"--",
"sh",
"-c",
'mkdir -p "$(dirname "$1")" && cat > "$1" && test -s "$1"',
"--",
path,
],
input_text=text,
)
return result.returncode == 0
def find_paths(namespace: str, pod: str, root: str, workspace_mount: str, include_acceptance_output: bool, expression: str, limit: int) -> list[str]:
exclude_root = workspace_mount.rstrip("/") + "/acceptance"
if include_acceptance_output:
exclude_root = "/__droboticflow_no_acceptance_exclude__"
script = (
'if [ ! -d "$1" ]; then exit 0; fi; '
f'find "$1" \\( -path "$2" -o -path "$2/*" \\) -prune -o {expression} -print | sort | head -n "$3"'
)
output = remote_shell(namespace, pod, script, [root, exclude_root, str(limit)])
paths = [line.strip() for line in output.splitlines() if line.strip()]
return paths
def sorted_candidates(candidates: list[Candidate]) -> list[Candidate]:
return sorted(candidates, key=lambda item: (-item.score, item.path))
def first_video_count(namespace: str, pod: str, root: str, workspace_mount: str, include_acceptance_output: bool) -> int:
paths = find_paths(
namespace,
pod,
root,
workspace_mount,
include_acceptance_output,
"\\( -type f \\( -iname '*.mp4' -o -iname '*.mov' -o -iname '*.avi' -o -iname '*.mkv' \\) \\)",
20,
)
return len(paths)
def discover_xplatform(namespace: str, pod: str, roots: list[str], workspace_mount: str, include_acceptance_output: bool, limit: int) -> list[Candidate]:
candidates: list[Candidate] = []
script = (
'if [ ! -d "$1" ]; then exit 0; fi; '
'find "$1" \\( -path "$2" -o -path "$2/*" \\) -prune -o -type f -name meta.json -print '
"| while IFS= read -r file; do dir=$(dirname \"$file\"); "
'if [ -s "$dir/video_meta.json" ]; then printf "%s\\n" "$dir"; fi; done | sort | head -n "$3"'
)
exclude_root = workspace_mount.rstrip("/") + "/acceptance"
if include_acceptance_output:
exclude_root = "/__droboticflow_no_acceptance_exclude__"
for root in roots:
output = remote_shell(namespace, pod, script, [root, exclude_root, str(limit)])
for path in output.splitlines():
path = path.strip()
if not path:
continue
video_count = first_video_count(namespace, pod, path, workspace_mount, include_acceptance_output)
score = 100 + min(video_count, 20)
candidates.append(
Candidate(path=path, score=score, evidence={"metaJson": path + "/meta.json", "videoMetaJson": path + "/video_meta.json", "videoCountSample": video_count})
)
return sorted_candidates(dedupe_candidates(candidates))[:limit]
def discover_lerobot(namespace: str, pod: str, roots: list[str], workspace_mount: str, include_acceptance_output: bool, limit: int) -> list[Candidate]:
candidates: list[Candidate] = []
script = (
'if [ ! -d "$1" ]; then exit 0; fi; '
'find "$1" \\( -path "$2" -o -path "$2/*" \\) -prune -o -type f -path "*/meta/info.json" -print '
"| while IFS= read -r file; do dir=$(dirname \"$(dirname \"$file\")\"); "
'if [ -d "$dir/data" ] || [ -d "$dir/videos" ]; then printf "%s\\n" "$dir"; fi; done | sort | head -n "$3"'
)
exclude_root = workspace_mount.rstrip("/") + "/acceptance"
if include_acceptance_output:
exclude_root = "/__droboticflow_no_acceptance_exclude__"
for root in roots:
output = remote_shell(namespace, pod, script, [root, exclude_root, str(limit)])
for path in output.splitlines():
path = path.strip()
if path:
candidates.append(Candidate(path=path, score=100, evidence={"infoJson": path + "/meta/info.json"}))
return sorted_candidates(dedupe_candidates(candidates))[:limit]
def discover_rosbag(namespace: str, pod: str, roots: list[str], workspace_mount: str, include_acceptance_output: bool, limit: int) -> list[Candidate]:
candidates: list[Candidate] = []
for root in roots:
files = find_paths(
namespace,
pod,
root,
workspace_mount,
include_acceptance_output,
"\\( -type f \\( -iname '*.bag' -o -iname '*.mcap' \\) \\)",
limit,
)
for path in files:
candidates.append(Candidate(path=path, score=100, evidence={"format": pathlib.PurePosixPath(path).suffix.lower().lstrip(".")}))
metadata = find_paths(namespace, pod, root, workspace_mount, include_acceptance_output, "\\( -type f -name metadata.yaml \\)", limit)
for path in metadata:
directory = str(pathlib.PurePosixPath(path).parent)
candidates.append(Candidate(path=directory, score=90, evidence={"metadataYaml": path, "format": "rosbag2"}))
return sorted_candidates(dedupe_candidates(candidates))[:limit]
def parse_json_candidate(namespace: str, pod: str, path: str) -> Any | None:
text = remote_text(namespace, pod, path)
if not text.strip():
return None
try:
return json.loads(text)
except json.JSONDecodeError:
return None
def json_input_score(path: str, payload: Any) -> int:
name = pathlib.PurePosixPath(path).name.lower()
score = 1
if isinstance(payload, list) and payload and all(isinstance(item, dict) for item in payload):
score += 50
if isinstance(payload, dict):
items = payload.get("items")
if isinstance(items, list) and items and all(isinstance(item, dict) for item in items):
score += 60
elif payload:
score += 20
if any(token in name for token in ("record", "input", "item", "data", "sample")):
score += 20
if name in {"meta.json", "video_meta.json", "model.json", "operator.json", "repository.json", "poc-operator-acceptance.json"}:
score -= 80
return score
def model_score(path: str, payload: Any) -> int:
if not isinstance(payload, dict) or not str(payload.get("type") or "").strip():
return -100
name = pathlib.PurePosixPath(path).name.lower()
score = 50
if "model" in name:
score += 50
if any(key in payload for key in ("weights", "threshold", "positiveLabel", "negativeLabel", "features")):
score += 25
return score
def discover_json_files(
namespace: str,
pod: str,
roots: list[str],
workspace_mount: str,
include_acceptance_output: bool,
limit: int,
) -> tuple[list[Candidate], list[Candidate]]:
json_candidates: list[Candidate] = []
model_candidates: list[Candidate] = []
seen: set[str] = set()
for root in roots:
paths = find_paths(namespace, pod, root, workspace_mount, include_acceptance_output, "\\( -type f -iname '*.json' -size +0c \\)", limit * 8)
for path in paths:
if path in seen:
continue
seen.add(path)
payload = parse_json_candidate(namespace, pod, path)
if payload is None:
continue
input_score = json_input_score(path, payload)
if input_score > 0:
json_candidates.append(Candidate(path=path, score=input_score, evidence=json_payload_evidence(payload)))
candidate_model_score = model_score(path, payload)
if candidate_model_score > 0:
model_candidates.append(Candidate(path=path, score=candidate_model_score, evidence={"type": str(payload.get("type") or ""), "keys": sorted(payload.keys())[:12]}))
return sorted_candidates(json_candidates)[:limit], sorted_candidates(model_candidates)[:limit]
def json_payload_evidence(payload: Any) -> dict[str, Any]:
if isinstance(payload, list):
return {"shape": "array", "itemCount": len(payload)}
if isinstance(payload, dict):
items = payload.get("items")
return {"shape": "object", "keys": sorted(payload.keys())[:12], "itemCount": len(items) if isinstance(items, list) else None}
return {"shape": type(payload).__name__}
def discover_csv(namespace: str, pod: str, roots: list[str], workspace_mount: str, include_acceptance_output: bool, limit: int) -> list[Candidate]:
candidates: list[Candidate] = []
for root in roots:
paths = find_paths(
namespace,
pod,
root,
workspace_mount,
include_acceptance_output,
"\\( -type f \\( -iname '*.csv' -o -iname '*.tsv' \\) -size +0c \\)",
limit,
)
for path in paths:
header = remote_text(namespace, pod, path, 4096)
lines = [line for line in header.splitlines() if line.strip()]
delimiter = "\t" if pathlib.PurePosixPath(path).suffix.lower() == ".tsv" else ","
score = 50
if len(lines) >= 2:
score += 40
if lines and delimiter in lines[0]:
score += 20
candidates.append(Candidate(path=path, score=score, evidence={"lineSampleCount": len(lines), "delimiter": delimiter}))
return sorted_candidates(dedupe_candidates(candidates))[:limit]
def dedupe_candidates(candidates: list[Candidate]) -> list[Candidate]:
best: dict[str, Candidate] = {}
for candidate in candidates:
previous = best.get(candidate.path)
if previous is None or candidate.score > previous.score:
best[candidate.path] = candidate
return list(best.values())
def candidate_to_json(candidate: Candidate) -> dict[str, Any]:
return {"path": candidate.path, "score": candidate.score, "evidence": candidate.evidence}
def build_manifest(selected: dict[str, Candidate], shell_command: str) -> dict[str, Any]:
return {
"fixtures": {
"xplatform": selected["xplatform"].path,
"csv": selected["csv"].path,
"json": selected["json"].path,
"lerobot": selected["lerobot"].path,
"rosbag": selected["rosbag"].path,
"model": selected["model"].path,
},
"shellCommand": shell_command,
}
def main() -> int:
parser = argparse.ArgumentParser(description="Discover existing real POC acceptance fixture candidates on the shared workspace PVC")
parser.add_argument("--namespace", default=os.getenv("K8S_NAMESPACE") or DEFAULT_NAMESPACE)
parser.add_argument("--workspace-mount-path", default=os.getenv("WORKSPACE_MOUNT_PATH") or DEFAULT_WORKSPACE)
parser.add_argument("--roots", default=os.getenv("POC_ACCEPTANCE_DISCOVERY_ROOTS") or ",".join(DEFAULT_DISCOVERY_ROOTS))
parser.add_argument("--manifest-path", default=os.getenv("POC_ACCEPTANCE_FIXTURE_MANIFEST_PATH") or DEFAULT_MANIFEST_PATH)
parser.add_argument("--shell-command", default=os.getenv("POC_ACCEPTANCE_SHELL_COMMAND") or "")
parser.add_argument("--max-results", type=int, default=int(os.getenv("POC_ACCEPTANCE_DISCOVERY_MAX_RESULTS") or "10"))
parser.add_argument("--include-acceptance-output", action="store_true", default=os.getenv("POC_ACCEPTANCE_DISCOVERY_INCLUDE_ACCEPTANCE_OUTPUT", "").lower() in {"1", "true", "yes", "on"})
parser.add_argument("--write-manifest", action="store_true", help="write the selected manifest to --manifest-path when every required real fixture is found")
parser.add_argument("--require-complete", action="store_true", help="exit non-zero when the discovery result is incomplete")
args = parser.parse_args()
if args.max_results <= 0:
raise SystemExit("--max-results must be positive")
workspace_mount = args.workspace_mount_path.rstrip("/") or "/"
if not args.manifest_path.startswith("/"):
raise SystemExit("--manifest-path must be absolute")
if not workspace_path(args.manifest_path, workspace_mount):
raise SystemExit(f"--manifest-path must point under {workspace_mount}: {args.manifest_path}")
roots = normalize_roots(args.roots, workspace_mount)
pod = api_pod_name(args.namespace)
if not pod:
payload = {
"status": "error",
"namespace": args.namespace,
"message": "no droboticflow-api pod is available for workspace fixture discovery",
}
print(json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True))
return 2
xplatform = discover_xplatform(args.namespace, pod, roots, workspace_mount, args.include_acceptance_output, args.max_results)
lerobot = discover_lerobot(args.namespace, pod, roots, workspace_mount, args.include_acceptance_output, args.max_results)
rosbag = discover_rosbag(args.namespace, pod, roots, workspace_mount, args.include_acceptance_output, args.max_results)
csv = discover_csv(args.namespace, pod, roots, workspace_mount, args.include_acceptance_output, args.max_results)
json_input, model = discover_json_files(args.namespace, pod, roots, workspace_mount, args.include_acceptance_output, args.max_results)
candidates = {
"xplatform": xplatform,
"csv": csv,
"json": json_input,
"lerobot": lerobot,
"rosbag": rosbag,
"model": model,
}
selected = {name: values[0] for name, values in candidates.items() if values}
missing = [name for name in ("xplatform", "csv", "json", "lerobot", "rosbag", "model") if name not in selected]
shell_command = args.shell_command.strip()
if not shell_command:
missing.append("shellCommand")
manifest = build_manifest(selected, shell_command) if not missing else None
status = "ready" if manifest is not None else "incomplete"
write_result = ""
if args.write_manifest:
if manifest is None:
write_result = "skipped: discovery result is incomplete"
else:
rendered = json.dumps(manifest, ensure_ascii=False, indent=2, sort_keys=True) + "\n"
if not write_remote_text(args.namespace, pod, args.manifest_path, rendered):
payload = {"status": "error", "message": f"failed to write manifest to {args.manifest_path}", "namespace": args.namespace}
print(json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True))
return 2
write_result = "written"
payload = {
"status": status,
"namespace": args.namespace,
"apiPod": pod,
"workspaceMountPath": workspace_mount,
"roots": roots,
"acceptanceOutputIncluded": bool(args.include_acceptance_output),
"manifestPath": args.manifest_path,
"candidates": {name: [candidate_to_json(candidate) for candidate in values] for name, values in candidates.items()},
"selected": {name: candidate_to_json(candidate) for name, candidate in selected.items()},
"missing": missing,
"manifest": manifest,
"writeResult": write_result,
"nextActions": [],
}
if "shellCommand" in missing:
payload["nextActions"].append("Set POC_ACCEPTANCE_SHELL_COMMAND to the real validation command that should run inside the acceptance Job.")
if any(name != "shellCommand" for name in missing):
payload["nextActions"].append("Copy real fixture data onto the shared /workspace PVC, or set POC_ACCEPTANCE_DISCOVERY_ROOTS to the existing real-data roots.")
if status == "ready" and not args.write_manifest:
payload["nextActions"].append("Run this command again with --write-manifest, then run DEPLOY_ENV=poc npm run acceptance:poc-readiness.")
print(json.dumps(payload, ensure_ascii=False, indent=2, sort_keys=True))
if args.write_manifest and manifest is None:
return 1
if args.require_complete and status != "ready":
return 1
return 0
if __name__ == "__main__":
raise SystemExit(main())

View File

@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
DEPLOY_ENV="${DEPLOY_ENV:-}"
if [[ $# -gt 0 && -z "$DEPLOY_ENV" && "${1:-}" != -* ]]; then
DEPLOY_ENV="$1"
shift
fi
export DEPLOY_ENV
# shellcheck source=scripts/load-deploy-env.sh
source "$ROOT_DIR/scripts/load-deploy-env.sh"
python3 "$ROOT_DIR/scripts/discover_poc_acceptance_fixtures.py" "$@"

View File

@ -0,0 +1,182 @@
import json
import os
import pathlib
import subprocess
ROOT = pathlib.Path(__file__).resolve().parents[2]
SCRIPT = ROOT / "scripts" / "poc-acceptance-fixture-discovery.sh"
def write_fake_kubectl(tmp_path: pathlib.Path, remote_root: pathlib.Path) -> pathlib.Path:
fake_bin = tmp_path / "bin"
fake_bin.mkdir()
kubectl = fake_bin / "kubectl"
kubectl.write_text(
"#!/usr/bin/env python3\n"
"import pathlib\n"
"import subprocess\n"
"import sys\n"
f"remote_root = pathlib.Path({str(remote_root)!r})\n"
"args = sys.argv[1:]\n"
"def map_arg(value):\n"
" if value.startswith('/'):\n"
" return str(remote_root / value.lstrip('/'))\n"
" return value\n"
"def remote_stdout(text):\n"
" sys.stdout.write(text.replace(str(remote_root), ''))\n"
"if args[:4] == ['-n', 'droboticflow', 'get', 'pod']:\n"
" print('droboticflow-api-test')\n"
" raise SystemExit(0)\n"
"if 'exec' in args:\n"
" sep = args.index('--')\n"
" command = args[sep + 1:]\n"
" if command[:2] == ['sh', '-c']:\n"
" script = command[2]\n"
" rest = command[4:] if len(command) > 3 and command[3] == '--' else command[3:]\n"
" mapped = [map_arg(item) for item in rest]\n"
" if 'cat > \"$1\"' in script:\n"
" target = pathlib.Path(mapped[0])\n"
" target.parent.mkdir(parents=True, exist_ok=True)\n"
" target.write_text(sys.stdin.read(), encoding='utf-8')\n"
" raise SystemExit(0 if target.is_file() and target.stat().st_size > 0 else 1)\n"
" result = subprocess.run(['sh', '-c', script, '--', *mapped], text=True, capture_output=True)\n"
" remote_stdout(result.stdout)\n"
" sys.stderr.write(result.stderr.replace(str(remote_root), ''))\n"
" raise SystemExit(result.returncode)\n"
"print('unexpected kubectl call: ' + ' '.join(args), file=sys.stderr)\n"
"raise SystemExit(97)\n",
encoding="utf-8",
)
kubectl.chmod(0o755)
return fake_bin
def make_real_fixture_tree(remote_root: pathlib.Path, base: str = "/workspace/fixtures/real") -> dict[str, str]:
root = remote_root / base.lstrip("/")
xplatform = root / "xplatform" / "BJ_001_0001_OsmoNano_2026-03-19_14-51-43"
(xplatform / "DJI_001").mkdir(parents=True)
(xplatform / "meta.json").write_text('{"type":"家庭","place":"蓟门里小区"}', encoding="utf-8")
(xplatform / "video_meta.json").write_text('[{"filename":"clip.mp4"}]', encoding="utf-8")
(xplatform / "DJI_001" / "clip.mp4").write_bytes(b"real-video")
csv_path = root / "records" / "records.csv"
csv_path.parent.mkdir(parents=True)
csv_path.write_text("id,label,score\nclip-1,keep,0.91\n", encoding="utf-8")
json_path = root / "records" / "records.json"
json_path.write_text('{"items":[{"id":"clip-1","label":"keep","score":0.91}]}', encoding="utf-8")
lerobot = root / "lerobot"
(lerobot / "meta").mkdir(parents=True)
(lerobot / "data" / "chunk-000").mkdir(parents=True)
(lerobot / "meta" / "info.json").write_text('{"robot_type":"real-arm","fps":10}', encoding="utf-8")
(lerobot / "data" / "chunk-000" / "episode_000000.parquet").write_bytes(b"PAR1")
rosbag = root / "rosbag2"
rosbag.mkdir(parents=True)
(rosbag / "metadata.yaml").write_text("rosbag2_bagfile_information:\n version: 5\n", encoding="utf-8")
(rosbag / "poc_0.db3").write_bytes(b"sqlite")
model = root / "model" / "model.json"
model.parent.mkdir(parents=True)
model.write_text('{"type":"linear","features":["score"],"weights":[1]}', encoding="utf-8")
return {
"xplatform": str(pathlib.PurePosixPath(base) / "xplatform" / xplatform.name),
"csv": str(pathlib.PurePosixPath(base) / "records" / "records.csv"),
"json": str(pathlib.PurePosixPath(base) / "records" / "records.json"),
"lerobot": str(pathlib.PurePosixPath(base) / "lerobot"),
"rosbag": str(pathlib.PurePosixPath(base) / "rosbag2"),
"model": str(pathlib.PurePosixPath(base) / "model" / "model.json"),
}
def run_script(tmp_path: pathlib.Path, remote_root: pathlib.Path, extra_env: dict[str, str], *args: str) -> subprocess.CompletedProcess:
fake_bin = write_fake_kubectl(tmp_path, remote_root)
env = os.environ.copy()
for key in (
"DEPLOY_ENV",
"DROBOTICFLOW_DEPLOY_ENV_LOADED",
"K8S_NAMESPACE",
"POC_ACCEPTANCE_DISCOVERY_ROOTS",
"POC_ACCEPTANCE_DISCOVERY_INCLUDE_ACCEPTANCE_OUTPUT",
"POC_ACCEPTANCE_FIXTURE_MANIFEST_PATH",
"POC_ACCEPTANCE_SHELL_COMMAND",
"WORKSPACE_MOUNT_PATH",
):
env.pop(key, None)
env.update(
{
"PATH": f"{fake_bin}{os.pathsep}{env.get('PATH', '')}",
"DROBOTICFLOW_DEPLOY_ENV_LOADED": "test",
"K8S_NAMESPACE": "droboticflow",
"WORKSPACE_MOUNT_PATH": "/workspace",
}
)
env.update(extra_env)
return subprocess.run(["bash", str(SCRIPT), *args], cwd=ROOT, env=env, text=True, capture_output=True, check=False)
def parse_payload(result: subprocess.CompletedProcess) -> dict:
return json.loads(result.stdout)
def test_fixture_discovery_finds_real_candidates_but_requires_shell_command(tmp_path):
remote_root = tmp_path / "remote"
make_real_fixture_tree(remote_root)
result = run_script(tmp_path, remote_root, {"POC_ACCEPTANCE_DISCOVERY_ROOTS": "/workspace/fixtures"})
assert result.returncode == 0, result.stderr + result.stdout
payload = parse_payload(result)
assert payload["status"] == "incomplete"
assert payload["missing"] == ["shellCommand"]
assert set(payload["selected"]) == {"xplatform", "csv", "json", "lerobot", "rosbag", "model"}
assert payload["selected"]["json"]["path"].endswith("/records.json")
assert payload["manifest"] is None
def test_fixture_discovery_writes_manifest_when_all_real_inputs_are_ready(tmp_path):
remote_root = tmp_path / "remote"
expected = make_real_fixture_tree(remote_root)
manifest_path = "/workspace/fixtures/poc-operator-acceptance/poc-operator-acceptance.json"
result = run_script(
tmp_path,
remote_root,
{
"POC_ACCEPTANCE_DISCOVERY_ROOTS": "/workspace/fixtures",
"POC_ACCEPTANCE_FIXTURE_MANIFEST_PATH": manifest_path,
"POC_ACCEPTANCE_SHELL_COMMAND": "python3 /workspace/fixtures/real/check.py",
},
"--write-manifest",
)
assert result.returncode == 0, result.stderr + result.stdout
payload = parse_payload(result)
assert payload["status"] == "ready"
assert payload["writeResult"] == "written"
written = json.loads((remote_root / manifest_path.lstrip("/")).read_text(encoding="utf-8"))
assert written["fixtures"] == expected
assert written["shellCommand"] == "python3 /workspace/fixtures/real/check.py"
def test_fixture_discovery_excludes_acceptance_outputs_by_default(tmp_path):
remote_root = tmp_path / "remote"
make_real_fixture_tree(remote_root, base="/workspace/acceptance/generated")
result = run_script(
tmp_path,
remote_root,
{
"POC_ACCEPTANCE_DISCOVERY_ROOTS": "/workspace",
"POC_ACCEPTANCE_SHELL_COMMAND": "python3 /workspace/acceptance/generated/check.py",
},
)
assert result.returncode == 0, result.stderr + result.stdout
payload = parse_payload(result)
assert payload["status"] == "incomplete"
assert set(payload["missing"]) == {"xplatform", "csv", "json", "lerobot", "rosbag", "model"}
assert payload["selected"] == {}