@automatify-au/cli 0.1.1 → 0.1.2

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.
Files changed (2) hide show
  1. package/dist/automatify.js +151 -6
  2. package/package.json +1 -1
@@ -1772,7 +1772,7 @@ function parseArgs2(args) {
1772
1772
  const flags = {};
1773
1773
  const boolFlags = /* @__PURE__ */ new Set();
1774
1774
  const unknownFlags = [];
1775
- const supportedValueFlags = /* @__PURE__ */ new Set(["--id", ...CONFIG_FLAGS2]);
1775
+ const supportedValueFlags = /* @__PURE__ */ new Set(["--id", "--test-case-key", ...CONFIG_FLAGS2]);
1776
1776
  const supportedBoolFlags = /* @__PURE__ */ new Set(["--json"]);
1777
1777
  for (let index = 0; index < args.length; index += 1) {
1778
1778
  const token = args[index];
@@ -1847,6 +1847,17 @@ function scenarioToLines(scenario) {
1847
1847
  }
1848
1848
  return lines;
1849
1849
  }
1850
+ function automationToLines(payload, scenarioKey) {
1851
+ return [
1852
+ `Triggered scenario automation for ${scenarioKey}`,
1853
+ `Automation id: ${payload.automation.id}`,
1854
+ `Status: ${payload.automation.lastStatus ?? "queued"}`,
1855
+ `Triggered at: ${payload.automation.lastTriggeredAt ?? "unknown"}`,
1856
+ `Response status: ${payload.responseStatus}`,
1857
+ `Feature: ${payload.automation.label}`,
1858
+ `Scenario: ${scenarioKey}`
1859
+ ];
1860
+ }
1850
1861
  function missingProjectResponse() {
1851
1862
  return {
1852
1863
  exitCode: ExitCode.ValidationError,
@@ -1875,10 +1886,116 @@ function createBddHandler(deps = {}) {
1875
1886
  if (subcommand === "scenarios") {
1876
1887
  const nested = restArgs[0];
1877
1888
  if (nested !== "show") {
1878
- return {
1879
- exitCode: ExitCode.UsageError,
1880
- stderr: ["ERROR: Unsupported bdd scenarios subcommand. Use: testops bdd scenarios show --id <SCENARIO_ID>"]
1881
- };
1889
+ if (nested !== "run") {
1890
+ return {
1891
+ exitCode: ExitCode.UsageError,
1892
+ stderr: [
1893
+ "ERROR: Unsupported bdd scenarios subcommand. Use: testops bdd scenarios show --id <SCENARIO_ID> or testops bdd scenarios run --id <SCENARIO_ID> --test-case-key <TC-197>"
1894
+ ]
1895
+ };
1896
+ }
1897
+ const scenarioId2 = parsed.flags["--id"]?.trim() ?? "";
1898
+ const testCaseKey = parsed.flags["--test-case-key"]?.trim().toUpperCase() ?? "";
1899
+ if (!scenarioId2 && !testCaseKey) {
1900
+ return {
1901
+ exitCode: ExitCode.ValidationError,
1902
+ stderr: ["ERROR: Provide either --id <SCENARIO_ID> or --test-case-key <TC-197> for testops bdd scenarios run."]
1903
+ };
1904
+ }
1905
+ try {
1906
+ let scenarioIds = [];
1907
+ let scenarioLabel = scenarioId2 || testCaseKey;
1908
+ if (testCaseKey && !scenarioId2) {
1909
+ const testCaseResult = await context.invokeForgeContract("getTestCase", {
1910
+ context: {
1911
+ projectKey,
1912
+ issueKey: issueKey || void 0
1913
+ },
1914
+ testCaseKey
1915
+ });
1916
+ if (!testCaseResult.ok) {
1917
+ return {
1918
+ exitCode: ExitCode.RemoteError,
1919
+ stderr: [`ERROR: ${testCaseResult.error.code}: ${testCaseResult.error.message}`]
1920
+ };
1921
+ }
1922
+ const linksResult = await context.invokeForgeContract("listTestCaseScenarioLinks", {
1923
+ context: {
1924
+ projectKey,
1925
+ issueKey: issueKey || void 0
1926
+ }
1927
+ });
1928
+ if (!linksResult.ok) {
1929
+ return {
1930
+ exitCode: ExitCode.RemoteError,
1931
+ stderr: [`ERROR: ${linksResult.error.code}: ${linksResult.error.message}`]
1932
+ };
1933
+ }
1934
+ const testCase = testCaseResult.data;
1935
+ scenarioIds = linksResult.data.filter((link) => link.testCaseId === testCase.id).map((link) => link.scenarioId);
1936
+ if (scenarioIds.length === 0) {
1937
+ return {
1938
+ exitCode: ExitCode.RemoteError,
1939
+ stderr: [`ERROR: No linked scenarios were found for test case ${testCase.key}.`]
1940
+ };
1941
+ }
1942
+ scenarioLabel = `${testCase.key} (${scenarioIds.length} scenario${scenarioIds.length === 1 ? "" : "s"})`;
1943
+ } else if (scenarioId2) {
1944
+ scenarioIds = [scenarioId2];
1945
+ }
1946
+ const runs = [];
1947
+ for (const currentScenarioId of scenarioIds) {
1948
+ const result = await context.invokeForgeContract("runScenarioAutomation", {
1949
+ context: {
1950
+ projectKey,
1951
+ issueKey: issueKey || void 0
1952
+ },
1953
+ scenarioId: currentScenarioId
1954
+ });
1955
+ if (!result.ok) {
1956
+ return {
1957
+ exitCode: ExitCode.RemoteError,
1958
+ stderr: [`ERROR: ${result.error.code}: ${result.error.message}`]
1959
+ };
1960
+ }
1961
+ runs.push(result.data);
1962
+ }
1963
+ if (useJson) {
1964
+ return {
1965
+ exitCode: ExitCode.Success,
1966
+ stdout: toJsonLine({
1967
+ action: "bdd-scenarios-run",
1968
+ projectKey,
1969
+ issueKey: issueKey || null,
1970
+ item: {
1971
+ scenarioLabel,
1972
+ runCount: runs.length,
1973
+ runs: runs.map((run) => ({
1974
+ automationId: run.automation.id,
1975
+ label: run.automation.label,
1976
+ status: run.automation.lastStatus ?? "queued",
1977
+ externalRunId: run.automation.externalRunId ?? null,
1978
+ externalRunUrl: run.automation.externalRunUrl ?? null,
1979
+ responseStatus: run.responseStatus
1980
+ }))
1981
+ }
1982
+ })
1983
+ };
1984
+ }
1985
+ return {
1986
+ exitCode: ExitCode.Success,
1987
+ stdout: [
1988
+ `Scenario automation dispatches: ${runs.length}`,
1989
+ `Target: ${scenarioLabel}`,
1990
+ ...runs.flatMap((run) => automationToLines(run, scenarioLabel))
1991
+ ]
1992
+ };
1993
+ } catch (error) {
1994
+ return {
1995
+ exitCode: ExitCode.TransportError,
1996
+ stderr: [`ERROR: ${normalizeError(error)}`]
1997
+ };
1998
+ }
1882
1999
  }
1883
2000
  const scenarioId = parsed.flags["--id"]?.trim() ?? "";
1884
2001
  if (!scenarioId) {
@@ -2806,6 +2923,8 @@ function parseArgs6(args) {
2806
2923
  const unknownFlags = [];
2807
2924
  const valuedFlags = /* @__PURE__ */ new Set([
2808
2925
  "--file",
2926
+ "--scenario-id",
2927
+ "--test-case-key",
2809
2928
  "--feature-name",
2810
2929
  "--scenario-name",
2811
2930
  "--executed-at",
@@ -2903,7 +3022,9 @@ function mergeMetadataOverrides(input, parsed) {
2903
3022
  featureName: (parsed.flags["--feature-name"] ?? input.featureName ?? "").trim(),
2904
3023
  scenarioName: (parsed.flags["--scenario-name"] ?? input.scenarioName ?? "").trim(),
2905
3024
  executedAt: (parsed.flags["--executed-at"] ?? input.executedAt ?? "").trim(),
2906
- steps: Array.isArray(input.steps) ? input.steps : []
3025
+ scenarioId: (parsed.flags["--scenario-id"] ?? input.scenarioId ?? "").trim() || void 0,
3026
+ steps: Array.isArray(input.steps) ? input.steps : [],
3027
+ testCaseIds: Array.isArray(input.testCaseIds) ? input.testCaseIds : []
2907
3028
  };
2908
3029
  }
2909
3030
  function summarizeRunResult(result) {
@@ -2932,6 +3053,7 @@ function createRunUploadHandler(deps = {}) {
2932
3053
  const config = resolveCliConfig(configArgs, env, cwd);
2933
3054
  const projectKey = config.values.projectKey;
2934
3055
  const issueKey = config.values.issueKey;
3056
+ const testCaseKey = parsed.flags["--test-case-key"]?.trim().toUpperCase() ?? "";
2935
3057
  const sourceFile = parsed.flags["--file"] ? path7.resolve(cwd, parsed.flags["--file"]) : "";
2936
3058
  const useStdin = parsed.boolFlags.has("--stdin");
2937
3059
  const useJson = parsed.boolFlags.has("--json");
@@ -2971,6 +3093,29 @@ function createRunUploadHandler(deps = {}) {
2971
3093
  };
2972
3094
  }
2973
3095
  const runInput = mergeMetadataOverrides(payloadFromSource, parsed);
3096
+ if (testCaseKey) {
3097
+ try {
3098
+ const testCaseResult = await context.invokeForgeContract("getTestCase", {
3099
+ context: {
3100
+ projectKey,
3101
+ issueKey: issueKey || void 0
3102
+ },
3103
+ testCaseKey
3104
+ });
3105
+ if (!testCaseResult.ok) {
3106
+ return {
3107
+ exitCode: ExitCode.RemoteError,
3108
+ stderr: [`ERROR: ${testCaseResult.error.code}: ${testCaseResult.error.message}`]
3109
+ };
3110
+ }
3111
+ runInput.testCaseIds = [.../* @__PURE__ */ new Set([...runInput.testCaseIds ?? [], testCaseResult.data.id])];
3112
+ } catch (error) {
3113
+ return {
3114
+ exitCode: ExitCode.TransportError,
3115
+ stderr: [`ERROR: ${normalizeError4(error)}`]
3116
+ };
3117
+ }
3118
+ }
2974
3119
  const validationErrors = validateRunInput(runInput);
2975
3120
  if (validationErrors.length > 0) {
2976
3121
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automatify-au/cli",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Forge-first CLI for Automatify Jira TestOps",
5
5
  "type": "module",
6
6
  "bin": {