mirror of
https://github.com/stablyai/orca.git
synced 2026-10-30 16:47:34 +00:00
test: remove duplicate search assertion and strengthen file and image coverage (#33140)
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
@@ -94,8 +94,11 @@ it.skipIf(process.platform === 'win32')(
|
||||
cwd: directory
|
||||
})
|
||||
expect(execute().code).toBe(0)
|
||||
writeFileSync(join(bundleDir, 'index.html'), 'corrupt')
|
||||
expect(execute().code).not.toBe(0)
|
||||
const indexPath = join(bundleDir, 'index.html')
|
||||
writeFileSync(indexPath, 'x'.repeat(readFileSync(indexPath).length))
|
||||
const corrupted = execute()
|
||||
expect(corrupted.code).not.toBe(0)
|
||||
expect(corrupted.stderr).toContain('hashes to')
|
||||
} finally {
|
||||
rmSync(directory, { recursive: true, force: true })
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { existsSync, readFileSync, realpathSync } from 'node:fs'
|
||||
import { createRequire } from 'node:module'
|
||||
import { join } from 'node:path'
|
||||
import { pathToFileURL } from 'node:url'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { parse } from 'yaml'
|
||||
import { z } from 'zod'
|
||||
@@ -67,7 +68,13 @@ describe('undeclared dependency resolution', () => {
|
||||
}
|
||||
)
|
||||
|
||||
it('aliases the DOM-free decode-named-character-reference entry', () => {
|
||||
expect(markdownParserAliases['decode-named-character-reference']).toMatch(/[\\/]index\.js$/)
|
||||
it('decodes named references through the DOM-free parser alias', async () => {
|
||||
const decoder = await import(
|
||||
pathToFileURL(markdownParserAliases['decode-named-character-reference']).href
|
||||
)
|
||||
expect(typeof decoder.decodeNamedCharacterReference).toBe('function')
|
||||
expect(decoder.decodeNamedCharacterReference('amp')).toBe('&')
|
||||
expect(decoder.decodeNamedCharacterReference('NotEqualTilde')).toBe('≂̸')
|
||||
expect(decoder.decodeNamedCharacterReference('not-an-entity')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { AppendImageUploadChunk } from '../../../src/shared/rpc-contract/clipboard-params'
|
||||
import {
|
||||
buildMobileImagePastePayload,
|
||||
buildMobileTerminalImagePastePayload,
|
||||
@@ -63,6 +64,12 @@ describe('mobile clipboard image paste helpers', () => {
|
||||
})
|
||||
).resolves.toBe('/tmp/orca-paste-image.png')
|
||||
|
||||
for (const call of client.calls) {
|
||||
if (call.method === 'clipboard.appendImageUploadChunk') {
|
||||
expect(AppendImageUploadChunk.safeParse(call.params).success).toBe(true)
|
||||
}
|
||||
}
|
||||
|
||||
expect(client.calls).toEqual([
|
||||
{
|
||||
method: 'clipboard.startImageUpload',
|
||||
|
||||
@@ -30,7 +30,7 @@ describe('attachMobileImageToTerminal', () => {
|
||||
async (agent) => {
|
||||
const client = clientWithResponses([
|
||||
ok('start', { uploadId: 'upload-1' }),
|
||||
ok('append', { received: 4 }),
|
||||
ok('append', { receivedBase64Length: 4 }),
|
||||
ok('commit', '/tmp/codex-shot.png'),
|
||||
ok('send', { send: { accepted: true } })
|
||||
])
|
||||
@@ -128,7 +128,7 @@ describe('attachMobileImageToTerminal', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('passes the active worktree connectionId to the upload', async () => {
|
||||
it('uploads the selected image bytes with the active worktree connectionId', async () => {
|
||||
const client = clientWithResponses([
|
||||
{
|
||||
id: 'start',
|
||||
@@ -150,7 +150,7 @@ describe('attachMobileImageToTerminal', () => {
|
||||
})
|
||||
|
||||
const saveCall = client.calls.find((c) => c.method === 'clipboard.saveImageAsTempFile')
|
||||
expect(saveCall?.params).toMatchObject({ connectionId: 'conn-ssh' })
|
||||
expect(saveCall?.params).toEqual({ contentBase64: 'BBBB', connectionId: 'conn-ssh' })
|
||||
})
|
||||
|
||||
it('does nothing and returns false when the picker is cancelled', async () => {
|
||||
|
||||
@@ -120,10 +120,10 @@ describe('pickMobileImage', () => {
|
||||
})
|
||||
)
|
||||
|
||||
expect(result.map((image) => image.uri)).toEqual([
|
||||
'file:///a.jpg',
|
||||
'file:///b.jpg',
|
||||
'file:///c.jpg'
|
||||
expect(result).toEqual([
|
||||
{ uri: 'file:///a.jpg', base64: 'AQ==' },
|
||||
{ uri: 'file:///b.jpg', base64: 'Ag==' },
|
||||
{ uri: 'file:///c.jpg', base64: 'Aw==' }
|
||||
])
|
||||
expect(launchLibrary).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
|
||||
@@ -132,13 +132,13 @@ describe('CSV range routing', () => {
|
||||
await expect(readRuntimeFileRange(localArgs, -1, 3)).rejects.toThrow('position')
|
||||
await expect(readRuntimeFileRange(localArgs, 0, 256 * 1024 + 1)).rejects.toThrow('limit')
|
||||
expect(fsReadFileChunk).not.toHaveBeenCalled()
|
||||
for (const result of [
|
||||
{ contentBase64: '', bytesRead: 0 },
|
||||
{ contentBase64: 'YWJj', bytesRead: 2 },
|
||||
{ contentBase64: 'YWJj', bytesRead: 3 }
|
||||
for (const { result, length } of [
|
||||
{ result: { contentBase64: '', bytesRead: 0 }, length: 2 },
|
||||
{ result: { contentBase64: 'YWJj', bytesRead: 2 }, length: 3 },
|
||||
{ result: { contentBase64: 'YWJj', bytesRead: 3 }, length: 2 }
|
||||
]) {
|
||||
fsReadFileChunk.mockResolvedValue(result)
|
||||
await expect(readRuntimeFileRange(localArgs, 0, 2)).rejects.toThrow('invalid CSV chunk')
|
||||
await expect(readRuntimeFileRange(localArgs, 0, length)).rejects.toThrow('invalid CSV chunk')
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -156,7 +156,10 @@ describe('CSV file admission', () => {
|
||||
it('keeps small files editable and preserves existing dirty drafts', async () => {
|
||||
fsStat.mockResolvedValue({ ...snapshot, size: CSV_PAGED_PREVIEW_BYTES - 1 })
|
||||
fsReadFile.mockResolvedValue({ content: 'a,b\n1,2', isBinary: false })
|
||||
expect((await readEditorCsvFileContent(localArgs)).csvPreview).toBeUndefined()
|
||||
expect(await readEditorCsvFileContent(localArgs)).toEqual({
|
||||
content: 'a,b\n1,2',
|
||||
isBinary: false
|
||||
})
|
||||
fsStat.mockClear()
|
||||
await readEditorCsvFileContent(localArgs, false)
|
||||
expect(fsStat).not.toHaveBeenCalled()
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
createEmptyRuntimeFileSearchResult,
|
||||
getRuntimeFileSearchRejectedField,
|
||||
isRuntimeFileSearchTextWithinLimit
|
||||
} from './runtime-file-search-bounds'
|
||||
@@ -26,11 +25,4 @@ describe('runtime file search bounds', () => {
|
||||
})
|
||||
).toBe('query')
|
||||
})
|
||||
|
||||
it('returns metadata-only empty results for rejected searches', () => {
|
||||
const result = createEmptyRuntimeFileSearchResult()
|
||||
|
||||
expect(result).toEqual({ files: [], totalMatches: 0, truncated: false })
|
||||
expect(JSON.stringify(result)).not.toContain('secret')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -59,6 +59,12 @@ it('old paired host retains scalar stats on that runtime and does not call the n
|
||||
([args]) => args.method === 'files.stat' && args.selector === 'owner-a'
|
||||
)
|
||||
).toBe(true)
|
||||
expect(runtimeEnvironmentCall.mock.calls.map(([args]) => args.params)).toEqual(
|
||||
paths.map((path) => ({
|
||||
worktree: 'id:folder-1',
|
||||
relativePath: path.slice('/folder/'.length)
|
||||
}))
|
||||
)
|
||||
expect(fsPathExists).not.toHaveBeenCalled()
|
||||
})
|
||||
it('new method missing after capability discovery falls back only for method_not_found', async () => {
|
||||
|
||||
@@ -167,29 +167,57 @@ describe('reading a failure fact', () => {
|
||||
|
||||
describe('reading all of a failure fact', () => {
|
||||
it('reads every part of a fact the host built, as it arrives off the wire', () => {
|
||||
for (const fact of [
|
||||
agentSessionFailureFact('startFailed', {
|
||||
refusal: { code: 'agent_session_conflict', details: { reason: 'claimConflicted' } }
|
||||
}),
|
||||
agentSessionFailureFact('providerRejected', {
|
||||
detail: providerDiagnostic('Image type .bmp', 'person')
|
||||
}),
|
||||
agentSessionFailureFact('attachmentInvalid', {
|
||||
attachment: { reason: 'tooLarge', limit: 5 * 1024 * 1024 }
|
||||
}),
|
||||
agentSessionFailureFact('providerRetrying', {
|
||||
retry: readProviderRetry({ error: 'rate_limit', status: 429 })
|
||||
}),
|
||||
agentSessionFailureFact('providerRetrying', {
|
||||
retry: readProviderRetry({
|
||||
error: 'server_error',
|
||||
status: 502,
|
||||
attempt: 3,
|
||||
maxRetries: 10
|
||||
})
|
||||
})
|
||||
for (const { fact, expected } of [
|
||||
{
|
||||
fact: agentSessionFailureFact('startFailed', {
|
||||
refusal: { code: 'agent_session_conflict', details: { reason: 'claimConflicted' } }
|
||||
}),
|
||||
expected: {
|
||||
kind: 'startFailed',
|
||||
refusal: { code: 'agent_session_conflict', details: { reason: 'claimConflicted' } }
|
||||
}
|
||||
},
|
||||
{
|
||||
fact: agentSessionFailureFact('providerRejected', {
|
||||
detail: providerDiagnostic('Image type .bmp', 'person')
|
||||
}),
|
||||
expected: {
|
||||
kind: 'providerRejected',
|
||||
detail: { text: 'Image type .bmp', audience: 'person' }
|
||||
}
|
||||
},
|
||||
{
|
||||
fact: agentSessionFailureFact('attachmentInvalid', {
|
||||
attachment: { reason: 'tooLarge', limit: 5 * 1024 * 1024 }
|
||||
}),
|
||||
expected: {
|
||||
kind: 'attachmentInvalid',
|
||||
attachment: { reason: 'tooLarge', limit: 5 * 1024 * 1024 }
|
||||
}
|
||||
},
|
||||
{
|
||||
fact: agentSessionFailureFact('providerRetrying', {
|
||||
retry: readProviderRetry({ error: 'rate_limit', status: 429 })
|
||||
}),
|
||||
expected: { kind: 'providerRetrying', retry: { error: 'rate_limit', status: 429 } }
|
||||
},
|
||||
{
|
||||
fact: agentSessionFailureFact('providerRetrying', {
|
||||
retry: readProviderRetry({
|
||||
error: 'server_error',
|
||||
status: 502,
|
||||
attempt: 3,
|
||||
maxRetries: 10
|
||||
})
|
||||
}),
|
||||
expected: {
|
||||
kind: 'providerRetrying',
|
||||
retry: { error: 'server_error', status: 502, attempt: 3, maxRetries: 10 }
|
||||
}
|
||||
}
|
||||
]) {
|
||||
expect(readWholeAgentSessionFailureFact(JSON.parse(JSON.stringify(fact)))).toEqual(fact)
|
||||
expect(fact).toEqual(expected)
|
||||
expect(readWholeAgentSessionFailureFact(JSON.parse(JSON.stringify(fact)))).toEqual(expected)
|
||||
}
|
||||
// Every reason a refusal can name, on the code that names it.
|
||||
for (const [code, reasons] of Object.entries(AGENT_SESSION_REFUSAL_REASONS)) {
|
||||
|
||||
Reference in New Issue
Block a user