/**
 * TestChildAgentPort — In-memory ChildAgentPort for unit testing.
 *
 * Workers execute synchronously in-process. Use for agent unit tests
 * that need supervisor-worker patterns without external infrastructure.
 *
 * @public
 */
export class TestChildAgentPort {
    workers = new Map();
    nextWorkerId = 1;
    spyFn;
    /**
     * Set a spy function that intercepts worker execution.
     * The spy receives the ChildAgentOptions and returns the output.
     */
    spy(fn) {
        this.spyFn = fn;
    }
    async spawnAsync(opts) {
        const workerId = `test-worker-${this.nextWorkerId++}`;
        this.workers.set(workerId, { opts, status: "accepted" });
        // Execute asynchronously (microtask)
        Promise.resolve().then(async () => {
            try {
                const output = this.spyFn ? await this.spyFn(opts) : undefined;
                this.workers.set(workerId, { opts, status: "completed", output });
            }
            catch {
                this.workers.set(workerId, { opts, status: "failed" });
            }
        });
        return { workerId };
    }
    async spawnSync(opts) {
        const workerId = `test-worker-${this.nextWorkerId++}`;
        try {
            const output = this.spyFn ? await this.spyFn(opts) : undefined;
            this.workers.set(workerId, { opts, status: "completed", output });
            return { workerId, status: "completed", output };
        }
        catch (err) {
            const error = err instanceof Error ? err.message : String(err);
            this.workers.set(workerId, { opts, status: "failed" });
            return { workerId, status: "failed", error };
        }
    }
    /** Get worker status. */
    getWorker(workerId) {
        return this.workers.get(workerId);
    }
    /** Clear all state. */
    reset() {
        this.workers.clear();
        this.nextWorkerId = 1;
        this.spyFn = undefined;
    }
}
//# sourceMappingURL=test-child-agent.js.map