Skip to content
This repository was archived by the owner on Jul 14, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
32 changes: 21 additions & 11 deletions src/tools/sync/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,22 @@ export const getDefaultBranch = async (
allowedMethod: "symbolicRef+origin" | "origin" = "symbolicRef+origin",
): Promise<string> => {
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",
e,
);
}
}

Expand Down Expand Up @@ -92,7 +98,11 @@ export const getGitContext = async (): Promise<GitContext | undefined> => {
defaultBranch,
};
return ctx;
} catch {
} catch (e) {
console.warn(
"could not identify git context, falling back to undefined",
e,
);
return undefined;
}
};
4 changes: 3 additions & 1 deletion src/tools/sync/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type ErrorResponse =
type PushOptions = {
testTargetId: string;
sourceDir: string;
branchName?: string;
client: Client<paths>;
onError: (error: ErrorResponse) => void;
};
Expand All @@ -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,
Expand Down
13 changes: 11 additions & 2 deletions tests/tools/sync/git.integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import {getDefaultBranch, parseGitRemote} from "../../../src/tools/sync/git";
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();

Expand All @@ -14,5 +19,9 @@ describe('git', () => {
expect(defaultBranch).toEqual("refs/heads/main");
});

it("returns a context", async () => {
const context = await getGitContext()

})
expect(context).toBeDefined()
});
})
13 changes: 13 additions & 0 deletions tests/tools/sync/push.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down