@buaa_smat/hometrans 26.0.0 → 26.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/README.md +7 -1
  2. package/package.json +11 -82
  3. package/skills/a2h-arch-generate/scripts/module_create/hap/src/main/ets/pages/Index.ets +2 -2
  4. package/skills/a2h-arch-generate/scripts/module_create/har/src/main/ets/components/MainPage.ets +2 -2
  5. package/skills/a2h-arch-generate/scripts/module_create/hsp/src/main/ets/pages/Index.ets +2 -2
  6. package/skills/a2h-batch-ui-align/references/conversion-procedure.md +1 -1
  7. 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
  8. package/skills/a2h-batch-ui-align/references/step3-capture.md +3 -3
  9. package/skills/a2h-batch-ui-align/references/step4-prepare.md +1 -1
  10. package/skills/a2h-batch-ui-align/scripts/detect_paradigm.mjs +11 -6
  11. package/skills/a2h-batch-ui-align/scripts/export_ui_info.mjs +59 -21
  12. package/skills/a2h-batch-ui-align/scripts/group_pack.mjs +3 -3
  13. package/skills/a2h-batch-ui-align/scripts/group_queue.mjs +1 -1
  14. package/skills/a2h-batch-ui-align/scripts/static_check/core/scan.ts +1 -1
  15. package/skills/a2h-utg-explorer/SKILL.md +1 -1
  16. package/skills/a2h-utg-explorer/references/architecture.md +2 -2
  17. package/skills/a2h-utg-explorer/scripts/compile_tasks.mjs +36 -11
  18. package/skills/a2h-utg-explorer/scripts/device_health.mjs +91 -6
  19. package/skills/a2h-utg-explorer/scripts/final_utg.mjs +20 -2
  20. package/skills/a2h-utg-explorer/scripts/hint_check.mjs +64 -8
  21. package/skills/a2h-utg-explorer/scripts/hint_source.mjs +119 -0
  22. package/skills/a2h-utg-explorer/scripts/recover.mjs +7 -1
  23. package/skills/a2h-utg-explorer/scripts/recover_b.mjs +8 -1
  24. package/skills/a2h-utg-explorer/scripts/utg_explorer/adapters.mjs +89 -7
  25. package/skills/a2h-utg-explorer/scripts/utg_explorer/semantics.mjs +173 -4
  26. package/skills/a2h-utg-explorer/scripts/utg_explorer/task_runner.mjs +82 -14
  27. package/skills/a2h-utg-static/SKILL.md +1 -1
  28. package/skills/a2h-utg-static/references/view-interactions.md +1 -1
  29. package/skills/a2h-utg-static/scripts/assemble.mjs +6 -3
  30. package/skills/a2h-utg-static/scripts/compose_body_text.mjs +23 -5
  31. package/skills/a2h-utg-static/scripts/compose_overlay.mjs +29 -3
  32. package/skills/a2h-utg-static/scripts/compose_titles.mjs +10 -1
  33. package/skills/a2h-utg-static/scripts/label_resolve.mjs +51 -2
  34. package/skills/a2h-utg-static/scripts/static_prior.mjs +2 -1
  35. package/skills/a2h-utg-static/scripts/tests/_zipw.mjs +28 -0
  36. package/skills/a2h-utg-static/scripts/tests/probe_autoload.mjs +108 -0
  37. package/skills/a2h-utg-static/scripts/tests/probe_layout_fragments.mjs +90 -0
  38. package/skills/a2h-utg-static/scripts/tests/probe_unknown_scope.mjs +61 -0
  39. package/skills/a2h-utg-static/scripts/tests/regression_matrix.mjs +1261 -0
  40. package/skills/a2h-utg-static/scripts/tests/test_activity_alias_launcher.mjs +135 -0
  41. package/skills/a2h-utg-static/scripts/tests/test_activity_supertype_chain.mjs +106 -0
  42. package/skills/a2h-utg-static/scripts/tests/test_bottom_sheet_container.mjs +58 -0
  43. package/skills/a2h-utg-static/scripts/tests/test_branch_guard.mjs +19 -0
  44. package/skills/a2h-utg-static/scripts/tests/test_callee_string_default.mjs +30 -0
  45. package/skills/a2h-utg-static/scripts/tests/test_carry_answers.mjs +103 -0
  46. package/skills/a2h-utg-static/scripts/tests/test_chrome_tokens.mjs +60 -0
  47. package/skills/a2h-utg-static/scripts/tests/test_commented_out_trigger.mjs +111 -0
  48. package/skills/a2h-utg-static/scripts/tests/test_commit_scope.mjs +113 -0
  49. package/skills/a2h-utg-static/scripts/tests/test_compose_file_private_route.mjs +117 -0
  50. package/skills/a2h-utg-static/scripts/tests/test_compose_nested_graph.mjs +166 -0
  51. package/skills/a2h-utg-static/scripts/tests/test_compose_res_text.mjs +108 -0
  52. package/skills/a2h-utg-static/scripts/tests/test_compose_route_holder_collision.mjs +112 -0
  53. package/skills/a2h-utg-static/scripts/tests/test_compose_vm_nav.mjs +289 -0
  54. package/skills/a2h-utg-static/scripts/tests/test_custom_source_root.mjs +71 -0
  55. package/skills/a2h-utg-static/scripts/tests/test_defensive_null_guard.mjs +77 -0
  56. package/skills/a2h-utg-static/scripts/tests/test_dialog_orphan_entries.mjs +99 -0
  57. package/skills/a2h-utg-static/scripts/tests/test_dialog_page_owner.mjs +69 -0
  58. package/skills/a2h-utg-static/scripts/tests/test_dialogshow_builder_forms.mjs +96 -0
  59. package/skills/a2h-utg-static/scripts/tests/test_dialogshow_java_factory.mjs +37 -0
  60. package/skills/a2h-utg-static/scripts/tests/test_disabled_guard.mjs +42 -0
  61. package/skills/a2h-utg-static/scripts/tests/test_drawer_panel_gesture.mjs +140 -0
  62. package/skills/a2h-utg-static/scripts/tests/test_edge_dedupe_by_gesture.mjs +111 -0
  63. package/skills/a2h-utg-static/scripts/tests/test_edge_provenance_lint.mjs +70 -0
  64. package/skills/a2h-utg-static/scripts/tests/test_enclosing_gesture.mjs +69 -0
  65. package/skills/a2h-utg-static/scripts/tests/test_external_surface_roots.mjs +43 -0
  66. package/skills/a2h-utg-static/scripts/tests/test_find_package_indirect.mjs +67 -0
  67. package/skills/a2h-utg-static/scripts/tests/test_forwarding_wrapper.mjs +38 -0
  68. package/skills/a2h-utg-static/scripts/tests/test_fragment_containment.mjs +85 -0
  69. package/skills/a2h-utg-static/scripts/tests/test_fragment_helper_trigger.mjs +92 -0
  70. package/skills/a2h-utg-static/scripts/tests/test_fresh_branch_guard.mjs +49 -0
  71. package/skills/a2h-utg-static/scripts/tests/test_graph.mjs +55 -0
  72. package/skills/a2h-utg-static/scripts/tests/test_guard_clause.mjs +86 -0
  73. package/skills/a2h-utg-static/scripts/tests/test_hint_language.mjs +136 -0
  74. package/skills/a2h-utg-static/scripts/tests/test_host_kind_by_chain.mjs +68 -0
  75. package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundle_attribution.mjs +74 -0
  76. package/skills/a2h-utg-static/scripts/tests/test_hybrid_bundled_pages.mjs +181 -0
  77. package/skills/a2h-utg-static/scripts/tests/test_hybrid_scope.mjs +293 -0
  78. package/skills/a2h-utg-static/scripts/tests/test_hybrid_title_renders.mjs +118 -0
  79. package/skills/a2h-utg-static/scripts/tests/test_i18n_term.mjs +155 -0
  80. package/skills/a2h-utg-static/scripts/tests/test_interaction_sites.mjs +272 -0
  81. package/skills/a2h-utg-static/scripts/tests/test_item_data_instance.mjs +51 -0
  82. package/skills/a2h-utg-static/scripts/tests/test_kotlin_fn_spans.mjs +69 -0
  83. package/skills/a2h-utg-static/scripts/tests/test_label_accessor_forms.mjs +187 -0
  84. package/skills/a2h-utg-static/scripts/tests/test_label_source.mjs +70 -0
  85. package/skills/a2h-utg-static/scripts/tests/test_launch_intent_guard.mjs +67 -0
  86. package/skills/a2h-utg-static/scripts/tests/test_layout_declared_fragment.mjs +103 -0
  87. package/skills/a2h-utg-static/scripts/tests/test_listener_call_forms.mjs +79 -0
  88. package/skills/a2h-utg-static/scripts/tests/test_listener_receiver_binding.mjs +47 -0
  89. package/skills/a2h-utg-static/scripts/tests/test_login_interceptor.mjs +328 -0
  90. package/skills/a2h-utg-static/scripts/tests/test_manifest_exported_default.mjs +40 -0
  91. package/skills/a2h-utg-static/scripts/tests/test_manifest_filters_modules.mjs +84 -0
  92. package/skills/a2h-utg-static/scripts/tests/test_manifest_srcfile.mjs +68 -0
  93. package/skills/a2h-utg-static/scripts/tests/test_mode_and_cb_param.mjs +172 -0
  94. package/skills/a2h-utg-static/scripts/tests/test_module_namespace.mjs +83 -0
  95. package/skills/a2h-utg-static/scripts/tests/test_module_strings.mjs +44 -0
  96. package/skills/a2h-utg-static/scripts/tests/test_multiple_entry_contracts.mjs +80 -0
  97. package/skills/a2h-utg-static/scripts/tests/test_nav_graph_xml.mjs +35 -0
  98. package/skills/a2h-utg-static/scripts/tests/test_nl_hint_grammar.mjs +42 -0
  99. package/skills/a2h-utg-static/scripts/tests/test_nl_hints_gate.mjs +85 -0
  100. package/skills/a2h-utg-static/scripts/tests/test_nl_hints_off_path.mjs +67 -0
  101. package/skills/a2h-utg-static/scripts/tests/test_node_id_collision.mjs +57 -0
  102. package/skills/a2h-utg-static/scripts/tests/test_non_gesture_step_flag.mjs +62 -0
  103. package/skills/a2h-utg-static/scripts/tests/test_out_of_scope_and_settings.mjs +72 -0
  104. package/skills/a2h-utg-static/scripts/tests/test_overload_and_climb.mjs +86 -0
  105. package/skills/a2h-utg-static/scripts/tests/test_pager_page_source.mjs +78 -0
  106. package/skills/a2h-utg-static/scripts/tests/test_pager_position_zero.mjs +65 -0
  107. package/skills/a2h-utg-static/scripts/tests/test_pager_variant_guard.mjs +172 -0
  108. package/skills/a2h-utg-static/scripts/tests/test_pipeline_llm_phases.mjs +107 -0
  109. package/skills/a2h-utg-static/scripts/tests/test_plain_dialog_nodes.mjs +167 -0
  110. package/skills/a2h-utg-static/scripts/tests/test_plaindialog_shared_anchor.mjs +117 -0
  111. package/skills/a2h-utg-static/scripts/tests/test_preference_click_nav.mjs +98 -0
  112. package/skills/a2h-utg-static/scripts/tests/test_preference_host_binding.mjs +87 -0
  113. package/skills/a2h-utg-static/scripts/tests/test_preference_nesting.mjs +183 -0
  114. package/skills/a2h-utg-static/scripts/tests/test_preference_widgets.mjs +48 -0
  115. package/skills/a2h-utg-static/scripts/tests/test_read_text_crlf.mjs +41 -0
  116. package/skills/a2h-utg-static/scripts/tests/test_resolver_tier_parity.mjs +126 -0
  117. package/skills/a2h-utg-static/scripts/tests/test_result_launcher.mjs +142 -0
  118. package/skills/a2h-utg-static/scripts/tests/test_review_fixes.mjs +135 -0
  119. package/skills/a2h-utg-static/scripts/tests/test_route_token_words.mjs +66 -0
  120. package/skills/a2h-utg-static/scripts/tests/test_same_name_decl_scope.mjs +236 -0
  121. package/skills/a2h-utg-static/scripts/tests/test_scope_utils.mjs +85 -0
  122. package/skills/a2h-utg-static/scripts/tests/test_sealed_dialog_state.mjs +148 -0
  123. package/skills/a2h-utg-static/scripts/tests/test_shared_overlay_split.mjs +63 -0
  124. package/skills/a2h-utg-static/scripts/tests/test_slug_parity.mjs +58 -0
  125. package/skills/a2h-utg-static/scripts/tests/test_starter_node_id.mjs +41 -0
  126. package/skills/a2h-utg-static/scripts/tests/test_state_guard_arity.mjs +109 -0
  127. package/skills/a2h-utg-static/scripts/tests/test_state_guard_commented_candidates.mjs +68 -0
  128. package/skills/a2h-utg-static/scripts/tests/test_state_guard_model_gates.mjs +127 -0
  129. package/skills/a2h-utg-static/scripts/tests/test_state_specific_hop.mjs +130 -0
  130. package/skills/a2h-utg-static/scripts/tests/test_synthetic_label_identity.mjs +51 -0
  131. package/skills/a2h-utg-static/scripts/tests/test_template_method_layout.mjs +81 -0
  132. package/skills/a2h-utg-static/scripts/tests/test_template_title.mjs +61 -0
  133. package/skills/a2h-utg-static/scripts/tests/test_trigger_id_spelling.mjs +68 -0
  134. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_action_override.mjs +91 -0
  135. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_flow_filter.mjs +110 -0
  136. package/skills/a2h-utg-static/scripts/tests/test_ui_elements_nl_hint_key.mjs +89 -0
  137. package/skills/a2h-utg-static/scripts/tests/test_uiless_host_fold.mjs +98 -0
  138. package/skills/a2h-utg-static/scripts/tests/test_uniapp_data_table.mjs +340 -0
  139. package/skills/a2h-utg-static/scripts/tests/test_uniapp_relative_url.mjs +125 -0
  140. package/skills/a2h-utg-static/scripts/tests/test_uniapp_source.mjs +231 -0
  141. package/skills/a2h-utg-static/scripts/tests/test_view_click_refs.mjs +104 -0
  142. package/skills/a2h-utg-static/scripts/tests/test_view_id_label.mjs +69 -0
  143. package/skills/a2h-utg-static/scripts/tests/test_view_interactions.mjs +346 -0
  144. package/skills/a2h-utg-static/scripts/tests/test_viewpage_nav.mjs +340 -0
  145. package/skills/a2h-utg-static/scripts/tests/test_vm_nav_helper_navigate.mjs +98 -0
  146. package/skills/a2h-utg-static/scripts/tests/test_widget_class_scope.mjs +92 -0
  147. package/skills/a2h-utg-static/scripts/tests/test_window_nav_kotlin.mjs +158 -0
  148. package/skills/a2h-utg-static/scripts/tests/test_worklist_parts.mjs +65 -0
@@ -0,0 +1,107 @@
1
+ // Port of test_pipeline_llm_phases.py: run_pipeline's two-phase LLM split (ORDER / RESET /
2
+ // GATE / NO-OP / MISSING). App-agnostic: synthetic signal dict + temp workspaces.
3
+ import { test } from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import * as fs from 'node:fs';
6
+ import * as os from 'node:os';
7
+ import * as path from 'node:path';
8
+ import * as rp from '../run_pipeline.mjs';
9
+ import { SystemExit } from '../_py.mjs';
10
+
11
+ const names = (steps) => steps.map((s) => s[0]);
12
+ const plan = (ev) => rp.plan('/proj', '/ws', 'com.example', { ...ev });
13
+ const tmp = () => fs.mkdtempSync(path.join(os.tmpdir(), 'rp-llm-'));
14
+ const wjson = (p, obj) => fs.writeFileSync(p, JSON.stringify(obj), 'utf8');
15
+ const raises = (fn) => { try { fn(); } catch (e) { if (e instanceof SystemExit) { return e; } throw e; } return null; };
16
+
17
+ test('plan order', () => {
18
+ const n = names(plan({ fragment: 'Base.java:1' }));
19
+ assert.ok(n.includes('dialogshow_nav'), 'every Fragment app runs the generic DialogFragment factory/show scan');
20
+ assert.ok(n.includes('_halt'), 'plan carries the phase boundary sentinel');
21
+ const h = n.indexOf('_halt');
22
+ for (const stage of ['state_guard-extract', 'nl_hints-extract']) {
23
+ assert.ok(n.includes(stage) && n.indexOf(stage) < h, stage + ' runs in phase A');
24
+ }
25
+ for (const stage of ['state_guard-apply', 'nl_hints-apply']) {
26
+ assert.ok(n.includes(stage) && n.indexOf(stage) > h, stage + ' runs in phase B');
27
+ }
28
+ const compose = names(plan({ compose_ui: 'Screen.kt:1', compose_routes: 'x' }));
29
+ assert.ok(compose.includes('nl_hints-extract') && compose.includes('state_guard-extract'),
30
+ 'asking stages are planned for a Compose app too');
31
+ const cps = n.flatMap((x, i) => (x === 'click_paths' ? [i] : []));
32
+ assert.ok(cps.length && Math.max(...cps) < n.indexOf('nl_hints-apply'), 'every click_paths run precedes nl_hints-apply');
33
+ const sga = n.indexOf('state_guard-apply');
34
+ const asm = n.flatMap((x, i) => (x === 'assemble' ? [i] : []));
35
+ assert.ok(asm.some((i) => i > sga), 'an assemble refresh follows state_guard-apply');
36
+ assert.ok(n.indexOf('phase_plan') > Math.max(...asm), 'phase_plan reads the refreshed utg.json');
37
+ for (const stage of ['phase_plan', '_ui_elements', 'utg_html']) {
38
+ assert.ok(n.indexOf(stage) > h, stage + ' is in phase B (consumes answers)');
39
+ }
40
+ });
41
+
42
+ test('worklist count: 0 and missing stay distinguishable', () => {
43
+ const ws = tmp();
44
+ try {
45
+ const p = path.join(ws, 'w.json');
46
+ assert.equal(rp._worklistCount(p), null, 'missing file -> None, not 0');
47
+ wjson(p, { items: [] });
48
+ assert.equal(rp._worklistCount(p), 0, 'empty worklist -> 0');
49
+ wjson(p, { items: [1, 2, 3] });
50
+ assert.equal(rp._worklistCount(p), 3, 'populated worklist -> count');
51
+ fs.writeFileSync(p, '{not json');
52
+ assert.equal(rp._worklistCount(p), null, 'unreadable file -> None');
53
+ } finally { fs.rmSync(ws, { recursive: true, force: true }); }
54
+ });
55
+
56
+ test('no-op auto-answer', () => {
57
+ let ws = tmp();
58
+ try {
59
+ for (const spec of rp.ASK_STAGES) { wjson(path.join(ws, spec.worklist), { items: [] }); }
60
+ const done = rp._autoanswerEmpty(ws);
61
+ assert.equal(done.length, rp.ASK_STAGES.length, 'every empty worklist answered');
62
+ assert.equal(rp._writePending(ws), false, 'an empty worklist does not halt');
63
+ } finally { fs.rmSync(ws, { recursive: true, force: true }); }
64
+
65
+ ws = tmp();
66
+ try {
67
+ assert.deepEqual(rp._autoanswerEmpty(ws), [], 'absent worklist is NOT answered');
68
+ for (const spec of rp.ASK_STAGES) {
69
+ assert.ok(!fs.existsSync(path.join(ws, spec.answers)), 'no ' + spec.answers + ' invented for an absent worklist');
70
+ }
71
+ assert.equal(rp._writePending(ws), false, 'absent worklists do not halt (nothing was asked)');
72
+ } finally { fs.rmSync(ws, { recursive: true, force: true }); }
73
+
74
+ ws = tmp();
75
+ try {
76
+ const spec = rp.ASK_STAGES[0];
77
+ wjson(path.join(ws, spec.worklist), { items: [] });
78
+ wjson(path.join(ws, spec.answers), { items: [{ key: 'kept' }] });
79
+ rp._autoanswerEmpty(ws);
80
+ const got = JSON.parse(fs.readFileSync(path.join(ws, spec.answers), 'utf8'));
81
+ assert.ok(got.items.length && got.items[0].key === 'kept', 'an existing answer file is left alone');
82
+ } finally { fs.rmSync(ws, { recursive: true, force: true }); }
83
+ });
84
+
85
+ test('resume gate', () => {
86
+ const ws = tmp();
87
+ try {
88
+ const spec = rp.ASK_STAGES[0];
89
+ wjson(path.join(ws, spec.worklist), { items: [{ key: 'a' }, { key: 'b' }] });
90
+ assert.equal(rp._writePending(ws), true, 'a populated worklist halts');
91
+ const rec = JSON.parse(fs.readFileSync(path.join(ws, rp.PENDING), 'utf8'));
92
+ assert.equal(rec.phase, 'awaiting_answers', 'pending file records the wait');
93
+
94
+ const e = raises(() => rp._resumeGate(ws));
95
+ assert.ok(e, 'unanswered worklist refuses to resume');
96
+ assert.ok(String(e.code).includes(spec.answers), 'the error names the file to write');
97
+
98
+ for (const [bad, label] of [[{ items: [] }, 'an empty answers file'],
99
+ [{ items: [{ key: 'a', category: 'action' }] }, 'a partial answers file'],
100
+ [{ items: [{ key: 'a' }, { key: 'b' }] }, 'an all-blank answers file']]) {
101
+ wjson(path.join(ws, spec.answers), bad);
102
+ assert.ok(raises(() => rp._resumeGate(ws)), `${label} refuses to resume`);
103
+ }
104
+ wjson(path.join(ws, spec.answers), { items: [{ key: 'a', category: 'action' }, { key: 'b', category: 'unresolved' }] });
105
+ assert.equal(raises(() => rp._resumeGate(ws)), null, 'resume proceeds once every key is answered');
106
+ } finally { fs.rmSync(ws, { recursive: true, force: true }); }
107
+ });
@@ -0,0 +1,167 @@
1
+ // Port of test_plain_dialog_nodes.py: android.app.Dialog subclasses become nodes; show sites resolve.
2
+ import { test } from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import * as fs from 'node:fs';
5
+ import * as os from 'node:os';
6
+ import * as path from 'node:path';
7
+ import * as pdn from '../plaindialog_nav.mjs';
8
+ import { buildListenerSpans } from '../fragment_nav.mjs';
9
+
10
+ const search = (rx, s) => { rx.lastIndex = 0; return rx.exec(s); };
11
+ const finditer = (rx, s) => { const g = new RegExp(rx.source, rx.flags.includes('g') ? rx.flags : rx.flags + 'g'); return [...s.matchAll(g)]; };
12
+
13
+ const BASE = `
14
+ package com.example.app.base;
15
+ public abstract class BaseDialog<DB> extends Dialog {
16
+ protected abstract int getLayoutId();
17
+ }
18
+ `;
19
+ const MODALS = `
20
+ package com.example.app.ui.dialog;
21
+ public class ReportModal extends BaseDialog<ReportBinding> {
22
+ public ReportModal(Context c) { super(c); }
23
+ }
24
+ public class InputModal extends BaseDialog<InputBinding> {
25
+ public InputModal(Context c) { super(c); }
26
+ }
27
+ `;
28
+ const SHEET_FRAG = `
29
+ package com.example.app.ui.sheet;
30
+ public class PickerSheet extends BottomSheetDialogFragment {
31
+ }
32
+ `;
33
+ const sources = [
34
+ ['/p/app/src/main/java/com/example/app/base/BaseDialog.java', BASE],
35
+ ['/p/app/src/main/java/com/example/app/ui/dialog/Modals.java', MODALS],
36
+ ['/p/app/src/main/java/com/example/app/ui/sheet/PickerSheet.java', SHEET_FRAG],
37
+ ];
38
+ const [dialogs] = pdn.buildDialogSet(sources, '/p');
39
+ const names = new Set(dialogs.keys());
40
+
41
+ test('node set: lineage in, DialogFragment lineage out', () => {
42
+ assert.ok(dialogs.has('ReportModal') && dialogs.has('InputModal'), [...dialogs.keys()].join(','));
43
+ assert.equal(dialogs.get('BaseDialog')?.abstract, true);
44
+ assert.ok(!dialogs.has('PickerSheet'));
45
+ });
46
+
47
+ const PAGE = `
48
+ package com.example.app.ui;
49
+ public class AlbumActivity extends BaseActivity {
50
+ private void initView() {
51
+ db.rowCreate.setOnClickListener(v -> { showCreateModal(); });
52
+ db.rowReport.setOnClickListener(v -> showReportModal("chat"));
53
+ }
54
+ private void showCreateModal() {
55
+ InputModal d = new InputModal(this);
56
+ d.setTitleText("name");
57
+ d.setConfirmListener(v -> d.dismiss());
58
+ d.show();
59
+ }
60
+ private void showReportModal(String origin) {
61
+ ReportModal r = new ReportModal(this);
62
+ r.setConfirmClick(v -> r.dismiss());
63
+ r.show();
64
+ }
65
+ }
66
+ `;
67
+
68
+ test('cross-statement construct / configure / show', () => {
69
+ const assigns = pdn._assignments(PAGE, false);
70
+ const declared = pdn._declaredTypes(PAGE, false);
71
+ const resolved = finditer(pdn._SHOW_BARE_RE, PAGE).map((m) => {
72
+ const [typ] = pdn._resolveReceiver(assigns, m[1], m.index, names, null, declared);
73
+ return [m[1], typ];
74
+ });
75
+ resolved.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0));
76
+ assert.deepEqual(resolved, [['d', 'InputModal'], ['r', 'ReportModal']]);
77
+ const spans = buildListenerSpans(PAGE);
78
+ assert.deepEqual(new Set(spans.map(([v]) => v)), new Set(['rowCreate', 'rowReport']));
79
+ const calls = new Map(spans.map(([vid, lo, hi]) => [vid, pdn._helperCallsIn(PAGE, lo, hi)]));
80
+ assert.ok(calls.get('rowCreate')?.has('showCreateModal') && calls.get('rowReport')?.has('showReportModal'));
81
+ });
82
+
83
+ test('ambiguity is refused, never resolved by proximity', () => {
84
+ const AMBIG = `
85
+ package com.example.app.ui;
86
+ public class TwoWayActivity extends BaseActivity {
87
+ private void ask(boolean flag) {
88
+ BaseDialog d;
89
+ if (flag) { d = new InputModal(this); } else { d = new ReportModal(this); }
90
+ d.show();
91
+ }
92
+ }
93
+ `;
94
+ const m = search(pdn._SHOW_BARE_RE, AMBIG);
95
+ const [typ, why] = pdn._resolveReceiver(pdn._assignments(AMBIG, false), m[1], m.index, names, null,
96
+ pdn._declaredTypes(AMBIG, false));
97
+ assert.equal(typ, null);
98
+ assert.ok(why.startsWith('ambiguous'), why);
99
+ });
100
+
101
+ test('declared-type tier: shown before constructed', () => {
102
+ const CACHED = `
103
+ package com.example.app.ui;
104
+ public class CachedActivity extends BaseActivity {
105
+ ReportModal checkModal;
106
+ private void showCheck() {
107
+ if (checkModal != null) { checkModal.show(); }
108
+ checkModal = new ReportModal(this);
109
+ }
110
+ }
111
+ `;
112
+ const m = search(pdn._SHOW_BARE_RE, CACHED);
113
+ const r = pdn._resolveReceiver(pdn._assignments(CACHED, false), m[1], m.index, names, null,
114
+ pdn._declaredTypes(CACHED, false));
115
+ assert.deepEqual(r, ['ReportModal', 'declared']);
116
+ });
117
+
118
+ function withLayout(name, xml, fn) {
119
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'pdn-'));
120
+ try {
121
+ const lay = path.join(tmp, 'app', 'src', 'main', 'res', 'layout');
122
+ fs.mkdirSync(lay, { recursive: true });
123
+ fs.writeFileSync(path.join(lay, name), xml, 'utf8');
124
+ fn(tmp);
125
+ } finally { fs.rmSync(tmp, { recursive: true, force: true }); }
126
+ }
127
+
128
+ test('container label descent: caption on a CHILD of the tapped row', () => {
129
+ withLayout('activity_album.xml', `<?xml version="1.0" encoding="utf-8"?>
130
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
131
+ <FrameLayout android:id="@+id/row_create">
132
+ <TextView android:id="@+id/tv_create" android:text="Create album" />
133
+ </FrameLayout>
134
+ <FrameLayout android:id="@+id/row_report">
135
+ <TextView android:id="@+id/tv_report" android:text="Report" />
136
+ </FrameLayout>
137
+ </LinearLayout>
138
+ `, (tmp) => {
139
+ const [perLayout, glob] = pdn.buildContainerLabelIndex(tmp, {});
140
+ assert.equal(glob.get('row_create'), 'Create album');
141
+ assert.equal(glob.get('row_report'), 'Report');
142
+ assert.deepEqual(pdn._labelForVid('rowCreate', null, [], [perLayout, glob]), ['Create album', 'row_create']);
143
+ });
144
+ });
145
+
146
+ test('caption+value row and peer group: resolved but flagged ambiguous', () => {
147
+ withLayout('activity_x.xml', `<?xml version="1.0" encoding="utf-8"?>
148
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
149
+ <FrameLayout android:id="@+id/cl_cache">
150
+ <TextView android:text="Clear cache" />
151
+ <TextView android:text="12M" />
152
+ </FrameLayout>
153
+ <FrameLayout android:id="@+id/layout_tab">
154
+ <TextView android:text="Home" />
155
+ <TextView android:text="Docs" />
156
+ <TextView android:text="Mine" />
157
+ </FrameLayout>
158
+ </LinearLayout>
159
+ `, (tmp) => {
160
+ pdn._AMBIGUOUS_CAPTIONS.clear();
161
+ const [, glob] = pdn.buildContainerLabelIndex(tmp, {});
162
+ assert.equal(glob.get('cl_cache'), 'Clear cache');
163
+ assert.equal(glob.get('layout_tab'), 'Home');
164
+ assert.equal(pdn._AMBIGUOUS_CAPTIONS.get('layout_tab'), true);
165
+ assert.equal(pdn._AMBIGUOUS_CAPTIONS.get('cl_cache'), true);
166
+ });
167
+ });
@@ -0,0 +1,117 @@
1
+ // Port of test_plaindialog_shared_anchor.py: which line a gesture reaching several .show() sites cites.
2
+ import { test, after } from 'node:test';
3
+ import assert from 'node:assert/strict';
4
+ import * as fs from 'node:fs';
5
+ import * as os from 'node:os';
6
+ import * as path from 'node:path';
7
+ import { spawnSync } from 'node:child_process';
8
+ import { fileURLToPath } from 'node:url';
9
+ import * as pdn from '../plaindialog_nav.mjs';
10
+
11
+ const HERE = path.dirname(fileURLToPath(import.meta.url));
12
+
13
+ const BASE = `package com.example.app.base;
14
+ public abstract class BaseDialog<DB> extends Dialog {
15
+ protected abstract int getLayoutId();
16
+ }
17
+ `;
18
+ const MODAL = `package com.example.app.ui.dialog;
19
+ public class ConfirmModal extends BaseDialog<ConfirmBinding> {
20
+ public ConfirmModal(Context c) { super(c); }
21
+ }
22
+ `;
23
+ // Line numbers asserted below are load-bearing; do not reflow.
24
+ const PAGE = `package com.example.app.ui;
25
+ public class ChatActivity extends BaseActivity {
26
+ private void onEvent() {
27
+ db.rowOnce.setOnClickListener(v -> showOnce());
28
+ handleAdapter.setOnItemClickListener((adapter, view, position) -> {
29
+ switch (position) {
30
+ case 0: showDeleteModal(); break;
31
+ case 1: showFilterModal(); break;
32
+ }
33
+ });
34
+ db.rowBranchy.setOnClickListener(v -> showBranchy(true));
35
+ }
36
+ private void showOnce() {
37
+ ConfirmModal a = new ConfirmModal(this);
38
+ a.show();
39
+ }
40
+ private void showDeleteModal() {
41
+ ConfirmModal b = new ConfirmModal(this);
42
+ b.show();
43
+ }
44
+ private void showFilterModal() {
45
+ ConfirmModal c = new ConfirmModal(this);
46
+ c.show();
47
+ }
48
+ private void showBranchy(boolean flag) {
49
+ if (flag) {
50
+ ConfirmModal d = new ConfirmModal(this);
51
+ d.show();
52
+ } else {
53
+ ConfirmModal e = new ConfirmModal(this);
54
+ e.show();
55
+ }
56
+ }
57
+ }
58
+ `;
59
+
60
+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'pdsa-'));
61
+ after(() => fs.rmSync(tmp, { recursive: true, force: true }));
62
+ const src = path.join(tmp, 'app', 'src', 'main', 'java', 'com', 'example', 'app');
63
+ fs.mkdirSync(path.join(src, 'base'), { recursive: true });
64
+ fs.mkdirSync(path.join(src, 'ui', 'dialog'), { recursive: true });
65
+ for (const [parts, body] of [[['base', 'BaseDialog.java'], BASE], [['ui', 'dialog', 'ConfirmModal.java'], MODAL],
66
+ [['ui', 'ChatActivity.java'], PAGE]]) {
67
+ fs.writeFileSync(path.join(src, ...parts), body, 'utf8');
68
+ }
69
+ const ws = path.join(tmp, 'ws');
70
+ fs.mkdirSync(ws);
71
+ fs.writeFileSync(path.join(ws, 'nodes.jsonl'),
72
+ JSON.stringify({ id: 'activity:ChatActivity', label: 'ChatActivity', kind: 'activity' }) + '\n', 'utf8');
73
+
74
+ const [, edges, , stats] = pdn.buildRecords(tmp, 'com.example.app', {}, ws);
75
+ const byVid = new Map();
76
+ for (const e of edges) { byVid.set((e.args || {}).trigger_id, [e, e.args || {}]); }
77
+ const lineOfEdge = (vid) => Number(byVid.get(vid)[0].trigger.split(':').at(-1));
78
+
79
+ test('one edge per (control, dialog)', () => {
80
+ assert.deepEqual([...byVid.keys()].sort(), ['handleAdapter', 'rowBranchy', 'rowOnce']);
81
+ });
82
+
83
+ test('an unambiguous single site is still cited at the site itself', () => {
84
+ assert.equal(lineOfEdge('rowOnce'), 15);
85
+ assert.ok(!('anchor' in byVid.get('rowOnce')[1]));
86
+ });
87
+
88
+ test('two sites in one helper are cited at the helper CALL', () => {
89
+ const a = byVid.get('rowBranchy')[1];
90
+ assert.equal(lineOfEdge('rowBranchy'), 11);
91
+ assert.equal(a.anchor, 'call-site');
92
+ assert.equal(a.show_sites, 2);
93
+ });
94
+
95
+ test('sites in two helpers are cited at the LISTENER, naming both helpers', () => {
96
+ const a = byVid.get('handleAdapter')[1];
97
+ assert.equal(lineOfEdge('handleAdapter'), 5);
98
+ assert.equal(a.anchor, 'listener');
99
+ assert.equal(a.via, 'helpers:showDeleteModal,showFilterModal');
100
+ });
101
+
102
+ test('neither fallback cites a line inside a branch', () => {
103
+ assert.ok(lineOfEdge('rowBranchy') < 13 && lineOfEdge('handleAdapter') < 13);
104
+ });
105
+
106
+ test('the climb is counted', () => { assert.equal(stats.shared_anchor, 2); });
107
+
108
+ test('the graph is identical across two runs (smoke check)', () => {
109
+ const runs = [];
110
+ for (let i = 0; i < 2; i++) {
111
+ const r = spawnSync(process.execPath, [path.join(HERE, '..', 'plaindialog_nav.mjs'), tmp, '--workspace', ws],
112
+ { encoding: 'utf8' });
113
+ runs.push((r.stdout || '').split(/\r?\n/).filter((l) => l).sort().join('\n'));
114
+ }
115
+ assert.equal(runs[0], runs[1]);
116
+ assert.notEqual(runs[0].trim(), '');
117
+ });
@@ -0,0 +1,98 @@
1
+ // Port of test_preference_click_nav.py: a Preference row whose click callback opens another
2
+ // settings PAGE is a labelled navigation edge.
3
+ import { test } from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import * as fs from 'node:fs';
6
+ import * as os from 'node:os';
7
+ import * as path from 'node:path';
8
+ import { buildRecords } from '../preference_nav.mjs';
9
+ import { loadProjectStrings } from '../label_resolve.mjs';
10
+
11
+ const write = (root, rel, text) => {
12
+ const p = path.join(root, rel);
13
+ fs.mkdirSync(path.dirname(p), { recursive: true });
14
+ fs.writeFileSync(p, text, 'utf8');
15
+ };
16
+
17
+ test('preference click-nav', () => {
18
+ const proj = fs.mkdtempSync(path.join(os.tmpdir(), 'prefclick-'));
19
+ try {
20
+ const res = 'app/src/main/res';
21
+ write(proj, res + '/values/strings.xml',
22
+ '<resources><string name="pb">Playback</string>' +
23
+ '<string name="ab">About</string><string name="mx">Mixed</string></resources>');
24
+ write(proj, res + '/xml/prefs_main.xml',
25
+ '<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">' +
26
+ '<Preference android:key="screen_playback" android:title="@string/pb"/>' +
27
+ '<Preference android:key="about" android:title="@string/ab"/>' +
28
+ '<Preference android:key="mixed" android:title="@string/mx"/>' +
29
+ '</PreferenceScreen>');
30
+ write(proj, res + '/xml/prefs_playback.xml',
31
+ '<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"/>');
32
+ const src = 'app/src/main/java/ex/';
33
+ write(proj, src + 'MainPrefs.java', `
34
+ package ex;
35
+ public class MainPrefs extends PreferenceFragmentCompat {
36
+ private static final String PREF_SCREEN_PLAYBACK = "screen_playback";
37
+ public void onCreatePreferences(Bundle b, String k) {
38
+ setPreferencesFromResource(R.xml.prefs_main, k);
39
+ findPreference(PREF_SCREEN_PLAYBACK).setOnPreferenceClickListener(p -> {
40
+ ((Host) getActivity()).openScreen(R.xml.prefs_playback);
41
+ return true;
42
+ });
43
+ findPreference("about").setOnPreferenceClickListener(p -> {
44
+ getParentFragmentManager().beginTransaction()
45
+ .replace(R.id.c, new AboutFragment()).commit();
46
+ return true;
47
+ });
48
+ findPreference("mixed").setOnPreferenceClickListener(p -> {
49
+ if (x) { open(new AboutFragment()); } else { open(new PlaybackPrefs()); }
50
+ return true;
51
+ });
52
+ }
53
+ }
54
+ `);
55
+ write(proj, src + 'PlaybackPrefs.java', `
56
+ package ex;
57
+ public class PlaybackPrefs extends PreferenceFragmentCompat {
58
+ public void onCreatePreferences(Bundle b, String k) {
59
+ setPreferencesFromResource(R.xml.prefs_playback, k);
60
+ }
61
+ }
62
+ `);
63
+ write(proj, src + 'AboutFragment.java', 'package ex;\npublic class AboutFragment extends Fragment {}\n');
64
+ write(proj, res + '/xml/prefs_other.xml',
65
+ '<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">' +
66
+ '<Preference android:key="proxy" android:title="@string/ab"/></PreferenceScreen>');
67
+ write(proj, src + 'OtherPrefs.java', `
68
+ package ex;
69
+ public class OtherPrefs extends PreferenceFragmentCompat {
70
+ public void onCreatePreferences(Bundle b, String k) {
71
+ setPreferencesFromResource(R.xml.prefs_other, k);
72
+ findPreference("proxy").setOnPreferenceClickListener(p -> {
73
+ ProxyPopup d = new ProxyPopup(getActivity());
74
+ d.show();
75
+ return true;
76
+ });
77
+ }
78
+ }
79
+ `);
80
+ write(proj, src + 'ProxyPopup.java', `
81
+ package ex;
82
+ public class ProxyPopup {
83
+ public ProxyPopup(Context c) {}
84
+ public Dialog show() { return new MaterialAlertDialogBuilder(c).setTitle("x").show(); }
85
+ }
86
+ `);
87
+ const strings = loadProjectStrings(proj);
88
+ const [, edges, stats] = buildRecords(proj, strings);
89
+ const nav = edges.filter((e) => e.args.via === 'preference-click-nav').map((e) => [e.target, e.args.label ?? null]);
90
+ const has = (t, l) => nav.some(([a, b]) => a === t && b === l);
91
+ assert.ok(has('fragment:PlaybackPrefs', 'Playback'), `R.xml row via constant key: ${JSON.stringify(nav)}`);
92
+ assert.ok(has('fragment:AboutFragment', 'About'), `fragment-constructing row: ${JSON.stringify(nav)}`);
93
+ assert.ok(!nav.some(([, l]) => l === 'Mixed'), 'two destinations must be refused');
94
+ assert.equal(stats.programmatic_navs, 2);
95
+ const modal = edges.filter((e) => e.args.preference_key === 'proxy').map((e) => e.target);
96
+ assert.deepEqual(modal, ['dialog:ProxyPopup']);
97
+ } finally { fs.rmSync(proj, { recursive: true, force: true }); }
98
+ });
@@ -0,0 +1,87 @@
1
+ // preference_nav host lookup: a preference XML is hosted by the class that binds it, found through the
2
+ // class's supertype chain, a Java typed local holding the id, or a single-XML factory argument.
3
+ import { test } from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import * as fs from 'node:fs';
6
+ import * as os from 'node:os';
7
+ import * as path from 'node:path';
8
+ import { buildHostMap, buildRecords } from '../preference_nav.mjs';
9
+
10
+ const src = (name, text) => ['src', `/p/src/main/java/a/${name}`, text];
11
+
12
+ test('literal bind in a class whose project base reaches PreferenceFragmentCompat', () => {
13
+ const host = buildHostMap([
14
+ src('BasePrefs.kt', 'package a\nabstract class BasePrefs : PreferenceFragmentCompat() {}\n'),
15
+ src('Behavior.kt', 'package a\nclass Behavior : BasePrefs() {\n' +
16
+ ' override fun onCreatePreferences(s: Bundle?, k: String?) {\n' +
17
+ ' setPreferencesFromResource(R.xml.behavior_prefs, k)\n }\n}\n'),
18
+ ], '/p');
19
+ assert.equal(host.get('behavior_prefs')?.[0], 'Behavior');
20
+ });
21
+
22
+ test('Java typed local holding the xml id, bound in the same class', () => {
23
+ const host = buildHostMap([src('Settings.java', 'package a;\n' +
24
+ 'public class Settings extends PreferenceFragmentCompat {\n' +
25
+ ' public void onCreatePreferences(Bundle b, String k) {\n' +
26
+ ' int xmlId = R.xml.settings;\n addPreferencesFromResource(xmlId);\n }\n}\n')], '/p');
27
+ assert.equal(host.get('settings')?.[0], 'Settings');
28
+ });
29
+
30
+ test('a Java int local in an unrelated class is not joined to another class\'s indirect bind', () => {
31
+ const host = buildHostMap([
32
+ src('Holder.java', 'package a;\npublic class Holder {\n void f() { int xmlId = R.xml.stray; }\n}\n'),
33
+ src('Base.kt', 'package a\nopen class Base : PreferenceFragmentCompat() {\n' +
34
+ ' fun bind(xmlId: Int) { addPreferencesFromResource(xmlId) }\n}\n'),
35
+ ], '/p');
36
+ assert.ok(!host.get('stray')?.[0]);
37
+ });
38
+
39
+ const BASE = 'package a\nopen class Plug : PreferenceFragmentCompat() {\n' +
40
+ ' override fun onCreatePreferences(s: Bundle?, k: String?) { addPreferencesFromResource(layout) }\n' +
41
+ ' companion object { fun newInstance(key: String, layout: Int): Plug = Plug() }\n}\n';
42
+
43
+ test('factory argument credits a host that receives exactly one xml', () => {
44
+ const host = buildHostMap([
45
+ src('Plug.kt', BASE),
46
+ src('Sftp.java', 'package a;\npublic class Sftp extends Plug {\n' +
47
+ ' public static Sftp newInstance(String key, int layout) { return new Sftp(); }\n}\n'),
48
+ src('SftpPlugin.kt', 'package a\nclass SftpPlugin {\n' +
49
+ ' fun f() = Sftp.newInstance(pluginKey, R.xml.sftp_prefs)\n}\n'),
50
+ ], '/p');
51
+ assert.equal(host.get('sftp_prefs')?.[0], 'Sftp');
52
+ });
53
+
54
+ test('factory argument refuses a host shared by several xml trees (incl. imported bare factory)', () => {
55
+ const host = buildHostMap([
56
+ src('Plug.kt', BASE),
57
+ src('A.kt', 'package a\nclass A {\n fun f() = Plug.newInstance(pluginKey, R.xml.a_prefs)\n}\n'),
58
+ src('B.kt', 'package b\nimport a.Plug.Companion.newInstance\nclass B {\n' +
59
+ ' fun f() = newInstance(pluginKey, R.xml.b_prefs)\n}\n'),
60
+ ], '/p');
61
+ assert.ok(!host.get('a_prefs')?.[0] && !host.get('b_prefs')?.[0]);
62
+ });
63
+
64
+ test('registry call pairing a host class literal with one xml id', () => {
65
+ const host = buildHostMap([
66
+ src('Base.java', 'package a;\npublic abstract class Base extends PreferenceFragmentCompat {}\n'),
67
+ src('Main.java', 'package a;\npublic class Main extends Base {}\n'),
68
+ src('Registry.java', 'package a;\npublic class Registry {\n Registry() {\n' +
69
+ ' add(Main.class, R.xml.main_settings);\n add(Other.class, R.xml.other_settings);\n }\n}\n'),
70
+ ], '/p');
71
+ assert.equal(host.get('main_settings')?.[0], 'Main');
72
+ assert.ok(!host.get('other_settings')?.[0], 'a class literal that is not a Preference host is ignored');
73
+ });
74
+
75
+ test('hostless counts distinct XML trees', () => {
76
+ const td = fs.mkdtempSync(path.join(os.tmpdir(), 'prefhost-'));
77
+ try {
78
+ const xml = '<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">' +
79
+ '<Preference android:key="k" android:title="T"/></PreferenceScreen>';
80
+ for (const d of ['app/src/main/res/xml', 'app/src/main/res/xml-v21']) {
81
+ fs.mkdirSync(path.join(td, d), { recursive: true });
82
+ fs.writeFileSync(path.join(td, d, 'orphan.xml'), xml);
83
+ }
84
+ const [, , stats] = buildRecords(td, {});
85
+ assert.ok(stats.hostless <= stats.pref_xml, `hostless=${stats.hostless} pref_xml=${stats.pref_xml}`);
86
+ } finally { fs.rmSync(td, { recursive: true, force: true }); }
87
+ });