rolloutdiff 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- rolloutdiff-0.1.0/.githooks/check_staged.py +139 -0
- rolloutdiff-0.1.0/.githooks/pre-commit +43 -0
- rolloutdiff-0.1.0/.githooks/pre-push +15 -0
- rolloutdiff-0.1.0/.github/ci-constraints.txt +36 -0
- rolloutdiff-0.1.0/.github/release_candidate.py +143 -0
- rolloutdiff-0.1.0/.github/test_release_candidate.py +290 -0
- rolloutdiff-0.1.0/.github/workflows/ci.yml +139 -0
- rolloutdiff-0.1.0/.github/workflows/release.yml +140 -0
- rolloutdiff-0.1.0/.gitignore +85 -0
- rolloutdiff-0.1.0/CODE_OF_CONDUCT.md +27 -0
- rolloutdiff-0.1.0/CONTRIBUTING.md +98 -0
- rolloutdiff-0.1.0/LICENSE +202 -0
- rolloutdiff-0.1.0/MANIFEST.in +210 -0
- rolloutdiff-0.1.0/PKG-INFO +158 -0
- rolloutdiff-0.1.0/README.md +127 -0
- rolloutdiff-0.1.0/SECURITY.md +21 -0
- rolloutdiff-0.1.0/bench/README.md +124 -0
- rolloutdiff-0.1.0/bench/aria.py +81 -0
- rolloutdiff-0.1.0/bench/dependence_study.py +392 -0
- rolloutdiff-0.1.0/bench/external_baselines.py +449 -0
- rolloutdiff-0.1.0/bench/external_manifest.json +116 -0
- rolloutdiff-0.1.0/bench/public_benchmark.py +597 -0
- rolloutdiff-0.1.0/bench/public_data.py +414 -0
- rolloutdiff-0.1.0/bench/public_eval.py +259 -0
- rolloutdiff-0.1.0/bench/public_manifest.json +921 -0
- rolloutdiff-0.1.0/bench/run_local.py +413 -0
- rolloutdiff-0.1.0/bench/sparse_replication.py +352 -0
- rolloutdiff-0.1.0/bench/synthetic.py +651 -0
- rolloutdiff-0.1.0/frontend/e2e/investigation.spec.ts +591 -0
- rolloutdiff-0.1.0/frontend/eslint.config.js +11 -0
- rolloutdiff-0.1.0/frontend/index.html +13 -0
- rolloutdiff-0.1.0/frontend/package-lock.json +3143 -0
- rolloutdiff-0.1.0/frontend/package.json +38 -0
- rolloutdiff-0.1.0/frontend/playwright.config.ts +9 -0
- rolloutdiff-0.1.0/frontend/public/assets/mona-sans-OFL.txt +93 -0
- rolloutdiff-0.1.0/frontend/public/assets/third-party-notices.txt +112 -0
- rolloutdiff-0.1.0/frontend/src/App.test.tsx +1172 -0
- rolloutdiff-0.1.0/frontend/src/App.tsx +495 -0
- rolloutdiff-0.1.0/frontend/src/BenchmarkEvidence.test.tsx +103 -0
- rolloutdiff-0.1.0/frontend/src/BenchmarkEvidence.tsx +179 -0
- rolloutdiff-0.1.0/frontend/src/CompareView.test.tsx +865 -0
- rolloutdiff-0.1.0/frontend/src/CompareView.tsx +957 -0
- rolloutdiff-0.1.0/frontend/src/EventsView.tsx +801 -0
- rolloutdiff-0.1.0/frontend/src/EvidenceView.test.tsx +621 -0
- rolloutdiff-0.1.0/frontend/src/EvidenceView.tsx +533 -0
- rolloutdiff-0.1.0/frontend/src/FeatureChart.tsx +437 -0
- rolloutdiff-0.1.0/frontend/src/FilePicker.test.tsx +314 -0
- rolloutdiff-0.1.0/frontend/src/FilePicker.tsx +307 -0
- rolloutdiff-0.1.0/frontend/src/ResponseDrawer.test.tsx +634 -0
- rolloutdiff-0.1.0/frontend/src/ResponseDrawer.tsx +386 -0
- rolloutdiff-0.1.0/frontend/src/RetrospectiveEvidence.tsx +42 -0
- rolloutdiff-0.1.0/frontend/src/SensitivityEvidence.tsx +100 -0
- rolloutdiff-0.1.0/frontend/src/api.ts +118 -0
- rolloutdiff-0.1.0/frontend/src/common.tsx +225 -0
- rolloutdiff-0.1.0/frontend/src/main.tsx +10 -0
- rolloutdiff-0.1.0/frontend/src/styles.css +1368 -0
- rolloutdiff-0.1.0/frontend/src/test-setup.ts +8 -0
- rolloutdiff-0.1.0/frontend/src/types.ts +317 -0
- rolloutdiff-0.1.0/frontend/tsconfig.json +16 -0
- rolloutdiff-0.1.0/frontend/vite.config.ts +13 -0
- rolloutdiff-0.1.0/pyproject.toml +54 -0
- rolloutdiff-0.1.0/scripts/build_release.py +310 -0
- rolloutdiff-0.1.0/scripts/check_install.py +202 -0
- rolloutdiff-0.1.0/src/rolloutdiff/__init__.py +130 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_aria_replay.py +346 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_benchmarks/m0-2026-11-06.json +318 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_dependence.py +195 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_feature_values.py +79 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_replay_container.py +568 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_report_validation.py +758 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_retrospective_policy.py +33 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_sampling.py +127 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_series_validation.py +67 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_watch_report.py +436 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_watch_storage.py +800 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_web/assets/index-D8uGEQ9w.js +12 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_web/assets/index-Dvo9nx9b.css +1 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_web/assets/mona-sans-OFL.txt +93 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_web/assets/mona-sans-latin-ext-wght-normal-BqSk0Z3x.woff2 +0 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_web/assets/mona-sans-latin-wght-normal-Pz49MTQZ.woff2 +0 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_web/assets/mona-sans-vietnamese-wght-normal-DsUdksa4.woff2 +0 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_web/assets/third-party-notices.txt +112 -0
- rolloutdiff-0.1.0/src/rolloutdiff/_web/index.html +14 -0
- rolloutdiff-0.1.0/src/rolloutdiff/adapters.py +264 -0
- rolloutdiff-0.1.0/src/rolloutdiff/app.py +956 -0
- rolloutdiff-0.1.0/src/rolloutdiff/app_evidence.py +678 -0
- rolloutdiff-0.1.0/src/rolloutdiff/benchmark_reference.py +458 -0
- rolloutdiff-0.1.0/src/rolloutdiff/cli.py +1292 -0
- rolloutdiff-0.1.0/src/rolloutdiff/comparison.py +572 -0
- rolloutdiff-0.1.0/src/rolloutdiff/comparison_report.py +982 -0
- rolloutdiff-0.1.0/src/rolloutdiff/corroboration.py +287 -0
- rolloutdiff-0.1.0/src/rolloutdiff/detect.py +307 -0
- rolloutdiff-0.1.0/src/rolloutdiff/events.py +173 -0
- rolloutdiff-0.1.0/src/rolloutdiff/evidence.py +285 -0
- rolloutdiff-0.1.0/src/rolloutdiff/exemplars.py +240 -0
- rolloutdiff-0.1.0/src/rolloutdiff/features.py +823 -0
- rolloutdiff-0.1.0/src/rolloutdiff/html_report.py +726 -0
- rolloutdiff-0.1.0/src/rolloutdiff/inspect_logs.py +383 -0
- rolloutdiff-0.1.0/src/rolloutdiff/inspection.py +207 -0
- rolloutdiff-0.1.0/src/rolloutdiff/integrations.py +552 -0
- rolloutdiff-0.1.0/src/rolloutdiff/investigation.py +1146 -0
- rolloutdiff-0.1.0/src/rolloutdiff/notifications.py +406 -0
- rolloutdiff-0.1.0/src/rolloutdiff/pipeline.py +809 -0
- rolloutdiff-0.1.0/src/rolloutdiff/producer.py +663 -0
- rolloutdiff-0.1.0/src/rolloutdiff/prompt_mix.py +258 -0
- rolloutdiff-0.1.0/src/rolloutdiff/ranking.py +388 -0
- rolloutdiff-0.1.0/src/rolloutdiff/replay.py +589 -0
- rolloutdiff-0.1.0/src/rolloutdiff/replication.py +572 -0
- rolloutdiff-0.1.0/src/rolloutdiff/report.py +838 -0
- rolloutdiff-0.1.0/src/rolloutdiff/retrospective.py +386 -0
- rolloutdiff-0.1.0/src/rolloutdiff/schema.py +109 -0
- rolloutdiff-0.1.0/src/rolloutdiff/sensitivity.py +202 -0
- rolloutdiff-0.1.0/src/rolloutdiff/series.py +430 -0
- rolloutdiff-0.1.0/src/rolloutdiff/tool_features.py +422 -0
- rolloutdiff-0.1.0/src/rolloutdiff/trajectories.py +236 -0
- rolloutdiff-0.1.0/src/rolloutdiff/watch-compatibility.json +13 -0
- rolloutdiff-0.1.0/src/rolloutdiff/watch.py +742 -0
- rolloutdiff-0.1.0/tests/_aria.py +34 -0
- rolloutdiff-0.1.0/tests/test_app.py +992 -0
- rolloutdiff-0.1.0/tests/test_app_cli.py +113 -0
- rolloutdiff-0.1.0/tests/test_app_evidence.py +487 -0
- rolloutdiff-0.1.0/tests/test_app_packaging.py +143 -0
- rolloutdiff-0.1.0/tests/test_aria_comparison.py +42 -0
- rolloutdiff-0.1.0/tests/test_aria_detection.py +184 -0
- rolloutdiff-0.1.0/tests/test_aria_full_pipeline.py +188 -0
- rolloutdiff-0.1.0/tests/test_aria_prompt_mix.py +138 -0
- rolloutdiff-0.1.0/tests/test_aria_replay.py +319 -0
- rolloutdiff-0.1.0/tests/test_aria_retrospective.py +231 -0
- rolloutdiff-0.1.0/tests/test_aria_validation_evidence.py +384 -0
- rolloutdiff-0.1.0/tests/test_bench_aria.py +18 -0
- rolloutdiff-0.1.0/tests/test_benchmark_reference.py +438 -0
- rolloutdiff-0.1.0/tests/test_bundled_reference.py +168 -0
- rolloutdiff-0.1.0/tests/test_cli.py +385 -0
- rolloutdiff-0.1.0/tests/test_comparison.py +707 -0
- rolloutdiff-0.1.0/tests/test_comparison_report.py +480 -0
- rolloutdiff-0.1.0/tests/test_console_entrypoint.py +117 -0
- rolloutdiff-0.1.0/tests/test_corroboration.py +295 -0
- rolloutdiff-0.1.0/tests/test_corroboration_bench.py +164 -0
- rolloutdiff-0.1.0/tests/test_corroboration_pipeline.py +231 -0
- rolloutdiff-0.1.0/tests/test_dependence.py +358 -0
- rolloutdiff-0.1.0/tests/test_dependence_study.py +172 -0
- rolloutdiff-0.1.0/tests/test_detect.py +301 -0
- rolloutdiff-0.1.0/tests/test_diff_cli.py +321 -0
- rolloutdiff-0.1.0/tests/test_diff_integrity.py +385 -0
- rolloutdiff-0.1.0/tests/test_event_pipeline.py +164 -0
- rolloutdiff-0.1.0/tests/test_event_ranking.py +636 -0
- rolloutdiff-0.1.0/tests/test_event_ranking_pipeline.py +227 -0
- rolloutdiff-0.1.0/tests/test_events.py +292 -0
- rolloutdiff-0.1.0/tests/test_evidence.py +329 -0
- rolloutdiff-0.1.0/tests/test_exemplar_pipeline.py +77 -0
- rolloutdiff-0.1.0/tests/test_exemplars.py +520 -0
- rolloutdiff-0.1.0/tests/test_external_baselines.py +504 -0
- rolloutdiff-0.1.0/tests/test_features.py +383 -0
- rolloutdiff-0.1.0/tests/test_fitted_synthetic.py +632 -0
- rolloutdiff-0.1.0/tests/test_full_pipeline.py +402 -0
- rolloutdiff-0.1.0/tests/test_git_hooks.py +453 -0
- rolloutdiff-0.1.0/tests/test_html_report.py +273 -0
- rolloutdiff-0.1.0/tests/test_ingestion.py +367 -0
- rolloutdiff-0.1.0/tests/test_inspect_cli.py +597 -0
- rolloutdiff-0.1.0/tests/test_inspect_logs.py +416 -0
- rolloutdiff-0.1.0/tests/test_inspection.py +577 -0
- rolloutdiff-0.1.0/tests/test_integrations.py +762 -0
- rolloutdiff-0.1.0/tests/test_investigation.py +797 -0
- rolloutdiff-0.1.0/tests/test_investigation_cli.py +242 -0
- rolloutdiff-0.1.0/tests/test_investigation_review.py +766 -0
- rolloutdiff-0.1.0/tests/test_local_bench.py +252 -0
- rolloutdiff-0.1.0/tests/test_nested_features.py +249 -0
- rolloutdiff-0.1.0/tests/test_notification_cli.py +81 -0
- rolloutdiff-0.1.0/tests/test_notifications.py +393 -0
- rolloutdiff-0.1.0/tests/test_pipeline.py +160 -0
- rolloutdiff-0.1.0/tests/test_producer.py +369 -0
- rolloutdiff-0.1.0/tests/test_prompt_mix.py +328 -0
- rolloutdiff-0.1.0/tests/test_public_data.py +383 -0
- rolloutdiff-0.1.0/tests/test_public_eval.py +407 -0
- rolloutdiff-0.1.0/tests/test_public_manifest.py +52 -0
- rolloutdiff-0.1.0/tests/test_public_runs.py +287 -0
- rolloutdiff-0.1.0/tests/test_render_cli.py +234 -0
- rolloutdiff-0.1.0/tests/test_replay.py +767 -0
- rolloutdiff-0.1.0/tests/test_replay_cli.py +141 -0
- rolloutdiff-0.1.0/tests/test_replay_container.py +666 -0
- rolloutdiff-0.1.0/tests/test_replication.py +400 -0
- rolloutdiff-0.1.0/tests/test_report.py +568 -0
- rolloutdiff-0.1.0/tests/test_report_validation.py +268 -0
- rolloutdiff-0.1.0/tests/test_retrospective.py +316 -0
- rolloutdiff-0.1.0/tests/test_retrospective_policy.py +322 -0
- rolloutdiff-0.1.0/tests/test_sampling.py +396 -0
- rolloutdiff-0.1.0/tests/test_sampling_replication.py +313 -0
- rolloutdiff-0.1.0/tests/test_sensitivity.py +369 -0
- rolloutdiff-0.1.0/tests/test_sensitivity_cli.py +128 -0
- rolloutdiff-0.1.0/tests/test_sensitivity_report.py +155 -0
- rolloutdiff-0.1.0/tests/test_series.py +328 -0
- rolloutdiff-0.1.0/tests/test_sparse_bench.py +56 -0
- rolloutdiff-0.1.0/tests/test_sparse_pipeline.py +53 -0
- rolloutdiff-0.1.0/tests/test_sparse_replication.py +313 -0
- rolloutdiff-0.1.0/tests/test_synthetic_detection.py +83 -0
- rolloutdiff-0.1.0/tests/test_synthetic_retrospective.py +71 -0
- rolloutdiff-0.1.0/tests/test_tool_features.py +204 -0
- rolloutdiff-0.1.0/tests/test_trajectories.py +281 -0
- rolloutdiff-0.1.0/tests/test_trajectory_cli.py +242 -0
- rolloutdiff-0.1.0/tests/test_unstepped_comparison.py +180 -0
- rolloutdiff-0.1.0/tests/test_verl_shard.py +54 -0
- rolloutdiff-0.1.0/tests/test_watch.py +496 -0
- rolloutdiff-0.1.0/tests/test_watch_analysis.py +237 -0
- rolloutdiff-0.1.0/tests/test_watch_cache.py +426 -0
- rolloutdiff-0.1.0/tests/test_watch_cli.py +220 -0
- rolloutdiff-0.1.0/tests/test_watch_recovery.py +148 -0
- rolloutdiff-0.1.0/tests/test_watch_report.py +370 -0
- rolloutdiff-0.1.0/tests/test_watch_storage.py +679 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"""Inspect staged blobs and enforce repository exclusions."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import re
|
|
5
|
+
import subprocess
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path, PurePosixPath
|
|
8
|
+
|
|
9
|
+
MAX_BYTES = 5 * 1024 * 1024
|
|
10
|
+
PRIVATE_DOCUMENTS = {"AGENTS.md", "Rollout Diff — Product & Engineering Plan.md"}
|
|
11
|
+
CREDENTIALS = re.compile(
|
|
12
|
+
rb"-----BEGIN (?:(?:RSA|DSA|EC|OPENSSH|ENCRYPTED) )?PRIVATE KEY-----"
|
|
13
|
+
rb"|\b(?:gh[pousr]_[A-Za-z0-9]{36,}|github_pat_[A-Za-z0-9_]{30,}"
|
|
14
|
+
rb"|sk-(?:proj-)?[A-Za-z0-9_-]{30,}|AKIA[A-Z0-9]{16}"
|
|
15
|
+
rb"|xox[baprs]-[A-Za-z0-9-]{20,})\b"
|
|
16
|
+
rb"|https?://[^\s/\"':]+:[^\s/@\"']+@"
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def git(*arguments, input=None, allowed=(0,)):
|
|
21
|
+
result = subprocess.run(
|
|
22
|
+
["git", *arguments], input=input, capture_output=True, check=False
|
|
23
|
+
)
|
|
24
|
+
if result.returncode not in allowed:
|
|
25
|
+
raise RuntimeError(f"git {arguments[0]} failed (exit {result.returncode})")
|
|
26
|
+
return result.stdout
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def index_entries():
|
|
30
|
+
entries = {}
|
|
31
|
+
for record in git("ls-files", "--stage", "-z").split(b"\0"):
|
|
32
|
+
if not record:
|
|
33
|
+
continue
|
|
34
|
+
metadata, path = record.split(b"\t", 1)
|
|
35
|
+
mode, oid, stage = metadata.decode("ascii").split()
|
|
36
|
+
if stage != "0":
|
|
37
|
+
raise RuntimeError("resolve unmerged index entries before committing")
|
|
38
|
+
entries[os.fsdecode(path)] = (mode, oid)
|
|
39
|
+
return entries
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def blob(oid):
|
|
43
|
+
size = int(git("cat-file", "-s", oid))
|
|
44
|
+
if size > MAX_BYTES:
|
|
45
|
+
raise RuntimeError("staged file exceeds the 5 MiB limit")
|
|
46
|
+
return git("cat-file", "blob", oid)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def check_ignore_policy(paths, entries):
|
|
50
|
+
# Git evaluates working-tree ignore files. Require their staged equivalents.
|
|
51
|
+
policies = {
|
|
52
|
+
str(parent / ".gitignore")
|
|
53
|
+
for path in paths
|
|
54
|
+
for parent in PurePosixPath(path).parents
|
|
55
|
+
}
|
|
56
|
+
for name in sorted(policies):
|
|
57
|
+
path = Path(name)
|
|
58
|
+
entry = entries.get(name)
|
|
59
|
+
if path.is_symlink() or (entry and entry[0] not in ("100644", "100755")):
|
|
60
|
+
raise RuntimeError(f"ignore policy {name!r} must be a regular file")
|
|
61
|
+
if path.is_file() and path.stat().st_size > MAX_BYTES:
|
|
62
|
+
raise RuntimeError(f"ignore policy {name!r} exceeds the 5 MiB limit")
|
|
63
|
+
working = path.read_bytes() if path.is_file() else None
|
|
64
|
+
staged = blob(entry[1]) if entry else None
|
|
65
|
+
if working != staged:
|
|
66
|
+
raise RuntimeError(
|
|
67
|
+
f"ignore policy {name!r} differs from the index; stage or restore it"
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def ignored_paths(paths):
|
|
72
|
+
output = git(
|
|
73
|
+
"check-ignore",
|
|
74
|
+
"--no-index",
|
|
75
|
+
"--stdin",
|
|
76
|
+
"-v",
|
|
77
|
+
"-z",
|
|
78
|
+
input=b"\0".join(os.fsencode(path) for path in paths) + b"\0",
|
|
79
|
+
allowed=(0, 1),
|
|
80
|
+
)
|
|
81
|
+
fields = output.split(b"\0")[:-1]
|
|
82
|
+
if len(fields) % 4:
|
|
83
|
+
raise RuntimeError("unexpected git check-ignore output")
|
|
84
|
+
return {
|
|
85
|
+
os.fsdecode(fields[index + 3])
|
|
86
|
+
for index in range(0, len(fields), 4)
|
|
87
|
+
if not fields[index + 2].startswith(b"!")
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def main():
|
|
92
|
+
root = os.fsdecode(git("rev-parse", "--show-toplevel")).rstrip("\n")
|
|
93
|
+
os.chdir(root)
|
|
94
|
+
entries = index_entries()
|
|
95
|
+
paths = [
|
|
96
|
+
os.fsdecode(path)
|
|
97
|
+
for path in git(
|
|
98
|
+
"diff",
|
|
99
|
+
"--cached",
|
|
100
|
+
"--name-only",
|
|
101
|
+
"--no-renames",
|
|
102
|
+
"--diff-filter=ACMT",
|
|
103
|
+
"-z",
|
|
104
|
+
).split(b"\0")
|
|
105
|
+
if path
|
|
106
|
+
]
|
|
107
|
+
if not paths:
|
|
108
|
+
return 0
|
|
109
|
+
check_ignore_policy(paths, entries)
|
|
110
|
+
ignored = ignored_paths(paths)
|
|
111
|
+
failures = []
|
|
112
|
+
for path in paths:
|
|
113
|
+
reason = None
|
|
114
|
+
mode, oid = entries[path]
|
|
115
|
+
if PurePosixPath(path).name in PRIVATE_DOCUMENTS:
|
|
116
|
+
reason = "private project document"
|
|
117
|
+
elif path in ignored:
|
|
118
|
+
reason = "excluded by Git ignore rules"
|
|
119
|
+
elif mode not in ("100644", "100755"):
|
|
120
|
+
reason = "staged entry must be a regular file"
|
|
121
|
+
else:
|
|
122
|
+
try:
|
|
123
|
+
if CREDENTIALS.search(blob(oid)):
|
|
124
|
+
reason = "credential marker in staged content"
|
|
125
|
+
except RuntimeError as error:
|
|
126
|
+
reason = str(error)
|
|
127
|
+
if reason:
|
|
128
|
+
failures.append(f"staged safety: {path!r}: {reason}")
|
|
129
|
+
for failure in failures:
|
|
130
|
+
print(failure, file=sys.stderr)
|
|
131
|
+
return int(bool(failures))
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
if __name__ == "__main__":
|
|
135
|
+
try:
|
|
136
|
+
sys.exit(main())
|
|
137
|
+
except (OSError, RuntimeError) as error:
|
|
138
|
+
print(f"staged safety: {error}", file=sys.stderr)
|
|
139
|
+
sys.exit(1)
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
set -eu
|
|
3
|
+
cd "$(git rev-parse --show-toplevel)"
|
|
4
|
+
export PYTHONDONTWRITEBYTECODE=1
|
|
5
|
+
|
|
6
|
+
python=.venv/bin/python
|
|
7
|
+
[ -x "$python" ] || python=python3
|
|
8
|
+
if ! "$python" .githooks/check_staged.py; then
|
|
9
|
+
echo "pre-commit: staged-file safety failed" >&2
|
|
10
|
+
exit 1
|
|
11
|
+
fi
|
|
12
|
+
if ! git diff --cached --check; then
|
|
13
|
+
echo "pre-commit: staged whitespace check failed" >&2
|
|
14
|
+
exit 1
|
|
15
|
+
fi
|
|
16
|
+
|
|
17
|
+
ruff=.venv/bin/ruff
|
|
18
|
+
if [ ! -x "$ruff" ]; then
|
|
19
|
+
ruff=$(command -v ruff || true)
|
|
20
|
+
fi
|
|
21
|
+
if [ -z "$ruff" ]; then
|
|
22
|
+
echo "pre-commit: install Ruff with: python -m pip install -c .github/ci-constraints.txt ruff" >&2
|
|
23
|
+
exit 1
|
|
24
|
+
fi
|
|
25
|
+
version=$(sed -n 's/^ruff==//p' .github/ci-constraints.txt)
|
|
26
|
+
if [ -z "$version" ] || [ "$("$ruff" --version)" != "ruff $version" ]; then
|
|
27
|
+
echo "pre-commit: Ruff must match the version in .github/ci-constraints.txt" >&2
|
|
28
|
+
exit 1
|
|
29
|
+
fi
|
|
30
|
+
if ! "$ruff" format --check --no-cache src bench tests; then
|
|
31
|
+
echo "pre-commit: Ruff formatting failed; review formatting changes before staging" >&2
|
|
32
|
+
exit 1
|
|
33
|
+
fi
|
|
34
|
+
if ! "$ruff" check --no-cache src bench tests; then
|
|
35
|
+
echo "pre-commit: Ruff lint failed" >&2
|
|
36
|
+
exit 1
|
|
37
|
+
fi
|
|
38
|
+
|
|
39
|
+
echo "pre-commit: TRY004 advisory review (non-blocking)"
|
|
40
|
+
if ! "$ruff" check --no-cache --select TRY004 --exit-zero src bench tests; then
|
|
41
|
+
echo "pre-commit: Ruff advisory check failed to run" >&2
|
|
42
|
+
exit 1
|
|
43
|
+
fi
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
set -eu
|
|
3
|
+
cd "$(git rev-parse --show-toplevel)"
|
|
4
|
+
python=.venv/bin/python
|
|
5
|
+
[ -x "$python" ] || python=python3
|
|
6
|
+
export PYTHONDONTWRITEBYTECODE=1 PYTEST_DISABLE_PLUGIN_AUTOLOAD=1
|
|
7
|
+
unset PYTEST_ADDOPTS PYTEST_PLUGINS
|
|
8
|
+
unset ROLLOUTDIFF_ARIA_PATH ROLLOUTDIFF_TRL_DIR ROLLOUTDIFF_FULL_ARIA
|
|
9
|
+
unset ROLLOUTDIFF_EXTERNAL_SOURCES ROLLOUTDIFF_METRICS_PATH ROLLOUTDIFF_PUBLIC_ROOT
|
|
10
|
+
|
|
11
|
+
echo "pre-push: running fast tests (local datasets and external snapshots excluded)"
|
|
12
|
+
if ! "$python" -m pytest -q -m 'not local_data' -p no:cacheprovider; then
|
|
13
|
+
echo "pre-push: fast tests failed" >&2
|
|
14
|
+
exit 1
|
|
15
|
+
fi
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# CI pins for the existing project, test, and build dependencies, plus Ruff.
|
|
2
|
+
annotated-types==0.8.0
|
|
3
|
+
iniconfig==2.3.1
|
|
4
|
+
# NumPy 2.5 requires Python 3.12 or newer.
|
|
5
|
+
numpy==2.4.6; python_version == "3.11"
|
|
6
|
+
numpy==2.5.4; python_version >= "3.12"
|
|
7
|
+
packaging==26.3
|
|
8
|
+
pandas==2.3.3
|
|
9
|
+
pluggy==1.7.0
|
|
10
|
+
pyarrow==26.0.0
|
|
11
|
+
pydantic==2.14.1
|
|
12
|
+
pydantic-core==2.50.1
|
|
13
|
+
Pygments==2.21.0
|
|
14
|
+
pytest==9.1.1
|
|
15
|
+
python-dateutil==2.9.0.post0
|
|
16
|
+
pytz==2026.5
|
|
17
|
+
ruff==0.17.0
|
|
18
|
+
setuptools==84.0.0
|
|
19
|
+
six==1.17.0
|
|
20
|
+
typing-inspection==0.4.4
|
|
21
|
+
typing_extensions==4.16.0
|
|
22
|
+
tzdata==2026.5
|
|
23
|
+
wheel==0.48.0
|
|
24
|
+
# Local investigation server and HTTP tests.
|
|
25
|
+
annotated-doc==0.0.5
|
|
26
|
+
anyio==4.16.0
|
|
27
|
+
certifi==2026.10.23
|
|
28
|
+
click==8.5.0
|
|
29
|
+
fastapi==0.162.0
|
|
30
|
+
h11==0.16.0
|
|
31
|
+
httpcore==1.0.9
|
|
32
|
+
httpx==0.28.1
|
|
33
|
+
idna==3.20
|
|
34
|
+
opentelemetry-api==1.45.2
|
|
35
|
+
starlette==1.10.0
|
|
36
|
+
uvicorn==0.54.0
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"""Select a successful main CI artifact for a manually approved release."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import re
|
|
6
|
+
import subprocess
|
|
7
|
+
import tomllib
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def github(path):
|
|
12
|
+
endpoint = f"repos/{os.environ['GITHUB_REPOSITORY']}/{path}"
|
|
13
|
+
return json.loads(subprocess.check_output(["gh", "api", endpoint]))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def configured_reviewer(entry):
|
|
17
|
+
if not isinstance(entry, dict) or entry.get("type") not in ("User", "Team"):
|
|
18
|
+
return False
|
|
19
|
+
reviewer = entry.get("reviewer")
|
|
20
|
+
return (
|
|
21
|
+
isinstance(reviewer, dict)
|
|
22
|
+
and type(reviewer.get("id")) is int
|
|
23
|
+
and reviewer["id"] > 0
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def verify_publishing_environment():
|
|
28
|
+
environment = github("environments/pypi")
|
|
29
|
+
if not isinstance(environment, dict) or environment.get("name") != "pypi":
|
|
30
|
+
raise SystemExit("Missing pypi environment")
|
|
31
|
+
rules = environment.get("protection_rules")
|
|
32
|
+
if not isinstance(rules, list) or not any(
|
|
33
|
+
isinstance(rule, dict)
|
|
34
|
+
and rule.get("type") == "required_reviewers"
|
|
35
|
+
and isinstance(reviewers := rule.get("reviewers"), list)
|
|
36
|
+
and reviewers
|
|
37
|
+
and all(configured_reviewer(entry) for entry in reviewers)
|
|
38
|
+
for rule in rules
|
|
39
|
+
):
|
|
40
|
+
raise SystemExit(
|
|
41
|
+
"The pypi environment requires a configured user or team reviewer"
|
|
42
|
+
)
|
|
43
|
+
mode = environment.get("deployment_branch_policy")
|
|
44
|
+
if (
|
|
45
|
+
not isinstance(mode, dict)
|
|
46
|
+
or mode.get("protected_branches") is not False
|
|
47
|
+
or mode.get("custom_branch_policies") is not True
|
|
48
|
+
):
|
|
49
|
+
raise SystemExit("The pypi environment must select custom deployment policies")
|
|
50
|
+
result = github("environments/pypi/deployment-branch-policies")
|
|
51
|
+
if not (
|
|
52
|
+
isinstance(result, dict)
|
|
53
|
+
and type(result.get("total_count")) is int
|
|
54
|
+
and result["total_count"] == 1
|
|
55
|
+
and isinstance(policies := result.get("branch_policies"), list)
|
|
56
|
+
and len(policies) == 1
|
|
57
|
+
and isinstance(policies[0], dict)
|
|
58
|
+
and policies[0].get("type") == "branch"
|
|
59
|
+
and policies[0].get("name") == "main"
|
|
60
|
+
):
|
|
61
|
+
raise SystemExit(
|
|
62
|
+
"The sole pypi deployment policy must be the exact main branch"
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def main():
|
|
67
|
+
tag = os.environ["RELEASE_TAG"]
|
|
68
|
+
run_id = os.environ["CI_RUN_ID"]
|
|
69
|
+
sha = os.environ["GITHUB_SHA"]
|
|
70
|
+
repository_id = int(os.environ["GITHUB_REPOSITORY_ID"])
|
|
71
|
+
if not re.fullmatch(r"[1-9][0-9]*", run_id):
|
|
72
|
+
raise SystemExit("CI run ID must be a positive integer")
|
|
73
|
+
for field in ("WHEEL_SHA256", "SDIST_SHA256"):
|
|
74
|
+
if not re.fullmatch(r"[0-9a-f]{64}", os.environ[field]):
|
|
75
|
+
raise SystemExit(f"{field} must be a lowercase SHA-256 digest")
|
|
76
|
+
|
|
77
|
+
with Path("pyproject.toml").open("rb") as source:
|
|
78
|
+
project = tomllib.load(source)["project"]
|
|
79
|
+
if project["name"] != "rolloutdiff" or tag != f"v{project['version']}":
|
|
80
|
+
raise SystemExit(
|
|
81
|
+
"Requested tag differs from the source package name or version"
|
|
82
|
+
)
|
|
83
|
+
if not re.fullmatch(r"v[0-9][a-zA-Z0-9.!+-]*", tag):
|
|
84
|
+
raise SystemExit("Invalid release version in tag")
|
|
85
|
+
|
|
86
|
+
if github("git/ref/heads/main")["object"]["sha"] != sha:
|
|
87
|
+
raise SystemExit("The release commit is no longer the main tip")
|
|
88
|
+
target = github(f"git/ref/tags/{tag}")["object"]
|
|
89
|
+
tag_oid = target["sha"]
|
|
90
|
+
while target["type"] == "tag":
|
|
91
|
+
target = github(f"git/tags/{target['sha']}")["object"]
|
|
92
|
+
if target["type"] != "commit" or target["sha"] != sha:
|
|
93
|
+
raise SystemExit("The release tag does not point to the selected main commit")
|
|
94
|
+
|
|
95
|
+
workflow = github("actions/workflows/ci.yml")
|
|
96
|
+
run = github(f"actions/runs/{run_id}")
|
|
97
|
+
expected_run = {
|
|
98
|
+
"id": int(run_id),
|
|
99
|
+
"workflow_id": workflow["id"],
|
|
100
|
+
"path": ".github/workflows/ci.yml",
|
|
101
|
+
"event": "push",
|
|
102
|
+
"head_branch": "main",
|
|
103
|
+
"head_sha": sha,
|
|
104
|
+
"status": "completed",
|
|
105
|
+
"conclusion": "success",
|
|
106
|
+
}
|
|
107
|
+
if any(run.get(key) != value for key, value in expected_run.items()):
|
|
108
|
+
raise SystemExit("Expected successful push CI on main for the release commit")
|
|
109
|
+
if any(
|
|
110
|
+
run[key]["id"] != repository_id for key in ("repository", "head_repository")
|
|
111
|
+
):
|
|
112
|
+
raise SystemExit("CI ran against a different repository")
|
|
113
|
+
|
|
114
|
+
attempt = run["run_attempt"]
|
|
115
|
+
name = f"rolloutdiff-{sha}-{attempt}"
|
|
116
|
+
result = github(f"actions/runs/{run_id}/artifacts?name={name}")
|
|
117
|
+
if result["total_count"] != 1 or len(result["artifacts"]) != 1:
|
|
118
|
+
raise SystemExit(f"Expected exactly one CI artifact named {name}")
|
|
119
|
+
artifact = result["artifacts"][0]
|
|
120
|
+
if artifact["name"] != name or artifact["expired"]:
|
|
121
|
+
raise SystemExit("The expected release artifact is unavailable")
|
|
122
|
+
if not re.fullmatch(r"sha256:[0-9a-f]{64}", artifact["digest"] or ""):
|
|
123
|
+
raise SystemExit("Missing GitHub artifact SHA-256 digest")
|
|
124
|
+
provenance = artifact["workflow_run"]
|
|
125
|
+
expected_source = {
|
|
126
|
+
"id": int(run_id),
|
|
127
|
+
"repository_id": repository_id,
|
|
128
|
+
"head_repository_id": repository_id,
|
|
129
|
+
"head_branch": "main",
|
|
130
|
+
"head_sha": sha,
|
|
131
|
+
}
|
|
132
|
+
if any(provenance.get(key) != value for key, value in expected_source.items()):
|
|
133
|
+
raise SystemExit("Artifact provenance differs from the selected CI run")
|
|
134
|
+
|
|
135
|
+
verify_publishing_environment()
|
|
136
|
+
with Path(os.environ["GITHUB_OUTPUT"]).open("a", encoding="utf-8") as output:
|
|
137
|
+
print(f"artifact_id={artifact['id']}", file=output)
|
|
138
|
+
print(f"ci_attempt={attempt}", file=output)
|
|
139
|
+
print(f"tag_oid={tag_oid}", file=output)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
if __name__ == "__main__":
|
|
143
|
+
main()
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import subprocess
|
|
3
|
+
import unittest
|
|
4
|
+
from contextlib import chdir
|
|
5
|
+
from copy import deepcopy
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from tempfile import TemporaryDirectory
|
|
8
|
+
from unittest.mock import patch
|
|
9
|
+
|
|
10
|
+
from release_candidate import main
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ReleaseCandidateTest(unittest.TestCase):
|
|
14
|
+
def setUp(self):
|
|
15
|
+
root = self.enterContext(TemporaryDirectory())
|
|
16
|
+
self.enterContext(chdir(root))
|
|
17
|
+
Path("pyproject.toml").write_text(
|
|
18
|
+
'[project]\nname="rolloutdiff"\nversion="0.1.0"'
|
|
19
|
+
)
|
|
20
|
+
self.sha = "1" * 40
|
|
21
|
+
self.tag_oid = "2" * 40
|
|
22
|
+
self.enterContext(
|
|
23
|
+
patch.dict(
|
|
24
|
+
os.environ,
|
|
25
|
+
RELEASE_TAG="v0.1.0",
|
|
26
|
+
CI_RUN_ID="17",
|
|
27
|
+
WHEEL_SHA256="a" * 64,
|
|
28
|
+
SDIST_SHA256="b" * 64,
|
|
29
|
+
GITHUB_SHA=self.sha,
|
|
30
|
+
GITHUB_REPOSITORY_ID="42",
|
|
31
|
+
GITHUB_OUTPUT="outputs",
|
|
32
|
+
)
|
|
33
|
+
)
|
|
34
|
+
name = f"rolloutdiff-{self.sha}-1"
|
|
35
|
+
self.artifacts_path = f"actions/runs/17/artifacts?name={name}"
|
|
36
|
+
self.api = {
|
|
37
|
+
"environments/pypi": {
|
|
38
|
+
"name": "pypi",
|
|
39
|
+
"protection_rules": [
|
|
40
|
+
{
|
|
41
|
+
"type": "required_reviewers",
|
|
42
|
+
"prevent_self_review": False,
|
|
43
|
+
"reviewers": [{"type": "User", "reviewer": {"id": 44}}],
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
"deployment_branch_policy": {
|
|
47
|
+
"protected_branches": False,
|
|
48
|
+
"custom_branch_policies": True,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
"environments/pypi/deployment-branch-policies": {
|
|
52
|
+
"total_count": 1,
|
|
53
|
+
"branch_policies": [{"name": "main", "type": "branch"}],
|
|
54
|
+
},
|
|
55
|
+
"git/ref/heads/main": {"object": {"sha": self.sha, "type": "commit"}},
|
|
56
|
+
"git/ref/tags/v0.1.0": {"object": {"sha": self.tag_oid, "type": "tag"}},
|
|
57
|
+
f"git/tags/{self.tag_oid}": {"object": {"sha": self.sha, "type": "commit"}},
|
|
58
|
+
"actions/workflows/ci.yml": {"id": 12},
|
|
59
|
+
"actions/runs/17": {
|
|
60
|
+
"id": 17,
|
|
61
|
+
"workflow_id": 12,
|
|
62
|
+
"path": ".github/workflows/ci.yml",
|
|
63
|
+
"event": "push",
|
|
64
|
+
"head_branch": "main",
|
|
65
|
+
"head_sha": self.sha,
|
|
66
|
+
"status": "completed",
|
|
67
|
+
"conclusion": "success",
|
|
68
|
+
"repository": {"id": 42},
|
|
69
|
+
"head_repository": {"id": 42},
|
|
70
|
+
"run_attempt": 1,
|
|
71
|
+
},
|
|
72
|
+
self.artifacts_path: {
|
|
73
|
+
"total_count": 1,
|
|
74
|
+
"artifacts": [
|
|
75
|
+
{
|
|
76
|
+
"id": 19,
|
|
77
|
+
"name": name,
|
|
78
|
+
"expired": False,
|
|
79
|
+
"digest": f"sha256:{'f' * 64}",
|
|
80
|
+
"workflow_run": {
|
|
81
|
+
"id": 17,
|
|
82
|
+
"repository_id": 42,
|
|
83
|
+
"head_repository_id": 42,
|
|
84
|
+
"head_branch": "main",
|
|
85
|
+
"head_sha": self.sha,
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
def verify(self, api):
|
|
93
|
+
with patch("release_candidate.github", side_effect=api.__getitem__):
|
|
94
|
+
main()
|
|
95
|
+
|
|
96
|
+
def test_annotated_and_lightweight_tags(self):
|
|
97
|
+
for tag_oid in (self.tag_oid, self.sha):
|
|
98
|
+
with self.subTest(tag=tag_oid):
|
|
99
|
+
if tag_oid == self.sha:
|
|
100
|
+
self.api["git/ref/tags/v0.1.0"] = self.api["git/ref/heads/main"]
|
|
101
|
+
self.verify(self.api)
|
|
102
|
+
outputs = Path("outputs")
|
|
103
|
+
self.assertEqual(
|
|
104
|
+
outputs.read_text().splitlines(),
|
|
105
|
+
["artifact_id=19", "ci_attempt=1", f"tag_oid={tag_oid}"],
|
|
106
|
+
)
|
|
107
|
+
outputs.unlink()
|
|
108
|
+
|
|
109
|
+
def test_wrong_ci_identity_or_outcome(self):
|
|
110
|
+
invalid_fields = {
|
|
111
|
+
"workflow_id": 13,
|
|
112
|
+
"path": ".github/workflows/other.yml",
|
|
113
|
+
"event": "pull_request",
|
|
114
|
+
"head_branch": "feature",
|
|
115
|
+
"head_sha": "3" * 40,
|
|
116
|
+
"status": "in_progress",
|
|
117
|
+
"conclusion": "failure",
|
|
118
|
+
"repository": {"id": 43},
|
|
119
|
+
"head_repository": {"id": 43},
|
|
120
|
+
}
|
|
121
|
+
for field, value in invalid_fields.items():
|
|
122
|
+
with self.subTest(field=field), self.assertRaises(SystemExit):
|
|
123
|
+
api = deepcopy(self.api)
|
|
124
|
+
api["actions/runs/17"][field] = value
|
|
125
|
+
self.verify(api)
|
|
126
|
+
self.assertFalse(Path("outputs").exists())
|
|
127
|
+
|
|
128
|
+
def test_environment_must_have_a_configured_reviewer(self):
|
|
129
|
+
for rules in (
|
|
130
|
+
None,
|
|
131
|
+
[],
|
|
132
|
+
[{"type": "wait_timer"}],
|
|
133
|
+
[{"type": "required_reviewers"}],
|
|
134
|
+
[{"type": "required_reviewers", "reviewers": []}],
|
|
135
|
+
[{"type": "required_reviewers", "reviewers": [{}]}],
|
|
136
|
+
[
|
|
137
|
+
{
|
|
138
|
+
"type": "required_reviewers",
|
|
139
|
+
"reviewers": [{"type": "User", "reviewer": {}}],
|
|
140
|
+
}
|
|
141
|
+
],
|
|
142
|
+
[
|
|
143
|
+
{
|
|
144
|
+
"type": "required_reviewers",
|
|
145
|
+
"reviewers": [{"type": "Team", "reviewer": {"id": False}}],
|
|
146
|
+
}
|
|
147
|
+
],
|
|
148
|
+
):
|
|
149
|
+
with self.subTest(rules=rules), self.assertRaises(SystemExit):
|
|
150
|
+
api = deepcopy(self.api)
|
|
151
|
+
api["environments/pypi"]["protection_rules"] = rules
|
|
152
|
+
self.verify(api)
|
|
153
|
+
self.assertFalse(Path("outputs").exists())
|
|
154
|
+
|
|
155
|
+
def test_one_team_is_a_valid_reviewer(self):
|
|
156
|
+
rules = self.api["environments/pypi"]["protection_rules"]
|
|
157
|
+
rules[0]["reviewers"] = [{"type": "Team", "reviewer": {"id": 5}}]
|
|
158
|
+
self.verify(self.api)
|
|
159
|
+
self.assertTrue(Path("outputs").exists())
|
|
160
|
+
|
|
161
|
+
def test_unavailable_environment_policy_never_emits_an_artifact(self):
|
|
162
|
+
for endpoint in (
|
|
163
|
+
"environments/pypi",
|
|
164
|
+
"environments/pypi/deployment-branch-policies",
|
|
165
|
+
):
|
|
166
|
+
|
|
167
|
+
def get(path, unavailable=endpoint):
|
|
168
|
+
if path == unavailable:
|
|
169
|
+
raise subprocess.CalledProcessError(1, ["gh", "api", path])
|
|
170
|
+
return self.api[path]
|
|
171
|
+
|
|
172
|
+
with (
|
|
173
|
+
self.subTest(endpoint=endpoint),
|
|
174
|
+
patch("release_candidate.github", side_effect=get),
|
|
175
|
+
self.assertRaises(subprocess.CalledProcessError),
|
|
176
|
+
):
|
|
177
|
+
main()
|
|
178
|
+
self.assertFalse(Path("outputs").exists())
|
|
179
|
+
|
|
180
|
+
def test_missing_environment_or_unrestricted_deployments(self):
|
|
181
|
+
for replacement in (
|
|
182
|
+
{},
|
|
183
|
+
{"name": "production"},
|
|
184
|
+
{"deployment_branch_policy": None},
|
|
185
|
+
{
|
|
186
|
+
"deployment_branch_policy": {
|
|
187
|
+
"protected_branches": True,
|
|
188
|
+
"custom_branch_policies": False,
|
|
189
|
+
}
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
"deployment_branch_policy": {
|
|
193
|
+
"protected_branches": False,
|
|
194
|
+
"custom_branch_policies": False,
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
"deployment_branch_policy": {
|
|
199
|
+
"protected_branches": 0,
|
|
200
|
+
"custom_branch_policies": 1,
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
):
|
|
204
|
+
with self.subTest(replacement=replacement), self.assertRaises(SystemExit):
|
|
205
|
+
api = deepcopy(self.api)
|
|
206
|
+
if replacement:
|
|
207
|
+
api["environments/pypi"].update(replacement)
|
|
208
|
+
else:
|
|
209
|
+
api["environments/pypi"] = {}
|
|
210
|
+
self.verify(api)
|
|
211
|
+
self.assertFalse(Path("outputs").exists())
|
|
212
|
+
|
|
213
|
+
def test_exact_main_branch_is_the_only_deployment_rule(self):
|
|
214
|
+
main_branch = {"name": "main", "type": "branch"}
|
|
215
|
+
for count, policies in (
|
|
216
|
+
(0, []),
|
|
217
|
+
(1, []),
|
|
218
|
+
(2, [main_branch]),
|
|
219
|
+
(1, [main_branch, {"name": "v*", "type": "tag"}]),
|
|
220
|
+
(2, [main_branch, {"name": "release", "type": "branch"}]),
|
|
221
|
+
(1, [{"name": "main", "type": "tag"}]),
|
|
222
|
+
(1, [{"name": "main"}]),
|
|
223
|
+
(1, [{"name": "*", "type": "branch"}]),
|
|
224
|
+
(1, [{"name": "main*", "type": "branch"}]),
|
|
225
|
+
(1, [{"name": "release", "type": "branch"}]),
|
|
226
|
+
(True, [main_branch]),
|
|
227
|
+
):
|
|
228
|
+
with (
|
|
229
|
+
self.subTest(count=count, policies=policies),
|
|
230
|
+
self.assertRaises(SystemExit),
|
|
231
|
+
):
|
|
232
|
+
api = deepcopy(self.api)
|
|
233
|
+
api["environments/pypi/deployment-branch-policies"] = {
|
|
234
|
+
"total_count": count,
|
|
235
|
+
"branch_policies": policies,
|
|
236
|
+
}
|
|
237
|
+
self.verify(api)
|
|
238
|
+
self.assertFalse(Path("outputs").exists())
|
|
239
|
+
|
|
240
|
+
def test_main_or_tag_points_to_another_commit(self):
|
|
241
|
+
for endpoint in ("git/ref/heads/main", f"git/tags/{self.tag_oid}"):
|
|
242
|
+
with self.subTest(endpoint=endpoint), self.assertRaises(SystemExit):
|
|
243
|
+
api = deepcopy(self.api)
|
|
244
|
+
api[endpoint]["object"]["sha"] = "3" * 40
|
|
245
|
+
self.verify(api)
|
|
246
|
+
|
|
247
|
+
def test_missing_duplicate_expired_or_unverified_artifact(self):
|
|
248
|
+
for count in (0, 2):
|
|
249
|
+
with self.subTest(count=count), self.assertRaises(SystemExit):
|
|
250
|
+
api = deepcopy(self.api)
|
|
251
|
+
result = api[self.artifacts_path]
|
|
252
|
+
result.update(total_count=count, artifacts=result["artifacts"] * count)
|
|
253
|
+
self.verify(api)
|
|
254
|
+
for field, value in {
|
|
255
|
+
"expired": True,
|
|
256
|
+
"name": "old-attempt",
|
|
257
|
+
"digest": "",
|
|
258
|
+
}.items():
|
|
259
|
+
with self.subTest(field=field), self.assertRaises(SystemExit):
|
|
260
|
+
api = deepcopy(self.api)
|
|
261
|
+
api[self.artifacts_path]["artifacts"][0][field] = value
|
|
262
|
+
self.verify(api)
|
|
263
|
+
for field in (
|
|
264
|
+
"id",
|
|
265
|
+
"repository_id",
|
|
266
|
+
"head_repository_id",
|
|
267
|
+
"head_branch",
|
|
268
|
+
"head_sha",
|
|
269
|
+
):
|
|
270
|
+
with self.subTest(field=field), self.assertRaises(SystemExit):
|
|
271
|
+
api = deepcopy(self.api)
|
|
272
|
+
api[self.artifacts_path]["artifacts"][0]["workflow_run"][field] = (
|
|
273
|
+
"other"
|
|
274
|
+
)
|
|
275
|
+
self.verify(api)
|
|
276
|
+
self.assertFalse(Path("outputs").exists())
|
|
277
|
+
|
|
278
|
+
def test_different_version_or_malformed_approval(self):
|
|
279
|
+
for field, value in {
|
|
280
|
+
"RELEASE_TAG": "v1.0.0",
|
|
281
|
+
"CI_RUN_ID": "-1",
|
|
282
|
+
"WHEEL_SHA256": "a" * 63,
|
|
283
|
+
"SDIST_SHA256": "x" * 64,
|
|
284
|
+
}.items():
|
|
285
|
+
with (
|
|
286
|
+
self.subTest(field=field),
|
|
287
|
+
patch.dict(os.environ, {field: value}),
|
|
288
|
+
self.assertRaises(SystemExit),
|
|
289
|
+
):
|
|
290
|
+
self.verify(self.api)
|