@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,67 @@
1
+ // Port of test_find_package_indirect.py: find_package through version-catalog aliases and
2
+ // convention plugins.
3
+ import { test, beforeEach, afterEach } from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import * as fs from 'node:fs';
6
+ import * as os from 'node:os';
7
+ import * as path from 'node:path';
8
+ import * as rp from '../run_pipeline.mjs';
9
+
10
+ let root;
11
+ beforeEach(() => { root = fs.mkdtempSync(path.join(os.tmpdir(), 'rp-pkg-')); });
12
+ afterEach(() => { fs.rmSync(root, { recursive: true, force: true }); });
13
+ const write = (rel, text) => {
14
+ const p = path.join(root, rel);
15
+ fs.mkdirSync(path.dirname(p), { recursive: true });
16
+ fs.writeFileSync(p, text, 'utf8');
17
+ };
18
+ const pkg = () => rp.findPackage(root);
19
+
20
+ test('catalog alias with custom name', () => {
21
+ write('gradle/libs.versions.toml',
22
+ '[plugins]\nagp-application = { id = "com.android.application", version = "8" }\n' +
23
+ 'agp-library = { id = "com.android.library", version = "8" }\n');
24
+ write('app/build.gradle.kts',
25
+ 'plugins { alias(libs.plugins.agp.application) }\n' +
26
+ 'android { namespace = "sample.ns"\n defaultConfig { applicationId = "sample.app" } }\n');
27
+ write('lib/build.gradle.kts', 'plugins { alias(libs.plugins.agp.library) }\nandroid { namespace = "a.lib" }\n');
28
+ assert.equal(pkg(), 'sample.app');
29
+ });
30
+
31
+ test('precompiled convention plugin', () => {
32
+ write('buildSrc/src/main/kotlin/acme.android.application.gradle.kts', 'plugins { id("com.android.application") }\n');
33
+ write('buildSrc/src/main/kotlin/acme.android.library.gradle.kts', 'plugins { id("com.android.library") }\n');
34
+ write('app/build.gradle.kts',
35
+ 'plugins { id("acme.android.application") }\n' +
36
+ 'android { defaultConfig { applicationId = "acme.app" } }\n');
37
+ write('core/build.gradle.kts', 'plugins { id("acme.android.library") }\nandroid { namespace = "acme.core" }\n');
38
+ assert.equal(pkg(), 'acme.app');
39
+ });
40
+
41
+ test('binary convention plugin', () => {
42
+ write('build-logic/convention/src/main/kotlin/AppConventionPlugin.kt',
43
+ 'class AppConventionPlugin : Plugin<Project> {\n' +
44
+ ' override fun apply(target: Project) { with(target) {\n' +
45
+ ' pluginManager.apply("com.android.application") } } }\n');
46
+ write('build-logic/convention/build.gradle.kts',
47
+ 'gradlePlugin { plugins { register("app") {\n' +
48
+ ' id = "acme.app.convention"\n implementationClass = "AppConventionPlugin" } } }\n');
49
+ write('app/build.gradle.kts', 'plugins { id("acme.app.convention") }\nandroid { namespace = "acme.bin" }\n');
50
+ assert.equal(pkg(), 'acme.bin');
51
+ });
52
+
53
+ test('direct main app beats convention demo', () => {
54
+ write('gradle/libs.versions.toml', '[plugins]\nandroid-application = { id = "com.android.application", version = "8" }\n');
55
+ write('build-logic/src/main/kotlin/sample-app.gradle.kts', 'plugins { id("com.android.application") }\n');
56
+ write('app/build.gradle.kts', 'plugins { id("com.android.application") }\nandroid { namespace = "org.main" }\n');
57
+ write('demo/cam/build.gradle.kts',
58
+ 'plugins { id("sample-app") }\n' +
59
+ 'android { defaultConfig { applicationId = "org.main.demo" } }\n');
60
+ assert.equal(pkg(), 'org.main');
61
+ });
62
+
63
+ test('library alias is not an app', () => {
64
+ write('gradle/libs.versions.toml', '[plugins]\nandroid-library = { id = "com.android.library", version = "8" }\n');
65
+ write('lib/build.gradle.kts', 'plugins { alias(libs.plugins.android.library) }\nandroid { namespace = "x.lib" }\n');
66
+ assert.equal(pkg(), null);
67
+ });
@@ -0,0 +1,38 @@
1
+ // Port of test_forwarding_wrapper.py: a class literal in a startActivity-family argument list
2
+ // is a forwarding-wrapper launch site; non-navigation Class-taking calls are not.
3
+ import { test } from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import * as an from '../activity_nav.mjs';
6
+
7
+ const evidence = (src, needle = 'Target.class') => an._hasLaunchEvidence(src, src.indexOf(needle));
8
+
9
+ const TERNARY = ' startActivity(Cfg.get("k").equals("v") ? Target.class : Other.class, bundle);\n';
10
+
11
+ const YES = [
12
+ [' startActivity(Target.class, bundle);\n', 'startActivity(Target.class, bundle) is a launch site'],
13
+ [' startActivity(Target.class);\n', 'the no-Bundle overload is a launch site too'],
14
+ [' this.startActivity(Target.class);\n', 'a this.-qualified forwarding call still resolves its head'],
15
+ [' activity.startActivity(Target.class, bundle);\n', 'a receiver-qualified forwarding call still resolves its head'],
16
+ [' startActivityForResult(Target.class, 42);\n', 'startActivityForResult forwards as well'],
17
+ [' startActivity(new Intent(this, Target.class));\n', 'the standard Intent form still anchors'],
18
+ [' intent.setClass(ctx, Target.class);\n', 'setClass still anchors'],
19
+ [' ComponentName(ctx, Target.class);\n', 'ComponentName still anchors'],
20
+ ];
21
+ const NO = [
22
+ [' killActivity(Target.class);\n', 'killActivity (teardown) is not a launch'],
23
+ [' toObservable(Target.class);\n', 'toObservable (Rx) is not a launch'],
24
+ [' parseObject(json, Target.class);\n', 'parseObject (deserialisation) is not a launch'],
25
+ [' startService(Target.class);\n', 'startService is not an Activity launch'],
26
+ [' val x = Target.class;\n', 'a bare assignment is not a launch'],
27
+ [' Target.class.getName();\n', 'a class literal used as a RECEIVER is not a launch'],
28
+ [' log(Target.class);\n', 'an unrelated helper taking a Class is not a launch'],
29
+ ];
30
+
31
+ for (const [src, why] of YES) { test(why, () => { assert.ok(evidence(src)); }); }
32
+ for (const [src, why] of NO) { test(why, () => { assert.ok(!evidence(src)); }); }
33
+ test("a ternary's FIRST branch anchors past the nested equals(...) call", () => {
34
+ assert.ok(evidence(TERNARY, 'Target.class'));
35
+ });
36
+ test("a ternary's SECOND branch anchors too", () => {
37
+ assert.ok(evidence(TERNARY, 'Other.class'));
38
+ });
@@ -0,0 +1,85 @@
1
+ // Port of test_fragment_containment.py — fragment_nav classifies child-FM embed / navigation /
2
+ // overlay, and assemble folds the embedded child into its host.
3
+ import { test } from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import * as fs from 'node:fs';
6
+ import * as os from 'node:os';
7
+ import * as path from 'node:path';
8
+ import { buildRecords } from '../fragment_nav.mjs';
9
+ import { enrichNodesAndEdges } from '../assemble.mjs';
10
+
11
+ const HOST_JAVA = `
12
+ package com.example.app;
13
+ import androidx.fragment.app.Fragment;
14
+ public class HostFragment extends Fragment {
15
+ public View onCreateView(LayoutInflater i, ViewGroup c, Bundle s) {
16
+ binding = FragmentHostBinding.inflate(getLayoutInflater());
17
+ getChildFragmentManager().beginTransaction()
18
+ .replace(binding.childContainer.getId(), ChildRegionFragment.newInstance())
19
+ .commit();
20
+ binding.goBtn.setOnClickListener(v -> {
21
+ DetailFragment d = DetailFragment.newInstance();
22
+ requireActivity().getSupportFragmentManager().beginTransaction()
23
+ .replace(R.id.fragment_container, d)
24
+ .addToBackStack(null)
25
+ .commit();
26
+ });
27
+ binding.moreBtn.setOnClickListener(v -> {
28
+ MoreSheetFragment sheet = MoreSheetFragment.newInstance();
29
+ sheet.show(requireActivity().getSupportFragmentManager(), "more");
30
+ });
31
+ return binding.getRoot();
32
+ }
33
+ }
34
+ `;
35
+ const CHILD_JAVA = `
36
+ package com.example.app;
37
+ import androidx.fragment.app.Fragment;
38
+ public class ChildRegionFragment extends Fragment {
39
+ public static ChildRegionFragment newInstance() { return new ChildRegionFragment(); }
40
+ }
41
+ `;
42
+ const DETAIL_JAVA = `
43
+ package com.example.app;
44
+ import androidx.fragment.app.Fragment;
45
+ public class DetailFragment extends Fragment {
46
+ public static DetailFragment newInstance() { return new DetailFragment(); }
47
+ }
48
+ `;
49
+ const SHEET_JAVA = `
50
+ package com.example.app;
51
+ import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
52
+ public class MoreSheetFragment extends BottomSheetDialogFragment {
53
+ public static MoreSheetFragment newInstance() { return new MoreSheetFragment(); }
54
+ }
55
+ `;
56
+ const FIXTURES = { 'HostFragment.java': HOST_JAVA, 'ChildRegionFragment.java': CHILD_JAVA,
57
+ 'DetailFragment.java': DETAIL_JAVA, 'MoreSheetFragment.java': SHEET_JAVA };
58
+
59
+ const findEdge = (edges, s, t) => edges.find((e) => e.source.endsWith(s) && e.target.endsWith(t)) ?? null;
60
+
61
+ test('containment / overlay classification and fold', () => {
62
+ const proj = fs.mkdtempSync(path.join(os.tmpdir(), 'fcont'));
63
+ const src = path.join(proj, 'app', 'src', 'main', 'java', 'com', 'example', 'app');
64
+ fs.mkdirSync(src, { recursive: true });
65
+ for (const [name, body] of Object.entries(FIXTURES)) { fs.writeFileSync(path.join(src, name), body, 'utf8'); }
66
+ try {
67
+ const [nodes, edges] = buildRecords(proj, 'com.example.app', {});
68
+ const embed = findEdge(edges, 'HostFragment', 'ChildRegionFragment');
69
+ const nav = findEdge(edges, 'HostFragment', 'DetailFragment');
70
+ const overlay = findEdge(edges, 'HostFragment', 'MoreSheetFragment');
71
+ assert.ok(embed !== null && embed.mechanism === 'fragment-embed', "child-FM .replace -> mechanism 'fragment-embed'");
72
+ assert.ok(embed !== null && (embed.args || {}).relation === 'containment', "embed edge tagged relation:'containment'");
73
+ assert.ok(nav !== null && nav.mechanism === 'fragment-transaction', "support-FM .replace -> mechanism 'fragment-transaction'");
74
+ assert.ok(overlay !== null && overlay.mechanism === 'open-overlay', "DialogFragment .show -> mechanism 'open-overlay'");
75
+ const nodeMap = {};
76
+ for (const n of nodes) { nodeMap[n.id] = { ...n }; }
77
+ enrichNodesAndEdges(nodeMap, edges);
78
+ const child = nodeMap['fragment:ChildRegionFragment'] ?? {};
79
+ const host = nodeMap['fragment:HostFragment'] ?? {};
80
+ assert.ok(child.denominator === false && child.role === 'embedded', "embedded child folded: denominator:false + role:'embedded'");
81
+ assert.equal(child.embedded_in, 'fragment:HostFragment', 'embedded child records embedded_in host');
82
+ assert.ok((host.contains || []).includes('fragment:ChildRegionFragment'), 'host records contains:[child]');
83
+ assert.ok(host.fullscreen === true && host.role === 'screen', 'host promoted to fullscreen screen');
84
+ } finally { fs.rmSync(proj, { recursive: true, force: true }); }
85
+ });
@@ -0,0 +1,92 @@
1
+ // Port of test_fragment_helper_trigger.py: bounded caller-hop evidence for helper navigation.
2
+ import { test } from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import { _helperCallerEvidence, buildListenerSpans } from '../fragment_nav.mjs';
5
+ import { fnRanges } from '../scope_utils.mjs';
6
+
7
+ function evidence(src, needle, p = 'X.kt') {
8
+ const pos = src.indexOf(needle);
9
+ return _helperCallerEvidence(src, pos, fnRanges(src, p), buildListenerSpans(src));
10
+ }
11
+ // Python returns None for "no evidence"; accept null/undefined.
12
+ const norm = (v) => (v === undefined ? null : v);
13
+
14
+ const CASES = [
15
+ ['helper called only from lifecycle', `
16
+ class Host {
17
+ fun onCreate() { openPage() }
18
+ private fun openPage() {
19
+ fm.beginTransaction().replace(R.id.c, DetailFragment()).commit()
20
+ }
21
+ }
22
+ `, 'X.kt', { kind: 'lifecycle', reason: 'caller-lifecycle:onCreate' }],
23
+ ['helper called by one listener', `
24
+ class Host {
25
+ fun bind() { button.setOnClickListener { openPage() } }
26
+ private fun openPage() {
27
+ fm.beginTransaction().replace(R.id.c, DetailFragment()).commit()
28
+ }
29
+ }
30
+ `, 'X.kt', { kind: 'listener', trigger_id: 'button', reason: 'caller-listener' }],
31
+ ['different listeners stay ambiguous', `
32
+ class Host {
33
+ fun bind() {
34
+ first.setOnClickListener { openPage() }
35
+ second.setOnClickListener { openPage() }
36
+ }
37
+ private fun openPage() {
38
+ fm.beginTransaction().replace(R.id.c, DetailFragment()).commit()
39
+ }
40
+ }
41
+ `, 'X.kt', null],
42
+ ['lifecycle plus listener stays ambiguous', `
43
+ class Host {
44
+ fun onCreate() { openPage() }
45
+ fun bind() { button.setOnClickListener { openPage() } }
46
+ private fun openPage() {
47
+ fm.beginTransaction().replace(R.id.c, DetailFragment()).commit()
48
+ }
49
+ }
50
+ `, 'X.kt', null],
51
+ ['Java declaration and recursion are ignored', `
52
+ class Host {
53
+ void onCreate() { openPage(); }
54
+ void openPage() {
55
+ if (ready) openPage();
56
+ getSupportFragmentManager().beginTransaction()
57
+ .replace(R.id.c, new DetailFragment()).commit();
58
+ }
59
+ }
60
+ `, 'X.java', { kind: 'lifecycle', reason: 'caller-lifecycle:onCreate' }],
61
+ ['all framework lifecycle callers may agree', `
62
+ class Host {
63
+ void onResume() { routeIntent(); }
64
+ void routeIntent() {
65
+ fm.beginTransaction().replace(R.id.c, new DetailFragment()).commit();
66
+ }
67
+ void onNewIntent(Intent intent) { routeIntent(); }
68
+ }
69
+ `, 'X.java', { kind: 'lifecycle', reason: 'caller-lifecycle:onNewIntent,onResume' }],
70
+ ['back stack evidence beats lifecycle caller', `
71
+ class Host {
72
+ fun onCreate() { openPage() }
73
+ private fun openPage() {
74
+ fm.beginTransaction().replace(R.id.c, DetailFragment())
75
+ .addToBackStack(null).commit()
76
+ }
77
+ }
78
+ `, 'X.kt', null],
79
+ ['back stack helper still inherits listener control', `
80
+ class Host {
81
+ fun bind() { tile.setOnClickListener { openPage() } }
82
+ private fun openPage() {
83
+ fm.beginTransaction().replace(R.id.c, DetailFragment())
84
+ .addToBackStack(null).commit()
85
+ }
86
+ }
87
+ `, 'X.kt', { kind: 'listener', trigger_id: 'tile', reason: 'caller-listener' }],
88
+ ];
89
+
90
+ for (const [label, src, p, want] of CASES) {
91
+ test(label, () => { assert.deepEqual(norm(evidence(src, '.replace(', p)), want); });
92
+ }
@@ -0,0 +1,49 @@
1
+ // A data-state branch that a fresh install takes (no data yet) is not a `content` precondition.
2
+ // Measured (yd-weather): Splash -> SelectCity runs when no city is stored, yet its guard put
3
+ // SelectCity, WeatherPreview and its five popups behind an added city.
4
+ import { test } from 'node:test';
5
+ import assert from 'node:assert/strict';
6
+ import { StaticPrior, holdsWithoutData } from '../static_prior.mjs';
7
+ import { classify } from '../phase_planner.mjs';
8
+ import { nodeLinkGraph } from '../_graph.mjs';
9
+
10
+ const HAS = 'branch:!TextUtils.isEmpty(locationCity.cityId) || !TextUtils.isEmpty(currentCityId)';
11
+ const NONE = 'branch:!(!TextUtils.isEmpty(locationCity.cityId) || !TextUtils.isEmpty(currentCityId))';
12
+
13
+ test('holdsWithoutData reads each test with empty data', () => {
14
+ assert.equal(holdsWithoutData(HAS), false);
15
+ assert.equal(holdsWithoutData(NONE), true);
16
+ assert.equal(holdsWithoutData('branch:not (cities.size > Constants.MAX_CITY_LIST_LENGTH)'), true);
17
+ assert.equal(holdsWithoutData('branch:items.isNotEmpty()'), false);
18
+ assert.equal(holdsWithoutData('branch:items.isNullOrEmpty() && user == null'), true);
19
+ assert.equal(holdsWithoutData('branch:list.size == 0'), true);
20
+ assert.equal(holdsWithoutData('branch:songs.count > 0 or not songs.isEmpty()'), false);
21
+ });
22
+
23
+ test('anything beyond emptiness tests is left to the guard kind', () => {
24
+ assert.equal(holdsWithoutData('branch:items.isEmpty() && isPremium'), null);
25
+ assert.equal(holdsWithoutData('branch:prefs.getBoolean("seen", false)'), null);
26
+ assert.equal(holdsWithoutData(''), null);
27
+ assert.equal(holdsWithoutData('branch:(a.isEmpty()'), null);
28
+ });
29
+
30
+ test('pages behind the fresh branch plan P0_fresh, the other branch keeps content', () => {
31
+ const g = nodeLinkGraph({
32
+ directed: true, multigraph: true,
33
+ nodes: [
34
+ { id: 'compose-route:Splash', kind: 'compose-route', launch_hint: { is_launcher: true } },
35
+ { id: 'compose-route:SelectCity', kind: 'compose-route' },
36
+ { id: 'compose-route:Preview', kind: 'compose-route' },
37
+ { id: 'compose-route:Main', kind: 'compose-route' },
38
+ ],
39
+ links: [
40
+ { source: 'compose-route:Splash', target: 'compose-route:Main', guard: { kind: 'data-state', text: HAS } },
41
+ { source: 'compose-route:Splash', target: 'compose-route:SelectCity', guard: { kind: 'data-state', text: NONE } },
42
+ { source: 'compose-route:SelectCity', target: 'compose-route:Preview', args: { label: '北京市' } },
43
+ ],
44
+ }, { edges: 'links' });
45
+ const prior = new StaticPrior(g);
46
+ assert.equal(classify(prior.requiredState('compose-route:SelectCity')), 'P0_fresh');
47
+ assert.equal(classify(prior.requiredState('compose-route:Preview')), 'P0_fresh');
48
+ assert.deepEqual([...prior.requiredState('compose-route:Main')], ['content']);
49
+ });
@@ -0,0 +1,55 @@
1
+ // Unit tests for _graph.mjs: networkx MultiDiGraph semantics static_prior relies on
2
+ // (expected values taken from networkx 3.6.1 on the same inputs).
3
+ import { test } from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import { MultiDiGraph, nodeLinkGraph, dijkstraPath, NetworkXNoPath, NodeNotFound } from '../_graph.mjs';
6
+
7
+ test('multi-edge keys follow new_edge_key', () => {
8
+ const g = new MultiDiGraph();
9
+ assert.equal(g.addEdge('a', 'b'), 0);
10
+ assert.equal(g.addEdge('a', 'b'), 1);
11
+ assert.equal(g.addEdge('a', 'b', 5), 5);
12
+ assert.equal(g.addEdge('a', 'b'), 3);
13
+ assert.equal(g.outDegree('a'), 4);
14
+ assert.deepEqual(g.nodes(), ['a', 'b']);
15
+ assert.deepEqual(g.predecessors('b'), ['a']);
16
+ });
17
+
18
+ test('node_link_graph keeps node/edge order and edge keys', () => {
19
+ const g = nodeLinkGraph({ directed: true, multigraph: true,
20
+ nodes: [{ id: 'x', kind: 'k' }, { id: 'y' }],
21
+ links: [{ source: 'y', target: 'z', key: 7, w: 1 }, { source: 'x', target: 'y' }] }, { edges: 'links' });
22
+ assert.deepEqual(g.nodes(), ['x', 'y', 'z']);
23
+ assert.deepEqual(g.nodeGet('x'), { kind: 'k' });
24
+ assert.deepEqual([...g.edgeDict('y', 'z').keys()], [7]);
25
+ assert.deepEqual(g.inEdges('y').map((e) => e[0]), ['x']);
26
+ });
27
+
28
+ test('dijkstra ties resolve by push order (networkx: a->b->d, not a->c->d)', () => {
29
+ const g = new MultiDiGraph();
30
+ for (const [u, v] of [['a', 'b'], ['a', 'c'], ['b', 'd'], ['c', 'd']]) { g.addEdge(u, v); }
31
+ assert.deepEqual(dijkstraPath(g, 'a', 'd', () => 1), ['a', 'b', 'd']);
32
+ const h = new MultiDiGraph();
33
+ for (const [u, v] of [['a', 'c'], ['a', 'b'], ['b', 'd'], ['c', 'd']]) { h.addEdge(u, v); }
34
+ assert.deepEqual(dijkstraPath(h, 'a', 'd', () => 1), ['a', 'c', 'd']);
35
+ });
36
+
37
+ test('dijkstra honours weights and raises like networkx', () => {
38
+ const g = new MultiDiGraph();
39
+ g.addEdge('a', 'b', null, { guard: 1 }); g.addEdge('b', 'd'); g.addEdge('a', 'c'); g.addEdge('c', 'e'); g.addEdge('e', 'd');
40
+ const w = (u, v, kd) => ([...kd.values()].some((d) => d.guard) ? 50 : 1);
41
+ assert.deepEqual(dijkstraPath(g, 'a', 'd', w), ['a', 'c', 'e', 'd']);
42
+ g.addNode('z');
43
+ assert.throws(() => dijkstraPath(g, 'a', 'z', w), NetworkXNoPath);
44
+ assert.throws(() => dijkstraPath(g, 'q', 'z', w), NodeNotFound);
45
+ });
46
+
47
+ test('subgraph view is induced and keeps base order', () => {
48
+ const g = new MultiDiGraph();
49
+ for (const [u, v] of [['a', 'b'], ['b', 'c'], ['a', 'c'], ['c', 'd']]) { g.addEdge(u, v); }
50
+ const s = g.subgraph(['d', 'c', 'a']);
51
+ assert.deepEqual(s.nodes(), ['a', 'c', 'd']);
52
+ assert.equal(s.hasEdge('a', 'b'), false);
53
+ assert.deepEqual(s.successors('a'), ['c']);
54
+ assert.deepEqual(dijkstraPath(s, 'a', 'd', () => 1), ['a', 'c', 'd']);
55
+ });
@@ -0,0 +1,86 @@
1
+ // Port of test_guard_clause.py — guard clauses (`if (!x) { ...; return; }`) gate the code after
2
+ // them: assemble._earlyReturnConditions / _fnDeclPos / _negateCond / _LOGIN_TEST_RE.
3
+ import { test } from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import * as A from '../assemble.mjs';
6
+ import { reSearch } from '../_py.mjs';
7
+
8
+ const BAIL = `package a;
9
+ public class P {
10
+ private void openThing() {
11
+ if (!isLoggedIn()) { showLogin(); return; }
12
+ DCUniMPSDK.getInstance().openUniMP(ctx, id, cfg);
13
+ }
14
+ }
15
+ `;
16
+ const FALLTHROUGH = `package a;
17
+ public class P {
18
+ private void openThing() {
19
+ if (!isLoggedIn()) { log("not logged in"); }
20
+ DCUniMPSDK.getInstance().openUniMP(ctx, id, cfg);
21
+ }
22
+ }
23
+ `;
24
+ const NEIGHBOUR = `package a;
25
+ public class P {
26
+ private void unrelated() {
27
+ if (!hasToken()) { return; }
28
+ }
29
+ private void openThing() {
30
+ DCUniMPSDK.getInstance().openUniMP(ctx, id, cfg);
31
+ }
32
+ }
33
+ `;
34
+ const ENCLOSING = `package a;
35
+ public class P {
36
+ private void openThing() {
37
+ if (isLoggedIn()) {
38
+ DCUniMPSDK.getInstance().openUniMP(ctx, id, cfg);
39
+ return;
40
+ }
41
+ }
42
+ }
43
+ `;
44
+ const BRACELESS = `package a;
45
+ public class P {
46
+ private void openThing() {
47
+ if (!isLoggedIn()) return;
48
+ DCUniMPSDK.getInstance().openUniMP(ctx, id, cfg);
49
+ }
50
+ }
51
+ `;
52
+ const OVERLOADS = `package a;
53
+ public class P {
54
+ private void go(int a) { if (!x()) { return; } }
55
+ private void go(String a) { if (!y()) { return; } }
56
+ }
57
+ `;
58
+ const erc = (s) => A._earlyReturnConditions(s, s.indexOf('openUniMP'));
59
+
60
+ test('a bail-out before the trigger is collected, negated into a requirement', () => {
61
+ const got = erc(BAIL);
62
+ assert.deepEqual(got, ['isLoggedIn()'], 'a bail-out before the trigger is collected');
63
+ assert.ok(got.length && !got[0].startsWith('!'), 'the collected condition is negated into a requirement');
64
+ });
65
+ test('an if whose body falls through is NOT a gate', () => { assert.deepEqual(erc(FALLTHROUGH), []); });
66
+ test("a bail-out in another function is not this trigger's guard", () => { assert.deepEqual(erc(NEIGHBOUR), []); });
67
+ test('an if that contains the trigger is not treated as a bail-out', () => { assert.deepEqual(erc(ENCLOSING), []); });
68
+ test('a braceless `if (x) return;` is a gate too', () => { assert.deepEqual(erc(BRACELESS), ['isLoggedIn()']); });
69
+
70
+ test('overload refusal', () => {
71
+ assert.equal(A._fnDeclPos(OVERLOADS, 'go'), null, 'a helper name with several overloads is refused, not guessed');
72
+ assert.notEqual(A._fnDeclPos(BAIL, 'openThing'), null, 'a uniquely named helper still resolves');
73
+ });
74
+
75
+ test('the negation itself', () => {
76
+ assert.equal(A._negateCond('!loggedIn'), 'loggedIn', '`!x` unwraps rather than double-negating');
77
+ assert.equal(A._negateCond('getLoginType() != 1'), 'getLoginType() == 1', '`x != 1` becomes the equality a reader expects');
78
+ assert.equal(A._negateCond('a && b'), 'not (a && b)', 'anything else is wrapped, never mangled');
79
+ });
80
+
81
+ test('the vocabulary tier', () => {
82
+ assert.ok(reSearch(A._LOGIN_TEST_RE, 'UserUtils.getLoginType() == 1'), 'a login accessor call is recognised');
83
+ assert.ok(reSearch(A._LOGIN_TEST_RE, '!isLoggedIn()'), 'an isLoggedIn() call is recognised');
84
+ assert.ok(!reSearch(A._LOGIN_TEST_RE, 'loginDialog'), 'a bare flag whose name merely mentions login is NOT a login test');
85
+ assert.ok(!reSearch(A._LOGIN_TEST_RE, 'showLoginHint'), 'a bare showLogin flag is not a login test');
86
+ });
@@ -0,0 +1,136 @@
1
+ // Port of test_hint_language.py: nl_hints states WHICH language hints belong in, and lints a mismatch.
2
+ import { test } from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import fs from 'node:fs';
5
+ import * as os from 'node:os';
6
+ import * as path from 'node:path';
7
+ import { syncBuiltinESMExports } from 'node:module';
8
+ import * as nl from '../nl_hints.mjs';
9
+
10
+ const CJK_UTG = {
11
+ nodes: [
12
+ { id: 'r:HOME', kind: 'compose-route', label: '首页', expected: { title_any: ['首页'] } },
13
+ { id: 'r:SET', kind: 'compose-route', label: '设置', expected: { title_any: ['设置'] } },
14
+ ],
15
+ links: [{ source: 'r:HOME', target: 'r:SET', args: { label: '设置' } }],
16
+ };
17
+
18
+ const LATIN_UTG = {
19
+ nodes: [
20
+ { id: 'r:HOME', kind: 'compose-route', label: 'Home', expected: { title_any: ['Home'] } },
21
+ { id: 'r:SET', kind: 'compose-route', label: 'Settings', expected: { title_any: ['Settings'] } },
22
+ ],
23
+ links: [{ source: 'r:HOME', target: 'r:SET', args: { label: 'Settings' } }],
24
+ };
25
+
26
+ const tmp = () => fs.mkdtempSync(path.join(os.tmpdir(), 'hl_'));
27
+ const STEPS = () => [
28
+ { action: 'launch', label: null, target_id: 'r:HOME', target_kind: 'compose-route' },
29
+ { action: 'tap', label: 'Item', target_id: 'r:SET', target_kind: 'compose-route', label_source: 'code-name' },
30
+ ];
31
+
32
+ /** Capture fd-2 writes made via fs.writeSync (pyPrintErr) while fn runs. */
33
+ function captureErr(fn) {
34
+ const orig = fs.writeSync;
35
+ let buf = '';
36
+ fs.writeSync = (fd, data, ...rest) => {
37
+ if (fd === 2) { buf += String(data); return Buffer.byteLength(String(data)); }
38
+ return orig.call(fs, fd, data, ...rest);
39
+ };
40
+ syncBuiltinESMExports();
41
+ try { fn(); } finally { fs.writeSync = orig; syncBuiltinESMExports(); }
42
+ return buf;
43
+ }
44
+
45
+ function applyWith(hint, wantLang) {
46
+ const ws = tmp();
47
+ fs.writeFileSync(path.join(ws, 'click_paths.json'),
48
+ JSON.stringify({ root: 'r:HOME', paths: { 'r:SET': { clicks: 1, steps: STEPS() } } }));
49
+ fs.writeFileSync(path.join(ws, 'nl_hints_worklist.json'), JSON.stringify({ hint_language: wantLang, items: [] }));
50
+ fs.writeFileSync(path.join(ws, 'nl_hints_answers.json'),
51
+ JSON.stringify({ items: [{ key: 'Item|r:SET', nl_hint: hint, evidence: 'Screen.kt:12' }] }));
52
+ const err = captureErr(() => nl.apply(ws));
53
+ const cp = JSON.parse(fs.readFileSync(path.join(ws, 'click_paths.json'), 'utf8'));
54
+ return [err, cp.paths['r:SET'].steps.at(-1)];
55
+ }
56
+
57
+ test('language is measured from the graph', () => {
58
+ assert.equal(nl.dominantScript(CJK_UTG), 'zh', 'CJK-dominant app reports zh');
59
+ assert.equal(nl.dominantScript(LATIN_UTG), 'en', 'Latin app reports en');
60
+ assert.equal(nl.dominantScript({ nodes: [], links: [] }), 'en', 'empty graph degrades to en rather than raising');
61
+ });
62
+
63
+ test('extract publishes the language and a note', () => {
64
+ const ws = tmp();
65
+ fs.writeFileSync(path.join(ws, 'utg.json'), JSON.stringify(CJK_UTG));
66
+ fs.writeFileSync(path.join(ws, 'click_paths.json'),
67
+ JSON.stringify({ root: 'r:HOME', paths: { 'r:SET': { clicks: 1, steps: STEPS() } } }));
68
+ nl.extract(ws, tmp());
69
+ const wl = JSON.parse(fs.readFileSync(path.join(ws, 'nl_hints_worklist.json'), 'utf8'));
70
+ assert.equal(wl.hint_language, 'zh', 'worklist declares hint_language');
71
+ assert.ok((wl.hint_language_note || '').includes('Chinese'), 'worklist explains which language to write in');
72
+ });
73
+
74
+ test('mismatch is linted but still applied; symmetric', () => {
75
+ let [err, step] = applyWith('Tap the settings row in the drawer.', 'zh');
76
+ assert.ok(err.includes('LINT'), 'English hint on a zh app is linted');
77
+ assert.equal(step.nl_hint, 'Tap the settings row in the drawer.', 'linted hint is still applied (warning, not rejection)');
78
+
79
+ [err, step] = applyWith('点击抽屉中的「设置」一行。', 'zh');
80
+ assert.ok(!err.includes('LINT'), 'matching-language hint is not linted');
81
+ assert.equal(step.nl_hint, '点击抽屉中的「设置」一行。', 'matching hint applied');
82
+
83
+ [err] = applyWith('点击设置。', 'en');
84
+ assert.ok(err.includes('LINT'), 'CJK hint on an en app is linted (rule is symmetric)');
85
+ });
86
+
87
+ test('i18n: a no-gesture hint is never a language mismatch, in either form', () => {
88
+ const LANG_LINT = "not written in the app's UI language";
89
+ for (const [hint, want] of [['(no action)', 'zh'], ['(No action) the splash timer opens it', 'zh'],
90
+ ['(无需操作)', 'en'], ['(无需点击)启动后自动进入', 'en'], ['(no action)', 'en'], ['(无需操作)', 'zh']]) {
91
+ const [err, step] = applyWith(hint, want);
92
+ assert.ok(!err.includes('LINT'), `${hint} on a ${want} app: no lint (got ${JSON.stringify(err)})`);
93
+ assert.equal(step.nl_hint, hint);
94
+ }
95
+ // a gesture hint in the wrong language is still caught, in both directions
96
+ let [err] = applyWith('Tap “设置”', 'en');
97
+ assert.ok(err.includes(LANG_LINT), 'CJK-quoted tap hint on an en app');
98
+ [err] = applyWith('Tap “Settings”', 'zh');
99
+ assert.ok(err.includes(LANG_LINT), 'English tap hint on a zh app');
100
+ assert.equal(nl.hintGrammarIssue('(no action)'), null);
101
+ assert.equal(nl.hintGrammarIssue('(无需点击)'), null);
102
+ });
103
+
104
+ // The UI language is what the DEVICE renders: its locale's `values-<lang>` overlay when the app ships one,
105
+ // else the default `values` strings. Compose node labels are code names and must not decide it.
106
+ const resProject = (dirs) => {
107
+ const d = tmp();
108
+ for (const [dir, body] of Object.entries(dirs)) {
109
+ fs.mkdirSync(path.join(d, 'app', 'src', 'main', 'res', dir), { recursive: true });
110
+ fs.writeFileSync(path.join(d, 'app', 'src', 'main', 'res', dir, 'strings.xml'), `<resources>${body}</resources>`);
111
+ }
112
+ return d;
113
+ };
114
+
115
+ test('uiLanguage: Chinese default strings + values-en overlay, Chinese device -> zh; code-name labels ignored', () => {
116
+ const d = resProject({ values: '<string name="cart">购物车</string><string name="go">去逛逛</string>',
117
+ 'values-en': '<string name="cart">Cart</string><string name="go">Shop now</string>' });
118
+ try {
119
+ assert.equal(nl.uiLanguage(d, LATIN_UTG, 'zh-Hans-CN'), 'zh', 'no values-zh: the device renders the default strings');
120
+ assert.equal(nl.uiLanguage(d, LATIN_UTG, null), 'zh', 'unknown device locale: the default strings decide');
121
+ assert.equal(nl.uiLanguage(d, CJK_UTG, 'en-US'), 'en', 'an English device renders the values-en overlay');
122
+ assert.equal(nl._localeStrings(d, 'zh').cart, '购物车', 'values-en must not replace the default strings for zh');
123
+ assert.equal(nl._localeStrings(d, 'en').cart, 'Cart', 'the matching overlay wins for en');
124
+ } finally { fs.rmSync(d, { recursive: true, force: true }); }
125
+ });
126
+
127
+ test('_valuesLang reads language qualifiers only', () => {
128
+ assert.equal(nl._valuesLang('res/values'), '');
129
+ assert.equal(nl._valuesLang('res/values-night'), '');
130
+ assert.equal(nl._valuesLang('res/values-v21'), '');
131
+ assert.equal(nl._valuesLang('res/values-sw600dp'), '');
132
+ assert.equal(nl._valuesLang('res/values-en'), 'en');
133
+ assert.equal(nl._valuesLang('res/values-zh-rCN'), 'zh');
134
+ assert.equal(nl._valuesLang('res/values-b+zh+Hans'), 'zh');
135
+ assert.equal(nl._valuesLang('res/values-night-en'), 'en');
136
+ });