diff --git a/.github/workflows/pr-ci.yml b/.github/workflows/pr-ci.yml index 4c5c026158..339c3fd0c8 100644 --- a/.github/workflows/pr-ci.yml +++ b/.github/workflows/pr-ci.yml @@ -428,6 +428,9 @@ jobs: - label: up-provider-microsandbox-registry-consumer expected-spec-count: 3 provider-mode: external + - label: up-provider-microsandbox-remote-agent-binaries + expected-spec-count: 1 + provider-mode: external runs-on: ubuntu-latest timeout-minutes: 25 steps: diff --git a/e2e/tests/up/MICROSANDBOX.md b/e2e/tests/up/MICROSANDBOX.md index 7600bd72d3..01b4809e7c 100644 --- a/e2e/tests/up/MICROSANDBOX.md +++ b/e2e/tests/up/MICROSANDBOX.md @@ -85,6 +85,31 @@ Its `TestMain` preserves the production runtime-supervisor dispatch and recogniz the helper only at its canonical, current-user-owned private path. Other test invocations retain the normal test runner path. +## Remote agent binary delivery + +The Linux-only `up-provider-microsandbox-remote-agent-binaries` row uses the +published external provider with `agent.local: false` and a fresh, test-owned +agent container. Separate endpoint counters prove a Devsy agent executable +transfer and exactly one runtime download through `Agent.Binaries`. The runtime +is checked against the published manifest and the workspace copy's checksum, +executable mode and inode. + +Container preflight requires KVM access, Docker connectivity, curl and a +populated system CA store for ordinary HTTPS image metadata resolution. + +After the first successful `up`, the case removes only the private agent's +provider-download cache and makes the runtime endpoint return 404. Stop/start +must retain the workspace binary's checksum and inode without another runtime +GET, and guest commands must succeed before and after restart. The separate +Devsy agent endpoint stays available; this is workspace-runtime reuse, not an +offline-agent executable guarantee. Workspace, container and server cleanup +have independent bounded attempts. + +This external-only row brings the configured catalogue to 15 suites/78 cases +(37 built-in, 41 external). Earlier 77-case consumer reports do not prove the +remote-agent case. Its native Linux/amd64 KVM report must pass once without +selected skips; source checks, fixture unit tests and dry runs cannot prove it. + ## Runtime startup measurements The existing two-case lifecycle label optionally captures its ordinary fresh diff --git a/e2e/tests/up/provider_microsandbox_remote_agent_linux.go b/e2e/tests/up/provider_microsandbox_remote_agent_linux.go new file mode 100644 index 0000000000..05e0f4dcb4 --- /dev/null +++ b/e2e/tests/up/provider_microsandbox_remote_agent_linux.go @@ -0,0 +1,503 @@ +//go:build linux + +package up + +import ( + "context" + "errors" + "fmt" + "net" + "net/http" + "os" + "os/exec" + "path/filepath" + "runtime" + "strings" + "sync/atomic" + "time" + + "al.essio.dev/pkg/shellescape" + "github.com/devsy-org/devsy/e2e/framework" + "github.com/devsy-org/devsy/pkg/config" + "github.com/devsy-org/devsy/pkg/provider" + "github.com/devsy-org/devsy/pkg/types" + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" + "sigs.k8s.io/yaml" +) + +type remoteAgentArtifactServer struct { + server *http.Server + listener net.Listener + done chan error + runtimeRequests atomic.Int32 + agentRequests atomic.Int32 + offline atomic.Bool + runtime []byte + agent []byte +} + +const ( + remoteAgentDockerRunFlag = "run" + remoteAgentDockerMountFlag = "--mount" + remoteAgentDockerEnvFlag = "--env" +) + +var _ = ginkgo.Describe("published MicroSandbox provider remote agent binaries", + ginkgo.Label("up-provider-microsandbox-remote-agent-binaries", "microsandbox-external"), + func() { + ginkgo.It( + "downloads the external runtime on the remote agent and reuses its workspace copy", + func(ctx ginkgo.SpecContext) { + session := newMicrosandboxTestSession(ctx) + framework.ExpectNoError(requireRemoteAgentHostPrerequisites()) + + providerName := "case-a-remote-agent" + stageProviderName := "case-a-remote-stage" + session.addProvider(ctx, microsandboxExternalProvider, stageProviderName) + staged := prepareMicrosandboxConsumerProvider(ctx, stageProviderName) + runtimeBytes, err := os.ReadFile(staged.runtimeBinary) + framework.ExpectNoError(err) + runtimeRelativePath, err := remoteAgentRuntimeRelativePath(staged) + framework.ExpectNoError(err) + descriptor, err := provider.LoadProviderConfig( + config.DefaultContext, + stageProviderName, + ) + framework.ExpectNoError(err) + + containerName := "devsy-" + microsandboxConsumerID("agent") + agentHome := filepath.Join( + "/tmp/devsy-remote-agent-fixture", + microsandboxConsumerID("home"), + "agent", + ) + bundleRoot, err := remoteAgentBundleRoot() + framework.ExpectNoError(err) + dockerPath, err := exec.LookPath("docker") + framework.ExpectNoError(err) + dockerPath, err = filepath.Abs(dockerPath) + framework.ExpectNoError(err) + preflightRemoteAgentContainer(ctx, bundleRoot, dockerPath, filepath.Dir(agentHome)) + + binaryName := descriptor.Agent.External.Binary + checksums := descriptor.Agent.Binaries[binaryName] + binaryEntry := remoteAgentLinuxBinary(checksums) + descriptorHash := strings.TrimPrefix( + strings.ToLower(binaryEntry.Checksum), + "sha256:", + ) + gomega.Expect(descriptorHash).To(gomega.Equal(staged.runtimeHash)) + agentPath := filepath.Join( + session.framework.DevsyBinDir, + session.framework.DevsyBinName, + ) + server := startRemoteAgentArtifactServer(runtimeBytes, agentPath) + ginkgo.DeferCleanup(func(cleanupCtx ginkgo.SpecContext) error { + closeCtx, cancel := context.WithTimeout( + context.WithoutCancel(cleanupCtx), 10*time.Second, + ) + defer cancel() + return server.close(closeCtx) + }) + + descriptor.Name = providerName + descriptor.Agent.Local = types.StrBool("false") + descriptor.Agent.DataPath = agentHome + descriptor.Agent.DownloadURL = server.agentURL() + binaryEntry.Path = server.runtimeURL() + descriptor.Agent.Binaries[binaryName] = checksums + descriptor.Exec = remoteAgentCommands( + containerName, + bundleRoot, + dockerPath, + agentHome, + ) + configPath := filepath.Join(ginkgo.GinkgoT().TempDir(), "provider.yaml") + configBytes, err := yaml.Marshal(descriptor) + framework.ExpectNoError(err) + framework.ExpectNoError(os.WriteFile(configPath, configBytes, 0o600)) + session.addProvider(ctx, configPath, providerName) + framework.ExpectNoError(session.framework.DevsyProviderUse(ctx, providerName)) + + workspace := session.newWorkspace() + ginkgo.DeferCleanup(func(cleanupCtx ginkgo.SpecContext) error { + boundedCtx, cancel := context.WithTimeout( + context.WithoutCancel(cleanupCtx), 20*time.Second, + ) + defer cancel() + return removeRemoteAgentContainer(boundedCtx, containerName) + }) + ginkgo.DeferCleanup(session.framework.CleanupWorkspace, workspace) + framework.ExpectNoError(session.framework.DevsyUp(ctx, workspace)) + gomega.Expect(server.runtimeRequests.Load()).To(gomega.Equal(int32(1)), + "remote agent must fetch the published provider binary exactly once") + gomega.Expect(server.agentRequests.Load()).To(gomega.BeNumerically(">", 0), + "remote agent must fetch its agent binary from the fixture endpoint") + workspaceRecord, err := session.framework.FindWorkspace(ctx, workspace) + framework.ExpectNoError(err) + remoteBinaryPath := filepath.Join( + agentHome, "contexts", config.DefaultContext, "workspaces", workspaceRecord.ID, + "binaries", runtimeRelativePath, + ) + firstBinary := assertRemoteAgentBinary( + ctx, containerName, remoteBinaryPath, staged.runtimeHash, + ) + assertRemoteAgentGuest(ctx, session.framework, workspace) + + clearRemoteAgentBinaryCache(ctx, containerName, filepath.Dir(agentHome)) + framework.ExpectNoError(session.framework.DevsyStop(ctx, workspace)) + server.offline.Store(true) + framework.ExpectNoError(session.framework.DevsyUp(ctx, workspace)) + gomega.Expect(server.runtimeRequests.Load()).To(gomega.Equal(int32(1)), + "existing workspace binary must be reused when its source returns 404") + secondBinary := assertRemoteAgentBinary( + ctx, containerName, remoteBinaryPath, staged.runtimeHash, + ) + gomega.Expect(secondBinary).To( + gomega.Equal(firstBinary), + "workspace binary identity must survive stop and restart", + ) + assertRemoteAgentGuest(ctx, session.framework, workspace) + }, ginkgo.SpecTimeout(framework.TimeoutLong()), + ) + }, +) + +func remoteAgentRuntimeRelativePath(staged microsandboxConsumerProvider) (string, error) { + binaryRoot := filepath.Join(staged.origin, "binaries") + relative, err := filepath.Rel(binaryRoot, staged.runtimeBinary) + if err != nil { + return "", fmt.Errorf("resolve staged provider binary path: %w", err) + } + if relative == "." || filepath.IsAbs(relative) || relative == ".." || + strings.HasPrefix(relative, ".."+string(filepath.Separator)) { + return "", fmt.Errorf( + "staged provider binary path escapes its binaries directory: %q", relative, + ) + } + return relative, nil +} + +func remoteAgentLinuxBinary(entries []*provider.ProviderBinary) *provider.ProviderBinary { + for _, entry := range entries { + if entry.OS == runtime.GOOS && entry.Arch == runtime.GOARCH { + return entry + } + } + ginkgo.Fail("published MicroSandbox descriptor has no Linux/amd64 runtime binary") + return nil +} + +func startRemoteAgentArtifactServer( + runtimeBinary []byte, + agentPath string, +) *remoteAgentArtifactServer { + // #nosec G304 -- agentPath is built from Framework.DevsyBinDir and its configured binary name. + agentBinary, err := os.ReadFile(agentPath) + framework.ExpectNoError(err) + // #nosec G102 -- Docker bridge containers need the ephemeral host port; cleanup closes this test server. + listener, err := net.Listen("tcp", "0.0.0.0:0") + framework.ExpectNoError(err) + server := &remoteAgentArtifactServer{ + listener: listener, runtime: runtimeBinary, done: make(chan error, 1), + } + server.agent = agentBinary + server.server = &http.Server{ + Handler: server.artifactHandler(), + ReadHeaderTimeout: 5 * time.Second, + ReadTimeout: 15 * time.Second, + WriteTimeout: 3 * time.Minute, + IdleTimeout: 30 * time.Second, + } + go func() { server.done <- server.server.Serve(listener) }() + return server +} + +func (s *remoteAgentArtifactServer) artifactHandler() http.Handler { + mux := http.NewServeMux() + mux.HandleFunc("/agent/devsy-linux-amd64", s.serveAgent) + mux.HandleFunc("/provider/runtime", s.serveRuntime) + return mux +} + +func (s *remoteAgentArtifactServer) serveAgent(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodGet { + http.Error(w, "method not allowed", http.StatusMethodNotAllowed) + return + } + s.agentRequests.Add(1) + _, _ = w.Write(s.agent) +} + +func (s *remoteAgentArtifactServer) serveRuntime(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodGet { + http.Error(w, "method not allowed", http.StatusMethodNotAllowed) + return + } + s.runtimeRequests.Add(1) + if s.offline.Load() { + http.NotFound(w, r) + return + } + _, _ = w.Write(s.runtime) +} + +func (s *remoteAgentArtifactServer) baseURL() string { + address, err := remoteAgentArtifactBaseURL(s.listener.Addr().String()) + framework.ExpectNoError(err) + return address +} + +func remoteAgentArtifactBaseURL(address string) (string, error) { + _, port, err := net.SplitHostPort(address) + if err != nil { + return "", fmt.Errorf("parse remote agent artifact listener: %w", err) + } + return "http://" + net.JoinHostPort("host.docker.internal", port), nil +} + +func (s *remoteAgentArtifactServer) runtimeURL() string { return s.baseURL() + "/provider/runtime" } +func (s *remoteAgentArtifactServer) agentURL() string { return s.baseURL() + "/agent" } + +func (s *remoteAgentArtifactServer) close(ctx context.Context) error { + shutdownErr := s.server.Shutdown(ctx) + closeErr := s.server.Close() + select { + case serveErr := <-s.done: + if errors.Is(serveErr, http.ErrServerClosed) { + serveErr = nil + } + return errors.Join(shutdownErr, closeErr, serveErr) + case <-ctx.Done(): + return errors.Join(shutdownErr, closeErr, ctx.Err()) + } +} + +func remoteAgentCommands( + containerName, bundleRoot, dockerPath, agentHome string, +) provider.ProviderCommands { + devsyHome := filepath.Dir(agentHome) + create := remoteAgentContainerCreateCommand(containerName, bundleRoot, dockerPath, devsyHome) + return provider.ProviderCommands{ + Create: types.StrArray{ + create, + }, + Command: types.StrArray{ + fmt.Sprintf("docker exec -i %s sh -c \"${COMMAND}\"", containerName), + }, + Stop: types.StrArray{ + "docker stop " + shellescape.Quote(containerName), + }, + Start: types.StrArray{ + "docker start " + shellescape.Quote(containerName), + }, + Status: types.StrArray{ + fmt.Sprintf( + `state=$(docker inspect -f '{{.State.Status}}' %s 2>/dev/null) || { echo NOTFOUND; exit 0; } +case "$state" in + running) echo RUNNING ;; + exited) echo STOPPED ;; + *) echo BUSY ;; +esac`, + containerName, + ), + }, + Delete: types.StrArray{ + "docker rm -f " + shellescape.Quote(containerName), + }, + } +} + +const ( + remoteAgentContainerImage = "ubuntu:24.04" + remoteAgentContainerInit = `apt-get update && +apt-get install -y --no-install-recommends ca-certificates curl && +rm -rf /var/lib/apt/lists/* && +touch /tmp/devsy-agent-ready && +sleep infinity` + remoteAgentContainerReady = `test -e /tmp/devsy-agent-ready && +test "$(uname -s)" = Linux && +test "$(uname -m)" = x86_64 && +grep -Eq '^(ID=ubuntu|ID=debian)$' /etc/os-release && +test -c /dev/kvm && +test -r /dev/kvm && +test -w /dev/kvm && +command -v curl >/dev/null && +test -s /etc/ssl/certs/ca-certificates.crt && +/opt/devsy-microsandbox/bin/msb --version && +/usr/local/bin/docker version >/dev/null` +) + +func remoteAgentContainerArgs(name, bundleRoot, dockerPath, devsyHome string) []string { + return []string{ + remoteAgentDockerRunFlag, + "-d", + "--name", + name, + "--add-host=host.docker.internal:host-gateway", + "--device=/dev/kvm:/dev/kvm", + remoteAgentDockerMountFlag, + "type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock", + remoteAgentDockerMountFlag, + "type=bind,src=" + bundleRoot + ",dst=/opt/devsy-microsandbox,readonly", + remoteAgentDockerMountFlag, + "type=bind,src=" + dockerPath + ",dst=/usr/local/bin/docker,readonly", + remoteAgentDockerEnvFlag, + "HOME=/root", + remoteAgentDockerEnvFlag, + "DEVSY_HOME=" + devsyHome, + remoteAgentDockerEnvFlag, + "PATH=/opt/devsy-microsandbox/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", + remoteAgentDockerEnvFlag, + "LD_LIBRARY_PATH=/opt/devsy-microsandbox/lib", + remoteAgentContainerImage, + "sh", + "-c", + remoteAgentContainerInit, + } +} + +func remoteAgentContainerCreateCommand(name, bundleRoot, dockerPath, devsyHome string) string { + args := remoteAgentContainerArgs(name, bundleRoot, dockerPath, devsyHome) + quotedArgs := make([]string, len(args)) + for i, arg := range args { + quotedArgs[i] = shellescape.Quote(arg) + } + waitForSetup := fmt.Sprintf(`i=0 +while [ "$i" -lt 180 ]; do + if docker exec %s test -e /tmp/devsy-agent-ready; then break; fi + i=$((i + 1)) + sleep 1 +done`, shellescape.Quote(name)) + checkReady := "docker exec " + shellescape.Quote(name) + + " sh -c " + shellescape.Quote(remoteAgentContainerReady) + return strings.Join([]string{ + "docker " + strings.Join(quotedArgs, " "), + "&& { " + waitForSetup + "; }", + "&& " + checkReady, + }, " ") +} + +func requireRemoteAgentHostPrerequisites() error { + if runtime.GOOS != osLinux || runtime.GOARCH != "amd64" { + return fmt.Errorf("remote MicroSandbox agent proof requires Linux/amd64") + } + if _, err := os.Stat("/dev/kvm"); err != nil { + return fmt.Errorf("remote MicroSandbox agent proof requires host /dev/kvm: %w", err) + } + if _, err := os.Stat("/var/run/docker.sock"); err != nil { + return fmt.Errorf("remote MicroSandbox agent proof requires Docker socket: %w", err) + } + if _, err := exec.LookPath("docker"); err != nil { + return err + } + return nil +} + +func remoteAgentBundleRoot() (string, error) { + msb, err := exec.LookPath("msb") + if err != nil { + return "", err + } + resolved, err := filepath.EvalSymlinks(msb) + if err != nil { + return "", err + } + if filepath.Base(filepath.Dir(resolved)) != "bin" || + filepath.Base(filepath.Dir(filepath.Dir(resolved))) != ".microsandbox" { + return "", fmt.Errorf("msb is not in the pinned .microsandbox bundle: %s", resolved) + } + return filepath.Dir(filepath.Dir(resolved)), nil +} + +func preflightRemoteAgentContainer(ctx context.Context, bundleRoot, dockerPath, devsyHome string) { + name := "devsy-agent-preflight-" + microsandboxConsumerID("container") + defer func() { + cleanupCtx, cancel := context.WithTimeout(context.Background(), 15*time.Second) + defer cancel() + if err := removeRemoteAgentContainer(cleanupCtx, name); err != nil { + ginkgo.Fail("remove remote agent preflight container: " + err.Error()) + } + }() + cmdCtx, cancel := context.WithTimeout(ctx, 4*time.Minute) + defer cancel() + args := remoteAgentContainerArgs(name, bundleRoot, dockerPath, devsyHome) + // #nosec G204 -- args are fixed by the builder and use test-owned paths. + output, err := exec.CommandContext(cmdCtx, "docker", args...).CombinedOutput() + framework.ExpectNoError(err, string(output)) + framework.ExpectNoError(waitRemoteAgentContainer(cmdCtx, dockerPath, name)) + // #nosec G204 -- script is fixed and name is a generated fixture nonce. + preflightOutput, err := exec.CommandContext( + cmdCtx, "docker", "exec", name, "sh", "-c", remoteAgentContainerReady, + ).CombinedOutput() + framework.ExpectNoError(err, "remote agent container prerequisites: "+string(preflightOutput)) +} + +func waitRemoteAgentContainer(ctx context.Context, dockerPath, name string) error { + ticker := time.NewTicker(time.Second) + defer ticker.Stop() + for { + // #nosec G204 -- dockerPath is from exec.LookPath; arguments are fixed or nonce-generated. + cmd := exec.CommandContext( + ctx, dockerPath, "exec", name, "test", "-e", "/tmp/devsy-agent-ready", + ) + if err := cmd.Run(); err == nil { + return nil + } + select { + case <-ctx.Done(): + return fmt.Errorf("wait for remote agent container setup: %w", ctx.Err()) + case <-ticker.C: + } + } +} + +func removeRemoteAgentContainer(ctx context.Context, name string) error { + // #nosec G204 -- docker is fixed; name is a nonce generated within this test. + cmd := exec.CommandContext(ctx, "docker", "rm", "-f", name) + output, err := cmd.CombinedOutput() + if err != nil && !strings.Contains(string(output), "No such container") { + return fmt.Errorf("remove remote agent container: %w: %s", err, output) + } + return nil +} + +func assertRemoteAgentBinary(ctx context.Context, containerName, path, expectedHash string) string { + command := fmt.Sprintf( + "test -x %s && stat -c '%%a %%i' %s && sha256sum %s", + shellescape.Quote(path), shellescape.Quote(path), shellescape.Quote(path), + ) + cmdCtx, cancel := context.WithTimeout(ctx, 15*time.Second) + defer cancel() + // #nosec G204 -- docker is fixed and command uses shell-quoted test-owned paths. + output, err := exec.CommandContext( + cmdCtx, "docker", "exec", containerName, "sh", "-c", command, + ).CombinedOutput() + framework.ExpectNoError(err, string(output)) + fields := strings.Fields(string(output)) + gomega.Expect(fields).To(gomega.HaveLen(4)) + gomega.Expect(fields[0]).To(gomega.Equal("755")) + gomega.Expect(fields[2]).To(gomega.Equal(expectedHash)) + return fields[1] +} + +func clearRemoteAgentBinaryCache(ctx context.Context, containerName, devsyHome string) { + cmdCtx, cancel := context.WithTimeout(ctx, 15*time.Second) + defer cancel() + cacheDir := filepath.Join(devsyHome, "cache", "providers") + command := "rm -rf " + shellescape.Quote(cacheDir) + + " && test ! -e " + shellescape.Quote(cacheDir) + // #nosec G204 -- command removes only the nonce-scoped private provider cache. + output, err := exec.CommandContext( + cmdCtx, "docker", "exec", containerName, "sh", "-c", command, + ).CombinedOutput() + framework.ExpectNoError(err, string(output)) +} + +func assertRemoteAgentGuest(ctx context.Context, f *framework.Framework, workspace string) { + marker := "remote-agent-" + microsandboxConsumerID("guest") + out, err := f.DevsySSHOnce(ctx, workspace, "printf %s "+shellescape.Quote(marker)) + framework.ExpectNoError(err) + gomega.Expect(strings.TrimSpace(out)).To(gomega.Equal(marker)) +} diff --git a/e2e/tests/up/provider_microsandbox_remote_agent_linux_test.go b/e2e/tests/up/provider_microsandbox_remote_agent_linux_test.go new file mode 100644 index 0000000000..36e45c37f1 --- /dev/null +++ b/e2e/tests/up/provider_microsandbox_remote_agent_linux_test.go @@ -0,0 +1,114 @@ +//go:build linux + +package up + +import ( + "bytes" + "net/http" + "net/http/httptest" + "testing" +) + +const ( + runtimeEndpointPath = "/provider/runtime" + agentEndpointPath = "/agent/devsy-linux-amd64" +) + +func TestRemoteAgentArtifactBaseURLUsesListenerPort(t *testing.T) { + for _, address := range []string{"0.0.0.0:35437", "[::]:35437", "127.0.0.1:35437", "[::1]:35437"} { + t.Run(address, func(t *testing.T) { + got, err := remoteAgentArtifactBaseURL(address) + if err != nil { + t.Fatal(err) + } + if want := "http://host.docker.internal:35437"; got != want { + t.Fatalf("artifact base URL = %q, want %q", got, want) + } + }) + } +} + +func TestRemoteAgentArtifactBaseURLRejectsInvalidAddress(t *testing.T) { + if _, err := remoteAgentArtifactBaseURL("missing-port"); err == nil { + t.Fatal("expected an invalid listener address error") + } +} + +func TestRemoteAgentArtifactEndpointsTrackIndependentGETs(t *testing.T) { + server := &remoteAgentArtifactServer{ + runtime: []byte("runtime binary"), + agent: []byte("agent binary"), + } + handler := server.artifactHandler() + + assertArtifactResponse(t, handler, artifactResponseExpectation{ + method: http.MethodGet, + path: runtimeEndpointPath, + status: http.StatusOK, + body: server.runtime, + }) + assertArtifactResponse(t, handler, artifactResponseExpectation{ + method: http.MethodGet, path: agentEndpointPath, status: http.StatusOK, body: server.agent, + }) + + if got := server.runtimeRequests.Load(); got != 1 { + t.Fatalf("runtime GET count = %d, want 1", got) + } + if got := server.agentRequests.Load(); got != 1 { + t.Fatalf("agent GET count = %d, want 1", got) + } +} + +func TestRemoteAgentArtifactEndpointMethodsAndOfflineRuntime(t *testing.T) { + server := &remoteAgentArtifactServer{ + runtime: []byte("runtime binary"), + agent: []byte("agent binary"), + } + handler := server.artifactHandler() + server.offline.Store(true) + + assertArtifactResponse(t, handler, artifactResponseExpectation{ + method: http.MethodGet, path: runtimeEndpointPath, status: http.StatusNotFound, + }) + assertArtifactResponse(t, handler, artifactResponseExpectation{ + method: http.MethodGet, path: agentEndpointPath, status: http.StatusOK, body: server.agent, + }) + assertArtifactResponse(t, handler, artifactResponseExpectation{ + method: http.MethodPost, path: runtimeEndpointPath, status: http.StatusMethodNotAllowed, + }) + assertArtifactResponse(t, handler, artifactResponseExpectation{ + method: http.MethodPost, path: agentEndpointPath, status: http.StatusMethodNotAllowed, + }) + + if got := server.runtimeRequests.Load(); got != 1 { + t.Fatalf("runtime GET count = %d, want the offline GET only", got) + } + if got := server.agentRequests.Load(); got != 1 { + t.Fatalf("agent GET count = %d, want the successful GET only", got) + } +} + +type artifactResponseExpectation struct { + method, path string + status int + body []byte +} + +func assertArtifactResponse(t *testing.T, handler http.Handler, want artifactResponseExpectation) { + t.Helper() + request := httptest.NewRequest(want.method, want.path, nil) + response := httptest.NewRecorder() + handler.ServeHTTP(response, request) + if response.Code != want.status { + t.Fatalf("%s %s status = %d, want %d", want.method, want.path, response.Code, want.status) + } + if want.body != nil && !bytes.Equal(response.Body.Bytes(), want.body) { + t.Fatalf( + "%s %s body = %q, want %q", + want.method, + want.path, + response.Body.Bytes(), + want.body, + ) + } +} diff --git a/sites/docs-devsy-sh/content/docs/developing-providers/runtime-protocol.mdx b/sites/docs-devsy-sh/content/docs/developing-providers/runtime-protocol.mdx index 8c4f6873cb..a479fed6d8 100644 --- a/sites/docs-devsy-sh/content/docs/developing-providers/runtime-protocol.mdx +++ b/sites/docs-devsy-sh/content/docs/developing-providers/runtime-protocol.mdx @@ -169,6 +169,12 @@ The Linux-only `up-provider-microsandbox-registry-consumer` label selects exactl DEVSY_REQUIRE_MICROSANDBOX=true task cli:test:e2e:suite -- up-provider-microsandbox-registry-consumer ``` +The Linux-only `up-provider-microsandbox-remote-agent-binaries` label uses the published external provider with `agent.local: false` and a test-owned remote agent container. It separately counts the Devsy agent executable transfer and the runtime binary download through `Agent.Binaries`. After the first successful `up`, it removes only the agent's provider-download cache, makes the runtime source return 404, and requires a later `up` to reuse the retained workspace binary with unchanged checksum and inode. A guest command verifies the workspace remains usable. The Devsy agent endpoint remains available; this does not promise offline reuse of that separate executable or ordinary `up` image metadata resolution. This added one-case external-only row brings the configured catalogue to 78 cases; earlier 77-case reports do not prove it. Acceptance requires current-head native Linux/KVM reports, not documentation or registration alone. + +```sh +DEVSY_REQUIRE_MICROSANDBOX=true task cli:test:e2e:suite -- up-provider-microsandbox-remote-agent-binaries +``` + For the existing two-case lifecycle label, the external-provider case can capture ordinary fresh and reused `up` wall time and filtered runtime startup events when CI supplies all five explicit inputs: `DEVSY_TEST_RUNTIME_SPAWN_PROBE`, `DEVSY_TEST_RUNTIME_SUPERVISOR`, `DEVSY_TEST_RUNTIME_PERFORMANCE_DIR`, `DEVSY_TEST_RUNTIME_REVISION`, and `DEVSY_TEST_RUNTIME_SDK_VERSION`. The built-in case keeps its existing path. After both ordinary commands pass, the helper stages a checksum-verified copy of the published runtime and runs direct/supervised/supervised/direct Info/Find comparisons, each with a first launch and 100 warm samples. The JSON artifact records tool/runtime provenance and reaped processes. Startup events measure launch, handshake and dispense before RPC; they exclude binary resolution, RPC and reaping. These measurements use warm host caches, add no latency threshold or VM case, and do not claim cold-cache performance or total plugin overhead. These scenarios do not establish complete parity. Compatibility shims verify preservation under injected version faults but do not establish behavior against an actual historical MicroSandbox release. Green lifecycle, image, mount, resource, persistent-storage, ephemeral-root, TCP-egress, prebuild, Dockerless, request-invalid and managed-policy recreation, logs, and cancellation checks alone do not authorize that cutover. Dockerless refusal checks cover fresh creation, not preservation after an invalid recreation request. Egress coverage does not establish UDP, DNS, TLS, ingress, or live-policy modification behavior.