test: remove workflow string checks and strengthen provider assertions (#33017)

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-10-23 20:17:20 -07:00
committed by GitHub
co-authored by OrcaWin
parent cedce2aa9f
commit 4d22306d25
7 changed files with 131 additions and 79 deletions
@@ -65,7 +65,14 @@ describe('Codex child names from provider metadata', () => {
it('recovers a child first seen in a tool hook and retries metadata that was not yet written', () => {
const { writeMeta, post } = fixture()
expect(post('PostToolUse')?.[0]?.description).toBeUndefined()
expect(post('PostToolUse')).toEqual([
expect.objectContaining({
id: 'child',
agentType: 'default',
description: undefined,
state: 'working'
})
])
writeMeta({ agent_path: '/root/review/mobile' })
expect(post('PostToolUse')?.[0]?.description).toBe('mobile')
})
@@ -1,4 +1,5 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { createHash } from 'node:crypto'
import { mkdtempSync, rmSync, statSync, writeFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
@@ -18,6 +19,7 @@ describe('shared agent-hook-listener', () => {
})
afterEach(() => {
vi.restoreAllMocks()
clearGrokSessionPathLookupCacheForTests()
vi.unstubAllEnvs()
})
@@ -422,7 +424,10 @@ describe('shared agent-hook-listener', () => {
'production'
)
expect(tool?.payload.prompt.startsWith('pasted prompt WWW')).toBe(true)
expect(tool?.payload.prompt).toBe(promptText.slice(0, 200))
expect(tool?.promptInteractionKey?.split('-')[5]).toBe(
createHash('sha256').update(promptText).digest('hex').slice(0, 12)
)
} finally {
rmSync(tmpDir, { recursive: true, force: true })
}
@@ -466,7 +471,24 @@ describe('shared agent-hook-listener', () => {
'production'
)
expect(tool?.payload.prompt ?? '').toBe('')
expect(tool?.payload).toMatchObject({
state: 'working',
agentType: 'command-code',
prompt: '',
toolName: 'shell_command',
toolInput: 'pwd'
})
writeFileSync(transcriptPath, `${lines[0]}\n`, { flag: 'a' })
const recent = normalizeHookPayload(
createHookListenerState(),
'command-code',
{
paneKey: PANE_KEY,
payload: { hook_event_name: 'PreToolUse', transcript_path: transcriptPath }
},
'production'
)
expect(recent?.payload.prompt).toBe('ancient prompt')
} finally {
rmSync(tmpDir, { recursive: true, force: true })
}
@@ -525,7 +547,7 @@ describe('shared agent-hook-listener', () => {
const filler = Array.from({ length: 900 }, (_value, index) =>
JSON.stringify({
role: 'assistant',
content: [{ type: 'text', text: `${'f'.repeat(200)}${index}` }]
content: [{ type: 'text', text: `😀${'f'.repeat(200)}${index}` }]
})
)
const head = `${filler.join('\n')}\n`
+28 -5
View File
@@ -1,4 +1,7 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import {
createHookListenerState,
type HookListenerState
@@ -6,9 +9,6 @@ import {
import { normalizeHookPayload } from './agent-hook-listener'
import { PANE_KEY } from './agent-hook-listener-test-harness'
// Payloads below are jcode 0.87.1's own `JCODE_HOOK_PAYLOAD` objects, captured by
// pointing every `[hooks]` entry at a logging script; see
// docs/reference/jcode-hook-events.md.
function ingest(state: HookListenerState, payload: Record<string, unknown>) {
return normalizeHookPayload(
state,
@@ -20,13 +20,17 @@ function ingest(state: HookListenerState, payload: Record<string, unknown>) {
describe('shared agent-hook-listener: jcode', () => {
let state: HookListenerState
let jcodeHome: string
beforeEach(() => {
jcodeHome = mkdtempSync(join(tmpdir(), 'orca-jcode-hooks-'))
vi.stubEnv('JCODE_HOME', jcodeHome)
state = createHookListenerState()
})
afterEach(() => {
vi.unstubAllEnvs()
rmSync(jcodeHome, { recursive: true, force: true })
})
it('maps turn_start to working before any tool has run', () => {
@@ -104,11 +108,20 @@ describe('shared agent-hook-listener: jcode', () => {
toolName: 'request_permission'
})
expect(JSON.parse(event?.payload?.interactivePrompt ?? '{}')).toMatchObject({
action: 'delete the staging bucket'
action: 'delete the staging bucket',
reason: 'Why this needs approval'
})
})
it('does not re-open a question on post_tool, which fires after the answer', () => {
const pending = ingest(state, {
event: 'pre_tool',
session_id: 'session_jc_2',
tool_name: 'request_permission',
tool_input: '{"action":"delete the staging bucket","reason":"Why this needs approval"}'
})
expect(pending?.payload.state).toBe('waiting')
expect(pending?.payload.interactivePrompt).toBeDefined()
const event = ingest(state, {
event: 'post_tool',
session_id: 'session_jc_2',
@@ -116,6 +129,7 @@ describe('shared agent-hook-listener: jcode', () => {
status: 'ok'
})
expect(event?.payload).toMatchObject({ state: 'working' })
expect(event?.payload.interactivePrompt).toBeUndefined()
})
it('leaves unrelated tool names working even when they read like a question', () => {
@@ -145,6 +159,13 @@ describe('shared agent-hook-listener: jcode', () => {
})
it('surfaces the turn error instead of a stale reply when a turn fails', () => {
const previous = ingest(state, {
event: 'turn_end',
session_id: 'session_jc_3',
status: 'ok',
last_assistant_text: 'Stale reply.'
})
expect(previous?.payload.lastAssistantMessage).toBe('Stale reply.')
const event = ingest(state, {
event: 'turn_end',
session_id: 'session_jc_3',
@@ -184,12 +205,13 @@ describe('shared agent-hook-listener: jcode', () => {
})
it('clears the previous turn tool when a new turn starts', () => {
ingest(state, {
const previous = ingest(state, {
event: 'pre_tool',
session_id: 'session_jc_4',
tool_name: 'bash',
tool_input: '{"command":"pnpm lint"}'
})
expect(previous?.payload).toMatchObject({ toolName: 'bash', toolInput: 'pnpm lint' })
const event = ingest(state, {
event: 'turn_start',
session_id: 'session_jc_4',
@@ -209,6 +231,7 @@ describe('shared agent-hook-listener: jcode', () => {
})
expect(event?.payload).toMatchObject({ agentType: 'jcode', state: 'done' })
expect(event?.providerSession).toEqual({ key: 'session_id', id: 'session_jc_5' })
expect(event?.providerSessionOnly).toBe(true)
})
it('reads the lifecycle point from jcode\u2019s own `event` key', () => {
@@ -35,7 +35,7 @@ describe('OMP plan review status', () => {
state = createHookListenerState()
})
it('blocks on the review with a plan card whose choices reach the extension', () => {
it('blocks on the review with a parsed plan card and answer choices', () => {
const blocked = requestReview(state, '# Add a greeting')
expect(blocked?.state).toBe('blocked')