Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 17 additions & 1 deletion scripts/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -12956,13 +12956,29 @@ def product_candidate_promotion_materialized_source_dir(
return None
commit_paths = string_list(promotion_request.get("commit_paths"))
if commit_paths and all(
path.startswith("runs/repaired_materialized_candidate_specs/")
product_candidate_promotion_is_repaired_materialized_path(path)
for path in commit_paths
):
# Promotion paths remain repository-relative even when a durable
# workspace binding scopes artifacts below runs/<workspace-id>.
# Git Service joins this source root with each approved path.
for ancestor in (runs_dir, *runs_dir.parents):
if ancestor.name == "runs":
return ancestor.parent
Comment on lines +12965 to +12967

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reject repaired paths outside current run scope

When executing a scoped run such as plan.runs_dir = /repo/runs/current, a stale approval path like runs/other/repaired_materialized_candidate_specs/foo.yaml now passes product_candidate_promotion_is_repaired_materialized_path and this returns /repo as the copy root, so Git Service will copy /repo/runs/other/... into the review worktree. The existing source-ref checks constrain approval source artifacts to plan_runs_dir, but they do not constrain promotion_request.paths, so this can promote another run/workspace's repaired file instead of failing closed.

Useful? React with 👍 / 👎.

return runs_dir.parent
return runs_dir / "materialized_candidate_specs"


def product_candidate_promotion_is_repaired_materialized_path(path: str) -> bool:
parts = Path(path).parts
return (
len(parts) >= 3
and parts[0] == "runs"
and ".." not in parts
and "repaired_materialized_candidate_specs" in parts
)


def product_candidate_promotion_operation(
*,
name: str,
Expand Down
82 changes: 82 additions & 0 deletions tests/test_platform_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import unittest

from scripts import hosted_managed_operation_queue as queue_module
from scripts import platform as platform_module
from tests.platform_fixtures import workspace_creation_request
from tests.test_hosted_managed_operation_queue import request_for

Expand Down Expand Up @@ -10780,6 +10781,87 @@ def test_product_candidate_promotion_execute_copies_repaired_paths(
).is_file()
)

def test_product_candidate_promotion_execute_copies_workspace_scoped_repaired_paths(
self,
) -> None:
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_root = Path(tmp_dir)
plan_path = self.build_graph_repository_execution_plan(tmp_root)
approved_path = (
"runs/hosted-operation-canary/"
"repaired_materialized_candidate_specs/IDEA-ALPHA.yaml"
)
approval_decision = self.write_candidate_approval_decision(
tmp_root,
paths=[approved_path],
)
promotion_request = tmp_root / "graph_repository_promotion_request.json"
request_result = self.run_cli(
"product-candidate-promotion",
"request",
"--plan",
str(plan_path),
"--approval-decision",
str(approval_decision),
"--output",
str(promotion_request),
"--format",
"json",
)
self.assertEqual(request_result.returncode, 0, request_result.stderr)
repaired_spec_path = tmp_root / approved_path
repaired_spec_path.parent.mkdir(parents=True, exist_ok=True)
repaired_spec_path.write_text(
"id: IDEA-ALPHA\nsummary: Scoped repaired candidate spec\n",
encoding="utf-8",
)
repository_dir = self.create_graph_repository_checkout(tmp_root)
workspace_dir = tmp_root / "candidate-worktree"

result = self.run_cli(
"product-candidate-promotion",
"execute",
"--promotion-request",
str(promotion_request),
"--approval-decision",
str(approval_decision),
"--repository-dir",
str(repository_dir),
"--workspace-dir",
str(workspace_dir),
"--open-review-dry-run",
"--format",
"json",
)

self.assertEqual(result.returncode, 0, result.stderr)
payload = json.loads(result.stdout)
self.assertTrue(payload["ok"], payload["diagnostics"])
self.assertEqual(payload["materialized_source_dir"], str(tmp_root.resolve()))
self.assertEqual(payload["git_review"]["copied_file_count"], 1)
self.assertTrue((workspace_dir / approved_path).is_file())

def test_product_candidate_promotion_resolves_scoped_repaired_paths_from_repository_root(
self,
) -> None:
with tempfile.TemporaryDirectory() as tmp_dir:
tmp_root = Path(tmp_dir)
runs_dir = tmp_root / "runs" / "hosted-operation-canary"
plan_path = runs_dir / "graph_repository_execution_plan.json"
source_dir = platform_module.product_candidate_promotion_materialized_source_dir(
explicit=None,
plan_path=plan_path,
plan={"runs_dir": str(runs_dir)},
promotion_request={
"commit_paths": [
"runs/hosted-operation-canary/"
"repaired_materialized_candidate_specs/IDEA-ALPHA.yaml"
]
},
)

self.assertEqual(source_dir, tmp_root.resolve())

def test_product_candidate_promotion_execute_resolves_relative_child_inputs(
self,
) -> None:
Expand Down