@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,57 @@
|
|
|
1
|
+
// Port of test_node_id_collision.py — assemble.mergeNodeRecords: identity kind outranks role kind,
|
|
2
|
+
// order-independently, keeping the role as an attribute and reporting every collision.
|
|
3
|
+
import { test } from 'node:test';
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import { mergeNodeRecords, _ROLE_KINDS } from '../assemble.mjs';
|
|
6
|
+
|
|
7
|
+
const ROLE = { id: 'fragment:SettingsChild', kind: 'pager-page', label: 'SettingsChild',
|
|
8
|
+
declared_at: 'PagerHostActivity.kt:75', provenance: 'static:fragment-adapter' };
|
|
9
|
+
const IDENT = { id: 'fragment:SettingsChild', kind: 'fragment', label: 'SettingsChild',
|
|
10
|
+
declared_at: 'SettingsChild.kt:35', provenance: 'static:homegraph', launch_hint: 'fragment;base:BaseFragment' };
|
|
11
|
+
|
|
12
|
+
test('identity outranks role, in BOTH orders', () => {
|
|
13
|
+
const fwd = mergeNodeRecords(ROLE, IDENT); const rev = mergeNodeRecords(IDENT, ROLE);
|
|
14
|
+
assert.equal(fwd.kind, 'fragment', "role-first: kind resolves to identity 'fragment'");
|
|
15
|
+
assert.equal(rev.kind, 'fragment', "identity-first: kind resolves to identity 'fragment'");
|
|
16
|
+
assert.equal(fwd.kind, rev.kind, 'ORDER-INDEPENDENT: both orders agree on kind');
|
|
17
|
+
assert.notEqual(fwd.kind, 'pager-page', 'regression: role kind must NOT win when an identity kind is present');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test("the identity's declaration site wins", () => {
|
|
21
|
+
assert.equal(mergeNodeRecords(ROLE, IDENT).declared_at, 'SettingsChild.kt:35', "declared_at is the class's own declaration");
|
|
22
|
+
assert.equal(mergeNodeRecords(IDENT, ROLE).declared_at, 'SettingsChild.kt:35', 'declared_at is order-independent too');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('the ROLE FACT is preserved, not discarded', () => {
|
|
26
|
+
for (const [name, m] of [['role-first', mergeNodeRecords(ROLE, IDENT)], ['identity-first', mergeNodeRecords(IDENT, ROLE)]]) {
|
|
27
|
+
assert.equal(m.pager_child, true, `${name}: pager_child attribute set`);
|
|
28
|
+
assert.equal(m.pager_declared_at, 'PagerHostActivity.kt:75', `${name}: pager_declared_at keeps the adapter site`);
|
|
29
|
+
}
|
|
30
|
+
assert.ok(_ROLE_KINDS.has('pager-page'), "'pager-page' is registered as a ROLE kind");
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('collisions are REPORTED, never silent', () => {
|
|
34
|
+
const log = [];
|
|
35
|
+
mergeNodeRecords(ROLE, IDENT, log);
|
|
36
|
+
assert.equal(log.length, 1, 'one collision recorded');
|
|
37
|
+
assert.equal(log[0][0], 'fragment:SettingsChild', 'collision names the id');
|
|
38
|
+
assert.ok(log[0][1].includes('pager-page+fragment'), 'collision names both kinds');
|
|
39
|
+
assert.equal(log[0][2], 'role folded to attribute', 'collision states the resolution');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('two IDENTITY kinds is an unresolved conflict, reported as such', () => {
|
|
43
|
+
const log2 = [];
|
|
44
|
+
const m2 = mergeNodeRecords({ id: 'x:A', kind: 'dialog', declared_at: 'A.kt:1' }, { id: 'x:A', kind: 'sheet', declared_at: 'B.kt:2' }, log2);
|
|
45
|
+
assert.equal(m2.kind, 'dialog', 'first-seen identity kind is kept');
|
|
46
|
+
assert.ok(log2.length && log2[0][2] === 'UNRESOLVED', 'an identity/identity clash is flagged UNRESOLVED');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('no collision: behaviour is unchanged (no-op guarantee)', () => {
|
|
50
|
+
const log3 = [];
|
|
51
|
+
const same = mergeNodeRecords({ id: 'x:B', kind: 'dialog', a: 1 }, { id: 'x:B', kind: 'dialog', b: 2 }, log3);
|
|
52
|
+
assert.deepEqual(same, { id: 'x:B', kind: 'dialog', a: 1, b: 2 }, 'same-kind records merge by plain field union');
|
|
53
|
+
assert.equal(log3.length, 0, 'no collision logged when kinds agree');
|
|
54
|
+
assert.deepEqual(mergeNodeRecords(null, IDENT), IDENT, 'first record passes through');
|
|
55
|
+
const missing = mergeNodeRecords({ id: 'x:C' }, { id: 'x:C', kind: 'dialog' }, log3);
|
|
56
|
+
assert.ok(missing.kind === 'dialog' && !log3.length, 'a record with no kind is not treated as a clash');
|
|
57
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Port of test_non_gesture_step_flag.py: click_paths stamps non_gesture on non-touch hops and narrates them.
|
|
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 cp from '../click_paths.mjs';
|
|
8
|
+
|
|
9
|
+
function run(links, nodes) {
|
|
10
|
+
const ws = fs.mkdtempSync(path.join(os.tmpdir(), 'ngs_'));
|
|
11
|
+
fs.writeFileSync(path.join(ws, 'utg.json'),
|
|
12
|
+
JSON.stringify({ directed: true, multigraph: true, graph: {}, nodes, links }), 'utf8');
|
|
13
|
+
cp.main([ws]);
|
|
14
|
+
return JSON.parse(fs.readFileSync(path.join(ws, 'click_paths.json'), 'utf8')).paths;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const NODES = [
|
|
18
|
+
{ id: 'compose-route:HOME', kind: 'compose-route', label: 'HOME', entry: true },
|
|
19
|
+
{ id: 'compose-route:LIST', kind: 'compose-route', label: '列表' },
|
|
20
|
+
{ id: 'compose-route:LIST#empty', kind: 'compose-route-variant', label: 'LIST (empty)', variant_of: 'compose-route:LIST' },
|
|
21
|
+
];
|
|
22
|
+
const TAP = { source: 'compose-route:HOME', target: 'compose-route:LIST', mechanism: 'compose-navigate',
|
|
23
|
+
trigger: 'onClick@Home.kt:10', args: { label: '列表' } };
|
|
24
|
+
|
|
25
|
+
test('render-branch data-variant hop is flagged', () => {
|
|
26
|
+
const paths = run([TAP, { source: 'compose-route:LIST', target: 'compose-route:LIST#empty',
|
|
27
|
+
mechanism: 'data-variant', trigger: 'render-branch', args: {} }], NODES);
|
|
28
|
+
const v = paths['compose-route:LIST#empty'];
|
|
29
|
+
assert.ok(v !== undefined, 'the variant is still reachable (not dropped)');
|
|
30
|
+
assert.equal(v.steps.at(-1).non_gesture, true, 'render-branch step carries non_gesture:true');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('ordinary onClick is not flagged', () => {
|
|
34
|
+
const step = run([TAP], NODES.slice(0, 2))['compose-route:LIST'].steps.at(-1);
|
|
35
|
+
assert.ok(!('non_gesture' in step), 'a real onClick step is not flagged (field absent, old behaviour)');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('other non-gesture trigger vocabularies are flagged', () => {
|
|
39
|
+
for (const trig of ['startDestination@Nav.kt:3', 'createFragment@Host.kt:7']) {
|
|
40
|
+
const s = run([{ source: 'compose-route:HOME', target: 'compose-route:LIST', mechanism: 'fragment-transaction',
|
|
41
|
+
trigger: trig, args: { label: '列表' } }], NODES.slice(0, 2))['compose-route:LIST'].steps.at(-1);
|
|
42
|
+
assert.equal(s.non_gesture, true, `${trig.split('@')[0]} is flagged`);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('prose does not narrate a non-gesture hop as a tap', () => {
|
|
47
|
+
const paths = run([{ source: 'compose-route:HOME', target: 'compose-route:LIST', mechanism: 'fragment-transaction',
|
|
48
|
+
trigger: 'lifecycle@Splash.kt:20', args: {} }], NODES.slice(0, 2));
|
|
49
|
+
const pt = paths['compose-route:LIST'].path_text;
|
|
50
|
+
assert.ok(!pt.includes('点击'), `no tap verb in prose for a lifecycle hop (${pt})`);
|
|
51
|
+
assert.ok(pt.includes('自动跳转'), 'the hop is narrated as an automatic transition');
|
|
52
|
+
assert.ok(pt.includes('列表'), 'the destination is still named');
|
|
53
|
+
const p = paths['compose-route:LIST'];
|
|
54
|
+
assert.equal(p.clicks, 0, 'a non-gesture-only path costs 0 clicks');
|
|
55
|
+
assert.deepEqual(p.labels, [], 'and offers no tap label');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('a real tap is still narrated as one', () => {
|
|
59
|
+
const pt = run([TAP], NODES.slice(0, 2))['compose-route:LIST'].path_text;
|
|
60
|
+
assert.ok(pt.includes('点击'), `a real onClick is still narrated as 点击 (${pt})`);
|
|
61
|
+
assert.ok(!pt.includes('自动跳转'), 'and is not relabelled an automatic transition');
|
|
62
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Port of test_out_of_scope_and_settings.py — inherited layout (view_widgets.nodeLayoutNames),
|
|
2
|
+
// out-of-scope marking (assemble._markOutOfScope) and app-setting guards (_resolveAppSetting).
|
|
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 A from '../assemble.mjs';
|
|
9
|
+
import * as vw from '../view_widgets.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('out of scope and app settings', () => {
|
|
18
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'oos'));
|
|
19
|
+
try {
|
|
20
|
+
const src = 'app/src/main/java/p/';
|
|
21
|
+
write(root, src + 'BaseSortDialog.java',
|
|
22
|
+
'package p;\npublic class BaseSortDialog extends BottomSheetDialogFragment {\n' +
|
|
23
|
+
' public View onCreateView(LayoutInflater i, ViewGroup c, Bundle b) {\n' +
|
|
24
|
+
' return i.inflate(R.layout.sort_dialog, c, false);\n }\n}\n');
|
|
25
|
+
write(root, src + 'Host.java',
|
|
26
|
+
'package p;\npublic class Host extends Fragment {\n' +
|
|
27
|
+
' void open() { new InboxSortDialog().show(getChildFragmentManager(), null); }\n' +
|
|
28
|
+
' public static class InboxSortDialog extends BaseSortDialog {\n' +
|
|
29
|
+
' public void onCreate(Bundle b) { super.onCreate(b); }\n }\n' +
|
|
30
|
+
' protected List<Item> loadMoreData(int page) {\n return null;\n }\n}\n');
|
|
31
|
+
write(root, src + 'Prefs.java',
|
|
32
|
+
'package p;\npublic class Prefs {\n public static final String PREF_BOTTOM = "prefBottom";\n' +
|
|
33
|
+
' public static boolean isBottomEnabled() {\n return prefs.getBoolean(PREF_BOTTOM, true);\n }\n}\n');
|
|
34
|
+
write(root, src + 'UiPrefsFragment.java',
|
|
35
|
+
'package p;\npublic class UiPrefsFragment extends PreferenceFragmentCompat {\n' +
|
|
36
|
+
' public void onCreatePreferences(Bundle b, String k) {\n' +
|
|
37
|
+
' addPreferencesFromResource(R.xml.preferences_ui);\n }\n}\n');
|
|
38
|
+
write(root, 'app/src/main/res/xml/preferences_ui.xml',
|
|
39
|
+
'<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">\n' +
|
|
40
|
+
' <SwitchPreferenceCompat android:title="Bottom bar" android:defaultValue="true"\n' +
|
|
41
|
+
' android:key="prefBottom" />\n</PreferenceScreen>\n');
|
|
42
|
+
|
|
43
|
+
// 1. inherited layout
|
|
44
|
+
const node = { id: 'dialog:InboxSortDialog', label: 'InboxSortDialog', declared_at: src + 'Host.java:4' };
|
|
45
|
+
assert.deepEqual(vw.nodeLayoutNames(node, root, new Map()), ['sort_dialog'], "subclass must inherit its base's declared layout");
|
|
46
|
+
|
|
47
|
+
// 2. out of scope
|
|
48
|
+
const nodes = {
|
|
49
|
+
'media-browse:root': { id: 'media-browse:root', kind: 'media-browse', surface: ['media-browse'] },
|
|
50
|
+
'dialog:loadMoreData': { id: 'dialog:loadMoreData', kind: 'dialog', provenance: 'static:llm', declared_at: src + 'Host.java:6' },
|
|
51
|
+
'fragment:BaseSortDialog': { id: 'fragment:BaseSortDialog', kind: 'dialog' },
|
|
52
|
+
'fragment:InboxSortDialog': { id: 'fragment:InboxSortDialog', kind: 'dialog' },
|
|
53
|
+
'fragment:UiPrefsFragment': { id: 'fragment:UiPrefsFragment', kind: 'fragment' },
|
|
54
|
+
};
|
|
55
|
+
A._CALLER_CACHE.clear();
|
|
56
|
+
A._markOutOfScope(nodes, [], root);
|
|
57
|
+
const reason = Object.fromEntries(Object.entries(nodes).map(([k, n]) => [k, n.out_of_scope ?? '']));
|
|
58
|
+
assert.ok(reason['media-browse:root'].startsWith('external-surface'), JSON.stringify(reason));
|
|
59
|
+
assert.ok(reason['dialog:loadMoreData'].startsWith('pseudo-page'), JSON.stringify(reason));
|
|
60
|
+
assert.ok(reason['fragment:BaseSortDialog'].startsWith('base-only'), JSON.stringify(reason));
|
|
61
|
+
assert.ok(!reason['fragment:InboxSortDialog'], 'a constructed subclass stays a page');
|
|
62
|
+
assert.ok(!reason['fragment:UiPrefsFragment'], 'an ordinary page stays a page');
|
|
63
|
+
|
|
64
|
+
// 3. app-setting
|
|
65
|
+
const g = A._resolveAppSetting('Prefs.isBottomEnabled()', false, root, nodes);
|
|
66
|
+
assert.ok(g && g.kind === 'app-setting' && g.pref_key === 'prefBottom' && g.value === false &&
|
|
67
|
+
g.row_title === 'Bottom bar' && g.screen === 'fragment:UiPrefsFragment', JSON.stringify(g));
|
|
68
|
+
const g2 = A._resolveAppSetting('!Prefs.isBottomEnabled()', true, root, nodes);
|
|
69
|
+
assert.ok(g2 && g2.value === false, 'negation folds into the wanted value');
|
|
70
|
+
assert.equal(A._resolveAppSetting('Prefs.unknown()', false, root, nodes), null, 'an unresolvable getter refuses');
|
|
71
|
+
} finally { fs.rmSync(root, { recursive: true, force: true }); }
|
|
72
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Port of test_overload_and_climb.py: overloaded page headers and name-collision climbs.
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import { buildCallIndex, resolveSource } from '../compose_overlay.mjs';
|
|
5
|
+
import { discoverPageHeaders } from '../compose_titles.mjs';
|
|
6
|
+
|
|
7
|
+
const BARS = `
|
|
8
|
+
@Composable
|
|
9
|
+
fun FitStatusBarTopAppBar(
|
|
10
|
+
title: @Composable () -> Unit,
|
|
11
|
+
modifier: Modifier = Modifier,
|
|
12
|
+
navigationIcon: @Composable (() -> Unit) = {},
|
|
13
|
+
) = LargeTopAppBar(title = title, modifier = modifier)
|
|
14
|
+
|
|
15
|
+
@Composable
|
|
16
|
+
fun FitStatusBarTopAppBar(
|
|
17
|
+
title: String,
|
|
18
|
+
onBackPressed: () -> Unit,
|
|
19
|
+
modifier: Modifier = Modifier,
|
|
20
|
+
) = LargeTopAppBar(title = { Text(title) })
|
|
21
|
+
|
|
22
|
+
@Composable
|
|
23
|
+
fun SongRow(title: String, subtitle: String) { Text(title) }
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
test('overloaded page header', () => {
|
|
27
|
+
const p = 'app/src/main/kotlin/Bars.kt';
|
|
28
|
+
const fnIndex = new Map([
|
|
29
|
+
['FitStatusBarTopAppBar', [p, BARS.indexOf('fun FitStatusBarTopAppBar')]],
|
|
30
|
+
['SongRow', [p, BARS.indexOf('fun SongRow')]],
|
|
31
|
+
]);
|
|
32
|
+
const headers = discoverPageHeaders(fnIndex, new Map([[p, BARS]]));
|
|
33
|
+
assert.equal(headers.has('FitStatusBarTopAppBar'), true, 'overloaded header found via sibling decl');
|
|
34
|
+
assert.equal(headers.has('SongRow'), false, 'a list row is still not page chrome');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('slot-only bar is not page chrome', () => {
|
|
38
|
+
const SLOT_ONLY = `
|
|
39
|
+
@Composable
|
|
40
|
+
fun PlainBar(title: @Composable () -> Unit, modifier: Modifier = Modifier) =
|
|
41
|
+
LargeTopAppBar(title = title)
|
|
42
|
+
`;
|
|
43
|
+
const p2 = 'app/src/main/kotlin/Plain.kt';
|
|
44
|
+
const h = discoverPageHeaders(new Map([['PlainBar', [p2, SLOT_ONLY.indexOf('fun PlainBar')]]]), new Map([[p2, SLOT_ONLY]]));
|
|
45
|
+
assert.equal(h.has('PlainBar'), false);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const ACT = `
|
|
49
|
+
package com.x
|
|
50
|
+
class PreviewIconActivity : AppCompatActivity() {
|
|
51
|
+
override fun onItemClicked(activity: BreezyActivity) { helperLaunch() }
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
const ADAPTER = `
|
|
55
|
+
package com.x
|
|
56
|
+
class AbsDailyTrendAdapter(activity: Activity) {
|
|
57
|
+
inner class ViewHolder {
|
|
58
|
+
protected fun onItemClicked(activity: Activity, index: Int) {
|
|
59
|
+
IntentHelper.startDailyWeatherActivity(activity)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
const UNIQUE = `
|
|
65
|
+
package com.x
|
|
66
|
+
class SettingsActivity : AppCompatActivity() {
|
|
67
|
+
fun openUniquePage() { IntentHelper.startAboutActivity(this) }
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
|
|
71
|
+
test('name-collision climb', () => {
|
|
72
|
+
const files = new Map([
|
|
73
|
+
['P/PreviewIconActivity.kt', ACT],
|
|
74
|
+
['P/AbsDailyTrendAdapter.kt', ADAPTER],
|
|
75
|
+
['P/SettingsActivity.kt', UNIQUE],
|
|
76
|
+
]);
|
|
77
|
+
const ci = buildCallIndex(files, new Map());
|
|
78
|
+
const cnt = ci.decl_file_count || new Map();
|
|
79
|
+
const g = (k) => (cnt instanceof Map ? (cnt.get(k) ?? 0) : (cnt[k] ?? 0));
|
|
80
|
+
assert.equal(g('onItemClicked') >= 2, true, 'decl_file_count sees overridden-only methods');
|
|
81
|
+
assert.equal(g('openUniquePage'), 1, 'decl_file_count for a unique name');
|
|
82
|
+
const [sid] = resolveSource('P/AbsDailyTrendAdapter.kt', 'onItemClicked', new Map(), new Set(), ci, { partial_tiers: true });
|
|
83
|
+
assert.notEqual(sid, 'activity:PreviewIconActivity', 'colliding name does NOT claim an Activity');
|
|
84
|
+
const [sid2] = resolveSource('P/SettingsActivity.kt', 'openUniquePage', new Map(), new Set(), ci, { partial_tiers: true });
|
|
85
|
+
assert.equal(sid2, 'activity:SettingsActivity', 'unique name still resolves to its Activity');
|
|
86
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Port of test_pager_page_source.py: a helper inside a pager page resolves to the PAGE,
|
|
2
|
+
// not to the pager's host.
|
|
3
|
+
import { test } from 'node:test';
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import * as co from '../compose_overlay.mjs';
|
|
6
|
+
|
|
7
|
+
const HOST = `
|
|
8
|
+
@Composable
|
|
9
|
+
fun PlayerUI() {
|
|
10
|
+
HorizontalPager(state = pagerState, beyondViewportPageCount = 2) { page ->
|
|
11
|
+
when (page) {
|
|
12
|
+
0 -> LyricsScreen(themeColor = themeColor)
|
|
13
|
+
1 -> PlayerCover(themeColor = themeColor)
|
|
14
|
+
2 -> PanelUI(themeColor = themeColor)
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
const toObj = (m) => Object.fromEntries(m instanceof Map ? m : Object.entries(m));
|
|
20
|
+
|
|
21
|
+
test('scan_pager_page_names', () => {
|
|
22
|
+
const ids = co.scanPagerPageNames(new Map([['a/PlayerUI.kt', HOST]]));
|
|
23
|
+
assert.deepEqual(toObj(ids), {
|
|
24
|
+
LyricsScreen: 'pager:LyricsScreen', PlayerCover: 'pager:PlayerCover', PanelUI: 'pager:PanelUI',
|
|
25
|
+
}, 'every `when` branch of a pager becomes a pager page id');
|
|
26
|
+
const VERTICAL = HOST.replace('HorizontalPager', 'VerticalPager');
|
|
27
|
+
assert.deepEqual(new Set(co.scanPagerPageNames(new Map([['a/V.kt', VERTICAL]])).keys()), new Set(ids.keys()),
|
|
28
|
+
'VerticalPager is scanned the same way');
|
|
29
|
+
assert.equal(co.scanPagerPageNames(new Map([['a/N.kt', 'fun A() { Column { Text("x") } }']])).size, 0,
|
|
30
|
+
'a file with no pager yields nothing');
|
|
31
|
+
const STRUCT = `fun P() {
|
|
32
|
+
HorizontalPager(state = s) { page -> when (page) { 0 -> Box { Real() } } }
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
assert.ok(!co.scanPagerPageNames(new Map([['a/S.kt', STRUCT]])).has('Box'),
|
|
36
|
+
'a structural primitive is not mistaken for a pager page');
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const CALLEE_TO_CALLERS = new Map([
|
|
40
|
+
['ControlPanel', ['PanelUI']], ['PanelUI', ['PlayerUI']], ['PlayerUI', ['MainActivityContent']],
|
|
41
|
+
]);
|
|
42
|
+
const CI = () => [new Map(), CALLEE_TO_CALLERS, new Map([['MainActivityContent', 'activity:Main']])];
|
|
43
|
+
const GATED = new Map([['PlayerUI', 'sheet-screen:PlayerUI']]);
|
|
44
|
+
const PAGERS = new Map([['PanelUI', 'pager:PanelUI'], ['LyricsScreen', 'pager:LyricsScreen']]);
|
|
45
|
+
|
|
46
|
+
test('resolve_source: the pager page wins over its host', () => {
|
|
47
|
+
assert.deepEqual(co.resolveSource('a/ControlPanel.kt', 'ControlPanel', new Map(), new Set(),
|
|
48
|
+
{ call_index: CI(), gated_slot_ids: GATED, pager_page_ids: PAGERS }),
|
|
49
|
+
['pager:PanelUI', 'callgraph-pager-page'], 'a helper inside a pager page resolves to the PAGE');
|
|
50
|
+
const [sidOld] = co.resolveSource('a/ControlPanel.kt', 'ControlPanel', new Map(), new Set(),
|
|
51
|
+
{ call_index: CI(), gated_slot_ids: GATED });
|
|
52
|
+
assert.equal(sidOld, 'sheet-screen:PlayerUI', 'without pager_page_ids it still climbs to the host');
|
|
53
|
+
assert.deepEqual(co.resolveSource('a/PanelUI.kt', 'PanelUI', new Map(), new Set(),
|
|
54
|
+
{ call_index: CI(), gated_slot_ids: GATED, pager_page_ids: PAGERS }),
|
|
55
|
+
['pager:PanelUI', 'fn-pager-page'], "the pager page's OWN fn resolves to itself");
|
|
56
|
+
assert.deepEqual(co.resolveSource('a/L.kt', 'LyricsScreen', new Map([['LyricsScreen', 'LYRICS']]), new Set(),
|
|
57
|
+
{ call_index: CI(), pager_page_ids: PAGERS }),
|
|
58
|
+
['compose-route:LYRICS', 'fn-screen'], 'a known compose route still wins over the pager-page tier');
|
|
59
|
+
assert.deepEqual(co.resolveSource('a/x.kt', 'Inner', new Map(), new Set(['SomeDialog']), {
|
|
60
|
+
call_index: [new Map(), new Map([['Inner', ['SomeDialog']], ['SomeDialog', ['PanelUI']]]), new Map()],
|
|
61
|
+
pager_page_ids: PAGERS,
|
|
62
|
+
}), ['overlay:SomeDialog', 'callgraph-overlay'], 'the nearest ancestor wins');
|
|
63
|
+
assert.equal(co.resolveSource('a/x.kt', 'Nobody', new Map(), new Set(),
|
|
64
|
+
{ call_index: [new Map(), new Map(), new Map()], pager_page_ids: PAGERS })[1], 'fallback',
|
|
65
|
+
'an unresolvable fn still reports fallback');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('resolve_sources: same tier, list form', () => {
|
|
69
|
+
assert.deepEqual(co.resolveSources('a/ControlPanel.kt', 'ControlPanel', new Map(), new Set(),
|
|
70
|
+
{ call_index: CI(), gated_slot_ids: GATED, pager_page_ids: PAGERS }),
|
|
71
|
+
[['pager:PanelUI', 'callgraph-pager-page']], 'resolve_sources agrees with resolve_source');
|
|
72
|
+
assert.deepEqual(co.resolveSources('a/PanelUI.kt', 'PanelUI', new Map(), new Set(),
|
|
73
|
+
{ call_index: CI(), gated_slot_ids: GATED, pager_page_ids: PAGERS }),
|
|
74
|
+
[['pager:PanelUI', 'fn-pager-page']], "the fast path for the page's own fn matches too");
|
|
75
|
+
assert.deepEqual(co.resolveSources('a/x.kt', 'PanelUI', new Map(), new Set(),
|
|
76
|
+
{ call_index: CI(), gated_slot_ids: GATED }),
|
|
77
|
+
[['sheet-screen:PlayerUI', 'callgraph-gated-slot']], 'pager_page_ids is optional');
|
|
78
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Port of test_pager_position_zero.py — assemble._pagerPositionZero: only a case arm that proves
|
|
2
|
+
// position 0 (literal or a same-file constant = 0) names the page shown on open.
|
|
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 assemble from '../assemble.mjs';
|
|
9
|
+
|
|
10
|
+
const JAVA = `package ex;
|
|
11
|
+
public class Host extends Fragment {
|
|
12
|
+
private static final int POS_FIRST = 0;
|
|
13
|
+
private static final int POS_SECOND = 1;
|
|
14
|
+
class Adapter extends FragmentStateAdapter {
|
|
15
|
+
public Fragment createFragment(int position) {
|
|
16
|
+
switch (position) {
|
|
17
|
+
case POS_SECOND:
|
|
18
|
+
return new Second();
|
|
19
|
+
default:
|
|
20
|
+
case POS_FIRST:
|
|
21
|
+
return new First();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
`;
|
|
27
|
+
const KOTLIN = `package ex
|
|
28
|
+
class Tabs : Fragment() {
|
|
29
|
+
inner class Adapter : FragmentStateAdapter(this) {
|
|
30
|
+
override fun createFragment(position: Int): Fragment {
|
|
31
|
+
return when (position) {
|
|
32
|
+
1 -> Right()
|
|
33
|
+
else -> Left()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
`;
|
|
39
|
+
|
|
40
|
+
function edgesFor(rel, src, targets, text) {
|
|
41
|
+
const lines = text.split('\n');
|
|
42
|
+
return targets.map((cls) => {
|
|
43
|
+
const ln = lines.findIndex((l) => l.includes(`${cls}()`)) + 1;
|
|
44
|
+
return { source: src, target: `fragment:${cls}`, trigger: `X@${rel}:${ln}`,
|
|
45
|
+
args: { commit_scope: 'non-lifecycle-fn:createFragment' } };
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
test('pager position-0 checks', () => {
|
|
50
|
+
const proj = fs.mkdtempSync(path.join(os.tmpdir(), 'ppz'));
|
|
51
|
+
try {
|
|
52
|
+
for (const [rel, text] of [['app/src/main/java/ex/Host.java', JAVA], ['app/src/main/java/ex/Tabs.kt', KOTLIN]]) {
|
|
53
|
+
const p = path.join(proj, rel);
|
|
54
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
55
|
+
fs.writeFileSync(p, text, 'utf8');
|
|
56
|
+
}
|
|
57
|
+
const fns = ['createFragment', 'getItem', 'instantiateItem'];
|
|
58
|
+
const e1 = edgesFor('app/src/main/java/ex/Host.java', 'fragment:Host', ['First', 'Second'], JAVA);
|
|
59
|
+
let got = assemble._pagerPositionZero(e1, 'fragment:Host', proj, fns);
|
|
60
|
+
assert.equal(got, 'fragment:First', `constant POS_FIRST=0 arm, even behind default: ${got}`);
|
|
61
|
+
const e2 = edgesFor('app/src/main/java/ex/Tabs.kt', 'fragment:Tabs', ['Left', 'Right'], KOTLIN);
|
|
62
|
+
got = assemble._pagerPositionZero(e2, 'fragment:Tabs', proj, fns);
|
|
63
|
+
assert.equal(got, null, `no arm proves position 0 (\`else\` is not proof): ${got}`);
|
|
64
|
+
} finally { fs.rmSync(proj, { recursive: true, force: true }); }
|
|
65
|
+
});
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// Port of test_pager_variant_guard.py: responsive-layout variants (device-env `when` arms),
|
|
2
|
+
// hoisted pager initialPage across files, and the duck-typed call-index plumbing.
|
|
3
|
+
import { test } from 'node:test';
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import * as co from '../compose_overlay.mjs';
|
|
6
|
+
|
|
7
|
+
const SHELL = `
|
|
8
|
+
@Composable
|
|
9
|
+
fun ContentShell(queueState: PagerState) {
|
|
10
|
+
BoxWithConstraints {
|
|
11
|
+
val ratio = maxWidth / maxHeight
|
|
12
|
+
when {
|
|
13
|
+
deviceIsKiosk && maxWidth > maxHeight && maxWidth > 600.dp -> {
|
|
14
|
+
KioskLayout(queueState = queueState)
|
|
15
|
+
}
|
|
16
|
+
maxWidth > 600.dp && maxHeight > 600.dp && ratio > 0.7f -> {
|
|
17
|
+
WideLayout(queueState = queueState)
|
|
18
|
+
}
|
|
19
|
+
maxWidth > maxHeight -> {
|
|
20
|
+
LandscapeLayout(queueState = queueState)
|
|
21
|
+
}
|
|
22
|
+
else -> {
|
|
23
|
+
UprightLayout(queueState = queueState)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
`;
|
|
29
|
+
const UPRIGHT = `
|
|
30
|
+
@Composable
|
|
31
|
+
fun UprightLayout(queueState: PagerState) {
|
|
32
|
+
val host = LocalContext.current as HostActivity
|
|
33
|
+
InnerBody(bodyState = host.shellBodyPagerState!!, queueState = queueState)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@Composable
|
|
37
|
+
private fun InnerBody(bodyState: PagerState, queueState: PagerState) {
|
|
38
|
+
HorizontalPager(state = bodyState) { page ->
|
|
39
|
+
when (page) {
|
|
40
|
+
0 -> AlphaPane()
|
|
41
|
+
1 -> BetaPane()
|
|
42
|
+
2 -> GammaPane()
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
`;
|
|
47
|
+
const HOSTFILE = `
|
|
48
|
+
class HostActivity : ComponentActivity() {
|
|
49
|
+
var shellBodyPagerState: PagerState? = null
|
|
50
|
+
override fun onCreate(b: Bundle?) {
|
|
51
|
+
setContent {
|
|
52
|
+
shellBodyPagerState = rememberPagerState(
|
|
53
|
+
initialPage = 1,
|
|
54
|
+
initialPageOffsetFraction = 0f
|
|
55
|
+
) { 3 }
|
|
56
|
+
ContentShell(queueState = rememberPagerState { 2 })
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
61
|
+
const WIDE = `
|
|
62
|
+
@Composable
|
|
63
|
+
fun WideLayout(queueState: PagerState) {
|
|
64
|
+
val paneState = rememberPagerState { 2 }
|
|
65
|
+
HorizontalPager(state = paneState) { page ->
|
|
66
|
+
when (page) {
|
|
67
|
+
0 -> AlphaPane()
|
|
68
|
+
1 -> BetaPane()
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
`;
|
|
73
|
+
const FILES = new Map([
|
|
74
|
+
['src/ContentShell.kt', SHELL],
|
|
75
|
+
['src/UprightLayout.kt', UPRIGHT],
|
|
76
|
+
['src/HostActivity.kt', HOSTFILE],
|
|
77
|
+
['src/WideLayout.kt', WIDE],
|
|
78
|
+
]);
|
|
79
|
+
|
|
80
|
+
test('enclosingRenderConditions: each arm is recovered', () => {
|
|
81
|
+
for (const [fn, want] of [
|
|
82
|
+
['KioskLayout', 'deviceIsKiosk && maxWidth > maxHeight && maxWidth > 600.dp'],
|
|
83
|
+
['WideLayout', 'maxWidth > 600.dp && maxHeight > 600.dp && ratio > 0.7f'],
|
|
84
|
+
['LandscapeLayout', 'maxWidth > maxHeight'],
|
|
85
|
+
['UprightLayout', 'else']]) {
|
|
86
|
+
const conds = co.enclosingRenderConditions(SHELL, SHELL.indexOf(fn + '(queueState'));
|
|
87
|
+
assert.equal(conds.length ? conds[0].text : null, want, `${fn}: arm condition recovered`);
|
|
88
|
+
}
|
|
89
|
+
assert.equal(co.enclosingRenderConditions(SHELL, SHELL.indexOf('UprightLayout(queueState'))[0].form, 'else',
|
|
90
|
+
"the default arm is reported as form 'else'");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
test('_enclosingWhenGroup: N mutually exclusive arms', () => {
|
|
94
|
+
const g = co._enclosingWhenGroup(SHELL, SHELL.indexOf('WideLayout(queueState'));
|
|
95
|
+
assert.ok(g !== null && g[1] && g[1].length === 4, 'all 4 arms are seen as siblings');
|
|
96
|
+
assert.equal(g[2], 1, 'the arm INDEX is correct');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('classifyConditionKind / inferSurface', () => {
|
|
100
|
+
const bothAxes = 'maxWidth > 600.dp && maxHeight > 600.dp && ratio > 0.7f';
|
|
101
|
+
const env = co.classifyConditionKind(bothAxes);
|
|
102
|
+
assert.ok(env !== null && env.kind === 'device-env', 'a framework size gate is device-env');
|
|
103
|
+
assert.deepEqual(co.inferSurface(bothAxes, env), ['tablet'], 'both axes at M3 breakpoint -> tablet');
|
|
104
|
+
const oneAxis = 'deviceIsKiosk && maxWidth > maxHeight && maxWidth > 600.dp';
|
|
105
|
+
const env1 = co.classifyConditionKind(oneAxis);
|
|
106
|
+
assert.ok(env1 !== null && env1.kind === 'device-env', 'a single-axis gate is still device-env');
|
|
107
|
+
assert.deepEqual(co.inferSurface(oneAxis, env1), [], 'only ONE axis gated -> NO surface');
|
|
108
|
+
assert.deepEqual(co.inferSurface('maxWidth > maxHeight'), ['phone-landscape'], 'orientation -> phone-landscape');
|
|
109
|
+
assert.equal(co.classifyConditionKind('userIsPremium && hasSubscription'), null, 'non-device condition not claimed');
|
|
110
|
+
assert.equal(co.classifyConditionKind('else'), null, "'else' names no device API");
|
|
111
|
+
const odd = 'maxWidth > 480.dp && maxHeight > 480.dp';
|
|
112
|
+
assert.ok(co.classifyConditionKind(odd).kind === 'device-env' && co.inferSurface(odd).length === 0,
|
|
113
|
+
'an undocumented breakpoint yields a guard but no surface');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('_inferPagerInitialPage: hoisted state across files', () => {
|
|
117
|
+
const pagerPos = UPRIGHT.indexOf('HorizontalPager(state = bodyState)');
|
|
118
|
+
assert.deepEqual(co._inferPagerInitialPage(UPRIGHT, pagerPos, { file_text: FILES }), [1, true],
|
|
119
|
+
'initialPage traced through a PARAMETER to a property in a 3rd file');
|
|
120
|
+
assert.deepEqual(co._inferPagerInitialPage(UPRIGHT, pagerPos), [0, false],
|
|
121
|
+
'without cross-file access it reports UNRESOLVED, not a confident 0');
|
|
122
|
+
const widePos = WIDE.indexOf('HorizontalPager(state = paneState)');
|
|
123
|
+
assert.deepEqual(co._inferPagerInitialPage(WIDE, widePos, { file_text: FILES }), [0, true],
|
|
124
|
+
'`rememberPagerState { n }` resolves to a CONFIDENT 0');
|
|
125
|
+
const AMBIG = new Map(FILES);
|
|
126
|
+
AMBIG.set('src/OtherHost.kt',
|
|
127
|
+
'class OtherHost { var shellBodyPagerState: PagerState? = null\n' +
|
|
128
|
+
' fun f() { shellBodyPagerState = rememberPagerState(initialPage = 2) { 3 } } }');
|
|
129
|
+
assert.deepEqual(co._inferPagerInitialPage(UPRIGHT, pagerPos, { file_text: AMBIG }), [0, false],
|
|
130
|
+
'two files with DIFFERENT initialPage -> unresolved');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('the direction that initialPage decides', () => {
|
|
134
|
+
const direction = (idx, initial, horizontal = true) => {
|
|
135
|
+
if (idx === initial) { return 'default'; }
|
|
136
|
+
if (horizontal) { return idx > initial ? 'swipe-left' : 'swipe-right'; }
|
|
137
|
+
return idx > initial ? 'swipe-up' : 'swipe-down';
|
|
138
|
+
};
|
|
139
|
+
assert.ok(direction(0, 1) === 'swipe-right' && direction(1, 1) === 'default' && direction(2, 1) === 'swipe-left',
|
|
140
|
+
'with initialPage=1');
|
|
141
|
+
assert.ok(direction(0, 0) === 'default' && direction(1, 0) === 'swipe-left', 'with a WRONG initialPage=0');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('clean no-op when there is no responsive `when`', () => {
|
|
145
|
+
const PLAIN = `
|
|
146
|
+
@Composable
|
|
147
|
+
fun PlainHost() {
|
|
148
|
+
val s = rememberPagerState { 2 }
|
|
149
|
+
HorizontalPager(state = s) { page -> when (page) { 0 -> A(); 1 -> B() } }
|
|
150
|
+
}
|
|
151
|
+
`;
|
|
152
|
+
assert.deepEqual(co.enclosingRenderConditions(PLAIN, PLAIN.indexOf('HorizontalPager')), [],
|
|
153
|
+
'an unconditionally rendered pager reports no conditions');
|
|
154
|
+
const ft = new Map([['src/Plain.kt', PLAIN]]);
|
|
155
|
+
const ci = co.buildCallIndex(ft, new Map());
|
|
156
|
+
assert.deepEqual(co._variantOf('src/Plain.kt', PLAIN.indexOf('HorizontalPager'), PLAIN, [], ci, ft, 'src'), {},
|
|
157
|
+
'no climb chain -> no variant');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
test('call-index shape stays duck-typed', () => {
|
|
161
|
+
const ci3 = co.asCallIndex([{}, { A: ['B'] }, {}]);
|
|
162
|
+
const cs = ci3.call_sites;
|
|
163
|
+
assert.equal(cs instanceof Map ? cs.size : Object.keys(cs).length, 0, 'plain 3-tuple accepted, call_sites empty');
|
|
164
|
+
assert.ok(co.buildCallIndex(new Map([['a/A.kt', 'fun H(){ C() }\nfun C(){}\n']]), new Map()) instanceof co.CallIndex,
|
|
165
|
+
'buildCallIndex returns a CallIndex');
|
|
166
|
+
const tuple = [{}, { C: ['H'] }, { H: 'activity:H' }];
|
|
167
|
+
assert.deepEqual(co.resolveSource('a/x.kt', 'C', {}, new Set(), { call_index: tuple, partial_tiers: true }),
|
|
168
|
+
['activity:H', 'callgraph-activity'], 'resolveSource works with a plain 3-tuple');
|
|
169
|
+
const r2 = co.resolveSource('a/x.kt', 'C', {}, new Set(), { call_index: tuple, partial_tiers: true, return_path: true });
|
|
170
|
+
assert.ok(r2.length === 3, 'return_path adds a third element');
|
|
171
|
+
assert.deepEqual(r2[2], [['C', 'H']], 'return_path adds the climb chain');
|
|
172
|
+
});
|