mirror of
https://github.com/stablyai/orca.git
synced 2026-11-18 11:54:46 +00:00
refactor(relay): delete the SSH relay server, its build assets and tests (#27215)
* wip: delete the SSH relay server and its build, assets and tests * wip: drop main/relay plugin conformance; WSL reader lookup test * fix: drop the emptied relay bench; prune baselines * test: keep the native halves of tests that also covered the relay * chore(ci): drop shard timings for the deleted relay server tests * fix: keep the directory listing budget that darwin terminal names now import --------- Co-authored-by: m4air <m4air@Mac.localdomain>
This commit is contained in:
@@ -1,36 +1,39 @@
|
||||
import { readFile, unlink, utimes, writeFile } from 'node:fs/promises'
|
||||
import { readFile, rm, unlink, utimes, writeFile } from 'node:fs/promises'
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { mkdtempSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import * as path from 'node:path'
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
import { runProcess } from '@orca/process-host'
|
||||
import { gitCommit, gitInit, type MockDispatcher } from '../../../relay/git-handler-test-setup'
|
||||
import {
|
||||
createGitHandlerRelay,
|
||||
createGitTempDir,
|
||||
removeGitTempDir
|
||||
} from '../../../relay/git-handler-test-harness'
|
||||
import type { GitHandler } from '../../../relay/git-handler'
|
||||
import { isMissingGitBlobPath } from '../../../shared/git-blob-absence'
|
||||
import { readGitBlobAtIndexPath } from './git-blob-read'
|
||||
import { getDiff } from './file-diff'
|
||||
import { invalidateGitReadCaches, settledDiffCache } from './git-read-cache-invalidation'
|
||||
import { readWorktreeDiffStamp } from './worktree-diff-stamp'
|
||||
|
||||
function gitInit(dir: string): void {
|
||||
execFileSync('git', ['init'], { cwd: dir, stdio: 'pipe' })
|
||||
execFileSync('git', ['config', 'user.email', 'test@example.com'], { cwd: dir, stdio: 'pipe' })
|
||||
execFileSync('git', ['config', 'user.name', 'Test User'], { cwd: dir, stdio: 'pipe' })
|
||||
}
|
||||
|
||||
function gitCommit(dir: string, message: string): void {
|
||||
execFileSync('git', ['add', '.'], { cwd: dir, stdio: 'pipe' })
|
||||
execFileSync('git', ['commit', '-m', message, '--allow-empty'], { cwd: dir, stdio: 'pipe' })
|
||||
}
|
||||
|
||||
describe('real Git missing paths and failed blob reads', () => {
|
||||
let repo: string
|
||||
let dispatcher: MockDispatcher
|
||||
let handler: GitHandler
|
||||
|
||||
beforeEach(() => {
|
||||
repo = createGitTempDir()
|
||||
;({ dispatcher, handler } = createGitHandlerRelay())
|
||||
repo = mkdtempSync(path.join(tmpdir(), 'orca-real-git-'))
|
||||
gitInit(repo)
|
||||
invalidateGitReadCaches()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
handler.dispose()
|
||||
invalidateGitReadCaches()
|
||||
await removeGitTempDir(repo)
|
||||
await rm(repo, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
async function git(args: string[], input?: string): Promise<string> {
|
||||
@@ -39,75 +42,60 @@ describe('real Git missing paths and failed blob reads', () => {
|
||||
return result.stdout
|
||||
}
|
||||
|
||||
function diff(host: 'native' | 'relay', staged = false): Promise<unknown> {
|
||||
return host === 'native'
|
||||
? getDiff(repo, 'file.txt', staged)
|
||||
: dispatcher.callRequest('git.diff', { worktreePath: repo, filePath: 'file.txt', staged })
|
||||
function diff(staged = false): Promise<unknown> {
|
||||
return getDiff(repo, 'file.txt', staged)
|
||||
}
|
||||
|
||||
it.each(['native', 'relay'] as const)(
|
||||
'does not substitute HEAD for a corrupt index blob on %s',
|
||||
async (host) => {
|
||||
await writeFile(path.join(repo, 'file.txt'), 'committed\n')
|
||||
gitCommit(repo, 'initial')
|
||||
await writeFile(path.join(repo, 'file.txt'), 'staged\n')
|
||||
await git(['add', 'file.txt'])
|
||||
const oid = (await git(['rev-parse', ':file.txt'])).trim()
|
||||
await writeFile(path.join(repo, 'file.txt'), 'working\n')
|
||||
const old = new Date(Date.now() - 10_000)
|
||||
await Promise.all(
|
||||
['.git/index', 'file.txt'].map((file) => utimes(path.join(repo, file), old, old))
|
||||
)
|
||||
const before = await readWorktreeDiffStamp(repo, 'file.txt', true)
|
||||
await unlink(path.join(repo, '.git', 'objects', oid.slice(0, 2), oid.slice(2)))
|
||||
expect(await readGitBlobAtIndexPath(repo, 'file.txt')).toMatchObject({
|
||||
exists: false,
|
||||
failed: true
|
||||
})
|
||||
it('does not substitute HEAD for a corrupt index blob', async () => {
|
||||
await writeFile(path.join(repo, 'file.txt'), 'committed\n')
|
||||
gitCommit(repo, 'initial')
|
||||
await writeFile(path.join(repo, 'file.txt'), 'staged\n')
|
||||
await git(['add', 'file.txt'])
|
||||
const oid = (await git(['rev-parse', ':file.txt'])).trim()
|
||||
await writeFile(path.join(repo, 'file.txt'), 'working\n')
|
||||
const old = new Date(Date.now() - 10_000)
|
||||
await Promise.all(
|
||||
['.git/index', 'file.txt'].map((file) => utimes(path.join(repo, file), old, old))
|
||||
)
|
||||
const before = await readWorktreeDiffStamp(repo, 'file.txt', true)
|
||||
await unlink(path.join(repo, '.git', 'objects', oid.slice(0, 2), oid.slice(2)))
|
||||
expect(await readGitBlobAtIndexPath(repo, 'file.txt')).toMatchObject({
|
||||
exists: false,
|
||||
failed: true
|
||||
})
|
||||
|
||||
expect(await diff(host)).toMatchObject({ originalContent: '', modifiedContent: 'working\n' })
|
||||
if (host === 'native') {
|
||||
expect(settledDiffCache.stats().entries).toBe(0)
|
||||
}
|
||||
await git(['hash-object', '-w', '--stdin'], 'staged\n')
|
||||
const after = await readWorktreeDiffStamp(repo, 'file.txt', true)
|
||||
expect(after?.value).toBe(before?.value)
|
||||
expect(await diff()).toMatchObject({ originalContent: '', modifiedContent: 'working\n' })
|
||||
expect(settledDiffCache.stats().entries).toBe(0)
|
||||
await git(['hash-object', '-w', '--stdin'], 'staged\n')
|
||||
const after = await readWorktreeDiffStamp(repo, 'file.txt', true)
|
||||
expect(after?.value).toBe(before?.value)
|
||||
|
||||
expect(await diff(host)).toMatchObject({
|
||||
originalContent: 'staged\n',
|
||||
modifiedContent: 'working\n'
|
||||
})
|
||||
if (host === 'native') {
|
||||
expect(settledDiffCache.stats().entries).toBe(1)
|
||||
}
|
||||
}
|
||||
)
|
||||
expect(await diff()).toMatchObject({
|
||||
originalContent: 'staged\n',
|
||||
modifiedContent: 'working\n'
|
||||
})
|
||||
expect(settledDiffCache.stats().entries).toBe(1)
|
||||
})
|
||||
|
||||
it.each(['native', 'relay'] as const)(
|
||||
'retains added paths on an unborn branch on %s',
|
||||
async (host) => {
|
||||
await writeFile(path.join(repo, 'file.txt'), 'new file\n')
|
||||
await git(['add', 'file.txt'])
|
||||
expect(await diff(host, true)).toMatchObject({
|
||||
originalContent: '',
|
||||
modifiedContent: 'new file\n'
|
||||
})
|
||||
}
|
||||
)
|
||||
it('retains added paths on an unborn branch', async () => {
|
||||
await writeFile(path.join(repo, 'file.txt'), 'new file\n')
|
||||
await git(['add', 'file.txt'])
|
||||
expect(await diff(true)).toMatchObject({
|
||||
originalContent: '',
|
||||
modifiedContent: 'new file\n'
|
||||
})
|
||||
})
|
||||
|
||||
it.each(['native', 'relay'] as const)(
|
||||
'retains additions absent from a valid HEAD tree on %s',
|
||||
async (host) => {
|
||||
await writeFile(path.join(repo, 'seed.txt'), 'seed\n')
|
||||
gitCommit(repo, 'initial')
|
||||
await writeFile(path.join(repo, 'file.txt'), 'new file\n')
|
||||
await git(['add', 'file.txt'])
|
||||
expect(await diff(host, true)).toMatchObject({
|
||||
originalContent: '',
|
||||
modifiedContent: 'new file\n'
|
||||
})
|
||||
}
|
||||
)
|
||||
it('retains additions absent from a valid HEAD tree', async () => {
|
||||
await writeFile(path.join(repo, 'seed.txt'), 'seed\n')
|
||||
gitCommit(repo, 'initial')
|
||||
await writeFile(path.join(repo, 'file.txt'), 'new file\n')
|
||||
await git(['add', 'file.txt'])
|
||||
expect(await diff(true)).toMatchObject({
|
||||
originalContent: '',
|
||||
modifiedContent: 'new file\n'
|
||||
})
|
||||
})
|
||||
|
||||
it('recognizes actual index and tree absence without accepting corrupt objects', async () => {
|
||||
await writeFile(path.join(repo, 'seed.txt'), 'seed\n')
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
import { readFile, writeFile } from 'node:fs/promises'
|
||||
import * as path from 'node:path'
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
import { runProcess } from '@orca/process-host'
|
||||
import { gitCommit, gitInit, type MockDispatcher } from '../../../relay/git-handler-test-setup'
|
||||
import {
|
||||
createGitHandlerRelay,
|
||||
createGitTempDir,
|
||||
removeGitTempDir
|
||||
} from '../../../relay/git-handler-test-harness'
|
||||
import type { GitHandler } from '../../../relay/git-handler'
|
||||
import { bulkStageFiles, bulkUnstageFiles } from './staging'
|
||||
import { bulkDiscardChanges } from './discard-changes'
|
||||
|
||||
describe('bulk pathspec stdin on execution hosts', () => {
|
||||
let repo: string
|
||||
let dispatcher: MockDispatcher
|
||||
let handler: GitHandler
|
||||
|
||||
beforeEach(() => {
|
||||
repo = createGitTempDir()
|
||||
;({ dispatcher, handler } = createGitHandlerRelay())
|
||||
gitInit(repo)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
handler.dispose()
|
||||
await removeGitTempDir(repo)
|
||||
})
|
||||
|
||||
async function changedFiles(staged: boolean): Promise<string[]> {
|
||||
const result = await runProcess({
|
||||
program: 'git',
|
||||
args: ['diff', ...(staged ? ['--cached'] : []), '--name-only', '-z'],
|
||||
cwd: repo
|
||||
})
|
||||
expect(result.code).toBe(0)
|
||||
return result.stdout.split('\0').filter(Boolean).sort()
|
||||
}
|
||||
|
||||
function mutate(
|
||||
host: 'native' | 'relay',
|
||||
action: 'stage' | 'unstage' | 'discard',
|
||||
filePaths: string[]
|
||||
): Promise<unknown> {
|
||||
if (host === 'relay') {
|
||||
const methods = {
|
||||
stage: 'git.bulkStage',
|
||||
unstage: 'git.bulkUnstage',
|
||||
discard: 'git.bulkDiscard'
|
||||
}
|
||||
return dispatcher.callRequest(methods[action], { worktreePath: repo, filePaths })
|
||||
}
|
||||
const operations = {
|
||||
stage: bulkStageFiles,
|
||||
unstage: bulkUnstageFiles,
|
||||
discard: bulkDiscardChanges
|
||||
}
|
||||
return operations[action](repo, filePaths)
|
||||
}
|
||||
|
||||
it.each(['native', 'relay'] as const)(
|
||||
'stages, unstages and discards over 100 literal paths on %s',
|
||||
async (host) => {
|
||||
const selected = Array.from({ length: 105 }, (_, index) => `file-${index}.txt`)
|
||||
selected.push('[k]eep.log', 'space name.txt', '-option.txt')
|
||||
if (process.platform !== 'win32') {
|
||||
selected.push('line\nname.txt', ':(magic).txt', 'back\\slash.txt')
|
||||
}
|
||||
const allPaths = [...selected, 'keep.log']
|
||||
await Promise.all(
|
||||
allPaths.map((filePath) => writeFile(path.join(repo, filePath), 'original\n'))
|
||||
)
|
||||
gitCommit(repo, 'initial')
|
||||
await Promise.all(
|
||||
allPaths.map((filePath) => writeFile(path.join(repo, filePath), 'modified\n'))
|
||||
)
|
||||
|
||||
await mutate(host, 'stage', [])
|
||||
expect(await changedFiles(true)).toEqual([])
|
||||
await mutate(host, 'stage', selected)
|
||||
expect(await changedFiles(true)).toEqual([...selected].sort())
|
||||
await mutate(host, 'unstage', [])
|
||||
expect(await changedFiles(true)).toEqual([...selected].sort())
|
||||
await mutate(host, 'unstage', selected)
|
||||
expect(await changedFiles(true)).toEqual([])
|
||||
await mutate(host, 'discard', [])
|
||||
expect(await changedFiles(false)).toEqual([...allPaths].sort())
|
||||
await mutate(host, 'discard', selected)
|
||||
expect(await changedFiles(false)).toEqual(['keep.log'])
|
||||
expect(await readFile(path.join(repo, 'keep.log'), 'utf8')).toBe('modified\n')
|
||||
}
|
||||
)
|
||||
|
||||
it.each(['native', 'relay'] as const)('rejects NUL path injection on %s', async (host) => {
|
||||
await writeFile(path.join(repo, 'one.txt'), 'original\n')
|
||||
gitCommit(repo, 'initial')
|
||||
await writeFile(path.join(repo, 'one.txt'), 'modified\n')
|
||||
|
||||
await expect(mutate(host, 'stage', ['one.txt\0:(top)**'])).rejects.toThrow('NUL')
|
||||
expect(await changedFiles(true)).toEqual([])
|
||||
})
|
||||
})
|
||||
@@ -1,38 +1,36 @@
|
||||
import { readFile, writeFile } from 'node:fs/promises'
|
||||
import { readFile, rm, writeFile } from 'node:fs/promises'
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { mkdtempSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import * as path from 'node:path'
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
import { runProcess } from '@orca/process-host'
|
||||
import { gitCommit, gitInit, type MockDispatcher } from '../../../relay/git-handler-test-setup'
|
||||
import {
|
||||
createGitHandlerRelay,
|
||||
createGitTempDir,
|
||||
removeGitTempDir
|
||||
} from '../../../relay/git-handler-test-harness'
|
||||
import type { GitHandler } from '../../../relay/git-handler'
|
||||
import { bulkUnstageFiles, unstageFile } from './staging'
|
||||
import { bulkDiscardChanges, discardChanges } from './discard-changes'
|
||||
|
||||
const modes = [
|
||||
{ host: 'native', bulk: false },
|
||||
{ host: 'native', bulk: true },
|
||||
{ host: 'relay', bulk: false },
|
||||
{ host: 'relay', bulk: true }
|
||||
] as const
|
||||
function gitInit(dir: string): void {
|
||||
execFileSync('git', ['init'], { cwd: dir, stdio: 'pipe' })
|
||||
execFileSync('git', ['config', 'user.email', 'test@example.com'], { cwd: dir, stdio: 'pipe' })
|
||||
execFileSync('git', ['config', 'user.name', 'Test User'], { cwd: dir, stdio: 'pipe' })
|
||||
}
|
||||
|
||||
function gitCommit(dir: string, message: string): void {
|
||||
execFileSync('git', ['add', '.'], { cwd: dir, stdio: 'pipe' })
|
||||
execFileSync('git', ['commit', '-m', message, '--allow-empty'], { cwd: dir, stdio: 'pipe' })
|
||||
}
|
||||
|
||||
const modes = [{ bulk: false }, { bulk: true }] as const
|
||||
|
||||
describe('staging and discard preserve index authority', () => {
|
||||
let repo: string
|
||||
let dispatcher: MockDispatcher
|
||||
let handler: GitHandler
|
||||
|
||||
beforeEach(() => {
|
||||
repo = createGitTempDir()
|
||||
;({ dispatcher, handler } = createGitHandlerRelay())
|
||||
repo = mkdtempSync(path.join(tmpdir(), 'orca-real-git-'))
|
||||
gitInit(repo)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
handler.dispose()
|
||||
await removeGitTempDir(repo)
|
||||
await rm(repo, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
async function git(args: string[], input?: string): Promise<string> {
|
||||
@@ -46,19 +44,13 @@ describe('staging and discard preserve index authority', () => {
|
||||
action: 'unstage' | 'discard',
|
||||
filePaths: string[]
|
||||
): Promise<unknown> {
|
||||
if (mode.host === 'relay') {
|
||||
return dispatcher.callRequest(
|
||||
`git.${mode.bulk ? (action === 'unstage' ? 'bulkUnstage' : 'bulkDiscard') : action}`,
|
||||
{ worktreePath: repo, ...(mode.bulk ? { filePaths } : { filePath: filePaths[0] }) }
|
||||
)
|
||||
}
|
||||
if (mode.bulk) {
|
||||
return (action === 'unstage' ? bulkUnstageFiles : bulkDiscardChanges)(repo, filePaths)
|
||||
}
|
||||
return (action === 'unstage' ? unstageFile : discardChanges)(repo, filePaths[0])
|
||||
}
|
||||
|
||||
it.each(modes)('preserves staged MM content during $host bulk=$bulk discard', async (mode) => {
|
||||
it.each(modes)('preserves staged MM content during bulk=$bulk discard', async (mode) => {
|
||||
await writeFile(path.join(repo, 'file.txt'), 'committed\n')
|
||||
gitCommit(repo, 'initial')
|
||||
await writeFile(path.join(repo, 'file.txt'), 'staged\n')
|
||||
@@ -73,7 +65,7 @@ describe('staging and discard preserve index authority', () => {
|
||||
expect(await git(['diff', '--cached', '--name-only'])).toBe('file.txt\n')
|
||||
})
|
||||
|
||||
it.each(modes)('restores staged additions during $host bulk=$bulk AM discard', async (mode) => {
|
||||
it.each(modes)('restores staged additions during bulk=$bulk AM discard', async (mode) => {
|
||||
await writeFile(path.join(repo, 'initial.txt'), 'committed\n')
|
||||
gitCommit(repo, 'initial')
|
||||
await writeFile(path.join(repo, 'new.txt'), 'staged addition\n')
|
||||
@@ -87,7 +79,7 @@ describe('staging and discard preserve index authority', () => {
|
||||
expect(await git(['diff', '--name-only'])).toBe('')
|
||||
})
|
||||
|
||||
it.each(modes)('unstages selected unborn paths on $host bulk=$bulk', async (mode) => {
|
||||
it.each(modes)('unstages selected unborn paths on bulk=$bulk', async (mode) => {
|
||||
await writeFile(path.join(repo, 'selected.txt'), 'selected\n')
|
||||
await writeFile(path.join(repo, 'keep.txt'), 'keep\n')
|
||||
await git(['add', '.'])
|
||||
@@ -98,7 +90,7 @@ describe('staging and discard preserve index authority', () => {
|
||||
expect(await readFile(path.join(repo, 'selected.txt'), 'utf8')).toBe('selected\n')
|
||||
})
|
||||
|
||||
it.each(['native', 'relay'] as const)('unstages both rename paths on %s', async (host) => {
|
||||
it('unstages both rename paths', async () => {
|
||||
await writeFile(path.join(repo, 'old.txt'), 'rename content\n')
|
||||
await writeFile(path.join(repo, 'keep.txt'), 'keep\n')
|
||||
gitCommit(repo, 'initial')
|
||||
@@ -106,32 +98,29 @@ describe('staging and discard preserve index authority', () => {
|
||||
await writeFile(path.join(repo, 'keep.txt'), 'keep staged\n')
|
||||
await git(['add', 'keep.txt'])
|
||||
|
||||
await mutate({ host, bulk: true }, 'unstage', ['new.txt', 'old.txt'])
|
||||
await mutate({ bulk: true }, 'unstage', ['new.txt', 'old.txt'])
|
||||
|
||||
expect(await git(['diff', '--cached', '--name-only'])).toBe('keep.txt\n')
|
||||
expect(await git(['ls-files', '-z'])).toBe('keep.txt\0old.txt\0')
|
||||
expect(await readFile(path.join(repo, 'new.txt'), 'utf8')).toBe('rename content\n')
|
||||
})
|
||||
|
||||
it.each(['native', 'relay'] as const)(
|
||||
'discards a staged rename after unstaging both paths on %s',
|
||||
async (host) => {
|
||||
await writeFile(path.join(repo, 'old.txt'), 'rename content\n')
|
||||
gitCommit(repo, 'initial')
|
||||
await git(['mv', 'old.txt', 'new.txt'])
|
||||
it('discards a staged rename after unstaging both paths', async () => {
|
||||
await writeFile(path.join(repo, 'old.txt'), 'rename content\n')
|
||||
gitCommit(repo, 'initial')
|
||||
await git(['mv', 'old.txt', 'new.txt'])
|
||||
|
||||
await mutate({ host, bulk: true }, 'unstage', ['new.txt', 'old.txt'])
|
||||
await mutate({ host, bulk: true }, 'discard', ['new.txt', 'old.txt'])
|
||||
await mutate({ bulk: true }, 'unstage', ['new.txt', 'old.txt'])
|
||||
await mutate({ bulk: true }, 'discard', ['new.txt', 'old.txt'])
|
||||
|
||||
expect(await git(['status', '--porcelain'])).toBe('')
|
||||
expect(await readFile(path.join(repo, 'old.txt'), 'utf8')).toBe('rename content\n')
|
||||
await expect(readFile(path.join(repo, 'new.txt'), 'utf8')).rejects.toMatchObject({
|
||||
code: 'ENOENT'
|
||||
})
|
||||
}
|
||||
)
|
||||
expect(await git(['status', '--porcelain'])).toBe('')
|
||||
expect(await readFile(path.join(repo, 'old.txt'), 'utf8')).toBe('rename content\n')
|
||||
await expect(readFile(path.join(repo, 'new.txt'), 'utf8')).rejects.toMatchObject({
|
||||
code: 'ENOENT'
|
||||
})
|
||||
})
|
||||
|
||||
it.each(modes)('rejects an unresolved conflict on $host bulk=$bulk', async (mode) => {
|
||||
it.each(modes)('rejects an unresolved conflict on bulk=$bulk', async (mode) => {
|
||||
await writeFile(path.join(repo, 'file.txt'), 'base\n')
|
||||
gitCommit(repo, 'initial')
|
||||
const blobs = await Promise.all(
|
||||
|
||||
Reference in New Issue
Block a user