From bcf4bab1a1f203f658b0efcb05dcd62ad83dc1bd Mon Sep 17 00:00:00 2001 From: Maximilian Link Date: Fri, 25 Jul 2025 13:17:38 +0200 Subject: [PATCH 1/3] add list test targets --- src/tools/test-targets.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/tools/test-targets.ts diff --git a/src/tools/test-targets.ts b/src/tools/test-targets.ts new file mode 100644 index 0000000..fd0b170 --- /dev/null +++ b/src/tools/test-targets.ts @@ -0,0 +1,13 @@ +import { client, handleError } from "./client"; + +export const getTestTargets = async () => { + const { data, error } = await client.GET("/apiKey/v2/test-targets"); + + handleError(error); + + if (!data) { + throw Error("No test targets found"); + } + + return data; +}; From a47d1373f6ea5e33e2b18fad64a3b3d1d5418e4f Mon Sep 17 00:00:00 2001 From: Maximilian Link Date: Fri, 25 Jul 2025 13:55:02 +0200 Subject: [PATCH 2/3] list test targets and allow switching test targets --- src/cli.ts | 51 +++++++++++++++++++++++++++++++++++---- src/tools/test-targets.ts | 21 +++++++++++++++- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 52de606..6697058 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -20,6 +20,7 @@ import { promptUser, resolveTestTargetId } from "./helpers"; import { runDebugtopus } from "./debugtopus"; import { startPrivateLocationWorker, stopPLW } from "./plw"; +import { getTestTargets, listTestTargets } from "./tools/test-targets"; const createCommandWithCommonOptions = (command: string): Command => { return program @@ -30,6 +31,26 @@ const createCommandWithCommonOptions = (command: string): Command => { const splitter = (value: string): string[] => value.split(/,| |\|/); const toJSON = (value: string): object => JSON.parse(value); +const selectTestTarget = async (): Promise => { + const testTargets = await getTestTargets(); + await listTestTargets({}); + + if (testTargets.length === 1 && testTargets[0]?.id) { + return testTargets[0].id; + } + + const testTargetIndex = await promptUser( + "Enter number of the test target you want to use (optional, press Enter to skip): " + ); + const testTargetId = testTargets[Number.parseInt(testTargetIndex) - 1].id; + if (!testTargetId) { + console.log("❌ could not find a test target with the index you provided"); + process.exit(1); + } + + return testTargetId; +} + export const buildCmd = (): Command => { program .name("octomind-cli") @@ -80,12 +101,14 @@ export const buildCmd = (): Command => { process.exit(1); } } - let testTargetId; - if (!options.testTargetId) { - testTargetId = await promptUser( - "Enter test target id (optional, press Enter to skip): " - ); + // saving here to be able to use the api key for the test targets + const newApiKeyConfig = { + ...existingConfig, + apiKey: options.apiKey ?? apiKey, } + await saveConfig(newApiKeyConfig); + + const testTargetId = await selectTestTarget(); const newConfig: Config = { ...existingConfig, @@ -106,6 +129,20 @@ export const buildCmd = (): Command => { } ); + program + .command("switch-test-target") + .description("Switch to a different test target") + .action(async () => { + const testTargetId = await selectTestTarget(); + const existingConfig = await loadConfig(); + const newConfig: Config = { + ...existingConfig, + testTargetId, + }; + await saveConfig(newConfig); + console.log(`✨ Switched to test target: ${testTargetId}`); + }); + createCommandWithCommonOptions("debug") .description("run test cases against local build") .requiredOption("-u, --url ", "url the tests should run against") @@ -321,5 +358,9 @@ export const buildCmd = (): Command => { void listTestCases({...options, status: "ENABLED"}); }); + createCommandWithCommonOptions("list-test-targets") + .description("List all test targets") + .action(listTestTargets); + return program; }; diff --git a/src/tools/test-targets.ts b/src/tools/test-targets.ts index fd0b170..eec6c0e 100644 --- a/src/tools/test-targets.ts +++ b/src/tools/test-targets.ts @@ -1,4 +1,4 @@ -import { client, handleError } from "./client"; +import { client, handleError, ListOptions, logJson } from "./client"; export const getTestTargets = async () => { const { data, error } = await client.GET("/apiKey/v2/test-targets"); @@ -11,3 +11,22 @@ export const getTestTargets = async () => { return data; }; + +export const listTestTargets = async (options: ListOptions): Promise => { + const testTargets = await getTestTargets(); + + if (options.json) { + logJson(testTargets); + return; + } + + console.log("Test Targets:"); + testTargets.forEach((testTarget, idx) => { + const idxString = `${idx + 1}. `.padEnd( + testTargets.length.toString().length + 2, + ); + const paddingString = " ".repeat(idxString.length); + console.log(`${idxString}ID: ${testTarget.id}`); + console.log(`${paddingString}App: ${testTarget.app}`); + }); +}; From dbbb759efa758b1c1a19080af16d8e2b3b888054 Mon Sep 17 00:00:00 2001 From: Maximilian Link Date: Fri, 25 Jul 2025 13:56:53 +0200 Subject: [PATCH 3/3] fix schema --- openapi.yaml | 3 +++ src/cli.ts | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/openapi.yaml b/openapi.yaml index 0b520ba..dd75b6b 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -919,6 +919,9 @@ components: items: $ref: "#/components/schemas/EnvironmentSimpleResponse" description: The environments of the test target + required: + - id + - app TestTargetUpdateRequest: type: object properties: diff --git a/src/cli.ts b/src/cli.ts index 6697058..676e258 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -35,7 +35,8 @@ const selectTestTarget = async (): Promise => { const testTargets = await getTestTargets(); await listTestTargets({}); - if (testTargets.length === 1 && testTargets[0]?.id) { + if (testTargets.length === 1) { + console.log(`Only one test target found, using it: ${testTargets[0].app} (${testTargets[0].id})`); return testTargets[0].id; }