mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-19 10:22:07 +08:00
test(perf): add proxy scroll scene to the perf adapter
Adds a proxy page scenario to the measurement adapter: a core-module shim serves synthetic proxy/clash/run-state data at the invoke seam (active only for the proxy scenario; other scenarios stay byte-identical), and a sawtooth scroll driver keeps the virtualizer measuring and the throttled scroll-position save running. Running the scene additionally requires the harness-side scenario contract and schema v10 from the clash-verge-rev-harness repository.
This commit is contained in:
+1
-1
@@ -220,7 +220,7 @@ pub fn run() -> std::process::ExitCode {
|
||||
.set_activation_policy(tauri::ActivationPolicy::Prohibited)?;
|
||||
let scenario = std::env::var("PERF_SCENARIO").unwrap_or_else(|_| "traffic".into());
|
||||
let layer = std::env::var("PERF_LAYER").unwrap_or_else(|_| "component".into());
|
||||
if !matches!(scenario.as_str(), "traffic" | "logs" | "connections")
|
||||
if !matches!(scenario.as_str(), "traffic" | "logs" | "connections" | "proxy")
|
||||
|| !matches!(layer.as_str(), "page" | "component" | "dom")
|
||||
{
|
||||
return Err("invalid perf scene".into());
|
||||
|
||||
@@ -2,6 +2,8 @@ import { layer, scenario, startReplay } from './replay'
|
||||
|
||||
if (scenario === 'traffic') {
|
||||
await import('./traffic')
|
||||
} else if (scenario === 'proxy') {
|
||||
await import('./proxy')
|
||||
} else {
|
||||
const root = document.getElementById('root')!
|
||||
document.body.style.cssText = 'margin:0;font:14px -apple-system,sans-serif'
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
// Only this perf build aliases '@tauri-apps/api/core' to a shim that serves
|
||||
// these responses for the proxy scenario; the normal application never
|
||||
// imports it. The runtime-injected __TAURI_INTERNALS__ is read-only, so
|
||||
// interception happens at import resolution instead. Unknown commands pass
|
||||
// through to the real backend (perf_state, event plugin), keeping harness
|
||||
// ownership probes and lifecycle commands working. The proxy scenario is
|
||||
// therefore a JavaScript invoke adapter, not native plugin IPC.
|
||||
|
||||
const GROUP_COUNT = 40
|
||||
const NODES_PER_GROUP = 24
|
||||
|
||||
const capabilities = {
|
||||
udp: true,
|
||||
xudp: false,
|
||||
tfo: false,
|
||||
mptcp: false,
|
||||
smux: false,
|
||||
}
|
||||
|
||||
const history = (delay: number) => [{ time: '2026-11-19T00:00:00Z', delay }]
|
||||
|
||||
const buildProxyView = () => {
|
||||
const records: Record<string, unknown> = {}
|
||||
const groups: {
|
||||
name: string
|
||||
type: string
|
||||
now: string
|
||||
hidden: boolean
|
||||
history: { time: string; delay: number }[]
|
||||
members: unknown[]
|
||||
}[] = []
|
||||
|
||||
for (let g = 0; g < GROUP_COUNT; g++) {
|
||||
const members: unknown[] = []
|
||||
for (let n = 0; n < NODES_PER_GROUP; n++) {
|
||||
const name = `node-${g}-${n}`
|
||||
const recordId = `record-${g}-${n}`
|
||||
records[recordId] = {
|
||||
recordId,
|
||||
name,
|
||||
type: n % 3 === 0 ? 'Shadowsocks' : n % 3 === 1 ? 'Vmess' : 'Trojan',
|
||||
history: history(30 + ((g * 7 + n * 13) % 40) * 10),
|
||||
source: { kind: 'core', proxyName: name },
|
||||
...capabilities,
|
||||
}
|
||||
members.push({ kind: 'node', name, recordId })
|
||||
}
|
||||
groups.push({
|
||||
name: `group-${String(g).padStart(2, '0')}`,
|
||||
type: g % 2 === 0 ? 'Selector' : 'URLTest',
|
||||
now: `node-${g}-0`,
|
||||
hidden: false,
|
||||
history: history(20),
|
||||
members,
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
schemaVersion: 1,
|
||||
orderSource: 'runtime',
|
||||
providerState: 'ready',
|
||||
global: {
|
||||
name: 'GLOBAL',
|
||||
type: 'Selector',
|
||||
now: 'group-00',
|
||||
hidden: true,
|
||||
history: [],
|
||||
members: groups.map((group) => ({ kind: 'group', name: group.name })),
|
||||
...capabilities,
|
||||
},
|
||||
direct: 'DIRECT',
|
||||
groups: groups.map((group) => ({ ...group, ...capabilities })),
|
||||
records,
|
||||
standalone: [],
|
||||
providers: [],
|
||||
}
|
||||
}
|
||||
|
||||
const handlers: Record<string, () => unknown> = {
|
||||
get_proxy_view: buildProxyView,
|
||||
get_verge_config: () => ({
|
||||
language: 'en',
|
||||
theme_mode: 'light',
|
||||
proxy_layout_column: 2,
|
||||
default_latency_timeout: 10000,
|
||||
enable_hover_jump_navigator: true,
|
||||
hover_jump_navigator_delay: 200,
|
||||
pause_render_traffic_stats_on_blur: false,
|
||||
}),
|
||||
get_profiles: () => ({
|
||||
current: 'perf-profile',
|
||||
items: [
|
||||
{
|
||||
uid: 'perf-profile',
|
||||
type: 'remote',
|
||||
name: 'Perf Profile',
|
||||
desc: '',
|
||||
url: '',
|
||||
selected: true,
|
||||
extra: {},
|
||||
option: { update_interval: 0 },
|
||||
},
|
||||
],
|
||||
}),
|
||||
get_clash_info: () => ({
|
||||
mixed_port: 7897,
|
||||
socks_port: 0,
|
||||
port: 0,
|
||||
server: '127.0.0.1:9097',
|
||||
secret: null,
|
||||
}),
|
||||
get_runtime_config: () => null,
|
||||
get_sys_proxy: () => ({ enable: false, bypass: '', pac_file: '' }),
|
||||
get_runtime_state: () => ({
|
||||
mode: 'Sidecar',
|
||||
service: 'ready',
|
||||
serviceUnavailableReason: null,
|
||||
pendingAction: null,
|
||||
sidecarAllowed: true,
|
||||
isAdmin: false,
|
||||
opInFlight: false,
|
||||
serviceUsable: true,
|
||||
tunCapable: false,
|
||||
serviceNeedsAttention: false,
|
||||
}),
|
||||
get_sidecar_failure: () => null,
|
||||
get_pending_failures: () => [],
|
||||
'plugin:mihomo|get_configs': () => ({ mode: 'rule', 'mixed-port': 7897 }),
|
||||
'plugin:mihomo|get_rule_providers': () => ({ providers: {} }),
|
||||
'plugin:mihomo|get_rules': () => ({ rules: [] }),
|
||||
}
|
||||
|
||||
/** Returns the mocked response, or undefined to pass through to the backend. */
|
||||
export const mockCommand = (cmd: string): unknown => {
|
||||
const handler = handlers[cmd]
|
||||
return handler ? handler() : undefined
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import { ThemeProvider, createTheme } from '@mui/material'
|
||||
import { useEffect } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import { SWRConfig } from 'swr'
|
||||
|
||||
import { AppDataProvider } from '../../src/providers/app-data-provider'
|
||||
import { initializeLanguage } from '../../src/services/i18n'
|
||||
import { setPreloadConfig } from '../../src/services/preload'
|
||||
import { swrConfig } from '../../src/services/query-client'
|
||||
import { AppStoreProvider } from '../../src/store/app-store'
|
||||
|
||||
import '../../src/assets/styles/page.scss'
|
||||
|
||||
const root = document.getElementById('root')!
|
||||
document.body.style.cssText = 'margin:0;font:14px -apple-system,sans-serif'
|
||||
root.style.cssText = 'width:1000px;height:700px;overflow:hidden'
|
||||
new MutationObserver(() => {
|
||||
document.documentElement.dataset.perfDraw = String(Date.now())
|
||||
}).observe(root, { childList: true, characterData: true, subtree: true })
|
||||
|
||||
setPreloadConfig({
|
||||
language: 'en',
|
||||
theme_mode: 'light',
|
||||
pause_render_traffic_stats_on_blur: false,
|
||||
} as IVergeConfig)
|
||||
await initializeLanguage('en')
|
||||
|
||||
const ProxyPage = (await import('../../src/pages/proxies')).default
|
||||
|
||||
const findScroller = () => {
|
||||
const elements = document.querySelectorAll<HTMLElement>('#root *')
|
||||
for (const element of elements) {
|
||||
const { overflowY } = getComputedStyle(element)
|
||||
if (
|
||||
(overflowY === 'auto' || overflowY === 'scroll') &&
|
||||
element.scrollHeight > element.clientHeight
|
||||
) {
|
||||
return element
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
// Deterministic sawtooth scrolling keeps the virtualizer measuring, the
|
||||
// throttled scroll-position save running and the DOM mutating so the perfDraw
|
||||
// marker tracks view-input delivery. Each applied scroll step counts as one
|
||||
// delivered view input; the interval keeps delivering (throttled by the
|
||||
// browser) while the window is hidden and rAF is suspended.
|
||||
export const ScrollDriver = () => {
|
||||
useEffect(() => {
|
||||
const data = document.documentElement.dataset
|
||||
let stopped = false
|
||||
const step = () => {
|
||||
const scroller = findScroller()
|
||||
if (scroller) {
|
||||
const max = scroller.scrollHeight - scroller.clientHeight
|
||||
if (max > 0) {
|
||||
const next =
|
||||
scroller.scrollTop + 36 > max - 36 ? 0 : scroller.scrollTop + 36
|
||||
scroller.scrollTop = next
|
||||
data.perfScroll = String(Number(data.perfScroll || 0) + 1)
|
||||
data.perfDelivered = String(Number(data.perfDelivered || 0) + 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
const drive = () => {
|
||||
if (stopped) return
|
||||
step()
|
||||
requestAnimationFrame(drive)
|
||||
}
|
||||
const handle = requestAnimationFrame(drive)
|
||||
const timer = window.setInterval(step, 250)
|
||||
return () => {
|
||||
stopped = true
|
||||
cancelAnimationFrame(handle)
|
||||
window.clearInterval(timer)
|
||||
}
|
||||
}, [])
|
||||
return null
|
||||
}
|
||||
|
||||
createRoot(root).render(
|
||||
<SWRConfig value={swrConfig}>
|
||||
<ThemeProvider theme={createTheme()}>
|
||||
<AppStoreProvider>
|
||||
<AppDataProvider>
|
||||
<ProxyPage />
|
||||
<ScrollDriver />
|
||||
</AppDataProvider>
|
||||
</AppStoreProvider>
|
||||
</ThemeProvider>
|
||||
</SWRConfig>,
|
||||
)
|
||||
@@ -0,0 +1,17 @@
|
||||
import { startReplay } from './replay'
|
||||
|
||||
// Thin loader: error handlers must precede scene module evaluation so any
|
||||
// startup failure surfaces in perfError.
|
||||
const data = document.documentElement.dataset
|
||||
window.addEventListener('error', (event) => {
|
||||
data.perfError = event.message
|
||||
})
|
||||
window.addEventListener('unhandledrejection', (event) => {
|
||||
data.perfError = String(event.reason)
|
||||
})
|
||||
|
||||
data.perfStage = 'loader'
|
||||
await import('./proxy-scene')
|
||||
data.perfStage = 'scene'
|
||||
startReplay()
|
||||
data.perfStage = 'replay'
|
||||
@@ -0,0 +1,30 @@
|
||||
// Aliased in place of '@tauri-apps/api/core' only by the perf build. The
|
||||
// direct relative import keeps the original module outside the alias so this
|
||||
// shim can forward to it. Invocation stays byte-identical for every scenario
|
||||
// except proxy, which needs the JavaScript invoke adapter.
|
||||
import {
|
||||
Channel,
|
||||
convertFileSrc,
|
||||
invoke as realInvoke,
|
||||
type InvokeArgs,
|
||||
type InvokeOptions,
|
||||
} from '../../node_modules/@tauri-apps/api/core.js'
|
||||
|
||||
import { mockCommand } from './invoke-mock'
|
||||
import { scenario } from './replay'
|
||||
|
||||
const proxied = scenario === 'proxy'
|
||||
|
||||
export const invoke = async <T>(
|
||||
cmd: string,
|
||||
args?: InvokeArgs,
|
||||
options?: InvokeOptions,
|
||||
): Promise<T> => {
|
||||
if (proxied) {
|
||||
const mocked = mockCommand(cmd)
|
||||
if (mocked !== undefined) return mocked as T
|
||||
}
|
||||
return realInvoke(cmd, args, options)
|
||||
}
|
||||
|
||||
export { Channel, convertFileSrc }
|
||||
@@ -6,5 +6,11 @@ export default mergeConfig(
|
||||
defineConfig({
|
||||
root: 'scripts/perf',
|
||||
build: { outDir: '../../target/perf/dist', target: 'safari16' },
|
||||
resolve: {
|
||||
alias: {
|
||||
'@tauri-apps/api/core': new URL('./tauri-core-shim.ts', import.meta.url)
|
||||
.pathname,
|
||||
},
|
||||
},
|
||||
}),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user