@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.
- package/package.json +11 -82
- package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/ets/pages/Index.ets +2 -2
- package/skills/a2h-arch-generate/scripts/module_create/har/src/main/ets/components/MainPage.ets +2 -2
- package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/ets/pages/Index.ets +2 -2
- package/skills/a2h-batch-ui-align/references/conversion-procedure.md +1 -1
- 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
- package/skills/a2h-batch-ui-align/references/step3-capture.md +3 -3
- package/skills/a2h-batch-ui-align/references/step4-prepare.md +1 -1
- package/skills/a2h-batch-ui-align/scripts/detect_paradigm.mjs +11 -6
- package/skills/a2h-batch-ui-align/scripts/export_ui_info.mjs +59 -21
- package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +3 -3
- package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +1 -1
- package/skills/a2h-batch-ui-align/scripts/static_check/core/scan.ts +1 -1
- package/skills/a2h-utg-explorer/SKILL.md +1 -1
- package/skills/a2h-utg-explorer/references/architecture.md +2 -2
- package/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +36 -11
- package/skills/a2h-utg-explorer/scripts/device_health.mjs +91 -6
- package/skills/a2h-utg-explorer/scripts/final_utg.mjs +20 -2
- package/skills/a2h-utg-explorer/scripts/hint_check.mjs +64 -8
- package/skills/a2h-utg-explorer/scripts/hint_source.mjs +119 -0
- package/skills/a2h-utg-explorer/scripts/recover.mjs +7 -1
- package/skills/a2h-utg-explorer/scripts/recover_b.mjs +8 -1
- package/skills/a2h-utg-explorer/scripts/utg_explorer/adapters.mjs +89 -7
- package/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +173 -4
- package/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +82 -14
- package/skills/a2h-utg-static/SKILL.md +1 -1
- package/skills/a2h-utg-static/references/view-interactions.md +1 -1
- package/skills/a2h-utg-static/scripts/assemble.mjs +6 -3
- package/skills/a2h-utg-static/scripts/compose_body_text.mjs +23 -5
- package/skills/a2h-utg-static/scripts/compose_overlay.mjs +29 -3
- package/skills/a2h-utg-static/scripts/compose_titles.mjs +10 -1
- package/skills/a2h-utg-static/scripts/label_resolve.mjs +51 -2
- package/skills/a2h-utg-static/scripts/static_prior.mjs +2 -1
- package/skills/a2h-utg-static/scripts/tests/_zipw.mjs +28 -0
- package/skills/a2h-utg-static/scripts/tests/probe_autoload.mjs +108 -0
- package/skills/a2h-utg-static/scripts/tests/probe_layout_fragments.mjs +90 -0
- package/skills/a2h-utg-static/scripts/tests/probe_unknown_scope.mjs +61 -0
- package/skills/a2h-utg-static/scripts/tests/regression_matrix.mjs +1261 -0
- package/skills/a2h-utg-static/scripts/tests/test_activity_alias_launcher.mjs +135 -0
- package/skills/a2h-utg-static/scripts/tests/test_activity_supertype_chain.mjs +106 -0
- package/skills/a2h-utg-static/scripts/tests/test_bottom_sheet_container.mjs +58 -0
- package/skills/a2h-utg-static/scripts/tests/test_branch_guard.mjs +19 -0
- package/skills/a2h-utg-static/scripts/tests/test_callee_string_default.mjs +30 -0
- package/skills/a2h-utg-static/scripts/tests/test_carry_answers.mjs +103 -0
- package/skills/a2h-utg-static/scripts/tests/test_chrome_tokens.mjs +60 -0
- package/skills/a2h-utg-static/scripts/tests/test_commented_out_trigger.mjs +111 -0
- package/skills/a2h-utg-static/scripts/tests/test_commit_scope.mjs +113 -0
- package/skills/a2h-utg-static/scripts/tests/test_compose_file_private_route.mjs +117 -0
- package/skills/a2h-utg-static/scripts/tests/test_compose_nested_graph.mjs +166 -0
- package/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +108 -0
- package/skills/a2h-utg-static/scripts/tests/test_compose_route_holder_collision.mjs +112 -0
- package/skills/a2h-utg-static/scripts/tests/test_compose_vm_nav.mjs +289 -0
- package/skills/a2h-utg-static/scripts/tests/test_custom_source_root.mjs +71 -0
- package/skills/a2h-utg-static/scripts/tests/test_defensive_null_guard.mjs +77 -0
- package/skills/a2h-utg-static/scripts/tests/test_dialog_orphan_entries.mjs +99 -0
- package/skills/a2h-utg-static/scripts/tests/test_dialog_page_owner.mjs +69 -0
- package/skills/a2h-utg-static/scripts/tests/test_dialogshow_builder_forms.mjs +96 -0
- package/skills/a2h-utg-static/scripts/tests/test_dialogshow_java_factory.mjs +37 -0
- package/skills/a2h-utg-static/scripts/tests/test_disabled_guard.mjs +42 -0
- package/skills/a2h-utg-static/scripts/tests/test_drawer_panel_gesture.mjs +140 -0
- package/skills/a2h-utg-static/scripts/tests/test_edge_dedupe_by_gesture.mjs +111 -0
- package/skills/a2h-utg-static/scripts/tests/test_edge_provenance_lint.mjs +70 -0
- package/skills/a2h-utg-static/scripts/tests/test_enclosing_gesture.mjs +69 -0
- package/skills/a2h-utg-static/scripts/tests/test_external_surface_roots.mjs +43 -0
- package/skills/a2h-utg-static/scripts/tests/test_find_package_indirect.mjs +67 -0
- package/skills/a2h-utg-static/scripts/tests/test_forwarding_wrapper.mjs +38 -0
- package/skills/a2h-utg-static/scripts/tests/test_fragment_containment.mjs +85 -0
- package/skills/a2h-utg-static/scripts/tests/test_fragment_helper_trigger.mjs +92 -0
- package/skills/a2h-utg-static/scripts/tests/test_fresh_branch_guard.mjs +49 -0
- package/skills/a2h-utg-static/scripts/tests/test_graph.mjs +55 -0
- package/skills/a2h-utg-static/scripts/tests/test_guard_clause.mjs +86 -0
- package/skills/a2h-utg-static/scripts/tests/test_hint_language.mjs +136 -0
- package/skills/a2h-utg-static/scripts/tests/test_host_kind_by_chain.mjs +68 -0
- package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundle_attribution.mjs +74 -0
- package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundled_pages.mjs +181 -0
- package/skills/a2h-utg-static/scripts/tests/test_hybrid_scope.mjs +293 -0
- package/skills/a2h-utg-static/scripts/tests/test_hybrid_title_renders.mjs +118 -0
- package/skills/a2h-utg-static/scripts/tests/test_i18n_term.mjs +155 -0
- package/skills/a2h-utg-static/scripts/tests/test_interaction_sites.mjs +272 -0
- package/skills/a2h-utg-static/scripts/tests/test_item_data_instance.mjs +51 -0
- package/skills/a2h-utg-static/scripts/tests/test_kotlin_fn_spans.mjs +69 -0
- package/skills/a2h-utg-static/scripts/tests/test_label_accessor_forms.mjs +187 -0
- package/skills/a2h-utg-static/scripts/tests/test_label_source.mjs +70 -0
- package/skills/a2h-utg-static/scripts/tests/test_launch_intent_guard.mjs +67 -0
- package/skills/a2h-utg-static/scripts/tests/test_layout_declared_fragment.mjs +103 -0
- package/skills/a2h-utg-static/scripts/tests/test_listener_call_forms.mjs +79 -0
- package/skills/a2h-utg-static/scripts/tests/test_listener_receiver_binding.mjs +47 -0
- package/skills/a2h-utg-static/scripts/tests/test_login_interceptor.mjs +328 -0
- package/skills/a2h-utg-static/scripts/tests/test_manifest_exported_default.mjs +40 -0
- package/skills/a2h-utg-static/scripts/tests/test_manifest_filters_modules.mjs +84 -0
- package/skills/a2h-utg-static/scripts/tests/test_manifest_srcfile.mjs +68 -0
- package/skills/a2h-utg-static/scripts/tests/test_mode_and_cb_param.mjs +172 -0
- package/skills/a2h-utg-static/scripts/tests/test_module_namespace.mjs +83 -0
- package/skills/a2h-utg-static/scripts/tests/test_module_strings.mjs +44 -0
- package/skills/a2h-utg-static/scripts/tests/test_multiple_entry_contracts.mjs +80 -0
- package/skills/a2h-utg-static/scripts/tests/test_nav_graph_xml.mjs +35 -0
- package/skills/a2h-utg-static/scripts/tests/test_nl_hint_grammar.mjs +42 -0
- package/skills/a2h-utg-static/scripts/tests/test_nl_hints_gate.mjs +85 -0
- package/skills/a2h-utg-static/scripts/tests/test_nl_hints_off_path.mjs +67 -0
- package/skills/a2h-utg-static/scripts/tests/test_node_id_collision.mjs +57 -0
- package/skills/a2h-utg-static/scripts/tests/test_non_gesture_step_flag.mjs +62 -0
- package/skills/a2h-utg-static/scripts/tests/test_out_of_scope_and_settings.mjs +72 -0
- package/skills/a2h-utg-static/scripts/tests/test_overload_and_climb.mjs +86 -0
- package/skills/a2h-utg-static/scripts/tests/test_pager_page_source.mjs +78 -0
- package/skills/a2h-utg-static/scripts/tests/test_pager_position_zero.mjs +65 -0
- package/skills/a2h-utg-static/scripts/tests/test_pager_variant_guard.mjs +172 -0
- package/skills/a2h-utg-static/scripts/tests/test_pipeline_llm_phases.mjs +107 -0
- package/skills/a2h-utg-static/scripts/tests/test_plain_dialog_nodes.mjs +167 -0
- package/skills/a2h-utg-static/scripts/tests/test_plaindialog_shared_anchor.mjs +117 -0
- package/skills/a2h-utg-static/scripts/tests/test_preference_click_nav.mjs +98 -0
- package/skills/a2h-utg-static/scripts/tests/test_preference_host_binding.mjs +87 -0
- package/skills/a2h-utg-static/scripts/tests/test_preference_nesting.mjs +183 -0
- package/skills/a2h-utg-static/scripts/tests/test_preference_widgets.mjs +48 -0
- package/skills/a2h-utg-static/scripts/tests/test_read_text_crlf.mjs +41 -0
- package/skills/a2h-utg-static/scripts/tests/test_resolver_tier_parity.mjs +126 -0
- package/skills/a2h-utg-static/scripts/tests/test_result_launcher.mjs +142 -0
- package/skills/a2h-utg-static/scripts/tests/test_review_fixes.mjs +135 -0
- package/skills/a2h-utg-static/scripts/tests/test_route_token_words.mjs +66 -0
- package/skills/a2h-utg-static/scripts/tests/test_same_name_decl_scope.mjs +236 -0
- package/skills/a2h-utg-static/scripts/tests/test_scope_utils.mjs +85 -0
- package/skills/a2h-utg-static/scripts/tests/test_sealed_dialog_state.mjs +148 -0
- package/skills/a2h-utg-static/scripts/tests/test_shared_overlay_split.mjs +63 -0
- package/skills/a2h-utg-static/scripts/tests/test_slug_parity.mjs +58 -0
- package/skills/a2h-utg-static/scripts/tests/test_starter_node_id.mjs +41 -0
- package/skills/a2h-utg-static/scripts/tests/test_state_guard_arity.mjs +109 -0
- package/skills/a2h-utg-static/scripts/tests/test_state_guard_commented_candidates.mjs +68 -0
- package/skills/a2h-utg-static/scripts/tests/test_state_guard_model_gates.mjs +127 -0
- package/skills/a2h-utg-static/scripts/tests/test_state_specific_hop.mjs +130 -0
- package/skills/a2h-utg-static/scripts/tests/test_synthetic_label_identity.mjs +51 -0
- package/skills/a2h-utg-static/scripts/tests/test_template_method_layout.mjs +81 -0
- package/skills/a2h-utg-static/scripts/tests/test_template_title.mjs +61 -0
- package/skills/a2h-utg-static/scripts/tests/test_trigger_id_spelling.mjs +68 -0
- package/skills/a2h-utg-static/scripts/tests/test_ui_elements_action_override.mjs +91 -0
- package/skills/a2h-utg-static/scripts/tests/test_ui_elements_flow_filter.mjs +110 -0
- package/skills/a2h-utg-static/scripts/tests/test_ui_elements_nl_hint_key.mjs +89 -0
- package/skills/a2h-utg-static/scripts/tests/test_uiless_host_fold.mjs +98 -0
- package/skills/a2h-utg-static/scripts/tests/test_uniapp_data_table.mjs +340 -0
- package/skills/a2h-utg-static/scripts/tests/test_uniapp_relative_url.mjs +125 -0
- package/skills/a2h-utg-static/scripts/tests/test_uniapp_source.mjs +231 -0
- package/skills/a2h-utg-static/scripts/tests/test_view_click_refs.mjs +104 -0
- package/skills/a2h-utg-static/scripts/tests/test_view_id_label.mjs +69 -0
- package/skills/a2h-utg-static/scripts/tests/test_view_interactions.mjs +346 -0
- package/skills/a2h-utg-static/scripts/tests/test_viewpage_nav.mjs +340 -0
- package/skills/a2h-utg-static/scripts/tests/test_vm_nav_helper_navigate.mjs +98 -0
- package/skills/a2h-utg-static/scripts/tests/test_widget_class_scope.mjs +92 -0
- package/skills/a2h-utg-static/scripts/tests/test_window_nav_kotlin.mjs +158 -0
- package/skills/a2h-utg-static/scripts/tests/test_worklist_parts.mjs +65 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// Port of test_commit_scope.py: fragment_nav.classifyCommit — lifecycle vs dispatched vs unknown.
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { classifyCommit } from '../fragment_nav.mjs';
|
|
5
|
+
import { fnRanges } from '../scope_utils.mjs';
|
|
6
|
+
|
|
7
|
+
function cls(src, needle, p = 'X.kt') {
|
|
8
|
+
const pos = src.indexOf(needle);
|
|
9
|
+
assert.ok(pos >= 0, `needle ${needle}`);
|
|
10
|
+
return classifyCommit(src, pos, fnRanges(src, p));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const CASES = [
|
|
14
|
+
['onCreate commit is lifecycle', `
|
|
15
|
+
class Host : AppCompatActivity() {
|
|
16
|
+
override fun onCreate(b: Bundle?) {
|
|
17
|
+
supportFragmentManager.beginTransaction()
|
|
18
|
+
.replace(R.id.container, HomeFragment())
|
|
19
|
+
.commit()
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
`, '.replace(', 'X.kt', 0, 'lifecycle'],
|
|
23
|
+
['onViewCreated commit is lifecycle', `
|
|
24
|
+
class Host : Fragment() {
|
|
25
|
+
override fun onViewCreated(v: View, b: Bundle?) {
|
|
26
|
+
childFragmentManager.beginTransaction().add(R.id.c, ListFragment()).commit()
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
`, '.add(', 'X.kt', 0, 'lifecycle'],
|
|
30
|
+
['initViews commit is lifecycle', `
|
|
31
|
+
class Host : AppCompatActivity() {
|
|
32
|
+
private fun initViews() {
|
|
33
|
+
supportFragmentManager.beginTransaction().replace(R.id.c, MainFragment()).commit()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
`, '.replace(', 'X.kt', 0, 'lifecycle'],
|
|
37
|
+
['addToBackStack beats any fn name', `
|
|
38
|
+
class Host : AppCompatActivity() {
|
|
39
|
+
fun setManagementFragmentVisibility(visible: Boolean) {
|
|
40
|
+
supportFragmentManager.beginTransaction()
|
|
41
|
+
.add(R.id.fragment, PushedManagementFragment.getInstance(), TAG)
|
|
42
|
+
.addToBackStack(null)
|
|
43
|
+
.commit()
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
`, '.add(', 'X.kt', 0, 'dispatched'],
|
|
47
|
+
['addToBackStack wins inside onCreate', `
|
|
48
|
+
class Host : AppCompatActivity() {
|
|
49
|
+
override fun onCreate(b: Bundle?) {
|
|
50
|
+
supportFragmentManager.beginTransaction()
|
|
51
|
+
.replace(R.id.c, DetailFragment()).addToBackStack(null).commit()
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
`, '.replace(', 'X.kt', 0, 'dispatched'],
|
|
55
|
+
['onFabClick commit is dispatched', `
|
|
56
|
+
class Host extends Fragment {
|
|
57
|
+
private void onFabClick(View v) {
|
|
58
|
+
getParentFragmentManager().beginTransaction().replace(R.id.c, new AddFragment()).commit();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
`, '.replace(', 'X.java', 0, 'dispatched'],
|
|
62
|
+
['onMenuItemClick commit is dispatched', `
|
|
63
|
+
class Host extends Fragment {
|
|
64
|
+
public boolean onMenuItemClick(MenuItem item) {
|
|
65
|
+
getChildFragmentManager().beginTransaction().add(R.id.c, new FilterFragment()).commit();
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
`, '.add(', 'X.java', 0, 'dispatched'],
|
|
70
|
+
['doInBackground commit is dispatched', `
|
|
71
|
+
class Host extends AppCompatActivity {
|
|
72
|
+
protected Void doInBackground(Void... p) {
|
|
73
|
+
getSupportFragmentManager().beginTransaction().replace(R.id.c, new X()).commit();
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
`, '.replace(', 'X.java', 0, 'dispatched'],
|
|
78
|
+
['reason names addToBackStack', `
|
|
79
|
+
class Host : AppCompatActivity() {
|
|
80
|
+
fun show() {
|
|
81
|
+
supportFragmentManager.beginTransaction().replace(R.id.c, A()).addToBackStack(null).commit()
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
`, '.replace(', 'X.kt', 1, 'addToBackStack'],
|
|
85
|
+
['reason names the lifecycle fn', `
|
|
86
|
+
class Host : AppCompatActivity() {
|
|
87
|
+
override fun onCreate(b: Bundle?) {
|
|
88
|
+
supportFragmentManager.beginTransaction().replace(R.id.c, A()).commit()
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
`, '.replace(', 'X.kt', 1, 'lifecycle-fn:onCreate'],
|
|
92
|
+
['top-level site is unknown', 'val t = fm.beginTransaction().replace(R.id.c, A()).commit()\n',
|
|
93
|
+
'.replace(', 'X.kt', 0, 'unknown'],
|
|
94
|
+
];
|
|
95
|
+
|
|
96
|
+
for (const [label, src, needle, p, idx, want] of CASES) {
|
|
97
|
+
test(label, () => { assert.equal(cls(src, needle, p)[idx], want); });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const TWO = `
|
|
101
|
+
class Host : AppCompatActivity() {
|
|
102
|
+
override fun onCreate(b: Bundle?) {
|
|
103
|
+
supportFragmentManager.beginTransaction().replace(R.id.c, HomeFragment()).commit()
|
|
104
|
+
supportFragmentManager.beginTransaction().replace(R.id.c, SubFragment()).addToBackStack(null).commit()
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
`;
|
|
108
|
+
test('first commit not tainted by later addToBackStack', () => {
|
|
109
|
+
assert.equal(cls(TWO, '.replace(R.id.c, HomeFragment())')[0], 'lifecycle');
|
|
110
|
+
});
|
|
111
|
+
test('second commit keeps its own addToBackStack', () => {
|
|
112
|
+
assert.equal(cls(TWO, '.replace(R.id.c, SubFragment())')[0], 'dispatched');
|
|
113
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// compose_nav: routes written as FILE-PRIVATE constants. Feature nav files each declare the same
|
|
2
|
+
// `private const val ROUTE`, so constants resolve per file; `navigation(startDestination = ROUTE,
|
|
3
|
+
// route = ROUTE_GRAPH)` graphs, `NavController.navigateToX()` wrappers and callbacks handed to a
|
|
4
|
+
// `NavGraphBuilder` extension at the NavHost all resolve to the right route.
|
|
5
|
+
import { test } from 'node:test';
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import * as fs from 'node:fs';
|
|
8
|
+
import * as os from 'node:os';
|
|
9
|
+
import * as path from 'node:path';
|
|
10
|
+
import { spawnSync } from 'node:child_process';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
|
|
13
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const NAV = path.join(HERE, '..', 'compose_nav.mjs');
|
|
15
|
+
|
|
16
|
+
const FEATURE = (pkg, name, route, extra = '') => `package app.${pkg}.nav
|
|
17
|
+
|
|
18
|
+
import androidx.navigation.NavController
|
|
19
|
+
import androidx.navigation.NavGraphBuilder
|
|
20
|
+
import androidx.navigation.compose.composable
|
|
21
|
+
import androidx.navigation.navigation
|
|
22
|
+
|
|
23
|
+
private const val ROUTE = "${route}"
|
|
24
|
+
private const val ROUTE_GRAPH = "${route}_graph"
|
|
25
|
+
|
|
26
|
+
fun NavController.navigateTo${name}Graph() {
|
|
27
|
+
this.navigate(ROUTE_GRAPH) { launchSingleTop = true }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
fun NavGraphBuilder.${pkg}Graph(onBackClick: () -> Unit, onOpenClick: () -> Unit, nestGraph: NavGraphBuilder.() -> Unit) {
|
|
31
|
+
navigation(startDestination = ROUTE, route = ROUTE_GRAPH) {
|
|
32
|
+
composable(route = ROUTE) {
|
|
33
|
+
${name}Route(onBackClick = onBackClick, onOpenClick = onOpenClick)
|
|
34
|
+
}
|
|
35
|
+
nestGraph()
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
${extra}`;
|
|
39
|
+
|
|
40
|
+
const SHOW = `package app.show.nav
|
|
41
|
+
|
|
42
|
+
private const val base = "item_show"
|
|
43
|
+
private const val ROUTE = "$base/{$idArg}"
|
|
44
|
+
internal const val idArg = "id"
|
|
45
|
+
|
|
46
|
+
fun NavController.navigateToItemShow(id: Int) { this.navigate("$base/$id") }
|
|
47
|
+
|
|
48
|
+
fun NavGraphBuilder.itemShowScreen(onBackClick: () -> Unit) {
|
|
49
|
+
composable(route = ROUTE, arguments = listOf(navArgument(idArg) { type = NavType.StringType })) {
|
|
50
|
+
ItemShowRoute(onBackClick = onBackClick)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
const HOST = `package app.route
|
|
56
|
+
|
|
57
|
+
@Composable
|
|
58
|
+
fun AppNavHost(navController: NavHostController) {
|
|
59
|
+
NavHost(navController = navController, startDestination = ROUTE_HOME_GRAPH) {
|
|
60
|
+
homeGraph(onBackClick = navController::navigateUp, onOpenClick = navController::navigateToListGraph, nestGraph = {
|
|
61
|
+
listGraph(onBackClick = navController::navigateUp, onOpenClick = { navController.navigateToItemShow(1) }) {
|
|
62
|
+
itemShowScreen(onBackClick = navController::navigateUp)
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
|
|
69
|
+
function project() {
|
|
70
|
+
const td = fs.mkdtempSync(path.join(os.tmpdir(), 'cn-private-'));
|
|
71
|
+
const files = {
|
|
72
|
+
'home/nav/HomeNav.kt': FEATURE('home', 'Home', 'home').replace('private const val ROUTE_GRAPH', 'const val ROUTE_HOME_GRAPH = "home_graph"\nprivate const val ROUTE_GRAPH'),
|
|
73
|
+
'list/nav/ListNav.kt': FEATURE('list', 'List', 'list_index'),
|
|
74
|
+
'show/nav/ShowNav.kt': SHOW,
|
|
75
|
+
'route/AppNavHost.kt': HOST,
|
|
76
|
+
};
|
|
77
|
+
for (const [rel, text] of Object.entries(files)) {
|
|
78
|
+
const p = path.join(td, 'app', 'src', 'main', 'java', 'app', rel);
|
|
79
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
80
|
+
fs.writeFileSync(p, text);
|
|
81
|
+
}
|
|
82
|
+
return td;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
test('a file-private ROUTE constant resolves in its own file, never across files', async () => {
|
|
86
|
+
const { buildRouteConstIndex, constResolver, routeKeyC } = await import('../compose_nav.mjs');
|
|
87
|
+
assert.equal(typeof routeKeyC, 'function', 'compose_nav resolves route constants');
|
|
88
|
+
const idx = buildRouteConstIndex([['a/A.kt', 'private const val ROUTE = "alpha"\n'], ['b/B.kt', 'private const val ROUTE = "beta"\n']]);
|
|
89
|
+
assert.equal(routeKeyC('route = ROUTE', new Set(['X']), constResolver(idx, 'a/A.kt')), 'alpha');
|
|
90
|
+
assert.equal(routeKeyC('ROUTE', new Set(['X']), constResolver(idx, 'b/B.kt')), 'beta');
|
|
91
|
+
assert.equal(routeKeyC('ROUTE', new Set(['X']), constResolver(idx, 'c/C.kt')), null, 'a private const is not visible elsewhere');
|
|
92
|
+
const show = buildRouteConstIndex([['s/S.kt', SHOW]]);
|
|
93
|
+
assert.equal(routeKeyC('route = ROUTE, arguments = listOf(navArgument(idArg))', new Set(['X']), constResolver(show, 's/S.kt')),
|
|
94
|
+
'item_show', 'a `$base/{$id}` template keeps its static prefix');
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('compose_nav on a project of file-private route constants', () => {
|
|
98
|
+
const td = project();
|
|
99
|
+
try {
|
|
100
|
+
const r = spawnSync(process.execPath, [NAV, td], { encoding: 'utf8' });
|
|
101
|
+
assert.equal(r.status, 0, r.stderr);
|
|
102
|
+
const recs = r.stdout.trim().split('\n').filter(Boolean).map((l) => JSON.parse(l));
|
|
103
|
+
const routes = new Map(recs.filter((x) => x.type === 'route').map((x) => [x.route_key, x.screen]));
|
|
104
|
+
assert.deepEqual([...routes.keys()].sort(), ['home', 'item_show', 'list_index']);
|
|
105
|
+
const start = recs.filter((x) => x.type === 'start_destination');
|
|
106
|
+
assert.ok(start.length && start.every((s) => s.screen), 'every start destination (graph or page) resolves');
|
|
107
|
+
const host = start.find((s) => s.literal === 'ROUTE_HOME_GRAPH');
|
|
108
|
+
assert.equal(host?.screen, 'HomeRoute', 'the NavHost start graph resolves to its start page');
|
|
109
|
+
const edges = recs.filter((x) => x.type === 'edge');
|
|
110
|
+
const cb = (from, to) => edges.some((e) => e.host_route === from && e.route_key === to);
|
|
111
|
+
assert.ok(cb('home', 'list_index'), 'a `::navigateToListGraph` callback runs on the home route and lands on the graph start');
|
|
112
|
+
assert.ok(cb('list_index', 'item_show'), 'a lambda callback `{ nav.navigateToItemShow(1) }` is attributed to the list route');
|
|
113
|
+
assert.ok(!edges.some((e) => e.host_route === 'home' && e.route_key === 'item_show'),
|
|
114
|
+
'a callback of a NESTED builder call is not credited to the outer builder');
|
|
115
|
+
assert.equal(recs.filter((x) => x.type === 'unresolved').length, 0);
|
|
116
|
+
} finally { fs.rmSync(td, { recursive: true, force: true }); }
|
|
117
|
+
});
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// Compose shapes that leaked unknown endpoints or skipped titles (measured on the open-source corpus
|
|
2
|
+
// 2026-10): nested `navigation<G>(startDestination = …)` graphs used as navigate targets, condition
|
|
3
|
+
// gates folded into a layout-shell dialog that emits no node, and class-labelled pages (Voyager
|
|
4
|
+
// `Screen.Content()`, an Activity's `setContent {}`) whose header the title walk never reached.
|
|
5
|
+
import { test } from 'node:test';
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import * as fs from 'node:fs';
|
|
8
|
+
import * as os from 'node:os';
|
|
9
|
+
import * as path from 'node:path';
|
|
10
|
+
import { spawnSync } from 'node:child_process';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
import { enclosingNavGraph, graphStartMap, inNestedNavGraph } from '../compose_nav.mjs';
|
|
13
|
+
import { classEntryBodies } from '../compose_titles.mjs';
|
|
14
|
+
|
|
15
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
const SRC = 'app/src/main/java/com/ex';
|
|
17
|
+
|
|
18
|
+
function project(files) {
|
|
19
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'utg-graph-'));
|
|
20
|
+
for (const [rel, text] of Object.entries(files)) {
|
|
21
|
+
const p = path.join(root, rel);
|
|
22
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
23
|
+
fs.writeFileSync(p, text);
|
|
24
|
+
}
|
|
25
|
+
return root;
|
|
26
|
+
}
|
|
27
|
+
const run = (script, args) => {
|
|
28
|
+
const r = spawnSync(process.execPath, [path.join(HERE, '..', script), ...args], { encoding: 'utf8' });
|
|
29
|
+
assert.equal(r.status, 0, r.stderr);
|
|
30
|
+
return r;
|
|
31
|
+
};
|
|
32
|
+
const jsonl = (s) => s.trim().split(/\r?\n/).filter(Boolean).map((l) => JSON.parse(l));
|
|
33
|
+
|
|
34
|
+
const AUTH_NAV = `package com.ex
|
|
35
|
+
@Serializable data object AuthGraphRoute
|
|
36
|
+
@Serializable data object LandingRoute
|
|
37
|
+
@Serializable data object LoginRoute
|
|
38
|
+
fun NavGraphBuilder.authGraph(navController: NavHostController) {
|
|
39
|
+
navigation<AuthGraphRoute>(
|
|
40
|
+
startDestination = LandingRoute,
|
|
41
|
+
) {
|
|
42
|
+
composable<LandingRoute> { LandingScreen(onLogin = { navController.navigate(LoginRoute) }) }
|
|
43
|
+
composable<LoginRoute> { LoginScreen() }
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
fun NavController.navigateToAuthGraph() { navigate(AuthGraphRoute) }
|
|
47
|
+
`;
|
|
48
|
+
const ROOT_NAV = `package com.ex
|
|
49
|
+
@Serializable data object HomeRoute
|
|
50
|
+
@Serializable data object OuterGraph
|
|
51
|
+
fun NavGraphBuilder.outerGraph() {
|
|
52
|
+
navigation(startDestination = AuthGraphRoute, route = "outer") { }
|
|
53
|
+
}
|
|
54
|
+
@Composable fun HomeScreen(navController: NavController) {
|
|
55
|
+
Button(onClick = { navController.navigate(AuthGraphRoute) }) { Text("Sign in") }
|
|
56
|
+
Button(onClick = { navController.navigate("outer") }) { Text("Outer") }
|
|
57
|
+
}
|
|
58
|
+
fun NavGraphBuilder.home(navController: NavController) { composable<HomeRoute> { HomeScreen(navController) } }
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
test('nested graph: the startDestination knows its graph, navigate(graph) lands on its start route', () => {
|
|
62
|
+
const at = AUTH_NAV.indexOf('startDestination');
|
|
63
|
+
assert.equal(inNestedNavGraph(AUTH_NAV, at), true);
|
|
64
|
+
assert.equal(enclosingNavGraph(AUTH_NAV, at, new Set()), 'AuthGraphRoute');
|
|
65
|
+
const at2 = ROOT_NAV.indexOf('startDestination');
|
|
66
|
+
assert.equal(enclosingNavGraph(ROOT_NAV, at2, new Set()), 'outer', 'untyped graph reads its route = arg');
|
|
67
|
+
assert.equal(inNestedNavGraph('NavHost(navController, startDestination = HomeRoute) { }', 30), false,
|
|
68
|
+
'a NavHost start destination is not a nested graph');
|
|
69
|
+
|
|
70
|
+
const routes = new Map([['LandingRoute', {}], ['HomeRoute', {}]]);
|
|
71
|
+
const g = graphStartMap([
|
|
72
|
+
{ graph_key: 'AuthGraphRoute', route_key: 'LandingRoute' },
|
|
73
|
+
{ graph_key: 'outer', route_key: 'AuthGraphRoute' },
|
|
74
|
+
], routes);
|
|
75
|
+
assert.equal(g.get('AuthGraphRoute'), 'LandingRoute');
|
|
76
|
+
assert.equal(g.get('outer'), 'LandingRoute', 'a graph starting on a graph is followed transitively');
|
|
77
|
+
|
|
78
|
+
const root = project({ [`${SRC}/AuthNav.kt`]: AUTH_NAV, [`${SRC}/RootNav.kt`]: ROOT_NAV });
|
|
79
|
+
const recs = jsonl(run('compose_nav.mjs', [root]).stdout);
|
|
80
|
+
const toLanding = recs.filter((x) => x.type === 'edge' && x.route_key === 'LandingRoute');
|
|
81
|
+
assert.deepEqual(toLanding.map((e) => e.args.via_graph).sort(), ['AuthGraphRoute', 'outer'],
|
|
82
|
+
JSON.stringify(recs));
|
|
83
|
+
assert.equal(recs.filter((x) => x.type === 'unresolved' && /AuthGraphRoute|outer/.test(x.token)).length, 0);
|
|
84
|
+
const sd = recs.filter((x) => x.type === 'start_destination' && x.nested_graph);
|
|
85
|
+
assert.equal(sd.length, 2);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('compose_overlay: a nested-graph or ownerless startDestination emits no screen:<fn> endpoint', () => {
|
|
89
|
+
const root = project({ [`${SRC}/AuthNav.kt`]: AUTH_NAV, [`${SRC}/RootNav.kt`]: ROOT_NAV });
|
|
90
|
+
const r = run('compose_overlay.mjs', [root]);
|
|
91
|
+
const fake = jsonl(r.stdout).filter((x) => x.type === 'edge' && String(x.source).startsWith('screen:'));
|
|
92
|
+
assert.deepEqual(fake, []);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const DIALOGS = `package com.ex
|
|
96
|
+
@Composable fun SelectionDialog(title: String, onDismiss: () -> Unit, content: @Composable () -> Unit) {
|
|
97
|
+
Dialog(onDismissRequest = onDismiss) { Column { Text(title); content() } }
|
|
98
|
+
}
|
|
99
|
+
@Composable fun LockOrLogoutDialog(onDismiss: () -> Unit) {
|
|
100
|
+
SelectionDialog(title = "Lock or log out", onDismiss = onDismiss) { Text("Lock") }
|
|
101
|
+
}
|
|
102
|
+
@Composable fun HomeScreen() {
|
|
103
|
+
var show by remember { mutableStateOf(false) }
|
|
104
|
+
Button(onClick = { show = true }) { Text("Account") }
|
|
105
|
+
if (show) { LockOrLogoutDialog(onDismiss = { show = false }) }
|
|
106
|
+
}
|
|
107
|
+
`;
|
|
108
|
+
|
|
109
|
+
test('a gate whose delegate is a layout shell keeps its own node; no edge targets the shell', () => {
|
|
110
|
+
const root = project({
|
|
111
|
+
[`${SRC}/Dialogs.kt`]: DIALOGS,
|
|
112
|
+
[`${SRC}/Nav.kt`]: 'package com.ex\n@Serializable data object HomeRoute\n' +
|
|
113
|
+
'fun NavGraphBuilder.home() { composable<HomeRoute> { HomeScreen() } }\n',
|
|
114
|
+
});
|
|
115
|
+
const r = run('compose_overlay.mjs', [root]);
|
|
116
|
+
const recs = jsonl(r.stdout);
|
|
117
|
+
const ids = new Set(recs.filter((x) => x.type === 'node').map((x) => x.id));
|
|
118
|
+
const dangling = recs.filter((x) => x.type === 'edge' && String(x.target).startsWith('overlay:') && !ids.has(x.target));
|
|
119
|
+
assert.deepEqual(dangling, [], r.stderr);
|
|
120
|
+
assert.ok(ids.has('overlay:LockOrLogoutDialog'), r.stderr);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('class-labelled pages: Voyager Content() and an Activity setContent {} are the title walk entry', () => {
|
|
124
|
+
const VOYAGER = `package com.ex
|
|
125
|
+
class CategoryScreen : Screen {
|
|
126
|
+
@Composable
|
|
127
|
+
override fun Content() {
|
|
128
|
+
Scaffold(topBar = { AppBar(title = "Categories", navigateUp = { }) }) { }
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
`;
|
|
132
|
+
const ACTIVITY = `package com.ex
|
|
133
|
+
class LicenseActivity : BaseActivity() {
|
|
134
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
|
135
|
+
super.onCreate(savedInstanceState)
|
|
136
|
+
setContent { LicenseScreen(title = "Licenses", onBack = { finish() }) }
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
`;
|
|
140
|
+
const ft = new Map([['/p/CategoryScreen.kt', VOYAGER], ['/p/LicenseActivity.kt', ACTIVITY]]);
|
|
141
|
+
const [cat] = classEntryBodies('CategoryScreen', 'app/CategoryScreen.kt:2', ft);
|
|
142
|
+
assert.ok(cat && cat[3].includes('AppBar(title = "Categories"'), 'Content() body found');
|
|
143
|
+
const [lic] = classEntryBodies('LicenseActivity', 'app/src/main/AndroidManifest.xml', ft);
|
|
144
|
+
assert.ok(lic && lic[3].includes('LicenseScreen('), 'setContent lambda found');
|
|
145
|
+
assert.deepEqual(classEntryBodies('Missing', null, ft), []);
|
|
146
|
+
|
|
147
|
+
const HEADERS = `package com.ex
|
|
148
|
+
@Composable fun AppBar(title: String, navigateUp: () -> Unit) { TopAppBar(title = { Text(title) }) }
|
|
149
|
+
@Composable fun LicenseScreen(title: String, onBack: () -> Unit) { AppBar(title = title, navigateUp = onBack) }
|
|
150
|
+
`;
|
|
151
|
+
const root = project({
|
|
152
|
+
[`${SRC}/CategoryScreen.kt`]: VOYAGER, [`${SRC}/LicenseActivity.kt`]: ACTIVITY, [`${SRC}/Headers.kt`]: HEADERS,
|
|
153
|
+
});
|
|
154
|
+
const ws = fs.mkdtempSync(path.join(os.tmpdir(), 'utg-graph-ws-'));
|
|
155
|
+
fs.writeFileSync(path.join(ws, 'nodes.jsonl'), [
|
|
156
|
+
{ id: 'voyager-screen:CategoryScreen', kind: 'voyager-screen', label: 'CategoryScreen',
|
|
157
|
+
declared_at: `${SRC}/CategoryScreen.kt:2` },
|
|
158
|
+
{ id: 'activity:LicenseActivity', kind: 'activity', label: 'LicenseActivity',
|
|
159
|
+
declared_at: 'app/src/main/AndroidManifest.xml' },
|
|
160
|
+
].map((n) => JSON.stringify(n)).join('\n') + '\n');
|
|
161
|
+
const r = run('compose_titles.mjs', [ws, '--project', root, '--append']);
|
|
162
|
+
const byId = new Map(jsonl(fs.readFileSync(path.join(ws, 'nodes.jsonl'), 'utf8')).map((n) => [n.id, n]));
|
|
163
|
+
assert.deepEqual(byId.get('voyager-screen:CategoryScreen').identity_text, ['Categories'], r.stderr);
|
|
164
|
+
assert.deepEqual(byId.get('activity:LicenseActivity').identity_text, ['Licenses'], r.stderr);
|
|
165
|
+
assert.doesNotMatch(r.stderr, /SANITY/);
|
|
166
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// Shapes that left coolmall's Compose pages without an anchor (measured 2026-11, 51 unmapped dynamic
|
|
2
|
+
// nodes): strings.xml values kept raw (`\n`, `&`), placeholder / *Text params and `@StringRes Int`
|
|
3
|
+
// arguments never read, and `*Modal` bottom sheets never recognised as overlays.
|
|
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 { spawnSync } from 'node:child_process';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { decodeAndroidString } from '../label_resolve.mjs';
|
|
12
|
+
import { bodyTexts } from '../compose_body_text.mjs';
|
|
13
|
+
import { _resolveTitle } from '../compose_titles.mjs';
|
|
14
|
+
|
|
15
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
16
|
+
|
|
17
|
+
test('decodeAndroidString renders what the device shows', () => {
|
|
18
|
+
assert.equal(decodeAndroidString(String.raw`你好,\n欢迎登录青商城`), '你好,\n欢迎登录青商城');
|
|
19
|
+
assert.equal(decodeAndroidString('© 2025 Joker.X & Contributors'), '© 2025 Joker.X & Contributors');
|
|
20
|
+
assert.equal(decodeAndroidString(String.raw`It\'s \"ok\" 中`), 'It\'s "ok" 中');
|
|
21
|
+
assert.equal(decodeAndroidString(' a \n b '), 'a b', 'unquoted whitespace collapses');
|
|
22
|
+
assert.equal(decodeAndroidString('" a b "'), ' a b ', 'a quoted value keeps its whitespace');
|
|
23
|
+
assert.equal(decodeAndroidString('<b>粗体</b>与<![CDATA[原文]]>'), '粗体与原文');
|
|
24
|
+
assert.equal(decodeAndroidString('中文'), '中文');
|
|
25
|
+
// CDATA content is literal: neither a tag nor an entity inside it
|
|
26
|
+
assert.equal(decodeAndroidString('<![CDATA[满100<减20>起]]>'), '满100<减20>起');
|
|
27
|
+
assert.equal(decodeAndroidString('<![CDATA[A & B]]>'), 'A & B');
|
|
28
|
+
// aapt drops every unescaped quote, not only a wrapping pair; an escaped backslash is literal
|
|
29
|
+
assert.equal(decodeAndroidString('Tap "OK" now'), 'Tap OK now');
|
|
30
|
+
assert.equal(decodeAndroidString('"C:\\\\"'), 'C:' + '\\');
|
|
31
|
+
assert.equal(decodeAndroidString('a " b " c'), 'a b c');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const PAGE = `@Composable
|
|
35
|
+
fun LoginScreen() {
|
|
36
|
+
Field(placeholder = stringResource(id = R.string.password_hint))
|
|
37
|
+
Link(messageText = stringResource(id = R.string.go_register), actionText = stringResource(R.string.forgot))
|
|
38
|
+
CenterTopAppBar(title = R.string.cart)
|
|
39
|
+
Empty(message = R.string.empty_cart, subtitle = R.string.empty_sub)
|
|
40
|
+
val t by animateFloatAsState(1f, label = "fade")
|
|
41
|
+
Icon(painter = painterResource(R.string.cart.hashCode()))
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
test('bodyTexts reads placeholder / *Text params and @StringRes Int arguments', () => {
|
|
46
|
+
const strings = { password_hint: '请输入密码', go_register: '去注册', forgot: '忘记密码', cart: '购物车',
|
|
47
|
+
empty_cart: '购物车是空的', empty_sub: '快去添加商品吧' };
|
|
48
|
+
const file = '/p/LoginScreen.kt';
|
|
49
|
+
const fnIndex = new Map([['LoginScreen', [file, PAGE.indexOf('fun LoginScreen')]]]);
|
|
50
|
+
const got = bodyTexts('LoginScreen', fnIndex, new Map([[file, PAGE]]), strings, 0, new Set(), () => 'LoginScreen.kt')
|
|
51
|
+
.map((t) => t.text).sort();
|
|
52
|
+
assert.deepEqual(got, ['去注册', '忘记密码', '快去添加商品吧', '请输入密码', '购物车', '购物车是空的']);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const SHEETS = `package com.ex
|
|
56
|
+
@Composable fun BottomModal(visible: Boolean, title: String? = null, onDismiss: () -> Unit, content: @Composable () -> Unit) {
|
|
57
|
+
if (visible) { ModalBottomSheet(onDismissRequest = onDismiss) { title?.let { Text(it) }; content() } }
|
|
58
|
+
}
|
|
59
|
+
@Composable fun CouponModal(visible: Boolean, onDismiss: () -> Unit) {
|
|
60
|
+
BottomModal(visible = visible, title = "领取优惠券", onDismiss = onDismiss) { Text("立即领取") }
|
|
61
|
+
}
|
|
62
|
+
@Composable fun GoodsScreen() {
|
|
63
|
+
var show by remember { mutableStateOf(false) }
|
|
64
|
+
Button(onClick = { show = true }) { Text("领券") }
|
|
65
|
+
CouponModal(visible = show, onDismiss = { show = false })
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
|
|
69
|
+
test('a *Modal wrapping ModalBottomSheet is a sheet overlay node', () => {
|
|
70
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'utg-sheet-'));
|
|
71
|
+
try {
|
|
72
|
+
const src = path.join(root, 'app/src/main/java/com/ex');
|
|
73
|
+
fs.mkdirSync(src, { recursive: true });
|
|
74
|
+
fs.writeFileSync(path.join(src, 'Sheets.kt'), SHEETS);
|
|
75
|
+
fs.writeFileSync(path.join(src, 'Nav.kt'), 'package com.ex\n@Serializable data object GoodsRoute\n' +
|
|
76
|
+
'fun NavGraphBuilder.goods() { composable<GoodsRoute> { GoodsScreen() } }\n');
|
|
77
|
+
const r = spawnSync(process.execPath, [path.join(HERE, '..', 'compose_overlay.mjs'), root], { encoding: 'utf8' });
|
|
78
|
+
assert.equal(r.status, 0, r.stderr);
|
|
79
|
+
const nodes = r.stdout.split('\n').filter(Boolean).map((l) => JSON.parse(l)).filter((x) => x.type === 'node');
|
|
80
|
+
const coupon = nodes.find((n) => n.id === 'overlay:CouponModal');
|
|
81
|
+
assert.ok(coupon, r.stderr + r.stdout);
|
|
82
|
+
assert.equal(coupon.kind, 'sheet', 'a gate delegating to a bottom-sheet shell is a sheet, not the dialog default');
|
|
83
|
+
} finally { fs.rmSync(root, { recursive: true, force: true }); }
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// A full page that happens to be named *Sheet (a balance sheet, a timesheet) is no overlay.
|
|
87
|
+
test('a *Sheet / *Modal name that shows no overlay is not an overlay node', () => {
|
|
88
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'utg-sheet-'));
|
|
89
|
+
try {
|
|
90
|
+
const src = path.join(root, 'app/src/main/java/com/ex');
|
|
91
|
+
fs.mkdirSync(src, { recursive: true });
|
|
92
|
+
fs.writeFileSync(path.join(src, 'Sheets.kt'), SHEETS +
|
|
93
|
+
'@Composable fun BalanceSheet() { Column { Text("资产负债表") } }\n' +
|
|
94
|
+
'@Composable fun TimeSheet() { Column { Text("工时") }; CouponModal(visible = true, onDismiss = {}) }\n');
|
|
95
|
+
fs.writeFileSync(path.join(src, 'Nav.kt'), 'package com.ex\n@Serializable data object GoodsRoute\n' +
|
|
96
|
+
'fun NavGraphBuilder.goods() { composable<GoodsRoute> { GoodsScreen(); BalanceSheet() } }\n');
|
|
97
|
+
const r = spawnSync(process.execPath, [path.join(HERE, '..', 'compose_overlay.mjs'), root], { encoding: 'utf8' });
|
|
98
|
+
assert.equal(r.status, 0, r.stderr);
|
|
99
|
+
const ids = r.stdout.split('\n').filter(Boolean).map((l) => JSON.parse(l)).filter((x) => x.type === 'node').map((n) => n.id);
|
|
100
|
+
assert.ok(ids.includes('overlay:CouponModal'), r.stdout);
|
|
101
|
+
assert.ok(!ids.includes('overlay:BalanceSheet'), 'a page named *Sheet');
|
|
102
|
+
} finally { fs.rmSync(root, { recursive: true, force: true }); }
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('_resolveTitle reads an @StringRes title argument', () => {
|
|
106
|
+
assert.deepEqual(_resolveTitle('title = R.string.cart, onBackClick = {}', { cart: '购物车' }, null), ['购物车', 'R.string.cart']);
|
|
107
|
+
assert.deepEqual(_resolveTitle('title = R.string.cart.toString()', { cart: '购物车' }, null)[0], null);
|
|
108
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// compose_nav: nav3 NavKey holders that reuse a member name (`OrderRoutes.List` / `FeedbackRoutes.List`)
|
|
2
|
+
// are two pages. A short route key declared under 2+ holders is qualified `Holder.Key` everywhere it
|
|
3
|
+
// is emitted (routes, navigate targets, host routes); keys that do not collide keep their short id.
|
|
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 { spawnSync } from 'node:child_process';
|
|
10
|
+
import { fileURLToPath } from 'node:url';
|
|
11
|
+
import { collidingRouteKeys, qualifyRouteKey, heldRouteKey } from '../compose_nav.mjs';
|
|
12
|
+
import { findNavbars } from '../compose_navbar_nav.mjs';
|
|
13
|
+
|
|
14
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const SRC = 'app/src/main/java/com/ex';
|
|
16
|
+
|
|
17
|
+
function project(files) {
|
|
18
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'utg-holder-'));
|
|
19
|
+
for (const [rel, text] of Object.entries(files)) {
|
|
20
|
+
const p = path.join(root, rel);
|
|
21
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
22
|
+
fs.writeFileSync(p, text);
|
|
23
|
+
}
|
|
24
|
+
return root;
|
|
25
|
+
}
|
|
26
|
+
const jsonl = (s) => s.trim().split(/\r?\n/).filter(Boolean).map((l) => JSON.parse(l));
|
|
27
|
+
const composeNav = (root) => {
|
|
28
|
+
const r = spawnSync(process.execPath, [path.join(HERE, '..', 'compose_nav.mjs'), root], { encoding: 'utf8' });
|
|
29
|
+
assert.equal(r.status, 0, r.stderr);
|
|
30
|
+
return jsonl(r.stdout);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const ROUTES = `package com.ex
|
|
34
|
+
import androidx.navigation3.runtime.NavKey
|
|
35
|
+
object OrderRoutes {
|
|
36
|
+
@Serializable data object List : NavKey
|
|
37
|
+
@Serializable data class Detail(val id: Long) : NavKey
|
|
38
|
+
@Serializable data object Pay : NavKey
|
|
39
|
+
}
|
|
40
|
+
object FeedbackRoutes {
|
|
41
|
+
@Serializable data object List : NavKey
|
|
42
|
+
@Serializable data object Submit : NavKey
|
|
43
|
+
}
|
|
44
|
+
object GoodsRoutes {
|
|
45
|
+
@Serializable data class Detail(val id: Long) : NavKey
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
const GRAPH = `package com.ex
|
|
49
|
+
import androidx.navigation3.runtime.entryProvider
|
|
50
|
+
fun graph(backStack: NavBackStack) = entryProvider {
|
|
51
|
+
entry<OrderRoutes.List> { OrderListRoute(onOpen = { backStack.add(OrderRoutes.Detail(1)) }) }
|
|
52
|
+
entry<OrderRoutes.Detail> { OrderDetailRoute(onPay = { backStack.add(OrderRoutes.Pay) }) }
|
|
53
|
+
entry<OrderRoutes.Pay> { OrderPayRoute() }
|
|
54
|
+
entry<FeedbackRoutes.List> { FeedbackListRoute(onSubmit = { backStack.add(FeedbackRoutes.Submit) }) }
|
|
55
|
+
entry<FeedbackRoutes.Submit> { FeedbackSubmitRoute() }
|
|
56
|
+
entry<GoodsRoutes.Detail> { GoodsDetailRoute(onOrders = { backStack.add(OrderRoutes.List) }) }
|
|
57
|
+
}
|
|
58
|
+
`;
|
|
59
|
+
|
|
60
|
+
test('colliding short keys are qualified with their holder; others stay short', () => {
|
|
61
|
+
const root = project({ [`${SRC}/Routes.kt`]: ROUTES, [`${SRC}/Graph.kt`]: GRAPH });
|
|
62
|
+
const out = composeNav(root);
|
|
63
|
+
const routes = out.filter((d) => d.type === 'route');
|
|
64
|
+
const keyOf = Object.fromEntries(routes.map((r) => [r.screen, r.route_key]));
|
|
65
|
+
assert.deepEqual(keyOf, {
|
|
66
|
+
OrderListRoute: 'OrderRoutes.List', OrderDetailRoute: 'OrderRoutes.Detail', OrderPayRoute: 'Pay',
|
|
67
|
+
FeedbackListRoute: 'FeedbackRoutes.List', FeedbackSubmitRoute: 'Submit', GoodsDetailRoute: 'GoodsRoutes.Detail',
|
|
68
|
+
});
|
|
69
|
+
assert.equal(new Set(routes.map((r) => r.route_key)).size, 6, 'six distinct page keys (no merge)');
|
|
70
|
+
const edges = out.filter((d) => d.type === 'edge').map((e) => `${e.host_route}->${e.route_key}`).sort();
|
|
71
|
+
assert.deepEqual(edges, [
|
|
72
|
+
'FeedbackRoutes.List->Submit',
|
|
73
|
+
'GoodsRoutes.Detail->OrderRoutes.List',
|
|
74
|
+
'OrderRoutes.Detail->Pay',
|
|
75
|
+
'OrderRoutes.List->OrderRoutes.Detail',
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('no collision: ids byte-identical to the short spelling', () => {
|
|
80
|
+
const root = project({
|
|
81
|
+
[`${SRC}/Routes.kt`]: 'package com.ex\nobject AppRoutes {\n data object Home : NavKey\n data object List : NavKey\n}\n',
|
|
82
|
+
[`${SRC}/Graph.kt`]: 'package com.ex\nimport androidx.navigation3.runtime.entryProvider\n' +
|
|
83
|
+
'fun g(backStack: NavBackStack) = entryProvider {\n' +
|
|
84
|
+
' entry<AppRoutes.Home> { HomeRoute(onList = { backStack.add(AppRoutes.List) }) }\n' +
|
|
85
|
+
' entry<AppRoutes.List> { ListRoute() }\n}\n',
|
|
86
|
+
});
|
|
87
|
+
const out = composeNav(root);
|
|
88
|
+
assert.deepEqual(out.filter((d) => d.type === 'route').map((r) => r.route_key).sort(), ['Home', 'List']);
|
|
89
|
+
assert.deepEqual(out.filter((d) => d.type === 'edge').map((e) => [e.host_route, e.route_key]), [['Home', 'List']]);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('helpers', () => {
|
|
93
|
+
const routes = [{ route_key: 'List', holder: 'A' }, { route_key: 'List', holder: 'B' }, { route_key: 'Home', holder: 'A' },
|
|
94
|
+
{ route_key: 'X.Y', holder: null }];
|
|
95
|
+
const c = collidingRouteKeys(routes);
|
|
96
|
+
assert.deepEqual([...c], ['List']);
|
|
97
|
+
assert.equal(qualifyRouteKey('List', 'A', c), 'A.List');
|
|
98
|
+
assert.equal(qualifyRouteKey('Home', 'A', c), 'Home');
|
|
99
|
+
assert.equal(qualifyRouteKey('List', null, c), 'List', 'no holder -> left for the member resolver');
|
|
100
|
+
const keys = new Set(['A.List', 'B.List', 'Home']);
|
|
101
|
+
assert.equal(heldRouteKey('B', 'List', keys), 'B.List');
|
|
102
|
+
assert.equal(heldRouteKey('A', 'Home', keys), 'Home');
|
|
103
|
+
assert.equal(heldRouteKey('C', 'List', keys), null, 'ambiguous bare member never picks one');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('navbar table entries resolve to the holder-qualified key', () => {
|
|
107
|
+
const text = 'fun Bar(onNav: (String) -> Unit) {\n val items = listOf(\n' +
|
|
108
|
+
' Item(A.LIST, "Orders"),\n Item(B.LIST, "Feedback"),\n Item(A.HOME, "Home"),\n )\n onNav("x")\n}\n';
|
|
109
|
+
const bars = findNavbars(new Map([['Bar.kt', text]]), new Set(['A.LIST', 'B.LIST', 'HOME']));
|
|
110
|
+
assert.equal(bars.length, 1);
|
|
111
|
+
assert.deepEqual(bars[0].items, [['A.LIST', 'Orders'], ['B.LIST', 'Feedback'], ['HOME', 'Home']]);
|
|
112
|
+
});
|