@fabricorg/experiments 0.6.4 → 0.7.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.
- package/README.md +27 -2
- package/dist/bin/fx.cjs +488 -42
- package/dist/bin/fx.cjs.map +1 -1
- package/dist/bin/fx.js +489 -43
- package/dist/bin/fx.js.map +1 -1
- package/package.json +2 -2
package/dist/bin/fx.js
CHANGED
|
@@ -2,13 +2,17 @@
|
|
|
2
2
|
import { realpathSync, existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
3
3
|
import { resolve, join, basename, dirname, extname } from 'path';
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
|
-
import { mkdir, writeFile, readFile, copyFile, access, readdir, stat } from 'fs/promises';
|
|
5
|
+
import { mkdir, writeFile, readFile, copyFile, access, readdir, stat, rename, chmod, unlink } from 'fs/promises';
|
|
6
6
|
import { parse, stringify } from 'yaml';
|
|
7
7
|
import { randomUUID, webcrypto, createHash } from 'crypto';
|
|
8
8
|
import { createServer } from 'http';
|
|
9
9
|
import { createRequire } from 'module';
|
|
10
10
|
import { createWorkspaceContext, deleteEphemeralLakebaseBranch, createEphemeralLakebaseBranch, toLakebaseBranchId } from '@fabricorg/databricks-testkit';
|
|
11
11
|
import { XMLParser } from 'fast-xml-parser';
|
|
12
|
+
import { execFile } from 'child_process';
|
|
13
|
+
import { homedir } from 'os';
|
|
14
|
+
import { promisify } from 'util';
|
|
15
|
+
import { stdin, stderr } from 'process';
|
|
12
16
|
|
|
13
17
|
var __defProp = Object.defineProperty;
|
|
14
18
|
var __export = (target, all) => {
|
|
@@ -7434,6 +7438,39 @@ var AuditEvent = external_exports.object({
|
|
|
7434
7438
|
payload: external_exports.record(external_exports.unknown())
|
|
7435
7439
|
});
|
|
7436
7440
|
var AuditListResponse = external_exports.object({ events: external_exports.array(AuditEvent) });
|
|
7441
|
+
var GovernanceSettings = external_exports.object({
|
|
7442
|
+
requireQualityForProduction: external_exports.boolean(),
|
|
7443
|
+
requiredQualitySuites: external_exports.array(external_exports.string().min(1).max(240)).max(50),
|
|
7444
|
+
qualityMaxAgeHours: external_exports.number().int().min(1).max(8760),
|
|
7445
|
+
retentionDays: external_exports.number().int().min(30).max(3650),
|
|
7446
|
+
legalHold: external_exports.boolean(),
|
|
7447
|
+
updatedBy: external_exports.string().nullable(),
|
|
7448
|
+
updatedAt: external_exports.string().datetime().nullable()
|
|
7449
|
+
});
|
|
7450
|
+
var UpdateGovernanceSettingsInput = GovernanceSettings.pick({
|
|
7451
|
+
requireQualityForProduction: true,
|
|
7452
|
+
requiredQualitySuites: true,
|
|
7453
|
+
qualityMaxAgeHours: true,
|
|
7454
|
+
retentionDays: true,
|
|
7455
|
+
legalHold: true
|
|
7456
|
+
});
|
|
7457
|
+
var QualityGateResult = external_exports.object({
|
|
7458
|
+
enabled: external_exports.boolean(),
|
|
7459
|
+
passed: external_exports.boolean(),
|
|
7460
|
+
checks: external_exports.array(
|
|
7461
|
+
external_exports.object({
|
|
7462
|
+
suite: external_exports.string(),
|
|
7463
|
+
passed: external_exports.boolean(),
|
|
7464
|
+
reason: external_exports.string(),
|
|
7465
|
+
runId: external_exports.string().nullable(),
|
|
7466
|
+
finishedAt: external_exports.string().datetime().nullable()
|
|
7467
|
+
})
|
|
7468
|
+
)
|
|
7469
|
+
});
|
|
7470
|
+
var GovernanceStatusResponse = external_exports.object({
|
|
7471
|
+
settings: GovernanceSettings,
|
|
7472
|
+
qualityGate: QualityGateResult
|
|
7473
|
+
});
|
|
7437
7474
|
var AuditExport = external_exports.object({
|
|
7438
7475
|
id: external_exports.string(),
|
|
7439
7476
|
destinationKind: external_exports.enum(["s3", "r2", "splunk-hec"]),
|
|
@@ -7540,7 +7577,8 @@ var TestRunListInput = external_exports.object({
|
|
|
7540
7577
|
status: TestRunStatus.optional(),
|
|
7541
7578
|
source: CreateTestRunInput.shape.source.optional(),
|
|
7542
7579
|
suite: external_exports.string().min(1).max(240).optional(),
|
|
7543
|
-
limit: external_exports.coerce.number().int().min(1).max(200).optional()
|
|
7580
|
+
limit: external_exports.coerce.number().int().min(1).max(200).optional(),
|
|
7581
|
+
offset: external_exports.coerce.number().int().min(0).max(1e5).optional()
|
|
7544
7582
|
});
|
|
7545
7583
|
var TestRunListResponse = external_exports.object({
|
|
7546
7584
|
runs: external_exports.array(TestRun.omit({ cases: true }))
|
|
@@ -7754,6 +7792,22 @@ var endpoints = {
|
|
|
7754
7792
|
mutates: false,
|
|
7755
7793
|
requiresRole: "viewer"
|
|
7756
7794
|
},
|
|
7795
|
+
"governance.get": {
|
|
7796
|
+
method: "GET",
|
|
7797
|
+
path: "/v1/orgs/:orgId/governance",
|
|
7798
|
+
params: Empty,
|
|
7799
|
+
response: GovernanceStatusResponse,
|
|
7800
|
+
mutates: false,
|
|
7801
|
+
requiresRole: "viewer"
|
|
7802
|
+
},
|
|
7803
|
+
"governance.update": {
|
|
7804
|
+
method: "POST",
|
|
7805
|
+
path: "/v1/orgs/:orgId/governance",
|
|
7806
|
+
params: UpdateGovernanceSettingsInput,
|
|
7807
|
+
response: GovernanceStatusResponse,
|
|
7808
|
+
mutates: true,
|
|
7809
|
+
requiresRole: "admin"
|
|
7810
|
+
},
|
|
7757
7811
|
"audit.exports.list": {
|
|
7758
7812
|
method: "GET",
|
|
7759
7813
|
path: "/v1/orgs/:orgId/audit/exports",
|
|
@@ -8005,6 +8059,10 @@ var ApiClient = class {
|
|
|
8005
8059
|
audit = {
|
|
8006
8060
|
list: (orgId) => this.call("audit.list", {}, orgId ? { orgId } : void 0)
|
|
8007
8061
|
};
|
|
8062
|
+
governance = {
|
|
8063
|
+
get: (orgId) => this.call("governance.get", {}, orgId ? { orgId } : void 0),
|
|
8064
|
+
update: (params, orgId) => this.call("governance.update", params, orgId ? { orgId } : void 0)
|
|
8065
|
+
};
|
|
8008
8066
|
preview = {
|
|
8009
8067
|
sign: (params, orgId) => this.call("preview.sign", params, orgId ? { orgId } : void 0)
|
|
8010
8068
|
};
|
|
@@ -8052,6 +8110,7 @@ async function cmdPreview(experimentId, options) {
|
|
|
8052
8110
|
const client = new ApiClient({
|
|
8053
8111
|
baseUrl: options.apiUrl,
|
|
8054
8112
|
apiKey: options.apiKey,
|
|
8113
|
+
bearerToken: options.bearerToken,
|
|
8055
8114
|
defaultOrgId: tenantId
|
|
8056
8115
|
});
|
|
8057
8116
|
const r = await client.call(
|
|
@@ -8138,7 +8197,12 @@ async function cmdPush(dir, options = {}) {
|
|
|
8138
8197
|
);
|
|
8139
8198
|
return 1;
|
|
8140
8199
|
}
|
|
8141
|
-
const api = new ApiClient({
|
|
8200
|
+
const api = new ApiClient({
|
|
8201
|
+
baseUrl: apiUrl,
|
|
8202
|
+
apiKey,
|
|
8203
|
+
bearerToken: options.bearerToken,
|
|
8204
|
+
defaultOrgId: tenantId
|
|
8205
|
+
});
|
|
8142
8206
|
const specs = (await loadExperimentDir(resolve(dir))).map((s) => s.spec);
|
|
8143
8207
|
const summaries = (await api.experiments.list()).experiments;
|
|
8144
8208
|
const current = [];
|
|
@@ -8523,6 +8587,141 @@ async function writeState(path, state) {
|
|
|
8523
8587
|
await writeFile(path, `${JSON.stringify(state, null, 2)}
|
|
8524
8588
|
`, "utf8");
|
|
8525
8589
|
}
|
|
8590
|
+
var execFileAsync = promisify(execFile);
|
|
8591
|
+
function defaultConfigPath(env = process.env) {
|
|
8592
|
+
const configDir = env.FX_CONFIG_DIR ?? (process.platform === "win32" ? join(env.APPDATA ?? homedir(), "Fabric Experiments") : join(env.XDG_CONFIG_HOME ?? join(homedir(), ".config"), "fabric-experiments"));
|
|
8593
|
+
return join(configDir, "config.json");
|
|
8594
|
+
}
|
|
8595
|
+
async function loadHostedConfig(path = defaultConfigPath()) {
|
|
8596
|
+
try {
|
|
8597
|
+
const parsed = JSON.parse(await readFile(path, "utf8"));
|
|
8598
|
+
return {
|
|
8599
|
+
version: 1,
|
|
8600
|
+
activeProfile: parsed.activeProfile,
|
|
8601
|
+
profiles: parsed.profiles ?? {}
|
|
8602
|
+
};
|
|
8603
|
+
} catch (error) {
|
|
8604
|
+
if (error.code === "ENOENT") {
|
|
8605
|
+
return { version: 1, profiles: {} };
|
|
8606
|
+
}
|
|
8607
|
+
throw new Error(`Unable to read Fabric CLI config at ${path}: ${error.message}`);
|
|
8608
|
+
}
|
|
8609
|
+
}
|
|
8610
|
+
async function saveHostedConfig(config, path = defaultConfigPath()) {
|
|
8611
|
+
await mkdir(dirname(path), { recursive: true, mode: 448 });
|
|
8612
|
+
const temporary = `${path}.${process.pid}.tmp`;
|
|
8613
|
+
await writeFile(temporary, `${JSON.stringify(config, null, 2)}
|
|
8614
|
+
`, { mode: 384 });
|
|
8615
|
+
await rename(temporary, path);
|
|
8616
|
+
await chmod(path, 384);
|
|
8617
|
+
}
|
|
8618
|
+
async function removeHostedProfile(profileName, path = defaultConfigPath()) {
|
|
8619
|
+
const config = await loadHostedConfig(path);
|
|
8620
|
+
if (!config.profiles[profileName]) return false;
|
|
8621
|
+
delete config.profiles[profileName];
|
|
8622
|
+
if (config.activeProfile === profileName) {
|
|
8623
|
+
config.activeProfile = Object.keys(config.profiles).sort()[0];
|
|
8624
|
+
}
|
|
8625
|
+
if (Object.keys(config.profiles).length === 0) {
|
|
8626
|
+
try {
|
|
8627
|
+
await unlink(path);
|
|
8628
|
+
} catch (error) {
|
|
8629
|
+
if (error.code !== "ENOENT") throw error;
|
|
8630
|
+
}
|
|
8631
|
+
return true;
|
|
8632
|
+
}
|
|
8633
|
+
await saveHostedConfig(config, path);
|
|
8634
|
+
return true;
|
|
8635
|
+
}
|
|
8636
|
+
async function configPermissionsArePrivate(path = defaultConfigPath()) {
|
|
8637
|
+
if (process.platform === "win32") return true;
|
|
8638
|
+
try {
|
|
8639
|
+
const details = await stat(path);
|
|
8640
|
+
return (details.mode & 63) === 0;
|
|
8641
|
+
} catch (error) {
|
|
8642
|
+
if (error.code === "ENOENT") return true;
|
|
8643
|
+
throw error;
|
|
8644
|
+
}
|
|
8645
|
+
}
|
|
8646
|
+
async function resolveHostedContext(options = {}) {
|
|
8647
|
+
const env = options.env ?? process.env;
|
|
8648
|
+
const config = await loadHostedConfig(options.configPath ?? defaultConfigPath(env));
|
|
8649
|
+
const profileName = options.profileName ?? env.FX_PROFILE ?? config.activeProfile;
|
|
8650
|
+
const profile = profileName ? config.profiles[profileName] : void 0;
|
|
8651
|
+
const apiUrl = options.apiUrl ?? env.FX_API_URL ?? profile?.apiUrl;
|
|
8652
|
+
const apiKey = options.apiKey ?? env.FX_API_KEY ?? profile?.apiKey;
|
|
8653
|
+
const tenantId = options.tenantId ?? env.FX_ORG_ID ?? profile?.orgId;
|
|
8654
|
+
const bearerToken = options.bearerToken ?? (apiUrl ? await resolveGatewayBearer(apiUrl, {
|
|
8655
|
+
env,
|
|
8656
|
+
databricksProfile: profile?.databricksProfile,
|
|
8657
|
+
tokenProvider: options.tokenProvider
|
|
8658
|
+
}) : void 0);
|
|
8659
|
+
return { profileName, apiUrl, apiKey, tenantId, bearerToken };
|
|
8660
|
+
}
|
|
8661
|
+
async function resolveStudioApiUrl(studioUrl, fetchImpl = globalThis.fetch) {
|
|
8662
|
+
const source = new URL(studioUrl);
|
|
8663
|
+
const response = await fetchImpl(source.toString(), { method: "HEAD", redirect: "manual" });
|
|
8664
|
+
const location = response.headers.get("location");
|
|
8665
|
+
const target = location ? new URL(location, source) : source;
|
|
8666
|
+
target.pathname = "/api";
|
|
8667
|
+
target.search = "";
|
|
8668
|
+
target.hash = "";
|
|
8669
|
+
return target.toString().replace(/\/$/, "");
|
|
8670
|
+
}
|
|
8671
|
+
async function resolveGatewayBearer(apiUrl, options = {}) {
|
|
8672
|
+
const env = options.env ?? process.env;
|
|
8673
|
+
if (env.FX_GATEWAY_BEARER_TOKEN) return env.FX_GATEWAY_BEARER_TOKEN;
|
|
8674
|
+
if (!new URL(apiUrl).hostname.endsWith(".databricksapps.com")) return void 0;
|
|
8675
|
+
const databricksProfile = options.databricksProfile ?? env.FX_DATABRICKS_PROFILE;
|
|
8676
|
+
if (databricksProfile) {
|
|
8677
|
+
return (options.tokenProvider ?? databricksCliToken)(databricksProfile);
|
|
8678
|
+
}
|
|
8679
|
+
const host = env.DATABRICKS_HOST?.replace(/\/$/, "");
|
|
8680
|
+
const clientId = env.FX_QUALITY_DATABRICKS_CLIENT_ID ?? env.DATABRICKS_CLIENT_ID;
|
|
8681
|
+
const clientSecret = env.FX_QUALITY_DATABRICKS_CLIENT_SECRET ?? env.DATABRICKS_CLIENT_SECRET;
|
|
8682
|
+
if (!host || !clientId || !clientSecret) {
|
|
8683
|
+
try {
|
|
8684
|
+
return await (options.tokenProvider ?? databricksCliToken)();
|
|
8685
|
+
} catch {
|
|
8686
|
+
throw new Error(
|
|
8687
|
+
"Databricks Apps access requires a Databricks CLI login, --databricks-profile, FX_DATABRICKS_PROFILE, or DATABRICKS_HOST with client credentials"
|
|
8688
|
+
);
|
|
8689
|
+
}
|
|
8690
|
+
}
|
|
8691
|
+
const response = await fetch(`${host}/oidc/v1/token`, {
|
|
8692
|
+
method: "POST",
|
|
8693
|
+
headers: {
|
|
8694
|
+
authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString("base64")}`,
|
|
8695
|
+
"content-type": "application/x-www-form-urlencoded"
|
|
8696
|
+
},
|
|
8697
|
+
body: new URLSearchParams({ grant_type: "client_credentials", scope: "all-apis" })
|
|
8698
|
+
});
|
|
8699
|
+
if (!response.ok) {
|
|
8700
|
+
throw new Error(`Databricks OAuth failed (${response.status} ${response.statusText})`);
|
|
8701
|
+
}
|
|
8702
|
+
const body = await response.json();
|
|
8703
|
+
if (typeof body.access_token !== "string" || !body.access_token) {
|
|
8704
|
+
throw new Error("Databricks OAuth response did not include an access token");
|
|
8705
|
+
}
|
|
8706
|
+
return body.access_token;
|
|
8707
|
+
}
|
|
8708
|
+
async function databricksCliToken(profile) {
|
|
8709
|
+
try {
|
|
8710
|
+
const args = ["auth", "token", ...profile ? [profile] : [], "--output", "json"];
|
|
8711
|
+
const { stdout } = await execFileAsync("databricks", args, { encoding: "utf8" });
|
|
8712
|
+
const parsed = JSON.parse(stdout);
|
|
8713
|
+
if (typeof parsed.access_token !== "string" || !parsed.access_token) {
|
|
8714
|
+
throw new Error("token response did not include access_token");
|
|
8715
|
+
}
|
|
8716
|
+
return parsed.access_token;
|
|
8717
|
+
} catch (error) {
|
|
8718
|
+
throw new Error(
|
|
8719
|
+
`Unable to obtain a Databricks token${profile ? ` for profile ${profile}` : ""}: ${error.message}`
|
|
8720
|
+
);
|
|
8721
|
+
}
|
|
8722
|
+
}
|
|
8723
|
+
|
|
8724
|
+
// src/commands/test-publish.ts
|
|
8526
8725
|
async function cmdTestPublish(evidencePath, options = {}) {
|
|
8527
8726
|
const env = options.env ?? process.env;
|
|
8528
8727
|
const apiUrl = options.apiUrl ?? env.FX_API_URL;
|
|
@@ -8551,30 +8750,7 @@ async function cmdTestPublish(evidencePath, options = {}) {
|
|
|
8551
8750
|
return 0;
|
|
8552
8751
|
}
|
|
8553
8752
|
async function resolveGatewayToken(apiUrl, env) {
|
|
8554
|
-
|
|
8555
|
-
if (!new URL(apiUrl).hostname.endsWith(".databricksapps.com")) return void 0;
|
|
8556
|
-
const host = env.DATABRICKS_HOST?.replace(/\/$/, "");
|
|
8557
|
-
const clientId = env.FX_QUALITY_DATABRICKS_CLIENT_ID ?? env.DATABRICKS_CLIENT_ID;
|
|
8558
|
-
const clientSecret = env.FX_QUALITY_DATABRICKS_CLIENT_SECRET ?? env.DATABRICKS_CLIENT_SECRET;
|
|
8559
|
-
if (!host || !clientId || !clientSecret) {
|
|
8560
|
-
throw new Error("Databricks Apps publication requires DATABRICKS_HOST and client credentials");
|
|
8561
|
-
}
|
|
8562
|
-
const response = await fetch(`${host}/oidc/v1/token`, {
|
|
8563
|
-
method: "POST",
|
|
8564
|
-
headers: {
|
|
8565
|
-
authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString("base64")}`,
|
|
8566
|
-
"content-type": "application/x-www-form-urlencoded"
|
|
8567
|
-
},
|
|
8568
|
-
body: new URLSearchParams({ grant_type: "client_credentials", scope: "all-apis" })
|
|
8569
|
-
});
|
|
8570
|
-
if (!response.ok) {
|
|
8571
|
-
throw new Error(`Databricks OAuth failed (${response.status} ${response.statusText})`);
|
|
8572
|
-
}
|
|
8573
|
-
const body = await response.json();
|
|
8574
|
-
if (typeof body.access_token !== "string" || !body.access_token) {
|
|
8575
|
-
throw new Error("Databricks OAuth response did not include an access token");
|
|
8576
|
-
}
|
|
8577
|
-
return body.access_token;
|
|
8753
|
+
return resolveGatewayBearer(apiUrl, { env });
|
|
8578
8754
|
}
|
|
8579
8755
|
function normalizeTestEvidence(value, options = {}) {
|
|
8580
8756
|
if (!value || typeof value !== "object") throw new Error("Evidence must be a JSON object");
|
|
@@ -8659,6 +8835,42 @@ function normalizeTestEvidence(value, options = {}) {
|
|
|
8659
8835
|
artifacts
|
|
8660
8836
|
};
|
|
8661
8837
|
}
|
|
8838
|
+
if (kind === "fabric-cli" || kind === "cli") {
|
|
8839
|
+
const cases = arrayOfRecords(evidence.cases).map((testCase, index) => ({
|
|
8840
|
+
id: String(testCase.id ?? `cli:${index}`),
|
|
8841
|
+
name: String(testCase.name ?? `CLI check ${index + 1}`),
|
|
8842
|
+
...typeof testCase.uri === "string" ? { uri: testCase.uri } : {},
|
|
8843
|
+
status: normalizeCaseStatus(testCase.status),
|
|
8844
|
+
durationMs: nonnegativeNumber(testCase.durationMs),
|
|
8845
|
+
tags: Array.isArray(testCase.tags) ? testCase.tags.map(String) : [],
|
|
8846
|
+
...typeof testCase.error === "string" ? { error: testCase.error } : {},
|
|
8847
|
+
...typeof testCase.statementId === "string" ? { statementId: testCase.statementId } : {},
|
|
8848
|
+
...typeof testCase.resourceUrl === "string" ? { resourceUrl: testCase.resourceUrl } : {},
|
|
8849
|
+
...testCase.details && typeof testCase.details === "object" ? { details: testCase.details } : {}
|
|
8850
|
+
}));
|
|
8851
|
+
const summary = summarize(cases);
|
|
8852
|
+
const requestedStatus = String(evidence.status ?? "").toLowerCase();
|
|
8853
|
+
const status = ["running", "passed", "failed", "skipped", "canceled"].includes(requestedStatus) ? requestedStatus : evidence.success === false || summary.failed > 0 ? "failed" : summary.total > 0 && summary.total === summary.skipped ? "skipped" : "passed";
|
|
8854
|
+
return {
|
|
8855
|
+
...externalId ? { externalId } : {},
|
|
8856
|
+
source: "cli",
|
|
8857
|
+
suite: options.suite ?? String(evidence.suite ?? "Fabric CLI checks"),
|
|
8858
|
+
status,
|
|
8859
|
+
startedAt: isoOrNull(evidence.startedAt),
|
|
8860
|
+
finishedAt: isoOrNull(evidence.finishedAt) ?? (/* @__PURE__ */ new Date()).toISOString(),
|
|
8861
|
+
durationMs: nonnegativeNumber(
|
|
8862
|
+
evidence.durationMs ?? cases.reduce((sum, item) => sum + item.durationMs, 0)
|
|
8863
|
+
),
|
|
8864
|
+
summary,
|
|
8865
|
+
environment: {
|
|
8866
|
+
...objectOf(evidence.environment),
|
|
8867
|
+
...compact({ profile: env.DBX_TEST_PROFILE, workspace: env.DATABRICKS_HOST })
|
|
8868
|
+
},
|
|
8869
|
+
revision: { ...objectOf(evidence.revision), ...revision },
|
|
8870
|
+
cases,
|
|
8871
|
+
artifacts
|
|
8872
|
+
};
|
|
8873
|
+
}
|
|
8662
8874
|
if (kind === "junit") {
|
|
8663
8875
|
const cases = arrayOfRecords(evidence.cases).map((testCase, index) => ({
|
|
8664
8876
|
id: String(testCase.id ?? `junit:${index}`),
|
|
@@ -8761,6 +8973,9 @@ function xmlText(value) {
|
|
|
8761
8973
|
function compact(value) {
|
|
8762
8974
|
return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== void 0));
|
|
8763
8975
|
}
|
|
8976
|
+
function objectOf(value) {
|
|
8977
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
8978
|
+
}
|
|
8764
8979
|
function nonnegativeNumber(value) {
|
|
8765
8980
|
const number = Number(value ?? 0);
|
|
8766
8981
|
return Number.isFinite(number) && number >= 0 ? Math.round(number) : 0;
|
|
@@ -8769,6 +8984,188 @@ function isoOrNull(value) {
|
|
|
8769
8984
|
if (typeof value !== "string" || Number.isNaN(Date.parse(value))) return null;
|
|
8770
8985
|
return new Date(value).toISOString();
|
|
8771
8986
|
}
|
|
8987
|
+
async function cmdLogin(options = {}) {
|
|
8988
|
+
const env = options.env ?? process.env;
|
|
8989
|
+
const profileName = options.profileName ?? "production";
|
|
8990
|
+
const apiUrl = options.apiUrl ? normalizeApiUrl(options.apiUrl) : await resolveStudioApiUrl(
|
|
8991
|
+
options.studioUrl ?? "https://studio.experiments.fabric.pro",
|
|
8992
|
+
options.fetchImpl
|
|
8993
|
+
);
|
|
8994
|
+
const apiKey = options.apiKey ?? env.FX_API_KEY ?? await (options.promptSecret ?? readSecretApiKey)();
|
|
8995
|
+
if (!apiKey) throw new Error("A Fabric API key is required");
|
|
8996
|
+
const bearerToken = await resolveGatewayBearer(apiUrl, {
|
|
8997
|
+
env,
|
|
8998
|
+
databricksProfile: options.databricksProfile,
|
|
8999
|
+
tokenProvider: options.tokenProvider
|
|
9000
|
+
});
|
|
9001
|
+
const client = new ApiClient({
|
|
9002
|
+
baseUrl: apiUrl,
|
|
9003
|
+
apiKey,
|
|
9004
|
+
bearerToken,
|
|
9005
|
+
fetchImpl: options.fetchImpl
|
|
9006
|
+
});
|
|
9007
|
+
const tenant = await client.tenants.me();
|
|
9008
|
+
if (options.tenantId && options.tenantId !== tenant.organization.id) {
|
|
9009
|
+
throw new Error(
|
|
9010
|
+
`API key belongs to ${tenant.organization.id}, not requested organization ${options.tenantId}`
|
|
9011
|
+
);
|
|
9012
|
+
}
|
|
9013
|
+
const now3 = (/* @__PURE__ */ new Date()).toISOString();
|
|
9014
|
+
const path = options.configPath ?? defaultConfigPath(env);
|
|
9015
|
+
const config = await loadHostedConfig(path);
|
|
9016
|
+
const existing = config.profiles[profileName];
|
|
9017
|
+
config.profiles[profileName] = {
|
|
9018
|
+
apiUrl,
|
|
9019
|
+
apiKey,
|
|
9020
|
+
orgId: tenant.organization.id,
|
|
9021
|
+
organizationName: tenant.organization.name,
|
|
9022
|
+
organizationSlug: tenant.organization.slug,
|
|
9023
|
+
role: tenant.member.role,
|
|
9024
|
+
databricksProfile: options.databricksProfile,
|
|
9025
|
+
createdAt: existing?.createdAt ?? now3,
|
|
9026
|
+
updatedAt: now3
|
|
9027
|
+
};
|
|
9028
|
+
config.activeProfile = profileName;
|
|
9029
|
+
await saveHostedConfig(config, path);
|
|
9030
|
+
process.stdout.write(
|
|
9031
|
+
`Logged in to ${tenant.organization.name} as ${tenant.member.role} (profile: ${profileName}).
|
|
9032
|
+
`
|
|
9033
|
+
);
|
|
9034
|
+
return 0;
|
|
9035
|
+
}
|
|
9036
|
+
async function cmdLogout(profileName, options = {}) {
|
|
9037
|
+
const env = options.env ?? process.env;
|
|
9038
|
+
const path = options.configPath ?? defaultConfigPath(env);
|
|
9039
|
+
const config = await loadHostedConfig(path);
|
|
9040
|
+
const target = profileName ?? config.activeProfile;
|
|
9041
|
+
if (!target) {
|
|
9042
|
+
process.stdout.write("No Fabric CLI profile is configured.\n");
|
|
9043
|
+
return 0;
|
|
9044
|
+
}
|
|
9045
|
+
const removed = await removeHostedProfile(target, path);
|
|
9046
|
+
process.stdout.write(
|
|
9047
|
+
removed ? `Logged out profile ${target}.
|
|
9048
|
+
` : `Profile ${target} not found.
|
|
9049
|
+
`
|
|
9050
|
+
);
|
|
9051
|
+
return removed ? 0 : 1;
|
|
9052
|
+
}
|
|
9053
|
+
async function cmdProfile(action = "list", profileName, options = {}) {
|
|
9054
|
+
const env = options.env ?? process.env;
|
|
9055
|
+
const path = options.configPath ?? defaultConfigPath(env);
|
|
9056
|
+
const config = await loadHostedConfig(path);
|
|
9057
|
+
if (action === "use") {
|
|
9058
|
+
if (!profileName || !config.profiles[profileName]) {
|
|
9059
|
+
process.stderr.write("Usage: fx profile use <name>\n");
|
|
9060
|
+
return 1;
|
|
9061
|
+
}
|
|
9062
|
+
config.activeProfile = profileName;
|
|
9063
|
+
await saveHostedConfig(config, path);
|
|
9064
|
+
process.stdout.write(`Active profile: ${profileName}
|
|
9065
|
+
`);
|
|
9066
|
+
return 0;
|
|
9067
|
+
}
|
|
9068
|
+
if (action === "show") {
|
|
9069
|
+
const selected = profileName ?? config.activeProfile;
|
|
9070
|
+
const profile = selected ? config.profiles[selected] : void 0;
|
|
9071
|
+
if (!selected || !profile) {
|
|
9072
|
+
process.stderr.write("No active Fabric CLI profile. Run fx login.\n");
|
|
9073
|
+
return 1;
|
|
9074
|
+
}
|
|
9075
|
+
process.stdout.write(formatProfile(selected, profile, selected === config.activeProfile));
|
|
9076
|
+
return 0;
|
|
9077
|
+
}
|
|
9078
|
+
const names = Object.keys(config.profiles).sort();
|
|
9079
|
+
if (names.length === 0) {
|
|
9080
|
+
process.stdout.write("No Fabric CLI profiles. Run fx login.\n");
|
|
9081
|
+
return 0;
|
|
9082
|
+
}
|
|
9083
|
+
for (const name of names) {
|
|
9084
|
+
process.stdout.write(
|
|
9085
|
+
formatProfile(name, config.profiles[name], name === config.activeProfile)
|
|
9086
|
+
);
|
|
9087
|
+
}
|
|
9088
|
+
return 0;
|
|
9089
|
+
}
|
|
9090
|
+
async function cmdDoctor(options = {}) {
|
|
9091
|
+
const env = options.env ?? process.env;
|
|
9092
|
+
const path = options.configPath ?? defaultConfigPath(env);
|
|
9093
|
+
const context = await resolveHostedContext({
|
|
9094
|
+
profileName: options.profileName,
|
|
9095
|
+
env,
|
|
9096
|
+
configPath: path,
|
|
9097
|
+
tokenProvider: options.tokenProvider
|
|
9098
|
+
});
|
|
9099
|
+
if (!context.apiUrl || !context.apiKey || !context.tenantId) {
|
|
9100
|
+
process.stderr.write("No complete hosted profile. Run fx login.\n");
|
|
9101
|
+
return 1;
|
|
9102
|
+
}
|
|
9103
|
+
const client = new ApiClient({
|
|
9104
|
+
baseUrl: context.apiUrl,
|
|
9105
|
+
apiKey: context.apiKey,
|
|
9106
|
+
bearerToken: context.bearerToken,
|
|
9107
|
+
defaultOrgId: context.tenantId,
|
|
9108
|
+
fetchImpl: options.fetchImpl
|
|
9109
|
+
});
|
|
9110
|
+
const tenant = await client.tenants.me();
|
|
9111
|
+
const privatePermissions = await configPermissionsArePrivate(path);
|
|
9112
|
+
process.stdout.write(
|
|
9113
|
+
[
|
|
9114
|
+
"Fabric CLI doctor",
|
|
9115
|
+
` Profile: ${context.profileName ?? "(environment)"}`,
|
|
9116
|
+
` API: ${context.apiUrl}`,
|
|
9117
|
+
` Organization: ${tenant.organization.name} (${tenant.organization.id})`,
|
|
9118
|
+
` Role: ${tenant.member.role}`,
|
|
9119
|
+
` Gateway: ${context.bearerToken ? "authenticated" : "not required"}`,
|
|
9120
|
+
` Config mode: ${privatePermissions ? "private" : "INSECURE"}`,
|
|
9121
|
+
""
|
|
9122
|
+
].join("\n")
|
|
9123
|
+
);
|
|
9124
|
+
return privatePermissions ? 0 : 2;
|
|
9125
|
+
}
|
|
9126
|
+
function normalizeApiUrl(value) {
|
|
9127
|
+
const url = new URL(value);
|
|
9128
|
+
if (!url.pathname || url.pathname === "/") url.pathname = "/api";
|
|
9129
|
+
return url.toString().replace(/\/$/, "");
|
|
9130
|
+
}
|
|
9131
|
+
function formatProfile(name, profile, active) {
|
|
9132
|
+
return `${active ? "*" : " "} ${name} \u2014 ${profile.organizationName ?? profile.orgId} (${profile.role ?? "unknown"})
|
|
9133
|
+
${profile.apiUrl}
|
|
9134
|
+
`;
|
|
9135
|
+
}
|
|
9136
|
+
async function readSecretApiKey() {
|
|
9137
|
+
if (!stdin.isTTY || typeof stdin.setRawMode !== "function") {
|
|
9138
|
+
throw new Error("Set FX_API_KEY or pass --api-key when stdin is not interactive");
|
|
9139
|
+
}
|
|
9140
|
+
stderr.write("Fabric API key: ");
|
|
9141
|
+
stdin.setRawMode(true);
|
|
9142
|
+
stdin.resume();
|
|
9143
|
+
return new Promise((resolve11, reject) => {
|
|
9144
|
+
let value = "";
|
|
9145
|
+
const onData = (chunk) => {
|
|
9146
|
+
const text = chunk.toString("utf8");
|
|
9147
|
+
if (text === "") {
|
|
9148
|
+
cleanup();
|
|
9149
|
+
reject(new Error("Login canceled"));
|
|
9150
|
+
return;
|
|
9151
|
+
}
|
|
9152
|
+
if (text === "\r" || text === "\n") {
|
|
9153
|
+
cleanup();
|
|
9154
|
+
stderr.write("\n");
|
|
9155
|
+
resolve11(value.trim());
|
|
9156
|
+
return;
|
|
9157
|
+
}
|
|
9158
|
+
if (text === "\x7F") value = value.slice(0, -1);
|
|
9159
|
+
else value += text;
|
|
9160
|
+
};
|
|
9161
|
+
const cleanup = () => {
|
|
9162
|
+
stdin.off("data", onData);
|
|
9163
|
+
stdin.setRawMode(false);
|
|
9164
|
+
stdin.pause();
|
|
9165
|
+
};
|
|
9166
|
+
stdin.on("data", onData);
|
|
9167
|
+
});
|
|
9168
|
+
}
|
|
8772
9169
|
|
|
8773
9170
|
// src/bin/fx.ts
|
|
8774
9171
|
var HELP = `fx \u2014 Fabric Experiments CLI
|
|
@@ -8788,8 +9185,12 @@ COMMANDS
|
|
|
8788
9185
|
import-mojito <dir> Import a directory of Mojito waves into Fabric YAML.
|
|
8789
9186
|
preview <experimentId> Mint a signed preview link for a variant. Requires --variant.
|
|
8790
9187
|
test env <action> Create, destroy, list, or reap Databricks test environments.
|
|
8791
|
-
test publish <file> Publish BDD/live evidence to Studio Quality.
|
|
9188
|
+
test publish <file> Publish BDD/live/JUnit/CLI evidence to Studio Quality.
|
|
8792
9189
|
init databricks-tests Scaffold a Databricks BDD test project.
|
|
9190
|
+
login Configure and verify a secure hosted profile.
|
|
9191
|
+
logout [profile] Remove a stored hosted profile.
|
|
9192
|
+
profile [list|show|use] Inspect or switch hosted profiles.
|
|
9193
|
+
doctor Verify API, tenant, gateway, role, and config security.
|
|
8793
9194
|
|
|
8794
9195
|
GLOBAL FLAGS
|
|
8795
9196
|
--tenant <id> Tenant scope (default: default)
|
|
@@ -8804,8 +9205,11 @@ GLOBAL FLAGS
|
|
|
8804
9205
|
--remote-url <url> publish: post to a manifest-worker
|
|
8805
9206
|
--admin-token <tok> publish: bearer token for --remote-url
|
|
8806
9207
|
--static <dir> publish: write signed manifest + tag-loader bundle to <dir>
|
|
8807
|
-
--api-url <url> push/preview: hosted API base URL
|
|
8808
|
-
--api-key <key> push/preview: hosted API key
|
|
9208
|
+
--api-url <url> push/preview/test publish: hosted API base URL
|
|
9209
|
+
--api-key <key> push/preview/test publish: hosted API key
|
|
9210
|
+
--profile <name> hosted profile (default: active profile)
|
|
9211
|
+
--studio-url <url> login: branded Studio URL
|
|
9212
|
+
--databricks-profile <p> login: Databricks CLI profile used for Apps OAuth
|
|
8809
9213
|
--no-publish push: apply actions without publishing manifest
|
|
8810
9214
|
--name <name> test env: environment name (for example pr-1234)
|
|
8811
9215
|
--seed <dir> test env create: JSON fixture directory
|
|
@@ -8824,7 +9228,7 @@ GLOBAL FLAGS
|
|
|
8824
9228
|
-h, --help print this help
|
|
8825
9229
|
-v, --version print version
|
|
8826
9230
|
`;
|
|
8827
|
-
var VERSION2 = "0.
|
|
9231
|
+
var VERSION2 = "0.7.0";
|
|
8828
9232
|
function parse2(argv) {
|
|
8829
9233
|
const positional = [];
|
|
8830
9234
|
const flags = {};
|
|
@@ -8869,13 +9273,32 @@ async function main() {
|
|
|
8869
9273
|
`);
|
|
8870
9274
|
return 0;
|
|
8871
9275
|
}
|
|
8872
|
-
const
|
|
9276
|
+
const explicitTenantId = args.flags.tenant;
|
|
9277
|
+
const tenantId = explicitTenantId ?? "default";
|
|
8873
9278
|
const allowDeletes = args.flags["allow-deletes"] === true;
|
|
8874
9279
|
switch (args.command) {
|
|
8875
9280
|
case "":
|
|
8876
9281
|
case "help":
|
|
8877
9282
|
process.stdout.write(HELP);
|
|
8878
9283
|
return 0;
|
|
9284
|
+
case "login":
|
|
9285
|
+
return cmdLogin({
|
|
9286
|
+
profileName: args.flags.profile,
|
|
9287
|
+
studioUrl: args.flags["studio-url"],
|
|
9288
|
+
apiUrl: args.flags["api-url"],
|
|
9289
|
+
apiKey: args.flags["api-key"],
|
|
9290
|
+
tenantId: explicitTenantId,
|
|
9291
|
+
databricksProfile: args.flags["databricks-profile"]
|
|
9292
|
+
});
|
|
9293
|
+
case "logout":
|
|
9294
|
+
return cmdLogout(args.positional[0] ?? args.flags.profile);
|
|
9295
|
+
case "profile":
|
|
9296
|
+
return cmdProfile(
|
|
9297
|
+
args.positional[0] ?? "list",
|
|
9298
|
+
args.positional[1] ?? args.flags.profile
|
|
9299
|
+
);
|
|
9300
|
+
case "doctor":
|
|
9301
|
+
return cmdDoctor({ profileName: args.flags.profile });
|
|
8879
9302
|
case "validate":
|
|
8880
9303
|
return cmdValidate(args.positional[0] ?? ".");
|
|
8881
9304
|
case "plan":
|
|
@@ -8894,17 +9317,25 @@ async function main() {
|
|
|
8894
9317
|
dryRun: args.flags["dry-run"] === true,
|
|
8895
9318
|
allowDeletes
|
|
8896
9319
|
});
|
|
8897
|
-
case "push":
|
|
9320
|
+
case "push": {
|
|
9321
|
+
const hosted = await resolveHostedContext({
|
|
9322
|
+
profileName: args.flags.profile,
|
|
9323
|
+
apiUrl: args.flags["api-url"],
|
|
9324
|
+
apiKey: args.flags["api-key"],
|
|
9325
|
+
tenantId: explicitTenantId
|
|
9326
|
+
});
|
|
8898
9327
|
return cmdPush(args.positional[0] ?? ".", {
|
|
8899
|
-
tenantId,
|
|
9328
|
+
tenantId: hosted.tenantId,
|
|
8900
9329
|
ownerId: args.flags.owner,
|
|
8901
9330
|
approverId: args.flags.approver,
|
|
8902
9331
|
dryRun: args.flags["dry-run"] === true,
|
|
8903
9332
|
allowDeletes,
|
|
8904
|
-
apiUrl:
|
|
8905
|
-
apiKey:
|
|
9333
|
+
apiUrl: hosted.apiUrl,
|
|
9334
|
+
apiKey: hosted.apiKey,
|
|
9335
|
+
bearerToken: hosted.bearerToken,
|
|
8906
9336
|
publish: args.flags["no-publish"] !== true
|
|
8907
9337
|
});
|
|
9338
|
+
}
|
|
8908
9339
|
case "dev":
|
|
8909
9340
|
return cmdDev({
|
|
8910
9341
|
port: args.flags.port ? Number(args.flags.port) : void 0,
|
|
@@ -8947,32 +9378,47 @@ async function main() {
|
|
|
8947
9378
|
outputDir: args.flags.out,
|
|
8948
9379
|
reportFile: args.flags.report,
|
|
8949
9380
|
strict: args.flags.strict === true});
|
|
8950
|
-
case "preview":
|
|
9381
|
+
case "preview": {
|
|
8951
9382
|
if (!args.positional[0]) {
|
|
8952
9383
|
process.stderr.write(
|
|
8953
9384
|
"Usage: fx preview <experimentId> --variant <key> [--ttl 900] [--origin https://...] [--api-url ... --api-key ...]\n"
|
|
8954
9385
|
);
|
|
8955
9386
|
return 1;
|
|
8956
9387
|
}
|
|
9388
|
+
const hosted = args.flags.local === true ? {} : await resolveHostedContext({
|
|
9389
|
+
profileName: args.flags.profile,
|
|
9390
|
+
apiUrl: args.flags["api-url"],
|
|
9391
|
+
apiKey: args.flags["api-key"],
|
|
9392
|
+
tenantId: explicitTenantId
|
|
9393
|
+
});
|
|
8957
9394
|
return cmdPreview(args.positional[0], {
|
|
8958
|
-
tenantId,
|
|
9395
|
+
tenantId: hosted.tenantId ?? tenantId,
|
|
8959
9396
|
variantKey: typeof args.flags.variant === "string" ? args.flags.variant : "",
|
|
8960
9397
|
ttlSeconds: args.flags.ttl ? Number(args.flags.ttl) : void 0,
|
|
8961
9398
|
origin: args.flags.origin,
|
|
8962
|
-
apiUrl:
|
|
8963
|
-
apiKey:
|
|
9399
|
+
apiUrl: hosted.apiUrl,
|
|
9400
|
+
apiKey: hosted.apiKey,
|
|
9401
|
+
bearerToken: hosted.bearerToken,
|
|
8964
9402
|
local: args.flags.local === true
|
|
8965
9403
|
});
|
|
9404
|
+
}
|
|
8966
9405
|
case "test":
|
|
8967
9406
|
if (args.positional[0] === "publish") {
|
|
8968
9407
|
if (!args.positional[1]) {
|
|
8969
|
-
process.stderr.write("Usage: fx test publish <evidence.json> [flags]\n");
|
|
9408
|
+
process.stderr.write("Usage: fx test publish <evidence.json|junit.xml> [flags]\n");
|
|
8970
9409
|
return 1;
|
|
8971
9410
|
}
|
|
8972
|
-
|
|
8973
|
-
|
|
9411
|
+
const hosted = await resolveHostedContext({
|
|
9412
|
+
profileName: args.flags.profile,
|
|
8974
9413
|
apiUrl: args.flags["api-url"],
|
|
8975
9414
|
apiKey: args.flags["api-key"],
|
|
9415
|
+
tenantId: explicitTenantId
|
|
9416
|
+
});
|
|
9417
|
+
return cmdTestPublish(args.positional[1], {
|
|
9418
|
+
tenantId: hosted.tenantId,
|
|
9419
|
+
apiUrl: hosted.apiUrl,
|
|
9420
|
+
apiKey: hosted.apiKey,
|
|
9421
|
+
bearerToken: hosted.bearerToken,
|
|
8976
9422
|
suite: args.flags.suite,
|
|
8977
9423
|
externalId: args.flags["external-id"],
|
|
8978
9424
|
runUrl: args.flags["run-url"]
|