@fabricorg/databricks-testkit 0.2.1 → 0.2.3

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/dist/index.cjs CHANGED
@@ -562,7 +562,7 @@ async function runLiveSuite(spec, runtime = {}) {
562
562
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
563
563
  const ownedWarehouse = runtime.warehouse === void 0;
564
564
  const client = runtime.client ?? createClientFromEnv(env);
565
- const warehouse = runtime.warehouse ?? await createWorkspaceContext({ env, client });
565
+ const warehouse = runtime.warehouse ?? (hasWarehouseConfig(env) ? await createWorkspaceContext({ env, client }) : unavailableWarehouseContext());
566
566
  const results = [];
567
567
  try {
568
568
  for (const check of spec.checks) {
@@ -616,6 +616,24 @@ async function runLiveSuite(spec, runtime = {}) {
616
616
  if (spec.junitPath) await writeReport(spec.junitPath, renderJUnit(evidence));
617
617
  return evidence;
618
618
  }
619
+ function hasWarehouseConfig(env) {
620
+ return Boolean(env.DATABRICKS_WAREHOUSE_ID || env.DATABRICKS_HTTP_PATH);
621
+ }
622
+ function unavailableWarehouseContext() {
623
+ const unavailable = async () => {
624
+ throw new Error(
625
+ "This live check requires DATABRICKS_WAREHOUSE_ID or DATABRICKS_HTTP_PATH; REST-only checks can run without SQL warehouse configuration"
626
+ );
627
+ };
628
+ return {
629
+ profile: "live",
630
+ qual: (table) => table,
631
+ exec: unavailable,
632
+ query: unavailable,
633
+ loadFixture: unavailable,
634
+ close: async () => void 0
635
+ };
636
+ }
619
637
  async function writeReport(path$1, contents) {
620
638
  await promises.mkdir(path.dirname(path$1), { recursive: true });
621
639
  await promises.writeFile(path$1, contents, "utf8");
@@ -690,6 +708,7 @@ function sqlRoundTripCheck() {
690
708
  return {
691
709
  id: "sql",
692
710
  description: "SQL Statement Execution round-trip",
711
+ configured: (env) => Boolean(env.DATABRICKS_WAREHOUSE_ID || env.DATABRICKS_HTTP_PATH),
693
712
  async run({ warehouse }) {
694
713
  const rows = await warehouse.query("SELECT 1 AS dbx_test_ok");
695
714
  if (Number(rows[0]?.dbx_test_ok) !== 1)
@@ -1298,6 +1317,7 @@ function failureRecoveryCheck() {
1298
1317
  return {
1299
1318
  id: "failure-recovery",
1300
1319
  description: "A failed statement is isolated and a subsequent statement recovers",
1320
+ configured: (env) => Boolean(env.DATABRICKS_WAREHOUSE_ID || env.DATABRICKS_HTTP_PATH),
1301
1321
  async run({ warehouse }) {
1302
1322
  let failedAsExpected = false;
1303
1323
  try {
@@ -1343,6 +1363,7 @@ function backupRestoreCheck() {
1343
1363
  return {
1344
1364
  id: "backup-restore",
1345
1365
  description: "Delta DEEP CLONE backup restores a dropped scratch table",
1366
+ configured: (env) => Boolean(env.DATABRICKS_WAREHOUSE_ID || env.DATABRICKS_HTTP_PATH),
1346
1367
  async run({ warehouse }) {
1347
1368
  const source = warehouse.qual(safeName("backup_source"));
1348
1369
  const backup = warehouse.qual(safeName("backup_clone"));
@@ -1365,6 +1386,7 @@ function rollbackCheck() {
1365
1386
  return {
1366
1387
  id: "rollback",
1367
1388
  description: "Delta time-travel rollback restores a known-good table version",
1389
+ configured: (env) => Boolean(env.DATABRICKS_WAREHOUSE_ID || env.DATABRICKS_HTTP_PATH),
1368
1390
  async run({ warehouse }) {
1369
1391
  const table = warehouse.qual(safeName("rollback_probe"));
1370
1392
  try {
@@ -1412,6 +1434,9 @@ function classicComputeCheck() {
1412
1434
  env.DBX_TEST_CLASSIC_SPARK_VERSION && env.DBX_TEST_CLASSIC_NODE_TYPE && env.DBX_TEST_NOTEBOOK_PATH
1413
1435
  ),
1414
1436
  async run({ env, client }) {
1437
+ const numWorkers = Number(env.DBX_TEST_CLASSIC_WORKERS ?? 1);
1438
+ const alternateNodeTypes = (env.DBX_TEST_CLASSIC_ALTERNATE_NODE_TYPES ?? "").split(",").map((value) => value.trim()).filter(Boolean);
1439
+ const singleNode = numWorkers === 0;
1415
1440
  const submitted = await client.post("/api/2.1/jobs/runs/submit", {
1416
1441
  run_name: `fabric-experiments-classic-certification-${Date.now()}`,
1417
1442
  tasks: [
@@ -1420,9 +1445,24 @@ function classicComputeCheck() {
1420
1445
  new_cluster: {
1421
1446
  spark_version: env.DBX_TEST_CLASSIC_SPARK_VERSION,
1422
1447
  node_type_id: env.DBX_TEST_CLASSIC_NODE_TYPE,
1423
- num_workers: Number(env.DBX_TEST_CLASSIC_WORKERS ?? 1),
1424
- autotermination_minutes: 10,
1425
- data_security_mode: env.DBX_TEST_CLASSIC_SECURITY_MODE ?? "SINGLE_USER"
1448
+ num_workers: numWorkers,
1449
+ data_security_mode: env.DBX_TEST_CLASSIC_SECURITY_MODE ?? "SINGLE_USER",
1450
+ ...env.DBX_TEST_CLASSIC_SINGLE_USER_NAME ? { single_user_name: env.DBX_TEST_CLASSIC_SINGLE_USER_NAME } : {},
1451
+ ...singleNode ? {
1452
+ spark_conf: {
1453
+ "spark.databricks.cluster.profile": "singleNode",
1454
+ "spark.master": "local[*]"
1455
+ },
1456
+ custom_tags: { ResourceClass: "SingleNode" }
1457
+ } : {},
1458
+ ...alternateNodeTypes.length ? {
1459
+ worker_node_type_flexibility: {
1460
+ alternate_node_type_ids: alternateNodeTypes
1461
+ },
1462
+ driver_node_type_flexibility: {
1463
+ alternate_node_type_ids: alternateNodeTypes
1464
+ }
1465
+ } : {}
1426
1466
  },
1427
1467
  notebook_task: { notebook_path: env.DBX_TEST_NOTEBOOK_PATH }
1428
1468
  }
@@ -1435,7 +1475,10 @@ function classicComputeCheck() {
1435
1475
  });
1436
1476
  const result = run.state?.result_state;
1437
1477
  if (result !== "SUCCESS") {
1438
- throw new Error(`Classic compute run ended in ${result ?? "UNKNOWN"}`);
1478
+ const message = run.state?.state_message;
1479
+ throw new Error(
1480
+ `Classic compute run ${submitted.run_id} ended in ${result ?? "UNKNOWN"}${message ? `: ${message}` : ""}`
1481
+ );
1439
1482
  }
1440
1483
  return {
1441
1484
  runId: submitted.run_id,