@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,346 @@
1
+ // Port of test_view_interactions.py: app-independent interaction inventory, semantic gates
2
+ // and output regression.
3
+ import { test, beforeEach, afterEach } from 'node:test';
4
+ import assert from 'node:assert/strict';
5
+ import * as fs from 'node:fs';
6
+ import * as os from 'node:os';
7
+ import * as path from 'node:path';
8
+ import { spawnSync } from 'node:child_process';
9
+ import { fileURLToPath } from 'node:url';
10
+ import * as vi from '../view_interactions.mjs';
11
+ import * as rp from '../run_pipeline.mjs';
12
+ import { PyValueError, deepCopy, jsonDumps } from '../_py.mjs';
13
+
14
+ const SCRIPTS = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
15
+
16
+ const JAVA = `package sample;
17
+ class Host extends Activity {
18
+ Control ctl = new Control();
19
+ void onCreate() { setContentView(R.layout.host); }
20
+ public void reveal(View view) { ctl.show(); }
21
+ public void change(View view) { ctl.choose(); }
22
+ public void persist(View view) { repository.save(); }
23
+ void attach() {
24
+ button.setOnClickListener(v -> { ctl.show(); });
25
+ // ghost.setOnClickListener(v -> fake());
26
+ String ignored = "fake.setOnClickListener(v -> fake())";
27
+ }
28
+ }
29
+ class Control {
30
+ void show() { if (opened) { region.setVisibility(View.GONE); } else { region.addView(new Options()); region.setVisibility(View.VISIBLE); } opened = !opened; }
31
+ void choose() { selected = !selected; editor.setVisibility(selected ? View.VISIBLE : View.GONE); }
32
+ }
33
+ class Options extends LinearLayout { }
34
+ `;
35
+ const XML = `<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android">
36
+ <Button android:id="@+id/reveal" android:onClick="reveal"/>
37
+ <Button android:id="@+id/change" android:onClick="change"/>
38
+ <Button android:id="@+id/persist" android:onClick="persist"/>
39
+ <!-- <Button android:onClick="fake"/> -->
40
+ </LinearLayout>`;
41
+ const KT = `package sample
42
+ class Other : Activity() {
43
+ fun onCreate() { setContentView(R.layout.other) }
44
+ fun attach() {
45
+ findViewById<Button>(R.id.open).setOnClickListener { area.visibility = View.VISIBLE }
46
+ }
47
+ }
48
+ `;
49
+ const THIRD = `package sample;
50
+ class Third extends Activity {
51
+ Repo repo = new Repo();
52
+ Runnable cb;
53
+ Listener listener;
54
+ Sink sink;
55
+ MutableLiveData<Boolean> open = new MutableLiveData<>();
56
+ void onCreate() { setContentView(R.layout.other); }
57
+ void attach() {
58
+ save.setOnClickListener(v -> { repo.store(1); count++; });
59
+ deep.setOnClickListener(v -> { stepOne(); });
60
+ fwd.setOnClickListener(listener);
61
+ cb.setOnClickListener(v -> cb.run());
62
+ iface.setOnClickListener(v -> sink.consume(1));
63
+ live.setOnClickListener(v -> open.setValue(true));
64
+ go.setOnClickListener(v -> {
65
+ startActivity(new Intent(this, Host.class));
66
+ });
67
+ }
68
+ void stepOne() { stepTwo(); }
69
+ void stepTwo() { panel.setVisibility(View.VISIBLE); }
70
+ }
71
+ class Repo { void store(int v) { cache = v; } }
72
+ interface Sink { void consume(int v); }
73
+ class ShowingSink implements Sink { public void consume(int v) { dialog.show(); } }
74
+ `;
75
+
76
+ const plain = (x) => JSON.parse(JSON.stringify(x));
77
+ const throwsValueError = (fn) => assert.throws(fn, (e) => e instanceof PyValueError);
78
+ const run = (argv) => spawnSync(argv[0], argv.slice(1), { encoding: 'utf8' });
79
+ const byte = (p) => fs.readFileSync(p);
80
+
81
+ let t;
82
+ beforeEach(() => {
83
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'vi-'));
84
+ t = { root, project: path.join(root, 'project'), ws: path.join(root, 'ws'), java: 'app/src/main/java/sample/Host.java' };
85
+ fs.mkdirSync(t.ws);
86
+ write(t.java, JAVA);
87
+ write('app/src/main/java/sample/Other.kt', KT);
88
+ write('app/src/main/res/layout/host.xml', XML);
89
+ write('app/src/main/res/layout/other.xml', '<FrameLayout/>');
90
+ write('app/src/test/java/sample/Noise.java', JAVA);
91
+ t.nodes = [{ id: 'activity:Host', kind: 'activity', name: 'Host', fqn: 'sample.Host', is_launcher: true,
92
+ provenance: 'static:manifest', declared_at: 'app/src/main/AndroidManifest.xml' },
93
+ { id: 'activity:Other', kind: 'activity', name: 'Other', fqn: 'sample.Other', provenance: 'static:manifest' }];
94
+ jsonl('nodes.jsonl', t.nodes);
95
+ jsonl('edges.jsonl', []);
96
+ vi.extract(t.ws, t.project);
97
+ t.wl = vi.readJson(path.join(t.ws, 'view_interactions_worklist.json'));
98
+ });
99
+ afterEach(() => { fs.rmSync(t.root, { recursive: true, force: true }); });
100
+
101
+ function write(rel, text) {
102
+ const p = path.join(t.project, rel);
103
+ fs.mkdirSync(path.dirname(p), { recursive: true });
104
+ fs.writeFileSync(p, text, 'utf8');
105
+ }
106
+ const pyDumps = (r) => jsonDumps(r); // json.dumps defaults
107
+ function jsonl(name, rows) { fs.writeFileSync(path.join(t.ws, name), rows.map((r) => pyDumps(r) + '\n').join(''), 'utf8'); }
108
+ const site = (it, fragment) => it.code_window.find((c) => c.text.includes(fragment)).at;
109
+
110
+ function answers() {
111
+ const items = [];
112
+ for (const it of t.wl.items) {
113
+ const handler = it.widget.handler ?? null;
114
+ let a = { key: it.key, category: 'unresolved', reason: 'Not reviewed in fixture' };
115
+ if (handler === 'reveal' || handler === 'change') {
116
+ const panel = handler === 'reveal';
117
+ const s = site(it, panel ? 'region.addView' : 'selected =');
118
+ const kind = panel ? 'panel' : 'ui-state';
119
+ const surface = { key: panel ? 'options' : 'editing', kind, label: panel ? 'Options' : 'Editing',
120
+ observable: 'New interactive controls visible', evidence: [s] };
121
+ a = { ...a, category: panel ? 'panel' : 'state', evidence: [s], reason: 'Callback changes an interactive surface',
122
+ transitions: [{ host: 'activity:Host', target: surface, effect: panel ? 'open' : 'state', guard: null,
123
+ instruction: 'Tap the appropriate control', evidence: [s] }] };
124
+ if (panel) {
125
+ a.transitions.push({ host: 'activity:Host', source: vi.surfaceId('activity:Host', 'options', 'panel'),
126
+ target: 'activity:Host', effect: 'close', guard: null, instruction: 'Tap to close the panel', evidence: [s] });
127
+ }
128
+ } else if (handler === 'persist') {
129
+ a = { ...a, category: 'action', reason: 'Saves data without a new surface', evidence: [site(it, 'repository.save')] };
130
+ }
131
+ items.push(a);
132
+ }
133
+ return { items };
134
+ }
135
+ const saveAnswers = (ans = null) => vi.save(path.join(t.ws, 'view_interactions_answers.json'), ans ?? answers());
136
+ const W = (f) => path.join(t.ws, f);
137
+
138
+ test('inventory and context', () => {
139
+ assert.equal(t.wl.items.length, 4);
140
+ assert.deepEqual(t.wl.prescreened.map((it) => it.widget.handler), ['persist']);
141
+ const xml = [...t.wl.items, ...t.wl.prescreened].filter((it) => it.binding === 'xml-onClick');
142
+ assert.equal(xml.length, 3);
143
+ assert.ok(xml.every((it) => JSON.stringify(it.host_candidates) === '["activity:Host"]'));
144
+ const opening = xml.find((it) => it.widget.handler === 'reveal');
145
+ assert.ok(site(opening, 'region.addView'));
146
+ const kotlin = t.wl.items.find((it) => it.trigger_at.includes('Other.kt'));
147
+ assert.deepEqual(plain(kotlin.host_candidates), ['activity:Other']);
148
+ assert.equal(kotlin.widget.view_id, 'open');
149
+ assert.equal(vi.readJson(W('interaction_audit.json')).unresolved, 4);
150
+ });
151
+
152
+ test('apply idempotent and no false action page', () => {
153
+ saveAnswers();
154
+ vi.apply(t.ws);
155
+ const first = [byte(W('nodes.jsonl')), byte(W('edges.jsonl'))];
156
+ assert.equal(vi.records(W('nodes.jsonl')).length, 4);
157
+ assert.equal(vi.records(W('edges.jsonl')).length, 3);
158
+ assert.equal(vi.readJson(W('interaction_audit.json')).unresolved, 2);
159
+ vi.apply(t.ws);
160
+ assert.ok(first[0].equals(byte(W('nodes.jsonl'))) && first[1].equals(byte(W('edges.jsonl'))));
161
+ saveAnswers({ items: t.wl.items.map((it) => ({ key: it.key, category: 'unresolved', reason: 'Withdrawn' })) });
162
+ vi.apply(t.ws);
163
+ assert.deepEqual(plain(vi.records(W('nodes.jsonl'))), plain(t.nodes));
164
+ assert.deepEqual(plain(vi.records(W('edges.jsonl'))), []);
165
+ });
166
+
167
+ test('bad answers leave graph untouched', () => {
168
+ const before = byte(W('nodes.jsonl'));
169
+ const valid = answers();
170
+ const m = [];
171
+ const partial = deepCopy(valid); partial.items.pop(); m.push(partial);
172
+ const duplicate = deepCopy(valid); duplicate.items.push(duplicate.items[0]); m.push(duplicate);
173
+ const invented = deepCopy(valid); invented.items[0].evidence = ['missing.java:42']; m.push(invented);
174
+ const cross = deepCopy(valid); cross.items[0].transitions[0].host = 'activity:Other'; m.push(cross);
175
+ const noGuard = deepCopy(valid); delete noGuard.items[0].transitions[0].guard; m.push(noGuard);
176
+ const wrong = deepCopy(valid); wrong.items[0].transitions[0].target.kind = 'activity'; m.push(wrong);
177
+ for (const ans of m) {
178
+ saveAnswers(ans);
179
+ throwsValueError(() => vi.apply(t.ws));
180
+ assert.ok(before.equals(byte(W('nodes.jsonl'))));
181
+ }
182
+ });
183
+
184
+ test('stale source and evidence gate', () => {
185
+ saveAnswers();
186
+ const it = t.wl.items[0];
187
+ vi.addEvidence(t.ws, [`${it.key}=${t.java}:1`]);
188
+ throwsValueError(() => vi.addEvidence(t.ws, [`${it.key}=../../outside.java:1`]));
189
+ write(t.java, JAVA + '\n// source changed');
190
+ throwsValueError(() => vi.apply(t.ws));
191
+ });
192
+
193
+ test('renaming does not change discovery', () => {
194
+ write(t.java, JAVA.replaceAll('reveal', 'zeta').replaceAll('show()', 'omega()'));
195
+ write('app/src/main/res/layout/host.xml', XML.replaceAll('reveal', 'zeta'));
196
+ const renamed = vi.collect(t.project, t.ws);
197
+ assert.equal(renamed.count, t.wl.count);
198
+ const item = renamed.items.find((it) => (it.widget.handler ?? null) === 'zeta');
199
+ assert.ok(site(item, 'region.addView'));
200
+ });
201
+
202
+ function prescreenFixture(edges = []) {
203
+ write('app/src/main/java/sample/Third.java', THIRD);
204
+ t.nodes.push({ id: 'activity:Third', kind: 'activity', name: 'Third', fqn: 'sample.Third', provenance: 'static:manifest' });
205
+ jsonl('nodes.jsonl', t.nodes);
206
+ jsonl('edges.jsonl', edges);
207
+ vi.extract(t.ws, t.project);
208
+ return vi.readJson(W('view_interactions_worklist.json'));
209
+ }
210
+ function bySite(wl, fragment) {
211
+ const lines = fs.readFileSync(path.join(t.project, 'app/src/main/java/sample/Third.java'), 'utf8').split('\n');
212
+ const line = lines.findIndex((x) => x.includes(fragment)) + 1;
213
+ const at = `app/src/main/java/sample/Third.java:${line}`;
214
+ for (const bucket of ['items', 'prescreened']) {
215
+ for (const it of wl[bucket]) { if (it.trigger_at === at) { return [bucket, it]; } }
216
+ }
217
+ throw new assert.AssertionError({ message: at });
218
+ }
219
+
220
+ test('prescreen only proven actions', () => {
221
+ const wl = prescreenFixture();
222
+ assert.equal(bySite(wl, 'save.setOnClickListener')[0], 'prescreened');
223
+ for (const s of ['deep.setOnClickListener', 'fwd.setOnClickListener', 'cb.setOnClickListener',
224
+ 'iface.setOnClickListener', 'live.setOnClickListener']) {
225
+ assert.equal(bySite(wl, s)[0], 'items', s);
226
+ }
227
+ const pre = new Set(wl.prescreened.map((p) => p.key));
228
+ assert.ok(t.wl.items.every((it) => !pre.has(it.key)));
229
+ const disabled = vi.collect(t.project, t.ws, false);
230
+ assert.deepEqual(plain(disabled.prescreened), []);
231
+ assert.equal(disabled.count, wl.items.length + wl.prescreened.length);
232
+ });
233
+
234
+ test('ownerless binding prescreened', () => {
235
+ write('app/src/main/java/sample/Orphan.java',
236
+ 'package sample;\nclass Orphan {\n void bind() {\n b.setOnClickListener(v -> { startActivity(new Intent()); });\n }\n}\n');
237
+ let wl = vi.collect(t.project, t.ws);
238
+ const orphan = wl.prescreened.filter((it) => it.trigger_at.includes('Orphan.java'));
239
+ assert.equal(orphan.length, 1);
240
+ assert.equal(orphan[0].prescreen.category, 'ownerless');
241
+ assert.ok(!wl.items.some((it) => it.trigger_at.includes('Orphan.java')));
242
+ vi.extract(t.ws, t.project);
243
+ wl = vi.readJson(W('view_interactions_worklist.json'));
244
+ saveAnswers({ items: wl.items.map((it) => ({ key: it.key, category: 'action', reason: 'fixture', evidence: [it.trigger_at] })) });
245
+ vi.apply(t.ws);
246
+ const audit = vi.readJson(W('interaction_audit.json'));
247
+ assert.equal(audit.unresolved, 0);
248
+ assert.equal(audit.ownerless, 1);
249
+ const a = run([process.execPath, path.join(SCRIPTS, 'assemble.mjs'), t.ws]);
250
+ assert.equal(a.status, 0, a.stdout + a.stderr);
251
+ const p = run([process.execPath, path.join(SCRIPTS, 'audit.mjs'), t.ws]);
252
+ assert.ok(!(p.stdout + p.stderr).includes('remain unclassified'));
253
+ assert.ok(p.stdout.includes('ownerless_interactions=1'));
254
+ });
255
+
256
+ test('window is callback not registering method', () => {
257
+ const wl = prescreenFixture();
258
+ const [, go] = bySite(wl, 'go.setOnClickListener');
259
+ const text = go.code_window.map((c) => c.text).join('\n');
260
+ assert.ok(text.includes('startActivity'));
261
+ assert.ok(!text.includes('repo.store'));
262
+ const [, deep] = bySite(wl, 'deep.setOnClickListener');
263
+ assert.ok(deep.code_window.map((c) => c.text).join('\n').includes('panel.setVisibility'));
264
+ });
265
+
266
+ test('prescreened reach audit without answers', () => {
267
+ const wl = prescreenFixture();
268
+ assert.ok(wl.prescreened.length);
269
+ const ans = { items: wl.items.map((it) => ({ key: it.key, category: 'unresolved', reason: 'fixture' })) };
270
+ saveAnswers(ans);
271
+ vi.apply(t.ws);
272
+ const audit = vi.readJson(W('interaction_audit.json'));
273
+ assert.equal(audit.count, wl.items.length + wl.prescreened.length);
274
+ const auto = audit.items.filter((a) => a.prescreened);
275
+ assert.equal(auto.length, wl.prescreened.length);
276
+ assert.ok(auto.every((a) => a.category === 'action'));
277
+ const bad = deepCopy(ans);
278
+ bad.items.push({ key: wl.prescreened[0].key, category: 'action', reason: 'dup', evidence: wl.prescreened[0].prescreen.evidence });
279
+ saveAnswers(bad);
280
+ throwsValueError(() => vi.apply(t.ws));
281
+ });
282
+
283
+ test('covered navigation confirms without duplicate edge', () => {
284
+ const java = 'app/src/main/java/sample/Third.java';
285
+ write(java, THIRD);
286
+ const line = THIRD.split('\n').findIndex((x) => x.includes('startActivity')) + 1;
287
+ const existing = { source: 'activity:Third', target: 'activity:Host', mechanism: 'startActivity',
288
+ trigger: `Third@${java}:${line}`, provenance: 'static:homegraph' };
289
+ const wl = prescreenFixture([existing]);
290
+ const [bucket, it] = bySite(wl, 'go.setOnClickListener');
291
+ assert.equal(bucket, 'items');
292
+ assert.deepEqual(it.covered_by.map((c) => [c.source, c.target]), [['activity:Third', 'activity:Host']]);
293
+ const s = it.code_window.find((c) => c.text.includes('startActivity')).at;
294
+ let items = wl.items.map((x) => (x.key === it.key ? { key: x.key, category: 'navigation', reason: 'covered', evidence: [s] }
295
+ : { key: x.key, category: 'unresolved', reason: 'fixture' }));
296
+ saveAnswers({ items });
297
+ vi.apply(t.ws);
298
+ assert.deepEqual(plain(vi.records(W('edges.jsonl'))), [existing]);
299
+ items[items.map((a) => a.key).indexOf(it.key)].transitions = [{ host: 'activity:Third', target: 'activity:Host',
300
+ effect: 'navigate', guard: null, instruction: 'Tap go', evidence: [s] }];
301
+ saveAnswers({ items });
302
+ vi.apply(t.ws);
303
+ assert.deepEqual(plain(vi.records(W('edges.jsonl'))), [existing]);
304
+ const plainItem = wl.items.find((x) => !x.covered_by || !x.covered_by.length);
305
+ items = wl.items.map((x) => ({ key: x.key, category: 'unresolved', reason: 'fixture' }));
306
+ items[items.map((a) => a.key).indexOf(plainItem.key)] = { key: plainItem.key, category: 'navigation', reason: 'x',
307
+ evidence: [plainItem.trigger_at] };
308
+ saveAnswers({ items });
309
+ throwsValueError(() => vi.apply(t.ws));
310
+ });
311
+
312
+ test('pipeline order', () => {
313
+ const names = rp.plan(t.project, t.ws, 'sample', {}).map((s) => s[0]);
314
+ assert.ok(names.indexOf('view_interactions-extract') < names.indexOf('_halt'));
315
+ assert.ok(names.indexOf('view_interactions-apply') > names.indexOf('_halt'));
316
+ const after = names.slice(names.indexOf('view_interactions-apply'));
317
+ assert.ok(after.indexOf('assemble') < after.indexOf('click_paths'));
318
+ assert.ok(after.indexOf('click_paths') < after.indexOf('nl_hints-apply'));
319
+ });
320
+
321
+ test('downstream', () => {
322
+ saveAnswers();
323
+ vi.apply(t.ws);
324
+ for (const script of ['assemble.mjs', 'click_paths.mjs', 'utg_html.mjs']) {
325
+ const p = run([process.execPath, path.join(SCRIPTS, script), t.ws]);
326
+ assert.equal(p.status, 0, p.stdout + p.stderr);
327
+ }
328
+ const graph = vi.readJson(W('utg.json'));
329
+ assert.equal(graph.links.length, 3);
330
+ const cp = vi.readJson(W('click_paths.json'));
331
+ const surface = vi.surfaceId('activity:Host', 'options', 'panel');
332
+ const steps = cp.paths[surface].steps;
333
+ assert.equal(steps[steps.length - 1].nl_hint, 'Tap the appropriate control');
334
+ const converter = path.join(path.dirname(SCRIPTS), 'tools', 'convert_static_utg_to_ui_elements.ts');
335
+ const out = W('ui_elements.json');
336
+ let p = run(['node', converter, '--input', t.ws, '--out', out]);
337
+ assert.equal(p.status, 0, p.stdout + p.stderr);
338
+ const raw = JSON.stringify(vi.readJson(out));
339
+ assert.ok(raw.includes('UI_state_change'));
340
+ assert.ok(raw.includes('Navigate_overlay_close'));
341
+ assert.ok(raw.includes('Not reviewed in fixture'));
342
+ assert.ok(!raw.includes('"value": "Tap the appropriate control"') && !raw.includes('"value":"Tap the appropriate control"'));
343
+ p = run([process.execPath, path.join(SCRIPTS, 'audit.mjs'), t.ws, '--strict']);
344
+ assert.equal(p.status, 1);
345
+ assert.ok(p.stdout.includes('unresolved_interactions=2'));
346
+ });