@buaa_smat/hometrans 26.0.0 → 26.0.2

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 (148) hide show
  1. package/README.md +7 -1
  2. package/package.json +11 -82
  3. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/ets/pages/Index.ets +2 -2
  4. package/skills/a2h-arch-generate/scripts/module_create/har/src/main/ets/components/MainPage.ets +2 -2
  5. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/ets/pages/Index.ets +2 -2
  6. package/skills/a2h-batch-ui-align/references/conversion-procedure.md +1 -1
  7. package/skills/a2h-batch-ui-align/references/state-mgmt/_/350/214/203/345/274/217/351/200/211/346/213/251/350/257/264/346/230/216.md +1 -1
  8. package/skills/a2h-batch-ui-align/references/step3-capture.md +3 -3
  9. package/skills/a2h-batch-ui-align/references/step4-prepare.md +1 -1
  10. package/skills/a2h-batch-ui-align/scripts/detect_paradigm.mjs +11 -6
  11. package/skills/a2h-batch-ui-align/scripts/export_ui_info.mjs +59 -21
  12. package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +3 -3
  13. package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +1 -1
  14. package/skills/a2h-batch-ui-align/scripts/static_check/core/scan.ts +1 -1
  15. package/skills/a2h-utg-explorer/SKILL.md +1 -1
  16. package/skills/a2h-utg-explorer/references/architecture.md +2 -2
  17. package/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +36 -11
  18. package/skills/a2h-utg-explorer/scripts/device_health.mjs +91 -6
  19. package/skills/a2h-utg-explorer/scripts/final_utg.mjs +20 -2
  20. package/skills/a2h-utg-explorer/scripts/hint_check.mjs +64 -8
  21. package/skills/a2h-utg-explorer/scripts/hint_source.mjs +119 -0
  22. package/skills/a2h-utg-explorer/scripts/recover.mjs +7 -1
  23. package/skills/a2h-utg-explorer/scripts/recover_b.mjs +8 -1
  24. package/skills/a2h-utg-explorer/scripts/utg_explorer/adapters.mjs +89 -7
  25. package/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +173 -4
  26. package/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +82 -14
  27. package/skills/a2h-utg-static/SKILL.md +1 -1
  28. package/skills/a2h-utg-static/references/view-interactions.md +1 -1
  29. package/skills/a2h-utg-static/scripts/assemble.mjs +6 -3
  30. package/skills/a2h-utg-static/scripts/compose_body_text.mjs +23 -5
  31. package/skills/a2h-utg-static/scripts/compose_overlay.mjs +29 -3
  32. package/skills/a2h-utg-static/scripts/compose_titles.mjs +10 -1
  33. package/skills/a2h-utg-static/scripts/label_resolve.mjs +51 -2
  34. package/skills/a2h-utg-static/scripts/static_prior.mjs +2 -1
  35. package/skills/a2h-utg-static/scripts/tests/_zipw.mjs +28 -0
  36. package/skills/a2h-utg-static/scripts/tests/probe_autoload.mjs +108 -0
  37. package/skills/a2h-utg-static/scripts/tests/probe_layout_fragments.mjs +90 -0
  38. package/skills/a2h-utg-static/scripts/tests/probe_unknown_scope.mjs +61 -0
  39. package/skills/a2h-utg-static/scripts/tests/regression_matrix.mjs +1261 -0
  40. package/skills/a2h-utg-static/scripts/tests/test_activity_alias_launcher.mjs +135 -0
  41. package/skills/a2h-utg-static/scripts/tests/test_activity_supertype_chain.mjs +106 -0
  42. package/skills/a2h-utg-static/scripts/tests/test_bottom_sheet_container.mjs +58 -0
  43. package/skills/a2h-utg-static/scripts/tests/test_branch_guard.mjs +19 -0
  44. package/skills/a2h-utg-static/scripts/tests/test_callee_string_default.mjs +30 -0
  45. package/skills/a2h-utg-static/scripts/tests/test_carry_answers.mjs +103 -0
  46. package/skills/a2h-utg-static/scripts/tests/test_chrome_tokens.mjs +60 -0
  47. package/skills/a2h-utg-static/scripts/tests/test_commented_out_trigger.mjs +111 -0
  48. package/skills/a2h-utg-static/scripts/tests/test_commit_scope.mjs +113 -0
  49. package/skills/a2h-utg-static/scripts/tests/test_compose_file_private_route.mjs +117 -0
  50. package/skills/a2h-utg-static/scripts/tests/test_compose_nested_graph.mjs +166 -0
  51. package/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +108 -0
  52. package/skills/a2h-utg-static/scripts/tests/test_compose_route_holder_collision.mjs +112 -0
  53. package/skills/a2h-utg-static/scripts/tests/test_compose_vm_nav.mjs +289 -0
  54. package/skills/a2h-utg-static/scripts/tests/test_custom_source_root.mjs +71 -0
  55. package/skills/a2h-utg-static/scripts/tests/test_defensive_null_guard.mjs +77 -0
  56. package/skills/a2h-utg-static/scripts/tests/test_dialog_orphan_entries.mjs +99 -0
  57. package/skills/a2h-utg-static/scripts/tests/test_dialog_page_owner.mjs +69 -0
  58. package/skills/a2h-utg-static/scripts/tests/test_dialogshow_builder_forms.mjs +96 -0
  59. package/skills/a2h-utg-static/scripts/tests/test_dialogshow_java_factory.mjs +37 -0
  60. package/skills/a2h-utg-static/scripts/tests/test_disabled_guard.mjs +42 -0
  61. package/skills/a2h-utg-static/scripts/tests/test_drawer_panel_gesture.mjs +140 -0
  62. package/skills/a2h-utg-static/scripts/tests/test_edge_dedupe_by_gesture.mjs +111 -0
  63. package/skills/a2h-utg-static/scripts/tests/test_edge_provenance_lint.mjs +70 -0
  64. package/skills/a2h-utg-static/scripts/tests/test_enclosing_gesture.mjs +69 -0
  65. package/skills/a2h-utg-static/scripts/tests/test_external_surface_roots.mjs +43 -0
  66. package/skills/a2h-utg-static/scripts/tests/test_find_package_indirect.mjs +67 -0
  67. package/skills/a2h-utg-static/scripts/tests/test_forwarding_wrapper.mjs +38 -0
  68. package/skills/a2h-utg-static/scripts/tests/test_fragment_containment.mjs +85 -0
  69. package/skills/a2h-utg-static/scripts/tests/test_fragment_helper_trigger.mjs +92 -0
  70. package/skills/a2h-utg-static/scripts/tests/test_fresh_branch_guard.mjs +49 -0
  71. package/skills/a2h-utg-static/scripts/tests/test_graph.mjs +55 -0
  72. package/skills/a2h-utg-static/scripts/tests/test_guard_clause.mjs +86 -0
  73. package/skills/a2h-utg-static/scripts/tests/test_hint_language.mjs +136 -0
  74. package/skills/a2h-utg-static/scripts/tests/test_host_kind_by_chain.mjs +68 -0
  75. package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundle_attribution.mjs +74 -0
  76. package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundled_pages.mjs +181 -0
  77. package/skills/a2h-utg-static/scripts/tests/test_hybrid_scope.mjs +293 -0
  78. package/skills/a2h-utg-static/scripts/tests/test_hybrid_title_renders.mjs +118 -0
  79. package/skills/a2h-utg-static/scripts/tests/test_i18n_term.mjs +155 -0
  80. package/skills/a2h-utg-static/scripts/tests/test_interaction_sites.mjs +272 -0
  81. package/skills/a2h-utg-static/scripts/tests/test_item_data_instance.mjs +51 -0
  82. package/skills/a2h-utg-static/scripts/tests/test_kotlin_fn_spans.mjs +69 -0
  83. package/skills/a2h-utg-static/scripts/tests/test_label_accessor_forms.mjs +187 -0
  84. package/skills/a2h-utg-static/scripts/tests/test_label_source.mjs +70 -0
  85. package/skills/a2h-utg-static/scripts/tests/test_launch_intent_guard.mjs +67 -0
  86. package/skills/a2h-utg-static/scripts/tests/test_layout_declared_fragment.mjs +103 -0
  87. package/skills/a2h-utg-static/scripts/tests/test_listener_call_forms.mjs +79 -0
  88. package/skills/a2h-utg-static/scripts/tests/test_listener_receiver_binding.mjs +47 -0
  89. package/skills/a2h-utg-static/scripts/tests/test_login_interceptor.mjs +328 -0
  90. package/skills/a2h-utg-static/scripts/tests/test_manifest_exported_default.mjs +40 -0
  91. package/skills/a2h-utg-static/scripts/tests/test_manifest_filters_modules.mjs +84 -0
  92. package/skills/a2h-utg-static/scripts/tests/test_manifest_srcfile.mjs +68 -0
  93. package/skills/a2h-utg-static/scripts/tests/test_mode_and_cb_param.mjs +172 -0
  94. package/skills/a2h-utg-static/scripts/tests/test_module_namespace.mjs +83 -0
  95. package/skills/a2h-utg-static/scripts/tests/test_module_strings.mjs +44 -0
  96. package/skills/a2h-utg-static/scripts/tests/test_multiple_entry_contracts.mjs +80 -0
  97. package/skills/a2h-utg-static/scripts/tests/test_nav_graph_xml.mjs +35 -0
  98. package/skills/a2h-utg-static/scripts/tests/test_nl_hint_grammar.mjs +42 -0
  99. package/skills/a2h-utg-static/scripts/tests/test_nl_hints_gate.mjs +85 -0
  100. package/skills/a2h-utg-static/scripts/tests/test_nl_hints_off_path.mjs +67 -0
  101. package/skills/a2h-utg-static/scripts/tests/test_node_id_collision.mjs +57 -0
  102. package/skills/a2h-utg-static/scripts/tests/test_non_gesture_step_flag.mjs +62 -0
  103. package/skills/a2h-utg-static/scripts/tests/test_out_of_scope_and_settings.mjs +72 -0
  104. package/skills/a2h-utg-static/scripts/tests/test_overload_and_climb.mjs +86 -0
  105. package/skills/a2h-utg-static/scripts/tests/test_pager_page_source.mjs +78 -0
  106. package/skills/a2h-utg-static/scripts/tests/test_pager_position_zero.mjs +65 -0
  107. package/skills/a2h-utg-static/scripts/tests/test_pager_variant_guard.mjs +172 -0
  108. package/skills/a2h-utg-static/scripts/tests/test_pipeline_llm_phases.mjs +107 -0
  109. package/skills/a2h-utg-static/scripts/tests/test_plain_dialog_nodes.mjs +167 -0
  110. package/skills/a2h-utg-static/scripts/tests/test_plaindialog_shared_anchor.mjs +117 -0
  111. package/skills/a2h-utg-static/scripts/tests/test_preference_click_nav.mjs +98 -0
  112. package/skills/a2h-utg-static/scripts/tests/test_preference_host_binding.mjs +87 -0
  113. package/skills/a2h-utg-static/scripts/tests/test_preference_nesting.mjs +183 -0
  114. package/skills/a2h-utg-static/scripts/tests/test_preference_widgets.mjs +48 -0
  115. package/skills/a2h-utg-static/scripts/tests/test_read_text_crlf.mjs +41 -0
  116. package/skills/a2h-utg-static/scripts/tests/test_resolver_tier_parity.mjs +126 -0
  117. package/skills/a2h-utg-static/scripts/tests/test_result_launcher.mjs +142 -0
  118. package/skills/a2h-utg-static/scripts/tests/test_review_fixes.mjs +135 -0
  119. package/skills/a2h-utg-static/scripts/tests/test_route_token_words.mjs +66 -0
  120. package/skills/a2h-utg-static/scripts/tests/test_same_name_decl_scope.mjs +236 -0
  121. package/skills/a2h-utg-static/scripts/tests/test_scope_utils.mjs +85 -0
  122. package/skills/a2h-utg-static/scripts/tests/test_sealed_dialog_state.mjs +148 -0
  123. package/skills/a2h-utg-static/scripts/tests/test_shared_overlay_split.mjs +63 -0
  124. package/skills/a2h-utg-static/scripts/tests/test_slug_parity.mjs +58 -0
  125. package/skills/a2h-utg-static/scripts/tests/test_starter_node_id.mjs +41 -0
  126. package/skills/a2h-utg-static/scripts/tests/test_state_guard_arity.mjs +109 -0
  127. package/skills/a2h-utg-static/scripts/tests/test_state_guard_commented_candidates.mjs +68 -0
  128. package/skills/a2h-utg-static/scripts/tests/test_state_guard_model_gates.mjs +127 -0
  129. package/skills/a2h-utg-static/scripts/tests/test_state_specific_hop.mjs +130 -0
  130. package/skills/a2h-utg-static/scripts/tests/test_synthetic_label_identity.mjs +51 -0
  131. package/skills/a2h-utg-static/scripts/tests/test_template_method_layout.mjs +81 -0
  132. package/skills/a2h-utg-static/scripts/tests/test_template_title.mjs +61 -0
  133. package/skills/a2h-utg-static/scripts/tests/test_trigger_id_spelling.mjs +68 -0
  134. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_action_override.mjs +91 -0
  135. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_flow_filter.mjs +110 -0
  136. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_nl_hint_key.mjs +89 -0
  137. package/skills/a2h-utg-static/scripts/tests/test_uiless_host_fold.mjs +98 -0
  138. package/skills/a2h-utg-static/scripts/tests/test_uniapp_data_table.mjs +340 -0
  139. package/skills/a2h-utg-static/scripts/tests/test_uniapp_relative_url.mjs +125 -0
  140. package/skills/a2h-utg-static/scripts/tests/test_uniapp_source.mjs +231 -0
  141. package/skills/a2h-utg-static/scripts/tests/test_view_click_refs.mjs +104 -0
  142. package/skills/a2h-utg-static/scripts/tests/test_view_id_label.mjs +69 -0
  143. package/skills/a2h-utg-static/scripts/tests/test_view_interactions.mjs +346 -0
  144. package/skills/a2h-utg-static/scripts/tests/test_viewpage_nav.mjs +340 -0
  145. package/skills/a2h-utg-static/scripts/tests/test_vm_nav_helper_navigate.mjs +98 -0
  146. package/skills/a2h-utg-static/scripts/tests/test_widget_class_scope.mjs +92 -0
  147. package/skills/a2h-utg-static/scripts/tests/test_window_nav_kotlin.mjs +158 -0
  148. package/skills/a2h-utg-static/scripts/tests/test_worklist_parts.mjs +65 -0
@@ -0,0 +1,340 @@
1
+ // uni-app home menus rendered from an imported JSON route table. The module imports
2
+ // `menu.json`, a forwarder reads the row (`uni.navigateTo({url: menu.url})`), and a grid
3
+ // component calls it with the row variable (`navigateToMenu(menu)`). Each row whose url names a
4
+ // pages.json route is an edge from every page that embeds the grid, labelled with the row's
5
+ // own text. The grid sits under a layout switch whose bare `v-else` branch always renders.
6
+ // Also: a uni-app launcher page (no Manifest class) gets a component launch contract, not
7
+ // `external-surface`, so the explorer can compile tasks from it.
8
+ import { test } from 'node:test';
9
+ import assert from 'node:assert/strict';
10
+ import * as fs from 'node:fs';
11
+ import * as os from 'node:os';
12
+ import * as path from 'node:path';
13
+ import { spawnSync } from 'node:child_process';
14
+ import { fileURLToPath } from 'node:url';
15
+ import { jsonDumps } from '../_py.mjs';
16
+ import { scanTableCalls, dataTables } from '../uniapp_nav.mjs';
17
+
18
+ const SCRIPTS = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
19
+ const NAV = path.join(SCRIPTS, 'uniapp_nav.mjs');
20
+ const PATHS = path.join(SCRIPTS, 'click_paths.mjs');
21
+
22
+ function run(argv) {
23
+ const p = spawnSync(process.execPath, argv, { encoding: 'utf8', maxBuffer: 1 << 28 });
24
+ const recs = (p.stdout || '').split(/\r?\n/).filter((l) => l.trim()).map((l) => JSON.parse(l));
25
+ return [recs.filter((r) => r.type === 'node'), recs.filter((r) => r.type === 'edge'), p.stderr || ''];
26
+ }
27
+ function write(root, rel, text) {
28
+ const p = path.join(root, ...rel.split('/'));
29
+ fs.mkdirSync(path.dirname(p), { recursive: true });
30
+ fs.writeFileSync(p, text, 'utf8');
31
+ }
32
+
33
+ function project() {
34
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'uniapp-table-'));
35
+ write(root, 'src/pages.json', jsonDumps({
36
+ pages: [
37
+ { path: 'pages/index/index', style: { navigationBarTitleText: '工作台' } },
38
+ { path: 'pages-system/user/index', style: { navigationBarTitleText: '用户管理' } },
39
+ { path: 'pages-system/role/index', style: { navigationBarTitleText: '角色管理' } },
40
+ { path: 'pages-crm/hidden/index', style: { navigationBarTitleText: '隐藏' } },
41
+ { path: 'pages-other/lonely/index', style: { navigationBarTitleText: '孤立' } },
42
+ ],
43
+ }, { ensure_ascii: false }));
44
+ write(root, 'src/pages/index/menu.json', jsonDumps({
45
+ groups: [{
46
+ key: 'system', name: '系统管理',
47
+ subGroups: [{
48
+ key: 'permission', name: '权限管理',
49
+ menus: [
50
+ { key: 'user', name: '用户管理', url: '/pages-system/user/index' },
51
+ { key: 'role', name: '角色管理', url: '/pages-system/role/index?x=1' },
52
+ { key: 'gone', name: '不存在', url: '/pages-nowhere/index' },
53
+ { key: 'hidden', name: '隐藏', visible: false, url: '/pages-crm/hidden/index' },
54
+ ],
55
+ }],
56
+ }],
57
+ }, { ensure_ascii: false }));
58
+ write(root, 'src/pages/index/index.ts', `import menuConfig from './menu.json'
59
+ export const groups = menuConfig.groups
60
+ export function useMenuNavigate() {
61
+ function navigateToMenu(menu) {
62
+ uni.navigateTo({ url: menu.url })
63
+ }
64
+ return { navigateToMenu }
65
+ }
66
+ `);
67
+ write(root, 'src/pages/index/components/menu-grid.vue', `<template>
68
+ <view>
69
+ <view v-for="menu in menus" :key="menu.key" @click="navigateToMenu(menu)">{{ menu.name }}</view>
70
+ </view>
71
+ </template>
72
+ <script setup>
73
+ import { useMenuNavigate } from '../index'
74
+ const { navigateToMenu } = useMenuNavigate()
75
+ </script>
76
+ `);
77
+ // A layout switch: three literal branches (a dispatch table) and a bare v-else default.
78
+ for (const name of ['menu-layout-a', 'menu-layout-b', 'menu-layout-c', 'menu-layout-default']) {
79
+ write(root, `src/pages/index/components/${name}.vue`, `<template>
80
+ <view><MenuGrid :menus="m" /></view>
81
+ </template>
82
+ <script setup>
83
+ import MenuGrid from './menu-grid.vue'
84
+ </script>
85
+ `);
86
+ }
87
+ write(root, 'src/pages/index/components/menu-section.vue', `<template>
88
+ <view>
89
+ <MenuLayoutA v-if="layout === 'a'" />
90
+ <MenuLayoutB v-else-if="layout === 'b'" />
91
+ <MenuLayoutC v-else-if="layout === 'c'" />
92
+ <MenuLayoutDefault v-else />
93
+ </view>
94
+ </template>
95
+ <script setup>
96
+ import MenuLayoutA from './menu-layout-a.vue'
97
+ import MenuLayoutB from './menu-layout-b.vue'
98
+ import MenuLayoutC from './menu-layout-c.vue'
99
+ import MenuLayoutDefault from './menu-layout-default.vue'
100
+ </script>
101
+ `);
102
+ write(root, 'src/pages/index/index.vue', `<template>
103
+ <view><MenuSection /></view>
104
+ </template>
105
+ <script setup>
106
+ import MenuSection from './components/menu-section.vue'
107
+ </script>
108
+ `);
109
+ // Same function name, never imported from the table module: must not be credited.
110
+ write(root, 'src/pages-other/lonely/index.vue', `<template>
111
+ <view @click="navigateToMenu(item)">x</view>
112
+ </template>
113
+ <script setup>
114
+ function navigateToMenu(item) { console.log(item) }
115
+ </script>
116
+ `);
117
+ write(root, 'src/manifest.json', jsonDumps({ name: 't', appid: '__UNI__TABLE' }));
118
+ return root;
119
+ }
120
+
121
+ const id = (r) => `hybrid-page:__UNI__TABLE/${r}`;
122
+
123
+ test('rows of an imported JSON table become labelled edges from the embedding page', () => {
124
+ const root = project();
125
+ try {
126
+ const [, edges, stderr] = run([NAV, root]);
127
+ const table = edges.filter((e) => e.args.resolved_by === 'data-table');
128
+ const pairs = table.map((e) => [e.source, e.target, e.args.label]).sort();
129
+ assert.deepEqual(pairs, [
130
+ [id('pages/index/index'), id('pages-system/role/index'), '角色管理'],
131
+ [id('pages/index/index'), id('pages-system/user/index'), '用户管理'],
132
+ ]);
133
+ const user = table.find((e) => e.target === id('pages-system/user/index'));
134
+ assert.equal(user.args.context_label, '权限管理');
135
+ assert.match(user.args.table_row, /^pages\/index\/menu\.json:\d+$/);
136
+ assert.equal(user.args.component, 'pages/index/components/menu-grid.vue');
137
+ assert.match(user.trigger, /menu-grid\.vue:3$/);
138
+ assert.ok(!edges.some((e) => e.source === id('pages-other/lonely/index')), 'unrelated same-name function credited');
139
+ assert.ok(!edges.some((e) => e.target === id('pages-crm/hidden/index')), 'visible:false row emitted');
140
+ assert.match(stderr, /data tables: forwarders=1 rows=2 edges=2/);
141
+ } finally { fs.rmSync(root, { recursive: true, force: true }); }
142
+ });
143
+
144
+ test('a uni-app launcher with no class gets a component launch contract', () => {
145
+ const ws = fs.mkdtempSync(path.join(os.tmpdir(), 'uniapp-launch-'));
146
+ try {
147
+ const home = id('pages/index/index'); const user = id('pages-system/user/index');
148
+ fs.writeFileSync(path.join(ws, 'utg.json'), jsonDumps({
149
+ directed: true, multigraph: true,
150
+ nodes: [
151
+ { id: home, kind: 'hybrid-page', label: '工作台', entry: true, is_launcher: true,
152
+ launch_hint: 'hybrid-page;runtime:UniApp;appid:__UNI__TABLE' },
153
+ { id: user, kind: 'hybrid-page', label: '用户管理' },
154
+ ],
155
+ links: [{ source: home, target: user, key: 0, mechanism: 'hybrid-route', trigger: 'onClick@a.vue:1',
156
+ args: { action: 'tap', label: '用户管理' } }],
157
+ }, { ensure_ascii: false }));
158
+ const p = spawnSync(process.execPath, [PATHS, ws], { encoding: 'utf8' });
159
+ assert.equal(p.status, 0, p.stderr);
160
+ const cp = JSON.parse(fs.readFileSync(path.join(ws, 'click_paths.json'), 'utf8'));
161
+ assert.equal(cp.root, home);
162
+ assert.deepEqual(cp.entries[home], { type: 'component', component_fqn: null });
163
+ assert.ok(cp.paths[user], 'target unreachable from launcher');
164
+ } finally { fs.rmSync(ws, { recursive: true, force: true }); }
165
+ });
166
+
167
+ test('a globalStyle title is not inherited as a page title or tap label', () => {
168
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'uniapp-gtitle-'));
169
+ try {
170
+ write(root, 'src/pages.json', jsonDumps({
171
+ globalStyle: { navigationBarTitleText: '应用名' },
172
+ pages: [
173
+ { path: 'pages/index/index', style: { navigationBarTitleText: '' } },
174
+ { path: 'pages/a/index', style: {} },
175
+ { path: 'pages/b/index', style: { navigationBarTitleText: '页面B' } },
176
+ ],
177
+ }, { ensure_ascii: false }));
178
+ write(root, 'src/pages/index/index.vue', `<template><view @click="go">x</view></template>
179
+ <script setup>
180
+ function go() { uni.navigateTo({ url: '/pages/a/index' }) }
181
+ </script>
182
+ `);
183
+ write(root, 'src/manifest.json', jsonDumps({ name: 't', appid: '__UNI__G' }));
184
+ const [nodes] = run([NAV, root]);
185
+ const by = Object.fromEntries(nodes.map((n) => [n.route, n]));
186
+ assert.equal(by['pages/index/index'].title, undefined);
187
+ assert.equal(by['pages/a/index'].title, undefined);
188
+ assert.ok(!JSON.stringify(nodes).includes('应用名'), 'global title leaked into a node');
189
+ assert.equal(by['pages/b/index'].title, '页面B');
190
+ } finally { fs.rmSync(root, { recursive: true, force: true }); }
191
+ });
192
+
193
+ test('a custom navigation bar title becomes the page identity', () => {
194
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'uniapp-navbar-'));
195
+ try {
196
+ write(root, 'src/pages.json', jsonDumps({
197
+ globalStyle: { navigationStyle: 'custom', navigationBarTitleText: '应用名' },
198
+ pages: [
199
+ { path: 'pages/index/index', style: { navigationBarTitleText: '' } },
200
+ { path: 'pages/form/index', style: {} },
201
+ { path: 'pages/list/index', style: {} },
202
+ ],
203
+ }, { ensure_ascii: false }));
204
+ write(root, 'src/pages/list/index.vue', `<template>
205
+ <wd-navbar v-if="picking" :title="pickTitle" />
206
+ <wd-navbar v-else title='列表' />
207
+ </template>
208
+ `);
209
+ write(root, 'src/pages/index/index.vue', `<template>
210
+ <view>
211
+ <wd-navbar title="工作台" placeholder fixed />
212
+ </view>
213
+ </template>
214
+ `);
215
+ write(root, 'src/pages/form/index.vue', `<template>
216
+ <view><wd-navbar :title="getTitle" left-arrow /></view>
217
+ </template>
218
+ `);
219
+ write(root, 'src/manifest.json', jsonDumps({ name: 't', appid: '__UNI__N' }));
220
+ const [nodes, , stderr] = run([NAV, root]);
221
+ const by = Object.fromEntries(nodes.map((n) => [n.route, n]));
222
+ assert.deepEqual(by['pages/index/index'].identity_text, ['工作台']);
223
+ assert.equal(by['pages/index/index'].identity_text_from, 'pages/index/index.vue:3');
224
+ assert.equal(by['pages/form/index'].identity_text, undefined, 'a bound :title is not a literal');
225
+ assert.deepEqual(by['pages/list/index'].identity_text, ['列表'], 'single quotes, after a bound bar');
226
+ assert.equal(by['pages/list/index'].identity_text_from, 'pages/list/index.vue:3');
227
+ assert.equal(by['pages/index/index'].label, '工作台');
228
+ assert.equal(by['pages/index/index'].label_synthetic, undefined, 'a painted navbar title is not synthetic');
229
+ assert.match(stderr, /navbar titles: 2\/3/);
230
+ } finally { fs.rmSync(root, { recursive: true, force: true }); }
231
+ });
232
+
233
+ test('a navbar tag on a page with a native bar does not replace its title', () => {
234
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'uniapp-navnative-'));
235
+ try {
236
+ write(root, 'src/pages.json', jsonDumps({
237
+ pages: [{ path: 'pages/index/index', style: { navigationBarTitleText: '首页' } }],
238
+ }, { ensure_ascii: false }));
239
+ write(root, 'src/pages/index/index.vue', `<template>
240
+ <view><uni-nav-bar title="返回" /></view>
241
+ </template>
242
+ `);
243
+ write(root, 'src/manifest.json', jsonDumps({ name: 't', appid: '__UNI__NN' }));
244
+ const [nodes, , stderr] = run([NAV, root]);
245
+ assert.equal(nodes[0].label, '首页');
246
+ assert.equal(nodes[0].identity_text, undefined);
247
+ assert.match(stderr, /navbar titles: 0\/1/);
248
+ } finally { fs.rmSync(root, { recursive: true, force: true }); }
249
+ });
250
+
251
+ test('a method definition is not a call; this.method(row) is', () => {
252
+ const fw = new Map([['navigateToMenu', [{ file: 'pages/index/index.vue', api: 'navigateTo', rows: [{ route: 'a' }, { route: 'b' }] }]]]);
253
+ const none = () => false;
254
+ const def = 'export default { methods: { navigateToMenu(menu) { uni.navigateTo({ url: menu.url }) } } }';
255
+ assert.equal(scanTableCalls('pages/index/index.vue', def, fw, none).length, 0);
256
+ const viaThis = 'export default { methods: { open(item) { this.navigateToMenu(item) } } }';
257
+ assert.deepEqual(scanTableCalls('pages/index/index.vue', viaThis, fw, none).map((s) => s.dst), ['a', 'b']);
258
+ const other = 'export default { methods: { open(item) { api.navigateToMenu(item) } } }';
259
+ assert.equal(scanTableCalls('pages/index/index.vue', other, fw, none).length, 0);
260
+ });
261
+
262
+ test('table rows point at their own line in compact JSON with a repeated url', () => {
263
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'uniapp-rowline-'));
264
+ try {
265
+ write(root, 'src/menu.json', '{"menus":[\n{"name":"甲","url":"/pages/a/index"},\n{"name":"乙","url":"/pages/a/index"}\n]}\n');
266
+ const sources = new Map([['pages/index/index.ts', "import m from '../../menu.json'\n"]]);
267
+ const got = dataTables(path.join(root, 'src'), sources, new Set(['pages/a/index']));
268
+ assert.deepEqual(got.get('pages/index/index.ts')[0].rows.map((r) => [r.label, r.at]),
269
+ [['甲', 'menu.json:2'], ['乙', 'menu.json:3']]);
270
+ } finally { fs.rmSync(root, { recursive: true, force: true }); }
271
+ });
272
+
273
+ test('a parent row whose url follows its children keeps its own line', () => {
274
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'uniapp-roworder-'));
275
+ try {
276
+ write(root, 'src/menu.json', '[{"name":"父","children":[\n{"name":"子","url":"/pages/b/index"}\n],\n"url":"/pages/a/index"}]\n');
277
+ const sources = new Map([['pages/index/index.ts', "import m from '../../menu.json'\n"]]);
278
+ const got = dataTables(path.join(root, 'src'), sources, new Set(['pages/a/index', 'pages/b/index']));
279
+ assert.deepEqual(got.get('pages/index/index.ts')[0].rows.map((r) => [r.label, r.at]),
280
+ [['父', 'menu.json:4'], ['子', 'menu.json:2']]);
281
+ } finally { fs.rmSync(root, { recursive: true, force: true }); }
282
+ });
283
+
284
+ /** A page `pages/<page>/index` embedding nothing, whose script imports `forwarderModule`. */
285
+ function tableProject(files) {
286
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'uniapp-tables-'));
287
+ write(root, 'src/pages.json', jsonDumps({ pages: ['home', 'other', 'a', 'b', 'c'].map((r) => ({
288
+ path: `pages/${r}/index`, style: { navigationBarTitleText: r } })) }));
289
+ write(root, 'src/manifest.json', jsonDumps({ name: 't', appid: '__UNI__T2' }));
290
+ for (const [rel, text] of Object.entries(files)) { write(root, rel, text); }
291
+ return root;
292
+ }
293
+ const fwModule = (imports) => `${imports}
294
+ export function navigateToMenu(menu) {
295
+ uni.navigateTo({ url: menu.url })
296
+ }
297
+ `;
298
+ const caller = (from) => `<template>
299
+ <view v-for="m in list" @click="navigateToMenu(m)">{{ m.name }}</view>
300
+ </template>
301
+ <script setup>
302
+ import { navigateToMenu } from '${from}'
303
+ </script>
304
+ `;
305
+ const tableId = (r) => `hybrid-page:__UNI__T2/${r}`;
306
+
307
+ test('a module importing two route tables is refused, not merged', () => {
308
+ const root = tableProject({
309
+ 'src/common/menu.json': jsonDumps([{ name: 'A', url: '/pages/a/index' }]),
310
+ 'src/common/tabs.json': jsonDumps([{ name: 'B', url: '/pages/b/index' }]),
311
+ 'src/common/nav.ts': fwModule("import menu from './menu.json'\nimport tabs from './tabs.json'"),
312
+ 'src/pages/home/index.vue': caller('@/common/nav'),
313
+ });
314
+ try {
315
+ const [, edges, stderr] = run([NAV, root]);
316
+ assert.equal(edges.filter((e) => e.args.resolved_by === 'data-table').length, 0);
317
+ assert.match(stderr, /data tables: forwarders=0 rows=0 edges=0 refused_multi_table=1/);
318
+ } finally { fs.rmSync(root, { recursive: true, force: true }); }
319
+ });
320
+
321
+ test('two modules defining the same forwarder name each keep their own table', () => {
322
+ const root = tableProject({
323
+ 'src/common/menu.json': jsonDumps([{ name: 'A', url: '/pages/a/index' }]),
324
+ 'src/common/nav.ts': fwModule("import menu from './menu.json'"),
325
+ 'src/other/menu.json': jsonDumps([{ name: 'C', url: '/pages/c/index' }]),
326
+ 'src/other/nav.ts': fwModule("import menu from './menu.json'"),
327
+ 'src/pages/home/index.vue': caller('@/common/nav'),
328
+ 'src/pages/other/index.vue': caller('@/other/nav'),
329
+ });
330
+ try {
331
+ const [, edges, stderr] = run([NAV, root]);
332
+ const pairs = edges.filter((e) => e.args.resolved_by === 'data-table')
333
+ .map((e) => [e.source, e.target, e.args.label]).sort();
334
+ assert.deepEqual(pairs, [
335
+ [tableId('pages/home/index'), tableId('pages/a/index'), 'A'],
336
+ [tableId('pages/other/index'), tableId('pages/c/index'), 'C'],
337
+ ]);
338
+ assert.match(stderr, /data tables: forwarders=2 rows=2 edges=2/);
339
+ } finally { fs.rmSync(root, { recursive: true, force: true }); }
340
+ });
@@ -0,0 +1,125 @@
1
+ // uni-app options-API forwarders called with RELATIVE page URLs. A method declared as
2
+ // `goUrl: function (str) { uni.navigateTo({url: str}) }` is a forwarder, and a template call
3
+ // `goUrl('../info/index')` resolves against the calling page's route; a call inside a component
4
+ // resolves once per page that embeds it.
5
+ import { test } from 'node:test';
6
+ import assert from 'node:assert/strict';
7
+ import * as fs from 'node:fs';
8
+ import * as os from 'node:os';
9
+ import * as path from 'node:path';
10
+ import { spawnSync } from 'node:child_process';
11
+ import { fileURLToPath } from 'node:url';
12
+ import { jsonDumps } from '../_py.mjs';
13
+ import { _resolveRel } from '../uniapp_nav.mjs';
14
+
15
+ const SCRIPTS = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
16
+ const NAV = path.join(SCRIPTS, 'uniapp_nav.mjs');
17
+
18
+ function run(argv) {
19
+ const p = spawnSync(process.execPath, argv, { encoding: 'utf8', maxBuffer: 1 << 28 });
20
+ const recs = (p.stdout || '').split(/\r?\n/).filter((l) => l.trim()).map((l) => JSON.parse(l));
21
+ return [recs.filter((r) => r.type === 'node'), recs.filter((r) => r.type === 'edge'), p.stderr || ''];
22
+ }
23
+ function write(root, rel, text) {
24
+ const p = path.join(root, ...rel.split('/'));
25
+ fs.mkdirSync(path.dirname(p), { recursive: true });
26
+ fs.writeFileSync(p, text, 'utf8');
27
+ }
28
+
29
+ const PAGES_JSON = jsonDumps({
30
+ pages: [
31
+ { path: 'pages/index/index', style: { navigationBarTitleText: '首页' } },
32
+ { path: 'pages/info/index', style: { navigationBarTitleText: '播放' } },
33
+ { path: 'pages/new/index', style: { navigationBarTitleText: '新歌' } },
34
+ ],
35
+ }, { ensure_ascii: false });
36
+
37
+ const INDEX_VUE = `<template>
38
+ <view>
39
+ <view class="cover" @tap="goUrl('../info/index')"><text>个性电台</text></view>
40
+ <view v-for="(val,index) in list" :key="index" @tap="goUrl('../new/index?count='+index)">{{val.name}}</view>
41
+ <view @tap="goUrl('../missing/index')">不存在</view>
42
+ <albumblock :prodata="list"></albumblock>
43
+ </view>
44
+ </template>
45
+ <script>
46
+ import albumblock from '../../components/albumblock'
47
+ export default {
48
+ components: {albumblock},
49
+ data() { return { list: [] } },
50
+ methods: {
51
+ goUrl : function (str){
52
+ uni.navigateTo({
53
+ url: str
54
+ });
55
+ },
56
+ }
57
+ }
58
+ </script>
59
+ `;
60
+ const NEW_VUE = `<template>
61
+ <view><album :prodata="list"></album></view>
62
+ </template>
63
+ <script>
64
+ import album from '../../components/album'
65
+ export default { components: {album}, data() { return { list: [] } } }
66
+ </script>
67
+ `;
68
+ const INFO_VUE = '<template><view>播放</view></template>\n<script>export default {}</script>\n';
69
+ const ALBUMBLOCK_VUE = `<template>
70
+ <view><album :prodata="prodata"></album></view>
71
+ </template>
72
+ <script>
73
+ import album from './album.vue'
74
+ export default { props: ['prodata'], components: {album} }
75
+ </script>
76
+ `;
77
+ const ALBUM_VUE = `<template>
78
+ <view v-for="(val,index) in prodata" :key="index" @tap="goUrl('../info/index')">{{val.name}}</view>
79
+ </template>
80
+ <script>
81
+ export default {
82
+ props: ['prodata'],
83
+ methods: {
84
+ goUrl(str) { uni.navigateTo({ url: str }); }
85
+ }
86
+ }
87
+ </script>
88
+ `;
89
+
90
+ const P = (r) => `hybrid-page:__UNI__T/${r}`;
91
+
92
+ test('relative URL resolves against the calling page route', () => {
93
+ assert.equal(_resolveRel('pages/index/index', '../info/index'), 'pages/info/index');
94
+ assert.equal(_resolveRel('pages/index/index', './detail?id=1'), 'pages/index/detail');
95
+ assert.equal(_resolveRel('pages/a/b/c', '../../x/y'), 'pages/x/y');
96
+ });
97
+
98
+ test('options-API forwarder with relative URLs yields page and component edges', () => {
99
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'uniapp_rel_'));
100
+ try {
101
+ write(tmp, 'pages.json', PAGES_JSON);
102
+ write(tmp, 'manifest.json', jsonDumps({ appid: '__UNI__T', name: 't' }));
103
+ write(tmp, 'pages/index/index.vue', INDEX_VUE);
104
+ write(tmp, 'pages/info/index.vue', INFO_VUE);
105
+ write(tmp, 'pages/new/index.vue', NEW_VUE);
106
+ write(tmp, 'components/albumblock.vue', ALBUMBLOCK_VUE);
107
+ write(tmp, 'components/album.vue', ALBUM_VUE);
108
+
109
+ const [nodes, edges, err] = run([NAV, tmp]);
110
+ assert.equal(nodes.length, 3, err);
111
+ assert.doesNotMatch(err, /SANITY/);
112
+ const got = new Set(edges.map((e) => `${e.source} -> ${e.target} @ ${e.trigger}`));
113
+ const want = [
114
+ `${P('pages/index/index')} -> ${P('pages/info/index')} @ onTap@pages/index/index.vue:3`,
115
+ `${P('pages/index/index')} -> ${P('pages/new/index')} @ onTap@pages/index/index.vue:4`,
116
+ // album.vue is embedded in index (through albumblock) and directly in new.
117
+ `${P('pages/index/index')} -> ${P('pages/info/index')} @ onTap@components/album.vue:2`,
118
+ `${P('pages/new/index')} -> ${P('pages/info/index')} @ onTap@components/album.vue:2`,
119
+ ];
120
+ for (const w of want) { assert.ok(got.has(w), `missing edge: ${w}\n got: ${[...got].join('\n ')}`); }
121
+ // '../missing/index' names no route in pages.json, so it makes no edge.
122
+ assert.equal(edges.length, want.length, [...got].join('\n'));
123
+ for (const e of edges) { assert.equal(e.args.resolved_by, 'forwarder-relative'); assert.equal(e.args.callee, 'goUrl'); }
124
+ } finally { fs.rmSync(tmp, { recursive: true, force: true }); }
125
+ });