Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 150 additions & 13 deletions scripts/sales_readiness.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,24 @@ def _read_json(path: Path) -> dict[str, Any]:
return read_json_object(path)


def _resolve_cli_output_path(value: str, repo_root: Path) -> Path:
"""Return a CLI manifest path confined to the declared repository root."""
root = repo_root.resolve()
requested = Path(value)
candidate = (
requested.resolve(strict=False)
if requested.is_absolute()
else (root / requested).resolve(strict=False)
)
try:
candidate.relative_to(root)
except ValueError:
raise ValueError("sales-readiness --out must stay within --repo-root") from None
if candidate == root:
raise ValueError("sales-readiness --out must name a file within --repo-root")
return candidate


def _sha256(path: Path) -> str:
digest = hashlib.sha256()
with path.open("rb") as fh:
Expand Down Expand Up @@ -404,7 +422,10 @@ def _validate_20b_product_evidence(
checks.append(
_check(
"20b:roi_contract_value",
(contract_value_krw is None or payload.get("contract_value_krw") == contract_value_krw),
(
contract_value_krw is None
or payload.get("contract_value_krw") == contract_value_krw
),
"ROI manifest contract value matches readiness gate",
expected=contract_value_krw,
actual=payload.get("contract_value_krw"),
Expand All @@ -427,8 +448,9 @@ def _validate_20b_product_evidence(
isinstance(figma_url, str)
and figma_url.startswith("https://www.figma.com/design/"),
(
"optional Figma artifact URL must start with https://www.figma.com/design/; "
"FigJam /board/ URLs do not satisfy the design-file evidence contract"
"optional Figma artifact URL must start with "
"https://www.figma.com/design/; FigJam /board/ URLs "
"do not satisfy the design-file evidence contract"
),
actual=figma_url,
)
Expand All @@ -448,7 +470,10 @@ def _validate_20b_product_evidence(
checks.append(
_check(
"20b:completion_contract_value",
(contract_value_krw is None or payload.get("contract_value_krw") == contract_value_krw),
(
contract_value_krw is None
or payload.get("contract_value_krw") == contract_value_krw
),
"completion manifest contract value matches readiness gate",
expected=contract_value_krw,
actual=payload.get("contract_value_krw"),
Expand Down Expand Up @@ -493,6 +518,25 @@ def _validate_acceptance_summary(
)
)

declared_root_value = summary.get("out")
declared_root = (
Path(declared_root_value).resolve(strict=False)
if isinstance(declared_root_value, str) and declared_root_value
else None
)
acceptance_root = acceptance_path.resolve(strict=False).parent
evidence_root_ok = declared_root == acceptance_root
expected_auto_fit_path = acceptance_root / "fit_auto"
checks.append(
_check(
"acceptance:evidence_root_authority",
evidence_root_ok,
"acceptance summary is bound to its containing evidence root",
declared_root=(str(declared_root) if declared_root is not None else None),
expected_root=str(acceptance_root),
)
)

steps = summary.get("steps", [])
commands = {step.get("command") for step in steps if isinstance(step, dict)}
missing_commands = sorted(REQUIRED_ACCEPTANCE_COMMANDS - commands)
Expand All @@ -505,11 +549,12 @@ def _validate_acceptance_summary(
)
)

fit_backends = [
step.get("backend")
fit_steps = [
step
for step in steps
if isinstance(step, dict) and step.get("command") == "fit"
]
fit_backends = [step.get("backend") for step in fit_steps]
checks.append(
_check(
"acceptance:fit_backend_record",
Expand All @@ -520,6 +565,78 @@ def _validate_acceptance_summary(
)
)

auto_fit_steps = []
for step in fit_steps:
out_value = step.get("out")
if (
isinstance(out_value, str)
and out_value
and Path(out_value).resolve(strict=False) == expected_auto_fit_path
):
auto_fit_steps.append(step)
auto_fit_backend = (
auto_fit_steps[0].get("backend") if len(auto_fit_steps) == 1 else None
)
checks.append(
_check(
"acceptance:auto_fit_backend_authority",
len(auto_fit_steps) == 1 and auto_fit_backend == "rust",
"canonical automatic acceptance fit resolves exactly once to Rust",
count=len(auto_fit_steps),
backend=auto_fit_backend,
expected_out=str(expected_auto_fit_path),
)
)

auto_summary_ok = False
auto_summary_backend: object = None
auto_summary_path: Path | None = None
expected_auto_summary_path: Path | None = expected_auto_fit_path / "fit_summary.json"
auto_summary_error: str | None = None
if len(auto_fit_steps) == 1:
auto_fit = auto_fit_steps[0]
files = auto_fit.get("files")
summary_value = files.get("summary") if isinstance(files, dict) else None
if isinstance(summary_value, str) and summary_value:
auto_summary_path = Path(summary_value)
auto_summary_resolved = auto_summary_path.resolve(strict=False)
if not evidence_root_ok:
auto_summary_error = "acceptance evidence root is not authoritative"
elif auto_summary_resolved != expected_auto_summary_path:
auto_summary_error = "summary path is not bound to canonical fit_auto output"
elif not auto_summary_resolved.is_file():
auto_summary_error = "fit_auto summary is missing"
else:
try:
auto_summary = _read_json(auto_summary_resolved)
except (RuntimeError, ValueError) as exc:
auto_summary_error = str(exc)
else:
auto_summary_backend = auto_summary.get("backend")
auto_summary_ok = auto_summary_backend == "rust"
if not auto_summary_ok:
auto_summary_error = "persisted fit_auto backend is not rust"
else:
auto_summary_error = "fit_auto summary path is missing"
else:
auto_summary_error = "canonical fit_auto step is not unique"
checks.append(
_check(
"acceptance:auto_fit_summary_backend_authority",
auto_summary_ok,
"persisted canonical fit_auto summary is root-bound, path-bound, and Rust-owned",
backend=auto_summary_backend,
evidence_root=str(acceptance_root),
summary=(str(auto_summary_path) if auto_summary_path is not None else None),
expected_summary=(
str(expected_auto_summary_path)
if expected_auto_summary_path is not None
else None
),
error=auto_summary_error,
)
)

if require_rust:
explicit_rust = [
step
Expand Down Expand Up @@ -675,7 +792,10 @@ def _validate_buyer_packet(
),
_check(
"buyer_packet:contract_value",
(contract_value_krw is None or payload.get("contract_value_krw") == contract_value_krw),
(
contract_value_krw is None
or payload.get("contract_value_krw") == contract_value_krw
),
"buyer packet contract value matches readiness gate",
expected=contract_value_krw,
actual=payload.get("contract_value_krw"),
Expand Down Expand Up @@ -918,7 +1038,10 @@ def _validate_release_evidence_index(
),
_check(
"release_evidence_index:contract_value",
(contract_value_krw is None or payload.get("contract_value_krw") == contract_value_krw),
(
contract_value_krw is None
or payload.get("contract_value_krw") == contract_value_krw
),
"release evidence index contract value matches readiness gate",
expected=contract_value_krw,
actual=payload.get("contract_value_krw"),
Expand Down Expand Up @@ -1027,8 +1150,11 @@ def _validate_procurement_due_diligence(
),
_check(
"procurement_due_diligence:contract_value",
(contract_value_krw is None or payload.get("contract_value_krw") == contract_value_krw),
"procurement due-diligence contract value matches readiness gate",
(
contract_value_krw is None
or payload.get("contract_value_krw") == contract_value_krw
),
"procurement due-diligence manifest contract value matches readiness gate",
expected=contract_value_krw,
actual=payload.get("contract_value_krw"),
),
Expand Down Expand Up @@ -1139,7 +1265,10 @@ def _validate_pr_queue_governance(
),
_check(
"pr_queue_governance:contract_value",
(contract_value_krw is None or payload.get("contract_value_krw") == contract_value_krw),
(
contract_value_krw is None
or payload.get("contract_value_krw") == contract_value_krw
),
"PR queue governance contract value matches readiness gate",
expected=contract_value_krw,
actual=payload.get("contract_value_krw"),
Expand All @@ -1154,7 +1283,9 @@ def _validate_pr_queue_governance(
"pr_queue_governance:category_coverage",
REQUIRED_PR_QUEUE_GOVERNANCE_CATEGORIES.issubset(ok_categories),
"PR queue governance covers GitHub snapshot, queue state, risk classification, and release boundary evidence",
missing=sorted(REQUIRED_PR_QUEUE_GOVERNANCE_CATEGORIES - ok_categories),
missing=sorted(
REQUIRED_PR_QUEUE_GOVERNANCE_CATEGORIES - ok_categories
),
),
_check(
"pr_queue_governance:open_pr_count",
Expand Down Expand Up @@ -1266,7 +1397,10 @@ def _validate_figma_evidence_sync(
),
_check(
"figma_evidence_sync:contract_value",
(contract_value_krw is None or payload.get("contract_value_krw") == contract_value_krw),
(
contract_value_krw is None
or payload.get("contract_value_krw") == contract_value_krw
),
"Figma evidence sync contract value matches readiness gate",
expected=contract_value_krw,
actual=payload.get("contract_value_krw"),
Expand Down Expand Up @@ -1631,6 +1765,9 @@ def main(argv: list[str] | None = None) -> int:
parser = build_parser()
args = parser.parse_args(argv)
try:
repo_root = Path(args.repo_root).resolve()
args.repo_root = str(repo_root)
args.out = str(_resolve_cli_output_path(args.out, repo_root))
manifest = run_sales_readiness(args)
except Exception as exc:
print(json.dumps({"status": "failed", "error": str(exc)}, ensure_ascii=False))
Expand Down
5 changes: 3 additions & 2 deletions tests/test_sales_readiness.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ def _load_sales_readiness():

def _touch(path: Path) -> str:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text("ok", encoding="utf-8")
content = json.dumps({"backend": "rust"}) if path.name == "fit_summary.json" else "ok"
path.write_text(content, encoding="utf-8")
return str(path)


Expand Down Expand Up @@ -74,7 +75,7 @@ def _write_acceptance(tmp_path: Path, *, include_rust: bool = True) -> Path:
"files": {"summary": _touch(artifacts / "fit_rust" / "fit_summary.json")},
}
)
path = tmp_path / "acceptance_summary.json"
path = artifacts / "acceptance_summary.json"
path.write_text(module.json.dumps(summary), encoding="utf-8")
return path

Expand Down
Loading
Loading