修 GitHub App 安装在 Postgres 上崩:适配层译 INSERT OR IGNORE,安装后增减仓库同步
This commit is contained in:
1 parent
f07b3ccc7c
commit
9fa80bef89
3 files changed
+101
-8
No files matched your search
@@ -242,6 +242,47 @@ class SignatureAnyTestCase(unittest.TestCase):
|
||||
self.assertFalse(verify_github_signature_any([], raw, "sha256=x"))
|
||||
|
||||
|
||||
class DialectTranslationTestCase(unittest.TestCase):
|
||||
"""Postgres 适配层翻译:2026-10-26 实弹回归——安装事件在生产
|
||||
Postgres 上因 INSERT OR IGNORE 未翻译直接报语法错。
|
||||
|
||||
直接测 _translate_sql(纯函数):函数发出的 SQL 在这里翻
|
||||
译成合法 Postgres,SQLite 路径不受影响(翻译只走 Pg 游标)。
|
||||
"""
|
||||
|
||||
def test_or_ignore_translates(self):
|
||||
from cloud.db import _translate_sql
|
||||
sql, kind = _translate_sql(
|
||||
"INSERT OR IGNORE INTO github_app_installations("
|
||||
"installation_id, account_login, repo_full_name, created_at)"
|
||||
" VALUES(?, ?, ?, ?)")
|
||||
self.assertEqual(kind, "normal")
|
||||
self.assertNotIn("OR IGNORE", sql)
|
||||
self.assertIn("ON CONFLICT DO NOTHING", sql)
|
||||
self.assertIn("%s", sql)
|
||||
self.assertNotIn("?", sql)
|
||||
|
||||
def test_or_ignore_with_null_value_translates(self):
|
||||
from cloud.db import _translate_sql
|
||||
sql, _ = _translate_sql(
|
||||
"INSERT OR IGNORE INTO github_fix_review_dedup("
|
||||
"repo, pr_number, comment_id, task_id, created_at)"
|
||||
" VALUES(?, ?, ?, NULL, ?)")
|
||||
self.assertNotIn("OR IGNORE", sql)
|
||||
self.assertIn("ON CONFLICT DO NOTHING", sql)
|
||||
self.assertIn("NULL", sql)
|
||||
|
||||
def test_or_replace_app_config_updates_on_conflict(self):
|
||||
from cloud.db import _translate_sql
|
||||
sql, _ = _translate_sql(
|
||||
"INSERT OR REPLACE INTO github_app_config(id, app_id, slug,"
|
||||
" client_id, webhook_secret, pem, html_url, created_at)"
|
||||
" VALUES(1, ?, ?, ?, ?, ?, ?, ?)")
|
||||
self.assertIn("ON CONFLICT (id) DO UPDATE SET", sql)
|
||||
self.assertIn("slug = EXCLUDED.slug", sql)
|
||||
self.assertNotIn("OR REPLACE", sql)
|
||||
|
||||
|
||||
class AppHttpTestCase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
@@ -391,6 +432,33 @@ class AppHttpTestCase(unittest.TestCase):
|
||||
self.assertEqual(
|
||||
body["installations"][0]["repo_full_name"], "octo/a")
|
||||
|
||||
def test_installation_repositories_sync(self):
|
||||
# 安装后增减仓库的同步事件:added 增行。
|
||||
conn = _db_connect(self.db_path)
|
||||
try:
|
||||
save_app_config(conn, {
|
||||
"app_id": 424242, "slug": "fake-codex-app",
|
||||
"client_id": "Iv1.fake", "webhook_secret": "fake-app-secret",
|
||||
"pem": "fake-pem",
|
||||
"html_url": "https://github.com/apps/fake-codex-app"})
|
||||
finally:
|
||||
conn.close()
|
||||
payload = {
|
||||
"action": "added",
|
||||
"installation": {"id": 11, "account": {"login": "octo"}},
|
||||
"repositories_added": [{"full_name": "octo/c"}]}
|
||||
status, body = self._webhook(
|
||||
"installation_repositories", payload, "fake-app-secret",
|
||||
"d-inst-repos-1")
|
||||
self.assertEqual(status, 200, body)
|
||||
self.assertEqual(body["result"], "installation_recorded")
|
||||
status, body = self._req(
|
||||
"GET", "/github-app/status", key=self.key_a)
|
||||
self.assertEqual(status, 200, body)
|
||||
self.assertEqual(
|
||||
[r["repo_full_name"] for r in body["installations"]],
|
||||
["octo/c"])
|
||||
|
||||
def test_webhook_no_secret_is_503(self):
|
||||
os.environ.pop("GITHUB_WEBHOOK_SECRET", None)
|
||||
status, _ = self._webhook(
|
||||
|
||||
Reference in new issue
Block a user