@buaa_smat/hometrans 26.0.0 → 26.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- 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,172 @@
|
|
|
1
|
+
// Port of test_mode_and_cb_param.py: mode-gated composables, nullable-callback gates,
|
|
2
|
+
// and fan-out over a whole frontier level in resolve_sources.
|
|
3
|
+
import { test } from 'node:test';
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import * as co from '../compose_overlay.mjs';
|
|
6
|
+
|
|
7
|
+
const LIST = `
|
|
8
|
+
@Composable
|
|
9
|
+
fun SongLazyColumn(
|
|
10
|
+
songList: List<Song>,
|
|
11
|
+
onRemovePlaylist: ((List<String>) -> Unit)? = null
|
|
12
|
+
) {
|
|
13
|
+
var multiChoiceMode by remember { mutableStateOf(false) }
|
|
14
|
+
Item(onClick = { multiChoiceMode = true }, text = "多选")
|
|
15
|
+
if (multiChoiceMode) {
|
|
16
|
+
MultiChoiceBottomBar(songList = songList, onRemovePlaylist = onRemovePlaylist)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@Composable
|
|
21
|
+
fun BoxScope.MultiChoiceBottomBar(
|
|
22
|
+
songList: List<Song>,
|
|
23
|
+
onRemovePlaylist: ((List<String>) -> Unit)? = null
|
|
24
|
+
) {
|
|
25
|
+
var deleteForeverDialog by remember { mutableStateOf(false) }
|
|
26
|
+
var removeDialog by remember { mutableStateOf(false) }
|
|
27
|
+
ControlItem(text = "永久删除", onClick = { deleteForeverDialog = true })
|
|
28
|
+
if (onRemovePlaylist != null) {
|
|
29
|
+
ControlItem(text = "从此歌单中移除", onClick = { removeDialog = true })
|
|
30
|
+
}
|
|
31
|
+
if (deleteForeverDialog) { YesNoDialog(title = "永久删除") }
|
|
32
|
+
if (removeDialog) { YesNoDialog(title = "从此歌单中移除") }
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
const SONGSCREEN = `
|
|
36
|
+
@Composable
|
|
37
|
+
fun SongScreen() { SongLazyColumn(songList = songs) }
|
|
38
|
+
`;
|
|
39
|
+
const PLAYLIST = `
|
|
40
|
+
@Composable
|
|
41
|
+
fun NewPlaylistContentScreen() {
|
|
42
|
+
ContentUI(songs = songs, onRemovePlaylist = { ids -> vm.removeSongs(ids) })
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Composable
|
|
46
|
+
fun ContentUI(songs: List<Song>, onRemovePlaylist: ((List<String>) -> Unit)? = null) {
|
|
47
|
+
var multiChoiceMode by remember { mutableStateOf(false) }
|
|
48
|
+
Item(onClick = { multiChoiceMode = true }, text = "多选")
|
|
49
|
+
if (multiChoiceMode) {
|
|
50
|
+
MultiChoiceBottomBar(songList = songs, onRemovePlaylist = onRemovePlaylist)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
const FT = new Map([
|
|
55
|
+
['a/SongLazyColumn.kt', LIST],
|
|
56
|
+
['a/SongScreen.kt', SONGSCREEN],
|
|
57
|
+
['a/NewPlaylistContentScreen.kt', PLAYLIST],
|
|
58
|
+
]);
|
|
59
|
+
const setEq = (s, arr) => s instanceof Set && s.size === arr.length && arr.every((x) => s.has(x));
|
|
60
|
+
|
|
61
|
+
test('scan_mode_gated_names', () => {
|
|
62
|
+
const gated = co.scanModeGatedNames(FT);
|
|
63
|
+
assert.equal(gated.get('MultiChoiceBottomBar'), 'multiChoiceMode', 'a composable rendered only under `if (modeFlag)` is mode-gated');
|
|
64
|
+
assert.ok(!gated.has('ControlItem'), 'a component INSIDE the mode-gated composable is not itself listed');
|
|
65
|
+
const BOTH = new Map(FT);
|
|
66
|
+
BOTH.set('a/Other.kt', '@Composable\nfun OtherScreen() { MultiChoiceBottomBar(songList = s) }\n');
|
|
67
|
+
assert.ok(!co.scanModeGatedNames(BOTH).has('MultiChoiceBottomBar'),
|
|
68
|
+
'a component rendered BOTH inside and outside a mode is NOT mode-gated');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('mode_flag_is_interactive', () => {
|
|
72
|
+
const DISPLAY = `fun PlayerTime() {
|
|
73
|
+
var reversePlayMode by remember { mutableStateOf(false) }
|
|
74
|
+
if (reversePlayMode) { Text(text = "-" + time) }
|
|
75
|
+
LaunchedEffect(Unit) { reversePlayMode = mmkv.decodeBool(K, false) }
|
|
76
|
+
}
|
|
77
|
+
`;
|
|
78
|
+
assert.ok(!co.modeFlagIsInteractive(DISPLAY, 'reversePlayMode'), 'display-only flag set from config is NOT a mode');
|
|
79
|
+
assert.ok(co.modeFlagIsInteractive(LIST, 'multiChoiceMode'), 'a flag set by a control AND gating interactive content IS a mode');
|
|
80
|
+
const NO_SETTER = DISPLAY.replace('reversePlayMode = mmkv.decodeBool(K, false)', '');
|
|
81
|
+
assert.ok(!co.modeFlagIsInteractive(NO_SETTER, 'reversePlayMode'), 'a flag nothing ever sets true is not a mode');
|
|
82
|
+
const CLICKABLE = `fun S() {
|
|
83
|
+
var editMode by remember { mutableStateOf(false) }
|
|
84
|
+
Icon(modifier = Modifier.clickable { editMode = true })
|
|
85
|
+
if (editMode) { Row(modifier = Modifier.clickable { act() }) { Text("x") } }
|
|
86
|
+
}
|
|
87
|
+
`;
|
|
88
|
+
assert.ok(co.modeFlagIsInteractive(CLICKABLE, 'editMode'), '`.clickable {}` counts as interactive');
|
|
89
|
+
assert.equal(co.scanModeGatedNames(new Map([['a/D.kt', DISPLAY]])).size, 0, 'the pre-pass drops display-only flags too');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('mode_node_id', () => {
|
|
93
|
+
assert.equal(co.modeNodeId('multiChoiceMode', 'SONG'), 'mode:MULTI_CHOICE@SONG', 'the id is derived from the FLAG name');
|
|
94
|
+
assert.equal(co.modeNodeId('editMode', 'X'), 'mode:EDIT@X', 'a second, different mode gets a different node');
|
|
95
|
+
assert.ok(co._routePart('mode:MULTI_CHOICE@SONG') === 'SONG' && co._routePart('compose-route:SONG') === 'SONG',
|
|
96
|
+
'a page and a per-page sub-state of it compare equal');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('_cb_param_providers: forwarding', () => {
|
|
100
|
+
const prov = co._cbParamProviders('onRemovePlaylist', 'MultiChoiceBottomBar', FT, '');
|
|
101
|
+
assert.ok(setEq(prov, ['NewPlaylistContentScreen']), `only the caller that supplies a REAL callback is a provider (got ${[...prov]})`);
|
|
102
|
+
assert.ok(setEq(co._nullableCbParamsOf(LIST, 'MultiChoiceBottomBar'), ['onRemovePlaylist']), 'nullable callback params of a signature are read');
|
|
103
|
+
assert.ok(setEq(co._nullableCbParamsOf(LIST, 'SongLazyColumn'), ['onRemovePlaylist']), "the relay's own signature is read the same way");
|
|
104
|
+
const funs = co.buildFunIndex(LIST);
|
|
105
|
+
assert.deepEqual(co._nullableCbGates(LIST, LIST.indexOf('removeDialog = true'), funs), ['onRemovePlaylist'],
|
|
106
|
+
'a trigger inside `if (onRemovePlaylist != null)` reports that parameter');
|
|
107
|
+
assert.deepEqual(co._nullableCbGates(LIST, LIST.indexOf('deleteForeverDialog = true'), funs), [],
|
|
108
|
+
'a trigger OUTSIDE the null-check reports nothing');
|
|
109
|
+
const LOCAL = `fun S() {
|
|
110
|
+
val onThing: (() -> Unit)? = null
|
|
111
|
+
if (onThing != null) { Item(onClick = { flag = true }) }
|
|
112
|
+
}
|
|
113
|
+
`;
|
|
114
|
+
assert.deepEqual(co._nullableCbGates(LOCAL, LOCAL.indexOf('flag = true'), co.buildFunIndex(LOCAL)), [],
|
|
115
|
+
'a nullable LOCAL is not a caller-supplied parameter');
|
|
116
|
+
const EXPLICIT = new Map(FT);
|
|
117
|
+
EXPLICIT.set('a/NewPlaylistContentScreen.kt', PLAYLIST.replace(
|
|
118
|
+
'onRemovePlaylist = { ids -> vm.removeSongs(ids) }', 'onRemovePlaylist = null'));
|
|
119
|
+
assert.equal(co._cbParamProviders('onRemovePlaylist', 'MultiChoiceBottomBar', EXPLICIT, '').size, 0,
|
|
120
|
+
'passing an explicit `null` does not make a caller a provider');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('_filter_sources_by_cb_param: conservative', () => {
|
|
124
|
+
const SRC = [['compose-route:SONG', 'callgraph-fanout'],
|
|
125
|
+
['compose-route:NEW_PLAYLIST_CONTENT', 'callgraph-fanout']];
|
|
126
|
+
const IDX = [new Map([['SongScreen', 1], ['NewPlaylistContentScreen', 1]]), new Map(), new Map()];
|
|
127
|
+
const kept = co._filterSourcesByCbParam(SRC, 'onRemovePlaylist', 'MultiChoiceBottomBar', FT, '',
|
|
128
|
+
new Map([['SongScreen', 'SONG'], ['NewPlaylistContentScreen', 'NEW_PLAYLIST_CONTENT']]),
|
|
129
|
+
new Set(), IDX, new Map(), new Map());
|
|
130
|
+
assert.deepEqual(kept, [['compose-route:NEW_PLAYLIST_CONTENT', 'callgraph-fanout']], 'only the providing page keeps the gated control');
|
|
131
|
+
assert.deepEqual(co._filterSourcesByCbParam(SRC, 'onNothing', 'MultiChoiceBottomBar', FT, '',
|
|
132
|
+
new Map(), new Set(), IDX, new Map(), new Map()), SRC, 'no demonstrable provider => nothing is dropped');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
const SCREENS = new Map([['SongScreen', 1], ['FolderScreen', 1], ['SearchScreen', 1], ['NewPlaylistContentScreen', 1]]);
|
|
136
|
+
const S2R = new Map([['SongScreen', 'SONG'], ['FolderScreen', 'FOLDER_CONTENT'],
|
|
137
|
+
['SearchScreen', 'SEARCH_ALL_SONGS'], ['NewPlaylistContentScreen', 'NEW_PLAYLIST_CONTENT']]);
|
|
138
|
+
const C2C = new Map([['MultiChoiceBottomBar', ['SongLazyColumn', 'ContentUI']],
|
|
139
|
+
['SongLazyColumn', ['SongScreen', 'FolderScreen', 'SearchScreen']],
|
|
140
|
+
['ContentUI', ['NewPlaylistContentScreen']]]);
|
|
141
|
+
const IDX2 = [SCREENS, C2C, new Map()];
|
|
142
|
+
const ids = (xs) => xs.map((x) => x[0]).sort();
|
|
143
|
+
|
|
144
|
+
test('resolve_sources: a whole frontier LEVEL is collected', () => {
|
|
145
|
+
const got = co.resolveSources('a/x.kt', 'MultiChoiceBottomBar', S2R, new Set(), { call_index: IDX2 });
|
|
146
|
+
assert.deepEqual(ids(got), ['compose-route:FOLDER_CONTENT', 'compose-route:NEW_PLAYLIST_CONTENT',
|
|
147
|
+
'compose-route:SEARCH_ALL_SONGS', 'compose-route:SONG'], 'all 4 owning pages survive');
|
|
148
|
+
const C2C_HOST = new Map([['Widget', ['PlayerTop', 'SomeHelper']], ['PlayerTop', ['PlayerScreenBody']],
|
|
149
|
+
['SomeHelper', ['OnCreateBody']]]);
|
|
150
|
+
const host = () => [new Map(), C2C_HOST, new Map([['OnCreateBody', 'activity:WebActivity']])];
|
|
151
|
+
const got2 = co.resolveSources('a/x.kt', 'Widget', new Map(), new Set(), {
|
|
152
|
+
call_index: host(), gated_slot_ids: new Map([['PlayerScreenBody', 'sheet-screen:PlayerScreen']]),
|
|
153
|
+
});
|
|
154
|
+
assert.deepEqual(got2, [['sheet-screen:PlayerScreen', 'callgraph-gated-slot']],
|
|
155
|
+
'a precise page hit SUPPRESSES the Activity-host hit found on a sibling branch');
|
|
156
|
+
assert.deepEqual(co.resolveSources('a/x.kt', 'Widget', new Map(), new Set(), { call_index: host() }),
|
|
157
|
+
[['activity:WebActivity', 'callgraph-activity']], 'with no page anywhere, the host fallback is still returned');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('_mode_wrap composes with fan-out', () => {
|
|
161
|
+
const MG = new Map([['MultiChoiceBottomBar', 'multiChoiceMode']]);
|
|
162
|
+
const wrapped = co.resolveSources('a/x.kt', 'MultiChoiceBottomBar', S2R, new Set(), { call_index: IDX2, mode_gated_fns: MG });
|
|
163
|
+
assert.deepEqual(ids(wrapped), ['mode:MULTI_CHOICE@FOLDER_CONTENT', 'mode:MULTI_CHOICE@NEW_PLAYLIST_CONTENT',
|
|
164
|
+
'mode:MULTI_CHOICE@SEARCH_ALL_SONGS', 'mode:MULTI_CHOICE@SONG'], 'each owning page gets its OWN mode node');
|
|
165
|
+
assert.ok(wrapped.every((x) => x[1] === 'mode-gated'), 'the wrap is reported in source_resolved_by');
|
|
166
|
+
assert.deepEqual(co.resolveSources('a/d.kt', 'SongMenuDialog', new Map(), new Set(['SongMenuDialog']),
|
|
167
|
+
{ call_index: IDX2, mode_gated_fns: MG }), [['overlay:SongMenuDialog', 'fn-overlay']],
|
|
168
|
+
'the identically-labelled 永久删除 on the song context menu is NOT re-parented onto a mode');
|
|
169
|
+
const got = co.resolveSources('a/x.kt', 'MultiChoiceBottomBar', S2R, new Set(), { call_index: IDX2 });
|
|
170
|
+
assert.deepEqual(co.resolveSources('a/x.kt', 'MultiChoiceBottomBar', S2R, new Set(), { call_index: IDX2 }), got,
|
|
171
|
+
'mode_gated_fns is optional');
|
|
172
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// Port of test_module_namespace.py: relative activity names resolve per module namespace.
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import * as os from 'node:os';
|
|
6
|
+
import * as path from 'node:path';
|
|
7
|
+
import { _collect } from '../manifest.mjs';
|
|
8
|
+
|
|
9
|
+
function write(root, rel, text) {
|
|
10
|
+
const p = path.join(root, rel);
|
|
11
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
12
|
+
fs.writeFileSync(p, text, 'utf8');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
test('relative names resolve per module', () => {
|
|
16
|
+
const proj = fs.mkdtempSync(path.join(os.tmpdir(), 'ns-'));
|
|
17
|
+
try {
|
|
18
|
+
const ns = 'http://schemas.android.com/apk/res/android';
|
|
19
|
+
write(proj, 'app/build.gradle', 'android { namespace "ex.app" }\n');
|
|
20
|
+
write(proj, 'app/src/main/AndroidManifest.xml',
|
|
21
|
+
`<manifest xmlns:android="${ns}"><application><activity android:name=".Main"/></application></manifest>`);
|
|
22
|
+
write(proj, 'ui/echo/build.gradle.kts', 'android { namespace = "ex.ui.echo" }\n');
|
|
23
|
+
write(proj, 'ui/echo/src/main/AndroidManifest.xml',
|
|
24
|
+
`<manifest xmlns:android="${ns}"><application><activity android:name=".EchoActivity"/></application></manifest>`);
|
|
25
|
+
write(proj, 'legacy/src/main/AndroidManifest.xml',
|
|
26
|
+
`<manifest xmlns:android="${ns}" package="ex.legacy"><application><activity android:name=".Old"/></application></manifest>`);
|
|
27
|
+
const [acts] = _collect(proj, 'ex.app', []);
|
|
28
|
+
const names = new Set(acts.map((r) => r.name));
|
|
29
|
+
for (const n of ['ex.app.Main', 'ex.ui.echo.EchoActivity', 'ex.legacy.Old']) {
|
|
30
|
+
assert.ok(names.has(n), `relative names must resolve per module: ${[...names].sort()}`);
|
|
31
|
+
}
|
|
32
|
+
} finally { fs.rmSync(proj, { recursive: true, force: true }); }
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('no literal namespace: sources win over the applicationId', () => {
|
|
36
|
+
// A convention plugin sets the namespace and debug adds applicationIdSuffix, so the caller's
|
|
37
|
+
// package is "ex.shop.debug"; the class lives in "ex.shop".
|
|
38
|
+
const proj = fs.mkdtempSync(path.join(os.tmpdir(), 'ns-'));
|
|
39
|
+
try {
|
|
40
|
+
const ns = 'http://schemas.android.com/apk/res/android';
|
|
41
|
+
write(proj, 'app/build.gradle.kts', 'plugins { alias(libs.plugins.shop.application) }\n');
|
|
42
|
+
write(proj, 'app/src/main/AndroidManifest.xml',
|
|
43
|
+
`<manifest xmlns:android="${ns}"><application android:name=".ShopApp">` +
|
|
44
|
+
'<activity android:name=".MainActivity"/><activity android:name=".ui.Detail"/></application></manifest>');
|
|
45
|
+
write(proj, 'app/src/main/java/ex/shop/MainActivity.kt', 'package ex.shop\n\nclass MainActivity\n');
|
|
46
|
+
write(proj, 'app/src/main/java/ex/shop/ui/Detail.kt', 'package ex.shop.ui\n\nclass Detail\n');
|
|
47
|
+
const [acts] = _collect(proj, 'ex.shop.debug', []);
|
|
48
|
+
const names = new Set(acts.map((r) => r.name));
|
|
49
|
+
for (const n of ['ex.shop.MainActivity', 'ex.shop.ui.Detail']) {
|
|
50
|
+
assert.ok(names.has(n), `relative names must resolve against the source package: ${[...names].sort()}`);
|
|
51
|
+
}
|
|
52
|
+
} finally { fs.rmSync(proj, { recursive: true, force: true }); }
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('no literal namespace: src/main decides over a flavour holding a same-named class', () => {
|
|
56
|
+
// `aDemo` sorts before `main` and walks first by name; its MainActivity lives in another package.
|
|
57
|
+
const proj = fs.mkdtempSync(path.join(os.tmpdir(), 'ns-'));
|
|
58
|
+
try {
|
|
59
|
+
const ns = 'http://schemas.android.com/apk/res/android';
|
|
60
|
+
write(proj, 'app/build.gradle.kts', 'plugins { alias(libs.plugins.shop.application) }\n');
|
|
61
|
+
write(proj, 'app/src/main/AndroidManifest.xml',
|
|
62
|
+
`<manifest xmlns:android="${ns}"><application><activity android:name=".MainActivity"/></application></manifest>`);
|
|
63
|
+
write(proj, 'app/src/aDemo/java/ex/demo/MainActivity.kt', 'package ex.demo\n\nclass MainActivity\n');
|
|
64
|
+
write(proj, 'app/src/main/java/ex/shop/MainActivity.kt', 'package ex.shop\n\nclass MainActivity\n');
|
|
65
|
+
const [acts] = _collect(proj, 'ex.shop.debug', []);
|
|
66
|
+
assert.ok(acts.some((r) => r.name === 'ex.shop.MainActivity'), JSON.stringify(acts.map((r) => r.name)));
|
|
67
|
+
} finally { fs.rmSync(proj, { recursive: true, force: true }); }
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('no literal namespace: same-named classes in sibling packages resolve by name, not readdir order', () => {
|
|
71
|
+
// readdir order differs between NTFS and ext4: the walk sorts every level, so ex/aa wins over ex/zz.
|
|
72
|
+
const proj = fs.mkdtempSync(path.join(os.tmpdir(), 'ns-'));
|
|
73
|
+
try {
|
|
74
|
+
const ns = 'http://schemas.android.com/apk/res/android';
|
|
75
|
+
write(proj, 'app/build.gradle.kts', 'plugins { alias(libs.plugins.shop.application) }\n');
|
|
76
|
+
write(proj, 'app/src/main/AndroidManifest.xml',
|
|
77
|
+
`<manifest xmlns:android="${ns}"><application><activity android:name=".MainActivity"/></application></manifest>`);
|
|
78
|
+
write(proj, 'app/src/main/java/ex/zz/MainActivity.kt', 'package ex.zz\n\nclass MainActivity\n');
|
|
79
|
+
write(proj, 'app/src/main/java/ex/aa/MainActivity.kt', 'package ex.aa\n\nclass MainActivity\n');
|
|
80
|
+
const [acts] = _collect(proj, 'ex.shop.debug', []);
|
|
81
|
+
assert.ok(acts.some((r) => r.name === 'ex.aa.MainActivity'), JSON.stringify(acts.map((r) => r.name)));
|
|
82
|
+
} finally { fs.rmSync(proj, { recursive: true, force: true }); }
|
|
83
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// loadProjectStrings reads every module's strings: a modularised app keeps its pages' strings in
|
|
2
|
+
// feature/core modules, and its `app` module declares little beyond app_name.
|
|
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 { loadProjectStrings, valuesDirLang } from '../label_resolve.mjs';
|
|
9
|
+
|
|
10
|
+
function project(files) {
|
|
11
|
+
const td = fs.mkdtempSync(path.join(os.tmpdir(), 'modstr-'));
|
|
12
|
+
for (const [rel, body] of Object.entries(files)) {
|
|
13
|
+
fs.mkdirSync(path.dirname(path.join(td, rel)), { recursive: true });
|
|
14
|
+
fs.writeFileSync(path.join(td, rel), `<resources>${body}</resources>`);
|
|
15
|
+
}
|
|
16
|
+
return td;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
test('feature-module strings resolve; app overrides libraries; zh wins; other languages ignored', () => {
|
|
20
|
+
const td = project({
|
|
21
|
+
'app/src/main/res/values/strings.xml': '<string name="app_name">商城</string><string name="shared">app版</string>',
|
|
22
|
+
'feature/main/src/main/res/values/strings.xml': '<string name="flash_sale">限时精选</string><string name="shared">库版</string>',
|
|
23
|
+
'feature/main/src/main/res/values-en/strings.xml': '<string name="flash_sale">Flash sale</string>',
|
|
24
|
+
'core/ui/src/main/res/values/strings.xml': '<string name="empty">Empty</string>',
|
|
25
|
+
'core/ui/src/main/res/values-zh-rCN/strings.xml': '<string name="empty">暂无数据</string>',
|
|
26
|
+
});
|
|
27
|
+
try {
|
|
28
|
+
const s = loadProjectStrings(td);
|
|
29
|
+
assert.equal(s.flash_sale, '限时精选', 'a feature module string resolves, and values-en does not replace it');
|
|
30
|
+
assert.equal(s.app_name, '商城');
|
|
31
|
+
assert.equal(s.shared, 'app版', 'the app module overrides a library, as the resource merger does');
|
|
32
|
+
assert.equal(s.empty, '暂无数据', 'a Chinese overlay wins');
|
|
33
|
+
} finally { fs.rmSync(td, { recursive: true, force: true }); }
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('valuesDirLang reads language qualifiers only', () => {
|
|
37
|
+
assert.equal(valuesDirLang('res/values'), '');
|
|
38
|
+
assert.equal(valuesDirLang('res/values-night'), '');
|
|
39
|
+
assert.equal(valuesDirLang('res/values-v21'), '');
|
|
40
|
+
assert.equal(valuesDirLang('res/values-en'), 'en');
|
|
41
|
+
assert.equal(valuesDirLang('res/values-zh-rTW'), 'zh');
|
|
42
|
+
assert.equal(valuesDirLang('res/values-b+zh+Hans'), 'zh');
|
|
43
|
+
assert.equal(valuesDirLang('moko-resources/base'), '');
|
|
44
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// Port of test_multiple_entry_contracts.py: launcher/action/deep-link entry contracts in click_paths.
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import * as os from 'node:os';
|
|
6
|
+
import * as path from 'node:path';
|
|
7
|
+
import * as clickPaths from '../click_paths.mjs';
|
|
8
|
+
import * as manifest from '../manifest.mjs';
|
|
9
|
+
|
|
10
|
+
function runPaths(nodes, links) {
|
|
11
|
+
const ws = fs.mkdtempSync(path.join(os.tmpdir(), 'mec_'));
|
|
12
|
+
fs.writeFileSync(path.join(ws, 'utg.json'), JSON.stringify({ directed: true, multigraph: true, graph: {}, nodes, links }));
|
|
13
|
+
clickPaths.main([ws]);
|
|
14
|
+
return JSON.parse(fs.readFileSync(path.join(ws, 'click_paths.json'), 'utf8'));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
test('multiple entry contracts', () => {
|
|
18
|
+
const launcher = manifest.toNode({ name: 'example.touch.HomeActivity', exported: true,
|
|
19
|
+
is_launcher: true, actions: [], deep_links: [] });
|
|
20
|
+
const action = manifest.toNode({ name: 'example.player.ExternalPlayerActivity', exported: true,
|
|
21
|
+
is_launcher: false, actions: ['example.action.PLAY'], deep_links: [] });
|
|
22
|
+
const deep = manifest.toNode({ name: 'example.links.RouteActivity', exported: true,
|
|
23
|
+
is_launcher: false, actions: [],
|
|
24
|
+
deep_links: [{ scheme: 'demo', host: 'open', pathPrefix: '/deeplink/main' }] });
|
|
25
|
+
const priv = manifest.toNode({ name: 'example.internal.PrivateActivity', exported: false,
|
|
26
|
+
is_launcher: false, actions: ['example.action.PRIVATE'], deep_links: [] });
|
|
27
|
+
|
|
28
|
+
assert.equal(launcher.entry_kind, 'launcher', 'launcher entry missing');
|
|
29
|
+
assert.equal(action.entry_kind, 'intent-action', 'action entry missing');
|
|
30
|
+
assert.equal(deep.entry_kind, 'deep-link', 'deep-link entry missing');
|
|
31
|
+
assert.ok(!priv.entry, 'non-exported action must not be an entry');
|
|
32
|
+
|
|
33
|
+
const child = { id: 'fragment:PlayerMenu', kind: 'menu', label: 'Menu' };
|
|
34
|
+
let doc = runPaths([launcher, action, deep, priv, child], [{
|
|
35
|
+
source: action.id, target: child.id, mechanism: 'open-overlay', trigger: 'onClick@Player.kt:10',
|
|
36
|
+
args: { label: 'Menu' } }]);
|
|
37
|
+
assert.equal(doc.root, launcher.id, 'primary launcher must remain root');
|
|
38
|
+
assert.ok((doc.entry_roots ?? []).includes(action.id), 'exported action Activity must be a secondary root');
|
|
39
|
+
assert.ok((doc.entry_roots ?? []).includes(deep.id), 'deep-link Activity must be a secondary root');
|
|
40
|
+
assert.ok((doc.unreachable ?? []).includes(priv.id), 'private Activity without an in-edge remains unreachable');
|
|
41
|
+
assert.ok(!(doc.unreachable ?? []).includes(child.id), 'a descendant of a secondary root is reachable');
|
|
42
|
+
const p = doc.paths[action.id];
|
|
43
|
+
assert.equal(p.steps[0].launch.type, 'intent-action', 'path launch step must retain the action recipe');
|
|
44
|
+
assert.equal(doc.entries[deep.id].scheme, 'demo', 'entries map must retain the deep-link recipe');
|
|
45
|
+
assert.equal(doc.entries[deep.id].pathPrefix, '/deeplink/main', 'entries map must retain deep-link path constraints');
|
|
46
|
+
|
|
47
|
+
const splash = manifest.toNode({ name: 'example.touch.SplashActivity', exported: true,
|
|
48
|
+
is_launcher: true, actions: [], deep_links: [] });
|
|
49
|
+
const host = manifest.toNode({ name: 'example.touch.MainHost', exported: true,
|
|
50
|
+
is_launcher: false, actions: [], deep_links: [{ scheme: 'https', host: 'example.org' }] });
|
|
51
|
+
const page = { id: 'fragment:Inbox', kind: 'fragment', label: 'Inbox' };
|
|
52
|
+
doc = runPaths([splash, host, page], [
|
|
53
|
+
{ source: splash.id, target: host.id, mechanism: 'startActivity-explicit', trigger: 'lifecycle@Splash.kt:5', args: {} },
|
|
54
|
+
{ source: host.id, target: page.id, mechanism: 'fragment-transaction', trigger: 'onClick@Host.kt:9', args: { label: 'Inbox' } }]);
|
|
55
|
+
assert.equal(doc.root, splash.id, 'launcher must be root');
|
|
56
|
+
for (const ident of [host.id, page.id]) {
|
|
57
|
+
const q = doc.paths[ident];
|
|
58
|
+
assert.ok(!('entry_root' in q), `${ident} must keep the launcher route, got ${q.entry_root}`);
|
|
59
|
+
assert.equal(q.steps[0].target_id, splash.id, `${ident} path must start at the launcher`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const ns = 'http://schemas.android.com/apk/res/android';
|
|
63
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'mec_m_'));
|
|
64
|
+
const manifestPath = path.join(dir, 'xAndroidManifest.xml');
|
|
65
|
+
fs.writeFileSync(manifestPath, `<manifest xmlns:android="${ns}"><application>
|
|
66
|
+
<activity android:name=".RouteActivity" android:exported="true">
|
|
67
|
+
<intent-filter><action android:name="android.intent.action.VIEW"/>
|
|
68
|
+
<category android:name="android.intent.category.DEFAULT"/>
|
|
69
|
+
<data android:scheme="demo" android:host="open"
|
|
70
|
+
android:pathPrefix="/deeplink/main"/>
|
|
71
|
+
</intent-filter>
|
|
72
|
+
</activity>
|
|
73
|
+
</application></manifest>`, 'utf8');
|
|
74
|
+
try {
|
|
75
|
+
const record = manifest.parseManifest(manifestPath, 'example')[0];
|
|
76
|
+
assert.equal(record.deep_links[0].pathPrefix, '/deeplink/main', 'manifest parser must preserve pathPrefix');
|
|
77
|
+
const parsedNode = manifest.toNode(record);
|
|
78
|
+
assert.equal(parsedNode.launch.pathPrefix, '/deeplink/main', 'node launch recipe must preserve pathPrefix');
|
|
79
|
+
} finally { fs.unlinkSync(manifestPath); }
|
|
80
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// scanNavGraphXml: attribute order, @+id destinations, and no build/ copies of the graph.
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import * as os from 'node:os';
|
|
6
|
+
import * as path from 'node:path';
|
|
7
|
+
import { scanNavGraphXml } from '../screen_nav.mjs';
|
|
8
|
+
|
|
9
|
+
function write(root, rel, text) {
|
|
10
|
+
const p = path.join(root, rel);
|
|
11
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
12
|
+
fs.writeFileSync(p, text, 'utf8');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const GRAPH = `<navigation xmlns:android="http://schemas.android.com/apk/res/android"
|
|
16
|
+
xmlns:app="http://schemas.android.com/apk/res-auto">
|
|
17
|
+
<fragment android:name="ex.app.HomeFragment" android:id="@+id/home">
|
|
18
|
+
<action app:destination="@+id/detail" android:id="@+id/to_detail"/>
|
|
19
|
+
</fragment>
|
|
20
|
+
<fragment android:id="@+id/detail" android:name="ex.app.DetailFragment"/>
|
|
21
|
+
</navigation>`;
|
|
22
|
+
|
|
23
|
+
test('nav graph: any attribute order, @+id destination, build/ copies skipped', () => {
|
|
24
|
+
const proj = fs.mkdtempSync(path.join(os.tmpdir(), 'nav-'));
|
|
25
|
+
try {
|
|
26
|
+
write(proj, 'app/src/main/res/navigation/main.xml', GRAPH);
|
|
27
|
+
write(proj, 'app/build/intermediates/merged_res/debug/res/navigation/main.xml', GRAPH);
|
|
28
|
+
write(proj, 'app/src/main/assets/navigation/not_a_graph.xml', GRAPH); // not under res/
|
|
29
|
+
const [routes, edges] = scanNavGraphXml(proj);
|
|
30
|
+
assert.deepEqual(routes.map((r) => [r.route_key, r.screen]).sort(),
|
|
31
|
+
[['detail', 'DetailFragment'], ['home', 'HomeFragment']]);
|
|
32
|
+
assert.deepEqual(edges.map((e) => [e.args.action_id, e.target]), [['to_detail', 'detail']]);
|
|
33
|
+
assert.ok(routes.every((r) => !r.file.includes('build')));
|
|
34
|
+
} finally { fs.rmSync(proj, { recursive: true, force: true }); }
|
|
35
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// nl_hints states and lints the hint grammar the explorer compiles, so a hint whose quoted target sits
|
|
2
|
+
// in parentheses (stripped as commentary) is caught at apply time, not at the explorer's compile.
|
|
3
|
+
import { test } from 'node:test';
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import * as fs from 'node:fs';
|
|
6
|
+
import * as path from 'node:path';
|
|
7
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
8
|
+
import * as nl from '../nl_hints.mjs';
|
|
9
|
+
|
|
10
|
+
const CASES = [
|
|
11
|
+
['点击「设置」', null],
|
|
12
|
+
['点击顶部栏的收藏列表图标(“收藏列表”)', 'hint-target-not-quoted'],
|
|
13
|
+
['点击右上角的“收藏列表”图标', null],
|
|
14
|
+
['点击首页右上角的GitHub图标', 'hint-target-not-quoted'],
|
|
15
|
+
['无需操作,启动页动画结束后自动进入主页', null],
|
|
16
|
+
['(无需点击)自动进入', null],
|
|
17
|
+
['点击列表中任意一个条目', null],
|
|
18
|
+
['点击“请输入汉字查询”搜索框,输入一个汉字后按键盘搜索键提交', 'hint-unsupported-gesture'],
|
|
19
|
+
['点击〔id:settings_btn〕', null],
|
|
20
|
+
['Tap “Settings”, then tap “About”', null],
|
|
21
|
+
['先查看页面', 'hint-has-no-quoted-tap'],
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
test('hintGrammarIssue classifies the forms reviewers actually write', () => {
|
|
25
|
+
for (const [hint, want] of CASES) { assert.equal(nl.hintGrammarIssue(hint), want, hint); }
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('the worklist carries the grammar', () => {
|
|
29
|
+
assert.match(nl.HINT_GRAMMAR, /OUTSIDE parentheses/);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Parity with the explorer's compiler when that skill is installed beside this one.
|
|
33
|
+
const here = path.dirname(fileURLToPath(import.meta.url));
|
|
34
|
+
const explorer = path.resolve(here, '..', '..', '..', 'a2h-utg-explorer', 'scripts', 'compile_tasks.mjs');
|
|
35
|
+
test('parity with a2h-utg-explorer hintSteps', { skip: !fs.existsSync(explorer) && 'explorer not installed' }, async () => {
|
|
36
|
+
const { hintSteps } = await import(pathToFileURL(explorer).href);
|
|
37
|
+
for (const [hint] of CASES) {
|
|
38
|
+
const [, reason] = hintSteps(hint);
|
|
39
|
+
const want = reason === 'hint-no-gesture' ? null : (reason ?? null);
|
|
40
|
+
assert.equal(nl.hintGrammarIssue(hint), want, `drift from compile_tasks.hintSteps: ${hint}`);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Port of test_nl_hints_gate.py: nl_hints' trigger classification (hintReasons) and the apply() answer gate.
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import * as os from 'node:os';
|
|
6
|
+
import * as path from 'node:path';
|
|
7
|
+
import * as nl from '../nl_hints.mjs';
|
|
8
|
+
|
|
9
|
+
const R = nl.hintReasons;
|
|
10
|
+
|
|
11
|
+
test('hint_reasons', () => {
|
|
12
|
+
assert.deepEqual(R({ action: 'tap', label: '设置' }), [], 'plain CJK tap needs no hint');
|
|
13
|
+
assert.deepEqual(R({ action: 'launch', label: null }), [], 'launch step is never surfaced');
|
|
14
|
+
assert.ok(R({ action: 'tap', label: 'Sky' }).includes('code-name'), 'non-CJK label surfaces as code-name');
|
|
15
|
+
assert.ok(R({ action: 'tap', label: '菜单', label_ambiguous: true }).includes('ambiguous'),
|
|
16
|
+
'label_ambiguous surfaces even though the text is real CJK');
|
|
17
|
+
assert.ok(R({ action: 'long_press', label: '菜单' }).includes('gesture'),
|
|
18
|
+
'long_press surfaces: the label cannot say WHAT to press');
|
|
19
|
+
assert.ok(R({ action: 'double_tap', label: '关于' }).includes('gesture'), 'double_tap surfaces');
|
|
20
|
+
assert.ok(!R({ action: 'swipe-up', label: '队列' }).includes('gesture'),
|
|
21
|
+
'a swipe is objectless — no control to describe, so no gesture reason');
|
|
22
|
+
assert.ok(!R({ action: 'default', label: '首页' }).includes('gesture'),
|
|
23
|
+
'an auto-load hop needs no gesture instruction');
|
|
24
|
+
|
|
25
|
+
const eSd = { trigger: 'startDestination@Nav.kt:155' };
|
|
26
|
+
assert.ok(R({ action: 'tap', label: 'Sky' }, eSd).includes('non-gesture'),
|
|
27
|
+
'labelled startDestination surfaces as non-gesture');
|
|
28
|
+
assert.deepEqual(R({ action: 'tap', label: null }, { trigger: 'render-branch' }), [],
|
|
29
|
+
'UNLABELLED render-branch is silent: no phantom instruction exists');
|
|
30
|
+
assert.ok(!R({ action: 'tap', label: '设置' }, { trigger: 'onClick@A.kt:10' }).includes('non-gesture'),
|
|
31
|
+
'an ordinary onClick is not non-gesture');
|
|
32
|
+
|
|
33
|
+
const multi = R({ action: 'double_tap', label: 'Clickable', label_ambiguous: true }, eSd);
|
|
34
|
+
assert.deepEqual(new Set(multi), new Set(['code-name', 'ambiguous', 'gesture', 'non-gesture']),
|
|
35
|
+
'all applicable reasons are reported together');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
function mkWs(steps) {
|
|
39
|
+
const d = fs.mkdtempSync(path.join(os.tmpdir(), 'nlh_'));
|
|
40
|
+
const cp = { root: 'n:HOME', paths: { 'n:T': { clicks: 1, steps } } };
|
|
41
|
+
fs.writeFileSync(path.join(d, 'click_paths.json'), JSON.stringify(cp), 'utf8');
|
|
42
|
+
return d;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function doApply(ws, items) {
|
|
46
|
+
fs.writeFileSync(path.join(ws, 'nl_hints_answers.json'), JSON.stringify({ items }), 'utf8');
|
|
47
|
+
nl.apply(ws);
|
|
48
|
+
return JSON.parse(fs.readFileSync(path.join(ws, 'click_paths.json'), 'utf8')).paths['n:T'].steps;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const STEP = { action: 'tap', label: 'Sky', target_id: 'n:T', target_kind: 'compose-route' };
|
|
52
|
+
const KEY = 'Sky|n:T';
|
|
53
|
+
|
|
54
|
+
test('apply() answer gate', () => {
|
|
55
|
+
let ws = mkWs([{ ...STEP }]);
|
|
56
|
+
let steps = doApply(ws, [{ key: KEY, nl_hint: '点击底部的安全防护入口', evidence: 'DevScreen.kt:173' }]);
|
|
57
|
+
assert.equal(steps[0].nl_hint, '点击底部的安全防护入口', 'answer with file:line evidence is applied');
|
|
58
|
+
|
|
59
|
+
ws = mkWs([{ ...STEP }]);
|
|
60
|
+
steps = doApply(ws, [{ key: KEY, nl_hint: '点击某处' }]);
|
|
61
|
+
assert.ok(!('nl_hint' in steps[0]), 'answer without evidence is rejected');
|
|
62
|
+
|
|
63
|
+
ws = mkWs([{ ...STEP }]);
|
|
64
|
+
steps = doApply(ws, [{ key: KEY, nl_hint: 'x', evidence: 'DevScreen.kt' }]);
|
|
65
|
+
assert.ok(!('nl_hint' in steps[0]), 'evidence without a line number is rejected');
|
|
66
|
+
|
|
67
|
+
ws = mkWs([{ ...STEP }]);
|
|
68
|
+
steps = doApply(ws, [{ key: KEY, action_override: 'long_press', evidence: 'SongItem.kt:179' }]);
|
|
69
|
+
assert.equal(steps[0].action, 'long_press', 'known gesture override applied');
|
|
70
|
+
assert.equal(steps[0].action_source, 'static:llm', 'override records its provenance');
|
|
71
|
+
|
|
72
|
+
ws = mkWs([{ ...STEP }]);
|
|
73
|
+
steps = doApply(ws, [{ key: KEY, action_override: 'triple_tap', evidence: 'A.kt:1' }]);
|
|
74
|
+
assert.equal(steps[0].action, 'tap', 'unknown gesture is rejected, step keeps its original action');
|
|
75
|
+
|
|
76
|
+
ws = mkWs([{ ...STEP }]);
|
|
77
|
+
doApply(ws, [{ key: KEY, not_clickable: true, evidence: 'Nav.kt:155' }]);
|
|
78
|
+
const vp = path.join(ws, 'nl_hints_vetoes.json');
|
|
79
|
+
assert.ok(fs.existsSync(vp), 'veto is persisted for path re-search');
|
|
80
|
+
const v = JSON.parse(fs.readFileSync(vp, 'utf8')).vetoes;
|
|
81
|
+
assert.ok(v.length && v[0].key === KEY, 'veto records the control key');
|
|
82
|
+
|
|
83
|
+
doApply(ws, [{ key: KEY, nl_hint: 'y', evidence: 'A.kt:2' }]);
|
|
84
|
+
assert.ok(!fs.existsSync(vp), 'retracted veto removes the stale file');
|
|
85
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Off-path edges (no click path ends with them) get their own nl_hints item, and apply stores the
|
|
2
|
+
// answer in click_paths.json `edge_hints` (coolmall 2026-10-29: Guide → Main had no hint, so every
|
|
3
|
+
// cold launch stayed on Guide).
|
|
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 nl from '../nl_hints.mjs';
|
|
10
|
+
|
|
11
|
+
const launch = { action: 'launch', label: null, target_id: 'r:Splash' };
|
|
12
|
+
const auto = (id) => ({ action: 'tap', label: id, target_id: id, label_source: 'code-name' });
|
|
13
|
+
const CP = { root: 'r:Splash', paths: {
|
|
14
|
+
'r:Splash': { steps: [launch] }, 'r:Guide': { steps: [launch, auto('r:Guide')] }, 'r:Main': { steps: [launch, auto('r:Main')] } } };
|
|
15
|
+
const UTG = {
|
|
16
|
+
nodes: [{ id: 'r:Splash', kind: 'compose-route' }, { id: 'r:Guide', kind: 'compose-route' }, { id: 'r:Main', kind: 'compose-route' }],
|
|
17
|
+
links: [
|
|
18
|
+
{ source: 'r:Splash', target: 'r:Main', trigger: 'onClick@s.kt:66', args: {} },
|
|
19
|
+
{ source: 'r:Guide', target: 'r:Main', trigger: 'onClick@g.kt:109', args: { via: 'viewmodel' } },
|
|
20
|
+
{ source: 'r:Guide', target: 'r:Main', trigger: 'onClick@g.kt:120', args: { label: '跳过' } },
|
|
21
|
+
{ source: 'r:Main', target: 'r:Guide', trigger: 'lifecycle@m.kt:1', args: {} },
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function ws() {
|
|
26
|
+
const d = fs.mkdtempSync(path.join(os.tmpdir(), 'nlo_'));
|
|
27
|
+
fs.writeFileSync(path.join(d, 'click_paths.json'), JSON.stringify(CP));
|
|
28
|
+
fs.writeFileSync(path.join(d, 'utg.json'), JSON.stringify(UTG));
|
|
29
|
+
return d;
|
|
30
|
+
}
|
|
31
|
+
const quiet = (fn) => { const w = process.stdout.write; process.stdout.write = () => true; try { return fn(); } finally { process.stdout.write = w; } };
|
|
32
|
+
|
|
33
|
+
test('only the label-less edge no click path ends with becomes an item', () => {
|
|
34
|
+
const d = ws();
|
|
35
|
+
try {
|
|
36
|
+
quiet(() => nl.extract(d, d));
|
|
37
|
+
const items = JSON.parse(fs.readFileSync(path.join(d, 'nl_hints_worklist.json'), 'utf8')).items;
|
|
38
|
+
const off = items.filter((x) => x.key.startsWith(nl.EDGE_KEY_PREFIX));
|
|
39
|
+
assert.deepEqual(off.map((x) => x.key), ['edge|r:Guide|r:Main|onClick@g.kt:109']);
|
|
40
|
+
assert.equal(off[0].parent_id, 'r:Guide');
|
|
41
|
+
assert.deepEqual(off[0].reasons, ['off-path']);
|
|
42
|
+
} finally { fs.rmSync(d, { recursive: true, force: true }); }
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('apply writes off-path answers to edge_hints, not to any step', () => {
|
|
46
|
+
const d = ws();
|
|
47
|
+
try {
|
|
48
|
+
fs.writeFileSync(path.join(d, 'nl_hints_answers.json'), JSON.stringify({ items: [
|
|
49
|
+
{ key: 'edge|r:Guide|r:Main|onClick@g.kt:109', nl_hint: '点击「跳过」', evidence: 'g.kt:109' }] }));
|
|
50
|
+
quiet(() => nl.apply(d));
|
|
51
|
+
const cp = JSON.parse(fs.readFileSync(path.join(d, 'click_paths.json'), 'utf8'));
|
|
52
|
+
assert.deepEqual(cp.edge_hints, { 'r:Guide|r:Main|onClick@g.kt:109': { nl_hint: '点击「跳过」' } });
|
|
53
|
+
assert.equal(cp.paths['r:Main'].steps[1].nl_hint, undefined);
|
|
54
|
+
} finally { fs.rmSync(d, { recursive: true, force: true }); }
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('a not_clickable answer for an off-path edge is kept in edge_hints with its evidence', () => {
|
|
58
|
+
const d = ws();
|
|
59
|
+
try {
|
|
60
|
+
fs.writeFileSync(path.join(d, 'nl_hints_answers.json'), JSON.stringify({ items: [
|
|
61
|
+
{ key: 'edge|r:Guide|r:Main|onClick@g.kt:109', not_clickable: true, evidence: 'g.kt:109' }] }));
|
|
62
|
+
quiet(() => nl.apply(d));
|
|
63
|
+
const cp = JSON.parse(fs.readFileSync(path.join(d, 'click_paths.json'), 'utf8'));
|
|
64
|
+
assert.deepEqual(cp.edge_hints, { 'r:Guide|r:Main|onClick@g.kt:109': { not_clickable: true, evidence: 'g.kt:109' } });
|
|
65
|
+
assert.equal(fs.existsSync(path.join(d, 'nl_hints_vetoes.json')), false, 'not a label|target veto');
|
|
66
|
+
} finally { fs.rmSync(d, { recursive: true, force: true }); }
|
|
67
|
+
});
|