@fabricorg/experiments 0.6.1 → 0.6.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/README.md +11 -0
- package/dist/bin/fx.cjs +124 -15
- package/dist/bin/fx.cjs.map +1 -1
- package/dist/bin/fx.js +124 -15
- package/dist/bin/fx.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -41,8 +41,19 @@ fx dev Start local dev server.
|
|
|
41
41
|
fx publish Sign current manifest; optionally push to manifest-worker.
|
|
42
42
|
fx report <experimentId> Print results for an experiment.
|
|
43
43
|
fx kill <experimentId> Kill a running experiment. Requires --reason.
|
|
44
|
+
fx import-mojito <dir> Convert Mojito waves and emit a compatibility report.
|
|
44
45
|
```
|
|
45
46
|
|
|
47
|
+
For a migration gate that fails until every trigger and asset is portable:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
fx import-mojito ./waves --out ./experiments --strict
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Common pathname, URL-contains, DOM-ready, and wait-for-element triggers are
|
|
54
|
+
converted automatically. `import-report.json` inventories every conversion and
|
|
55
|
+
manual-review warning.
|
|
56
|
+
|
|
46
57
|
## Docs
|
|
47
58
|
|
|
48
59
|
Full documentation: [https://experiments.fabric.pro](https://experiments.fabric.pro)
|
package/dist/bin/fx.cjs
CHANGED
|
@@ -7089,7 +7089,8 @@ async function cmdImportMojito(inputDir, options = {}) {
|
|
|
7089
7089
|
results.push({
|
|
7090
7090
|
source: waveDir,
|
|
7091
7091
|
target: "",
|
|
7092
|
-
warnings: [`failed to convert: ${e.message}`]
|
|
7092
|
+
warnings: [`failed to convert: ${e.message}`],
|
|
7093
|
+
trigger: "manual"
|
|
7093
7094
|
});
|
|
7094
7095
|
}
|
|
7095
7096
|
}
|
|
@@ -7106,8 +7107,36 @@ async function cmdImportMojito(inputDir, options = {}) {
|
|
|
7106
7107
|
for (const w of r.warnings) process.stdout.write(` ! ${w}
|
|
7107
7108
|
`);
|
|
7108
7109
|
}
|
|
7110
|
+
const reportFile = path.resolve(options.reportFile ?? path.join(outDir, "import-report.json"));
|
|
7111
|
+
await promises.writeFile(
|
|
7112
|
+
reportFile,
|
|
7113
|
+
`${JSON.stringify(
|
|
7114
|
+
{
|
|
7115
|
+
schemaVersion: 1,
|
|
7116
|
+
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
7117
|
+
input: root,
|
|
7118
|
+
output: outDir,
|
|
7119
|
+
summary: {
|
|
7120
|
+
waves: results.length,
|
|
7121
|
+
converted: results.filter((result) => result.target).length,
|
|
7122
|
+
failed: results.filter((result) => !result.target).length,
|
|
7123
|
+
manualReview: results.filter((result) => result.warnings.length > 0).length
|
|
7124
|
+
},
|
|
7125
|
+
waves: results
|
|
7126
|
+
},
|
|
7127
|
+
null,
|
|
7128
|
+
2
|
|
7129
|
+
)}
|
|
7130
|
+
`,
|
|
7131
|
+
"utf8"
|
|
7132
|
+
);
|
|
7133
|
+
process.stdout.write(`
|
|
7134
|
+
Compatibility report: ${reportFile}
|
|
7135
|
+
`);
|
|
7109
7136
|
const failed = results.filter((r) => !r.target).length;
|
|
7110
|
-
|
|
7137
|
+
if (failed > 0) return 2;
|
|
7138
|
+
if (options.strict && results.some((result) => result.warnings.length > 0)) return 3;
|
|
7139
|
+
return 0;
|
|
7111
7140
|
}
|
|
7112
7141
|
async function findWaves(root) {
|
|
7113
7142
|
const out = [];
|
|
@@ -7162,12 +7191,23 @@ async function convertWave(waveDir, outDir) {
|
|
|
7162
7191
|
variants.push(variant);
|
|
7163
7192
|
}
|
|
7164
7193
|
let triggerNote = null;
|
|
7194
|
+
let convertedTrigger;
|
|
7195
|
+
let triggerMigration = "none";
|
|
7165
7196
|
if (cfg.trigger) {
|
|
7166
7197
|
triggerNote = await promises.readFile(path.join(waveDir, cfg.trigger), "utf8").catch(() => "");
|
|
7167
7198
|
if (triggerNote) {
|
|
7168
|
-
|
|
7169
|
-
|
|
7170
|
-
|
|
7199
|
+
const translated = translateCommonTrigger(triggerNote);
|
|
7200
|
+
convertedTrigger = translated.trigger;
|
|
7201
|
+
triggerMigration = translated.kind;
|
|
7202
|
+
if (!translated.trigger) {
|
|
7203
|
+
warnings.push(
|
|
7204
|
+
"trigger.js was not auto-converted \u2014 review and translate to a Trigger DSL or host-supplied trigger override."
|
|
7205
|
+
);
|
|
7206
|
+
triggerMigration = "manual";
|
|
7207
|
+
}
|
|
7208
|
+
} else {
|
|
7209
|
+
warnings.push(`trigger file not found: ${cfg.trigger}`);
|
|
7210
|
+
triggerMigration = "manual";
|
|
7171
7211
|
}
|
|
7172
7212
|
}
|
|
7173
7213
|
let sharedJs;
|
|
@@ -7194,20 +7234,47 @@ async function convertWave(waveDir, outDir) {
|
|
|
7194
7234
|
if (cfg.manualExposure) spec.manualExposure = true;
|
|
7195
7235
|
if (sharedJs) spec.sharedJs = sharedJs;
|
|
7196
7236
|
if (sharedCss) spec.sharedCss = sharedCss;
|
|
7197
|
-
if (triggerNote) spec.trigger = { kind: "auto" };
|
|
7237
|
+
if (triggerNote) spec.trigger = convertedTrigger ?? { kind: "auto" };
|
|
7198
7238
|
const header = [
|
|
7199
7239
|
"# Imported from Mojito wave",
|
|
7200
7240
|
`# Source: ${waveDir}`,
|
|
7201
7241
|
cfg.state ? `# Original state: ${cfg.state}` : null,
|
|
7202
7242
|
triggerNote ? "#" : null,
|
|
7203
|
-
triggerNote ? "# Original trigger.js (NOT auto-applied):" : null,
|
|
7243
|
+
triggerNote ? convertedTrigger ? `# Original trigger.js (auto-converted to ${String(convertedTrigger.kind)}):` : "# Original trigger.js (NOT auto-applied):" : null,
|
|
7204
7244
|
triggerNote ? triggerNote.split("\n").map((l) => `# ${l}`).join("\n") : null
|
|
7205
7245
|
].filter((l) => l !== null).join("\n");
|
|
7206
7246
|
const yamlBody = yaml.stringify(spec);
|
|
7207
7247
|
const target = path.join(outDir, `${spec.id}.yaml`);
|
|
7208
7248
|
await promises.writeFile(target, `${header}
|
|
7209
7249
|
${yamlBody}`, "utf8");
|
|
7210
|
-
return { source: waveDir, target, warnings };
|
|
7250
|
+
return { source: waveDir, target, warnings, trigger: triggerMigration };
|
|
7251
|
+
}
|
|
7252
|
+
function translateCommonTrigger(source) {
|
|
7253
|
+
const selector = source.match(/(?:waitForElement|waitForSelector)\s*\(\s*(['"])([^'"]+)\1/);
|
|
7254
|
+
if (selector?.[2]) {
|
|
7255
|
+
return {
|
|
7256
|
+
trigger: { kind: "waitForSelector", selector: selector[2] },
|
|
7257
|
+
kind: "waitForSelector"
|
|
7258
|
+
};
|
|
7259
|
+
}
|
|
7260
|
+
const pathname = source.match(/(?:document\.)?location\.pathname\s*={2,3}\s*(['"])([^'"]+)\1/);
|
|
7261
|
+
if (pathname?.[2]) {
|
|
7262
|
+
const escaped = pathname[2].replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
7263
|
+
return {
|
|
7264
|
+
trigger: { kind: "urlMatch", pattern: `https?://[^/]+${escaped}(?:[?#]|$)`, regex: true },
|
|
7265
|
+
kind: "urlMatch"
|
|
7266
|
+
};
|
|
7267
|
+
}
|
|
7268
|
+
const hrefIncludes = source.match(
|
|
7269
|
+
/(?:document\.)?location\.href\.(?:includes|indexOf)\s*\(\s*(['"])([^'"]+)\1/
|
|
7270
|
+
);
|
|
7271
|
+
if (hrefIncludes?.[2]) {
|
|
7272
|
+
return { trigger: { kind: "urlMatch", pattern: hrefIncludes[2] }, kind: "urlMatch" };
|
|
7273
|
+
}
|
|
7274
|
+
if (/\bdomReady\s*\(/.test(source) && !/\bif\s*\(/.test(source)) {
|
|
7275
|
+
return { trigger: { kind: "auto" }, kind: "auto" };
|
|
7276
|
+
}
|
|
7277
|
+
return { kind: "manual" };
|
|
7211
7278
|
}
|
|
7212
7279
|
function normalizeKey(k) {
|
|
7213
7280
|
return k.toLowerCase().replace(/[^a-z0-9_-]/g, "-");
|
|
@@ -7827,14 +7894,17 @@ var ApiClient = class {
|
|
|
7827
7894
|
orgId: this.opts.defaultOrgId,
|
|
7828
7895
|
...pathParams ?? {}
|
|
7829
7896
|
};
|
|
7830
|
-
const
|
|
7897
|
+
const baseUrl = this.opts.baseUrl.endsWith("/") ? this.opts.baseUrl : `${this.opts.baseUrl}/`;
|
|
7898
|
+
const endpointPath = buildPath(def.path, merged).replace(/^\//, "");
|
|
7899
|
+
const url = new URL(endpointPath, baseUrl);
|
|
7831
7900
|
const init = {
|
|
7832
7901
|
method: def.method,
|
|
7833
7902
|
headers: {
|
|
7834
7903
|
accept: "application/json",
|
|
7835
7904
|
// Hosted Fabric API keys use their own header so upstream auth
|
|
7836
7905
|
// middleware cannot mistake them for OAuth bearer credentials.
|
|
7837
|
-
...this.opts.apiKey ? { "x-api-key": this.opts.apiKey } : {}
|
|
7906
|
+
...this.opts.apiKey ? { "x-api-key": this.opts.apiKey } : {},
|
|
7907
|
+
...this.opts.bearerToken ? { authorization: `Bearer ${this.opts.bearerToken}` } : {}
|
|
7838
7908
|
},
|
|
7839
7909
|
credentials: "include"
|
|
7840
7910
|
};
|
|
@@ -8136,7 +8206,7 @@ var FILES = {
|
|
|
8136
8206
|
devDependencies: {
|
|
8137
8207
|
"@cucumber/cucumber": "^13.0.0",
|
|
8138
8208
|
"@duckdb/node-api": "^1.5.0",
|
|
8139
|
-
"@fabricorg/databricks-bdd": "^0.3.
|
|
8209
|
+
"@fabricorg/databricks-bdd": "^0.3.2",
|
|
8140
8210
|
tsx: "^4.19.2",
|
|
8141
8211
|
typescript: "^5.8.3"
|
|
8142
8212
|
}
|
|
@@ -8469,7 +8539,13 @@ async function cmdTestPublish(evidencePath, options = {}) {
|
|
|
8469
8539
|
}
|
|
8470
8540
|
const evidence = parseEvidenceText(await promises.readFile(path.resolve(evidencePath), "utf8"));
|
|
8471
8541
|
const input = normalizeTestEvidence(evidence, { ...options, env });
|
|
8472
|
-
const
|
|
8542
|
+
const bearerToken = options.bearerToken ?? await resolveGatewayToken(apiUrl, env);
|
|
8543
|
+
const api = new ApiClient({
|
|
8544
|
+
baseUrl: apiUrl,
|
|
8545
|
+
apiKey,
|
|
8546
|
+
...bearerToken ? { bearerToken } : {},
|
|
8547
|
+
defaultOrgId: tenantId
|
|
8548
|
+
});
|
|
8473
8549
|
const created = await api.testRuns.create(input);
|
|
8474
8550
|
process.stdout.write(
|
|
8475
8551
|
`Published ${created.source} run ${created.id}: ${created.status} (${created.summary.passed}/${created.summary.total} passed)
|
|
@@ -8477,6 +8553,32 @@ async function cmdTestPublish(evidencePath, options = {}) {
|
|
|
8477
8553
|
);
|
|
8478
8554
|
return 0;
|
|
8479
8555
|
}
|
|
8556
|
+
async function resolveGatewayToken(apiUrl, env) {
|
|
8557
|
+
if (env.FX_GATEWAY_BEARER_TOKEN) return env.FX_GATEWAY_BEARER_TOKEN;
|
|
8558
|
+
if (!new URL(apiUrl).hostname.endsWith(".databricksapps.com")) return void 0;
|
|
8559
|
+
const host = env.DATABRICKS_HOST?.replace(/\/$/, "");
|
|
8560
|
+
const clientId = env.FX_QUALITY_DATABRICKS_CLIENT_ID ?? env.DATABRICKS_CLIENT_ID;
|
|
8561
|
+
const clientSecret = env.FX_QUALITY_DATABRICKS_CLIENT_SECRET ?? env.DATABRICKS_CLIENT_SECRET;
|
|
8562
|
+
if (!host || !clientId || !clientSecret) {
|
|
8563
|
+
throw new Error("Databricks Apps publication requires DATABRICKS_HOST and client credentials");
|
|
8564
|
+
}
|
|
8565
|
+
const response = await fetch(`${host}/oidc/v1/token`, {
|
|
8566
|
+
method: "POST",
|
|
8567
|
+
headers: {
|
|
8568
|
+
authorization: `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString("base64")}`,
|
|
8569
|
+
"content-type": "application/x-www-form-urlencoded"
|
|
8570
|
+
},
|
|
8571
|
+
body: new URLSearchParams({ grant_type: "client_credentials", scope: "all-apis" })
|
|
8572
|
+
});
|
|
8573
|
+
if (!response.ok) {
|
|
8574
|
+
throw new Error(`Databricks OAuth failed (${response.status} ${response.statusText})`);
|
|
8575
|
+
}
|
|
8576
|
+
const body = await response.json();
|
|
8577
|
+
if (typeof body.access_token !== "string" || !body.access_token) {
|
|
8578
|
+
throw new Error("Databricks OAuth response did not include an access token");
|
|
8579
|
+
}
|
|
8580
|
+
return body.access_token;
|
|
8581
|
+
}
|
|
8480
8582
|
function normalizeTestEvidence(value, options = {}) {
|
|
8481
8583
|
if (!value || typeof value !== "object") throw new Error("Evidence must be a JSON object");
|
|
8482
8584
|
const evidence = value;
|
|
@@ -8719,10 +8821,13 @@ GLOBAL FLAGS
|
|
|
8719
8821
|
--external-id <id> test publish: idempotent CI run identifier
|
|
8720
8822
|
--run-url <url> test publish: CI artifact/run link
|
|
8721
8823
|
--key-id <id> publish: keyId to sign with (default: dev-default)
|
|
8824
|
+
--out <dir> import-mojito: output directory
|
|
8825
|
+
--report <file> import-mojito: compatibility report path
|
|
8826
|
+
--strict import-mojito: fail while manual-review warnings remain
|
|
8722
8827
|
-h, --help print this help
|
|
8723
8828
|
-v, --version print version
|
|
8724
8829
|
`;
|
|
8725
|
-
var VERSION2 = "0.6.
|
|
8830
|
+
var VERSION2 = "0.6.3";
|
|
8726
8831
|
function parse2(argv) {
|
|
8727
8832
|
const positional = [];
|
|
8728
8833
|
const flags = {};
|
|
@@ -8836,11 +8941,15 @@ async function main() {
|
|
|
8836
8941
|
});
|
|
8837
8942
|
case "import-mojito":
|
|
8838
8943
|
if (!args.positional[0]) {
|
|
8839
|
-
process.stderr.write(
|
|
8944
|
+
process.stderr.write(
|
|
8945
|
+
"Usage: fx import-mojito <dir> [--out <out-dir>] [--report <file>] [--strict]\n"
|
|
8946
|
+
);
|
|
8840
8947
|
return 1;
|
|
8841
8948
|
}
|
|
8842
8949
|
return cmdImportMojito(args.positional[0], {
|
|
8843
|
-
outputDir: args.flags.out
|
|
8950
|
+
outputDir: args.flags.out,
|
|
8951
|
+
reportFile: args.flags.report,
|
|
8952
|
+
strict: args.flags.strict === true});
|
|
8844
8953
|
case "preview":
|
|
8845
8954
|
if (!args.positional[0]) {
|
|
8846
8955
|
process.stderr.write(
|