From 404ab9fccfac51eae6db56248648c11f11066d7c Mon Sep 17 00:00:00 2001 From: OrcaWin Date: Fri, 13 Nov 2026 02:50:19 -0800 Subject: [PATCH] test: remove upstream projections and duplicate submodule guard (#41974) Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com> --- .../scripts/ci/sharding/ci-shard-timings.json | 1 - .../submodules/status-submodule.test.ts | 33 ------------- .../upstream/status-upstream-ref.test.ts | 43 ----------------- .../source-control/upstream/upstream.test.ts | 34 ------------- .../git-config-snapshot-runner.test.ts | 24 ---------- .../git-resolution-config-snapshot.test.ts | 20 +------- .../diff/git-diff-transport-budget.test.ts | 48 +------------------ 7 files changed, 3 insertions(+), 200 deletions(-) delete mode 100644 src/main/git/source-control/upstream/upstream.test.ts diff --git a/config/scripts/ci/sharding/ci-shard-timings.json b/config/scripts/ci/sharding/ci-shard-timings.json index 282a02f98c0..fcbafaeab0f 100644 --- a/config/scripts/ci/sharding/ci-shard-timings.json +++ b/config/scripts/ci/sharding/ci-shard-timings.json @@ -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, diff --git a/src/main/git/source-control/submodules/status-submodule.test.ts b/src/main/git/source-control/submodules/status-submodule.test.ts index 8dd28c57de6..47d29365545 100644 --- a/src/main/git/source-control/submodules/status-submodule.test.ts +++ b/src/main/git/source-control/submodules/status-submodule.test.ts @@ -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') - }) }) diff --git a/src/main/git/source-control/upstream/status-upstream-ref.test.ts b/src/main/git/source-control/upstream/status-upstream-ref.test.ts index 85071b37cc0..5b4b05dcc34 100644 --- a/src/main/git/source-control/upstream/status-upstream-ref.test.ts +++ b/src/main/git/source-control/upstream/status-upstream-ref.test.ts @@ -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() diff --git a/src/main/git/source-control/upstream/upstream.test.ts b/src/main/git/source-control/upstream/upstream.test.ts deleted file mode 100644 index 2f7ec01d798..00000000000 --- a/src/main/git/source-control/upstream/upstream.test.ts +++ /dev/null @@ -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>()), - 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') - }) -}) diff --git a/src/shared/git/commands/git-config-snapshot-runner.test.ts b/src/shared/git/commands/git-config-snapshot-runner.test.ts index ef8ecf687a4..707f73353b2 100644 --- a/src/shared/git/commands/git-config-snapshot-runner.test.ts +++ b/src/shared/git/commands/git-config-snapshot-runner.test.ts @@ -10,17 +10,6 @@ function listSnapshot(records: string[]): string { type GitCommandRunner = Parameters[0] -function countCalls( - runGit: ReturnType>, - 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(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(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) }) }) diff --git a/src/shared/git/compatibility/git-resolution-config-snapshot.test.ts b/src/shared/git/compatibility/git-resolution-config-snapshot.test.ts index fd433f1ddd3..61dae350b3d 100644 --- a/src/shared/git/compatibility/git-resolution-config-snapshot.test.ts +++ b/src/shared/git/compatibility/git-resolution-config-snapshot.test.ts @@ -1,27 +1,14 @@ import { describe, expect, it, vi } from 'vitest' import { resolveConfiguredGitPushTarget } from '../remotes/git-push-target-resolution' -function createRunner(config = new Map(), snapshotFails = false) { +function createRunner(config = new Map()) { 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']] - ]) }) }) diff --git a/src/shared/git/diff/git-diff-transport-budget.test.ts b/src/shared/git/diff/git-diff-transport-budget.test.ts index 6ff43690fa1..29c4b980be2 100644 --- a/src/shared/git/diff/git-diff-transport-budget.test.ts +++ b/src/shared/git/diff/git-diff-transport-budget.test.ts @@ -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 - ) - }) })