From 76e624b4c11b4949ed8077565c016e26e9d35b40 Mon Sep 17 00:00:00 2001 From: Daniel Draper Date: Wed, 17 Dec 2025 16:43:48 +0100 Subject: [PATCH 1/5] try in ci --- src/tools/sync/git.ts | 3 ++- src/tools/sync/push.ts | 4 +++- tests/tools/sync/git.integration.spec.ts | 6 +++++- tests/tools/sync/push.spec.ts | 13 +++++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/tools/sync/git.ts b/src/tools/sync/git.ts index 3e07f65..8dea2df 100644 --- a/src/tools/sync/git.ts +++ b/src/tools/sync/git.ts @@ -92,7 +92,8 @@ export const getGitContext = async (): Promise => { defaultBranch, }; return ctx; - } catch { + } catch (e) { + console.warn("could not identify git context, falling back to undefined", e); return undefined; } }; diff --git a/src/tools/sync/push.ts b/src/tools/sync/push.ts index 379b15d..89ea1bb 100644 --- a/src/tools/sync/push.ts +++ b/src/tools/sync/push.ts @@ -19,6 +19,7 @@ type ErrorResponse = type PushOptions = { testTargetId: string; sourceDir: string; + branchName?: string; client: Client; onError: (error: ErrorResponse) => void; }; @@ -29,7 +30,8 @@ export const push = async ( const testCases = readTestCasesFromDir(options.sourceDir); checkForConsistency(testCases); const context = await getGitContext(); - const isDefaultBranch = context?.defaultBranch === context?.ref; + const refName = options.branchName ?? context?.ref + const isDefaultBranch = !!context && context.defaultBranch === refName const body: TestTargetSyncData = { testCases, diff --git a/tests/tools/sync/git.integration.spec.ts b/tests/tools/sync/git.integration.spec.ts index 84e5738..e6be6c4 100644 --- a/tests/tools/sync/git.integration.spec.ts +++ b/tests/tools/sync/git.integration.spec.ts @@ -1,4 +1,4 @@ -import {getDefaultBranch, parseGitRemote} from "../../../src/tools/sync/git"; +import {getDefaultBranch, getGitContext, parseGitRemote} from "../../../src/tools/sync/git"; describe('git', () => { it("should return the actual owner and repo", async () => { @@ -14,5 +14,9 @@ describe('git', () => { expect(defaultBranch).toEqual("refs/heads/main"); }); + it("returns a context", async () => { + const context = await getGitContext() + expect(context).toBeDefined() + }); }) \ No newline at end of file diff --git a/tests/tools/sync/push.spec.ts b/tests/tools/sync/push.spec.ts index f43fa19..976c95c 100644 --- a/tests/tools/sync/push.spec.ts +++ b/tests/tools/sync/push.spec.ts @@ -63,6 +63,19 @@ describe("push", () => { expect(mockedClient.POST).toHaveBeenCalledWith("/apiKey/beta/test-targets/{testTargetId}/draft/push", expect.anything()) }) + it("pushes to draft if no git context", async () => { + jest.mocked(getGitContext).mockResolvedValue(undefined) + + await push({ + testTargetId: "someId", + sourceDir: ".", + client: mockedClient, + onError: jest.fn(), + }) + + expect(mockedClient.POST).toHaveBeenCalledWith("/apiKey/beta/test-targets/{testTargetId}/draft/push", expect.anything()) + }) + it("calls the handleError callback on error", async () => { jest.mocked(getGitContext).mockResolvedValue({ defaultBranch: "refs/heads/main", From 0a90e6689c19c1e506f72cea400db614901cf4ec Mon Sep 17 00:00:00 2001 From: Daniel Draper Date: Wed, 17 Dec 2025 16:47:36 +0100 Subject: [PATCH 2/5] allow failing symbolicRef --- src/tools/sync/git.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/tools/sync/git.ts b/src/tools/sync/git.ts index 8dea2df..2c7aed9 100644 --- a/src/tools/sync/git.ts +++ b/src/tools/sync/git.ts @@ -47,16 +47,19 @@ export const getDefaultBranch = async ( allowedMethod: "symbolicRef+origin" | "origin" = "symbolicRef+origin", ): Promise => { if (allowedMethod === "symbolicRef+origin") { - const symbolicRef = ( - await simpleGit().raw("symbolic-ref", "refs/remotes/origin/HEAD") - ).trim(); - const symbolicRefBranch = symbolicRef.replace( - "refs/remotes/origin/", - "refs/heads/", - ); - - if (symbolicRefBranch) { - return symbolicRefBranch; + try { + const symbolicRef = ( + await simpleGit().raw("symbolic-ref", "refs/remotes/origin/HEAD") + ).trim(); + const symbolicRefBranch = symbolicRef.replace( + "refs/remotes/origin/", + "refs/heads/", + ); + if (symbolicRefBranch) { + return symbolicRefBranch; + } + } catch (e) { + console.warn("could not identify symbolic ref, falling back to origin parsing"); } } From 11f8824cac8af09fc1a59a06c9353806097ddcef Mon Sep 17 00:00:00 2001 From: Daniel Draper Date: Wed, 17 Dec 2025 16:54:06 +0100 Subject: [PATCH 3/5] allow failing symbolicRef, allow overriding branch name explicitly --- package.json | 2 +- src/tools/sync/git.ts | 16 +++++++++++----- src/tools/sync/push.ts | 4 ++-- tests/tools/sync/git.integration.spec.ts | 5 +++++ 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 1dddf9b..348917c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@octomind/octomind", - "version": "3.4.1", + "version": "3.5.0", "description": "a command line client for octomind apis", "main": "./dist/index.js", "packageManager": "pnpm@10.26.0+sha512.3b3f6c725ebe712506c0ab1ad4133cf86b1f4b687effce62a9b38b4d72e3954242e643190fc51fa1642949c735f403debd44f5cb0edd657abe63a8b6a7e1e402", diff --git a/src/tools/sync/git.ts b/src/tools/sync/git.ts index 2c7aed9..8479e2f 100644 --- a/src/tools/sync/git.ts +++ b/src/tools/sync/git.ts @@ -49,17 +49,20 @@ export const getDefaultBranch = async ( if (allowedMethod === "symbolicRef+origin") { try { const symbolicRef = ( - await simpleGit().raw("symbolic-ref", "refs/remotes/origin/HEAD") + await simpleGit().raw("symbolic-ref", "refs/remotes/origin/HEAD") ).trim(); const symbolicRefBranch = symbolicRef.replace( - "refs/remotes/origin/", - "refs/heads/", + "refs/remotes/origin/", + "refs/heads/", ); if (symbolicRefBranch) { return symbolicRefBranch; } } catch (e) { - console.warn("could not identify symbolic ref, falling back to origin parsing"); + console.warn( + "could not identify symbolic ref, falling back to origin parsing", + e, + ); } } @@ -96,7 +99,10 @@ export const getGitContext = async (): Promise => { }; return ctx; } catch (e) { - console.warn("could not identify git context, falling back to undefined", e); + console.warn( + "could not identify git context, falling back to undefined", + e, + ); return undefined; } }; diff --git a/src/tools/sync/push.ts b/src/tools/sync/push.ts index 89ea1bb..647e01e 100644 --- a/src/tools/sync/push.ts +++ b/src/tools/sync/push.ts @@ -30,8 +30,8 @@ export const push = async ( const testCases = readTestCasesFromDir(options.sourceDir); checkForConsistency(testCases); const context = await getGitContext(); - const refName = options.branchName ?? context?.ref - const isDefaultBranch = !!context && context.defaultBranch === refName + const refName = options.branchName ?? context?.ref; + const isDefaultBranch = !!context && context.defaultBranch === refName; const body: TestTargetSyncData = { testCases, diff --git a/tests/tools/sync/git.integration.spec.ts b/tests/tools/sync/git.integration.spec.ts index e6be6c4..e7377ce 100644 --- a/tests/tools/sync/git.integration.spec.ts +++ b/tests/tools/sync/git.integration.spec.ts @@ -1,6 +1,11 @@ import {getDefaultBranch, getGitContext, parseGitRemote} from "../../../src/tools/sync/git"; describe('git', () => { + + beforeEach(() => { + console.warn = jest.fn(); + }) + it("should return the actual owner and repo", async () => { const remote = await parseGitRemote(); From 005aa0007b96d106fdc9965a890a224dea05d230 Mon Sep 17 00:00:00 2001 From: Daniel Draper Date: Wed, 17 Dec 2025 16:57:19 +0100 Subject: [PATCH 4/5] test for me --- tests/tools/sync/git.integration.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/tools/sync/git.integration.spec.ts b/tests/tools/sync/git.integration.spec.ts index e7377ce..c5ad894 100644 --- a/tests/tools/sync/git.integration.spec.ts +++ b/tests/tools/sync/git.integration.spec.ts @@ -23,5 +23,6 @@ describe('git', () => { const context = await getGitContext() expect(context).toBeDefined() + console.log(context) }); }) \ No newline at end of file From 1bd44b68119103ebae7e719f35d60f786a3d5c57 Mon Sep 17 00:00:00 2001 From: Daniel Draper Date: Wed, 17 Dec 2025 17:01:45 +0100 Subject: [PATCH 5/5] fix it! --- tests/tools/sync/git.integration.spec.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/tools/sync/git.integration.spec.ts b/tests/tools/sync/git.integration.spec.ts index c5ad894..4706687 100644 --- a/tests/tools/sync/git.integration.spec.ts +++ b/tests/tools/sync/git.integration.spec.ts @@ -23,6 +23,5 @@ describe('git', () => { const context = await getGitContext() expect(context).toBeDefined() - console.log(context) }); -}) \ No newline at end of file +})