@fabricorg/experiments 0.11.1 → 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 CHANGED
@@ -28,6 +28,8 @@ For the hosted product, create a scoped API key in Studio and log in once:
28
28
  ```bash
29
29
  fx login --api-key fx_key_...
30
30
  fx doctor
31
+ fx harness doctor
32
+ fx harness fiber
31
33
  fx profile show
32
34
  fx push experiments/
33
35
  fx test publish reports/evidence.json
@@ -73,6 +75,9 @@ fx login Configure and verify a secure hosted profile.
73
75
  fx logout [profile] Remove a hosted profile.
74
76
  fx profile [list|show|use] Inspect or switch profiles without printing secrets.
75
77
  fx doctor Verify API, gateway, tenant, role, and config security.
78
+ fx harness list List tenant-scoped Fabric Harness operator jobs.
79
+ fx harness run <job> Run a finite job; mutation/delivery requires explicit input.
80
+ fx harness fiber Open Fiber through a localhost-only credential bridge.
76
81
  fx targets list List typed workload target packs and maturity.
77
82
  fx targets doctor <pack> Check a pack's environment without exposing secrets.
78
83
  fx targets run <pack> --live Run a pack against a real target and write evidence.
package/dist/bin/fx.cjs CHANGED
@@ -7587,6 +7587,15 @@ var TestRunListInput = external_exports.object({
7587
7587
  var TestRunListResponse = external_exports.object({
7588
7588
  runs: external_exports.array(TestRun.omit({ cases: true }))
7589
7589
  });
7590
+ var HarnessOperatorDefinition = external_exports.object({
7591
+ name: external_exports.enum(["quality-status", "srm-watcher", "analyst"]),
7592
+ kind: external_exports.literal("job"),
7593
+ description: external_exports.string(),
7594
+ mutates: external_exports.boolean()
7595
+ });
7596
+ var HarnessOperatorListResponse = external_exports.array(HarnessOperatorDefinition);
7597
+ var HarnessJobInput = external_exports.record(external_exports.unknown()).default({});
7598
+ var HarnessJobResponse = external_exports.record(external_exports.unknown());
7590
7599
  var endpoints = {
7591
7600
  "tenants.me": {
7592
7601
  method: "GET",
@@ -7899,6 +7908,22 @@ var endpoints = {
7899
7908
  response: TestRun,
7900
7909
  mutates: false,
7901
7910
  requiresRole: "viewer"
7911
+ },
7912
+ "harness.definitions": {
7913
+ method: "GET",
7914
+ path: "/v1/orgs/:orgId/harness/admin/agents",
7915
+ params: Empty,
7916
+ response: HarnessOperatorListResponse,
7917
+ mutates: false,
7918
+ requiresRole: "viewer"
7919
+ },
7920
+ "harness.invokeJob": {
7921
+ method: "POST",
7922
+ path: "/v1/orgs/:orgId/harness/jobs/:jobName",
7923
+ params: HarnessJobInput,
7924
+ response: HarnessJobResponse,
7925
+ mutates: true,
7926
+ requiresRole: "experimenter"
7902
7927
  }
7903
7928
  };
7904
7929
  function buildPath(template, pathParams) {
@@ -7956,6 +7981,7 @@ var ApiClient = class {
7956
7981
  method: def.method,
7957
7982
  headers: {
7958
7983
  accept: "application/json",
7984
+ ...this.opts.headers ?? {},
7959
7985
  // Hosted Fabric API keys use their own header so upstream auth
7960
7986
  // middleware cannot mistake them for OAuth bearer credentials.
7961
7987
  ...this.opts.apiKey ? { "x-api-key": this.opts.apiKey } : {},
@@ -8084,6 +8110,10 @@ var ApiClient = class {
8084
8110
  get: (runId, orgId) => this.call("testRuns.get", {}, orgId ? { orgId, runId } : { runId }),
8085
8111
  create: (params, orgId) => this.call("testRuns.create", params, orgId ? { orgId } : void 0)
8086
8112
  };
8113
+ harness = {
8114
+ definitions: (orgId) => this.call("harness.definitions", {}, orgId ? { orgId } : void 0),
8115
+ invokeJob: (jobName, params = {}, orgId) => this.call("harness.invokeJob", params, orgId ? { orgId, jobName } : { jobName })
8116
+ };
8087
8117
  };
8088
8118
  async function safeJson(r) {
8089
8119
  try {
@@ -9321,6 +9351,158 @@ function symbol(status) {
9321
9351
  function objectOf2(value) {
9322
9352
  return value && typeof value === "object" && !Array.isArray(value) ? value : {};
9323
9353
  }
9354
+ async function cmdHarness(action, jobName, options) {
9355
+ const client = new ApiClient({
9356
+ baseUrl: options.apiUrl,
9357
+ apiKey: options.apiKey,
9358
+ bearerToken: options.bearerToken,
9359
+ defaultOrgId: options.tenantId,
9360
+ fetchImpl: options.fetchImpl
9361
+ });
9362
+ if (action === "list" || action === "doctor") {
9363
+ const definitions = await client.harness.definitions();
9364
+ if (options.json) process.stdout.write(`${JSON.stringify(definitions, null, 2)}
9365
+ `);
9366
+ else {
9367
+ for (const item of definitions) {
9368
+ process.stdout.write(
9369
+ `${item.name.padEnd(16)} ${item.mutates ? "controlled write" : "read only"} ${item.description}
9370
+ `
9371
+ );
9372
+ }
9373
+ if (action === "doctor") {
9374
+ process.stdout.write(
9375
+ `Harness operator ready: ${definitions.length} jobs \xB7 tenant ${options.tenantId}
9376
+ `
9377
+ );
9378
+ }
9379
+ }
9380
+ return definitions.length > 0 ? 0 : 1;
9381
+ }
9382
+ if (action === "run") {
9383
+ if (!jobName) throw new Error("Usage: fx harness run <job> [--input <json>]");
9384
+ const output = await client.harness.invokeJob(jobName, parseInput(options.input));
9385
+ process.stdout.write(`${JSON.stringify(output, null, 2)}
9386
+ `);
9387
+ return 0;
9388
+ }
9389
+ if (action === "fiber") return runFiberThroughBridge(options);
9390
+ throw new Error(`Unknown harness action: ${action}`);
9391
+ }
9392
+ async function createHarnessCredentialBridge(options) {
9393
+ const remote = `${options.apiUrl.replace(/\/+$/, "")}/v1/orgs/${encodeURIComponent(options.tenantId)}/harness`;
9394
+ const bridgeToken = crypto$1.randomBytes(24).toString("base64url");
9395
+ const server = http.createServer((request, response) => {
9396
+ void proxyHarnessRequest(request, response, remote, bridgeToken, options);
9397
+ });
9398
+ await new Promise((resolve11, reject) => {
9399
+ server.once("error", reject);
9400
+ server.listen(0, "127.0.0.1", resolve11);
9401
+ });
9402
+ const address = server.address();
9403
+ if (!address || typeof address === "string") {
9404
+ server.close();
9405
+ throw new Error("Unable to bind the local Fiber credential bridge");
9406
+ }
9407
+ return {
9408
+ url: `http://127.0.0.1:${address.port}`,
9409
+ token: bridgeToken,
9410
+ close: () => new Promise(
9411
+ (resolve11, reject) => server.close((error) => error ? reject(error) : resolve11())
9412
+ )
9413
+ };
9414
+ }
9415
+ async function runFiberThroughBridge(options) {
9416
+ const bridge = await createHarnessCredentialBridge(options);
9417
+ const harnessBin = options.harnessBin ?? module$1.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('fx.cjs', document.baseURI).href))).resolve("@fabric-harness/cli");
9418
+ const tokenVariable = "FX_FIBER_BRIDGE_TOKEN";
9419
+ const args = [harnessBin, "fiber", "--url", bridge.url, "--token-env", tokenVariable];
9420
+ if (options.plain) args.push("--plain");
9421
+ try {
9422
+ return await new Promise((resolve11, reject) => {
9423
+ const child = (options.spawnProcess ?? child_process.spawn)(process.execPath, args, {
9424
+ stdio: "inherit",
9425
+ env: { ...process.env, [tokenVariable]: bridge.token }
9426
+ });
9427
+ child.once("error", reject);
9428
+ child.once("exit", (code, signal) => {
9429
+ if (signal) reject(new Error(`Fiber exited from signal ${signal}`));
9430
+ else resolve11(code ?? 1);
9431
+ });
9432
+ });
9433
+ } finally {
9434
+ await bridge.close();
9435
+ }
9436
+ }
9437
+ async function proxyHarnessRequest(incoming, outgoing, remoteBase, bridgeToken, options) {
9438
+ try {
9439
+ if (incoming.headers.authorization !== `Bearer ${bridgeToken}`) {
9440
+ outgoing.writeHead(401, { "content-type": "application/json" });
9441
+ outgoing.end(JSON.stringify({ error: { message: "Invalid Fiber bridge token" } }));
9442
+ return;
9443
+ }
9444
+ const url = new URL(incoming.url ?? "/", "http://bridge.invalid");
9445
+ if (!isAllowedHarnessPath(incoming.method, url.pathname)) {
9446
+ outgoing.writeHead(404, { "content-type": "application/json" });
9447
+ outgoing.end(JSON.stringify({ error: { message: "Unsupported Harness operator route" } }));
9448
+ return;
9449
+ }
9450
+ const body = await readBody(incoming);
9451
+ const response = await (options.fetchImpl ?? fetch)(
9452
+ `${remoteBase}${url.pathname}${url.search}`,
9453
+ {
9454
+ method: incoming.method,
9455
+ headers: {
9456
+ accept: "application/json",
9457
+ "x-api-key": options.apiKey,
9458
+ ...options.bearerToken ? { authorization: `Bearer ${options.bearerToken}` } : {},
9459
+ ...body.length > 0 ? { "content-type": "application/json" } : {}
9460
+ },
9461
+ body: body.length > 0 ? body.toString("utf8") : void 0
9462
+ }
9463
+ );
9464
+ const responseBody = Buffer.from(await response.arrayBuffer());
9465
+ outgoing.writeHead(response.status, {
9466
+ "content-type": response.headers.get("content-type") ?? "application/json",
9467
+ "cache-control": "no-store"
9468
+ });
9469
+ outgoing.end(responseBody);
9470
+ } catch (error) {
9471
+ outgoing.writeHead(502, { "content-type": "application/json" });
9472
+ outgoing.end(
9473
+ JSON.stringify({
9474
+ error: { message: error instanceof Error ? error.message : "Fiber bridge failed" }
9475
+ })
9476
+ );
9477
+ }
9478
+ }
9479
+ function isAllowedHarnessPath(method, path) {
9480
+ return method === "GET" && path === "/admin/agents" || method === "POST" && /^\/jobs\/[A-Za-z0-9_.-]+$/.test(path);
9481
+ }
9482
+ async function readBody(request) {
9483
+ const chunks = [];
9484
+ let size = 0;
9485
+ for await (const chunk of request) {
9486
+ const value = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
9487
+ size += value.length;
9488
+ if (size > 64 * 1024) throw new Error("Fiber request body exceeds 64 KiB");
9489
+ chunks.push(value);
9490
+ }
9491
+ return Buffer.concat(chunks);
9492
+ }
9493
+ function parseInput(value) {
9494
+ if (!value) return {};
9495
+ let parsed;
9496
+ try {
9497
+ parsed = JSON.parse(value);
9498
+ } catch {
9499
+ throw new Error("--input must be valid JSON");
9500
+ }
9501
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
9502
+ throw new Error("--input must be a JSON object");
9503
+ }
9504
+ return parsed;
9505
+ }
9324
9506
 
9325
9507
  // src/bin/fx.ts
9326
9508
  var HELP = `fx \u2014 Fabric Experiments CLI
@@ -9346,6 +9528,7 @@ COMMANDS
9346
9528
  logout [profile] Remove a stored hosted profile.
9347
9529
  profile [list|show|use] Inspect or switch hosted profiles.
9348
9530
  doctor Verify API, tenant, gateway, role, and config security.
9531
+ harness <action> List/run operator jobs or open the Fiber terminal console.
9349
9532
  targets list List built-in Databricks target packs.
9350
9533
  targets doctor <pack> Validate target configuration without creating resources.
9351
9534
  targets run <pack> Run a pack and write JSON/JUnit evidence. Requires --live.
@@ -9384,6 +9567,8 @@ GLOBAL FLAGS
9384
9567
  --required <ids> targets run: comma-separated required check IDs
9385
9568
  --evidence <file> targets run: evidence JSON output path
9386
9569
  --junit <file> targets run: JUnit XML output path
9570
+ --input <json> harness run: typed operator job input
9571
+ --plain harness fiber: use the line-oriented console
9387
9572
  --key-id <id> publish: keyId to sign with (default: dev-default)
9388
9573
  --out <dir> import-mojito: output directory
9389
9574
  --report <file> import-mojito: compatibility report path
@@ -9391,7 +9576,7 @@ GLOBAL FLAGS
9391
9576
  -h, --help print this help
9392
9577
  -v, --version print version
9393
9578
  `;
9394
- var VERSION2 = "0.11.1";
9579
+ var VERSION2 = "0.12.0";
9395
9580
  function parse2(argv) {
9396
9581
  const positional = [];
9397
9582
  const flags = {};
@@ -9462,6 +9647,28 @@ async function main() {
9462
9647
  );
9463
9648
  case "doctor":
9464
9649
  return cmdDoctor({ profileName: args.flags.profile });
9650
+ case "harness": {
9651
+ const action = args.positional[0] ?? "list";
9652
+ const hosted = await resolveHostedContext({
9653
+ profileName: args.flags.profile,
9654
+ databricksProfile: args.flags["databricks-profile"],
9655
+ apiUrl: args.flags["api-url"],
9656
+ apiKey: args.flags["api-key"],
9657
+ tenantId: explicitTenantId
9658
+ });
9659
+ if (!hosted.apiUrl || !hosted.apiKey || !hosted.tenantId) {
9660
+ throw new Error("Run fx login first or provide --api-url, --api-key, and --tenant");
9661
+ }
9662
+ return cmdHarness(action, args.positional[1], {
9663
+ apiUrl: hosted.apiUrl,
9664
+ apiKey: hosted.apiKey,
9665
+ tenantId: hosted.tenantId,
9666
+ bearerToken: hosted.bearerToken,
9667
+ input: args.flags.input,
9668
+ json: args.flags.json === true,
9669
+ plain: args.flags.plain === true
9670
+ });
9671
+ }
9465
9672
  case "targets": {
9466
9673
  const action = args.positional[0] ?? "list";
9467
9674
  if (action === "publish") {