Files
orca/src/main/runtime/orca-runtime-git.test.ts
T
OrcaWinandOrcaWin 7d6603aa17 [comment audit] Complete repository-wide comment cleanup (#33249)
* [comment audit] Align legacy failure-read counts with cached display

* [comment audit] Condense shared provider lifecycle and browser recovery comments [skip ci]

* [comment audit] Condense shared generation, path and preview comments [skip ci]

* [comment audit] Condense host, file and Git contract rationale [skip ci]

* [comment audit] Tighten Git lifecycle and provider contract comments [skip ci]

* [comment audit] Clarify shared host authority and launch isolation [skip ci]

* [comment audit] simplify local access mobile and native chat contracts [skip ci]

* [comment audit] simplify native chat presentation and state contracts [skip ci]

* [comment audit] simplify native runtime and provider contracts [skip ci]

* [comment audit] simplify migration and orchestration contracts [skip ci]

* [comment audit] simplify plugin trust and process capture rationale [skip ci]

* [comment audit] simplify terminal delivery and remote compatibility rationale [skip ci]

* [comment audit] clarify remote recovery and launch wire rationale [skip ci]

* [comment audit] shorten shared RPC compatibility and runtime evidence comments [skip ci]

* [comment audit] simplify secure storage shell startup and sidebar rationale [skip ci]

* [comment audit] clarify sidebar, skill and SSH invariants [skip ci]

* [comment audit] condense structured chat delivery and timing rationale [skip ci]

* [comment audit] condense terminal replay and telemetry invariants [skip ci]

* [comment audit] clarify launch permission and terminal delivery rationale [skip ci]

* [comment audit] clarify workspace ownership and layout contracts [skip ci]

* [comment audit] wait for fitted and painted SSH terminal links

* [comment audit] clarify layout persistence and session ownership [skip ci]

* [comment audit] clarify host routing and workspace lifecycle contracts [skip ci]

* [comment audit] clarify startup persistence and app lifetime comments [skip ci]

* [comment audit] clarify recovery and activity boundaries [skip ci]

* [comment audit] condense activity and artifact invariants [skip ci]

* [comment audit] condense automation authority contracts [skip ci]

* [comment audit] simplify automation scheduling and history contracts [skip ci]

* [comment audit] clarify browser chrome and annotation lifecycles [skip ci]

* [comment audit] clarify browser routing and retained guest ownership [skip ci]

* [comment audit] clarify browser recovery and document ownership comments [skip ci]

* [comment audit] restore hosted runners required by native IME fixtures

* [comment audit] shorten preview, palette and dashboard invariants [skip ci]

* [comment audit] clarify terminal preview, dashboard and retention comments [skip ci]

* [comment audit] clarify diff-note recovery and editor lifecycle comments [skip ci]

* [comment audit] shorten rich-text and combined-diff ownership comments [skip ci]

* [comment audit] shorten autosave, draft recovery and model ownership comments [skip ci]

* [comment audit] shorten save-queue, notebook and Markdown constraints [skip ci]

* [comment audit] shorten Monaco, PDF and rich Markdown safeguards [skip ci]

* [comment audit] clarify rich Markdown source and selection safeguards [skip ci]

* [comment audit] clarify editor loading and emulator stream lifetimes [skip ci]

* [comment audit] trim emulator and feature tour narration [skip ci]

* [comment audit] clarify floating workspace and GitHub cache ownership [skip ci]

* [comment audit] trim provider controls and Linear filter explanations [skip ci]

* [comment audit] clarify pairing and chat resume lifetimes [skip ci]

* [comment audit] clarify chat delivery and transcript lifetimes [skip ci]

* [comment audit] clarify session options and host-owned status [skip ci]

* [comment audit] clarify draft durability and live-status precedence [skip ci]

* [comment audit] Trim chat send and model ownership explanations [skip ci]

* [comment audit] Shorten transcript ownership and send recovery comments [skip ci]

* [comment audit] Simplify native chat composer and transcript hook comments [skip ci]

* [comment audit] Shorten native chat scroll and structured session explanations [skip ci]

* [comment audit] Trim workspace picker and onboarding commentary [skip ci]

* [comment audit] Simplify pet rendering, review cache and quick open comments [skip ci]

* [comment audit] Trim sidebar and session history explanations [skip ci]

* [comment audit] Condense session resume and review checks comments [skip ci]

* [comment audit] Shorten checks state and file explorer refresh comments [skip ci]

* [comment audit] Trim plugin bridge and source-control action rationale [skip ci]

* [comment audit] Trim source-control listing and review rationale [skip ci]

* [comment audit] Shorten sidebar lifecycle and explorer safeguards [skip ci]

* [comment audit] Condense Settings account and appearance rationale [skip ci]

* [comment audit] Trim pairing and repository Settings explanations [skip ci]

* [comment audit] Condense Settings search SSH and terminal safeguards [skip ci]

* [comment audit] Shorten Settings voice and provider ownership comments [skip ci]

* [comment audit] Condense Settings draft persistence and host-state rationale [skip ci]

* [comment audit] Trim Settings hooks and sidebar setup rationale [skip ci]

* [comment audit] Condense sidebar deletion and board-filter safeguards [skip ci]

* [comment audit] Condense worktree cards, host ownership and Markdown contracts [skip ci]

* [comment audit] Condense sidebar drag, folder and filtering contracts [skip ci]

* [comment audit] Condense sidebar parity, sleep and host ownership contracts [skip ci]

* [comment audit] Prune focus-read baseline after comment cleanup

* [comment audit] Clarify sidebar visibility, board drops and agent evidence [skip ci]

* [comment audit] Tighten sidebar listing, drag and reveal contracts [skip ci]

* [comment audit] Clarify viewport geometry and skill update safeguards [skip ci]

* [comment audit] Tighten skill inventory, usage and host status comments [skip ci]

* [comment audit] Clarify usage ownership and resource kill safeguards [skip ci]

* [comment audit] Tighten tab selection, rename and search contracts [skip ci]

* [comment audit] Tighten tab-strip geometry and drag ownership comments [skip ci]

* [comment audit] Tighten Tasks recovery, pagination and mutation comments [skip ci]

* [comment audit] Tighten provider loading and terminal recovery comments [skip ci]

* [comment audit] Tighten completion, cadence and PTY ownership comments [skip ci]

* [comment audit] Clarify terminal restore and parked-pane boundaries [skip ci]

* [comment audit] Tighten PTY startup and replay explanations [skip ci]

* [comment audit] Clarify PTY identity and delivery ownership [skip ci]

* [comment audit] Shorten remote reconnect and input replay rationale [skip ci]

* [comment audit] Condense terminal parking clipboard and file link comments [skip ci]

* [comment audit] Clarify IME ownership and trim trace history [skip ci]

* [comment audit] Shorten pane recovery and parked watcher explanations [skip ci]

* [comment audit] Condense snapshot replay and visibility recovery rationale [skip ci]

* [comment audit] Shorten terminal parking and keyboard ownership rationale [skip ci]

* [comment audit] Trim renderer lifecycle and menu rationale [skip ci]

* [comment audit] Condense workspace cleanup ownership and settlement notes [skip ci]

* [comment audit] Clarify renderer hook evidence and source ownership [skip ci]

* [comment audit] Tighten IPC ownership and reconnect explanations [skip ci]

* [comment audit] Trim renderer focus, paste and attention comments [skip ci]

* [comment audit] Shorten scroll, locale and agent lifecycle comments [skip ci]

* [comment audit] Trim agent launch, resume and ownership commentary [skip ci]

* [comment audit] Shorten account, browser and editor comments [skip ci]

* [comment audit] Clarify host-mirror waits, previews and input ownership [skip ci]

* [comment audit] Condense launch recovery and editor tokenization comments [skip ci]

* [comment audit] Condense workspace selection and terminal pane rationale [skip ci]

* [comment audit] Condense terminal fitting and rendering recovery comments [skip ci]

* [comment audit] Condense terminal input and host routing explanations [skip ci]

* [comment audit] Condense ownership and sleeping-session recovery rationale [skip ci]

* [comment audit] Condense structured launch and terminal link explanations [skip ci]

* [comment audit] Condense terminal ownership and workspace file routing rationale [skip ci]

* [comment audit] Condense session persistence and workspace activation rationale [skip ci]

* [comment audit] Condense workspace routing and browser ownership rationale [skip ci]

* [comment audit] Condense mirror recovery and layout authority rationale [skip ci]

* [comment audit] Condense runtime transport and file safety rationale [skip ci]

* [comment audit] Condense runtime graph and structured session rationale [skip ci]

* [comment audit] Condense browser creation and remote tab recovery rationale [skip ci]

* [comment audit] Condense snapshot authority and publisher recovery rationale [skip ci]

* [comment audit] Condense frame, startup and provider cache rationale [skip ci]

* [comment audit] Condense host twin and agent lifecycle rationale [skip ci]

* [comment audit] Condense browser authority and editor cleanup rationale [skip ci]

* [comment audit] Condense editor buffer identity and review cache rationale [skip ci]

* [comment audit] Condense provider lifetime and repository ownership rationale [skip ci]

* [comment audit] Condense reconnect, hydration and terminal retirement rationale [skip ci]

* [comment audit] Condense recovery, reconciliation and persistence rationale [skip ci]

* [comment audit] Condense cleanup ownership and listing admission rationale [skip ci]

* [comment audit] Condense teardown ordering and terminal ownership rationale [skip ci]

* [comment audit] Condense recovery ledger and web host-boundary rationale [skip ci]

* [comment audit] Condense web reconnect and credential lifecycle rationale [skip ci]

* [comment audit] Condense cloud rollout and assignment safety rationale [skip ci]

* [comment audit] Condense relay session and database recovery rationale [skip ci]

* [comment audit] Condense relay placement and protocol compatibility rationale [skip ci]

* [comment audit] Condense build and packaging constraints [skip ci]

* [comment audit] Condense CI gates and validation isolation rationale [skip ci]

* [comment audit] Condense catalog identity and browser validation rationale [skip ci]

* [comment audit] Condense mobile browser and frame-budget rationale [skip ci]

* [comment audit] Shorten mobile route and browser test explanations [skip ci]

* [comment audit] Condense editor and session seam test rationale [skip ci]

* [comment audit] Trim session and terminal closure history [skip ci]

* [comment audit] Shorten terminal browser and census explanations [skip ci]

* [comment audit] Preserve root-only E2E diagnostic baseline

* [comment audit] Condense mobile seam and HTML preview test rationale [skip ci]

* [comment audit] Condense preview instrumentation and render harness rationale [skip ci]

* [comment audit] Condense bundle contracts and native-build constraints [skip ci]

* [comment audit] Shorten native packaging and CI routing rationale [skip ci]

* [comment audit] Condense release tooling and benchmark constraints [skip ci]

* [comment audit] Condense packaging and platform gate rationale [skip ci]

* [comment audit] Shorten mobile route and history rationale [skip ci]

* [comment audit] Condense mobile browser and component rationale [skip ci]

* [comment audit] Shorten drawer and workspace-form rationale [skip ci]

* [comment audit] Trim mobile review and editor-document explanations [skip ci]

* [comment audit] Condense editor lifecycle and Markdown explanations [skip ci]

* [comment audit] Trim mobile file, diagnostics and dictation commentary [skip ci]

* [comment audit] Simplify mobile host-list and workspace-view explanations [skip ci]

* [comment audit] Clarify mobile shell lifetime and bridge delivery constraints [skip ci]

* [comment audit] Condense bridge stream, native request and audio rationale [skip ci]

* [comment audit] Reduce bridge schema and page-client commentary [skip ci]

* [comment audit] Tighten mobile page bridge contracts [skip ci]

* [comment audit] Clarify mobile cache and session constraints [skip ci]

* [comment audit] Condense mobile route and lifecycle rationale [skip ci]

* [comment audit] Tighten mobile shell hook timing rationale [skip ci]

* [comment audit] Clarify route handoff and notification compatibility [skip ci]

* [comment audit] Clarify push registration and dictation cleanup constraints [skip ci]

* [comment audit] Condense keyboard geometry and native media ownership rationale [skip ci]

* [comment audit] Tighten mobile chat scroll and composer concurrency rationale [skip ci]

* [comment audit] Condense mobile reply compatibility and upload ownership rationale [skip ci]

* [comment audit] Condense optimistic echo and scroll ownership rationale [skip ci]

* [comment audit] Tighten stream replay and queued session ownership rationale [skip ci]

* [comment audit] Condense mobile composer and reply-schema constraints [skip ci]

* [comment audit] Clarify mobile transcript recovery and session ownership [skip ci]

* [comment audit] Clarify mobile queue and source-control compatibility [skip ci]

* [comment audit] Condense storage and task launch constraints [skip ci]

* [comment audit] Clarify task schemas and terminal document ownership [skip ci]

* [comment audit] Tighten terminal input and viewport rationale [skip ci]

* [comment audit] Shorten terminal and RPC recorder contracts [skip ci]

* [comment audit] Condense recorder engine and connection contracts [skip ci]

* [comment audit] Shorten host credential and relay recovery comments [skip ci]

* [comment audit] Tighten pairing recovery and bundle transport rationale [skip ci]

* [comment audit] Clarify RPC delivery and workspace catalog boundaries [skip ci]

* [comment audit] Condense catalog and relay entry contracts [skip ci]

* [comment audit] Shorten shutdown and SSH relay delivery contracts [skip ci]

* [comment audit] Condense WSL relay and E2E regression rationale [skip ci]

* [comment audit] Shorten cross-version harness and renderer fixture explanations [skip ci]

* [comment audit] Condense paired-host and E2E lifecycle rationale [skip ci]

* [comment audit] Shorten layout oracle and regression explanations [skip ci]

* [comment audit] Condense paired recovery and ownership regression contracts [skip ci]

* [comment audit] Shorten restart, sidebar and SSH lifecycle contracts [skip ci]

* [comment audit] Condense terminal rendering and IME regression rationale [skip ci]

* [comment audit] Shorten terminal recovery and benchmark contracts [skip ci]

* [comment audit] Condense tooling and Windows lifecycle proof rationale [skip ci]

* [comment audit] Condense workflow routing and release rationale [skip ci]

* [comment audit] Condense mobile security and installer contracts [skip ci]

* [comment audit] Shorten native rationale and stylesheet workarounds [skip ci]

* [comment audit] Shorten Windows visibility probe rationale [skip ci]

* [comment audit] Condense embedded release and signing rationale [skip ci]

* [comment audit] Retain current main test behavior in final reconciliation [skip ci]

* [comment audit] Complete final comment review across current source inventory

* [comment audit] Handle consolidated audit reports before final CI

* [comment audit] Preserve credential storage census detail [skip ci]

* [comment audit] Scale broad changed E2E selections with verified timing shards

* [comment audit] Align E2E assertions with browser close and settled session metadata

* [comment audit] Match existing E2Es to current resource and windowing contracts

* [comment audit] Observe the shared server outage notice in reconnect coverage

* [comment audit] Make existing renderer probes measure settled tab and PTY work

* [comment audit] Align palette E2E selector with task search

* [comment audit] Refresh remaining palette search selectors

* [comment audit] Keep selector correction within selected audit specs

* [comment audit] Await emoji fixture settings inside renderer evaluation

* [comment audit] Cancel fixture fit retries between terminal tests

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-10-25 04:05:46 -07:00

720 lines
26 KiB
TypeScript

import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { GlobalSettings } from '../../shared/global-settings-types'
import type * as GitStatusModule from '../git/status'
import type * as CommitMessageTextGenerationModule from '../text-generation/commit-message-text-generation'
import type * as PullRequestContextModule from '../text-generation/pull-request-context'
import {
SSH_HOST_NOT_SERVED_MESSAGE,
SshHostNotServedError
} from '../providers/ssh-host-not-served-error'
import { RuntimeGitCommands } from './orca-runtime-git'
import type { ResolvedRuntimeGitWorktree } from './runtime-git-command-target'
const mocks = vi.hoisted(() => ({
checkoutBranch: vi.fn(),
discardChanges: vi.fn(),
listLocalBranches: vi.fn(),
getStagedCommitContext: vi.fn(),
getPullRequestDraftContext: vi.fn(),
generateCommitMessageFromContext: vi.fn(),
generatePullRequestFieldsFromContext: vi.fn(),
resolveCommitMessageSettings: vi.fn(),
resolveHostedReviewBodyForGeneration: vi.fn(),
loadPullRequestLinkedIssue: vi.fn(),
getStatus: vi.fn()
}))
vi.mock('../git/status', async () => ({
...(await vi.importActual<typeof GitStatusModule>('../git/status')),
discardChanges: mocks.discardChanges,
getStagedCommitContext: mocks.getStagedCommitContext,
getStatus: mocks.getStatus
}))
vi.mock('../git/checkout', () => ({
checkoutBranch: mocks.checkoutBranch,
listLocalBranches: mocks.listLocalBranches
}))
vi.mock('../text-generation/commit-message-text-generation', async () => ({
...(await vi.importActual<typeof CommitMessageTextGenerationModule>(
'../text-generation/commit-message-text-generation'
)),
generateCommitMessageFromContext: mocks.generateCommitMessageFromContext,
generatePullRequestFieldsFromContext: mocks.generatePullRequestFieldsFromContext,
resolveCommitMessageSettings: mocks.resolveCommitMessageSettings
}))
vi.mock('../text-generation/pull-request-context', async () => ({
...(await vi.importActual<typeof PullRequestContextModule>(
'../text-generation/pull-request-context'
)),
getPullRequestDraftContext: mocks.getPullRequestDraftContext
}))
vi.mock('../source-control/pull-request-template', () => ({
resolveHostedReviewBodyForGeneration: mocks.resolveHostedReviewBodyForGeneration
}))
vi.mock('../source-control/pull-request-linked-issue', () => ({
loadPullRequestLinkedIssue: mocks.loadPullRequestLinkedIssue
}))
const tempDirs: string[] = []
function makeWorktree(path: string, linkedIssue: number | null = null): ResolvedRuntimeGitWorktree {
// satisfies checks real worktree keys/types while permitting fixture omissions.
const worktree = {
id: 'wt-1',
repoId: 'repo-1',
path,
linkedIssue,
git: {
path,
branch: 'main',
isBare: false,
isMainWorktree: false,
head: 'a'.repeat(40)
}
} satisfies Partial<ResolvedRuntimeGitWorktree>
return worktree as unknown as ResolvedRuntimeGitWorktree
}
function localTarget(worktreePath: string, linkedIssue: number | null = null) {
return { worktree: makeWorktree(worktreePath, linkedIssue), executionHostId: 'local' as const }
}
function makeCommands(worktreePath: string): RuntimeGitCommands {
return new RuntimeGitCommands({
resolveRuntimeGitTarget: async () => localTarget(worktreePath),
getRuntimeSettings: () => ({}) as GlobalSettings
})
}
describe('RuntimeGitCommands', () => {
beforeEach(() => {
mocks.getStagedCommitContext.mockReset()
mocks.getPullRequestDraftContext.mockReset()
mocks.generateCommitMessageFromContext.mockReset()
mocks.generatePullRequestFieldsFromContext.mockReset()
mocks.resolveCommitMessageSettings.mockReset()
mocks.resolveHostedReviewBodyForGeneration.mockReset()
mocks.resolveHostedReviewBodyForGeneration.mockImplementation(async ({ body }) => body)
mocks.loadPullRequestLinkedIssue.mockReset()
mocks.loadPullRequestLinkedIssue.mockResolvedValue(null)
mocks.getStatus.mockReset()
mocks.checkoutBranch.mockReset()
mocks.discardChanges.mockReset()
mocks.listLocalBranches.mockReset()
})
afterEach(() => {
while (tempDirs.length > 0) {
rmSync(tempDirs.pop()!, { recursive: true, force: true })
}
})
// #10451: node_modules/ ignores directories, not Orca symlinks; runtime status must pass their paths explicitly.
it('passes the repo shared link paths through local runtime status', async () => {
mocks.getStatus.mockResolvedValue({ entries: [], conflictOperation: 'none' })
const commands = new RuntimeGitCommands({
resolveRuntimeGitTarget: async () => ({
executionHostId: 'local',
worktree: makeWorktree('/workspace/feature'),
repo: { path: '/workspace/repo', symlinkPaths: ['node_modules'] } as never
}),
getRuntimeSettings: () => ({}) as GlobalSettings
})
await commands.getRuntimeGitStatus('id:wt-1')
expect(mocks.getStatus).toHaveBeenCalledWith('/workspace/feature', {
admissionTier: 'status',
sharedLinkPaths: ['node_modules']
})
})
it('refuses an SSH runtime status without running git here', async () => {
const commands = new RuntimeGitCommands({
resolveRuntimeGitTarget: async () => ({
worktree: makeWorktree('/remote/repo'),
repo: { path: '/remote/repo', symlinkPaths: ['node_modules'] } as never,
executionHostId: 'ssh:conn-1'
}),
getRuntimeSettings: () => ({}) as GlobalSettings
})
await expect(commands.getRuntimeGitStatus('id:wt-1')).rejects.toThrow(SshHostNotServedError)
expect(mocks.getStatus).not.toHaveBeenCalled()
})
it('checks out a local branch through the resolved worktree', async () => {
const worktreePath = mkdtempSync(join(tmpdir(), 'orca-runtime-git-'))
tempDirs.push(worktreePath)
const commands = new RuntimeGitCommands({
resolveRuntimeGitTarget: async () => ({
executionHostId: 'local',
worktree: makeWorktree(worktreePath),
localGitOptions: { wslDistro: 'Ubuntu' }
}),
getRuntimeSettings: () => ({}) as GlobalSettings
})
mocks.checkoutBranch.mockResolvedValue(undefined)
await expect(commands.checkoutRuntimeGitBranch('id:wt-1', 'feature/x')).resolves.toEqual({
ok: true,
branch: 'feature/x'
})
expect(mocks.checkoutBranch).toHaveBeenCalledWith(worktreePath, 'feature/x', {
admissionTier: 'interactive',
wslDistro: 'Ubuntu'
})
})
it('lists local branches through the resolved worktree', async () => {
const worktreePath = mkdtempSync(join(tmpdir(), 'orca-runtime-git-'))
tempDirs.push(worktreePath)
const commands = makeCommands(worktreePath)
mocks.listLocalBranches.mockResolvedValue({ current: 'main', branches: ['main', 'feature/x'] })
await expect(commands.listRuntimeGitLocalBranches('id:wt-1')).resolves.toEqual({
current: 'main',
branches: ['main', 'feature/x']
})
expect(mocks.listLocalBranches).toHaveBeenCalledWith(worktreePath, {})
})
it('prioritizes a local single-file discard without losing WSL routing', async () => {
const commands = new RuntimeGitCommands({
resolveRuntimeGitTarget: async () => ({
executionHostId: 'local',
worktree: makeWorktree('/workspace/repo'),
localGitOptions: { wslDistro: 'Ubuntu' }
}),
getRuntimeSettings: () => ({}) as GlobalSettings
})
await commands.discardRuntimeGitPath('id:wt-1', 'src/app.ts')
expect(mocks.discardChanges).toHaveBeenCalledWith('/workspace/repo', 'src/app.ts', {
admissionTier: 'interactive',
wslDistro: 'Ubuntu'
})
})
it('rejects slash-only git mutation paths before they can target the worktree root', async () => {
const worktreePath = mkdtempSync(join(tmpdir(), 'orca-runtime-git-'))
tempDirs.push(worktreePath)
const commands = makeCommands(worktreePath)
await expect(commands.bulkDiscardRuntimeGitPaths('id:wt-1', ['///'])).rejects.toThrow(
'invalid_relative_path'
)
await expect(commands.discardRuntimeGitPath('id:wt-1', '///')).rejects.toThrow(
'invalid_relative_path'
)
})
it('prepares the selected local agent environment before generating commit messages', async () => {
const worktreePath = mkdtempSync(join(tmpdir(), 'orca-runtime-git-'))
tempDirs.push(worktreePath)
const context = {
branch: 'main',
stagedSummary: 'M\tREADME.md',
stagedPatch: '+hello'
}
const params = { agentId: 'codex', model: 'gpt-5.4-mini', thinkingLevel: 'low' }
mocks.resolveCommitMessageSettings.mockReturnValue({ ok: true, params })
mocks.getStagedCommitContext.mockResolvedValue(context)
mocks.generateCommitMessageFromContext.mockResolvedValue({
success: true,
message: 'docs: update readme'
})
const commands = new RuntimeGitCommands({
resolveRuntimeGitTarget: async () => localTarget(worktreePath),
getRuntimeSettings: () =>
({
commitMessageAi: { enabled: true, agentId: 'codex' },
agentCmdOverrides: {}
}) as GlobalSettings,
getCommitMessageAgentEnvironment: () => ({
prepareForCodexLaunch: () => '/managed/codex-home'
})
})
await expect(commands.generateRuntimeCommitMessage('id:wt-1')).resolves.toEqual({
success: true,
message: 'docs: update readme'
})
expect(mocks.resolveCommitMessageSettings).toHaveBeenCalledWith(
expect.objectContaining({
commitMessageAi: { enabled: true, agentId: 'codex' }
}),
'local',
'commitMessage',
null
)
expect(mocks.generateCommitMessageFromContext).toHaveBeenCalledWith(
context,
params,
expect.objectContaining({
kind: 'local',
cwd: worktreePath,
env: expect.objectContaining({ CODEX_HOME: '/managed/codex-home' })
})
)
})
it('routes local WSL project runtime commit-message generation through the runtime target', async () => {
const worktreePath = mkdtempSync(join(tmpdir(), 'orca-runtime-git-'))
tempDirs.push(worktreePath)
const context = {
branch: 'main',
stagedSummary: 'M\tREADME.md',
stagedPatch: '+hello'
}
const params = { agentId: 'codex', model: 'gpt-5.4-mini', thinkingLevel: 'low' }
const prepareForCodexLaunch = vi.fn(() => '\\\\wsl.localhost\\Ubuntu\\home\\tester\\.codex')
mocks.resolveCommitMessageSettings.mockReturnValue({ ok: true, params })
mocks.getStagedCommitContext.mockResolvedValue(context)
mocks.generateCommitMessageFromContext.mockResolvedValue({
success: true,
message: 'docs: update readme'
})
const commands = new RuntimeGitCommands({
resolveRuntimeGitTarget: async () => ({
executionHostId: 'local',
worktree: makeWorktree(worktreePath),
localGitOptions: { wslDistro: 'Ubuntu' }
}),
getRuntimeSettings: () =>
({
commitMessageAi: { enabled: true, agentId: 'codex' },
agentCmdOverrides: {}
}) as GlobalSettings,
getCommitMessageAgentEnvironment: () => ({
prepareForCodexLaunch
})
})
await expect(commands.generateRuntimeCommitMessage('id:wt-1')).resolves.toEqual({
success: true,
message: 'docs: update readme'
})
expect(mocks.getStagedCommitContext).toHaveBeenCalledWith(worktreePath, {
admissionTier: 'interactive',
wslDistro: 'Ubuntu'
})
expect(prepareForCodexLaunch).toHaveBeenCalledWith({
runtime: 'wsl',
wslDistro: 'Ubuntu'
})
expect(mocks.generateCommitMessageFromContext).toHaveBeenCalledWith(
context,
params,
expect.objectContaining({
kind: 'local',
cwd: worktreePath,
wslDistro: 'Ubuntu',
env: expect.objectContaining({ CODEX_HOME: '/home/tester/.codex' })
})
)
})
it('uses one-shot resolved params before runtime commit-message defaults', async () => {
const worktreePath = mkdtempSync(join(tmpdir(), 'orca-runtime-git-'))
tempDirs.push(worktreePath)
const context = {
branch: 'main',
stagedSummary: 'M\tREADME.md',
stagedPatch: '+hello'
}
const sourceControlAiResolvedParams = {
agentId: 'codex' as const,
model: 'gpt-5.5',
thinkingLevel: 'high',
customPrompt: 'Use Conventional Commits.'
}
mocks.getStagedCommitContext.mockResolvedValue(context)
mocks.generateCommitMessageFromContext.mockResolvedValue({
success: true,
message: 'feat: update readme'
})
const commands = new RuntimeGitCommands({
resolveRuntimeGitTarget: async () => localTarget(worktreePath),
getRuntimeSettings: () =>
({
sourceControlAi: {
commitMessage: {
enabled: true,
agentId: 'cursor',
customPrompt: 'Saved default that should not win.'
}
}
}) as unknown as GlobalSettings
})
await expect(
commands.generateRuntimeCommitMessage('id:wt-1', { sourceControlAiResolvedParams })
).resolves.toEqual({
success: true,
message: 'feat: update readme'
})
expect(mocks.resolveCommitMessageSettings).not.toHaveBeenCalled()
expect(mocks.generateCommitMessageFromContext).toHaveBeenCalledWith(
context,
sourceControlAiResolvedParams,
expect.objectContaining({
kind: 'local',
cwd: worktreePath
})
)
})
it('uses one-shot resolved params before runtime pull-request defaults', async () => {
const worktreePath = mkdtempSync(join(tmpdir(), 'orca-runtime-git-'))
tempDirs.push(worktreePath)
const context = {
base: 'main',
branch: 'feature/source-control-ai',
commitSummary: 'abc123 feat: test',
changeSummary: 'M README.md',
patch: '+hello',
currentTitle: '',
currentBody: '',
currentDraft: false
}
const sourceControlAiResolvedParams = {
agentId: 'codex' as const,
model: 'gpt-5.5',
thinkingLevel: 'high',
commandInputTemplate: '{basePrompt}\n\nUse release-note style.'
}
mocks.getPullRequestDraftContext.mockResolvedValue(context)
mocks.generatePullRequestFieldsFromContext.mockResolvedValue({
success: true,
fields: {
base: 'main',
title: 'Improve Source Control AI',
body: 'Body',
draft: false
}
})
const commands = new RuntimeGitCommands({
resolveRuntimeGitTarget: async () => localTarget(worktreePath),
getRuntimeSettings: () =>
({
sourceControlAi: {
pullRequest: {
enabled: true,
agentId: 'cursor',
customPrompt: 'Saved default that should not win.'
}
}
}) as unknown as GlobalSettings
})
await expect(
commands.generateRuntimePullRequestFields(
'id:wt-1',
{ base: 'main', title: '', body: '', draft: false },
{ sourceControlAiResolvedParams }
)
).resolves.toEqual({
success: true,
fields: {
base: 'main',
title: 'Improve Source Control AI',
body: 'Body',
draft: false
}
})
expect(mocks.resolveCommitMessageSettings).not.toHaveBeenCalled()
expect(mocks.generatePullRequestFieldsFromContext).toHaveBeenCalledWith(
context,
sourceControlAiResolvedParams,
expect.objectContaining({
kind: 'local',
cwd: worktreePath
})
)
})
it('loads the hosted review template before generating pull-request fields', async () => {
const worktreePath = mkdtempSync(join(tmpdir(), 'orca-runtime-git-'))
tempDirs.push(worktreePath)
const templateBody = '## Summary\n\n## Testing\n\n- [ ] Required checks'
const context = {
base: 'main',
branch: 'feature/template-aware-pr',
branchChangedByPreparation: false,
commitSummary: 'abc123 feat: test',
changeSummary: 'M README.md',
patch: '+hello',
currentTitle: '',
currentBody: templateBody,
currentDraft: false
}
const sourceControlAiResolvedParams = {
agentId: 'codex' as const,
model: 'gpt-5.5'
}
mocks.resolveHostedReviewBodyForGeneration.mockResolvedValue(templateBody)
mocks.getPullRequestDraftContext.mockResolvedValue(context)
mocks.generatePullRequestFieldsFromContext.mockResolvedValue({
success: true,
fields: {
base: 'main',
title: 'Use existing template',
body: templateBody,
draft: false
}
})
const commands = new RuntimeGitCommands({
resolveRuntimeGitTarget: async () => localTarget(worktreePath),
getRuntimeSettings: () => ({}) as GlobalSettings
})
await commands.generateRuntimePullRequestFields(
'id:wt-1',
{
base: 'main',
title: '',
body: '',
draft: false,
provider: 'gitlab',
useTemplate: true
},
{ sourceControlAiResolvedParams }
)
expect(mocks.resolveHostedReviewBodyForGeneration).toHaveBeenCalledWith({
body: '',
repoPath: worktreePath,
connectionId: undefined,
provider: 'gitlab',
useTemplate: true
})
expect(mocks.getPullRequestDraftContext).toHaveBeenCalledWith(
expect.any(Function),
expect.objectContaining({
currentBody: templateBody
})
)
})
it('resolves SSH commit-message settings against the host cache, then reports it unserved', async () => {
const worktreePath = '/remote/repo'
const params = { agentId: 'cursor', model: 'remote-model' }
mocks.resolveCommitMessageSettings.mockReturnValue({ ok: true, params })
const commands = new RuntimeGitCommands({
resolveRuntimeGitTarget: async () => ({
worktree: makeWorktree(worktreePath),
executionHostId: 'ssh:conn-1'
}),
getRuntimeSettings: () =>
({
commitMessageAi: {
enabled: true,
agentId: 'cursor',
selectedModelByAgentByHost: { 'ssh:conn-1': { cursor: 'remote-model' } }
}
}) as unknown as GlobalSettings
})
await expect(commands.generateRuntimeCommitMessage('id:wt-1')).resolves.toEqual({
success: false,
error: SSH_HOST_NOT_SERVED_MESSAGE
})
expect(mocks.resolveCommitMessageSettings).toHaveBeenCalledWith(
expect.any(Object),
'ssh:conn-1',
'commitMessage',
null
)
expect(mocks.getStagedCommitContext).not.toHaveBeenCalled()
expect(mocks.generateCommitMessageFromContext).not.toHaveBeenCalled()
})
it('enriches the local commit context with the workspace linked issue', async () => {
const worktreePath = mkdtempSync(join(tmpdir(), 'orca-runtime-git-'))
tempDirs.push(worktreePath)
const context = { branch: 'main', stagedSummary: 'M\tREADME.md', stagedPatch: '+hello' }
const params = { agentId: 'codex', model: 'gpt-5.4-mini' }
mocks.resolveCommitMessageSettings.mockReturnValue({ ok: true, params })
mocks.getStagedCommitContext.mockResolvedValue(context)
mocks.generateCommitMessageFromContext.mockResolvedValue({ success: true, message: 'docs' })
const commands = new RuntimeGitCommands({
resolveRuntimeGitTarget: async () => localTarget(worktreePath, 123),
getRuntimeSettings: () => ({}) as GlobalSettings
})
await commands.generateRuntimeCommitMessage('id:wt-1')
expect(mocks.generateCommitMessageFromContext).toHaveBeenCalledWith(
{ ...context, linkedIssue: 123 },
params,
expect.objectContaining({ kind: 'local' })
)
})
it('prefers live meta over the linked issue projected onto the resolved worktree', async () => {
const worktreePath = mkdtempSync(join(tmpdir(), 'orca-runtime-git-'))
tempDirs.push(worktreePath)
const context = { branch: 'main', stagedSummary: 'M\tREADME.md', stagedPatch: '+hello' }
const params = { agentId: 'codex', model: 'gpt-5.4-mini' }
mocks.resolveCommitMessageSettings.mockReturnValue({ ok: true, params })
mocks.getStagedCommitContext.mockResolvedValue(context)
mocks.generateCommitMessageFromContext.mockResolvedValue({ success: true, message: 'docs' })
const getWorktreeLinkedIssue = vi.fn(() => 321)
const commands = new RuntimeGitCommands({
resolveRuntimeGitTarget: async () => localTarget(worktreePath, 123),
getRuntimeSettings: () => ({}) as GlobalSettings,
getWorktreeLinkedIssue
})
await commands.generateRuntimeCommitMessage('id:wt-1')
expect(getWorktreeLinkedIssue).toHaveBeenCalledWith('wt-1')
expect(mocks.generateCommitMessageFromContext).toHaveBeenCalledWith(
{ ...context, linkedIssue: 321 },
params,
expect.objectContaining({ kind: 'local' })
)
})
it('drops a stale worktree issue number when live meta reports the workspace unlinked', async () => {
const worktreePath = mkdtempSync(join(tmpdir(), 'orca-runtime-git-'))
tempDirs.push(worktreePath)
const context = { branch: 'main', stagedSummary: 'M\tREADME.md', stagedPatch: '+hello' }
mocks.resolveCommitMessageSettings.mockReturnValue({
ok: true,
params: { agentId: 'codex', model: 'gpt-5.4-mini' }
})
mocks.getStagedCommitContext.mockResolvedValue(context)
mocks.generateCommitMessageFromContext.mockResolvedValue({ success: true, message: 'docs' })
const commands = new RuntimeGitCommands({
resolveRuntimeGitTarget: async () => localTarget(worktreePath, 123),
getRuntimeSettings: () => ({}) as GlobalSettings,
getWorktreeLinkedIssue: () => null
})
await commands.generateRuntimeCommitMessage('id:wt-1')
expect(mocks.generateCommitMessageFromContext.mock.calls[0][0]).not.toHaveProperty(
'linkedIssue'
)
})
it('keeps the cached issue number when live meta is unavailable rather than unlinked', async () => {
const worktreePath = mkdtempSync(join(tmpdir(), 'orca-runtime-git-'))
tempDirs.push(worktreePath)
const context = { branch: 'main', stagedSummary: 'M\tREADME.md', stagedPatch: '+hello' }
const params = { agentId: 'codex', model: 'gpt-5.4-mini' }
mocks.resolveCommitMessageSettings.mockReturnValue({ ok: true, params })
mocks.getStagedCommitContext.mockResolvedValue(context)
mocks.generateCommitMessageFromContext.mockResolvedValue({ success: true, message: 'docs' })
const commands = new RuntimeGitCommands({
resolveRuntimeGitTarget: async () => localTarget(worktreePath, 123),
getRuntimeSettings: () => ({}) as GlobalSettings,
getWorktreeLinkedIssue: () => undefined
})
await commands.generateRuntimeCommitMessage('id:wt-1')
expect(mocks.generateCommitMessageFromContext).toHaveBeenCalledWith(
{ ...context, linkedIssue: 123 },
params,
expect.objectContaining({ kind: 'local' })
)
})
it('reads pull-request linked issues from live meta too', async () => {
const worktreePath = mkdtempSync(join(tmpdir(), 'orca-runtime-git-'))
tempDirs.push(worktreePath)
const context = {
base: 'main',
branch: 'feature/login',
commitSummary: 'abc123 feat: test',
changeSummary: 'M README.md',
patch: '+hello',
currentTitle: '',
currentBody: '',
currentDraft: false
}
mocks.getPullRequestDraftContext.mockResolvedValue(context)
mocks.generatePullRequestFieldsFromContext.mockResolvedValue({ success: true, fields: {} })
const commands = new RuntimeGitCommands({
resolveRuntimeGitTarget: async () => localTarget(worktreePath, 123),
getRuntimeSettings: () => ({}) as GlobalSettings,
getWorktreeLinkedIssue: () => 321
})
await commands.generateRuntimePullRequestFields(
'id:wt-1',
{ base: 'main', title: '', body: '', draft: false },
{ sourceControlAiResolvedParams: { agentId: 'codex' as const, model: 'gpt-5.5' } }
)
expect(mocks.generatePullRequestFieldsFromContext.mock.calls[0][0]).toEqual({
...context,
linkedIssue: 321
})
})
it('leaves the commit context untouched when no issue is linked', async () => {
const worktreePath = mkdtempSync(join(tmpdir(), 'orca-runtime-git-'))
tempDirs.push(worktreePath)
const context = { branch: 'main', stagedSummary: 'M\tREADME.md', stagedPatch: '+hello' }
const params = { agentId: 'codex', model: 'gpt-5.4-mini' }
mocks.resolveCommitMessageSettings.mockReturnValue({ ok: true, params })
mocks.getStagedCommitContext.mockResolvedValue(context)
mocks.generateCommitMessageFromContext.mockResolvedValue({ success: true, message: 'docs' })
await makeCommands(worktreePath).generateRuntimeCommitMessage('id:wt-1')
expect(mocks.generateCommitMessageFromContext.mock.calls[0][0]).not.toHaveProperty(
'linkedIssue'
)
})
it('leaves the pull-request context untouched when no issue is linked', async () => {
const worktreePath = mkdtempSync(join(tmpdir(), 'orca-runtime-git-'))
tempDirs.push(worktreePath)
const context = {
base: 'main',
branch: 'feature/login',
commitSummary: 'abc123 feat: test',
changeSummary: 'M README.md',
patch: '+hello',
currentTitle: '',
currentBody: '',
currentDraft: false
}
const params = { agentId: 'codex' as const, model: 'gpt-5.5' }
mocks.getPullRequestDraftContext.mockResolvedValue(context)
mocks.generatePullRequestFieldsFromContext.mockResolvedValue({ success: true, fields: {} })
await makeCommands(worktreePath).generateRuntimePullRequestFields(
'id:wt-1',
{ base: 'main', title: '', body: '', draft: false },
{ sourceControlAiResolvedParams: params }
)
expect(mocks.generatePullRequestFieldsFromContext.mock.calls).toHaveLength(1)
expect(mocks.generatePullRequestFieldsFromContext.mock.calls[0][0]).not.toHaveProperty(
'linkedIssue'
)
})
})