From 06194d1dd1ad989229090e145951914abdf3fef8 Mon Sep 17 00:00:00 2001 From: Stefan Rinke Date: Wed, 30 Jul 2025 15:12:46 +0200 Subject: [PATCH 1/2] fix url fix config file --- README.md | 22 ++++++++++++++++++++-- package.json | 2 +- src/config.ts | 29 ++++++++++++++++++++--------- src/url.ts | 16 ++++++++-------- tests/config.spec.ts | 4 ++-- 5 files changed, 51 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index e2b95ff..17472c2 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ See [API documentation](https://octomind.dev/docs/api-reference/) # octomind -Octomind cli tool. Version: 1.0.5. Additional documentation see https://octomind.dev/docs/api-reference/ +Octomind cli tool. Version: 1.1.1. Additional documentation see https://octomind.dev/docs/api-reference/ **Usage:** `octomind [options] [command]` @@ -26,7 +26,7 @@ Octomind cli tool. Version: 1.0.5. Additional documentation see https://octomind # octomind CLI Documentation -Octomind cli tool. Version: 1.0.5. Additional documentation see https://octomind.dev/docs/api-reference/ +Octomind cli tool. Version: 1.1.1. Additional documentation see https://octomind.dev/docs/api-reference/ ## Commands @@ -44,6 +44,12 @@ Initialize configuration by setting up API key | `-k, --api-key ` | the api key for authentication | Yes | | | `-f, --force` | Force overwrite existing configuration | No | | +## switch-test-target + +Switch to a different test target + +**Usage:** `switch-test-target [options]` + ## debug run test cases against local build @@ -287,6 +293,18 @@ List all test cases | `-j, --json` | Output raw JSON response | No | | | `-t, --test-target-id [id]` | Test target ID, if not provided will use the test target id from the config | No | | +## list-test-targets + +List all test targets + +**Usage:** `list-test-targets [options]` + +### Options + +| Option | Description | Required | Default | +|--------|-------------|----------|--------| +| `-j, --json` | Output raw JSON response | No | | + ## Output Formats diff --git a/package.json b/package.json index 3b7a3f3..67dacfd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@octomind/octomind", - "version": "1.0.5", + "version": "1.1.1", "description": "a command line client for octomind apis", "main": "./dist/index.js", "packageManager": "pnpm@10.13.1", diff --git a/src/config.ts b/src/config.ts index 46703bc..1286037 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,20 +1,31 @@ -import path from "path"; import fs from "fs/promises"; +import { homedir } from 'os'; +import { join } from 'path'; +import { existsSync } from 'fs'; + +const OCTOMIND_CONFIG_FILE = "octomind.json"; +const CONFIG_DIR = ".config"; + +export async function getConfigPath(): Promise { + const homeDir = homedir(); + const configDir = join(homeDir, CONFIG_DIR); + const configPath = join(configDir, OCTOMIND_CONFIG_FILE); + + if (!existsSync(configDir)) { + await fs.mkdir(configDir, { recursive: true }); + } + + return configPath; +} export interface Config { apiKey?: string; testTargetId?: string; } -const OCTOMIND_CONFIG_FILE = "octomind.config.json"; - -export function getConfigPath(): string { - return path.join(process.cwd(), OCTOMIND_CONFIG_FILE); -} - export async function loadConfig(force?: boolean): Promise { try { - const configPath = getConfigPath(); + const configPath = await getConfigPath(); const data = await fs.readFile(configPath, "utf8"); return JSON.parse(data); } catch (error) { @@ -32,7 +43,7 @@ export async function loadConfig(force?: boolean): Promise { export async function saveConfig(config: Config): Promise { try { - const configPath = getConfigPath(); + const configPath = await getConfigPath(); await fs.writeFile(configPath, JSON.stringify(config, null, 2), "utf8"); console.log(`✅ Configuration saved to ${configPath}`); } catch (error) { diff --git a/src/url.ts b/src/url.ts index 25aa7e7..de82822 100644 --- a/src/url.ts +++ b/src/url.ts @@ -15,20 +15,20 @@ export const getUrl = async ( ): Promise => { const relevantBaseUrl = new URL(BASE_URL).origin; const config = await loadConfig(); - const testTargetId = config.testTargetId; - if (!testTargetId) { - throw new Error("Test target id is not set"); + const configuredTestTargetId = config.testTargetId; + if (!configuredTestTargetId && input.entityType !== "test-target") { + return ""; } switch (input.entityType) { case "test-case": - return `${relevantBaseUrl}/testtargets/${testTargetId}/testcases?testCaseId=${input.testCaseId}`; + return `${relevantBaseUrl}/testtargets/${configuredTestTargetId}/testcases?testCaseId=${input.testCaseId}`; case "test-target": - return `${relevantBaseUrl}/testtargets/${testTargetId}`; + return `${relevantBaseUrl}/testtargets/${input.testTargetId}`; case "test-report": - return `${relevantBaseUrl}/testtargets/${testTargetId}/testreports/${input.testReportId}`; + return `${relevantBaseUrl}/testtargets/${configuredTestTargetId}/testreports/${input.testReportId}`; case "test-result": - return `${relevantBaseUrl}/testtargets/${testTargetId}/testreports/${input.testReportId}/testresults/${input.testResultId}`; + return `${relevantBaseUrl}/testtargets/${configuredTestTargetId}/testreports/${input.testReportId}/testresults/${input.testResultId}`; case "discovery": - return `${relevantBaseUrl}/testtargets/${testTargetId}/testcases/${input.testCaseId}`; + return `${relevantBaseUrl}/testtargets/${configuredTestTargetId}/testcases/${input.testCaseId}`; } }; diff --git a/tests/config.spec.ts b/tests/config.spec.ts index 33a793a..29e738e 100644 --- a/tests/config.spec.ts +++ b/tests/config.spec.ts @@ -1,7 +1,7 @@ import fs from "fs/promises"; import path from "path"; import { loadConfig, Config } from "../src/config"; - +import { homedir } from "os"; jest.mock("fs/promises"); const mockedFs = fs as jest.Mocked; @@ -29,7 +29,7 @@ describe("Config", () => { expect(result).toEqual(mockConfig); expect(mockedFs.readFile).toHaveBeenCalledWith( - path.join(process.cwd(), "octomind.config.json"), + path.join(homedir(), ".config", "octomind.json"), "utf8", ); }); From abfe2aac1180fdef7dc7c9b55cdc4cfdd7bd5efd Mon Sep 17 00:00:00 2001 From: Stefan Rinke Date: Wed, 30 Jul 2025 15:22:38 +0200 Subject: [PATCH 2/2] mkdir only when write --- src/config.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config.ts b/src/config.ts index 1286037..9a8da42 100644 --- a/src/config.ts +++ b/src/config.ts @@ -6,12 +6,12 @@ import { existsSync } from 'fs'; const OCTOMIND_CONFIG_FILE = "octomind.json"; const CONFIG_DIR = ".config"; -export async function getConfigPath(): Promise { +export async function getConfigPath(ensureDir?: boolean): Promise { const homeDir = homedir(); const configDir = join(homeDir, CONFIG_DIR); const configPath = join(configDir, OCTOMIND_CONFIG_FILE); - if (!existsSync(configDir)) { + if (ensureDir && !existsSync(configDir)) { await fs.mkdir(configDir, { recursive: true }); } @@ -43,7 +43,7 @@ export async function loadConfig(force?: boolean): Promise { export async function saveConfig(config: Config): Promise { try { - const configPath = await getConfigPath(); + const configPath = await getConfigPath(true); await fs.writeFile(configPath, JSON.stringify(config, null, 2), "utf8"); console.log(`✅ Configuration saved to ${configPath}`); } catch (error) {