diff --git a/packages/js-sdk/tests/sandbox/git/add.test.ts b/packages/js-sdk/tests/sandbox/git/add.test.ts deleted file mode 100644 index f554b0c4da..0000000000 --- a/packages/js-sdk/tests/sandbox/git/add.test.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { expect } from 'vitest' - -import { gitTest } from '../../setup.js' -import { cleanupBaseDir, createBaseDir, createRepo } from './helpers.js' - -gitTest('git add stages files', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepo(sandbox, baseDir) - await sandbox.files.write(`${repoPath}/README.md`, 'hello\n') - - await sandbox.git.add(repoPath) - - const status = await sandbox.git.status(repoPath) - const entry = status.fileStatus.find( - (file: any) => file.name === 'README.md' - ) - expect(entry?.status).toBe('added') - expect(entry?.staged).toBe(true) - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) diff --git a/packages/js-sdk/tests/sandbox/git/branches.test.ts b/packages/js-sdk/tests/sandbox/git/branches.test.ts deleted file mode 100644 index 3377331851..0000000000 --- a/packages/js-sdk/tests/sandbox/git/branches.test.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { expect } from 'vitest' - -import { gitTest } from '../../setup.js' -import { - cleanupBaseDir, - createBaseDir, - createRepoWithCommit, -} from './helpers.js' - -gitTest('git branches lists current and feature', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepoWithCommit(sandbox, baseDir) - await sandbox.commands.run(`git -C "${repoPath}" branch feature`) - - const branches = await sandbox.git.branches(repoPath) - expect(branches.currentBranch).toBe('main') - expect(branches.branches).toContain('main') - expect(branches.branches).toContain('feature') - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) - -gitTest('git checkoutBranch switches branch', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepoWithCommit(sandbox, baseDir) - await sandbox.commands.run(`git -C "${repoPath}" branch feature`) - - await sandbox.git.checkoutBranch(repoPath, 'feature') - - const head = ( - await sandbox.commands.run( - `git -C "${repoPath}" rev-parse --abbrev-ref HEAD` - ) - ).stdout.trim() - expect(head).toBe('feature') - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) - -gitTest( - 'git createBranch creates and checks out branch', - async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepoWithCommit(sandbox, baseDir) - await sandbox.git.createBranch(repoPath, 'feature') - - const branches = await sandbox.git.branches(repoPath) - expect(branches.branches).toContain('feature') - expect(branches.currentBranch).toBe('feature') - } finally { - await cleanupBaseDir(sandbox, baseDir) - } - } -) - -gitTest('git deleteBranch removes branch', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepoWithCommit(sandbox, baseDir) - await sandbox.commands.run(`git -C "${repoPath}" branch feature`) - - await sandbox.git.deleteBranch(repoPath, 'feature') - - const branch = ( - await sandbox.commands.run(`git -C "${repoPath}" branch --list feature`) - ).stdout.trim() - const branches = await sandbox.git.branches(repoPath) - expect(branch).toBe('') - expect(branches.branches).not.toContain('feature') - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) diff --git a/packages/js-sdk/tests/sandbox/git/clone.test.ts b/packages/js-sdk/tests/sandbox/git/clone.test.ts deleted file mode 100644 index f9f4a020fb..0000000000 --- a/packages/js-sdk/tests/sandbox/git/clone.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { expect } from 'vitest' - -import { gitTest } from '../../setup.js' -import { - cleanupBaseDir, - createBaseDir, - createRepoWithCommit, - startGitDaemon, -} from './helpers.js' - -gitTest('git clone fetches repo', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepoWithCommit(sandbox, baseDir) - const daemon = await startGitDaemon(sandbox, baseDir) - const clonePath = `${baseDir}/clone` - - try { - await sandbox.git.remoteAdd(repoPath, 'origin', daemon.remoteUrl) - await sandbox.git.push(repoPath, { - remote: 'origin', - branch: 'main', - }) - - await sandbox.git.clone(daemon.remoteUrl, { path: clonePath }) - const contents = await sandbox.files.read(`${clonePath}/README.md`) - expect(contents).toContain('hello') - } finally { - await daemon.handle.kill() - } - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) diff --git a/packages/js-sdk/tests/sandbox/git/commit.test.ts b/packages/js-sdk/tests/sandbox/git/commit.test.ts deleted file mode 100644 index 3e91a8944d..0000000000 --- a/packages/js-sdk/tests/sandbox/git/commit.test.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { expect } from 'vitest' - -import { gitTest } from '../../setup.js' -import { - AUTHOR_EMAIL, - AUTHOR_NAME, - cleanupBaseDir, - createBaseDir, - createRepo, -} from './helpers.js' - -gitTest('git commit creates commit', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepo(sandbox, baseDir) - await sandbox.files.write(`${repoPath}/README.md`, 'hello\n') - await sandbox.git.add(repoPath) - - await sandbox.git.commit(repoPath, 'Initial commit', { - authorName: AUTHOR_NAME, - authorEmail: AUTHOR_EMAIL, - }) - - const message = ( - await sandbox.commands.run(`git -C "${repoPath}" log -1 --pretty=%B`) - ).stdout.trim() - expect(message).toBe('Initial commit') - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) - -gitTest( - 'git commit uses config for missing author fields', - async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepo(sandbox, baseDir) - await sandbox.commands.run( - `git -C "${repoPath}" config --local user.email "${AUTHOR_EMAIL}"` - ) - - await sandbox.files.write(`${repoPath}/README.md`, 'hello\n') - await sandbox.git.add(repoPath) - - const overrideName = 'Override Bot' - await sandbox.git.commit(repoPath, 'Partial author commit', { - authorName: overrideName, - }) - - const authorName = ( - await sandbox.commands.run(`git -C "${repoPath}" log -1 --pretty=%an`) - ).stdout.trim() - const authorEmail = ( - await sandbox.commands.run(`git -C "${repoPath}" log -1 --pretty=%ae`) - ).stdout.trim() - - expect(authorName).toBe(overrideName) - expect(authorEmail).toBe(AUTHOR_EMAIL) - } finally { - await cleanupBaseDir(sandbox, baseDir) - } - } -) diff --git a/packages/js-sdk/tests/sandbox/git/config.test.ts b/packages/js-sdk/tests/sandbox/git/config.test.ts deleted file mode 100644 index b4b08bc23b..0000000000 --- a/packages/js-sdk/tests/sandbox/git/config.test.ts +++ /dev/null @@ -1,84 +0,0 @@ -import { expect } from 'vitest' - -import { gitTest } from '../../setup.js' -import { - AUTHOR_EMAIL, - AUTHOR_NAME, - cleanupBaseDir, - createBaseDir, - createRepo, -} from './helpers.js' - -gitTest('git getConfig reads local config', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepo(sandbox, baseDir) - await sandbox.commands.run( - `git -C "${repoPath}" config --local pull.rebase true` - ) - - const value = await sandbox.git.getConfig('pull.rebase', { - scope: 'local', - path: repoPath, - }) - const commandValue = ( - await sandbox.commands.run( - `git -C "${repoPath}" config --local --get pull.rebase` - ) - ).stdout.trim() - expect(value).toBe('true') - expect(commandValue).toBe('true') - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) - -gitTest('git setConfig updates local config', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepo(sandbox, baseDir) - - await sandbox.git.setConfig('pull.rebase', 'true', { - scope: 'local', - path: repoPath, - }) - - const value = ( - await sandbox.commands.run( - `git -C "${repoPath}" config --local --get pull.rebase` - ) - ).stdout.trim() - const configuredValue = await sandbox.git.getConfig('pull.rebase', { - scope: 'local', - path: repoPath, - }) - expect(value).toBe('true') - expect(configuredValue).toBe('true') - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) - -gitTest('git configureUser sets global user config', async ({ sandbox }) => { - await sandbox.git.configureUser(AUTHOR_NAME, AUTHOR_EMAIL) - - const name = ( - await sandbox.commands.run('git config --global --get user.name') - ).stdout.trim() - const email = ( - await sandbox.commands.run('git config --global --get user.email') - ).stdout.trim() - const configuredName = await sandbox.git.getConfig('user.name', { - scope: 'global', - }) - const configuredEmail = await sandbox.git.getConfig('user.email', { - scope: 'global', - }) - - expect(name).toBe(AUTHOR_NAME) - expect(email).toBe(AUTHOR_EMAIL) - expect(configuredName).toBe(AUTHOR_NAME) - expect(configuredEmail).toBe(AUTHOR_EMAIL) -}) diff --git a/packages/js-sdk/tests/sandbox/git/dangerouslyAuthenticate.test.ts b/packages/js-sdk/tests/sandbox/git/dangerouslyAuthenticate.test.ts deleted file mode 100644 index 681015bb20..0000000000 --- a/packages/js-sdk/tests/sandbox/git/dangerouslyAuthenticate.test.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { expect } from 'vitest' - -import { gitTest } from '../../setup.js' -import { HOST, PASSWORD, PROTOCOL, USERNAME } from './helpers.js' - -gitTest('git dangerouslyAuthenticate sets helper', async ({ sandbox }) => { - await sandbox.git.dangerouslyAuthenticate({ - username: USERNAME, - password: PASSWORD, - host: HOST, - protocol: PROTOCOL, - }) - - const helper = ( - await sandbox.commands.run('git config --global --get credential.helper') - ).stdout.trim() - const configuredHelper = await sandbox.git.getConfig('credential.helper', { - scope: 'global', - }) - expect(helper).toBe('store') - expect(configuredHelper).toBe('store') -}) diff --git a/packages/js-sdk/tests/sandbox/git/helpers.test.ts b/packages/js-sdk/tests/sandbox/git/helpers.test.ts deleted file mode 100644 index 0f363be2b7..0000000000 --- a/packages/js-sdk/tests/sandbox/git/helpers.test.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { describe, expect, test, vi } from 'vitest' - -import { isGitTestsEnabled } from '../../setup.js' -import { cleanupBaseDir } from './helpers.js' - -describe.skipIf(!isGitTestsEnabled)('cleanupBaseDir', () => { - test('retries a Cloudflare dropped connection once', async () => { - const run = vi - .fn() - .mockRejectedValueOnce(new Error('2: [unknown] Network connection lost.')) - .mockResolvedValueOnce(undefined) - - await cleanupBaseDir({ commands: { run } }, '/tmp/test-git/example') - - expect(run).toHaveBeenCalledTimes(2) - expect(run).toHaveBeenNthCalledWith(1, 'rm -rf "/tmp/test-git/example"') - expect(run).toHaveBeenNthCalledWith(2, 'rm -rf "/tmp/test-git/example"') - }) - - test('does not retry other cleanup failures', async () => { - const error = new Error('permission denied') - const run = vi.fn().mockRejectedValue(error) - - await expect( - cleanupBaseDir({ commands: { run } }, '/tmp/test-git/example') - ).rejects.toBe(error) - - expect(run).toHaveBeenCalledTimes(1) - }) - - test('propagates the second dropped connection after one retry', async () => { - const firstError = new Error('2: [unknown] Network connection lost.') - const secondError = new Error('2: [unknown] Network connection lost again.') - const run = vi - .fn() - .mockRejectedValueOnce(firstError) - .mockRejectedValueOnce(secondError) - - await expect( - cleanupBaseDir({ commands: { run } }, '/tmp/test-git/example') - ).rejects.toBe(secondError) - - expect(run).toHaveBeenCalledTimes(2) - }) -}) diff --git a/packages/js-sdk/tests/sandbox/git/helpers.ts b/packages/js-sdk/tests/sandbox/git/helpers.ts deleted file mode 100644 index 91ddf76c61..0000000000 --- a/packages/js-sdk/tests/sandbox/git/helpers.ts +++ /dev/null @@ -1,78 +0,0 @@ -export const AUTHOR_NAME = 'Sandbox Bot' -export const AUTHOR_EMAIL = 'sandbox@example.com' -export const USERNAME = 'git' -export const PASSWORD = 'token' -export const HOST = 'example.com' -export const PROTOCOL = 'https' - -const BASE_DIR = '/tmp/test-git' - -export async function createBaseDir(sandbox: any) { - const baseDir = `${BASE_DIR}/${crypto.randomUUID()}` - await sandbox.commands.run(`rm -rf "${baseDir}" && mkdir -p "${baseDir}"`) - return baseDir -} - -export async function cleanupBaseDir(sandbox: any, baseDir: string) { - const command = `rm -rf "${baseDir}"` - - try { - await sandbox.commands.run(command) - } catch (error) { - if ( - !(error instanceof Error) || - !error.message.includes('Network connection lost') - ) { - throw error - } - - await sandbox.commands.run(command) - } -} - -export async function createRepo(sandbox: any, baseDir: string) { - const repoPath = `${baseDir}/repo` - await sandbox.git.init(repoPath, { initialBranch: 'main' }) - return repoPath -} - -export async function createRepoWithCommit(sandbox: any, baseDir: string) { - const repoPath = await createRepo(sandbox, baseDir) - await sandbox.files.write(`${repoPath}/README.md`, 'hello\n') - await sandbox.git.add(repoPath) - await sandbox.git.commit(repoPath, 'Initial commit', { - authorName: AUTHOR_NAME, - authorEmail: AUTHOR_EMAIL, - }) - return repoPath -} - -export async function startGitDaemon(sandbox: any, baseDir: string) { - const remotePath = `${baseDir}/remote.git` - await sandbox.commands.run( - `git init --bare --initial-branch=main "${remotePath}"` - ) - const port = 9418 + Math.floor(Math.random() * 1000) - const handle = await sandbox.commands.run( - `git daemon --reuseaddr --base-path="${baseDir}" --export-all ` + - `--enable=receive-pack --informative-errors --listen=127.0.0.1 --port=${port}`, - { background: true } - ) - const remoteUrl = `git://127.0.0.1:${port}/remote.git` - - try { - await sandbox.commands.run( - `for i in $(seq 1 50); do git ls-remote "${remoteUrl}" >/dev/null 2>&1 && exit 0; sleep 0.1; done; exit 1` - ) - } catch (error) { - await handle.kill().catch(() => {}) - throw error - } - - return { - handle, - remotePath, - remoteUrl, - port, - } -} diff --git a/packages/js-sdk/tests/sandbox/git/init.test.ts b/packages/js-sdk/tests/sandbox/git/init.test.ts deleted file mode 100644 index 7d8f7baaf9..0000000000 --- a/packages/js-sdk/tests/sandbox/git/init.test.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { expect } from 'vitest' - -import { gitTest } from '../../setup.js' -import { cleanupBaseDir, createBaseDir } from './helpers.js' - -gitTest('git init', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = `${baseDir}/repo` - - await sandbox.git.init(repoPath, { initialBranch: 'main' }) - - expect(await sandbox.files.exists(`${repoPath}/.git`)).toBe(true) - const head = ( - await sandbox.commands.run( - `git -C "${repoPath}" symbolic-ref --short HEAD` - ) - ).stdout.trim() - expect(head).toBe('main') - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) diff --git a/packages/js-sdk/tests/sandbox/git/remote.test.ts b/packages/js-sdk/tests/sandbox/git/remote.test.ts deleted file mode 100644 index 38e10965c6..0000000000 --- a/packages/js-sdk/tests/sandbox/git/remote.test.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { expect } from 'vitest' - -import { gitTest } from '../../setup.js' -import { - cleanupBaseDir, - createBaseDir, - createRepo, - startGitDaemon, -} from './helpers.js' - -gitTest( - 'git remoteGet returns undefined for missing remote', - async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepo(sandbox, baseDir) - const missingUrl = await sandbox.git.remoteGet(repoPath, 'origin') - expect(missingUrl).toBeUndefined() - } finally { - await cleanupBaseDir(sandbox, baseDir) - } - } -) - -gitTest('git remoteAdd adds remote', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepo(sandbox, baseDir) - const daemon = await startGitDaemon(sandbox, baseDir) - - try { - await sandbox.git.remoteAdd(repoPath, 'origin', daemon.remoteUrl) - const remoteUrl = await sandbox.git.remoteGet(repoPath, 'origin') - expect(remoteUrl).toBe(daemon.remoteUrl) - } finally { - await daemon.handle.kill() - } - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) - -gitTest('git remoteAdd overwrites existing remote', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepo(sandbox, baseDir) - const daemon = await startGitDaemon(sandbox, baseDir) - - try { - await sandbox.git.remoteAdd(repoPath, 'origin', daemon.remoteUrl) - const currentUrl = ( - await sandbox.commands.run(`git -C "${repoPath}" remote get-url origin`) - ).stdout.trim() - const currentRemote = await sandbox.git.remoteGet(repoPath, 'origin') - expect(currentUrl).toBe(daemon.remoteUrl) - expect(currentRemote).toBe(daemon.remoteUrl) - - const secondPath = `${baseDir}/remote-2.git` - await sandbox.commands.run( - `git init --bare --initial-branch=main "${secondPath}"` - ) - const secondUrl = `git://127.0.0.1:${daemon.port}/remote-2.git` - - await sandbox.git.remoteAdd(repoPath, 'origin', secondUrl, { - overwrite: true, - }) - const updatedUrl = ( - await sandbox.commands.run(`git -C "${repoPath}" remote get-url origin`) - ).stdout.trim() - const updatedRemote = await sandbox.git.remoteGet(repoPath, 'origin') - expect(updatedUrl).toBe(secondUrl) - expect(updatedRemote).toBe(secondUrl) - } finally { - await daemon.handle.kill() - } - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) diff --git a/packages/js-sdk/tests/sandbox/git/reset.test.ts b/packages/js-sdk/tests/sandbox/git/reset.test.ts deleted file mode 100644 index 5fe1d41a92..0000000000 --- a/packages/js-sdk/tests/sandbox/git/reset.test.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { expect } from 'vitest' - -import { gitTest } from '../../setup.js' -import { - cleanupBaseDir, - createBaseDir, - createRepoWithCommit, -} from './helpers.js' - -gitTest( - 'git reset --hard discards changes', - async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepoWithCommit(sandbox, baseDir) - await sandbox.files.write(`${repoPath}/README.md`, 'changed\n') - - const status = await sandbox.git.status(repoPath) - expect(status.isClean).toBe(false) - - await sandbox.git.reset(repoPath, { mode: 'hard', target: 'HEAD' }) - - const statusAfter = await sandbox.git.status(repoPath) - expect(statusAfter.isClean).toBe(true) - - const contents = await sandbox.files.read(`${repoPath}/README.md`) - expect(contents).toBe('hello\n') - } finally { - await cleanupBaseDir(sandbox, baseDir) - } - }, - 60_000 -) diff --git a/packages/js-sdk/tests/sandbox/git/restore.test.ts b/packages/js-sdk/tests/sandbox/git/restore.test.ts deleted file mode 100644 index 67e60ad1a9..0000000000 --- a/packages/js-sdk/tests/sandbox/git/restore.test.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { expect } from 'vitest' - -import { gitTest } from '../../setup.js' -import { - cleanupBaseDir, - createBaseDir, - createRepoWithCommit, -} from './helpers.js' - -gitTest('git restore --staged unstages changes', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepoWithCommit(sandbox, baseDir) - await sandbox.files.write(`${repoPath}/README.md`, 'changed\n') - await sandbox.git.add(repoPath, { files: ['README.md'] }) - - const status = await sandbox.git.status(repoPath) - expect(status.hasStaged).toBe(true) - - await sandbox.git.restore(repoPath, { - paths: ['README.md'], - staged: true, - worktree: false, - }) - - const statusAfter = await sandbox.git.status(repoPath) - expect(statusAfter.hasStaged).toBe(false) - expect(statusAfter.hasChanges).toBe(true) - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) - -gitTest('git restore discards working tree changes', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepoWithCommit(sandbox, baseDir) - await sandbox.files.write(`${repoPath}/README.md`, 'changed\n') - - const status = await sandbox.git.status(repoPath) - expect(status.isClean).toBe(false) - - await sandbox.git.restore(repoPath, { paths: ['README.md'] }) - - const statusAfter = await sandbox.git.status(repoPath) - expect(statusAfter.isClean).toBe(true) - - const contents = await sandbox.files.read(`${repoPath}/README.md`) - expect(contents).toBe('hello\n') - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) diff --git a/packages/js-sdk/tests/sandbox/git/status.test.ts b/packages/js-sdk/tests/sandbox/git/status.test.ts deleted file mode 100644 index 009e49ce7b..0000000000 --- a/packages/js-sdk/tests/sandbox/git/status.test.ts +++ /dev/null @@ -1,99 +0,0 @@ -import { expect } from 'vitest' - -import { gitTest } from '../../setup.js' -import { - AUTHOR_EMAIL, - AUTHOR_NAME, - cleanupBaseDir, - createBaseDir, - createRepo, -} from './helpers.js' - -gitTest('git status reports untracked file', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepo(sandbox, baseDir) - await sandbox.files.write(`${repoPath}/README.md`, 'hello\n') - - const status = await sandbox.git.status(repoPath) - const entry = status.fileStatus.find( - (file: any) => file.name === 'README.md' - ) - expect(entry?.status).toBe('untracked') - expect(status.isClean).toBe(false) - expect(status.hasChanges).toBe(true) - expect(status.hasUntracked).toBe(true) - expect(status.hasStaged).toBe(false) - expect(status.hasConflicts).toBe(false) - expect(status.totalCount).toBe(1) - expect(status.stagedCount).toBe(0) - expect(status.unstagedCount).toBe(1) - expect(status.untrackedCount).toBe(1) - expect(status.conflictCount).toBe(0) - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) - -gitTest( - 'git status reports added modified deleted renamed', - async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepo(sandbox, baseDir) - await sandbox.files.write(`${repoPath}/README.md`, 'hello\n') - await sandbox.files.write(`${repoPath}/DELETE.md`, 'delete me\n') - await sandbox.files.write(`${repoPath}/RENAME.md`, 'rename me\n') - await sandbox.git.add(repoPath) - await sandbox.git.commit(repoPath, 'Initial commit', { - authorName: AUTHOR_NAME, - authorEmail: AUTHOR_EMAIL, - }) - - await sandbox.files.write(`${repoPath}/README.md`, 'hello again\n') - await sandbox.files.write(`${repoPath}/NEW.md`, 'new file\n') - await sandbox.git.add(repoPath, { files: ['NEW.md'] }) - await sandbox.commands.run(`git -C "${repoPath}" rm DELETE.md`) - await sandbox.commands.run(`git -C "${repoPath}" mv RENAME.md RENAMED.md`) - - const status = await sandbox.git.status(repoPath) - - const modified = status.fileStatus.find( - (file: any) => file.name === 'README.md' - ) - const added = status.fileStatus.find( - (file: any) => file.name === 'NEW.md' - ) - const deleted = status.fileStatus.find( - (file: any) => file.name === 'DELETE.md' - ) - const renamed = status.fileStatus.find( - (file: any) => file.name === 'RENAMED.md' - ) - - expect(modified?.status).toBe('modified') - expect(modified?.staged).toBe(false) - expect(added?.status).toBe('added') - expect(added?.staged).toBe(true) - expect(deleted?.status).toBe('deleted') - expect(deleted?.staged).toBe(true) - expect(renamed?.status).toBe('renamed') - expect(renamed?.staged).toBe(true) - expect(renamed?.renamedFrom).toBe('RENAME.md') - - expect(status.hasChanges).toBe(true) - expect(status.hasStaged).toBe(true) - expect(status.hasUntracked).toBe(false) - expect(status.hasConflicts).toBe(false) - expect(status.totalCount).toBe(4) - expect(status.stagedCount).toBe(3) - expect(status.unstagedCount).toBe(1) - expect(status.untrackedCount).toBe(0) - expect(status.conflictCount).toBe(0) - } finally { - await cleanupBaseDir(sandbox, baseDir) - } - } -) diff --git a/packages/js-sdk/tests/sandbox/git/sync.test.ts b/packages/js-sdk/tests/sandbox/git/sync.test.ts deleted file mode 100644 index 9e2fe52598..0000000000 --- a/packages/js-sdk/tests/sandbox/git/sync.test.ts +++ /dev/null @@ -1,116 +0,0 @@ -import { expect } from 'vitest' - -import { gitTest } from '../../setup.js' -import { - AUTHOR_EMAIL, - AUTHOR_NAME, - cleanupBaseDir, - createBaseDir, - createRepoWithCommit, - startGitDaemon, -} from './helpers.js' - -gitTest('git push updates remote', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepoWithCommit(sandbox, baseDir) - const daemon = await startGitDaemon(sandbox, baseDir) - - try { - await sandbox.git.remoteAdd(repoPath, 'origin', daemon.remoteUrl) - await sandbox.git.push(repoPath, { - remote: 'origin', - branch: 'main', - }) - - const message = ( - await sandbox.commands.run( - `git --git-dir="${daemon.remotePath}" log -1 --pretty=%B` - ) - ).stdout.trim() - expect(message).toBe('Initial commit') - } finally { - await daemon.handle.kill() - } - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) - -gitTest('git push warns when no upstream', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepoWithCommit(sandbox, baseDir) - const daemon = await startGitDaemon(sandbox, baseDir) - - try { - await sandbox.git.remoteAdd(repoPath, 'origin', daemon.remoteUrl) - - await expect( - sandbox.git.push(repoPath, { setUpstream: false }) - ).rejects.toThrow(/no upstream branch is configured/i) - } finally { - await daemon.handle.kill() - } - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) - -gitTest('git pull updates clone', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepoWithCommit(sandbox, baseDir) - const daemon = await startGitDaemon(sandbox, baseDir) - const clonePath = `${baseDir}/clone` - - try { - await sandbox.git.remoteAdd(repoPath, 'origin', daemon.remoteUrl) - await sandbox.git.push(repoPath, { - remote: 'origin', - branch: 'main', - }) - await sandbox.git.clone(daemon.remoteUrl, { path: clonePath }) - - await sandbox.files.write(`${repoPath}/README.md`, 'hello\nmore\n') - await sandbox.git.add(repoPath) - await sandbox.git.commit(repoPath, 'Update README', { - authorName: AUTHOR_NAME, - authorEmail: AUTHOR_EMAIL, - }) - await sandbox.git.push(repoPath) - - await sandbox.git.pull(clonePath) - const contents = await sandbox.files.read(`${clonePath}/README.md`) - expect(contents).toContain('more') - } finally { - await daemon.handle.kill() - } - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) - -gitTest('git pull warns when no upstream', async ({ sandbox }) => { - const baseDir = await createBaseDir(sandbox) - - try { - const repoPath = await createRepoWithCommit(sandbox, baseDir) - const daemon = await startGitDaemon(sandbox, baseDir) - - try { - await sandbox.git.remoteAdd(repoPath, 'origin', daemon.remoteUrl) - - await expect(sandbox.git.pull(repoPath)).rejects.toThrow( - /no upstream branch is configured/i - ) - } finally { - await daemon.handle.kill() - } - } finally { - await cleanupBaseDir(sandbox, baseDir) - } -}) diff --git a/packages/js-sdk/tests/sandbox/git/validation.test.ts b/packages/js-sdk/tests/sandbox/git/validation.test.ts deleted file mode 100644 index 3d425b8fcc..0000000000 --- a/packages/js-sdk/tests/sandbox/git/validation.test.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { test as base, expect } from 'vitest' - -import { isGitTestsEnabled } from '../../setup.js' -import { Git } from '../../../src/sandbox/git' -import type { Commands } from '../../../src/sandbox/commands' -import { InvalidArgumentError } from '../../../src/errors' - -// Stub command runner that fails if a git command is actually executed — -// validation must throw before reaching it. -const failingCommands = { - run: () => { - throw new Error('commands.run should not be called') - }, -} as unknown as Commands - -const test = base.skipIf(!isGitTestsEnabled) - -test('git.reset throws InvalidArgumentError on an invalid mode', async () => { - const git = new Git(failingCommands) - await expect( - // @ts-expect-error - testing runtime validation with an invalid mode - git.reset('/repo', { mode: 'bogus' }) - ).rejects.toThrow(InvalidArgumentError) -}) - -test('git.reset accepts a valid mode', async () => { - const git = new Git(failingCommands) - // A valid mode must pass validation and reach the (stubbed) command runner. - await expect(git.reset('/repo', { mode: 'hard' })).rejects.toThrow( - 'commands.run should not be called' - ) -}) - -test('git.remoteAdd throws InvalidArgumentError when name or url is missing', async () => { - const git = new Git(failingCommands) - await expect( - git.remoteAdd('/repo', '', 'https://example.com') - ).rejects.toThrow(InvalidArgumentError) - await expect(git.remoteAdd('/repo', 'origin', '')).rejects.toThrow( - InvalidArgumentError - ) -}) - -test('git.remoteGet throws InvalidArgumentError when name is missing', async () => { - const git = new Git(failingCommands) - await expect(git.remoteGet('/repo', '')).rejects.toThrow(InvalidArgumentError) -}) diff --git a/packages/js-sdk/tests/setup.ts b/packages/js-sdk/tests/setup.ts index a2c09b6c81..9323939b3f 100644 --- a/packages/js-sdk/tests/setup.ts +++ b/packages/js-sdk/tests/setup.ts @@ -146,11 +146,6 @@ export const volumeTest = base.extend({ export const isDebug = process.env.E2B_DEBUG !== undefined -/** The sandbox `git` API is deprecated; its tests only run when opted in. */ -export const isGitTestsEnabled = process.env.ENABLE_GIT_TESTS !== undefined - -export const gitTest = sandboxTest.skipIf(!isGitTestsEnabled) - /** Placeholder API key with a valid format for tests that don't hit the API. */ export const TEST_API_KEY = `e2b_${'0'.repeat(40)}` diff --git a/packages/python-sdk/tests/shared/git/conftest.py b/packages/python-sdk/tests/shared/git/conftest.py deleted file mode 100644 index c9ef484981..0000000000 --- a/packages/python-sdk/tests/shared/git/conftest.py +++ /dev/null @@ -1,88 +0,0 @@ -import os -import random -from uuid import uuid4 - -import pytest - -BASE_DIR = "/tmp/test-git" - - -@pytest.fixture(autouse=True) -def skip_unless_git_tests_enabled(): - """The sandbox `git` API is deprecated; its tests only run when opted in.""" - if os.getenv("ENABLE_GIT_TESTS") is None: - pytest.skip("skipped because ENABLE_GIT_TESTS is not set") - - -@pytest.fixture -def git_sandbox(sandbox_factory): - # Git suites can cross the old 10-second lifetime while the live backend is - # busy, which kills the sandbox in the middle of an otherwise healthy RPC. - return sandbox_factory(timeout=60) - - -@pytest.fixture -def git_author(): - return "Sandbox Bot", "sandbox@example.com" - - -@pytest.fixture -def git_credentials(): - return "git", "token", "example.com", "https" - - -@pytest.fixture -def git_base_dir(git_sandbox): - base_dir = f"{BASE_DIR}/{uuid4().hex}" - git_sandbox.commands.run(f'rm -rf "{base_dir}" && mkdir -p "{base_dir}"') - yield base_dir - git_sandbox.commands.run(f'rm -rf "{base_dir}"') - - -@pytest.fixture -def git_repo(git_sandbox, git_base_dir, git_author): - repo_path = f"{git_base_dir}/repo" - git_sandbox.git.init(repo_path, initial_branch="main") - author_name, author_email = git_author - git_sandbox.git.configure_user(author_name, author_email) - return repo_path - - -@pytest.fixture -def git_repo_with_commit(git_sandbox, git_repo, git_author): - author_name, author_email = git_author - git_sandbox.files.write(f"{git_repo}/README.md", "hello\n") - git_sandbox.git.add(git_repo, all=True) - git_sandbox.git.commit( - git_repo, - message="Initial commit", - author_name=author_name, - author_email=author_email, - ) - return git_repo - - -@pytest.fixture -def git_daemon(git_sandbox, git_base_dir): - remote_path = f"{git_base_dir}/remote.git" - git_sandbox.commands.run(f'git init --bare --initial-branch=main "{remote_path}"') - port = 9418 + random.randint(0, 1000) - cmd = ( - f'git daemon --reuseaddr --base-path="{git_base_dir}" --export-all ' - f"--enable=receive-pack --informative-errors --listen=127.0.0.1 --port={port}" - ) - handle = git_sandbox.commands.run(cmd, background=True) - remote_url = f"git://127.0.0.1:{port}/remote.git" - try: - git_sandbox.commands.run( - f'for i in $(seq 1 50); do git ls-remote "{remote_url}" >/dev/null 2>&1 ' - "&& exit 0; sleep 0.1; done; exit 1" - ) - yield { - "remote_path": remote_path, - "remote_url": remote_url, - "port": port, - "base_dir": git_base_dir, - } - finally: - handle.kill() diff --git a/packages/python-sdk/tests/shared/git/test_add.py b/packages/python-sdk/tests/shared/git/test_add.py deleted file mode 100644 index 5e549a3aed..0000000000 --- a/packages/python-sdk/tests/shared/git/test_add.py +++ /dev/null @@ -1,16 +0,0 @@ -import pytest - - -@pytest.mark.skip_debug() -def test_add_stages_files(git_sandbox, git_repo): - git_sandbox.files.write(f"{git_repo}/README.md", "hello\n") - - git_sandbox.git.add(git_repo, all=True) - - status = git_sandbox.git.status(git_repo) - entry = next( - (item for item in status.file_status if item.name == "README.md"), None - ) - assert entry is not None - assert entry.status == "added" - assert entry.staged is True diff --git a/packages/python-sdk/tests/shared/git/test_args.py b/packages/python-sdk/tests/shared/git/test_args.py deleted file mode 100644 index 81fe8b7639..0000000000 --- a/packages/python-sdk/tests/shared/git/test_args.py +++ /dev/null @@ -1,31 +0,0 @@ -import pytest - -from e2b.exceptions import InvalidArgumentException -from e2b.sandbox._git import ( - build_remote_add_args, - build_remote_get_command, - build_reset_args, -) - - -def test_build_reset_args_rejects_invalid_mode(): - with pytest.raises(InvalidArgumentException) as exc: - build_reset_args("bogus", None, None) - # Order must match the JS SDK exactly. - assert "Reset mode must be one of soft, mixed, hard, merge, keep." in str(exc.value) - - -def test_build_reset_args_accepts_valid_mode(): - assert build_reset_args("hard", "HEAD", None) == ["reset", "--hard", "HEAD"] - - -def test_build_remote_add_args_requires_name_and_url(): - with pytest.raises(InvalidArgumentException): - build_remote_add_args("", "https://example.com", False) - with pytest.raises(InvalidArgumentException): - build_remote_add_args("origin", "", False) - - -def test_build_remote_get_command_requires_name(): - with pytest.raises(InvalidArgumentException): - build_remote_get_command("/repo", "") diff --git a/packages/python-sdk/tests/shared/git/test_branches.py b/packages/python-sdk/tests/shared/git/test_branches.py deleted file mode 100644 index c2385f1fc2..0000000000 --- a/packages/python-sdk/tests/shared/git/test_branches.py +++ /dev/null @@ -1,52 +0,0 @@ -import pytest - - -@pytest.mark.skip_debug() -def test_branches_lists_current_and_feature(git_sandbox, git_repo_with_commit): - repo_path = git_repo_with_commit - - git_sandbox.commands.run(f'git -C "{repo_path}" branch feature') - - branches = git_sandbox.git.branches(repo_path) - assert branches.current_branch == "main" - assert "main" in branches.branches - assert "feature" in branches.branches - - -@pytest.mark.skip_debug() -def test_checkout_branch_switches_branch(git_sandbox, git_repo_with_commit): - repo_path = git_repo_with_commit - - git_sandbox.commands.run(f'git -C "{repo_path}" branch feature') - git_sandbox.git.checkout_branch(repo_path, "feature") - - head = git_sandbox.commands.run( - f'git -C "{repo_path}" rev-parse --abbrev-ref HEAD' - ).stdout.strip() - assert head == "feature" - - -@pytest.mark.skip_debug() -def test_create_branch_creates_branch(git_sandbox, git_repo_with_commit): - repo_path = git_repo_with_commit - - git_sandbox.git.create_branch(repo_path, "feature") - - branches = git_sandbox.git.branches(repo_path) - assert "feature" in branches.branches - assert branches.current_branch == "feature" - - -@pytest.mark.skip_debug() -def test_delete_branch_removes_branch(git_sandbox, git_repo_with_commit): - repo_path = git_repo_with_commit - - git_sandbox.commands.run(f'git -C "{repo_path}" branch feature') - git_sandbox.git.delete_branch(repo_path, "feature") - - branch = git_sandbox.commands.run( - f'git -C "{repo_path}" branch --list feature' - ).stdout.strip() - branches = git_sandbox.git.branches(repo_path) - assert branch == "" - assert "feature" not in branches.branches diff --git a/packages/python-sdk/tests/shared/git/test_clone.py b/packages/python-sdk/tests/shared/git/test_clone.py deleted file mode 100644 index 9281319071..0000000000 --- a/packages/python-sdk/tests/shared/git/test_clone.py +++ /dev/null @@ -1,22 +0,0 @@ -import pytest - - -@pytest.mark.skip_debug() -def test_clone_fetches_repo( - git_sandbox, git_repo_with_commit, git_daemon, git_base_dir -): - repo_path = git_repo_with_commit - remote_url = git_daemon["remote_url"] - clone_path = f"{git_base_dir}/clone" - - git_sandbox.git.remote_add(repo_path, "origin", remote_url) - git_sandbox.git.push( - repo_path, - remote="origin", - branch="main", - set_upstream=True, - ) - - git_sandbox.git.clone(remote_url, clone_path) - contents = git_sandbox.files.read(f"{clone_path}/README.md") - assert "hello" in contents diff --git a/packages/python-sdk/tests/shared/git/test_commit.py b/packages/python-sdk/tests/shared/git/test_commit.py deleted file mode 100644 index bead2190e7..0000000000 --- a/packages/python-sdk/tests/shared/git/test_commit.py +++ /dev/null @@ -1,46 +0,0 @@ -import pytest - - -@pytest.mark.skip_debug() -def test_commit_creates_commit(git_sandbox, git_repo, git_author): - git_sandbox.set_timeout(20) - - author_name, author_email = git_author - - git_sandbox.files.write(f"{git_repo}/README.md", "hello\n") - git_sandbox.git.add(git_repo, all=True) - git_sandbox.git.commit( - git_repo, - message="Initial commit", - author_name=author_name, - author_email=author_email, - ) - - message = git_sandbox.commands.run( - f'git -C "{git_repo}" log -1 --pretty=%B' - ).stdout.strip() - assert message == "Initial commit" - - -@pytest.mark.skip_debug() -def test_commit_uses_config_for_missing_author(git_sandbox, git_repo, git_author): - _, expected_email = git_author - - git_sandbox.files.write(f"{git_repo}/README.md", "hello\n") - git_sandbox.git.add(git_repo, all=True) - override_name = "Override Bot" - git_sandbox.git.commit( - git_repo, - message="Partial author commit", - author_name=override_name, - ) - - author_name = git_sandbox.commands.run( - f'git -C "{git_repo}" log -1 --pretty=%an' - ).stdout.strip() - logged_email = git_sandbox.commands.run( - f'git -C "{git_repo}" log -1 --pretty=%ae' - ).stdout.strip() - - assert author_name == override_name - assert logged_email == expected_email diff --git a/packages/python-sdk/tests/shared/git/test_config.py b/packages/python-sdk/tests/shared/git/test_config.py deleted file mode 100644 index af52bf77f2..0000000000 --- a/packages/python-sdk/tests/shared/git/test_config.py +++ /dev/null @@ -1,52 +0,0 @@ -import pytest - - -@pytest.mark.skip_debug() -def test_get_config_reads_local_config(git_sandbox, git_repo): - git_sandbox.commands.run(f'git -C "{git_repo}" config --local pull.rebase true') - - value = git_sandbox.git.get_config("pull.rebase", scope="local", path=git_repo) - command_value = git_sandbox.commands.run( - f'git -C "{git_repo}" config --local --get pull.rebase' - ).stdout.strip() - assert value == "true" - assert command_value == "true" - - -@pytest.mark.skip_debug() -def test_set_config_updates_local_config(git_sandbox, git_repo): - git_sandbox.git.set_config( - "pull.rebase", - "true", - scope="local", - path=git_repo, - ) - - value = git_sandbox.commands.run( - f'git -C "{git_repo}" config --local --get pull.rebase' - ).stdout.strip() - configured_value = git_sandbox.git.get_config( - "pull.rebase", scope="local", path=git_repo - ) - assert value == "true" - assert configured_value == "true" - - -@pytest.mark.skip_debug() -def test_configure_user_sets_global_config(git_sandbox, git_author): - author_name, author_email = git_author - - git_sandbox.git.configure_user(author_name, author_email) - - name = git_sandbox.commands.run( - "git config --global --get user.name" - ).stdout.strip() - email = git_sandbox.commands.run( - "git config --global --get user.email" - ).stdout.strip() - configured_name = git_sandbox.git.get_config("user.name", scope="global") - configured_email = git_sandbox.git.get_config("user.email", scope="global") - assert name == author_name - assert email == author_email - assert configured_name == author_name - assert configured_email == author_email diff --git a/packages/python-sdk/tests/shared/git/test_dangerously_authenticate.py b/packages/python-sdk/tests/shared/git/test_dangerously_authenticate.py deleted file mode 100644 index 67b44b4dfb..0000000000 --- a/packages/python-sdk/tests/shared/git/test_dangerously_authenticate.py +++ /dev/null @@ -1,20 +0,0 @@ -import pytest - - -@pytest.mark.skip_debug() -def test_dangerously_authenticate_sets_helper(git_sandbox, git_credentials): - username, password, host, protocol = git_credentials - - git_sandbox.git.dangerously_authenticate( - username, - password, - host=host, - protocol=protocol, - ) - - helper = git_sandbox.commands.run( - "git config --global --get credential.helper" - ).stdout.strip() - configured_helper = git_sandbox.git.get_config("credential.helper", scope="global") - assert helper == "store" - assert configured_helper == "store" diff --git a/packages/python-sdk/tests/shared/git/test_init.py b/packages/python-sdk/tests/shared/git/test_init.py deleted file mode 100644 index 19f5089b9b..0000000000 --- a/packages/python-sdk/tests/shared/git/test_init.py +++ /dev/null @@ -1,14 +0,0 @@ -import pytest - - -@pytest.mark.skip_debug() -def test_init_creates_repo(git_sandbox, git_base_dir): - repo_path = f"{git_base_dir}/repo" - - git_sandbox.git.init(repo_path, initial_branch="main") - - assert git_sandbox.files.exists(f"{repo_path}/.git") - head = git_sandbox.commands.run( - f'git -C "{repo_path}" symbolic-ref --short HEAD' - ).stdout.strip() - assert head == "main" diff --git a/packages/python-sdk/tests/shared/git/test_parity.py b/packages/python-sdk/tests/shared/git/test_parity.py deleted file mode 100644 index c45b8f9293..0000000000 --- a/packages/python-sdk/tests/shared/git/test_parity.py +++ /dev/null @@ -1,33 +0,0 @@ -import inspect - -from e2b.sandbox_async.git import Git as AsyncGit -from e2b.sandbox_sync.git import Git as SyncGit - - -def _public_methods(cls): - return { - name: getattr(cls, name) - for name in sorted(dir(cls)) - if not name.startswith("_") and callable(getattr(cls, name)) - } - - -def test_identical_method_signatures(): - sync = _public_methods(SyncGit) - async_ = _public_methods(AsyncGit) - - assert set(sync) == set(async_), ( - f"missing from async: {set(sync) - set(async_)}, " - f"missing from sync: {set(async_) - set(sync)}" - ) - - for name in sync: - assert inspect.signature(sync[name]) == inspect.signature(async_[name]), ( - f"{name}: sync{inspect.signature(sync[name])} " - f"!= async{inspect.signature(async_[name])}" - ) - - -def test_async_methods_are_coroutines(): - for name, method in _public_methods(AsyncGit).items(): - assert inspect.iscoroutinefunction(method), f"AsyncGit.{name} is not async" diff --git a/packages/python-sdk/tests/shared/git/test_remote.py b/packages/python-sdk/tests/shared/git/test_remote.py deleted file mode 100644 index b66f104dd3..0000000000 --- a/packages/python-sdk/tests/shared/git/test_remote.py +++ /dev/null @@ -1,44 +0,0 @@ -import pytest - - -@pytest.mark.skip_debug() -def test_remote_get_returns_none_for_missing_remote(git_sandbox, git_repo): - repo_path = git_repo - missing_url = git_sandbox.git.remote_get(repo_path, "origin") - assert missing_url is None - - -@pytest.mark.skip_debug() -def test_remote_add_adds_remote(git_sandbox, git_repo, git_daemon): - repo_path = git_repo - remote_url = git_daemon["remote_url"] - - git_sandbox.git.remote_add(repo_path, "origin", remote_url) - current_url = git_sandbox.git.remote_get(repo_path, "origin") - assert current_url == remote_url - - -@pytest.mark.skip_debug() -def test_remote_add_overwrites_existing_remote(git_sandbox, git_repo, git_daemon): - repo_path = git_repo - remote_url = git_daemon["remote_url"] - - git_sandbox.git.remote_add(repo_path, "origin", remote_url) - current_url = git_sandbox.commands.run( - f'git -C "{repo_path}" remote get-url origin' - ).stdout.strip() - current_remote = git_sandbox.git.remote_get(repo_path, "origin") - assert current_url == remote_url - assert current_remote == remote_url - - second_path = f"{git_daemon['base_dir']}/remote-2.git" - git_sandbox.commands.run(f'git init --bare --initial-branch=main "{second_path}"') - second_url = f"git://127.0.0.1:{git_daemon['port']}/remote-2.git" - git_sandbox.git.remote_add(repo_path, "origin", second_url, overwrite=True) - - updated_url = git_sandbox.commands.run( - f'git -C "{repo_path}" remote get-url origin' - ).stdout.strip() - updated_remote = git_sandbox.git.remote_get(repo_path, "origin") - assert updated_url == second_url - assert updated_remote == second_url diff --git a/packages/python-sdk/tests/shared/git/test_reset.py b/packages/python-sdk/tests/shared/git/test_reset.py deleted file mode 100644 index b216aeab0f..0000000000 --- a/packages/python-sdk/tests/shared/git/test_reset.py +++ /dev/null @@ -1,17 +0,0 @@ -import pytest - - -@pytest.mark.skip_debug() -def test_reset_hard_discards_changes(git_sandbox, git_repo_with_commit): - git_sandbox.files.write(f"{git_repo_with_commit}/README.md", "changed\n") - - status = git_sandbox.git.status(git_repo_with_commit) - assert status.is_clean is False - - git_sandbox.git.reset(git_repo_with_commit, mode="hard", target="HEAD") - - status_after = git_sandbox.git.status(git_repo_with_commit) - assert status_after.is_clean is True - - contents = git_sandbox.files.read(f"{git_repo_with_commit}/README.md") - assert contents == "hello\n" diff --git a/packages/python-sdk/tests/shared/git/test_restore.py b/packages/python-sdk/tests/shared/git/test_restore.py deleted file mode 100644 index 53dc7f2264..0000000000 --- a/packages/python-sdk/tests/shared/git/test_restore.py +++ /dev/null @@ -1,37 +0,0 @@ -import pytest - - -@pytest.mark.skip_debug() -def test_restore_unstages_changes(git_sandbox, git_repo_with_commit): - git_sandbox.files.write(f"{git_repo_with_commit}/README.md", "changed\n") - git_sandbox.git.add(git_repo_with_commit, files=["README.md"]) - - status = git_sandbox.git.status(git_repo_with_commit) - assert status.has_staged is True - - git_sandbox.git.restore( - git_repo_with_commit, - paths=["README.md"], - staged=True, - worktree=False, - ) - - status_after = git_sandbox.git.status(git_repo_with_commit) - assert status_after.has_staged is False - assert status_after.has_changes is True - - -@pytest.mark.skip_debug() -def test_restore_worktree_discards_changes(git_sandbox, git_repo_with_commit): - git_sandbox.files.write(f"{git_repo_with_commit}/README.md", "changed\n") - - status = git_sandbox.git.status(git_repo_with_commit) - assert status.is_clean is False - - git_sandbox.git.restore(git_repo_with_commit, paths=["README.md"]) - - status_after = git_sandbox.git.status(git_repo_with_commit) - assert status_after.is_clean is True - - contents = git_sandbox.files.read(f"{git_repo_with_commit}/README.md") - assert contents == "hello\n" diff --git a/packages/python-sdk/tests/shared/git/test_status.py b/packages/python-sdk/tests/shared/git/test_status.py deleted file mode 100644 index 5ac450ddfb..0000000000 --- a/packages/python-sdk/tests/shared/git/test_status.py +++ /dev/null @@ -1,88 +0,0 @@ -import pytest - - -@pytest.mark.skip_debug() -def test_status_reports_untracked_file(git_sandbox, git_repo): - git_sandbox.files.write(f"{git_repo}/README.md", "hello\n") - - status = git_sandbox.git.status(git_repo) - entry = next( - (item for item in status.file_status if item.name == "README.md"), None - ) - - assert entry is not None - assert entry.status == "untracked" - assert status.is_clean is False - assert status.has_changes is True - assert status.has_untracked is True - assert status.has_staged is False - assert status.has_conflicts is False - assert status.total_count == 1 - assert status.staged_count == 0 - assert status.unstaged_count == 1 - assert status.untracked_count == 1 - assert status.conflict_count == 0 - - -@pytest.mark.skip_debug() -def test_status_reports_added_modified_deleted_renamed( - git_sandbox, git_repo, git_author -): - author_name, author_email = git_author - - git_sandbox.files.write(f"{git_repo}/README.md", "hello\n") - git_sandbox.files.write(f"{git_repo}/DELETE.md", "delete me\n") - git_sandbox.files.write(f"{git_repo}/RENAME.md", "rename me\n") - git_sandbox.git.add(git_repo, all=True) - git_sandbox.git.commit( - git_repo, - message="Initial commit", - author_name=author_name, - author_email=author_email, - ) - - git_sandbox.files.write(f"{git_repo}/README.md", "hello again\n") - git_sandbox.files.write(f"{git_repo}/NEW.md", "new file\n") - git_sandbox.git.add(git_repo, files=["NEW.md"]) - git_sandbox.commands.run(f'git -C "{git_repo}" rm DELETE.md') - git_sandbox.commands.run(f'git -C "{git_repo}" mv RENAME.md RENAMED.md') - - status = git_sandbox.git.status(git_repo) - modified = next( - (item for item in status.file_status if item.name == "README.md"), None - ) - added = next((item for item in status.file_status if item.name == "NEW.md"), None) - deleted = next( - (item for item in status.file_status if item.name == "DELETE.md"), None - ) - renamed = next( - (item for item in status.file_status if item.name == "RENAMED.md"), - None, - ) - - assert modified is not None - assert modified.status == "modified" - assert modified.staged is False - - assert added is not None - assert added.status == "added" - assert added.staged is True - - assert deleted is not None - assert deleted.status == "deleted" - assert deleted.staged is True - - assert renamed is not None - assert renamed.status == "renamed" - assert renamed.staged is True - assert renamed.renamed_from == "RENAME.md" - - assert status.has_changes is True - assert status.has_staged is True - assert status.has_untracked is False - assert status.has_conflicts is False - assert status.total_count == 4 - assert status.staged_count == 3 - assert status.unstaged_count == 1 - assert status.untracked_count == 0 - assert status.conflict_count == 0 diff --git a/packages/python-sdk/tests/shared/git/test_sync.py b/packages/python-sdk/tests/shared/git/test_sync.py deleted file mode 100644 index 2cd591f31d..0000000000 --- a/packages/python-sdk/tests/shared/git/test_sync.py +++ /dev/null @@ -1,81 +0,0 @@ -import pytest - -from e2b.exceptions import GitUpstreamException - - -@pytest.mark.skip_debug() -def test_push_updates_remote(git_sandbox, git_repo_with_commit, git_daemon): - repo_path = git_repo_with_commit - remote_url = git_daemon["remote_url"] - - git_sandbox.git.remote_add(repo_path, "origin", remote_url) - git_sandbox.git.push( - repo_path, - remote="origin", - branch="main", - set_upstream=True, - ) - - message = git_sandbox.commands.run( - f'git --git-dir="{git_daemon["remote_path"]}" log -1 --pretty=%B' - ).stdout.strip() - assert message == "Initial commit" - - -@pytest.mark.skip_debug() -def test_push_without_upstream_warns(git_sandbox, git_repo_with_commit, git_daemon): - repo_path = git_repo_with_commit - remote_url = git_daemon["remote_url"] - - git_sandbox.git.remote_add(repo_path, "origin", remote_url) - - with pytest.raises(GitUpstreamException) as exc: - git_sandbox.git.push(repo_path, set_upstream=False) - - assert "no upstream branch is configured" in str(exc.value).lower() - - -@pytest.mark.skip_debug() -def test_pull_updates_clone( - git_sandbox, git_repo_with_commit, git_daemon, git_base_dir, git_author -): - repo_path = git_repo_with_commit - remote_url = git_daemon["remote_url"] - clone_path = f"{git_base_dir}/clone" - - git_sandbox.git.remote_add(repo_path, "origin", remote_url) - git_sandbox.git.push( - repo_path, - remote="origin", - branch="main", - set_upstream=True, - ) - git_sandbox.git.clone(remote_url, clone_path) - - git_sandbox.files.write(f"{repo_path}/README.md", "hello\nmore\n") - author_name, author_email = git_author - git_sandbox.git.add(repo_path, all=True) - git_sandbox.git.commit( - repo_path, - message="Update README", - author_name=author_name, - author_email=author_email, - ) - git_sandbox.git.push(repo_path) - - git_sandbox.git.pull(clone_path) - contents = git_sandbox.files.read(f"{clone_path}/README.md") - assert "more" in contents - - -@pytest.mark.skip_debug() -def test_pull_without_upstream_warns(git_sandbox, git_repo_with_commit, git_daemon): - repo_path = git_repo_with_commit - remote_url = git_daemon["remote_url"] - - git_sandbox.git.remote_add(repo_path, "origin", remote_url) - - with pytest.raises(GitUpstreamException) as exc: - git_sandbox.git.pull(repo_path) - - assert "no upstream branch is configured" in str(exc.value).lower()