@mandujs/cli 0.1.0 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mandujs/cli",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Agent-Native Fullstack Framework - 에이전트가 코딩해도 아키텍처가 무너지지 않는 개발 OS",
5
5
  "type": "module",
6
6
  "main": "./src/main.ts",
@@ -32,7 +32,7 @@
32
32
  "access": "public"
33
33
  },
34
34
  "dependencies": {
35
- "@mandujs/core": "^0.1.0"
35
+ "@mandujs/core": "^0.2.0"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "bun": ">=1.0.0"
@@ -1,4 +1,4 @@
1
- import { loadManifest, startServer, registerApiHandler, registerPageLoader } from "@mandu/core";
1
+ import { loadManifest, startServer, registerApiHandler, registerPageLoader } from "@mandujs/core";
2
2
  import { resolveFromCwd } from "../util/fs";
3
3
  import path from "path";
4
4
 
@@ -1,4 +1,4 @@
1
- import { loadManifest, generateRoutes, buildGenerateReport, printReportSummary, writeReport } from "@mandu/core";
1
+ import { loadManifest, generateRoutes, buildGenerateReport, printReportSummary, writeReport } from "@mandujs/core";
2
2
  import { resolveFromCwd, getRootDir } from "../util/fs";
3
3
 
4
4
  export async function generateApply(): Promise<boolean> {
@@ -1,12 +1,27 @@
1
- import { loadManifest, runGuardCheck, buildGuardReport, printReportSummary, writeReport } from "@mandu/core";
1
+ import {
2
+ loadManifest,
3
+ runGuardCheck,
4
+ buildGuardReport,
5
+ printReportSummary,
6
+ writeReport,
7
+ runAutoCorrect,
8
+ isAutoCorrectableViolation,
9
+ } from "@mandujs/core";
2
10
  import { resolveFromCwd, getRootDir } from "../util/fs";
3
11
 
4
- export async function guardCheck(): Promise<boolean> {
12
+ export interface GuardCheckOptions {
13
+ autoCorrect?: boolean;
14
+ }
15
+
16
+ export async function guardCheck(options: GuardCheckOptions = {}): Promise<boolean> {
17
+ const { autoCorrect = true } = options;
18
+
5
19
  const specPath = resolveFromCwd("spec/routes.manifest.json");
6
20
  const rootDir = getRootDir();
7
21
 
8
22
  console.log(`🥟 Mandu Guard`);
9
- console.log(`📄 Spec 파일: ${specPath}\n`);
23
+ console.log(`📄 Spec 파일: ${specPath}`);
24
+ console.log(`🔧 Auto-correct: ${autoCorrect ? "ON" : "OFF"}\n`);
10
25
 
11
26
  const result = await loadManifest(specPath);
12
27
 
@@ -19,7 +34,55 @@ export async function guardCheck(): Promise<boolean> {
19
34
  console.log(`✅ Spec 로드 완료`);
20
35
  console.log(`🔍 Guard 검사 중...\n`);
21
36
 
22
- const checkResult = await runGuardCheck(result.data, rootDir);
37
+ let checkResult = await runGuardCheck(result.data, rootDir);
38
+
39
+ // Auto-correct 시도
40
+ if (!checkResult.passed && autoCorrect) {
41
+ const autoCorrectableCount = checkResult.violations.filter(isAutoCorrectableViolation).length;
42
+
43
+ if (autoCorrectableCount > 0) {
44
+ console.log(`⚠️ ${checkResult.violations.length}개 위반 감지 (자동 수정 가능: ${autoCorrectableCount}개)`);
45
+ console.log(`🔄 Auto-correct 실행 중...\n`);
46
+
47
+ const autoCorrectResult = await runAutoCorrect(
48
+ checkResult.violations,
49
+ result.data,
50
+ rootDir
51
+ );
52
+
53
+ // 수행된 단계 출력
54
+ for (const step of autoCorrectResult.steps) {
55
+ const icon = step.success ? "✅" : "❌";
56
+ console.log(` ${icon} [${step.action}] ${step.message}`);
57
+ }
58
+
59
+ if (autoCorrectResult.fixed) {
60
+ console.log(`\n✅ Auto-correct 완료 (${autoCorrectResult.retriedCount}회 재시도)`);
61
+
62
+ // 최종 Guard 재검사
63
+ checkResult = await runGuardCheck(result.data, rootDir);
64
+ } else {
65
+ console.log(`\n⚠️ 일부 위반은 수동 수정이 필요합니다:`);
66
+
67
+ const manualViolations = autoCorrectResult.remainingViolations.filter(
68
+ (v) => !isAutoCorrectableViolation(v)
69
+ );
70
+
71
+ for (const v of manualViolations) {
72
+ console.log(` - [${v.ruleId}] ${v.file}`);
73
+ console.log(` 💡 ${v.suggestion}`);
74
+ }
75
+
76
+ // 남은 위반으로 업데이트
77
+ checkResult = {
78
+ passed: autoCorrectResult.remainingViolations.length === 0,
79
+ violations: autoCorrectResult.remainingViolations,
80
+ };
81
+ }
82
+
83
+ console.log("");
84
+ }
85
+ }
23
86
 
24
87
  const report = buildGuardReport(checkResult);
25
88
  printReportSummary(report);
@@ -29,11 +92,11 @@ export async function guardCheck(): Promise<boolean> {
29
92
  console.log(`📋 Report 저장: ${reportPath}`);
30
93
 
31
94
  if (!checkResult.passed) {
32
- console.log(`\n❌ guard 실패: ${checkResult.violations.length}개 위반 발견`);
95
+ console.log(`\n❌ Guard 실패: ${checkResult.violations.length}개 위반 발견`);
33
96
  return false;
34
97
  }
35
98
 
36
- console.log(`\n✅ guard 통과`);
99
+ console.log(`\n✅ Guard 통과`);
37
100
  console.log(`💡 다음 단계: bunx mandu dev`);
38
101
 
39
102
  return true;
@@ -1,4 +1,4 @@
1
- import { loadManifest, writeLock, readLock } from "@mandu/core";
1
+ import { loadManifest, writeLock, readLock } from "@mandujs/core";
2
2
  import { resolveFromCwd } from "../util/fs";
3
3
  import path from "path";
4
4
 
package/src/main.ts CHANGED
@@ -19,10 +19,11 @@ Commands:
19
19
  dev 개발 서버 실행
20
20
 
21
21
  Options:
22
- --name <name> init 시 프로젝트 이름 (기본: my-mandu-app)
23
- --file <path> spec-upsert 시 사용할 spec 파일 경로
24
- --port <port> dev 서버 포트 (기본: 3000)
25
- --help, -h 도움말 표시
22
+ --name <name> init 시 프로젝트 이름 (기본: my-mandu-app)
23
+ --file <path> spec-upsert 시 사용할 spec 파일 경로
24
+ --port <port> dev 서버 포트 (기본: 3000)
25
+ --no-auto-correct guard 시 자동 수정 비활성화
26
+ --help, -h 도움말 표시
26
27
 
27
28
  Examples:
28
29
  bunx mandu init --name my-app
@@ -83,7 +84,9 @@ async function main(): Promise<void> {
83
84
  break;
84
85
 
85
86
  case "guard":
86
- success = await guardCheck();
87
+ success = await guardCheck({
88
+ autoCorrect: options["no-auto-correct"] !== "true",
89
+ });
87
90
  break;
88
91
 
89
92
  case "dev":
@@ -1,4 +1,4 @@
1
- import { loadManifest, startServer, registerApiHandler, registerPageLoader } from "@mandu/core";
1
+ import { loadManifest, startServer, registerApiHandler, registerPageLoader } from "@mandujs/core";
2
2
  import path from "path";
3
3
 
4
4
  const SPEC_PATH = path.resolve(import.meta.dir, "../../spec/routes.manifest.json");
@@ -6,15 +6,17 @@
6
6
  "dev": "mandu dev",
7
7
  "generate": "mandu generate",
8
8
  "guard": "mandu guard",
9
- "spec": "mandu spec-upsert"
9
+ "spec": "mandu spec-upsert",
10
+ "test": "bun test",
11
+ "test:watch": "bun test --watch"
10
12
  },
11
13
  "dependencies": {
12
- "@mandujs/core": "^0.1.0",
14
+ "@mandujs/core": "^0.2.0",
13
15
  "react": "^18.2.0",
14
16
  "react-dom": "^18.2.0"
15
17
  },
16
18
  "devDependencies": {
17
- "@mandujs/cli": "^0.1.0",
19
+ "@mandujs/cli": "^0.2.0",
18
20
  "@types/react": "^18.2.0",
19
21
  "@types/react-dom": "^18.2.0",
20
22
  "typescript": "^5.0.0"
@@ -0,0 +1,58 @@
1
+ // Mandu Example Test
2
+ // 이 파일은 테스트 작성 방법을 보여주는 예제입니다.
3
+
4
+ import { describe, it, expect } from "bun:test";
5
+ import { createTestRequest, parseJsonResponse, assertStatus } from "./helpers";
6
+
7
+ describe("Example Tests", () => {
8
+ describe("Basic Assertions", () => {
9
+ it("should pass basic equality test", () => {
10
+ expect(1 + 1).toBe(2);
11
+ });
12
+
13
+ it("should pass object equality test", () => {
14
+ const obj = { status: "ok", data: { message: "hello" } };
15
+ expect(obj).toEqual({
16
+ status: "ok",
17
+ data: { message: "hello" },
18
+ });
19
+ });
20
+ });
21
+
22
+ describe("Test Helpers", () => {
23
+ it("should create test request", () => {
24
+ const req = createTestRequest("http://localhost:3000/api/test", {
25
+ method: "POST",
26
+ body: { name: "test" },
27
+ });
28
+
29
+ expect(req.method).toBe("POST");
30
+ expect(req.url).toBe("http://localhost:3000/api/test");
31
+ });
32
+
33
+ it("should parse JSON response", async () => {
34
+ const mockResponse = new Response(
35
+ JSON.stringify({ status: "ok" }),
36
+ { status: 200 }
37
+ );
38
+
39
+ const data = await parseJsonResponse<{ status: string }>(mockResponse);
40
+ expect(data.status).toBe("ok");
41
+ });
42
+ });
43
+ });
44
+
45
+ // API 핸들러 테스트 예제 (실제 핸들러 import 후 사용)
46
+ // import handler from "../apps/server/generated/routes/health.route";
47
+ //
48
+ // describe("API: GET /api/health", () => {
49
+ // it("should return 200 with status ok", async () => {
50
+ // const req = createTestRequest("http://localhost:3000/api/health");
51
+ // const response = handler(req, {});
52
+ //
53
+ // assertStatus(response, 200);
54
+ //
55
+ // const data = await parseJsonResponse<{ status: string }>(response);
56
+ // expect(data.status).toBe("ok");
57
+ // });
58
+ // });
@@ -0,0 +1,52 @@
1
+ // Mandu Test Helpers
2
+ // 테스트에서 사용할 유틸리티 함수들
3
+
4
+ import type { Request } from "bun";
5
+
6
+ /**
7
+ * API 핸들러 테스트용 Request 생성
8
+ */
9
+ export function createTestRequest(
10
+ url: string,
11
+ options?: {
12
+ method?: string;
13
+ body?: unknown;
14
+ headers?: Record<string, string>;
15
+ }
16
+ ): Request {
17
+ const { method = "GET", body, headers = {} } = options || {};
18
+
19
+ return new Request(url, {
20
+ method,
21
+ headers: {
22
+ "Content-Type": "application/json",
23
+ ...headers,
24
+ },
25
+ body: body ? JSON.stringify(body) : undefined,
26
+ });
27
+ }
28
+
29
+ /**
30
+ * Response를 JSON으로 파싱
31
+ */
32
+ export async function parseJsonResponse<T = unknown>(response: Response): Promise<T> {
33
+ return response.json() as Promise<T>;
34
+ }
35
+
36
+ /**
37
+ * Response 상태 검증
38
+ */
39
+ export function assertStatus(response: Response, expectedStatus: number): void {
40
+ if (response.status !== expectedStatus) {
41
+ throw new Error(
42
+ `Expected status ${expectedStatus}, got ${response.status}`
43
+ );
44
+ }
45
+ }
46
+
47
+ /**
48
+ * 테스트용 라우트 파라미터 생성
49
+ */
50
+ export function createParams(params: Record<string, string>): Record<string, string> {
51
+ return params;
52
+ }
@@ -0,0 +1,9 @@
1
+ // Mandu Test Setup
2
+ // Bun 테스트 환경 설정
3
+
4
+ // 테스트 타임아웃 설정 (필요 시)
5
+ // import { setDefaultTimeout } from "bun:test";
6
+ // setDefaultTimeout(10000);
7
+
8
+ // 환경 변수 설정
9
+ process.env.NODE_ENV = "test";