@buaa_smat/hometrans 26.0.0 → 26.0.1

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 (147) hide show
  1. package/package.json +11 -82
  2. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/ets/pages/Index.ets +2 -2
  3. package/skills/a2h-arch-generate/scripts/module_create/har/src/main/ets/components/MainPage.ets +2 -2
  4. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/ets/pages/Index.ets +2 -2
  5. package/skills/a2h-batch-ui-align/references/conversion-procedure.md +1 -1
  6. 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
  7. package/skills/a2h-batch-ui-align/references/step3-capture.md +3 -3
  8. package/skills/a2h-batch-ui-align/references/step4-prepare.md +1 -1
  9. package/skills/a2h-batch-ui-align/scripts/detect_paradigm.mjs +11 -6
  10. package/skills/a2h-batch-ui-align/scripts/export_ui_info.mjs +59 -21
  11. package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +3 -3
  12. package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +1 -1
  13. package/skills/a2h-batch-ui-align/scripts/static_check/core/scan.ts +1 -1
  14. package/skills/a2h-utg-explorer/SKILL.md +1 -1
  15. package/skills/a2h-utg-explorer/references/architecture.md +2 -2
  16. package/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +36 -11
  17. package/skills/a2h-utg-explorer/scripts/device_health.mjs +91 -6
  18. package/skills/a2h-utg-explorer/scripts/final_utg.mjs +20 -2
  19. package/skills/a2h-utg-explorer/scripts/hint_check.mjs +64 -8
  20. package/skills/a2h-utg-explorer/scripts/hint_source.mjs +119 -0
  21. package/skills/a2h-utg-explorer/scripts/recover.mjs +7 -1
  22. package/skills/a2h-utg-explorer/scripts/recover_b.mjs +8 -1
  23. package/skills/a2h-utg-explorer/scripts/utg_explorer/adapters.mjs +89 -7
  24. package/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +173 -4
  25. package/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +82 -14
  26. package/skills/a2h-utg-static/SKILL.md +1 -1
  27. package/skills/a2h-utg-static/references/view-interactions.md +1 -1
  28. package/skills/a2h-utg-static/scripts/assemble.mjs +6 -3
  29. package/skills/a2h-utg-static/scripts/compose_body_text.mjs +23 -5
  30. package/skills/a2h-utg-static/scripts/compose_overlay.mjs +29 -3
  31. package/skills/a2h-utg-static/scripts/compose_titles.mjs +10 -1
  32. package/skills/a2h-utg-static/scripts/label_resolve.mjs +51 -2
  33. package/skills/a2h-utg-static/scripts/static_prior.mjs +2 -1
  34. package/skills/a2h-utg-static/scripts/tests/_zipw.mjs +28 -0
  35. package/skills/a2h-utg-static/scripts/tests/probe_autoload.mjs +108 -0
  36. package/skills/a2h-utg-static/scripts/tests/probe_layout_fragments.mjs +90 -0
  37. package/skills/a2h-utg-static/scripts/tests/probe_unknown_scope.mjs +61 -0
  38. package/skills/a2h-utg-static/scripts/tests/regression_matrix.mjs +1261 -0
  39. package/skills/a2h-utg-static/scripts/tests/test_activity_alias_launcher.mjs +135 -0
  40. package/skills/a2h-utg-static/scripts/tests/test_activity_supertype_chain.mjs +106 -0
  41. package/skills/a2h-utg-static/scripts/tests/test_bottom_sheet_container.mjs +58 -0
  42. package/skills/a2h-utg-static/scripts/tests/test_branch_guard.mjs +19 -0
  43. package/skills/a2h-utg-static/scripts/tests/test_callee_string_default.mjs +30 -0
  44. package/skills/a2h-utg-static/scripts/tests/test_carry_answers.mjs +103 -0
  45. package/skills/a2h-utg-static/scripts/tests/test_chrome_tokens.mjs +60 -0
  46. package/skills/a2h-utg-static/scripts/tests/test_commented_out_trigger.mjs +111 -0
  47. package/skills/a2h-utg-static/scripts/tests/test_commit_scope.mjs +113 -0
  48. package/skills/a2h-utg-static/scripts/tests/test_compose_file_private_route.mjs +117 -0
  49. package/skills/a2h-utg-static/scripts/tests/test_compose_nested_graph.mjs +166 -0
  50. package/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +108 -0
  51. package/skills/a2h-utg-static/scripts/tests/test_compose_route_holder_collision.mjs +112 -0
  52. package/skills/a2h-utg-static/scripts/tests/test_compose_vm_nav.mjs +289 -0
  53. package/skills/a2h-utg-static/scripts/tests/test_custom_source_root.mjs +71 -0
  54. package/skills/a2h-utg-static/scripts/tests/test_defensive_null_guard.mjs +77 -0
  55. package/skills/a2h-utg-static/scripts/tests/test_dialog_orphan_entries.mjs +99 -0
  56. package/skills/a2h-utg-static/scripts/tests/test_dialog_page_owner.mjs +69 -0
  57. package/skills/a2h-utg-static/scripts/tests/test_dialogshow_builder_forms.mjs +96 -0
  58. package/skills/a2h-utg-static/scripts/tests/test_dialogshow_java_factory.mjs +37 -0
  59. package/skills/a2h-utg-static/scripts/tests/test_disabled_guard.mjs +42 -0
  60. package/skills/a2h-utg-static/scripts/tests/test_drawer_panel_gesture.mjs +140 -0
  61. package/skills/a2h-utg-static/scripts/tests/test_edge_dedupe_by_gesture.mjs +111 -0
  62. package/skills/a2h-utg-static/scripts/tests/test_edge_provenance_lint.mjs +70 -0
  63. package/skills/a2h-utg-static/scripts/tests/test_enclosing_gesture.mjs +69 -0
  64. package/skills/a2h-utg-static/scripts/tests/test_external_surface_roots.mjs +43 -0
  65. package/skills/a2h-utg-static/scripts/tests/test_find_package_indirect.mjs +67 -0
  66. package/skills/a2h-utg-static/scripts/tests/test_forwarding_wrapper.mjs +38 -0
  67. package/skills/a2h-utg-static/scripts/tests/test_fragment_containment.mjs +85 -0
  68. package/skills/a2h-utg-static/scripts/tests/test_fragment_helper_trigger.mjs +92 -0
  69. package/skills/a2h-utg-static/scripts/tests/test_fresh_branch_guard.mjs +49 -0
  70. package/skills/a2h-utg-static/scripts/tests/test_graph.mjs +55 -0
  71. package/skills/a2h-utg-static/scripts/tests/test_guard_clause.mjs +86 -0
  72. package/skills/a2h-utg-static/scripts/tests/test_hint_language.mjs +136 -0
  73. package/skills/a2h-utg-static/scripts/tests/test_host_kind_by_chain.mjs +68 -0
  74. package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundle_attribution.mjs +74 -0
  75. package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundled_pages.mjs +181 -0
  76. package/skills/a2h-utg-static/scripts/tests/test_hybrid_scope.mjs +293 -0
  77. package/skills/a2h-utg-static/scripts/tests/test_hybrid_title_renders.mjs +118 -0
  78. package/skills/a2h-utg-static/scripts/tests/test_i18n_term.mjs +155 -0
  79. package/skills/a2h-utg-static/scripts/tests/test_interaction_sites.mjs +272 -0
  80. package/skills/a2h-utg-static/scripts/tests/test_item_data_instance.mjs +51 -0
  81. package/skills/a2h-utg-static/scripts/tests/test_kotlin_fn_spans.mjs +69 -0
  82. package/skills/a2h-utg-static/scripts/tests/test_label_accessor_forms.mjs +187 -0
  83. package/skills/a2h-utg-static/scripts/tests/test_label_source.mjs +70 -0
  84. package/skills/a2h-utg-static/scripts/tests/test_launch_intent_guard.mjs +67 -0
  85. package/skills/a2h-utg-static/scripts/tests/test_layout_declared_fragment.mjs +103 -0
  86. package/skills/a2h-utg-static/scripts/tests/test_listener_call_forms.mjs +79 -0
  87. package/skills/a2h-utg-static/scripts/tests/test_listener_receiver_binding.mjs +47 -0
  88. package/skills/a2h-utg-static/scripts/tests/test_login_interceptor.mjs +328 -0
  89. package/skills/a2h-utg-static/scripts/tests/test_manifest_exported_default.mjs +40 -0
  90. package/skills/a2h-utg-static/scripts/tests/test_manifest_filters_modules.mjs +84 -0
  91. package/skills/a2h-utg-static/scripts/tests/test_manifest_srcfile.mjs +68 -0
  92. package/skills/a2h-utg-static/scripts/tests/test_mode_and_cb_param.mjs +172 -0
  93. package/skills/a2h-utg-static/scripts/tests/test_module_namespace.mjs +83 -0
  94. package/skills/a2h-utg-static/scripts/tests/test_module_strings.mjs +44 -0
  95. package/skills/a2h-utg-static/scripts/tests/test_multiple_entry_contracts.mjs +80 -0
  96. package/skills/a2h-utg-static/scripts/tests/test_nav_graph_xml.mjs +35 -0
  97. package/skills/a2h-utg-static/scripts/tests/test_nl_hint_grammar.mjs +42 -0
  98. package/skills/a2h-utg-static/scripts/tests/test_nl_hints_gate.mjs +85 -0
  99. package/skills/a2h-utg-static/scripts/tests/test_nl_hints_off_path.mjs +67 -0
  100. package/skills/a2h-utg-static/scripts/tests/test_node_id_collision.mjs +57 -0
  101. package/skills/a2h-utg-static/scripts/tests/test_non_gesture_step_flag.mjs +62 -0
  102. package/skills/a2h-utg-static/scripts/tests/test_out_of_scope_and_settings.mjs +72 -0
  103. package/skills/a2h-utg-static/scripts/tests/test_overload_and_climb.mjs +86 -0
  104. package/skills/a2h-utg-static/scripts/tests/test_pager_page_source.mjs +78 -0
  105. package/skills/a2h-utg-static/scripts/tests/test_pager_position_zero.mjs +65 -0
  106. package/skills/a2h-utg-static/scripts/tests/test_pager_variant_guard.mjs +172 -0
  107. package/skills/a2h-utg-static/scripts/tests/test_pipeline_llm_phases.mjs +107 -0
  108. package/skills/a2h-utg-static/scripts/tests/test_plain_dialog_nodes.mjs +167 -0
  109. package/skills/a2h-utg-static/scripts/tests/test_plaindialog_shared_anchor.mjs +117 -0
  110. package/skills/a2h-utg-static/scripts/tests/test_preference_click_nav.mjs +98 -0
  111. package/skills/a2h-utg-static/scripts/tests/test_preference_host_binding.mjs +87 -0
  112. package/skills/a2h-utg-static/scripts/tests/test_preference_nesting.mjs +183 -0
  113. package/skills/a2h-utg-static/scripts/tests/test_preference_widgets.mjs +48 -0
  114. package/skills/a2h-utg-static/scripts/tests/test_read_text_crlf.mjs +41 -0
  115. package/skills/a2h-utg-static/scripts/tests/test_resolver_tier_parity.mjs +126 -0
  116. package/skills/a2h-utg-static/scripts/tests/test_result_launcher.mjs +142 -0
  117. package/skills/a2h-utg-static/scripts/tests/test_review_fixes.mjs +135 -0
  118. package/skills/a2h-utg-static/scripts/tests/test_route_token_words.mjs +66 -0
  119. package/skills/a2h-utg-static/scripts/tests/test_same_name_decl_scope.mjs +236 -0
  120. package/skills/a2h-utg-static/scripts/tests/test_scope_utils.mjs +85 -0
  121. package/skills/a2h-utg-static/scripts/tests/test_sealed_dialog_state.mjs +148 -0
  122. package/skills/a2h-utg-static/scripts/tests/test_shared_overlay_split.mjs +63 -0
  123. package/skills/a2h-utg-static/scripts/tests/test_slug_parity.mjs +58 -0
  124. package/skills/a2h-utg-static/scripts/tests/test_starter_node_id.mjs +41 -0
  125. package/skills/a2h-utg-static/scripts/tests/test_state_guard_arity.mjs +109 -0
  126. package/skills/a2h-utg-static/scripts/tests/test_state_guard_commented_candidates.mjs +68 -0
  127. package/skills/a2h-utg-static/scripts/tests/test_state_guard_model_gates.mjs +127 -0
  128. package/skills/a2h-utg-static/scripts/tests/test_state_specific_hop.mjs +130 -0
  129. package/skills/a2h-utg-static/scripts/tests/test_synthetic_label_identity.mjs +51 -0
  130. package/skills/a2h-utg-static/scripts/tests/test_template_method_layout.mjs +81 -0
  131. package/skills/a2h-utg-static/scripts/tests/test_template_title.mjs +61 -0
  132. package/skills/a2h-utg-static/scripts/tests/test_trigger_id_spelling.mjs +68 -0
  133. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_action_override.mjs +91 -0
  134. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_flow_filter.mjs +110 -0
  135. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_nl_hint_key.mjs +89 -0
  136. package/skills/a2h-utg-static/scripts/tests/test_uiless_host_fold.mjs +98 -0
  137. package/skills/a2h-utg-static/scripts/tests/test_uniapp_data_table.mjs +340 -0
  138. package/skills/a2h-utg-static/scripts/tests/test_uniapp_relative_url.mjs +125 -0
  139. package/skills/a2h-utg-static/scripts/tests/test_uniapp_source.mjs +231 -0
  140. package/skills/a2h-utg-static/scripts/tests/test_view_click_refs.mjs +104 -0
  141. package/skills/a2h-utg-static/scripts/tests/test_view_id_label.mjs +69 -0
  142. package/skills/a2h-utg-static/scripts/tests/test_view_interactions.mjs +346 -0
  143. package/skills/a2h-utg-static/scripts/tests/test_viewpage_nav.mjs +340 -0
  144. package/skills/a2h-utg-static/scripts/tests/test_vm_nav_helper_navigate.mjs +98 -0
  145. package/skills/a2h-utg-static/scripts/tests/test_widget_class_scope.mjs +92 -0
  146. package/skills/a2h-utg-static/scripts/tests/test_window_nav_kotlin.mjs +158 -0
  147. package/skills/a2h-utg-static/scripts/tests/test_worklist_parts.mjs +65 -0
@@ -0,0 +1,135 @@
1
+ // Regression tests for review findings H1/H2/M1/M2/M9/M10/M11/M12.
2
+ import { test } from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import * as fs from 'node:fs';
5
+ import * as os from 'node:os';
6
+ import * as path from 'node:path';
7
+ import { IS_WIN, reSearch } from '../_py.mjs';
8
+ import * as assemble from '../assemble.mjs';
9
+ import { _CLASS_DECL_RE } from '../fragment_nav.mjs';
10
+ import { StaticPrior } from '../static_prior.mjs';
11
+ import { _easycomTags } from '../uniapp_nav.mjs';
12
+ import { extract as windowExtract } from '../window_nav.mjs';
13
+ import { nodeLinkGraph } from '../_graph.mjs';
14
+
15
+ const tmp = (p) => fs.mkdtempSync(path.join(os.tmpdir(), p));
16
+ const write = (root, rel, text) => {
17
+ const f = path.join(root, rel);
18
+ fs.mkdirSync(path.dirname(f), { recursive: true });
19
+ fs.writeFileSync(f, text, 'utf8');
20
+ };
21
+
22
+ const popupActivity = (name) => `package com.example.app;
23
+ public class ${name} extends AppCompatActivity {
24
+ void openMenu(View anchor) {
25
+ View v = getLayoutInflater().inflate(R.layout.popup_menu, null);
26
+ PopupWindow pw = new PopupWindow(v, 100, 100);
27
+ pw.setFocusable(true);
28
+ pw.showAsDropDown(anchor);
29
+ }
30
+ }
31
+ `;
32
+
33
+ test('H1/M10/M11 window_nav: full layout name, real show() line, one node per id', () => {
34
+ const proj = tmp('wnp'); const ws = tmp('wnw');
35
+ try {
36
+ write(proj, 'app/src/main/java/com/example/app/AActivity.java', popupActivity('AActivity'));
37
+ write(proj, 'app/src/main/java/com/example/app/BActivity.java', popupActivity('BActivity'));
38
+ fs.writeFileSync(path.join(ws, 'nodes.jsonl'),
39
+ '{"id":"activity:AActivity","kind":"activity"}\n{"id":"activity:BActivity","kind":"activity"}\n', 'utf8');
40
+ const { nodes, edges, surfaces } = windowExtract(proj, ws);
41
+ assert.equal(surfaces, 2, 'two surfaces (different files) share one layout');
42
+ assert.deepEqual(nodes.map((n) => n.id), ['window:popup_menu'], 'H1 + M11: one node, full layout slug');
43
+ assert.equal(nodes[0].layout, 'popup_menu');
44
+ assert.deepEqual(edges.map((e) => e.source).sort(), ['activity:AActivity', 'activity:BActivity']);
45
+ for (const e of edges) {
46
+ assert.equal(e.target, 'window:popup_menu');
47
+ assert.match(e.trigger, /:7$/, 'M10: trigger points at the showAsDropDown line (1-based)');
48
+ }
49
+ } finally {
50
+ fs.rmSync(proj, { recursive: true, force: true }); fs.rmSync(ws, { recursive: true, force: true });
51
+ }
52
+ });
53
+
54
+ test('H2 _easycomTags: literal easycom rule maps without crashing', () => {
55
+ const custom = {
56
+ '^my-button$': '@/components/my-button.vue',
57
+ '^uni-(.*)': '@/components/uni-$1/uni-$1.vue',
58
+ };
59
+ assert.deepEqual([..._easycomTags('components/my-button.vue', custom)].sort(), ['my-button']);
60
+ assert.deepEqual([..._easycomTags('components/uni-card/uni-card.vue', custom)].sort(), ['uni-card']);
61
+ const tags = _easycomTags('components/fancy.vue', { '^x-fancy$': '@/components/fancy.vue' });
62
+ assert.deepEqual([...tags].sort(), ['fancy', 'x-fancy']);
63
+ });
64
+
65
+ test('M1 _foldUilessHosts: edge without mechanism does not crash', () => {
66
+ const proj = tmp('m1');
67
+ try {
68
+ write(proj, 'app/src/main/java/com/example/app/MainActivity.java', `package com.example.app;
69
+ public class MainActivity extends AppCompatActivity {
70
+ protected void onCreate(Bundle s) { setContentView(R.layout.activity_main); }
71
+ }
72
+ `);
73
+ write(proj, 'app/src/main/res/layout/activity_main.xml', `<?xml version="1.0" encoding="utf-8"?>
74
+ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
75
+ android:id="@+id/placeHolder"
76
+ android:layout_width="match_parent" android:layout_height="match_parent" />
77
+ `);
78
+ const nodes = {
79
+ 'activity:MainActivity': { id: 'activity:MainActivity', kind: 'activity', label: 'MainActivity',
80
+ declared_at: 'app/src/main/java/com/example/app/MainActivity.java:2',
81
+ launch_hint: { is_launcher: true, exported: true }, exported: true },
82
+ 'fragment:MainFragment': { id: 'fragment:MainFragment', kind: 'fragment', label: 'MainFragment' },
83
+ };
84
+ const edges = [
85
+ { source: 'activity:MainActivity', target: 'fragment:MainFragment' }, // no mechanism
86
+ { source: 'activity:MainActivity', target: 'fragment:MainFragment', mechanism: 'fragment-transaction',
87
+ args: { via: 'auto-load', action: 'default' } },
88
+ ];
89
+ assert.doesNotThrow(() => assemble.enrichNodesAndEdges(nodes, edges, proj));
90
+ } finally { fs.rmSync(proj, { recursive: true, force: true }); }
91
+ });
92
+
93
+ test('M2 breadcrumb: overlay cycles terminate', () => {
94
+ const g = nodeLinkGraph({
95
+ directed: true, multigraph: true,
96
+ nodes: [
97
+ { id: 'dialog:A', kind: 'dialog' }, { id: 'dialog:B', kind: 'dialog' },
98
+ { id: 'dialog:Self', kind: 'dialog' },
99
+ ],
100
+ links: [
101
+ { source: 'dialog:A', target: 'dialog:B', mechanism: 'open-overlay', args: { label: 'b' } },
102
+ { source: 'dialog:B', target: 'dialog:A', mechanism: 'open-overlay', args: { label: 'a' } },
103
+ { source: 'dialog:Self', target: 'dialog:Self', mechanism: 'open-overlay', args: { label: 's' } },
104
+ ],
105
+ }, { edges: 'links' });
106
+ const prior = new StaticPrior(g);
107
+ assert.equal(typeof prior.breadcrumb('dialog:A'), 'string');
108
+ assert.equal(typeof prior.breadcrumb('dialog:Self'), 'string');
109
+ });
110
+
111
+ test('M9 pIsAbs: Windows backslash drive and UNC paths', { skip: !IS_WIN }, () => {
112
+ assert.equal(assemble.pIsAbs('C:\\x\\y.java'), true);
113
+ assert.equal(assemble.pIsAbs('C:/x/y.java'), true);
114
+ assert.equal(assemble.pIsAbs('\\\\srv\\share\\a.java'), true);
115
+ assert.equal(assemble.pIsAbs('//srv/share/a.java'), true);
116
+ assert.equal(assemble.pIsAbs('app\\src\\a.java'), false);
117
+ assert.equal(assemble.pIsAbs('C:rel'), false);
118
+ });
119
+
120
+ test('M12 fragment _CLASS_DECL_RE: nested ctor parens and annotated constructor', () => {
121
+ const cases = [
122
+ ['class Foo(val x: Int = f()) : Fragment()', 'Foo'],
123
+ ['class Foo(val x: Int = f(g(1))) : Fragment()', 'Foo'],
124
+ ['class Foo @Inject constructor(a: A) : Fragment()', 'Foo'],
125
+ ['class Foo @Inject constructor(a: A = make()) : Fragment()', 'Foo'],
126
+ ['class Foo private constructor(a: A) : DialogFragment()', 'Foo'],
127
+ ['public class Foo extends Fragment {', 'Foo'],
128
+ ];
129
+ for (const [src, name] of cases) {
130
+ const m = reSearch(_CLASS_DECL_RE, src);
131
+ assert.ok(m, src);
132
+ assert.equal(m[1], name, src);
133
+ assert.match(m[2], /Fragment$/, src);
134
+ }
135
+ });
@@ -0,0 +1,66 @@
1
+ // assemble._hasToken: a guard kind inferred from a route/page NAME matches tokens on whole words of the
2
+ // identifier (snake/kebab/camel/Pascal/dots), never on substrings — `chinese_proverb` / `Profile`
3
+ // contain "PRO" but are not pay pages, so the explorer must still attempt them.
4
+ import { test } from 'node:test';
5
+ import assert from 'node:assert/strict';
6
+ import {
7
+ _hasToken, _identWords, _PAY_ROUTE_TOKENS, _ENV_ROUTE_TOKENS, _LOGIN_ROUTE_TOKENS, _INSTANCE_ROUTE_SUFFIXES,
8
+ enrichNodesAndEdges,
9
+ } from '../assemble.mjs';
10
+
11
+ test('identifier word split', () => {
12
+ assert.deepEqual(_identWords('chinese_proverb_index'), ['CHINESE', 'PROVERB', 'INDEX']);
13
+ assert.deepEqual(_identWords('VIPCenterScreen'), ['VIP', 'CENTER', 'SCREEN']);
14
+ assert.deepEqual(_identWords('OrderRoutes.Pay'), ['ORDER', 'ROUTES', 'PAY']);
15
+ assert.deepEqual(_identWords('sign-in'), ['SIGN', 'IN']);
16
+ });
17
+
18
+ test('pay tokens: substrings do not count', () => {
19
+ for (const k of ['chinese_proverb_index', 'chinese_proverb_show', 'Profile', 'ProfileEdit', 'repay', 'Display', 'improve']) {
20
+ assert.equal(_hasToken(k, _PAY_ROUTE_TOKENS), false, k);
21
+ }
22
+ for (const k of ['pro', 'ProVersion', 'go_pro', 'VIPCenter', 'pay_success', 'Pay', 'OrderRoutes.Pay', 'PaymentResult',
23
+ 'premium-plans', 'Purchases', 'donate']) {
24
+ assert.equal(_hasToken(k, _PAY_ROUTE_TOKENS), true, k);
25
+ }
26
+ });
27
+
28
+ test('env / login tokens: whole (multi-)words', () => {
29
+ assert.equal(_hasToken('GooglePlayInfo', _ENV_ROUTE_TOKENS), true);
30
+ assert.equal(_hasToken('google_play', _ENV_ROUTE_TOKENS), true);
31
+ assert.equal(_hasToken('flymeSettings', _ENV_ROUTE_TOKENS), true);
32
+ assert.equal(_hasToken('playground', _ENV_ROUTE_TOKENS), false);
33
+ for (const k of ['Login', 'AccountLogin', 'SmsLogin', 'Register', 'SignIn', 'sign_in', 'account_settings']) {
34
+ assert.equal(_hasToken(k, _LOGIN_ROUTE_TOKENS), true, k);
35
+ }
36
+ for (const k of ['loginless', 'registry', 'accounting_report', 'design_info']) {
37
+ assert.equal(_hasToken(k, _LOGIN_ROUTE_TOKENS), false, k);
38
+ }
39
+ });
40
+
41
+ test('instance suffixes need a real separator', () => {
42
+ for (const k of ['chinese_riddle_info', 'poem_detail', 'settings_shared_user_info', 'file-path']) {
43
+ assert.equal(_hasToken(k, _INSTANCE_ROUTE_SUFFIXES), true, k);
44
+ }
45
+ for (const k of ['x_information', 'detail', 'info', 'userInfo', 'content_list', 'image_paths_old',
46
+ 'GoodsRoutes.Detail', 'OrderRoutes.Detail']) {
47
+ assert.equal(_hasToken(k, _INSTANCE_ROUTE_SUFFIXES), false, k);
48
+ }
49
+ });
50
+
51
+ test('guard backfill: Profile / proverb routes get no inferred pay guard', () => {
52
+ const nodes = {
53
+ 'compose-route:home': { id: 'compose-route:home', kind: 'compose-route', label: 'Home' },
54
+ 'compose-route:chinese_proverb_index': { id: 'compose-route:chinese_proverb_index', kind: 'compose-route', label: 'P' },
55
+ 'compose-route:Profile': { id: 'compose-route:Profile', kind: 'compose-route', label: 'Profile' },
56
+ 'compose-route:VipCenter': { id: 'compose-route:VipCenter', kind: 'compose-route', label: 'Vip' },
57
+ };
58
+ const edges = ['chinese_proverb_index', 'Profile', 'VipCenter'].map((t) => ({
59
+ source: 'compose-route:home', target: `compose-route:${t}`, mechanism: 'compose-navigate', guard: null,
60
+ }));
61
+ enrichNodesAndEdges(nodes, edges, null);
62
+ const g = (t) => edges.find((e) => e.target === `compose-route:${t}`).guard;
63
+ assert.ok(!g('chinese_proverb_index'), 'proverb page is not pay-guarded');
64
+ assert.ok(!g('Profile'), 'Profile is not pay-guarded');
65
+ assert.equal(g('VipCenter')?.kind, 'pay', 'a real VIP page still is');
66
+ });
@@ -0,0 +1,236 @@
1
+ // Port of test_same_name_decl_scope.py: same-name composable declarations are resolved per
2
+ // declaration (private/public visibility, file scope), refused (and counted) when ambiguous.
3
+ import { test } from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import * as co from '../compose_overlay.mjs';
6
+ import { tupleKey } from '../_py.mjs';
7
+
8
+ const PUBLIC_DECL = `
9
+ package app.ui.list
10
+
11
+ @Composable
12
+ fun RowEntry(
13
+ onClick: () -> Unit,
14
+ onRemove: () -> Unit,
15
+ entry: Entry
16
+ ) {
17
+ Row(modifier = Modifier.clickable { onClick() }) {
18
+ Text(text = entry.name)
19
+ }
20
+ var menuVisible by remember { mutableStateOf(false) }
21
+ Image(
22
+ painter = painterResource(id = R.drawable.ic_more),
23
+ contentDescription = null,
24
+ modifier = Modifier.clickable { menuVisible = true }
25
+ )
26
+ if (menuVisible) {
27
+ EntryMenuDialog(
28
+ entry = entry,
29
+ onRemove = onRemove,
30
+ onDismissRequest = { menuVisible = false }
31
+ )
32
+ }
33
+ }
34
+ `;
35
+ const PUBLIC_CALLER = `
36
+ package app.ui.list
37
+
38
+ @Composable
39
+ fun ListPage() {
40
+ LazyColumn {
41
+ items(entries) { entry ->
42
+ RowEntry(
43
+ onClick = { },
44
+ onRemove = { },
45
+ entry = entry
46
+ )
47
+ }
48
+ }
49
+ }
50
+ `;
51
+ const PRIVATE_DECL_AND_CALLER = `
52
+ package app.ui.picker
53
+
54
+ @Composable
55
+ fun PickerSheet(onPicked: () -> Unit) {
56
+ LazyColumn {
57
+ items(entries) { entry ->
58
+ RowEntry(
59
+ onClick = { onPicked() },
60
+ entry = entry
61
+ )
62
+ }
63
+ }
64
+ }
65
+
66
+ @Composable
67
+ private fun RowEntry(
68
+ onClick: () -> Unit,
69
+ entry: Entry
70
+ ) {
71
+ Box(modifier = Modifier.clickable { onClick() }) {
72
+ Text(text = entry.name)
73
+ }
74
+ }
75
+ `;
76
+ const FILES_A = new Map([
77
+ ['src/list/RowEntry.kt', PUBLIC_DECL],
78
+ ['src/list/ListPage.kt', PUBLIC_CALLER],
79
+ ['src/picker/PickerSheet.kt', PRIVATE_DECL_AND_CALLER],
80
+ ]);
81
+ const dget = (d, k, dflt) => (d instanceof Map ? (d.has(k) ? d.get(k) : dflt) : (Object.hasOwn(d, k) ? d[k] : dflt));
82
+ const dsize = (d) => (d instanceof Map ? d.size : Object.keys(d).length);
83
+
84
+ test('fixture A: private + public decl of the same name', () => {
85
+ const s2r = new Map([['ListPage', 'LIST']]);
86
+ const ci = co.buildCallIndex(FILES_A, s2r);
87
+ const decls = new Map(dget(ci.fn_decls, 'RowEntry', []));
88
+ assert.equal(decls.size, 2, 'both RowEntry declarations recorded');
89
+ assert.equal(decls.get('src/list/RowEntry.kt'), false, 'public RowEntry recorded as non-private');
90
+ assert.equal(decls.get('src/picker/PickerSheet.kt'), true, 'private RowEntry recorded as private');
91
+ const pooled = [...dget(ci.callee_to_callers, 'RowEntry', [])];
92
+ assert.deepEqual(new Set(pooled), new Set(['ListPage', 'PickerSheet']), 'name-keyed view still pools both');
93
+ assert.deepEqual([...dget(ci.callers_by_decl, tupleKey('RowEntry', 'src/list/RowEntry.kt'), [])], ['ListPage'],
94
+ "public decl's callers == [ListPage]");
95
+ assert.deepEqual([...dget(ci.callers_by_decl, tupleKey('RowEntry', 'src/picker/PickerSheet.kt'), [])], ['PickerSheet'],
96
+ "private decl's callers == [PickerSheet]");
97
+ co.resetAmbiguousHops();
98
+ const ov = new Set(['EntryMenuDialog', 'PickerSheet']);
99
+ const [srcPub] = co.resolveSource('src/list/RowEntry.kt', 'RowEntry', s2r, ov, ci, { partial_tiers: true });
100
+ assert.equal(srcPub, 'compose-route:LIST', "show-site in the public file resolves to its OWN caller's page");
101
+ assert.notEqual(srcPub, 'overlay:PickerSheet', 'REGRESSION: resolved to the PRIVATE sibling caller');
102
+ const [srcPriv] = co.resolveSource('src/picker/PickerSheet.kt', 'RowEntry', s2r, ov, ci, { partial_tiers: true });
103
+ assert.equal(srcPriv, 'overlay:PickerSheet', 'call site in the private file resolves to its own overlay');
104
+ assert.equal(co.ambiguousHops().length, 0, 'a private/public pair is DECIDABLE — no hop refused');
105
+ });
106
+
107
+ const PRIV_ONE = `
108
+ package app.a
109
+
110
+ @Composable
111
+ fun PageOne() {
112
+ Cell(onClick = { })
113
+ }
114
+
115
+ @Composable
116
+ private fun Cell(onClick: () -> Unit) {
117
+ Box(modifier = Modifier.clickable { onClick() }) { Text(text = "a") }
118
+ }
119
+ `;
120
+ const PRIV_TWO = `
121
+ package app.b
122
+
123
+ @Composable
124
+ fun PageTwo() {
125
+ Cell(onClick = { })
126
+ }
127
+
128
+ @Composable
129
+ private fun Cell(onClick: () -> Unit) {
130
+ Box(modifier = Modifier.clickable { onClick() }) { Text(text = "b") }
131
+ }
132
+ `;
133
+ const FILES_B = new Map([['src/a/PageOne.kt', PRIV_ONE], ['src/b/PageTwo.kt', PRIV_TWO]]);
134
+ const S2R_B = new Map([['PageOne', 'ONE'], ['PageTwo', 'TWO']]);
135
+ const ciB = co.buildCallIndex(FILES_B, S2R_B);
136
+
137
+ test('fixture B: two private decls in different files', () => {
138
+ co.resetAmbiguousHops();
139
+ const [one] = co.resolveSource('src/a/PageOne.kt', 'Cell', S2R_B, new Set(), ciB, { partial_tiers: true });
140
+ const [two] = co.resolveSource('src/b/PageTwo.kt', 'Cell', S2R_B, new Set(), ciB, { partial_tiers: true });
141
+ assert.equal(one, 'compose-route:ONE', 'private Cell in file a -> PageOne');
142
+ assert.equal(two, 'compose-route:TWO', 'private Cell in file b -> PageTwo');
143
+ assert.notEqual(one, two, 'two private same-name decls must not collapse');
144
+ assert.equal(co.ambiguousHops().length, 0, 'two private decls are DECIDABLE by file scope');
145
+ });
146
+
147
+ const PUB_A = `
148
+ package app.x
149
+
150
+ @Composable
151
+ fun Widget(onClick: () -> Unit) {
152
+ Box(modifier = Modifier.clickable { onClick() }) { Text(text = "x") }
153
+ }
154
+ `;
155
+ const PUB_B = PUB_A.replace('app.x', 'app.y').replace('"x"', '"y"');
156
+ const THIRD = `
157
+ package app.z
158
+
159
+ @Composable
160
+ fun HostPage() {
161
+ Widget(onClick = { })
162
+ }
163
+ `;
164
+ const FILES_C = new Map([['src/x/WidgetX.kt', PUB_A], ['src/y/WidgetY.kt', PUB_B], ['src/z/HostPage.kt', THIRD]]);
165
+
166
+ test('fixture C/D: two public decls called from a third file; unique names', () => {
167
+ co.resetAmbiguousHops();
168
+ const s2r = new Map([['HostPage', 'HOST']]);
169
+ const ciC = co.buildCallIndex(FILES_C, s2r);
170
+ const [declC, whyC] = co.resolveCalleeDecl('Widget', 'src/z/HostPage.kt', ciC.fn_decls);
171
+ assert.ok(declC === null && whyC === co.DECL_AMBIGUOUS, 'two visible same-name decls == AMBIGUOUS');
172
+ const [srcC] = co.resolveSource('src/x/WidgetX.kt', 'Widget', s2r, new Set(), ciC, { partial_tiers: true });
173
+ assert.notEqual(srcC, 'compose-route:HOST', 'an AMBIGUOUS hop is not attributed to a guessed caller');
174
+ assert.ok(co.ambiguousHops().length > 0, 'an AMBIGUOUS hop is COUNTED');
175
+ assert.ok(co.ambiguousHops().some(([c]) => c === 'Widget'), 'the refused callee is NAMED');
176
+ assert.deepEqual(co.dupCalleeNames(ciC), ['Widget'], 'dupCalleeNames reports the reachable collision only');
177
+ assert.deepEqual(co.resolveCalleeDecl('HostPage', 'src/z/HostPage.kt', ciC.fn_decls),
178
+ ['src/z/HostPage.kt', co.DECL_UNIQUE], 'a single-declaration name resolves as UNIQUE');
179
+ assert.deepEqual(co.dupCalleeNames(ciB), ['Cell'], 'a DECIDABLE collision is still reported');
180
+ });
181
+
182
+ // Mid is declared publicly in two files and called from a third, so the hop is refused both while
183
+ // indexing (from Host.kt) and during the upward walk from Leaf, where Mid's own file is undecidable.
184
+ const MID = (pkg) => `
185
+ package ${pkg}
186
+
187
+ @Composable
188
+ fun Mid() { Leaf() }
189
+ `;
190
+ const FILES_E = new Map([
191
+ ['src/l/Leaf.kt', 'package app.l\n\n@Composable\nfun Leaf() { Text(text = "leaf") }\n'],
192
+ ['src/m1/Mid.kt', MID('app.m1')], ['src/m2/Mid.kt', MID('app.m2')],
193
+ ['src/h/Host.kt', 'package app.h\n\n@Composable\nfun Host() { Mid() }\n'],
194
+ ]);
195
+
196
+ test('fixture E: a refused hop from an undecidable file still sorts (Signal-Android crash)', () => {
197
+ co.resetAmbiguousHops();
198
+ const s2r = new Map([['Host', 'HOST']]);
199
+ const ciE = co.buildCallIndex(FILES_E, s2r);
200
+ co.resolveSource('src/l/Leaf.kt', 'Leaf', s2r, new Set(), ciE, { partial_tiers: true });
201
+ const hops = co.ambiguousHops();
202
+ assert.ok(hops.filter(([c]) => c === 'Mid').length >= 2, 'Mid is refused from both the index and the walk');
203
+ assert.ok(hops.every(([, , f]) => typeof f === 'string'), 'the hop file is always a string, never null');
204
+ });
205
+
206
+ test('back-compat: plain 3-tuple CallIndex', () => {
207
+ const legacy = [new Set(['ListPage']), { RowEntry: ['ListPage'] }, {}];
208
+ const coerced = co.asCallIndex(legacy);
209
+ assert.ok(dsize(coerced.fn_decls) === 0 && dsize(coerced.callers_by_decl) === 0, '3-tuple coerces with empty decl maps');
210
+ const [srcLegacy] = co.resolveSource('src/list/RowEntry.kt', 'RowEntry', new Map([['ListPage', 'LIST']]), new Set(),
211
+ legacy, { partial_tiers: true });
212
+ assert.equal(srcLegacy, 'compose-route:LIST', '3-tuple CallIndex still resolves via the name-keyed map');
213
+ assert.deepEqual(co.dupCalleeNames(legacy), [], 'dupCalleeNames on a 3-tuple is empty');
214
+ });
215
+
216
+ test('visibility parsing', () => {
217
+ const BOTH_ORDERS = `
218
+ @Composable
219
+ private fun AfterAnnotation() { }
220
+
221
+ private @Composable
222
+ fun BeforeAnnotation() { }
223
+
224
+ @Composable
225
+ fun PublicOne() { }
226
+
227
+ @Composable
228
+ internal fun InternalOne() { }
229
+ `;
230
+ const vis = new Map(co.buildFunDeclIndex(BOTH_ORDERS).map(([, n, , p]) => [n, p]));
231
+ assert.equal(vis.get('AfterAnnotation'), true, '`@Composable private fun` read as private');
232
+ assert.equal(vis.get('BeforeAnnotation'), true, '`private @Composable fun` read as private');
233
+ assert.equal(vis.get('PublicOne'), false, 'plain `fun` read as non-private; earlier `private` does not leak');
234
+ assert.equal(vis.get('InternalOne'), false, '`internal fun` is NOT file-private');
235
+ assert.ok(co.buildFunIndex(BOTH_ORDERS).every((t) => t.length === 3), 'buildFunIndex still yields 3-tuples');
236
+ });
@@ -0,0 +1,85 @@
1
+ // Port of test_scope_utils.py: language-dual scope detection + the vacuous-gate alarm.
2
+ import { test } from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import { fnRanges, innermostFnAt, enclosingClass, scopeSearch, sanityFloor, braceScopeAt } from '../scope_utils.mjs';
5
+
6
+ const JAVA = `
7
+ package com.x;
8
+ public class SplashActivity extends Activity {
9
+ @Override
10
+ protected void onCreate(Bundle b) {
11
+ super.onCreate(b);
12
+ loader.subscribe(() -> {
13
+ Intent intent = new Intent(SplashActivity.this, MainActivity.class);
14
+ startActivity(intent);
15
+ });
16
+ }
17
+ private PendingIntent buildTile(Context c) {
18
+ Intent i = new Intent(c, TileActivity.class);
19
+ return PendingIntent.getActivity(c, 0, i, 0);
20
+ }
21
+ }
22
+ `;
23
+
24
+ const KOTLIN = `
25
+ package com.x
26
+ class Foo {
27
+ fun onClick() {
28
+ val i = Intent(ctx, BarActivity::class.java)
29
+ ctx.startActivity(i)
30
+ }
31
+ val prop = Intent(ctx, BazActivity::class.java)
32
+ }
33
+ `;
34
+
35
+ const NESTED = `
36
+ public class Host {
37
+ public static class Inner extends Dialog {
38
+ void helper() { int x = 1; }
39
+ }
40
+ void onTap() {
41
+ startActivity(new Intent(this, TargetActivity.class));
42
+ }
43
+ }
44
+ `;
45
+
46
+ const sink = () => { const b = { s: '', write(x) { b.s += x; } }; return b; };
47
+
48
+ test('Java method ranges', () => {
49
+ const jr = fnRanges(JAVA, 'A.java');
50
+ const names = new Set(jr.map((r) => r[2]));
51
+ assert.ok(names.has('onCreate') && names.has('buildTile'), 'Java method declarations are found');
52
+ const pos = JAVA.indexOf('MainActivity.class');
53
+ assert.equal(innermostFnAt(jr, pos), 'onCreate', 'innermost enclosing Java method resolves for a lambda site');
54
+ assert.ok(scopeSearch(String.raw`\bstartActivity\s*\(`, JAVA, pos, jr), 'dispatch in the ENCLOSING method is seen');
55
+ for (const k of ['if', 'for', 'switch', 'catch']) { assert.ok(!names.has(k), 'control keywords are not methods'); }
56
+ });
57
+
58
+ test('Kotlin still works', () => {
59
+ const kr = fnRanges(KOTLIN, 'A.kt');
60
+ const kpos = KOTLIN.indexOf('BarActivity');
61
+ assert.equal(innermostFnAt(kr, kpos), 'onClick');
62
+ assert.ok(scopeSearch(String.raw`startActivity\s*\(`, KOTLIN, kpos, kr));
63
+ const ppos = KOTLIN.indexOf('BazActivity');
64
+ assert.ok(!scopeSearch(String.raw`startActivity\s*\(`, KOTLIN, ppos, kr, { widen_lexical: false }),
65
+ 'a property initializer does not inherit another fn\'s dispatch');
66
+ });
67
+
68
+ test('class ownership by nesting', () => {
69
+ assert.equal(enclosingClass(NESTED, NESTED.indexOf('TargetActivity')), 'Host');
70
+ });
71
+
72
+ test('lexical fallback', () => {
73
+ const pos = JAVA.indexOf('MainActivity.class');
74
+ const sc = braceScopeAt(JAVA, pos);
75
+ assert.ok(sc !== null && sc[0] < pos && pos < sc[1]);
76
+ });
77
+
78
+ test('the alarm', () => {
79
+ const buf = sink();
80
+ assert.ok(sanityFloor('t', 14, 0, { stream: buf }) && buf.s.includes('SANITY'), 'candidates>0, 0 emitted trips SANITY');
81
+ const buf2 = sink();
82
+ assert.ok(!sanityFloor('t', 0, 0, { stream: buf2 }) && buf2.s === '', 'a genuine no-op stays silent');
83
+ const buf3 = sink();
84
+ assert.ok(!sanityFloor('t', 5, 3, { stream: buf3 }), 'partial emission does not trip');
85
+ });
@@ -0,0 +1,148 @@
1
+ // Port of test_sealed_dialog_state.py: sealed-class dialog state (`when (state.dialog) { is X -> }`)
2
+ // openers resolve to their OWN control's label via hoisted callback slots.
3
+ import { test } from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import * as co from '../compose_overlay.mjs';
6
+ import * as lr from '../label_resolve.mjs';
7
+ import { pyRe, reFindall } from '../_py.mjs';
8
+
9
+ const STRINGS = { action_delete: '删除', action_rename: '重命名', action_archive: '归档' };
10
+
11
+ const SCREEN = `
12
+ @Composable
13
+ fun ItemsRoute(model: ItemsModel) {
14
+ val state by model.state.collectAsState()
15
+
16
+ ItemsContent(
17
+ items = state.items,
18
+ onClickRename = { model.showDialog(AppDialog.Rename(it)) },
19
+ onClickDelete = { model.showDialog(AppDialog.Delete(it)) },
20
+ )
21
+
22
+ when (val d = state.dialog) {
23
+ null -> {}
24
+ is AppDialog.Rename -> {
25
+ RenameEntryDialog(
26
+ onDismissRequest = model::dismissDialog,
27
+ onRename = { model.rename(d.item, it) },
28
+ )
29
+ }
30
+ is AppDialog.Delete -> {
31
+ DeleteEntryDialog(
32
+ onDismissRequest = model::dismissDialog,
33
+ onDelete = { model.delete(d.item.id) },
34
+ )
35
+ }
36
+ }
37
+ }
38
+ `;
39
+ const CONTENT = `
40
+ @Composable
41
+ fun ItemsContent(
42
+ items: List<Item>,
43
+ onClickRename: (Item) -> Unit,
44
+ onClickDelete: (Item) -> Unit,
45
+ ) {
46
+ LazyColumn {
47
+ items(items) { item ->
48
+ EntryRow(
49
+ item = item,
50
+ onRename = { onClickRename(item) },
51
+ onDelete = { onClickDelete(item) },
52
+ )
53
+ }
54
+ }
55
+ }
56
+ `;
57
+ const ROW = `
58
+ @Composable
59
+ fun LazyItemScope.EntryRow(
60
+ item: Item,
61
+ onRename: () -> Unit,
62
+ onDelete: () -> Unit,
63
+ ) {
64
+ Row {
65
+ Text(text = item.name)
66
+ IconButton(onClick = onRename) {
67
+ Icon(
68
+ imageVector = Icons.Outlined.Edit,
69
+ contentDescription = stringResource(MR.strings.action_rename),
70
+ )
71
+ }
72
+ IconButton(onClick = onDelete) {
73
+ Icon(
74
+ imageVector = Icons.Outlined.Delete,
75
+ contentDescription = stringResource(MR.strings.action_delete),
76
+ )
77
+ }
78
+ }
79
+ }
80
+ `;
81
+ const FILES = new Map([['src/ItemsRoute.kt', SCREEN], ['src/ItemsContent.kt', CONTENT], ['src/EntryRow.kt', ROW]]);
82
+ const dPos = SCREEN.indexOf('onClickDelete = { model.showDialog');
83
+ const rPos = SCREEN.indexOf('onClickRename = { model.showDialog');
84
+
85
+ test('hoistedCallbackLabel follows (callee, parameter) slots', () => {
86
+ const [lblD, keyD] = lr.hoistedCallbackLabel(SCREEN, dPos, STRINGS, FILES);
87
+ assert.deepEqual([lblD, keyD], ['删除', 'action_delete'], 'the DELETE opener resolves to its own label');
88
+ const [lblR, keyR] = lr.hoistedCallbackLabel(SCREEN, rPos, STRINGS, FILES);
89
+ assert.deepEqual([lblR, keyR], ['重命名', 'action_rename'], 'the RENAME opener resolves to ITS own label');
90
+ assert.notEqual(lblD, lblR, 'two adjacent openers do not collapse onto one label');
91
+ assert.notEqual(lr._findDecl('EntryRow', FILES), null, 'an extension-function declaration is located');
92
+ assert.notEqual(lr._findDecl('ItemsContent', FILES), null, 'a plain declaration is still located');
93
+ });
94
+
95
+ test('refusals: a wrong label is worse than none', () => {
96
+ const AMBIG = new Map(FILES);
97
+ AMBIG.set('src/OtherRow.kt', ROW.replace('LazyItemScope.EntryRow', 'EntryRow'));
98
+ assert.equal(lr._findDecl('EntryRow', AMBIG), null, 'two declarations of one name -> refuse');
99
+ assert.deepEqual(lr.hoistedCallbackLabel(SCREEN, dPos, STRINGS, AMBIG), [null, null], 'ambiguous callee refuses');
100
+ assert.deepEqual(lr.hoistedCallbackLabel(SCREEN, dPos, STRINGS, new Map()), [null, null], 'no project text -> refuse');
101
+ const NO_LABEL = new Map(FILES);
102
+ NO_LABEL.set('src/EntryRow.kt', ROW.replace(
103
+ 'contentDescription = stringResource(MR.strings.action_delete),', 'contentDescription = null,'));
104
+ const [lblNl] = lr.hoistedCallbackLabel(SCREEN, dPos, STRINGS, NO_LABEL);
105
+ assert.notEqual(lblNl, '重命名', 'rename label is not substituted for an unlabeled delete control');
106
+ const LOOP = new Map([
107
+ ['src/A.kt', '@Composable\nfun A(onX: () -> Unit) { B(onY = onX) }\n'],
108
+ ['src/B.kt', '@Composable\nfun B(onY: () -> Unit) { A(onX = onY) }\n']]);
109
+ assert.deepEqual(lr._resolveParamLabel('A', 'onX', STRINGS, LOOP, null, 4), [null, null], 'a callback cycle terminates');
110
+ });
111
+
112
+ // Mirror of the extractor's gate scan (as in the Python test).
113
+ const GATE_RE = pyRe(String.raw`if\s*\(\s*(\w+)(?:\.value)?\s*(?:!=\s*null\s*)?\)|\b(\w+)(?:\.value)?\s*\?\.\s*let\s*\{`);
114
+ const ARM_RE = pyRe(String.raw`(?:is\s+)?([A-Z]\w*(?:\.\w+)+)\s*->`);
115
+ function gatesAt(text, pos) {
116
+ const back = text.slice(Math.max(0, pos - 400), pos);
117
+ let g = reFindall(GATE_RE, back).map(([a, b]) => a || b);
118
+ if (!g.length) { g = reFindall(ARM_RE, back).map((a) => a.split('.').at(-1)).slice(-1); }
119
+ return g;
120
+ }
121
+ const BOOL = `
122
+ @Composable
123
+ fun Host() {
124
+ var showConfirm by remember { mutableStateOf(false) }
125
+ Button(onClick = { showConfirm = true }) { Text("x") }
126
+ if (showConfirm) {
127
+ ConfirmDialog(onDismissRequest = { showConfirm = false })
128
+ }
129
+ }
130
+ `;
131
+
132
+ test('render-site gate: a `when` arm yields the variant token', () => {
133
+ assert.deepEqual(gatesAt(SCREEN, SCREEN.indexOf('DeleteEntryDialog(')), ['Delete'], 'delete render site');
134
+ assert.deepEqual(gatesAt(SCREEN, SCREEN.indexOf('RenameEntryDialog(')), ['Rename'], 'rename render site');
135
+ assert.deepEqual(gatesAt(BOOL, BOOL.indexOf('ConfirmDialog(')), ['showConfirm'], 'a local boolean flag still wins');
136
+ });
137
+
138
+ test('_buildFlagLabels: the variant becomes a keyed opener', () => {
139
+ const funs = co.buildFunIndex(SCREEN);
140
+ const fl = co._buildFlagLabels(SCREEN, funs, STRINGS, FILES, co._buildCalleeIndex(FILES));
141
+ assert.ok(fl.has('Delete') && fl.get('Delete')[1] === '删除', `Delete keyed (got ${JSON.stringify(fl.get('Delete'))})`);
142
+ assert.ok(fl.has('Rename') && fl.get('Rename')[1] === '重命名', `Rename keyed (got ${JSON.stringify(fl.get('Rename'))})`);
143
+ const bFiles = new Map([['src/B.kt', BOOL]]);
144
+ const flB = co._buildFlagLabels(BOOL, co.buildFunIndex(BOOL), STRINGS, bFiles, co._buildCalleeIndex(bFiles));
145
+ const isUp = (c) => c !== c.toLowerCase() && c === c.toUpperCase();
146
+ assert.ok([...flB.keys()].every((k) => !isUp(k[0]) || k === '__multi__'),
147
+ `a boolean-only file gains no variant keys (got ${[...flB.keys()]})`);
148
+ });