fix: 收口依赖兼容与会话撤销

为 miniprogram-ci 和 Jimp 依赖增加兼容 patch 与 smoke test;修复平台模板管理员路由漏配;收紧模板契约校验;为 admin/customer 增加 token 撤销和集中会话存储;同步品牌切换角色、doctor source hash、多屏宽截图证据和 CI 构建门禁。
This commit is contained in:
que01 committed 2026-10-18 23:43:25 +08:00
1 parent 4f0b50c7f1
commit 3017e3eb49
65 files changed
+1623 -975

No files matched your search

+81 -2
View File
@@ -247,6 +247,30 @@ test("模板失败指标仅平台模板管理员可查,按窗口聚合且不
await prisma.adminUser.delete({ where: { id: ordinaryUser.id } });
}
const templateAdminWithoutMembership = await prisma.adminUser.create({
data: {
username: `metrics-platform-${randomUUID()}`,
passwordHash: "unused",
displayName: "平台模板管理员",
platformTemplateRole: "template_admin",
mustChangePassword: false,
},
});
try {
const response = await request("/admin/template-operations/failures", {
headers: {
authorization: `Bearer ${signIdentity({
subject: templateAdminWithoutMembership.id,
brandId: "00000000-0000-0000-0000-000000000000",
role: "admin",
})}`,
},
});
assert.equal(response.statusCode, 200, response.body);
} finally {
await prisma.adminUser.delete({ where: { id: templateAdminWithoutMembership.id } });
}
const login = await request("/admin/session/login", {
method: "POST",
payload: { username: "admin", password: process.env.SEED_ADMIN_PASSWORD },
@@ -516,7 +540,10 @@ test("平台模板管理员可以按行业预览版本,且预览不写入品
/所属行业|must match its key/,
],
[{ ...stored.manifestSnapshot, requiredCapabilities: ["unknown"] }, /未注册的 capability/],
[{ ...stored.manifestSnapshot, visualTemplateKey: "unknown" }, /元数据/],
[
{ ...stored.manifestSnapshot, visualTemplateKey: "unknown" },
/visualTemplateKey must match packageKey|元数据/,
],
[{ ...stored.manifestSnapshot, runtimeContract: "9.0" }, /契约/],
[{ ...stored.manifestSnapshot, dataSlots: [null] }, /契约/],
[{ ...stored.manifestSnapshot, navigation: [null] }, /契约/],
@@ -3868,6 +3895,54 @@ test("admin login validates credentials", async () => {
assert.equal(response.statusCode, 401);
});
test("admin logout revokes the current token", async () => {
const username = `logout-admin-${randomUUID()}`;
const password = "logout-password-123";
const user = await prisma.adminUser.create({
data: {
username,
passwordHash: await bcrypt.hash(password, 12),
displayName: "登出测试管理员",
mustChangePassword: false,
},
});
await prisma.brandMembership.create({
data: { brandId, adminUserId: user.id, role: "owner", isEnabled: true },
});
try {
const login = await request("/admin/session/login", {
method: "POST",
payload: { username, password },
});
assert.equal(login.statusCode, 201, login.body);
const token = JSON.parse(login.body).token;
const headers = { authorization: `Bearer ${token}` };
const before = await request("/admin/bookings/unread-count", { headers });
assert.equal(before.statusCode, 200);
const logout = await request("/admin/session/logout", { method: "POST", headers });
assert.equal(logout.statusCode, 201);
const after = await request("/admin/bookings/unread-count", { headers });
assert.equal(after.statusCode, 401);
} finally {
await prisma.adminUser.delete({ where: { id: user.id } });
}
});
test("customer logout revokes the current token", async () => {
const openid = `logout-${randomUUID()}`;
await prisma.customerUser.create({ data: { brandId, openid } });
const token = signIdentity({ subject: openid, brandId, role: "customer" });
const headers = { authorization: `Bearer ${token}` };
const before = await request("/customer/inquiry-submissions", { headers });
assert.equal(before.statusCode, 200);
const logout = await request("/customer/session/logout", { method: "POST", headers });
assert.equal(logout.statusCode, 201);
const after = await request("/customer/inquiry-submissions", { headers });
assert.equal(after.statusCode, 401);
});
test("admin login does not auto-grant ownership to users without memberships", async () => {
const username = `no-membership-${Date.now()}`;
const user = await prisma.adminUser.create({
@@ -4287,7 +4362,7 @@ test("admin can manage trust content", async () => {
test("customer booking endpoints require a valid customer session", async () => {
const missing = await request("/customer/bookings");
assert.equal(missing.statusCode, 400);
assert.equal(missing.statusCode, 401);
const list = await request("/customer/bookings", {
headers: { authorization: `Bearer ${customerToken}` },
@@ -4774,6 +4849,9 @@ test("atelier template imports selected package and preserves draft publication
(await json("/public/workspace?brandSlug=" + slug)).brand.visualPresentation.home.title,
"仅草稿可见的新标题",
);
const atelierCustomer = await prisma.customerUser.create({
data: { brandId: brand.id, openid: "atelier-test-customer" },
});
const customerHeaders = {
authorization: `Bearer ${signIdentity({ subject: "atelier-test-customer", brandId: brand.id, role: "customer" })}`,
};
@@ -4819,6 +4897,7 @@ test("atelier template imports selected package and preserves draft publication
);
}
} finally {
await prisma.customerUser.deleteMany({ where: { brandId: brand.id } });
await prisma.brandProfile.delete({ where: { id: brand.id } });
}
});
@@ -0,0 +1,31 @@
import assert from "node:assert/strict";
import { createRequire } from "node:module";
import test from "node:test";
const require = createRequire(import.meta.url);
const png = Buffer.from(
"89504e470d0a1a0a0000000d4948445200000001000000010802000000907753de0000000c49444154789c63f8cfc0000003010100c9fe92ef0000000049454e44ae426082",
"hex",
);
test("miniprogram-ci compatibility patches keep overridden runtime APIs usable", async () => {
const buildCloud = require(
require.resolve("miniprogram-ci/dist/modules/nativecompiler/ios/buildCloud.js"),
);
assert.equal(typeof buildCloud.default, "object");
const uuid = require("uuid") as { v4: () => string };
assert.match(uuid.v4(), /^[0-9a-f-]{36}$/);
const imageSize = require("image-size") as {
imageSize: (input: Buffer) => { width: number; height: number; type: string };
};
assert.deepEqual(imageSize.imageSize(png), { width: 1, height: 1, type: "png" });
const Jimp = require("jimp") as {
read: (input: Buffer) => Promise<{ bitmap: { width: number; height: number } }>;
};
const image = await Jimp.read(png);
assert.equal(image.bitmap.width, 1);
assert.equal(image.bitmap.height, 1);
});
@@ -45,7 +45,7 @@ async function main() {
.filter((entry) => entry.isDirectory() && entry.name !== targetMigration)
.map((entry) => entry.name)
.sort();
assert.equal(migrationDirs.at(-1), "20261018170000_add_admin_token_version");
assert.equal(migrationDirs.at(-1), "20261018180000_add_customer_token_version");
await admin.$executeRawUnsafe(`CREATE SCHEMA "${schema}"`);
createdSchema = true;