@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,66 @@
|
|
|
1
|
+
import { createRef } from "react";
|
|
2
|
+
|
|
3
|
+
import { render, screen } from "@testing-library/react";
|
|
4
|
+
import { describe, expect, it, vi } from "vitest";
|
|
5
|
+
|
|
6
|
+
import type { UnifiedSessionState } from "../../hooks/useUnifiedSessions";
|
|
7
|
+
import { ChatWorkspace } from "../ChatWorkspace";
|
|
8
|
+
|
|
9
|
+
vi.mock("react-markdown", () => ({
|
|
10
|
+
default: ({ children }: { children: string }) => <div data-testid="markdown">{children}</div>,
|
|
11
|
+
}));
|
|
12
|
+
vi.mock("rehype-highlight", () => ({ default: () => {} }));
|
|
13
|
+
vi.mock("remark-gfm", () => ({ default: () => {} }));
|
|
14
|
+
|
|
15
|
+
function renderWorkspace(session: UnifiedSessionState) {
|
|
16
|
+
return render(
|
|
17
|
+
<ChatWorkspace
|
|
18
|
+
selectedSession={session}
|
|
19
|
+
selectedSessionDir=""
|
|
20
|
+
overallConnectionStatus="connected"
|
|
21
|
+
currentDir=""
|
|
22
|
+
error={null}
|
|
23
|
+
inputDisabled={false}
|
|
24
|
+
bottomRef={createRef<HTMLDivElement>()}
|
|
25
|
+
modelSettingsByAgent={{}}
|
|
26
|
+
onTerminateSession={vi.fn()}
|
|
27
|
+
onSend={vi.fn()}
|
|
28
|
+
onSendMessage={vi.fn()}
|
|
29
|
+
onDirChange={vi.fn()}
|
|
30
|
+
onModelSettingsChange={vi.fn()}
|
|
31
|
+
/>,
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function session(overrides: Partial<UnifiedSessionState> = {}): UnifiedSessionState {
|
|
36
|
+
return {
|
|
37
|
+
info: { id: "session-1", title: "Claude", createdAt: "2024-01-01" },
|
|
38
|
+
messages: [],
|
|
39
|
+
streaming: "",
|
|
40
|
+
isWaiting: false,
|
|
41
|
+
messagesLoaded: true,
|
|
42
|
+
agentId: "claude",
|
|
43
|
+
...overrides,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
describe("ChatWorkspace", () => {
|
|
48
|
+
it("renders malformed permission messages as system fallback", () => {
|
|
49
|
+
renderWorkspace(
|
|
50
|
+
session({
|
|
51
|
+
messages: [
|
|
52
|
+
{
|
|
53
|
+
id: "permission-1",
|
|
54
|
+
role: "permission",
|
|
55
|
+
content: "{bad json",
|
|
56
|
+
createdAt: new Date("2024-01-01"),
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
}),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
expect(screen.getByText("system")).toBeInTheDocument();
|
|
63
|
+
expect(screen.getByText(/권한 요청을 표시할 수 없습니다/)).toBeInTheDocument();
|
|
64
|
+
expect(screen.getByText(/\{bad json/)).toBeInTheDocument();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
|
|
5
|
+
import type { DiffLine } from "./DiffHunk";
|
|
6
|
+
import { DiffHunk } from "./DiffHunk";
|
|
7
|
+
import type { ChangeType } from "./FileChangeBadge";
|
|
8
|
+
import { FileChangeBadge } from "./FileChangeBadge";
|
|
9
|
+
|
|
10
|
+
export interface DiffFile {
|
|
11
|
+
filePath: string;
|
|
12
|
+
changeType: ChangeType;
|
|
13
|
+
additions: number;
|
|
14
|
+
deletions: number;
|
|
15
|
+
lines: DiffLine[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface Props {
|
|
19
|
+
file: DiffFile;
|
|
20
|
+
defaultOpen?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function DiffFileRow({ file, defaultOpen = false }: Props) {
|
|
24
|
+
const [open, setOpen] = useState(defaultOpen);
|
|
25
|
+
|
|
26
|
+
const fileName = file.filePath.split("/").pop() ?? file.filePath;
|
|
27
|
+
const dirName = file.filePath.includes("/")
|
|
28
|
+
? file.filePath.slice(0, file.filePath.lastIndexOf("/"))
|
|
29
|
+
: "";
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div className="overflow-hidden rounded-lg border border-gray-900/[0.07] dark:border-white/[0.07]">
|
|
33
|
+
<button
|
|
34
|
+
type="button"
|
|
35
|
+
onClick={() => setOpen((p) => !p)}
|
|
36
|
+
className="flex w-full items-center gap-2 px-3 py-2 text-left hover:bg-gray-900/[0.02] dark:hover:bg-white/[0.02]"
|
|
37
|
+
>
|
|
38
|
+
<svg
|
|
39
|
+
viewBox="0 0 16 16"
|
|
40
|
+
fill="currentColor"
|
|
41
|
+
className={`h-3 w-3 shrink-0 text-gray-900/20 transition-transform dark:text-white/20 ${open ? "rotate-90" : ""}`}
|
|
42
|
+
>
|
|
43
|
+
<path fillRule="evenodd" d="M6.22 4.22a.75.75 0 011.06 0l3.25 3.25a.75.75 0 010 1.06l-3.25 3.25a.75.75 0 01-1.06-1.06L8.94 8 6.22 5.28a.75.75 0 010-1.06z" clipRule="evenodd" />
|
|
44
|
+
</svg>
|
|
45
|
+
|
|
46
|
+
<FileChangeBadge type={file.changeType} />
|
|
47
|
+
|
|
48
|
+
<span className="min-w-0 flex-1 truncate text-[12px]">
|
|
49
|
+
{dirName && <span className="text-gray-900/30 dark:text-white/30">{dirName}/</span>}
|
|
50
|
+
<span className="font-medium text-gray-900/70 dark:text-white/70">{fileName}</span>
|
|
51
|
+
</span>
|
|
52
|
+
|
|
53
|
+
<span className="shrink-0 text-[10px] font-mono">
|
|
54
|
+
{file.additions > 0 && (
|
|
55
|
+
<span className="text-emerald-600 dark:text-emerald-400">+{file.additions}</span>
|
|
56
|
+
)}
|
|
57
|
+
{file.additions > 0 && file.deletions > 0 && (
|
|
58
|
+
<span className="mx-0.5 text-gray-900/15 dark:text-white/15">/</span>
|
|
59
|
+
)}
|
|
60
|
+
{file.deletions > 0 && (
|
|
61
|
+
<span className="text-red-600 dark:text-red-400">-{file.deletions}</span>
|
|
62
|
+
)}
|
|
63
|
+
</span>
|
|
64
|
+
</button>
|
|
65
|
+
|
|
66
|
+
{open && file.lines.length > 0 && (
|
|
67
|
+
<div className="border-t border-gray-900/[0.05] dark:border-white/[0.05]">
|
|
68
|
+
<DiffHunk lines={file.lines} />
|
|
69
|
+
</div>
|
|
70
|
+
)}
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
export interface DiffLine {
|
|
4
|
+
type: "context" | "added" | "removed" | "hunk";
|
|
5
|
+
content: string;
|
|
6
|
+
oldLineNo?: number;
|
|
7
|
+
newLineNo?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
lines: DiffLine[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const LINE_STYLE: Record<DiffLine["type"], string> = {
|
|
15
|
+
context: "text-gray-900/50 dark:text-white/40",
|
|
16
|
+
added: "bg-emerald-500/[0.08] text-emerald-700 dark:text-emerald-400",
|
|
17
|
+
removed: "bg-red-500/[0.08] text-red-700 dark:text-red-400",
|
|
18
|
+
hunk: "text-purple-500/70 dark:text-purple-400/70",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const LINE_NO_STYLE: Record<DiffLine["type"], string> = {
|
|
22
|
+
context: "text-gray-900/15 dark:text-white/15",
|
|
23
|
+
added: "text-emerald-600/40 dark:text-emerald-400/40",
|
|
24
|
+
removed: "text-red-600/40 dark:text-red-400/40",
|
|
25
|
+
hunk: "text-purple-500/30 dark:text-purple-400/30",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export function DiffHunk({ lines }: Props) {
|
|
29
|
+
return (
|
|
30
|
+
<div className="overflow-x-auto rounded-lg bg-gray-950/[0.03] dark:bg-white/[0.03]">
|
|
31
|
+
<table className="w-full border-collapse font-mono text-[11px] leading-relaxed">
|
|
32
|
+
<tbody>
|
|
33
|
+
{lines.map((line, i) => (
|
|
34
|
+
<tr key={i} className={LINE_STYLE[line.type]}>
|
|
35
|
+
{line.type === "hunk" ? (
|
|
36
|
+
<td colSpan={3} className="px-3 py-0.5 text-purple-500/70 dark:text-purple-400/70 select-none">
|
|
37
|
+
{line.content}
|
|
38
|
+
</td>
|
|
39
|
+
) : (
|
|
40
|
+
<>
|
|
41
|
+
<td className={`w-10 select-none px-2 py-0.5 text-right ${LINE_NO_STYLE[line.type]}`}>
|
|
42
|
+
{line.oldLineNo ?? ""}
|
|
43
|
+
</td>
|
|
44
|
+
<td className={`w-10 select-none px-2 py-0.5 text-right ${LINE_NO_STYLE[line.type]}`}>
|
|
45
|
+
{line.newLineNo ?? ""}
|
|
46
|
+
</td>
|
|
47
|
+
<td className="px-3 py-0.5 whitespace-pre">
|
|
48
|
+
<span className="mr-1 select-none opacity-50">
|
|
49
|
+
{line.type === "added" ? "+" : line.type === "removed" ? "-" : " "}
|
|
50
|
+
</span>
|
|
51
|
+
{line.content}
|
|
52
|
+
</td>
|
|
53
|
+
</>
|
|
54
|
+
)}
|
|
55
|
+
</tr>
|
|
56
|
+
))}
|
|
57
|
+
</tbody>
|
|
58
|
+
</table>
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
export type ChangeType = "added" | "modified" | "deleted" | "renamed";
|
|
4
|
+
|
|
5
|
+
const CONFIG: Record<ChangeType, { label: string; className: string }> = {
|
|
6
|
+
added: { label: "추가", className: "bg-emerald-500/10 text-emerald-600 border-emerald-500/20 dark:text-emerald-400" },
|
|
7
|
+
modified: { label: "수정", className: "bg-blue-500/10 text-blue-600 border-blue-500/20 dark:text-blue-400" },
|
|
8
|
+
deleted: { label: "삭제", className: "bg-red-500/10 text-red-600 border-red-500/20 dark:text-red-400" },
|
|
9
|
+
renamed: { label: "이동", className: "bg-amber-500/10 text-amber-600 border-amber-500/20 dark:text-amber-400" },
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
type: ChangeType;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function FileChangeBadge({ type }: Props) {
|
|
17
|
+
const { label, className } = CONFIG[type];
|
|
18
|
+
return (
|
|
19
|
+
<span className={`inline-flex items-center rounded-md border px-1.5 py-0.5 text-[10px] font-medium ${className}`}>
|
|
20
|
+
{label}
|
|
21
|
+
</span>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import userEvent from "@testing-library/user-event";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { DiffFileRow } from "../DiffFileRow";
|
|
6
|
+
|
|
7
|
+
const file = {
|
|
8
|
+
filePath: "src/features/App.tsx",
|
|
9
|
+
changeType: "modified" as const,
|
|
10
|
+
additions: 2,
|
|
11
|
+
deletions: 1,
|
|
12
|
+
lines: [
|
|
13
|
+
{ type: "hunk" as const, content: "@@" },
|
|
14
|
+
{ type: "added" as const, content: "new line", newLineNo: 10 },
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
describe("DiffFileRow", () => {
|
|
19
|
+
it("renders file metadata and opens diff by default when requested", () => {
|
|
20
|
+
render(<DiffFileRow file={file} defaultOpen={true} />);
|
|
21
|
+
|
|
22
|
+
expect(screen.getByText("src/features/")).toBeInTheDocument();
|
|
23
|
+
expect(screen.getByText("App.tsx")).toBeInTheDocument();
|
|
24
|
+
expect(screen.getByText("수정")).toBeInTheDocument();
|
|
25
|
+
expect(screen.getByText("+2")).toBeInTheDocument();
|
|
26
|
+
expect(screen.getByText("-1")).toBeInTheDocument();
|
|
27
|
+
expect(screen.getByText("new line")).toBeInTheDocument();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("toggles diff contents when clicked", async () => {
|
|
31
|
+
const user = userEvent.setup();
|
|
32
|
+
render(<DiffFileRow file={file} />);
|
|
33
|
+
|
|
34
|
+
expect(screen.queryByText("new line")).not.toBeInTheDocument();
|
|
35
|
+
await user.click(screen.getByRole("button"));
|
|
36
|
+
expect(screen.getByText("new line")).toBeInTheDocument();
|
|
37
|
+
await user.click(screen.getByRole("button"));
|
|
38
|
+
expect(screen.queryByText("new line")).not.toBeInTheDocument();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { DiffHunk } from "../DiffHunk";
|
|
5
|
+
|
|
6
|
+
describe("DiffHunk", () => {
|
|
7
|
+
it("renders hunk, context, added, and removed lines with line numbers", () => {
|
|
8
|
+
render(
|
|
9
|
+
<DiffHunk
|
|
10
|
+
lines={[
|
|
11
|
+
{ type: "hunk", content: "@@ -1,2 +1,2 @@" },
|
|
12
|
+
{ type: "context", content: "const a = 1;", oldLineNo: 1, newLineNo: 1 },
|
|
13
|
+
{ type: "removed", content: "const b = 2;", oldLineNo: 2 },
|
|
14
|
+
{ type: "added", content: "const b = 3;", newLineNo: 2 },
|
|
15
|
+
]}
|
|
16
|
+
/>,
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
expect(screen.getByText("@@ -1,2 +1,2 @@")).toBeInTheDocument();
|
|
20
|
+
expect(screen.getByText("const a = 1;")).toBeInTheDocument();
|
|
21
|
+
expect(screen.getByText("const b = 2;")).toBeInTheDocument();
|
|
22
|
+
expect(screen.getByText("const b = 3;")).toBeInTheDocument();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { render, screen } from "@testing-library/react";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
|
|
4
|
+
import { FileChangeBadge } from "../FileChangeBadge";
|
|
5
|
+
|
|
6
|
+
describe("FileChangeBadge", () => {
|
|
7
|
+
it.each([
|
|
8
|
+
["added", "추가"],
|
|
9
|
+
["modified", "수정"],
|
|
10
|
+
["deleted", "삭제"],
|
|
11
|
+
["renamed", "이동"],
|
|
12
|
+
] as const)("renders %s label", (type, label) => {
|
|
13
|
+
render(<FileChangeBadge type={type} />);
|
|
14
|
+
expect(screen.getByText(label)).toBeInTheDocument();
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SERVER_URL } from "@/lib/constants";
|
|
2
|
+
|
|
3
|
+
export interface DirListResult {
|
|
4
|
+
path: string;
|
|
5
|
+
dirs: string[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export async function fetchDirs(path?: string): Promise<DirListResult> {
|
|
9
|
+
const url = new URL(`${SERVER_URL}/fs/dirs`);
|
|
10
|
+
if (path) url.searchParams.set("path", path);
|
|
11
|
+
const res = await fetch(url.toString());
|
|
12
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
13
|
+
return res.json();
|
|
14
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useState } from "react";
|
|
4
|
+
|
|
5
|
+
import { fetchDirs } from "../api/fs.api";
|
|
6
|
+
|
|
7
|
+
export interface DirBrowserState {
|
|
8
|
+
open: boolean;
|
|
9
|
+
currentPath: string;
|
|
10
|
+
dirs: string[];
|
|
11
|
+
loading: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function useDirBrowser() {
|
|
15
|
+
const [open, setOpen] = useState(false);
|
|
16
|
+
const [currentPath, setCurrentPath] = useState("");
|
|
17
|
+
const [dirs, setDirs] = useState<string[]>([]);
|
|
18
|
+
const [loading, setLoading] = useState(false);
|
|
19
|
+
|
|
20
|
+
const navigate = useCallback(async (path?: string) => {
|
|
21
|
+
setLoading(true);
|
|
22
|
+
try {
|
|
23
|
+
const result = await fetchDirs(path);
|
|
24
|
+
setCurrentPath(result.path);
|
|
25
|
+
setDirs(result.dirs);
|
|
26
|
+
} catch {
|
|
27
|
+
setDirs([]);
|
|
28
|
+
} finally {
|
|
29
|
+
setLoading(false);
|
|
30
|
+
}
|
|
31
|
+
}, []);
|
|
32
|
+
|
|
33
|
+
const openBrowser = useCallback(
|
|
34
|
+
async (initialPath?: string) => {
|
|
35
|
+
setOpen(true);
|
|
36
|
+
await navigate(initialPath || undefined);
|
|
37
|
+
},
|
|
38
|
+
[navigate],
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const closeBrowser = useCallback(() => setOpen(false), []);
|
|
42
|
+
|
|
43
|
+
const navigateUp = useCallback(() => {
|
|
44
|
+
const sep = currentPath.includes("/") ? "/" : "\\";
|
|
45
|
+
const idx = currentPath.lastIndexOf(sep);
|
|
46
|
+
if (idx > 0) void navigate(currentPath.slice(0, idx));
|
|
47
|
+
}, [currentPath, navigate]);
|
|
48
|
+
|
|
49
|
+
return { open, currentPath, dirs, loading, navigate, openBrowser, closeBrowser, navigateUp };
|
|
50
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { deleteHarness, fetchAllHarnesses, fetchHarness, saveHarness } from "../harness.api";
|
|
4
|
+
|
|
5
|
+
const mockFetch = vi.fn();
|
|
6
|
+
|
|
7
|
+
beforeEach(() => { vi.stubGlobal("fetch", mockFetch); });
|
|
8
|
+
afterEach(() => { vi.unstubAllGlobals(); });
|
|
9
|
+
|
|
10
|
+
function ok(body?: unknown) {
|
|
11
|
+
return Promise.resolve({ ok: true, json: () => Promise.resolve(body) } as Response);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function err(status: number) {
|
|
15
|
+
return Promise.resolve({ ok: false, status } as Response);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe("harness api", () => {
|
|
19
|
+
it("fetches all harnesses", async () => {
|
|
20
|
+
const body = [{ role: "frontend", ext: "md", content: "rules" }];
|
|
21
|
+
mockFetch.mockReturnValueOnce(ok(body));
|
|
22
|
+
|
|
23
|
+
await expect(fetchAllHarnesses()).resolves.toEqual(body);
|
|
24
|
+
expect(mockFetch).toHaveBeenCalledWith(expect.stringContaining("/harness"));
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("fetches one harness by role", async () => {
|
|
28
|
+
const body = { role: "backend", ext: "tsx", content: "code" };
|
|
29
|
+
mockFetch.mockReturnValueOnce(ok(body));
|
|
30
|
+
|
|
31
|
+
await expect(fetchHarness("backend")).resolves.toEqual(body);
|
|
32
|
+
expect(mockFetch).toHaveBeenCalledWith(expect.stringContaining("/harness/backend"));
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("saves harness content with PUT JSON", async () => {
|
|
36
|
+
const body = { role: "doc", ext: "md", content: "updated" };
|
|
37
|
+
mockFetch.mockReturnValueOnce(ok(body));
|
|
38
|
+
|
|
39
|
+
await expect(saveHarness("doc", "updated", "md")).resolves.toEqual(body);
|
|
40
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
41
|
+
expect.stringContaining("/harness/doc"),
|
|
42
|
+
{
|
|
43
|
+
method: "PUT",
|
|
44
|
+
headers: { "Content-Type": "application/json" },
|
|
45
|
+
body: JSON.stringify({ content: "updated", ext: "md" }),
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("deletes harness by role", async () => {
|
|
51
|
+
mockFetch.mockReturnValueOnce(Promise.resolve({ ok: true } as Response));
|
|
52
|
+
|
|
53
|
+
await deleteHarness("operation");
|
|
54
|
+
expect(mockFetch).toHaveBeenCalledWith(
|
|
55
|
+
expect.stringContaining("/harness/operation"),
|
|
56
|
+
{ method: "DELETE" },
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("throws for non-ok fetch/save responses", async () => {
|
|
61
|
+
mockFetch.mockReturnValueOnce(err(404));
|
|
62
|
+
await expect(fetchHarness("other")).rejects.toThrow("HTTP 404");
|
|
63
|
+
|
|
64
|
+
mockFetch.mockReturnValueOnce(err(500));
|
|
65
|
+
await expect(saveHarness("other", "x", "md")).rejects.toThrow("HTTP 500");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("throws for non-ok delete responses", async () => {
|
|
69
|
+
mockFetch.mockReturnValueOnce(err(409));
|
|
70
|
+
|
|
71
|
+
await expect(deleteHarness("operation")).rejects.toThrow("HTTP 409");
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { SERVER_URL } from "@/lib/constants";
|
|
2
|
+
|
|
3
|
+
export type HarnessRole = "common" | "frontend" | "backend" | "doc" | "operation" | "other";
|
|
4
|
+
export type HarnessExt = "md" | "tsx";
|
|
5
|
+
|
|
6
|
+
export interface Harness {
|
|
7
|
+
role: HarnessRole;
|
|
8
|
+
ext: HarnessExt;
|
|
9
|
+
content: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export const HARNESS_ROLES: { role: HarnessRole; label: string }[] = [
|
|
13
|
+
{ role: "common", label: "공통" },
|
|
14
|
+
{ role: "frontend", label: "Frontend" },
|
|
15
|
+
{ role: "backend", label: "Backend" },
|
|
16
|
+
{ role: "doc", label: "Doc" },
|
|
17
|
+
{ role: "operation", label: "Operation" },
|
|
18
|
+
{ role: "other", label: "Other" },
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
export async function fetchAllHarnesses(): Promise<Harness[]> {
|
|
22
|
+
const res = await fetch(`${SERVER_URL}/harness`);
|
|
23
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
24
|
+
return res.json();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function fetchHarness(role: HarnessRole): Promise<Harness> {
|
|
28
|
+
const res = await fetch(`${SERVER_URL}/harness/${role}`);
|
|
29
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
30
|
+
return res.json();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export async function saveHarness(role: HarnessRole, content: string, ext: HarnessExt): Promise<Harness> {
|
|
34
|
+
const res = await fetch(`${SERVER_URL}/harness/${role}`, {
|
|
35
|
+
method: "PUT",
|
|
36
|
+
headers: { "Content-Type": "application/json" },
|
|
37
|
+
body: JSON.stringify({ content, ext }),
|
|
38
|
+
});
|
|
39
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
40
|
+
return res.json();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export async function deleteHarness(role: HarnessRole): Promise<void> {
|
|
44
|
+
const res = await fetch(`${SERVER_URL}/harness/${role}`, { method: "DELETE" });
|
|
45
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
46
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
|
|
4
|
+
import * as harnessApi from "../../api/harness.api";
|
|
5
|
+
import { useHarness } from "../useHarness";
|
|
6
|
+
|
|
7
|
+
vi.mock("../../api/harness.api", () => ({
|
|
8
|
+
fetchHarness: vi.fn(),
|
|
9
|
+
saveHarness: vi.fn(),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
const mockFetchHarness = vi.mocked(harnessApi.fetchHarness);
|
|
13
|
+
const mockSaveHarness = vi.mocked(harnessApi.saveHarness);
|
|
14
|
+
|
|
15
|
+
afterEach(() => { vi.clearAllMocks(); });
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
mockFetchHarness.mockResolvedValue({ role: "backend", ext: "md", content: "" });
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe("useHarness", () => {
|
|
22
|
+
it("does not load when role is null", () => {
|
|
23
|
+
const { result } = renderHook(() => useHarness(null));
|
|
24
|
+
|
|
25
|
+
expect(result.current.harness).toBeNull();
|
|
26
|
+
expect(mockFetchHarness).not.toHaveBeenCalled();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("loads harness for a role and resets dirty state", async () => {
|
|
30
|
+
mockFetchHarness.mockResolvedValueOnce({ role: "frontend", ext: "tsx", content: "hello" });
|
|
31
|
+
const { result } = renderHook(() => useHarness("frontend"));
|
|
32
|
+
|
|
33
|
+
expect(result.current.loading).toBe(true);
|
|
34
|
+
await waitFor(() => expect(result.current.loading).toBe(false));
|
|
35
|
+
expect(result.current.content).toBe("hello");
|
|
36
|
+
expect(result.current.ext).toBe("tsx");
|
|
37
|
+
expect(result.current.dirty).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("marks dirty when content or extension changes", () => {
|
|
41
|
+
const { result } = renderHook(() => useHarness(null));
|
|
42
|
+
|
|
43
|
+
act(() => {
|
|
44
|
+
result.current.setContent("new");
|
|
45
|
+
result.current.setExt("tsx");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
expect(result.current.content).toBe("new");
|
|
49
|
+
expect(result.current.ext).toBe("tsx");
|
|
50
|
+
expect(result.current.dirty).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("saves current content and clears dirty", async () => {
|
|
54
|
+
mockSaveHarness.mockResolvedValueOnce({ role: "backend", ext: "md", content: "saved" });
|
|
55
|
+
const { result } = renderHook(() => useHarness("backend"));
|
|
56
|
+
|
|
57
|
+
act(() => { result.current.setContent("saved"); });
|
|
58
|
+
await act(async () => { await result.current.save(); });
|
|
59
|
+
|
|
60
|
+
expect(mockSaveHarness).toHaveBeenCalledWith("backend", "saved", "md");
|
|
61
|
+
expect(result.current.harness).toEqual({ role: "backend", ext: "md", content: "saved" });
|
|
62
|
+
expect(result.current.saving).toBe(false);
|
|
63
|
+
expect(result.current.dirty).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useState } from "react";
|
|
4
|
+
|
|
5
|
+
import type { Harness, HarnessExt, HarnessRole } from "../api/harness.api";
|
|
6
|
+
import { fetchHarness, saveHarness } from "../api/harness.api";
|
|
7
|
+
|
|
8
|
+
export function useHarness(role: HarnessRole | null) {
|
|
9
|
+
const [harness, setHarness] = useState<Harness | null>(null);
|
|
10
|
+
const [content, setContent] = useState("");
|
|
11
|
+
const [ext, setExt] = useState<HarnessExt>("md");
|
|
12
|
+
const [loading, setLoading] = useState(false);
|
|
13
|
+
const [saving, setSaving] = useState(false);
|
|
14
|
+
const [dirty, setDirty] = useState(false);
|
|
15
|
+
|
|
16
|
+
const load = useCallback(async (r: HarnessRole) => {
|
|
17
|
+
setLoading(true);
|
|
18
|
+
try {
|
|
19
|
+
const data = await fetchHarness(r);
|
|
20
|
+
setHarness(data);
|
|
21
|
+
setContent(data.content);
|
|
22
|
+
setExt(data.ext);
|
|
23
|
+
setDirty(false);
|
|
24
|
+
} finally {
|
|
25
|
+
setLoading(false);
|
|
26
|
+
}
|
|
27
|
+
}, []);
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (role) void load(role);
|
|
31
|
+
}, [role, load]);
|
|
32
|
+
|
|
33
|
+
const handleContentChange = (val: string) => {
|
|
34
|
+
setContent(val);
|
|
35
|
+
setDirty(true);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const handleExtChange = (newExt: HarnessExt) => {
|
|
39
|
+
setExt(newExt);
|
|
40
|
+
setDirty(true);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const save = useCallback(async () => {
|
|
44
|
+
if (!role) return;
|
|
45
|
+
setSaving(true);
|
|
46
|
+
try {
|
|
47
|
+
const saved = await saveHarness(role, content, ext);
|
|
48
|
+
setHarness(saved);
|
|
49
|
+
setDirty(false);
|
|
50
|
+
} finally {
|
|
51
|
+
setSaving(false);
|
|
52
|
+
}
|
|
53
|
+
}, [role, content, ext]);
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
harness,
|
|
57
|
+
content,
|
|
58
|
+
ext,
|
|
59
|
+
loading,
|
|
60
|
+
saving,
|
|
61
|
+
dirty,
|
|
62
|
+
setContent: handleContentChange,
|
|
63
|
+
setExt: handleExtChange,
|
|
64
|
+
save,
|
|
65
|
+
};
|
|
66
|
+
}
|