fix: validate platform keys at the gate and stop auto-register
All checks were successful
技能自动化发布 / release (push) Successful in 6s
All checks were successful
技能自动化发布 / release (push) Successful in 6s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -74,3 +74,60 @@ class TestResolvePlatformKeyDynamicParsing:
|
||||
clean_db.commit()
|
||||
result = resolve_platform_key_dynamic("bad_alias", conn=clean_db)
|
||||
assert result.platform_key == "bad_alias"
|
||||
|
||||
|
||||
class TestPlatformKeyFormatAndAmbiguity:
|
||||
def test_format_rejects_mixed_case(self):
|
||||
from util.platforms import is_valid_platform_key_format
|
||||
|
||||
assert is_valid_platform_key_format("haokan") is True
|
||||
assert is_valid_platform_key_format("HaoKan") is False
|
||||
assert is_valid_platform_key_format("hao_kan") is True
|
||||
|
||||
def test_deepseek_display_resolves_to_key(self, clean_db):
|
||||
from util.platforms import resolve_platform_key_dynamic
|
||||
|
||||
result = resolve_platform_key_dynamic("DeepSeek", conn=clean_db)
|
||||
assert result.ok
|
||||
assert result.platform_key == "deepseek"
|
||||
|
||||
def test_douyin_alias_still_unique(self, clean_db):
|
||||
from util.platforms import resolve_platform_key_dynamic
|
||||
|
||||
result = resolve_platform_key_dynamic("抖音", conn=clean_db)
|
||||
assert result.platform_key == "douyin"
|
||||
|
||||
def test_wechat_key_wins(self, clean_db):
|
||||
from util.platforms import resolve_platform_key_dynamic
|
||||
|
||||
result = resolve_platform_key_dynamic("wechat", conn=clean_db)
|
||||
assert result.ok
|
||||
assert result.platform_key == "wechat"
|
||||
|
||||
def test_gongzhonghao_is_ambiguous(self, clean_db):
|
||||
from util.platforms import resolve_platform_key_dynamic
|
||||
|
||||
result = resolve_platform_key_dynamic("公众号", conn=clean_db)
|
||||
assert not result.ok
|
||||
assert result.error_code == "AMBIGUOUS_PLATFORM"
|
||||
assert "wechat" in (result.message or "")
|
||||
assert "wechat_mp" in (result.message or "")
|
||||
|
||||
def test_unregistered_lookalike_key(self, clean_db):
|
||||
from util.platforms import resolve_platform_key_dynamic
|
||||
|
||||
result = resolve_platform_key_dynamic("HaoKan", conn=clean_db)
|
||||
assert result.error_code == "INVALID_PLATFORM_KEY"
|
||||
assert "platform ensure" in (result.message or "")
|
||||
|
||||
def test_unregistered_valid_key_not_inserted(self, clean_db):
|
||||
from util.platforms import resolve_platform_key_dynamic
|
||||
|
||||
result = resolve_platform_key_dynamic("hao_kan", conn=clean_db)
|
||||
assert result.error_code == "PLATFORM_NOT_REGISTERED"
|
||||
assert "已拒绝写入" in (result.message or "")
|
||||
count = clean_db.execute(
|
||||
"SELECT COUNT(*) FROM platforms WHERE platform_key = 'hao_kan'"
|
||||
).fetchone()[0]
|
||||
assert count == 0
|
||||
|
||||
|
||||
Reference in New Issue
Block a user