@steve31415/baselib 3.64.0 → 3.65.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,6 @@
1
1
  import type { Runner } from './types.js';
2
+ /** A gate's output shows its test browser process crashed (e.g. a segfault). */
3
+ export declare function testBrowserCrashed(output: string): boolean;
2
4
  export interface DeployOptions {
3
5
  repoRoot: string;
4
6
  runner: Runner;
@@ -16,6 +16,12 @@ import { consistentBaseSha, readServingState, SHA40 } from './plan.js';
16
16
  import { writeDeployMarker } from './deploy-marker.js';
17
17
  const RELEASE_DEADLINE_MS = 25 * 60_000;
18
18
  const IMAGE_DIGEST = /@sha256:[0-9a-f]{64}$/;
19
+ /** Chromium's crash-handler line as Playwright relays a browser's stderr. */
20
+ const BROWSER_CRASH = /^\s*\[pid=\d+\]\[err\] Received signal \d+ /m;
21
+ /** A gate's output shows its test browser process crashed (e.g. a segfault). */
22
+ export function testBrowserCrashed(output) {
23
+ return BROWSER_CRASH.test(output);
24
+ }
19
25
  const MAX_DIRTY_PATHS = 20;
20
26
  /** The clean-worktree refusal, naming what made the tree dirty (`git status
21
27
  * --porcelain` lines) so the reader need not go and look (2026-10-11: games'
@@ -216,11 +222,24 @@ export async function runDeploy(options) {
216
222
  if (!skipGates) {
217
223
  for (const [index, gate] of config.gates.entries()) {
218
224
  const gateStart = Date.now();
219
- const result = await runner('bash', ['-c', gate], {
225
+ const runGate = () => runner('bash', ['-c', gate], {
220
226
  cwd: options.repoRoot,
221
227
  timeoutMs: 15 * 60_000,
222
228
  });
229
+ let result = await runGate();
223
230
  await evidence.save(`gate-${index}.log`, result.stdout + result.stderr);
231
+ if (result.code !== 0 && testBrowserCrashed(result.stdout + result.stderr)) {
232
+ // The test browser itself segfaulted (Chromium's crash handler line,
233
+ // relayed by Playwright), which no app code under test causes or a
234
+ // code fix repairs: rerun the gate once. Any other failure still
235
+ // fails at once (TESTING.md "no retries, flakes must surface"), and
236
+ // the rerun must pass in full. Notes lost three deploys to one
237
+ // headless-shell crash in browser.newContext (2026-10-31, and twice
238
+ // on 2026-11-16, Coder tasks 7632cdaa and a0f43dda).
239
+ log(`gate failed because the test browser crashed (evidence gate-${index}.log); rerunning once: ${gate}`);
240
+ result = await runGate();
241
+ await evidence.save(`gate-${index}-rerun.log`, result.stdout + result.stderr);
242
+ }
224
243
  timer.record(`gate:${gate}`, Date.now() - gateStart);
225
244
  if (result.code !== 0) {
226
245
  // Quote the tail of BOTH streams: test runners put the failing spec on
package/dist/http.d.ts CHANGED
@@ -25,10 +25,16 @@ export interface StartServerOptions {
25
25
  app: Hono;
26
26
  logger: Logger;
27
27
  port?: number;
28
+ /** Work to finish on SIGTERM before the process exits — work that is not
29
+ * an HTTP request, which closing the server does not wait for (radar's
30
+ * timer-driven held sends, 2026-11-16). Awaited after the server stops
31
+ * accepting; still bounded by the 5 s exit, inside Cloud Run's 10 s
32
+ * grace. A rejection is logged and the exit goes on. */
33
+ beforeExit?: () => Promise<unknown>;
28
34
  }
29
35
  /** Standard entry point: safety check, crash logging (logUncaughtErrors),
30
36
  * serve, graceful SIGTERM shutdown
31
- * (stop accepting, then flush all loggers, then exit). Returns the Node
37
+ * (stop accepting, then `beforeExit`, then flush all loggers, then exit). Returns the Node
32
38
  * server so callers can attach protocol upgrades (e.g. @hono/node-ws's
33
39
  * injectWebSocket). */
34
40
  export declare function startServer(opts: StartServerOptions): ReturnType<typeof serve>;
package/dist/http.js CHANGED
@@ -65,7 +65,7 @@ export function errorHandler(logger) {
65
65
  }
66
66
  /** Standard entry point: safety check, crash logging (logUncaughtErrors),
67
67
  * serve, graceful SIGTERM shutdown
68
- * (stop accepting, then flush all loggers, then exit). Returns the Node
68
+ * (stop accepting, then `beforeExit`, then flush all loggers, then exit). Returns the Node
69
69
  * server so callers can attach protocol upgrades (e.g. @hono/node-ws's
70
70
  * injectWebSocket). */
71
71
  export function startServer(opts) {
@@ -80,11 +80,14 @@ export function startServer(opts) {
80
80
  });
81
81
  process.once('SIGTERM', () => {
82
82
  opts.logger.info('SIGTERM received, shutting down');
83
+ const drained = opts.beforeExit
84
+ ? opts.beforeExit().catch((error) => opts.logger.error('beforeExit failed', { error: error instanceof Error ? error.message : String(error) }))
85
+ : Promise.resolve();
83
86
  // final: last-chance delivery + drop markers, time-boxed. The two racing
84
87
  // callers below join the same single-flight finalFlush, so whichever
85
88
  // fires second waits for the real work instead of exiting under it.
86
89
  server.close(() => {
87
- void flushAllLoggers({ final: true }).finally(() => process.exit(0));
90
+ void drained.finally(() => flushAllLoggers({ final: true }).finally(() => process.exit(0)));
88
91
  });
89
92
  // Cloud Run's grace period is 10s; don't rely on every socket closing.
90
93
  setTimeout(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steve31415/baselib",
3
- "version": "3.64.0",
3
+ "version": "3.65.0",
4
4
  "description": "Plasticine new-world shared platform library: logging, auth, service-to-service auth, db, HTTP, sync, app updates",
5
5
  "type": "module",
6
6
  "license": "MIT",