ZJU-REAL/Easel / skills/builtin/skill-wechat-publisher
skill-wechat-publisher
Verified微信公众号文章自动创作与发布工具。给定参考文章、文字或文档,自动搜索整理全网相关信息、生成图文并茂的公众号文章,并发布到微信公众号草稿箱。特别强调反 AI 检测写作。 触发场景(沾边就用):用户提到"公众号 / 微信文章 / 推文 / 公号 / 发文 / mp / 草稿箱 / 群发",或要求把话题/文档/笔记写成公众号文章并发布到微信。
tests/conftest.py
View on GitHub"""
pytest fixtures for wechat-publisher.
Key goals:
- Tests must run **without** real WeChat credentials.
- All network calls are monkeypatched to raise so accidental real HTTP
during tests fails loudly instead of silently hitting the internet.
- `scripts/` is added to sys.path so tests can `import config`,
`import ai_score`, `import html_converter` directly.
"""
from __future__ import annotations
import sys
import textwrap
from pathlib import Path
import pytest
# Make scripts/ importable for all test files.
_SCRIPTS_DIR = Path(__file__).parent.parent / "scripts"
if str(_SCRIPTS_DIR) not in sys.path:
sys.path.insert(0, str(_SCRIPTS_DIR))
# ---------------------------------------------------------------------------
# wechat-publisher.yaml fixture
# ---------------------------------------------------------------------------
# Minimal but realistic wechat-publisher.yaml content.
# Just enough for config.py to parse successfully. No real credentials.
_MIN_CONFIG_YAML = textwrap.dedent(
"""\
default: main
accounts:
main:
name: "Test Main"
app_id: "wx_fake_main_app_id_0001"
app_secret: "fake_main_secret"
author: "飞哥"
theme: "refined-blue"
voice: "test-voice-main"
tech:
name: "Test Tech"
app_id: "wx_fake_tech_app_id_0002"
app_secret: "fake_tech_secret"
author: "葱哥"
theme: "minimal-mono"
voice: "test-voice-tech"
"""
)
@pytest.fixture
def tmp_config_yaml(tmp_path, monkeypatch):
"""
Drop a minimal `wechat-publisher.yaml` into a temp directory.
Yields the parsed dict (handy when tests want to double-check what's in
the file they're testing against).
"""
import yaml
yaml_path = tmp_path / "wechat-publisher.yaml"
yaml_path.write_text(_MIN_CONFIG_YAML, encoding="utf-8")
# Reset any active account set by a previous test.
try:
import config
config.set_account(None)
monkeypatch.setattr(config, "_config_path", lambda: yaml_path)
except ImportError:
pass
data = yaml.safe_load(_MIN_CONFIG_YAML)
yield data
# Teardown: clear active account again so leakage doesn't affect later tests.
try:
import config
config.set_account(None)
except ImportError:
pass
@pytest.fixture
def write_config_yaml(tmp_path, monkeypatch):
"""
Like `tmp_config_yaml` but returns a writer function so a test can
supply custom YAML content.
"""
try:
import config
config.set_account(None)
except ImportError:
pass
def _write(yaml_text: str) -> Path:
p = tmp_path / "wechat-publisher.yaml"
p.write_text(yaml_text, encoding="utf-8")
try:
import config
config.set_account(None)
monkeypatch.setattr(config, "_config_path", lambda: p)
except ImportError:
pass
return p
yield _write
try:
import config
config.set_account(None)
except ImportError:
pass
# ---------------------------------------------------------------------------
# Network blocker
# ---------------------------------------------------------------------------
@pytest.fixture
def no_network(monkeypatch):
"""
Monkeypatch requests.get / requests.post to raise so the test fails
loudly if a code path accidentally hits the real WeChat API.
Usage:
def test_thing(no_network):
... # if requests.get is called, RuntimeError is raised
"""
def _boom(*args, **kwargs):
raise RuntimeError(
"Accidental network call in a unit test — mock this explicitly."
)
try:
import requests
monkeypatch.setattr(requests, "get", _boom)
monkeypatch.setattr(requests, "post", _boom)
except ImportError:
# requests not installed — nothing to block.
pass
# Also block urllib just in case.
try:
import urllib.request
monkeypatch.setattr(urllib.request, "urlopen", _boom)
except ImportError:
pass
yield
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |