topmindspace/topmind-writing-skills / topmind-viral-posts
topmind-viral-posts
Verified创作有内容、有观察、有意思的 X 段子、互动短帖、装傻真提问、算账吐槽、内行轻判断、引用转发与神回复;提供可直接使用的文案,支持作者样本与多元思路探索。信息型快讯与干货短文用 topmind-briefs,现成文字只排版用 topmind-format,独立改稿用 topmind-revise。
scripts/negative_tests.py
View on GitHub#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""topmind-viral-posts 异常输入测试:技能工具链在坏输入下干净失败、不崩溃(任一失败 → 退出码 1)。
覆盖:
1. 工作流引用的跨技能脚本存在(md2x-html.py / md2wechat.py 缺失即失败,不静默)
2. audit_skill.py 在 frontmatter 损坏的 SKILL.md 上退出码 1(不抛未捕获异常)
3. package_skill.py --check 在缺 README.md 的技能目录上退出码 1(不抛未捕获异常)
4. scripts/*.py 全部可编译
"""
from __future__ import annotations
import shutil
import re
import subprocess
import sys
import tempfile
from pathlib import Path
try:
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
except Exception:
pass
ROOT = Path(__file__).resolve().parent.parent
REPO = ROOT.parent
PY = sys.executable
fails: list[str] = []
def check(name: str, cond: bool, detail: str = "") -> None:
print((" ✓ " if cond else " ✗ ") + name + (f" — {detail}" if detail and not cond else ""))
if not cond:
fails.append(name)
def run_quiet(args: list[str], cwd: Path) -> subprocess.CompletedProcess:
return subprocess.run([PY, *args], capture_output=True, text=True, timeout=60, cwd=str(cwd))
def main() -> None:
print("[negative_tests] topmind-viral-posts")
# 1. 自包含:SKILL.md / references 不引用技能目录外的路径(单独安装也能用)
outside = []
for md in [ROOT / "SKILL.md", *sorted((ROOT / "references").glob("*.md"))]:
if not md.is_file():
continue
for link in re.findall(r"\]\(([^)]+)\)", md.read_text(encoding="utf-8")):
if link.startswith(("https://", "http://", "mailto:", "#")):
continue
# ../knowledge is still inside a standalone skill; compare resolved paths.
target = (md.parent / link.split("#")[0]).resolve()
if not target.is_relative_to(ROOT.resolve()):
outside.append(f"{md.relative_to(ROOT).as_posix()}: {link}")
check("不引用技能目录外的相对路径", not outside, "、".join(outside))
# 2. frontmatter 损坏 → audit_skill 退出 1 且不崩溃
with tempfile.TemporaryDirectory() as td:
t = Path(td)
shutil.copytree(ROOT, t / "skill", ignore=shutil.ignore_patterns("dist", "__pycache__"))
sk = t / "skill" / "SKILL.md"
sk.write_text("no frontmatter here\n# broken\n", encoding="utf-8")
r = run_quiet(["scripts/audit_skill.py"], t / "skill")
check("audit_skill 在坏 frontmatter 上退出码=1",
r.returncode == 1, f"rc={r.returncode}")
check("audit_skill 在坏 frontmatter 上无未捕获 Traceback",
"Traceback" not in (r.stderr or ""), (r.stderr or "")[-200:])
# 3. 缺 README.md → package_skill --check 退出 1 且不崩溃
with tempfile.TemporaryDirectory() as td:
t = Path(td)
shutil.copytree(ROOT, t / "skill", ignore=shutil.ignore_patterns("dist", "__pycache__"))
(t / "skill" / "README.md").unlink()
(t / "skill" / "README.en.md").unlink(missing_ok=True)
r = run_quiet(["scripts/package_skill.py", "--check"], t / "skill")
check("package_skill --check 在缺 README.md 时退出码=1",
r.returncode == 1, f"rc={r.returncode}")
check("package_skill --check 在缺 README.md 时无未捕获 Traceback",
"Traceback" not in (r.stderr or ""), (r.stderr or "")[-200:])
# 3b. X 稿检查脚本随包自带:Markdown 列表 → 失败;emoji 列表 → 通过;--fix 后通过;公众号稿不受影响
lint = ROOT / "scripts" / "lint_x_post.py"
check("X 稿检查脚本随包自带: scripts/lint_x_post.py", lint.is_file())
if lint.is_file():
with tempfile.TemporaryDirectory() as td:
t = Path(td)
bad = t / "bad.txt"
bad.write_text("三个变化:\n\n- 响应更快\n- 价格更低\n1. 先装\n## 标题\n**加粗**\n\n#话题\n", encoding="utf-8")
good = t / "good.txt"
good.write_text("三个变化:\n\n🔹 响应更快\n🔹 价格更低\n ▫️ 细节\n\n1️⃣ 先装\n2️⃣ 再用\n\n#话题\n", encoding="utf-8")
r = run_quiet([str(lint), str(bad)], t)
check("lint_x_post 对 Markdown 列表/标题/加粗退出码=1", r.returncode == 1, f"rc={r.returncode}")
r = run_quiet([str(lint), str(good)], t)
check("lint_x_post 对 emoji 列表退出码=0", r.returncode == 0, r.stdout[-200:])
r = run_quiet([str(lint), str(bad), "--fix", "--style", "emoji", "--out", str(t / "fixed.txt")], t)
fixed = (t / "fixed.txt").read_text(encoding="utf-8") if (t / "fixed.txt").exists() else ""
check("lint_x_post --fix 后无 Markdown 列表且检查通过",
r.returncode == 0 and "🔹 响应更快" in fixed and "1️⃣ 先装" in fixed and "**" not in fixed, r.stdout[-200:])
r = run_quiet([str(lint), str(t / "nope.txt")], t)
check("lint_x_post 缺失文件干净报错", r.returncode == 2 and "Traceback" not in (r.stderr or ""))
# 4. scripts/*.py 可编译(用内置 compile 只验语法,不写 .pyc,避免污染工作区)
for py in sorted((ROOT / "scripts").glob("*.py")):
try:
compile(py.read_text(encoding="utf-8"), str(py), "exec")
check(f"可编译: scripts/{py.name}", True)
except SyntaxError as e:
check(f"可编译: scripts/{py.name}", False, str(e))
if fails:
print(f"\n[negative_tests] topmind-viral-posts: {len(fails)} 项失败")
sys.exit(1)
print("\n[negative_tests] topmind-viral-posts: 全部通过")
if __name__ == "__main__":
main()
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 196k | Updated | Claude CodeCodex | Verified | Install |