@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.js CHANGED
@@ -150,7 +150,7 @@ async function runLiveSuite(spec, runtime = {}) {
150
150
  const startedAt = (/* @__PURE__ */ new Date()).toISOString();
151
151
  const ownedWarehouse = runtime.warehouse === void 0;
152
152
  const client = runtime.client ?? createClientFromEnv(env);
153
- const warehouse = runtime.warehouse ?? await createWorkspaceContext({ env, client });
153
+ const warehouse = runtime.warehouse ?? (hasWarehouseConfig(env) ? await createWorkspaceContext({ env, client }) : unavailableWarehouseContext());
154
154
  const results = [];
155
155
  try {
156
156
  for (const check of spec.checks) {
@@ -204,6 +204,24 @@ async function runLiveSuite(spec, runtime = {}) {
204
204
  if (spec.junitPath) await writeReport(spec.junitPath, renderJUnit(evidence));
205
205
  return evidence;
206
206
  }
207
+ function hasWarehouseConfig(env) {
208
+ return Boolean(env.DATABRICKS_WAREHOUSE_ID || env.DATABRICKS_HTTP_PATH);
209
+ }
210
+ function unavailableWarehouseContext() {
211
+ const unavailable = async () => {
212
+ throw new Error(
213
+ "This live check requires DATABRICKS_WAREHOUSE_ID or DATABRICKS_HTTP_PATH; REST-only checks can run without SQL warehouse configuration"
214
+ );
215
+ };
216
+ return {
217
+ profile: "live",
218
+ qual: (table) => table,
219
+ exec: unavailable,
220
+ query: unavailable,
221
+ loadFixture: unavailable,
222
+ close: async () => void 0
223
+ };
224
+ }
207
225
  async function writeReport(path, contents) {
208
226
  await mkdir(dirname(path), { recursive: true });
209
227
  await writeFile(path, contents, "utf8");
@@ -278,6 +296,7 @@ function sqlRoundTripCheck() {
278
296
  return {
279
297
  id: "sql",
280
298
  description: "SQL Statement Execution round-trip",
299
+ configured: (env) => Boolean(env.DATABRICKS_WAREHOUSE_ID || env.DATABRICKS_HTTP_PATH),
281
300
  async run({ warehouse }) {
282
301
  const rows = await warehouse.query("SELECT 1 AS dbx_test_ok");
283
302
  if (Number(rows[0]?.dbx_test_ok) !== 1)
@@ -881,6 +900,7 @@ function failureRecoveryCheck() {
881
900
  return {
882
901
  id: "failure-recovery",
883
902
  description: "A failed statement is isolated and a subsequent statement recovers",
903
+ configured: (env) => Boolean(env.DATABRICKS_WAREHOUSE_ID || env.DATABRICKS_HTTP_PATH),
884
904
  async run({ warehouse }) {
885
905
  let failedAsExpected = false;
886
906
  try {
@@ -926,6 +946,7 @@ function backupRestoreCheck() {
926
946
  return {
927
947
  id: "backup-restore",
928
948
  description: "Delta DEEP CLONE backup restores a dropped scratch table",
949
+ configured: (env) => Boolean(env.DATABRICKS_WAREHOUSE_ID || env.DATABRICKS_HTTP_PATH),
929
950
  async run({ warehouse }) {
930
951
  const source = warehouse.qual(safeName("backup_source"));
931
952
  const backup = warehouse.qual(safeName("backup_clone"));
@@ -948,6 +969,7 @@ function rollbackCheck() {
948
969
  return {
949
970
  id: "rollback",
950
971
  description: "Delta time-travel rollback restores a known-good table version",
972
+ configured: (env) => Boolean(env.DATABRICKS_WAREHOUSE_ID || env.DATABRICKS_HTTP_PATH),
951
973
  async run({ warehouse }) {
952
974
  const table = warehouse.qual(safeName("rollback_probe"));
953
975
  try {
@@ -995,6 +1017,9 @@ function classicComputeCheck() {
995
1017
  env.DBX_TEST_CLASSIC_SPARK_VERSION && env.DBX_TEST_CLASSIC_NODE_TYPE && env.DBX_TEST_NOTEBOOK_PATH
996
1018
  ),
997
1019
  async run({ env, client }) {
1020
+ const numWorkers = Number(env.DBX_TEST_CLASSIC_WORKERS ?? 1);
1021
+ const alternateNodeTypes = (env.DBX_TEST_CLASSIC_ALTERNATE_NODE_TYPES ?? "").split(",").map((value) => value.trim()).filter(Boolean);
1022
+ const singleNode = numWorkers === 0;
998
1023
  const submitted = await client.post("/api/2.1/jobs/runs/submit", {
999
1024
  run_name: `fabric-experiments-classic-certification-${Date.now()}`,
1000
1025
  tasks: [
@@ -1003,9 +1028,24 @@ function classicComputeCheck() {
1003
1028
  new_cluster: {
1004
1029
  spark_version: env.DBX_TEST_CLASSIC_SPARK_VERSION,
1005
1030
  node_type_id: env.DBX_TEST_CLASSIC_NODE_TYPE,
1006
- num_workers: Number(env.DBX_TEST_CLASSIC_WORKERS ?? 1),
1007
- autotermination_minutes: 10,
1008
- data_security_mode: env.DBX_TEST_CLASSIC_SECURITY_MODE ?? "SINGLE_USER"
1031
+ num_workers: numWorkers,
1032
+ data_security_mode: env.DBX_TEST_CLASSIC_SECURITY_MODE ?? "SINGLE_USER",
1033
+ ...env.DBX_TEST_CLASSIC_SINGLE_USER_NAME ? { single_user_name: env.DBX_TEST_CLASSIC_SINGLE_USER_NAME } : {},
1034
+ ...singleNode ? {
1035
+ spark_conf: {
1036
+ "spark.databricks.cluster.profile": "singleNode",
1037
+ "spark.master": "local[*]"
1038
+ },
1039
+ custom_tags: { ResourceClass: "SingleNode" }
1040
+ } : {},
1041
+ ...alternateNodeTypes.length ? {
1042
+ worker_node_type_flexibility: {
1043
+ alternate_node_type_ids: alternateNodeTypes
1044
+ },
1045
+ driver_node_type_flexibility: {
1046
+ alternate_node_type_ids: alternateNodeTypes
1047
+ }
1048
+ } : {}
1009
1049
  },
1010
1050
  notebook_task: { notebook_path: env.DBX_TEST_NOTEBOOK_PATH }
1011
1051
  }
@@ -1018,7 +1058,10 @@ function classicComputeCheck() {
1018
1058
  });
1019
1059
  const result = run.state?.result_state;
1020
1060
  if (result !== "SUCCESS") {
1021
- throw new Error(`Classic compute run ended in ${result ?? "UNKNOWN"}`);
1061
+ const message = run.state?.state_message;
1062
+ throw new Error(
1063
+ `Classic compute run ${submitted.run_id} ended in ${result ?? "UNKNOWN"}${message ? `: ${message}` : ""}`
1064
+ );
1022
1065
  }
1023
1066
  return {
1024
1067
  runId: submitted.run_id,