cursedops 0.10.15 → 0.10.16

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cursedops",
3
- "version": "0.10.15",
3
+ "version": "0.10.16",
4
4
  "description": "The build-and-ops answers this generation's apps wrote independently and identically: finding a generation's roots — and printing a command that runs when pasted — without knowing a path, the generation's whole-tree laws run over one repo from a checkout or a worktree, macOS launchd agent install/replace/remove and the live port a job serves, the scaffolding and verdicts of a deployed smoke (origin probe, the smoke's own environment, a network that lies about DNS, a settled version), the static-serving helpers eight apps copied — the path-traversal guard among them — the API floor that keeps an unmatched /api/... from ever being answered with the app shell, the commit and dirty flag a checkout-served process reports, the Cloudflare Worker deploy toolkit four apps copied (the deploy sequence, exact-set secrets over a pipe, origin-first rollback, the curl edge fetch, the row-for-row D1 import proof, the billed-CPU tail check around a deploy's walk and smoke, and each app's worker:secrets and worker:smoke main as one function of its data), the relay a Worker fronts a Mac-bound app with (the Durable Object, the frames, the Mac's dialer and key rotation — lifted from station for roms — and the signed-in stage walk's skeleton and the relay app's whole worker:deploy), the Worker import-graph and await-port checks every Worker app's suite runs over its own source, and the public-surface ratchet three published libraries each carried a forked copy of. Mechanism only — no app knows its name from here. Bun, zero runtime dependencies (typescript is an optional peer, for public-surface only), ships source.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -292,6 +292,11 @@ export interface WorkerDeploySpec {
292
292
  export interface DeployDeps {
293
293
  /** Run a command, inheriting stdio; returns its exit code. */
294
294
  run: (argv: readonly string[], env: Record<string, string>) => number;
295
+ /**
296
+ * Run a command with its STDOUT captured (stderr inherited) — for a step whose exit code alone
297
+ * proves nothing: the schema step reads wrangler's `--json` answer back ({@link judgeSchemaApply}).
298
+ */
299
+ capture: (argv: readonly string[], env: Record<string, string>) => { code: number; stdout: string };
295
300
  /** `git <args>` in the checkout; trimmed stdout, `""` on failure. */
296
301
  git: (args: readonly string[]) => string;
297
302
  /** A file in the checkout, as text — the schema. Default: `readFileSync` against the process's cwd. */
@@ -316,12 +321,25 @@ export interface DeployResult {
316
321
 
317
322
  /** The real {@link DeployDeps}, rooted at the app's checkout. */
318
323
  export function workerDeployDeps(cwd: string): DeployDeps {
324
+ // a schema `--command` is kilobytes of DDL — the echo names it, it does not reprint it
325
+ const echo = (argv: readonly string[]): void =>
326
+ console.log(` $ ${argv.map((arg) => (arg.length > 160 ? `${arg.slice(0, 120)}… (${arg.length} chars)` : arg)).join(" ")}`);
319
327
  return {
320
328
  run: (argv, env) => {
321
- // a schema `--command` is kilobytes of DDL — the echo names it, it does not reprint it
322
- console.log(` $ ${argv.map((arg) => (arg.length > 160 ? `${arg.slice(0, 120)}… (${arg.length} chars)` : arg)).join(" ")}`);
329
+ echo(argv);
323
330
  return spawnSync(argv[0] as string, argv.slice(1), { cwd, stdio: "inherit", env: { ...process.env, ...env } }).status ?? 1;
324
331
  },
332
+ capture: (argv, env) => {
333
+ echo(argv);
334
+ const r = spawnSync(argv[0] as string, argv.slice(1), {
335
+ cwd,
336
+ stdio: ["inherit", "pipe", "inherit"],
337
+ encoding: "utf8",
338
+ maxBuffer: 64 * 1024 * 1024,
339
+ env: { ...process.env, ...env },
340
+ });
341
+ return { code: r.status ?? 1, stdout: r.stdout ?? "" };
342
+ },
325
343
  git: (args) => (spawnSync("git", [...args], { cwd, encoding: "utf8" }).stdout ?? "").trim(),
326
344
  read: (path) => readFileSync(join(cwd, path), "utf8"),
327
345
  };
@@ -433,7 +451,39 @@ export function schemaCommands(text: string, maxBytes: number = SCHEMA_COMMAND_B
433
451
  * `workerDeploy.test.ts` pins that no argv here ever carries `--file`.
434
452
  */
435
453
  export function schemaApplyArgv(databaseName: string, commands: readonly string[], envArgs: readonly string[]): string[][] {
436
- return commands.map((command) => ["bunx", "wrangler", "d1", "execute", databaseName, "--remote", "--command", command, "-y", ...envArgs]);
454
+ return commands.map((command) => ["bunx", "wrangler", "d1", "execute", databaseName, "--remote", "--command", command, "--json", "-y", ...envArgs]);
455
+ }
456
+
457
+ /**
458
+ * Did one schema chunk APPLY? Its exit code alone does not say.
459
+ *
460
+ * Measured 2026-09-26 (task 2173): this Mac has no `node` on a non-interactive PATH, so `bunx
461
+ * wrangler` runs wrangler under Bun — and under Bun it sometimes exits 0 part-way through its
462
+ * first API request, having printed nothing but its banner. `binary-server`'s edge deploy did it
463
+ * twice in a row and deployed nothing. For this step that is a schema that "passed" without
464
+ * running: the new code ships, and the first request touching the new column 500s in production
465
+ * while the smoke's census of existing routes stays green.
466
+ *
467
+ * So the step asks for `--json` and requires what wrangler prints when a query ran: an array with
468
+ * one result per statement, every one `success: true`. Anything else — no JSON, an empty array,
469
+ * a failed result — is not applied. Pure, so its failure path is tested without wrangler.
470
+ */
471
+ export function judgeSchemaApply(code: number, stdout: string): { applied: boolean; line: string } {
472
+ if (code !== 0) return { applied: false, line: `wrangler exited ${code}` };
473
+ // the first `[` that opens a JSON array, never the `[ERROR]`/`[WARNING]` of a banner — as `wranglerRows`
474
+ const start = stdout.search(/\[\s*[{\]]/);
475
+ const banner = stdout.trim().slice(0, 160).replace(/\s+/g, " ") || "(nothing)";
476
+ if (start < 0) return { applied: false, line: `wrangler exited 0 and printed no JSON result — it did not run the query. It printed: ${banner}` };
477
+ let parsed: unknown;
478
+ try {
479
+ parsed = JSON.parse(stdout.slice(start));
480
+ } catch (cause) {
481
+ return { applied: false, line: `wrangler's JSON result did not parse (${(cause as Error).message})` };
482
+ }
483
+ if (!Array.isArray(parsed) || parsed.length === 0) return { applied: false, line: "wrangler printed an empty result — no statement ran" };
484
+ const failed = parsed.filter((result) => (result as { success?: unknown } | null)?.success !== true);
485
+ if (failed.length > 0) return { applied: false, line: `${failed.length} of ${parsed.length} result(s) did not report success` };
486
+ return { applied: true, line: `applied — ${parsed.length} result(s), every one success` };
437
487
  }
438
488
 
439
489
  /**
@@ -505,7 +555,19 @@ export function runWorkerDeploy(spec: WorkerDeploySpec, deps: DeployDeps): Deplo
505
555
  return stop("schema", `${schema} could not be read as statements (${(cause as Error).message}) — nothing was deployed.`);
506
556
  }
507
557
  for (const argv of schemaApplyArgv(spec.databaseName, commands, envArgs)) {
508
- if (deps.run(argv, spec.credential) !== 0) return stop("schema", "the schema did not apply — nothing was deployed.");
558
+ // a silent exit 0 is intermittent and the schema is idempotent, so ONE retry; a real
559
+ // failure (non-zero) is not retried — it would fail the same way
560
+ const attempt = (): { code: number; verdict: ReturnType<typeof judgeSchemaApply> } => {
561
+ const { code, stdout } = deps.capture(argv, spec.credential);
562
+ return { code, verdict: judgeSchemaApply(code, stdout) };
563
+ };
564
+ let { code, verdict } = attempt();
565
+ if (!verdict.applied && code === 0) {
566
+ error(` 🟡 ${verdict.line} — retrying once`);
567
+ ({ code, verdict } = attempt());
568
+ }
569
+ if (!verdict.applied) return stop("schema", `the schema did not apply (${verdict.line}) — nothing was deployed.`);
570
+ log(` ${verdict.line}`);
509
571
  }
510
572
  }
511
573
  step(`deploy ${spec.workerName} @ ${commit.slice(0, 8)}${dirty ? " (dirty — stage only)" : ""}`);