| | @@ -25,6 +25,8 @@ |
| 25 | 25 | const AGENT = resolve(APP, "../../containers/runner/dist/agent.mjs"); |
| 26 | 26 | const work = mkdtempSync(join(tmpdir(), "diffinery-e2e-")); |
| 27 | 27 | let base; |
| 28 | +/** The shared server's Worker itself, behind wrangler dev's proxy (see startServer). */ |
| 29 | +let direct; |
| 28 | 30 | // The dev server writes to a file, not a pipe: a long synchronous git command keeps this process |
| 29 | 31 | // from reading a pipe, and a full one (retried webhooks log a stack each) stalls the server mid-push. |
| 30 | 32 | const devLogFile = join(work, "wrangler.log"); |
| | @@ -183,6 +185,7 @@ |
| 183 | 185 | const url = `http://127.0.0.1:${port}`; |
| 184 | 186 | const persist = join(work, name ? `state-${name}` : "state"); |
| 185 | 187 | const logFile = name ? join(work, `wrangler-${name}.log`) : devLogFile; |
| 188 | + const debugLogFile = join(work, name ? `wrangler-debug-${name}.log` : "wrangler-debug.log"); |
| 186 | 189 | const log = () => (existsSync(logFile) ? readFileSync(logFile, "utf8") : ""); |
| 187 | 190 | migratedState(APP, persist); |
| 188 | 191 | // Until the web UI exists, run the same app through the API-only entry. |
| | @@ -190,7 +193,7 @@ |
| 190 | 193 | const out = openSync(logFile, "a"); |
| 191 | 194 | const child = spawn("pnpm", ["exec", "wrangler", "dev", ...entry, "-e", "dev", "--ip", "127.0.0.1", "--port", String(port), "--inspector-port", String(await freePort()), "--persist-to", persist, "--var", `PUBLIC_URL:${url}`, "--var", `MASTER_KEY:${randomBytes(32).toString("base64")}`, "--var", "SCHEDULE_TICK_MINUTES:1", "--show-interactive-dev-session=false"], { |
| 192 | 195 | cwd: APP, |
| 193 | | - env: { ...process.env, CI: "1", WRANGLER_SEND_METRICS: "false" }, |
| 196 | + env: { ...process.env, CI: "1", WRANGLER_SEND_METRICS: "false", WRANGLER_LOG_PATH: debugLogFile }, |
| 194 | 197 | stdio: ["ignore", out, out], |
| 195 | 198 | detached: true, |
| 196 | 199 | }); |
| | @@ -208,12 +211,24 @@ |
| 208 | 211 | process.kill(-child.pid, "SIGTERM"); |
| 209 | 212 | } catch {} |
| 210 | 213 | }; |
| 211 | | - return { base: url, token: (await res.json()).token, log, stop }; |
| 214 | + return { base: url, direct: workerUrl(debugLogFile), token: (await res.json()).token, log, stop }; |
| 212 | 215 | } |
| 213 | 216 | |
| 217 | +/** |
| 218 | + * wrangler dev answers on `base` through a proxy Worker of its own, which drops one of several large |
| 219 | + * pushes streaming through it at once ("Error inside ProxyWorker ... Network connection lost": the |
| 220 | + * push never reaches our Worker; 3 of 5 runs of three pushes, none of 5 sent to the Worker itself). |
| 221 | + * Its debug log names the Worker's own address; null if it doesn't. |
| 222 | + */ |
| 223 | +function workerUrl(debugLogFile) { |
| 224 | + const log = existsSync(debugLogFile) ? readFileSync(debugLogFile, "utf8") : ""; |
| 225 | + const at = [...log.matchAll(/"userWorkerUrl":\{"protocol":"(https?:)","hostname":"([^"]+)","port":"(\d+)"/g)].pop(); |
| 226 | + return at ? `${at[1]}//${at[2]}:${at[3]}` : null; |
| 227 | +} |
| 228 | + |
| 214 | 229 | before(async () => { |
| 215 | 230 | assert.ok(existsSync(AGENT), `build the runner first: pnpm --filter @diffinery/runner build (missing ${AGENT})`); |
| 216 | | - ({ base, token } = await startServer()); |
| 231 | + ({ base, direct, token } = await startServer()); |
| 217 | 232 | }); |
| 218 | 233 | |
| 219 | 234 | after(() => { |
| | @@ -2935,7 +2950,9 @@ |
| 2935 | 2950 | test("large pushes: three large pushes into one repository at once all go in, and a fetch meanwhile works", async () => { |
| 2936 | 2951 | const me = await ok("GET", "/user"); |
| 2937 | 2952 | await ok("POST", "/user/repos", { name: "pushes-at-once" }); |
| 2938 | | - const remote = `${base}/${me.login}/pushes-at-once.git`; |
| 2953 | + // Straight to the Worker: wrangler dev's own proxy, not Diffinery, drops pushes streaming through it at once (see workerUrl). |
| 2954 | + assert.ok(direct && (await fetch(`${direct}/healthz`)).ok, `the Worker's own address wasn't found in wrangler dev's debug log (${direct})`); |
| 2955 | + const remote = `${direct}/${me.login}/pushes-at-once.git`; |
| 2939 | 2956 | const src = join(work, "pushes-at-once"); |
| 2940 | 2957 | mkdirSync(src, { recursive: true }); |
| 2941 | 2958 | git(src, ["init", "-q", "-b", "main"]); |