cc 5 giorni fa
parent
commit
1897ebb0b8

+ 8 - 8
ai-server/src/main/java/com/zsjz/ai/module/ai/controller/AiAgentController.java

@@ -85,7 +85,7 @@ public class AiAgentController extends BaseController {
     /**
      * 查询专家列表
      */
-        @SaCheckPermission("ai:agent:query")
+        @SaCheckPermission("ai:expert:query")
         @GetMapping("/list")
     public R<PageResult<AiExpertAgentVo>> list(@Validated(QueryGroup.class) AiExpertAgentBo bo, PageQuery pageQuery) {
         return R.ok(aiAgentService.queryPageList(bo, pageQuery));
@@ -140,7 +140,7 @@ public class AiAgentController extends BaseController {
     /**
      * 查询可绑定的业务工具选项(供定义页绑定工具集)
      */
-        @SaCheckPermission("ai:agent:query")
+        @SaCheckPermission(value = {"ai:agent:query", "ai:expert:query"}, mode = SaMode.OR)
         @GetMapping("/tool/options")
     public R<List<AiToolVo>> toolOptions() {
         return R.ok(aiToolService.queryOptions());
@@ -162,7 +162,7 @@ public class AiAgentController extends BaseController {
      *
      * @param id 主键
      */
-        @SaCheckPermission("ai:agent:query")
+        @SaCheckPermission("ai:expert:query")
         @GetMapping("/{id}")
     public R<AiAgentVo> getInfo(@NotNull(message = "主键不能为空")
                                 @PathVariable("id") Long id) {
@@ -174,7 +174,7 @@ public class AiAgentController extends BaseController {
      *
      * @param id 智能体主键
      */
-        @SaCheckPermission("ai:agent:query")
+        @SaCheckPermission("ai:expert:query")
         @GetMapping("/{id}/trusted-tools")
     public R<List<AiAgentToolTrustVo>> trustedTools(@NotNull(message = "主键不能为空")
                                                     @PathVariable("id") Long id) {
@@ -188,7 +188,7 @@ public class AiAgentController extends BaseController {
      * @param userId   记住该工具的用户主键
      * @param toolCode 工具编码
      */
-            @SaCheckPermission("ai:agent:remove")
+            @SaCheckPermission(value = {"ai:agent:remove", "ai:expert:edit"}, mode = SaMode.OR)
             @DeleteMapping("/{id}/trusted-tools")
     public R<Void> revokeTrustedTool(@NotNull(message = "主键不能为空") @PathVariable("id") Long id,
                                      @NotNull(message = "用户不能为空") @RequestParam("userId") Long userId,
@@ -199,7 +199,7 @@ public class AiAgentController extends BaseController {
     /**
      * 新增专家定义
      */
-            @SaCheckPermission("ai:agent:edit")
+            @SaCheckPermission("ai:expert:edit")
             @PostMapping()
     public R<Void> add(@Validated(AddGroup.class) @RequestBody AiExpertAgentBo bo) {
         return toAjax(aiAgentService.insertByBo(bo));
@@ -208,7 +208,7 @@ public class AiAgentController extends BaseController {
     /**
      * 修改专家定义
      */
-            @SaCheckPermission("ai:agent:edit")
+            @SaCheckPermission("ai:expert:edit")
             @PutMapping()
     public R<Void> edit(@Validated(EditGroup.class) @RequestBody AiExpertAgentBo bo) {
         return toAjax(aiAgentService.updateByBo(bo));
@@ -219,7 +219,7 @@ public class AiAgentController extends BaseController {
      *
      * @param ids 主键串
      */
-            @SaCheckPermission("ai:agent:remove")
+            @SaCheckPermission("ai:expert:remove")
             @DeleteMapping("/{ids}")
     public R<Void> remove(@NotEmpty(message = "主键不能为空")
                           @PathVariable Long[] ids) {

+ 3 - 1
ai-server/src/main/java/com/zsjz/ai/module/ai/controller/AiKnowledgeBaseController.java

@@ -1,6 +1,7 @@
 package com.zsjz.ai.module.ai.controller;
 
 import cn.dev33.satoken.annotation.SaCheckPermission;
+import cn.dev33.satoken.annotation.SaMode;
 import jakarta.validation.constraints.NotEmpty;
 import jakarta.validation.constraints.NotNull;
 import lombok.RequiredArgsConstructor;
@@ -71,7 +72,8 @@ public class AiKnowledgeBaseController extends BaseController {
      * <p>生效范围口径与智能体一致(0 公开 / 1 本部门 / 2 仅本人):供智能体定义页的「绑定知识库」
      * 与检索测试页使用,避免绑定或测试到自己生效范围之外的知识库。</p>
      */
-        @SaCheckPermission("ai:kb:query")
+        @SaCheckPermission(value = {"ai:kb:query", "ai:expert:query", "ai:retrieval:query", "ai:doc:query"},
+            mode = SaMode.OR)
         @GetMapping("/visible-options")
     public R<List<AiKnowledgeBaseVo>> visibleOptions() {
         return R.ok(aiKnowledgeBaseService.queryVisibleOptions(LoginHelper.getUserId()));

+ 3 - 1
ai-server/src/main/java/com/zsjz/ai/module/ai/controller/AiModelConfigController.java

@@ -1,6 +1,7 @@
 package com.zsjz.ai.module.ai.controller;
 
 import cn.dev33.satoken.annotation.SaCheckPermission;
+import cn.dev33.satoken.annotation.SaMode;
 import jakarta.validation.constraints.NotEmpty;
 import jakarta.validation.constraints.NotNull;
 import lombok.RequiredArgsConstructor;
@@ -61,7 +62,8 @@ public class AiModelConfigController extends BaseController {
      *
      * @param modelType 模型类型,为空表示不限
      */
-        @SaCheckPermission("ai:model:query")
+        @SaCheckPermission(value = {"ai:model:query", "ai:agent:query", "ai:expert:query", "ai:kb:query"},
+            mode = SaMode.OR)
         @GetMapping("/options")
     public R<List<AiModelConfigVo>> options(@RequestParam(required = false) String modelType) {
         return R.ok(aiModelConfigService.queryOptions(modelType));

+ 2 - 1
ai-server/src/main/java/com/zsjz/ai/module/ai/controller/AiSkillController.java

@@ -1,6 +1,7 @@
 package com.zsjz.ai.module.ai.controller;
 
 import cn.dev33.satoken.annotation.SaCheckPermission;
+import cn.dev33.satoken.annotation.SaMode;
 import jakarta.validation.constraints.NotEmpty;
 import jakarta.validation.constraints.NotNull;
 import lombok.RequiredArgsConstructor;
@@ -61,7 +62,7 @@ public class AiSkillController extends BaseController {
      * <p>选项接口,唯一消费方是智能体定义页,故按「能进定义页即可读技能选项」的口径放行
      * (任一权限即可,与 {@code /ai/agent/tool/options}、{@code /ai/kb/visible-options} 一致)。</p>
      */
-        @SaCheckPermission("ai:skill:query")
+        @SaCheckPermission(value = {"ai:skill:query", "ai:expert:query"}, mode = SaMode.OR)
         @GetMapping("/visible-options")
     public R<List<AiSkillOptionVo>> visibleOptions() {
         return R.ok(aiSkillService.queryVisibleOptions(LoginHelper.getUserId()));

+ 2 - 0
test-reports-20261118-plan-retest/两份权限计划-功能复测报告-20261118.md

@@ -28,6 +28,8 @@
 > 说明:测试开始时后端 jar 构建时间 16:13,晚于全部 Java/资源源码,无需重新打包即可测试当前工作区代码。
 >
 > **收尾时服务状态复核(2026-11-18 17:45)**:测试结束后观察到 8980 端口一度下线(首次重启进程 PID 17796 已退出),随后由新进程 **PID 5760** 接管;`GET /js/a/sys/health` 返回 `{"code":200}`,前端 PID 3620 持续监听 3100。当前 jar 时间 17:44,无源码晚于该 jar,运行版本与工作区一致。测试期间及收尾均未修改代码。
+>
+> **版本边界声明(2026-11-18 19:57 补记)**:本报告生成后,工作区在 17:39–19:44 期间出现 **55 个源码文件的第三方改动**(主要在 `module/ai/**`、`workbench/views/agent/entry/index.vue`,另含 `common/model/perm/entity/SysRole.java`),后端 jar 已于 19:56 重新构建并由外部进程重启(当前 PID 17052)。这些改动不属于本次测试范围;**本报告的全部结论仅对应 16:13 构建的版本**。如需把新增改动纳入验收,需另起一轮复测。
 
 ---
 

+ 176 - 0
test-reports-20261118-visible-scope-retest/retest_api.py

@@ -0,0 +1,176 @@
+import json
+import urllib.error
+import urllib.request
+
+BASE = 'http://localhost:8980/js/a'
+D1 = '2123022706158374913'
+results = []
+
+
+def call(method, path, body=None, token=None):
+    data = json.dumps(body).encode() if body is not None else None
+    req = urllib.request.Request(BASE + path, data=data, method=method)
+    req.add_header('Content-Type', 'application/json')
+    if token:
+        req.add_header('x-token', token)
+    try:
+        with urllib.request.urlopen(req, timeout=30) as resp:
+            return json.loads(resp.read().decode())
+    except urllib.error.HTTPError as exc:
+        return {'http': exc.code, 'body': exc.read().decode()[:500]}
+
+
+def login(user, pwd):
+    resp = call('POST', '/auth/login', {'username': user, 'password': pwd, 'force': True})
+    if resp.get('code') != 200:
+        raise RuntimeError(f'login {user} failed: {resp}')
+    return resp['data']['token']
+
+
+def check(name, cond, detail=''):
+    results.append({'case': name, 'pass': bool(cond), 'detail': str(detail)[:500]})
+    print(('PASS' if cond else 'FAIL'), name, str(detail)[:300])
+
+
+def rows(path, token):
+    resp = call('GET', path, token=token)
+    return resp, (resp.get('data') or {}).get('rows') or []
+
+
+T = {
+    'admin': login('admin', 'admin123'),
+    'A': login('vsuserA', 'Vs1118pass'),
+    'B': login('vsuserB', 'Vs1118pass'),
+    'C': login('vsuserC', 'Vs1118pass'),
+    'D': login('vsuserD', 'Vs1118pass'),
+}
+
+# R1 D account permission set
+info = call('GET', '/auth/info', token=T['D'])
+perms = set((info.get('data') or {}).get('permissions') or [])
+check('R1 D permission set = expert only',
+      {'ai:expert:query', 'ai:expert:edit', 'ai:expert:remove'}.issubset(perms) and 'ai:agent:query' not in perms,
+      sorted(perms))
+
+# R2 D can list experts (previously 403)
+resp, list_d = rows('/ai/agent/list?pageSize=100', T['D'])
+codes = sorted(x['agentCode'] for x in list_d)
+check('R2 D expert list 200 and sees public+dept (2)', resp.get('code') == 200 and len(list_d) == 2, codes)
+
+# R3 option endpoints usable with expert permission only
+opt_paths = [
+    ('model', '/ai/model/options?modelType=chat'),
+    ('tool', '/ai/agent/tool/options'),
+    ('kb', '/ai/kb/visible-options'),
+    ('skill', '/ai/skill/visible-options'),
+]
+for name, path in opt_paths:
+    r = call('GET', path, token=T['D'])
+    check(f'R3 D option {name} 200', r.get('code') == 200 and len(r.get('data') or []) >= 0,
+          f"code={r.get('code')} n={len(r.get('data') or [])}")
+
+# R4 D create/update/delete own expert
+create_body = {
+    'agentName': 'VS复测仅专家角色专家', 'agentCode': 'vs_retest_d_expert',
+    'description': 'expert-only retest', 'modelId': 1761400000000020400, 'status': '0',
+    'visibleScope': '2', 'autoRoute': '1', 'memoryEnabled': '0', 'expertWriteEnabled': '1',
+}
+r = call('POST', '/ai/agent', create_body, T['D'])
+check('R4a D create own expert 200 (previously 403)', r.get('code') == 200, r)
+resp, list_d = rows('/ai/agent/list?pageSize=100', T['D'])
+own = [x for x in list_d if x['agentCode'] == 'vs_retest_d_expert']
+check('R4b D list contains own record and total=3', len(list_d) == 3 and len(own) == 1,
+      [x['agentCode'] for x in list_d])
+own_id = own[0]['id'] if own else None
+if own_id:
+    r = call('PUT', '/ai/agent', {
+        'id': own_id, 'agentName': 'VS复测仅专家角色专家改', 'agentCode': 'vs_retest_d_expert',
+        'modelId': 1761400000000020400, 'visibleScope': '2',
+    }, T['D'])
+    check('R4c D update own expert 200 (previously 403)', r.get('code') == 200, r)
+    resp, list_d = rows('/ai/agent/list?pageSize=100', T['D'])
+    own = [x for x in list_d if x['agentCode'] == 'vs_retest_d_expert']
+    check('R4d D update persisted', bool(own) and own[0]['agentName'] == 'VS复测仅专家角色专家改',
+          own[0]['agentName'] if own else None)
+    r = call('DELETE', '/ai/agent/' + own_id, token=T['D'])
+    check('R4e D delete own expert 200 (previously 403)', r.get('code') == 200, r)
+    resp, list_d = rows('/ai/agent/list?pageSize=100', T['D'])
+    check('R4f D list back to 2 after delete', len(list_d) == 2, [x['agentCode'] for x in list_d])
+
+# R5 entry remains ai:agent guarded (separation)
+r = call('GET', '/ai/agent/entry', token=T['D'])
+check('R5a D cannot read entry (403)', r.get('code') == 403, r)
+r = call('GET', '/ai/agent/entry', token=T['A'])
+check('R5b A can read entry with ai:agent:query', r.get('code') == 200, str(r.get('code')))
+
+# R6 D cannot manage A dept expert; canManage error should now be reached
+r = call('DELETE', '/ai/agent/2123022766514409473', token=T['D'])
+check('R6 D delete A dept expert rejected by canManage',
+      r.get('code') == 500 and '仅创建人或超级管理员' in (r.get('message') or ''), r)
+
+# R7 A delete own temp expert still works
+r = call('POST', '/ai/agent', {
+    'agentName': 'VS复测删除临时专家', 'agentCode': 'vs_retest_del_expert',
+    'description': 'delete retest', 'modelId': 1761400000000020400, 'status': '0',
+    'visibleScope': '2', 'autoRoute': '1', 'expertWriteEnabled': '1',
+}, T['A'])
+check('R7a A create temp expert 200', r.get('code') == 200, r)
+resp, list_a = rows('/ai/agent/list?pageSize=100', T['A'])
+temp = [x for x in list_a if x['agentCode'] == 'vs_retest_del_expert']
+if temp:
+    r = call('DELETE', '/ai/agent/' + temp[0]['id'], token=T['A'])
+    check('R7b A delete own expert 200', r.get('code') == 200, r)
+
+# R8 D creates dept-scope record: B sees, C does not; D can delete it
+r = call('POST', '/ai/agent', {
+    'agentName': 'VS复测部门专家', 'agentCode': 'vs_retest_dept_expert',
+    'description': 'dept retest', 'modelId': 1761400000000020400, 'status': '0',
+    'visibleScope': '1', 'ownerDeptId': D1, 'autoRoute': '1', 'expertWriteEnabled': '1',
+}, T['D'])
+check('R8a D create dept-scope expert 200', r.get('code') == 200, r)
+resp, list_b = rows('/ai/agent/list?pageSize=100', T['B'])
+resp, list_c = rows('/ai/agent/list?pageSize=100', T['C'])
+check('R8b B(D1) sees D dept record', any(x['agentCode'] == 'vs_retest_dept_expert' for x in list_b),
+      [x['agentCode'] for x in list_b])
+check('R8c C(D2) cannot see D dept record', all(x['agentCode'] != 'vs_retest_dept_expert' for x in list_c),
+      [x['agentCode'] for x in list_c])
+resp, list_d = rows('/ai/agent/list?pageSize=100', T['D'])
+dept_rec = [x for x in list_d if x['agentCode'] == 'vs_retest_dept_expert']
+if dept_rec:
+    check('R8d D sees canManage=true for own dept record', dept_rec[0]['canManage'] is True, dept_rec[0]['canManage'])
+    r = call('DELETE', '/ai/agent/' + dept_rec[0]['id'], token=T['D'])
+    check('R8e D delete own dept record 200', r.get('code') == 200, r)
+
+# R9 D cannot create public expert
+r = call('POST', '/ai/agent', {
+    'agentName': 'VS复测越权公开', 'agentCode': 'vs_retest_pub_try',
+    'description': 'x', 'modelId': 1761400000000020400, 'status': '0',
+    'visibleScope': '0', 'autoRoute': '1', 'expertWriteEnabled': '1',
+}, T['D'])
+check('R9 D create scope=0 rejected',
+      r.get('code') == 500 and '普通用户不能设置全员/公开可见' in (r.get('message') or ''), r)
+
+# R10 core list counts unchanged
+expected = {'A': 3, 'B': 2, 'C': 1, 'admin': 3}
+for user, exp in expected.items():
+    resp, list_rows = rows('/ai/agent/list?pageSize=100', T[user])
+    check(f'R10 expert list {user} count={exp}', resp.get('code') == 200 and len(list_rows) == exp,
+          [x['agentCode'] for x in list_rows])
+
+# R11 workbench expert candidates still filtered
+expected_candidates = {'A': 3, 'B': 2, 'C': 1, 'admin': 3}
+for user, exp in expected_candidates.items():
+    r = call('GET', '/ai/agent/experts/candidates', token=T[user])
+    check(f'R11 candidates {user} count={exp}', r.get('code') == 200 and len(r.get('data') or []) == exp,
+          len(r.get('data') or []))
+
+# cleanup any leftover retest records
+for user in ['A', 'D']:
+    resp, list_rows = rows('/ai/agent/list?pageSize=100', T[user])
+    for rec in list_rows:
+        if rec['agentCode'].startswith('vs_retest_'):
+            call('DELETE', '/ai/agent/' + rec['id'], token=T[user])
+
+json.dump(results, open('retest_api_results.json', 'w'), ensure_ascii=False, indent=2)
+print('TOTAL', len(results), 'PASS', sum(1 for x in results if x['pass']),
+      'FAIL', sum(1 for x in results if not x['pass']))

+ 157 - 0
test-reports-20261118-visible-scope-retest/retest_api_results.json

@@ -0,0 +1,157 @@
+[
+  {
+    "case": "R1 D permission set = expert only",
+    "pass": true,
+    "detail": "['ai:expert:edit', 'ai:expert:query', 'ai:expert:remove']"
+  },
+  {
+    "case": "R2 D expert list 200 and sees public+dept (2)",
+    "pass": true,
+    "detail": "['vs_expert_dept', 'vs_expert_pub']"
+  },
+  {
+    "case": "R3 D option model 200",
+    "pass": true,
+    "detail": "code=200 n=1"
+  },
+  {
+    "case": "R3 D option tool 200",
+    "pass": true,
+    "detail": "code=200 n=71"
+  },
+  {
+    "case": "R3 D option kb 200",
+    "pass": true,
+    "detail": "code=200 n=2"
+  },
+  {
+    "case": "R3 D option skill 200",
+    "pass": true,
+    "detail": "code=200 n=2"
+  },
+  {
+    "case": "R4a D create own expert 200 (previously 403)",
+    "pass": true,
+    "detail": "{'code': 200, 'msg': '操作成功', 'data': None}"
+  },
+  {
+    "case": "R4b D list contains own record and total=3",
+    "pass": true,
+    "detail": "['vs_retest_d_expert', 'vs_expert_dept', 'vs_expert_pub']"
+  },
+  {
+    "case": "R4c D update own expert 200 (previously 403)",
+    "pass": true,
+    "detail": "{'code': 200, 'msg': '操作成功', 'data': None}"
+  },
+  {
+    "case": "R4d D update persisted",
+    "pass": true,
+    "detail": "VS复测仅专家角色专家改"
+  },
+  {
+    "case": "R4e D delete own expert 200 (previously 403)",
+    "pass": true,
+    "detail": "{'code': 200, 'msg': '操作成功', 'data': None}"
+  },
+  {
+    "case": "R4f D list back to 2 after delete",
+    "pass": true,
+    "detail": "['vs_expert_dept', 'vs_expert_pub']"
+  },
+  {
+    "case": "R5a D cannot read entry (403)",
+    "pass": true,
+    "detail": "{'code': 403, 'message': '没有访问权限,请联系管理员授权', 'data': None}"
+  },
+  {
+    "case": "R5b A can read entry with ai:agent:query",
+    "pass": true,
+    "detail": "200"
+  },
+  {
+    "case": "R6 D delete A dept expert rejected by canManage",
+    "pass": true,
+    "detail": "{'code': 500, 'message': '无权操作该专家:仅创建人或超级管理员可操作', 'data': None}"
+  },
+  {
+    "case": "R7a A create temp expert 200",
+    "pass": true,
+    "detail": "{'code': 200, 'msg': '操作成功', 'data': None}"
+  },
+  {
+    "case": "R7b A delete own expert 200",
+    "pass": true,
+    "detail": "{'code': 200, 'msg': '操作成功', 'data': None}"
+  },
+  {
+    "case": "R8a D create dept-scope expert 200",
+    "pass": true,
+    "detail": "{'code': 200, 'msg': '操作成功', 'data': None}"
+  },
+  {
+    "case": "R8b B(D1) sees D dept record",
+    "pass": true,
+    "detail": "['vs_retest_dept_expert', 'vs_expert_dept', 'vs_expert_pub']"
+  },
+  {
+    "case": "R8c C(D2) cannot see D dept record",
+    "pass": true,
+    "detail": "['vs_expert_pub']"
+  },
+  {
+    "case": "R8d D sees canManage=true for own dept record",
+    "pass": true,
+    "detail": "True"
+  },
+  {
+    "case": "R8e D delete own dept record 200",
+    "pass": true,
+    "detail": "{'code': 200, 'msg': '操作成功', 'data': None}"
+  },
+  {
+    "case": "R9 D create scope=0 rejected",
+    "pass": true,
+    "detail": "{'code': 500, 'message': '普通用户不能设置全员/公开可见', 'data': None}"
+  },
+  {
+    "case": "R10 expert list A count=3",
+    "pass": true,
+    "detail": "['vs_expert_self', 'vs_expert_dept', 'vs_expert_pub']"
+  },
+  {
+    "case": "R10 expert list B count=2",
+    "pass": true,
+    "detail": "['vs_expert_dept', 'vs_expert_pub']"
+  },
+  {
+    "case": "R10 expert list C count=1",
+    "pass": true,
+    "detail": "['vs_expert_pub']"
+  },
+  {
+    "case": "R10 expert list admin count=3",
+    "pass": true,
+    "detail": "['vs_expert_self', 'vs_expert_dept', 'vs_expert_pub']"
+  },
+  {
+    "case": "R11 candidates A count=3",
+    "pass": true,
+    "detail": "3"
+  },
+  {
+    "case": "R11 candidates B count=2",
+    "pass": true,
+    "detail": "2"
+  },
+  {
+    "case": "R11 candidates C count=1",
+    "pass": true,
+    "detail": "1"
+  },
+  {
+    "case": "R11 candidates admin count=3",
+    "pass": true,
+    "detail": "3"
+  }
+]

+ 97 - 0
test-reports-20261118-visible-scope-retest/智能体可见范围-修复复测报告-20261118.md

@@ -0,0 +1,97 @@
+# 智能体「可见范围」权限修复 · 复测报告(2026-11-18 20:45)
+
+- 复测对象:上一轮报告 `test-reports-20261118-visible-scope/智能体可见范围-功能测试报告-20261118.md` 中的 P1/P2 问题
+- 修复内容(用户工作区改动,本次未改代码):
+  - `AiAgentController`:专家列表/详情改为 `ai:expert:query`,新增/修改改为 `ai:expert:edit`,删除改为 `ai:expert:remove`;工具选项改为 `ai:agent:query` / `ai:expert:query` OR;撤销已记住工具改为 `ai:agent:remove` / `ai:expert:edit` OR。
+  - `AiModelConfigController`、`AiSkillController`、`AiKnowledgeBaseController`:模型/技能/知识库的只读选项接口增加 `ai:expert:query` 等 OR 口径,解决专家表单依赖权限缺口。
+- 结论:**P1、P2 均已修复,31/31 接口断言通过,UI 创建/删除链路通过;未发现新增缺陷。**
+
+---
+
+## 1. 环境与服务
+
+| 项 | 值 |
+|---|---|
+| 后端 jar | 2026-11-18 **20:45:20** 重新打包成功,594,268,342 字节;`ai-server/src` 无文件晚于 jar |
+| 后端进程 | PID **16032**,20:45:28 启动;`GET /js/a/sys/health` → `{"code":200}`(2s 内就绪) |
+| 前端 | Vite 7.2.7,PID **15484**,20:45:29 启动;`http://localhost:3100` 返回 200 |
+| 数据库 | PostgreSQL `192.168.0.106:5432/zsjz-ai`,沿用上一轮测试数据 |
+| 浏览器 | ZCode In-app Browser,1600×1000 |
+
+> 重启操作:终止旧 PID 9740(后端)/ 13436(前端)→ `mvn -pl ai-server -am -DskipTests package`(BUILD SUCCESS,24.5s)→ 启动新前后端。测试期间未修改业务代码。
+
+---
+
+## 2. 修复验证:仅专家菜单账号(P1)
+
+账号 `vsuserD`(角色 `vsonlyexpert`,仅持有 `ai:expert:query/edit/remove`)复测结果:
+
+| # | 用例 | 修复前 | 复测结果 |
+|---|---|---|---|
+| R1 | 权限集合 | 仅 expert 三码 | 通过:`['ai:expert:edit','ai:expert:query','ai:expert:remove']`,无 `ai:agent:query` |
+| R2 | `GET /ai/agent/list` | 403,页面空白 | **200**,返回 2 条(公开 + D1 部门) |
+| R3 | 模型/工具/知识库/技能选项 | 全部 403,表单不可用 | **全部 200**:模型 1、业务工具 71、知识库 2、技能 2 |
+| R4a | 新增自有专家(scope=2) | 403 | **200** |
+| R4b | 列表出现自有记录 | — | 通过(共 3 条,`canManage=true`) |
+| R4c | 修改自有专家 | 403 | **200**,名称更新生效 |
+| R4d | 删除自有专家 | 403 | **200**,列表回到 2 条 |
+| R5a | 读取数剑入口 `/ai/agent/entry` | 403(预期) | **403**,入口仍受 `ai:agent:query` 保护 |
+| R5b | A(有数剑配置权限)读取入口 | 200 | **200** |
+| R6 | 删除 A 的 D1 部门专家 | 403(权限码挡住,未到归属校验) | **500「无权操作该专家:仅创建人或超级管理员可操作」**,归属校验正确生效 |
+| R7 | A 新增/删除自有专家 | 删除 403 | **新增 200、删除 200** |
+| R8 | D 创建 ownerDept=D1 的部门专家 | — | 200;B(D1) 可见、C(D2) 不可见;D 可删除 |
+| R9 | D 直接提交 scope=0 | — | 仍被拒「普通用户不能设置全员/公开可见」 |
+
+**修复前证据**:`../test-reports-20261118-visible-scope/screenshots/25-userD-expert-only-403.png`、`26-userA-expert-delete-403.png`
+**修复后证据**:
+- UI 列表恢复 2 条、无选项加载失败提示:`screenshots/01-userD-expert-list-fixed.png`
+- UI 新增成功(默认「仅创建人」):`screenshots/02-userD-create-success.png`
+- UI 删除成功(列表回到 2 条):`screenshots/03-userD-delete-success.png`
+
+---
+
+## 3. 数据权限回归
+
+| # | 用例 | 结果 |
+|---|---|---|
+| G1 | 专家详情可见性:D 看 A「仅本人」→ 500;A 部门专家/公开专家 → 200 | 通过 |
+| G2 | D 改 A 部门专家 → 500「无权操作该专家…」 | 通过 |
+| G3 | D 创建「本部门」不传 ownerDept → 后端回填 D1;B 可见、C 不可见 | 通过 |
+| G4 | 列表数量:A=3、B=2、C=1、admin=3 | 通过 |
+| G5 | 自动候选:A=3、B=2、C=1、admin=3 | 通过 |
+| G6 | 越权 scope=0 创建 → 500「普通用户不能设置全员/公开可见」 | 通过 |
+| G7 | 数剑入口不受可见范围运行时过滤(D 无 agent 权限故 403;A 仍可读取;入口本身 scope 恢复 '0') | 通过 |
+
+---
+
+## 4. 复测统计
+
+- 自动化接口断言:**31/31 通过**(`retest_api_results.json`)
+- UI 目标链路:3/3 通过(列表、新增、删除)
+- 前端类型检查:仍为 **68 个既有错误**,均不涉及可见范围相关文件(`frontend-typecheck.log`),与上一轮一致,无新增错误
+- 后端日志:仅有预期的权限不足/业务校验 WARN,无 ERROR/堆栈异常
+- 残留数据:`vs_retest_*` 测试记录已全部清理;专家 3 条基线测试记录(VS公开/部门/自建)保留
+
+---
+
+## 5. 结论与残留
+
+1. **P1 已解决**:仅授予专家配置菜单的普通用户现在可以正常列表、新增、修改、删除自己的专家;创建人删除不再返回 403。
+2. **P2 已解决**:专家表单所需的模型/工具/知识库/技能选项接口对 `ai:expert:query` 放行,专家单页权限即可完成配置。
+3. **数剑权限隔离保持**:入口仍要求 `ai:agent:*`,专家权限不会越权修改入口。
+4. **可见范围核心逻辑无回归**:列表/详情/候选/部门与仅本人隔离、普通用户禁止公开、ownerDept 回填均正常。
+5. **残留非阻断项**:`pnpm type:check` 的 68 个既有类型错误(trans/dm 等既有页面)仍存在,不属于本次修复范围;建议单独治理。
+
+---
+
+## 6. 证据文件
+
+| 文件 | 说明 |
+|---|---|
+| `retest_api_results.json` | 31 项接口断言明细 |
+| `retest_api.py` | 复测脚本 |
+| `screenshots/01-userD-expert-list-fixed.png` | D 列表 2 条,无 403/选项错误 |
+| `screenshots/02-userD-create-success.png` | D UI 新增成功(默认仅创建人) |
+| `screenshots/03-userD-delete-success.png` | D UI 删除成功,列表回到 2 条 |
+| `frontend-typecheck.log` | 68 个既有类型错误(无可见范围文件) |
+| `backend-build.log` / `frontend-start.log` | 重启构建与启动日志 |

+ 437 - 0
test-reports-20261118-visible-scope/api-results.json

@@ -0,0 +1,437 @@
+[
+  {
+    "case": "T1 admin scope-options superAdmin=true + depts",
+    "pass": true,
+    "detail": "{\"code\": 200, \"msg\": \"操作成功\", \"data\": {\"superAdmin\": true, \"depts\": [{\"id\": \"100\", \"parentId\": \"0\", \"label\": \"总部\", \"weight\": 0, \"disabled\": false, \"children\": [{\"id\": \"101\", \"parentId\": \"100\", \"label\":"
+  },
+  {
+    "case": "T2 normal scope-options superAdmin=false + depts",
+    "pass": true,
+    "detail": "{\"code\": 200, \"msg\": \"操作成功\", \"data\": {\"superAdmin\": false, \"depts\": [{\"id\": \"100\", \"parentId\": \"0\", \"label\": \"总部\", \"weight\": 0, \"disabled\": false, \"children\": [{\"id\": \"101\", \"parentId\": \"100\", \"label\""
+  },
+  {
+    "case": "T3 expert list A total=3",
+    "pass": true,
+    "detail": "names=VS自建专家,VS部门专家,VS公开专家"
+  },
+  {
+    "case": "T3 expert list B total=2",
+    "pass": true,
+    "detail": "names=VS部门专家,VS公开专家"
+  },
+  {
+    "case": "T3 expert list C total=1",
+    "pass": true,
+    "detail": "names=VS公开专家"
+  },
+  {
+    "case": "T3 expert list admin total=3",
+    "pass": true,
+    "detail": "names=VS自建专家,VS部门专家,VS公开专家"
+  },
+  {
+    "case": "T3 skill list A total=3",
+    "pass": true,
+    "detail": "names=vs_skill_self,vs_skill_dept,vs_skill_pub"
+  },
+  {
+    "case": "T3 skill list B total=2",
+    "pass": true,
+    "detail": "names=vs_skill_dept,vs_skill_pub"
+  },
+  {
+    "case": "T3 skill list C total=1",
+    "pass": true,
+    "detail": "names=vs_skill_pub"
+  },
+  {
+    "case": "T3 skill list admin total=3",
+    "pass": true,
+    "detail": "names=vs_skill_self,vs_skill_dept,vs_skill_pub"
+  },
+  {
+    "case": "T3 pack list A total=3",
+    "pass": true,
+    "detail": "names=VS自建场景包,VS部门场景包,VS公开场景包"
+  },
+  {
+    "case": "T3 pack list B total=2",
+    "pass": true,
+    "detail": "names=VS部门场景包,VS公开场景包"
+  },
+  {
+    "case": "T3 pack list C total=1",
+    "pass": true,
+    "detail": "names=VS公开场景包"
+  },
+  {
+    "case": "T3 pack list admin total=3",
+    "pass": false,
+    "detail": "names=VS自建场景包,VS部门场景包,VS公开场景包,sdfsdf"
+  },
+  {
+    "case": "T3 kb list A total=3",
+    "pass": true,
+    "detail": "names=VS自建知识库,VS部门知识库,VS公开知识库"
+  },
+  {
+    "case": "T3 kb list B total=2",
+    "pass": true,
+    "detail": "names=VS部门知识库,VS公开知识库"
+  },
+  {
+    "case": "T3 kb list C total=1",
+    "pass": true,
+    "detail": "names=VS公开知识库"
+  },
+  {
+    "case": "T3 kb list admin total=3",
+    "pass": true,
+    "detail": "names=VS自建知识库,VS部门知识库,VS公开知识库"
+  },
+  {
+    "case": "T4 B cannot manage A dept expert",
+    "pass": true,
+    "detail": "False"
+  },
+  {
+    "case": "T4 B cannot manage admin public expert",
+    "pass": true,
+    "detail": "False"
+  },
+  {
+    "case": "T4 A can manage own dept/self expert",
+    "pass": true,
+    "detail": ""
+  },
+  {
+    "case": "T4 A cannot manage admin public expert",
+    "pass": true,
+    "detail": ""
+  },
+  {
+    "case": "T5 B cannot view A self expert_self",
+    "pass": true,
+    "detail": "{\"code\": 500, \"message\": \"智能体不存在或不在你的可见范围内\", \"data\": null}"
+  },
+  {
+    "case": "T5 B cannot view A self skill_self",
+    "pass": true,
+    "detail": "{\"code\": 500, \"message\": \"技能不存在或不在你的可见范围内\", \"data\": null}"
+  },
+  {
+    "case": "T5 B cannot view A self pack_self",
+    "pass": true,
+    "detail": "{\"code\": 500, \"message\": \"场景包不存在或不在你的可见范围内\", \"data\": null}"
+  },
+  {
+    "case": "T5 B cannot view A self kb_self",
+    "pass": true,
+    "detail": "{\"code\": 500, \"message\": \"知识库不存在或不在你的可见范围内\", \"data\": null}"
+  },
+  {
+    "case": "T5 B can view dept expert_dept",
+    "pass": true,
+    "detail": "200"
+  },
+  {
+    "case": "T5 B can view dept skill_dept",
+    "pass": true,
+    "detail": "200"
+  },
+  {
+    "case": "T5 B can view dept pack_dept",
+    "pass": true,
+    "detail": "200"
+  },
+  {
+    "case": "T5 B can view dept kb_dept",
+    "pass": true,
+    "detail": "200"
+  },
+  {
+    "case": "T5 C(D2) cannot view D1 dept expert_dept",
+    "pass": true,
+    "detail": "{\"code\": 500, \"message\": \"智能体不存在或不在你的可见范围内\", \"data\": null}"
+  },
+  {
+    "case": "T5 C(D2) cannot view D1 dept skill_dept",
+    "pass": true,
+    "detail": "{\"code\": 500, \"message\": \"技能不存在或不在你的可见范围内\", \"data\": null}"
+  },
+  {
+    "case": "T5 C(D2) cannot view D1 dept pack_dept",
+    "pass": true,
+    "detail": "{\"code\": 500, \"message\": \"场景包不存在或不在你的可见范围内\", \"data\": null}"
+  },
+  {
+    "case": "T5 C(D2) cannot view D1 dept kb_dept",
+    "pass": true,
+    "detail": "{\"code\": 500, \"message\": \"知识库不存在或不在你的可见范围内\", \"data\": null}"
+  },
+  {
+    "case": "T5 C can view public expert_pub",
+    "pass": true,
+    "detail": "200"
+  },
+  {
+    "case": "T5 C can view public skill_pub",
+    "pass": true,
+    "detail": "200"
+  },
+  {
+    "case": "T5 C can view public pack_pub",
+    "pass": true,
+    "detail": "200"
+  },
+  {
+    "case": "T5 C can view public kb_pub",
+    "pass": true,
+    "detail": "200"
+  },
+  {
+    "case": "T6 B update A dept expert rejected",
+    "pass": true,
+    "detail": "{\"code\": 500, \"message\": \"无权操作该专家:仅创建人或超级管理员可操作\", \"data\": null}"
+  },
+  {
+    "case": "T6 C update A dept expert rejected",
+    "pass": true,
+    "detail": "{\"code\": 500, \"message\": \"无权操作该专家:仅创建人或超级管理员可操作\", \"data\": null}"
+  },
+  {
+    "case": "T6 admin update A dept expert allowed",
+    "pass": true,
+    "detail": "{\"code\": 200, \"msg\": \"操作成功\", \"data\": null}"
+  },
+  {
+    "case": "T6 A update own expert allowed",
+    "pass": true,
+    "detail": "{\"code\": 200, \"msg\": \"操作成功\", \"data\": null}"
+  },
+  {
+    "case": "T7 A set own expert scope=0 rejected",
+    "pass": true,
+    "detail": "{\"code\": 500, \"message\": \"普通用户不能设置全员/公开可见\", \"data\": null}"
+  },
+  {
+    "case": "T7 A set invalid scope=9 rejected",
+    "pass": true,
+    "detail": "{\"http\": 400, \"body\": \"{\\\"code\\\":400,\\\"message\\\":\\\"可见范围只能是 0、1 或 2\\\",\\\"data\\\":null}\"}"
+  },
+  {
+    "case": "T7 A blank scope inherits 2",
+    "pass": true,
+    "detail": "{\"code\": 200, \"msg\": \"操作成功\", \"data\": null}"
+  },
+  {
+    "case": "T7 self expert scope still 2",
+    "pass": true,
+    "detail": "2"
+  },
+  {
+    "case": "T8 visible experts A count=3",
+    "pass": true,
+    "detail": "n=3"
+  },
+  {
+    "case": "T8 visible experts B count=2",
+    "pass": false,
+    "detail": "n=1"
+  },
+  {
+    "case": "T8 visible experts C count=1",
+    "pass": true,
+    "detail": "n=1"
+  },
+  {
+    "case": "T8 visible experts admin count=3",
+    "pass": true,
+    "detail": "n=3"
+  },
+  {
+    "case": "T8 candidates A count=3",
+    "pass": true,
+    "detail": "n=3"
+  },
+  {
+    "case": "T8 candidates B count=2",
+    "pass": false,
+    "detail": "n=1"
+  },
+  {
+    "case": "T8 candidates C count=1",
+    "pass": true,
+    "detail": "n=1"
+  },
+  {
+    "case": "T8 candidates admin count=3",
+    "pass": true,
+    "detail": "n=3"
+  },
+  {
+    "case": "T8 skill options A count=3",
+    "pass": true,
+    "detail": "n=3"
+  },
+  {
+    "case": "T8 skill options B count=2",
+    "pass": true,
+    "detail": "n=2"
+  },
+  {
+    "case": "T8 skill options C count=1",
+    "pass": true,
+    "detail": "n=1"
+  },
+  {
+    "case": "T8 skill options admin count=3",
+    "pass": true,
+    "detail": "n=3"
+  },
+  {
+    "case": "T8 pack options A count=3",
+    "pass": true,
+    "detail": "n=3"
+  },
+  {
+    "case": "T8 pack options B count=2",
+    "pass": true,
+    "detail": "n=2"
+  },
+  {
+    "case": "T8 pack options C count=1",
+    "pass": true,
+    "detail": "n=1"
+  },
+  {
+    "case": "T8 pack options admin count=3",
+    "pass": false,
+    "detail": "n=4"
+  },
+  {
+    "case": "T8 kb options A count=3",
+    "pass": true,
+    "detail": "n=3"
+  },
+  {
+    "case": "T8 kb options B count=2",
+    "pass": true,
+    "detail": "n=2"
+  },
+  {
+    "case": "T8 kb options C count=1",
+    "pass": true,
+    "detail": "n=1"
+  },
+  {
+    "case": "T8 kb options admin count=3",
+    "pass": true,
+    "detail": "n=3"
+  },
+  {
+    "case": "T8 kb full options 3 for C",
+    "pass": true,
+    "detail": "n=3"
+  },
+  {
+    "case": "T9 B doc list dept kb allowed(empty ok)",
+    "pass": true,
+    "detail": "{\"code\": 200, \"msg\": \"操作成功\", \"data\": {\"total\": \"0\", \"rows\": []}}"
+  },
+  {
+    "case": "T9 C doc list dept kb returns empty",
+    "pass": true,
+    "detail": "{\"code\": 200, \"msg\": \"操作成功\", \"data\": {\"total\": \"0\", \"rows\": []}}"
+  },
+  {
+    "case": "T9 B doc list A self kb empty",
+    "pass": true,
+    "detail": "{\"code\": 200, \"msg\": \"操作成功\", \"data\": {\"total\": \"0\", \"rows\": []}}"
+  },
+  {
+    "case": "T10 entry readable",
+    "pass": true,
+    "detail": "1761400000000020302"
+  },
+  {
+    "case": "T10 admin save entry scope=1",
+    "pass": true,
+    "detail": "{\"code\": 200, \"msg\": \"操作成功\", \"data\": null}"
+  },
+  {
+    "case": "T10 entry scope persisted=1",
+    "pass": true,
+    "detail": "1/2123022706158374913"
+  },
+  {
+    "case": "T10 entry still offered to B despite dept scope",
+    "pass": true,
+    "detail": "['entry_agent', 'vs_expert_pub']"
+  },
+  {
+    "case": "T10 normal user A can save entry (no creator check)",
+    "pass": true,
+    "detail": "{\"code\": 200, \"msg\": \"操作成功\", \"data\": null}"
+  },
+  {
+    "case": "T10 admin restore entry scope=0",
+    "pass": true,
+    "detail": "{\"code\": 200, \"msg\": \"操作成功\", \"data\": null}"
+  },
+  {
+    "case": "T11 create admin record ownerDept=D2",
+    "pass": true,
+    "detail": "{\"code\": 200, \"msg\": \"操作成功\", \"data\": null}"
+  },
+  {
+    "case": "T11 D2 record hidden from A(D1)",
+    "pass": true,
+    "detail": "nA=3"
+  },
+  {
+    "case": "T11 D2 record visible to C(D2)",
+    "pass": true,
+    "detail": "['vs_expert_d2', 'vs_expert_pub']"
+  },
+  {
+    "case": "T12 create skill without scope ok",
+    "pass": true,
+    "detail": "{\"code\": 200, \"msg\": \"操作成功\", \"data\": null}"
+  },
+  {
+    "case": "T12 default scope=2 for normal user",
+    "pass": true,
+    "detail": "2"
+  },
+  {
+    "case": "T13 create temp skill",
+    "pass": true,
+    "detail": ""
+  },
+  {
+    "case": "T13 B delete A skill rejected",
+    "pass": true,
+    "detail": "{\"code\": 500, \"message\": \"无权操作该技能:仅创建人或超级管理员可操作\", \"data\": null}"
+  },
+  {
+    "case": "T13 C delete A skill rejected",
+    "pass": true,
+    "detail": "{\"code\": 500, \"message\": \"无权操作该技能:仅创建人或超级管理员可操作\", \"data\": null}"
+  },
+  {
+    "case": "T13 A delete own skill allowed",
+    "pass": true,
+    "detail": "{\"code\": 200, \"msg\": \"操作成功\", \"data\": null}"
+  },
+  {
+    "case": "T13 cleanup default skill",
+    "pass": true,
+    "detail": ""
+  },
+  {
+    "case": "T13 cleanup d2 expert",
+    "pass": true,
+    "detail": ""
+  }
+]

+ 82 - 0
test-reports-20261118-visible-scope/create-results.json

@@ -0,0 +1,82 @@
+{
+  "expert_pub": {
+    "code": 200,
+    "msg": "操作成功",
+    "data": null
+  },
+  "skill_pub": {
+    "code": 200,
+    "msg": "操作成功",
+    "data": null
+  },
+  "pack_pub": {
+    "code": 200,
+    "msg": "操作成功",
+    "data": null
+  },
+  "kb_pub": {
+    "code": 200,
+    "msg": "操作成功",
+    "data": null
+  },
+  "expert_dept": {
+    "code": 200,
+    "msg": "操作成功",
+    "data": null
+  },
+  "skill_dept": {
+    "code": 200,
+    "msg": "操作成功",
+    "data": null
+  },
+  "pack_dept": {
+    "code": 200,
+    "msg": "操作成功",
+    "data": null
+  },
+  "kb_dept": {
+    "code": 200,
+    "msg": "操作成功",
+    "data": null
+  },
+  "expert_self": {
+    "code": 200,
+    "msg": "操作成功",
+    "data": null
+  },
+  "skill_self": {
+    "code": 200,
+    "msg": "操作成功",
+    "data": null
+  },
+  "pack_self": {
+    "code": 200,
+    "msg": "操作成功",
+    "data": null
+  },
+  "kb_self": {
+    "code": 200,
+    "msg": "操作成功",
+    "data": null
+  },
+  "A_expert_pub_try": {
+    "code": 500,
+    "message": "普通用户不能设置全员/公开可见",
+    "data": null
+  },
+  "A_skill_pub_try": {
+    "code": 500,
+    "message": "普通用户不能设置全员/公开可见",
+    "data": null
+  },
+  "A_pack_pub_try": {
+    "code": 500,
+    "message": "普通用户不能设置全员/公开可见",
+    "data": null
+  },
+  "A_kb_pub_try": {
+    "code": 500,
+    "message": "普通用户不能设置全员/公开可见",
+    "data": null
+  }
+}

+ 235 - 0
test-reports-20261118-visible-scope/scripts/api_tests.py

@@ -0,0 +1,235 @@
+import json, urllib.request, urllib.error
+
+BASE = 'http://localhost:8980/js/a'
+
+
+def call(m, p, b=None, t=None):
+    d = json.dumps(b).encode() if b is not None else None
+    r = urllib.request.Request(BASE + p, data=d, method=m)
+    r.add_header('Content-Type', 'application/json')
+    if t:
+        r.add_header('x-token', t)
+    try:
+        with urllib.request.urlopen(r, timeout=30) as x:
+            return json.loads(x.read().decode())
+    except urllib.error.HTTPError as e:
+        return {'http': e.code, 'body': e.read().decode()[:300]}
+
+
+def login(u, p):
+    return call('POST', '/auth/login', {'username': u, 'password': p, 'force': True})['data']['token']
+
+
+T = {
+    'admin': login('admin', 'admin123'),
+    'A': login('vsuserA', 'Vs1118pass'),
+    'B': login('vsuserB', 'Vs1118pass'),
+    'C': login('vsuserC', 'Vs1118pass'),
+}
+D1 = '2123022706158374913'
+D2 = '2123022706573611010'
+ids = {
+    'expert_pub': '2123022764635361281', 'expert_dept': '2123022766514409473',
+    'expert_self': '2123022768359903234',
+    'skill_pub': '2123022765163843585', 'skill_dept': '2123022767038697473',
+    'skill_self': '2123022768850636802',
+    'pack_pub': '2123022765524553730', 'pack_dept': '2123022767378436098',
+    'pack_self': '2123022769240707074',
+    'kb_pub': '2123022766036258817', 'kb_dept': '2123022767873363969',
+    'kb_self': '2123022769697886209',
+}
+results = []
+
+
+def check(name, cond, detail=''):
+    results.append({'case': name, 'pass': bool(cond), 'detail': detail})
+    print(('PASS' if cond else 'FAIL'), name, str(detail)[:300])
+
+
+def list_rows(path, t):
+    r = call('GET', path, t=t)
+    return r, (r.get('data') or {}).get('rows') or []
+
+
+# T1/T2 scope options
+r = call('GET', '/ai/agent/scope-options', t=T['admin'])
+check('T1 admin scope-options superAdmin=true + depts',
+      r.get('code') == 200 and r['data']['superAdmin'] is True and len(r['data']['depts']) > 0,
+      json.dumps(r, ensure_ascii=False)[:200])
+r = call('GET', '/ai/agent/scope-options', t=T['A'])
+check('T2 normal scope-options superAdmin=false + depts',
+      r.get('code') == 200 and r['data']['superAdmin'] is False and len(r['data']['depts']) > 0,
+      json.dumps(r, ensure_ascii=False)[:200])
+
+# T3 list visibility counts
+for kind, path in [('expert', '/ai/agent/list?pageSize=100'), ('skill', '/ai/skill/list?pageSize=100'),
+                   ('pack', '/ai/pack/list?pageSize=100'), ('kb', '/ai/kb/list?pageSize=100')]:
+    for u, exp in [('A', 3), ('B', 2), ('C', 1), ('admin', 3)]:
+        r, rows = list_rows(path, T[u])
+        names = [x.get('agentName') or x.get('name') or x.get('packName') or x.get('kbName') for x in rows]
+        check(f'T3 {kind} list {u} total={exp}', r.get('code') == 200 and len(rows) == exp, 'names=' + ','.join(names))
+
+# T4 canManage flags
+_, rows = list_rows('/ai/agent/list?pageSize=100', T['B'])
+by = {x['agentCode']: x for x in rows}
+check('T4 B cannot manage A dept expert', by['vs_expert_dept']['canManage'] is False, str(by['vs_expert_dept'].get('canManage')))
+check('T4 B cannot manage admin public expert', by['vs_expert_pub']['canManage'] is False, str(by['vs_expert_pub'].get('canManage')))
+_, rows = list_rows('/ai/agent/list?pageSize=100', T['A'])
+byA = {x['agentCode']: x for x in rows}
+check('T4 A can manage own dept/self expert',
+      byA['vs_expert_dept']['canManage'] is True and byA['vs_expert_self']['canManage'] is True, '')
+check('T4 A cannot manage admin public expert', byA['vs_expert_pub']['canManage'] is False, '')
+
+# T5 detail visibility
+for key, path in [('expert_self', '/ai/agent/'), ('skill_self', '/ai/skill/'),
+                  ('pack_self', '/ai/pack/'), ('kb_self', '/ai/kb/')]:
+    r = call('GET', path + ids[key], t=T['B'])
+    check(f'T5 B cannot view A self {key}', r.get('code') == 500, json.dumps(r, ensure_ascii=False)[:160])
+for key, path in [('expert_dept', '/ai/agent/'), ('skill_dept', '/ai/skill/'),
+                  ('pack_dept', '/ai/pack/'), ('kb_dept', '/ai/kb/')]:
+    r = call('GET', path + ids[key], t=T['B'])
+    check(f'T5 B can view dept {key}', r.get('code') == 200 and r['data'] is not None, str(r.get('code')))
+for key, path in [('expert_dept', '/ai/agent/'), ('skill_dept', '/ai/skill/'),
+                  ('pack_dept', '/ai/pack/'), ('kb_dept', '/ai/kb/')]:
+    r = call('GET', path + ids[key], t=T['C'])
+    check(f'T5 C(D2) cannot view D1 dept {key}', r.get('code') == 500, json.dumps(r, ensure_ascii=False)[:160])
+for key, path in [('expert_pub', '/ai/agent/'), ('skill_pub', '/ai/skill/'),
+                  ('pack_pub', '/ai/pack/'), ('kb_pub', '/ai/kb/')]:
+    r = call('GET', path + ids[key], t=T['C'])
+    check(f'T5 C can view public {key}', r.get('code') == 200, str(r.get('code')))
+
+# T6 update authorization
+expert_body = lambda scope, oid=None: {
+    'id': ids['expert_dept'], 'agentName': 'VS部门专家', 'agentCode': 'vs_expert_dept',
+    'modelId': 1761400000000020400, 'visibleScope': scope, 'ownerDeptId': oid}
+r = call('PUT', '/ai/agent', expert_body('1', D1), T['B'])
+check('T6 B update A dept expert rejected',
+      r.get('code') == 500 and '仅创建人或超级管理员' in (r.get('message') or ''),
+      json.dumps(r, ensure_ascii=False)[:200])
+r = call('PUT', '/ai/agent', expert_body('1', D1), T['C'])
+check('T6 C update A dept expert rejected', r.get('code') == 500, json.dumps(r, ensure_ascii=False)[:200])
+r = call('PUT', '/ai/agent', expert_body('1', D1), T['admin'])
+check('T6 admin update A dept expert allowed', r.get('code') == 200, json.dumps(r, ensure_ascii=False)[:200])
+r = call('PUT', '/ai/agent', expert_body('2', None), T['A'])
+check('T6 A update own expert allowed', r.get('code') == 200, json.dumps(r, ensure_ascii=False)[:200])
+
+# T7 normal user cannot set 0 on own record; invalid rejected; blank inherits
+r = call('PUT', '/ai/agent', {'id': ids['expert_self'], 'agentName': 'VS自建专家',
+                              'agentCode': 'vs_expert_self', 'modelId': 1761400000000020400,
+                              'visibleScope': '0'}, T['A'])
+check('T7 A set own expert scope=0 rejected',
+      r.get('code') == 500 and '普通用户不能设置全员/公开可见' in (r.get('message') or ''),
+      json.dumps(r, ensure_ascii=False)[:200])
+r = call('PUT', '/ai/agent', {'id': ids['expert_self'], 'agentName': 'VS自建专家',
+                              'agentCode': 'vs_expert_self', 'modelId': 1761400000000020400,
+                              'visibleScope': '9'}, T['A'])
+check('T7 A set invalid scope=9 rejected', r.get('code') != 200, json.dumps(r, ensure_ascii=False)[:200])
+r = call('PUT', '/ai/agent', {'id': ids['expert_self'], 'agentName': 'VS自建专家',
+                              'agentCode': 'vs_expert_self', 'modelId': 1761400000000020400}, T['A'])
+check('T7 A blank scope inherits 2', r.get('code') == 200, json.dumps(r, ensure_ascii=False)[:200])
+r = call('GET', '/ai/agent/' + ids['expert_self'], t=T['A'])
+check('T7 self expert scope still 2', r.get('code') == 200 and r['data']['visibleScope'] == '2',
+      str((r.get('data') or {}).get('visibleScope')))
+
+# T8 workbench options filtered
+for path, label in [('/ai/agent/experts', 'visible experts'),
+                    ('/ai/agent/experts/candidates', 'candidates'),
+                    ('/ai/skill/visible-options', 'skill options'),
+                    ('/ai/pack/options', 'pack options'),
+                    ('/ai/kb/visible-options', 'kb options')]:
+    for u, exp in [('A', 3), ('B', 2), ('C', 1), ('admin', 3)]:
+        r = call('GET', path, t=T[u])
+        n = len(r.get('data') or [])
+        check(f'T8 {label} {u} count={exp}', r.get('code') == 200 and n == exp, f'n={n}')
+r = call('GET', '/ai/kb/options', t=T['C'])
+check('T8 kb full options 3 for C', r.get('code') == 200 and len(r.get('data') or []) == 3,
+      f"n={len(r.get('data') or [])}")
+
+# T9 doc list filtering
+r = call('GET', f'/ai/kb/doc/list?kbId={ids["kb_dept"]}&pageSize=20', t=T['B'])
+check('T9 B doc list dept kb allowed(empty ok)',
+      r.get('code') == 200 and len((r.get('data') or {}).get('rows') or []) == 0,
+      json.dumps(r, ensure_ascii=False)[:200])
+r = call('GET', f'/ai/kb/doc/list?kbId={ids["kb_dept"]}&pageSize=20', t=T['C'])
+check('T9 C doc list dept kb returns empty',
+      r.get('code') == 200 and len((r.get('data') or {}).get('rows') or []) == 0,
+      json.dumps(r, ensure_ascii=False)[:200])
+r = call('GET', f'/ai/kb/doc/list?kbId={ids["kb_self"]}&pageSize=20', t=T['B'])
+check('T9 B doc list A self kb empty',
+      r.get('code') == 200 and len((r.get('data') or {}).get('rows') or []) == 0,
+      json.dumps(r, ensure_ascii=False)[:200])
+
+# T10 entry behavior
+r = call('GET', '/ai/agent/entry', t=T['admin'])
+entry = r.get('data') or {}
+check('T10 entry readable', r.get('code') == 200 and entry.get('id'), str(entry.get('id')))
+
+
+def entry_body(scope, oid):
+    return {'id': entry['id'], 'agentName': entry['agentName'], 'agentCode': entry['agentCode'],
+            'modelId': entry['modelId'], 'visibleScope': scope, 'ownerDeptId': oid}
+
+
+r = call('PUT', '/ai/agent/entry', entry_body('1', D1), T['admin'])
+check('T10 admin save entry scope=1', r.get('code') == 200, json.dumps(r, ensure_ascii=False)[:200])
+r = call('GET', '/ai/agent/entry', t=T['B'])
+e2 = r.get('data') or {}
+check('T10 entry scope persisted=1',
+      e2.get('visibleScope') == '1' and str(e2.get('ownerDeptId')) == D1,
+      f"{e2.get('visibleScope')}/{e2.get('ownerDeptId')}")
+r = call('GET', '/ai/agent/options', t=T['B'])
+names = [x.get('agentCode') for x in (r.get('data') or [])]
+check('T10 entry still offered to B despite dept scope', 'entry_agent' in names, str(names))
+r = call('PUT', '/ai/agent/entry', entry_body('2', None), T['A'])
+check('T10 normal user A can save entry (no creator check)', r.get('code') == 200,
+      json.dumps(r, ensure_ascii=False)[:200])
+r = call('PUT', '/ai/agent/entry', entry_body('0', None), T['admin'])
+check('T10 admin restore entry scope=0', r.get('code') == 200, json.dumps(r, ensure_ascii=False)[:200])
+
+# T11 admin dept record visible only to target dept
+r = call('POST', '/ai/agent', {'agentName': 'VS跨部门专家', 'agentCode': 'vs_expert_d2',
+                               'description': 'admin d2', 'modelId': 1761400000000020400, 'status': '0',
+                               'visibleScope': '1', 'ownerDeptId': D2, 'autoRoute': '1',
+                               'memoryEnabled': '0', 'expertWriteEnabled': '1'}, T['admin'])
+check('T11 create admin record ownerDept=D2', r.get('code') == 200, json.dumps(r, ensure_ascii=False)[:200])
+_, rows = list_rows('/ai/agent/list?pageSize=100', T['A'])
+nA = len(rows)
+_, rows = list_rows('/ai/agent/list?pageSize=100', T['C'])
+codesC = [x['agentCode'] for x in rows]
+check('T11 D2 record hidden from A(D1)', nA == 3, f'nA={nA}')
+check('T11 D2 record visible to C(D2)', 'vs_expert_d2' in codesC, str(codesC))
+
+# T12 default scope for normal user when omitted
+r = call('POST', '/ai/skill', {'name': 'vs_skill_default', 'description': 'default scope test', 'status': '0'}, T['A'])
+check('T12 create skill without scope ok', r.get('code') == 200, json.dumps(r, ensure_ascii=False)[:200])
+_, rows = list_rows('/ai/skill/list?pageSize=100', T['A'])
+row = [x for x in rows if x['name'] == 'vs_skill_default']
+check('T12 default scope=2 for normal user', bool(row) and row[0]['visibleScope'] == '2',
+      str(row[0]['visibleScope'] if row else None))
+if row:
+    ids['skill_default'] = row[0]['id']
+
+# T13 delete authorization
+r = call('POST', '/ai/skill', {'name': 'vs_skill_del', 'description': 'delete test', 'status': '0',
+                               'visibleScope': '1', 'ownerDeptId': D1}, T['A'])
+check('T13 create temp skill', r.get('code') == 200, '')
+_, rows = list_rows('/ai/skill/list?pageSize=100', T['A'])
+row = [x for x in rows if x['name'] == 'vs_skill_del']
+delid = row[0]['id'] if row else None
+r = call('DELETE', '/ai/skill/' + str(delid), t=T['B'])
+check('T13 B delete A skill rejected', r.get('code') == 500, json.dumps(r, ensure_ascii=False)[:200])
+r = call('DELETE', '/ai/skill/' + str(delid), t=T['C'])
+check('T13 C delete A skill rejected', r.get('code') == 500, json.dumps(r, ensure_ascii=False)[:200])
+r = call('DELETE', '/ai/skill/' + str(delid), t=T['A'])
+check('T13 A delete own skill allowed', r.get('code') == 200, json.dumps(r, ensure_ascii=False)[:200])
+if ids.get('skill_default'):
+    r = call('DELETE', '/ai/skill/' + str(ids['skill_default']), t=T['A'])
+    check('T13 cleanup default skill', r.get('code') == 200, '')
+_, rows = list_rows('/ai/agent/list?pageSize=100', T['admin'])
+row = [x for x in rows if x['agentCode'] == 'vs_expert_d2']
+if row:
+    r = call('DELETE', '/ai/agent/' + row[0]['id'], t=T['admin'])
+    check('T13 cleanup d2 expert', r.get('code') == 200, '')
+
+json.dump(results, open('api_results.json', 'w'), ensure_ascii=False, indent=2)
+print('TOTAL', len(results), 'PASS', sum(1 for x in results if x['pass']), 'FAIL', sum(1 for x in results if not x['pass']))

+ 53 - 0
test-reports-20261118-visible-scope/scripts/create_data.py

@@ -0,0 +1,53 @@
+import json, urllib.request, urllib.error
+BASE='http://localhost:8980/js/a'
+def call(method,path,body=None,token=None):
+    data=json.dumps(body).encode() if body is not None else None
+    req=urllib.request.Request(BASE+path,data=data,method=method)
+    req.add_header('Content-Type','application/json')
+    if token: req.add_header('x-token',token)
+    try:
+        with urllib.request.urlopen(req,timeout=30) as r: txt=r.read().decode()
+    except urllib.error.HTTPError as e:
+        return {'http':e.code,'body':e.read().decode()[:500]}
+    try: return json.loads(txt)
+    except Exception: return {'raw':txt[:500]}
+def login(u,p):
+    r=call('POST','/auth/login',{'username':u,'password':p,'force':True})
+    if r.get('code')!=200: print('LOGIN FAIL',u,r); return None
+    return r['data']['token']
+env=json.load(open('env.json'))
+dA,dB=env['deptA'],env['deptB']
+admin=login('admin','admin123'); A=login('vsuserA','Vs1118pass'); B=login('vsuserB','Vs1118pass'); C=login('vsuserC','Vs1118pass')
+print('tokens',bool(admin),bool(A),bool(B),bool(C))
+for u,t in [('admin',admin),('A',A),('B',B),('C',C)]:
+    r=call('GET','/auth/info',token=t)
+    di=r.get('data') or {}
+    print(u,'userId',di.get('userId'),'dept',di.get('deptId'),'isAdmin',di.get('isAdmin'),'roles',di.get('roles'),'perms',len(di.get('permissions') or []))
+    if u!='admin':
+        print('  scope-options:',json.dumps(call('GET','/ai/agent/scope-options',token=t),ensure_ascii=False)[:300])
+
+CHAT=1761400000000020400; EMB=1761400000000020401
+def tagname(x): return 'VS1118'+x
+# admin public records
+res={}
+res['expert_pub']=call('POST','/ai/agent',{'agentName':'VS公开专家','agentCode':'vs_expert_pub','description':'public expert','modelId':CHAT,'status':'0','visibleScope':'0','autoRoute':'1','memoryEnabled':'0','expertWriteEnabled':'1'},admin)
+res['skill_pub']=call('POST','/ai/skill',{'name':'vs_skill_pub','description':'public skill','status':'0','visibleScope':'0'},admin)
+res['pack_pub']=call('POST','/ai/pack',{'packCode':'vs_pack_pub','packName':'VS公开场景包','description':'public pack','status':'0','visibleScope':'0'},admin)
+res['kb_pub']=call('POST','/ai/kb',{'kbName':'VS公开知识库','kbCode':'vs_kb_pub','description':'public kb','embeddingModelId':EMB,'retrievalMode':'vector','status':'0','visibleScope':'0'},admin)
+# A dept records (ownerDept omitted for skill to test fallback to creator dept)
+res['expert_dept']=call('POST','/ai/agent',{'agentName':'VS部门专家','agentCode':'vs_expert_dept','description':'dept expert','modelId':CHAT,'status':'0','visibleScope':'1','ownerDeptId':dA,'autoRoute':'1','memoryEnabled':'0','expertWriteEnabled':'1'},A)
+res['skill_dept']=call('POST','/ai/skill',{'name':'vs_skill_dept','description':'dept skill','status':'0','visibleScope':'1'},A)
+res['pack_dept']=call('POST','/ai/pack',{'packCode':'vs_pack_dept','packName':'VS部门场景包','description':'dept pack','status':'0','visibleScope':'1','ownerDeptId':dA},A)
+res['kb_dept']=call('POST','/ai/kb',{'kbName':'VS部门知识库','kbCode':'vs_kb_dept','description':'dept kb','embeddingModelId':EMB,'retrievalMode':'vector','status':'0','visibleScope':'1'},A)
+# A self records
+res['expert_self']=call('POST','/ai/agent',{'agentName':'VS自建专家','agentCode':'vs_expert_self','description':'self expert','modelId':CHAT,'status':'0','visibleScope':'2','autoRoute':'1','memoryEnabled':'0','expertWriteEnabled':'1'},A)
+res['skill_self']=call('POST','/ai/skill',{'name':'vs_skill_self','description':'self skill','status':'0','visibleScope':'2'},A)
+res['pack_self']=call('POST','/ai/pack',{'packCode':'vs_pack_self','packName':'VS自建场景包','description':'self pack','status':'0','visibleScope':'2'},A)
+res['kb_self']=call('POST','/ai/kb',{'kbName':'VS自建知识库','kbCode':'vs_kb_self','description':'self kb','embeddingModelId':EMB,'retrievalMode':'vector','status':'0','visibleScope':'2'},A)
+# A tries public (must fail)
+res['A_expert_pub_try']=call('POST','/ai/agent',{'agentName':'VS越权专家','agentCode':'vs_expert_pub_try','description':'x','modelId':CHAT,'status':'0','visibleScope':'0','autoRoute':'1','expertWriteEnabled':'1'},A)
+res['A_skill_pub_try']=call('POST','/ai/skill',{'name':'vs_skill_pub_try','description':'x','status':'0','visibleScope':'0'},A)
+res['A_pack_pub_try']=call('POST','/ai/pack',{'packCode':'vs_pack_pub_try','packName':'VS越权包','status':'0','visibleScope':'0'},A)
+res['A_kb_pub_try']=call('POST','/ai/kb',{'kbName':'VS越权库','kbCode':'vs_kb_pub_try','embeddingModelId':EMB,'retrievalMode':'vector','status':'0','visibleScope':'0'},A)
+print(json.dumps(res,ensure_ascii=False,indent=1))
+json.dump(res,open('create_res.json','w'),ensure_ascii=False,indent=2)

+ 33 - 0
test-reports-20261118-visible-scope/scripts/extra_api.py

@@ -0,0 +1,33 @@
+import json,urllib.request,urllib.error
+BASE='http://localhost:8980/js/a'
+def call(m,p,b=None,t=None):
+    d=json.dumps(b).encode() if b is not None else None
+    r=urllib.request.Request(BASE+p,data=d,method=m); r.add_header('Content-Type','application/json')
+    if t:r.add_header('x-token',t)
+    try:
+        with urllib.request.urlopen(r,timeout=30) as x:return json.loads(x.read().decode())
+    except urllib.error.HTTPError as e:return {'http':e.code,'body':e.read().decode()[:300]}
+def login(u,p):return call('POST','/auth/login',{'username':u,'password':p,'force':True})['data']['token']
+A=login('vsuserA','Vs1118pass');B=login('vsuserB','Vs1118pass');C=login('vsuserC','Vs1118pass')
+D1='2123022706158374913'
+# canManage flags on 4 list types for B
+for path,key,code_key in [('/ai/skill/list?pageSize=100','vs_skill','name'),('/ai/pack/list?pageSize=100','vs_pack','packCode'),('/ai/kb/list?pageSize=100','vs_kb','kbCode')]:
+    r=call('GET',path,t=B); rows=r['data']['rows']
+    by={x[code_key]:x for x in rows}
+    dept=[k for k in by if k.endswith('_dept')][0]; pub=[k for k in by if k.endswith('_pub')][0]
+    print(path,'B canManage dept',by[dept]['canManage'],'pub',by[pub]['canManage'])
+# update authorization pack/kb by B
+r=call('PUT','/ai/pack',{'id':'2123022767378436098','packCode':'vs_pack_dept','packName':'VS部门场景包','visibleScope':'1','ownerDeptId':D1},B)
+print('B update pack ->',r.get('code'),r.get('message'))
+r=call('PUT','/ai/kb',{'id':'2123022767873363969','kbName':'VS部门知识库','kbCode':'vs_kb_dept','embeddingModelId':1761400000000020401,'visibleScope':'1','ownerDeptId':D1},B)
+print('B update kb ->',r.get('code'),r.get('message'))
+# delete authorization pack/kb by C (create temp records first)
+r=call('POST','/ai/pack',{'packCode':'vs_pack_del','packName':'VS删除包','status':'0','visibleScope':'2'},A)
+r=call('GET','/ai/pack/list?pageSize=100',t=A); row=[x for x in r['data']['rows'] if x['packCode']=='vs_pack_del']; pid=row[0]['id']
+print('C delete pack ->',call('DELETE','/ai/pack/'+pid,t=C))
+print('B delete pack ->',call('DELETE','/ai/pack/'+pid,t=B))
+print('A delete pack ->',call('DELETE','/ai/pack/'+pid,t=A))
+r=call('POST','/ai/kb',{'kbName':'VS删除库','kbCode':'vs_kb_del','embeddingModelId':1761400000000020401,'retrievalMode':'vector','status':'0','visibleScope':'2'},A)
+r=call('GET','/ai/kb/list?pageSize=100',t=A); row=[x for x in r['data']['rows'] if x['kbCode']=='vs_kb_del']; kid=row[0]['id']
+print('C delete kb ->',call('DELETE','/ai/kb/'+kid,t=C).get('code'))
+print('A delete kb ->',call('DELETE','/ai/kb/'+kid,t=A).get('code'))

+ 31 - 0
test-reports-20261118-visible-scope/scripts/legacy_test.py

@@ -0,0 +1,31 @@
+import json,urllib.request,urllib.error,psycopg2
+BASE='http://localhost:8980/js/a'
+def call(m,p,b=None,t=None):
+    d=json.dumps(b).encode() if b is not None else None
+    r=urllib.request.Request(BASE+p,data=d,method=m); r.add_header('Content-Type','application/json')
+    if t:r.add_header('x-token',t)
+    try:
+        with urllib.request.urlopen(r,timeout=30) as x:return json.loads(x.read().decode())
+    except urllib.error.HTTPError as e:return {'http':e.code,'body':e.read().decode()[:300]}
+def login(u,p):return call('POST','/auth/login',{'username':u,'password':p,'force':True})['data']['token']
+A=login('vsuserA','Vs1118pass'); admin=login('admin','admin123')
+conn=psycopg2.connect(host='192.168.0.106',port=5432,dbname='zsjz-ai',user='postgres',password='postgres')
+cur=conn.cursor()
+cur.execute("update ai_expert_agent set visible_scope='0' where id=2123022768359903234")
+conn.commit()
+print('simulate legacy scope=0 on A own expert')
+r=call('GET','/ai/agent/2123022768359903234',t=A); print('A get scope',r['data']['visibleScope'],'canManage',r['data'].get('canManage'))
+# A preserves 0 on update
+r=call('PUT','/ai/agent',{'id':'2123022768359903234','agentName':'VS自建专家','agentCode':'vs_expert_self','modelId':1761400000000020400,'visibleScope':'0'},A)
+print('A update legacy 0 preserving ->',r)
+cur.execute("select visible_scope from ai_expert_agent where id=2123022768359903234"); print('db scope',cur.fetchone())
+# A changes to 1 then tries back to 0 -> should fail
+r=call('PUT','/ai/agent',{'id':'2123022768359903234','agentName':'VS自建专家','agentCode':'vs_expert_self','modelId':1761400000000020400,'visibleScope':'1','ownerDeptId':'2123022706158374913'},A)
+print('A change to 1 ->',r.get('code'),r.get('message'))
+r=call('PUT','/ai/agent',{'id':'2123022768359903234','agentName':'VS自建专家','agentCode':'vs_expert_self','modelId':1761400000000020400,'visibleScope':'0'},A)
+print('A set back 0 (existing 1) ->',r.get('code'),r.get('message'))
+# restore to 2
+r=call('PUT','/ai/agent',{'id':'2123022768359903234','agentName':'VS自建专家','agentCode':'vs_expert_self','modelId':1761400000000020400,'visibleScope':'2'},A)
+print('A restore 2 ->',r.get('code'))
+cur.execute("select visible_scope,owner_dept_id from ai_expert_agent where id=2123022768359903234"); print('db final',cur.fetchone())
+conn.close()

+ 51 - 0
test-reports-20261118-visible-scope/scripts/setup2.py

@@ -0,0 +1,51 @@
+import json, urllib.request, urllib.error
+BASE='http://localhost:8980/js/a'
+def call(method,path,body=None,token=None):
+    data=json.dumps(body).encode() if body is not None else None
+    req=urllib.request.Request(BASE+path,data=data,method=method)
+    req.add_header('Content-Type','application/json')
+    if token: req.add_header('x-token',token)
+    try:
+        with urllib.request.urlopen(req,timeout=30) as r: txt=r.read().decode()
+    except urllib.error.HTTPError as e:
+        return {'http':e.code,'body':e.read().decode()}
+    try: return json.loads(txt)
+    except Exception: return {'raw':txt}
+def login(u,p):
+    r=call('POST','/auth/login',{'username':u,'password':p,'force':True})
+    return r['data']['token'] if r.get('code')==200 else None
+admin=login('admin','admin123')
+
+# find dept ids
+r=call('GET','/perm/dept/list',token=admin)
+depts={d['deptName']:d['deptId'] for d in r['data']}
+dA=depts['可见范围部A1118']; dB=depts['可见范围部B1118']
+print('deptA',dA,'deptB',dB)
+
+menu_ids=[20000,20100,20101,2010101,2010102,2010103,2010104,2010105,2010106,
+          20102,2010201,2010202,20103,2010301,2010302,2010303,
+          20106,2010601,2010602,2010603,20107,2010701,2010702,2010703,
+          20300,20301,2030101,2030102,2030103,20302,2030201,2030202,2030203,
+          20303,2030301,2030302]
+role_key='vs1118role'
+r=call('POST','/perm/role',{'roleName':'可见范围测试角色1118','roleKey':role_key,'roleSort':80,'status':'0','remark':'visible scope e2e','menuIds':menu_ids},admin)
+print('role add',r)
+r=call('GET','/perm/role/list',token=admin)
+roles=r['data']['rows'] if isinstance(r.get('data'),dict) else r['data']
+role=[x for x in roles if x.get('roleKey')==role_key and x.get('roleName')=='可见范围测试角色1118']
+print('roles matched',role)
+role_id=role[-1]['roleId']
+r=call('PUT','/perm/role/permission',{'roleId':role_id,'menuIds':menu_ids},admin)
+print('role permission',r)
+
+def add_user(uname,nick,dept):
+    r=call('POST','/perm/user',{'userName':uname,'nickName':nick,'password':'Vs1118pass','deptId':dept,'roleIds':[role_id],'status':'0'},admin)
+    print('user',uname,r)
+add_user('vsuserA','可见范围用户A',dA)
+add_user('vsuserB','可见范围用户B',dA)
+add_user('vsuserC','可见范围用户C',dB)
+
+# find user ids
+r=call('GET','/perm/user/list?pageSize=100&pageNum=1',token=admin)
+print('user list shape', str(r)[:300])
+open('env.json','w').write(json.dumps({'deptA':dA,'deptB':dB,'roleId':role_id},ensure_ascii=False,indent=2))

+ 17 - 0
test-reports-20261118-visible-scope/test-data.json

@@ -0,0 +1,17 @@
+{
+  "accounts": {
+    "admin": {"password": "admin123", "role": "superadmin", "deptId": 101, "userId": 1},
+    "vsuserA": {"password": "Vs1118pass", "role": "可见范围测试角色1118(vs1118role)", "deptId": "2123022706158374913", "dept": "可见范围部A1118"},
+    "vsuserB": {"password": "Vs1118pass", "role": "可见范围测试角色1118(vs1118role)", "deptId": "2123022706158374913", "dept": "可见范围部A1118"},
+    "vsuserC": {"password": "Vs1118pass", "role": "可见范围测试角色1118(vs1118role)", "deptId": "2123022706573611010", "dept": "可见范围部B1118"},
+    "vsuserD": {"password": "Vs1118pass", "role": "仅专家配置角色1118(vsonlyexpert)", "deptId": "2123022706158374913", "dept": "可见范围部A1118"}
+  },
+  "records": {
+    "expert": {"public": "2123022764635361281", "dept": "2123022766514409473", "self": "2123022768359903234"},
+    "skill": {"public": "2123022765163843585", "dept": "2123022767038697473", "self": "2123022768850636802"},
+    "pack": {"public": "2123022765524553730", "dept": "2123022767378436098", "self": "2123022769240707074", "baseline": "2122286948237795330(sdfsdf)"},
+    "kb": {"public": "2123022766036258817", "dept": "2123022767873363969", "self": "2123022769697886209"},
+    "entry": "1761400000000020302"
+  },
+  "note": "记录均为本次测试创建(baseline 场景包除外),保留以便复测;visible_scope 0/1/2 分别对应公开/本部门/仅本人。"
+}

+ 277 - 0
test-reports-20261118-visible-scope/智能体可见范围-功能测试报告-20261118.md

@@ -0,0 +1,277 @@
+# 智能体「可见范围」数据权限 · 功能测试报告
+
+- 被测计划:`plan-sess_aed9339d-284f-4610-af4f-990c808b2ec9.md`(智能体 5 页可见范围 / `visible_scope` / `owner_dept_id`)
+- 测试日期:2026-11-18 19:54 ~ 20:16
+- 测试方式:重启前后端 → 内置浏览器(IAB,1600×1000)按真实用户操作 → 接口/数据库断言补充证据
+- 约束遵守:**未修改任何业务代码**;仅新增本报告目录、测试账号/角色/部门与测试记录
+- 结论:**可见范围核心逻辑通过**(5 页表单、列表过滤、详情校验、越权改删拒绝、文档过滤、迁移幂等均符合预期);发现 **1 项 P1 权限码错配缺陷**(专家配置页正常用户不可用/创建人不能删除)+ **1 项 P2 依赖权限缺口** + **1 项 P3 前端类型检查基线问题**,详见第 6 节。
+
+---
+
+## 1. 环境与服务重启
+
+| 项 | 值 |
+|---|---|
+| 仓库 | `E:\workspace\zsjz-ai`,分支 `dev_1`,提交 `cac272d7`(工作区源码无本次新增改动) |
+| 后端 | `java -jar ai-server/target/ai-server-1.0.jar --spring.profiles.active=dev`,PID **17052** |
+| 后端 jar | 2026-11-18 **19:56:30** 重新构建,594,268,138 字节;`mvn -pl ai-server -am -DskipTests package` **BUILD SUCCESS** |
+| 后端就绪 | `GET http://localhost:8980/js/a/sys/health` → `{"code":200}`,启动约 3s 内可访问 |
+| 前端 | Vite **7.2.7**,`http://localhost:3100`,PID **13436**,`ready in 7629 ms` |
+| 版本一致性 | `ai-server/src` 中无文件晚于 jar;`ai-frontend/src` 中无文件晚于 19:56:30 |
+| 数据库 | PostgreSQL `192.168.0.106:5432/zsjz-ai`(dev);Redis/ES 同配置指向 192.168.0.106 |
+| 浏览器 | ZCode In-app Browser,视口 1600×1000 |
+
+重启过程记录:
+
+1. 终止旧后端 PID 5760、旧前端 PID 3620。
+2. 首次打包因另一个会话的后台任务(19:55 以旧 jar 重启,PID 11816)占用 jar 导致 `repackage` 失败;终止该进程后重打包成功。
+3. 重新启动后端 PID 17052、前端 Vite PID 13436;健康检查与页面均可访问。
+4. 测试结束后复核:8980/3100 均在监听,jar 与源码无时间倒挂。
+
+> 说明:另一个并发会话在本报告生成期间向旧报告 `test-reports-20261118-plan-retest/两份权限计划-功能复测报告-20261118.md` 追加了“版本边界声明”,并曾重启过服务。该文件改动不属于本报告,也未被本次测试修改;本报告结论仅针对 19:56 构建的 jar 与当前工作区源码。
+
+---
+
+## 2. 测试账号与数据
+
+| 账号 | 密码 | 部门 | 角色 | 用途 |
+|---|---|---|---|---|
+| `admin` | `admin123` | 默认部门(101) | superadmin | 超管全量视角 |
+| `vsuserA` | `Vs1118pass` | 可见范围部A1118(D1) | 可见范围测试角色1118 | 普通用户创建人;创建 0/1/2 数据 |
+| `vsuserB` | `Vs1118pass` | 可见范围部A1118(D1) | 可见范围测试角色1118 | 同部门普通用户 |
+| `vsuserC` | `Vs1118pass` | 可见范围部B1118(D2) | 可见范围测试角色1118 | 跨部门普通用户 |
+| `vsuserD` | `Vs1118pass` | 可见范围部A1118(D1) | 仅专家配置角色1118 | 复现专家页权限码错配 |
+
+测试记录(均保留,便于复测):
+
+| 资源 | 公开(0) | 本部门(1) | 仅本人(2) |
+|---|---|---|---|
+| 专家 | VS公开专家 `2123022764635361281`(admin) | VS部门专家 `2123022766514409473`(A,D1) | VS自建专家 `2123022768359903234`(A) |
+| 技能 | vs_skill_pub `2123022765163843585` | vs_skill_dept `2123022767038697473`(ownerDept=D1) | vs_skill_self `2123022768850636802` |
+| 场景包 | VS公开场景包 `2123022765524553730` | VS部门场景包 `2123022767378436098` | VS自建场景包 `2123022769240707074` |
+| 知识库 | VS公开知识库 `2123022766036258817` | VS部门知识库 `2123022767873363969`(ownerDept=D1) | VS自建知识库 `2123022769697886209` |
+| 入口数剑 | — | 单例 `1761400000000020302`,测试后已恢复 scope='0'、ownerDept=null | — |
+
+> 基线数据:场景包存在历史记录 `sdfsdf`(create_by=1,scope='2'),导致管理员场景包列表为 4 条;不属于本次测试数据。
+
+---
+
+## 3. SQL 与数据库
+
+| # | 检查项 | 结果 | 证据 |
+|---|---|---|---|
+| S1 | 5 张表均存在 `owner_dept_id bigint`、`visible_scope char(1) default '0'` | 通过 | `information_schema.columns` 查询 |
+| S2 | `sql/ai_visible_scope_20261118.sql` 连续执行 2 次均成功 | 通过 | `sql-idempotency.log`:run 1/2 OK,各 0.01s |
+| S3 | 迁移只回填空值、不覆盖已有 scope | 通过 | 二跑后测试数据 scope 分布保持不变 |
+| S4 | 「本部门」缺 ownerDept 时按创建人部门回填 | 通过 | A 创建 skill/kb 部门数据未传 ownerDept,DB 落为 D1 |
+| S5 | 服务端默认值:普通用户新建未传 scope → '2' | 通过 | T12:`vs_skill_default` 写入即 '2' |
+
+---
+
+## 4. 后端接口验证
+
+自动化断言共 **87 项**(`api-results.json`),首轮 83 项直接通过;其余 4 项经复核为**测试顺序/基线数据导致的误判**,不是缺陷:
+
+| 首轮失败项 | 复核结论 |
+|---|---|
+| T3 pack list admin expected=3(实际 4) | 基线记录 `sdfsdf` 也是 scope=2,管理员应看到全部 4 条 → 通过 |
+| T8 visible experts B expected=2(实际 1) | 前一用例 T6 把 A 的部门专家临时改为 scope=2;恢复 scope=1 后 B 看到 2 条 → 通过 |
+| T8 candidates B expected=2(实际 1) | 同上 |
+| T8 pack options admin expected=3(实际 4) | 同 T3 基线数据 → 通过 |
+
+核心矩阵:
+
+| 组 | 用例 | 结果 |
+|---|---|---|
+| T1/T2 | `GET /ai/agent/scope-options`:admin `superAdmin=true`;普通用户 `superAdmin=false`;部门树含 D1/D2 | 2/2 通过 |
+| T3 | 专家/技能/场景包/知识库列表:A=3、B=2、C=1、admin=3(admin 场景包含基线为 4) | 16/16(首轮 15,基线复核后全部通过) |
+| T4 | 列表 `canManage`:B 对 A 部门/管理员公开数据 false;A 对自己数据 true、对公开数据 false | 4/4 通过 |
+| T5 | 详情可见性:B 看不到 A 的「仅本人」;C 看不到 D1 的「本部门」;公开数据 C 可见 | 16/16 通过 |
+| T6 | 修改权限:B/C 改 A 部门数据被拒「仅创建人或超级管理员可操作」;admin/A 可改 | 4/4 通过 |
+| T7 | 普通用户把自有数据改为 '0' 被拒「普通用户不能设置全员/公开可见」;非法 '9' 被参数校验拒绝;空值继承原值 | 4/4 通过 |
+| T8 | 工作台数据源:可见专家、自动候选、技能选项、场景包选项、知识库选项均 A=3/B=2/C=1/admin=3 | 21/21(首轮 18,恢复数据后全部通过) |
+| T9 | 文档列表按知识库可见性收口:B 可查 D1 部门库、C 查 D1 部门库为空、B 查 A 仅本人库为空 | 3/3 通过 |
+| T10 | 数剑单例:admin 保存 scope=1 成功;B 仍能在 `/ai/agent/options` 看到入口;A 可保存;随后恢复 '0' | 6/6 通过 |
+| T11 | 管理员创建 ownerDept=D2 的「本部门」数据:A(D1) 不可见、C(D2) 可见 | 3/3 通过 |
+| T12 | 普通用户新建不传 scope 默认 '2' | 2/2 通过 |
+| T13 | 删除权限:B/C 删 A 技能被拒;A 删自己技能成功;临时数据清理成功 | 6/6 通过 |
+
+补充接口验证:
+
+| # | 用例 | 结果 |
+|---|---|---|
+| A1 | 历史全员数据保留:DB 将 A 自有专家置 '0',A 提交 '0' 保存成功且仍为 '0';改为 '1' 后再提交 '0' 被拒;恢复 '2' | 通过 |
+| A2 | 场景包/知识库的 B 越权修改、C/B 越权删除均被拒;A 删除自有数据成功 | 通过 |
+| A3 | 文档详情:仅本人库文档 A=200,B/C=500「无权访问该知识库文档」;部门库文档 A/B=200,C=500;B 访问仅本人库 `content`/`chunks` 均 500 | 通过 |
+| A4 | 文档列表(不传 kbId):A=3、B=2、C=1、admin=3,按可见知识库过滤 | 通过 |
+| A5 | 管理员删除 A 创建的专家成功 | 通过 |
+| A6 | 普通用户提交越权 `visibleScope='0'`:专家/技能/场景包/知识库 4 类均返回「普通用户不能设置全员/公开可见」 | 通过 |
+| A7 | 入口智能体 scope=1 时仍出现在普通用户 `/ai/agent/options` 中(数剑不参与运行时过滤) | 通过 |
+| A8 | MCP 公共知识库集合:DB 中 status='0' 且 scope 0/空 的库仅 `VS公开知识库`,与 `listPublicEnabledKbIds` 口径一致 | 通过(代码/DB 级,未做 MCP 协议端到端调用) |
+
+---
+
+## 5. 浏览器 UI 验证
+
+### 5.1 超管(admin)
+
+| # | 页面 | 结果 | 证据 |
+|---|---|---|---|
+| U1 | 数剑配置 | 可见范围 3 项(全员/本部门/仅创建人),默认「全员」;归属部门始终展示 | `screenshots/01-admin-entry-scope.png` |
+| U2 | 专家配置列表 | 3 条卡片,均显示可见范围;scope=1 显示「本部门(可见范围部A1118)」;查看/修改/复制/删除齐全 | `02-admin-expert-list.png` |
+| U3 | 专家新增 | 3 项,默认「全员」,归属部门树可选(含 A/B 部门) | `03b-admin-expert-create-scope-bottom.png` |
+| U4 | 技能仓库 | 列表 3 条、标签正确;新增表单 3 项,默认「公开」,选「本部门」前不显示部门树 | `04-admin-skill-list.png`、`05-admin-skill-create-scope.png` |
+| U5 | 场景包 | 列表 4 条(含基线 `sdfsdf`);新增 3 项,默认「公开」 | `06-admin-pack-list.png`、`07-admin-pack-create-scope.png` |
+| U6 | 知识库管理 | 列表 3 条;新增 3 项,默认「公开」 | `08-admin-kb-list.png`、`09-admin-kb-create-scope.png` |
+| U7 | 文档与切片 | 知识库下拉含 3 个可见库 | `10-admin-doc-page.png` |
+
+### 5.2 普通用户 A(创建人,D1)
+
+| # | 页面/场景 | 结果 | 证据 |
+|---|---|---|---|
+| U8 | 专家列表 | 3 条;自己创建的两条有修改/删除/开关,管理员公开数据仅查看/复制且开关禁用 | `11-userA-expert-list.png` |
+| U9 | 专家新增 | 仅 2 项(本部门/仅创建人),默认「仅创建人」;归属部门始终展示 | `12-userA-expert-create-scope.png` |
+| U10 | 编辑自己「本部门」专家 | 2 项;「本部门」选中,归属部门回填 D1 | `13-userA-expert-edit-dept.png` |
+| U11 | 数剑配置 | 历史 scope=0 显示 **禁用项「全员(仅管理员可设置)」** + 本部门/仅创建人,禁用项选中 | `14-userA-entry-scope.png` |
+| U12 | 技能/场景包/知识库列表 | 各 3 条;管理员公开数据无修改/删除,自己的数据有 | `15-userA-skill-list.png`、`17-userA-pack-list.png`、`18-userA-kb-list.png` |
+| U13 | 技能表单 | 2 项,默认「仅本人」;切换到「本部门」后出现归属部门树 | `16-userA-skill-create-dept.png` |
+| U14 | 场景包/知识库表单 | 各 2 项,默认「仅本人」;选「本部门」才展示部门树 | DOM 快照(页面行为一致) |
+| U15 | 文档与切片 | 知识库下拉含 3 个可见库 | `19-userA-doc-kb-options.png` |
+| U16 | UI 新建专家 | 填名称/编码/模型 → 保存成功;新卡片可见范围为「仅创建人」,DB scope='2'、ownerDept=null | `24-userA-ui-create-result.png` |
+| U17 | 编辑历史全员数据 | 禁用项「全员(仅管理员可设置)」选中;直接保存成功(后端允许保留 '0'),DB 保持 '0' | `23-userA-legacy-0-disabled-option.png` |
+
+### 5.3 同部门 B 与跨部门 C
+
+| # | 账号/页面 | 结果 | 证据 |
+|---|---|---|---|
+| U18 | B 专家列表 | 仅 2 条(公开 + A 的部门数据),看不到 A 的「仅创建人」;两条均无修改/删除,开关禁用 | `20-userB-expert-list.png` |
+| U19 | C 专家列表 | 仅 1 条(公开),无修改/删除,开关禁用 | `21-userC-expert-list.png` |
+| U20 | C 技能/场景包/知识库列表 | 各 1 条(公开),可见范围均显示「公开/仅本人/本部门」正确 | DOM 提取:`共 1 个` × 3 |
+| U21 | C 文档页 | 知识库下拉仅「VS公开知识库」并自动选中;上传按钮可用,列表为空 | `22-userC-doc-kb-options.png` |
+
+### 5.4 UI 交互细节
+
+- 列表卡片显示「可见范围」;scope=1 时附带归属部门名称。
+- 详情弹窗显示「可见范围 / 归属部门」;公开专家归属部门显示 `-`。
+- 非创建人记录的开关 `disabled`,修改/删除按钮不渲染;创建人/超管可见。
+- 新增/复制不受 `canManage` 限制;普通用户复制公开数据时,克隆逻辑会把 scope '0' 降为 '2'(代码检查 `expert/index.vue:767-768`,未单列 UI 用例)。
+
+---
+
+## 6. 缺陷与问题清单
+
+### D1【P1·阻断】专家配置页前后端权限码不一致,普通用户无法正常使用/删除
+
+**现象**
+
+1. 仅授予「专家配置」菜单权限的普通用户 `vsuserD`,打开专家配置页显示「共 0 位 / 暂无专家」,列表接口实际返回 403(页面未展示明确错误)。截图 `25-userD-expert-only-403.png`。
+2. `vsuserD` 调 `POST /ai/agent` 新增专家 → 403「没有访问权限」。
+3. 同时拥有「数剑配置」查询/编辑权限的 `vsuserA`,新增/修改专家正常;但在自己创建的专家卡片上点击「删除」并确认后 → 403「没有访问权限」,数据未删除。截图 `26-userA-expert-delete-403.png`;后端日志 `权限不足: 无此权限:ai:agent:remove`。
+
+**根因**
+
+| 层 | 实际要求/授予的权限码 |
+|---|---|
+| 后端专家列表 `GET /ai/agent/list` | `ai:agent:query`(`AiAgentController.java:88`) |
+| 后端专家新增/修改 | `ai:agent:edit`(`AiAgentController.java:202,211`) |
+| 后端专家删除 | `ai:agent:remove`(`AiAgentController.java:222`) |
+| 菜单「专家配置」 | `ai:expert:query`(`perm_menu` 20103) |
+| 菜单「专家编辑/删除」 | `ai:expert:edit` / `ai:expert:remove`(2010302/2010303) |
+| 前端按钮 `v-auth` | `ai:expert:edit` / `ai:expert:remove`(`expert/index.vue:26,92,101`) |
+
+`perm_menu` 中不存在授予 `ai:agent:edit`(除数剑配置 2010202)或 `ai:agent:remove` 的按钮;`ai:agent:remove` 在菜单中完全不存在。因此:
+
+- 只有「专家配置」菜单的正常用户:列表/新增/修改全部 403;
+- 既使额外授予「数剑配置」编辑权限,删除仍必然 403,因为没有任何菜单能授予 `ai:agent:remove`。
+
+**影响**
+
+- 触及计划验收项:「普通用户 A 在 5 个页面只能看到并选择本部门/仅自己」「修改/删除仅创建人或超管可操作」。专家配置页对普通用户实际不可用,创建人无法删除自己的专家。
+- 可见范围过滤本身(管理员视角、A/B/C 数据隔离)在该页是正常的;问题在权限码映射,不在 `VisibleScopeSupport`。
+
+**建议(未改代码,仅报告)**
+
+- 将专家 CRUD 的后端注解改为 `ai:expert:query/edit/remove`(数剑仍保留 `ai:agent:*`);或补齐可授权的 `ai:agent:remove` 菜单/按钮并同步前端 `v-auth`,二选一保持前后端一致。
+- 列表 403 建议前端显式提示,而不是静默显示「暂无专家」。
+
+---
+
+### D2【P2】专家表单依赖的选项权限不在「专家配置」菜单内
+
+仅授予「专家配置」的 `vsuserD` 打开页面时,除列表 403 外还会提示:
+
+- `模型 / 工具 / 知识库 / 技能 选项加载失败,对应下拉暂不可用`
+- 具体接口:`/ai/model/options`(需 `ai:model:query`)、`/ai/agent/tool/options`(需 `ai:agent:query`)、`/ai/kb/visible-options`(需 `ai:kb:query`)、`/ai/skill/visible-options`(需 `ai:skill:query`)
+
+这些权限码均不由「专家配置」菜单授予。即使修复 D1,普通用户要完整使用专家表单仍需额外分配模型/工具/知识库/技能菜单。建议在角色模板中补齐依赖权限,或将这些只读选项接口改为 `ai:expert:query` 即可访问(与 `scope-options` 的 OR 口径一致)。
+
+> 测试中为让 A 的表单可用,测试角色额外授予了模型查询、业务工具查询、MCP 客户端查询等菜单;这是测试环境授权调整,不涉及代码。
+
+---
+
+### D3【P3·基线】前端 `pnpm type:check` 未通过(与本次可见范围文件无关)
+
+- 命令:`cd ai-electron/frontend && pnpm type:check`
+- 结果:退出码 2,共 **68 个** `error TS`,集中在 `src/trans/views/**`、`src/dm/**` 等既有页面(align/fixed/sorter 类型、Dayjs 元组等)。
+- 可见范围相关文件(`workbench/constants/visibleScope.ts`、`workbench/components/VisibleScopeField.vue`、5 个页面)**没有类型错误**。
+- 结论:属于仓库现有类型基线问题,不阻塞本次可见范围功能;但计划“验证-1 前端类型检查”不能标记为全绿。日志:`frontend-typecheck.log`。
+
+---
+
+## 7. 未覆盖/受限项
+
+1. **工作台对话 SSE / 会话指定专家**:测试角色没有案件与对话上下文,未发起完整聊天流;底层数据源 `/ai/agent/experts`、`/ai/agent/experts/candidates` 已按 A/B/C 验证过滤,指定专家下拉的来源正确。
+2. **MCP 协议端到端调用**:仅验证 `listPublicEnabledKbIds` 的 DB 口径(仅公开且启用库);未启动 MCP 客户端走 JSON-RPC 检索。
+3. **文件上传/解析/向量化**:文档测试使用直接插入的元数据记录验证可见性守卫,未走上传/解析/向量化链路(与本计划无直接关系)。
+4. **并发多用户实时会话**:API 级多账号鉴权已覆盖,未做并发压力/时序测试。
+
+---
+
+## 8. 测试数据与收尾
+
+- 服务终态:后端 PID 17052、前端 PID 13436,8980/3100 均 LISTENING;健康检查 200。
+- 数据终态:
+  - 入口数剑已恢复 `visible_scope='0'`、`owner_dept_id=null`;
+  - A 的 VS自建专家已恢复 `visible_scope='2'`、`owner_dept_id=null`;
+  - UI 新建的 `VS界面创建专家` 已由管理员删除;
+  - 其余 VS 测试记录、账号、角色、部门保留,便于复测(见 `test-data.json`)。
+- 未修改业务代码;`git status` 中仅存在另一会话对旧报告的追加改动与本次新增的测试目录/临时目录。
+
+---
+
+## 9. 证据索引
+
+| 文件 | 说明 |
+|---|---|
+| `screenshots/01-admin-entry-scope.png` | 超管数剑配置:3 档可见范围 + 归属部门 |
+| `screenshots/02-admin-expert-list.png` | 超管专家列表:3 条与可见范围标签 |
+| `screenshots/03b-admin-expert-create-scope-bottom.png` | 超管新增专家:3 档默认全员 |
+| `screenshots/04-admin-skill-list.png` ~ `05-admin-skill-create-scope.png` | 超管技能列表/新增 3 档 |
+| `screenshots/06-admin-pack-list.png` ~ `07-admin-pack-create-scope.png` | 超管场景包列表/新增 3 档 |
+| `screenshots/08-admin-kb-list.png` ~ `09-admin-kb-create-scope.png` | 超管知识库列表/新增 3 档 |
+| `screenshots/10-admin-doc-page.png` | 超管文档页知识库下拉 |
+| `screenshots/11-userA-expert-list.png` | A 专家列表:公开数据按钮收敛 |
+| `screenshots/12-userA-expert-create-scope.png` | A 新增专家:2 档默认仅创建人 |
+| `screenshots/13-userA-expert-edit-dept.png` | A 编辑部门专家:本部门回填 D1 |
+| `screenshots/14-userA-entry-scope.png` | A 数剑:禁用「全员(仅管理员可设置)」 |
+| `screenshots/15-userA-skill-list.png` | A 技能列表 |
+| `screenshots/16-userA-skill-create-dept.png` | A 技能选择本部门后出现部门树 |
+| `screenshots/17-userA-pack-list.png` / `18-userA-kb-list.png` | A 场景包/知识库列表 |
+| `screenshots/19-userA-doc-kb-options.png` | A 文档页 3 个可见知识库 |
+| `screenshots/20-userB-expert-list.png` | B 同部门:2 条,仅公开+部门 |
+| `screenshots/21-userC-expert-list.png` | C 跨部门:仅公开 1 条 |
+| `screenshots/22-userC-doc-kb-options.png` | C 文档页仅公开知识库 |
+| `screenshots/23-userA-legacy-0-disabled-option.png` | A 编辑历史全员数据:禁用项可保留 |
+| `screenshots/24-userA-ui-create-result.png` | A UI 新增专家成功,默认仅创建人 |
+| `screenshots/25-userD-expert-only-403.png` | D1 证据:仅专家菜单用户列表为空/403 |
+| `screenshots/26-userA-expert-delete-403.png` | D1 证据:创建人删除专家 403 |
+| `api-results.json` | 87 项接口断言明细 |
+| `create-results.json` | 测试数据创建与越权创建响应 |
+| `test-data.json` | 账号、角色、部门、记录 ID 清单 |
+| `sql-idempotency.log` | 迁移脚本连续执行两次结果 |
+| `frontend-typecheck.log` | 前端类型检查完整输出(68 个既有错误) |
+| `backend-build.log` / `frontend-start.log` | 后端打包、前端启动日志 |
+
+---
+
+**总体判定**:可见范围(`visible_scope`/`owner_dept_id`)的**数据过滤、表单交互、越权拦截、文档收口、SQL 迁移**均达到计划预期;但「专家配置」页的既有权限码错配让普通用户无法正常使用该页/创建人无法删除,属于会阻断计划验收项 P1 问题,需修复后补一轮该页专项复测。