mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
Brings seaweed-block main (v1.1.1 plus the docs and a test fix after it) into seaweed-block/ as one commit. Only files under seaweed-block/ change, and the subtree equals seaweed-block main exactly. The module's full history stays in the seaweed-block repository. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
3.9 KiB
Python
59 lines
3.9 KiB
Python
"""Trusted-base gate contracts and a PR that replaces its own checkers."""
|
|
from pathlib import Path
|
|
import os, shutil, subprocess, tempfile, unittest
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
|
|
class BaseGateTests(unittest.TestCase):
|
|
def test_readonly_events_and_separate_base_checkout(self):
|
|
for filename in ('spec-trace.yml', 'post-merge-review.yml'):
|
|
with self.subTest(workflow=filename):
|
|
text=(ROOT/'.github/workflows'/filename).read_text()
|
|
self.assertIn(' pull_request:',text)
|
|
self.assertNotIn('pull_request_target:',text)
|
|
self.assertIn(' contents: read',text)
|
|
self.assertNotIn('secrets.',text)
|
|
self.assertIn(' runs-on: ubuntu-latest',text)
|
|
self.assertIn('ref: ${{ github.event.pull_request.base.sha }}',text)
|
|
self.assertIn('path: trusted-base',text)
|
|
self.assertIn('working-directory: trusted-base',text)
|
|
self.assertIn('persist-credentials: false',text)
|
|
self.assertNotIn('ref: ${{ github.event.pull_request.head.sha }}',text)
|
|
self.assertNotIn('ref: ${{ github.sha }}',text)
|
|
text=(ROOT/'.github/workflows/spec-trace.yml').read_text()
|
|
self.assertIn('go-version-file: trusted-base/go.mod',text)
|
|
|
|
def test_pr_cannot_replace_base_validators_or_allowlist(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
root=Path(tmp); source=root/'source'; source.mkdir()
|
|
scripts=source/'.github/scripts'; scripts.mkdir(parents=True)
|
|
names=('spec-trace-check.sh','post-merge-review-check.sh','post-merge-review-changed.sh')
|
|
for name in names: shutil.copyfile(ROOT/'.github/scripts'/name,scripts/name)
|
|
allow=source/'.github/post-merge-review-allow.txt'; allow.write_text('docs/**\n')
|
|
def git(*args,cwd=source):
|
|
return subprocess.check_output(['git',*args],cwd=cwd,stderr=subprocess.PIPE,timeout=15)
|
|
git('init','-b','main'); git('config','user.name','Example'); git('config','user.email','example@example.invalid'); git('config','commit.gpgsign','false')
|
|
git('add','.'); git('commit','-m','base')
|
|
base=git('rev-parse','HEAD').decode().strip()
|
|
(source/'docs').mkdir(); (source/'docs/example.md').write_text('Documentation')
|
|
git('add','.'); git('commit','-m','documentation')
|
|
good=git('rev-parse','HEAD').decode().strip()
|
|
for name in ('spec-trace-check.sh','post-merge-review-check.sh'):
|
|
(scripts/name).write_text('#!/bin/sh\ntouch ../pr-code-ran\nexit 0\n')
|
|
allow.write_text('*\n')
|
|
git('add','.'); git('commit','-m','replace validators')
|
|
bad=git('rev-parse','HEAD').decode().strip()
|
|
checkout=root/'trusted-base'; git('clone','--quiet',str(source),str(checkout)); git('checkout','--detach',base,cwd=checkout)
|
|
self.assertEqual(git('rev-parse','HEAD',cwd=checkout).decode().strip(),base)
|
|
body=checkout/'body.txt'
|
|
valid='Feature: documentation\nMachine/INV: DOCS\nModel: NONE (documentation fixture only)\nRed-first: fixture validation\n'
|
|
for head,description,success in ((good,valid,True),(bad,'missing trace',False)):
|
|
body.write_text(description)
|
|
changes=git('diff','-z','--name-status','--no-renames',base+'...'+head,cwd=checkout)
|
|
for command in (['spec-trace-check.sh',str(body)],['post-merge-review-check.sh','.github/post-merge-review-allow.txt']):
|
|
result=subprocess.run(['bash','.github/scripts/'+command[0],*command[1:]],cwd=checkout,input=changes,capture_output=True,timeout=15)
|
|
self.assertEqual(result.returncode==0,success,result.stdout.decode()+result.stderr.decode())
|
|
self.assertFalse((root/'pr-code-ran').exists())
|
|
|
|
if __name__=='__main__': unittest.main()
|