@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,135 @@
|
|
|
1
|
+
// Port of test_activity_alias_launcher.py: <activity-alias> launcher / alias names.
|
|
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 mf from '../manifest.mjs';
|
|
8
|
+
|
|
9
|
+
const ALIASED = `<?xml version="1.0" encoding="utf-8"?>
|
|
10
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
11
|
+
package="com.example.app">
|
|
12
|
+
<application>
|
|
13
|
+
<activity android:name=".MainActivity" android:exported="true" />
|
|
14
|
+
<activity android:name=".ui.SplashActivity" android:exported="true" />
|
|
15
|
+
<activity-alias
|
|
16
|
+
android:name=".MainActivityAlias"
|
|
17
|
+
android:enabled="true"
|
|
18
|
+
android:exported="true"
|
|
19
|
+
android:targetActivity="com.example.app.ui.SplashActivity">
|
|
20
|
+
<intent-filter>
|
|
21
|
+
<action android:name="android.intent.action.MAIN" />
|
|
22
|
+
<category android:name="android.intent.category.LAUNCHER" />
|
|
23
|
+
</intent-filter>
|
|
24
|
+
</activity-alias>
|
|
25
|
+
<activity-alias
|
|
26
|
+
android:name=".MainActivityAliasB"
|
|
27
|
+
android:enabled="false"
|
|
28
|
+
android:exported="true"
|
|
29
|
+
android:targetActivity="com.example.app.ui.SplashActivity">
|
|
30
|
+
<intent-filter>
|
|
31
|
+
<action android:name="android.intent.action.MAIN" />
|
|
32
|
+
<category android:name="android.intent.category.LAUNCHER" />
|
|
33
|
+
</intent-filter>
|
|
34
|
+
</activity-alias>
|
|
35
|
+
</application>
|
|
36
|
+
</manifest>
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
const PLAIN = `<?xml version="1.0" encoding="utf-8"?>
|
|
40
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
41
|
+
package="com.example.app">
|
|
42
|
+
<application>
|
|
43
|
+
<activity android:name=".MainActivity" android:exported="true">
|
|
44
|
+
<intent-filter>
|
|
45
|
+
<action android:name="android.intent.action.MAIN" />
|
|
46
|
+
<category android:name="android.intent.category.LAUNCHER" />
|
|
47
|
+
</intent-filter>
|
|
48
|
+
</activity>
|
|
49
|
+
</application>
|
|
50
|
+
</manifest>
|
|
51
|
+
`;
|
|
52
|
+
|
|
53
|
+
const DISABLED_ONLY = ALIASED.replaceAll('android:enabled="true"', 'android:enabled="false"');
|
|
54
|
+
|
|
55
|
+
function parse(xml) {
|
|
56
|
+
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'mf-'));
|
|
57
|
+
try {
|
|
58
|
+
const p = path.join(tmp, 'AndroidManifest.xml');
|
|
59
|
+
fs.writeFileSync(p, xml, 'utf8');
|
|
60
|
+
return Object.fromEntries(mf.parseManifest(p, 'com.example.app').map((r) => [r.name, r]));
|
|
61
|
+
} finally { fs.rmSync(tmp, { recursive: true, force: true }); }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const ALIASES = ['com.example.app.MainActivityAlias', 'com.example.app.MainActivityAliasB'];
|
|
65
|
+
|
|
66
|
+
test('aliased launcher credits the target', () => {
|
|
67
|
+
const byName = parse(ALIASED);
|
|
68
|
+
const splash = byName['com.example.app.ui.SplashActivity'];
|
|
69
|
+
assert.equal(splash.is_launcher, true);
|
|
70
|
+
assert.equal(byName['com.example.app.MainActivity'].is_launcher, false);
|
|
71
|
+
assert.deepEqual(splash.aliases, ALIASES);
|
|
72
|
+
assert.deepEqual(Object.keys(byName).sort(), ['com.example.app.MainActivity', 'com.example.app.ui.SplashActivity']);
|
|
73
|
+
assert.ok(!('alias_disabled_only' in splash));
|
|
74
|
+
const node = mf.toNode(splash);
|
|
75
|
+
assert.equal(node.is_launcher, true);
|
|
76
|
+
assert.deepEqual(node.aliases, ALIASES);
|
|
77
|
+
assert.equal(node.id, 'activity:SplashActivity');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('the launch contract names the enabled launcher alias, not its target class', () => {
|
|
81
|
+
// The target usually carries no filter and is not exported: `am start -n <target>` from the
|
|
82
|
+
// shell is a SecurityException (measured, Simple Calendar: 98 of 100 tasks failed at launch).
|
|
83
|
+
const splash = parse(ALIASED)['com.example.app.ui.SplashActivity'];
|
|
84
|
+
assert.equal(splash.launcher_alias, 'com.example.app.MainActivityAlias');
|
|
85
|
+
assert.deepEqual(mf.toNode(splash).launch, { type: 'component', component_fqn: 'com.example.app.MainActivityAlias' });
|
|
86
|
+
// No enabled alias: nothing better is known, keep the class.
|
|
87
|
+
const off = parse(DISABLED_ONLY)['com.example.app.ui.SplashActivity'];
|
|
88
|
+
assert.ok(!('launcher_alias' in off));
|
|
89
|
+
assert.equal(mf.toNode(off).launch.component_fqn, 'com.example.app.ui.SplashActivity');
|
|
90
|
+
// The class's own LAUNCHER filter wins over an alias.
|
|
91
|
+
assert.equal(mf.toNode(parse(PLAIN)['com.example.app.MainActivity']).launch.component_fqn, 'com.example.app.MainActivity');
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test('an alias enabled by a resource is only a fallback launcher', () => {
|
|
95
|
+
const xml = ALIASED.replace('android:enabled="true"', 'android:enabled="@bool/is_default"');
|
|
96
|
+
const viaRes = parse(xml)['com.example.app.ui.SplashActivity'];
|
|
97
|
+
assert.equal(viaRes.launcher_alias, 'com.example.app.MainActivityAlias');
|
|
98
|
+
// A literal enabled alias wins over a resource-valued one declared first.
|
|
99
|
+
const both = xml.replace('android:name=".MainActivityAliasB"\n android:enabled="false"',
|
|
100
|
+
'android:name=".MainActivityAliasB"\n android:enabled="true"');
|
|
101
|
+
assert.equal(parse(both)['com.example.app.ui.SplashActivity'].launcher_alias, 'com.example.app.MainActivityAliasB');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('a deep link only an alias declares launches through that alias', () => {
|
|
105
|
+
const xml = `<?xml version="1.0" encoding="utf-8"?>
|
|
106
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.app">
|
|
107
|
+
<application>
|
|
108
|
+
<activity android:name=".Viewer" />
|
|
109
|
+
<activity-alias android:name=".ViewerLink" android:exported="true" android:targetActivity=".Viewer">
|
|
110
|
+
<intent-filter>
|
|
111
|
+
<action android:name="android.intent.action.VIEW" />
|
|
112
|
+
<data android:scheme="app" android:host="view" />
|
|
113
|
+
</intent-filter>
|
|
114
|
+
</activity-alias>
|
|
115
|
+
</application>
|
|
116
|
+
</manifest>
|
|
117
|
+
`;
|
|
118
|
+
const v = parse(xml)['com.example.app.Viewer'];
|
|
119
|
+
assert.equal(v.exported, false);
|
|
120
|
+
const launch = mf.toNode(v).launch;
|
|
121
|
+
assert.equal(launch.type, 'deep-link');
|
|
122
|
+
assert.equal(launch.component_fqn, 'com.example.app.ViewerLink');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('all-disabled aliases still credit LAUNCHER and are recorded', () => {
|
|
126
|
+
const t = parse(DISABLED_ONLY)['com.example.app.ui.SplashActivity'];
|
|
127
|
+
assert.equal(t.is_launcher, true);
|
|
128
|
+
assert.equal(t.alias_disabled_only, true);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test('an app with no alias is unaffected', () => {
|
|
132
|
+
const m = parse(PLAIN)['com.example.app.MainActivity'];
|
|
133
|
+
assert.equal(m.is_launcher, true);
|
|
134
|
+
assert.ok(!('aliases' in m));
|
|
135
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Activity-ness is read from a class's own header and its supertype CHAIN, never from file text:
|
|
2
|
+
// a constructor parameter typed `AppCompatActivity` or a Javadoc example is not a supertype, an
|
|
3
|
+
// Activity whose name lacks the `Activity` suffix is still a page, and an abstract base Activity
|
|
4
|
+
// credits its navigation to its concrete subclasses instead of becoming an `unknown` endpoint.
|
|
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 { ActivityChain, EXTENDS_ACTIVITY_RE, buildClassIndex } from '../host_resolve.mjs';
|
|
11
|
+
import { _owningClass, buildRecords } from '../fragment_nav.mjs';
|
|
12
|
+
import { _recreditNonPageSources } from '../assemble.mjs';
|
|
13
|
+
|
|
14
|
+
const ADAPTER_KT = `
|
|
15
|
+
package com.example.app
|
|
16
|
+
class RowAdapter(private val activity: AppCompatActivity, val rows: List<Row>) : RecyclerView.Adapter<VH>() {
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
const JAVADOC_JAVA = `
|
|
20
|
+
package com.example.app;
|
|
21
|
+
/**
|
|
22
|
+
* Usage:
|
|
23
|
+
* class MyActivity extends AppCompatActivity { }
|
|
24
|
+
* class MyViewModel extends ViewModel { }
|
|
25
|
+
*/
|
|
26
|
+
public class PagedAdapter<T> extends RecyclerView.Adapter<VH> { }
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
test('EXTENDS_ACTIVITY_RE reads the header, not a ctor parameter or a comment', () => {
|
|
30
|
+
assert.equal(EXTENDS_ACTIVITY_RE.test(ADAPTER_KT), false, 'ctor parameter type is not a supertype');
|
|
31
|
+
assert.equal(EXTENDS_ACTIVITY_RE.test(JAVADOC_JAVA), false, 'a Javadoc example is not a declaration');
|
|
32
|
+
assert.ok(EXTENDS_ACTIVITY_RE.test('class MainActivity : AppCompatActivity() {\n}'), 'Kotlin supertype');
|
|
33
|
+
assert.ok(EXTENDS_ACTIVITY_RE.test('public class A extends\n AppCompatActivity\n implements B {}'), 'wrapped Java header');
|
|
34
|
+
assert.ok(EXTENDS_ACTIVITY_RE.test('class A @Inject constructor(x: Int) : BaseActivity() {}'), 'after an injected ctor');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('_owningClass ignores classes named in comments', () => {
|
|
38
|
+
assert.equal(_owningClass(JAVADOC_JAVA), 'PagedAdapter');
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const SOURCES = [
|
|
42
|
+
['ActivityMain.java', 'public class ActivityMain extends ActivityBase implements Foo { }'],
|
|
43
|
+
['ActivityBase.java', 'abstract class ActivityBase extends AppCompatActivity { }'],
|
|
44
|
+
['RowAdapter.kt', ADAPTER_KT],
|
|
45
|
+
['Panels.kt', 'abstract class PanelActivity : AppCompatActivity()\nclass PlayerActivity : PanelActivity(),\n Listener {\n}\n'],
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
test('ActivityChain: chain decides Activity-ness; abstract bases credit concrete pages', () => {
|
|
49
|
+
const chain = new ActivityChain(buildClassIndex(SOURCES), new Set(['ActivityMain', 'PlayerActivity']));
|
|
50
|
+
assert.ok(chain.isPage('ActivityMain'), 'suffix-less Activity via a project base is a page');
|
|
51
|
+
assert.ok(chain.isBase('ActivityBase') && !chain.isPage('ActivityBase'), 'abstract base is not a page');
|
|
52
|
+
assert.deepEqual(chain.concretePages('ActivityBase'), ['ActivityMain']);
|
|
53
|
+
assert.deepEqual(chain.concretePages('PanelActivity'), ['PlayerActivity'], 'bodyless Kotlin header parsed');
|
|
54
|
+
assert.equal(chain.isActivity('RowAdapter'), false, 'adapter with an Activity ctor param is not an Activity');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const BASE_KT = `
|
|
58
|
+
package com.example.app
|
|
59
|
+
abstract class HostBaseActivity : AppCompatActivity() {
|
|
60
|
+
fun openDetail() {
|
|
61
|
+
btnDetail.setOnClickListener {
|
|
62
|
+
supportFragmentManager.beginTransaction().replace(R.id.container, DetailFragment()).commit()
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
`;
|
|
67
|
+
const MAIN_KT = 'package com.example.app\nclass MainActivity : HostBaseActivity() {\n}\n';
|
|
68
|
+
const DETAIL_KT = 'package com.example.app\nclass DetailFragment : Fragment() {\n}\n';
|
|
69
|
+
|
|
70
|
+
test('fragment_nav credits a base Activity\'s transaction to its concrete subclass', () => {
|
|
71
|
+
const proj = fs.mkdtempSync(path.join(os.tmpdir(), 'achain'));
|
|
72
|
+
const src = path.join(proj, 'app', 'src', 'main', 'java', 'com', 'example', 'app');
|
|
73
|
+
fs.mkdirSync(src, { recursive: true });
|
|
74
|
+
for (const [n, b] of Object.entries({ 'HostBaseActivity.kt': BASE_KT, 'MainActivity.kt': MAIN_KT, 'DetailFragment.kt': DETAIL_KT })) {
|
|
75
|
+
fs.writeFileSync(path.join(src, n), b, 'utf8');
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const [, edges] = buildRecords(proj, 'com.example.app', {}, { manifest: new Set(['MainActivity']) });
|
|
79
|
+
const sources = edges.filter((e) => e.target === 'fragment:DetailFragment').map((e) => e.source);
|
|
80
|
+
assert.deepEqual(sources, ['activity:MainActivity'], 'no edge from the abstract base');
|
|
81
|
+
} finally { fs.rmSync(proj, { recursive: true, force: true }); }
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test('assemble re-credits undeclared non-page sources, drops unowned ones', () => {
|
|
85
|
+
const proj = fs.mkdtempSync(path.join(os.tmpdir(), 'achain2'));
|
|
86
|
+
const src = path.join(proj, 'app', 'src', 'main', 'java', 'com', 'example', 'app');
|
|
87
|
+
fs.mkdirSync(src, { recursive: true });
|
|
88
|
+
const files = {
|
|
89
|
+
'MainActivity.kt': 'package com.example.app\nclass MainActivity : HostBaseActivity() {\n val a = RowAdapter(this, rows)\n}\n',
|
|
90
|
+
'HostBaseActivity.kt': 'package com.example.app\nabstract class HostBaseActivity : AppCompatActivity() {\n}\n',
|
|
91
|
+
'RowAdapter.kt': ADAPTER_KT,
|
|
92
|
+
'LonelyHelper.kt': 'package com.example.app\nclass LonelyHelper(val activity: AppCompatActivity) {\n}\n',
|
|
93
|
+
};
|
|
94
|
+
for (const [n, b] of Object.entries(files)) { fs.writeFileSync(path.join(src, n), b, 'utf8'); }
|
|
95
|
+
try {
|
|
96
|
+
const nodes = { 'activity:MainActivity': { id: 'activity:MainActivity' }, 'dialog:ColorDialog': { id: 'dialog:ColorDialog' } };
|
|
97
|
+
const mk = (s) => ({ source: s, target: 'dialog:ColorDialog', mechanism: 'open-overlay', trigger: `${s}@x:1` });
|
|
98
|
+
const [out, st] = _recreditNonPageSources(nodes,
|
|
99
|
+
[mk('activity:RowAdapter'), mk('activity:HostBaseActivity'), mk('activity:LonelyHelper'), mk('activity:MainActivity')], proj, null);
|
|
100
|
+
const srcs = out.map((e) => e.source);
|
|
101
|
+
assert.deepEqual(srcs, ['activity:MainActivity', 'activity:MainActivity', 'activity:MainActivity']);
|
|
102
|
+
assert.equal(out[0].args.written_in, 'RowAdapter');
|
|
103
|
+
assert.equal(out[1].args.credited_via, 'base-activity-subclass');
|
|
104
|
+
assert.equal(st.dropped, 1, 'an owner no page constructs is dropped, not fabricated');
|
|
105
|
+
} finally { fs.rmSync(proj, { recursive: true, force: true }); }
|
|
106
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Port of test_bottom_sheet_container.py: a fragment committed into a BottomSheetBehavior
|
|
2
|
+
// container needs a gesture; an ordinary container keeps its auto-load.
|
|
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 fn from '../fragment_nav.mjs';
|
|
9
|
+
|
|
10
|
+
function write(root, rel, text) {
|
|
11
|
+
const p = path.join(root, rel);
|
|
12
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
13
|
+
fs.writeFileSync(p, text, 'utf8');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
test('bottom-sheet container', () => {
|
|
17
|
+
const proj = fs.mkdtempSync(path.join(os.tmpdir(), 'bsc-'));
|
|
18
|
+
const ws = fs.mkdtempSync(path.join(os.tmpdir(), 'bscws-'));
|
|
19
|
+
try {
|
|
20
|
+
write(proj, 'app/src/main/res/layout/main.xml', `<androidx.coordinatorlayout.widget.CoordinatorLayout
|
|
21
|
+
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
22
|
+
xmlns:app="http://schemas.android.com/apk/res-auto">
|
|
23
|
+
<FrameLayout android:id="@+id/content_area"/>
|
|
24
|
+
<androidx.fragment.app.FragmentContainerView android:id="@+id/sheet"
|
|
25
|
+
app:layout_behavior="ex.ui.LockableSheetBehavior"/>
|
|
26
|
+
</androidx.coordinatorlayout.widget.CoordinatorLayout>`);
|
|
27
|
+
write(proj, 'app/src/main/java/ex/ui/LockableSheetBehavior.java',
|
|
28
|
+
'package ex.ui;\npublic class LockableSheetBehavior<V> extends BottomSheetBehavior<V> {}\n');
|
|
29
|
+
write(proj, 'app/src/main/java/ex/Host.java', `package ex;
|
|
30
|
+
public class Host extends AppCompatActivity {
|
|
31
|
+
protected void onCreate(Bundle b) {
|
|
32
|
+
setContentView(R.layout.main);
|
|
33
|
+
FragmentTransaction t = getSupportFragmentManager().beginTransaction();
|
|
34
|
+
PlayerFragment player = new PlayerFragment();
|
|
35
|
+
t.replace(R.id.sheet, player);
|
|
36
|
+
HomeFragment home = new HomeFragment();
|
|
37
|
+
t.replace(R.id.content_area, home);
|
|
38
|
+
t.commit();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
`);
|
|
42
|
+
for (const name of ['PlayerFragment', 'HomeFragment']) {
|
|
43
|
+
write(proj, `app/src/main/java/ex/${name}.java`, `package ex;\npublic class ${name} extends Fragment {}\n`);
|
|
44
|
+
}
|
|
45
|
+
assert.deepEqual([...fn._bottomSheetContainerIds(proj)], ['sheet']);
|
|
46
|
+
fn.main([proj, '--workspace', ws, '--append']);
|
|
47
|
+
const edges = fs.readFileSync(path.join(ws, 'edges.jsonl'), 'utf8').split('\n')
|
|
48
|
+
.filter((l) => l.trim()).map((l) => JSON.parse(l));
|
|
49
|
+
const by = {};
|
|
50
|
+
for (const e of edges) { if (e.source === 'activity:Host') { by[e.target] = e.args; } }
|
|
51
|
+
const p = by['fragment:PlayerFragment'] ?? {};
|
|
52
|
+
assert.ok(p.via === 'bottom-sheet' && p.action === 'tap', `sheet child needs a gesture: ${JSON.stringify(p)}`);
|
|
53
|
+
assert.equal((by['fragment:HomeFragment'] ?? {}).action, 'default');
|
|
54
|
+
} finally {
|
|
55
|
+
fs.rmSync(proj, { recursive: true, force: true });
|
|
56
|
+
fs.rmSync(ws, { recursive: true, force: true });
|
|
57
|
+
}
|
|
58
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Port of test_branch_guard.py — the crawler-side check ([6]) only: the time-window guard kind
|
|
2
|
+
// maps to a bypass axis and lands in a BYPASS phase (static_prior.mjs / phase_planner.mjs).
|
|
3
|
+
// Checks [1]-[5d] and the _infer_guard_kind half of [6] exercise assemble._branch_guard /
|
|
4
|
+
// assemble._infer_guard_kind; they belong to the batch that ports assemble.py.
|
|
5
|
+
import { test } from 'node:test';
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import { _GUARD_AXIS } from '../static_prior.mjs';
|
|
8
|
+
import { PHASES, LEVEL_BYPASS } from '../phase_planner.mjs';
|
|
9
|
+
|
|
10
|
+
test('crawler maps time-window -> env:time', () => {
|
|
11
|
+
assert.equal(_GUARD_AXIS['time-window'], 'env:time');
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('env:time lands in a BYPASS phase', () => {
|
|
15
|
+
const axis = _GUARD_AXIS['time-window'];
|
|
16
|
+
const bypass = PHASES.filter((p) => p.axes.has(axis));
|
|
17
|
+
assert.ok(bypass.length > 0);
|
|
18
|
+
assert.equal(bypass[0].level, LEVEL_BYPASS);
|
|
19
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// A String parameter a call leaves to its default renders that default on the calling page.
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { bodyTexts, _passes } from '../compose_body_text.mjs';
|
|
5
|
+
|
|
6
|
+
const SCAFFOLD = 'f/Scaffold.kt';
|
|
7
|
+
const FILES = new Map([
|
|
8
|
+
[SCAFFOLD, '@Composable\nfun SimpleSearchScaffold(\n onBackClick: () -> Unit,\n' +
|
|
9
|
+
' placeholder: String = stringResource(R.string.enter),\n title: String = "搜索页",\n content: @Composable () -> Unit\n) { }\n'],
|
|
10
|
+
['f/A.kt', '@Composable\nfun ASearchScreen() {\n SimpleSearchScaffold(onBackClick = {}) { }\n}\n'],
|
|
11
|
+
['f/B.kt', '@Composable\nfun BSearchScreen() {\n SimpleSearchScaffold(onBackClick = {}, placeholder = query) { }\n}\n'],
|
|
12
|
+
['f/C.kt', '@Composable\nfun CSearchScreen() {\n SimpleSearchScaffold({}, "x") { }\n}\n'],
|
|
13
|
+
]);
|
|
14
|
+
const idx = new Map([...FILES].map(([p, t]) => { const m = /fun (\w+)\(/.exec(t); return [m[1], [p, m.index]]; }));
|
|
15
|
+
const run = (n) => bodyTexts(n, idx, FILES, { enter: '请输入' }, 2, new Set(), (p) => p).map((t) => t.text);
|
|
16
|
+
|
|
17
|
+
test('unpassed String defaults become the caller\'s body text', () => {
|
|
18
|
+
assert.ok(run('ASearchScreen').includes('请输入'), 'stringResource default');
|
|
19
|
+
assert.ok(run('ASearchScreen').includes('搜索页'), 'literal default');
|
|
20
|
+
});
|
|
21
|
+
test('a passed parameter does not contribute its default', () => {
|
|
22
|
+
assert.ok(!run('BSearchScreen').includes('请输入'), 'named arg passed');
|
|
23
|
+
assert.ok(run('BSearchScreen').includes('搜索页'));
|
|
24
|
+
assert.ok(!run('CSearchScreen').includes('请输入'), 'positional arg passed');
|
|
25
|
+
});
|
|
26
|
+
test('_passes: named and positional', () => {
|
|
27
|
+
assert.equal(_passes('onBack = {}', 'placeholder', 1), false);
|
|
28
|
+
assert.equal(_passes('{}, "q"', 'placeholder', 1), true);
|
|
29
|
+
assert.equal(_passes('{}, placeholder = p', 'placeholder', 1), true);
|
|
30
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Port of test_carry_answers.py: only byte-identical questions carry; parts skip carried items.
|
|
2
|
+
import { test, beforeEach, afterEach } 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 ca from '../carry_answers.mjs';
|
|
8
|
+
import * as wp from '../worklist_parts.mjs';
|
|
9
|
+
|
|
10
|
+
function sgItem(key, at = 'p/A.java:10', window = 'if (x == null) return;') {
|
|
11
|
+
return { key, node_id: key, kind: 'fragment', declared_at: 'p/A.java:1',
|
|
12
|
+
candidates: [{ at, condition: 'x == null', source_window: window }],
|
|
13
|
+
abstain: true, guard_kind: '', guard_text: '', evidence: '' };
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let tmp; let prev; let ws;
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'carry-'));
|
|
19
|
+
prev = path.join(tmp, 'prev'); ws = path.join(tmp, 'ws');
|
|
20
|
+
fs.mkdirSync(prev); fs.mkdirSync(ws);
|
|
21
|
+
ca._save(path.join(prev, 'state_guard_worklist.json'), { items: [sgItem('a'), sgItem('b'), sgItem('c')] });
|
|
22
|
+
ca._save(path.join(prev, 'state_guard_answers.json'), { items: [
|
|
23
|
+
{ key: 'a', abstain: false, guard_kind: 'data-state', guard_text: 't', evidence: 'p/A.java:10' },
|
|
24
|
+
{ key: 'b', abstain: true }, { key: 'c', abstain: true }] });
|
|
25
|
+
});
|
|
26
|
+
afterEach(() => fs.rmSync(tmp, { recursive: true, force: true }));
|
|
27
|
+
|
|
28
|
+
test('identical items carry, changed ones do not', () => {
|
|
29
|
+
ca._save(path.join(ws, 'state_guard_worklist.json'), { items: [
|
|
30
|
+
sgItem('a'), sgItem('b', 'p/A.java:10', 'if (x == null) { show(); }'), sgItem('d')] });
|
|
31
|
+
const rep = ca.carry(ws, prev).stages.state_guard;
|
|
32
|
+
assert.deepEqual(rep, { carried: 1, remaining: 2 });
|
|
33
|
+
const carried = ca._load(path.join(ws, 'state_guard_answers.carried.json')).items;
|
|
34
|
+
assert.deepEqual(carried.map((x) => x.key), ['a']);
|
|
35
|
+
assert.equal(carried[0].guard_kind, 'data-state');
|
|
36
|
+
assert.equal(fs.existsSync(path.join(ws, 'state_guard_answers.json')), false);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('fully carried stage writes answers', () => {
|
|
40
|
+
ca._save(path.join(ws, 'state_guard_worklist.json'), { items: [sgItem('a'), sgItem('b'), sgItem('c')] });
|
|
41
|
+
const rep = ca.carry(ws, prev).stages.state_guard;
|
|
42
|
+
assert.ok(rep.complete);
|
|
43
|
+
assert.equal(ca._load(path.join(ws, 'state_guard_answers.json')).items.length, 3);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('helper fields do not invalidate', () => {
|
|
47
|
+
const base = { key: 'k', label: 'X', target_id: 'n:X', trigger: 't@A.kt:1',
|
|
48
|
+
trigger_context: 'a', source_context: 'b', reasons: ['code-name'] };
|
|
49
|
+
assert.equal(ca.fingerprint('nl_hints', base),
|
|
50
|
+
ca.fingerprint('nl_hints', { ...base, strings: { k: 'v' }, other_entry_points: [{}] }));
|
|
51
|
+
assert.notEqual(ca.fingerprint('nl_hints', base), ca.fingerprint('nl_hints', { ...base, trigger_context: 'c' }));
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('vi answer with vanished endpoint is not carried', () => {
|
|
55
|
+
const item = { key: 'v', binding: 'setOnClickListener', trigger_at: 'A.java:5',
|
|
56
|
+
host_candidates: ['fragment:A'], widget: {}, code_window: [] };
|
|
57
|
+
ca._save(path.join(prev, 'view_interactions_worklist.json'), { items: [item] });
|
|
58
|
+
ca._save(path.join(prev, 'view_interactions_answers.json'), { items: [
|
|
59
|
+
{ key: 'v', category: 'navigation', reason: 'r', transitions: [{ host: 'fragment:A', target: 'fragment:Gone' }] }] });
|
|
60
|
+
ca._save(path.join(ws, 'view_interactions_worklist.json'), { items: [item] });
|
|
61
|
+
fs.writeFileSync(path.join(ws, 'nodes.jsonl'), '{"id": "fragment:A"}\n');
|
|
62
|
+
assert.equal(ca.carry(ws, prev).stages.view_interactions.carried, 0);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('state_guard narrowed net keeps verdict on offered line', () => {
|
|
66
|
+
const two = [{ at: 'p/A.java:10', condition: 'x == null', source_window: 'w' },
|
|
67
|
+
{ at: 'p/A.java:20', condition: 'd != null', source_window: 'w2' }];
|
|
68
|
+
ca._save(path.join(prev, 'state_guard_worklist.json'), { items: [
|
|
69
|
+
{ ...sgItem('a'), candidates: two }, { ...sgItem('b'), candidates: two }] });
|
|
70
|
+
ca._save(path.join(prev, 'state_guard_answers.json'), { items: [
|
|
71
|
+
{ key: 'a', abstain: false, guard_kind: 'data-state', guard_text: 't', evidence: 'p/A.java:10' },
|
|
72
|
+
{ key: 'b', abstain: false, guard_kind: 'data-state', guard_text: 't', evidence: 'p/A.java:20' }] });
|
|
73
|
+
ca._save(path.join(ws, 'state_guard_worklist.json'), { items: [
|
|
74
|
+
{ ...sgItem('a'), candidates: two.slice(0, 1) }, { ...sgItem('b'), candidates: two.slice(0, 1) }] });
|
|
75
|
+
ca.carry(ws, prev);
|
|
76
|
+
const got = ca._load(path.join(ws, 'state_guard_answers.carried.json')).items.map((x) => x.key);
|
|
77
|
+
assert.deepEqual(got, ['a']);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('vi window change carries only on identical tree', () => {
|
|
81
|
+
const old = { key: 'v', binding: 'b', trigger_at: 'A.java:5', host_candidates: [], widget: {},
|
|
82
|
+
code_window: [{ at: 'A.java:5', text: 'x' }, { at: 'A.java:9', text: 'y' }] };
|
|
83
|
+
const nw = { ...old, code_window: [{ at: 'A.java:5', text: 'x' }] };
|
|
84
|
+
const ans = { key: 'v', category: 'action', reason: 'r', evidence: ['A.java:5'] };
|
|
85
|
+
ca._save(path.join(prev, 'view_interactions_answers.json'), { items: [ans] });
|
|
86
|
+
for (const [digestNew, want] of [['d', 1], ['other', 0]]) {
|
|
87
|
+
ca._save(path.join(prev, 'view_interactions_worklist.json'), { source_digest: 'd', items: [old] });
|
|
88
|
+
ca._save(path.join(ws, 'view_interactions_worklist.json'), { source_digest: digestNew, items: [nw] });
|
|
89
|
+
assert.equal(ca.carry(ws, prev).stages.view_interactions.carried, want, digestNew);
|
|
90
|
+
}
|
|
91
|
+
ca._save(path.join(ws, 'view_interactions_worklist.json'), { source_digest: 'd',
|
|
92
|
+
items: [{ ...old, code_window: [{ at: 'A.java:9', text: 'y' }] }] });
|
|
93
|
+
assert.equal(ca.carry(ws, prev).stages.view_interactions.carried, 0);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
test('parts skip carried and merge restores them', () => {
|
|
97
|
+
ca._save(path.join(ws, 'state_guard_worklist.json'), { items: [sgItem('a'), sgItem('d'), sgItem('e')] });
|
|
98
|
+
ca.carry(ws, prev);
|
|
99
|
+
const parts = wp.split(ws, 10);
|
|
100
|
+
assert.deepEqual(parts.map((p) => p.items), [2]);
|
|
101
|
+
wp._save(parts[0].answers, { items: [{ key: 'd', abstain: true }, { key: 'e', abstain: true }] });
|
|
102
|
+
assert.deepEqual(wp.merge(ws), { state_guard: 3 });
|
|
103
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Port of test_chrome_tokens.py: generic-control token filtering and comment stripping.
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { _isChromeRes, _filterChromeTokens, _stripComments, overlayIdentityText, nearestLabel } from '../label_resolve.mjs';
|
|
5
|
+
|
|
6
|
+
test('_isChromeRes: name-based, affix-tolerant', () => {
|
|
7
|
+
for (const name of ['cancel', 'CANCEL', 'confirm', 'ok', 'close', 'back']) { assert.ok(_isChromeRes(name), name); }
|
|
8
|
+
for (const name of ['btn_cancel', 'action_ok', 'cancel_button', 'title_close']) { assert.ok(_isChromeRes(name), name); }
|
|
9
|
+
for (const name of ['res_page_heading', 'media_source', 'sleep_timer', '']) { assert.ok(!_isChromeRes(name), name); }
|
|
10
|
+
assert.ok(!_isChromeRes(null), 'None is handled without error');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('_filterChromeTokens: drop chrome, but never empty the set', () => {
|
|
14
|
+
const mixed = [['res_heading', 'HEADING'], ['cancel', 'CANCEL']];
|
|
15
|
+
assert.deepEqual(_filterChromeTokens(mixed), [['res_heading', 'HEADING']]);
|
|
16
|
+
const onlyChrome = [['cancel', 'CANCEL'], ['ok', 'OK']];
|
|
17
|
+
assert.deepEqual(_filterChromeTokens(onlyChrome), onlyChrome);
|
|
18
|
+
assert.deepEqual(_filterChromeTokens([]), []);
|
|
19
|
+
const clean = [['res_a', 'A'], ['res_b', 'B']];
|
|
20
|
+
assert.deepEqual(_filterChromeTokens(clean), clean);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('_stripComments: blanked, offsets preserved', () => {
|
|
24
|
+
const src = 'live1\n// dead comment\nlive2\n/* dead\nblock */\nlive3';
|
|
25
|
+
const out = _stripComments(src);
|
|
26
|
+
assert.equal(out.length, src.length);
|
|
27
|
+
assert.equal(out.split('\n').length, src.split('\n').length);
|
|
28
|
+
assert.ok(!out.includes('dead'));
|
|
29
|
+
assert.ok(out.includes('live1') && out.includes('live2') && out.includes('live3'));
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const strings = { res_heading: '标题甲', cancel: '控件乙', confirm: '控件丙' };
|
|
33
|
+
|
|
34
|
+
test('overlayIdentityText: commented-out chrome is not identity', () => {
|
|
35
|
+
const wrapper = 'fun Wrapper(title: String) {\n' +
|
|
36
|
+
' LibraryDialog(title = title)\n' +
|
|
37
|
+
'// DialogColumn {\n' +
|
|
38
|
+
'// ItemButton(text = stringResource(id = R.string.cancel))\n' +
|
|
39
|
+
'// ItemButton(text = stringResource(id = R.string.confirm))\n' +
|
|
40
|
+
'// }\n' +
|
|
41
|
+
'}';
|
|
42
|
+
assert.deepEqual(overlayIdentityText(wrapper, strings), []);
|
|
43
|
+
const real = 'fun RealDialog() {\n' +
|
|
44
|
+
' Text(stringResource(id = R.string.res_heading))\n' +
|
|
45
|
+
' ItemButton(text = stringResource(id = R.string.cancel))\n' +
|
|
46
|
+
'}';
|
|
47
|
+
assert.deepEqual(overlayIdentityText(real, strings), ['标题甲']);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('nearestLabel: chrome deprioritised, never the last resort', () => {
|
|
51
|
+
const trig = 'onClick = { open() }\n' +
|
|
52
|
+
' ItemButton(text = stringResource(id = R.string.cancel))\n' +
|
|
53
|
+
' Text(stringResource(id = R.string.res_heading))\n';
|
|
54
|
+
const [key] = nearestLabel(trig, trig.indexOf('onClick'), strings);
|
|
55
|
+
assert.equal(key, 'res_heading');
|
|
56
|
+
const only = 'onClick = { go() }\n ItemButton(text = stringResource(id = R.string.cancel))\n';
|
|
57
|
+
const [key2, val2] = nearestLabel(only, only.indexOf('onClick'), strings);
|
|
58
|
+
assert.equal(key2, 'cancel');
|
|
59
|
+
assert.equal(val2, '控件乙');
|
|
60
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
// Port of test_commented_out_trigger.py: commented-out code renders nothing, so it must
|
|
2
|
+
// neither open an overlay nor lend its neighbour's label to one.
|
|
3
|
+
import { test } from 'node:test';
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import * as co from '../compose_overlay.mjs';
|
|
6
|
+
import * as lr from '../label_resolve.mjs';
|
|
7
|
+
|
|
8
|
+
const SRC = `fun A() {
|
|
9
|
+
val url = "https://example.com/a" // trailing comment
|
|
10
|
+
val live = 1
|
|
11
|
+
// val dead = 2
|
|
12
|
+
/* block
|
|
13
|
+
spans */
|
|
14
|
+
val after = 3
|
|
15
|
+
}
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
test('is_commented_out / _strip_comments', () => {
|
|
19
|
+
assert.ok(!lr.isCommentedOut(SRC, SRC.indexOf('val live')), 'live code is live');
|
|
20
|
+
assert.ok(lr.isCommentedOut(SRC, SRC.indexOf('val dead')), 'code behind // is commented out');
|
|
21
|
+
assert.ok(lr.isCommentedOut(SRC, SRC.indexOf('spans')), 'code inside a /* */ block is commented out');
|
|
22
|
+
assert.ok(!lr.isCommentedOut(SRC, SRC.indexOf('val after')), 'code AFTER a block comment closes is live again');
|
|
23
|
+
assert.ok(!lr.isCommentedOut(SRC, SRC.indexOf('val url')), 'a `//` inside a STRING does not comment out its own line');
|
|
24
|
+
assert.ok(lr._stripComments(SRC).includes('https://example.com/a'), 'the string literal survives stripping intact');
|
|
25
|
+
assert.ok(!lr._stripComments(SRC).includes('trailing comment'), 'the real trailing comment on that same line IS stripped');
|
|
26
|
+
const QSRC = "// don't do this\nval live = true\n";
|
|
27
|
+
assert.ok(!lr.isCommentedOut(QSRC, QSRC.indexOf('val live')), 'an apostrophe inside a comment does not swallow the following code');
|
|
28
|
+
const st = lr._stripComments(SRC);
|
|
29
|
+
assert.ok(st.length === SRC.length && st.split('\n').length === SRC.split('\n').length,
|
|
30
|
+
'stripping preserves length and newlines');
|
|
31
|
+
assert.ok(!lr.isCommentedOut(SRC, -1) && !lr.isCommentedOut(SRC, SRC.length + 5),
|
|
32
|
+
"an out-of-range offset is not 'commented out' (no crash)");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const MEASURED = `
|
|
36
|
+
@Composable
|
|
37
|
+
fun SongMenu() {
|
|
38
|
+
val clipDialog = remember { mutableStateOf(false) }
|
|
39
|
+
val infoDialog = remember { mutableStateOf(false) }
|
|
40
|
+
Column {
|
|
41
|
+
// DialogItem(text = "歌曲片段") {
|
|
42
|
+
// clipDialog.value = true
|
|
43
|
+
// }
|
|
44
|
+
DialogItem(text = "分享", onClick = { infoDialog.value = true })
|
|
45
|
+
}
|
|
46
|
+
if (clipDialog.value) { ClipDialog() }
|
|
47
|
+
if (infoDialog.value) { InfoDialog() }
|
|
48
|
+
}
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
const mget = (m, k) => (m instanceof Map ? (m.has(k) ? m.get(k) : null) : (m && Object.hasOwn(m, k) ? m[k] : null));
|
|
52
|
+
|
|
53
|
+
test('_build_flag_labels: a dead setter is not a trigger', () => {
|
|
54
|
+
const funs = co.buildFunIndex(MEASURED);
|
|
55
|
+
const fl = co._buildFlagLabels(MEASURED, funs, {});
|
|
56
|
+
const multi = mget(fl, '__multi__');
|
|
57
|
+
assert.ok(mget(fl, 'clipDialog') === null && !(multi && (multi instanceof Map ? multi.has('clipDialog') : 'clipDialog' in multi)),
|
|
58
|
+
'a flag whose only setter is commented out gets NO label');
|
|
59
|
+
assert.ok(mget(fl, 'infoDialog') !== null, 'the neighbouring LIVE flag still resolves');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const size = (s) => (s instanceof Set || s instanceof Map ? s.size : Object.keys(s).length);
|
|
63
|
+
|
|
64
|
+
test('_dead_state_flags', () => {
|
|
65
|
+
const dead = co._deadStateFlags(MEASURED);
|
|
66
|
+
assert.ok(dead.has('clipDialog'), 'a flag with assignments, ALL commented out, is dead');
|
|
67
|
+
assert.ok(!dead.has('infoDialog'), 'a flag with a live setter is not dead');
|
|
68
|
+
|
|
69
|
+
const NO_SETTER = `fun A() {
|
|
70
|
+
val d = remember { mutableStateOf(false) }
|
|
71
|
+
if (d.value) { Dialog() }
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
74
|
+
assert.equal(size(co._deadStateFlags(NO_SETTER)), 0, 'a flag with NO assignment anywhere is NOT dead');
|
|
75
|
+
|
|
76
|
+
const MIXED = `fun A() {
|
|
77
|
+
val d = remember { mutableStateOf(false) }
|
|
78
|
+
// d.value = true
|
|
79
|
+
Button(onClick = { d.value = true })
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
assert.equal(size(co._deadStateFlags(MIXED)), 0, 'one live setter outweighs any number of commented-out ones');
|
|
83
|
+
|
|
84
|
+
const DISMISS_ONLY = `fun A() {
|
|
85
|
+
val d = remember { mutableStateOf(false) }
|
|
86
|
+
Dialog(onDismissRequest = { d.value = false })
|
|
87
|
+
}
|
|
88
|
+
`;
|
|
89
|
+
assert.equal(size(co._deadStateFlags(DISMISS_ONLY)), 0, 'a DISMISS-only flag is not reported');
|
|
90
|
+
|
|
91
|
+
const DESTRUCTURED = `fun A() {
|
|
92
|
+
val (show, setShow) = remember { mutableStateOf(false) }
|
|
93
|
+
// setShow(true)
|
|
94
|
+
if (show) { Dialog() }
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
97
|
+
assert.ok(co._deadStateFlags(DESTRUCTURED).has('show'), 'the destructured setter form `setShow(true)` is judged too');
|
|
98
|
+
|
|
99
|
+
const DECL_DEAD = `fun A() {
|
|
100
|
+
// val d = remember { mutableStateOf(false) }
|
|
101
|
+
// d.value = true
|
|
102
|
+
}
|
|
103
|
+
`;
|
|
104
|
+
assert.equal(size(co._deadStateFlags(DECL_DEAD)), 0, 'a commented-out DECLARATION yields no flag at all');
|
|
105
|
+
|
|
106
|
+
const PARAM = `fun A(show: MutableState<Boolean>) {
|
|
107
|
+
if (show.value) { Dialog() }
|
|
108
|
+
}
|
|
109
|
+
`;
|
|
110
|
+
assert.equal(size(co._deadStateFlags(PARAM)), 0, 'a flag NOT declared in this file is never judged dead');
|
|
111
|
+
});
|