test: remove hook and generation replays and cache assertions

This commit is contained in:
OrcaWin
2026-11-13 02:03:43 -08:00
parent 7f43d8aab6
commit 6ee504ad5f
11 changed files with 2 additions and 390 deletions
+1 -3
View File
@@ -20,7 +20,6 @@
5 test-no-in-test-import-actual:src/main/ssh/config/ssh-config-loader-regression.test.ts
2 test-no-in-test-import-actual:src/main/ssh/connection/ssh-connection-auth-fallback.test.ts
1 test-no-in-test-import-actual:src/main/window/file-drop/dropped-path-preparation.test.ts
2 test-no-in-test-import-actual:src/main/workspace-hooks/hooks-runner.test.ts
1 test-no-in-test-import-actual:src/main/workspaces/removal/local-worktree-removal-recovery.test.ts
1 test-no-in-test-import-actual:src/renderer/src/components/terminal-pane/pty-connection/notifications/pty-connection-hook-idle-arbitration.test.ts
3 test-no-in-test-import-actual:src/renderer/src/components/terminal-pane/snapshots/remote-snapshot-alt-screen-host-chain.test.ts
@@ -624,8 +623,7 @@
1 test-timeout-needs-reason:src/main/windows/windows-msys-job.win32.test.ts
2 test-timeout-needs-reason:src/main/windows/windows-pty-job.win32.test.ts
5 test-timeout-needs-reason:src/main/worker-thread-child-process/worker-thread-child-process.test.ts
1 test-timeout-needs-reason:src/main/workspace-hooks/hook-archive-timeout-observation.test.ts
2 test-timeout-needs-reason:src/main/workspace-hooks/hook-termination-real-process.test.ts
1 test-timeout-needs-reason:src/main/workspace-hooks/hook-termination-real-process.test.ts
2 test-timeout-needs-reason:src/main/workspaces/removal/local-worktree-filesystem-wsl-banner.wsl.test.ts
4 test-timeout-needs-reason:src/main/wsl/execution/wsl-runner.wsl.test.ts
4 test-timeout-needs-reason:src/packages/process-host/src/run-process.test.ts
@@ -1893,11 +1893,8 @@
"src/main/hermes/hermes-config-source-edits.test.ts": 280,
"src/main/hermes/hermes-windows-home.test.ts": 121,
"src/main/hermes/hook-service.test.ts": 589,
"src/main/workspace-hooks/hook-archive-timeout-observation.test.ts": 1103,
"src/main/workspace-hooks/hook-termination-real-process.test.ts": 3284,
"src/main/workspace-hooks/hooks-archive-exit-observation.test.ts": 339,
"src/main/workspace-hooks/hooks-orca-yaml-unc-drive.test.ts": 402,
"src/main/workspace-hooks/hooks-runner.test.ts": 314,
"src/main/filesystem/host-checkout-removal.test.ts": 52,
"src/main/filesystem/host-tree-removal-asar.electron.test.ts": 308,
"src/main/host/deferred-secret-protection-report.test.ts": 81,
@@ -3888,7 +3885,6 @@
"src/main/pty/history/terminal-history-gc.test.ts": 824,
"src/main/pty/history/terminal-history-tombstone-retry.test.ts": 715,
"src/main/text-generation/failures/agent-failure-output.test.ts": 49,
"src/main/text-generation/failures/antigravity-generation-stream.test.ts": 479,
"src/main/text-generation/execution/command-environment-process.test.ts": 1044,
"src/main/text-generation/execution/commit-message-agent-environment.test.ts": 95,
"src/main/text-generation/requests/commit-message-text-generation-branch-name.test.ts": 496,
@@ -4,7 +4,6 @@ import { tmpdir } from 'node:os'
import * as path from 'node:path'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { getBranchCompare } from './branch-compare'
import { settledBranchChangeListCache } from './branch-change-list-cache'
// Old mtimes put every input past the racy-write margin, so only stamp contents decide reuse.
const aged = new Date('2020-01-01T00:00:00Z')
@@ -67,9 +66,6 @@ describe('branch compare changed-files reuse', () => {
const counted = [{ path: 'docs/notes.txt', status: 'modified', added: 1, removed: 0 }]
const binary = [{ path: 'docs/notes.txt', status: 'modified' }]
expect((await getBranchCompare(repo, 'base')).entries).toEqual(counted)
const hitsBefore = settledBranchChangeListCache.stats().hits
expect((await getBranchCompare(repo, 'base')).entries).toEqual(counted)
expect(settledBranchChangeListCache.stats().hits).toBe(hitsBefore + 1)
await writeFile(nestedAttributes, '*.txt -diff\n')
await age(nestedAttributes)
@@ -1,5 +1,5 @@
import { execFileSync } from 'node:child_process'
import { mkdtemp, readFile, readdir, realpath, rm, utimes, writeFile } from 'node:fs/promises'
import { mkdtemp, readdir, realpath, rm, utimes, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import * as path from 'node:path'
import { afterEach, describe, expect, it } from 'vitest'
@@ -136,21 +136,6 @@ describe('getBranchCompare real refs', () => {
expect(await commitsAhead(repo)).toBe(1)
})
it('recounts after an existing loose replace ref is edited in place', async () => {
const { repo, oids } = await createChainRepo()
git(repo, ['replace', '--graft', oids.tip, oids.a])
const replaceRef = path.join(repo, '.git', 'refs', 'replace', oids.tip)
const tipOntoA = await readFile(replaceRef, 'utf8')
git(repo, ['replace', '--force', '--graft', oids.tip, oids.root])
await ageReplaceRefs(repo)
expect(await commitsAhead(repo)).toBe(1)
await writeFile(replaceRef, tipOntoA)
await utimes(path.dirname(replaceRef), aged, aged)
expect(await commitsAhead(repo)).toBe(2)
})
it('recounts after a replace ref is packed away from refs/replace', async () => {
const { repo, oids } = await createChainRepo()
expect(await commitsAhead(repo)).toBe(3)
@@ -163,20 +148,6 @@ describe('getBranchCompare real refs', () => {
expect(await commitsAhead(repo)).toBe(1)
})
it('keeps per-worktree core.useReplaceRefs answers apart', async () => {
const { repo, oids } = await createChainRepo()
git(repo, ['replace', '--graft', oids.tip, oids.root])
const linked = path.join(path.dirname(repo), `${path.basename(repo)}-linked`)
tempRoots.push(linked)
git(repo, ['worktree', 'add', '-q', '--detach', linked, oids.tip])
git(repo, ['config', 'extensions.worktreeConfig', 'true'])
git(linked, ['config', '--worktree', 'core.useReplaceRefs', 'false'])
await ageReplaceRefs(repo)
expect(await commitsAhead(repo)).toBe(1)
expect(await commitsAhead(linked)).toBe(3)
})
it('honors a custom GIT_REPLACE_REF_BASE namespace', async () => {
const { repo, oids } = await createChainRepo()
const previous = process.env.GIT_REPLACE_REF_BASE
@@ -211,9 +182,6 @@ describe('getBranchCompare real refs', () => {
execFileSync('git', ['clone', '-q', source, client])
git(client, ['fetch', source, 'refs/tags/annotated:refs/remotes/origin/tagbase'])
expect(git(client, ['branch', '-r', '--format=%(refname:short)']).split(/\r?\n/)).toContain(
'origin/tagbase'
)
const rawOid = git(client, ['rev-parse', '--verify', 'refs/remotes/origin/tagbase'])
const peeledOid = git(client, [
'rev-parse',
@@ -1,136 +0,0 @@
import { describe, expect, it, vi } from 'vitest'
import { parseAntigravityGenerationOutput } from '../../../shared/antigravity-generation-stream'
import {
generateCommitMessageFromContext,
generatePullRequestFieldsFromContext
} from '../commit-message-text-generation'
import { generatePullRequestFields } from '../requests/source-control-text-generation-requests'
import {
createMockDiscoveryChild,
withPlatform
} from '../execution/commit-message-text-generation-test-harness'
const resultEvent = (response: string, status = 'SUCCESS', error?: string): string =>
JSON.stringify({ event: 'result', result: { status, response, error } })
const context = {
branch: 'feature/large-diff',
base: 'main',
branchChangedByPreparation: false,
currentTitle: '',
currentBody: '',
currentDraft: false,
commitSummary: 'Add fixture',
changeSummary: 'A\tfixture.txt',
patch: `diff --git a/fixture.txt b/fixture.txt\n+${'x'.repeat(200_000)}`
}
const params = { agentId: 'antigravity', model: 'default' } as const
const fields = { base: 'main', title: 'Add fixture', body: 'Describe the fixture', draft: false }
describe('Antigravity generation stream', () => {
it('generates pull request fields on Windows without putting a large patch on argv', async () => {
await withPlatform('win32', async () => {
const child = createMockDiscoveryChild()
const pending = generatePullRequestFields({
context,
params,
target: { kind: 'local', cwd: 'C:\\folder-workspace' },
spawnAgent: (input) => {
if (input.args.includes('--help')) {
const probe = createMockDiscoveryChild()
probe.stdin.end.mockImplementation(() =>
queueMicrotask(() => {
probe.stdout.emit('data', Buffer.from(' --settings <path>\n'))
probe.emit('close', 0)
})
)
return probe
}
expect(input.args.join(' ').length).toBeLessThan(30_000)
expect(input.args).toContain('--input-format=stream-json')
return child
}
})
await vi.waitFor(() => expect(child.stdin.end).toHaveBeenCalled())
const input = JSON.parse(child.stdin.end.mock.calls[0]?.[0] ?? '')
expect(input.message.content[0].text).toContain('(diff truncated,')
expect(input.message.content[0].text.length).toBeGreaterThan(200_000)
child.stdout.emit('data', Buffer.from(resultEvent(JSON.stringify(fields))))
child.emit('close', 0)
await expect(pending).resolves.toMatchObject({ success: true, fields })
})
})
it('sends structured stdin and parses only the final answer across remote execution', async () => {
const result = await generatePullRequestFieldsFromContext(context, params, {
kind: 'remote',
cwd: '/folder-workspace',
missingBinaryLocation: 'remote PATH',
execute: async (plan) => {
expect(JSON.parse(plan.stdinPayload ?? '').event).toBe('user')
return {
stdout: [
JSON.stringify({ event: 'init', init: { tools: ['read_file'] } }),
JSON.stringify({ event: 'step_update', step_update: { text_delta: 'Partial' } }),
resultEvent(JSON.stringify(fields))
].join('\r\n'),
stderr: '',
exitCode: 0,
timedOut: false
}
}
})
expect(result).toMatchObject({ success: true, fields, agentLabel: 'Antigravity' })
})
it('does not treat a failed stream turn as a successful commit message when exit code is zero', async () => {
const result = await generateCommitMessageFromContext(
{ branch: 'main', stagedSummary: 'A\tfixture.txt', stagedPatch: '+fixture' },
params,
{
kind: 'remote',
cwd: '/folder-workspace',
missingBinaryLocation: 'remote PATH',
execute: async () => ({
stdout: resultEvent('Partial answer', 'ERROR', 'Model unavailable'),
stderr: '',
exitCode: 0,
timedOut: false
})
}
)
expect(result).toMatchObject({ success: false, error: 'Model unavailable' })
})
it('preserves actionable stderr when a nonzero exit has a malformed result event', async () => {
const result = await generateCommitMessageFromContext(
{ branch: 'main', stagedSummary: 'A\tfixture.txt', stagedPatch: '+fixture' },
params,
{
kind: 'remote',
cwd: '/folder-workspace',
missingBinaryLocation: 'remote PATH',
execute: async () => ({
stdout: '{"event":"result"}',
stderr: 'Not logged into Antigravity. Run agy login.',
exitCode: 1,
timedOut: false
})
}
)
expect(result).toMatchObject({ success: false })
if (result.success) {
throw new Error('Expected generation to fail')
}
expect(result.error).toContain('Not logged into Antigravity. Run agy login.')
expect(result.error).not.toContain('invalid result')
})
it.each([
'plain output',
'{"event":"result"}',
'{"event":"step_update","step_update":{"text_delta":"Partial"}}',
'{"event":"result","result":{"status":"SUCCESS","response":42}}'
])('rejects malformed or incomplete output: %s', (output) => {
expect(parseAntigravityGenerationOutput(output)).toMatchObject({ ok: false })
})
})
@@ -2,53 +2,6 @@ import { describe, expect, it } from 'vitest'
import { generateCommitMessageFromContext } from '../commit-message-text-generation'
describe('commit-message generation regressions', () => {
it('renders the complete commit policy before handing execution to the owning host', async () => {
let prompt = ''
let operation = ''
const result = await generateCommitMessageFromContext(
{
branch: 'feature/policy',
stagedSummary: 'M src/policy.ts',
stagedPatch: '+preserve host scope',
linkedIssue: 73
},
{
agentId: 'custom',
model: '',
customAgentCommand: 'agent',
commandInputTemplate:
'{basePrompt}\n\nBranch: {branch}\nFiles: {stagedFiles}\nPatch: {stagedPatch}\nIssue: {linkedIssue}'
},
{
kind: 'remote',
cwd: '/remote/repo',
missingBinaryLocation: 'remote PATH',
execute: async (plan, _cwd, _timeout, generationOperation) => {
prompt = plan.stdinPayload ?? ''
operation = generationOperation
return {
stdout: 'Preserve source-control policy\n',
stderr: '',
exitCode: 0,
timedOut: false
}
}
}
)
expect(operation).toBe('commit-message')
expect(prompt).toContain('Branch: feature/policy')
expect(prompt).toContain('Files: M src/policy.ts')
expect(prompt).toContain('Patch: +preserve host scope')
expect(prompt).toContain('Issue: 73')
expect(prompt).not.toMatch(/\{(?:branch|stagedFiles|stagedPatch|linkedIssue)\}/)
expect(result).toEqual({
success: true,
message: 'Preserve source-control policy',
agentLabel: 'agent'
})
})
it('keeps bounded diagnostic captures out of commit-message results', async () => {
const result = await generateCommitMessageFromContext(
{
@@ -1,33 +0,0 @@
import { describe, expect, it, vi } from 'vitest'
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import type { Repo } from '../../shared/repo-types'
vi.mock('./effective-hook-config', () => ({
getEffectiveHooksFromConfig: (_repo: unknown, hooks: unknown) => hooks
}))
const REPO: Repo = { id: 'r', path: '/repo', displayName: 'r', badgeColor: '#000', addedAt: 0 }
async function runArchive(script: string, timeoutMs = 400) {
const { runHook } = await import('./hooks')
const dir = mkdtempSync(join(tmpdir(), 'orca-hook-deadline-'))
writeFileSync(join(dir, 'orca.yaml'), `scripts:\n archive: |\n ${script}\n`)
try {
return await runHook('archive', dir, REPO, dir, undefined, { timeoutMs })
} finally {
rmSync(dir, { recursive: true, force: true })
}
}
// Real shells expose SIGTERM traps that exit 0 after an archive timeout (#19334).
describe.skipIf(process.platform === 'win32')('archive hook deadline', () => {
it('fails a hook that traps SIGTERM and exits zero, despite its zero exit', async () => {
const result = await runArchive("trap 'exit 0' TERM; sleep 30")
expect(result.success).toBe(false)
// Missing exitCode keeps the removal verdict unverifiable.
expect(result.exitCode).toBeUndefined()
expect(result.output).toContain('timed out')
}, 20_000)
})
@@ -49,14 +49,6 @@ async function survivorsAfterDeadline(
// Mocked kill probes cannot prove a process group exists; exercise real signals here.
describe.skipIf(process.platform === 'win32')('hook termination against real processes', () => {
it('kills the shell and its child when the deadline expires', async () => {
const { shell, child, output } = await survivorsAfterDeadline(
'echo "archive step 3 of 7"\nsleep 120 &\necho "$$ $!" > "$PWD/pids"\nwait'
)
expect({ shell, child }).toEqual({ shell: false, child: false })
expect(output).toContain('archive step 3 of 7')
}, 30_000)
it('kills a descendant that ignores SIGTERM', async () => {
// Only the group SIGKILL can end this one; a SIGTERM to the shell alone leaves it running.
const { child } = await survivorsAfterDeadline(
@@ -77,37 +77,12 @@ async function runArchiveWith(
// Real-process timeout/group tests live in hook-termination-real-process.test.ts (#19334).
describe('archive hook exit observation', () => {
it.each([
['a non-zero exit', 23],
['a shell command-not-found', 127]
])('reports %s as the observed exit it is', async (_label, code) => {
await expect(runArchiveWith({ code })).resolves.toMatchObject({
success: false,
exitCode: code
})
})
it('caps what it retains from a hook that floods stdout', async () => {
const megabyte = 'x'.repeat(1024 * 1024)
const result = await runArchiveWith(
{ code: 0 },
Array.from({ length: 12 }, () => megabyte)
)
expect(result.output.length).toBeLessThan(11 * 1024 * 1024)
expect(result.output).toContain('output truncated at 10485760 bytes')
})
it('survives an error on the output stream', async () => {
await expect(
runArchiveWith({ code: 0 }, ['partial'], new Error('EIO: read failed'))
).resolves.toMatchObject({ success: true })
})
it('names a signalled exit as one rather than reporting "exit code null"', async () => {
const result = await runArchiveWith({ code: null, signal: 'SIGKILL' })
expect(result.output).toContain('terminated without reporting an exit code')
})
it.each([
['was killed by a signal', { code: null, signal: 'SIGKILL' as const }],
// Spawn errors carry string codes; a bare Error would not exercise the numeric-code guard.
@@ -1,44 +0,0 @@
import type * as NodeFs from 'node:fs'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
const fsMock = vi.hoisted(() => ({ existsSync: vi.fn(), readFileSync: vi.fn() }))
vi.mock('node:fs', async (importOriginal) => ({
...(await importOriginal<typeof NodeFs>()),
...fsMock
}))
import { hasHooksFile, hasUnrecognizedOrcaYamlKeys, loadHooks } from './hooks'
const UNC = String.raw`\\wsl.localhost\Ubuntu\mnt\c\src\app`
const DRIVE_YAML = String.raw`C:\src\app\orca.yaml`
const originalPlatform = process.platform
describe('orca.yaml of a UNC drive-mount repo', () => {
beforeEach(() => {
Object.defineProperty(process, 'platform', { configurable: true, value: 'win32' })
// WSL 2.7 refuses Windows access to a drive mount over UNC (existsSync swallows it as false).
fsMock.existsSync.mockImplementation((path: string) => path === DRIVE_YAML)
fsMock.readFileSync.mockImplementation((path: string) => {
if (path !== DRIVE_YAML) {
throw Object.assign(new Error(`EPERM: operation not permitted, open '${path}'`), {
code: 'EPERM'
})
}
return 'scripts:\n setup: pnpm install\nfutureKey: 1\n'
})
})
afterEach(() => {
Object.defineProperty(process, 'platform', { configurable: true, value: originalPlatform })
})
it('reads the setup hooks through the drive path', () => {
expect(hasHooksFile(UNC)).toBe(true)
expect(loadHooks(UNC)?.scripts?.setup).toBe('pnpm install')
expect(hasUnrecognizedOrcaYamlKeys(UNC)).toBe(true)
expect(fsMock.readFileSync).not.toHaveBeenCalledWith(
expect.stringMatching(/^\\\\/),
expect.anything()
)
})
})
@@ -1,53 +0,0 @@
import type * as NodeChildProcess from 'node:child_process'
import type * as NodeFs from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { describe, expect, it, vi } from 'vitest'
const { execFileSyncMock, statSyncMock } = vi.hoisted(() => ({
execFileSyncMock: vi.fn(),
statSyncMock: vi.fn()
}))
vi.mock('fs', () => ({
readFileSync: vi.fn(),
statSync: statSyncMock,
existsSync: vi.fn(),
mkdirSync: vi.fn(),
writeFileSync: vi.fn(),
chmodSync: vi.fn()
}))
vi.mock('child_process', () => ({
exec: vi.fn(),
execFileSync: execFileSyncMock,
execFile: vi.fn(),
spawn: vi.fn()
}))
describe('createSetupRunnerScript', () => {
it.skipIf(process.platform === 'win32')(
'runs a script whose shebang carries invocation-only bash flags',
async () => {
// Reapplying login/interactive flags through set would abort before the first user line.
const { buildPosixRunnerScript } = await import('./setup-runner-script-text')
const { mkdtempSync, rmSync, writeFileSync } = await vi.importActual<typeof NodeFs>('node:fs')
const { execFileSync } = await vi.importActual<typeof NodeChildProcess>('node:child_process')
const dir = mkdtempSync(join(tmpdir(), 'orca-posix-runner-'))
try {
const runnerPath = join(dir, 'setup-runner.sh')
writeFileSync(
runnerPath,
buildPosixRunnerScript('#!/bin/bash -l\necho SETUP_RAN\n'),
'utf-8'
)
expect(execFileSync('bash', [runnerPath], { encoding: 'utf-8' })).toContain('SETUP_RAN')
} finally {
rmSync(dir, { recursive: true, force: true })
}
}
)
})