@jcjeon/integration-cli 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitignore +23 -0
- package/.npmignore +21 -0
- package/.prettierignore +6 -0
- package/.prettierrc +26 -0
- package/AGENTS.md +10 -0
- package/CLAUDE.md +10 -0
- package/README.md +384 -0
- package/apps/server/README.md +294 -0
- package/apps/server/eslint.config.mjs +20 -0
- package/apps/server/nest-cli.json +8 -0
- package/apps/server/package.json +89 -0
- package/apps/server/scripts/postinstall.js +53 -0
- package/apps/server/src/__mocks__/glob.js +6 -0
- package/apps/server/src/__mocks__/uuid.js +5 -0
- package/apps/server/src/app.controller.spec.ts +24 -0
- package/apps/server/src/app.controller.ts +13 -0
- package/apps/server/src/app.module.ts +18 -0
- package/apps/server/src/app.service.ts +8 -0
- package/apps/server/src/common/ji-paths.ts +41 -0
- package/apps/server/src/database/database.module.ts +27 -0
- package/apps/server/src/database/entities/agent-changelog.entity.ts +39 -0
- package/apps/server/src/database/entities/agent-session.entity.ts +29 -0
- package/apps/server/src/database/entities/conversation.entity.ts +41 -0
- package/apps/server/src/database/entities/session.entity.ts +16 -0
- package/apps/server/src/database/entities/task-agent-run.entity.ts +40 -0
- package/apps/server/src/database/entities/task-agent.entity.ts +42 -0
- package/apps/server/src/database/entities/task-requirement.entity.ts +27 -0
- package/apps/server/src/database/entities/task-run.entity.ts +41 -0
- package/apps/server/src/database/entities/task.entity.ts +44 -0
- package/apps/server/src/main.ts +65 -0
- package/apps/server/src/modules/agents/agent-model-settings.spec.ts +80 -0
- package/apps/server/src/modules/agents/agents.module.ts +11 -0
- package/apps/server/src/modules/agents/claude/claude-auth.manager.ts +83 -0
- package/apps/server/src/modules/agents/claude/claude-pty.manager.ts +380 -0
- package/apps/server/src/modules/agents/claude/claude.controller.ts +85 -0
- package/apps/server/src/modules/agents/claude/claude.gateway.ts +158 -0
- package/apps/server/src/modules/agents/claude/claude.module.ts +18 -0
- package/apps/server/src/modules/agents/claude/claude.service.ts +67 -0
- package/apps/server/src/modules/agents/claude/dto/create-session.dto.ts +24 -0
- package/apps/server/src/modules/agents/claude/dto/resize-session.dto.ts +13 -0
- package/apps/server/src/modules/agents/claude/dto/send-input.dto.ts +9 -0
- package/apps/server/src/modules/agents/claude/interfaces/claude-session.interface.ts +26 -0
- package/apps/server/src/modules/agents/claude/interfaces/pty-event.interface.ts +10 -0
- package/apps/server/src/modules/agents/claude/interfaces/stream-event.interface.ts +61 -0
- package/apps/server/src/modules/agents/codex/codex-auth.manager.ts +107 -0
- package/apps/server/src/modules/agents/codex/codex-session.manager.ts +357 -0
- package/apps/server/src/modules/agents/codex/codex.controller.ts +64 -0
- package/apps/server/src/modules/agents/codex/codex.gateway.ts +97 -0
- package/apps/server/src/modules/agents/codex/codex.module.ts +17 -0
- package/apps/server/src/modules/agents/codex/dto/configure-auth.dto.ts +7 -0
- package/apps/server/src/modules/agents/gemini/dto/configure-auth.dto.ts +15 -0
- package/apps/server/src/modules/agents/gemini/dto/create-session.dto.ts +9 -0
- package/apps/server/src/modules/agents/gemini/dto/send-input.dto.ts +9 -0
- package/apps/server/src/modules/agents/gemini/gemini-auth.manager.ts +157 -0
- package/apps/server/src/modules/agents/gemini/gemini-session.manager.ts +287 -0
- package/apps/server/src/modules/agents/gemini/gemini.controller.ts +93 -0
- package/apps/server/src/modules/agents/gemini/gemini.gateway.ts +149 -0
- package/apps/server/src/modules/agents/gemini/gemini.module.ts +17 -0
- package/apps/server/src/modules/agents/gemini/interfaces/gemini-session.interface.ts +18 -0
- package/apps/server/src/modules/agents/gemini/interfaces/stream-event.interface.ts +14 -0
- package/apps/server/src/modules/agents/session-termination.spec.ts +103 -0
- package/apps/server/src/modules/changelog/changelog.controller.ts +20 -0
- package/apps/server/src/modules/changelog/changelog.module.ts +14 -0
- package/apps/server/src/modules/changelog/changelog.service.spec.ts +531 -0
- package/apps/server/src/modules/changelog/changelog.service.ts +690 -0
- package/apps/server/src/modules/conversations/conversation.controller.spec.ts +106 -0
- package/apps/server/src/modules/conversations/conversation.controller.ts +60 -0
- package/apps/server/src/modules/conversations/conversation.module.ts +14 -0
- package/apps/server/src/modules/conversations/conversation.service.spec.ts +176 -0
- package/apps/server/src/modules/conversations/conversation.service.ts +54 -0
- package/apps/server/src/modules/conversations/dto/create-conversation.dto.ts +37 -0
- package/apps/server/src/modules/conversations/enums/conversation.enum.ts +13 -0
- package/apps/server/src/modules/fs/fs.controller.ts +29 -0
- package/apps/server/src/modules/fs/fs.module.ts +8 -0
- package/apps/server/src/modules/harness/dto/save-harness.dto.ts +9 -0
- package/apps/server/src/modules/harness/harness.controller.spec.ts +95 -0
- package/apps/server/src/modules/harness/harness.controller.ts +35 -0
- package/apps/server/src/modules/harness/harness.module.ts +11 -0
- package/apps/server/src/modules/harness/harness.service.spec.ts +217 -0
- package/apps/server/src/modules/harness/harness.service.ts +112 -0
- package/apps/server/src/modules/sessions/session.controller.spec.ts +68 -0
- package/apps/server/src/modules/sessions/session.controller.ts +43 -0
- package/apps/server/src/modules/sessions/session.module.ts +14 -0
- package/apps/server/src/modules/sessions/session.service.spec.ts +106 -0
- package/apps/server/src/modules/sessions/session.service.ts +35 -0
- package/apps/server/src/modules/tasks/dto/create-task.dto.ts +54 -0
- package/apps/server/src/modules/tasks/dto/execute-task.dto.ts +22 -0
- package/apps/server/src/modules/tasks/dto/merge-file.dto.ts +7 -0
- package/apps/server/src/modules/tasks/dto/rerun-task.dto.ts +14 -0
- package/apps/server/src/modules/tasks/dto/update-task.dto.ts +55 -0
- package/apps/server/src/modules/tasks/task-execution.service.ts +978 -0
- package/apps/server/src/modules/tasks/task.gateway.ts +140 -0
- package/apps/server/src/modules/tasks/tasks.controller.spec.ts +210 -0
- package/apps/server/src/modules/tasks/tasks.controller.ts +139 -0
- package/apps/server/src/modules/tasks/tasks.module.ts +30 -0
- package/apps/server/src/modules/tasks/tasks.service.spec.ts +552 -0
- package/apps/server/src/modules/tasks/tasks.service.ts +333 -0
- package/apps/server/test/app.e2e-spec.ts +28 -0
- package/apps/server/test/jest-e2e.json +9 -0
- package/apps/server/tsconfig.build.json +4 -0
- package/apps/server/tsconfig.json +13 -0
- package/apps/web/AGENTS.md +7 -0
- package/apps/web/CLAUDE.md +1 -0
- package/apps/web/README.md +36 -0
- package/apps/web/eslint.config.mjs +21 -0
- package/apps/web/next-env.d.ts +6 -0
- package/apps/web/next.config.ts +7 -0
- package/apps/web/package.json +49 -0
- package/apps/web/postcss.config.mjs +7 -0
- package/apps/web/public/file.svg +1 -0
- package/apps/web/public/globe.svg +1 -0
- package/apps/web/public/next.svg +1 -0
- package/apps/web/public/vercel.svg +1 -0
- package/apps/web/public/window.svg +1 -0
- package/apps/web/src/app/claude/page.tsx +5 -0
- package/apps/web/src/app/codex/page.tsx +126 -0
- package/apps/web/src/app/favicon.ico +0 -0
- package/apps/web/src/app/gemini/page.tsx +130 -0
- package/apps/web/src/app/globals.css +149 -0
- package/apps/web/src/app/layout.tsx +40 -0
- package/apps/web/src/app/login/page.tsx +67 -0
- package/apps/web/src/app/page.tsx +497 -0
- package/apps/web/src/app/task/[id]/page.tsx +11 -0
- package/apps/web/src/app/test/page.tsx +298 -0
- package/apps/web/src/components/ui/Modal.tsx +78 -0
- package/apps/web/src/components/ui/WorkingDirPicker.tsx +195 -0
- package/apps/web/src/components/ui/__tests__/Modal.test.tsx +68 -0
- package/apps/web/src/features/auth/api/__tests__/auth.api.test.ts +83 -0
- package/apps/web/src/features/auth/api/auth.api.ts +81 -0
- package/apps/web/src/features/auth/hooks/__tests__/useClaudeAuth.test.ts +166 -0
- package/apps/web/src/features/auth/hooks/__tests__/useCodexAuth.test.ts +127 -0
- package/apps/web/src/features/auth/hooks/__tests__/useGeminiAuth.test.ts +120 -0
- package/apps/web/src/features/auth/hooks/useClaudeAuth.ts +88 -0
- package/apps/web/src/features/auth/hooks/useCodexAuth.ts +149 -0
- package/apps/web/src/features/auth/hooks/useGeminiAuth.ts +125 -0
- package/apps/web/src/features/auth/ui/CodexLoginPanel.tsx +302 -0
- package/apps/web/src/features/auth/ui/GeminiLoginPanel.tsx +316 -0
- package/apps/web/src/features/auth/ui/LoginForm.tsx +190 -0
- package/apps/web/src/features/auth/ui/LoginPanel.tsx +114 -0
- package/apps/web/src/features/auth/ui/__tests__/LoginPanel.test.tsx +105 -0
- package/apps/web/src/features/chat/api/__tests__/sessions.api.test.ts +187 -0
- package/apps/web/src/features/chat/api/sessions.api.ts +161 -0
- package/apps/web/src/features/chat/container/ClaudePageContainer.tsx +152 -0
- package/apps/web/src/features/chat/hooks/__tests__/useCodexSessions.test.ts +131 -0
- package/apps/web/src/features/chat/hooks/__tests__/useGeminiSessions.test.ts +130 -0
- package/apps/web/src/features/chat/hooks/useAgentModelSettings.ts +54 -0
- package/apps/web/src/features/chat/hooks/useClaudeSessions.ts +323 -0
- package/apps/web/src/features/chat/hooks/useCodexSessions.ts +275 -0
- package/apps/web/src/features/chat/hooks/useGeminiSessions.ts +255 -0
- package/apps/web/src/features/chat/hooks/useSessionCommand.ts +66 -0
- package/apps/web/src/features/chat/hooks/useSessionRename.ts +61 -0
- package/apps/web/src/features/chat/hooks/useSessionWorkingDirectories.ts +34 -0
- package/apps/web/src/features/chat/hooks/useUnifiedSessions.ts +156 -0
- package/apps/web/src/features/chat/lib/agentModelOptions.ts +72 -0
- package/apps/web/src/features/chat/ui/AgentModelPicker.tsx +134 -0
- package/apps/web/src/features/chat/ui/AgentSelectModal.tsx +236 -0
- package/apps/web/src/features/chat/ui/ChatInput.tsx +162 -0
- package/apps/web/src/features/chat/ui/ChatMessage.tsx +204 -0
- package/apps/web/src/features/chat/ui/ChatWorkspace.tsx +207 -0
- package/apps/web/src/features/chat/ui/CheckingSkeleton.tsx +44 -0
- package/apps/web/src/features/chat/ui/ClaudeLoginView.tsx +44 -0
- package/apps/web/src/features/chat/ui/PermissionCard.tsx +37 -0
- package/apps/web/src/features/chat/ui/SessionSidebar.tsx +280 -0
- package/apps/web/src/features/chat/ui/__tests__/AgentSelectModal.test.tsx +58 -0
- package/apps/web/src/features/chat/ui/__tests__/ChatInput.test.tsx +134 -0
- package/apps/web/src/features/chat/ui/__tests__/ChatMessage.test.tsx +106 -0
- package/apps/web/src/features/chat/ui/__tests__/ChatWorkspace.test.tsx +66 -0
- package/apps/web/src/features/diff/ui/DiffFileRow.tsx +73 -0
- package/apps/web/src/features/diff/ui/DiffHunk.tsx +61 -0
- package/apps/web/src/features/diff/ui/FileChangeBadge.tsx +23 -0
- package/apps/web/src/features/diff/ui/__tests__/DiffFileRow.test.tsx +40 -0
- package/apps/web/src/features/diff/ui/__tests__/DiffHunk.test.tsx +24 -0
- package/apps/web/src/features/diff/ui/__tests__/FileChangeBadge.test.tsx +16 -0
- package/apps/web/src/features/fs/api/fs.api.ts +14 -0
- package/apps/web/src/features/fs/hooks/useDirBrowser.ts +50 -0
- package/apps/web/src/features/harness/api/__tests__/harness.api.test.ts +73 -0
- package/apps/web/src/features/harness/api/harness.api.ts +46 -0
- package/apps/web/src/features/harness/hooks/__tests__/useHarness.test.ts +65 -0
- package/apps/web/src/features/harness/hooks/useHarness.ts +66 -0
- package/apps/web/src/features/harness/ui/HarnessModal.tsx +171 -0
- package/apps/web/src/features/harness/ui/__tests__/HarnessModal.test.tsx +46 -0
- package/apps/web/src/features/status/ui/AgentStatusModal.tsx +267 -0
- package/apps/web/src/features/status/ui/__tests__/AgentStatusModal.test.tsx +71 -0
- package/apps/web/src/features/tasks/api/__tests__/changelog.api.test.ts +89 -0
- package/apps/web/src/features/tasks/api/__tests__/tasks.api.test.ts +282 -0
- package/apps/web/src/features/tasks/api/changelog.api.ts +52 -0
- package/apps/web/src/features/tasks/api/tasks.api.ts +175 -0
- package/apps/web/src/features/tasks/container/TaskDetailPageContainer.tsx +69 -0
- package/apps/web/src/features/tasks/hooks/__tests__/useChangelogCodeCopy.test.ts +48 -0
- package/apps/web/src/features/tasks/hooks/__tests__/useTaskChangelog.test.ts +48 -0
- package/apps/web/src/features/tasks/hooks/__tests__/useTaskCreate.test.ts +217 -0
- package/apps/web/src/features/tasks/hooks/__tests__/useTaskEdit.test.ts +152 -0
- package/apps/web/src/features/tasks/hooks/__tests__/useTaskExecution.test.ts +143 -0
- package/apps/web/src/features/tasks/hooks/__tests__/useTaskList.test.ts +168 -0
- package/apps/web/src/features/tasks/hooks/__tests__/useTaskNotification.test.ts +125 -0
- package/apps/web/src/features/tasks/hooks/__tests__/useTaskRuns.test.ts +51 -0
- package/apps/web/src/features/tasks/hooks/useChangelogCodeCopy.ts +52 -0
- package/apps/web/src/features/tasks/hooks/useCopyToClipboard.ts +47 -0
- package/apps/web/src/features/tasks/hooks/useTaskChangelog.ts +32 -0
- package/apps/web/src/features/tasks/hooks/useTaskCreate.ts +137 -0
- package/apps/web/src/features/tasks/hooks/useTaskDetail.ts +217 -0
- package/apps/web/src/features/tasks/hooks/useTaskEdit.ts +130 -0
- package/apps/web/src/features/tasks/hooks/useTaskExecution.ts +137 -0
- package/apps/web/src/features/tasks/hooks/useTaskList.ts +159 -0
- package/apps/web/src/features/tasks/hooks/useTaskNotification.ts +80 -0
- package/apps/web/src/features/tasks/hooks/useTaskRuns.ts +32 -0
- package/apps/web/src/features/tasks/ui/AgentOutputPanel.tsx +203 -0
- package/apps/web/src/features/tasks/ui/AgentRoleSelect.tsx +97 -0
- package/apps/web/src/features/tasks/ui/ChangelogPanel.tsx +321 -0
- package/apps/web/src/features/tasks/ui/RunHistoryPanel.tsx +193 -0
- package/apps/web/src/features/tasks/ui/TaskCreateModal.tsx +205 -0
- package/apps/web/src/features/tasks/ui/TaskDetailView.tsx +413 -0
- package/apps/web/src/features/tasks/ui/TaskEditModal.tsx +165 -0
- package/apps/web/src/features/tasks/ui/TaskListModal.tsx +591 -0
- package/apps/web/src/features/tasks/ui/__tests__/AgentRoleSelect.test.tsx +91 -0
- package/apps/web/src/features/tasks/ui/__tests__/ChangelogPanel.test.tsx +94 -0
- package/apps/web/src/features/tasks/ui/__tests__/RunHistoryPanel.test.tsx +71 -0
- package/apps/web/src/features/tasks/ui/__tests__/TaskCreateModal.test.tsx +153 -0
- package/apps/web/src/features/tasks/ui/__tests__/TaskEditModal.test.tsx +75 -0
- package/apps/web/src/features/tasks/ui/__tests__/TaskListModal.test.tsx +243 -0
- package/apps/web/src/hooks/useWorkingDir.ts +28 -0
- package/apps/web/src/lib/__tests__/ansi.test.ts +88 -0
- package/apps/web/src/lib/ansi.ts +105 -0
- package/apps/web/src/lib/constants.ts +4 -0
- package/apps/web/src/lib/quota.ts +22 -0
- package/apps/web/src/lib/theme.tsx +78 -0
- package/apps/web/src/lib/toast.tsx +175 -0
- package/apps/web/src/store/agentStatusStore.ts +38 -0
- package/apps/web/tsconfig.json +18 -0
- package/apps/web/vitest.config.ts +25 -0
- package/apps/web/vitest.setup.ts +10 -0
- package/package.json +85 -0
- package/packages/cli/dist/commands/check.d.ts +1 -0
- package/packages/cli/dist/commands/check.js +89 -0
- package/packages/cli/dist/commands/init.d.ts +5 -0
- package/packages/cli/dist/commands/init.js +183 -0
- package/packages/cli/dist/commands/start.d.ts +4 -0
- package/packages/cli/dist/commands/start.js +188 -0
- package/packages/cli/dist/index.d.ts +2 -0
- package/packages/cli/dist/index.js +71 -0
- package/packages/cli/dist/utils/agent-tools.d.ts +28 -0
- package/packages/cli/dist/utils/agent-tools.js +193 -0
- package/packages/cli/dist/utils/project-init.d.ts +12 -0
- package/packages/cli/dist/utils/project-init.js +258 -0
- package/packages/cli/dist/utils/proxy.d.ts +8 -0
- package/packages/cli/dist/utils/proxy.js +138 -0
- package/packages/cli/package.json +30 -0
- package/packages/cli/src/commands/check.ts +77 -0
- package/packages/cli/src/commands/init.ts +209 -0
- package/packages/cli/src/commands/start.ts +183 -0
- package/packages/cli/src/index.ts +91 -0
- package/packages/cli/src/utils/agent-tools.ts +201 -0
- package/packages/cli/src/utils/project-init.ts +252 -0
- package/packages/cli/src/utils/proxy.ts +123 -0
- package/packages/cli/tsconfig.json +14 -0
- package/packages/eslint-config/base.mjs +31 -0
- package/packages/eslint-config/nest.mjs +55 -0
- package/packages/eslint-config/next.mjs +23 -0
- package/packages/eslint-config/package.json +20 -0
- package/packages/typescript-config/base.json +16 -0
- package/packages/typescript-config/nestjs.json +17 -0
- package/packages/typescript-config/nextjs.json +15 -0
- package/packages/typescript-config/package.json +11 -0
- package/turbo.json +28 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
import { BadRequestException } from '@nestjs/common';
|
|
5
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
6
|
+
|
|
7
|
+
import { JI_PATHS } from '../../common/ji-paths';
|
|
8
|
+
import { HarnessService } from './harness.service';
|
|
9
|
+
|
|
10
|
+
jest.mock('fs');
|
|
11
|
+
|
|
12
|
+
describe('HarnessService', () => {
|
|
13
|
+
let service: HarnessService;
|
|
14
|
+
|
|
15
|
+
const harnessDir = JI_PATHS.harness;
|
|
16
|
+
|
|
17
|
+
beforeEach(async () => {
|
|
18
|
+
const module: TestingModule = await Test.createTestingModule({
|
|
19
|
+
providers: [HarnessService],
|
|
20
|
+
}).compile();
|
|
21
|
+
|
|
22
|
+
service = module.get(HarnessService);
|
|
23
|
+
jest.clearAllMocks();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// ─── findAll ─────────────────────────────────────────────────────────────
|
|
27
|
+
|
|
28
|
+
describe('findAll', () => {
|
|
29
|
+
it('존재하는 harness 파일들을 모두 반환한다', () => {
|
|
30
|
+
(fs.existsSync as jest.Mock).mockImplementation((p: string) =>
|
|
31
|
+
p === path.join(harnessDir, 'common.md') || p === path.join(harnessDir, 'frontend.tsx'),
|
|
32
|
+
);
|
|
33
|
+
(fs.readFileSync as jest.Mock).mockReturnValue('# content');
|
|
34
|
+
|
|
35
|
+
const result = service.findAll();
|
|
36
|
+
|
|
37
|
+
expect(result).toHaveLength(2);
|
|
38
|
+
expect(result[0]).toEqual({ role: 'common', ext: 'md', content: '# content' });
|
|
39
|
+
expect(result[1]).toEqual({ role: 'frontend', ext: 'tsx', content: '# content' });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('파일이 없으면 빈 배열을 반환한다', () => {
|
|
43
|
+
(fs.existsSync as jest.Mock).mockReturnValue(false);
|
|
44
|
+
|
|
45
|
+
const result = service.findAll();
|
|
46
|
+
|
|
47
|
+
expect(result).toEqual([]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('md와 tsx 중 먼저 찾은 파일을 반환한다', () => {
|
|
51
|
+
(fs.existsSync as jest.Mock).mockImplementation((p: string) =>
|
|
52
|
+
p === path.join(harnessDir, 'backend.md'),
|
|
53
|
+
);
|
|
54
|
+
(fs.readFileSync as jest.Mock).mockReturnValue('backend content');
|
|
55
|
+
|
|
56
|
+
const result = service.findAll();
|
|
57
|
+
|
|
58
|
+
const backendEntry = result.find((h) => h.role === 'backend');
|
|
59
|
+
expect(backendEntry?.ext).toBe('md');
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
// ─── findOne ─────────────────────────────────────────────────────────────
|
|
64
|
+
|
|
65
|
+
describe('findOne', () => {
|
|
66
|
+
it('md 파일이 있으면 반환한다', () => {
|
|
67
|
+
(fs.existsSync as jest.Mock).mockImplementation((p: string) =>
|
|
68
|
+
p === path.join(harnessDir, 'common.md'),
|
|
69
|
+
);
|
|
70
|
+
(fs.readFileSync as jest.Mock).mockReturnValue('# common template');
|
|
71
|
+
|
|
72
|
+
const result = service.findOne('common');
|
|
73
|
+
|
|
74
|
+
expect(result).toEqual({ role: 'common', ext: 'md', content: '# common template' });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('tsx 파일을 md보다 우선하지 않는다 (md 먼저 확인)', () => {
|
|
78
|
+
(fs.existsSync as jest.Mock).mockImplementation((p: string) =>
|
|
79
|
+
p === path.join(harnessDir, 'frontend.tsx'),
|
|
80
|
+
);
|
|
81
|
+
(fs.readFileSync as jest.Mock).mockReturnValue('export default () => <div/>;');
|
|
82
|
+
|
|
83
|
+
const result = service.findOne('frontend');
|
|
84
|
+
|
|
85
|
+
expect(result).toEqual({ role: 'frontend', ext: 'tsx', content: 'export default () => <div/>;' });
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('파일이 없으면 null을 반환한다', () => {
|
|
89
|
+
(fs.existsSync as jest.Mock).mockReturnValue(false);
|
|
90
|
+
|
|
91
|
+
const result = service.findOne('backend');
|
|
92
|
+
|
|
93
|
+
expect(result).toBeNull();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('readFileSync를 utf8로 호출한다', () => {
|
|
97
|
+
const mdPath = path.join(harnessDir, 'doc.md');
|
|
98
|
+
(fs.existsSync as jest.Mock).mockImplementation((p: string) => p === mdPath);
|
|
99
|
+
(fs.readFileSync as jest.Mock).mockReturnValue('content');
|
|
100
|
+
|
|
101
|
+
service.findOne('doc');
|
|
102
|
+
|
|
103
|
+
expect(fs.readFileSync).toHaveBeenCalledWith(mdPath, 'utf8');
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('허용되지 않는 role이면 파일 시스템 접근 전에 거부한다', () => {
|
|
107
|
+
expect(() => service.findOne('../common')).toThrow(BadRequestException);
|
|
108
|
+
expect(fs.existsSync).not.toHaveBeenCalled();
|
|
109
|
+
expect(fs.readFileSync).not.toHaveBeenCalled();
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
// ─── save ─────────────────────────────────────────────────────────────────
|
|
114
|
+
|
|
115
|
+
describe('save', () => {
|
|
116
|
+
it('md 파일을 저장한다', () => {
|
|
117
|
+
(fs.existsSync as jest.Mock).mockReturnValue(false);
|
|
118
|
+
|
|
119
|
+
const result = service.save('common', '# new content', 'md');
|
|
120
|
+
|
|
121
|
+
expect(fs.writeFileSync).toHaveBeenCalledWith(
|
|
122
|
+
path.join(harnessDir, 'common.md'),
|
|
123
|
+
'# new content',
|
|
124
|
+
'utf8',
|
|
125
|
+
);
|
|
126
|
+
expect(result).toEqual({ role: 'common', ext: 'md', content: '# new content' });
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('tsx 파일을 저장한다', () => {
|
|
130
|
+
(fs.existsSync as jest.Mock).mockReturnValue(false);
|
|
131
|
+
|
|
132
|
+
const result = service.save('frontend', 'const X = () => null;', 'tsx');
|
|
133
|
+
|
|
134
|
+
expect(fs.writeFileSync).toHaveBeenCalledWith(
|
|
135
|
+
path.join(harnessDir, 'frontend.tsx'),
|
|
136
|
+
'const X = () => null;',
|
|
137
|
+
'utf8',
|
|
138
|
+
);
|
|
139
|
+
expect(result).toEqual({ role: 'frontend', ext: 'tsx', content: 'const X = () => null;' });
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('확장자 변경 시 기존 파일을 삭제한다', () => {
|
|
143
|
+
const oldPath = path.join(harnessDir, 'common.tsx');
|
|
144
|
+
(fs.existsSync as jest.Mock).mockImplementation((p: string) => p === oldPath);
|
|
145
|
+
|
|
146
|
+
service.save('common', 'content', 'md');
|
|
147
|
+
|
|
148
|
+
expect(fs.unlinkSync).toHaveBeenCalledWith(oldPath);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('다른 확장자 파일이 없으면 삭제하지 않는다', () => {
|
|
152
|
+
(fs.existsSync as jest.Mock).mockReturnValue(false);
|
|
153
|
+
|
|
154
|
+
service.save('operation', 'content', 'md');
|
|
155
|
+
|
|
156
|
+
expect(fs.unlinkSync).not.toHaveBeenCalled();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('허용되지 않는 role이면 파일 쓰기를 수행하지 않는다', () => {
|
|
160
|
+
expect(() => service.save('../common', 'content', 'md')).toThrow(BadRequestException);
|
|
161
|
+
expect(fs.existsSync).not.toHaveBeenCalled();
|
|
162
|
+
expect(fs.unlinkSync).not.toHaveBeenCalled();
|
|
163
|
+
expect(fs.writeFileSync).not.toHaveBeenCalled();
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('허용되지 않는 확장자이면 파일 쓰기를 수행하지 않는다', () => {
|
|
167
|
+
expect(() => service.save('common', 'content', 'json' as never)).toThrow(BadRequestException);
|
|
168
|
+
expect(fs.existsSync).not.toHaveBeenCalled();
|
|
169
|
+
expect(fs.unlinkSync).not.toHaveBeenCalled();
|
|
170
|
+
expect(fs.writeFileSync).not.toHaveBeenCalled();
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// ─── remove ──────────────────────────────────────────────────────────────
|
|
175
|
+
|
|
176
|
+
describe('remove', () => {
|
|
177
|
+
it('md 파일을 삭제한다', () => {
|
|
178
|
+
const mdPath = path.join(harnessDir, 'common.md');
|
|
179
|
+
(fs.existsSync as jest.Mock).mockImplementation((p: string) => p === mdPath);
|
|
180
|
+
|
|
181
|
+
service.remove('common');
|
|
182
|
+
|
|
183
|
+
expect(fs.unlinkSync).toHaveBeenCalledWith(mdPath);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('tsx 파일을 삭제한다', () => {
|
|
187
|
+
const tsxPath = path.join(harnessDir, 'frontend.tsx');
|
|
188
|
+
(fs.existsSync as jest.Mock).mockImplementation((p: string) => p === tsxPath);
|
|
189
|
+
|
|
190
|
+
service.remove('frontend');
|
|
191
|
+
|
|
192
|
+
expect(fs.unlinkSync).toHaveBeenCalledWith(tsxPath);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('두 확장자 모두 존재하면 둘 다 삭제한다', () => {
|
|
196
|
+
(fs.existsSync as jest.Mock).mockReturnValue(true);
|
|
197
|
+
|
|
198
|
+
service.remove('backend');
|
|
199
|
+
|
|
200
|
+
expect(fs.unlinkSync).toHaveBeenCalledTimes(2);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('파일이 없으면 삭제하지 않는다', () => {
|
|
204
|
+
(fs.existsSync as jest.Mock).mockReturnValue(false);
|
|
205
|
+
|
|
206
|
+
service.remove('other');
|
|
207
|
+
|
|
208
|
+
expect(fs.unlinkSync).not.toHaveBeenCalled();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('허용되지 않는 role이면 파일 삭제를 수행하지 않는다', () => {
|
|
212
|
+
expect(() => service.remove('../common')).toThrow(BadRequestException);
|
|
213
|
+
expect(fs.existsSync).not.toHaveBeenCalled();
|
|
214
|
+
expect(fs.unlinkSync).not.toHaveBeenCalled();
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
|
|
4
|
+
import { BadRequestException, Injectable, InternalServerErrorException } from '@nestjs/common';
|
|
5
|
+
|
|
6
|
+
import { JI_PATHS } from '../../common/ji-paths';
|
|
7
|
+
|
|
8
|
+
export const HARNESS_ROLES = ['common', 'frontend', 'backend', 'doc', 'operation', 'other'] as const;
|
|
9
|
+
const HARNESS_EXTENSIONS = ['md', 'tsx'] as const;
|
|
10
|
+
|
|
11
|
+
export type HarnessRole = (typeof HARNESS_ROLES)[number];
|
|
12
|
+
export type HarnessExt = (typeof HARNESS_EXTENSIONS)[number];
|
|
13
|
+
|
|
14
|
+
export interface Harness {
|
|
15
|
+
role: HarnessRole;
|
|
16
|
+
ext: HarnessExt;
|
|
17
|
+
content: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const ALL_ROLES: HarnessRole[] = [...HARNESS_ROLES];
|
|
21
|
+
const HARNESS_ROOT = path.resolve(JI_PATHS.harness);
|
|
22
|
+
|
|
23
|
+
@Injectable()
|
|
24
|
+
export class HarnessService {
|
|
25
|
+
|
|
26
|
+
findAll(): Harness[] {
|
|
27
|
+
try {
|
|
28
|
+
return ALL_ROLES.map((role) => this.findOne(role)).filter(Boolean) as Harness[];
|
|
29
|
+
} catch (err) {
|
|
30
|
+
this.rethrowHarnessError(err);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
findOne(role: string): Harness | null {
|
|
35
|
+
try {
|
|
36
|
+
const harnessRole = this.parseRole(role);
|
|
37
|
+
|
|
38
|
+
for (const ext of HARNESS_EXTENSIONS) {
|
|
39
|
+
const filePath = this.resolveHarnessPath(harnessRole, ext);
|
|
40
|
+
if (fs.existsSync(filePath)) {
|
|
41
|
+
return { role: harnessRole, ext, content: fs.readFileSync(filePath, 'utf8') };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
} catch (err) {
|
|
46
|
+
this.rethrowHarnessError(err);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
save(role: string, content: string, ext: HarnessExt): Harness {
|
|
51
|
+
try {
|
|
52
|
+
const harnessRole = this.parseRole(role);
|
|
53
|
+
const harnessExt = this.parseExt(ext);
|
|
54
|
+
const targetPath = this.resolveHarnessPath(harnessRole, harnessExt);
|
|
55
|
+
const otherExt: HarnessExt = harnessExt === 'md' ? 'tsx' : 'md';
|
|
56
|
+
const otherPath = this.resolveHarnessPath(harnessRole, otherExt);
|
|
57
|
+
|
|
58
|
+
// 다른 확장자 파일 존재 시 제거 (확장자 변경 처리)
|
|
59
|
+
if (fs.existsSync(otherPath)) fs.unlinkSync(otherPath);
|
|
60
|
+
|
|
61
|
+
fs.writeFileSync(targetPath, content, 'utf8');
|
|
62
|
+
return { role: harnessRole, ext: harnessExt, content };
|
|
63
|
+
} catch (err) {
|
|
64
|
+
this.rethrowHarnessError(err);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
remove(role: string): void {
|
|
69
|
+
try {
|
|
70
|
+
const harnessRole = this.parseRole(role);
|
|
71
|
+
|
|
72
|
+
for (const ext of HARNESS_EXTENSIONS) {
|
|
73
|
+
const filePath = this.resolveHarnessPath(harnessRole, ext);
|
|
74
|
+
if (fs.existsSync(filePath)) fs.unlinkSync(filePath);
|
|
75
|
+
}
|
|
76
|
+
} catch (err) {
|
|
77
|
+
this.rethrowHarnessError(err);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private parseRole(role: string): HarnessRole {
|
|
82
|
+
if (!HARNESS_ROLES.includes(role as HarnessRole)) {
|
|
83
|
+
throw new BadRequestException(`지원하지 않는 harness role입니다: ${role}`);
|
|
84
|
+
}
|
|
85
|
+
return role as HarnessRole;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private parseExt(ext: string): HarnessExt {
|
|
89
|
+
if (!HARNESS_EXTENSIONS.includes(ext as HarnessExt)) {
|
|
90
|
+
throw new BadRequestException(`지원하지 않는 harness 확장자입니다: ${ext}`);
|
|
91
|
+
}
|
|
92
|
+
return ext as HarnessExt;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private resolveHarnessPath(role: HarnessRole, ext: HarnessExt): string {
|
|
96
|
+
const targetPath = path.resolve(HARNESS_ROOT, `${role}.${ext}`);
|
|
97
|
+
|
|
98
|
+
if (path.dirname(targetPath) !== HARNESS_ROOT) {
|
|
99
|
+
throw new BadRequestException(`유효하지 않은 harness 경로입니다: ${role}`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return targetPath;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private rethrowHarnessError(err: unknown): never {
|
|
106
|
+
if (err instanceof BadRequestException) {
|
|
107
|
+
throw err;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
throw new InternalServerErrorException('하네스 파일 처리 중 오류가 발생했습니다.');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
2
|
+
|
|
3
|
+
import { SessionEntity } from '../../database/entities/session.entity';
|
|
4
|
+
import { SessionController } from './session.controller';
|
|
5
|
+
import { SessionService } from './session.service';
|
|
6
|
+
|
|
7
|
+
const baseSession: SessionEntity = {
|
|
8
|
+
sessionId: 'sess-uuid-1',
|
|
9
|
+
agentType: 'claude',
|
|
10
|
+
title: 'Test Session',
|
|
11
|
+
createdAt: new Date('2024-01-01'),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
describe('SessionController', () => {
|
|
15
|
+
let controller: SessionController;
|
|
16
|
+
let service: jest.Mocked<SessionService>;
|
|
17
|
+
|
|
18
|
+
beforeEach(async () => {
|
|
19
|
+
const module: TestingModule = await Test.createTestingModule({
|
|
20
|
+
controllers: [SessionController],
|
|
21
|
+
providers: [
|
|
22
|
+
{
|
|
23
|
+
provide: SessionService,
|
|
24
|
+
useValue: {
|
|
25
|
+
findAll: jest.fn(),
|
|
26
|
+
findOne: jest.fn(),
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
}).compile();
|
|
31
|
+
|
|
32
|
+
controller = module.get(SessionController);
|
|
33
|
+
service = module.get(SessionService) as jest.Mocked<SessionService>;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
afterEach(() => jest.clearAllMocks());
|
|
37
|
+
|
|
38
|
+
describe('findAll', () => {
|
|
39
|
+
it('agentType 없이 전체 목록을 반환한다', async () => {
|
|
40
|
+
service.findAll.mockResolvedValue([baseSession]);
|
|
41
|
+
|
|
42
|
+
const result = await controller.findAll();
|
|
43
|
+
|
|
44
|
+
expect(service.findAll).toHaveBeenCalledWith(undefined);
|
|
45
|
+
expect(result).toEqual([baseSession]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('agentType 필터와 함께 목록을 반환한다', async () => {
|
|
49
|
+
service.findAll.mockResolvedValue([baseSession]);
|
|
50
|
+
|
|
51
|
+
const result = await controller.findAll('claude');
|
|
52
|
+
|
|
53
|
+
expect(service.findAll).toHaveBeenCalledWith('claude');
|
|
54
|
+
expect(result).toEqual([baseSession]);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe('findOne', () => {
|
|
59
|
+
it('service.findOne을 sessionId로 호출한다', async () => {
|
|
60
|
+
service.findOne.mockResolvedValue(baseSession);
|
|
61
|
+
|
|
62
|
+
const result = await controller.findOne('sess-uuid-1');
|
|
63
|
+
|
|
64
|
+
expect(service.findOne).toHaveBeenCalledWith('sess-uuid-1');
|
|
65
|
+
expect(result).toBe(baseSession);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Body, Controller, Get, HttpCode, HttpStatus, Param, Patch, Query } from '@nestjs/common';
|
|
2
|
+
import { ApiOkResponse, ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
|
|
3
|
+
import { IsNotEmpty, IsString } from 'class-validator';
|
|
4
|
+
|
|
5
|
+
import { SessionService } from './session.service';
|
|
6
|
+
|
|
7
|
+
class UpdateTitleDto {
|
|
8
|
+
@IsString()
|
|
9
|
+
@IsNotEmpty()
|
|
10
|
+
title!: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@ApiTags('sessions')
|
|
14
|
+
@Controller('sessions')
|
|
15
|
+
export class SessionController {
|
|
16
|
+
constructor(private readonly sessionService: SessionService) {}
|
|
17
|
+
|
|
18
|
+
@ApiOperation({ summary: 'DB 저장 세션 목록 조회' })
|
|
19
|
+
@ApiQuery({ name: 'agentType', required: false, enum: ['claude', 'gemini'], description: '에이전트 필터' })
|
|
20
|
+
@ApiOkResponse({ description: '세션 목록' })
|
|
21
|
+
@Get()
|
|
22
|
+
findAll(@Query('agentType') agentType?: string) {
|
|
23
|
+
return this.sessionService.findAll(agentType);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@ApiOperation({ summary: 'DB 저장 세션 단건 조회' })
|
|
27
|
+
@ApiOkResponse({ description: '세션 정보' })
|
|
28
|
+
@Get(':sessionId')
|
|
29
|
+
findOne(@Param('sessionId') sessionId: string) {
|
|
30
|
+
return this.sessionService.findOne(sessionId);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@ApiOperation({ summary: '세션 타이틀 수정' })
|
|
34
|
+
@ApiOkResponse({ description: '수정된 세션 정보' })
|
|
35
|
+
@Patch(':sessionId/title')
|
|
36
|
+
@HttpCode(HttpStatus.OK)
|
|
37
|
+
updateTitle(
|
|
38
|
+
@Param('sessionId') sessionId: string,
|
|
39
|
+
@Body() dto: UpdateTitleDto,
|
|
40
|
+
) {
|
|
41
|
+
return this.sessionService.updateTitle(sessionId, dto.title);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
3
|
+
|
|
4
|
+
import { SessionEntity } from '../../database/entities/session.entity';
|
|
5
|
+
import { SessionController } from './session.controller';
|
|
6
|
+
import { SessionService } from './session.service';
|
|
7
|
+
|
|
8
|
+
@Module({
|
|
9
|
+
imports: [TypeOrmModule.forFeature([SessionEntity])],
|
|
10
|
+
controllers: [SessionController],
|
|
11
|
+
providers: [SessionService],
|
|
12
|
+
exports: [SessionService],
|
|
13
|
+
})
|
|
14
|
+
export class SessionModule {}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { NotFoundException } from '@nestjs/common';
|
|
2
|
+
import { Test, TestingModule } from '@nestjs/testing';
|
|
3
|
+
import { getRepositoryToken } from '@nestjs/typeorm';
|
|
4
|
+
|
|
5
|
+
import { SessionEntity } from '../../database/entities/session.entity';
|
|
6
|
+
import { SessionService } from './session.service';
|
|
7
|
+
|
|
8
|
+
const mockRepo = () => ({
|
|
9
|
+
findOne: jest.fn(),
|
|
10
|
+
find: jest.fn(),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe('SessionService', () => {
|
|
14
|
+
let service: SessionService;
|
|
15
|
+
let repo: ReturnType<typeof mockRepo>;
|
|
16
|
+
|
|
17
|
+
const baseSession: SessionEntity = {
|
|
18
|
+
sessionId: 'sess-uuid-1',
|
|
19
|
+
agentType: 'claude',
|
|
20
|
+
title: 'Test Session',
|
|
21
|
+
createdAt: new Date('2024-01-01'),
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
beforeEach(async () => {
|
|
25
|
+
const module: TestingModule = await Test.createTestingModule({
|
|
26
|
+
providers: [
|
|
27
|
+
SessionService,
|
|
28
|
+
{ provide: getRepositoryToken(SessionEntity), useFactory: mockRepo },
|
|
29
|
+
],
|
|
30
|
+
}).compile();
|
|
31
|
+
|
|
32
|
+
service = module.get(SessionService);
|
|
33
|
+
repo = module.get(getRepositoryToken(SessionEntity));
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
afterEach(() => jest.clearAllMocks());
|
|
37
|
+
|
|
38
|
+
// ─── findAll ─────────────────────────────────────────────────────────────
|
|
39
|
+
|
|
40
|
+
describe('findAll', () => {
|
|
41
|
+
it('전체 세션 목록을 최신순으로 반환한다', async () => {
|
|
42
|
+
repo.find.mockResolvedValue([baseSession]);
|
|
43
|
+
|
|
44
|
+
const result = await service.findAll();
|
|
45
|
+
|
|
46
|
+
expect(result).toEqual([baseSession]);
|
|
47
|
+
expect(repo.find).toHaveBeenCalledWith({
|
|
48
|
+
where: undefined,
|
|
49
|
+
order: { createdAt: 'DESC' },
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('agentType 필터로 세션을 조회한다', async () => {
|
|
54
|
+
repo.find.mockResolvedValue([baseSession]);
|
|
55
|
+
|
|
56
|
+
const result = await service.findAll('claude');
|
|
57
|
+
|
|
58
|
+
expect(result).toEqual([baseSession]);
|
|
59
|
+
expect(repo.find).toHaveBeenCalledWith({
|
|
60
|
+
where: { agentType: 'claude' },
|
|
61
|
+
order: { createdAt: 'DESC' },
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('gemini agentType 필터를 지원한다', async () => {
|
|
66
|
+
const geminiSession = { ...baseSession, agentType: 'gemini' };
|
|
67
|
+
repo.find.mockResolvedValue([geminiSession]);
|
|
68
|
+
|
|
69
|
+
const result = await service.findAll('gemini');
|
|
70
|
+
|
|
71
|
+
expect(result).toEqual([geminiSession]);
|
|
72
|
+
expect(repo.find).toHaveBeenCalledWith({
|
|
73
|
+
where: { agentType: 'gemini' },
|
|
74
|
+
order: { createdAt: 'DESC' },
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('결과가 없으면 빈 배열을 반환한다', async () => {
|
|
79
|
+
repo.find.mockResolvedValue([]);
|
|
80
|
+
|
|
81
|
+
const result = await service.findAll();
|
|
82
|
+
|
|
83
|
+
expect(result).toEqual([]);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// ─── findOne ─────────────────────────────────────────────────────────────
|
|
88
|
+
|
|
89
|
+
describe('findOne', () => {
|
|
90
|
+
it('sessionId로 세션을 조회한다', async () => {
|
|
91
|
+
repo.findOne.mockResolvedValue(baseSession);
|
|
92
|
+
|
|
93
|
+
const result = await service.findOne('sess-uuid-1');
|
|
94
|
+
|
|
95
|
+
expect(result).toBe(baseSession);
|
|
96
|
+
expect(repo.findOne).toHaveBeenCalledWith({ where: { sessionId: 'sess-uuid-1' } });
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('존재하지 않는 sessionId는 NotFoundException을 던진다', async () => {
|
|
100
|
+
repo.findOne.mockResolvedValue(null);
|
|
101
|
+
|
|
102
|
+
await expect(service.findOne('not-exist')).rejects.toThrow(NotFoundException);
|
|
103
|
+
await expect(service.findOne('not-exist')).rejects.toThrow('Session not-exist not found');
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
2
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
3
|
+
import { Repository } from 'typeorm';
|
|
4
|
+
|
|
5
|
+
import { SessionEntity } from '../../database/entities/session.entity';
|
|
6
|
+
|
|
7
|
+
@Injectable()
|
|
8
|
+
export class SessionService {
|
|
9
|
+
constructor(
|
|
10
|
+
@InjectRepository(SessionEntity)
|
|
11
|
+
private readonly repo: Repository<SessionEntity>,
|
|
12
|
+
) {}
|
|
13
|
+
|
|
14
|
+
/** 전체 세션 목록 (최신순), agentType 필터 옵션 */
|
|
15
|
+
findAll(agentType?: string): Promise<SessionEntity[]> {
|
|
16
|
+
return this.repo.find({
|
|
17
|
+
where: agentType ? { agentType } : undefined,
|
|
18
|
+
order: { createdAt: 'DESC' },
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** 단건 조회 */
|
|
23
|
+
async findOne(sessionId: string): Promise<SessionEntity> {
|
|
24
|
+
const entity = await this.repo.findOne({ where: { sessionId } });
|
|
25
|
+
if (!entity) throw new NotFoundException(`Session ${sessionId} not found`);
|
|
26
|
+
return entity;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** 타이틀 업데이트 */
|
|
30
|
+
async updateTitle(sessionId: string, title: string): Promise<SessionEntity> {
|
|
31
|
+
const entity = await this.findOne(sessionId);
|
|
32
|
+
entity.title = title;
|
|
33
|
+
return this.repo.save(entity);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
|
2
|
+
import { Type } from 'class-transformer';
|
|
3
|
+
import { IsArray, IsOptional, IsString, ValidateNested } from 'class-validator';
|
|
4
|
+
|
|
5
|
+
export class CreateRequirementDto {
|
|
6
|
+
@ApiProperty({ example: 'TypeScript로 마이그레이션', description: '요구 사항 내용' })
|
|
7
|
+
@IsString()
|
|
8
|
+
content!: string;
|
|
9
|
+
|
|
10
|
+
@ApiPropertyOptional({ example: 0, description: '순서 인덱스' })
|
|
11
|
+
@IsOptional()
|
|
12
|
+
orderIndex?: number;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class CreateAgentDto {
|
|
16
|
+
@ApiPropertyOptional({ enum: ['claude', 'gemini'], example: 'claude', description: '에이전트 종류' })
|
|
17
|
+
@IsOptional()
|
|
18
|
+
@IsString()
|
|
19
|
+
agentType?: string;
|
|
20
|
+
|
|
21
|
+
@ApiProperty({ example: 'developer', description: '에이전트 역할' })
|
|
22
|
+
@IsString()
|
|
23
|
+
role!: string;
|
|
24
|
+
|
|
25
|
+
@ApiPropertyOptional({ example: '시니어 백엔드 개발자', description: '커스텀 역할 설명' })
|
|
26
|
+
@IsOptional()
|
|
27
|
+
@IsString()
|
|
28
|
+
customRole?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class CreateTaskDto {
|
|
32
|
+
@ApiProperty({ example: 'API 리팩터링', description: '작업 제목' })
|
|
33
|
+
@IsString()
|
|
34
|
+
title!: string;
|
|
35
|
+
|
|
36
|
+
@ApiPropertyOptional({ example: '/Users/me/my-project', description: '작업 디렉토리' })
|
|
37
|
+
@IsOptional()
|
|
38
|
+
@IsString()
|
|
39
|
+
workingDir?: string;
|
|
40
|
+
|
|
41
|
+
@ApiPropertyOptional({ type: [CreateRequirementDto], description: '요구 사항 목록' })
|
|
42
|
+
@IsOptional()
|
|
43
|
+
@IsArray()
|
|
44
|
+
@ValidateNested({ each: true })
|
|
45
|
+
@Type(() => CreateRequirementDto)
|
|
46
|
+
requirements?: CreateRequirementDto[];
|
|
47
|
+
|
|
48
|
+
@ApiPropertyOptional({ type: [CreateAgentDto], description: '투입 에이전트 목록' })
|
|
49
|
+
@IsOptional()
|
|
50
|
+
@IsArray()
|
|
51
|
+
@ValidateNested({ each: true })
|
|
52
|
+
@Type(() => CreateAgentDto)
|
|
53
|
+
agents?: CreateAgentDto[];
|
|
54
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ApiPropertyOptional } from '@nestjs/swagger';
|
|
2
|
+
import { Type } from 'class-transformer';
|
|
3
|
+
import { IsArray, IsBoolean, IsNumber, IsOptional, ValidateNested } from 'class-validator';
|
|
4
|
+
|
|
5
|
+
export class AgentTestCodePreferenceDto {
|
|
6
|
+
@ApiPropertyOptional({ example: 1, description: '에이전트 ID' })
|
|
7
|
+
@IsNumber()
|
|
8
|
+
agentId!: number;
|
|
9
|
+
|
|
10
|
+
@ApiPropertyOptional({ example: true, description: '테스트 코드 작성 여부' })
|
|
11
|
+
@IsBoolean()
|
|
12
|
+
writeTestCode!: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export class ExecuteTaskDto {
|
|
16
|
+
@ApiPropertyOptional({ type: [AgentTestCodePreferenceDto], description: '에이전트별 테스트 코드 작성 여부' })
|
|
17
|
+
@IsOptional()
|
|
18
|
+
@IsArray()
|
|
19
|
+
@ValidateNested({ each: true })
|
|
20
|
+
@Type(() => AgentTestCodePreferenceDto)
|
|
21
|
+
agentTestCodePreferences?: AgentTestCodePreferenceDto[];
|
|
22
|
+
}
|