@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,81 @@
|
|
|
1
|
+
// Port of test_template_method_layout.py: a page that declares its layout by RETURNING it.
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import * as lr from '../layout_resolve.mjs';
|
|
5
|
+
|
|
6
|
+
const TEMPLATE_PLUS_INFLATE = `
|
|
7
|
+
public class HomeFragment extends BaseBindFragment<FragmentHomeBinding> {
|
|
8
|
+
@Override protected int getLayoutId() { return R.layout.fragment_home; }
|
|
9
|
+
private void initView() {
|
|
10
|
+
View emptyView = LayoutInflater.from(getActivity())
|
|
11
|
+
.inflate(R.layout.view_home_no_data, null);
|
|
12
|
+
adapter.setEmptyView(emptyView);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
const SETCONTENTVIEW_PLUS_INFLATE = `
|
|
17
|
+
public class DetailActivity extends AppCompatActivity {
|
|
18
|
+
protected void onCreate(Bundle b) {
|
|
19
|
+
setContentView(R.layout.activity_detail);
|
|
20
|
+
header = LayoutInflater.from(this).inflate(R.layout.view_header, null);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
const CTOR_ARG = `
|
|
25
|
+
class NoteEditorFragment : Fragment(R.layout.fragment_note_editor) {
|
|
26
|
+
private fun showDialog() { layoutInflater.inflate(R.layout.dialog_tags, null) }
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
const KOTLIN_EXPR_BODY = `
|
|
30
|
+
class MineFragment : BaseBindFragment<FragmentMineBinding>() {
|
|
31
|
+
override fun getLayoutId(): Int = R.layout.fragment_mine
|
|
32
|
+
private fun empty() = layoutInflater.inflate(R.layout.view_no_data, null)
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
const KOTLIN_PROPERTY = `
|
|
36
|
+
class SettingsFragment : BaseFragment() {
|
|
37
|
+
override val layoutId: Int get() = R.layout.fragment_settings
|
|
38
|
+
private fun row() = inflate(R.layout.item_setting_row)
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
const KOTLIN_PLAIN_FIELD = `
|
|
42
|
+
class FeedFragment : BaseFragment() {
|
|
43
|
+
private val rowLayout = R.layout.item_feed_row
|
|
44
|
+
override fun onCreateView(i: LayoutInflater, c: ViewGroup?, s: Bundle?) =
|
|
45
|
+
i.inflate(R.layout.fragment_feed, c, false)
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
const TRUE_SHELL = `
|
|
49
|
+
public class LaunchProxyActivity extends Activity {
|
|
50
|
+
protected void onCreate(Bundle b) {
|
|
51
|
+
super.onCreate(b);
|
|
52
|
+
startActivity(new Intent(this, MainActivity.class));
|
|
53
|
+
finish();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
57
|
+
|
|
58
|
+
test('tier order', () => {
|
|
59
|
+
assert.deepEqual(lr.tieredLayoutNames(TEMPLATE_PLUS_INFLATE), ['fragment_home'], 'returned id outranks inflate');
|
|
60
|
+
assert.deepEqual(lr.tieredLayoutNames(SETCONTENTVIEW_PLUS_INFLATE), ['activity_detail'], 'setContentView outranks inflate');
|
|
61
|
+
assert.deepEqual(lr.tieredLayoutNames(CTOR_ARG), ['fragment_note_editor'], 'Fragment(R.layout.x) wins');
|
|
62
|
+
assert.deepEqual(lr.tieredLayoutNames(KOTLIN_EXPR_BODY), ['fragment_mine'], 'Kotlin expression-body override');
|
|
63
|
+
assert.deepEqual(lr.tieredLayoutNames(KOTLIN_PROPERTY), ['fragment_settings'], 'Kotlin override property');
|
|
64
|
+
assert.deepEqual(lr.tieredLayoutNames(KOTLIN_PLAIN_FIELD), ['fragment_feed'], 'plain val is NOT a declaration');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
test('declaresOwnLayout', () => {
|
|
68
|
+
for (const src of [TEMPLATE_PLUS_INFLATE, SETCONTENTVIEW_PLUS_INFLATE, KOTLIN_EXPR_BODY]) {
|
|
69
|
+
assert.equal(lr.declaresOwnLayout(src), true);
|
|
70
|
+
}
|
|
71
|
+
assert.equal(lr.declaresOwnLayout(TRUE_SHELL), false, 'a real UI-less launch shell');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('binding stem keeps acronym', () => {
|
|
75
|
+
assert.equal(lr.camelToSnake('ActivityWXEntry'), 'activity_wx_entry');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test('all_layout_names is a superset of the tiered answer', () => {
|
|
79
|
+
const all = new Set(lr.allLayoutNames(TEMPLATE_PLUS_INFLATE));
|
|
80
|
+
assert.ok(lr.tieredLayoutNames(TEMPLATE_PLUS_INFLATE).every((n) => all.has(n)));
|
|
81
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Port of test_template_title.py: format-template title salvage.
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { pageOwnTitle, templateFragments, _ANY_SR_RE, _TITLE_SR_RE } from '../label_resolve.mjs';
|
|
5
|
+
|
|
6
|
+
test('parameterized stringResource is visible to the scanner', () => {
|
|
7
|
+
const m = _ANY_SR_RE.exec('hint = stringResource(id = R.string.res_tmpl, count),');
|
|
8
|
+
assert.equal(m?.[1], 'res_tmpl');
|
|
9
|
+
const m2 = _ANY_SR_RE.exec('text = stringResource(id = R.string.res_plain)');
|
|
10
|
+
assert.equal(m2?.[1], 'res_plain');
|
|
11
|
+
const m3 = _TITLE_SR_RE.exec('title = stringResource(id = R.string.res_t, n)');
|
|
12
|
+
assert.equal(m3?.[1], 'res_t');
|
|
13
|
+
const m4 = _ANY_SR_RE.exec('stringResource(id = R.string.res_a, other)');
|
|
14
|
+
assert.equal(m4?.[1], 'res_a');
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('template splitting', () => {
|
|
18
|
+
assert.deepEqual(templateFragments('SHORT %d LONGERSUFFIX'), ['LONGERSUFFIX', 'SHORT']);
|
|
19
|
+
assert.deepEqual(templateFragments('BBB %d AAA'), ['AAA', 'BBB']);
|
|
20
|
+
assert.deepEqual(templateFragments('%s'), []);
|
|
21
|
+
assert.deepEqual(templateFragments('A %d B'), []);
|
|
22
|
+
assert.deepEqual(templateFragments('KEEPME %1$s'), ['KEEPME']);
|
|
23
|
+
assert.deepEqual(templateFragments(''), []);
|
|
24
|
+
assert.deepEqual(templateFragments(null), []);
|
|
25
|
+
assert.deepEqual(templateFragments('ONE %s TWO %s ONE'), ['ONE', 'TWO']);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const strings = { res_title: 'REALTITLE', res_tmpl: 'PREFIX %d SUFFIX' };
|
|
29
|
+
|
|
30
|
+
test('a real title still wins over any template', () => {
|
|
31
|
+
const src = 'fun DemoScreen() {\n Scaffold(\n' +
|
|
32
|
+
' title = stringResource(id = R.string.res_title),\n' +
|
|
33
|
+
' body = { Text(stringResource(id = R.string.res_tmpl, n)) }\n )\n}';
|
|
34
|
+
assert.deepEqual(pageOwnTitle(src, src.indexOf('fun DemoScreen'), strings), ['REALTITLE', 'res_title']);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('a template-only page salvages a literal fragment', () => {
|
|
38
|
+
const filler = ' // padding line to push the template past the title window\n'.repeat(12);
|
|
39
|
+
const src = 'fun DemoScreen() {\n Scaffold(\n title = "",\n' + filler +
|
|
40
|
+
' titleContent = { Header(hint = stringResource(id = R.string.res_tmpl, n)) }\n )\n}';
|
|
41
|
+
const [val] = pageOwnTitle(src, src.indexOf('fun DemoScreen'), strings);
|
|
42
|
+
assert.ok(val === 'PREFIX' || val === 'SUFFIX', String(val));
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('a page with no strings yields [null, null]', () => {
|
|
46
|
+
const src = 'fun DemoScreen() {\n Column { Icon(Icons.Back) }\n}';
|
|
47
|
+
assert.deepEqual(pageOwnTitle(src, src.indexOf('fun DemoScreen'), strings), [null, null]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// A page header whose title is passed positionally (`SimpleScaffold(onBackClick, "收藏夹")`).
|
|
51
|
+
import * as ctl from '../compose_titles.mjs';
|
|
52
|
+
test('positional title argument of a discovered page header is stamped', () => {
|
|
53
|
+
ctl._HEADER_TITLE_POS.set('SimpleScaffold', 1);
|
|
54
|
+
assert.deepEqual(ctl._positionalTitle('onBackClick, "收藏夹"', 1, {}, null), ['收藏夹', null]);
|
|
55
|
+
assert.deepEqual(ctl._positionalTitle('onBackClick, stringResource(R.string.bm)', 1, { bm: '收藏' }, null), ['收藏', 'R.string.bm']);
|
|
56
|
+
assert.deepEqual(ctl._positionalTitle('onBack = x, "收藏夹"', 1, {}, null), [null, null], 'a named arg before it: not positional');
|
|
57
|
+
assert.deepEqual(ctl._positionalTitle('onBackClick, title', 1, {}, null), [null, null], 'a runtime value is not a title');
|
|
58
|
+
// coolmall: `CenterTopAppBar(R.string.category, showBackIcon = false)`, an @StringRes Int title.
|
|
59
|
+
assert.deepEqual(ctl._positionalTitle('R.string.category, showBackIcon = false', 0, { category: '分类' }, null), ['分类', 'R.string.category']);
|
|
60
|
+
assert.deepEqual(ctl._positionalTitle('R.string.category.length', 0, { category: '分类' }, null), [null, null], 'an expression on the id is not a title');
|
|
61
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Port of test_trigger_id_spelling.py: binding-property receivers resolve to resource ids; trigger containers are widgets.
|
|
2
|
+
import { test, after } 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 fn from '../fragment_nav.mjs';
|
|
8
|
+
import * as lr from '../layout_resolve.mjs';
|
|
9
|
+
import * as vw from '../view_widgets.mjs';
|
|
10
|
+
|
|
11
|
+
const LAYOUT = `<?xml version="1.0" encoding="utf-8"?>
|
|
12
|
+
<androidx.constraintlayout.widget.ConstraintLayout
|
|
13
|
+
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
14
|
+
android:id="@+id/root">
|
|
15
|
+
<androidx.constraintlayout.widget.ConstraintLayout
|
|
16
|
+
android:id="@+id/cl_wechat_virtual"
|
|
17
|
+
android:layout_width="match_parent"
|
|
18
|
+
android:layout_height="wrap_content"/>
|
|
19
|
+
<androidx.constraintlayout.widget.ConstraintLayout
|
|
20
|
+
android:id="@+id/cl_decorative"
|
|
21
|
+
android:layout_width="match_parent"
|
|
22
|
+
android:layout_height="wrap_content"/>
|
|
23
|
+
<androidx.appcompat.widget.AppCompatTextView
|
|
24
|
+
android:id="@+id/viewPager"
|
|
25
|
+
android:text="Pager"/>
|
|
26
|
+
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
27
|
+
`;
|
|
28
|
+
const SOURCE = `
|
|
29
|
+
public class HomeFragment extends BaseBindFragment<FragmentHomeBinding> {
|
|
30
|
+
private void onEvent() {
|
|
31
|
+
db.clWechatVirtual.setOnClickListener(view -> startOpenUnimp(0));
|
|
32
|
+
uniMenuAdapter.setOnItemClickListener((a, v, p) -> startOpenUnimp(0));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
|
|
37
|
+
const project = fs.mkdtempSync(path.join(os.tmpdir(), 'tis-'));
|
|
38
|
+
after(() => fs.rmSync(project, { recursive: true, force: true }));
|
|
39
|
+
const lay = path.join(project, 'app', 'src', 'main', 'res', 'layout');
|
|
40
|
+
fs.mkdirSync(lay, { recursive: true });
|
|
41
|
+
const layoutPath = path.join(lay, 'fragment_home.xml');
|
|
42
|
+
fs.writeFileSync(layoutPath, LAYOUT, 'utf8');
|
|
43
|
+
const ids = lr.buildViewIdIndex(project);
|
|
44
|
+
|
|
45
|
+
test('view id resolution', () => {
|
|
46
|
+
for (const x of ['cl_wechat_virtual', 'cl_decorative', 'viewPager']) { assert.ok(ids.has(x), x); }
|
|
47
|
+
assert.equal(lr.resolveViewId('clWechatVirtual', ids), 'cl_wechat_virtual');
|
|
48
|
+
assert.equal(lr.resolveViewId('viewPager', ids), 'viewPager');
|
|
49
|
+
assert.equal(lr.resolveViewId('uniMenuAdapter', ids), 'uniMenuAdapter');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test('build_listener_spans normalises only with a project', () => {
|
|
53
|
+
const withProject = fn.buildListenerSpans(SOURCE, project).map(([v]) => v);
|
|
54
|
+
const without = fn.buildListenerSpans(SOURCE).map(([v]) => v);
|
|
55
|
+
assert.ok(withProject.includes('cl_wechat_virtual'), String(withProject));
|
|
56
|
+
assert.ok(withProject.includes('uniMenuAdapter'), String(withProject));
|
|
57
|
+
assert.deepEqual(without, ['clWechatVirtual', 'uniMenuAdapter']);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
test('a container named by a trigger is a widget', () => {
|
|
61
|
+
const plainIds = new Set(vw.scanLayout(layoutPath, project, {}, new Map(), 0).map((w) => w.view_id));
|
|
62
|
+
assert.ok(!plainIds.has('cl_wechat_virtual') && !plainIds.has('cl_decorative'));
|
|
63
|
+
const prom = new Map(vw.scanLayout(layoutPath, project, {}, new Map(), 0,
|
|
64
|
+
{ trigger_ids: new Set(['cl_wechat_virtual']) }).map((w) => [w.view_id, w]));
|
|
65
|
+
assert.ok(prom.has('cl_wechat_virtual'));
|
|
66
|
+
assert.equal(prom.get('cl_wechat_virtual').kind, 'action');
|
|
67
|
+
assert.ok(!prom.has('cl_decorative'));
|
|
68
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Port of test_ui_elements_action_override.py: the ui_elements converter must honour
|
|
2
|
+
// action_override from click_paths.json (nl_hints apply writes step.action + action_source).
|
|
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 { spawnSync } from 'node:child_process';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
|
|
11
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const TOOL = path.join(path.dirname(path.dirname(HERE)), 'tools', 'convert_static_utg_to_ui_elements.ts');
|
|
13
|
+
|
|
14
|
+
function write(ws, name, obj, jsonl = false) {
|
|
15
|
+
fs.writeFileSync(path.join(ws, name), jsonl ? obj.map((r) => JSON.stringify(r) + '\n').join('') : JSON.stringify(obj), 'utf8');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** 2-page graph with ONE edge. utg.json says tap; click_paths (when present) says long_press. */
|
|
19
|
+
function workspace(ws, withOverride = true) {
|
|
20
|
+
const nodes = [
|
|
21
|
+
{ id: 'activity:MainActivity', kind: 'activity', label: 'MainActivity', declared_at: 'Main.java:1', status: 'static-only', widgets: [] },
|
|
22
|
+
{ id: 'fragment:SettingsFragment', kind: 'fragment', label: 'Settings', declared_at: 'Settings.java:1', status: 'static-only', widgets: [] },
|
|
23
|
+
];
|
|
24
|
+
const edges = [{
|
|
25
|
+
source: 'activity:MainActivity', target: 'fragment:SettingsFragment', mechanism: 'fragment-transaction',
|
|
26
|
+
trigger: 'onMenuItemSelected@Main.java:42',
|
|
27
|
+
args: { via: 'instantiation', action: 'tap', label: 'Settings' }, provenance: 'static:llm', confidence: 0.9,
|
|
28
|
+
}];
|
|
29
|
+
write(ws, 'nodes.jsonl', nodes, true);
|
|
30
|
+
write(ws, 'edges.jsonl', edges, true);
|
|
31
|
+
write(ws, 'utg.json', { directed: true, nodes, links: edges });
|
|
32
|
+
if (withOverride) {
|
|
33
|
+
write(ws, 'click_paths.json', {
|
|
34
|
+
root: 'activity:MainActivity',
|
|
35
|
+
paths: { 'fragment:SettingsFragment': {
|
|
36
|
+
clicks: 1, labels: ['Settings'], kind: 'fragment',
|
|
37
|
+
steps: [
|
|
38
|
+
{ action: 'launch', label: null, target_id: 'activity:MainActivity', target_kind: 'activity', guard: null },
|
|
39
|
+
{ action: 'long_press', label: 'Settings', target_id: 'fragment:SettingsFragment', target_kind: 'fragment',
|
|
40
|
+
guard: null, label_source: 'screen-text', action_source: 'static:llm' },
|
|
41
|
+
] } },
|
|
42
|
+
unreachable: [],
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function convert(ws) {
|
|
48
|
+
const out = path.join(ws, 'ui_elements.json');
|
|
49
|
+
const p = spawnSync(process.execPath, [TOOL, '--input', ws, '--out', out], { encoding: 'utf8' });
|
|
50
|
+
if (p.status !== 0) { console.log(p.stdout + p.stderr); return null; }
|
|
51
|
+
return JSON.parse(fs.readFileSync(out, 'utf8'));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function withTmp(fn) {
|
|
55
|
+
const ws = fs.mkdtempSync(path.join(os.tmpdir(), 'uiao_'));
|
|
56
|
+
try { fn(ws); } finally { fs.rmSync(ws, { recursive: true, force: true }); }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
test('click_paths action override reaches ui_elements.json', () => withTmp((ws) => {
|
|
60
|
+
workspace(ws, true);
|
|
61
|
+
const d = convert(ws);
|
|
62
|
+
assert.ok(d !== null, 'converter ran');
|
|
63
|
+
if (d && d.edges.length) {
|
|
64
|
+
const e = d.edges[0];
|
|
65
|
+
assert.equal(e.gesture, 'LONG_PRESS', 'action override reaches ui_elements.json (gesture=LONG_PRESS)');
|
|
66
|
+
assert.ok(e.from === 'activity_MainActivity' && e.to === 'fragment_SettingsFragment', 'the override landed on the correct edge');
|
|
67
|
+
assert.equal(e.gesture, 'LONG_PRESS', 'click_paths long_press wins (gesture field present)');
|
|
68
|
+
}
|
|
69
|
+
}));
|
|
70
|
+
|
|
71
|
+
test('absent click_paths falls back to utg.json', () => withTmp((ws) => {
|
|
72
|
+
workspace(ws, false);
|
|
73
|
+
const d = convert(ws);
|
|
74
|
+
assert.ok(d !== null && d.edges.length === 1, 'absent click_paths.json still converts the graph');
|
|
75
|
+
if (d && d.edges.length) {
|
|
76
|
+
assert.equal(d.edges[0].gesture ?? null, null, 'fallback to utg.json when click_paths is absent (no gesture field = CLICK)');
|
|
77
|
+
}
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
test('no override when action_source is absent', () => withTmp((ws) => {
|
|
81
|
+
workspace(ws, true);
|
|
82
|
+
const cpPath = path.join(ws, 'click_paths.json');
|
|
83
|
+
const cp = JSON.parse(fs.readFileSync(cpPath, 'utf8'));
|
|
84
|
+
cp.paths['fragment:SettingsFragment'].steps[1].action = 'tap';
|
|
85
|
+
delete cp.paths['fragment:SettingsFragment'].steps[1].action_source;
|
|
86
|
+
write(ws, 'click_paths.json', cp);
|
|
87
|
+
const d = convert(ws);
|
|
88
|
+
if (d && d.edges.length) {
|
|
89
|
+
assert.equal(d.edges[0].gesture ?? null, null, 'no override when action_source is absent (no gesture field = CLICK)');
|
|
90
|
+
}
|
|
91
|
+
}));
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Port of test_ui_elements_flow_filter.py: the converter's flow filter is a BLACKLIST of
|
|
2
|
+
// non-gesture trigger prefixes mirroring click_paths' _NON_GESTURE_TRIGGERS; pins parity,
|
|
3
|
+
// behaviour on every emitted prefix family, and mechanism-map coverage.
|
|
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 { _NON_GESTURE_TRIGGERS } from '../click_paths.mjs';
|
|
12
|
+
|
|
13
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
14
|
+
const SCRIPTS = path.dirname(HERE);
|
|
15
|
+
const SKILL = path.dirname(SCRIPTS);
|
|
16
|
+
const TS = path.join(SKILL, 'tools', 'convert_static_utg_to_ui_elements.ts');
|
|
17
|
+
|
|
18
|
+
test('blacklist parity (click_paths <-> convert_static_utg_to_ui_elements.ts)', () => {
|
|
19
|
+
const src = fs.readFileSync(TS, 'utf8');
|
|
20
|
+
const m = /const NON_GESTURE_TRIGGERS\s*=\s*\[([^\]]*)\]/.exec(src);
|
|
21
|
+
assert.ok(m, 'found NON_GESTURE_TRIGGERS in the TS source');
|
|
22
|
+
const tsList = [...m[1].matchAll(/"([^"]+)"/g)].map((x) => x[1]);
|
|
23
|
+
assert.deepEqual(tsList, [..._NON_GESTURE_TRIGGERS], `TS mirror matches Python authority ${_NON_GESTURE_TRIGGERS}`);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// [trigger, gesture, action, should_emit_flow, why]
|
|
27
|
+
const EDGE_CASES = [
|
|
28
|
+
['onClick@F.kt:1', 'tap', '', true, 'compose/activity onClick'],
|
|
29
|
+
['onLongClick@F.kt:2', 'long_press', '', true, 'long-press variant'],
|
|
30
|
+
['inflateMenu@menu.xml:3', 'tap', '', true, 'menu_nav overflow menu'],
|
|
31
|
+
['onMenuItemSelected@F.kt:4', 'tap', '', true, 'menu_nav item handler'],
|
|
32
|
+
['section@F.kt:5', 'tap', '', true, 'presenter_nav section'],
|
|
33
|
+
['catalog@F.kt:6', 'tap', '', true, 'presenter_nav page catalog'],
|
|
34
|
+
['register(MyView)@F.kt:7', 'tap', '', true, 'registry_nav ViewManager registry'],
|
|
35
|
+
['SettingsFragment@F.kt:8', 'tap', '', true, 'fragment_nav bare host symbol name'],
|
|
36
|
+
['prefs_root@prefs.xml:9', 'tap', '', true, 'preference_nav xml name'],
|
|
37
|
+
['pager@F.kt:10', 'tap', 'swipe-up', true, 'pager swipe (direction in args.action)'],
|
|
38
|
+
['ViewManager.setRoot', 'tap', '', true, 'trigger with no @file:line at all'],
|
|
39
|
+
['', 'tap', '', true, 'edge with NO trigger — under-specified is not fabricated'],
|
|
40
|
+
['startDestination@F.kt:11', 'tap', '', false, 'NavHost initial route'],
|
|
41
|
+
['render-branch@F.kt:12', 'tap', '', false, 'recomposition under a state test'],
|
|
42
|
+
['createFragment@F.kt:13', 'tap', '', false, 'lifecycle commit'],
|
|
43
|
+
['pager@F.kt:14', 'tap', 'default', false, 'pager INITIAL page — renders with host, no gesture'],
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
function writeWs(ws) {
|
|
47
|
+
const nodes = [{ id: 'activity:Home', kind: 'activity', label: 'Home',
|
|
48
|
+
widgets: [{ widget: 'Button', kind: 'action', text: '去详情', at: 'F.kt:99' }] }];
|
|
49
|
+
const edges = [];
|
|
50
|
+
EDGE_CASES.forEach(([trig, gesture, action], i) => {
|
|
51
|
+
const tid = `compose-route:T${i}`;
|
|
52
|
+
nodes.push({ id: tid, kind: 'compose-route', label: `T${i}`, expected: { title_any: [`页面${i}`] } });
|
|
53
|
+
const args = { label: `控件${i}`, gesture };
|
|
54
|
+
if (action) { args.action = action; }
|
|
55
|
+
edges.push({ source: 'activity:Home', target: tid, mechanism: 'compose-navigate', trigger: trig, guard: null, args });
|
|
56
|
+
});
|
|
57
|
+
nodes.push({ id: 'compose-route:PAY', kind: 'compose-route', label: 'PAY' });
|
|
58
|
+
edges.push({ source: 'activity:Home', target: 'compose-route:PAY', mechanism: 'compose-navigate',
|
|
59
|
+
trigger: 'onClick@F.kt:50', guard: null, args: { label: '订阅', gesture: 'tap' } });
|
|
60
|
+
fs.writeFileSync(path.join(ws, 'nodes.jsonl'), nodes.map((n) => JSON.stringify(n) + '\n').join(''), 'utf8');
|
|
61
|
+
fs.writeFileSync(path.join(ws, 'edges.jsonl'), edges.map((e) => JSON.stringify(e) + '\n').join(''), 'utf8');
|
|
62
|
+
fs.writeFileSync(path.join(ws, 'phase_plan_nodes.json'), JSON.stringify({
|
|
63
|
+
phases: [{ name: 'BYPASS_paywall', level: 'BYPASS', desc: 'paywalled', count: 1 }],
|
|
64
|
+
nodes: [{ id: 'compose-route:PAY', level: 'BYPASS', phase: 'BYPASS_paywall', desc: 'paywalled' }] }), 'utf8');
|
|
65
|
+
fs.writeFileSync(path.join(ws, 'e2.log'),
|
|
66
|
+
"# orphan overlays (no show-site found, needs manual wiring): ['overlay:Ghost']\n", 'utf8');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
test('flow filter behaviour (synthetic workspace through the real converter)', () => {
|
|
70
|
+
assert.ok(fs.existsSync(TS), `converter exists at ${TS}`);
|
|
71
|
+
const ws = fs.mkdtempSync(path.join(os.tmpdir(), 'uielem_'));
|
|
72
|
+
try {
|
|
73
|
+
writeWs(ws);
|
|
74
|
+
const out = path.join(ws, 'ui_elements.json');
|
|
75
|
+
const r = spawnSync(process.execPath, [TS, '--input', ws, '--out', out], { encoding: 'utf8' });
|
|
76
|
+
assert.equal(r.status, 0, `converter exited 0 (got ${r.status}) ${(r.stderr || r.stdout).trim().slice(0, 400)}`);
|
|
77
|
+
const doc = JSON.parse(fs.readFileSync(out, 'utf8'));
|
|
78
|
+
const diag = JSON.parse(fs.readFileSync(out.slice(0, -5) + '.diagnostics.json', 'utf8'));
|
|
79
|
+
const emitted = new Set(doc.edges.map((e) => e.to));
|
|
80
|
+
EDGE_CASES.forEach(([trig, , action, keep, why], i) => {
|
|
81
|
+
const label = `${keep ? 'keep' : 'skip'} ${trig || '(no trigger)'}` + (action ? ` action=${action}` : '') + ` — ${why}`;
|
|
82
|
+
assert.equal(emitted.has(`compose_route_T${i}`), keep, label);
|
|
83
|
+
});
|
|
84
|
+
assert.ok(!emitted.has('compose_route_PAY'), 'skip edge into a BYPASS node');
|
|
85
|
+
assert.ok(diag.gaps.some((g) => g.type === 'page' && g.location === 'compose_route_PAY'), 'BYPASS node recorded as a type=page gap');
|
|
86
|
+
assert.ok(!Object.hasOwn(doc.pages, 'compose_route_PAY'), 'BYPASS node excluded from pages');
|
|
87
|
+
const sw = doc.edges.filter((e) => e.gesture === 'SWIPE');
|
|
88
|
+
assert.ok(sw.length === 1 && sw[0].direction === 'swipe-up', 'SWIPE edge carries direction from args.action');
|
|
89
|
+
assert.ok(doc.edges.filter((e) => e.gesture !== 'SWIPE').every((e) => !('direction' in e)), 'non-swipe edges carry no direction');
|
|
90
|
+
const lp = doc.edges.filter((e) => e.gesture === 'LONG_PRESS');
|
|
91
|
+
assert.equal(lp.length, 1, 'args.gesture=long_press maps to LONG_PRESS');
|
|
92
|
+
assert.ok(diag.flows.every((f) => ['CLICK', 'SWIPE', 'LONG_PRESS'].includes(f.event_type)),
|
|
93
|
+
'diagnostics flows carry an event_type from the known set');
|
|
94
|
+
const skips = /edges skipped\s*=\s*(\d+)/.exec(r.stdout);
|
|
95
|
+
assert.ok(skips && Number(skips[1]) === 5, 'all 5 skipped edges reported in the stdout breakdown');
|
|
96
|
+
} finally { fs.rmSync(ws, { recursive: true, force: true }); }
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('mechanism map covers the documented domain', () => {
|
|
100
|
+
const src = fs.readFileSync(TS, 'utf8');
|
|
101
|
+
const m = /const MECHANISM_MAP[^{]*\{([\s\S]*?)\n\};/.exec(src);
|
|
102
|
+
assert.ok(m, 'found MECHANISM_MAP in the TS source');
|
|
103
|
+
const mapped = new Set([...m[1].matchAll(/"([A-Za-z-]+)":/g)].map((x) => x[1]));
|
|
104
|
+
const documented = ['startActivity-explicit', 'startActivity-implicit', 'fragment-transaction', 'nav-component-action',
|
|
105
|
+
'voyager-push', 'compose-navigate', 'compose-navigate-param', 'open-overlay', 'enter-mode', 'data-variant',
|
|
106
|
+
'media-browse-select', 'media-play'];
|
|
107
|
+
const missing = documented.filter((x) => !mapped.has(x)).sort();
|
|
108
|
+
assert.deepEqual(missing, [], `all ${documented.length} documented mechanisms mapped`);
|
|
109
|
+
assert.ok(src.includes('|| "Navigate_unknown"'), 'unknown mechanism falls back to an explicit Navigate_unknown');
|
|
110
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// Port of test_ui_elements_nl_hint_key.py: an nl_hint answered for an edge reaches
|
|
2
|
+
// ui_elements.json via click_paths.json's edge key (consecutive steps[].target_id).
|
|
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 { spawnSync } from 'node:child_process';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
|
|
11
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const TOOL = path.join(path.dirname(path.dirname(HERE)), 'tools', 'convert_static_utg_to_ui_elements.ts');
|
|
13
|
+
const HINT = 'in the note list, tap any note to open its detail';
|
|
14
|
+
|
|
15
|
+
function write(ws, name, obj, jsonl = false) {
|
|
16
|
+
fs.writeFileSync(path.join(ws, name), jsonl ? obj.map((r) => JSON.stringify(r) + '\n').join('') : JSON.stringify(obj), 'utf8');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** A minimal 2-page graph with ONE edge whose args carry no label. */
|
|
20
|
+
function workspace(ws, { with_click_paths = true, with_answers = true } = {}) {
|
|
21
|
+
const nodes = [
|
|
22
|
+
{ id: 'activity:MainActivity', kind: 'activity', label: 'MainActivity', declared_at: 'Main.java:1', status: 'static-only', widgets: [] },
|
|
23
|
+
{ id: 'fragment:DetailFragment', kind: 'fragment', label: 'DetailFragment', declared_at: 'Detail.java:1', status: 'static-only', widgets: [] },
|
|
24
|
+
];
|
|
25
|
+
const edges = [{
|
|
26
|
+
source: 'activity:MainActivity', target: 'fragment:DetailFragment', mechanism: 'fragment-transaction',
|
|
27
|
+
trigger: 'onClick@Main.java:500', args: { via: 'instantiation', action: 'tap' }, provenance: 'static:llm', confidence: 0.9,
|
|
28
|
+
}];
|
|
29
|
+
write(ws, 'nodes.jsonl', nodes, true);
|
|
30
|
+
write(ws, 'edges.jsonl', edges, true);
|
|
31
|
+
write(ws, 'utg.json', { directed: true, nodes, links: edges });
|
|
32
|
+
if (with_answers) {
|
|
33
|
+
write(ws, 'nl_hints_answers.json', { items: [
|
|
34
|
+
{ key: 'DetailFragment|fragment:DetailFragment', nl_hint: HINT, evidence: 'Main.java:500' }] });
|
|
35
|
+
}
|
|
36
|
+
if (with_click_paths) {
|
|
37
|
+
write(ws, 'click_paths.json', {
|
|
38
|
+
root: 'activity:MainActivity',
|
|
39
|
+
paths: { 'fragment:DetailFragment': {
|
|
40
|
+
clicks: 1, labels: ['DetailFragment'], kind: 'fragment',
|
|
41
|
+
steps: [
|
|
42
|
+
{ action: 'launch', label: null, target_id: 'activity:MainActivity', target_kind: 'activity', guard: null },
|
|
43
|
+
{ action: 'tap', label: 'DetailFragment', target_id: 'fragment:DetailFragment', target_kind: 'fragment',
|
|
44
|
+
guard: null, label_source: 'code-name', nl_hint: HINT },
|
|
45
|
+
] } },
|
|
46
|
+
unreachable: [],
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function convert(ws) {
|
|
52
|
+
const out = path.join(ws, 'ui_elements.json');
|
|
53
|
+
const p = spawnSync(process.execPath, [TOOL, '--input', ws, '--out', out], { encoding: 'utf8' });
|
|
54
|
+
if (p.status !== 0) { console.log(p.stdout + p.stderr); return null; }
|
|
55
|
+
return JSON.parse(fs.readFileSync(out, 'utf8'));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function withTmp(fn) {
|
|
59
|
+
const ws = fs.mkdtempSync(path.join(os.tmpdir(), 'uinl_'));
|
|
60
|
+
try { fn(ws); } finally { fs.rmSync(ws, { recursive: true, force: true }); }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
test('hint reaches ui_elements.json via the click_paths edge key', () => withTmp((ws) => {
|
|
64
|
+
workspace(ws);
|
|
65
|
+
const d = convert(ws);
|
|
66
|
+
assert.ok(d !== null, 'converter ran');
|
|
67
|
+
if (d) {
|
|
68
|
+
assert.ok(JSON.stringify(d).includes(HINT), 'hint reaches ui_elements.json via the click_paths edge key');
|
|
69
|
+
const hinted = d.edges.filter((e) => String(e.hint || '') === HINT);
|
|
70
|
+
assert.equal(hinted.length, 1, 'the hint lands on exactly one edge');
|
|
71
|
+
if (hinted.length) {
|
|
72
|
+
assert.ok(hinted[0].from === 'activity_MainActivity' && hinted[0].to === 'fragment_DetailFragment',
|
|
73
|
+
'it lands on the edge it was answered for');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}));
|
|
77
|
+
|
|
78
|
+
test('absent click_paths.json still converts the graph', () => withTmp((ws) => {
|
|
79
|
+
workspace(ws, { with_click_paths: false });
|
|
80
|
+
const d = convert(ws);
|
|
81
|
+
assert.ok(d !== null && d.edges.length === 1, 'absent click_paths.json still converts the graph');
|
|
82
|
+
}));
|
|
83
|
+
|
|
84
|
+
test('a run with no hints at all converts the graph', () => withTmp((ws) => {
|
|
85
|
+
workspace(ws, { with_click_paths: false, with_answers: false });
|
|
86
|
+
const d = convert(ws);
|
|
87
|
+
assert.ok(d !== null && d.edges.length === 1, 'a run with no hints at all converts the graph');
|
|
88
|
+
if (d) { assert.ok(!JSON.stringify(d).includes(HINT), 'no hint is invented when none was answered'); }
|
|
89
|
+
}));
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// Port of test_uiless_host_fold.py — a bare-container launcher Activity folds into the fragment
|
|
2
|
+
// it auto-loads (assemble._foldUilessHosts via enrichNodesAndEdges); a chrome host does not.
|
|
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 * as assemble from '../assemble.mjs';
|
|
9
|
+
|
|
10
|
+
const MAIN_ACT_JAVA = `
|
|
11
|
+
package com.example.app;
|
|
12
|
+
public class MainActivity extends AppCompatActivity {
|
|
13
|
+
protected void onCreate(Bundle s) {
|
|
14
|
+
binding = ActivityMainBinding.inflate(getLayoutInflater());
|
|
15
|
+
setContentView(binding.getRoot());
|
|
16
|
+
getSupportFragmentManager().beginTransaction()
|
|
17
|
+
.replace(binding.placeHolder.getId(), MainFragment.newInstance()).commit();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
const ACTIVITY_MAIN_XML = `<?xml version="1.0" encoding="utf-8"?>
|
|
22
|
+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
23
|
+
android:id="@+id/placeHolder"
|
|
24
|
+
android:layout_width="match_parent" android:layout_height="match_parent" />
|
|
25
|
+
`;
|
|
26
|
+
const ACTIVITY_CHROME_JAVA = `
|
|
27
|
+
package com.example.app;
|
|
28
|
+
public class ChromeActivity extends AppCompatActivity {
|
|
29
|
+
protected void onCreate(Bundle s) {
|
|
30
|
+
setContentView(R.layout.activity_chrome);
|
|
31
|
+
getSupportFragmentManager().beginTransaction()
|
|
32
|
+
.replace(R.id.container, ChromeFragment.newInstance()).commit();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
const ACTIVITY_CHROME_XML = `<?xml version="1.0" encoding="utf-8"?>
|
|
37
|
+
<androidx.constraintlayout.widget.ConstraintLayout
|
|
38
|
+
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
39
|
+
android:layout_width="match_parent" android:layout_height="match_parent">
|
|
40
|
+
<androidx.appcompat.widget.Toolbar android:id="@+id/toolbar"
|
|
41
|
+
android:layout_width="match_parent" android:layout_height="wrap_content" />
|
|
42
|
+
<FrameLayout android:id="@+id/container"
|
|
43
|
+
android:layout_width="match_parent" android:layout_height="0dp" />
|
|
44
|
+
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
function writeProject(root) {
|
|
48
|
+
const src = path.join(root, 'app', 'src', 'main', 'java', 'com', 'example', 'app');
|
|
49
|
+
const lay = path.join(root, 'app', 'src', 'main', 'res', 'layout');
|
|
50
|
+
fs.mkdirSync(src, { recursive: true }); fs.mkdirSync(lay, { recursive: true });
|
|
51
|
+
fs.writeFileSync(path.join(src, 'MainActivity.java'), MAIN_ACT_JAVA, 'utf8');
|
|
52
|
+
fs.writeFileSync(path.join(src, 'ChromeActivity.java'), ACTIVITY_CHROME_JAVA, 'utf8');
|
|
53
|
+
fs.writeFileSync(path.join(lay, 'activity_main.xml'), ACTIVITY_MAIN_XML, 'utf8');
|
|
54
|
+
fs.writeFileSync(path.join(lay, 'activity_chrome.xml'), ACTIVITY_CHROME_XML, 'utf8');
|
|
55
|
+
return root;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function fixtureGraph() {
|
|
59
|
+
const nodes = {
|
|
60
|
+
'activity:MainActivity': { id: 'activity:MainActivity', kind: 'activity', label: 'MainActivity',
|
|
61
|
+
declared_at: 'app/src/main/java/com/example/app/MainActivity.java:2',
|
|
62
|
+
launch_hint: { is_launcher: true, exported: true }, exported: true },
|
|
63
|
+
'fragment:MainFragment': { id: 'fragment:MainFragment', kind: 'fragment', label: 'MainFragment',
|
|
64
|
+
declared_at: 'app/src/main/java/com/example/app/MainFragment.java:1' },
|
|
65
|
+
'activity:ChromeActivity': { id: 'activity:ChromeActivity', kind: 'activity', label: 'ChromeActivity',
|
|
66
|
+
declared_at: 'app/src/main/java/com/example/app/ChromeActivity.java:2',
|
|
67
|
+
launch_hint: { is_launcher: false, exported: false }, exported: false },
|
|
68
|
+
'fragment:ChromeFragment': { id: 'fragment:ChromeFragment', kind: 'fragment', label: 'ChromeFragment',
|
|
69
|
+
declared_at: 'app/src/main/java/com/example/app/ChromeFragment.java:1' },
|
|
70
|
+
};
|
|
71
|
+
const edges = [
|
|
72
|
+
{ source: 'activity:MainActivity', target: 'fragment:MainFragment', mechanism: 'fragment-transaction',
|
|
73
|
+
args: { via: 'auto-load', action: 'default' } },
|
|
74
|
+
{ source: 'activity:ChromeActivity', target: 'fragment:ChromeFragment', mechanism: 'fragment-transaction',
|
|
75
|
+
args: { via: 'auto-load', action: 'default' } },
|
|
76
|
+
];
|
|
77
|
+
return [nodes, edges];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
test('UI-less host fold', () => {
|
|
81
|
+
const proj = writeProject(fs.mkdtempSync(path.join(os.tmpdir(), 'uhf')));
|
|
82
|
+
try {
|
|
83
|
+
const [nodes, edges] = fixtureGraph();
|
|
84
|
+
assemble.enrichNodesAndEdges(nodes, edges, proj);
|
|
85
|
+
assert.ok(!('activity:MainActivity' in nodes), 'UI-less MainActivity removed from node set');
|
|
86
|
+
const mf = nodes['fragment:MainFragment'] ?? {};
|
|
87
|
+
assert.equal((mf.host_activity ?? {}).id, 'activity:MainActivity', 'MainFragment carries host_activity attribute (folded shell)');
|
|
88
|
+
assert.equal(mf.entry, true, 'content fragment promoted to entry (graph root)');
|
|
89
|
+
assert.ok(!edges.some((e) => e.source === 'activity:MainActivity' || e.target === 'activity:MainActivity'),
|
|
90
|
+
'auto-load edge absorbed; no dangling edge references the shell');
|
|
91
|
+
assert.ok('activity:ChromeActivity' in nodes, 'ChromeActivity (has Toolbar UI) kept as its own node');
|
|
92
|
+
const cf = nodes['fragment:ChromeFragment'] ?? {};
|
|
93
|
+
assert.ok(!('host_activity' in cf), 'ChromeFragment NOT given a host_activity (host has real UI)');
|
|
94
|
+
const [nodes2, edges2] = fixtureGraph();
|
|
95
|
+
assemble.enrichNodesAndEdges(nodes2, edges2, null);
|
|
96
|
+
assert.ok('activity:MainActivity' in nodes2, 'no --project -> shell NOT removed (conservative skip)');
|
|
97
|
+
} finally { fs.rmSync(proj, { recursive: true, force: true }); }
|
|
98
|
+
});
|