@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,68 @@
|
|
|
1
|
+
// Host kind comes from the supertype chain, not a name suffix or a whole-file regex:
|
|
2
|
+
// a PreferenceActivity host is an `activity:` node, and menu_nav neither treats a class whose
|
|
3
|
+
// constructor takes an Activity as a page nor credits a base Activity instead of its subclasses.
|
|
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 pref from '../preference_nav.mjs';
|
|
10
|
+
import * as menu from '../menu_nav.mjs';
|
|
11
|
+
|
|
12
|
+
function project(files) {
|
|
13
|
+
const td = fs.mkdtempSync(path.join(os.tmpdir(), 'hostkind-'));
|
|
14
|
+
for (const [rel, text] of Object.entries(files)) {
|
|
15
|
+
const p = path.join(td, 'app', 'src', 'main', rel);
|
|
16
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
17
|
+
fs.writeFileSync(p, text);
|
|
18
|
+
}
|
|
19
|
+
return td;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const PREF_XML = '<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">\n' +
|
|
23
|
+
' <Preference android:key="k" android:title="T" android:fragment="a.Other"/>\n</PreferenceScreen>\n';
|
|
24
|
+
|
|
25
|
+
test('a PreferenceActivity host is named activity:, not fragment:', () => {
|
|
26
|
+
const td = project({
|
|
27
|
+
'java/a/SettingsHost.java': 'package a;\npublic class SettingsHost extends PreferenceActivity {\n' +
|
|
28
|
+
' protected void onCreate(Bundle b) {\n addPreferencesFromResource(R.xml.main_prefs);\n }\n}\n',
|
|
29
|
+
'res/xml/main_prefs.xml': PREF_XML,
|
|
30
|
+
});
|
|
31
|
+
try {
|
|
32
|
+
const [nodes, edges] = pref.buildRecords(td, {});
|
|
33
|
+
const ids = new Set([...nodes.map((n) => n.id), ...edges.map((e) => e.source)]);
|
|
34
|
+
assert.ok(!ids.has('fragment:SettingsHost'), 'an Activity host must not get a fragment: id');
|
|
35
|
+
assert.ok(edges.some((e) => e.source === 'activity:SettingsHost'), 'its edges start at activity:SettingsHost');
|
|
36
|
+
} finally { fs.rmSync(td, { recursive: true, force: true }); }
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const MENU_XML = '<menu xmlns:android="http://schemas.android.com/apk/res/android">\n' +
|
|
40
|
+
' <item android:id="@+id/go" android:title="Go"/>\n</menu>\n';
|
|
41
|
+
const DISPATCH = (cls) => ` public boolean onOptionsItemSelected(MenuItem item) {\n switch (item.getItemId()) {\n` +
|
|
42
|
+
` case R.id.go:\n startActivity(new Intent(this, Target${cls}.class));\n return true;\n` +
|
|
43
|
+
' }\n return false;\n }\n';
|
|
44
|
+
|
|
45
|
+
test('menu_nav: constructor param typed Activity is not a page; base Activity credits subclasses', () => {
|
|
46
|
+
const td = project({
|
|
47
|
+
'java/a/Helper.kt': 'package a\nclass Helper(private val activity: AppCompatActivity) {\n' +
|
|
48
|
+
' fun bind(menu: Menu) { activity.menuInflater.inflate(R.menu.helper_menu, menu) }\n}\n',
|
|
49
|
+
'java/a/BaseScreen.java': 'package a;\npublic abstract class BaseScreen extends AppCompatActivity {\n' +
|
|
50
|
+
' public boolean onCreateOptionsMenu(Menu m) {\n getMenuInflater().inflate(R.menu.base_menu, m);\n' +
|
|
51
|
+
' return true;\n }\n' + DISPATCH('Activity') + '}\n',
|
|
52
|
+
'java/a/HomeScreen.java': 'package a;\npublic class HomeScreen extends BaseScreen {}\n',
|
|
53
|
+
'java/a/TargetActivity.java': 'package a;\npublic class TargetActivity extends AppCompatActivity {}\n',
|
|
54
|
+
'res/menu/helper_menu.xml': MENU_XML,
|
|
55
|
+
'res/menu/base_menu.xml': MENU_XML,
|
|
56
|
+
});
|
|
57
|
+
try {
|
|
58
|
+
menu._setManifestActivities(new Set(['HomeScreen', 'TargetActivity']));
|
|
59
|
+
const [nodes, edges] = menu.buildRecords(td, {});
|
|
60
|
+
const ids = new Set([...nodes.map((n) => n.id), ...edges.flatMap((e) => [e.source, e.target])]);
|
|
61
|
+
assert.ok(!ids.has('activity:Helper'), 'a class taking an Activity ctor param is not an Activity page');
|
|
62
|
+
assert.ok(!ids.has('activity:BaseScreen'), 'an abstract base Activity is not a page');
|
|
63
|
+
assert.ok([...ids].some((id) => id.includes('HomeScreen')), "the base's menu is credited to its concrete subclass");
|
|
64
|
+
} finally {
|
|
65
|
+
menu._setManifestActivities(new Set());
|
|
66
|
+
fs.rmSync(td, { recursive: true, force: true });
|
|
67
|
+
}
|
|
68
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Port of test_hybrid_bundle_attribution.py: bundle attribution, the JS lexer, subpackage routes.
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import * as hb from '../hybrid_bundle.mjs';
|
|
5
|
+
import * as hp from '../hybrid_pages.mjs';
|
|
6
|
+
|
|
7
|
+
const Q = "'";
|
|
8
|
+
const sitesOf = (text) => [...text.matchAll(new RegExp(hp._NAV_CALL_RE.source, hp._NAV_CALL_RE.flags.replace('g', '') + 'g'))]
|
|
9
|
+
.map((m) => [m.index, m[1], hp._normRoute(m[2])]);
|
|
10
|
+
|
|
11
|
+
test('1: attribution over a concatenated bundle', () => {
|
|
12
|
+
const BUNDLE = 'const Aa={__name:"index",setup(){' +
|
|
13
|
+
'uni.navigateTo({url:"/pages/detail/detail"});' +
|
|
14
|
+
'uni.navigateTo({url:"/pages/mine/mine?from=index"})}};' +
|
|
15
|
+
'const Bb={__name:"detail",setup(){' +
|
|
16
|
+
'uni.redirectTo({url:"/pages/mine/mine"})}};' +
|
|
17
|
+
'const Cc=S(Bb,[["__scopeId","data-v-1"]]);' +
|
|
18
|
+
'function shared(){uni.navigateTo({url:"/pages/detail/detail"})}' +
|
|
19
|
+
'__definePage("pages/index/index",Aa),__definePage("pages/detail/detail",Cc);';
|
|
20
|
+
const ROUTES = ['pages/index/index', 'pages/detail/detail', 'pages/mine/mine'];
|
|
21
|
+
const [edges, st] = hb.attribute(BUNDLE, sitesOf(BUNDLE), ROUTES);
|
|
22
|
+
assert.equal(st.components, 2);
|
|
23
|
+
assert.deepEqual(edges, [
|
|
24
|
+
['pages/index/index', 'pages/detail/detail', 'navigateTo'],
|
|
25
|
+
['pages/index/index', 'pages/mine/mine', 'navigateTo'],
|
|
26
|
+
['pages/detail/detail', 'pages/mine/mine', 'redirectTo'],
|
|
27
|
+
]);
|
|
28
|
+
assert.equal(st.no_owner, 1);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('2: the lexer (regex literal, division, comments, unclosed)', () => {
|
|
32
|
+
const REGEX_BUNDLE = 'const Aa={__name:"x",setup(){' +
|
|
33
|
+
'const s=String(v).replace(/' + Q + '/g,"");' +
|
|
34
|
+
'uni.navigateTo({url:"/pages/b/b"})}};' +
|
|
35
|
+
'const Bb={__name:"y",setup(){' +
|
|
36
|
+
'uni.navigateTo({url:"/pages/c/c"})}};' +
|
|
37
|
+
'__definePage("pages/a/a",Aa),__definePage("pages/b/b",Bb);';
|
|
38
|
+
const [rEdges, rSt] = hb.attribute(REGEX_BUNDLE, sitesOf(REGEX_BUNDLE), ['pages/a/a', 'pages/b/b', 'pages/c/c']);
|
|
39
|
+
assert.ok(rEdges.some((e) => e.join('|') === 'pages/a/a|pages/b/b|navigateTo'), JSON.stringify(rEdges));
|
|
40
|
+
assert.equal(rSt.ambiguous, 0);
|
|
41
|
+
assert.equal(rSt.attributed, 2);
|
|
42
|
+
|
|
43
|
+
const DIV = 'const Aa={__name:"x",n:(a+b)/2,m:c/d,setup(){}};';
|
|
44
|
+
assert.equal(hb.exprEnd(DIV, DIV.indexOf('{')), DIV.length - 1);
|
|
45
|
+
assert.equal(hb.exprEnd('{a:1//x}\n};', 0), 10);
|
|
46
|
+
assert.equal(hb.exprEnd('{a:1/*}*/};', 0), 10);
|
|
47
|
+
assert.equal(hb.exprEnd('{a:{b:{c:1', 0), null);
|
|
48
|
+
|
|
49
|
+
const RUNAWAY = 'const Aa={__name:"x",setup(){uni.navigateTo({url:"/pages/b/b"})}};' +
|
|
50
|
+
'const Bb={{{;' +
|
|
51
|
+
'__definePage("pages/a/a",Aa),__definePage("pages/b/b",Bb);';
|
|
52
|
+
const [wEdges, wSt] = hb.attribute(RUNAWAY, sitesOf(RUNAWAY), ['pages/a/a', 'pages/b/b']);
|
|
53
|
+
assert.equal(wSt.components, 1);
|
|
54
|
+
assert.equal(wSt.ambiguous, 0);
|
|
55
|
+
assert.deepEqual(wEdges, [['pages/a/a', 'pages/b/b', 'navigateTo']]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('3: subpackage routes and route-record shape', () => {
|
|
59
|
+
const SUBPKG = 'const __uniConfig={"pages":[]};' +
|
|
60
|
+
'subPackages:[{root:"pages/call-log",pages:[' +
|
|
61
|
+
'{path:"call",style:{navigationBarTitleText:"通话记录"}},' +
|
|
62
|
+
'{path:"detail/callDetail",style:{navigationBarTitleText:"通话详情"}}]},' +
|
|
63
|
+
'{root:"pages/shopping",pages:[' +
|
|
64
|
+
'{path:"jingdong/list-index",style:{navigationBarTitleText:"京东"}}]}];';
|
|
65
|
+
const subs = hp._routesIn(SUBPKG);
|
|
66
|
+
assert.deepEqual(subs, ['pages/call-log/call', 'pages/call-log/detail/callDetail',
|
|
67
|
+
'pages/shopping/jingdong/list-index']);
|
|
68
|
+
const DATA = 'const __uniConfig={"pages":["pages/index/index"]};' +
|
|
69
|
+
'const icons=[{path:"static/img/a.png",w:2},{path:"static/img/b.png"}];';
|
|
70
|
+
assert.deepEqual(hp._routesIn(DATA), ['pages/index/index']);
|
|
71
|
+
const RECORDS = 'const __uniRoutes=[{"path":"pages/index/index","meta":{}},' +
|
|
72
|
+
'{"path":"pages/x/y","meta":{"navigationBar":{"titleText":"X"}}}];';
|
|
73
|
+
assert.deepEqual(hp._routesIn(RECORDS), ['pages/index/index', 'pages/x/y']);
|
|
74
|
+
});
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
// Port of test_hybrid_bundled_pages.py: a PRE-BUNDLED (or --wgt supplied) uni-app package is
|
|
2
|
+
// enumerable — its pages become nodes, the boundary flips to enumerable:true, launch/tab/route
|
|
3
|
+
// edges are emitted, and an unreadable supplied package is refused out loud.
|
|
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 crypto from 'node:crypto';
|
|
10
|
+
import * as hp from '../hybrid_pages.mjs';
|
|
11
|
+
import { buildRecords } from '../hybrid_scope.mjs';
|
|
12
|
+
import { jsonDumps } from '../_py.mjs';
|
|
13
|
+
import { writeZip } from './_zipw.mjs';
|
|
14
|
+
|
|
15
|
+
const VUE2_CONFIG = ';(function(){\n' +
|
|
16
|
+
'var __uniConfig = {"pages":["pages/index/index","pages/chat/chat","pages/mine/mine"],' +
|
|
17
|
+
'"globalStyle":{"navigationBarTextStyle":"black"},' +
|
|
18
|
+
'"tabBar":{"color":"#7A7E83","list":[' +
|
|
19
|
+
'{"pagePath":"pages/index/index","text":"首页","iconPath":"static/t1.png"},' +
|
|
20
|
+
'{"pagePath":"pages/mine/mine","text":"我的","iconPath":"static/t2.png"}]}};\n' +
|
|
21
|
+
'__uniConfig.page = {};\n' +
|
|
22
|
+
"__uniConfig.page['pages/index/index'] = {};\n" +
|
|
23
|
+
"__uniConfig.page['pages/index/index'].window = {\"navigationBarTitleText\":\"聊天列表\"};\n" +
|
|
24
|
+
"__uniConfig.page['pages/chat/chat'] = {};\n" +
|
|
25
|
+
"__uniConfig.page['pages/chat/chat'].window = {\"navigationBarTitleText\":\"聊天详情\"};\n" +
|
|
26
|
+
"__uniConfig.page['pages/mine/mine'] = {};\n" +
|
|
27
|
+
"__uniConfig.page['pages/mine/mine'].window = {\"navigationBarTitleText\":\"个人中心\"};\n" +
|
|
28
|
+
'})();\n';
|
|
29
|
+
const VUE3_CONFIG = 'const __uniRoutes = [' +
|
|
30
|
+
'{path:"pages/index/index",meta:{isQuit:true},window:{navigationBarTitleText:"首页"}},' +
|
|
31
|
+
'{path:"pages/detail/detail",meta:{},window:{navigationBarTitleText:"详情"}}' +
|
|
32
|
+
'].map(t=>t);\n';
|
|
33
|
+
const CHAT_CHUNK = '\n"use strict";\nvar _r = {methods:{go:function(){uni.navigateTo({url:"/pages/mine/mine?from=chat"})}}};\nmodule.exports = _r;\n';
|
|
34
|
+
const BUNDLE_ALL = '\n"use strict";\nuni.navigateTo({url:"/pages/chat/chat"});\nuni.redirectTo({url:"/pages/mine/mine"});\n';
|
|
35
|
+
const pj = (o) => jsonDumps(o);
|
|
36
|
+
const MANIFEST = pj({ id: '__UNI__A1B2C3D', name: 'WeChat Sim', version: { name: '1.0.0', code: 100 } });
|
|
37
|
+
const NODESET = [{ id: 'fragment:HomeFragment', label: 'HomeFragment', kind: 'fragment' }];
|
|
38
|
+
const HOST_PAGE = `package com.example.app.ui;
|
|
39
|
+
|
|
40
|
+
import io.dcloud.feature.sdk.DCUniMPSDK;
|
|
41
|
+
|
|
42
|
+
public class HomeFragment extends BaseFragment {
|
|
43
|
+
private void open() {
|
|
44
|
+
db.clTile.setOnClickListener(v ->
|
|
45
|
+
DCUniMPSDK.getInstance().openUniMP(getContext(), appId, config));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
`;
|
|
49
|
+
|
|
50
|
+
function bareProject() {
|
|
51
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'hbp-'));
|
|
52
|
+
const src = path.join(tmp, 'app', 'src', 'main', 'java', 'com', 'example', 'ui');
|
|
53
|
+
fs.mkdirSync(src, { recursive: true });
|
|
54
|
+
fs.writeFileSync(path.join(src, 'HomeFragment.java'), HOST_PAGE);
|
|
55
|
+
const ws = path.join(tmp, 'ws');
|
|
56
|
+
fs.mkdirSync(ws);
|
|
57
|
+
fs.writeFileSync(path.join(ws, 'nodes.jsonl'), NODESET.map((r) => pj(r) + '\n').join(''));
|
|
58
|
+
return [tmp, ws];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function makeProject(www, appidDir = '__UNI__A1B2C3D', asWgt = false, second = null) {
|
|
62
|
+
const [tmp, ws] = bareProject();
|
|
63
|
+
const assets = path.join(tmp, 'app', 'src', 'main', 'assets', 'apps');
|
|
64
|
+
const writePkg = (d, files, wgt) => {
|
|
65
|
+
if (wgt) {
|
|
66
|
+
fs.mkdirSync(assets, { recursive: true });
|
|
67
|
+
writeZip(path.join(assets, d + '.wgt'), Object.entries(files).map(([n, b]) => ['www/' + n, b]));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
for (const [n, body] of Object.entries(files)) {
|
|
71
|
+
const p = path.join(assets, d, 'www', ...n.split('/'));
|
|
72
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
73
|
+
fs.writeFileSync(p, body);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
writePkg(appidDir, www, asWgt);
|
|
77
|
+
if (second) { writePkg(second[0], second[1], false); }
|
|
78
|
+
return [tmp, ws];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
test('1: unpacked Vue2 package with a per-page chunk', () => {
|
|
82
|
+
const [proj, ws] = makeProject({ 'manifest.json': MANIFEST, 'app-config-service.js': VUE2_CONFIG, 'pages/chat/chat.js': CHAT_CHUNK });
|
|
83
|
+
const [nodes, edges, scope] = buildRecords(proj, ws);
|
|
84
|
+
const byId = Object.fromEntries(nodes.map((n) => [n.id, n]));
|
|
85
|
+
const pages = nodes.filter((n) => n.kind === 'hybrid-page');
|
|
86
|
+
assert.equal(pages.length, 3);
|
|
87
|
+
assert.ok('hybrid-page:__UNI__A1B2C3D/pages/index/index' in byId);
|
|
88
|
+
assert.equal(byId['hybrid-page:__UNI__A1B2C3D/pages/chat/chat'].label, '聊天详情');
|
|
89
|
+
assert.ok(pages.every((n) => n.appid === '__UNI__A1B2C3D'));
|
|
90
|
+
const b = byId['hybrid:UniMP'];
|
|
91
|
+
assert.equal(b.enumerable, true);
|
|
92
|
+
assert.ok(b.enumerable_reason.includes('pre-bundled'));
|
|
93
|
+
assert.equal(b.denominator, false);
|
|
94
|
+
const launch = edges.filter((e) => e.mechanism === 'hybrid-launch');
|
|
95
|
+
assert.equal(launch.length, 1);
|
|
96
|
+
assert.equal(launch[0].source, 'hybrid:UniMP');
|
|
97
|
+
assert.equal(launch[0].target, 'hybrid-page:__UNI__A1B2C3D/pages/index/index');
|
|
98
|
+
assert.ok(launch[0].trigger.startsWith('startDestination@') && launch[0].args.action === 'default');
|
|
99
|
+
const tabs = edges.filter((e) => e.mechanism === 'hybrid-tabbar');
|
|
100
|
+
assert.equal(tabs.length, 1);
|
|
101
|
+
assert.equal(tabs[0].target, 'hybrid-page:__UNI__A1B2C3D/pages/mine/mine');
|
|
102
|
+
assert.equal(tabs[0].args.label, '我的');
|
|
103
|
+
const routed = edges.filter((e) => e.mechanism === 'hybrid-route');
|
|
104
|
+
assert.equal(routed.length, 1);
|
|
105
|
+
assert.deepEqual([routed[0].source, routed[0].target],
|
|
106
|
+
['hybrid-page:__UNI__A1B2C3D/pages/chat/chat', 'hybrid-page:__UNI__A1B2C3D/pages/mine/mine']);
|
|
107
|
+
assert.equal(routed[0].args.needs_trigger, true);
|
|
108
|
+
assert.equal(scope[0].packages[0].pages, 3);
|
|
109
|
+
assert.equal(scope[0].packages[0].appid, '__UNI__A1B2C3D');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test('2: concatenated bundle — counted, never attributed', () => {
|
|
113
|
+
const [proj, ws] = makeProject({ 'manifest.json': MANIFEST, 'app-config-service.js': VUE2_CONFIG, 'app-service.js': BUNDLE_ALL });
|
|
114
|
+
const [, e2, s2] = buildRecords(proj, ws);
|
|
115
|
+
assert.deepEqual(e2.filter((e) => e.mechanism === 'hybrid-route'), []);
|
|
116
|
+
assert.equal(s2[0].packages[0].unattributed_nav, 2);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('3: a .wgt archive is read in place', () => {
|
|
120
|
+
const [proj, ws] = makeProject({ 'manifest.json': MANIFEST, 'app-config-service.js': VUE2_CONFIG }, '__UNI__A1B2C3D', true);
|
|
121
|
+
const [n3] = buildRecords(proj, ws);
|
|
122
|
+
assert.equal(n3.filter((n) => n.kind === 'hybrid-page').length, 3);
|
|
123
|
+
assert.ok(!fs.existsSync(path.join(proj, 'app', 'src', 'main', 'assets', 'apps', '__UNI__A1B2C3D')));
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('4: Vue3 __uniRoutes shape, and the modern titleText spelling', () => {
|
|
127
|
+
const [proj, ws] = makeProject({ 'manifest.json': pj({ id: '__UNI__V3PACK' }), 'app-config.js': VUE3_CONFIG });
|
|
128
|
+
const v3 = Object.fromEntries(buildRecords(proj, ws)[0].filter((n) => n.kind === 'hybrid-page').map((n) => [n.id, n]));
|
|
129
|
+
assert.deepEqual(Object.keys(v3).sort(), ['hybrid-page:__UNI__V3PACK/pages/detail/detail', 'hybrid-page:__UNI__V3PACK/pages/index/index']);
|
|
130
|
+
assert.equal(v3['hybrid-page:__UNI__V3PACK/pages/detail/detail'].label, '详情');
|
|
131
|
+
|
|
132
|
+
const X = 'const __uniRoutes=[{"path":"pages/index/index","meta":{"navigationBar":' +
|
|
133
|
+
'{"titleText":"首页","style":"custom"}}},{"path":"pages/index/chat/chat",' +
|
|
134
|
+
'"meta":{"softinputMode":"adjustResize","navigationBar":{"titleText":' +
|
|
135
|
+
'"聊天页面","style":"custom"}}},{"path":"pages/mine/mine","meta":' +
|
|
136
|
+
'{"navigationBar":{"style":"custom"}}}];';
|
|
137
|
+
const [pX, wX] = makeProject({ 'manifest.json': pj({ id: '__UNI__MODERN' }), 'app-config-service.js': X });
|
|
138
|
+
const mod = Object.fromEntries(buildRecords(pX, wX)[0].filter((n) => n.kind === 'hybrid-page').map((n) => [n.route, n]));
|
|
139
|
+
assert.equal(mod['pages/index/index'].label, '首页');
|
|
140
|
+
assert.equal(mod['pages/index/chat/chat'].label, '聊天页面');
|
|
141
|
+
assert.equal(mod['pages/mine/mine'].title, undefined);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('5: two bundled packages do not merge', () => {
|
|
145
|
+
const [proj, ws] = makeProject({ 'manifest.json': MANIFEST, 'app-config-service.js': VUE2_CONFIG }, '__UNI__A1B2C3D', false,
|
|
146
|
+
['__UNI__ALIPAYX', { 'manifest.json': pj({ id: '__UNI__ALIPAYX' }), 'app-config-service.js': VUE2_CONFIG }]);
|
|
147
|
+
const [n5] = buildRecords(proj, ws);
|
|
148
|
+
const ids = new Set(n5.filter((n) => n.kind === 'hybrid-page').map((n) => n.id));
|
|
149
|
+
assert.ok(ids.has('hybrid-page:__UNI__A1B2C3D/pages/index/index') && ids.has('hybrid-page:__UNI__ALIPAYX/pages/index/index'));
|
|
150
|
+
assert.deepEqual([...n5.find((n) => n.id === 'hybrid:UniMP').packages].sort(), ['__UNI__A1B2C3D', '__UNI__ALIPAYX']);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test('6: no bundled package; --wgt supplied; corrupted supplied package refused', () => {
|
|
154
|
+
const [proj6, ws6] = bareProject();
|
|
155
|
+
const [n6, , s6] = buildRecords(proj6, ws6);
|
|
156
|
+
assert.ok(n6.length === 1 && n6[0].enumerable === false && n6[0].enumerable_reason.includes('released/downloaded at runtime'));
|
|
157
|
+
assert.ok(!n6.some((n) => n.kind === 'hybrid-page') && !s6[0].packages.length);
|
|
158
|
+
|
|
159
|
+
const supDir = fs.mkdtempSync(path.join(os.tmpdir(), 'hbs-'));
|
|
160
|
+
const sup = path.join(supDir, '__UNI__PULLED.wgt');
|
|
161
|
+
writeZip(sup, [['www/manifest.json', pj({ id: '__UNI__PULLED' })], ['www/app-config-service.js', VUE2_CONFIG]]);
|
|
162
|
+
const [n7, , s7] = buildRecords(proj6, ws6, { supplied: [sup] });
|
|
163
|
+
const sp = n7.filter((n) => n.kind === 'hybrid-page');
|
|
164
|
+
assert.ok(sp.length === 3 && sp.every((n) => n.appid === '__UNI__PULLED'));
|
|
165
|
+
assert.equal(s7[0].packages[0].origin_kind, 'supplied');
|
|
166
|
+
assert.equal(s7[0].packages[0].sha256, crypto.createHash('sha256').update(fs.readFileSync(sup)).digest('hex'));
|
|
167
|
+
assert.ok(n7.find((n) => n.id === 'hybrid:UniMP').enumerable_reason.includes('--wgt'));
|
|
168
|
+
|
|
169
|
+
const bad = path.join(supDir, '__UNI__BROKEN.wgt');
|
|
170
|
+
const blob = fs.readFileSync(sup);
|
|
171
|
+
fs.writeFileSync(bad, blob.subarray(0, Math.floor(blob.length / 2)));
|
|
172
|
+
const refus = [];
|
|
173
|
+
const pkgs = hp.findPackages(proj6, { supplied: [bad], refusals: refus });
|
|
174
|
+
assert.equal(pkgs.length, 0);
|
|
175
|
+
assert.ok(refus.length === 1 && refus[0][1].includes('exec-out'), JSON.stringify(refus));
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('7: route normalisation', () => {
|
|
179
|
+
assert.deepEqual([hp._normRoute('/pages/x/y?id=1'), hp._normRoute('pages/x/y'), hp._normRoute('/pages/x/y.html')],
|
|
180
|
+
['pages/x/y', 'pages/x/y', 'pages/x/y']);
|
|
181
|
+
});
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
// Port of test_hybrid_scope.py: an embedded non-native UI stack must be DECLARED (boundary
|
|
2
|
+
// node, enumerable:false, real inbound edge), entry gestures anchored per tile, labels resolved
|
|
3
|
+
// with the right ceilings, and the gesture -> package join all-or-nothing.
|
|
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 { buildRecords } from '../hybrid_scope.mjs';
|
|
10
|
+
import { jsonDumps } from '../_py.mjs';
|
|
11
|
+
import { writeZip } from './_zipw.mjs';
|
|
12
|
+
|
|
13
|
+
function makeWgt(dir, appid, name, pages, tabbar = []) {
|
|
14
|
+
const p = path.join(dir, `${appid}.wgt`);
|
|
15
|
+
const cfg = { pages: pages.map((r) => ({ path: r, style: {} })) };
|
|
16
|
+
if (tabbar.length) { cfg.tabBar = { list: tabbar.map(([r, t]) => ({ pagePath: r, text: t })) }; }
|
|
17
|
+
const pyJson = (o) => jsonDumps(o, { ensure_ascii: false });
|
|
18
|
+
writeZip(p, [['manifest.json', pyJson({ id: appid, name })],
|
|
19
|
+
['app-config-service.js', ';(function(){var __uniConfig=' + pyJson(cfg)]]);
|
|
20
|
+
return p;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function build(files, nodesJsonl = null, layouts = null, supplied = []) {
|
|
24
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'hs-'));
|
|
25
|
+
const src = path.join(tmp, 'app', 'src', 'main', 'java', 'com', 'example', 'app', 'ui');
|
|
26
|
+
fs.mkdirSync(src, { recursive: true });
|
|
27
|
+
for (const [fn, body] of Object.entries(files)) { fs.writeFileSync(path.join(src, fn), body); }
|
|
28
|
+
if (layouts) {
|
|
29
|
+
const lay = path.join(tmp, 'app', 'src', 'main', 'res', 'layout');
|
|
30
|
+
fs.mkdirSync(lay, { recursive: true });
|
|
31
|
+
for (const [fn, body] of Object.entries(layouts)) { fs.writeFileSync(path.join(lay, fn), body); }
|
|
32
|
+
}
|
|
33
|
+
const ws = path.join(tmp, 'ws');
|
|
34
|
+
fs.mkdirSync(ws);
|
|
35
|
+
if (nodesJsonl) { fs.writeFileSync(path.join(ws, 'nodes.jsonl'), nodesJsonl.map((r) => JSON.stringify(r) + '\n').join('')); }
|
|
36
|
+
return buildRecords(tmp, ws, { supplied });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const NODESET = [{ id: 'fragment:HomeFragment', label: 'HomeFragment', kind: 'fragment' },
|
|
40
|
+
{ id: 'activity:MainActivity', label: 'MainActivity', kind: 'activity' }];
|
|
41
|
+
|
|
42
|
+
const HOST_PAGE = `package com.example.app.ui;
|
|
43
|
+
|
|
44
|
+
import io.dcloud.feature.sdk.DCUniMPSDK;
|
|
45
|
+
|
|
46
|
+
public class HomeFragment extends BaseFragment {
|
|
47
|
+
private void openMiniApp(String appId) {
|
|
48
|
+
DCUniMPSDK.getInstance().openUniMP(getContext(), appId, config);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
const IMPORT_ONLY = `package com.example.app.util;
|
|
53
|
+
|
|
54
|
+
import io.dcloud.feature.sdk.DCUniMPSDK;
|
|
55
|
+
|
|
56
|
+
public class Unrelated {
|
|
57
|
+
public void nothing() { }
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
60
|
+
const NATIVE_PAGE = `package com.example.app.ui;
|
|
61
|
+
|
|
62
|
+
public class PlainFragment extends BaseFragment {
|
|
63
|
+
private void go() { startActivity(new Intent(this, OtherActivity.class)); }
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
test('1-6: boundary declared from the open api; import is not entry; native app is a no-op', () => {
|
|
68
|
+
const [nodes, edges, scope] = build({ 'HomeFragment.java': HOST_PAGE }, NODESET);
|
|
69
|
+
assert.deepEqual(scope.map((s) => s.runtime), ['UniMP']);
|
|
70
|
+
assert.equal(nodes.length, 1); assert.equal(nodes[0].id, 'hybrid:UniMP');
|
|
71
|
+
assert.equal(nodes[0].enumerable, false); assert.ok(nodes[0].enumerable_reason);
|
|
72
|
+
assert.equal(nodes[0].denominator, false);
|
|
73
|
+
assert.ok(nodes[0].host_activities.some((h) => h.startsWith('io.dcloud.')));
|
|
74
|
+
assert.equal(edges.length, 1);
|
|
75
|
+
assert.deepEqual([edges[0].source, edges[0].target], ['fragment:HomeFragment', 'hybrid:UniMP']);
|
|
76
|
+
assert.equal(edges[0].mechanism, 'open-overlay');
|
|
77
|
+
assert.equal(edges[0].args.needs_trigger, true);
|
|
78
|
+
assert.ok(edges[0].trigger.includes('HomeFragment.java:7'), edges[0].trigger);
|
|
79
|
+
assert.match(edges[0].trigger.split('@')[0], /^[A-Za-z_]\w*$/);
|
|
80
|
+
assert.equal(edges[0].trigger.split('@').length - 1, 1);
|
|
81
|
+
|
|
82
|
+
const [, iEdges, iScope] = build({ 'Unrelated.java': IMPORT_ONLY }, NODESET);
|
|
83
|
+
assert.deepEqual(iEdges, []);
|
|
84
|
+
assert.deepEqual(iScope.map((s) => s.runtime), ['UniMP']);
|
|
85
|
+
|
|
86
|
+
assert.deepEqual(build({ 'PlainFragment.java': NATIVE_PAGE }, NODESET), [[], [], []]);
|
|
87
|
+
});
|
|
88
|
+
const TWO_TILES = `package com.example.app.ui;
|
|
89
|
+
|
|
90
|
+
import io.dcloud.feature.sdk.DCUniMPSDK;
|
|
91
|
+
|
|
92
|
+
public class HomeFragment extends BaseFragment {
|
|
93
|
+
private void onEvent() {
|
|
94
|
+
DCUniMPSDK.getInstance().setOnUniMPEventCallBack(callback);
|
|
95
|
+
db.clWechatVirtual.setOnClickListener(view -> startOpenUnimp(0));
|
|
96
|
+
db.clAlipayVirtual.setOnClickListener(view -> startOpenUnimp(1));
|
|
97
|
+
}
|
|
98
|
+
private void startOpenUnimp(int type) {
|
|
99
|
+
DCUniMPSDK.getInstance().openUniMP(getContext(), appId, config);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
`;
|
|
103
|
+
const TWO_BRANCH_HELPER = `package com.example.app.ui;
|
|
104
|
+
|
|
105
|
+
import io.dcloud.feature.sdk.DCUniMPSDK;
|
|
106
|
+
|
|
107
|
+
public class HomeFragment extends BaseFragment {
|
|
108
|
+
private void onEvent() {
|
|
109
|
+
db.clWechatVirtual.setOnClickListener(view -> startOpenUnimp("", 0));
|
|
110
|
+
db.clAlipayVirtual.setOnClickListener(view -> startOpenUnimp("", 1));
|
|
111
|
+
}
|
|
112
|
+
private void startOpenUnimp(String path, int type) {
|
|
113
|
+
if (type == 0) {
|
|
114
|
+
if (wechatIUniMP != null) {
|
|
115
|
+
DCUniMPSDK.getInstance().openUniMP(getContext(), wxId, config);
|
|
116
|
+
}
|
|
117
|
+
} else if (type == 1) {
|
|
118
|
+
if (alipayIUniMP != null) {
|
|
119
|
+
DCUniMPSDK.getInstance().openUniMP(getContext(), aliId, config);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
`;
|
|
125
|
+
const argsOf = (e) => e.args ?? {};
|
|
126
|
+
const sortedJs = (xs) => [...xs].sort();
|
|
127
|
+
|
|
128
|
+
test('7: two tiles into one runtime -> two gesture-anchored edges', () => {
|
|
129
|
+
const [, tEdges, tScope] = build({ 'HomeFragment.java': TWO_TILES }, NODESET);
|
|
130
|
+
assert.equal(tEdges.length, 2);
|
|
131
|
+
assert.deepEqual(sortedJs(tEdges.map((e) => argsOf(e).trigger_id)), ['clAlipayVirtual', 'clWechatVirtual']);
|
|
132
|
+
assert.ok(tEdges.every((e) => argsOf(e).hop === 'helper:startOpenUnimp'));
|
|
133
|
+
assert.ok(!tEdges.some((e) => e.trigger.includes(':8')));
|
|
134
|
+
assert.ok(!tEdges.some((e) => argsOf(e).needs_trigger));
|
|
135
|
+
assert.equal(Object.keys(tScope[0].opened_at).length, 2);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('8: two enter sites in one helper -> anchored at each call site', () => {
|
|
139
|
+
const [, bEdges, bScope] = build({ 'HomeFragment.java': TWO_BRANCH_HELPER }, NODESET);
|
|
140
|
+
const lines = bEdges.map((e) => e.trigger.slice(e.trigger.lastIndexOf(':') + 1));
|
|
141
|
+
assert.equal(bEdges.length, 2);
|
|
142
|
+
assert.deepEqual(sortedJs(bEdges.map((e) => argsOf(e).trigger_id)), ['clAlipayVirtual', 'clWechatVirtual']);
|
|
143
|
+
assert.equal(new Set(lines).size, lines.length);
|
|
144
|
+
assert.ok(bEdges.every((e) => argsOf(e).anchor === 'call-site'));
|
|
145
|
+
assert.ok(bEdges.every((e) => argsOf(e).enter_sites === 2));
|
|
146
|
+
assert.ok(bEdges.every((e) => (argsOf(e).enter_api ?? '').includes('openUniMP')));
|
|
147
|
+
assert.ok(bEdges.every((e) => e.trigger.split('@')[0] === 'onClick'));
|
|
148
|
+
assert.ok(lines.every((n) => Number(n) < 9), String(lines));
|
|
149
|
+
assert.equal(Object.keys(bScope[0].opened_at).length, bEdges.length);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const LABELLED_ONE_ENTRY = `package com.example.app.ui;
|
|
153
|
+
|
|
154
|
+
import io.dcloud.feature.sdk.DCUniMPSDK;
|
|
155
|
+
|
|
156
|
+
public class HomeFragment extends BaseFragment {
|
|
157
|
+
private void onEvent() {
|
|
158
|
+
db.clWechatVirtual.setOnClickListener(view -> startOpenUnimp("", 0));
|
|
159
|
+
}
|
|
160
|
+
private void startOpenUnimp(String path, int type) {
|
|
161
|
+
DCUniMPSDK.getInstance().openUniMP(getContext(), wxId, config);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
`;
|
|
165
|
+
const LAYOUT_ONE = `<?xml version="1.0" encoding="utf-8"?>
|
|
166
|
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
|
|
167
|
+
<TextView
|
|
168
|
+
android:id="@+id/cl_wechat_virtual"
|
|
169
|
+
android:text="聊天模拟" />
|
|
170
|
+
</LinearLayout>
|
|
171
|
+
`;
|
|
172
|
+
const LAYOUT_TWO = `<?xml version="1.0" encoding="utf-8"?>
|
|
173
|
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
|
|
174
|
+
<TextView
|
|
175
|
+
android:id="@+id/cl_wechat_virtual"
|
|
176
|
+
android:text="聊天模拟" />
|
|
177
|
+
<TextView
|
|
178
|
+
android:id="@+id/cl_alipay_virtual"
|
|
179
|
+
android:text="支付模拟" />
|
|
180
|
+
</LinearLayout>
|
|
181
|
+
`;
|
|
182
|
+
const SHARED_CAPTION_LAYOUT = `<?xml version="1.0" encoding="utf-8"?>
|
|
183
|
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
|
|
184
|
+
<TextView android:text="聊天模拟" />
|
|
185
|
+
<RelativeLayout android:id="@+id/cl_wechat_virtual">
|
|
186
|
+
<TextView android:id="@+id/tv_load_a" android:text="加载中..." />
|
|
187
|
+
</RelativeLayout>
|
|
188
|
+
<TextView android:text="支付模拟" />
|
|
189
|
+
<RelativeLayout android:id="@+id/cl_alipay_virtual">
|
|
190
|
+
<TextView android:id="@+id/tv_load_b" android:text="加载中..." />
|
|
191
|
+
</RelativeLayout>
|
|
192
|
+
</LinearLayout>
|
|
193
|
+
`;
|
|
194
|
+
const boundaryOf = (nodes) => nodes.find((n) => n.kind === 'hybrid');
|
|
195
|
+
|
|
196
|
+
test('9: boundary and entry-edge labels (floor + ceiling)', () => {
|
|
197
|
+
const [cNodes, cEdges] = build({ 'HomeFragment.java': LABELLED_ONE_ENTRY }, NODESET, { 'fragment_home.xml': LAYOUT_ONE });
|
|
198
|
+
const c = boundaryOf(cNodes);
|
|
199
|
+
assert.equal(argsOf(cEdges[0]).label, '聊天模拟');
|
|
200
|
+
assert.equal(argsOf(cEdges[0]).label_source, 'view-id');
|
|
201
|
+
assert.equal(c.label, '聊天模拟');
|
|
202
|
+
assert.equal(c.label_source, 'view-id');
|
|
203
|
+
assert.deepEqual(c.expected?.hint_any, ['聊天模拟']);
|
|
204
|
+
|
|
205
|
+
const [dNodes, dEdges] = build({ 'HomeFragment.java': TWO_BRANCH_HELPER }, NODESET, { 'fragment_home.xml': LAYOUT_TWO });
|
|
206
|
+
const d = boundaryOf(dNodes);
|
|
207
|
+
assert.deepEqual(sortedJs(dEdges.map((e) => argsOf(e).label)), ['支付模拟', '聊天模拟']);
|
|
208
|
+
assert.ok(!['聊天模拟', '支付模拟'].includes(d.label));
|
|
209
|
+
assert.ok(!d.label.includes('/') && !d.label.includes(','));
|
|
210
|
+
assert.equal(d.label_source, 'code-name');
|
|
211
|
+
assert.deepEqual(d.expected?.hint_any, ['支付模拟', '聊天模拟']);
|
|
212
|
+
assert.equal((d.entry_labels ?? []).length, 2);
|
|
213
|
+
|
|
214
|
+
const e = boundaryOf(build({ 'HomeFragment.java': TWO_BRANCH_HELPER }, NODESET)[0]);
|
|
215
|
+
assert.equal(e.label, 'UniMP (hybrid stack)');
|
|
216
|
+
assert.ok(e.label_source === 'code-name' && !('expected' in e));
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test('10: a caption shared by two doors is demoted, not adopted', () => {
|
|
220
|
+
const [fNodes, fEdges] = build({ 'HomeFragment.java': TWO_BRANCH_HELPER }, NODESET,
|
|
221
|
+
{ 'fragment_home.xml': SHARED_CAPTION_LAYOUT });
|
|
222
|
+
const f = boundaryOf(fNodes);
|
|
223
|
+
assert.ok(f.label === 'UniMP (hybrid stack)' && f.label_source === 'code-name');
|
|
224
|
+
assert.ok(!('expected' in f));
|
|
225
|
+
assert.deepEqual(sortedJs(fEdges.map((e) => argsOf(e).label_source)), ['view-id-ambiguous', 'view-id-ambiguous']);
|
|
226
|
+
assert.ok(fEdges.every((e) => argsOf(e).label === '加载中...'));
|
|
227
|
+
});
|
|
228
|
+
const TWO_PKG_HOST = `package com.example.app.ui;
|
|
229
|
+
|
|
230
|
+
import io.dcloud.feature.sdk.DCUniMPSDK;
|
|
231
|
+
|
|
232
|
+
public class HomeFragment extends BaseFragment {
|
|
233
|
+
private void initData() {
|
|
234
|
+
wechatUpdateBean = list.stream().filter(i -> "wx".equals(i.getUnimp_type())).findAny().orElse(null);
|
|
235
|
+
alipayUpdateBean = list.stream().filter(i -> "alipay".equals(i.getUnimp_type())).findAny().orElse(null);
|
|
236
|
+
}
|
|
237
|
+
private void onEvent() {
|
|
238
|
+
db.clWechatVirtual.setOnClickListener(view -> startOpenUnimp("", 0));
|
|
239
|
+
db.clAlipayVirtual.setOnClickListener(view -> startOpenUnimp("", 1));
|
|
240
|
+
}
|
|
241
|
+
private void startOpenUnimp(String path, int type) {
|
|
242
|
+
if (type == 0) {
|
|
243
|
+
if (wechatUpdateBean != null) {
|
|
244
|
+
DCUniMPSDK.getInstance().openUniMP(getContext(), wxId, config);
|
|
245
|
+
}
|
|
246
|
+
} else if (type == 1) {
|
|
247
|
+
if (alipayUpdateBean != null) {
|
|
248
|
+
DCUniMPSDK.getInstance().openUniMP(getContext(), aliId, config);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
`;
|
|
254
|
+
|
|
255
|
+
test('11: which package a door opens (all-or-nothing join)', () => {
|
|
256
|
+
const pkgdir = fs.mkdtempSync(path.join(os.tmpdir(), 'hsp-'));
|
|
257
|
+
const WX = makeWgt(pkgdir, '__UNI__WX01', '微信', ['pages/index/index', 'pages/me/index'],
|
|
258
|
+
[['pages/index/index', '微信'], ['pages/me/index', '我']]);
|
|
259
|
+
const ALI = makeWgt(pkgdir, '__UNI__ALI01', 'alipay-emulator', ['pages/call-log/call', 'pages/bill/bill']);
|
|
260
|
+
const pk = (b) => Object.keys(b).filter((k) => k.includes('packages_'));
|
|
261
|
+
|
|
262
|
+
const [jNodes, jEdges] = build({ 'HomeFragment.java': TWO_PKG_HOST }, NODESET, null, [WX, ALI]);
|
|
263
|
+
const j = jNodes.find((n) => n.id === 'hybrid:UniMP');
|
|
264
|
+
const launch = jEdges.filter((e) => e.mechanism === 'hybrid-launch');
|
|
265
|
+
const doors = jEdges.filter((e) => e.target === 'hybrid:UniMP');
|
|
266
|
+
assert.ok(j.packages_resolved === true && !('packages_ambiguous' in j), String(pk(j)));
|
|
267
|
+
assert.deepEqual(launch.map((e) => [e.source, argsOf(e).trigger_id, argsOf(e).appid]).sort(),
|
|
268
|
+
[['fragment:HomeFragment', 'clAlipayVirtual', '__UNI__ALI01'],
|
|
269
|
+
['fragment:HomeFragment', 'clWechatVirtual', '__UNI__WX01']]);
|
|
270
|
+
assert.ok(launch.some((e) => argsOf(e).appid === '__UNI__WX01' && argsOf(e).trigger_id === 'clWechatVirtual'));
|
|
271
|
+
assert.ok(launch.every((e) => argsOf(e).action === 'tap' && !('launch_ambiguous' in argsOf(e))));
|
|
272
|
+
assert.deepEqual(sortedJs(doors.map((e) => argsOf(e).appid)), ['__UNI__ALI01', '__UNI__WX01']);
|
|
273
|
+
assert.ok(!jEdges.some((e) => 'package_token' in argsOf(e)));
|
|
274
|
+
|
|
275
|
+
const DYN = TWO_PKG_HOST.replace('startOpenUnimp("", 0)', 'startOpenUnimp("", currentType)');
|
|
276
|
+
const [dNodes, dEdges] = build({ 'HomeFragment.java': DYN }, NODESET, null, [WX, ALI]);
|
|
277
|
+
const d = dNodes.find((n) => n.id === 'hybrid:UniMP');
|
|
278
|
+
assert.ok(d.packages_ambiguous === true && !('packages_resolved' in d));
|
|
279
|
+
assert.ok(dEdges.filter((e) => e.mechanism === 'hybrid-launch').every((e) => argsOf(e).launch_ambiguous === true));
|
|
280
|
+
|
|
281
|
+
const SAME = TWO_PKG_HOST.replace('startOpenUnimp("", 1)', 'startOpenUnimp("", 0)');
|
|
282
|
+
assert.equal(build({ 'HomeFragment.java': SAME }, NODESET, null, [WX, ALI])[0]
|
|
283
|
+
.find((n) => n.id === 'hybrid:UniMP').packages_ambiguous, true);
|
|
284
|
+
|
|
285
|
+
const UNK = TWO_PKG_HOST.replace('"alipay".equals', '"qq".equals');
|
|
286
|
+
const u = build({ 'HomeFragment.java': UNK }, NODESET, null, [WX, ALI])[0].find((n) => n.id === 'hybrid:UniMP');
|
|
287
|
+
assert.ok(u.packages_ambiguous === true && !('packages_resolved' in u));
|
|
288
|
+
|
|
289
|
+
const [, oEdges] = build({ 'HomeFragment.java': TWO_PKG_HOST }, NODESET, null, [WX]);
|
|
290
|
+
const oL = oEdges.filter((e) => e.mechanism === 'hybrid-launch');
|
|
291
|
+
assert.ok(oL.length === 1 && oL[0].source === 'hybrid:UniMP' && argsOf(oL[0]).action === 'default' &&
|
|
292
|
+
oL[0].trigger.startsWith('startDestination@'));
|
|
293
|
+
});
|