@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,328 @@
1
+ // A centralized login interceptor on typed routes (coolmall, Navigation3, measured 2026-11): the gate
2
+ // lives in the navigator every navigation passes through, so no trigger site carries it. Without
3
+ // route_interceptor.mjs the 14 protected routes were planned into P0_fresh and the explorer, logged
4
+ // out, landed on the login page instead. Also covers the `isLoggedIn.value` arm of _LOGIN_TEST_RE.
5
+ import { test } from 'node:test';
6
+ import assert from 'node:assert/strict';
7
+ import { reSearch } from '../_py.mjs';
8
+ import * as fs from 'node:fs';
9
+ import * as os from 'node:os';
10
+ import * as path from 'node:path';
11
+ import { _LOGIN_TEST_RE, _branchGuard } from '../assemble.mjs';
12
+ import { StaticPrior } from '../static_prior.mjs';
13
+ import { _guardHint } from '../click_paths.mjs';
14
+ import {
15
+ findLoginInterceptor, applyLoginInterceptor, classSets, loginPolarity, routeResolver,
16
+ } from '../route_interceptor.mjs';
17
+
18
+ const isLogin = (s) => reSearch(_LOGIN_TEST_RE, s) !== null;
19
+
20
+ test('_LOGIN_TEST_RE reads a login flag accessed as a property', () => {
21
+ for (const s of ['!appState.isLoggedIn.value', 'isLoggedIn.value && userInfo.value == null',
22
+ '!_isLoggedIn.value', 'isLogin', '!viewModel.isSignedIn', 'hasLoggedIn']) {
23
+ assert.ok(isLogin(s), s);
24
+ }
25
+ });
26
+
27
+ test('_LOGIN_TEST_RE: the identifier must be the whole flag', () => {
28
+ for (const s of ['isLoggedInRequired', 'isLoginButtonVisible', 'loggedInUserId.isEmpty()',
29
+ 'routeInterceptor.requiresLogin(route)', 'showLoginHint']) {
30
+ assert.ok(!isLogin(s), s);
31
+ }
32
+ });
33
+
34
+ test('_LOGIN_TEST_RE keeps its earlier arms', () => {
35
+ assert.ok(isLogin('!isLoggedIn()'));
36
+ assert.ok(isLogin('isLogin == false'));
37
+ });
38
+
39
+ const INTERCEPTOR = `package a
40
+ class RouteInterceptor {
41
+ // the protected set
42
+ private val loginRequiredRouteTypes: Set<KClass<out NavKey>> = setOf(
43
+ UserRoutes.Profile::class,
44
+ OrderRoutes.List::class,
45
+ FeedbackRoutes.List::class,
46
+ )
47
+ fun requiresLogin(route: NavKey): Boolean {
48
+ val routeClass = route::class
49
+ return loginRequiredRouteTypes.contains(routeClass)
50
+ }
51
+ fun getLoginRoute(): NavKey = AuthRoutes.Login
52
+ }
53
+ `;
54
+ const NAVIGATOR = `package a
55
+ class AppNavigator(private val routeInterceptor: RouteInterceptor, private val appState: AppState) {
56
+ fun navigateTo(route: NavKey) { execute(resolveTargetRoute(route)) }
57
+ private fun resolveTargetRoute(route: NavKey): NavKey {
58
+ return if (routeInterceptor.requiresLogin(route) && !appState.isLoggedIn.value) {
59
+ routeInterceptor.getLoginRoute()
60
+ } else {
61
+ route
62
+ }
63
+ }
64
+ }
65
+ `;
66
+ // a ::class route table with a membership test but no login test: bottom-bar routes, not a gate
67
+ const BOTTOM_BAR = `package a
68
+ class Chrome {
69
+ private val tabRoutes = setOf(MainRoutes.Home::class, MainRoutes.Me::class)
70
+ fun isTab(route: NavKey) = tabRoutes.contains(route::class)
71
+ fun showBar(route: NavKey) { if (isTab(route)) bar.show() }
72
+ }
73
+ `;
74
+
75
+ function fake(files) {
76
+ return { sources: Object.keys(files), read: (p) => { if (!(p in files)) { throw new Error(p); } return files[p]; } };
77
+ }
78
+
79
+ test('classSets accepts only all-::class literal collections', () => {
80
+ assert.deepEqual(classSets('val a = setOf(X.Y::class, Z::class)')[0].members,
81
+ [{ holder: 'X', member: 'Y' }, { holder: null, member: 'Z' }]);
82
+ assert.equal(classSets('val a = setOf(X.Y::class, "z")').length, 0);
83
+ assert.equal(classSets('val a = setOf()').length, 0);
84
+ });
85
+
86
+ test('finds the protected set, the gate and the redirect', () => {
87
+ const { sources, read } = fake({ '/p/RouteInterceptor.kt': INTERCEPTOR, '/p/AppNavigator.kt': NAVIGATOR, '/p/Chrome.kt': BOTTOM_BAR });
88
+ const f = findLoginInterceptor(sources, _LOGIN_TEST_RE, read);
89
+ assert.equal(f.set_file, '/p/RouteInterceptor.kt');
90
+ assert.equal(f.set_line, 4);
91
+ assert.equal(f.gate_file, '/p/AppNavigator.kt');
92
+ assert.equal(f.gate_line, 5);
93
+ assert.deepEqual(f.redirect, ['AuthRoutes.Login']);
94
+ assert.deepEqual(f.members.map((m) => `${m.holder}.${m.member}`), ['UserRoutes.Profile', 'OrderRoutes.List', 'FeedbackRoutes.List']);
95
+ });
96
+
97
+ test('a ::class set with no login test in its gate is not an interceptor', () => {
98
+ const { sources, read } = fake({ '/p/Chrome.kt': BOTTOM_BAR, '/p/RouteInterceptor.kt': INTERCEPTOR });
99
+ assert.equal(findLoginInterceptor(sources, _LOGIN_TEST_RE, read), null);
100
+ });
101
+
102
+ test('two login-gated sets are ambiguous and refused', () => {
103
+ const second = INTERCEPTOR.replace('class RouteInterceptor', 'class VipInterceptor')
104
+ .replace(/loginRequiredRouteTypes/g, 'vipTypes').replace(/requiresLogin/g, 'requiresVip')
105
+ .replace('UserRoutes.Profile::class', 'VipRoutes.Center::class');
106
+ const nav2 = NAVIGATOR.replace(/requiresLogin/g, 'requiresVip').replace('class AppNavigator', 'class VipNavigator');
107
+ const { sources, read } = fake({ '/p/A.kt': INTERCEPTOR, '/p/B.kt': NAVIGATOR, '/p/C.kt': second, '/p/D.kt': nav2 });
108
+ assert.match(findLoginInterceptor(sources, _LOGIN_TEST_RE, read).refused, /2 login-gated/);
109
+ });
110
+
111
+ test('apply stamps nodes and unguarded edges, keeps an earned guard', () => {
112
+ const nodes = {
113
+ 'compose-route:Me': {}, 'compose-route:Profile': {}, 'compose-route:Login': {},
114
+ 'compose-route:OrderRoutes.List': {}, 'compose-route:FeedbackRoutes.List': { required_state: ['content'] },
115
+ };
116
+ const dataGuard = { text: 'branch:items.isNotEmpty()', kind: 'data-state' };
117
+ const edges = [
118
+ { source: 'compose-route:Me', target: 'compose-route:Profile' },
119
+ { source: 'compose-route:Me', target: 'compose-route:OrderRoutes.List#empty' },
120
+ { source: 'compose-route:Me', target: 'compose-route:FeedbackRoutes.List', guard: dataGuard },
121
+ { source: 'compose-route:Me', target: 'compose-route:Login' },
122
+ ];
123
+ const { sources, read } = fake({ '/p/RouteInterceptor.kt': INTERCEPTOR, '/p/AppNavigator.kt': NAVIGATOR });
124
+ const r = applyLoginInterceptor(nodes, edges, findLoginInterceptor(sources, _LOGIN_TEST_RE, read), '/p');
125
+ assert.equal(r.nodes.length, 3);
126
+ assert.equal(r.edges, 2);
127
+ assert.deepEqual(nodes['compose-route:FeedbackRoutes.List'].required_state, ['content', 'login']);
128
+ assert.equal(nodes['compose-route:Profile'].login_interceptor.redirect_when_unmet, 'compose-route:Login');
129
+ assert.deepEqual(edges[0].guard, { text: 'interceptor:RouteInterceptor.kt:4', kind: 'login', redirect_when_unmet: 'compose-route:Login' });
130
+ assert.equal(edges[1].guard.kind, 'login');
131
+ assert.equal(edges[2].guard, dataGuard);
132
+ assert.equal(edges[3].guard, undefined);
133
+ assert.equal(nodes['compose-route:Login'].required_state, undefined);
134
+ assert.equal(nodes['compose-route:Me'].required_state, undefined);
135
+ });
136
+
137
+ test('apply reports members with no route node', () => {
138
+ const nodes = { 'compose-route:Profile': {}, 'compose-route:Login': {} };
139
+ const { sources, read } = fake({ '/p/RouteInterceptor.kt': INTERCEPTOR, '/p/AppNavigator.kt': NAVIGATOR });
140
+ const r = applyLoginInterceptor(nodes, [], findLoginInterceptor(sources, _LOGIN_TEST_RE, read), '/p');
141
+ assert.deepEqual(r.unmatched, ['OrderRoutes.List', 'FeedbackRoutes.List']);
142
+ assert.deepEqual(r.nodes, ['compose-route:Profile']);
143
+ });
144
+
145
+ test('apply stamps nothing when the redirect is not a route node', () => {
146
+ const nodes = { 'compose-route:Profile': {} };
147
+ const { sources, read } = fake({ '/p/RouteInterceptor.kt': INTERCEPTOR, '/p/AppNavigator.kt': NAVIGATOR });
148
+ const r = applyLoginInterceptor(nodes, [], findLoginInterceptor(sources, _LOGIN_TEST_RE, read), '/p');
149
+ assert.match(r.skipped, /not a route node/);
150
+ assert.equal(nodes['compose-route:Profile'].required_state, undefined);
151
+ });
152
+
153
+ // ---- PR !105 review findings --------------------------------------------------------------------
154
+ const find = (files) => { const { sources, read } = fake(files); return findLoginInterceptor(sources, _LOGIN_TEST_RE, read); };
155
+ const kclassNames = (f) => f.members.map((m) => `${m.holder}.${m.member}`);
156
+
157
+ test('a #variant node of a protected route carries the login axis too', () => {
158
+ const nodes = { 'compose-route:Profile': {}, 'compose-route:Profile#empty': { required_state: ['empty-state'] }, 'compose-route:Login': {} };
159
+ const r = applyLoginInterceptor(nodes, [], find({ '/p/A.kt': INTERCEPTOR, '/p/B.kt': NAVIGATOR }), '/p');
160
+ assert.deepEqual(r.nodes, ['compose-route:Profile', 'compose-route:Profile#empty']);
161
+ assert.deepEqual(nodes['compose-route:Profile#empty'].required_state, ['empty-state', 'login']);
162
+ });
163
+
164
+ test('a "/*" or "//" inside a string literal does not swallow the gate', () => {
165
+ const nav = NAVIGATOR.replace(' private fun resolveTargetRoute',
166
+ ' val mime = "image/*"\n val home = "https://x.y//z"\n private fun resolveTargetRoute') + '/** kdoc */\n';
167
+ const f = find({ '/p/A.kt': INTERCEPTOR, '/p/B.kt': nav });
168
+ assert.equal(f.gate_line, 7);
169
+ });
170
+
171
+ test('a bracket inside a string in the gate condition does not truncate it', () => {
172
+ const nav = NAVIGATOR.replace('!appState.isLoggedIn.value)', '!appState.isLoggedIn.value && tag != ")")');
173
+ const f = find({ '/p/A.kt': INTERCEPTOR, '/p/B.kt': nav });
174
+ // string contents are blanked in the recorded condition; what matters is it was not cut at the ")"
175
+ assert.match(f.gate_cond, /isLoggedIn\.value && tag !=$/);
176
+ assert.deepEqual(f.redirect, ['AuthRoutes.Login']);
177
+ });
178
+
179
+ test('setOf with explicit type arguments and by-less = is read', () => {
180
+ const ic = INTERCEPTOR.replace(': Set<KClass<out NavKey>> = setOf(', ' = setOf<KClass<out NavKey>>(');
181
+ assert.deepEqual(kclassNames(find({ '/p/A.kt': ic, '/p/B.kt': NAVIGATOR })), ['UserRoutes.Profile', 'OrderRoutes.List', 'FeedbackRoutes.List']);
182
+ });
183
+
184
+ test('a when-arm gate is recognised', () => {
185
+ const nav = `package a
186
+ class AppNavigator(private val interceptor: RouteInterceptor, private val appState: AppState) {
187
+ private fun resolveTargetRoute(route: NavKey): NavKey = when {
188
+ interceptor.requiresLogin(route) && !appState.isLoggedIn.value -> interceptor.getLoginRoute()
189
+ else -> route
190
+ }
191
+ }
192
+ `;
193
+ const f = find({ '/p/A.kt': INTERCEPTOR, '/p/B.kt': nav });
194
+ assert.equal(f.gate_line, 4);
195
+ assert.deepEqual(f.redirect, ['AuthRoutes.Login']);
196
+ });
197
+
198
+ test('test sources are not read; identical flavor copies are one set', () => {
199
+ const fakeInTest = INTERCEPTOR.replace(/UserRoutes\.Profile::class,/, 'X.Y::class,');
200
+ assert.ok(!find({ '/p/A.kt': INTERCEPTOR, '/p/B.kt': NAVIGATOR, '/p/src/test/java/C.kt': fakeInTest, '/p/src/test/java/D.kt': NAVIGATOR }).refused);
201
+ const f = find({ '/p/src/debug/A.kt': INTERCEPTOR, '/p/src/release/A.kt': INTERCEPTOR, '/p/B.kt': NAVIGATOR });
202
+ assert.ok(!f.refused);
203
+ assert.equal(f.set_file, '/p/src/debug/A.kt');
204
+ });
205
+
206
+ test('a membership test after a fun body is not credited to that fun', () => {
207
+ const ic = `package a
208
+ class RouteInterceptor {
209
+ private val gated = setOf(UserRoutes.Profile::class)
210
+ fun getLoginRoute(): NavKey = AuthRoutes.Login
211
+ val isTabGated = gated.contains(MainRoutes.Home::class)
212
+ fun requiresLogin(route: NavKey): Boolean { return gated.contains(route::class) }
213
+ }
214
+ `;
215
+ const nav = `package a
216
+ fun bad(i: RouteInterceptor) { if (i.getLoginRoute() != null && !isLoggedIn.value) go() }
217
+ `;
218
+ assert.equal(find({ '/p/A.kt': ic, '/p/B.kt': nav }), null);
219
+ assert.ok(find({ '/p/A.kt': ic, '/p/B.kt': NAVIGATOR }));
220
+ });
221
+
222
+ test('the redirect is found past an earlier call and as a constructor route', () => {
223
+ const tracked = NAVIGATOR.replace('routeInterceptor.getLoginRoute()', 'analytics.track()\n routeInterceptor.getLoginRoute()');
224
+ assert.deepEqual(find({ '/p/A.kt': INTERCEPTOR, '/p/B.kt': tracked }).redirect, ['AuthRoutes.Login']);
225
+ const ctor = NAVIGATOR.replace('routeInterceptor.getLoginRoute()', 'AuthRoutes.Login(returnTo = route)');
226
+ const f = find({ '/p/A.kt': INTERCEPTOR, '/p/B.kt': ctor });
227
+ const nodes = { 'compose-route:Profile': {}, 'compose-route:Login': {} };
228
+ applyLoginInterceptor(nodes, [], f, '/p');
229
+ assert.equal(nodes['compose-route:Profile'].login_interceptor.redirect_when_unmet, 'compose-route:Login');
230
+ });
231
+
232
+ // ---- PR !105 review, round 2 ---------------------------------------------------------------------
233
+ test('loginPolarity reads the direction of a login test', () => {
234
+ const p = (c) => loginPolarity(c, _LOGIN_TEST_RE);
235
+ for (const c of ['!isLoggedIn()', '!appState.isLoggedIn.value', ' && !appState.isLoggedIn.value',
236
+ 'isLogin == false', 'isLoggedIn.value == false', 'not (isLoggedIn())', 'isLoggedIn() != true']) {
237
+ assert.equal(p(c), 'logged-out', c);
238
+ }
239
+ for (const c of ['isLoggedIn()', 'appState.isLoggedIn.value', 'isLogin == true', 'isLoggedIn != false',
240
+ 'not (!isLoggedIn())', 'a != b && isLoggedIn']) {
241
+ assert.equal(p(c), 'logged-in', c);
242
+ }
243
+ assert.equal(p('isLoggedIn && !hasLoggedIn'), null);
244
+ assert.equal(p('items.isEmpty()'), null);
245
+ });
246
+
247
+ // the review's probe: a ::class set gated on a logged-IN flag with no redirect is a display rule
248
+ const BADGE = `package a
249
+ class Cfg {
250
+ private val badgeRoutes = setOf(UserRoutes.Profile::class, OrderRoutes.List::class)
251
+ fun showsBadge(route: NavKey): Boolean = badgeRoutes.contains(route::class)
252
+ }
253
+ `;
254
+ const BADGE_USE = `package a
255
+ fun bar(cfg: Cfg, route: NavKey) { if (cfg.showsBadge(route) && appState.isLoggedIn.value) { showBadge() } }
256
+ `;
257
+
258
+ test('a logged-in display rule with no redirect is not an interceptor', () => {
259
+ assert.equal(find({ '/p/Cfg.kt': BADGE, '/p/Bar.kt': BADGE_USE }), null);
260
+ });
261
+
262
+ test('a display rule beside a real interceptor does not make it ambiguous', () => {
263
+ const f = find({ '/p/Cfg.kt': BADGE, '/p/Bar.kt': BADGE_USE, '/p/A.kt': INTERCEPTOR, '/p/B.kt': NAVIGATOR });
264
+ assert.ok(!f.refused);
265
+ assert.equal(f.set_file, '/p/A.kt');
266
+ });
267
+
268
+ test('a logged-in gate redirects from its else branch', () => {
269
+ const nav = `package a
270
+ class AppNavigator(private val i: RouteInterceptor, private val s: AppState) {
271
+ private fun resolve(route: NavKey): NavKey =
272
+ if (!i.requiresLogin(route) || s.isLoggedIn.value) route else i.getLoginRoute()
273
+ private fun resolve2(route: NavKey): NavKey = when {
274
+ i.requiresLogin(route) && s.isLoggedIn.value -> route
275
+ else -> AuthRoutes.Login
276
+ }
277
+ }
278
+ `;
279
+ const f = find({ '/p/A.kt': INTERCEPTOR, '/p/B.kt': nav });
280
+ assert.deepEqual(f.redirect, ['AuthRoutes.Login']);
281
+ assert.equal(f.gate_line, 4);
282
+ });
283
+
284
+ test('the redirect must be a route node when the caller says which literals are', () => {
285
+ const nodes = { 'compose-route:Profile': {} };
286
+ const nav = NAVIGATOR.replace('routeInterceptor.getLoginRoute()', 'Toast.LENGTH_SHORT');
287
+ const { sources, read } = fake({ '/p/A.kt': INTERCEPTOR, '/p/B.kt': nav });
288
+ assert.equal(findLoginInterceptor(sources, _LOGIN_TEST_RE, read, routeResolver(nodes)), null);
289
+ });
290
+
291
+ test('a set declared by lazy is read', () => {
292
+ const ic = INTERCEPTOR.replace(': Set<KClass<out NavKey>> = setOf(', ' by lazy { setOf(')
293
+ .replace('FeedbackRoutes.List::class,\n )', 'FeedbackRoutes.List::class,\n ) }');
294
+ assert.equal(find({ '/p/A.kt': ic, '/p/B.kt': NAVIGATOR }).members.length, 3);
295
+ });
296
+
297
+ test('_branchGuard marks a logged-out branch, and the planner does not require login for it', () => {
298
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'utg-login-'));
299
+ const rel = 'app/src/main/java/a/HomeViewModel.kt';
300
+ fs.mkdirSync(path.join(root, path.dirname(rel)), { recursive: true });
301
+ fs.writeFileSync(path.join(root, rel), `package a
302
+ class HomeViewModel {
303
+ fun receive() {
304
+ if (!appState.isLoggedIn.value) {
305
+ navigate(AuthRoutes.Login)
306
+ return
307
+ }
308
+ navigate(GoodsRoutes.Detail)
309
+ }
310
+ }
311
+ `);
312
+ const out = _branchGuard({ trigger: `onClick@${rel}:5` }, root);
313
+ assert.deepEqual(out, { text: 'branch:!appState.isLoggedIn.value', kind: 'login', polarity: 'logged-out' });
314
+ const after = _branchGuard({ trigger: `onClick@${rel}:8` }, root);
315
+ assert.equal(after.kind, 'login');
316
+ assert.equal(after.polarity, undefined);
317
+ assert.equal(StaticPrior._axisOf(out), null);
318
+ assert.equal(StaticPrior._axisOf(after), 'login');
319
+ fs.rmSync(root, { recursive: true, force: true });
320
+ });
321
+
322
+ test('click-path text carries the direction and the redirect', () => {
323
+ assert.equal(_guardHint({ kind: 'login', text: 'branch:!isLoggedIn()', polarity: 'logged-out' }),
324
+ '(仅未登录时:branch:!isLoggedIn())');
325
+ assert.equal(_guardHint({ kind: 'login', text: 'interceptor:R.kt:29', redirect_when_unmet: 'compose-route:Login' }),
326
+ '(需满足前置条件:interceptor:R.kt:29;未登录时改跳到 Login)');
327
+ assert.equal(_guardHint({ kind: 'data-state', text: 'branch:x' }), '(需满足前置条件:branch:x)');
328
+ });
@@ -0,0 +1,40 @@
1
+ // android:exported omitted: Android's default is "exported iff the component
2
+ // has an <intent-filter>". Treating a missing attribute as false hid the
3
+ // launcher Activity from direct-launch (every item skipped).
4
+ import { test } from 'node:test';
5
+ import assert from 'node:assert/strict';
6
+ import * as fs from 'node:fs';
7
+ import * as os from 'node:os';
8
+ import * as path from 'node:path';
9
+ import * as mf from '../manifest.mjs';
10
+
11
+ const XML = `<?xml version="1.0" encoding="utf-8"?>
12
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.app">
13
+ <application>
14
+ <activity android:name=".Main">
15
+ <intent-filter>
16
+ <action android:name="android.intent.action.MAIN" />
17
+ <category android:name="android.intent.category.LAUNCHER" />
18
+ </intent-filter>
19
+ </activity>
20
+ <activity android:name=".Share">
21
+ <intent-filter><action android:name="android.intent.action.SEND" /></intent-filter>
22
+ </activity>
23
+ <activity android:name=".Internal" />
24
+ <activity android:name=".Hidden" android:exported="false">
25
+ <intent-filter><action android:name="com.example.HIDDEN" /></intent-filter>
26
+ </activity>
27
+ <activity android:name=".Open" android:exported="true" />
28
+ </application>
29
+ </manifest>
30
+ `;
31
+
32
+ test('missing android:exported follows the intent-filter default', () => {
33
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mf-'));
34
+ try {
35
+ const p = path.join(tmp, 'AndroidManifest.xml');
36
+ fs.writeFileSync(p, XML, 'utf8');
37
+ const by = Object.fromEntries(mf.parseManifest(p, 'com.example.app').map((r) => [r.name.split('.').pop(), r.exported]));
38
+ assert.deepEqual(by, { Main: true, Share: true, Internal: false, Hidden: false, Open: true });
39
+ } finally { fs.rmSync(tmp, { recursive: true, force: true }); }
40
+ });
@@ -0,0 +1,84 @@
1
+ // Regression: (5) the <data> elements of ONE intent-filter merge into launchable contracts;
2
+ // (6) two app modules declaring different activities with the same simple name no longer share
3
+ // one node id (the single-module id stays `activity:<Short>`).
4
+ import { test } from 'node:test';
5
+ import assert from 'node:assert/strict';
6
+ import * as fs from 'node:fs';
7
+ import * as os from 'node:os';
8
+ import * as path from 'node:path';
9
+ import * as mf from '../manifest.mjs';
10
+
11
+ const manifest = (pkg, body) => `<?xml version="1.0" encoding="utf-8"?>
12
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="${pkg}">
13
+ <application>
14
+ ${body}
15
+ </application>
16
+ </manifest>
17
+ `;
18
+
19
+ const withTmp = (fn) => {
20
+ const d = fs.mkdtempSync(path.join(os.tmpdir(), 'mff-'));
21
+ try { return fn(d); } finally { fs.rmSync(d, { recursive: true, force: true }); }
22
+ };
23
+
24
+ test('data elements of one filter merge; separate filters stay separate', () => withTmp((d) => {
25
+ const p = path.join(d, 'AndroidManifest.xml');
26
+ fs.writeFileSync(p, manifest('com.example.app', `
27
+ <activity android:name=".Link" android:exported="true">
28
+ <intent-filter>
29
+ <action android:name="android.intent.action.VIEW" />
30
+ <data android:scheme="https" />
31
+ <data android:host="example.com" />
32
+ <data android:pathPrefix="/item" />
33
+ <data android:mimeType="text/plain" />
34
+ </intent-filter>
35
+ <intent-filter>
36
+ <action android:name="android.intent.action.VIEW" />
37
+ <data android:scheme="app" android:host="open" />
38
+ </intent-filter>
39
+ </activity>
40
+ <activity android:name=".Multi" android:exported="true">
41
+ <intent-filter>
42
+ <action android:name="android.intent.action.VIEW" />
43
+ <data android:scheme="http" />
44
+ <data android:scheme="https" />
45
+ <data android:host="m.example.com" />
46
+ </intent-filter>
47
+ </activity>`), 'utf8');
48
+ const by = Object.fromEntries(mf.parseManifest(p, 'com.example.app').map((r) => [r.name.split('.').pop(), r]));
49
+ assert.deepEqual(by.Link.deep_links, [
50
+ { scheme: 'https', host: 'example.com', pathPrefix: '/item', mimeType: 'text/plain' },
51
+ { scheme: 'app', host: 'open' },
52
+ ]);
53
+ assert.deepEqual(by.Multi.deep_links, [
54
+ { scheme: 'http', host: 'm.example.com' }, { scheme: 'https', host: 'm.example.com' },
55
+ ]);
56
+ const node = mf.toNode(by.Link);
57
+ assert.equal(node.launch.scheme, 'https');
58
+ assert.equal(node.launch.host, 'example.com');
59
+ }));
60
+
61
+ test('same simple name in two app modules: distinct ids, primary keeps the short id', () => withTmp((d) => {
62
+ const write = (rel, text) => {
63
+ const f = path.join(d, rel);
64
+ fs.mkdirSync(path.dirname(f), { recursive: true });
65
+ fs.writeFileSync(f, text, 'utf8');
66
+ };
67
+ write('app/src/main/AndroidManifest.xml', manifest('com.example.app',
68
+ ' <activity android:name=".MainActivity" android:exported="true"><intent-filter>' +
69
+ '<action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/>' +
70
+ '</intent-filter></activity>\n <activity android:name=".Only" />'));
71
+ write('lite/src/main/AndroidManifest.xml', manifest('com.example.lite',
72
+ ' <activity android:name=".MainActivity" android:exported="true"><intent-filter>' +
73
+ '<action android:name="android.intent.action.MAIN"/><category android:name="android.intent.category.LAUNCHER"/>' +
74
+ '</intent-filter></activity>'));
75
+ write('app/src/debug/AndroidManifest.xml', manifest('com.example.app', ' <activity android:name=".Only" />'));
76
+ const [acts] = mf._collect(d, 'com.example.app', []);
77
+ const ids = acts.map((r) => [r.name, mf.toNode(r).id, mf.toNode(r).launch?.component_fqn ?? null]);
78
+ const find = (fqn) => ids.filter((x) => x[0] === fqn);
79
+ assert.deepEqual(find('com.example.app.MainActivity')[0].slice(1), ['activity:MainActivity', 'com.example.app.MainActivity']);
80
+ assert.deepEqual(find('com.example.lite.MainActivity')[0].slice(1),
81
+ ['activity:com.example.lite.MainActivity', 'com.example.lite.MainActivity']);
82
+ // Same FQN in a source-set overlay: not a collision, plain id.
83
+ assert.ok(find('com.example.app.Only').every((x) => x[1] === 'activity:Only'));
84
+ }));
@@ -0,0 +1,68 @@
1
+ // Regression: manifest discovery
2
+ // (1) honours a module's Gradle `manifest.srcFile` (legacy layout: manifest at the module root),
3
+ // Groovy and KTS forms, and is not derailed by globs like '**/*.so' that look like comments;
4
+ // (2) tests the `src` segment on the path RELATIVE to the project, so a project checked out under
5
+ // some `.../src/...` directory does not admit every manifest it contains;
6
+ // (3) never admits test / androidTest / generated source-set manifests.
7
+ import { test } from 'node:test';
8
+ import assert from 'node:assert/strict';
9
+ import * as fs from 'node:fs';
10
+ import * as os from 'node:os';
11
+ import * as path from 'node:path';
12
+ import * as mf from '../manifest.mjs';
13
+
14
+ const manifest = (pkg, names) => `<?xml version="1.0" encoding="utf-8"?>
15
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="${pkg}">
16
+ <application>
17
+ ${names.map((n) => ` <activity android:name=".${n}" />`).join('\n')}
18
+ </application>
19
+ </manifest>
20
+ `;
21
+
22
+ const put = (root, rel, text) => {
23
+ const p = path.join(root, ...rel.split('/'));
24
+ fs.mkdirSync(path.dirname(p), { recursive: true });
25
+ fs.writeFileSync(p, text, 'utf8');
26
+ };
27
+
28
+ // The project itself sits under a `src` directory, as a checkout inside a monorepo would.
29
+ const withProject = (fn) => {
30
+ const d = fs.mkdtempSync(path.join(os.tmpdir(), 'mfs-'));
31
+ const proj = path.join(d, 'src', 'proj');
32
+ try { return fn(proj); } finally { fs.rmSync(d, { recursive: true, force: true }); }
33
+ };
34
+
35
+ test('declared srcFile manifests are read; undeclared / test manifests are not', () => withProject((proj) => {
36
+ put(proj, 'legacy/build.gradle', `android {
37
+ packagingOptions { jniLibs { pickFirsts += ['**/*.so'] } }
38
+ /* manifest.srcFile 'commented/AndroidManifest.xml' */
39
+ sourceSets.main {
40
+ manifest.srcFile 'AndroidManifest.xml'
41
+ java.srcDirs = ['src']
42
+ }
43
+ }
44
+ `);
45
+ put(proj, 'legacy/AndroidManifest.xml', manifest('com.example.legacy', ['LegacyActivity']));
46
+ put(proj, 'legacy/commented/AndroidManifest.xml', manifest('com.example.legacy', ['CommentedActivity']));
47
+ put(proj, 'kts/build.gradle.kts', `android { sourceSets { getByName("main") { manifest.srcFile("manifests/AndroidManifest.xml") } } }\n`);
48
+ put(proj, 'kts/manifests/AndroidManifest.xml', manifest('com.example.kts', ['KtsActivity']));
49
+ put(proj, 'app/src/main/AndroidManifest.xml', manifest('com.example.app', ['MainActivity']));
50
+ put(proj, 'app/src/debug/AndroidManifest.xml', manifest('com.example.app', ['DebugToolActivity']));
51
+ put(proj, 'app/src/test/AndroidManifest.xml', manifest('com.example.app', ['UnitTestActivity']));
52
+ put(proj, 'app/src/androidTest/AndroidManifest.xml', manifest('com.example.app', ['InstrActivity']));
53
+ put(proj, 'stray/AndroidManifest.xml', manifest('com.example.stray', ['StrayActivity']));
54
+
55
+ const [acts] = mf._collect(proj, 'com.example.app', []);
56
+ const names = new Set(acts.map((r) => r.name.split('.').pop()));
57
+ assert.ok(names.has('LegacyActivity'), 'Groovy `manifest.srcFile` at the module root is read');
58
+ assert.ok(names.has('KtsActivity'), 'KTS `manifest.srcFile("...")` is read');
59
+ assert.ok(names.has('MainActivity') && names.has('DebugToolActivity'), 'src/<set> manifests still read');
60
+ assert.ok(!names.has('CommentedActivity'), 'a commented-out srcFile is not a declaration');
61
+ assert.ok(!names.has('StrayActivity'), 'an undeclared manifest outside src/ is not admitted, even under a `src` ancestor');
62
+ assert.ok(!names.has('UnitTestActivity') && !names.has('InstrActivity'), 'test/androidTest manifests are excluded');
63
+ }));
64
+
65
+ test('comment stripping keeps string contents', () => {
66
+ const s = mf._stripGradleComments(`a = ['**/*.so'] // gone\nb = "x//y" /* gone\n */ c`);
67
+ assert.equal(s, `a = ['**/*.so'] \nb = "x//y" \n c`);
68
+ });