test: remove upstream projections and duplicate submodule guard

This commit is contained in:
OrcaWin
2026-11-13 02:37:42 -08:00
parent 85873ef846
commit ddeb2c07b9
7 changed files with 3 additions and 200 deletions
@@ -1745,7 +1745,6 @@
"src/main/git/source-control/submodules/status-submodule.test.ts": 306,
"src/main/git/source-control/upstream/status-upstream-ref.test.ts": 52,
"src/main/git/source-control/upstream/upstream-deferred-fork-remote-real.test.ts": 319,
"src/main/git/source-control/upstream/upstream.test.ts": 406,
"src/main/git/worktrees/creation/worktree-add-local-base-refresh.test.ts": 362,
"src/main/git/worktrees/creation/worktree-add-pending-removal.test.ts": 346,
"src/main/git/worktrees/creation/worktree-add-remote-branch-upstream-real-git.test.ts": 786,
@@ -67,8 +67,6 @@ import { clearSubmodulePathsCacheForTests } from './submodule-paths'
import { getDiff } from '../diffs/file-diff'
describe('submodule diff routing', () => {
const OLD_OID = 'a'.repeat(40)
const NEW_OID = 'b'.repeat(40)
const PARENT = path.resolve('/repo-sm')
beforeEach(() => {
@@ -80,24 +78,6 @@ describe('submodule diff routing', () => {
statMock.mockReset()
existsSyncMock.mockReset()
statMock.mockResolvedValue({ isFile: () => true, size: 12 })
gitExecFileAsyncMock.mockImplementation((args: string[], options?: { cwd?: string }) => {
if (args[0] === 'config' && args.includes('.gitmodules')) {
// Declare the submodule only in its parent so recursion terminates.
return Promise.resolve({
stdout: options?.cwd === PARENT ? 'submodule.flutter_mine.path\nflutter_mine\0' : ''
})
}
if (args[0] === 'ls-files') {
return Promise.resolve({ stdout: `160000 ${OLD_OID} 0\tflutter_mine\n` })
}
if (args[0] === 'ls-tree') {
return Promise.resolve({ stdout: `160000 commit ${OLD_OID}\tflutter_mine\n` })
}
if (args[0] === 'rev-parse') {
return Promise.resolve({ stdout: `${NEW_OID}\n` })
}
return Promise.resolve({ stdout: '' })
})
})
it('rejects inner submodule diffs whose .gitmodules path escapes the worktree', async () => {
@@ -112,17 +92,4 @@ describe('submodule diff routing', () => {
await expect(getDiff(PARENT, '../evil/secret.txt', false)).rejects.toThrow('Access denied')
})
it('rejects gitlink pointer diffs whose .gitmodules path escapes the worktree', async () => {
gitExecFileAsyncMock.mockImplementation((args: string[], options?: { cwd?: string }) => {
if (args[0] === 'config' && args.includes('.gitmodules')) {
return Promise.resolve({
stdout: options?.cwd === PARENT ? 'submodule.evil.path\n../evil\0' : ''
})
}
return Promise.resolve({ stdout: '' })
})
await expect(getDiff(PARENT, '../evil', false)).rejects.toThrow('Access denied')
})
})
@@ -4,49 +4,6 @@ import { resolveGitStatusUpstreamRef } from './status-upstream-ref'
const signal = (): AbortSignal => new AbortController().signal
describe('resolveGitStatusUpstreamRef', () => {
it('preserves the exact namespace for a slash-containing remote name', async () => {
const execGit = vi.fn().mockResolvedValue({
stdout:
'refs/heads/feature/main\0refs/remotes/team/fork/feature/main\0team/fork/feature/main\n'
})
await expect(
resolveGitStatusUpstreamRef(
execGit,
'/repo',
'refs/heads/feature/main',
'team/fork/feature/main',
signal()
)
).resolves.toBe('refs/remotes/team/fork/feature/main')
expect(execGit).toHaveBeenCalledWith(
[
'for-each-ref',
'--format=%(refname)%00%(upstream)%00%(upstream:short)',
'--count=1',
'refs/heads/feature/main'
],
'/repo',
expect.any(AbortSignal)
)
})
it('returns a slash-named local upstream for the binding validator to reject', async () => {
const execGit = vi.fn().mockResolvedValue({
stdout: 'refs/heads/feature/topic\0refs/heads/feature/base\0feature/base\n'
})
await expect(
resolveGitStatusUpstreamRef(
execGit,
'/repo',
'refs/heads/feature/topic',
'feature/base',
signal()
)
).resolves.toBe('refs/heads/feature/base')
})
it('resolves an accepted effective upstream override explicitly', async () => {
const execGit = vi
.fn()
@@ -1,34 +0,0 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
const { gitExecFileAsyncMock } = vi.hoisted(() => ({
gitExecFileAsyncMock: vi.fn()
}))
vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
gitExecFileAsync: gitExecFileAsyncMock
}))
import { getUpstreamStatus, invalidateGitUpstreamStatusReads } from './upstream'
describe('getUpstreamStatus', () => {
beforeEach(() => {
gitExecFileAsyncMock.mockReset()
invalidateGitUpstreamStatusReads()
})
it('does not hide git failures while checking an explicit publish target', async () => {
gitExecFileAsyncMock.mockResolvedValueOnce({ stdout: '', stderr: '' }).mockRejectedValueOnce(
Object.assign(new Error('fatal: not a git repository'), {
stderr: 'fatal: not a git repository'
})
)
await expect(
getUpstreamStatus('/repo', {
remoteName: 'fork',
branchName: 'feature/fix'
})
).rejects.toThrow('fatal: not a git repository')
})
})
@@ -10,17 +10,6 @@ function listSnapshot(records: string[]): string {
type GitCommandRunner = Parameters<typeof createGitConfigSnapshotRunner>[0]
function countCalls(
runGit: ReturnType<typeof vi.fn<GitCommandRunner>>,
expectedArgs: string[]
): number {
return runGit.mock.calls.filter(([args]) => {
return (
args.length === expectedArgs.length && args.every((arg, index) => arg === expectedArgs[index])
)
}).length
}
describe('createGitConfigSnapshotRunner', () => {
it('case-folds the requested section and key', async () => {
const runGit = vi.fn<GitCommandRunner>(async () => ({
@@ -76,7 +65,6 @@ describe('createGitConfigSnapshotRunner', () => {
})
it('rejects an absent key from a loaded snapshot instead of returning empty success', async () => {
// Missing keys must reject like config --get, without respawning the command this snapshot coalesces.
const runGit = vi.fn<GitCommandRunner>(async () => ({
stdout: listSnapshot(['branch.main.remote\norigin'])
}))
@@ -85,12 +73,6 @@ describe('createGitConfigSnapshotRunner', () => {
await expect(runner(['config', '--get', 'branch.main.merge'])).rejects.toThrow(
GitConfigSnapshotKeyNotFoundError
)
expect(countCalls(runGit, ['config', '--list', '-z'])).toBe(1)
expect(
runGit.mock.calls.filter(([args]) => {
return args[0] === 'config' && args[1] === '--get'
})
).toHaveLength(0)
})
it('falls back to real config --get after snapshot fetch failure', async () => {
@@ -108,11 +90,5 @@ describe('createGitConfigSnapshotRunner', () => {
await expect(runner(['config', '--get', 'branch.main.remote'])).resolves.toEqual({
stdout: 'real:branch.main.remote'
})
await expect(runner(['config', '--get', 'branch.main.merge'])).resolves.toEqual({
stdout: 'real:branch.main.merge'
})
expect(countCalls(runGit, ['config', '--list', '-z'])).toBe(1)
expect(runGit.mock.calls.filter(([args]) => args[1] === '--get')).toHaveLength(2)
})
})
@@ -1,27 +1,14 @@
import { describe, expect, it, vi } from 'vitest'
import { resolveConfiguredGitPushTarget } from '../remotes/git-push-target-resolution'
function createRunner(config = new Map<string, string>(), snapshotFails = false) {
function createRunner(config = new Map<string, string>()) {
return vi.fn(async (args: string[]) => {
if (args[0] === 'symbolic-ref') {
return { stdout: 'refs/heads/feature\n' }
}
if (args[0] === 'config' && args[1] === '--list') {
if (snapshotFails) {
throw new Error('snapshot unavailable')
}
return { stdout: Array.from(config, ([key, value]) => `${key}\n${value}\0`).join('') }
}
if (args[0] === 'config' && args[1] === '--get') {
const value = config.get((args[2] ?? '').toLowerCase())
if (value === undefined) {
throw new Error('missing config key')
}
return { stdout: `${value}\n` }
}
if (args[0] === 'rev-parse') {
throw new Error(args.includes('HEAD@{u}') ? 'fatal: no upstream configured' : 'missing ref')
}
throw new Error(`unexpected Git command: ${args.join(' ')}`)
})
}
@@ -43,10 +30,5 @@ describe('resolution config snapshots', () => {
remote: 'other-fork',
refspec: 'HEAD:feature'
})
expect(runGit.mock.calls.filter(([args]) => args[0] === 'config')).toEqual([
[['config', '--list', '-z']],
[['config', '--list', '-z']]
])
})
})
@@ -1,15 +1,8 @@
// JSON escaping can expand controls sixfold while NUL-only sniffing treats them as text; pin each budget branch to JSON.stringify.
import { describe, expect, it } from 'vitest'
import type { GitDiffResult } from './git-diff-compare-types'
import { REMOTE_RUNTIME_MAX_OUTBOUND_JSON_BYTES } from '../../remote-runtime/remote-runtime-memory-limits'
import {
assertGitDiffWithinTransportBudget,
gitDiffExceedsTransportBudget
} from './git-diff-transport-budget'
import {
REMOTE_RPC_MAX_CONTENT_BYTES,
remoteRpcContentBudget
} from '../../remote-rpc-content-budget'
import { assertGitDiffWithinTransportBudget } from './git-diff-transport-budget'
import { REMOTE_RPC_MAX_CONTENT_BYTES } from '../../remote-rpc-content-budget'
const BUDGET = REMOTE_RPC_MAX_CONTENT_BYTES
@@ -83,41 +76,4 @@ describe('gitDiffExceedsTransportBudget', () => {
expect(referenceResultBytes(overBudget)).toBe(BUDGET + 1)
expect(budgetError(overBudget).code).toBe('diff_too_large')
})
it('rejects additive relay metadata beyond the result budget', () => {
const skewed = {
...textDiff(''),
futureMetadata: 'x'.repeat(BUDGET)
} as unknown as GitDiffResult
expect(gitDiffExceedsTransportBudget(skewed, BUDGET)).toBe(true)
expect(budgetError(skewed).code).toBe('diff_too_large')
})
})
// Why: the invariant the cap rests on — a diff that exactly fills the content budget must still
// serialize inside the outbound JSON limit once wrapped in an RPC reply. A base64-only version of
// this passes trivially; the newline and control-char fixtures are the load-bearing ones.
describe('envelope ceiling', () => {
function replyBytes(result: GitDiffResult, requestId = 'req_0123456789abcdef'): number {
return Buffer.byteLength(
JSON.stringify({
id: requestId,
ok: true,
result,
_meta: { runtimeId: '00000000-0000-4000-8000-000000000000' }
}),
'utf8'
)
}
it('charges an escape-dense request id instead of overflowing the fixed reserve', () => {
const requestId = '\u0001'.repeat(8_192)
const budget = remoteRpcContentBudget(requestId)
expect(budget).toBeLessThan(BUDGET)
expect(replyBytes(binaryDiffOfJsonBytes('a', budget), requestId)).toBeLessThanOrEqual(
REMOTE_RUNTIME_MAX_OUTBOUND_JSON_BYTES
)
})
})