Multiplayer agent harness for work.
Default porter deploys to private and make the egress pin sticky
Josh France1d1bc42fcd35
diff --git a/src/deploy/porter-deploy-provider.ts b/src/deploy/porter-deploy-provider.tsindex cef7564d2..ccef57fcd 100644--- a/src/deploy/porter-deploy-provider.ts+++ b/src/deploy/porter-deploy-provider.ts@@ -65,7 +65,7 @@ export interface PorterDeployProviderOptions {export function createPorterDeployProvider(opts: PorterDeployProviderOptions): DeployProvider {const appsDomain = opts.appsDomain;const image = opts.runnerImage ?? DEFAULT_RUNNER_IMAGE;- const visibility = opts.visibility ?? "public";+ const visibility = opts.visibility ?? "private";const prefix = opts.namePrefix ?? "qm";const appPort = opts.appPort ?? APP_PORT_DEFAULT;const readyWindowSec = opts.readyWindowSec ?? APP_READY_WINDOW_SEC_DEFAULT;diff --git a/src/sandbox/porter-sandbox.ts b/src/sandbox/porter-sandbox.tsindex f9355346a..fbf298eef 100644--- a/src/sandbox/porter-sandbox.ts+++ b/src/sandbox/porter-sandbox.ts@@ -177,7 +177,7 @@ export function createPorterSandbox(workspace: WorkspaceStore, opts: PorterSandbif (existing) {const wantProxy = egressMode === "proxy";const hasProxy = existing.sb.tags?.[EGRESS_TAG] === "proxy";- if (wantProxy === hasProxy) {+ if (!wantProxy || hasProxy) {scopeByBody.set(existing.name, scope);return { name: existing.name, coldStart: false };}diff --git a/test/porter-deploy-provider.test.ts b/test/porter-deploy-provider.test.tsindex 0287e452d..3d5bf4146 100644--- a/test/porter-deploy-provider.test.ts+++ b/test/porter-deploy-provider.test.ts@@ -67,7 +67,7 @@ const freeListener = (): void => {if (appPort) spawnSync("sh", ["-c", `lsof -ti tcp:${appPort} -sTCP:LISTEN | xargs kill 2>/dev/null; true`]);};-function make(extra: { terminateLag?: number; resolveCacheMs?: number } = {}): void {+function make(extra: { terminateLag?: number; resolveCacheMs?: number; visibility?: "public" | "private" } = {}): void {fake?.cleanup();fake = installFakePorter(extra.terminateLag ? { terminateLag: extra.terminateLag } : {});store = createMemoryMap<StoredPorterDeployBody>();@@ -77,6 +77,7 @@ function make(extra: { terminateLag?: number; resolveCacheMs?: number } = {}): vappPort,readyWindowSec: 10,resolveCacheMs: extra.resolveCacheMs ?? 0,+ ...(extra.visibility ? { visibility: extra.visibility } : {}),client: fake.client,store,});@@ -102,7 +103,7 @@ test("apply serves the app on a stable public domain", async () => {const body = fake.bodies()[0]!;assert.equal(body.phase, "running");assert.deepEqual(body.networking, [- { port: appPort, domains: [{ domain: "myapp.apps.test", visibility: "public" }] },+ { port: appPort, domains: [{ domain: "myapp.apps.test", visibility: "private" }] },]);assert.equal(body.tags["qm-deploy"], "dep-1");assert.equal(body.env?.APP_VERSION, "1");@@ -113,6 +114,14 @@ test("apply serves the app on a stable public domain", async () => {assert.equal(provider.profile.managedScaleToZero, false);});+test("explicit public visibility opts the domain out of the private default", async () => {+ make({ visibility: "public" });+ await provider.apply(deployment("dep-1b", "shown"), version({ "server.js": SERVER }, "node server.js"));+ assert.deepEqual(fake.bodies()[0]!.networking, [+ { port: appPort, domains: [{ domain: "shown.apps.test", visibility: "public" }] },+ ]);+});+test("redeploy keeps the domain and the /data volume and retires the old body", async () => {const d = deployment("dep-2", "keeper");await provider.apply(d, version({ "server.js": SERVER }, "node server.js", { env: { APP_VERSION: "1" } }));diff --git a/test/porter-sandbox.test.ts b/test/porter-sandbox.test.tsindex 2350cca96..4856405dc 100644--- a/test/porter-sandbox.test.ts+++ b/test/porter-sandbox.test.ts@@ -78,7 +78,7 @@ test("volume survives body replacement and coldStart stays false", async () => {assert.equal(await fresh.readFile(h2, "kept.txt"), "still here\n");});-test("egress proxy mode pins allowlist and injects proxy env; mode change rotates the body", async () => {+test("egress proxy mode pins allowlist and injects proxy env; the pin is sticky", async () => {const proxied = make({ egressProxyUrl: "https://egress.qm.internal:48080" });const h = await proxied.provision(layers, { egressToken: "tok-1" });assert.match(h.env?.HTTPS_PROXY ?? "", /x:tok-1@egress\.qm\.internal/);@@ -87,12 +87,25 @@ test("egress proxy mode pins allowlist and injects proxy env; mode change rotateassert.deepEqual(withEgress[0]!.egress, ["egress.qm.internal"]);assert.equal(withEgress[0]!.tags["qm-egress"], "proxy");const h2 = await proxied.provision(layers);- assert.notEqual(h2.id, h.id);+ assert.equal(h2.id, h.id);assert.equal(h2.env, undefined);+ const still = fake.bodies().filter((b) => b.phase === "running" && b.tags["qm-scope"] === slug);+ assert.equal(still.length, 1);+ assert.equal(still[0]!.tags["qm-egress"], "proxy");+});++test("a tokened turn on an open body rotates it into the proxy pin", async () => {+ const proxied = make({ egressProxyUrl: "https://egress.qm.internal:48080" });+ const h = await proxied.provision(layers);+ assert.equal(h.env, undefined);const open = fake.bodies().filter((b) => b.phase === "running" && b.tags["qm-scope"] === slug);- assert.equal(open.length, 1);assert.equal(open[0]!.tags["qm-egress"], "open");- assert.equal(open[0]!.egress, undefined);+ const h2 = await proxied.provision(layers, { egressToken: "tok-2" });+ assert.notEqual(h2.id, h.id);+ assert.match(h2.env?.HTTPS_PROXY ?? "", /x:tok-2@egress\.qm\.internal/);+ const pinned = fake.bodies().filter((b) => b.phase === "running" && b.tags["qm-scope"] === slug);+ assert.equal(pinned.length, 1);+ assert.equal(pinned[0]!.tags["qm-egress"], "proxy");});test("process sessions capability works end to end", async () => {