@databricks-solutions/lakebase-scm-utils 0.2.43 → 0.2.45

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.
Files changed (63) hide show
  1. package/dist/scripts/github/index.cjs +21 -4
  2. package/dist/scripts/github/index.js +21 -4
  3. package/dist/scripts/github/pr.cli.cjs +21 -4
  4. package/dist/scripts/github/pr.cli.js +21 -4
  5. package/dist/scripts/index.cjs +1224 -1157
  6. package/dist/scripts/index.d.cts +1 -1
  7. package/dist/scripts/index.d.ts +1 -1
  8. package/dist/scripts/index.js +1223 -1157
  9. package/dist/scripts/lakebase/branch.cli.cjs +21 -4
  10. package/dist/scripts/lakebase/branch.cli.js +21 -4
  11. package/dist/scripts/lakebase/ci-app-endpoint.cli.cjs +21 -4
  12. package/dist/scripts/lakebase/ci-app-endpoint.cli.js +21 -4
  13. package/dist/scripts/lakebase/ci-resolve-branch.cli.cjs +23 -6
  14. package/dist/scripts/lakebase/ci-resolve-branch.cli.js +23 -6
  15. package/dist/scripts/lakebase/collapse-heads.cli.cjs +23 -6
  16. package/dist/scripts/lakebase/collapse-heads.cli.js +23 -6
  17. package/dist/scripts/lakebase/cut-backup.cli.cjs +21 -4
  18. package/dist/scripts/lakebase/cut-backup.cli.js +21 -4
  19. package/dist/scripts/lakebase/cut-tier.cli.cjs +21 -4
  20. package/dist/scripts/lakebase/cut-tier.cli.js +21 -4
  21. package/dist/scripts/lakebase/detect-language.cli.cjs +23 -6
  22. package/dist/scripts/lakebase/detect-language.cli.js +23 -6
  23. package/dist/scripts/lakebase/doctor.cli.cjs +24 -7
  24. package/dist/scripts/lakebase/doctor.cli.js +24 -7
  25. package/dist/scripts/lakebase/get-connection.cli.cjs +23 -6
  26. package/dist/scripts/lakebase/get-connection.cli.js +23 -6
  27. package/dist/scripts/lakebase/index.cjs +489 -391
  28. package/dist/scripts/lakebase/index.d.cts +33 -1
  29. package/dist/scripts/lakebase/index.d.ts +33 -1
  30. package/dist/scripts/lakebase/index.js +488 -391
  31. package/dist/scripts/lakebase/infra-runner.cli.cjs +23 -6
  32. package/dist/scripts/lakebase/infra-runner.cli.js +23 -6
  33. package/dist/scripts/lakebase/new-migration.cli.cjs +23 -6
  34. package/dist/scripts/lakebase/new-migration.cli.js +23 -6
  35. package/dist/scripts/lakebase/schema-diff.cli.cjs +23 -6
  36. package/dist/scripts/lakebase/schema-diff.cli.js +23 -6
  37. package/dist/scripts/lakebase/schema-migrate.cli.cjs +23 -6
  38. package/dist/scripts/lakebase/schema-migrate.cli.js +23 -6
  39. package/dist/scripts/lakebase/scm-abandon-feature.cli.cjs +21 -4
  40. package/dist/scripts/lakebase/scm-abandon-feature.cli.js +21 -4
  41. package/dist/scripts/lakebase/scm-adopt-state.cli.cjs +21 -4
  42. package/dist/scripts/lakebase/scm-adopt-state.cli.js +21 -4
  43. package/dist/scripts/lakebase/scm-claim-feature.cli.cjs +23 -6
  44. package/dist/scripts/lakebase/scm-claim-feature.cli.js +23 -6
  45. package/dist/scripts/lakebase/scm-cleanup.cli.cjs +21 -4
  46. package/dist/scripts/lakebase/scm-cleanup.cli.js +21 -4
  47. package/dist/scripts/lakebase/scm-doctor.cli.cjs +23 -6
  48. package/dist/scripts/lakebase/scm-doctor.cli.js +23 -6
  49. package/dist/scripts/lakebase/scm-merge.cli.cjs +2305 -2037
  50. package/dist/scripts/lakebase/scm-merge.cli.js +360 -92
  51. package/dist/scripts/lakebase/scm-reconcile-tier.cli.cjs +23 -6
  52. package/dist/scripts/lakebase/scm-reconcile-tier.cli.js +23 -6
  53. package/dist/scripts/lakebase/scm-recover-orphans.cli.cjs +21 -4
  54. package/dist/scripts/lakebase/scm-recover-orphans.cli.js +21 -4
  55. package/dist/scripts/util/index.cjs +23 -6
  56. package/dist/scripts/util/index.js +23 -6
  57. package/package.json +1 -1
  58. package/scripts/lakebase/databricks-cli.ts +44 -4
  59. package/scripts/lakebase/doctor.ts +1 -1
  60. package/scripts/lakebase/runner-setup.ts +18 -2
  61. package/scripts/lakebase/scm-merge.ts +80 -1
  62. package/scripts/lakebase/secret-auth.ts +9 -2
  63. package/templates/project/common/scripts/run-tests.sh +10 -0
@@ -77731,16 +77731,33 @@ stdout: ${stdout}` : killed || signal ? `
77731
77731
  }
77732
77732
  async function runDatabricks(args, opts = {}) {
77733
77733
  const { argv, env, profile } = buildInvocation(args, opts);
77734
+ const timeout = opts.timeout ?? KIT_TIMEOUTS.cliDefault;
77734
77735
  try {
77735
- const { stdout } = await execFileP("databricks", argv, {
77736
- env,
77737
- timeout: opts.timeout ?? KIT_TIMEOUTS.cliDefault
77738
- });
77736
+ if (opts.input !== void 0) {
77737
+ return await execDatabricksWithStdin(argv, opts.input, env, timeout);
77738
+ }
77739
+ const { stdout } = await execFileP("databricks", argv, { env, timeout });
77739
77740
  return stdout.toString();
77740
77741
  } catch (err) {
77741
77742
  throw classifyDatabricksError(err, argv, profile);
77742
77743
  }
77743
77744
  }
77745
+ function execDatabricksWithStdin(argv, input, env, timeout) {
77746
+ return new Promise((resolve2, reject) => {
77747
+ const child = (0, import_node_child_process2.execFile)("databricks", argv, { env, timeout }, (err, stdout, stderr) => {
77748
+ if (err) {
77749
+ err.stdout = String(stdout ?? "");
77750
+ err.stderr = String(stderr ?? "");
77751
+ reject(err);
77752
+ return;
77753
+ }
77754
+ resolve2(String(stdout ?? ""));
77755
+ });
77756
+ child.stdin?.on("error", () => {
77757
+ });
77758
+ child.stdin?.end(input);
77759
+ });
77760
+ }
77744
77761
  function runDatabricksSync(args, opts = {}) {
77745
77762
  const { argv, env, profile } = buildInvocation(args, opts);
77746
77763
  try {
@@ -79270,8 +79287,8 @@ var PKG_NAME = "@databricks-solutions/lakebase-scm-utils";
79270
79287
  var cached;
79271
79288
  function substrateSelfVersion() {
79272
79289
  if (cached !== void 0) return cached;
79273
- if ("0.2.43".length > 0) {
79274
- cached = "0.2.43";
79290
+ if ("0.2.45".length > 0) {
79291
+ cached = "0.2.45";
79275
79292
  return cached;
79276
79293
  }
79277
79294
  cached = "unknown";
@@ -208,16 +208,33 @@ stdout: ${stdout}` : killed || signal ? `
208
208
  }
209
209
  async function runDatabricks(args, opts = {}) {
210
210
  const { argv, env, profile } = buildInvocation(args, opts);
211
+ const timeout = opts.timeout ?? KIT_TIMEOUTS.cliDefault;
211
212
  try {
212
- const { stdout } = await execFileP("databricks", argv, {
213
- env,
214
- timeout: opts.timeout ?? KIT_TIMEOUTS.cliDefault
215
- });
213
+ if (opts.input !== void 0) {
214
+ return await execDatabricksWithStdin(argv, opts.input, env, timeout);
215
+ }
216
+ const { stdout } = await execFileP("databricks", argv, { env, timeout });
216
217
  return stdout.toString();
217
218
  } catch (err) {
218
219
  throw classifyDatabricksError(err, argv, profile);
219
220
  }
220
221
  }
222
+ function execDatabricksWithStdin(argv, input, env, timeout) {
223
+ return new Promise((resolve2, reject) => {
224
+ const child = execFile("databricks", argv, { env, timeout }, (err, stdout, stderr) => {
225
+ if (err) {
226
+ err.stdout = String(stdout ?? "");
227
+ err.stderr = String(stderr ?? "");
228
+ reject(err);
229
+ return;
230
+ }
231
+ resolve2(String(stdout ?? ""));
232
+ });
233
+ child.stdin?.on("error", () => {
234
+ });
235
+ child.stdin?.end(input);
236
+ });
237
+ }
221
238
  function runDatabricksSync(args, opts = {}) {
222
239
  const { argv, env, profile } = buildInvocation(args, opts);
223
240
  try {
@@ -371,8 +388,8 @@ var PKG_NAME = "@databricks-solutions/lakebase-scm-utils";
371
388
  var cached;
372
389
  function substrateSelfVersion() {
373
390
  if (cached !== void 0) return cached;
374
- if ("0.2.43".length > 0) {
375
- cached = "0.2.43";
391
+ if ("0.2.45".length > 0) {
392
+ cached = "0.2.45";
376
393
  return cached;
377
394
  }
378
395
  cached = "unknown";
@@ -77849,16 +77849,33 @@ stdout: ${stdout}` : killed || signal ? `
77849
77849
  }
77850
77850
  async function runDatabricks(args, opts = {}) {
77851
77851
  const { argv, env, profile } = buildInvocation(args, opts);
77852
+ const timeout = opts.timeout ?? KIT_TIMEOUTS.cliDefault;
77852
77853
  try {
77853
- const { stdout } = await execFileP("databricks", argv, {
77854
- env,
77855
- timeout: opts.timeout ?? KIT_TIMEOUTS.cliDefault
77856
- });
77854
+ if (opts.input !== void 0) {
77855
+ return await execDatabricksWithStdin(argv, opts.input, env, timeout);
77856
+ }
77857
+ const { stdout } = await execFileP("databricks", argv, { env, timeout });
77857
77858
  return stdout.toString();
77858
77859
  } catch (err) {
77859
77860
  throw classifyDatabricksError(err, argv, profile);
77860
77861
  }
77861
77862
  }
77863
+ function execDatabricksWithStdin(argv, input, env, timeout) {
77864
+ return new Promise((resolve2, reject) => {
77865
+ const child = (0, import_node_child_process2.execFile)("databricks", argv, { env, timeout }, (err, stdout, stderr) => {
77866
+ if (err) {
77867
+ err.stdout = String(stdout ?? "");
77868
+ err.stderr = String(stderr ?? "");
77869
+ reject(err);
77870
+ return;
77871
+ }
77872
+ resolve2(String(stdout ?? ""));
77873
+ });
77874
+ child.stdin?.on("error", () => {
77875
+ });
77876
+ child.stdin?.end(input);
77877
+ });
77878
+ }
77862
77879
  function runDatabricksSync(args, opts = {}) {
77863
77880
  const { argv, env, profile } = buildInvocation(args, opts);
77864
77881
  try {
@@ -321,16 +321,33 @@ stdout: ${stdout}` : killed || signal ? `
321
321
  }
322
322
  async function runDatabricks(args, opts = {}) {
323
323
  const { argv, env, profile } = buildInvocation(args, opts);
324
+ const timeout = opts.timeout ?? KIT_TIMEOUTS.cliDefault;
324
325
  try {
325
- const { stdout } = await execFileP("databricks", argv, {
326
- env,
327
- timeout: opts.timeout ?? KIT_TIMEOUTS.cliDefault
328
- });
326
+ if (opts.input !== void 0) {
327
+ return await execDatabricksWithStdin(argv, opts.input, env, timeout);
328
+ }
329
+ const { stdout } = await execFileP("databricks", argv, { env, timeout });
329
330
  return stdout.toString();
330
331
  } catch (err) {
331
332
  throw classifyDatabricksError(err, argv, profile);
332
333
  }
333
334
  }
335
+ function execDatabricksWithStdin(argv, input, env, timeout) {
336
+ return new Promise((resolve2, reject) => {
337
+ const child = execFile("databricks", argv, { env, timeout }, (err, stdout, stderr) => {
338
+ if (err) {
339
+ err.stdout = String(stdout ?? "");
340
+ err.stderr = String(stderr ?? "");
341
+ reject(err);
342
+ return;
343
+ }
344
+ resolve2(String(stdout ?? ""));
345
+ });
346
+ child.stdin?.on("error", () => {
347
+ });
348
+ child.stdin?.end(input);
349
+ });
350
+ }
334
351
  function runDatabricksSync(args, opts = {}) {
335
352
  const { argv, env, profile } = buildInvocation(args, opts);
336
353
  try {
@@ -1659,8 +1659,8 @@ var PKG_NAME = "@databricks-solutions/lakebase-scm-utils";
1659
1659
  var cached;
1660
1660
  function substrateSelfVersion() {
1661
1661
  if (cached !== void 0) return cached;
1662
- if ("0.2.43".length > 0) {
1663
- cached = "0.2.43";
1662
+ if ("0.2.45".length > 0) {
1663
+ cached = "0.2.45";
1664
1664
  return cached;
1665
1665
  }
1666
1666
  cached = "unknown";
@@ -1928,16 +1928,33 @@ stdout: ${stdout}` : killed || signal ? `
1928
1928
  }
1929
1929
  async function runDatabricks(args, opts = {}) {
1930
1930
  const { argv, env, profile } = buildInvocation(args, opts);
1931
+ const timeout = opts.timeout ?? KIT_TIMEOUTS.cliDefault;
1931
1932
  try {
1932
- const { stdout } = await execFileP("databricks", argv, {
1933
- env,
1934
- timeout: opts.timeout ?? KIT_TIMEOUTS.cliDefault
1935
- });
1933
+ if (opts.input !== void 0) {
1934
+ return await execDatabricksWithStdin(argv, opts.input, env, timeout);
1935
+ }
1936
+ const { stdout } = await execFileP("databricks", argv, { env, timeout });
1936
1937
  return stdout.toString();
1937
1938
  } catch (err) {
1938
1939
  throw classifyDatabricksError(err, argv, profile);
1939
1940
  }
1940
1941
  }
1942
+ function execDatabricksWithStdin(argv, input, env, timeout) {
1943
+ return new Promise((resolve, reject) => {
1944
+ const child = (0, import_node_child_process2.execFile)("databricks", argv, { env, timeout }, (err, stdout, stderr) => {
1945
+ if (err) {
1946
+ err.stdout = String(stdout ?? "");
1947
+ err.stderr = String(stderr ?? "");
1948
+ reject(err);
1949
+ return;
1950
+ }
1951
+ resolve(String(stdout ?? ""));
1952
+ });
1953
+ child.stdin?.on("error", () => {
1954
+ });
1955
+ child.stdin?.end(input);
1956
+ });
1957
+ }
1941
1958
 
1942
1959
  // scripts/github/secrets.ts
1943
1960
  init_cjs_shims();
@@ -1630,8 +1630,8 @@ var PKG_NAME = "@databricks-solutions/lakebase-scm-utils";
1630
1630
  var cached;
1631
1631
  function substrateSelfVersion() {
1632
1632
  if (cached !== void 0) return cached;
1633
- if ("0.2.43".length > 0) {
1634
- cached = "0.2.43";
1633
+ if ("0.2.45".length > 0) {
1634
+ cached = "0.2.45";
1635
1635
  return cached;
1636
1636
  }
1637
1637
  cached = "unknown";
@@ -1899,16 +1899,33 @@ stdout: ${stdout}` : killed || signal ? `
1899
1899
  }
1900
1900
  async function runDatabricks(args, opts = {}) {
1901
1901
  const { argv, env, profile } = buildInvocation(args, opts);
1902
+ const timeout = opts.timeout ?? KIT_TIMEOUTS.cliDefault;
1902
1903
  try {
1903
- const { stdout } = await execFileP("databricks", argv, {
1904
- env,
1905
- timeout: opts.timeout ?? KIT_TIMEOUTS.cliDefault
1906
- });
1904
+ if (opts.input !== void 0) {
1905
+ return await execDatabricksWithStdin(argv, opts.input, env, timeout);
1906
+ }
1907
+ const { stdout } = await execFileP("databricks", argv, { env, timeout });
1907
1908
  return stdout.toString();
1908
1909
  } catch (err) {
1909
1910
  throw classifyDatabricksError(err, argv, profile);
1910
1911
  }
1911
1912
  }
1913
+ function execDatabricksWithStdin(argv, input, env, timeout) {
1914
+ return new Promise((resolve, reject) => {
1915
+ const child = execFile("databricks", argv, { env, timeout }, (err, stdout, stderr) => {
1916
+ if (err) {
1917
+ err.stdout = String(stdout ?? "");
1918
+ err.stderr = String(stderr ?? "");
1919
+ reject(err);
1920
+ return;
1921
+ }
1922
+ resolve(String(stdout ?? ""));
1923
+ });
1924
+ child.stdin?.on("error", () => {
1925
+ });
1926
+ child.stdin?.end(input);
1927
+ });
1928
+ }
1912
1929
 
1913
1930
  // scripts/github/secrets.ts
1914
1931
  init_esm_shims();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@databricks-solutions/lakebase-scm-utils",
3
- "version": "0.2.43",
3
+ "version": "0.2.45",
4
4
  "description": "Lakebase SCM + substrate engine: database branching, paired-branch SCM workflows, connection/credential minting, schema migration, project scaffold + deploy primitives, and the git/github utility layer. Extracted from consort for portable, standalone consumption by lakebase-scm-extension and the SFTDD orchestration.",
5
5
  "type": "module",
6
6
  "private": false,
@@ -36,6 +36,11 @@ export interface DatabricksCliOptions {
36
36
  * subcommand. Set this for version/help probes so they work regardless of
37
37
  * DATABRICKS_CONFIG_PROFILE. */
38
38
  noProfile?: boolean;
39
+ /** Data to feed on the child's STDIN (async path only). Used to keep a
40
+ * credential OFF the command line: pass the secret in a `--json @/dev/stdin`
41
+ * body here instead of as a `--string-value <cred>` argv element, so it never
42
+ * appears in the process table / `ps`. */
43
+ input?: string;
39
44
  }
40
45
 
41
46
  /** A `databricks` CLI call failed. Message: `databricks <args> failed: <msg>\nstderr: <stderr>`. */
@@ -203,17 +208,52 @@ export function classifyDatabricksError(err: unknown, argv: string[], profile: s
203
208
  /** Run the `databricks` CLI (async), returning stdout. */
204
209
  export async function runDatabricks(args: string[], opts: DatabricksCliOptions = {}): Promise<string> {
205
210
  const { argv, env, profile } = buildInvocation(args, opts);
211
+ const timeout = opts.timeout ?? KIT_TIMEOUTS.cliDefault;
206
212
  try {
207
- const { stdout } = await execFileP("databricks", argv, {
208
- env,
209
- timeout: opts.timeout ?? KIT_TIMEOUTS.cliDefault,
210
- });
213
+ if (opts.input !== undefined) {
214
+ return await execDatabricksWithStdin(argv, opts.input, env, timeout);
215
+ }
216
+ const { stdout } = await execFileP("databricks", argv, { env, timeout });
211
217
  return stdout.toString();
212
218
  } catch (err) {
213
219
  throw classifyDatabricksError(err, argv, profile);
214
220
  }
215
221
  }
216
222
 
223
+ /**
224
+ * Run `databricks` feeding `input` on STDIN, so a credential can travel in a
225
+ * `--json @/dev/stdin` body instead of a `--string-value <cred>` argv element
226
+ * that leaks into the process table. Buffers stdout/stderr and shapes
227
+ * the result like execFileP so classifyDatabricksError reads it uniformly.
228
+ *
229
+ * The stdin write is GUARDED: a child that exits/rejects the body before we finish
230
+ * writing raises EPIPE on the pipe, which is an UNHANDLED 'error' (crash) unless we
231
+ * listen for it. We swallow the pipe error and let the child's own exit code + stderr
232
+ * be the verdict (guard the write against EPIPE).
233
+ */
234
+ function execDatabricksWithStdin(
235
+ argv: string[],
236
+ input: string,
237
+ env: NodeJS.ProcessEnv,
238
+ timeout: number,
239
+ ): Promise<string> {
240
+ return new Promise((resolve, reject) => {
241
+ const child = execFile("databricks", argv, { env, timeout }, (err, stdout, stderr) => {
242
+ if (err) {
243
+ (err as { stdout?: string; stderr?: string }).stdout = String(stdout ?? "");
244
+ (err as { stdout?: string; stderr?: string }).stderr = String(stderr ?? "");
245
+ reject(err);
246
+ return;
247
+ }
248
+ resolve(String(stdout ?? ""));
249
+ });
250
+ // Guard the pipe: without this an EPIPE (child gone before we finish) is an
251
+ // uncaught exception; the child's exit/stderr is the real verdict.
252
+ child.stdin?.on("error", () => {});
253
+ child.stdin?.end(input);
254
+ });
255
+ }
256
+
217
257
  /** Run the `databricks` CLI (sync), returning stdout. */
218
258
  export function runDatabricksSync(args: string[], opts: DatabricksCliOptions = {}): string {
219
259
  const { argv, env, profile } = buildInvocation(args, opts);
@@ -628,7 +628,7 @@ function checkWorkflowDrift(projectDir: string): CheckResult {
628
628
  status: "warn",
629
629
  message: `Scaffolded workflows drift from kit: ${drifted} drifted, ${missing} missing`,
630
630
  detail: { files: report.files.map((f) => ({ name: f.name, status: f.status })) },
631
- hint: "Inspect via the lakebase_workflow_drift MCP tool (or detectWorkflowDrift import). Refresh manually until updateWorkflows lands.",
631
+ hint: "Refresh with updateWorkflows (or the lakebase_workflow_drift MCP tool). A stale merge.yml calling 'lakebase-schema-migrate apply' (not 'apply-tier') makes the promote's migrate-target fail on the tier guard; the scm-merge promote also self-heals drifted workflows onto the PR head before merging.",
632
632
  };
633
633
  } catch (err) {
634
634
  return {
@@ -271,8 +271,24 @@ export async function setupRunner(args: SetupRunnerArgs): Promise<RunnerInfo> {
271
271
  if (needsConfig) {
272
272
  report("Registering runner with GitHub...");
273
273
  const regToken = await createRegistrationToken(args.fullRepoName);
274
- cp.execSync(
275
- `./config.sh --url "https://github.com/${args.fullRepoName}" --token "${regToken}" --name "${name}" --labels self-hosted --unattended --replace`,
274
+ // Invoke config.sh with an argv array (execFileSync), NOT a shell-interpolated
275
+ // string (execSync). config.sh is GitHub's runner binary and only accepts the
276
+ // registration token as `--token <tok>`, so the token is unavoidably on its argv
277
+ // (a full off-`ps` fix would need the JIT-runner API — disproportionate for a
278
+ // SHORT-LIVED (~1h) reg token). But dropping the `/bin/sh -c` wrapper removes the
279
+ // extra shell process that also carried the token, closes the shell-trace /
280
+ // process-accounting exposure, and eliminates any shell-injection surface on the
281
+ // interpolated url/name.
282
+ cp.execFileSync(
283
+ "./config.sh",
284
+ [
285
+ "--url", `https://github.com/${args.fullRepoName}`,
286
+ "--token", regToken,
287
+ "--name", name,
288
+ "--labels", "self-hosted",
289
+ "--unattended",
290
+ "--replace",
291
+ ],
276
292
  { cwd: dir, timeout: KIT_TIMEOUTS.cliLong }
277
293
  );
278
294
  }
@@ -20,7 +20,9 @@ import { getOwnerRepo } from "../git/remote.js";
20
20
  import { pollUntil } from "../util/poll-until.js";
21
21
  import { exec } from "../util/exec.js";
22
22
  import { getCurrentBranch } from "../git/inspect.js";
23
+ import { pushCurrentBranchForPr } from "../git/sync.js";
23
24
  import { resolveGitBase } from "./scm-git-base.js";
25
+ import { detectWorkflowDrift, updateWorkflows } from "./workflow-drift.js";
24
26
 
25
27
  /**
26
28
  * Fast-forward the local tier ref to origin/<tier> after a remote merge, WITHOUT
@@ -149,6 +151,21 @@ export interface MergeArgs {
149
151
  * already on the parent branch after the merge).
150
152
  */
151
153
  localMigrateFallback?: () => Promise<{ ok: boolean; detail?: string }>;
154
+ /**
155
+ * Pre-merge workflow self-heal. Bumping SCM_UTILS_REF upgrades the CLI (e.g.
156
+ * the tier-migration guard) but leaves a scaffolded project's committed
157
+ * `.github/workflows/*.yml` at their older shape — so the promote's
158
+ * `migrate-target` can run a stale `lakebase-schema-migrate apply` against the
159
+ * parent TIER, which the guard refuses (CI red, cleanup skipped). This step
160
+ * refreshes drifted workflow files to the pinned template (so the promote uses
161
+ * `apply-tier`) and commits+pushes them onto the PR head BEFORE the merge, so
162
+ * the merge commit carries the corrected workflow and the triggered `<tier>
163
+ * Merge` run passes. BEST-EFFORT: it never blocks the merge — a detect/refresh/
164
+ * push failure is recorded as a warning and the merge proceeds (the local
165
+ * migrate fallback still keeps git and schema in sync). Defaults to the built-in
166
+ * implementation ({@link defaultRefreshPromoteWorkflows}); injected in tests.
167
+ */
168
+ refreshWorkflows?: () => Promise<{ refreshed: boolean; detail?: string }>;
152
169
  }
153
170
 
154
171
  export interface MergeResult {
@@ -221,6 +238,43 @@ function shaMigratePredicate(
221
238
  };
222
239
  }
223
240
 
241
+ /**
242
+ * Built-in {@link MergeArgs.refreshWorkflows}. Refreshes drifted scaffolded
243
+ * `.github/workflows/*.yml` to the pinned template and commits + pushes them onto
244
+ * the PR head, so the merge commit carries the corrected promote workflow (the
245
+ * `migrate-target` step's `lakebase-schema-migrate apply-tier`) and the triggered
246
+ * `<tier> Merge` run passes instead of failing on the tier guard. No-op when
247
+ * nothing drifted. Scoped to `.github/workflows` so it never sweeps unrelated
248
+ * working-tree changes. Callers invoke it BEST-EFFORT — a failure here must never
249
+ * block the merge (the local migrate fallback still keeps git + schema in sync).
250
+ */
251
+ export async function defaultRefreshPromoteWorkflows(
252
+ projectDir: string,
253
+ ): Promise<{ refreshed: boolean; detail?: string }> {
254
+ const drift = detectWorkflowDrift({ projectDir });
255
+ // Only self-heal a stale EXISTING workflow (drifted). A project with no
256
+ // scaffolded workflows at all (all "missing") is not the stale-apply case, so
257
+ // the promote never scaffolds files it doesn't own.
258
+ const touched = drift.files.filter((f) => f.status === "drifted").map((f) => f.name);
259
+ if (touched.length === 0) return { refreshed: false };
260
+ const result = updateWorkflows({ projectDir });
261
+ if (!result.changed) return { refreshed: false };
262
+ await exec(`git add ${shellEscape(".github/workflows")}`, { cwd: projectDir, timeout: 10_000 });
263
+ const staged = await exec("git diff --cached --name-only -- .github/workflows", {
264
+ cwd: projectDir,
265
+ timeout: 10_000,
266
+ });
267
+ if (!staged.trim()) return { refreshed: false };
268
+ await exec(
269
+ `git commit -m ${shellEscape(
270
+ "chore(ci): refresh scaffolded workflows to pinned substrate (promote uses apply-tier)",
271
+ )} -- .github/workflows`,
272
+ { cwd: projectDir, timeout: 15_000 },
273
+ );
274
+ await pushCurrentBranchForPr({ cwd: projectDir });
275
+ return { refreshed: true, detail: `refreshed + pushed ${touched.join(", ") || "workflow(s)"} onto the PR head` };
276
+ }
277
+
224
278
  export async function mergeFeature(args: MergeArgs): Promise<MergeResult> {
225
279
  const current = readWorkflowState(args.projectDir);
226
280
  if (!current) {
@@ -297,6 +351,31 @@ export async function mergeFeature(args: MergeArgs): Promise<MergeResult> {
297
351
  authVerified = true;
298
352
  }
299
353
 
354
+ // ─── Pre-merge workflow self-heal ───
355
+ // A scaffolded project's committed workflows can lag the pinned substrate ref
356
+ // (SCM_UTILS_REF bumped, workflow files not regenerated), so the promote's
357
+ // migrate-target runs a stale `lakebase-schema-migrate apply` against the parent
358
+ // TIER, which the guard refuses (CI red, cleanup skipped). Refresh drifted
359
+ // workflows onto the PR head BEFORE the merge so the merge commit carries the
360
+ // corrected `apply-tier` step. BEST-EFFORT: never blocks the merge.
361
+ // Runs regardless of waitMigrate: the promote workflow triggers on the tier
362
+ // push either way, so a stale merge.yml fails CI whether or not the caller waits.
363
+ const preflightNotes: string[] = [];
364
+ {
365
+ const refresh = args.refreshWorkflows ?? (() => defaultRefreshPromoteWorkflows(args.projectDir));
366
+ try {
367
+ const r = await refresh();
368
+ if (r.refreshed) {
369
+ preflightNotes.push(`Refreshed stale CI workflows before merge${r.detail ? ` (${r.detail})` : ""}.`);
370
+ }
371
+ } catch (err) {
372
+ preflightNotes.push(
373
+ `Workflow self-heal skipped (${err instanceof Error ? err.message : String(err)}); if the promote's ` +
374
+ `migrate-target fails on the tier guard, refresh .github/workflows (merge.yml must call 'lakebase-schema-migrate apply-tier').`,
375
+ );
376
+ }
377
+ }
378
+
300
379
  let paired: Awaited<ReturnType<typeof mergePairedPullRequest>>;
301
380
  try {
302
381
  paired = await mergePairedPullRequest({
@@ -312,7 +391,7 @@ export async function mergeFeature(args: MergeArgs): Promise<MergeResult> {
312
391
  );
313
392
  }
314
393
 
315
- const warnings: string[] = [...paired.warnings];
394
+ const warnings: string[] = [...preflightNotes, ...paired.warnings];
316
395
  let localBranchDeleted = false;
317
396
  let headAfter = current.branch;
318
397
  if (!args.skipLocalCleanup) {
@@ -100,10 +100,17 @@ export async function ensureLakebaseSecretAuth(
100
100
  throw new Error("databricks tokens create returned no token_value");
101
101
  }
102
102
 
103
- // 3. Store the PAT
104
- await runDatabricks(["secrets", "put-secret", scopeName, keyName, "--string-value", pat], {
103
+ // 3. Store the PAT. Feed the secret in a `--json @/dev/stdin` body (via opts.input)
104
+ // rather than a `--string-value <pat>` argv element, so the 90-day user PAT never
105
+ // appears in the process table / `ps`. The JSON MUST use `string_value`
106
+ // (not bytes_value): bare stdin would flip the CLI to a base64 `bytes_value` field,
107
+ // which the app then cannot read back as its Lakebase password at runtime. `pat` is
108
+ // already validated non-empty above, so the empty-stdin "silent success on no value"
109
+ // trap cannot occur here.
110
+ await runDatabricks(["secrets", "put-secret", "--json", "@/dev/stdin"], {
105
111
  profile,
106
112
  timeout: timeoutMs,
113
+ input: JSON.stringify({ scope: scopeName, key: keyName, string_value: pat }),
107
114
  });
108
115
 
109
116
  // 4. ACL (best-effort)
@@ -176,6 +176,16 @@ if [ "$#" -eq 0 ] && [ -f "$REPO_ROOT/client/package.json" ]; then
176
176
  ( cd "$REPO_ROOT/client" && npm install --include=dev )
177
177
  fi
178
178
  fi
179
+ # Strict typecheck BEFORE the tests, matching CI. CI builds the client with
180
+ # `tsc --noEmit && vite build` (strict), but the local test lanes run vitest +
181
+ # Playwright against the Vite dev server, which does NOT strict-typecheck the whole
182
+ # app — so a cross-story type regression (a later story making a field REQUIRED,
183
+ # breaking an earlier story's construction of that type) passed the local honest-GREEN
184
+ # + deploy feature-verify and was caught ONLY by CI, after promote. Run the SAME strict
185
+ # typecheck here so local GREEN matches CI. `--if-present` no-ops on an older scaffold
186
+ # with no `typecheck` script; a type error fails the run (set -e), exactly like a test.
187
+ echo "Running client strict typecheck (tsc --noEmit, matching CI's build)..."
188
+ ( cd "$REPO_ROOT/client" && npm run typecheck --if-present )
179
189
  echo "Running client unit tests (Vitest)..."
180
190
  ( cd "$REPO_ROOT/client" && npm test )
181
191
  fi