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
35 changes: 35 additions & 0 deletions scripts/tests/test_pr_automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,41 @@ def test_bulk_validation_covers_every_generated_metadata_family(tmp_path, monkey
check[0] for check in validation.BULK_GENERATOR_CHECKS]


def test_diff_whitespace_allows_generated_eof_blank_line_but_rejects_trailing_space(tmp_path):
repo = tmp_path / "repo"
repo.mkdir()

def git(*args):
return subprocess.run(
["git", "-C", str(repo), *args],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
)

git("init")
git("config", "user.name", "Test")
git("config", "user.email", "test@example.invalid")
(repo / "base.txt").write_text("base\n", encoding="utf-8")
git("add", "base.txt")
git("commit", "-m", "base")
base = git("rev-parse", "HEAD").stdout.strip()

(repo / "generated.ttl").write_bytes(b"generated .\n\n")
git("add", "generated.ttl")
git("commit", "-m", "generated")
generated_head = git("rev-parse", "HEAD").stdout.strip()
validation.check_diff_whitespace(repo, base, generated_head)

(repo / "invalid.txt").write_bytes(b"trailing space \n")
git("add", "invalid.txt")
git("commit", "-m", "invalid")
invalid_head = git("rev-parse", "HEAD").stdout.strip()
with pytest.raises(subprocess.CalledProcessError):
validation.check_diff_whitespace(repo, base, invalid_head)


def test_source_only_model_real_generation_and_final_state_validation(tmp_path):
from test_generate_png_metadata import minimal_png
from test_process_new_model_submission import make_model, make_repo
Expand Down
15 changes: 14 additions & 1 deletion scripts/validate_pr_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@
"--allow-missing-license", "--check", "--quiet"),
)

# Generated Turtle files in this repository intentionally end with a second
# newline. Keep the checks for trailing spaces and space-before-tab, but do
# not reject that generated-file formatting.
DIFF_CHECK_WHITESPACE = "blank-at-eol,space-before-tab,-blank-at-eof"


def check_diff_whitespace(source, base, head):
subprocess.run([
"git", "-C", str(source), "-c",
f"core.whitespace={DIFF_CHECK_WHITESPACE}",
"diff", "--check", f"{base}...{head}",
], check=True)


def validate_docs(root, plan):
for name in plan["docs"]:
Expand Down Expand Up @@ -159,7 +172,7 @@ def prepare_snapshot(source, trusted, number, head, base, plan_file):
require(git(source, "rev-parse", "HEAD").decode().strip() == head, "Checkout is not the dispatched final head")
require(git(trusted, "rev-parse", "HEAD").decode().strip() == base, "Trusted checkout is not the dispatched base")
subprocess.run(["git", "-C", str(source), "merge-base", "--is-ancestor", base, head], check=True)
subprocess.run(["git", "-C", str(source), "diff", "--check", f"{base}...{head}"], check=True)
check_diff_whitespace(source, base, head)
plan = classify(api.files(pr))
plan.update(identity)
same_state(api.pr(number), plan)
Expand Down
Loading