lantern-harness 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/README.md +7 -7
  3. package/builtin/case-backup-contract.mjs +27 -0
  4. package/builtin/case-workflow-contract.mjs +158 -0
  5. package/builtin/session/lh-nav-groups.mjs +33 -1
  6. package/builtin/session/space-layout.mjs +8 -1
  7. package/builtin/session/space-skills.mjs +8 -1
  8. package/cli/mcp-server.mjs +1211 -72
  9. package/cli/server.mjs +2 -0
  10. package/dist/500.html +9 -4
  11. package/dist/_astro/Base.ANghvs5L.css +1 -0
  12. package/dist/_astro/{Base.astro_astro_type_script_index_0_lang.XUV2H6ea.js → Base.astro_astro_type_script_index_0_lang.f7BIL9Qf.js} +1 -1
  13. package/dist/_astro/{BusinessMapBoard.mRxl2G3D.js → BusinessMapBoard.CYxHcku_.js} +1 -1
  14. package/dist/_astro/{CaseExecBoard.Cqkxuf5c.js → CaseExecBoard.CK9aGPmH.js} +1 -1
  15. package/dist/_astro/CaseExecutionBoard.p6Y23xyH.js +4 -0
  16. package/dist/_astro/CaseGenerateApp.D5uj5bSb.js +10 -0
  17. package/dist/_astro/CasesLibrary.CY1PRdzc.js +21 -0
  18. package/dist/_astro/ChatApp.BnV7drSC.js +1 -0
  19. package/dist/_astro/ChatApp.CqyrMX90.js +262 -0
  20. package/dist/_astro/{DashboardBoard.CAJVE2G4.js → DashboardBoard.qgc1s7pG.js} +1 -1
  21. package/dist/_astro/{DefectSubmitEntry.BzKXJ-zq.js → DefectSubmitEntry.JI85N1-i.js} +1 -1
  22. package/dist/_astro/{DocsFileBrowser.apKMbGVf.js → DocsFileBrowser.z5JZ74cy.js} +1 -1
  23. package/dist/_astro/{DocsPager.DMN9-Tjg.js → DocsPager.Dg765uHW.js} +1 -1
  24. package/dist/_astro/{KnowledgeLibrary.BcoMQeUd.js → KnowledgeLibrary.mkShtVun.js} +1 -1
  25. package/dist/_astro/{LifeKrTasksBoard.DJU0-QI-.js → LifeKrTasksBoard.DpAwQffE.js} +1 -1
  26. package/dist/_astro/{LifeKrTodosBoard.GK7KRAO3.js → LifeKrTodosBoard.BIjPiZ8H.js} +1 -1
  27. package/dist/_astro/{LifeObjectivesBoard.DuKa6Q3k.js → LifeObjectivesBoard.DYwLHPEG.js} +1 -1
  28. package/dist/_astro/{LifePlanTypeSelect.Cm2lUmnH.js → LifePlanTypeSelect.CYaziESp.js} +1 -1
  29. package/dist/_astro/{LifeReviewsBoard.BWOOVMtz.js → LifeReviewsBoard.DIxoWBDA.js} +1 -1
  30. package/dist/_astro/{LifeShared.bY2l01Ha.js → LifeShared.DuFQsMEx.js} +1 -1
  31. package/dist/_astro/{LifeStagesBoard.CIzxPOJB.js → LifeStagesBoard.DtOri9EW.js} +1 -1
  32. package/dist/_astro/{LifeYearCycleSelect.BlsyPmmI.js → LifeYearCycleSelect.ByJ9-PGg.js} +1 -1
  33. package/dist/_astro/{LifeYearPlansBoard.DaA9O08j.js → LifeYearPlansBoard.BQN07wcv.js} +1 -1
  34. package/dist/_astro/NavLibraries.BO4ezcUc.js +1 -0
  35. package/dist/_astro/{PluginsPage.B063QIlQ.js → PluginsPage.Cb6977dz.js} +2 -2
  36. package/dist/_astro/{PmBugsBoard.Cu-v0Gfd.js → PmBugsBoard.Ddl3kqqt.js} +1 -1
  37. package/dist/_astro/{PmIterationsBoard.CgRzkP-j.js → PmIterationsBoard.BJN7disI.js} +1 -1
  38. package/dist/_astro/{PmProjectDetail.DVCEh0Lm.js → PmProjectDetail.D78gWhqk.js} +1 -1
  39. package/dist/_astro/{PmProjectsBoard.z-bQa98r.js → PmProjectsBoard.Bf8VB3t6.js} +1 -1
  40. package/dist/_astro/PmRequirementsBoard.CDyNHN2a.js +1 -0
  41. package/dist/_astro/{PmRequirementsBoard.CyfBI0u_.js → PmRequirementsBoard.DarfGIrL.js} +1 -1
  42. package/dist/_astro/{PmShared.BQVzwsiz.js → PmShared.TOjBbtV8.js} +1 -1
  43. package/dist/_astro/{ReportsPage.najSzJeT.js → ReportsPage.BXGduuY3.js} +1 -1
  44. package/dist/_astro/{ReqAnalysisBoard.BQb8dHFD.js → ReqAnalysisBoard.C7V_fEh9.js} +1 -1
  45. package/dist/_astro/{RequirementBreakdownLibrary.Cn6OV6xt.js → RequirementBreakdownLibrary.DMoeTeqX.js} +1 -1
  46. package/dist/_astro/{RequirementsLibrary.CqKNFVsP.js → RequirementsLibrary.Iv7zOqWe.js} +1 -1
  47. package/dist/_astro/{SettingsDialog.db3BpFw0.js → SettingsDialog.CRbfEiyw.js} +1 -1
  48. package/dist/_astro/SlideOverDrawer.CvyB-quk.js +1 -0
  49. package/dist/_astro/{SpaceSwitcher.DSUVAPOi.js → SpaceSwitcher.D9bBNQBZ.js} +1 -1
  50. package/dist/_astro/{TableFieldConfig.72AL-8p-.js → TableFieldConfig.DHj25OKN.js} +1 -1
  51. package/dist/_astro/{TasksBoard.CCDhCSR7.js → TasksBoard.CXmGdylV.js} +1 -1
  52. package/dist/_astro/TemplatesLibrary.DsL2q-wp.js +1 -0
  53. package/dist/_astro/{TestReportsLibrary.fWiEyCRx.js → TestReportsLibrary.BBC1TYgP.js} +1 -1
  54. package/dist/_astro/{TestStatsBoard.BSUBsWSu.js → TestStatsBoard.VXjP4hu6.js} +1 -1
  55. package/dist/_astro/{TodosBoard.By5YdlUe.js → TodosBoard.-yKgp06M.js} +1 -1
  56. package/dist/_astro/UiAutoBoard.BZkPzwi8.js +3 -0
  57. package/dist/_astro/UiAutoEnvPanel.DrHUOlmH.js +10 -0
  58. package/dist/_astro/UiAutoGenerationDialog.gypq1zP9.js +12 -0
  59. package/dist/_astro/UiAutoProjectsPage.Dhzr09E9.js +3 -0
  60. package/dist/_astro/app-config.BSO5r82v.js +1 -0
  61. package/dist/_astro/app-version.B7nd7uBP.js +1 -0
  62. package/dist/_astro/{bash-tools.CS2w8LOb.js → bash-tools.C4DJiRJs.js} +1 -1
  63. package/dist/_astro/case-fields.C03NY3zC.js +148 -0
  64. package/dist/_astro/case-gen-run.DQR6uvH5.js +26 -0
  65. package/dist/_astro/case-prompt.ByLTgz4r.js +2 -0
  66. package/dist/_astro/{case-review.DFWZkoR9.js → case-review.BodP2jKm.js} +1 -1
  67. package/dist/_astro/{case-template.Clb7HrDB.js → case-template.CC2eXegU.js} +2 -2
  68. package/dist/_astro/case-types.BjF1BivA.js +1 -0
  69. package/dist/_astro/case-workflow-contract.BBQ9bbKL.js +1 -0
  70. package/dist/_astro/{defect-workbench.CjTb4FDv.js → defect-workbench.DBmohR-y.js} +1 -1
  71. package/dist/_astro/{hydrate-cache.O4CIma9y.js → hydrate-cache.CMMErx63.js} +1 -1
  72. package/dist/_astro/{i18n.Cp4so7KR.js → i18n.CEWjL5GX.js} +2 -2
  73. package/dist/_astro/{open-docs-in-session.BpcAcBSI.js → open-docs-in-session.BoyV6R2A.js} +1 -1
  74. package/dist/_astro/plugins.ChGmBEkF.js +1 -0
  75. package/dist/_astro/{project-docs.bB9lQ1Ki.js → project-docs.BRgNjXhG.js} +1 -1
  76. package/dist/_astro/{req-analysis.C_gARMrB.js → req-analysis.efWkT7Gv.js} +1 -1
  77. package/dist/_astro/{settings.D02wZj3w.js → settings.BojKNwUC.js} +2 -2
  78. package/dist/_astro/{spaces-client.BAtG6PkW.js → spaces-client.B28rzu8J.js} +1 -1
  79. package/dist/_astro/{story-review.DTN91Vl9.js → story-review.Dm9VcR6v.js} +1 -1
  80. package/dist/_astro/{test-points.C7ZgggQT.js → test-points.BSfPfq8z.js} +1 -1
  81. package/dist/_astro/ui-auto.LUcREUMe.js +1 -0
  82. package/dist/_astro/{view-prefs.COAKEQtZ.js → view-prefs.CWc5cQ2q.js} +1 -1
  83. package/dist/business-map/index.html +10 -5
  84. package/dist/case-exec/index.html +10 -5
  85. package/dist/case-execution/index.html +10 -5
  86. package/dist/cases/api/index.html +988 -0
  87. package/dist/cases/automation/index.html +988 -0
  88. package/dist/cases/functional/index.html +988 -0
  89. package/dist/cases/generate/index.html +10 -5
  90. package/dist/cases/index.html +1 -1
  91. package/dist/cases/library/index.html +1 -983
  92. package/dist/cases/other/index.html +988 -0
  93. package/dist/cases/performance/index.html +988 -0
  94. package/dist/dashboard/index.html +10 -5
  95. package/dist/defect-rules/index.html +10 -5
  96. package/dist/defect-submit/index.html +10 -5
  97. package/dist/defect-submit/templates/index.html +10 -5
  98. package/dist/docs/changelog/index.html +105 -58
  99. package/dist/docs/install/index.html +12 -6
  100. package/dist/docs/manual/index.html +62 -40
  101. package/dist/knowledge/index.html +10 -5
  102. package/dist/life/kr-tasks/index.html +10 -5
  103. package/dist/life/kr-todos/index.html +10 -5
  104. package/dist/life/objectives/index.html +10 -5
  105. package/dist/life/reviews/index.html +10 -5
  106. package/dist/life/stages/index.html +10 -5
  107. package/dist/life/year-plans/index.html +10 -5
  108. package/dist/plugins/index.html +10 -5
  109. package/dist/pm/bugs/index.html +10 -5
  110. package/dist/pm/iterations/index.html +10 -5
  111. package/dist/pm/projects/detail/index.html +10 -5
  112. package/dist/pm/projects/index.html +10 -5
  113. package/dist/pm/requirements/index.html +10 -5
  114. package/dist/reports/index.html +10 -5
  115. package/dist/requirement-analysis/index.html +10 -5
  116. package/dist/requirement-breakdowns/index.html +10 -5
  117. package/dist/requirements/index.html +10 -5
  118. package/dist/tasks/index.html +10 -5
  119. package/dist/templates/index.html +10 -5
  120. package/dist/test-automation/index.html +10 -5
  121. package/dist/test-automation/projects/index.html +10 -5
  122. package/dist/test-reports/index.html +10 -5
  123. package/dist/test-stats/index.html +10 -5
  124. package/dist/todos/index.html +10 -5
  125. package/dist/workbench/index.html +10 -5
  126. package/docs/Codex-MCP/351/233/206/346/210/220.md +117 -53
  127. package/docs//344/274/232/350/257/235/346/217/222/344/273/266.md +14 -1
  128. package/docs//345/205/250/345/261/200/346/217/222/344/273/266.md +5 -1
  129. package/docs//345/256/211/350/243/205/346/211/213/345/206/214.md +4 -2
  130. package/docs//346/223/215/344/275/234/346/211/213/345/206/214.md +45 -36
  131. package/lh-plugins/case-automation/service.mjs +927 -0
  132. package/lh-plugins/case-automation/store.mjs +231 -0
  133. package/lh-plugins/case-automation/tables.mjs +115 -0
  134. package/lh-plugins/case-automation-prompt.mjs +57 -0
  135. package/lh-plugins/case-execution/assets.mjs +180 -0
  136. package/lh-plugins/case-execution/files.mjs +123 -23
  137. package/lh-plugins/case-execution/plans.mjs +318 -0
  138. package/lh-plugins/case-execution/service.mjs +80 -13
  139. package/lh-plugins/case-execution-prompt.mjs +4 -1
  140. package/lh-plugins/lh-case-automation.mjs +169 -0
  141. package/lh-plugins/lh-case-design.mjs +456 -0
  142. package/lh-plugins/lh-case-execution.mjs +53 -1
  143. package/lh-plugins/lh-case-review.mjs +29 -11
  144. package/lh-plugins/lh-project-docs.mjs +24 -0
  145. package/lh-plugins/lh-stats.mjs +65 -4
  146. package/lh-plugins/lh-uiauto.mjs +111 -2
  147. package/lh-plugins/plugin-prompts.mjs +1 -0
  148. package/lh-plugins/uiauto-adapters/playwright.mjs +44 -4
  149. package/lh-plugins/uiauto-adapters/shared.mjs +4 -0
  150. package/lh-plugins/uiauto-explorer/emit-files.mjs +16 -2
  151. package/lh-plugins/uiauto-explorer/ir.mjs +3 -0
  152. package/lh-plugins/uiauto-explorer/merge.mjs +37 -1
  153. package/lh-plugins/uiauto-explorer/navigation-guard.mjs +255 -0
  154. package/lh-plugins/uiauto-explorer/runner.mjs +65 -3
  155. package/lh-plugins/uiauto-explorer/sessions.mjs +29 -1
  156. package/package.json +1 -1
  157. package/skills/case-automation-bridge/SKILL.md +27 -0
  158. package/skills/case-execution/SKILL.md +19 -2
  159. package/skills/lantern-workflow/SKILL.md +39 -1
  160. package/dist/_astro/Base.Du_-4L-4.css +0 -1
  161. package/dist/_astro/CaseExecutionBoard.CjX4CoKd.js +0 -5
  162. package/dist/_astro/CaseGenerateApp.acgnxl79.js +0 -10
  163. package/dist/_astro/CasesLibrary.zmzOQwdn.js +0 -21
  164. package/dist/_astro/ChatApp.Ben9LFra.js +0 -1
  165. package/dist/_astro/ChatApp.DBi6q7Qv.js +0 -262
  166. package/dist/_astro/NavLibraries.DVR5Ua-S.js +0 -1
  167. package/dist/_astro/PmRequirementsBoard.B0W6bsW2.js +0 -1
  168. package/dist/_astro/SlideOverDrawer.BMg2tce6.js +0 -1
  169. package/dist/_astro/TemplatesLibrary.peYzrHZ2.js +0 -1
  170. package/dist/_astro/UiAutoBoard.BGdlp5Sr.js +0 -3
  171. package/dist/_astro/UiAutoEnvPanel.BUASgPLB.js +0 -10
  172. package/dist/_astro/UiAutoGenerationDialog.D1PyCgrD.js +0 -12
  173. package/dist/_astro/UiAutoProjectsPage.B6A9NlVK.js +0 -3
  174. package/dist/_astro/app-config.Dvfzl5_N.js +0 -1
  175. package/dist/_astro/app-version.CNpnKIb9.js +0 -1
  176. package/dist/_astro/case-fields.CmePqYfh.js +0 -148
  177. package/dist/_astro/case-gen-run.Cvvdv_kv.js +0 -26
  178. package/dist/_astro/case-prompt.CZ3vWUju.js +0 -2
  179. package/dist/_astro/plugins.Db9xoFZb.js +0 -1
@@ -357,7 +357,12 @@ function normalizeStore(kind, raw) {
357
357
  // 维度名称按创建时间倒序:最新创建的在最上面,老数据缺的按记录创建时间补进来
358
358
  const arranged = arrangeOptions(
359
359
  kind,
360
- mergeOptions(DEFAULT_TEST_DIMENSIONS, [...uniqueTexts(raw.dimensions), ...used]),
360
+ mergeOptions(
361
+ Array.isArray(raw.dimensions)
362
+ ? uniqueTexts(raw.dimensions, 200, 40)
363
+ : DEFAULT_TEST_DIMENSIONS,
364
+ used,
365
+ ),
361
366
  raw.dimensionCreatedAt,
362
367
  items,
363
368
  );
@@ -452,6 +457,23 @@ function patchCaseItem(body, base) {
452
457
  return next;
453
458
  }
454
459
 
460
+ function statsRevision(store, root, kind) {
461
+ return crypto
462
+ .createHash('sha256')
463
+ .update(JSON.stringify({ root: path.resolve(root), kind, store }))
464
+ .digest('hex');
465
+ }
466
+
467
+ function checkRevision(body, store, root, kind) {
468
+ const currentRevision = statsRevision(store, root, kind);
469
+ if (body.expectedRevision !== undefined && body.expectedRevision !== currentRevision) {
470
+ throw Object.assign(new Error('统计数据已被其他操作修改,请重新读取后再保存'), {
471
+ statusCode: 409,
472
+ currentRevision,
473
+ });
474
+ }
475
+ }
476
+
455
477
  function optionsPayload(kind, store) {
456
478
  return kind === 'testStats' ? { dimensions: store.dimensions } : { projects: store.projects };
457
479
  }
@@ -485,7 +507,11 @@ export function lhStatsPlugin() {
485
507
 
486
508
  if (method === 'GET' && !itemId) {
487
509
  const store = readStore(root, kind);
488
- return sendJson(res, 200, { ok: true, ...store });
510
+ return sendJson(res, 200, {
511
+ ok: true,
512
+ ...store,
513
+ revision: statsRevision(store, root, kind),
514
+ });
489
515
  }
490
516
 
491
517
  // 选项级操作(项目名称 / 测试统计维度):重命名 / 删除整条选项。
@@ -496,8 +522,27 @@ export function lhStatsPlugin() {
496
522
  const maxLen = isDim ? 40 : 120;
497
523
  const body = JSON.parse((await readBody(req)) || '{}');
498
524
  const store = readStore(root, kind);
525
+ checkRevision(body, store, root, kind);
499
526
  const options = optionsOf(kind, store);
500
527
 
528
+ if (method === 'POST' && isDim) {
529
+ const name = text(body.name, maxLen);
530
+ if (!name) return sendJson(res, 400, { ok: false, error: `缺少${label}` });
531
+ if (!options.includes(name)) {
532
+ if (options.length >= 200)
533
+ return sendJson(res, 422, { ok: false, error: '选项最多 200 个' });
534
+ setOptions(kind, store, [...options, name]);
535
+ rememberOptionCreatedAt(kind, store, [name]);
536
+ refreshOptionOrder(kind, store);
537
+ writeStore(root, kind, store);
538
+ }
539
+ return sendJson(res, 200, {
540
+ ok: true,
541
+ revision: statsRevision(store, root, kind),
542
+ ...optionsPayload(kind, store),
543
+ });
544
+ }
545
+
501
546
  if (method === 'PUT') {
502
547
  const from = text(body.from, maxLen);
503
548
  const to = text(body.to, maxLen);
@@ -514,6 +559,7 @@ export function lhStatsPlugin() {
514
559
  }
515
560
  return sendJson(res, 200, {
516
561
  ok: true,
562
+ revision: statsRevision(store, root, kind),
517
563
  replaced,
518
564
  items: store.items,
519
565
  ...optionsPayload(kind, store),
@@ -546,6 +592,7 @@ export function lhStatsPlugin() {
546
592
  writeStore(root, kind, store);
547
593
  return sendJson(res, 200, {
548
594
  ok: true,
595
+ revision: statsRevision(store, root, kind),
549
596
  removed: 1,
550
597
  items: store.items,
551
598
  ...optionsPayload(kind, store),
@@ -564,6 +611,7 @@ export function lhStatsPlugin() {
564
611
  const name = text(body.name, 120);
565
612
  if (!name) return sendJson(res, 400, { ok: false, error: '缺少项目名称' });
566
613
  const store = readStore(root, kind);
614
+ checkRevision(body, store, root, kind);
567
615
  const targets = store.items.filter((x) => x.project === name);
568
616
  if (!targets.length) {
569
617
  return sendJson(res, 404, { ok: false, error: '项目名称不存在或还没有统计记录' });
@@ -611,6 +659,7 @@ export function lhStatsPlugin() {
611
659
  sessionId: body.sessionId,
612
660
  };
613
661
  const store = readStore(root, kind);
662
+ checkRevision(body, store, root, kind);
614
663
  const created = [];
615
664
  for (const raw of rawItems) {
616
665
  const item =
@@ -643,6 +692,7 @@ export function lhStatsPlugin() {
643
692
  writeStore(root, kind, store);
644
693
  return sendJson(res, 200, {
645
694
  ok: true,
695
+ revision: statsRevision(store, root, kind),
646
696
  items: created,
647
697
  total: store.items.length,
648
698
  ...optionsPayload(kind, store),
@@ -654,6 +704,7 @@ export function lhStatsPlugin() {
654
704
  const id = text(body.id ?? itemId, 64);
655
705
  if (!id) return sendJson(res, 400, { ok: false, error: '缺少记录 id' });
656
706
  const store = readStore(root, kind);
707
+ checkRevision(body, store, root, kind);
657
708
  const idx = store.items.findIndex((x) => x.id === id);
658
709
  if (idx < 0) return sendJson(res, 404, { ok: false, error: '记录不存在' });
659
710
 
@@ -676,6 +727,7 @@ export function lhStatsPlugin() {
676
727
  writeStore(root, kind, store);
677
728
  return sendJson(res, 200, {
678
729
  ok: true,
730
+ revision: statsRevision(store, root, kind),
679
731
  item: next,
680
732
  ...optionsPayload(kind, store),
681
733
  });
@@ -688,16 +740,25 @@ export function lhStatsPlugin() {
688
740
  .filter(Boolean);
689
741
  if (!ids.length) return sendJson(res, 400, { ok: false, error: '缺少记录 id' });
690
742
  const store = readStore(root, kind);
743
+ checkRevision(body, store, root, kind);
691
744
  const drop = new Set(ids);
692
745
  const before = store.items.length;
693
746
  store.items = store.items.filter((x) => !drop.has(x.id));
694
747
  writeStore(root, kind, store);
695
- return sendJson(res, 200, { ok: true, removed: before - store.items.length });
748
+ return sendJson(res, 200, {
749
+ ok: true,
750
+ removed: before - store.items.length,
751
+ revision: statsRevision(store, root, kind),
752
+ });
696
753
  }
697
754
 
698
755
  return sendJson(res, 405, { ok: false, error: 'Method Not Allowed' });
699
756
  } catch (err) {
700
- return sendJson(res, 500, { ok: false, error: String(err?.message ?? err) });
757
+ return sendJson(res, Number(err?.statusCode) || 500, {
758
+ ok: false,
759
+ error: String(err?.message ?? err),
760
+ ...(err?.currentRevision ? { currentRevision: err.currentRevision } : {}),
761
+ });
701
762
  }
702
763
  });
703
764
  },
@@ -67,6 +67,7 @@ import {
67
67
  taskView,
68
68
  } from './uiauto-adapters/tasks.mjs';
69
69
  import { hasFilesInside, hasReportEntry, snapshotReport } from './uiauto-report.mjs';
70
+ import { readAutomationLinks, upsertAutomationLinks } from './case-automation/store.mjs';
70
71
  import { nodeInstallPlan, nodeStatus, withProjectNode, writeNvmrc } from './uiauto-node.mjs';
71
72
  import { resolvePackageManager } from './uiauto-pm.mjs';
72
73
  import {
@@ -1395,6 +1396,40 @@ function normalizeRun(raw) {
1395
1396
  .filter(Boolean)
1396
1397
  .slice(0, 50)
1397
1398
  : [],
1399
+ tests: Array.isArray(raw.tests)
1400
+ ? raw.tests
1401
+ .filter((item) => item && typeof item === 'object')
1402
+ .slice(0, 5000)
1403
+ .map((item) => ({
1404
+ title: text(item.title, 1000),
1405
+ file: text(item.file, 1024),
1406
+ line: intOr(item.line, 0, 0, Number.MAX_SAFE_INTEGER),
1407
+ tags: Array.isArray(item.tags)
1408
+ ? item.tags
1409
+ .map((tag) => text(tag, 100))
1410
+ .filter(Boolean)
1411
+ .slice(0, 20)
1412
+ : [],
1413
+ annotations: Array.isArray(item.annotations)
1414
+ ? item.annotations
1415
+ .map((annotation) => ({
1416
+ type: text(annotation?.type, 200),
1417
+ description: text(annotation?.description, 2000),
1418
+ }))
1419
+ .filter((annotation) => annotation.type)
1420
+ .slice(0, 20)
1421
+ : [],
1422
+ automationCaseId: text(item.automationCaseId, 200),
1423
+ status: text(item.status, 40),
1424
+ durationMs: intOr(item.durationMs, 0, 0, Number.MAX_SAFE_INTEGER),
1425
+ errors: Array.isArray(item.errors)
1426
+ ? item.errors
1427
+ .map((error) => text(error, 2000))
1428
+ .filter(Boolean)
1429
+ .slice(0, 20)
1430
+ : [],
1431
+ }))
1432
+ : [],
1398
1433
  reportRel: text(raw.reportRel, 1024),
1399
1434
  // Allure 静态报告快照目录 + 「有原始结果、可以 generate」标记
1400
1435
  allureRel: text(raw.allureRel, 1024),
@@ -1993,6 +2028,7 @@ function finishRun(root, entry, runId, exitCode, spawnError) {
1993
2028
  run.failed = summary.failed;
1994
2029
  run.skipped = summary.skipped;
1995
2030
  run.flaky = summary.flaky;
2031
+ run.tests = summary.tests;
1996
2032
  if (summary.projectNames.length) run.projectNames = summary.projectNames;
1997
2033
  run.reportRel = reportRel;
1998
2034
  run.allureRel = allureRel;
@@ -2189,6 +2225,7 @@ function startRun(root, body) {
2189
2225
  taskId,
2190
2226
  taskLabel: task ? taskCommandLine(task) : '',
2191
2227
  projectNames: [],
2228
+ tests: [],
2192
2229
  reportRel: '',
2193
2230
  resultRel,
2194
2231
  logRel,
@@ -4462,6 +4499,35 @@ export function lhUiautoPlugin() {
4462
4499
  return findProject(store, projectId);
4463
4500
  };
4464
4501
 
4502
+ const applyPinnedIterationTarget = (project, record, files) => {
4503
+ const iterationFile = text(record?.iterationFile, 500).replace(/\\/g, '/');
4504
+ if (!iterationFile) return files;
4505
+ const layout = detectEmitLayout(project.dir);
4506
+ const fixture = `${layout.fixturesDir}/test.ts`.replace(/\\/g, '/');
4507
+ const fixtureAbs = path.join(project.dir, fixture);
4508
+ const testImport = fs.existsSync(fixtureAbs)
4509
+ ? path.posix
4510
+ .relative(path.posix.dirname(iterationFile), fixture.replace(/\.ts$/, ''))
4511
+ .replace(/^([^.])/, './$1')
4512
+ : '@playwright/test';
4513
+ return files.map((file) =>
4514
+ file.role === 'spec'
4515
+ ? {
4516
+ ...file,
4517
+ path: iterationFile,
4518
+ testImport,
4519
+ content:
4520
+ testImport === '@playwright/test'
4521
+ ? file.content
4522
+ : file.content.replace(
4523
+ "import { test, expect } from '@playwright/test';",
4524
+ `import { test, expect } from '${testImport}';`,
4525
+ ),
4526
+ }
4527
+ : file,
4528
+ );
4529
+ };
4530
+
4465
4531
  const requireExplorer = async (sessionId) => {
4466
4532
  const record = readGeneratedSession(agentBaseDir, sessionId);
4467
4533
  if (!record) throw new Error('生成会话不存在');
@@ -4877,13 +4943,22 @@ export function lhUiautoPlugin() {
4877
4943
  pagesDir: '',
4878
4944
  fixturesDir: '',
4879
4945
  };
4880
- const multi = emitFiles(body.ir || {}, body.target, {
4946
+ const record = text(body.sessionId, 64)
4947
+ ? readGeneratedSession(agentBaseDir, text(body.sessionId, 64))
4948
+ : null;
4949
+ let multi = emitFiles(body.ir || {}, body.target, {
4881
4950
  testDir: layout.testDir,
4882
4951
  pagesDir: layout.pagesDir || undefined,
4883
4952
  fixturesDir: layout.fixturesDir || undefined,
4884
4953
  tag: text(body.tag, 40),
4885
4954
  hasBaseURL: Boolean(body.hasBaseURL),
4886
4955
  });
4956
+ if (project && record) {
4957
+ multi = {
4958
+ ...multi,
4959
+ files: applyPinnedIterationTarget(project, record, multi.files),
4960
+ };
4961
+ }
4887
4962
  return sendJson(res, 200, {
4888
4963
  ok: true,
4889
4964
  code: emitted.code,
@@ -4891,6 +4966,16 @@ export function lhUiautoPlugin() {
4891
4966
  language: emitted.language,
4892
4967
  files: multi.files,
4893
4968
  configPatch: multi.configPatch,
4969
+ suggestedPath: project
4970
+ ? suggestedPath({
4971
+ project,
4972
+ session: record || {
4973
+ target: body.target,
4974
+ title: body.title,
4975
+ ir: body.ir || {},
4976
+ },
4977
+ })
4978
+ : '',
4894
4979
  });
4895
4980
  }
4896
4981
 
@@ -4961,7 +5046,9 @@ export function lhUiautoPlugin() {
4961
5046
  ...detectEmitLayout(project.dir),
4962
5047
  hasBaseURL: projectHasBaseURL(project.dir),
4963
5048
  });
4964
- files = emitted.files;
5049
+ files = applyPinnedIterationTarget(project, record, emitted.files);
5050
+ } else if (record.iterationFile) {
5051
+ files = applyPinnedIterationTarget(project, record, files);
4965
5052
  }
4966
5053
 
4967
5054
  const result = writeGeneratedFiles({
@@ -4989,6 +5076,20 @@ export function lhUiautoPlugin() {
4989
5076
  savedPaths: mergedSaved,
4990
5077
  changes: result.changes,
4991
5078
  });
5079
+ if (record.automationCaseId) {
5080
+ const link = readAutomationLinks(root).items.find(
5081
+ (item) => item.automationCaseId === record.automationCaseId,
5082
+ );
5083
+ if (link) {
5084
+ upsertAutomationLinks(root, [
5085
+ {
5086
+ ...link,
5087
+ scriptPath: spec || link.iterationFile || '',
5088
+ status: link.status === 'stale' ? 'stale' : 'connected',
5089
+ },
5090
+ ]);
5091
+ }
5092
+ }
4992
5093
  }
4993
5094
  return sendJson(res, result.ok ? 200 : 409, {
4994
5095
  ...result,
@@ -5237,3 +5338,11 @@ export function lhUiautoPlugin() {
5237
5338
  },
5238
5339
  };
5239
5340
  }
5341
+
5342
+ // In-process bridge: preserve the originating space while an execution plan runs.
5343
+ export { startRun as startAutomationProjectRun, stopRun as stopAutomationProjectRun };
5344
+ export function readAutomationProjectRun(root, id) {
5345
+ const run = findRun(readStore(root).store, id);
5346
+ if (!run) throw new Error('自动化执行记录不存在');
5347
+ return runView(run);
5348
+ }
@@ -70,6 +70,7 @@ export const PLUGIN_PROMPT_FILES = Object.freeze({
70
70
  '用例质量评审提示词.md': 'caseReview',
71
71
  '场景遗漏补全提示词.md': 'caseBlindspot',
72
72
  '用例执行提示词.md': 'caseExecution',
73
+ '功能用例转UI自动化提示词.md': 'uiAuto',
73
74
  '功能测试报告提示词.md': 'testReports',
74
75
  '接口测试报告提示词.md': 'testReports',
75
76
  '性能测试报告提示词.md': 'testReports',
@@ -118,23 +118,62 @@ export function parsePlaywrightReport(raw) {
118
118
  .slice(0, 20)
119
119
  : [];
120
120
  const failedTests = [];
121
+ const tests = [];
121
122
  const walk = (suite, trail) => {
122
123
  if (!suite || typeof suite !== 'object') return;
123
124
  const file = text(suite.file, 1024);
124
125
  const own = text(suite.title, 500);
125
126
  const nextTrail = own ? [...trail, own] : trail;
126
127
  for (const spec of Array.isArray(suite.specs) ? suite.specs : []) {
127
- const tests = Array.isArray(spec?.tests) ? spec.tests : [];
128
- const bad = tests.some(
128
+ const specTests = Array.isArray(spec?.tests) ? spec.tests : [];
129
+ const title = [...nextTrail, text(spec?.title, 500)].filter(Boolean).join(' › ');
130
+ const specAnnotations = Array.isArray(spec?.annotations) ? spec.annotations : [];
131
+ const tags = Array.isArray(spec?.tags) ? spec.tags.map((tag) => text(tag, 100)) : [];
132
+ for (const test of specTests.length ? specTests : [{}]) {
133
+ const annotations = [
134
+ ...specAnnotations,
135
+ ...(Array.isArray(test?.annotations) ? test.annotations : []),
136
+ ]
137
+ .map((item) => ({
138
+ type: text(item?.type, 200),
139
+ description: text(item?.description, 2000),
140
+ }))
141
+ .filter((item) => item.type);
142
+ const results = Array.isArray(test?.results) ? test.results : [];
143
+ const status = text(test?.status, 40) || (results[0] ? text(results[0].status, 40) : '');
144
+ const errors = results
145
+ .flatMap((result) => (Array.isArray(result?.errors) ? result.errors : []))
146
+ .map((item) => text(item?.message || item?.stack, 2000))
147
+ .filter(Boolean)
148
+ .slice(0, 20);
149
+ const durationMs = results.reduce(
150
+ (sum, result) => sum + intOr(result?.duration, 0, 0, Number.MAX_SAFE_INTEGER),
151
+ 0,
152
+ );
153
+ const automation = annotations.find((item) => item.type === 'com.lantern.automationCaseId');
154
+ tests.push({
155
+ title,
156
+ file,
157
+ line: intOr(spec?.line, 0, 0, Number.MAX_SAFE_INTEGER),
158
+ tags,
159
+ annotations,
160
+ automationCaseId: automation?.description || '',
161
+ status,
162
+ durationMs,
163
+ errors,
164
+ });
165
+ if (tests.length >= 5000) break;
166
+ }
167
+ const unmatched = specTests.some(
129
168
  (t) =>
130
169
  t?.status === 'unexpected' ||
131
170
  t?.status === 'timedOut' ||
132
171
  (Array.isArray(t?.results) &&
133
172
  t.results.some((r) => r?.status === 'unexpected' || r?.status === 'timedOut')),
134
173
  );
135
- if (!bad) continue;
174
+ if (!unmatched) continue;
136
175
  failedTests.push({
137
- title: [...nextTrail, text(spec?.title, 500)].filter(Boolean).join(' › '),
176
+ title,
138
177
  file,
139
178
  });
140
179
  if (failedTests.length >= 50) return;
@@ -151,6 +190,7 @@ export function parsePlaywrightReport(raw) {
151
190
  durationMs: intOr(stats.duration, 0, 0, Number.MAX_SAFE_INTEGER),
152
191
  errors,
153
192
  failedTests,
193
+ tests,
154
194
  projectNames,
155
195
  };
156
196
  }
@@ -261,6 +261,7 @@ export function emptySummary() {
261
261
  durationMs: 0,
262
262
  errors: [],
263
263
  failedTests: [],
264
+ tests: [],
264
265
  projectNames: [],
265
266
  };
266
267
  }
@@ -329,6 +330,9 @@ export function mergeSummaries(list) {
329
330
  for (const failed of item.failedTests ?? []) {
330
331
  if (out.failedTests.length < 50) out.failedTests.push(failed);
331
332
  }
333
+ for (const test of item.tests ?? []) {
334
+ if (out.tests.length < 5000) out.tests.push(test);
335
+ }
332
336
  for (const name of item.projectNames ?? []) {
333
337
  if (!out.projectNames.includes(name)) out.projectNames.push(name);
334
338
  }
@@ -202,6 +202,8 @@ export function renderTsPage(page) {
202
202
  /** TS spec:导航留在用例里,元素操作调 page object */
203
203
  export function renderTsSpec(ir, pages, options = {}) {
204
204
  const title = ir.title || 'AI 生成用例';
205
+ const automationCaseId = String(ir.automationCaseId || '').replace(/[^A-Za-z0-9_-]/g, '');
206
+ const automationTag = automationCaseId ? `@lantern-${automationCaseId.toLowerCase()}` : '';
205
207
  const lines = [];
206
208
  lines.push('/**');
207
209
  lines.push(` * ${title}`);
@@ -211,7 +213,7 @@ export function renderTsSpec(ir, pages, options = {}) {
211
213
  }
212
214
  }
213
215
  lines.push(' */');
214
- lines.push("import { test, expect } from '@playwright/test';");
216
+ lines.push(`import { test, expect } from '${options.testImport || '@playwright/test'}';`);
215
217
  // 页面对象可能在根级 pages/(企业级骨架)或 tests/pages/(老布局),import 按实际相对位置算
216
218
  const pagesImport = options.pagesImport || './pages';
217
219
  for (const page of pages) {
@@ -232,10 +234,20 @@ export function renderTsSpec(ir, pages, options = {}) {
232
234
  lines.push('');
233
235
  }
234
236
 
237
+ if (automationCaseId) lines.push(`/* lantern-automation:start ${automationCaseId} */`);
235
238
  lines.push(`test.describe(${q(title)}, () => {`);
239
+ const tags = [
240
+ normalizeTag(ir.tag) || normalizeTag(options.tag) || DEFAULT_TEST_TAG,
241
+ ...(automationTag ? [automationTag] : []),
242
+ ];
236
243
  lines.push(
237
- ` test(${q(title)}, { tag: [${q(normalizeTag(ir.tag) || normalizeTag(options.tag) || DEFAULT_TEST_TAG)}] }, async ({ page }) => {`,
244
+ ` test(${q(title)}, { tag: [${tags.map((tag) => q(tag)).join(', ')}] }, async ({ page }, testInfo) => {`,
238
245
  );
246
+ if (automationCaseId) {
247
+ lines.push(
248
+ ` testInfo.annotations.push({ type: 'com.lantern.automationCaseId', description: ${q(automationCaseId)} });`,
249
+ );
250
+ }
239
251
  if (ir.baseURL) lines.push(` // baseURL: ${ir.baseURL}`);
240
252
  for (const page of pages) {
241
253
  lines.push(` const ${varName(page.name)} = new ${page.name}(page);`);
@@ -281,6 +293,7 @@ export function renderTsSpec(ir, pages, options = {}) {
281
293
  }
282
294
  lines.push(' });');
283
295
  lines.push('});');
296
+ if (automationCaseId) lines.push(`/* lantern-automation:end ${automationCaseId} */`);
284
297
  lines.push('');
285
298
  return lines.join('\n');
286
299
  }
@@ -488,6 +501,7 @@ export function emitFiles(rawIr, target, options = {}) {
488
501
  fixtureImport,
489
502
  pagesImport: relativeImport(testDir, pagesDir),
490
503
  tag: options.tag,
504
+ testImport: options.testImport,
491
505
  }),
492
506
  language: 'ts',
493
507
  role: 'spec',
@@ -71,6 +71,9 @@ export function normalizeIr(raw, fallback = {}) {
71
71
  target: (source.target ?? fallback.target) === 'python' ? 'python' : 'ts',
72
72
  baseURL: String(source.baseURL ?? fallback.baseURL ?? ''),
73
73
  storageState: String(source.storageState ?? fallback.storageState ?? ''),
74
+ automationCaseId: String(source.automationCaseId ?? fallback.automationCaseId ?? '')
75
+ .replace(/[^A-Za-z0-9_-]/g, '')
76
+ .slice(0, 80),
74
77
  // 分级标签:为空表示用缺省级别(出码时补 @regression)
75
78
  tag: normalizeTag(source.tag ?? fallback.tag),
76
79
  source: String(source.source ?? fallback.source ?? '').slice(0, 2000),
@@ -114,6 +114,42 @@ export function mergeSpec(existing, incoming, lang) {
114
114
  return { content, unchanged: false };
115
115
  }
116
116
 
117
+ /**
118
+ * 合并带 automationCaseId 边界的 TS 测试块。
119
+ * 同一自动化用例重新生成时只替换自己的块,保留 iteration 文件里的其它测试。
120
+ */
121
+ export function mergeAutomationSpecBlock(existing, incoming, lang = 'ts') {
122
+ if (lang !== 'ts') return mergeSpec(existing, incoming, lang);
123
+ const id = /\/\* lantern-automation:start ([A-Za-z0-9_-]+) \*\//.exec(incoming)?.[1] || '';
124
+ if (!id) return mergeSpec(existing, incoming, lang);
125
+ const start = `/* lantern-automation:start ${id} */`;
126
+ const end = `/* lantern-automation:end ${id} */`;
127
+ const incStart = incoming.indexOf(start);
128
+ const incEnd = incoming.indexOf(end, incStart);
129
+ if (incStart < 0 || incEnd < 0) return null;
130
+ const incomingBlock = incoming.slice(incStart, incEnd + end.length);
131
+ const oldStart = existing.indexOf(start);
132
+ if (oldStart < 0) return mergeSpec(existing, incoming, lang);
133
+ if (existing.indexOf(start, oldStart + 1) >= 0 || existing.indexOf(end, oldStart) < 0)
134
+ return null;
135
+ const oldEnd = existing.indexOf(end, oldStart);
136
+ const next = existing.slice(0, oldStart) + incomingBlock + existing.slice(oldEnd + end.length);
137
+ const incLines = incoming.split('\n');
138
+ const [, incLastImport] = importRange(incLines, lang);
139
+ const existingSet = new Set(next.split('\n').map((line) => line.trim()));
140
+ const missing = [];
141
+ for (let index = 0; index <= incLastImport; index += 1) {
142
+ const line = incLines[index];
143
+ if (!isImportLine(line, lang)) continue;
144
+ const trimmed = line.trim();
145
+ if (!existingSet.has(trimmed)) missing.push(trimmed);
146
+ }
147
+ return {
148
+ content: insertImports(next, missing, lang),
149
+ unchanged: next === existing && !missing.length,
150
+ };
151
+ }
152
+
117
153
  /** TS page object 里的方法块(2 空格缩进,按大括号配平取方法体) */
118
154
  function tsMethods(text) {
119
155
  const lines = text.split('\n');
@@ -227,7 +263,7 @@ export function mergeGeneratedFile(existing, incoming, options = {}) {
227
263
  if (before.trim() === after.trim()) return { content: before, unchanged: true };
228
264
 
229
265
  const lang = guessLang(after, filePath);
230
- if (role === 'spec') return mergeSpec(before, after, lang);
266
+ if (role === 'spec') return mergeAutomationSpecBlock(before, after, lang);
231
267
  if (role === 'page')
232
268
  return lang === 'python' ? mergePyPage(before, after) : mergeTsPage(before, after);
233
269
  if (role === 'fixture') return mergeFixture(before, after);