Merge pull request #485 from chriswritescode-dev/chore/prune-redundant-tests

Remove duplicated and constant-only tests
This commit is contained in:
Chris Scott authored and GitHub committed 2026-11-13 17:22:25 -05:00
commit eba86dc3fc
8 files changed
+17 -366

No files matched your search

+3 -7
View File
@@ -44,14 +44,10 @@ describe('session pins routes', () => {
const { pins } = await readJson(res, SessionPinListSchema)
expect(pins).toHaveLength(1)
expect(pins[0]).toMatchObject({ sessionId: 'ses_1', directory: '/w/a' })
})
it('GET / returns pins after creation', async () => {
await togglePin(app, 'ses_1', '/w/a', true)
const res = await app.request('/session-pins')
expect(res.status).toBe(200)
expect((await readJson(res, SessionPinListSchema)).pins).toHaveLength(1)
const listRes = await app.request('/session-pins')
expect(listRes.status).toBe(200)
expect((await readJson(listRes, SessionPinListSchema)).pins).toHaveLength(1)
})
it('PUT / with pinned: false removes the pin', async () => {
+9 -104
View File
@@ -33,12 +33,6 @@ const ActiveSessionsSchema = z.object({
sessions: z.array(z.object({ sessionID: z.string(), directory: z.string() })),
})
const RestartResponseSchema = z.object({
success: z.boolean(),
message: z.string().optional(),
interruptedSessions: z.array(z.string()).optional(),
})
function lifecycleStatus(): OpenCodeLifecycleStatus {
return {
state: 'healthy',
@@ -109,33 +103,8 @@ describe('settings routes — serverEnvVars', () => {
expect((await readJson(res, SettingsResponseSchema)).preferences.serverEnvVars).toEqual([])
})
it('PATCH / saves and returns serverEnvVars', async () => {
const patchRes = await app.request('/settings', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
preferences: {
serverEnvVars: [
{
key: 'OPENCODE_EXPERIMENTAL_FEATURE',
value: 'true',
},
],
},
}),
})
expect(patchRes.status).toBe(200)
expect((await readJson(patchRes, SettingsResponseSchema)).preferences.serverEnvVars).toEqual([
{
key: 'OPENCODE_EXPERIMENTAL_FEATURE',
value: 'true',
},
])
})
it('PATCH / persists serverEnvVars and returns on GET', async () => {
await app.request('/settings', {
const patchRes = await app.request('/settings', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
@@ -148,6 +117,14 @@ describe('settings routes — serverEnvVars', () => {
}),
})
expect(patchRes.status).toBe(200)
expect((await readJson(patchRes, SettingsResponseSchema)).preferences.serverEnvVars).toEqual([
{
key: 'MY_FLAG',
value: '1',
},
])
const res = await app.request('/settings')
expect((await readJson(res, SettingsResponseSchema)).preferences.serverEnvVars).toEqual([
@@ -250,52 +227,6 @@ describe('settings routes — opencode model discovery', () => {
workspace.restore()
})
it.each([
{ label: 'missing', query: '' },
{ label: 'invalid', query: '?baseUrl=not-a-url' },
{ label: 'not http/https', query: '?baseUrl=ftp://example.com' },
])('returns 400 when baseUrl is $label', async ({ query }) => {
const res = await app.request(`/settings/opencode-discover-models${query}`)
expect(res.status).toBe(400)
})
it('discovers models from the endpoint', async () => {
fetchStub.mockResolvedValueOnce(
new Response(JSON.stringify({ data: [{ id: 'gpt-4o' }, { id: 'gpt-3.5-turbo' }] }), {
status: 200,
headers: { 'Content-Type': 'application/json' },
}),
)
const res = await app.request('/settings/opencode-discover-models?baseUrl=http://localhost:1234&refresh=true')
expect(res.status).toBe(200)
const data = await readJson(res, DiscoveredModelsSchema)
expect(data.models).toEqual(['gpt-4o', 'gpt-3.5-turbo'])
expect(data.cached).toBe(false)
})
it('returns cached models on subsequent requests without re-fetching', async () => {
fetchStub.mockResolvedValueOnce(
new Response(JSON.stringify({ data: [{ id: 'llama-3' }] }), {
status: 200,
headers: { 'Content-Type': 'application/json' },
}),
)
const firstRes = await app.request('/settings/opencode-discover-models?baseUrl=http://localhost:5678&refresh=true')
const firstData = await readJson(firstRes, DiscoveredModelsSchema)
expect(firstData.models).toEqual(['llama-3'])
expect(firstData.cached).toBe(false)
const secondRes = await app.request('/settings/opencode-discover-models?baseUrl=http://localhost:5678')
const secondData = await readJson(secondRes, DiscoveredModelsSchema)
expect(secondData.models).toEqual(['llama-3'])
expect(secondData.cached).toBe(true)
expect(fetchStub).toHaveBeenCalledTimes(1)
})
it('returns empty models when endpoint is unreachable', async () => {
fetchStub.mockRejectedValue(new Error('connection refused'))
@@ -338,30 +269,4 @@ describe('settings routes — active session reporting', () => {
expect(body.count).toBe(1)
expect(body.sessions).toEqual([{ sessionID: 's1', directory: '/a' }])
})
it('GET /opencode-active-sessions returns empty when nothing is active', async () => {
stubActiveSessions({})
const app = createTestApp(db, createSettingsDeps())
const res = await app.request('/settings/opencode-active-sessions')
expect(res.status).toBe(200)
const body = await readJson(res, ActiveSessionsSchema)
expect(body.count).toBe(0)
expect(body.sessions).toEqual([])
})
it('POST /opencode-restart restarts the server without reporting interrupted sessions', async () => {
stubActiveSessions({ '/a': ['s1'] })
const restart = vi.fn<OpenCodeRestartTarget['restart']>(async () => lifecycleStatus())
const app = createTestApp(db, createSettingsDeps(), { restart })
const res = await app.request('/settings/opencode-restart', { method: 'POST' })
expect(res.status).toBe(200)
const body = await readJson(res, RestartResponseSchema)
expect(body.success).toBe(true)
expect(body.interruptedSessions).toBeUndefined()
expect(restart).toHaveBeenCalledWith('settings_restart')
})
})
+2 -2
View File
@@ -966,11 +966,11 @@ describe('Settings routes', () => {
})
describe('PATCH / validation', () => {
it.each([5, 45, 2000, 30.5])('rejects activityWindowMinutes %s', async (minutes) => {
it('rejects an activityWindowMinutes value that is not an option', async () => {
const res = await settingsApp.request('/', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ preferences: { activityWindowMinutes: minutes } }),
body: JSON.stringify({ preferences: { activityWindowMinutes: 45 } }),
})
expect(res.status).toBe(400)
+2 -152
View File
@@ -1,6 +1,6 @@
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { spawn } from 'child_process'
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'fs'
import { mkdtempSync, readFileSync, rmSync } from 'fs'
import { tmpdir } from 'os'
import { join } from 'path'
import * as http from 'http'
@@ -213,153 +213,3 @@ describe('askpass-main', () => {
})
})
const askpassEnvKeys = [
'VSCODE_GIT_ASKPASS_PIPE',
'VSCODE_GIT_ASKPASS_TYPE',
'VSCODE_GIT_IPC_HANDLE',
'OCM_GIT_REPO_ID',
'OCM_GIT_REPO_CWD',
] as const
async function runAskpassInProcess(overrides: Record<string, string | undefined>): Promise<{ code: number | undefined; output: string | undefined }> {
const nextEnv = buildEnv(overrides)
const previousEnv: Record<string, string | undefined> = {}
for (const key of askpassEnvKeys) {
previousEnv[key] = process.env[key]
const next = nextEnv[key]
if (next === undefined) {
delete process.env[key]
} else {
process.env[key] = next
}
}
let resolveExit: (code: number | undefined) => void = () => {}
const exitPromise = new Promise<number | undefined>((resolve) => {
resolveExit = resolve
})
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
const originalExit = process.exit
Object.defineProperty(process, 'exit', {
value: (code?: string | number | null) => {
const exitCode = z.number().safeParse(code)
resolveExit(exitCode.success ? exitCode.data : undefined)
},
configurable: true,
writable: true,
})
vi.resetModules()
try {
await import('../../scripts/askpass-main')
const code = await exitPromise
return { code, output: existsSync(outputPath) ? readFileSync(outputPath, 'utf-8') : undefined }
} finally {
Object.defineProperty(process, 'exit', { value: originalExit, configurable: true, writable: true })
errorSpy.mockRestore()
for (const key of askpassEnvKeys) {
const previous = previousEnv[key]
if (previous === undefined) {
delete process.env[key]
} else {
process.env[key] = previous
}
}
}
}
describe('askpass-main in-process', () => {
it('exits 1 when the askpass pipe is missing', async () => {
const result = await runAskpassInProcess({})
expect(result.code).toBe(1)
expect(result.output).toBeUndefined()
})
it('exits 1 when the askpass type is missing', async () => {
const result = await runAskpassInProcess({ VSCODE_GIT_ASKPASS_PIPE: outputPath })
expect(result.code).toBe(1)
expect(result.output).toBeUndefined()
})
it('exits 1 for an invalid askpass type', async () => {
const result = await runAskpassInProcess({ VSCODE_GIT_ASKPASS_PIPE: outputPath, VSCODE_GIT_ASKPASS_TYPE: 'ftp' })
expect(result.code).toBe(1)
expect(result.output).toBeUndefined()
})
it('writes a newline and exits 0 when no IPC handle is configured', async () => {
const result = await runAskpassInProcess({ VSCODE_GIT_ASKPASS_PIPE: outputPath, VSCODE_GIT_ASKPASS_TYPE: 'https' })
expect(result.code).toBe(0)
expect(result.output).toBe('\n')
})
it('writes the handler result and exits 0 on IPC success', async () => {
const server = await startIPCServer()
server.registerHandler('askpass', { handle: async () => 'in-process-token' })
const result = await runAskpassInProcess({
VSCODE_GIT_ASKPASS_PIPE: outputPath,
VSCODE_GIT_ASKPASS_TYPE: 'https',
VSCODE_GIT_IPC_HANDLE: server.ipcHandlePath,
})
expect(result.code).toBe(0)
expect(result.output).toBe('in-process-token\n')
})
it('writes a newline and exits 0 when the handler returns an empty body', async () => {
const server = await startIPCServer()
server.registerHandler('askpass', { handle: async () => undefined })
const result = await runAskpassInProcess({
VSCODE_GIT_ASKPASS_PIPE: outputPath,
VSCODE_GIT_ASKPASS_TYPE: 'https',
VSCODE_GIT_IPC_HANDLE: server.ipcHandlePath,
})
expect(result.code).toBe(0)
expect(result.output).toBe('\n')
})
it('writes a newline and exits 1 when the IPC server returns a non-200 status', async () => {
const server = await startIPCServer()
const result = await runAskpassInProcess({
VSCODE_GIT_ASKPASS_PIPE: outputPath,
VSCODE_GIT_ASKPASS_TYPE: 'https',
VSCODE_GIT_IPC_HANDLE: server.ipcHandlePath,
})
expect(result.code).toBe(1)
expect(result.output).toBe('\n')
})
it('writes a newline and exits 1 when the response body is not JSON', async () => {
const socketPath = join(dir, 'raw-in-process.sock')
await startRawServer(socketPath, 'not-json')
const result = await runAskpassInProcess({
VSCODE_GIT_ASKPASS_PIPE: outputPath,
VSCODE_GIT_ASKPASS_TYPE: 'https',
VSCODE_GIT_IPC_HANDLE: socketPath,
})
expect(result.code).toBe(1)
expect(result.output).toBe('\n')
})
it('writes a newline and exits 1 when the IPC connection fails', async () => {
const result = await runAskpassInProcess({
VSCODE_GIT_ASKPASS_PIPE: outputPath,
VSCODE_GIT_ASKPASS_TYPE: 'https',
VSCODE_GIT_IPC_HANDLE: join(dir, 'missing-in-process.sock'),
})
expect(result.code).toBe(1)
expect(result.output).toBe('\n')
})
})
-33
View File
@@ -1136,39 +1136,6 @@ describe('repo service real git', () => {
expect(describeAfterRun(path.join(root, 'job-999999-run-1'))).toBeUndefined()
})
it('returns repo siblings when the OpenCode client fails', async () => {
const { getSiblingRepos } = await import('../../src/services/repo')
const origin = path.join(workspaceRoot, uniqueName('sibling-err-origin.git'))
const work = path.join(workspaceRoot, uniqueName('sibling-err-work'))
createOrigin(origin, work)
const repoA = path.join(reposPath, uniqueName('sibling-err-a'))
cloneOrigin(origin, repoA)
const a = createRepo(db, {
isLocal: true,
localPath: path.basename(repoA),
sourcePath: repoA,
branch: 'main',
defaultBranch: 'main',
cloneStatus: 'ready',
clonedAt: Date.now(),
})
const client = createStubOpenCodeClient({
api: {
location: {
get: async () => {
throw new Error('upstream unavailable')
},
},
worktree: { list: async () => [] },
},
})
const siblings = await getSiblingRepos(db, a.id, {}, client)
expect(siblings.some((repo) => repo.id === a.id)).toBe(true)
expect(siblings.some((repo) => isWorktreeSibling(repo))).toBe(false)
})
it('resolves the project id with the shared resolver', async () => {
const origin = path.join(workspaceRoot, uniqueName('sibling-resolver-origin.git'))
const work = path.join(workspaceRoot, uniqueName('sibling-resolver-work'))
-35
View File
@@ -8,13 +8,11 @@ import { getReposPath } from '@opencode-manager/shared/config/env'
import type { OpenCodeClient } from '../../src/services/opencode/client'
import type { Repo } from '../../src/types/repo'
import { createScheduleRun, updateScheduleRunWorktree } from '../../src/db/schedules'
import { getRepoByLocalPath } from '../../src/db/queries'
import {
discoverLocalRepos,
getSiblingRepos,
initLocalRepo,
listRepoSiblings,
relinkReposFromSessionDirectories,
resolveRepoForDirectory,
} from '../../src/services/repo'
import { cloneOrigin, createCommittedRepo, createGitAuthService, createOrigin, git } from '../helpers/git-fixtures'
@@ -43,15 +41,6 @@ describe('repo service', () => {
workspace.restore()
})
it('creates a new empty git repo for a relative path', async () => {
const result = await initLocalRepo(db, gitAuthService, 'my-new-repo')
expect(result.cloneStatus).toBe('ready')
expect(result.fullPath).toBe(path.join(getReposPath(), 'my-new-repo'))
expect(git(['rev-parse', '--git-dir'], result.fullPath)).toBe('.git')
expect(getRepoByLocalPath(db, 'my-new-repo')?.cloneStatus).toBe('ready')
})
it('links an absolute git repo in place and preserves its source path', async () => {
const sourcePath = path.join(workspace.path, 'outside', 'existing-repo')
createCommittedRepo(sourcePath)
@@ -102,30 +91,6 @@ describe('repo service', () => {
chmodSync(restricted, 0o755)
}
})
it('relinks imported session directories to nearest git repo roots', async () => {
const repoRoot = path.join(workspace.path, 'projects', 'app-one')
const webDirectory = path.join(repoRoot, 'apps', 'web')
const apiDirectory = path.join(repoRoot, 'packages', 'api')
const nonRepoDirectory = path.join(workspace.path, 'projects', 'not-a-repo')
createCommittedRepo(repoRoot)
mkdirSync(webDirectory, { recursive: true })
mkdirSync(apiDirectory, { recursive: true })
mkdirSync(nonRepoDirectory, { recursive: true })
const result = await relinkReposFromSessionDirectories(db, gitAuthService, [
webDirectory,
apiDirectory,
nonRepoDirectory,
])
expect(result.relinkedCount).toBe(1)
expect(result.existingCount).toBe(0)
expect(result.nonRepoPathCount).toBe(1)
expect(result.duplicatePathCount).toBe(1)
expect(result.errors).toEqual([])
expect(result.repos.map((repo) => repo.fullPath)).toEqual([repoRoot])
})
})
describe('getSiblingRepos worktree API', () => {
@@ -16,9 +16,7 @@ import {
isSameOpenCodeMajor,
isStableOpenCodeVersion,
isSupportedOpenCodeVersion,
normalizeOpenCodeVersion,
openCodeLocation,
parseOpenCodeVersion,
parseOpenCodeVersionOutput,
} from '@opencode-manager/shared/opencode'
@@ -124,30 +122,12 @@ describe('OpenCode v2 contract', () => {
})
describe('version parsing', () => {
it('normalizes surrounding whitespace and a leading v', () => {
expect(normalizeOpenCodeVersion(' v2.0.15\n')).toBe('2.0.15')
expect(normalizeOpenCodeVersion('2.0.15')).toBe('2.0.15')
})
it('parses version components and prerelease identifiers', () => {
expect(parseOpenCodeVersion('v2.1.3-beta.4')).toEqual({ major: 2, minor: 1, patch: 3, prerelease: ['beta', 4] })
expect(parseOpenCodeVersion('2.1')).toBeNull()
})
it('identifies stable MAJOR.MINOR.PATCH versions', () => {
expect(isStableOpenCodeVersion('v2.0.15')).toBe(true)
expect(isStableOpenCodeVersion('2.1.0-beta.1')).toBe(false)
expect(isStableOpenCodeVersion('2.0.15; cat /etc/passwd')).toBe(false)
})
it('orders versions by semver precedence', () => {
expect(compareOpenCodeVersions('2.0.15', '2.0.14')).toBeGreaterThan(0)
expect(compareOpenCodeVersions('v2.0.15', '2.0.15')).toBe(0)
expect(compareOpenCodeVersions('2.0.9', '2.0.10')).toBeLessThan(0)
expect(compareOpenCodeVersions('2.1.0-beta.1', '2.1.0')).toBeLessThan(0)
expect(() => compareOpenCodeVersions('invalid', '2.0.15')).toThrow(/invalid/)
})
it('extracts the version from opencode --version output', () => {
expect(parseOpenCodeVersionOutput('2.0.15\n')).toBe('2.0.15')
expect(parseOpenCodeVersionOutput('opencode v2.0.15\n')).toBe('2.0.15')
+1 -13
View File
@@ -1,19 +1,7 @@
import { describe, it, expect } from 'vitest';
import { getSessionListPath, getSwipeBackTarget, getAssistantPath, getAssistantSessionListPath, isAssistantPath, getPathWithReturnTo, getReturnToPath, getRepoPath, getServerProjectPath, getServerSessionPath, getSessionPath, isSessionDetailRoute, parseActivePickerSession, parseRepoRoute, parseServerProjectRoute, parseServerSessionRoute } from './navigation';
import { getSessionListPath, getSwipeBackTarget, isAssistantPath, getPathWithReturnTo, getReturnToPath, getRepoPath, getServerProjectPath, getServerSessionPath, getSessionPath, isSessionDetailRoute, parseActivePickerSession, parseRepoRoute, parseServerProjectRoute, parseServerSessionRoute } from './navigation';
import { LOCAL_OPENCODE_SERVER_ID } from '@opencode-manager/shared/schemas';
describe('getAssistantPath', () => {
it('returns /assistant', () => {
expect(getAssistantPath()).toBe('/assistant');
});
});
describe('getAssistantSessionListPath', () => {
it('returns /assistant', () => {
expect(getAssistantSessionListPath()).toBe('/assistant');
});
});
describe('isAssistantPath', () => {
it('returns true for /assistant', () => {
expect(isAssistantPath('/assistant')).toBe(true);