feat(users): 拆分 C 端身份并迁移历史聊天

- digital.users: 独立开户登录与凭据版本校验,后台查看用户及原始会话
- 017迁移: 保留聊天消息、实验分组和人工指定期限,迁移历史账号归属
- tests: 覆盖身份隔离、凭据失效、会话归属和长账号登录,同步 README
This commit is contained in:
湛兮
2026-10-27 18:56:19 +08:00
parent 57c89f4f32
commit b9d1a7f6bd
14 changed files with 747 additions and 32 deletions
+22 -11
View File
@@ -554,7 +554,8 @@ test("空白实验系统仍能启动前台,且不为默认界面写入实验
const { pool } = await import("../src/db/pool");
const { authService } = await import("../src/modules/auth/auth.service");
t.mock.method(authService, "getCurrentUser", async () => ({
accountType: "EMPLOYEE",
accountType: "DIGITAL_USER",
scene: "DIGITAL_APP",
}));
t.mock.method(pool, "query", async (options: { sql: string }) => {
assert.match(
@@ -566,7 +567,11 @@ test("空白实验系统仍能启动前台,且不为默认界面写入实验
const app = createApp();
try {
await app.ready();
const token = app.jwt.sign({ sub: "employee:1", accountType: "EMPLOYEE" });
const token = app.jwt.sign({
sub: "user:1",
accountType: "DIGITAL_USER",
scene: "DIGITAL_APP",
});
const result = await app.inject({
method: "GET",
url: "/api/digital/bootstrap",
@@ -832,7 +837,8 @@ test("真实 bootstrap 消费自建 UI 类型,两账号按人工指定返回
const { env } = await import("../src/config/env");
const { authService } = await import("../src/modules/auth/auth.service");
t.mock.method(authService, "getCurrentUser", async () => ({
accountType: "EMPLOYEE",
accountType: "DIGITAL_USER",
scene: "DIGITAL_APP",
}));
let state = "running",
receipts = 0,
@@ -855,7 +861,7 @@ test("真实 bootstrap 消费自建 UI 类型,两账号按人工指定返回
config: {
...config,
audience: "specified",
accounts: ["employee:1", "super_admin:1"],
accounts: ["user:1", "user:2"],
},
};
t.mock.method(pool, "query", async (q: { sql: string }, args: unknown[]) => {
@@ -877,7 +883,7 @@ test("真实 bootstrap 消费自建 UI 类型,两账号按人工指定返回
return [
[
{
variant: args[1] === "employee:1" ? "A" : "B",
variant: args[1] === "user:1" ? "A" : "B",
bypass_audience: false,
},
],
@@ -893,10 +899,14 @@ test("真实 bootstrap 消费自建 UI 类型,两账号按人工指定返回
try {
await app.ready();
for (const [account, value, variant] of [
["employee:1", false, "A"],
["super_admin:1", true, "B"],
["user:1", false, "A"],
["user:2", true, "B"],
] as const) {
const token = app.jwt.sign({ sub: account, accountType: "EMPLOYEE" });
const token = app.jwt.sign({
sub: account,
accountType: "DIGITAL_USER",
scene: "DIGITAL_APP",
});
for (let i = 0; i < 2; i++) {
const response = await app.inject({
method: "GET",
@@ -916,8 +926,9 @@ test("真实 bootstrap 消费自建 UI 类型,两账号按人工指定返回
assert.equal(decisions, 4);
state = "paused";
const token = app.jwt.sign({
sub: "super_admin:1",
accountType: "EMPLOYEE",
sub: "user:2",
accountType: "DIGITAL_USER",
scene: "DIGITAL_APP",
});
const response = await app.inject({
method: "GET",
@@ -944,7 +955,7 @@ test("UI 业务事件按实际接入的自建类型归因,不再写死 ui", as
return [{ affectedRows: 1 }, []];
});
await trackUiEvent(
"employee:1",
"user:1",
"decision",
"conversation_started",
"conversation",