Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/providers/src/claude/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,34 @@ describe('ClaudeProvider', () => {
expect(callArgs.options.sandbox).toEqual(sandbox);
});

test('initializes options.hooks when nodeConfig provides hooks and options.hooks is undefined', async () => {
// Regression: applyNodeConfig previously assumed options.hooks was
// already an object when per-node hooks were declared, causing
// "undefined is not an object" at runtime for any workflow using
// per-node hooks (e.g. archon-architect, archon-refactor-safely).
mockQuery.mockImplementation(async function* () {
yield { type: 'result', session_id: 'sid' };
});

for await (const _ of client.sendQuery('test', '/tmp', undefined, {
nodeConfig: {
hooks: {
PostToolUse: [{ matcher: 'Write', response: { continue: true } }],
},
},
})) {
// consume
}

expect(mockQuery).toHaveBeenCalledTimes(1);
const callArgs = mockQuery.mock.calls[0][0] as {
options: { hooks?: Record<string, Array<{ matcher?: string }>> };
};
expect(callArgs.options.hooks).toBeDefined();
expect(callArgs.options.hooks?.PostToolUse).toBeDefined();
expect(callArgs.options.hooks?.PostToolUse?.[0]?.matcher).toBe('Write');
});

test('ignores empty text blocks', async () => {
mockQuery.mockImplementation(async function* () {
yield {
Expand Down
1 change: 1 addition & 0 deletions packages/providers/src/claude/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ async function applyNodeConfig(
if (Object.keys(builtHooks).length > 0) {
// Merge with existing hooks (PostToolUse capture hook)
const existingHooks = options.hooks as SDKHooksMap | undefined;
options.hooks ??= {};
for (const [event, matchers] of Object.entries(builtHooks)) {
if (!matchers) continue;
const existing = existingHooks?.[event] as HookCallbackMatcher[] | undefined;
Expand Down