import { __awaiter } from "tslib";
import { assert, createLogicSuite } from '@genesislcap/foundation-testing';
import { defineStatefulAgent } from './define-stateful-agent';
// A minimal lifecycle context — `onActivate`/`onDeactivate` only read what the
// helper passes through, so the agent name, session key, and a live signal are
// enough to drive init/dispose in a Node-runnable test.
const lifecycleCtx = () => ({
    agentName: 'wizard',
    sessionKey: 'test-session',
    signal: new AbortController().signal,
});
const onUnresolvedTool = createLogicSuite('defineStatefulAgent onUnresolvedTool');
onUnresolvedTool('threads the live state into the hook after init', () => __awaiter(void 0, void 0, void 0, function* () {
    const config = defineStatefulAgent({
        name: 'wizard',
        description: 'guided wizard',
        init: () => ({ step: 'intake' }),
        onUnresolvedTool: ({ state, toolName, kind, availableTools }) => `step=${state.step} tool=${toolName} kind=${kind} avail=${availableTools.join(',')}`,
    });
    yield config.onActivate(lifecycleCtx());
    const result = yield config.onUnresolvedTool({
        toolName: 'generate_view',
        kind: 'stale',
        availableTools: ['ask_user', 'validate'],
    });
    assert.is(result, 'step=intake tool=generate_view kind=stale avail=ask_user,validate');
}));
onUnresolvedTool('returns undefined before init rather than throwing', () => __awaiter(void 0, void 0, void 0, function* () {
    const config = defineStatefulAgent({
        name: 'wizard',
        description: 'guided wizard',
        init: () => ({ step: 'intake' }),
        // Would throw if it were ever reached without state — proves the wrapper
        // short-circuits before delegating.
        onUnresolvedTool: ({ state }) => `step=${state.step}`,
    });
    // No `onActivate` call — state has not been built yet.
    const result = yield config.onUnresolvedTool({
        toolName: 'generate_view',
        kind: 'unknown',
        availableTools: [],
    });
    assert.is(result, undefined, 'a pre-init call must degrade to the framework default');
}));
onUnresolvedTool('omits the hook from the config when not supplied', () => {
    const config = defineStatefulAgent({
        name: 'wizard',
        description: 'guided wizard',
        init: () => ({ step: 'intake' }),
    });
    assert.is(config.onUnresolvedTool, undefined);
});
onUnresolvedTool.run();
