Commit Graph
2 Commits
Author SHA1 Message Date
ericandClaude Opus 5.5 488ff345f3 feat(plugins): download the plugins a config names by url
A plugin outbound can now give a url instead of a path. With the new
plugin-fetch feature, a start downloads what the cache is missing into
<cache>/<sha256>/<file> before any outbound is built, and points the
outbounds at it; a reload, and testing an outbound, resolve from the cache
only and refuse what they would have to download.

- https only, redirects included, and only together with a sha256 pin.
- Downloads go to a temporary file, are hashed as they arrive, and are
  renamed into place only once the digest matches, under the url's own
  name, with the platform's library suffix added when it has no
  extension, which is what Windows needs to load it. A download past the
  declared size, or past 64 MiB without one, is stopped.
- The cache directory comes from FetchOptions or PLUGIN_CACHE_DIR, with
  no default: whether a directory is safe to load code from is the
  embedding app's call.
- prefetch() reports QUEUED/CACHED for every plugin before any download,
  then STARTED, PROGRESS (at most every 100 ms) and exactly one DONE or
  FAILED each, on the calling thread; the callback can cancel. A download
  that has not finished gets a PROGRESS heartbeat at least once a second,
  before STARTED too, so that one stuck connecting or in the handshake
  can be cancelled as well as one stuck mid-body.

conf gains a [Plugin] section that declares each plugin once (path, url,
sha256, size) and a `plugin` proxy protocol that refers to it by name,
with args= or args-b64= for arguments that contain commas. Proxy
parameters are now split at the first `=` only, which used to drop any
value that contained one.

leaf-ffi gains leaf_prefetch_plugins, so that an app can download the
plugins as soon as it has the config, and show progress, and the start
that follows finds everything in the cache. Events arrive as a
LeafFetchEvent whose first field is its size, on the calling thread and
never after the call returns. Adds ERR_PLUGIN_FETCH, ERR_CANCELLED and
ERR_UNSUPPORTED, and the plugin and plugin-fetch features. It is tested
by unit tests rather than end to end: the library is a Rust dylib, which
does not link in a Windows debug build (LNK1189).

Twenty-three fetch/ e2e cases download from a per-case https server
whose routes can announce a wrong length, omit it, fail, redirect, or
hold a body at a gate until the case opens it. Every case checks its
events against one statement of the progress contract, and every
failure, cancel and timeout case checks that the cache is left empty.
One checks that testing an outbound reads the cache, including a file
put there by hand, and never downloads.

The READMEs describe plugins in conf files and downloading them, and
plugin-test and CI run the new unit tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 22:26:22 +08:00
eric b70eaa705a test(e2e): add the end-to-end suite for the plugin host
`leaf-e2e` starts real leaf instances and drives them from the outside over
SOCKS5, so a case covers the path a deployment takes -- config parsing, plugin
loading, routing, the dispatcher, the C ABI data plane -- and nothing reaches
into leaf to build a handler by hand. Cases are values rather than `#[test]`
functions, so the suite is a matrix of implementation, protocol, transport and
behaviour instead of a wall of copies, and each runs in its own process, free
to crash, hang, or set load-time environment.

The lanes:

- `differential` runs a behaviour natively and again with a plugin substituted
  for one stage, and requires the two to agree. The server is stock leaf, so
  these are interoperability tests. `protocols`, `halfclose` and `teardown`
  extend that across every stack, relay and selector, the end of a request on
  each transport, and shutdown.
- `abi`, `loader` and `coexist` check what the host accepts, refuses, and can
  load at once, through a real `dlopen`.
- `hostile` and `datagram` drive conformance plugins -- one in Rust, one in Go
  -- that misbehave on request, exercising the host's bounds checks, clamps,
  buffer growth and `decode_packet` handling.
- `stress` and the meters measure both sides back to back and assert the ratio,
  since absolute numbers from a shared runner say little; throughput, latency,
  setup cost and cpu cost land in `meters.json` beside the case logs. What the
  process is holding is asserted directly instead, against the case's own
  allocator, because what matters there is that it stopped growing.
- `blackbox` runs the shipped binary: on a config file, and on a plugin
  library through `--verify-plugin`, whose report has to agree with what the
  loader itself would do.

Plugins are built by the harness, and a case whose toolchain is missing is
reported as ignored with the reason; `--strict`, which CI passes, makes that a
failure, so the suite cannot go green by running nothing. The suite runs on
Windows too, where a pause is never shorter than 16ms and cases that dribble
bytes bound their pauses instead.
2026-09-10 17:59:49 +08:00