| 1 | """Tests for the pre-publish gate's mechanical checks."""
|
| 2 |
|
| 3 | from __future__ import annotations
|
| 4 |
|
| 5 | import contextlib
|
| 6 | import io
|
| 7 | import json
|
| 8 | import sys
|
| 9 | import tempfile
|
| 10 | import unittest
|
| 11 | from pathlib import Path
|
| 12 |
|
| 13 | sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "scripts"))
|
| 14 |
|
| 15 | import publish_gate
|
| 16 |
|
| 17 |
|
| 18 | OAK_SOURCE = {"source": {"oak_hash": "abc123", "oak_status": ""}, "binary_sha256": "b" * 64}
|
| 19 | ENV_ISOLATION = {"env_isolation_version": "1"}
|
| 20 |
|
| 21 |
|
| 22 | def with_conformance(directory: Path, path: Path) -> list[str]:
|
| 23 | """Inputs plus passing conformance rows (required whenever Oak rows are published)."""
|
| 24 | try:
|
| 25 | from tests.test_conformance_gate import healthy_rows
|
| 26 | except ImportError: # discover -s tests
|
| 27 | from test_conformance_gate import healthy_rows
|
| 28 | from oakbench import conformance_gate
|
| 29 | rows = healthy_rows(conformance_gate.load_expected()) # binary_sha256 "b"*64, as OAK_SOURCE
|
| 30 | return [str(path), str(write_rows(directory, "conformance.jsonl", rows))]
|
| 31 |
|
| 32 |
|
| 33 | def write_rows(directory: Path, name: str, rows: list[dict]) -> Path:
|
| 34 | path = directory / name
|
| 35 | path.write_text("\n".join(json.dumps(row) for row in rows) + "\n")
|
| 36 | return path
|
| 37 |
|
| 38 |
|
| 39 | class GateTest(unittest.TestCase):
|
| 40 | def test_mixed_transport_operation_fails(self) -> None:
|
| 41 | with tempfile.TemporaryDirectory() as tmp:
|
| 42 | path = write_rows(
|
| 43 | Path(tmp),
|
| 44 | "rows.jsonl",
|
| 45 | [
|
| 46 | {"subject": "oak", "operation": "x.push", "returncode": 0, "remote_transport": "network", **OAK_SOURCE},
|
| 47 | {"subject": "oak", "operation": "x.push", "returncode": 0, "remote_transport": "local_file", **OAK_SOURCE},
|
| 48 | ],
|
| 49 | )
|
| 50 | self.assertEqual(publish_gate.main([str(path)]), 1)
|
| 51 |
|
| 52 | def test_side_by_side_subjects_may_use_different_transports(self) -> None:
|
| 53 | with tempfile.TemporaryDirectory() as tmp:
|
| 54 | path = write_rows(
|
| 55 | Path(tmp),
|
| 56 | "rows.jsonl",
|
| 57 | [
|
| 58 | {"subject": "oak", "operation": "x.acquire", "returncode": 0, "remote_transport": "network", **OAK_SOURCE},
|
| 59 | {"subject": "git", "operation": "x.acquire", "returncode": 0, "remote_transport": "local_file"},
|
| 60 | ],
|
| 61 | )
|
| 62 | self.assertEqual(publish_gate.main(with_conformance(Path(tmp), path)), 0)
|
| 63 |
|
| 64 | def test_null_returncode_row_is_treated_as_failure_not_a_crash(self) -> None:
|
| 65 | with tempfile.TemporaryDirectory() as tmp:
|
| 66 | path = write_rows(
|
| 67 | Path(tmp),
|
| 68 | "rows.jsonl",
|
| 69 | [
|
| 70 | # Emitters may record returncode: null (unmeasured); the
|
| 71 | # gate must treat it as a failure, never raise TypeError.
|
| 72 | {"subject": "git", "operation": "status.clean", "returncode": None},
|
| 73 | {"subject": "git", "operation": "x.push", "returncode": 0, "remote_transport": "local_file"},
|
| 74 | ],
|
| 75 | )
|
| 76 | with contextlib.redirect_stdout(io.StringIO()):
|
| 77 | code = publish_gate.main([str(path)])
|
| 78 | self.assertEqual(code, 0)
|
| 79 |
|
| 80 | def test_null_returncode_public_core_row_counts_as_failed_operation(self) -> None:
|
| 81 | with tempfile.TemporaryDirectory() as tmp:
|
| 82 | path = write_rows(
|
| 83 | Path(tmp),
|
| 84 | "rows.jsonl",
|
| 85 | [
|
| 86 | {
|
| 87 | "profile": "standard",
|
| 88 | "subject": "git",
|
| 89 | "scenario": "tiny_text_100",
|
| 90 | "operation": "status.clean",
|
| 91 | "run": 0,
|
| 92 | "returncode": None,
|
| 93 | "randomized_subject_order": True,
|
| 94 | "subject_order": ["git"],
|
| 95 | }
|
| 96 | ],
|
| 97 | )
|
| 98 | stdout = io.StringIO()
|
| 99 | with contextlib.redirect_stdout(stdout):
|
| 100 | code = publish_gate.main([str(path)])
|
| 101 | self.assertEqual(code, 1)
|
| 102 | self.assertIn("failed operations", stdout.getvalue())
|
| 103 |
|
| 104 | def test_remote_row_without_transport_fails(self) -> None:
|
| 105 | with tempfile.TemporaryDirectory() as tmp:
|
| 106 | path = write_rows(
|
| 107 | Path(tmp),
|
| 108 | "rows.jsonl",
|
| 109 | [
|
| 110 | {
|
| 111 | "subject": "oak",
|
| 112 | "operation": "x.push",
|
| 113 | "returncode": 0,
|
| 114 | "remote_repo": "oak/bench-tmp",
|
| 115 | "remote_server": "oak.space",
|
| 116 | **OAK_SOURCE,
|
| 117 | }
|
| 118 | ],
|
| 119 | )
|
| 120 | self.assertEqual(publish_gate.main([str(path)]), 1)
|
| 121 |
|
| 122 | def test_dirty_oak_source_fails(self) -> None:
|
| 123 | with tempfile.TemporaryDirectory() as tmp:
|
| 124 | path = write_rows(
|
| 125 | Path(tmp),
|
| 126 | "rows.jsonl",
|
| 127 | [
|
| 128 | {
|
| 129 | "subject": "oak_main",
|
| 130 | "subject_kind": "oak",
|
| 131 | "operation": "status.clean",
|
| 132 | "returncode": 0,
|
| 133 | "source": {"oak_hash": "abc123", "oak_status": "M cli/src/main.rs"},
|
| 134 | }
|
| 135 | ],
|
| 136 | )
|
| 137 | self.assertEqual(publish_gate.main([str(path)]), 1)
|
| 138 |
|
| 139 | def test_missing_oak_source_hash_fails(self) -> None:
|
| 140 | with tempfile.TemporaryDirectory() as tmp:
|
| 141 | path = write_rows(
|
| 142 | Path(tmp),
|
| 143 | "rows.jsonl",
|
| 144 | [
|
| 145 | {
|
| 146 | "subject": "oak_main",
|
| 147 | "subject_kind": "oak",
|
| 148 | "operation": "status.clean",
|
| 149 | "returncode": 0,
|
| 150 | }
|
| 151 | ],
|
| 152 | )
|
| 153 | self.assertEqual(publish_gate.main([str(path)]), 1)
|
| 154 |
|
| 155 | def test_core_public_cells_require_randomized_n30(self) -> None:
|
| 156 | with tempfile.TemporaryDirectory() as tmp:
|
| 157 | rows = []
|
| 158 | for run in range(29):
|
| 159 | for subject in ("git", "git_untracked_cache", "git_fsmonitor", "oak_main"):
|
| 160 | rows.append(
|
| 161 | {
|
| 162 | "profile": "standard",
|
| 163 | "subject": subject,
|
| 164 | "subject_kind": "oak" if subject == "oak_main" else "git",
|
| 165 | "scenario": "tiny_text_100",
|
| 166 | "operation": "status.clean",
|
| 167 | "run": run,
|
| 168 | "returncode": 0,
|
| 169 | "randomized_subject_order": True,
|
| 170 | "subject_order": ["git", "git_untracked_cache", "git_fsmonitor", "oak_main"],
|
| 171 | **(OAK_SOURCE if subject == "oak_main" else {}),
|
| 172 | }
|
| 173 | )
|
| 174 | path = write_rows(Path(tmp), "rows.jsonl", rows)
|
| 175 | self.assertEqual(publish_gate.main([str(path)]), 1)
|
| 176 |
|
| 177 | def test_core_public_cells_pass_with_randomized_n30(self) -> None:
|
| 178 | with tempfile.TemporaryDirectory() as tmp:
|
| 179 | rows = []
|
| 180 | for run in range(30):
|
| 181 | for subject in ("git", "git_untracked_cache", "git_fsmonitor", "oak_main"):
|
| 182 | rows.append(
|
| 183 | {
|
| 184 | "profile": "standard",
|
| 185 | "subject": subject,
|
| 186 | "subject_kind": "oak" if subject == "oak_main" else "git",
|
| 187 | "scenario": "tiny_text_100",
|
| 188 | "operation": "status.clean",
|
| 189 | "run": run,
|
| 190 | "returncode": 0,
|
| 191 | "randomized_subject_order": True,
|
| 192 | "subject_order": ["git", "git_untracked_cache", "git_fsmonitor", "oak_main"],
|
| 193 | **ENV_ISOLATION,
|
| 194 | **(OAK_SOURCE if subject == "oak_main" else {}),
|
| 195 | }
|
| 196 | )
|
| 197 | path = write_rows(Path(tmp), "rows.jsonl", rows)
|
| 198 | self.assertEqual(publish_gate.main(with_conformance(Path(tmp), path)), 0)
|
| 199 |
|
| 200 | def test_public_core_rows_reject_weak_content_trust_sources(self) -> None:
|
| 201 | weak_sources = [
|
| 202 | ("mixed_payload_sources", ["git_head_payload_sha256", "git_lfs_worktree_payload_sha256"]),
|
| 203 | ("worktree_payload_sha256", ["worktree_payload_sha256"]),
|
| 204 | ("git_lfs_worktree_payload_sha256", ["git_lfs_worktree_payload_sha256"]),
|
| 205 | ]
|
| 206 | for source, sources in weak_sources:
|
| 207 | with self.subTest(source=source):
|
| 208 | with tempfile.TemporaryDirectory() as tmp:
|
| 209 | rows = []
|
| 210 | for run in range(30):
|
| 211 | for subject in ("git", "git_untracked_cache", "git_fsmonitor", "oak_main"):
|
| 212 | content_fields = (
|
| 213 | {
|
| 214 | "content_integrity_check_passed": True,
|
| 215 | "content_integrity_source": source,
|
| 216 | "content_integrity_sources": sources,
|
| 217 | "content_integrity_public_trust_passed": False,
|
| 218 | }
|
| 219 | if subject == "oak_main"
|
| 220 | else {}
|
| 221 | )
|
| 222 | rows.append(
|
| 223 | {
|
| 224 | "profile": "standard",
|
| 225 | "subject": subject,
|
| 226 | "subject_kind": "oak" if subject == "oak_main" else "git",
|
| 227 | "scenario": "tiny_text_100",
|
| 228 | "operation": "status.clean",
|
| 229 | "run": run,
|
| 230 | "returncode": 0,
|
| 231 | "randomized_subject_order": True,
|
| 232 | "subject_order": ["git", "git_untracked_cache", "git_fsmonitor", "oak_main"],
|
| 233 | **ENV_ISOLATION,
|
| 234 | **content_fields,
|
| 235 | **(OAK_SOURCE if subject == "oak_main" else {}),
|
| 236 | }
|
| 237 | )
|
| 238 | path = write_rows(Path(tmp), "rows.jsonl", rows)
|
| 239 | stdout = io.StringIO()
|
| 240 | with contextlib.redirect_stdout(stdout):
|
| 241 | code = publish_gate.main([str(path)])
|
| 242 | self.assertEqual(code, 1)
|
| 243 | self.assertIn("content-trust", stdout.getvalue())
|
| 244 |
|
| 245 | def test_public_core_rows_accept_strong_content_trust_source(self) -> None:
|
| 246 | with tempfile.TemporaryDirectory() as tmp:
|
| 247 | rows = []
|
| 248 | for run in range(30):
|
| 249 | for subject in ("git", "git_untracked_cache", "git_fsmonitor", "oak_main"):
|
| 250 | content_fields = (
|
| 251 | {
|
| 252 | "content_integrity_check_passed": True,
|
| 253 | "content_integrity_source": "git_head_payload_sha256",
|
| 254 | "content_integrity_sources": ["git_head_payload_sha256"],
|
| 255 | "content_integrity_public_trust_passed": True,
|
| 256 | }
|
| 257 | if subject == "oak_main"
|
| 258 | else {}
|
| 259 | )
|
| 260 | rows.append(
|
| 261 | {
|
| 262 | "profile": "standard",
|
| 263 | "subject": subject,
|
| 264 | "subject_kind": "oak" if subject == "oak_main" else "git",
|
| 265 | "scenario": "tiny_text_100",
|
| 266 | "operation": "status.clean",
|
| 267 | "run": run,
|
| 268 | "returncode": 0,
|
| 269 | "randomized_subject_order": True,
|
| 270 | "subject_order": ["git", "git_untracked_cache", "git_fsmonitor", "oak_main"],
|
| 271 | **ENV_ISOLATION,
|
| 272 | **content_fields,
|
| 273 | **(OAK_SOURCE if subject == "oak_main" else {}),
|
| 274 | }
|
| 275 | )
|
| 276 | path = write_rows(Path(tmp), "rows.jsonl", rows)
|
| 277 | self.assertEqual(publish_gate.main(with_conformance(Path(tmp), path)), 0)
|
| 278 |
|
| 279 | def test_public_core_rows_require_env_isolation_version(self) -> None:
|
| 280 | with tempfile.TemporaryDirectory() as tmp:
|
| 281 | rows = []
|
| 282 | for run in range(30):
|
| 283 | for subject in ("git", "git_untracked_cache", "git_fsmonitor", "oak_main"):
|
| 284 | rows.append(
|
| 285 | {
|
| 286 | "profile": "standard",
|
| 287 | "subject": subject,
|
| 288 | "subject_kind": "oak" if subject == "oak_main" else "git",
|
| 289 | "scenario": "tiny_text_100",
|
| 290 | "operation": "status.clean",
|
| 291 | "run": run,
|
| 292 | "returncode": 0,
|
| 293 | "randomized_subject_order": True,
|
| 294 | "subject_order": ["git", "git_untracked_cache", "git_fsmonitor", "oak_main"],
|
| 295 | **(OAK_SOURCE if subject == "oak_main" else {}),
|
| 296 | }
|
| 297 | )
|
| 298 | path = write_rows(Path(tmp), "rows.jsonl", rows)
|
| 299 | stdout = io.StringIO()
|
| 300 | with contextlib.redirect_stdout(stdout):
|
| 301 | code = publish_gate.main([str(path)])
|
| 302 | self.assertEqual(code, 1)
|
| 303 | self.assertIn("env-isolation", stdout.getvalue())
|
| 304 |
|
| 305 | def test_public_core_rows_reject_mixed_env_isolation_versions(self) -> None:
|
| 306 | with tempfile.TemporaryDirectory() as tmp:
|
| 307 | rows = []
|
| 308 | for run in range(30):
|
| 309 | for subject in ("git", "git_untracked_cache", "git_fsmonitor", "oak_main"):
|
| 310 | rows.append(
|
| 311 | {
|
| 312 | "profile": "standard",
|
| 313 | "subject": subject,
|
| 314 | "subject_kind": "oak" if subject == "oak_main" else "git",
|
| 315 | "scenario": "tiny_text_100",
|
| 316 | "operation": "status.clean",
|
| 317 | "run": run,
|
| 318 | "returncode": 0,
|
| 319 | "randomized_subject_order": True,
|
| 320 | "subject_order": ["git", "git_untracked_cache", "git_fsmonitor", "oak_main"],
|
| 321 | "env_isolation_version": "2" if subject == "oak_main" else "1",
|
| 322 | **(OAK_SOURCE if subject == "oak_main" else {}),
|
| 323 | }
|
| 324 | )
|
| 325 | path = write_rows(Path(tmp), "rows.jsonl", rows)
|
| 326 | stdout = io.StringIO()
|
| 327 | with contextlib.redirect_stdout(stdout):
|
| 328 | code = publish_gate.main([str(path)])
|
| 329 | self.assertEqual(code, 1)
|
| 330 | self.assertIn("mix env_isolation_version", stdout.getvalue())
|
| 331 |
|
| 332 | def test_public_core_failed_operation_fails_gate(self) -> None:
|
| 333 | with tempfile.TemporaryDirectory() as tmp:
|
| 334 | rows = []
|
| 335 | for run in range(30):
|
| 336 | for subject in ("git", "git_untracked_cache", "git_fsmonitor", "oak_main"):
|
| 337 | rows.append(
|
| 338 | {
|
| 339 | "profile": "standard",
|
| 340 | "subject": subject,
|
| 341 | "subject_kind": "oak" if subject == "oak_main" else "git",
|
| 342 | "scenario": "tiny_text_100",
|
| 343 | "operation": "status.clean",
|
| 344 | "run": run,
|
| 345 | "returncode": 1 if subject == "oak_main" and run == 0 else 0,
|
| 346 | "randomized_subject_order": True,
|
| 347 | "subject_order": ["git", "git_untracked_cache", "git_fsmonitor", "oak_main"],
|
| 348 | **(OAK_SOURCE if subject == "oak_main" else {}),
|
| 349 | }
|
| 350 | )
|
| 351 | path = write_rows(Path(tmp), "rows.jsonl", rows)
|
| 352 | self.assertEqual(publish_gate.main([str(path)]), 1)
|
| 353 |
|
| 354 | def test_public_core_zero_success_group_fails_gate(self) -> None:
|
| 355 | with tempfile.TemporaryDirectory() as tmp:
|
| 356 | rows = []
|
| 357 | for run in range(30):
|
| 358 | for subject in ("git", "git_untracked_cache", "git_fsmonitor", "oak_main"):
|
| 359 | rows.append(
|
| 360 | {
|
| 361 | "profile": "standard",
|
| 362 | "subject": subject,
|
| 363 | "subject_kind": "oak" if subject == "oak_main" else "git",
|
| 364 | "scenario": "tiny_text_100",
|
| 365 | "operation": "status.clean",
|
| 366 | "run": run,
|
| 367 | "returncode": 1 if subject == "oak_main" else 0,
|
| 368 | "randomized_subject_order": True,
|
| 369 | "subject_order": ["git", "git_untracked_cache", "git_fsmonitor", "oak_main"],
|
| 370 | **(OAK_SOURCE if subject == "oak_main" else {}),
|
| 371 | }
|
| 372 | )
|
| 373 | path = write_rows(Path(tmp), "rows.jsonl", rows)
|
| 374 | self.assertEqual(publish_gate.main([str(path)]), 1)
|
| 375 |
|
| 376 | def test_tuned_git_setup_failure_fails_gate(self) -> None:
|
| 377 | with tempfile.TemporaryDirectory() as tmp:
|
| 378 | rows = []
|
| 379 | for run in range(30):
|
| 380 | for subject in ("git", "git_untracked_cache", "git_fsmonitor", "oak_main"):
|
| 381 | rows.append(
|
| 382 | {
|
| 383 | "profile": "standard",
|
| 384 | "subject": subject,
|
| 385 | "subject_kind": "oak" if subject == "oak_main" else "git",
|
| 386 | "scenario": "tiny_text_100",
|
| 387 | "operation": "status.clean",
|
| 388 | "run": run,
|
| 389 | "returncode": 0,
|
| 390 | "randomized_subject_order": True,
|
| 391 | "subject_order": ["git", "git_untracked_cache", "git_fsmonitor", "oak_main"],
|
| 392 | **(OAK_SOURCE if subject == "oak_main" else {}),
|
| 393 | }
|
| 394 | )
|
| 395 | rows.append(
|
| 396 | {
|
| 397 | "profile": "standard",
|
| 398 | "subject": "git_fsmonitor",
|
| 399 | "subject_kind": "git",
|
| 400 | "scenario": "tiny_text_100",
|
| 401 | "operation": "mode.setup.fsmonitor",
|
| 402 | "run": 0,
|
| 403 | "returncode": 1,
|
| 404 | "randomized_subject_order": True,
|
| 405 | "subject_order": ["git", "git_untracked_cache", "git_fsmonitor", "oak_main"],
|
| 406 | }
|
| 407 | )
|
| 408 | path = write_rows(Path(tmp), "rows.jsonl", rows)
|
| 409 | self.assertEqual(publish_gate.main([str(path)]), 1)
|
| 410 |
|
| 411 | def test_tuned_lfs_setup_failure_fails_gate(self) -> None:
|
| 412 | # Mirrors the fsmonitor case: a nonzero mode.setup.lfs_* row means the
|
| 413 | # git_lfs subject silently measured stock git, so nothing publishes.
|
| 414 | for setup_operation in ("mode.setup.lfs_install", "mode.setup.lfs_track"):
|
| 415 | with tempfile.TemporaryDirectory() as tmp:
|
| 416 | rows = []
|
| 417 | for run in range(30):
|
| 418 | for subject in ("git", "git_untracked_cache", "git_fsmonitor", "oak_main"):
|
| 419 | rows.append(
|
| 420 | {
|
| 421 | "profile": "standard",
|
| 422 | "subject": subject,
|
| 423 | "subject_kind": "oak" if subject == "oak_main" else "git",
|
| 424 | "scenario": "tiny_text_100",
|
| 425 | "operation": "status.clean",
|
| 426 | "run": run,
|
| 427 | "returncode": 0,
|
| 428 | "randomized_subject_order": True,
|
| 429 | "subject_order": ["git", "git_untracked_cache", "git_fsmonitor", "oak_main"],
|
| 430 | **(OAK_SOURCE if subject == "oak_main" else {}),
|
| 431 | }
|
| 432 | )
|
| 433 | rows.append(
|
| 434 | {
|
| 435 | "profile": "standard",
|
| 436 | "subject": "git_lfs",
|
| 437 | "subject_kind": "git",
|
| 438 | "scenario": "single_large_binary",
|
| 439 | "operation": setup_operation,
|
| 440 | "run": 0,
|
| 441 | "returncode": 1,
|
| 442 | "randomized_subject_order": True,
|
| 443 | "subject_order": ["git", "git_lfs"],
|
| 444 | }
|
| 445 | )
|
| 446 | path = write_rows(Path(tmp), "rows.jsonl", rows)
|
| 447 | with contextlib.redirect_stdout(io.StringIO()):
|
| 448 | code = publish_gate.main([str(path)])
|
| 449 | self.assertEqual(code, 1, setup_operation)
|
| 450 |
|
| 451 | def test_missing_git_lfs_rows_do_not_fail_gate(self) -> None:
|
| 452 | # git_lfs only applies to binary-fixture scenarios on hosts with
|
| 453 | # git-lfs installed; absence is an honest gap, not a gate failure.
|
| 454 | self.assertNotIn("git_lfs", publish_gate.REQUIRED_TUNED_GIT_SUBJECTS)
|
| 455 | self.assertIn("git_lfs", publish_gate.TUNED_GIT_SUBJECTS)
|
| 456 |
|
| 457 | def test_core_public_cells_require_randomization_metadata(self) -> None:
|
| 458 | with tempfile.TemporaryDirectory() as tmp:
|
| 459 | rows = []
|
| 460 | for run in range(30):
|
| 461 | for subject in ("git", "git_untracked_cache", "git_fsmonitor", "oak_main"):
|
| 462 | rows.append(
|
| 463 | {
|
| 464 | "profile": "standard",
|
| 465 | "subject": subject,
|
| 466 | "subject_kind": "oak" if subject == "oak_main" else "git",
|
| 467 | "scenario": "tiny_text_100",
|
| 468 | "operation": "status.clean",
|
| 469 | "run": run,
|
| 470 | "returncode": 0,
|
| 471 | "subject_order": ["git", "git_untracked_cache", "git_fsmonitor", "oak_main"],
|
| 472 | **(OAK_SOURCE if subject == "oak_main" else {}),
|
| 473 | }
|
| 474 | )
|
| 475 | path = write_rows(Path(tmp), "rows.jsonl", rows)
|
| 476 | self.assertEqual(publish_gate.main([str(path)]), 1)
|
| 477 |
|
| 478 | def test_public_core_rows_randomized_false_fails(self) -> None:
|
| 479 | with tempfile.TemporaryDirectory() as tmp:
|
| 480 | rows = []
|
| 481 | for run in range(30):
|
| 482 | for subject in ("git", "git_untracked_cache", "git_fsmonitor", "oak_main"):
|
| 483 | rows.append(
|
| 484 | {
|
| 485 | "profile": "standard",
|
| 486 | "subject": subject,
|
| 487 | "subject_kind": "oak" if subject == "oak_main" else "git",
|
| 488 | "scenario": "tiny_text_100",
|
| 489 | "operation": "status.clean",
|
| 490 | "run": run,
|
| 491 | "returncode": 0,
|
| 492 | "randomized_subject_order": False,
|
| 493 | "subject_order": ["git", "git_untracked_cache", "git_fsmonitor", "oak_main"],
|
| 494 | **(OAK_SOURCE if subject == "oak_main" else {}),
|
| 495 | }
|
| 496 | )
|
| 497 | path = write_rows(Path(tmp), "rows.jsonl", rows)
|
| 498 | self.assertEqual(publish_gate.main([str(path)]), 1)
|
| 499 |
|
| 500 | def test_randomized_core_public_cells_require_subject_order(self) -> None:
|
| 501 | with tempfile.TemporaryDirectory() as tmp:
|
| 502 | rows = []
|
| 503 | for run in range(30):
|
| 504 | for subject in ("git", "git_untracked_cache", "git_fsmonitor", "oak_main"):
|
| 505 | rows.append(
|
| 506 | {
|
| 507 | "profile": "standard",
|
| 508 | "subject": subject,
|
| 509 | "subject_kind": "oak" if subject == "oak_main" else "git",
|
| 510 | "scenario": "tiny_text_100",
|
| 511 | "operation": "status.clean",
|
| 512 | "run": run,
|
| 513 | "returncode": 0,
|
| 514 | "randomized_subject_order": True,
|
| 515 | **(OAK_SOURCE if subject == "oak_main" else {}),
|
| 516 | }
|
| 517 | )
|
| 518 | path = write_rows(Path(tmp), "rows.jsonl", rows)
|
| 519 | self.assertEqual(publish_gate.main([str(path)]), 1)
|
| 520 |
|
| 521 | def test_skip_without_reason_fails(self) -> None:
|
| 522 | with tempfile.TemporaryDirectory() as tmp:
|
| 523 | path = write_rows(
|
| 524 | Path(tmp), "rows.jsonl", [{"operation": "x", "returncode": 77}]
|
| 525 | )
|
| 526 | self.assertEqual(publish_gate.main([str(path)]), 1)
|
| 527 |
|
| 528 | def test_clean_rows_pass(self) -> None:
|
| 529 | with tempfile.TemporaryDirectory() as tmp:
|
| 530 | path = write_rows(
|
| 531 | Path(tmp),
|
| 532 | "rows.jsonl",
|
| 533 | [
|
| 534 | {"operation": "x.push", "returncode": 0, "remote_transport": "network"},
|
| 535 | {"operation": "x", "returncode": 77, "skip_reason": "set FOO"},
|
| 536 | ],
|
| 537 | )
|
| 538 | self.assertEqual(publish_gate.main([str(path)]), 0)
|
| 539 |
|
| 540 | def test_fake_provider_rows_are_never_publishable(self) -> None:
|
| 541 | with tempfile.TemporaryDirectory() as tmp:
|
| 542 | path = write_rows(
|
| 543 | Path(tmp),
|
| 544 | "rows.jsonl",
|
| 545 | [
|
| 546 | {
|
| 547 | "profile": "platform",
|
| 548 | "benchmark_track": "platform-hosted",
|
| 549 | "scenario": "branch_triage_n4",
|
| 550 | "operation": "triage.total",
|
| 551 | "platform": "github",
|
| 552 | "driver": "fake-provider",
|
| 553 | "branch_triage_provider": "fake",
|
| 554 | "returncode": 0,
|
| 555 | }
|
| 556 | ],
|
| 557 | )
|
| 558 | stdout = io.StringIO()
|
| 559 | with contextlib.redirect_stdout(stdout):
|
| 560 | code = publish_gate.main([str(path)])
|
| 561 | self.assertEqual(code, 1)
|
| 562 | self.assertIn("fake-provider", stdout.getvalue())
|
| 563 |
|
| 564 | def test_mixed_instruction_levels_in_one_file_fail(self) -> None:
|
| 565 | with tempfile.TemporaryDirectory() as tmp:
|
| 566 | path = write_rows(
|
| 567 | Path(tmp),
|
| 568 | "rows.jsonl",
|
| 569 | [
|
| 570 | {"operation": "agent.workflow", "returncode": 0, "instruction_level": "zero-shot"},
|
| 571 | {"operation": "agent.workflow", "returncode": 0, "instruction_level": "cheat-sheet"},
|
| 572 | ],
|
| 573 | )
|
| 574 | self.assertEqual(publish_gate.main([str(path)]), 1)
|
| 575 |
|
| 576 | def test_mixed_benchmark_tracks_in_one_file_fail(self) -> None:
|
| 577 | with tempfile.TemporaryDirectory() as tmp:
|
| 578 | path = write_rows(
|
| 579 | Path(tmp),
|
| 580 | "rows.jsonl",
|
| 581 | [
|
| 582 | {"operation": "agent.workflow", "returncode": 0, "benchmark_track": "agent-default"},
|
| 583 | {"operation": "agent.workflow", "returncode": 0, "benchmark_track": "core-equivalent"},
|
| 584 | ],
|
| 585 | )
|
| 586 | self.assertEqual(publish_gate.main([str(path)]), 1)
|
| 587 |
|
| 588 |
|
| 589 | if __name__ == "__main__":
|
| 590 | unittest.main()
|