mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-17 05:00:20 +00:00
Integrate OpenHandoff factory workspace (#212)
This commit is contained in:
parent
3d9476ed0b
commit
bf282199b5
251 changed files with 42824 additions and 692 deletions
40
factory/packages/backend/test/helpers/test-context.ts
Normal file
40
factory/packages/backend/test/helpers/test-context.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { ConfigSchema, type AppConfig } from "@openhandoff/shared";
|
||||
import type { BackendDriver } from "../../src/driver.js";
|
||||
import { initActorRuntimeContext } from "../../src/actors/context.js";
|
||||
import { createProviderRegistry } from "../../src/providers/index.js";
|
||||
|
||||
export function createTestConfig(overrides?: Partial<AppConfig>): AppConfig {
|
||||
return ConfigSchema.parse({
|
||||
auto_submit: true,
|
||||
notify: ["terminal" as const],
|
||||
workspace: { default: "default" },
|
||||
backend: {
|
||||
host: "127.0.0.1",
|
||||
port: 7741,
|
||||
dbPath: join(
|
||||
tmpdir(),
|
||||
`hf-test-${Date.now()}-${Math.random().toString(16).slice(2)}.db`
|
||||
),
|
||||
opencode_poll_interval: 2,
|
||||
github_poll_interval: 30,
|
||||
backup_interval_secs: 3600,
|
||||
backup_retention_days: 7,
|
||||
},
|
||||
providers: {
|
||||
daytona: { image: "ubuntu:24.04" },
|
||||
},
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
|
||||
export function createTestRuntimeContext(
|
||||
driver: BackendDriver,
|
||||
configOverrides?: Partial<AppConfig>
|
||||
): { config: AppConfig } {
|
||||
const config = createTestConfig(configOverrides);
|
||||
const providers = createProviderRegistry(config, driver);
|
||||
initActorRuntimeContext(config, providers, undefined, driver);
|
||||
return { config };
|
||||
}
|
||||
127
factory/packages/backend/test/helpers/test-driver.ts
Normal file
127
factory/packages/backend/test/helpers/test-driver.ts
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
import type {
|
||||
BackendDriver,
|
||||
DaytonaClientLike,
|
||||
DaytonaDriver,
|
||||
GitDriver,
|
||||
GithubDriver,
|
||||
StackDriver,
|
||||
SandboxAgentDriver,
|
||||
SandboxAgentClientLike,
|
||||
TmuxDriver,
|
||||
} from "../../src/driver.js";
|
||||
import type { ListEventsRequest, ListPage, ListPageRequest, SessionEvent, SessionRecord } from "sandbox-agent";
|
||||
|
||||
export function createTestDriver(overrides?: Partial<BackendDriver>): BackendDriver {
|
||||
return {
|
||||
git: overrides?.git ?? createTestGitDriver(),
|
||||
stack: overrides?.stack ?? createTestStackDriver(),
|
||||
github: overrides?.github ?? createTestGithubDriver(),
|
||||
sandboxAgent: overrides?.sandboxAgent ?? createTestSandboxAgentDriver(),
|
||||
daytona: overrides?.daytona ?? createTestDaytonaDriver(),
|
||||
tmux: overrides?.tmux ?? createTestTmuxDriver(),
|
||||
};
|
||||
}
|
||||
|
||||
export function createTestGitDriver(overrides?: Partial<GitDriver>): GitDriver {
|
||||
return {
|
||||
validateRemote: async () => {},
|
||||
ensureCloned: async () => {},
|
||||
fetch: async () => {},
|
||||
listRemoteBranches: async () => [],
|
||||
remoteDefaultBaseRef: async () => "origin/main",
|
||||
revParse: async () => "abc1234567890",
|
||||
ensureRemoteBranch: async () => {},
|
||||
diffStatForBranch: async () => "+0/-0",
|
||||
conflictsWithMain: async () => false,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function createTestStackDriver(overrides?: Partial<StackDriver>): StackDriver {
|
||||
return {
|
||||
available: async () => false,
|
||||
listStack: async () => [],
|
||||
syncRepo: async () => {},
|
||||
restackRepo: async () => {},
|
||||
restackSubtree: async () => {},
|
||||
rebaseBranch: async () => {},
|
||||
reparentBranch: async () => {},
|
||||
trackBranch: async () => {},
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function createTestGithubDriver(overrides?: Partial<GithubDriver>): GithubDriver {
|
||||
return {
|
||||
listPullRequests: async () => [],
|
||||
createPr: async (_repoPath, _headBranch, _title) => ({
|
||||
number: 1,
|
||||
url: `https://github.com/test/repo/pull/1`,
|
||||
}),
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function createTestSandboxAgentDriver(
|
||||
overrides?: Partial<SandboxAgentDriver>
|
||||
): SandboxAgentDriver {
|
||||
return {
|
||||
createClient: (_opts) => createTestSandboxAgentClient(),
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function createTestSandboxAgentClient(
|
||||
overrides?: Partial<SandboxAgentClientLike>
|
||||
): SandboxAgentClientLike {
|
||||
return {
|
||||
createSession: async (_prompt) => ({ id: "test-session-1", status: "running" }),
|
||||
sessionStatus: async (sessionId) => ({ id: sessionId, status: "running" }),
|
||||
listSessions: async (_request?: ListPageRequest): Promise<ListPage<SessionRecord>> => ({
|
||||
items: [],
|
||||
nextCursor: undefined,
|
||||
}),
|
||||
listEvents: async (_request: ListEventsRequest): Promise<ListPage<SessionEvent>> => ({
|
||||
items: [],
|
||||
nextCursor: undefined,
|
||||
}),
|
||||
sendPrompt: async (_request) => {},
|
||||
cancelSession: async (_sessionId) => {},
|
||||
destroySession: async (_sessionId) => {},
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function createTestDaytonaDriver(
|
||||
overrides?: Partial<DaytonaDriver>
|
||||
): DaytonaDriver {
|
||||
return {
|
||||
createClient: (_opts) => createTestDaytonaClient(),
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function createTestDaytonaClient(
|
||||
overrides?: Partial<DaytonaClientLike>
|
||||
): DaytonaClientLike {
|
||||
return {
|
||||
createSandbox: async () => ({ id: "sandbox-test-1", state: "started" }),
|
||||
getSandbox: async (sandboxId) => ({ id: sandboxId, state: "started" }),
|
||||
startSandbox: async () => {},
|
||||
stopSandbox: async () => {},
|
||||
deleteSandbox: async () => {},
|
||||
executeCommand: async () => ({ exitCode: 0, result: "" }),
|
||||
getPreviewEndpoint: async (sandboxId, port) => ({
|
||||
url: `https://preview.example/sandbox/${sandboxId}/port/${port}`,
|
||||
token: "preview-token",
|
||||
}),
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
export function createTestTmuxDriver(overrides?: Partial<TmuxDriver>): TmuxDriver {
|
||||
return {
|
||||
setWindowStatus: () => 0,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue