✨ feat: WP-07 插件生态——Registry、三态分离与调用门(ADR-001/008)

- 迁移 14:plugin(kind 四形态、撤架三态)、plugin_version(Manifest JSONB + 规范化内容哈希签名、(plugin,version) 唯一)、plugin_installation(enabled + granted_permissions、(domain,plugin) 唯一)
- Registry:发布版本(Manifest 必须声明 permissions,签名=canonical 哈希);撤架阻断新调用与新安装,历史审计保留(验证:撤架后 invoked 审计仍在)
- 三态分离(购买≠安装≠启用≠授权):安装默认 disabled+零授权;启用必须显式授予权限子集(越界 422);调用门逐级校验(未装/未启/撤架各 403)
- 升级:Manifest 新增权限必须重新确认(未确认 422 且明示新增项);确认后升级成功
- 调用:按 Manifest response_template 真实执行(声明式确定性回填);remote/isolated 形态明示 501 随沙箱交付(WP-14),不静默降级;审计含版本哈希(快照语义)
- 权限标识统一 group:item 格式
- 测试 86 项全绿(+4):三态流、越界、升级确认、撤架阻断与历史保留
This commit is contained in:
chenxin committed 2026-09-12 10:18:20 +08:00
1 parent 795df0413e
commit 9ef2568c3b
7 files changed
+771

No files matched your search

+81
View File
@@ -1091,3 +1091,84 @@ class ProjectVersion(Base):
),
Index("uq_project_version_number", "project_id", "version", unique=True),
)
class Plugin(Base):
"""插件(Registry 条目,WP-07):撤架阻断新调用,历史审计保留。"""
__tablename__ = "plugin"
name: Mapped[str] = mapped_column(String, primary_key=True) # 点分稳定名
publisher_domain_id: Mapped[str] = mapped_column(
ForeignKey("personal_domain.id", ondelete="cascade"), nullable=False, index=True
)
kind: Mapped[str] = mapped_column(String, nullable=False, default="declarative")
status: Mapped[str] = mapped_column(String, nullable=False, default="published")
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, server_default=func.now()
)
__table_args__ = (
CheckConstraint(
"kind IN ('declarative', 'remote', 'isolated_process', 'container')",
name="kind_values",
),
CheckConstraint(
"status IN ('published', 'suspended', 'removed')", name="status_values"
),
)
class PluginVersion(Base):
"""插件版本:Manifest(权限/网络/数据声明)与内容签名(哈希)。"""
__tablename__ = "plugin_version"
id: Mapped[str] = mapped_column(
String, primary_key=True, default=lambda: new_id("plugin_version_")
)
plugin_name: Mapped[str] = mapped_column(
ForeignKey("plugin.name", ondelete="cascade"), nullable=False, index=True
)
version: Mapped[str] = mapped_column(String, nullable=False)
manifest: Mapped[dict[str, Any]] = mapped_column(JSONB, nullable=False, default=dict)
content_hash: Mapped[str] = mapped_column(String, nullable=False)
status: Mapped[str] = mapped_column(String, nullable=False, default="published")
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, server_default=func.now()
)
__table_args__ = (
CheckConstraint(
"status IN ('published', 'suspended', 'removed')", name="status_values"
),
Index("uq_plugin_version", "plugin_name", "version", unique=True),
)
class PluginInstallation(Base):
"""安装:购买≠安装≠启用≠授权;启用必须显式确认权限子集。"""
__tablename__ = "plugin_installation"
id: Mapped[str] = mapped_column(
String, primary_key=True, default=lambda: new_id("plugin_installation_")
)
domain_id: Mapped[str] = mapped_column(
ForeignKey("personal_domain.id", ondelete="cascade"), nullable=False, index=True
)
plugin_name: Mapped[str] = mapped_column(
ForeignKey("plugin.name", ondelete="cascade"), nullable=False
)
version_id: Mapped[str] = mapped_column(
ForeignKey("plugin_version.id", ondelete="restrict"), nullable=False
)
enabled: Mapped[bool] = mapped_column(nullable=False, default=False)
granted_permissions: Mapped[list[str]] = mapped_column(JSONB, nullable=False, default=list)
created_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), nullable=False, server_default=func.now()
)
__table_args__ = (
Index("uq_plugin_installation", "domain_id", "plugin_name", unique=True),
)