Skip to content

Commit 8474c75

Browse files
authored
Merge pull request #68 from Garsson-io/worktree-260317-1224-7026
fix: route dev case notifications to main group
2 parents da429f5 + a8b3658 commit 8474c75

File tree

2 files changed

+65
-7
lines changed

2 files changed

+65
-7
lines changed

src/ipc-github-issues.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,57 @@ describe('case_create auto-creates GitHub issue for dev cases', () => {
356356
);
357357
});
358358

359+
// INVARIANT: Dev case notifications go to main group, not source group
360+
// SUT: processTaskIpc case_create notification routing
361+
test('dev case created from non-main group notifies main group', async () => {
362+
mockedCreateGitHubIssue.mockResolvedValue({
363+
success: true,
364+
issueUrl: 'https://github.com/Garsson-io/kaizen/issues/60',
365+
issueNumber: 60,
366+
});
367+
368+
await processTaskIpc(
369+
{
370+
type: 'case_create',
371+
description: 'Fix widget rendering',
372+
caseType: 'dev',
373+
chatJid: 'tg:222',
374+
requestId: 'req-dev-routing',
375+
} as any,
376+
'telegram_work',
377+
false,
378+
deps,
379+
);
380+
381+
// Notification should go to main group (tg:111), not source group (tg:222)
382+
expect(sendMessage).toHaveBeenCalledWith(
383+
'tg:111',
384+
expect.stringContaining('dev case created'),
385+
);
386+
});
387+
388+
// INVARIANT: Work case notifications go to source group, not main group
389+
test('work case created from non-main group notifies source group', async () => {
390+
await processTaskIpc(
391+
{
392+
type: 'case_create',
393+
description: 'Process client order',
394+
caseType: 'work',
395+
chatJid: 'tg:222',
396+
requestId: 'req-work-routing',
397+
} as any,
398+
'telegram_work',
399+
false,
400+
deps,
401+
);
402+
403+
// Notification should go to source group (tg:222), not main
404+
expect(sendMessage).toHaveBeenCalledWith(
405+
'tg:222',
406+
expect.stringContaining('work case created'),
407+
);
408+
});
409+
359410
test('work case does NOT create GitHub issue', async () => {
360411
await processTaskIpc(
361412
{

src/ipc.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,12 +1080,17 @@ export async function processTaskIpc(
10801080
}),
10811081
);
10821082

1083-
// Notify user
1084-
if (resolvedChatJid) {
1083+
// Notify user — dev cases notify main group, work cases notify source group
1084+
const notifyJid =
1085+
caseType === 'dev'
1086+
? Object.entries(registeredGroups).find(([, g]) => g.isMain)?.[0] ||
1087+
resolvedChatJid
1088+
: resolvedChatJid;
1089+
if (notifyJid) {
10851090
const issueInfo = issueUrl ? `\nGitHub: ${issueUrl}` : '';
10861091
deps
10871092
.sendMessage(
1088-
resolvedChatJid,
1093+
notifyJid,
10891094
`📋 New ${caseType} case created: ${name}\n${d.description.slice(0, 200)}${issueInfo}`,
10901095
)
10911096
.catch(() => {
@@ -1115,10 +1120,12 @@ export async function processTaskIpc(
11151120
initiatorChannel: undefined,
11161121
githubIssue: d.githubIssue,
11171122
});
1118-
// Notify user about the suggestion
1119-
const targetJid = Object.entries(registeredGroups).find(
1120-
([, g]) => g.folder === sourceGroup,
1121-
)?.[0];
1123+
// Notify main group about the dev suggestion
1124+
const targetJid =
1125+
Object.entries(registeredGroups).find(([, g]) => g.isMain)?.[0] ||
1126+
Object.entries(registeredGroups).find(
1127+
([, g]) => g.folder === sourceGroup,
1128+
)?.[0];
11221129
if (targetJid) {
11231130
deps
11241131
.sendMessage(

0 commit comments

Comments
 (0)