Files
AirCoding/packages/runtime/test/regression/worker-result-envelope.test.ts
AirCoding ddefcbb2b1 fix: integrate audit findings round 1 - tools, worker, scheduler, main agent
- Unify ToolResultEnvelope (output vs content) for built-in tools
- Fix shell.run AsyncGenerator consumption in ToolRegistry.call/streaming
- Scheduler: consume WorkerResult.status instead of marking all running tasks completed
- WorkerProcess/WorkerManager: surface exit events and generate failed/cancelled result
- MainAgent: integrate ContextAssembler, Chinese destructive regex, ArchitectureDesigner impact gate
- run.ts: pendingConfirmation flow, dispatch extracted, .air files filtered from /results
- CapabilityRegistry wired into RuntimeApp and ServiceRegistry; DoctorService uses it
- release.ts: findRepoRoot/findBun, run air e2e + depcruise + runtime regression
- New gates: release-critical-gates, CLI run command regression
- 14/14 e2e gates pass; 3/3 release dry-run pass

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-05 18:39:10 +08:00

61 lines
2.2 KiB
TypeScript
Executable File

/**
* D3 regression: Worker result WorkerResult<T> envelope
* Validates that WorkerManager has the result field on WorkerHandle,
* wrap_worker_result and get_result methods, and imports WorkerResult
* from contracts.
*
* Uses source inspection (reading the source file as text).
*/
import { describe, it, expect } from 'bun:test'
import { readFileSync } from 'fs'
import { join } from 'path'
const source_path = join(import.meta.dir, '../../src/workers/WorkerManager.ts')
const source = readFileSync(source_path, 'utf-8')
describe('D3: Worker result envelope', () => {
it('WorkerHandle has result field', () => {
expect(source).toContain('result?: WorkerResult<unknown>')
})
it('wrap_worker_result method exists', () => {
expect(source).toContain('wrap_worker_result(')
// Should be a private method
expect(source).toContain('private wrap_worker_result')
})
it('get_result method exists', () => {
expect(source).toContain('get_result(agent_id: string)')
// Should return WorkerResult<unknown> | undefined
expect(source).toContain('WorkerResult<unknown> | undefined')
})
it('imports WorkerResult from contracts', () => {
expect(source).toContain("import type { WorkerResult")
expect(source).toContain("from '@aircoding/contracts'")
})
it('imports WorkerStatus from contracts', () => {
expect(source).toContain('WorkerStatus')
})
it('imports AgentType from contracts', () => {
expect(source).toContain('AgentType')
})
it('wrap_worker_result maps role results into WorkerResult with safe defaults', () => {
expect(source).toContain("agent_type: (payload.agent_type as AgentType) || 'executor'")
expect(source).toContain("const raw_status = (payload.status as string) || 'completed'")
expect(source).toContain("raw_status === 'fixed' || raw_status === 'pass'")
expect(source).toContain('changes.map((c: any) => String(c.file))')
expect(source).toContain("verification_payload ? [{ command: 'worker verification'")
expect(source).toContain('result: (payload.result as unknown) || payload')
})
it('get_result returns undefined for unknown agent', () => {
// The method should check if handle exists and return undefined
expect(source).toContain('if (!handle) return undefined')
})
})