diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index 0378766..1bfe52e 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -148,31 +148,51 @@ export class PublicWorkspaceController { @Get() async get(): Promise { const brandId = process.env.DEFAULT_BRAND_ID ?? "00000000-0000-0000-0000-000000000001"; - const [brand, modules, fields, offerings, inquiryForm, installation] = await Promise.all([ - this.prisma.brandProfile.findUnique({ where: { id: brandId } }), - this.prisma.brandModule.findMany({ - where: { brandId, isEnabled: true }, - orderBy: { sortOrder: "asc" }, - }), - this.prisma.brandFieldDefinition.findMany({ - where: { brandId, isVisible: true }, - orderBy: { sortOrder: "asc" }, - }), - this.prisma.offering.findMany({ - where: { brandId, isEnabled: true }, - orderBy: { sortOrder: "asc" }, - }), - this.prisma.inquiryForm.findFirst({ - where: { brandId, isEnabled: true }, - orderBy: { updatedAt: "desc" }, - }), - this.prisma.brandTemplateInstallation.findFirst({ - where: { brandId }, - orderBy: { updatedAt: "desc" }, - }), - ]); + const [brand, modules, fields, offerings, inquiryForm, installation, capabilityInstallations] = + await Promise.all([ + this.prisma.brandProfile.findUnique({ where: { id: brandId } }), + this.prisma.brandModule.findMany({ + where: { brandId, isEnabled: true }, + orderBy: { sortOrder: "asc" }, + }), + this.prisma.brandFieldDefinition.findMany({ + where: { brandId, isVisible: true }, + orderBy: { sortOrder: "asc" }, + }), + this.prisma.offering.findMany({ + where: { brandId, isEnabled: true }, + orderBy: { sortOrder: "asc" }, + }), + this.prisma.inquiryForm.findFirst({ + where: { brandId, isEnabled: true }, + orderBy: { updatedAt: "desc" }, + }), + this.prisma.brandTemplateInstallation.findFirst({ + where: { brandId }, + orderBy: { updatedAt: "desc" }, + }), + this.prisma.capabilityInstallation.findMany({ where: { brandId } }), + ]); const templateKey = installation?.templateKey ?? brand?.templateKey ?? "personal"; const template = getBrandTemplate(templateKey); + const runtimeCapabilities = capabilityInstallations.length + ? capabilityInstallations.map((item) => ({ + key: item.capabilityKey, + version: item.capabilityVersion, + status: item.status as "enabled" | "disabled" | "degraded", + config: + item.config && typeof item.config === "object" && !Array.isArray(item.config) + ? (item.config as Record) + : {}, + })) + : template + ? resolveCapabilities(template.capabilities).map((item) => ({ + key: item.key, + version: item.version, + status: "enabled" as const, + config: {}, + })) + : []; const brandConfig = brand?.config && typeof brand.config === "object" && !Array.isArray(brand.config) ? (brand.config as Record) @@ -259,14 +279,7 @@ export class PublicWorkspaceController { }, ] : [], - capabilities: (template ? resolveCapabilities(template.capabilities) : []).map( - (capability) => ({ - key: capability.key, - version: capability.version, - config: {}, - status: "enabled" as const, - }), - ), + capabilities: runtimeCapabilities, plugins: (template ? template.capabilities : []) .map((key) => capabilityPlugins[key as keyof typeof capabilityPlugins]) .filter(Boolean) diff --git a/apps/api/test/http.integration.test.js b/apps/api/test/http.integration.test.js index 711a08e..fdfe40a 100644 --- a/apps/api/test/http.integration.test.js +++ b/apps/api/test/http.integration.test.js @@ -60,6 +60,35 @@ test("health and public content are available without authentication", async () assert.ok(Array.isArray(runtime.plugins)); }); +test("public workspace uses brand-scoped capability installations and preserves status", async () => { + await prisma.capabilityInstallation.deleteMany({ where: { brandId } }); + const installation = await prisma.capabilityInstallation.create({ + data: { + brandId, + capabilityKey: "inquiry", + capabilityVersion: "1.0.0", + status: "disabled", + config: { source: "integration-test" }, + }, + }); + try { + const response = await request("/public/workspace"); + assert.equal(response.statusCode, 200); + const body = JSON.parse(response.body); + assert.deepEqual(body.capabilities, [ + { + key: "inquiry", + version: "1.0.0", + status: "disabled", + config: { source: "integration-test" }, + }, + ]); + assert.notEqual(body.capabilities[0].status, "enabled"); + } finally { + await prisma.capabilityInstallation.delete({ where: { id: installation.id } }); + } +}); + test("admin can install a template and public workspace exposes enabled configuration", async () => { await prisma.inquirySubmission.deleteMany({ where: { brandId } }); await prisma.inquiryForm.deleteMany({ where: { brandId } }); diff --git a/docs/template-runtime-progress.md b/docs/template-runtime-progress.md index c3b0551..3db23c9 100644 --- a/docs/template-runtime-progress.md +++ b/docs/template-runtime-progress.md @@ -58,7 +58,12 @@ - [x] 首页通过受控模块分支按 `layout.home` 实际改变模块渲染顺序。 - [x] 增加林境建筑画册与极简留白双视觉模板 fixture 验收。 - [x] 建立通用咨询 Capability Plugin manifest,明确模块依赖和 API 契约。 -- [ ] Phase 4:Capability Plugin。 +- [x] Phase 4:Capability Plugin 基础运行时合并。 +- [x] 新增 `CapabilityInstallation` 持久化模型、唯一约束和可逆 Prisma migration。 +- [x] Runtime Workspace 优先读取品牌级能力安装记录,并保留模板默认能力回退。 +- [x] 能力状态统一输出为 `enabled`、`disabled` 或 `degraded`,并保留能力配置。 +- [x] 集成测试覆盖品牌级能力安装读取、状态保留和配置隔离。 +- [ ] 增加 Admin 能力启用 / 停用写接口、DTO、权限、审计和状态转换测试。 - [ ] Phase 5:林境门作与第二行业双模板验证。 - [ ] Phase 6:Stitch 到 Manifest 的转换流水线。