Add managed runtime accounting and probe APIs - #150
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
It introduces a broad API version bump and significant runtime/probing/persistence behavior changes across many subsystems that warrant final human verification.
Pull request overview
This PR expands libXray’s capabilities around draft validation/probing and managed runtime accounting, while updating the typed Invoke wire contract to API v4 and aligning documentation accordingly.
Changes:
- Add managed runtime accounting: periodic persistence of inbound counters and an optional authenticated loopback HTTP endpoint for reading the saved snapshot.
- Add/extend draft operations: build-only validation, isolated route checking, URL probing, and optional location probing for
pingBatch. - Update share parsing/export behavior (use outbound
tagas the node name) and introduce build-input metadata recording for reproducible builds.
File summaries
| File | Description |
|---|---|
| xray/xray.go | Adds managed runtime lifecycle alongside the managed core instance (start/stop integration). |
| xray/xray_test.go | Adds coverage ensuring temporary operations reject overlap with an active managed instance. |
| xray/validation.go | Introduces build-only config validation and overlap rejection for testXray execution. |
| xray/runtime.go | Implements runtime snapshot sampling, persistence, and ownership locking. |
| xray/runtime_test.go | Adds tests for snapshot semantics (raw counters, save behavior, ownership, restart behavior). |
| xray/runtime_http.go | Implements authenticated loopback HTTP snapshot serving with timeouts and header constraints. |
| xray/runtime_http_test.go | Tests auth, snapshot serving behavior, symlink rejection behavior, and concurrent reads. |
| xray/runtime_file.go | Adds non-Windows file locking and atomic replace with directory sync. |
| xray/runtime_file_windows.go | Adds Windows file locking and atomic replace semantics via Win32 APIs. |
| xray/probe.go | Adds a draft URL probe that routes/dials through a constructed draft instance without listening. |
| xray/probe_test.go | Tests probe routing/DNS behavior and URL safety constraints. |
| xray/ping_location_test.go | Adds tests for PingBatch location probing and probeLocation behavior. |
| xray/ping_batch.go | Extends ping batch results with optional location probing, and preserves latency behavior. |
| xray/check_route.go | Adds draft route checking using the real Router without starting the instance or dispatching the target. |
| xray/check_route_test.go | Adds tests for route evidence correctness, side-effect avoidance, timeouts, and invalid inputs. |
| share/xray_json.go | Switches outbound display naming to tag (instead of sendThrough). |
| share/validate_outbound.go | Removes legacy sendThrough nulling since it’s no longer used as name metadata. |
| share/parse_stats.go | Adds stats-enabled share parsing that returns usable/failed counts plus projected config. |
| share/parse_stats_test.go | Adds tests for candidate counting, error redaction, and legacy config equivalence. |
| share/parse_share_test.go | Updates expectations to reflect tag-based node naming and sendThrough preservation. |
| share/marshal_share.go | Refactors marshal to return projected count and support stats mode. |
| share/marshal_share_test.go | Updates expectations for tag vs sendThrough semantics in projected outputs. |
| share/generate_share_test.go | Updates tests to ensure outbound naming ignores sendThrough for node name selection. |
| share/clash_meta_test.go | Updates tests to validate tag is used for Clash-derived node names. |
| share/age.go | Refactors age decryption path to return plaintext + encrypted flag, enabling stats mode reuse. |
| readme/README.zh_CN.md | Updates Chinese docs for API v4, probes, ping location, runtime accounting, and build metadata. |
| README.md | Updates English docs for API v4, probes, ping location, runtime accounting, and build metadata. |
| invoke.go | Wires new API v4 methods/fields: stats conversion, ping location, testXray buildOnly/url probe, checkRoute, runtime metadata. |
| invoke_test.go | Adds tests for build-only semantics, checkRoute wiring/shape, runtime metadata typing, API version updates. |
| invoke_probes_test.go | Adds tests for share stats response shape, URL probe behavior, and ping location field encoding. |
| invoke_model.go | Updates typed Invoke contract to API v4 and adds new request/response models for new features. |
| desktop_bin/main.go | Adds optional -runtime host metadata file support for the desktop session core. |
| desktop_bin/main_test.go | Extends option parsing tests to cover the new -runtime flag. |
| build/test_build_metadata.py | Adds unit tests for build input metadata capture behavior and failure modes. |
| build/app/build.py | Implements build input metadata recording (commit, dirty state, modules, hashes, gomobile details). |
| AGENTS.md | Updates the repo’s documented API contract and runtime semantics to v4 and new features. |
| .gitignore | Ignores generated build input metadata JSON files. |
Review details
- Files reviewed: 36/37 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🟡 Changes recommended
The new test xray/runtime_http_test.go uses sync.WaitGroup.Go(...), which is not a standard sync.WaitGroup API and will fail to compile unless corrected.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 36/37 changed files
- Comments generated: 1
- Review effort level: Lite
There was a problem hiding this comment.
🔵 Needs a closer look
It introduces broad, cross-cutting API/runtime/build changes (including a wire-contract version bump) that warrant careful human validation despite strong test coverage.
Review details
- Files reviewed: 41/42 changed files
- Comments generated: 1
- Review effort level: Lite
There was a problem hiding this comment.
🟡 Changes recommended
xray/runtime_file_windows.go is missing a //go:build windows constraint, which will break non-Windows builds.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (1)
invoke_model.go:14
- The PR description says the typed Invoke contract is updated to API v5, but the code (and updated docs) define and enforce
LibXrayAPIVersion = 3. Please reconcile this by updating the PR description (or, if v5 is truly intended, adjusting the code/docs/tests consistently—note AGENTS.md explicitly says to keep the version fixed at 3 for this release).
type LibXrayMethod string
const LibXrayAPIVersion = 3
- Files reviewed: 37/38 changed files
- Comments generated: 1
- Review effort level: Lite
There was a problem hiding this comment.
🔵 Needs a closer look
Significant new runtime persistence/HTTP surface and contract-adjacent behavior changes warrant final human review, and the PR description’s API version claim currently conflicts with the implemented v3 contract.
Review details
Suppressed comments (1)
invoke_model.go:15
- PR description says the typed Invoke contract is updated to API v5, but the implementation and docs in this PR keep the wire version fixed at 3 (LibXrayAPIVersion = 3; AGENTS/README examples use apiVersion: 3). Please reconcile by updating the PR description (or, if v5 is actually intended, aligning the constant/tests/docs accordingly).
type LibXrayMethod string
const LibXrayAPIVersion = 3
const (
- Files reviewed: 42/42 changed files
- Comments generated: 0 new
- Review effort level: Lite
概述
tag作为分享节点名称;统一分享解析,始终返回config、usableCount和failedCount,支持 age 加密订阅。TestXray仅通过core.LoadConfig验证配置,不创建或启动实例,也不保证配置能够启动或连接成功;移除ProbeXray和CheckRoute。locationJson返回,由 App 解析。go.mod/go.sum的恢复逻辑。LibXrayAPIVersion固定为3,不在本版本内递增。验证
go test ./... -count=1go test -race ./xray -run 'TestRuntimeHTTP|TestRuntimeStoresRawCountersWithoutResetOrTotals|TestRuntimeWriteFailuresPreserveSavedFile|TestManagedRuntimeStartFailureAndStop' -count=1python3 build/test_build.pygit diff --check以上检查已在 macOS(darwin/arm64,Go 1.27.1)通过。本轮未重新打包 Android / Apple 原生产物,也未执行 Windows / Linux 平台运行验证。