Skip to content

test(provider): cover ProviderCore auto-update, model loading, standalone server and SSD factory gaps - #1296

Closed
davidtai wants to merge 9 commits into
ci/provider-coverage-scopefrom
test/provider-core-gaps-coverage
Closed

davidtai wants to merge 9 commits into
ci/provider-coverage-scopefrom
test/provider-core-gaps-coverage

Conversation

@davidtai

@davidtai davidtai commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This PR adds 157 ProviderCoreTests tests for coverage gaps in ProviderCore. The tests need no model weights, no GPU work, no network beyond 127.0.0.1, no launchd change, no Keychain or Secure Enclave write and no write under the home folder. They cover:

  • the background auto-update cycle,
  • model load refusals, waits and slot bookkeeping in ProviderLoop,
  • drain and model admission in the standalone server,
  • the SSD prefix-cache factory,
  • LaunchAgent install, stop and restart against a scripted launchctl,
  • the error text of PersistentEnclaveKey.

The tests cover 800 more provider lines than the base (73,250 to 74,050 covered lines).

Merge after #1253 and #1273. This PR is based on ci/provider-coverage-scope.

Linked issue

None.

What the tests check

Tests/ProviderCoreTests/Update/AutoUpdateCycleTests.swift (14 tests). Each test uses a real ProviderLoop, a temp install root (UpdateRecoveryFixture) and the loopback MockCoordinator:

  • If the release has the same version, the cycle returns up to date and frees the cross-process lease.
  • If the release is for another platform, the check fails and the loop serves again.
  • A quarantined release is not downloaded.
  • A bundle hash mismatch fails the stage before any drain.
  • A newer release is staged, drained, committed and restarted once. The live binary in the temp root becomes v2. The recovery state holds the candidate with the injected launch baseline.
  • A failed restart makes the loop serve again. The next cycle restarts the installed candidate without a new download.
  • A held lease skips the cycle.
  • An update claim is exclusive. Shutdown and drain refuse it. A candidate restart without a lease fails and does not read the launch baseline.
  • The monitor task starts only when auto_update is true.

Tests/ProviderCoreTests/Service/LaunchAgentLifecycleTests.swift (26 tests) and LaunchAgentPathsAndErrorsTests.swift (7 tests):

  • Install writes the plist (label, RunAtLoad, KeepAlive, ExitTimeOut, log path, the full argv with config, models and local endpoint), then enables, bootstraps and kickstarts the service.
  • The exact launchctl call list for stop, restart, restart after drain, kickstartIfLoaded and uninstall.
  • Each error case: "already loaded" and "could not find service" are accepted. A disable, bootstrap, bootout or kickstart failure is thrown with trimmed text. A kickstart that cannot start launchctl is thrown. Restart with no plist throws notInstalled.
  • The plist allowance rewrite refuses a non-dictionary plist and garbage bytes and leaves the file unchanged.

Tests/ProviderCoreTests/KVCacheSSD/SSDPrefixCacheFactoryTests.swift (17 tests). Each test uses a temp root and an in-memory key:

  • Paths: the exact model folder names. The test root is trimmed and standardized, and the cache root falls back when the opt-in is off.
  • Flags: the ephemeral opt-in words, the forced in-memory key, and weight-hash trimming.
  • Each make refusal reports exactly one reason: missing hash, unsupported plan, key unavailable, unsafe path, epoch unavailable.
  • A built cache has the exact config fields: environment knobs, defaults and window sidecar geometry. A new key on the same root starts a new epoch.
  • Whole-root maintenance removes only stale temp files.

Tests/ProviderCoreTests/ProviderLoop/ (50 tests; helpers in ModelLoadingTestSupport.swift):

  • ModelLoadRefusalTests: ensureModelLoaded checks for shutdown and for a missing or unadvertised model (404). It also covers waits on the same model's load or unload, the load gate, the slot cap (503), memory refusals recorded for doctor, the final admission check and the before-load hook. A changed Qwen4 footprint stops the load. After each failure, the test checks that the load holds nothing.
  • ModelSlotBookkeepingTests: unload paths, warm state and weight-hash records.
  • ModelLoadEvictionAndAdmissionTests: eviction, fast admission, the activation reserve push order, load error status codes and VLM detection.

Tests/ProviderCoreTests/Server/ (40 tests):

  • StandaloneServerDrainTests: lifecycle drain outcomes (drained, timed out, forced, shared, replaced), drainAndStop, and start and stop (concurrent stop, a second start, /health while draining).
  • StandaloneServerModelAdmissionTests: catalog filter, config clamps, 404 and 429 error envelopes, tokenizer resolution and /tokenize, /metrics samples, slot reservations, LRU eviction, memory headroom gates, the fleet KV budget and weight-hash trimming.

Tests/ProviderCoreTests/Security/PersistentEnclaveKeyErrorTests.swift (3 tests): the exact text of every error case.

Production change to review

Two small test seams. Production does not use them, so production behavior does not change.

  1. ProviderLoop+AutoUpdate.swift: performAutoUpdateCheck was private and is now internal. It takes three optional trailing parameters: the updater, the launch-baseline reader and the restart. It returns its outcome (@discardableResult). prepareInstalledCandidateRestart takes the baseline reader as a closure with the same default, so the baseline is still read only after the lease check. The production caller (startAutoUpdateMonitor) passes none of these.
  2. LaunchctlControl.swift: two @TaskLocal values, runnerForTesting and homeDirectoryForTesting. LaunchAgent.plistPath() and logPath() now read the home folder through LaunchctlControl.homeDirectory(). With no task-local bound (production), the code spawns /bin/launchctl and uses the real home folder as before. A task-local value is visible only to the task that binds it, so parallel tests cannot see each other's values. This follows the existing @TaskLocal pattern in LocalRequestCancellation.

Coverage

Before: run 36780084216 (head of #1273). After: run 36818862397 (this PR, head 5b144441), artifact provider-coverage.

Row or file Lines before Lines after Regions before Regions after
Provider (Swift) product 82.17% of 78,968 83.17% of 78,981 75.83% 77.04%
Provider CLI (darkbloom) 32.22% of 8,579 32.22% of 8,579 36.72% 36.72%
ProviderBenchmark 53.71% of 9,136 53.71% of 9,136 55.33% 55.33%
Provider (Swift) total 74.81% of 97,919 75.61% of 97,932 70.42% 71.41%
ProviderLoop+AutoUpdate.swift 15.65% of 262 86.94% of 268
Service/LaunchAgent.swift 29.78% of 272 100.00% of 272
Service/LaunchctlControl.swift 58.06% of 62 82.61% of 69
KVCacheSSD/SSDPrefixCacheFactory.swift 29.89% of 261 85.06% of 261
Security/PersistentEnclaveKey.swift 25.61% of 285 34.39% of 285
Security/PersistentEnclaveKey+ECIES.swift 0.00% of 58 0.00% of 58
Server/StandaloneServer.swift 69.31% of 1,649 72.10% of 1,649
Server/StandaloneServer+Drain.swift 54.55% of 66 95.45% of 66
ProviderLoop+ModelLoading.swift 60.94% of 1,239 67.64% of 1,239

Not tested and why

  • PersistentEnclaveKey load, create, sign, delete and the ECIES extension: every path calls the real Secure Enclave or the Keychain, and the private initializer needs a real SecKey. Only the error text is tested.
  • The success path of ProviderLoop.ensureModelLoaded and StandaloneServer.ensureModelLoaded after the weights load: it needs a real model container, and the post-load KV headroom checks measure the real machine memory, so the results would depend on the runner.
  • SSDPrefixCacheFactory.stopWholeRootMaintenance() reads the process environment, so a test would act on the real cache root. The key-load failure branch of make needs the Keychain.
  • The auto-update commitFailed and drainTimedOut outcomes: the cycle gives no hook between stage and commit, and the drain deadline is 120 seconds.

Test plan

  • CI Provider Unit Tests, run 36818862397: all tests pass. Provider Prompt Parity and Provider SDK Tests pass. The Swift package was not built locally (CI is the authority).
  • make docs-impact-check BASE=origin/master and make docs-check

Components touched

  • coordinator (Go)
  • provider (Rust, legacy)
  • provider-swift (Swift CLI)
  • console-ui (Next.js)
  • enclave (Swift)
  • infra / CI / release
  • docs

Protocol / interface changes

  • No protocol/interface changes

Documentation impact

  • Canonical documentation updated
  • No documentation needed. Reason: tests and internal test seams only. No behavior, flag or wire change.

Diagrams

Behavior (what is tested):

flowchart LR
  subgraph Before
    T1[tests] -.no test.-> U1["auto-update cycle"]
    T1 -.no test.-> L1["LaunchAgent install / stop / restart"]
    T1 -.no test.-> F1["SSD cache factory make()"]
  end
  subgraph After
    T2[AutoUpdateCycleTests] --> U2["ProviderLoop.performAutoUpdateCheck"]
    U2 <-->|"http 127.0.0.1"| M2[MockCoordinator release]
    U2 --> R2["temp install root: stage, commit, candidate"]
    T3[LaunchAgentLifecycleTests] --> L2["LaunchAgent"] --> S3["scripted launchctl + temp home"]
    T4[SSDPrefixCacheFactoryTests] --> F2["make() on a temp root, in-memory key"]
    T5["ModelLoad / StandaloneServer tests"] --> E5["refusals, drains, eviction, admission"]
  end
  classDef old fill:#f5d5d5,stroke:#8a1c1c,color:#1a1a1a
  classDef new fill:#d5ecd5,stroke:#1c6b1c,color:#1a1a1a
  class U1,L1,F1 old
  class U2,L2,F2,E5,R2,S3 new
Loading

Code (the seams):

flowchart TD
  subgraph Before
    A1["performAutoUpdateCheck (private)"] --> B1["SelfUpdater for the running install"]
    A1 --> C1["LaunchAgent.launchSnapshot()"]
    A1 --> D1["ProcessLifecycle.restartAfterUpdate()"]
    E1["LaunchctlControl.runThrowing"] --> P1["/bin/launchctl"]
    H1["LaunchAgent.plistPath()"] --> K1["real home folder"]
  end
  subgraph After
    A2["performAutoUpdateCheck (internal)"] --> Q2{"argument passed?"}
    Q2 -->|"no, production"| B2["same updater, snapshot and restart as before"]
    Q2 -->|"yes, tests"| T2["temp updater, fixed snapshot, recorded restart"]
    E2["LaunchctlControl.runThrowing"] --> Q3{"runnerForTesting bound?"}
    Q3 -->|"no, production"| P2["/bin/launchctl"]
    Q3 -->|"yes, test task"| S2["scripted output"]
    H2["LaunchAgent.plistPath()"] --> Q4{"homeDirectoryForTesting bound?"}
    Q4 -->|"no, production"| K2["real home folder"]
    Q4 -->|"yes, test task"| K3["temp folder"]
  end
  classDef prod fill:#dde6f5,stroke:#1c3d8a,color:#1a1a1a
  classDef test fill:#f5ecd5,stroke:#8a6a1c,color:#1a1a1a
  class B1,C1,D1,P1,K1,B2,P2,K2 prod
  class T2,S2,K3 test
Loading

Notes for reviewers

  • The Vercel checks fail on this PR as on every open PR ("You don't have permission to create a Preview Deployment"). They are not related to this change.
  • The first two CI runs failed to compile the tests. One test file had the same name as an existing file, and one test needed the Benchmarking SPI import. Two follow-up commits fix these.

🤖 Generated with Claude Code

Refactor Pass

A dedicated refactor subagent reviewed the diff against the AGENTS.md structure, clean-code and refactor rules. Outcome: one test-only commit, aef4240 (6 files, +55 / −113), plus a signed merge of the refactored base #1273 (a1ff283).

  • ModelLoadEvictionAndAdmissionTests.swift: the type name now matches the file name.
  • LaunchAgentLifecycleTests.swift (9 places) and LaunchAgentPathsAndErrorsTests.swift (1 place): direct pattern catches, such as catch LaunchAgentError.bootstrapFailed(let detail), replace catch let error as … { guard case … }. A wrong error case still fails the test.
  • AutoUpdateCycleTests.swift: a private runAutoUpdateCycle(...) helper replaces 8 copies of the same performAutoUpdateCheck call. Each test still passes its own restart closure.
  • ModelLoadRefusalTests.swift: try #require(parked) replaces #expect(parked) in 9 places. A waiter that never parks now fails at that line and can no longer hang.
  • StandaloneServerModelAdmissionTests.swift: AdmissionCallRecorder is now WeightHashCallRecorder, because it records only weight-hash calls.
  • No production code, assertion or wait order changed.

Validation on the final tree: swift build --build-tests, then swift test --filter on the PR's suites, passes (157 tests in 15 suites). git diff --check, make docs-impact-check BASE=ci/provider-coverage-scope and make docs-check (330 OK) also pass.

For the author:

  • The test seams this PR adds to production code (performAutoUpdateCheck injection, LaunchctlControl.runnerForTesting and homeDirectoryForTesting) stay. The real paths call launchd and wait 5 minutes.
  • Three StandaloneServerDrainTests tests wait with sleeps (200 ms, 200 ms, 50 ms). They do not prove that the join or wait path ran, and the same file uses #expect(draining) after its polls.
  • Script defect, separate from this PR: scripts/stage-test-metallib.sh looks only for *PackageTests.xctest. Swift 6.4 builds one bundle per target (ProviderCoreTests.xctest), so the script stops with "test runner bundle not found".

Port to master, merge f1e1748 (follow-up): merged the ported #1273 (542c8fc), which carries master. The merge was clean. The three production files and the test folders are unchanged on master, and the test seams compile. A clean swift build --build-tests passes, and the 15 suites pass (157 tests, with the metallib copied by hand until #1346 lands). docs-impact-check passes, and docs-check shows only master's known failure.

…one server routes and SSD cache factory

Add ProviderCore tests that need no model weights, no GPU work, no
network beyond loopback and no writes under the home folder.

Add three internal test seams to the background auto-update cycle: the
updater, the launch baseline reader and the restart. Production passes
none of them, so production behavior does not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 1, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

Two test files in the target had the same name, so the build failed with
multiple producers for one object file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 1, 2026

Copy link
Copy Markdown

Deployment failed for project eigen-homepages-darkbloom with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: eigen-homepages-darkbloom.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Oct 1, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference-landing with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference-landing.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@vercel

vercel Bot commented Oct 1, 2026

Copy link
Copy Markdown

Deployment failed for project d-inference-console-ui-dev with the following error:

You don't have permission to create a Preview Deployment for this Vercel project: d-inference-console-ui-dev.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

davidtai and others added 2 commits September 30, 2026 23:59
…space

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ripted launchctl

Add two task-local test seams to LaunchctlControl: a launchctl runner
and the home folder for agent paths. Production never binds them, so it
still spawns /bin/launchctl and uses the real home folder. A task-local
value is visible only to the test task that binds it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
davidtai and others added 2 commits October 1, 2026 19:09
Brings in master through 1693685 and the updated coverage report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WatchdogAgent still reads the real home folder, so the comment no longer says "agent paths".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
davidtai added a commit that referenced this pull request Oct 2, 2026
The launchd child test, the daemon install test and the low-memory
preflight test call `runForeground` and `launchDaemon` with the real home
folder and the real launchctl. If a guard regressed, they could drain and
stop a live provider on a developer Mac. The launchctl and home folder
test seams come from #1296, which this branch does not have. The three
tests move to a follow-up PR on #1296's branch, where they bind both
seams.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
davidtai and others added 2 commits October 4, 2026 15:44
Catch LaunchAgentError cases by pattern, share the auto-update cycle call,
stop a model-load test when its waiter never parks, and name the suite and
the weight-hash recorder after what they cover.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@blacksmith-sh

blacksmith-sh Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Found 5 test failures on Blacksmith runners:

Failures

Test View Logs
TestIntegration_AttestationHeaders View Logs
TestIntegration_ConcurrentRequests View Logs
TestIntegration_ReferralRewardDistribution View Logs
TestIntegration_SwiftProviderRealRoutingGates View Logs
TestProfile_SingleProviderNonStreaming View Logs

Fix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

…s-coverage

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Gajesh2007 added a commit that referenced this pull request Oct 5, 2026
Combine #1253, #1273, #1275, #1292, #1293, #1294, #1295, #1296, #1303 and #1307 into one reviewable provider coverage change. Preserve coverage reporting and every CLI, fan, benchmark, serve-loop, update, model-loading and lifecycle test objective.

Co-authored-by: David Tai <dtaipublic@gmail.com>
@Gajesh2007

Copy link
Copy Markdown
Member

Consolidated into #1253 at cf08e55. Update recovery, loading, bookkeeping, standalone admission/drain, SSD factory, LaunchAgent and enclave-error objectives from f1e1748 are preserved. Lifecycle assertions now retain current master removal confirmation and error-37 rejection using virtual polling time. Closing this superseded stack PR; its source branch remains available. Final combined validation and human approval are tracked in #1253. Nothing has been merged into master.

@Gajesh2007 Gajesh2007 closed this Oct 5, 2026
Gajesh2007 added a commit that referenced this pull request Oct 5, 2026
Combine #1253, #1273, #1275, #1292, #1293, #1294, #1295, #1296, #1303 and #1307 into one reviewable provider coverage change. Preserve coverage reporting and every CLI, fan, benchmark, serve-loop, update, model-loading and lifecycle test objective.

Co-authored-by: David Tai <dtaipublic@gmail.com>
Gajesh2007 added a commit that referenced this pull request Oct 5, 2026
* test(provider): consolidate Swift coverage and lifecycle suites

Combine #1253, #1273, #1275, #1292, #1293, #1294, #1295, #1296, #1303 and #1307 into one reviewable provider coverage change. Preserve coverage reporting and every CLI, fan, benchmark, serve-loop, update, model-loading and lifecycle test objective.

Co-authored-by: David Tai <dtaipublic@gmail.com>

* test(provider): isolate diagnostics and preserve launchd removal checks

Adapt the consolidated lifecycle suite to confirmed launchd removal, supply synthetic report diagnostics, and characterize weighted coverage summaries. Document the combined test groups and safe local coverage workflow. The independent refactor pass preserves all source-stack test objectives.

* docs: prepare required fixtures in provider coverage recipe

---------

Co-authored-by: Gajesh Naik <26431906+Gajesh2007@users.noreply.github.com>

This branch was successfully deployed

No deployments
benchmarks — f1e1748e Deployed Oct 5, 2026 by davidtai via E2E Benchmarks #2251
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants