@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,118 @@
|
|
|
1
|
+
// Port of test_hybrid_title_renders.py — a mini-program page's declared title is on-screen text
|
|
2
|
+
// ONLY when the runtime draws the navigation bar that carries it (hybrid_pages / hybrid_scope),
|
|
3
|
+
// and assemble MERGES a pre-stamped hint_any instead of overwriting it.
|
|
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 hp from '../hybrid_pages.mjs';
|
|
10
|
+
import * as hs from '../hybrid_scope.mjs';
|
|
11
|
+
import * as assemble from '../assemble.mjs';
|
|
12
|
+
|
|
13
|
+
const MANIFEST = JSON.stringify({ appid: '__UNI__A1B2C3D', name: 'Sim' });
|
|
14
|
+
const CONFIG = `const __uniRoutes = [\
|
|
15
|
+
{path:"pages/index/index",meta:{},window:{"navigationBar":\
|
|
16
|
+
{"titleText":"首页","style":"custom","type":"default"}}},\
|
|
17
|
+
{path:"pages/crop/crop",meta:{},window:{"navigationBar":\
|
|
18
|
+
{"titleText":"裁剪图片","type":"default"}}},\
|
|
19
|
+
{path:"pages/legacy/legacy",meta:{},window:{"navigationBarTitleText":"旧版页"}},\
|
|
20
|
+
{path:"pages/nview/nview",meta:{},window:{"navigationBarTitleText":"无栏页",\
|
|
21
|
+
"app-plus":{"titleNView":false}}}\
|
|
22
|
+
].map(t=>t);
|
|
23
|
+
const __uniConfig = {"tabBar":{"list":[\
|
|
24
|
+
{"pagePath":"pages/index/index","text":"消息"}]}};
|
|
25
|
+
`;
|
|
26
|
+
const HOST_PAGE = `
|
|
27
|
+
package com.example.ui;
|
|
28
|
+
import io.dcloud.feature.sdk.DCUniMPSDK;
|
|
29
|
+
public class HomeFragment extends BaseFragment {
|
|
30
|
+
private void open() {
|
|
31
|
+
db.clTile.setOnClickListener(v ->
|
|
32
|
+
DCUniMPSDK.getInstance().openUniMP(getContext(), appId, config));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
const NODESET = [{ id: 'fragment:HomeFragment', kind: 'fragment', name: 'HomeFragment',
|
|
37
|
+
declared_at: 'app/src/main/java/com/example/ui/HomeFragment.java:1' }];
|
|
38
|
+
|
|
39
|
+
function makeProject() {
|
|
40
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'htr'));
|
|
41
|
+
const src = path.join(tmp, 'app', 'src', 'main', 'java', 'com', 'example', 'ui');
|
|
42
|
+
fs.mkdirSync(src, { recursive: true });
|
|
43
|
+
fs.writeFileSync(path.join(src, 'HomeFragment.java'), HOST_PAGE, 'utf8');
|
|
44
|
+
const root = path.join(tmp, 'app', 'src', 'main', 'assets', 'apps', '__UNI__A1B2C3D', 'www');
|
|
45
|
+
fs.mkdirSync(root, { recursive: true });
|
|
46
|
+
fs.writeFileSync(path.join(root, 'manifest.json'), MANIFEST, 'utf8');
|
|
47
|
+
fs.writeFileSync(path.join(root, 'app-config-service.js'), CONFIG, 'utf8');
|
|
48
|
+
const ws = path.join(tmp, 'ws');
|
|
49
|
+
fs.mkdirSync(ws);
|
|
50
|
+
fs.writeFileSync(path.join(ws, 'nodes.jsonl'), NODESET.map((r) => JSON.stringify(r) + '\n').join(''), 'utf8');
|
|
51
|
+
return [tmp, ws];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Minimal stand-in for the package object enumerateUnimp consumes. */
|
|
55
|
+
class Pkg {
|
|
56
|
+
constructor(text) { this._text = text; this.names = new Set(); this.appid = '__UNI__A1B2C3D'; }
|
|
57
|
+
configText() { return this._text; }
|
|
58
|
+
read() { return ''; }
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
test('1: the parser reports whether the bar that carries the title is drawn', () => {
|
|
62
|
+
const got = hp.enumerateUnimp(new Pkg(CONFIG));
|
|
63
|
+
const byRoute = Object.fromEntries(got.pages.map((p) => [p.route, p]));
|
|
64
|
+
assert.equal(byRoute['pages/index/index'].title_renders, false, 'a custom-style route reports title_renders False');
|
|
65
|
+
assert.equal(byRoute['pages/index/index'].title, '首页', 'but its title is still READ, not discarded');
|
|
66
|
+
assert.equal(byRoute['pages/crop/crop'].title_renders, true, 'a default-bar route reports title_renders True');
|
|
67
|
+
assert.equal(byRoute['pages/legacy/legacy'].title_renders, true, 'a config with no style key at all keeps the old meaning (renders)');
|
|
68
|
+
assert.equal(byRoute['pages/nview/nview'].title_renders, false, 'titleNView:false also means the bar is not drawn');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('2/3/4: how that lands on the graph node', () => {
|
|
72
|
+
const [proj, ws] = makeProject();
|
|
73
|
+
try {
|
|
74
|
+
const [nodes] = hs.buildRecords(proj, ws);
|
|
75
|
+
const byId = Object.fromEntries(nodes.map((n) => [n.id, n]));
|
|
76
|
+
const custom = byId['hybrid-page:__UNI__A1B2C3D/pages/index/index'];
|
|
77
|
+
const dflt = byId['hybrid-page:__UNI__A1B2C3D/pages/crop/crop'];
|
|
78
|
+
const nview = byId['hybrid-page:__UNI__A1B2C3D/pages/nview/nview'];
|
|
79
|
+
assert.equal(custom.label_synthetic, true, 'a page whose title never renders is flagged label_synthetic');
|
|
80
|
+
assert.deepEqual((custom.expected || {}).hint_any, ['首页'], 'and keeps the title as a WEAK hint');
|
|
81
|
+
assert.ok(!((custom.expected || {}).title_any?.length), 'never as a strong identity token');
|
|
82
|
+
assert.ok(nview.label_synthetic === true && JSON.stringify((nview.expected || {}).hint_any) === JSON.stringify(['无栏页']),
|
|
83
|
+
'titleNView:false is demoted the same way');
|
|
84
|
+
assert.ok(dflt.label_synthetic === undefined || dflt.label_synthetic === null, 'a DEFAULT-bar page is NOT demoted — no over-correction');
|
|
85
|
+
assert.ok(custom.label === '首页' && dflt.label === '裁剪图片', 'the label is unchanged either way (click_paths needs a name)');
|
|
86
|
+
assert.equal(custom.tab_text, '消息', 'a tabBar caption is untouched — it prints under the icon');
|
|
87
|
+
} finally { fs.rmSync(proj, { recursive: true, force: true }); }
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('a route with no title: synthetic basename label, no invented hint', () => {
|
|
91
|
+
const CONFIG_UNTITLED = `const __uniRoutes = [\
|
|
92
|
+
{path:"pages/moments/video/video",meta:{},window:{}}\
|
|
93
|
+
].map(t=>t);
|
|
94
|
+
`;
|
|
95
|
+
const got = hp.enumerateUnimp(new Pkg(CONFIG_UNTITLED));
|
|
96
|
+
assert.equal(got.pages[0].title, null, 'a route with no title declares none');
|
|
97
|
+
const [recs] = hs._packageRecords('hybrid:UniMP', 'UniMP', { appid: '__UNI__X', origin: 'pkg' },
|
|
98
|
+
{ pages: got.pages, launch: 'pages/moments/video/video', tabbar: [], edges: [] });
|
|
99
|
+
const untitled = recs[0];
|
|
100
|
+
assert.equal(untitled.label, 'video', 'and falls back to the route basename as its label');
|
|
101
|
+
assert.equal(untitled.label_synthetic, true, 'which is flagged synthetic, so it cannot become a strong identity token');
|
|
102
|
+
assert.ok(!((untitled.expected || {}).hint_any?.length), 'and no hint is invented from a path segment');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('5: assemble must MERGE a pre-stamped hint_any, not overwrite it', () => {
|
|
106
|
+
const nodes = {
|
|
107
|
+
'hybrid-page:x/pages/a/a': { id: 'hybrid-page:x/pages/a/a', kind: 'hybrid-page', label: '聊天页面',
|
|
108
|
+
label_synthetic: true, declared_at: 'pkg/pages/a/a', expected: { hint_any: ['聊天页面'] } },
|
|
109
|
+
'fragment:Home': { id: 'fragment:Home', kind: 'fragment', label: 'Home',
|
|
110
|
+
declared_at: 'app/src/main/java/com/example/ui/Home.java:1' },
|
|
111
|
+
};
|
|
112
|
+
const edges = [{ source: 'fragment:Home', target: 'hybrid-page:x/pages/a/a', mechanism: 'hybrid-launch', args: { label: '入口' } }];
|
|
113
|
+
assemble.enrichNodesAndEdges(nodes, edges, null);
|
|
114
|
+
const exp = nodes['hybrid-page:x/pages/a/a'].expected || {};
|
|
115
|
+
assert.ok((exp.hint_any || []).includes('聊天页面'), "assemble keeps an extractor's pre-stamped hint_any");
|
|
116
|
+
assert.ok(!(exp.title_any?.length), 'and still refuses it as a strong token');
|
|
117
|
+
assert.ok((exp.hint_any || []).includes('入口'), 'the inbound trigger label is merged in beside it, not replaced');
|
|
118
|
+
});
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// term(): click-path text, operation text, synthetic labels and the hint-grammar marker come out in
|
|
2
|
+
// the installed language. zh (no i18n.json next to the helper) keeps today's text; en uses
|
|
3
|
+
// i18n/skills/a2h-utg-static/scripts/i18n.json. Labels and page names inside stay as the app renders them.
|
|
4
|
+
import { test } from 'node:test';
|
|
5
|
+
import assert from 'node:assert/strict';
|
|
6
|
+
import * as path from 'node:path';
|
|
7
|
+
import { execFileSync } from 'node:child_process';
|
|
8
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
9
|
+
|
|
10
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
const SCRIPTS = path.resolve(HERE, '..');
|
|
12
|
+
const EN_TABLE = path.resolve(SCRIPTS, '..', '..', '..', 'i18n', 'skills', 'a2h-utg-static', 'scripts', 'i18n.json');
|
|
13
|
+
const url = (f) => JSON.stringify(pathToFileURL(path.join(SCRIPTS, f)).href);
|
|
14
|
+
|
|
15
|
+
/** Run a module snippet in a fresh process (term() caches its table per process). */
|
|
16
|
+
function run(code, en) {
|
|
17
|
+
const env = { ...process.env };
|
|
18
|
+
delete env.HT_I18N_FILE;
|
|
19
|
+
if (en) env.HT_I18N_FILE = EN_TABLE;
|
|
20
|
+
return JSON.parse(execFileSync(process.execPath, ['--input-type=module', '-e', code], { env, encoding: 'utf8' }));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const SNIPPET = `
|
|
24
|
+
import { _renderPathText, _guardHint } from ${url('click_paths.mjs')};
|
|
25
|
+
import { _DRAWER_LABEL } from ${url('fragment_nav.mjs')};
|
|
26
|
+
import { _catalogTitle } from ${url('presenter_nav.mjs')};
|
|
27
|
+
import { HINT_GRAMMAR, hintGrammarIssue } from ${url('nl_hints.mjs')};
|
|
28
|
+
import { StaticPrior } from ${url('static_prior.mjs')};
|
|
29
|
+
|
|
30
|
+
const nodes = new Map([
|
|
31
|
+
['activity:Main', { kind: 'activity', label: '首页' }],
|
|
32
|
+
['activity:Settings', { kind: 'activity', label: '设置' }],
|
|
33
|
+
['fragment:Pager', { kind: 'pager-page', label: '推荐' }],
|
|
34
|
+
['fragment:Drawer', { kind: 'fragment', label: '侧栏' }],
|
|
35
|
+
['dialog:Rate', { kind: 'dialog', label: '评分' }],
|
|
36
|
+
['activity:Detail', { kind: 'activity', label: '详情' }],
|
|
37
|
+
['menu:Ctx', { kind: 'menu', label: '更多' }],
|
|
38
|
+
['custom:X', { kind: 'other', label: '区域' }],
|
|
39
|
+
]);
|
|
40
|
+
const login = { kind: 'login', text: 'isLoggedIn', redirect_when_unmet: 'compose-route:Login' };
|
|
41
|
+
const pathText = _renderPathText([
|
|
42
|
+
{ action: 'launch', target_id: 'activity:Main' },
|
|
43
|
+
{ action: 'tap', label: '设置', target_id: 'activity:Settings', guard: login },
|
|
44
|
+
{ action: 'swipe-left', target_id: 'fragment:Pager' },
|
|
45
|
+
{ action: 'swipe', gesture: 'open-drawer', drawer_gravity: 'start', target_id: 'fragment:Drawer' },
|
|
46
|
+
{ action: 'swipe', gesture: 'open-drawer', drawer_gravity: 'end', target_id: 'fragment:Drawer' },
|
|
47
|
+
{ action: 'tap', non_gesture: true, target_id: 'dialog:Rate' },
|
|
48
|
+
{ action: 'tap', needs_trigger: true, target_id: 'activity:Detail', guard: { kind: 'login', polarity: 'logged-out', text: '!isLoggedIn()' } },
|
|
49
|
+
{ action: 'long_press', label: '条目', target_id: 'menu:Ctx', guard: 'x != null' },
|
|
50
|
+
{ action: 'double_tap', label: '图', target_id: 'custom:X', guard: {} },
|
|
51
|
+
], nodes);
|
|
52
|
+
const guards = [_guardHint({ kind: 'login' }), _guardHint({ kind: 'login', redirect_when_unmet: 'Login' })];
|
|
53
|
+
|
|
54
|
+
// operationText / iconSemanticDescription on a stand-in prior (only the members they read).
|
|
55
|
+
const titles = { 'activity:Settings': '设置', 'dialog:P': '播放器', 'menu:M': '更多', 'dialog:D': '确认删除' };
|
|
56
|
+
const prior = (steps, bc = '') => Object.assign(Object.create(StaticPrior.prototype), {
|
|
57
|
+
_cpPaths: () => (steps ? { n: { steps } } : {}),
|
|
58
|
+
_detourSteps: () => null,
|
|
59
|
+
_expectedTitle: (id) => titles[id] || '',
|
|
60
|
+
_isCodeNameApp: () => false,
|
|
61
|
+
breadcrumb: () => bc,
|
|
62
|
+
});
|
|
63
|
+
const opText = prior([
|
|
64
|
+
{ action: 'launch' },
|
|
65
|
+
{ action: 'tap', label: '设置', label_source: 'screen-text', target_id: 'activity:Settings' },
|
|
66
|
+
{ action: 'swipe-left', label: '第二页', label_source: 'screen-text', target_id: 'fragment:T' },
|
|
67
|
+
{ action: 'tap', label: 'MiniPlayer', label_source: 'code-name', target_id: 'dialog:P', target_kind: 'dialog' },
|
|
68
|
+
{ action: 'tap', label: 'Sky', label_source: 'code-name', target_id: 'activity:Q' },
|
|
69
|
+
{ action: 'long_press', label: '删除', label_source: 'screen-text', label_ambiguous: true, target_id: 'dialog:D', target_kind: 'dialog' },
|
|
70
|
+
{ action: 'default', target_id: 'menu:M', target_kind: 'menu' },
|
|
71
|
+
{ action: 'weird', label: '其它', label_source: 'screen-text', target_id: 'activity:Z' },
|
|
72
|
+
]).operationText('n', '应用');
|
|
73
|
+
const crumbs = [prior(null, 'A > B').operationText('n', '应用'), prior(null, '').operationText('n', '应用')];
|
|
74
|
+
const icon = (args, kind) => Object.assign(Object.create(StaticPrior.prototype), {
|
|
75
|
+
_terminalEdgeArgs: () => args, g: { nodeGet: () => ({ kind }) },
|
|
76
|
+
}).iconSemanticDescription('n');
|
|
77
|
+
const icons = [icon({ icon_only: true, icon: 'search' }, 'activity'), icon({ low_signal: true }, 'dialog')];
|
|
78
|
+
const merge = (h, a) => StaticPrior.prototype._mergeGestureIntoHint(h, a);
|
|
79
|
+
const merged = [merge('“条目”', 'long_press'), merge('点击“条目”', 'double_tap'), merge('Long Press “Item”', 'long_press'), merge('“x”', 'tap')];
|
|
80
|
+
|
|
81
|
+
console.log(JSON.stringify({ pathText, guards, drawer: _DRAWER_LABEL, settings: _catalogTitle({}), named: _catalogTitle({ settings: 'Prefs' }),
|
|
82
|
+
grammar: HINT_GRAMMAR, opText, crumbs, icons, merged,
|
|
83
|
+
noGesture: ['(no action) opens on launch', '(无需操作)启动后自动进入'].map(hintGrammarIssue) }));
|
|
84
|
+
`;
|
|
85
|
+
|
|
86
|
+
const zh = run(SNIPPET, false);
|
|
87
|
+
const en = run(SNIPPET, true);
|
|
88
|
+
|
|
89
|
+
test('zh install: click-path text is unchanged', () => {
|
|
90
|
+
assert.equal(zh.pathText, [
|
|
91
|
+
'启动应用,进入首页(首页)',
|
|
92
|
+
'点击[设置],进入 设置 页面(需满足前置条件:isLoggedIn;未登录时改跳到 Login)',
|
|
93
|
+
'左滑,切换到 推荐',
|
|
94
|
+
'从屏幕左侧边缘向内滑动(或点击标题栏抽屉按钮),打开 侧栏',
|
|
95
|
+
'从屏幕右侧边缘向内滑动(或点击标题栏抽屉按钮),打开 侧栏',
|
|
96
|
+
'自动跳转,弹出 评分',
|
|
97
|
+
'需操作页面内控件(控件未能从代码静态确定),进入 详情 页面(仅未登录时:!isLoggedIn())',
|
|
98
|
+
'长按[条目],弹出 更多(需满足前置条件:x != null)',
|
|
99
|
+
'双击[图] → 区域',
|
|
100
|
+
].join(' → '));
|
|
101
|
+
assert.deepEqual(zh.guards, ['(需满足前置条件:login)', '(需满足前置条件:login;未登录时改跳到 Login)']);
|
|
102
|
+
assert.equal(zh.drawer, '抽屉菜单');
|
|
103
|
+
assert.equal(zh.settings, '设置');
|
|
104
|
+
assert.equal(zh.named, 'Prefs');
|
|
105
|
+
assert.match(zh.grammar, /Start with (无需操作) for a page/);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('en install: click-path text comes from the English table; app labels stay verbatim', () => {
|
|
109
|
+
assert.equal(en.pathText, [
|
|
110
|
+
'Launch the app, enter the home page (首页)',
|
|
111
|
+
'Click[设置], enters the 设置 page (requires precondition: isLoggedIn; redirects to Login when logged out)',
|
|
112
|
+
'Swipe left, switch to 推荐',
|
|
113
|
+
'Swipe in from the left screen edge (or tap the drawer button in the title bar), open 侧栏',
|
|
114
|
+
'Swipe in from the right screen edge (or tap the drawer button in the title bar), open 侧栏',
|
|
115
|
+
'Automatic redirect, opens 评分',
|
|
116
|
+
'Operate a control on the page (the control could not be determined statically from the code), enters the 详情 page (only when logged out: !isLoggedIn())',
|
|
117
|
+
'Long Press[条目], opens 更多 (requires precondition: x != null)',
|
|
118
|
+
'Double Click[图] → 区域',
|
|
119
|
+
].join(' → '));
|
|
120
|
+
assert.deepEqual(en.guards, [' (requires precondition: login)', ' (requires precondition: login; redirects to Login when logged out)']);
|
|
121
|
+
assert.equal(en.drawer, 'drawer menu');
|
|
122
|
+
assert.equal(en.settings, 'Settings');
|
|
123
|
+
assert.equal(en.named, 'Prefs');
|
|
124
|
+
assert.match(en.grammar, /Start with \(no action\) for a page/);
|
|
125
|
+
// the grammar still teaches app-language quoting in both scripts
|
|
126
|
+
assert.match(en.grammar, /「设置」, “Settings”/);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('zh install: operation text is unchanged', () => {
|
|
130
|
+
assert.equal(zh.opText, '打开应用,点击「设置」,到达「设置」页面,向左滑动,到达「第二页」页面,' +
|
|
131
|
+
'找到并进入通往「播放器」对话框的入口,弹出该对话框,找到并进入与「Sky」相关的入口,到达对应页面,' +
|
|
132
|
+
'长按「删除」(该页面上有多个同名控件,请选择通往「确认删除」的那一个),弹出「确认删除」对话框,' +
|
|
133
|
+
'打开「更多」菜单,点击「其它」,到达「其它」页面。');
|
|
134
|
+
assert.deepEqual(zh.crumbs, ['打开应用,点击「A」,点击「B」。', '打开应用,回到应用首页。']);
|
|
135
|
+
assert.deepEqual(zh.icons, ['在界面顶部工具栏找到并点击「search」图标(该按钮只有图标、没有文字),进入对应页面',
|
|
136
|
+
'在界面顶部工具栏找到并点击对应的图标按钮(无文字标签),打开面板/弹层']);
|
|
137
|
+
assert.deepEqual(zh.merged, ['长按:“条目”', '双击“条目”', '长按:Long Press “Item”', '“x”']);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
test('en install: operation text comes from the English table', () => {
|
|
141
|
+
assert.equal(en.opText, 'Open 应用, Click "设置", reach the "设置" page, Swipe left, reach the "第二页" page, ' +
|
|
142
|
+
'Find and use the entry that leads to the "播放器" dialog, pop up that dialog, Find and use the entry related to "Sky", reach the matching page, ' +
|
|
143
|
+
'Long Press "删除" (this page has several controls with that name; choose the one that leads to "确认删除"), pop up the "确认删除" dialog, ' +
|
|
144
|
+
'open the "更多" menu, Click "其它", reach the "其它" page.');
|
|
145
|
+
assert.deepEqual(en.crumbs, ['Open 应用, Click "A", Click "B".', "Open 应用, back to the app's home page."]);
|
|
146
|
+
assert.deepEqual(en.icons, ['In the top toolbar, find and click the "search" icon (the button has an icon and no text), enter the corresponding page',
|
|
147
|
+
'In the top toolbar, find and click the matching icon button (no text label), open the panel or overlay']);
|
|
148
|
+
// a hint that already names the English gesture is not prefixed twice
|
|
149
|
+
assert.deepEqual(en.merged, ['Long Press: “条目”', 'Double Click“条目”', 'Long Press “Item”', '“x”']);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test('reader: both no-gesture markers pass the hint grammar in either install', () => {
|
|
153
|
+
assert.deepEqual(zh.noGesture, [null, null]);
|
|
154
|
+
assert.deepEqual(en.noGesture, [null, null]);
|
|
155
|
+
});
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
// interaction_sites + view_interactions inventory: factory callbacks are reviewed per call site,
|
|
2
|
+
// listeners in unreachable private builders are prescreened, nested registrations are listed
|
|
3
|
+
// and `apply` refuses page-sourced transitions evidenced only by them, and two reviewers'
|
|
4
|
+
// same-kind wording of one surface merges instead of failing.
|
|
5
|
+
import { test } from 'node:test';
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import * as fs from 'node:fs';
|
|
8
|
+
import * as os from 'node:os';
|
|
9
|
+
import * as path from 'node:path';
|
|
10
|
+
import * as vi from '../view_interactions.mjs';
|
|
11
|
+
import * as is from '../interaction_sites.mjs';
|
|
12
|
+
|
|
13
|
+
const PAGE = `package demo
|
|
14
|
+
|
|
15
|
+
class Host : Activity() {
|
|
16
|
+
fun onCreate() { setContentView(Board(this).build()) }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
fun tab(ctx: Context, label: String, onClick: () -> Unit): TextView =
|
|
20
|
+
TextView(ctx).apply {
|
|
21
|
+
text = label
|
|
22
|
+
setOnClickListener { onClick() }
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
class Board(private val host: Host) {
|
|
26
|
+
private var mode = 0
|
|
27
|
+
|
|
28
|
+
fun build(): View = compactLayout()
|
|
29
|
+
|
|
30
|
+
private fun compactLayout(): View = LinearLayout(host).apply {
|
|
31
|
+
addView(tab(host, "A") { mode = 0; render() })
|
|
32
|
+
addView(tab(host, "B") { mode = 1; render() })
|
|
33
|
+
addView(moreButton(compact = true))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private fun wideLayout(): View = LinearLayout(host).apply {
|
|
37
|
+
addView(moreButton())
|
|
38
|
+
addView(Button(host).apply { setOnClickListener { confirm() } })
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private fun moreButton(compact: Boolean = false): TextView = TextView(host).apply {
|
|
42
|
+
setOnClickListener { anchor ->
|
|
43
|
+
if (compact) {
|
|
44
|
+
PopupMenu(host, anchor).apply {
|
|
45
|
+
setOnMenuItemClickListener { item -> confirm(); true }
|
|
46
|
+
}.show()
|
|
47
|
+
} else {
|
|
48
|
+
confirm()
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private fun confirm() { AlertDialog.Builder(host).setTitle("Confirm").show() }
|
|
54
|
+
private fun render() {}
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
57
|
+
const HOST_NODE = { id: 'activity:Host', kind: 'activity', name: 'Host', fqn: 'demo.Host',
|
|
58
|
+
declared_at: 'app/src/main/AndroidManifest.xml' };
|
|
59
|
+
|
|
60
|
+
function fixture() {
|
|
61
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'is-'));
|
|
62
|
+
const src = path.join(root, 'app', 'src', 'main', 'java', 'demo');
|
|
63
|
+
fs.mkdirSync(src, { recursive: true });
|
|
64
|
+
fs.writeFileSync(path.join(src, 'Board.kt'), PAGE);
|
|
65
|
+
const ws = path.join(root, 'ws');
|
|
66
|
+
fs.mkdirSync(ws);
|
|
67
|
+
fs.writeFileSync(path.join(ws, 'nodes.jsonl'), JSON.stringify(HOST_NODE) + '\n');
|
|
68
|
+
fs.writeFileSync(path.join(ws, 'edges.jsonl'), '');
|
|
69
|
+
return { root, ws };
|
|
70
|
+
}
|
|
71
|
+
const AT = (ln) => `app/src/main/java/demo/Board.kt:${ln}`;
|
|
72
|
+
|
|
73
|
+
test('declParams: Kotlin function-type parameters and defaults', () => {
|
|
74
|
+
const code = 'fun f(a: Int, b: String = "x", onDone: (Int) -> Unit, cb: (() -> Unit)? = null) {}';
|
|
75
|
+
const ps = is.declParams(code, code.indexOf('('));
|
|
76
|
+
assert.deepEqual(ps.map((x) => [x.name, x.fnType, x.hasDefault]),
|
|
77
|
+
[['a', false, false], ['b', false, true], ['onDone', true, false], ['cb', true, true]]);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('factory listener is replaced by one item per call-site lambda', () => {
|
|
81
|
+
const { root, ws } = fixture();
|
|
82
|
+
const wl = vi.collect(root, ws);
|
|
83
|
+
const fac = wl.prescreened.find((i) => i.prescreen.category === 'factory');
|
|
84
|
+
assert.ok(fac && fac.trigger_at === AT(10), JSON.stringify(wl.prescreened.map((i) => i.trigger_at)));
|
|
85
|
+
const sites = [...wl.items, ...wl.prescreened].filter((i) => i.binding === 'factory-callback');
|
|
86
|
+
assert.deepEqual(sites.map((i) => i.trigger_at).sort(), [AT(19), AT(20)]);
|
|
87
|
+
for (const s of sites) {
|
|
88
|
+
assert.deepEqual(s.host_candidates, ['activity:Host'], 'owned by the page that makes the call');
|
|
89
|
+
assert.equal(s.widget.factory, 'tab');
|
|
90
|
+
assert.ok(s.code_window.some((w) => w.at === AT(10)), 'factory registration line is citable');
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('listeners in a builder only a dead builder calls are prescreened unreachable', () => {
|
|
95
|
+
const { root, ws } = fixture();
|
|
96
|
+
const wl = vi.collect(root, ws);
|
|
97
|
+
const dead = wl.prescreened.filter((i) => i.prescreen.category === 'unreachable').map((i) => i.trigger_at);
|
|
98
|
+
assert.deepEqual(dead, [AT(26)], 'wideLayout() is never called');
|
|
99
|
+
const more = wl.items.find((i) => i.trigger_at === AT(30));
|
|
100
|
+
assert.ok(more, 'moreButton is live through compactLayout');
|
|
101
|
+
assert.deepEqual(more.call_sites, [{ at: AT(21), live: true }, { at: AT(25), live: false }],
|
|
102
|
+
'the compact=false caller is visible as dead');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('nested registrations are listed and gate apply', () => {
|
|
106
|
+
const { root, ws } = fixture();
|
|
107
|
+
vi.extract(ws, root);
|
|
108
|
+
const wl = vi.readJson(path.join(ws, 'view_interactions_worklist.json'));
|
|
109
|
+
const more = wl.items.find((i) => i.trigger_at === AT(30));
|
|
110
|
+
assert.deepEqual(more.nested_registrations, [AT(33)]);
|
|
111
|
+
const answers = (bad) => wl.items.map((i) => {
|
|
112
|
+
if (i.key !== more.key) { return { key: i.key, category: 'unresolved', reason: 'fixture' }; }
|
|
113
|
+
const menu = { key: 'more_menu', kind: 'panel', label: 'More', observable: 'popup menu', evidence: [AT(30)] };
|
|
114
|
+
const dlg = { key: 'confirm', kind: 'panel', label: 'Confirm', observable: 'dialog', evidence: [AT(33)] };
|
|
115
|
+
return { key: i.key, category: 'panel', reason: 'r', evidence: [AT(30)], transitions: [
|
|
116
|
+
{ host: 'activity:Host', target: menu, effect: 'open', instruction: 'tap more', guard: null, evidence: [AT(30)] },
|
|
117
|
+
{ host: 'activity:Host', ...(bad ? {} : { source: 'panel:activity:Host#more_menu' }), target: dlg, effect: 'open',
|
|
118
|
+
instruction: 'tap the item', guard: null, evidence: [AT(33)] },
|
|
119
|
+
] };
|
|
120
|
+
});
|
|
121
|
+
vi.save(path.join(ws, 'view_interactions_answers.json'), { items: answers(true) });
|
|
122
|
+
assert.throws(() => vi.apply(ws), /nested registration/);
|
|
123
|
+
vi.save(path.join(ws, 'view_interactions_answers.json'), { items: answers(false) });
|
|
124
|
+
vi.apply(ws);
|
|
125
|
+
const edges = fs.readFileSync(path.join(ws, 'edges.jsonl'), 'utf8').trim().split('\n').map((l) => JSON.parse(l));
|
|
126
|
+
assert.ok(edges.some((e) => e.source === 'panel:activity:Host#more_menu' && e.target === 'panel:activity:Host#confirm'));
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('same surface, same kind, different wording from two reviewers merges', () => {
|
|
130
|
+
const { root, ws } = fixture();
|
|
131
|
+
vi.extract(ws, root, false);
|
|
132
|
+
const wl = vi.readJson(path.join(ws, 'view_interactions_worklist.json'));
|
|
133
|
+
const [a, b] = wl.items.filter((i) => i.binding === 'factory-callback');
|
|
134
|
+
const ans = wl.items.map((i) => {
|
|
135
|
+
if (i !== a && i !== b) { return { key: i.key, category: 'unresolved', reason: 'fixture' }; }
|
|
136
|
+
const tgt = { key: 'mode', kind: 'ui-state', label: i === a ? 'Mode' : 'Mode view',
|
|
137
|
+
observable: i === a ? 'x' : 'y', evidence: [i.trigger_at] };
|
|
138
|
+
return { key: i.key, category: 'state', reason: 'r', evidence: [i.trigger_at], transitions: [
|
|
139
|
+
{ host: 'activity:Host', target: tgt, effect: 'state', instruction: 'tap', guard: null, evidence: [i.trigger_at] }] };
|
|
140
|
+
});
|
|
141
|
+
vi.save(path.join(ws, 'view_interactions_answers.json'), { items: ans });
|
|
142
|
+
vi.apply(ws);
|
|
143
|
+
const nodes = fs.readFileSync(path.join(ws, 'nodes.jsonl'), 'utf8').trim().split('\n').map((l) => JSON.parse(l));
|
|
144
|
+
const st = nodes.filter((n) => n.id === 'ui-state:activity:Host#mode');
|
|
145
|
+
assert.equal(st.length, 1);
|
|
146
|
+
assert.equal(st[0].label, 'Mode', 'first wording kept');
|
|
147
|
+
assert.deepEqual(st[0].evidence.sort(), [a.trigger_at, b.trigger_at].sort(), 'evidence unioned');
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// ---- review fixes (PR !49) ------------------------------------------------------------------
|
|
151
|
+
|
|
152
|
+
const MIXED = `package demo
|
|
153
|
+
|
|
154
|
+
class Host : Activity() {
|
|
155
|
+
fun onCreate() { setContentView(Board(this).build()) }
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
fun busyTab(ctx: Context, label: String, onClick: () -> Unit): TextView =
|
|
159
|
+
TextView(ctx).apply {
|
|
160
|
+
setOnClickListener { ctx.performHaptic(it); showBanner(); onClick() }
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
fun quietTab(ctx: Context, onClick: () -> Unit): TextView =
|
|
164
|
+
TextView(ctx).apply { setOnClickListener { it.performHapticFeedback(1); onClick() } }
|
|
165
|
+
|
|
166
|
+
class Board(private val host: Host) {
|
|
167
|
+
fun build(): View = LinearLayout(host).apply {
|
|
168
|
+
addView(busyTab(host, "A") { render() })
|
|
169
|
+
addView(quietTab(host, ::openSettings))
|
|
170
|
+
addView(quietTab(host, handler))
|
|
171
|
+
}
|
|
172
|
+
private val handler: () -> Unit = { render() }
|
|
173
|
+
private fun openSettings() { AlertDialog.Builder(host).show() }
|
|
174
|
+
private fun render() {}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
class Custom(ctx: Context) : View(ctx) {
|
|
178
|
+
override fun setOnClickListener(l: OnClickListener?) {
|
|
179
|
+
log(l)
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
`;
|
|
183
|
+
const JAVA_DECL = `package demo;
|
|
184
|
+
public class JCustom extends View {
|
|
185
|
+
@Override public void setOnClickListener(OnClickListener l) {
|
|
186
|
+
log(l);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
`;
|
|
190
|
+
|
|
191
|
+
function fixture2() {
|
|
192
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'is2-'));
|
|
193
|
+
const src = path.join(root, 'app', 'src', 'main', 'java', 'demo');
|
|
194
|
+
fs.mkdirSync(src, { recursive: true });
|
|
195
|
+
fs.writeFileSync(path.join(src, 'Board.kt'), MIXED);
|
|
196
|
+
fs.writeFileSync(path.join(src, 'JCustom.java'), JAVA_DECL);
|
|
197
|
+
const ws = path.join(root, 'ws');
|
|
198
|
+
fs.mkdirSync(ws);
|
|
199
|
+
fs.writeFileSync(path.join(ws, 'nodes.jsonl'), JSON.stringify(HOST_NODE) + '\n');
|
|
200
|
+
fs.writeFileSync(path.join(ws, 'edges.jsonl'), '');
|
|
201
|
+
return { root, ws };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
test('impure factory: the builder registration stays reviewable alongside its call sites', () => {
|
|
205
|
+
const { root, ws } = fixture2();
|
|
206
|
+
const wl = vi.collect(root, ws, false);
|
|
207
|
+
const all = [...wl.items, ...wl.prescreened];
|
|
208
|
+
assert.ok(all.some((i) => i.trigger_at === AT(9) && i.binding === 'setOnClickListener'),
|
|
209
|
+
'busyTab does showBanner() itself, so its registration is not folded away');
|
|
210
|
+
assert.ok(!wl.prescreened.some((i) => i.trigger_at === AT(9) && i.prescreen.category === 'factory'));
|
|
211
|
+
assert.ok(all.some((i) => i.binding === 'factory-callback' && i.widget.factory === 'busyTab'), 'call site still expanded');
|
|
212
|
+
assert.ok(wl.prescreened.some((i) => i.trigger_at === AT(13) && i.prescreen.category === 'factory'),
|
|
213
|
+
'quietTab only touches its own listener argument: pure forward');
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test('reference and variable call-site arguments are offered, never dropped', () => {
|
|
217
|
+
const { root, ws } = fixture2();
|
|
218
|
+
const wl = vi.collect(root, ws);
|
|
219
|
+
const q = [...wl.items, ...wl.prescreened].filter((i) => i.binding === 'factory-callback' && i.widget.factory === 'quietTab');
|
|
220
|
+
assert.equal(q.length, 2, JSON.stringify(q.map((i) => i.trigger_at)));
|
|
221
|
+
const byArg = new Map(q.map((i) => [i.widget.callback_arg, i]));
|
|
222
|
+
assert.ok(byArg.has('::openSettings') && byArg.has('handler'), JSON.stringify([...byArg.keys()]));
|
|
223
|
+
assert.ok(wl.items.includes(byArg.get('handler')), 'unresolvable variable: offered for review, not prescreened');
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test('Java and Kotlin setOnClickListener declarations are not registrations', () => {
|
|
227
|
+
const { root, ws } = fixture2();
|
|
228
|
+
const wl = vi.collect(root, ws, false);
|
|
229
|
+
const ats = [...wl.items, ...wl.prescreened].map((i) => i.trigger_at);
|
|
230
|
+
assert.ok(!ats.includes('app/src/main/java/demo/JCustom.java:3'), ats.join(','));
|
|
231
|
+
assert.ok(!ats.includes(AT(27)), 'override fun declaration');
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test('apply: one key claimed as panel and as ui-state on one host is a conflict', () => {
|
|
235
|
+
const { root, ws } = fixture();
|
|
236
|
+
vi.extract(ws, root, false);
|
|
237
|
+
const wl = vi.readJson(path.join(ws, 'view_interactions_worklist.json'));
|
|
238
|
+
const [a, b] = wl.items.filter((i) => i.binding === 'factory-callback');
|
|
239
|
+
const ans = wl.items.map((i) => {
|
|
240
|
+
if (i !== a && i !== b) { return { key: i.key, category: 'unresolved', reason: 'fixture' }; }
|
|
241
|
+
const kind = i === a ? 'panel' : 'ui-state';
|
|
242
|
+
return { key: i.key, category: i === a ? 'panel' : 'state', reason: 'r', evidence: [i.trigger_at], transitions: [
|
|
243
|
+
{ host: 'activity:Host', target: { key: 'mode', kind, label: 'M', observable: 'o', evidence: [i.trigger_at] },
|
|
244
|
+
effect: i === a ? 'open' : 'state', instruction: 'tap', guard: null, evidence: [i.trigger_at] }] };
|
|
245
|
+
});
|
|
246
|
+
vi.save(path.join(ws, 'view_interactions_answers.json'), { items: ans });
|
|
247
|
+
assert.throws(() => vi.apply(ws), /conflicting surface definitions/);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test('apply: padding nested evidence with the outer trigger does not bypass the gate', () => {
|
|
251
|
+
const { root, ws } = fixture();
|
|
252
|
+
vi.extract(ws, root);
|
|
253
|
+
const wl = vi.readJson(path.join(ws, 'view_interactions_worklist.json'));
|
|
254
|
+
const more = wl.items.find((i) => i.trigger_at === AT(30));
|
|
255
|
+
const ans = wl.items.map((i) => (i.key !== more.key ? { key: i.key, category: 'unresolved', reason: 'fixture' } : {
|
|
256
|
+
key: i.key, category: 'panel', reason: 'r', evidence: [AT(30)], transitions: [
|
|
257
|
+
{ host: 'activity:Host', effect: 'open', instruction: 'tap', guard: null, evidence: [AT(30), AT(33)],
|
|
258
|
+
target: { key: 'confirm', kind: 'panel', label: 'C', observable: 'o', evidence: [AT(33)] } }] }));
|
|
259
|
+
vi.save(path.join(ws, 'view_interactions_answers.json'), { items: ans });
|
|
260
|
+
assert.throws(() => vi.apply(ws), /nested registration/);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test('Reachability: a deep chain of dead private builders resolves in one pass', () => {
|
|
264
|
+
const n = 60;
|
|
265
|
+
const fns = Array.from({ length: n }, (_, k) => ` private fun f${k}(): View = ${k + 1 < n ? `f${k + 1}()` : 'View(c)'}\n`).join('');
|
|
266
|
+
const code = `class Big(val c: Context) {\n fun build(): View = View(c)\n${fns}}\n`;
|
|
267
|
+
const t0 = Date.now();
|
|
268
|
+
const r = new is.Reachability(new Map([['/p/Big.kt', code]]));
|
|
269
|
+
assert.ok(r.isDead('/p/Big.kt', code.lastIndexOf('View(c)')), 'f59 is reached only through dead f0..f58');
|
|
270
|
+
assert.ok(!r.isDead('/p/Big.kt', code.indexOf('fun build')), 'public build is a root');
|
|
271
|
+
assert.ok(Date.now() - t0 < 2000);
|
|
272
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// Port of test_item_data_instance.py — a listener that forwards the tapped row's fields makes the
|
|
2
|
+
// destination require an instance (adapter_nav._passesItemData -> assemble step 2b).
|
|
3
|
+
import { test } from 'node:test';
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import * as an from '../adapter_nav.mjs';
|
|
6
|
+
import * as assemble from '../assemble.mjs';
|
|
7
|
+
|
|
8
|
+
const REAL = `
|
|
9
|
+
ChatRoom chatRoom = (ChatRoom) adapter.getItem(position);
|
|
10
|
+
Bundle bundle = new Bundle();
|
|
11
|
+
bundle.putString("room_id", chatRoom.getId());
|
|
12
|
+
bundle.putString("name", chatRoom.getGroup_name());
|
|
13
|
+
startActivity(AlbumListActivity.class, bundle);
|
|
14
|
+
`;
|
|
15
|
+
|
|
16
|
+
test('1: the predicate', () => {
|
|
17
|
+
assert.equal(an._passesItemData(REAL), true, 'a listener forwarding tapped-row fields needs an instance');
|
|
18
|
+
assert.equal(an._passesItemData('ChatRoom c = (ChatRoom) adapter.getItem(position);\n' +
|
|
19
|
+
'if (c.isLocked()) { return; }\nstartActivity(FooActivity.class);'), false,
|
|
20
|
+
'reading the item only to BRANCH on it does not');
|
|
21
|
+
assert.equal(an._passesItemData('Bundle b = new Bundle();\nb.putString("from", "home");\n' +
|
|
22
|
+
'startActivity(FooActivity.class, b);'), false, 'a CONSTANT extra does not — a direct launch can supply it');
|
|
23
|
+
assert.equal(an._passesItemData('startActivity(FooActivity.class);'), false, 'neither does a bare launch');
|
|
24
|
+
assert.equal(an._passesItemData('Item it = list.get(position);\nIntent i = new Intent(this, FooActivity.class);\n' +
|
|
25
|
+
'i.putExtra("id", it.getId());\nstartActivity(i);'), true, 'putExtra on an Intent counts as well as Bundle.put*');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('2: edge evidence becomes a NODE property', () => {
|
|
29
|
+
const nodes = {
|
|
30
|
+
'fragment:Home': { id: 'fragment:Home', kind: 'fragment', label: 'Home', declared_at: 'app/src/main/java/x/Home.java:1' },
|
|
31
|
+
'activity:AlbumList': { id: 'activity:AlbumList', kind: 'activity', label: 'AlbumList', fqn: 'x.AlbumList',
|
|
32
|
+
declared_at: 'app/src/main/AndroidManifest.xml' },
|
|
33
|
+
'activity:Plain': { id: 'activity:Plain', kind: 'activity', label: 'Plain', fqn: 'x.Plain',
|
|
34
|
+
declared_at: 'app/src/main/AndroidManifest.xml' },
|
|
35
|
+
};
|
|
36
|
+
const edges = [
|
|
37
|
+
{ source: 'fragment:Home', target: 'activity:AlbumList', mechanism: 'adapter-item-click',
|
|
38
|
+
trigger: 'app/src/main/java/x/Home.java:242',
|
|
39
|
+
args: { mechanism: 'adapter-item-click', via: 'adapter:RoomAdapter', passes_item_data: true, item_collection: 'RoomAdapter' } },
|
|
40
|
+
{ source: 'fragment:Home', target: 'activity:Plain', mechanism: 'adapter-item-click',
|
|
41
|
+
trigger: 'app/src/main/java/x/Home.java:300', args: { mechanism: 'adapter-item-click', via: 'adapter:RoomAdapter' } },
|
|
42
|
+
];
|
|
43
|
+
assemble.enrichNodesAndEdges(nodes, edges, null);
|
|
44
|
+
const al = nodes['activity:AlbumList']; const pl = nodes['activity:Plain'];
|
|
45
|
+
assert.equal(al.requires_instance, true, 'the destination is marked requires_instance');
|
|
46
|
+
assert.equal(al.do_not_crawl_directly, true, 'and do_not_crawl_directly, which is what the crawler reads');
|
|
47
|
+
assert.equal(al.instance_collection, 'RoomAdapter', 'the source collection is named, so a crawler knows WHAT to tap');
|
|
48
|
+
assert.ok(String(al.instance_evidence).includes(':'), 'with a file:line so the claim is auditable');
|
|
49
|
+
assert.ok(!pl.requires_instance, 'an adapter edge WITHOUT item data leaves its target launchable');
|
|
50
|
+
assert.ok(!(al.required_state?.length), 'needing an INSTANCE is not the same claim as needing device CONTENT');
|
|
51
|
+
});
|