|
|
|
|
@ -57,7 +57,10 @@ def make_repo(tmp_path: Path) -> Path:
|
|
|
|
|
(source / "README.md").write_text("old\n", encoding="utf-8")
|
|
|
|
|
(source / "engine").mkdir()
|
|
|
|
|
(source / "engine" / "requirements.txt").write_text("example-package==1.0\n", encoding="utf-8")
|
|
|
|
|
(source / ".gitignore").write_text("engine/.venv/\nruntime/\nweb/vendor/\n", encoding="utf-8")
|
|
|
|
|
(source / ".gitignore").write_text(
|
|
|
|
|
"engine/.venv/\nruntime/\nweb/vendor/\nweb/storage/ticket-attachments/\n",
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
)
|
|
|
|
|
git(source, "add", "README.md", "engine/requirements.txt", ".gitignore")
|
|
|
|
|
git(source, "commit", "-m", "initial")
|
|
|
|
|
checkout = tmp_path / "panel"
|
|
|
|
|
@ -135,6 +138,50 @@ class UpdaterTests(unittest.TestCase):
|
|
|
|
|
with self.assertRaisesRegex(UpdateError, "未提交"):
|
|
|
|
|
updater.apply()
|
|
|
|
|
|
|
|
|
|
def test_project_ignores_ticket_attachment_runtime_data(self):
|
|
|
|
|
project_root = Path(__file__).resolve().parents[2]
|
|
|
|
|
self.assertIn(
|
|
|
|
|
"/web/storage/ticket-attachments/",
|
|
|
|
|
(project_root / ".gitignore").read_text(encoding="utf-8"),
|
|
|
|
|
)
|
|
|
|
|
self.assertIn(
|
|
|
|
|
"storage/ticket-attachments/",
|
|
|
|
|
(project_root / "web" / ".gitignore").read_text(encoding="utf-8"),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
def test_ignored_ticket_attachments_do_not_make_checkout_dirty(self):
|
|
|
|
|
checkout = make_repo(self.tmp_path)
|
|
|
|
|
attachment = checkout / "web" / "storage" / "ticket-attachments" / "ticket-image.png"
|
|
|
|
|
attachment.parent.mkdir(parents=True)
|
|
|
|
|
attachment.write_bytes(b"private runtime image")
|
|
|
|
|
updater = Updater(checkout, MemoryStore())
|
|
|
|
|
updater._remote_head = lambda: git(checkout, "rev-parse", "HEAD")
|
|
|
|
|
|
|
|
|
|
self.assertTrue(updater.settings()["checkout_ready"])
|
|
|
|
|
self.assertEqual(updater.check()["status"], "current")
|
|
|
|
|
self.assertEqual(git(checkout, "status", "--porcelain=v1", "--untracked-files=all"), "")
|
|
|
|
|
|
|
|
|
|
source = self.tmp_path / "source"
|
|
|
|
|
target = advance_source(source)
|
|
|
|
|
local_fetch(updater, source)
|
|
|
|
|
applied = updater.apply()
|
|
|
|
|
self.assertEqual(applied["new_commit"], target)
|
|
|
|
|
self.assertEqual(attachment.read_bytes(), b"private runtime image")
|
|
|
|
|
|
|
|
|
|
def test_target_commit_cannot_vendor_ticket_attachments(self):
|
|
|
|
|
checkout = make_repo(self.tmp_path)
|
|
|
|
|
source = self.tmp_path / "source"
|
|
|
|
|
target = source / "web" / "storage" / "ticket-attachments" / "bundled.png"
|
|
|
|
|
target.parent.mkdir(parents=True)
|
|
|
|
|
target.write_bytes(b"must remain runtime-only")
|
|
|
|
|
git(source, "add", "-f", str(target.relative_to(source)))
|
|
|
|
|
git(source, "commit", "-m", "attempt to vendor ticket image")
|
|
|
|
|
updater = Updater(checkout, MemoryStore())
|
|
|
|
|
local_fetch(updater, source)
|
|
|
|
|
|
|
|
|
|
with self.assertRaisesRegex(UpdateError, "运行数据"):
|
|
|
|
|
updater.apply()
|
|
|
|
|
|
|
|
|
|
def test_fast_forward_job_is_persisted_and_calls_restart(self):
|
|
|
|
|
checkout = make_repo(self.tmp_path)
|
|
|
|
|
source = self.tmp_path / "source"
|
|
|
|
|
|