@fabricorg/experiments 0.11.0 → 0.12.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 +5 -0
- package/dist/bin/fx.cjs +211 -3
- package/dist/bin/fx.cjs.map +1 -1
- package/dist/bin/fx.js +213 -5
- package/dist/bin/fx.js.map +1 -1
- package/package.json +23 -33
package/dist/bin/fx.js
CHANGED
|
@@ -4,12 +4,12 @@ import { resolve, join, basename, dirname, extname } from 'path';
|
|
|
4
4
|
import { fileURLToPath } from 'url';
|
|
5
5
|
import { mkdir, writeFile, readFile, copyFile, access, readdir, stat, rename, chmod, unlink } from 'fs/promises';
|
|
6
6
|
import { parse, stringify } from 'yaml';
|
|
7
|
-
import { randomUUID, webcrypto, createHash } from 'crypto';
|
|
7
|
+
import { randomUUID, webcrypto, randomBytes, createHash } from 'crypto';
|
|
8
8
|
import { createServer } from 'http';
|
|
9
9
|
import { createRequire } from 'module';
|
|
10
10
|
import { createTargetPackRegistry, builtinTargetPacks, doctorTargetPack, runTargetPack, createWorkspaceContext, deleteEphemeralLakebaseBranch, createEphemeralLakebaseBranch, toLakebaseBranchId } from '@fabricorg/databricks-testkit';
|
|
11
11
|
import { XMLParser } from 'fast-xml-parser';
|
|
12
|
-
import { execFile } from 'child_process';
|
|
12
|
+
import { execFile, spawn } from 'child_process';
|
|
13
13
|
import { homedir } from 'os';
|
|
14
14
|
import { promisify } from 'util';
|
|
15
15
|
import { stdin, stderr } from 'process';
|
|
@@ -7584,6 +7584,15 @@ var TestRunListInput = external_exports.object({
|
|
|
7584
7584
|
var TestRunListResponse = external_exports.object({
|
|
7585
7585
|
runs: external_exports.array(TestRun.omit({ cases: true }))
|
|
7586
7586
|
});
|
|
7587
|
+
var HarnessOperatorDefinition = external_exports.object({
|
|
7588
|
+
name: external_exports.enum(["quality-status", "srm-watcher", "analyst"]),
|
|
7589
|
+
kind: external_exports.literal("job"),
|
|
7590
|
+
description: external_exports.string(),
|
|
7591
|
+
mutates: external_exports.boolean()
|
|
7592
|
+
});
|
|
7593
|
+
var HarnessOperatorListResponse = external_exports.array(HarnessOperatorDefinition);
|
|
7594
|
+
var HarnessJobInput = external_exports.record(external_exports.unknown()).default({});
|
|
7595
|
+
var HarnessJobResponse = external_exports.record(external_exports.unknown());
|
|
7587
7596
|
var endpoints = {
|
|
7588
7597
|
"tenants.me": {
|
|
7589
7598
|
method: "GET",
|
|
@@ -7896,6 +7905,22 @@ var endpoints = {
|
|
|
7896
7905
|
response: TestRun,
|
|
7897
7906
|
mutates: false,
|
|
7898
7907
|
requiresRole: "viewer"
|
|
7908
|
+
},
|
|
7909
|
+
"harness.definitions": {
|
|
7910
|
+
method: "GET",
|
|
7911
|
+
path: "/v1/orgs/:orgId/harness/admin/agents",
|
|
7912
|
+
params: Empty,
|
|
7913
|
+
response: HarnessOperatorListResponse,
|
|
7914
|
+
mutates: false,
|
|
7915
|
+
requiresRole: "viewer"
|
|
7916
|
+
},
|
|
7917
|
+
"harness.invokeJob": {
|
|
7918
|
+
method: "POST",
|
|
7919
|
+
path: "/v1/orgs/:orgId/harness/jobs/:jobName",
|
|
7920
|
+
params: HarnessJobInput,
|
|
7921
|
+
response: HarnessJobResponse,
|
|
7922
|
+
mutates: true,
|
|
7923
|
+
requiresRole: "experimenter"
|
|
7899
7924
|
}
|
|
7900
7925
|
};
|
|
7901
7926
|
function buildPath(template, pathParams) {
|
|
@@ -7953,6 +7978,7 @@ var ApiClient = class {
|
|
|
7953
7978
|
method: def.method,
|
|
7954
7979
|
headers: {
|
|
7955
7980
|
accept: "application/json",
|
|
7981
|
+
...this.opts.headers ?? {},
|
|
7956
7982
|
// Hosted Fabric API keys use their own header so upstream auth
|
|
7957
7983
|
// middleware cannot mistake them for OAuth bearer credentials.
|
|
7958
7984
|
...this.opts.apiKey ? { "x-api-key": this.opts.apiKey } : {},
|
|
@@ -8081,6 +8107,10 @@ var ApiClient = class {
|
|
|
8081
8107
|
get: (runId, orgId) => this.call("testRuns.get", {}, orgId ? { orgId, runId } : { runId }),
|
|
8082
8108
|
create: (params, orgId) => this.call("testRuns.create", params, orgId ? { orgId } : void 0)
|
|
8083
8109
|
};
|
|
8110
|
+
harness = {
|
|
8111
|
+
definitions: (orgId) => this.call("harness.definitions", {}, orgId ? { orgId } : void 0),
|
|
8112
|
+
invokeJob: (jobName, params = {}, orgId) => this.call("harness.invokeJob", params, orgId ? { orgId, jobName } : { jobName })
|
|
8113
|
+
};
|
|
8084
8114
|
};
|
|
8085
8115
|
async function safeJson(r) {
|
|
8086
8116
|
try {
|
|
@@ -8654,7 +8684,7 @@ async function resolveHostedContext(options = {}) {
|
|
|
8654
8684
|
const tenantId = options.tenantId ?? env.FX_ORG_ID ?? profile?.orgId;
|
|
8655
8685
|
const bearerToken = options.bearerToken ?? (apiUrl ? await resolveGatewayBearer(apiUrl, {
|
|
8656
8686
|
env,
|
|
8657
|
-
databricksProfile: profile?.databricksProfile,
|
|
8687
|
+
databricksProfile: options.databricksProfile ?? profile?.databricksProfile,
|
|
8658
8688
|
tokenProvider: options.tokenProvider
|
|
8659
8689
|
}) : void 0);
|
|
8660
8690
|
return { profileName, apiUrl, apiKey, tenantId, bearerToken };
|
|
@@ -9318,6 +9348,158 @@ function symbol(status) {
|
|
|
9318
9348
|
function objectOf2(value) {
|
|
9319
9349
|
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
9320
9350
|
}
|
|
9351
|
+
async function cmdHarness(action, jobName, options) {
|
|
9352
|
+
const client = new ApiClient({
|
|
9353
|
+
baseUrl: options.apiUrl,
|
|
9354
|
+
apiKey: options.apiKey,
|
|
9355
|
+
bearerToken: options.bearerToken,
|
|
9356
|
+
defaultOrgId: options.tenantId,
|
|
9357
|
+
fetchImpl: options.fetchImpl
|
|
9358
|
+
});
|
|
9359
|
+
if (action === "list" || action === "doctor") {
|
|
9360
|
+
const definitions = await client.harness.definitions();
|
|
9361
|
+
if (options.json) process.stdout.write(`${JSON.stringify(definitions, null, 2)}
|
|
9362
|
+
`);
|
|
9363
|
+
else {
|
|
9364
|
+
for (const item of definitions) {
|
|
9365
|
+
process.stdout.write(
|
|
9366
|
+
`${item.name.padEnd(16)} ${item.mutates ? "controlled write" : "read only"} ${item.description}
|
|
9367
|
+
`
|
|
9368
|
+
);
|
|
9369
|
+
}
|
|
9370
|
+
if (action === "doctor") {
|
|
9371
|
+
process.stdout.write(
|
|
9372
|
+
`Harness operator ready: ${definitions.length} jobs \xB7 tenant ${options.tenantId}
|
|
9373
|
+
`
|
|
9374
|
+
);
|
|
9375
|
+
}
|
|
9376
|
+
}
|
|
9377
|
+
return definitions.length > 0 ? 0 : 1;
|
|
9378
|
+
}
|
|
9379
|
+
if (action === "run") {
|
|
9380
|
+
if (!jobName) throw new Error("Usage: fx harness run <job> [--input <json>]");
|
|
9381
|
+
const output = await client.harness.invokeJob(jobName, parseInput(options.input));
|
|
9382
|
+
process.stdout.write(`${JSON.stringify(output, null, 2)}
|
|
9383
|
+
`);
|
|
9384
|
+
return 0;
|
|
9385
|
+
}
|
|
9386
|
+
if (action === "fiber") return runFiberThroughBridge(options);
|
|
9387
|
+
throw new Error(`Unknown harness action: ${action}`);
|
|
9388
|
+
}
|
|
9389
|
+
async function createHarnessCredentialBridge(options) {
|
|
9390
|
+
const remote = `${options.apiUrl.replace(/\/+$/, "")}/v1/orgs/${encodeURIComponent(options.tenantId)}/harness`;
|
|
9391
|
+
const bridgeToken = randomBytes(24).toString("base64url");
|
|
9392
|
+
const server = createServer((request, response) => {
|
|
9393
|
+
void proxyHarnessRequest(request, response, remote, bridgeToken, options);
|
|
9394
|
+
});
|
|
9395
|
+
await new Promise((resolve11, reject) => {
|
|
9396
|
+
server.once("error", reject);
|
|
9397
|
+
server.listen(0, "127.0.0.1", resolve11);
|
|
9398
|
+
});
|
|
9399
|
+
const address = server.address();
|
|
9400
|
+
if (!address || typeof address === "string") {
|
|
9401
|
+
server.close();
|
|
9402
|
+
throw new Error("Unable to bind the local Fiber credential bridge");
|
|
9403
|
+
}
|
|
9404
|
+
return {
|
|
9405
|
+
url: `http://127.0.0.1:${address.port}`,
|
|
9406
|
+
token: bridgeToken,
|
|
9407
|
+
close: () => new Promise(
|
|
9408
|
+
(resolve11, reject) => server.close((error) => error ? reject(error) : resolve11())
|
|
9409
|
+
)
|
|
9410
|
+
};
|
|
9411
|
+
}
|
|
9412
|
+
async function runFiberThroughBridge(options) {
|
|
9413
|
+
const bridge = await createHarnessCredentialBridge(options);
|
|
9414
|
+
const harnessBin = options.harnessBin ?? createRequire(import.meta.url).resolve("@fabric-harness/cli");
|
|
9415
|
+
const tokenVariable = "FX_FIBER_BRIDGE_TOKEN";
|
|
9416
|
+
const args = [harnessBin, "fiber", "--url", bridge.url, "--token-env", tokenVariable];
|
|
9417
|
+
if (options.plain) args.push("--plain");
|
|
9418
|
+
try {
|
|
9419
|
+
return await new Promise((resolve11, reject) => {
|
|
9420
|
+
const child = (options.spawnProcess ?? spawn)(process.execPath, args, {
|
|
9421
|
+
stdio: "inherit",
|
|
9422
|
+
env: { ...process.env, [tokenVariable]: bridge.token }
|
|
9423
|
+
});
|
|
9424
|
+
child.once("error", reject);
|
|
9425
|
+
child.once("exit", (code, signal) => {
|
|
9426
|
+
if (signal) reject(new Error(`Fiber exited from signal ${signal}`));
|
|
9427
|
+
else resolve11(code ?? 1);
|
|
9428
|
+
});
|
|
9429
|
+
});
|
|
9430
|
+
} finally {
|
|
9431
|
+
await bridge.close();
|
|
9432
|
+
}
|
|
9433
|
+
}
|
|
9434
|
+
async function proxyHarnessRequest(incoming, outgoing, remoteBase, bridgeToken, options) {
|
|
9435
|
+
try {
|
|
9436
|
+
if (incoming.headers.authorization !== `Bearer ${bridgeToken}`) {
|
|
9437
|
+
outgoing.writeHead(401, { "content-type": "application/json" });
|
|
9438
|
+
outgoing.end(JSON.stringify({ error: { message: "Invalid Fiber bridge token" } }));
|
|
9439
|
+
return;
|
|
9440
|
+
}
|
|
9441
|
+
const url = new URL(incoming.url ?? "/", "http://bridge.invalid");
|
|
9442
|
+
if (!isAllowedHarnessPath(incoming.method, url.pathname)) {
|
|
9443
|
+
outgoing.writeHead(404, { "content-type": "application/json" });
|
|
9444
|
+
outgoing.end(JSON.stringify({ error: { message: "Unsupported Harness operator route" } }));
|
|
9445
|
+
return;
|
|
9446
|
+
}
|
|
9447
|
+
const body = await readBody(incoming);
|
|
9448
|
+
const response = await (options.fetchImpl ?? fetch)(
|
|
9449
|
+
`${remoteBase}${url.pathname}${url.search}`,
|
|
9450
|
+
{
|
|
9451
|
+
method: incoming.method,
|
|
9452
|
+
headers: {
|
|
9453
|
+
accept: "application/json",
|
|
9454
|
+
"x-api-key": options.apiKey,
|
|
9455
|
+
...options.bearerToken ? { authorization: `Bearer ${options.bearerToken}` } : {},
|
|
9456
|
+
...body.length > 0 ? { "content-type": "application/json" } : {}
|
|
9457
|
+
},
|
|
9458
|
+
body: body.length > 0 ? body.toString("utf8") : void 0
|
|
9459
|
+
}
|
|
9460
|
+
);
|
|
9461
|
+
const responseBody = Buffer.from(await response.arrayBuffer());
|
|
9462
|
+
outgoing.writeHead(response.status, {
|
|
9463
|
+
"content-type": response.headers.get("content-type") ?? "application/json",
|
|
9464
|
+
"cache-control": "no-store"
|
|
9465
|
+
});
|
|
9466
|
+
outgoing.end(responseBody);
|
|
9467
|
+
} catch (error) {
|
|
9468
|
+
outgoing.writeHead(502, { "content-type": "application/json" });
|
|
9469
|
+
outgoing.end(
|
|
9470
|
+
JSON.stringify({
|
|
9471
|
+
error: { message: error instanceof Error ? error.message : "Fiber bridge failed" }
|
|
9472
|
+
})
|
|
9473
|
+
);
|
|
9474
|
+
}
|
|
9475
|
+
}
|
|
9476
|
+
function isAllowedHarnessPath(method, path) {
|
|
9477
|
+
return method === "GET" && path === "/admin/agents" || method === "POST" && /^\/jobs\/[A-Za-z0-9_.-]+$/.test(path);
|
|
9478
|
+
}
|
|
9479
|
+
async function readBody(request) {
|
|
9480
|
+
const chunks = [];
|
|
9481
|
+
let size = 0;
|
|
9482
|
+
for await (const chunk of request) {
|
|
9483
|
+
const value = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
9484
|
+
size += value.length;
|
|
9485
|
+
if (size > 64 * 1024) throw new Error("Fiber request body exceeds 64 KiB");
|
|
9486
|
+
chunks.push(value);
|
|
9487
|
+
}
|
|
9488
|
+
return Buffer.concat(chunks);
|
|
9489
|
+
}
|
|
9490
|
+
function parseInput(value) {
|
|
9491
|
+
if (!value) return {};
|
|
9492
|
+
let parsed;
|
|
9493
|
+
try {
|
|
9494
|
+
parsed = JSON.parse(value);
|
|
9495
|
+
} catch {
|
|
9496
|
+
throw new Error("--input must be valid JSON");
|
|
9497
|
+
}
|
|
9498
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
9499
|
+
throw new Error("--input must be a JSON object");
|
|
9500
|
+
}
|
|
9501
|
+
return parsed;
|
|
9502
|
+
}
|
|
9321
9503
|
|
|
9322
9504
|
// src/bin/fx.ts
|
|
9323
9505
|
var HELP = `fx \u2014 Fabric Experiments CLI
|
|
@@ -9343,6 +9525,7 @@ COMMANDS
|
|
|
9343
9525
|
logout [profile] Remove a stored hosted profile.
|
|
9344
9526
|
profile [list|show|use] Inspect or switch hosted profiles.
|
|
9345
9527
|
doctor Verify API, tenant, gateway, role, and config security.
|
|
9528
|
+
harness <action> List/run operator jobs or open the Fiber terminal console.
|
|
9346
9529
|
targets list List built-in Databricks target packs.
|
|
9347
9530
|
targets doctor <pack> Validate target configuration without creating resources.
|
|
9348
9531
|
targets run <pack> Run a pack and write JSON/JUnit evidence. Requires --live.
|
|
@@ -9365,7 +9548,7 @@ GLOBAL FLAGS
|
|
|
9365
9548
|
--api-key <key> push/preview/test publish: hosted API key
|
|
9366
9549
|
--profile <name> hosted profile (default: active profile)
|
|
9367
9550
|
--studio-url <url> login: branded Studio URL
|
|
9368
|
-
--databricks-profile <p>
|
|
9551
|
+
--databricks-profile <p> Databricks CLI profile used for Apps OAuth
|
|
9369
9552
|
--no-publish push: apply actions without publishing manifest
|
|
9370
9553
|
--name <name> test env: environment name (for example pr-1234)
|
|
9371
9554
|
--seed <dir> test env create: JSON fixture directory
|
|
@@ -9381,6 +9564,8 @@ GLOBAL FLAGS
|
|
|
9381
9564
|
--required <ids> targets run: comma-separated required check IDs
|
|
9382
9565
|
--evidence <file> targets run: evidence JSON output path
|
|
9383
9566
|
--junit <file> targets run: JUnit XML output path
|
|
9567
|
+
--input <json> harness run: typed operator job input
|
|
9568
|
+
--plain harness fiber: use the line-oriented console
|
|
9384
9569
|
--key-id <id> publish: keyId to sign with (default: dev-default)
|
|
9385
9570
|
--out <dir> import-mojito: output directory
|
|
9386
9571
|
--report <file> import-mojito: compatibility report path
|
|
@@ -9388,7 +9573,7 @@ GLOBAL FLAGS
|
|
|
9388
9573
|
-h, --help print this help
|
|
9389
9574
|
-v, --version print version
|
|
9390
9575
|
`;
|
|
9391
|
-
var VERSION2 = "0.
|
|
9576
|
+
var VERSION2 = "0.12.0";
|
|
9392
9577
|
function parse2(argv) {
|
|
9393
9578
|
const positional = [];
|
|
9394
9579
|
const flags = {};
|
|
@@ -9459,6 +9644,28 @@ async function main() {
|
|
|
9459
9644
|
);
|
|
9460
9645
|
case "doctor":
|
|
9461
9646
|
return cmdDoctor({ profileName: args.flags.profile });
|
|
9647
|
+
case "harness": {
|
|
9648
|
+
const action = args.positional[0] ?? "list";
|
|
9649
|
+
const hosted = await resolveHostedContext({
|
|
9650
|
+
profileName: args.flags.profile,
|
|
9651
|
+
databricksProfile: args.flags["databricks-profile"],
|
|
9652
|
+
apiUrl: args.flags["api-url"],
|
|
9653
|
+
apiKey: args.flags["api-key"],
|
|
9654
|
+
tenantId: explicitTenantId
|
|
9655
|
+
});
|
|
9656
|
+
if (!hosted.apiUrl || !hosted.apiKey || !hosted.tenantId) {
|
|
9657
|
+
throw new Error("Run fx login first or provide --api-url, --api-key, and --tenant");
|
|
9658
|
+
}
|
|
9659
|
+
return cmdHarness(action, args.positional[1], {
|
|
9660
|
+
apiUrl: hosted.apiUrl,
|
|
9661
|
+
apiKey: hosted.apiKey,
|
|
9662
|
+
tenantId: hosted.tenantId,
|
|
9663
|
+
bearerToken: hosted.bearerToken,
|
|
9664
|
+
input: args.flags.input,
|
|
9665
|
+
json: args.flags.json === true,
|
|
9666
|
+
plain: args.flags.plain === true
|
|
9667
|
+
});
|
|
9668
|
+
}
|
|
9462
9669
|
case "targets": {
|
|
9463
9670
|
const action = args.positional[0] ?? "list";
|
|
9464
9671
|
if (action === "publish") {
|
|
@@ -9469,6 +9676,7 @@ async function main() {
|
|
|
9469
9676
|
}
|
|
9470
9677
|
const hosted = await resolveHostedContext({
|
|
9471
9678
|
profileName: args.flags.profile,
|
|
9679
|
+
databricksProfile: args.flags["databricks-profile"],
|
|
9472
9680
|
apiUrl: args.flags["api-url"],
|
|
9473
9681
|
apiKey: args.flags["api-key"],
|
|
9474
9682
|
tenantId: explicitTenantId
|