@tuan_son.dinh/gsd 2.6.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/LICENSE +21 -0
- package/README.md +453 -0
- package/dist/app-paths.d.ts +4 -0
- package/dist/app-paths.js +6 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +269 -0
- package/dist/loader.d.ts +2 -0
- package/dist/loader.js +70 -0
- package/dist/logo.d.ts +16 -0
- package/dist/logo.js +25 -0
- package/dist/onboarding.d.ts +43 -0
- package/dist/onboarding.js +418 -0
- package/dist/pi-migration.d.ts +14 -0
- package/dist/pi-migration.js +57 -0
- package/dist/resource-loader.d.ts +22 -0
- package/dist/resource-loader.js +60 -0
- package/dist/tool-bootstrap.d.ts +4 -0
- package/dist/tool-bootstrap.js +74 -0
- package/dist/wizard.d.ts +7 -0
- package/dist/wizard.js +25 -0
- package/package.json +60 -0
- package/patches/@mariozechner+pi-coding-agent+0.57.1.patch +108 -0
- package/patches/@mariozechner+pi-tui+0.57.1.patch +47 -0
- package/pkg/dist/modes/interactive/theme/dark.json +85 -0
- package/pkg/dist/modes/interactive/theme/light.json +84 -0
- package/pkg/dist/modes/interactive/theme/theme-schema.json +335 -0
- package/pkg/dist/modes/interactive/theme/theme.d.ts +78 -0
- package/pkg/dist/modes/interactive/theme/theme.d.ts.map +1 -0
- package/pkg/dist/modes/interactive/theme/theme.js +949 -0
- package/pkg/dist/modes/interactive/theme/theme.js.map +1 -0
- package/pkg/package.json +8 -0
- package/scripts/postinstall.js +127 -0
- package/src/resources/GSD-WORKFLOW.md +661 -0
- package/src/resources/agents/researcher.md +29 -0
- package/src/resources/agents/scout.md +56 -0
- package/src/resources/agents/worker.md +31 -0
- package/src/resources/extensions/ask-user-questions.ts +249 -0
- package/src/resources/extensions/bg-shell/index.ts +2808 -0
- package/src/resources/extensions/browser-tools/BROWSER-TOOLS-V2-PROPOSAL.md +1277 -0
- package/src/resources/extensions/browser-tools/core.js +1057 -0
- package/src/resources/extensions/browser-tools/index.ts +4989 -0
- package/src/resources/extensions/browser-tools/package.json +20 -0
- package/src/resources/extensions/context7/index.ts +428 -0
- package/src/resources/extensions/context7/package.json +11 -0
- package/src/resources/extensions/get-secrets-from-user.ts +352 -0
- package/src/resources/extensions/google-search/index.ts +323 -0
- package/src/resources/extensions/google-search/package.json +9 -0
- package/src/resources/extensions/gsd/activity-log.ts +69 -0
- package/src/resources/extensions/gsd/auto.ts +2744 -0
- package/src/resources/extensions/gsd/commands.ts +313 -0
- package/src/resources/extensions/gsd/crash-recovery.ts +85 -0
- package/src/resources/extensions/gsd/dashboard-overlay.ts +521 -0
- package/src/resources/extensions/gsd/docs/preferences-reference.md +176 -0
- package/src/resources/extensions/gsd/doctor.ts +690 -0
- package/src/resources/extensions/gsd/files.ts +732 -0
- package/src/resources/extensions/gsd/git-service.ts +597 -0
- package/src/resources/extensions/gsd/gitignore.ts +168 -0
- package/src/resources/extensions/gsd/guided-flow.ts +817 -0
- package/src/resources/extensions/gsd/index.ts +558 -0
- package/src/resources/extensions/gsd/metrics.ts +374 -0
- package/src/resources/extensions/gsd/migrate/command.ts +218 -0
- package/src/resources/extensions/gsd/migrate/index.ts +42 -0
- package/src/resources/extensions/gsd/migrate/parser.ts +323 -0
- package/src/resources/extensions/gsd/migrate/parsers.ts +624 -0
- package/src/resources/extensions/gsd/migrate/preview.ts +48 -0
- package/src/resources/extensions/gsd/migrate/transformer.ts +346 -0
- package/src/resources/extensions/gsd/migrate/types.ts +370 -0
- package/src/resources/extensions/gsd/migrate/validator.ts +55 -0
- package/src/resources/extensions/gsd/migrate/writer.ts +539 -0
- package/src/resources/extensions/gsd/observability-validator.ts +408 -0
- package/src/resources/extensions/gsd/package.json +11 -0
- package/src/resources/extensions/gsd/paths.ts +308 -0
- package/src/resources/extensions/gsd/preferences.ts +757 -0
- package/src/resources/extensions/gsd/prompt-loader.ts +50 -0
- package/src/resources/extensions/gsd/prompts/complete-milestone.md +25 -0
- package/src/resources/extensions/gsd/prompts/complete-slice.md +29 -0
- package/src/resources/extensions/gsd/prompts/discuss.md +189 -0
- package/src/resources/extensions/gsd/prompts/doctor-heal.md +29 -0
- package/src/resources/extensions/gsd/prompts/execute-task.md +61 -0
- package/src/resources/extensions/gsd/prompts/guided-complete-slice.md +1 -0
- package/src/resources/extensions/gsd/prompts/guided-discuss-milestone.md +3 -0
- package/src/resources/extensions/gsd/prompts/guided-discuss-slice.md +59 -0
- package/src/resources/extensions/gsd/prompts/guided-execute-task.md +1 -0
- package/src/resources/extensions/gsd/prompts/guided-plan-milestone.md +23 -0
- package/src/resources/extensions/gsd/prompts/guided-plan-slice.md +1 -0
- package/src/resources/extensions/gsd/prompts/guided-research-slice.md +11 -0
- package/src/resources/extensions/gsd/prompts/guided-resume-task.md +1 -0
- package/src/resources/extensions/gsd/prompts/plan-milestone.md +65 -0
- package/src/resources/extensions/gsd/prompts/plan-slice.md +51 -0
- package/src/resources/extensions/gsd/prompts/queue.md +85 -0
- package/src/resources/extensions/gsd/prompts/reassess-roadmap.md +48 -0
- package/src/resources/extensions/gsd/prompts/replan-slice.md +39 -0
- package/src/resources/extensions/gsd/prompts/research-milestone.md +37 -0
- package/src/resources/extensions/gsd/prompts/research-slice.md +28 -0
- package/src/resources/extensions/gsd/prompts/review-migration.md +66 -0
- package/src/resources/extensions/gsd/prompts/run-uat.md +109 -0
- package/src/resources/extensions/gsd/prompts/system.md +187 -0
- package/src/resources/extensions/gsd/prompts/worktree-merge.md +123 -0
- package/src/resources/extensions/gsd/session-forensics.ts +487 -0
- package/src/resources/extensions/gsd/skill-discovery.ts +137 -0
- package/src/resources/extensions/gsd/state.ts +460 -0
- package/src/resources/extensions/gsd/templates/context.md +76 -0
- package/src/resources/extensions/gsd/templates/decisions.md +8 -0
- package/src/resources/extensions/gsd/templates/milestone-summary.md +73 -0
- package/src/resources/extensions/gsd/templates/plan.md +131 -0
- package/src/resources/extensions/gsd/templates/preferences.md +24 -0
- package/src/resources/extensions/gsd/templates/project.md +31 -0
- package/src/resources/extensions/gsd/templates/reassessment.md +28 -0
- package/src/resources/extensions/gsd/templates/requirements.md +81 -0
- package/src/resources/extensions/gsd/templates/research.md +46 -0
- package/src/resources/extensions/gsd/templates/roadmap.md +118 -0
- package/src/resources/extensions/gsd/templates/slice-context.md +58 -0
- package/src/resources/extensions/gsd/templates/slice-summary.md +99 -0
- package/src/resources/extensions/gsd/templates/state.md +19 -0
- package/src/resources/extensions/gsd/templates/task-plan.md +52 -0
- package/src/resources/extensions/gsd/templates/task-summary.md +57 -0
- package/src/resources/extensions/gsd/templates/uat.md +54 -0
- package/src/resources/extensions/gsd/tests/activity-log-prune.test.ts +327 -0
- package/src/resources/extensions/gsd/tests/auto-preflight.test.ts +56 -0
- package/src/resources/extensions/gsd/tests/auto-supervisor.test.mjs +53 -0
- package/src/resources/extensions/gsd/tests/complete-milestone.test.ts +225 -0
- package/src/resources/extensions/gsd/tests/cost-projection.test.ts +160 -0
- package/src/resources/extensions/gsd/tests/derive-state-deps.test.ts +341 -0
- package/src/resources/extensions/gsd/tests/derive-state.test.ts +689 -0
- package/src/resources/extensions/gsd/tests/discuss-prompt.test.ts +38 -0
- package/src/resources/extensions/gsd/tests/doctor.test.ts +505 -0
- package/src/resources/extensions/gsd/tests/git-service.test.ts +1313 -0
- package/src/resources/extensions/gsd/tests/idle-recovery.test.ts +308 -0
- package/src/resources/extensions/gsd/tests/metrics-io.test.ts +201 -0
- package/src/resources/extensions/gsd/tests/metrics.test.ts +217 -0
- package/src/resources/extensions/gsd/tests/migrate-command.test.ts +390 -0
- package/src/resources/extensions/gsd/tests/migrate-parser.test.ts +786 -0
- package/src/resources/extensions/gsd/tests/migrate-transformer.test.ts +657 -0
- package/src/resources/extensions/gsd/tests/migrate-validator-parsers.test.ts +443 -0
- package/src/resources/extensions/gsd/tests/migrate-writer-integration.test.ts +318 -0
- package/src/resources/extensions/gsd/tests/migrate-writer.test.ts +420 -0
- package/src/resources/extensions/gsd/tests/must-have-parser.test.ts +309 -0
- package/src/resources/extensions/gsd/tests/parsers.test.ts +1351 -0
- package/src/resources/extensions/gsd/tests/plan-milestone.test.ts +163 -0
- package/src/resources/extensions/gsd/tests/plan-quality-validator.test.ts +386 -0
- package/src/resources/extensions/gsd/tests/reassess-prompt.test.ts +171 -0
- package/src/resources/extensions/gsd/tests/remote-questions.test.ts +155 -0
- package/src/resources/extensions/gsd/tests/remote-status.test.ts +99 -0
- package/src/resources/extensions/gsd/tests/replan-slice.test.ts +521 -0
- package/src/resources/extensions/gsd/tests/requirements.test.ts +125 -0
- package/src/resources/extensions/gsd/tests/resolve-ts-hooks.mjs +34 -0
- package/src/resources/extensions/gsd/tests/resolve-ts.mjs +11 -0
- package/src/resources/extensions/gsd/tests/run-uat.test.ts +348 -0
- package/src/resources/extensions/gsd/tests/unit-runtime.test.ts +247 -0
- package/src/resources/extensions/gsd/tests/workflow-config.test.mjs +53 -0
- package/src/resources/extensions/gsd/tests/workspace-index.test.ts +94 -0
- package/src/resources/extensions/gsd/tests/worktree-integration.test.ts +253 -0
- package/src/resources/extensions/gsd/tests/worktree-manager.test.ts +160 -0
- package/src/resources/extensions/gsd/tests/worktree.test.ts +264 -0
- package/src/resources/extensions/gsd/types.ts +159 -0
- package/src/resources/extensions/gsd/unit-runtime.ts +184 -0
- package/src/resources/extensions/gsd/workspace-index.ts +203 -0
- package/src/resources/extensions/gsd/worktree-command.ts +845 -0
- package/src/resources/extensions/gsd/worktree-manager.ts +392 -0
- package/src/resources/extensions/gsd/worktree.ts +183 -0
- package/src/resources/extensions/mac-tools/index.ts +852 -0
- package/src/resources/extensions/mac-tools/swift-cli/Package.swift +22 -0
- package/src/resources/extensions/mac-tools/swift-cli/Sources/main.swift +1318 -0
- package/src/resources/extensions/mcporter/index.ts +429 -0
- package/src/resources/extensions/remote-questions/config.ts +81 -0
- package/src/resources/extensions/remote-questions/discord-adapter.ts +128 -0
- package/src/resources/extensions/remote-questions/format.ts +163 -0
- package/src/resources/extensions/remote-questions/manager.ts +192 -0
- package/src/resources/extensions/remote-questions/remote-command.ts +307 -0
- package/src/resources/extensions/remote-questions/slack-adapter.ts +92 -0
- package/src/resources/extensions/remote-questions/status.ts +31 -0
- package/src/resources/extensions/remote-questions/store.ts +77 -0
- package/src/resources/extensions/remote-questions/types.ts +75 -0
- package/src/resources/extensions/search-the-web/cache.ts +78 -0
- package/src/resources/extensions/search-the-web/command-search-provider.ts +95 -0
- package/src/resources/extensions/search-the-web/format.ts +258 -0
- package/src/resources/extensions/search-the-web/http.ts +238 -0
- package/src/resources/extensions/search-the-web/index.ts +65 -0
- package/src/resources/extensions/search-the-web/native-search.ts +157 -0
- package/src/resources/extensions/search-the-web/provider.ts +118 -0
- package/src/resources/extensions/search-the-web/tavily.ts +116 -0
- package/src/resources/extensions/search-the-web/tool-fetch-page.ts +519 -0
- package/src/resources/extensions/search-the-web/tool-llm-context.ts +561 -0
- package/src/resources/extensions/search-the-web/tool-search.ts +576 -0
- package/src/resources/extensions/search-the-web/url-utils.ts +91 -0
- package/src/resources/extensions/shared/confirm-ui.ts +126 -0
- package/src/resources/extensions/shared/interview-ui.ts +613 -0
- package/src/resources/extensions/shared/next-action-ui.ts +197 -0
- package/src/resources/extensions/shared/progress-widget.ts +282 -0
- package/src/resources/extensions/shared/terminal.ts +23 -0
- package/src/resources/extensions/shared/thinking-widget.ts +107 -0
- package/src/resources/extensions/shared/ui.ts +400 -0
- package/src/resources/extensions/shared/wizard-ui.ts +551 -0
- package/src/resources/extensions/slash-commands/audit.ts +88 -0
- package/src/resources/extensions/slash-commands/clear.ts +10 -0
- package/src/resources/extensions/slash-commands/create-extension.ts +297 -0
- package/src/resources/extensions/slash-commands/create-slash-command.ts +234 -0
- package/src/resources/extensions/slash-commands/index.ts +12 -0
- package/src/resources/extensions/subagent/agents.ts +126 -0
- package/src/resources/extensions/subagent/index.ts +1020 -0
- package/src/resources/extensions/voice/index.ts +195 -0
- package/src/resources/extensions/voice/speech-recognizer.swift +154 -0
- package/src/resources/skills/debug-like-expert/SKILL.md +231 -0
- package/src/resources/skills/debug-like-expert/references/debugging-mindset.md +253 -0
- package/src/resources/skills/debug-like-expert/references/hypothesis-testing.md +373 -0
- package/src/resources/skills/debug-like-expert/references/investigation-techniques.md +337 -0
- package/src/resources/skills/debug-like-expert/references/verification-patterns.md +425 -0
- package/src/resources/skills/debug-like-expert/references/when-to-research.md +361 -0
- package/src/resources/skills/frontend-design/SKILL.md +45 -0
- package/src/resources/skills/swiftui/SKILL.md +208 -0
- package/src/resources/skills/swiftui/references/animations.md +921 -0
- package/src/resources/skills/swiftui/references/architecture.md +1561 -0
- package/src/resources/skills/swiftui/references/layout-system.md +1186 -0
- package/src/resources/skills/swiftui/references/navigation.md +1492 -0
- package/src/resources/skills/swiftui/references/networking-async.md +214 -0
- package/src/resources/skills/swiftui/references/performance.md +1706 -0
- package/src/resources/skills/swiftui/references/platform-integration.md +204 -0
- package/src/resources/skills/swiftui/references/state-management.md +1443 -0
- package/src/resources/skills/swiftui/references/swiftdata.md +297 -0
- package/src/resources/skills/swiftui/references/testing-debugging.md +247 -0
- package/src/resources/skills/swiftui/references/uikit-appkit-interop.md +218 -0
- package/src/resources/skills/swiftui/workflows/add-feature.md +191 -0
- package/src/resources/skills/swiftui/workflows/build-new-app.md +311 -0
- package/src/resources/skills/swiftui/workflows/debug-swiftui.md +192 -0
- package/src/resources/skills/swiftui/workflows/optimize-performance.md +197 -0
- package/src/resources/skills/swiftui/workflows/ship-app.md +203 -0
- package/src/resources/skills/swiftui/workflows/write-tests.md +235 -0
|
@@ -0,0 +1,1313 @@
|
|
|
1
|
+
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
|
|
2
|
+
import { join, dirname } from "node:path";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { execSync } from "node:child_process";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
inferCommitType,
|
|
8
|
+
GitServiceImpl,
|
|
9
|
+
RUNTIME_EXCLUSION_PATHS,
|
|
10
|
+
VALID_BRANCH_NAME,
|
|
11
|
+
runGit,
|
|
12
|
+
type GitPreferences,
|
|
13
|
+
type CommitOptions,
|
|
14
|
+
type MergeSliceResult,
|
|
15
|
+
type PreMergeCheckResult,
|
|
16
|
+
} from "../git-service.ts";
|
|
17
|
+
|
|
18
|
+
let passed = 0;
|
|
19
|
+
let failed = 0;
|
|
20
|
+
|
|
21
|
+
function assert(condition: boolean, message: string): void {
|
|
22
|
+
if (condition) passed++;
|
|
23
|
+
else {
|
|
24
|
+
failed++;
|
|
25
|
+
console.error(` FAIL: ${message}`);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function assertEq<T>(actual: T, expected: T, message: string): void {
|
|
30
|
+
if (JSON.stringify(actual) === JSON.stringify(expected)) passed++;
|
|
31
|
+
else {
|
|
32
|
+
failed++;
|
|
33
|
+
console.error(` FAIL: ${message} — expected ${JSON.stringify(expected)}, got ${JSON.stringify(actual)}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function run(command: string, cwd: string): string {
|
|
38
|
+
return execSync(command, { cwd, stdio: ["ignore", "pipe", "pipe"], encoding: "utf-8" }).trim();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function main(): Promise<void> {
|
|
42
|
+
// ─── inferCommitType ───────────────────────────────────────────────────
|
|
43
|
+
|
|
44
|
+
console.log("\n=== inferCommitType ===");
|
|
45
|
+
|
|
46
|
+
assertEq(
|
|
47
|
+
inferCommitType("Implement user authentication"),
|
|
48
|
+
"feat",
|
|
49
|
+
"generic feature title → feat"
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
assertEq(
|
|
53
|
+
inferCommitType("Add dashboard page"),
|
|
54
|
+
"feat",
|
|
55
|
+
"add-style title → feat"
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
assertEq(
|
|
59
|
+
inferCommitType("Fix login redirect bug"),
|
|
60
|
+
"fix",
|
|
61
|
+
"title with 'fix' → fix"
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
assertEq(
|
|
65
|
+
inferCommitType("Bug in session handling"),
|
|
66
|
+
"fix",
|
|
67
|
+
"title with 'bug' → fix"
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
assertEq(
|
|
71
|
+
inferCommitType("Hotfix for production crash"),
|
|
72
|
+
"fix",
|
|
73
|
+
"title with 'hotfix' → fix"
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
assertEq(
|
|
77
|
+
inferCommitType("Patch memory leak"),
|
|
78
|
+
"fix",
|
|
79
|
+
"title with 'patch' → fix"
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
assertEq(
|
|
83
|
+
inferCommitType("Refactor state management"),
|
|
84
|
+
"refactor",
|
|
85
|
+
"title with 'refactor' → refactor"
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
assertEq(
|
|
89
|
+
inferCommitType("Restructure project layout"),
|
|
90
|
+
"refactor",
|
|
91
|
+
"title with 'restructure' → refactor"
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
assertEq(
|
|
95
|
+
inferCommitType("Reorganize module imports"),
|
|
96
|
+
"refactor",
|
|
97
|
+
"title with 'reorganize' → refactor"
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
assertEq(
|
|
101
|
+
inferCommitType("Update API documentation"),
|
|
102
|
+
"docs",
|
|
103
|
+
"title with 'documentation' → docs"
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
assertEq(
|
|
107
|
+
inferCommitType("Add doc for setup guide"),
|
|
108
|
+
"docs",
|
|
109
|
+
"title with 'doc' → docs"
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
assertEq(
|
|
113
|
+
inferCommitType("Add unit tests for auth"),
|
|
114
|
+
"test",
|
|
115
|
+
"title with 'tests' → test"
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
assertEq(
|
|
119
|
+
inferCommitType("Testing infrastructure setup"),
|
|
120
|
+
"test",
|
|
121
|
+
"title with 'testing' → test"
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
assertEq(
|
|
125
|
+
inferCommitType("Chore: update dependencies"),
|
|
126
|
+
"chore",
|
|
127
|
+
"title with 'chore' → chore"
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
assertEq(
|
|
131
|
+
inferCommitType("Cleanup unused imports"),
|
|
132
|
+
"chore",
|
|
133
|
+
"title with 'cleanup' → chore"
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
assertEq(
|
|
137
|
+
inferCommitType("Clean up stale branches"),
|
|
138
|
+
"chore",
|
|
139
|
+
"title with 'clean up' → chore"
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
assertEq(
|
|
143
|
+
inferCommitType("Archive old milestones"),
|
|
144
|
+
"chore",
|
|
145
|
+
"title with 'archive' → chore"
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
assertEq(
|
|
149
|
+
inferCommitType("Remove deprecated endpoints"),
|
|
150
|
+
"chore",
|
|
151
|
+
"title with 'remove' → chore"
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
assertEq(
|
|
155
|
+
inferCommitType("Delete temp files"),
|
|
156
|
+
"chore",
|
|
157
|
+
"title with 'delete' → chore"
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
// Mixed keywords — first match wins
|
|
161
|
+
assertEq(
|
|
162
|
+
inferCommitType("Fix and refactor the login module"),
|
|
163
|
+
"fix",
|
|
164
|
+
"mixed keywords → first match wins (fix before refactor)"
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
assertEq(
|
|
168
|
+
inferCommitType("Refactor test utilities"),
|
|
169
|
+
"refactor",
|
|
170
|
+
"mixed keywords → first match wins (refactor before test)"
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
// Unknown / unrecognized title → feat
|
|
174
|
+
assertEq(
|
|
175
|
+
inferCommitType("Build the new pipeline"),
|
|
176
|
+
"feat",
|
|
177
|
+
"unrecognized title → feat"
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
assertEq(
|
|
181
|
+
inferCommitType(""),
|
|
182
|
+
"feat",
|
|
183
|
+
"empty title → feat"
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
// Word boundary: "testify" should NOT match "test"
|
|
187
|
+
assertEq(
|
|
188
|
+
inferCommitType("Testify integration"),
|
|
189
|
+
"feat",
|
|
190
|
+
"'testify' does not match 'test' — word boundary prevents partial match"
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
// "documentary" should NOT match "doc" (word boundary)
|
|
194
|
+
assertEq(
|
|
195
|
+
inferCommitType("Documentary style UI"),
|
|
196
|
+
"feat",
|
|
197
|
+
"'documentary' does not match 'doc' — word boundary prevents partial match"
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
// "prefix" should NOT match "fix" (word boundary)
|
|
201
|
+
assertEq(
|
|
202
|
+
inferCommitType("Add prefix to all IDs"),
|
|
203
|
+
"feat",
|
|
204
|
+
"'prefix' does not match 'fix' — word boundary prevents partial match"
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
// ─── RUNTIME_EXCLUSION_PATHS ───────────────────────────────────────────
|
|
208
|
+
|
|
209
|
+
console.log("\n=== RUNTIME_EXCLUSION_PATHS ===");
|
|
210
|
+
|
|
211
|
+
assertEq(
|
|
212
|
+
RUNTIME_EXCLUSION_PATHS.length,
|
|
213
|
+
6,
|
|
214
|
+
"exactly 6 runtime exclusion paths"
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
const expectedPaths = [
|
|
218
|
+
".gsd/activity/",
|
|
219
|
+
".gsd/runtime/",
|
|
220
|
+
".gsd/worktrees/",
|
|
221
|
+
".gsd/auto.lock",
|
|
222
|
+
".gsd/metrics.json",
|
|
223
|
+
".gsd/STATE.md",
|
|
224
|
+
];
|
|
225
|
+
|
|
226
|
+
assertEq(
|
|
227
|
+
[...RUNTIME_EXCLUSION_PATHS],
|
|
228
|
+
expectedPaths,
|
|
229
|
+
"paths match expected set in order"
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
assert(
|
|
233
|
+
RUNTIME_EXCLUSION_PATHS.includes(".gsd/activity/"),
|
|
234
|
+
"includes .gsd/activity/"
|
|
235
|
+
);
|
|
236
|
+
assert(
|
|
237
|
+
RUNTIME_EXCLUSION_PATHS.includes(".gsd/STATE.md"),
|
|
238
|
+
"includes .gsd/STATE.md"
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
// ─── runGit ────────────────────────────────────────────────────────────
|
|
242
|
+
|
|
243
|
+
console.log("\n=== runGit ===");
|
|
244
|
+
|
|
245
|
+
const tempDir = mkdtempSync(join(tmpdir(), "gsd-git-service-test-"));
|
|
246
|
+
run("git init -b main", tempDir);
|
|
247
|
+
run("git config user.name 'Pi Test'", tempDir);
|
|
248
|
+
run("git config user.email 'pi@example.com'", tempDir);
|
|
249
|
+
|
|
250
|
+
// runGit should work on a valid repo
|
|
251
|
+
const branch = runGit(tempDir, ["branch", "--show-current"]);
|
|
252
|
+
assertEq(branch, "main", "runGit returns current branch");
|
|
253
|
+
|
|
254
|
+
// runGit allowFailure returns empty string on failure
|
|
255
|
+
const result = runGit(tempDir, ["log", "--oneline"], { allowFailure: true });
|
|
256
|
+
assertEq(result, "", "runGit allowFailure returns empty on error (no commits yet)");
|
|
257
|
+
|
|
258
|
+
// runGit throws on failure without allowFailure
|
|
259
|
+
let threw = false;
|
|
260
|
+
try {
|
|
261
|
+
runGit(tempDir, ["log", "--oneline"]);
|
|
262
|
+
} catch (e) {
|
|
263
|
+
threw = true;
|
|
264
|
+
assert(
|
|
265
|
+
(e as Error).message.includes("git log --oneline failed"),
|
|
266
|
+
"error message includes command and path"
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
assert(threw, "runGit throws without allowFailure on error");
|
|
270
|
+
|
|
271
|
+
// ─── Type exports compile check ────────────────────────────────────────
|
|
272
|
+
|
|
273
|
+
console.log("\n=== Type exports ===");
|
|
274
|
+
|
|
275
|
+
// These are compile-time checks — if we got here, the types import fine
|
|
276
|
+
const _prefs: GitPreferences = { auto_push: true, remote: "origin" };
|
|
277
|
+
const _opts: CommitOptions = { message: "test" };
|
|
278
|
+
const _result: MergeSliceResult = { branch: "main", mergedCommitMessage: "msg", deletedBranch: false };
|
|
279
|
+
assert(true, "GitPreferences type exported and usable");
|
|
280
|
+
assert(true, "CommitOptions type exported and usable");
|
|
281
|
+
assert(true, "MergeSliceResult type exported and usable");
|
|
282
|
+
|
|
283
|
+
// Cleanup T01 temp dir
|
|
284
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
285
|
+
|
|
286
|
+
// ─── Helper: create file with intermediate dirs ────────────────────────
|
|
287
|
+
|
|
288
|
+
function createFile(base: string, relativePath: string, content: string = "x"): void {
|
|
289
|
+
const full = join(base, relativePath);
|
|
290
|
+
mkdirSync(dirname(full), { recursive: true });
|
|
291
|
+
writeFileSync(full, content, "utf-8");
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
function initTempRepo(): string {
|
|
295
|
+
const dir = mkdtempSync(join(tmpdir(), "gsd-git-t02-"));
|
|
296
|
+
run("git init -b main", dir);
|
|
297
|
+
run("git config user.name 'Pi Test'", dir);
|
|
298
|
+
run("git config user.email 'pi@example.com'", dir);
|
|
299
|
+
// Need an initial commit so HEAD exists
|
|
300
|
+
createFile(dir, ".gitkeep", "");
|
|
301
|
+
run("git add -A", dir);
|
|
302
|
+
run("git commit -m 'init'", dir);
|
|
303
|
+
return dir;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// ─── GitServiceImpl: smart staging ─────────────────────────────────────
|
|
307
|
+
|
|
308
|
+
console.log("\n=== GitServiceImpl: smart staging ===");
|
|
309
|
+
|
|
310
|
+
{
|
|
311
|
+
const repo = initTempRepo();
|
|
312
|
+
const svc = new GitServiceImpl(repo);
|
|
313
|
+
|
|
314
|
+
// Create runtime files (should be excluded from staging)
|
|
315
|
+
createFile(repo, ".gsd/activity/log.jsonl", "log data");
|
|
316
|
+
createFile(repo, ".gsd/runtime/state.json", '{"state":true}');
|
|
317
|
+
createFile(repo, ".gsd/STATE.md", "# State");
|
|
318
|
+
createFile(repo, ".gsd/auto.lock", "lock");
|
|
319
|
+
createFile(repo, ".gsd/metrics.json", "{}");
|
|
320
|
+
createFile(repo, ".gsd/worktrees/wt/file.txt", "wt data");
|
|
321
|
+
|
|
322
|
+
// Create a real file (should be staged)
|
|
323
|
+
createFile(repo, "src/code.ts", 'console.log("hello");');
|
|
324
|
+
|
|
325
|
+
const result = svc.commit({ message: "test: smart staging" });
|
|
326
|
+
|
|
327
|
+
assertEq(result, "test: smart staging", "commit returns the commit message");
|
|
328
|
+
|
|
329
|
+
// Verify only src/code.ts is in the commit
|
|
330
|
+
const showStat = run("git show --stat --format='' HEAD", repo);
|
|
331
|
+
assert(showStat.includes("src/code.ts"), "src/code.ts is in the commit");
|
|
332
|
+
assert(!showStat.includes(".gsd/activity"), ".gsd/activity/ excluded from commit");
|
|
333
|
+
assert(!showStat.includes(".gsd/runtime"), ".gsd/runtime/ excluded from commit");
|
|
334
|
+
assert(!showStat.includes("STATE.md"), ".gsd/STATE.md excluded from commit");
|
|
335
|
+
assert(!showStat.includes("auto.lock"), ".gsd/auto.lock excluded from commit");
|
|
336
|
+
assert(!showStat.includes("metrics.json"), ".gsd/metrics.json excluded from commit");
|
|
337
|
+
assert(!showStat.includes(".gsd/worktrees"), ".gsd/worktrees/ excluded from commit");
|
|
338
|
+
|
|
339
|
+
// Verify runtime files are still untracked
|
|
340
|
+
// git status --short may collapse to "?? .gsd/" or show individual files
|
|
341
|
+
// Use --untracked-files=all to force individual listing
|
|
342
|
+
const statusOut = run("git status --short --untracked-files=all", repo);
|
|
343
|
+
assert(statusOut.includes(".gsd/activity/"), "activity still untracked after commit");
|
|
344
|
+
assert(statusOut.includes(".gsd/runtime/"), "runtime still untracked after commit");
|
|
345
|
+
assert(statusOut.includes(".gsd/STATE.md"), "STATE.md still untracked after commit");
|
|
346
|
+
|
|
347
|
+
rmSync(repo, { recursive: true, force: true });
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// ─── GitServiceImpl: smart staging fallback ────────────────────────────
|
|
351
|
+
|
|
352
|
+
console.log("\n=== GitServiceImpl: smart staging fallback ===");
|
|
353
|
+
|
|
354
|
+
{
|
|
355
|
+
// We can't easily make the pathspec fail in a real repo, but we can test
|
|
356
|
+
// the fallback behavior by verifying that if smart staging somehow fails,
|
|
357
|
+
// everything gets staged. We do this by checking that a commit with both
|
|
358
|
+
// runtime and real files works when pathspec would fail.
|
|
359
|
+
//
|
|
360
|
+
// To force the fallback: temporarily override RUNTIME_EXCLUSION_PATHS
|
|
361
|
+
// with an invalid pathspec. Since we can't modify a readonly array,
|
|
362
|
+
// we'll test the actual fallback by creating a custom subclass.
|
|
363
|
+
|
|
364
|
+
const repo = initTempRepo();
|
|
365
|
+
|
|
366
|
+
// Create a subclass that overrides smartStage to simulate failure + fallback
|
|
367
|
+
class FallbackTestService extends GitServiceImpl {
|
|
368
|
+
fallbackUsed = false;
|
|
369
|
+
smartStageWithBadPathspec(): void {
|
|
370
|
+
// Simulate: try bad pathspec, catch, fallback
|
|
371
|
+
try {
|
|
372
|
+
runGit(this.basePath, ["add", "-A", "--", ".", ":(exclude)__NONEXISTENT_PATHSPEC_SYNTAX_ERROR__["]);
|
|
373
|
+
// If the above doesn't throw, git accepted it (some versions do).
|
|
374
|
+
// That's fine — the point is testing the fallback path.
|
|
375
|
+
throw new Error("force fallback for test");
|
|
376
|
+
} catch {
|
|
377
|
+
console.error("GitService: smart staging failed, falling back to git add -A");
|
|
378
|
+
this.fallbackUsed = true;
|
|
379
|
+
runGit(this.basePath, ["add", "-A"]);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const svc = new FallbackTestService(repo);
|
|
385
|
+
createFile(repo, "src/real.ts", "real code");
|
|
386
|
+
createFile(repo, ".gsd/activity/log.jsonl", "log");
|
|
387
|
+
|
|
388
|
+
// Call the fallback path manually
|
|
389
|
+
svc.smartStageWithBadPathspec();
|
|
390
|
+
|
|
391
|
+
// Check that everything was staged (fallback stages all)
|
|
392
|
+
const staged = run("git diff --cached --name-only", repo);
|
|
393
|
+
assert(staged.includes("src/real.ts"), "fallback stages real files");
|
|
394
|
+
assert(staged.includes(".gsd/activity/log.jsonl"), "fallback stages runtime files too (no exclusion)");
|
|
395
|
+
assert(svc.fallbackUsed, "fallback path was actually used");
|
|
396
|
+
|
|
397
|
+
rmSync(repo, { recursive: true, force: true });
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// ─── GitServiceImpl: autoCommit on clean repo ──────────────────────────
|
|
401
|
+
|
|
402
|
+
console.log("\n=== GitServiceImpl: autoCommit ===");
|
|
403
|
+
|
|
404
|
+
{
|
|
405
|
+
const repo = initTempRepo();
|
|
406
|
+
const svc = new GitServiceImpl(repo);
|
|
407
|
+
|
|
408
|
+
// Clean repo — autoCommit should return null
|
|
409
|
+
const cleanResult = svc.autoCommit("task", "T01");
|
|
410
|
+
assertEq(cleanResult, null, "autoCommit on clean repo returns null");
|
|
411
|
+
|
|
412
|
+
rmSync(repo, { recursive: true, force: true });
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// ─── GitServiceImpl: autoCommit on dirty repo ──────────────────────────
|
|
416
|
+
|
|
417
|
+
console.log("\n=== GitServiceImpl: autoCommit on dirty repo ===");
|
|
418
|
+
|
|
419
|
+
{
|
|
420
|
+
const repo = initTempRepo();
|
|
421
|
+
const svc = new GitServiceImpl(repo);
|
|
422
|
+
|
|
423
|
+
createFile(repo, "src/new-feature.ts", "export const x = 1;");
|
|
424
|
+
const msg = svc.autoCommit("task", "T01");
|
|
425
|
+
|
|
426
|
+
assertEq(msg, "chore(T01): auto-commit after task", "autoCommit returns correct message format");
|
|
427
|
+
|
|
428
|
+
// Verify the commit exists
|
|
429
|
+
const log = run("git log --oneline -1", repo);
|
|
430
|
+
assert(log.includes("chore(T01): auto-commit after task"), "commit message is in git log");
|
|
431
|
+
|
|
432
|
+
rmSync(repo, { recursive: true, force: true });
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// ─── GitServiceImpl: empty-after-staging guard ─────────────────────────
|
|
436
|
+
|
|
437
|
+
console.log("\n=== GitServiceImpl: empty-after-staging guard ===");
|
|
438
|
+
|
|
439
|
+
{
|
|
440
|
+
const repo = initTempRepo();
|
|
441
|
+
const svc = new GitServiceImpl(repo);
|
|
442
|
+
|
|
443
|
+
// Create only runtime files
|
|
444
|
+
createFile(repo, ".gsd/activity/x.jsonl", "data");
|
|
445
|
+
|
|
446
|
+
const result = svc.autoCommit("task", "T02");
|
|
447
|
+
assertEq(result, null, "autoCommit returns null when only runtime files are dirty");
|
|
448
|
+
|
|
449
|
+
// Verify no new commit was created (should still be at init commit)
|
|
450
|
+
const logCount = run("git rev-list --count HEAD", repo);
|
|
451
|
+
assertEq(logCount, "1", "no new commit created when only runtime files changed");
|
|
452
|
+
|
|
453
|
+
rmSync(repo, { recursive: true, force: true });
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// ─── GitServiceImpl: commit returns null when nothing staged ───────────
|
|
457
|
+
|
|
458
|
+
console.log("\n=== GitServiceImpl: commit empty ===");
|
|
459
|
+
|
|
460
|
+
{
|
|
461
|
+
const repo = initTempRepo();
|
|
462
|
+
const svc = new GitServiceImpl(repo);
|
|
463
|
+
|
|
464
|
+
// Nothing dirty, commit should return null
|
|
465
|
+
const result = svc.commit({ message: "should not commit" });
|
|
466
|
+
assertEq(result, null, "commit returns null when nothing to stage");
|
|
467
|
+
|
|
468
|
+
rmSync(repo, { recursive: true, force: true });
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
// ─── Helper: create repo for branch tests ────────────────────────────
|
|
472
|
+
|
|
473
|
+
function initBranchTestRepo(): string {
|
|
474
|
+
const dir = mkdtempSync(join(tmpdir(), "gsd-git-t03-"));
|
|
475
|
+
run("git init -b main", dir);
|
|
476
|
+
run("git config user.name 'Pi Test'", dir);
|
|
477
|
+
run("git config user.email 'pi@example.com'", dir);
|
|
478
|
+
createFile(dir, ".gitkeep", "");
|
|
479
|
+
run("git add -A", dir);
|
|
480
|
+
run("git commit -m 'init'", dir);
|
|
481
|
+
return dir;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
// ─── getCurrentBranch / isOnSliceBranch / getActiveSliceBranch ─────────
|
|
485
|
+
|
|
486
|
+
console.log("\n=== Branch queries ===");
|
|
487
|
+
|
|
488
|
+
{
|
|
489
|
+
const repo = initBranchTestRepo();
|
|
490
|
+
const svc = new GitServiceImpl(repo);
|
|
491
|
+
|
|
492
|
+
// On main
|
|
493
|
+
assertEq(svc.getCurrentBranch(), "main", "getCurrentBranch returns main on main branch");
|
|
494
|
+
assertEq(svc.isOnSliceBranch(), false, "isOnSliceBranch returns false on main");
|
|
495
|
+
assertEq(svc.getActiveSliceBranch(), null, "getActiveSliceBranch returns null on main");
|
|
496
|
+
|
|
497
|
+
// Create and checkout a slice branch manually
|
|
498
|
+
run("git checkout -b gsd/M001/S01", repo);
|
|
499
|
+
assertEq(svc.getCurrentBranch(), "gsd/M001/S01", "getCurrentBranch returns slice branch name");
|
|
500
|
+
assertEq(svc.isOnSliceBranch(), true, "isOnSliceBranch returns true on slice branch");
|
|
501
|
+
assertEq(svc.getActiveSliceBranch(), "gsd/M001/S01", "getActiveSliceBranch returns branch name on slice branch");
|
|
502
|
+
|
|
503
|
+
// Non-slice feature branch
|
|
504
|
+
run("git checkout -b feature/foo", repo);
|
|
505
|
+
assertEq(svc.isOnSliceBranch(), false, "isOnSliceBranch returns false on non-slice branch");
|
|
506
|
+
assertEq(svc.getActiveSliceBranch(), null, "getActiveSliceBranch returns null on non-slice branch");
|
|
507
|
+
|
|
508
|
+
rmSync(repo, { recursive: true, force: true });
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// ─── getMainBranch ────────────────────────────────────────────────────
|
|
512
|
+
|
|
513
|
+
console.log("\n=== getMainBranch ===");
|
|
514
|
+
|
|
515
|
+
{
|
|
516
|
+
const repo = initBranchTestRepo();
|
|
517
|
+
const svc = new GitServiceImpl(repo);
|
|
518
|
+
|
|
519
|
+
// Basic case: repo has "main" branch
|
|
520
|
+
assertEq(svc.getMainBranch(), "main", "getMainBranch returns main when main exists");
|
|
521
|
+
|
|
522
|
+
rmSync(repo, { recursive: true, force: true });
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
{
|
|
526
|
+
// master-only repo
|
|
527
|
+
const repo = mkdtempSync(join(tmpdir(), "gsd-git-t03-master-"));
|
|
528
|
+
run("git init -b master", repo);
|
|
529
|
+
run("git config user.name 'Pi Test'", repo);
|
|
530
|
+
run("git config user.email 'pi@example.com'", repo);
|
|
531
|
+
createFile(repo, ".gitkeep", "");
|
|
532
|
+
run("git add -A", repo);
|
|
533
|
+
run("git commit -m 'init'", repo);
|
|
534
|
+
|
|
535
|
+
const svc = new GitServiceImpl(repo);
|
|
536
|
+
assertEq(svc.getMainBranch(), "master", "getMainBranch returns master when only master exists");
|
|
537
|
+
|
|
538
|
+
rmSync(repo, { recursive: true, force: true });
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// ─── ensureSliceBranch: creates and checks out ────────────────────────
|
|
542
|
+
|
|
543
|
+
console.log("\n=== ensureSliceBranch ===");
|
|
544
|
+
|
|
545
|
+
{
|
|
546
|
+
const repo = initBranchTestRepo();
|
|
547
|
+
const svc = new GitServiceImpl(repo);
|
|
548
|
+
|
|
549
|
+
const created = svc.ensureSliceBranch("M001", "S01");
|
|
550
|
+
assertEq(created, true, "ensureSliceBranch returns true on first call (branch created)");
|
|
551
|
+
assertEq(svc.getCurrentBranch(), "gsd/M001/S01", "ensureSliceBranch checks out the slice branch");
|
|
552
|
+
|
|
553
|
+
rmSync(repo, { recursive: true, force: true });
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// ─── ensureSliceBranch: idempotent ────────────────────────────────────
|
|
557
|
+
|
|
558
|
+
console.log("\n=== ensureSliceBranch: idempotent ===");
|
|
559
|
+
|
|
560
|
+
{
|
|
561
|
+
const repo = initBranchTestRepo();
|
|
562
|
+
const svc = new GitServiceImpl(repo);
|
|
563
|
+
|
|
564
|
+
svc.ensureSliceBranch("M001", "S01");
|
|
565
|
+
const secondCall = svc.ensureSliceBranch("M001", "S01");
|
|
566
|
+
assertEq(secondCall, false, "ensureSliceBranch returns false when already on the branch");
|
|
567
|
+
assertEq(svc.getCurrentBranch(), "gsd/M001/S01", "still on slice branch after idempotent call");
|
|
568
|
+
|
|
569
|
+
rmSync(repo, { recursive: true, force: true });
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// ─── ensureSliceBranch: from non-main working branch inherits artifacts ──
|
|
573
|
+
|
|
574
|
+
console.log("\n=== ensureSliceBranch: from non-main inherits artifacts ===");
|
|
575
|
+
|
|
576
|
+
{
|
|
577
|
+
const repo = initBranchTestRepo();
|
|
578
|
+
const svc = new GitServiceImpl(repo);
|
|
579
|
+
|
|
580
|
+
// Create a feature branch with planning artifacts
|
|
581
|
+
run("git checkout -b developer", repo);
|
|
582
|
+
createFile(repo, ".gsd/milestones/M001/M001-ROADMAP.md", "# Roadmap");
|
|
583
|
+
run("git add -A", repo);
|
|
584
|
+
run("git commit -m 'add roadmap'", repo);
|
|
585
|
+
|
|
586
|
+
// ensureSliceBranch from this non-main, non-slice branch
|
|
587
|
+
const created = svc.ensureSliceBranch("M001", "S01");
|
|
588
|
+
assertEq(created, true, "branch created from non-main working branch");
|
|
589
|
+
assertEq(svc.getCurrentBranch(), "gsd/M001/S01", "checked out to slice branch");
|
|
590
|
+
|
|
591
|
+
// The roadmap from developer branch should be present
|
|
592
|
+
const logOutput = run("git log --oneline", repo);
|
|
593
|
+
assert(logOutput.includes("add roadmap"), "slice branch inherits artifacts from working branch");
|
|
594
|
+
|
|
595
|
+
rmSync(repo, { recursive: true, force: true });
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// ─── ensureSliceBranch: from another slice branch falls back to main ──
|
|
599
|
+
|
|
600
|
+
console.log("\n=== ensureSliceBranch: from slice branch falls back to main ===");
|
|
601
|
+
|
|
602
|
+
{
|
|
603
|
+
const repo = initBranchTestRepo();
|
|
604
|
+
const svc = new GitServiceImpl(repo);
|
|
605
|
+
|
|
606
|
+
// Create file only on main
|
|
607
|
+
createFile(repo, "main-only.txt", "from main");
|
|
608
|
+
run("git add -A", repo);
|
|
609
|
+
run("git commit -m 'main-only file'", repo);
|
|
610
|
+
|
|
611
|
+
// Create and check out S01
|
|
612
|
+
svc.ensureSliceBranch("M001", "S01");
|
|
613
|
+
// Add a file only on S01
|
|
614
|
+
createFile(repo, "s01-only.txt", "from s01");
|
|
615
|
+
run("git add -A", repo);
|
|
616
|
+
run("git commit -m 'S01 work'", repo);
|
|
617
|
+
|
|
618
|
+
// Now create S02 from S01 — should fall back to main
|
|
619
|
+
const created = svc.ensureSliceBranch("M001", "S02");
|
|
620
|
+
assertEq(created, true, "S02 branch created from S01 (fell back to main)");
|
|
621
|
+
assertEq(svc.getCurrentBranch(), "gsd/M001/S02", "on S02 branch");
|
|
622
|
+
|
|
623
|
+
// S02 should NOT have the S01-only file (it branched from main)
|
|
624
|
+
const showFiles = run("git ls-files", repo);
|
|
625
|
+
assert(!showFiles.includes("s01-only.txt"), "S02 does not have S01-only files (branched from main)");
|
|
626
|
+
assert(showFiles.includes("main-only.txt"), "S02 has main files");
|
|
627
|
+
|
|
628
|
+
rmSync(repo, { recursive: true, force: true });
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// ─── ensureSliceBranch: auto-commits dirty files via smart staging ────
|
|
632
|
+
|
|
633
|
+
console.log("\n=== ensureSliceBranch: auto-commits with smart staging ===");
|
|
634
|
+
|
|
635
|
+
{
|
|
636
|
+
const repo = initBranchTestRepo();
|
|
637
|
+
const svc = new GitServiceImpl(repo);
|
|
638
|
+
|
|
639
|
+
// Create dirty files: both real and runtime
|
|
640
|
+
createFile(repo, "src/feature.ts", "export const y = 2;");
|
|
641
|
+
createFile(repo, ".gsd/activity/session.jsonl", "session data");
|
|
642
|
+
createFile(repo, ".gsd/STATE.md", "# Current State");
|
|
643
|
+
createFile(repo, ".gsd/metrics.json", '{"tasks":1}');
|
|
644
|
+
|
|
645
|
+
// ensureSliceBranch should auto-commit before checkout
|
|
646
|
+
svc.ensureSliceBranch("M001", "S01");
|
|
647
|
+
|
|
648
|
+
// The auto-commit on main should have src/feature.ts but NOT runtime files
|
|
649
|
+
run("git checkout main", repo);
|
|
650
|
+
const showStat = run("git show --stat --format='' HEAD", repo);
|
|
651
|
+
assert(showStat.includes("src/feature.ts"), "auto-commit includes real files");
|
|
652
|
+
assert(!showStat.includes(".gsd/activity"), "auto-commit excludes .gsd/activity/ (smart staging)");
|
|
653
|
+
assert(!showStat.includes("STATE.md"), "auto-commit excludes .gsd/STATE.md (smart staging)");
|
|
654
|
+
assert(!showStat.includes("metrics.json"), "auto-commit excludes .gsd/metrics.json (smart staging)");
|
|
655
|
+
|
|
656
|
+
rmSync(repo, { recursive: true, force: true });
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// ─── switchToMain ─────────────────────────────────────────────────────
|
|
660
|
+
|
|
661
|
+
console.log("\n=== switchToMain ===");
|
|
662
|
+
|
|
663
|
+
{
|
|
664
|
+
const repo = initBranchTestRepo();
|
|
665
|
+
const svc = new GitServiceImpl(repo);
|
|
666
|
+
|
|
667
|
+
// Switch to a slice branch first
|
|
668
|
+
svc.ensureSliceBranch("M001", "S01");
|
|
669
|
+
assertEq(svc.getCurrentBranch(), "gsd/M001/S01", "on slice branch before switchToMain");
|
|
670
|
+
|
|
671
|
+
// Create dirty files
|
|
672
|
+
createFile(repo, "src/work.ts", "work in progress");
|
|
673
|
+
createFile(repo, ".gsd/activity/log.jsonl", "activity log");
|
|
674
|
+
createFile(repo, ".gsd/runtime/state.json", '{"running":true}');
|
|
675
|
+
|
|
676
|
+
svc.switchToMain();
|
|
677
|
+
assertEq(svc.getCurrentBranch(), "main", "switchToMain switches to main");
|
|
678
|
+
|
|
679
|
+
// Verify the auto-commit on the slice branch used smart staging
|
|
680
|
+
const sliceLog = run("git log gsd/M001/S01 --oneline -1", repo);
|
|
681
|
+
assert(sliceLog.includes("pre-switch"), "auto-commit message includes pre-switch");
|
|
682
|
+
|
|
683
|
+
// Check that the auto-commit on the slice branch excluded runtime files
|
|
684
|
+
const showStat = run("git log gsd/M001/S01 -1 --format='' --stat", repo);
|
|
685
|
+
assert(showStat.includes("src/work.ts"), "switchToMain auto-commit includes real files");
|
|
686
|
+
assert(!showStat.includes(".gsd/activity"), "switchToMain auto-commit excludes .gsd/activity/");
|
|
687
|
+
assert(!showStat.includes(".gsd/runtime"), "switchToMain auto-commit excludes .gsd/runtime/");
|
|
688
|
+
|
|
689
|
+
rmSync(repo, { recursive: true, force: true });
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
// ─── switchToMain: idempotent when already on main ─────────────────────
|
|
693
|
+
|
|
694
|
+
console.log("\n=== switchToMain: idempotent ===");
|
|
695
|
+
|
|
696
|
+
{
|
|
697
|
+
const repo = initBranchTestRepo();
|
|
698
|
+
const svc = new GitServiceImpl(repo);
|
|
699
|
+
|
|
700
|
+
assertEq(svc.getCurrentBranch(), "main", "already on main");
|
|
701
|
+
svc.switchToMain(); // Should not throw
|
|
702
|
+
assertEq(svc.getCurrentBranch(), "main", "still on main after idempotent switchToMain");
|
|
703
|
+
|
|
704
|
+
// Verify no extra commits were created
|
|
705
|
+
const logCount = run("git rev-list --count HEAD", repo);
|
|
706
|
+
assertEq(logCount, "1", "no extra commits from idempotent switchToMain");
|
|
707
|
+
|
|
708
|
+
rmSync(repo, { recursive: true, force: true });
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
// ─── mergeSliceToMain: full lifecycle with feat ─────────────────────────
|
|
712
|
+
|
|
713
|
+
console.log("\n=== mergeSliceToMain: full lifecycle ===");
|
|
714
|
+
|
|
715
|
+
{
|
|
716
|
+
const repo = initBranchTestRepo();
|
|
717
|
+
const svc = new GitServiceImpl(repo);
|
|
718
|
+
|
|
719
|
+
// Create and switch to slice branch
|
|
720
|
+
svc.ensureSliceBranch("M001", "S01");
|
|
721
|
+
assertEq(svc.getCurrentBranch(), "gsd/M001/S01", "on slice branch for merge test");
|
|
722
|
+
|
|
723
|
+
// Do work on the slice branch
|
|
724
|
+
createFile(repo, "src/feature.ts", "export const feature = true;");
|
|
725
|
+
svc.commit({ message: "add feature module" });
|
|
726
|
+
|
|
727
|
+
// Switch to main and merge
|
|
728
|
+
svc.switchToMain();
|
|
729
|
+
const result = svc.mergeSliceToMain("M001", "S01", "Implement user authentication");
|
|
730
|
+
|
|
731
|
+
assertEq(result.mergedCommitMessage, "feat(M001/S01): Implement user authentication", "merge commit message uses feat type");
|
|
732
|
+
assertEq(result.deletedBranch, true, "branch was deleted");
|
|
733
|
+
assertEq(result.branch, "gsd/M001/S01", "result includes branch name");
|
|
734
|
+
|
|
735
|
+
// Verify commit is on main
|
|
736
|
+
const log = run("git log --oneline -1", repo);
|
|
737
|
+
assert(log.includes("feat(M001/S01): Implement user authentication"), "merge commit visible in git log");
|
|
738
|
+
|
|
739
|
+
// Verify the file is on main
|
|
740
|
+
const files = run("git ls-files", repo);
|
|
741
|
+
assert(files.includes("src/feature.ts"), "merged file exists on main");
|
|
742
|
+
|
|
743
|
+
// Verify slice branch is deleted
|
|
744
|
+
const branches = run("git branch", repo);
|
|
745
|
+
assert(!branches.includes("gsd/M001/S01"), "slice branch deleted after merge");
|
|
746
|
+
|
|
747
|
+
rmSync(repo, { recursive: true, force: true });
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// ─── mergeSliceToMain: fix type ───────────────────────────────────────
|
|
751
|
+
|
|
752
|
+
console.log("\n=== mergeSliceToMain: fix type ===");
|
|
753
|
+
|
|
754
|
+
{
|
|
755
|
+
const repo = initBranchTestRepo();
|
|
756
|
+
const svc = new GitServiceImpl(repo);
|
|
757
|
+
|
|
758
|
+
svc.ensureSliceBranch("M001", "S02");
|
|
759
|
+
createFile(repo, "src/bugfix.ts", "// fixed");
|
|
760
|
+
svc.commit({ message: "fix the bug" });
|
|
761
|
+
|
|
762
|
+
svc.switchToMain();
|
|
763
|
+
const result = svc.mergeSliceToMain("M001", "S02", "Fix broken config");
|
|
764
|
+
|
|
765
|
+
assert(result.mergedCommitMessage.startsWith("fix("), "merge commit starts with fix(");
|
|
766
|
+
assertEq(result.mergedCommitMessage, "fix(M001/S02): Fix broken config", "fix merge commit message correct");
|
|
767
|
+
|
|
768
|
+
rmSync(repo, { recursive: true, force: true });
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// ─── mergeSliceToMain: docs type ──────────────────────────────────────
|
|
772
|
+
|
|
773
|
+
console.log("\n=== mergeSliceToMain: docs type ===");
|
|
774
|
+
|
|
775
|
+
{
|
|
776
|
+
const repo = initBranchTestRepo();
|
|
777
|
+
const svc = new GitServiceImpl(repo);
|
|
778
|
+
|
|
779
|
+
svc.ensureSliceBranch("M001", "S03");
|
|
780
|
+
createFile(repo, "docs/guide.md", "# Guide");
|
|
781
|
+
svc.commit({ message: "write docs" });
|
|
782
|
+
|
|
783
|
+
svc.switchToMain();
|
|
784
|
+
const result = svc.mergeSliceToMain("M001", "S03", "Docs update");
|
|
785
|
+
|
|
786
|
+
assert(result.mergedCommitMessage.startsWith("docs("), "merge commit starts with docs(");
|
|
787
|
+
assertEq(result.mergedCommitMessage, "docs(M001/S03): Docs update", "docs merge commit message correct");
|
|
788
|
+
|
|
789
|
+
rmSync(repo, { recursive: true, force: true });
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// ─── mergeSliceToMain: refactor type ──────────────────────────────────
|
|
793
|
+
|
|
794
|
+
console.log("\n=== mergeSliceToMain: refactor type ===");
|
|
795
|
+
|
|
796
|
+
{
|
|
797
|
+
const repo = initBranchTestRepo();
|
|
798
|
+
const svc = new GitServiceImpl(repo);
|
|
799
|
+
|
|
800
|
+
svc.ensureSliceBranch("M001", "S04");
|
|
801
|
+
createFile(repo, "src/refactored.ts", "// cleaner");
|
|
802
|
+
svc.commit({ message: "restructure modules" });
|
|
803
|
+
|
|
804
|
+
svc.switchToMain();
|
|
805
|
+
const result = svc.mergeSliceToMain("M001", "S04", "Refactor state management");
|
|
806
|
+
|
|
807
|
+
assert(result.mergedCommitMessage.startsWith("refactor("), "merge commit starts with refactor(");
|
|
808
|
+
assertEq(result.mergedCommitMessage, "refactor(M001/S04): Refactor state management", "refactor merge commit message correct");
|
|
809
|
+
|
|
810
|
+
rmSync(repo, { recursive: true, force: true });
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
// ─── mergeSliceToMain: error — not on main ────────────────────────────
|
|
814
|
+
|
|
815
|
+
console.log("\n=== mergeSliceToMain: error cases ===");
|
|
816
|
+
|
|
817
|
+
{
|
|
818
|
+
const repo = initBranchTestRepo();
|
|
819
|
+
const svc = new GitServiceImpl(repo);
|
|
820
|
+
|
|
821
|
+
// Create a slice branch with a commit
|
|
822
|
+
svc.ensureSliceBranch("M001", "S01");
|
|
823
|
+
createFile(repo, "src/work.ts", "work");
|
|
824
|
+
svc.commit({ message: "slice work" });
|
|
825
|
+
|
|
826
|
+
// Try to merge while still on the slice branch
|
|
827
|
+
let threw = false;
|
|
828
|
+
try {
|
|
829
|
+
svc.mergeSliceToMain("M001", "S01", "Some feature");
|
|
830
|
+
} catch (e) {
|
|
831
|
+
threw = true;
|
|
832
|
+
const msg = (e as Error).message;
|
|
833
|
+
assert(msg.includes("must be called from the main branch"), "error mentions main branch requirement");
|
|
834
|
+
assert(msg.includes("gsd/M001/S01"), "error includes current branch name");
|
|
835
|
+
}
|
|
836
|
+
assert(threw, "mergeSliceToMain throws when not on main");
|
|
837
|
+
|
|
838
|
+
rmSync(repo, { recursive: true, force: true });
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
// ─── mergeSliceToMain: error — branch doesn't exist ───────────────────
|
|
842
|
+
|
|
843
|
+
{
|
|
844
|
+
const repo = initBranchTestRepo();
|
|
845
|
+
const svc = new GitServiceImpl(repo);
|
|
846
|
+
|
|
847
|
+
let threw = false;
|
|
848
|
+
try {
|
|
849
|
+
svc.mergeSliceToMain("M001", "S99", "Nonexistent");
|
|
850
|
+
} catch (e) {
|
|
851
|
+
threw = true;
|
|
852
|
+
const msg = (e as Error).message;
|
|
853
|
+
assert(msg.includes("does not exist"), "error mentions branch does not exist");
|
|
854
|
+
assert(msg.includes("gsd/M001/S99"), "error includes missing branch name");
|
|
855
|
+
}
|
|
856
|
+
assert(threw, "mergeSliceToMain throws when branch doesn't exist");
|
|
857
|
+
|
|
858
|
+
rmSync(repo, { recursive: true, force: true });
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// ─── mergeSliceToMain: error — no commits ahead ───────────────────────
|
|
862
|
+
|
|
863
|
+
{
|
|
864
|
+
const repo = initBranchTestRepo();
|
|
865
|
+
const svc = new GitServiceImpl(repo);
|
|
866
|
+
|
|
867
|
+
// Create slice branch but don't add any commits
|
|
868
|
+
svc.ensureSliceBranch("M001", "S01");
|
|
869
|
+
// Switch back to main without committing anything on the slice branch
|
|
870
|
+
svc.switchToMain();
|
|
871
|
+
|
|
872
|
+
let threw = false;
|
|
873
|
+
try {
|
|
874
|
+
svc.mergeSliceToMain("M001", "S01", "Empty slice");
|
|
875
|
+
} catch (e) {
|
|
876
|
+
threw = true;
|
|
877
|
+
const msg = (e as Error).message;
|
|
878
|
+
assert(msg.includes("no commits ahead"), "error mentions no commits ahead");
|
|
879
|
+
assert(msg.includes("gsd/M001/S01"), "error includes branch name");
|
|
880
|
+
}
|
|
881
|
+
assert(threw, "mergeSliceToMain throws when no commits ahead");
|
|
882
|
+
|
|
883
|
+
rmSync(repo, { recursive: true, force: true });
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
887
|
+
// S05: Enhanced features — merge guards, snapshots, auto-push, rich commits
|
|
888
|
+
// ═══════════════════════════════════════════════════════════════════════
|
|
889
|
+
|
|
890
|
+
// ─── createSnapshot: prefs enabled ─────────────────────────────────────
|
|
891
|
+
|
|
892
|
+
console.log("\n=== createSnapshot: enabled ===");
|
|
893
|
+
|
|
894
|
+
{
|
|
895
|
+
const repo = initBranchTestRepo();
|
|
896
|
+
const svc = new GitServiceImpl(repo, { snapshots: true });
|
|
897
|
+
|
|
898
|
+
// Create a slice branch with a commit
|
|
899
|
+
svc.ensureSliceBranch("M001", "S01");
|
|
900
|
+
createFile(repo, "src/snap.ts", "snapshot me");
|
|
901
|
+
svc.commit({ message: "snapshot test commit" });
|
|
902
|
+
|
|
903
|
+
// Create snapshot ref for this slice branch
|
|
904
|
+
svc.createSnapshot("gsd/M001/S01");
|
|
905
|
+
|
|
906
|
+
// Verify ref exists under refs/gsd/snapshots/
|
|
907
|
+
const refs = run("git for-each-ref refs/gsd/snapshots/", repo);
|
|
908
|
+
assert(refs.includes("refs/gsd/snapshots/gsd/M001/S01/"), "snapshot ref created under refs/gsd/snapshots/");
|
|
909
|
+
|
|
910
|
+
rmSync(repo, { recursive: true, force: true });
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
// ─── createSnapshot: prefs disabled ────────────────────────────────────
|
|
914
|
+
|
|
915
|
+
console.log("\n=== createSnapshot: disabled ===");
|
|
916
|
+
|
|
917
|
+
{
|
|
918
|
+
const repo = initBranchTestRepo();
|
|
919
|
+
const svc = new GitServiceImpl(repo, { snapshots: false });
|
|
920
|
+
|
|
921
|
+
svc.ensureSliceBranch("M001", "S01");
|
|
922
|
+
createFile(repo, "src/no-snap.ts", "no snapshot");
|
|
923
|
+
svc.commit({ message: "no snapshot commit" });
|
|
924
|
+
|
|
925
|
+
// createSnapshot should be a no-op when disabled
|
|
926
|
+
svc.createSnapshot("gsd/M001/S01");
|
|
927
|
+
|
|
928
|
+
const refs = run("git for-each-ref refs/gsd/snapshots/", repo);
|
|
929
|
+
assertEq(refs, "", "no snapshot ref created when prefs.snapshots is false");
|
|
930
|
+
|
|
931
|
+
rmSync(repo, { recursive: true, force: true });
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
// ─── runPreMergeCheck: pass ────────────────────────────────────────────
|
|
935
|
+
|
|
936
|
+
console.log("\n=== runPreMergeCheck: pass ===");
|
|
937
|
+
|
|
938
|
+
{
|
|
939
|
+
const repo = initBranchTestRepo();
|
|
940
|
+
// Create package.json with passing test script
|
|
941
|
+
createFile(repo, "package.json", JSON.stringify({
|
|
942
|
+
name: "test-pass",
|
|
943
|
+
scripts: { test: "node -e 'process.exit(0)'" },
|
|
944
|
+
}));
|
|
945
|
+
run("git add -A", repo);
|
|
946
|
+
run("git commit -m 'add package.json'", repo);
|
|
947
|
+
|
|
948
|
+
const svc = new GitServiceImpl(repo, { pre_merge_check: true });
|
|
949
|
+
const result: PreMergeCheckResult = svc.runPreMergeCheck();
|
|
950
|
+
|
|
951
|
+
assertEq(result.passed, true, "runPreMergeCheck returns passed:true when tests pass");
|
|
952
|
+
assert(!result.skipped, "runPreMergeCheck is not skipped when enabled");
|
|
953
|
+
|
|
954
|
+
rmSync(repo, { recursive: true, force: true });
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
// ─── runPreMergeCheck: fail ────────────────────────────────────────────
|
|
958
|
+
|
|
959
|
+
console.log("\n=== runPreMergeCheck: fail ===");
|
|
960
|
+
|
|
961
|
+
{
|
|
962
|
+
const repo = initBranchTestRepo();
|
|
963
|
+
// Create package.json with failing test script
|
|
964
|
+
createFile(repo, "package.json", JSON.stringify({
|
|
965
|
+
name: "test-fail",
|
|
966
|
+
scripts: { test: "node -e 'process.exit(1)'" },
|
|
967
|
+
}));
|
|
968
|
+
run("git add -A", repo);
|
|
969
|
+
run("git commit -m 'add failing package.json'", repo);
|
|
970
|
+
|
|
971
|
+
const svc = new GitServiceImpl(repo, { pre_merge_check: true });
|
|
972
|
+
const result: PreMergeCheckResult = svc.runPreMergeCheck();
|
|
973
|
+
|
|
974
|
+
assertEq(result.passed, false, "runPreMergeCheck returns passed:false when tests fail");
|
|
975
|
+
assert(!result.skipped, "runPreMergeCheck is not skipped when enabled");
|
|
976
|
+
|
|
977
|
+
rmSync(repo, { recursive: true, force: true });
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
// ─── runPreMergeCheck: disabled ────────────────────────────────────────
|
|
981
|
+
|
|
982
|
+
console.log("\n=== runPreMergeCheck: disabled ===");
|
|
983
|
+
|
|
984
|
+
{
|
|
985
|
+
const repo = initBranchTestRepo();
|
|
986
|
+
createFile(repo, "package.json", JSON.stringify({
|
|
987
|
+
name: "test-disabled",
|
|
988
|
+
scripts: { test: "node -e 'process.exit(1)'" },
|
|
989
|
+
}));
|
|
990
|
+
run("git add -A", repo);
|
|
991
|
+
run("git commit -m 'add package.json'", repo);
|
|
992
|
+
|
|
993
|
+
const svc = new GitServiceImpl(repo, { pre_merge_check: false });
|
|
994
|
+
const result: PreMergeCheckResult = svc.runPreMergeCheck();
|
|
995
|
+
|
|
996
|
+
assertEq(result.skipped, true, "runPreMergeCheck skipped when pre_merge_check is false");
|
|
997
|
+
assertEq(result.passed, true, "runPreMergeCheck returns passed:true when skipped (no block)");
|
|
998
|
+
|
|
999
|
+
rmSync(repo, { recursive: true, force: true });
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
// ─── runPreMergeCheck: custom command ──────────────────────────────────
|
|
1003
|
+
|
|
1004
|
+
console.log("\n=== runPreMergeCheck: custom command ===");
|
|
1005
|
+
|
|
1006
|
+
{
|
|
1007
|
+
const repo = initBranchTestRepo();
|
|
1008
|
+
// Custom command string overrides auto-detection
|
|
1009
|
+
const svc = new GitServiceImpl(repo, { pre_merge_check: "node -e 'process.exit(0)'" });
|
|
1010
|
+
const result: PreMergeCheckResult = svc.runPreMergeCheck();
|
|
1011
|
+
|
|
1012
|
+
assertEq(result.passed, true, "runPreMergeCheck passes with custom command that exits 0");
|
|
1013
|
+
assert(!result.skipped, "custom command is not skipped");
|
|
1014
|
+
|
|
1015
|
+
rmSync(repo, { recursive: true, force: true });
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
// ─── Rich commit message ──────────────────────────────────────────────
|
|
1019
|
+
|
|
1020
|
+
console.log("\n=== mergeSliceToMain: rich commit message ===");
|
|
1021
|
+
|
|
1022
|
+
{
|
|
1023
|
+
const repo = initBranchTestRepo();
|
|
1024
|
+
const svc = new GitServiceImpl(repo, { pre_merge_check: false });
|
|
1025
|
+
|
|
1026
|
+
svc.ensureSliceBranch("M001", "S01");
|
|
1027
|
+
|
|
1028
|
+
// Make 3 distinct commits on the slice branch
|
|
1029
|
+
createFile(repo, "src/auth.ts", "export const auth = true;");
|
|
1030
|
+
svc.commit({ message: "add auth module" });
|
|
1031
|
+
|
|
1032
|
+
createFile(repo, "src/login.ts", "export const login = true;");
|
|
1033
|
+
svc.commit({ message: "add login page" });
|
|
1034
|
+
|
|
1035
|
+
createFile(repo, "src/session.ts", "export const session = true;");
|
|
1036
|
+
svc.commit({ message: "add session handling" });
|
|
1037
|
+
|
|
1038
|
+
svc.switchToMain();
|
|
1039
|
+
const result = svc.mergeSliceToMain("M001", "S01", "Implement user authentication");
|
|
1040
|
+
|
|
1041
|
+
// Inspect the full commit body on main
|
|
1042
|
+
const commitBody = run("git log -1 --format=%B", repo);
|
|
1043
|
+
|
|
1044
|
+
// Rich commit should have the subject line
|
|
1045
|
+
assert(commitBody.includes("feat(M001/S01): Implement user authentication"),
|
|
1046
|
+
"rich commit has conventional subject line");
|
|
1047
|
+
|
|
1048
|
+
// Rich commit body should include task list with commit subjects
|
|
1049
|
+
assert(commitBody.includes("add auth module"),
|
|
1050
|
+
"rich commit body includes first commit subject");
|
|
1051
|
+
assert(commitBody.includes("add login page"),
|
|
1052
|
+
"rich commit body includes second commit subject");
|
|
1053
|
+
assert(commitBody.includes("add session handling"),
|
|
1054
|
+
"rich commit body includes third commit subject");
|
|
1055
|
+
|
|
1056
|
+
// Rich commit body should include Branch: line for forensics
|
|
1057
|
+
assert(commitBody.includes("Branch:"),
|
|
1058
|
+
"rich commit body includes Branch: line");
|
|
1059
|
+
assert(commitBody.includes("gsd/M001/S01"),
|
|
1060
|
+
"rich commit body Branch: line includes slice branch name");
|
|
1061
|
+
|
|
1062
|
+
rmSync(repo, { recursive: true, force: true });
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
// ─── Auto-push: enabled ───────────────────────────────────────────────
|
|
1066
|
+
|
|
1067
|
+
console.log("\n=== Auto-push: enabled ===");
|
|
1068
|
+
|
|
1069
|
+
{
|
|
1070
|
+
// Create a bare remote repo
|
|
1071
|
+
const bareDir = mkdtempSync(join(tmpdir(), "gsd-git-bare-"));
|
|
1072
|
+
run("git init --bare -b main", bareDir);
|
|
1073
|
+
|
|
1074
|
+
// Create local repo and add the bare as remote
|
|
1075
|
+
const repo = initBranchTestRepo();
|
|
1076
|
+
run(`git remote add origin ${bareDir}`, repo);
|
|
1077
|
+
run("git push -u origin main", repo);
|
|
1078
|
+
|
|
1079
|
+
const svc = new GitServiceImpl(repo, { auto_push: true, pre_merge_check: false });
|
|
1080
|
+
|
|
1081
|
+
svc.ensureSliceBranch("M001", "S01");
|
|
1082
|
+
createFile(repo, "src/pushed.ts", "export const pushed = true;");
|
|
1083
|
+
svc.commit({ message: "work to push" });
|
|
1084
|
+
|
|
1085
|
+
svc.switchToMain();
|
|
1086
|
+
svc.mergeSliceToMain("M001", "S01", "Add pushed feature");
|
|
1087
|
+
|
|
1088
|
+
// Verify the remote has the merge commit
|
|
1089
|
+
const remoteLog = run(`git --git-dir=${bareDir} log --oneline -1`, bareDir);
|
|
1090
|
+
assert(remoteLog.includes("Add pushed feature"),
|
|
1091
|
+
"auto-push: remote has the merge commit when auto_push is true");
|
|
1092
|
+
|
|
1093
|
+
rmSync(repo, { recursive: true, force: true });
|
|
1094
|
+
rmSync(bareDir, { recursive: true, force: true });
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
// ─── Auto-push: disabled ──────────────────────────────────────────────
|
|
1098
|
+
|
|
1099
|
+
console.log("\n=== Auto-push: disabled ===");
|
|
1100
|
+
|
|
1101
|
+
{
|
|
1102
|
+
const bareDir = mkdtempSync(join(tmpdir(), "gsd-git-bare-"));
|
|
1103
|
+
run("git init --bare -b main", bareDir);
|
|
1104
|
+
|
|
1105
|
+
const repo = initBranchTestRepo();
|
|
1106
|
+
run(`git remote add origin ${bareDir}`, repo);
|
|
1107
|
+
run("git push -u origin main", repo);
|
|
1108
|
+
|
|
1109
|
+
// auto_push explicitly false (or omitted — same behavior)
|
|
1110
|
+
const svc = new GitServiceImpl(repo, { auto_push: false, pre_merge_check: false });
|
|
1111
|
+
|
|
1112
|
+
svc.ensureSliceBranch("M001", "S01");
|
|
1113
|
+
createFile(repo, "src/not-pushed.ts", "export const notPushed = true;");
|
|
1114
|
+
svc.commit({ message: "work not pushed" });
|
|
1115
|
+
|
|
1116
|
+
svc.switchToMain();
|
|
1117
|
+
svc.mergeSliceToMain("M001", "S01", "Add unpushed feature");
|
|
1118
|
+
|
|
1119
|
+
// Remote should NOT have the new merge commit — still at the initial push
|
|
1120
|
+
const remoteLog = run(`git --git-dir=${bareDir} log --oneline`, bareDir);
|
|
1121
|
+
assert(!remoteLog.includes("Add unpushed feature"),
|
|
1122
|
+
"auto-push: remote does NOT have merge commit when auto_push is false");
|
|
1123
|
+
|
|
1124
|
+
rmSync(repo, { recursive: true, force: true });
|
|
1125
|
+
rmSync(bareDir, { recursive: true, force: true });
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
// ─── Remote fetch before branching: with remote ────────────────────────
|
|
1129
|
+
|
|
1130
|
+
console.log("\n=== Remote fetch: with remote ===");
|
|
1131
|
+
|
|
1132
|
+
{
|
|
1133
|
+
const bareDir = mkdtempSync(join(tmpdir(), "gsd-git-bare-"));
|
|
1134
|
+
run("git init --bare -b main", bareDir);
|
|
1135
|
+
|
|
1136
|
+
const repo = initBranchTestRepo();
|
|
1137
|
+
run(`git remote add origin ${bareDir}`, repo);
|
|
1138
|
+
run("git push -u origin main", repo);
|
|
1139
|
+
|
|
1140
|
+
// Add a commit to the remote via a temporary clone
|
|
1141
|
+
const cloneDir = mkdtempSync(join(tmpdir(), "gsd-git-clone-"));
|
|
1142
|
+
run(`git clone ${bareDir} ${cloneDir}`, cloneDir);
|
|
1143
|
+
run("git config user.name 'Remote Dev'", cloneDir);
|
|
1144
|
+
run("git config user.email 'remote@example.com'", cloneDir);
|
|
1145
|
+
createFile(cloneDir, "remote-file.txt", "from remote");
|
|
1146
|
+
run("git add -A", cloneDir);
|
|
1147
|
+
run("git commit -m 'remote commit'", cloneDir);
|
|
1148
|
+
run("git push origin main", cloneDir);
|
|
1149
|
+
|
|
1150
|
+
// ensureSliceBranch should fetch before creating the branch — no crash
|
|
1151
|
+
const svc = new GitServiceImpl(repo);
|
|
1152
|
+
let noError = true;
|
|
1153
|
+
try {
|
|
1154
|
+
svc.ensureSliceBranch("M001", "S01");
|
|
1155
|
+
} catch {
|
|
1156
|
+
noError = false;
|
|
1157
|
+
}
|
|
1158
|
+
assert(noError, "ensureSliceBranch succeeds when remote has new commits (fetch runs)");
|
|
1159
|
+
|
|
1160
|
+
rmSync(repo, { recursive: true, force: true });
|
|
1161
|
+
rmSync(bareDir, { recursive: true, force: true });
|
|
1162
|
+
rmSync(cloneDir, { recursive: true, force: true });
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
// ─── Remote fetch before branching: without remote ─────────────────────
|
|
1166
|
+
|
|
1167
|
+
console.log("\n=== Remote fetch: without remote ===");
|
|
1168
|
+
|
|
1169
|
+
{
|
|
1170
|
+
const repo = initBranchTestRepo();
|
|
1171
|
+
// No remote configured — ensureSliceBranch should not crash
|
|
1172
|
+
const svc = new GitServiceImpl(repo);
|
|
1173
|
+
|
|
1174
|
+
let noError = true;
|
|
1175
|
+
try {
|
|
1176
|
+
svc.ensureSliceBranch("M001", "S01");
|
|
1177
|
+
} catch {
|
|
1178
|
+
noError = false;
|
|
1179
|
+
}
|
|
1180
|
+
assert(noError, "ensureSliceBranch succeeds when no remote is configured");
|
|
1181
|
+
assertEq(svc.getCurrentBranch(), "gsd/M001/S01", "branch created even without remote");
|
|
1182
|
+
|
|
1183
|
+
rmSync(repo, { recursive: true, force: true });
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
// ─── Facade prefs: mergeSliceToMain creates snapshot when prefs set ────
|
|
1187
|
+
|
|
1188
|
+
console.log("\n=== Facade prefs: snapshot via merge with prefs ===");
|
|
1189
|
+
|
|
1190
|
+
{
|
|
1191
|
+
const repo = initBranchTestRepo();
|
|
1192
|
+
// Simulate facade behavior: GitServiceImpl with snapshots:true should
|
|
1193
|
+
// create a snapshot ref during mergeSliceToMain
|
|
1194
|
+
const svc = new GitServiceImpl(repo, { snapshots: true, pre_merge_check: false });
|
|
1195
|
+
|
|
1196
|
+
svc.ensureSliceBranch("M001", "S01");
|
|
1197
|
+
createFile(repo, "src/facade-test.ts", "facade");
|
|
1198
|
+
svc.commit({ message: "facade test commit" });
|
|
1199
|
+
|
|
1200
|
+
svc.switchToMain();
|
|
1201
|
+
svc.mergeSliceToMain("M001", "S01", "Facade snapshot test");
|
|
1202
|
+
|
|
1203
|
+
// After merge, a snapshot ref should exist (created before merge)
|
|
1204
|
+
const refs = run("git for-each-ref refs/gsd/snapshots/", repo);
|
|
1205
|
+
assert(refs.includes("refs/gsd/snapshots/"), "mergeSliceToMain creates snapshot when prefs.snapshots is true");
|
|
1206
|
+
assert(refs.includes("gsd/M001/S01"), "snapshot ref references the slice branch name");
|
|
1207
|
+
|
|
1208
|
+
rmSync(repo, { recursive: true, force: true });
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
// ─── Facade prefs: no snapshot when prefs omit snapshots ───────────────
|
|
1212
|
+
|
|
1213
|
+
console.log("\n=== Facade prefs: no snapshot when prefs omit snapshots ===");
|
|
1214
|
+
|
|
1215
|
+
{
|
|
1216
|
+
const repo = initBranchTestRepo();
|
|
1217
|
+
// Default prefs — snapshots not enabled
|
|
1218
|
+
const svc = new GitServiceImpl(repo, { pre_merge_check: false });
|
|
1219
|
+
|
|
1220
|
+
svc.ensureSliceBranch("M001", "S01");
|
|
1221
|
+
createFile(repo, "src/no-facade-snap.ts", "no facade snap");
|
|
1222
|
+
svc.commit({ message: "no facade snapshot" });
|
|
1223
|
+
|
|
1224
|
+
svc.switchToMain();
|
|
1225
|
+
svc.mergeSliceToMain("M001", "S01", "No snapshot test");
|
|
1226
|
+
|
|
1227
|
+
// No snapshot ref should exist
|
|
1228
|
+
const refs = run("git for-each-ref refs/gsd/snapshots/", repo);
|
|
1229
|
+
assertEq(refs, "", "no snapshot ref when snapshots pref is not set");
|
|
1230
|
+
|
|
1231
|
+
rmSync(repo, { recursive: true, force: true });
|
|
1232
|
+
}
|
|
1233
|
+
|
|
1234
|
+
// ─── VALID_BRANCH_NAME regex ──────────────────────────────────────────
|
|
1235
|
+
|
|
1236
|
+
console.log("\n=== VALID_BRANCH_NAME regex ===");
|
|
1237
|
+
|
|
1238
|
+
{
|
|
1239
|
+
// Valid branch names
|
|
1240
|
+
assert(VALID_BRANCH_NAME.test("main"), "VALID_BRANCH_NAME accepts 'main'");
|
|
1241
|
+
assert(VALID_BRANCH_NAME.test("master"), "VALID_BRANCH_NAME accepts 'master'");
|
|
1242
|
+
assert(VALID_BRANCH_NAME.test("develop"), "VALID_BRANCH_NAME accepts 'develop'");
|
|
1243
|
+
assert(VALID_BRANCH_NAME.test("feature/foo"), "VALID_BRANCH_NAME accepts 'feature/foo'");
|
|
1244
|
+
assert(VALID_BRANCH_NAME.test("release-1.0"), "VALID_BRANCH_NAME accepts 'release-1.0'");
|
|
1245
|
+
assert(VALID_BRANCH_NAME.test("my_branch"), "VALID_BRANCH_NAME accepts 'my_branch'");
|
|
1246
|
+
assert(VALID_BRANCH_NAME.test("v2.0.1"), "VALID_BRANCH_NAME accepts 'v2.0.1'");
|
|
1247
|
+
|
|
1248
|
+
// Invalid / injection attempts
|
|
1249
|
+
assert(!VALID_BRANCH_NAME.test("main; rm -rf /"), "VALID_BRANCH_NAME rejects shell injection");
|
|
1250
|
+
assert(!VALID_BRANCH_NAME.test("main && echo pwned"), "VALID_BRANCH_NAME rejects && injection");
|
|
1251
|
+
assert(!VALID_BRANCH_NAME.test(""), "VALID_BRANCH_NAME rejects empty string");
|
|
1252
|
+
assert(!VALID_BRANCH_NAME.test("branch name"), "VALID_BRANCH_NAME rejects spaces");
|
|
1253
|
+
assert(!VALID_BRANCH_NAME.test("branch`cmd`"), "VALID_BRANCH_NAME rejects backticks");
|
|
1254
|
+
assert(!VALID_BRANCH_NAME.test("branch$(cmd)"), "VALID_BRANCH_NAME rejects $() subshell");
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
// ─── getMainBranch: configured main_branch preference ──────────────────
|
|
1258
|
+
|
|
1259
|
+
console.log("\n=== getMainBranch: configured main_branch ===");
|
|
1260
|
+
|
|
1261
|
+
{
|
|
1262
|
+
const repo = initBranchTestRepo();
|
|
1263
|
+
const svc = new GitServiceImpl(repo, { main_branch: "trunk" });
|
|
1264
|
+
|
|
1265
|
+
assertEq(svc.getMainBranch(), "trunk", "getMainBranch returns configured main_branch preference");
|
|
1266
|
+
|
|
1267
|
+
rmSync(repo, { recursive: true, force: true });
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
// ─── getMainBranch: falls back to auto-detection when not set ──────────
|
|
1271
|
+
|
|
1272
|
+
console.log("\n=== getMainBranch: fallback to auto-detection ===");
|
|
1273
|
+
|
|
1274
|
+
{
|
|
1275
|
+
const repo = initBranchTestRepo();
|
|
1276
|
+
const svc = new GitServiceImpl(repo, {});
|
|
1277
|
+
|
|
1278
|
+
assertEq(svc.getMainBranch(), "main", "getMainBranch falls back to auto-detection when main_branch not set");
|
|
1279
|
+
|
|
1280
|
+
rmSync(repo, { recursive: true, force: true });
|
|
1281
|
+
}
|
|
1282
|
+
|
|
1283
|
+
// ─── getMainBranch: ignores invalid branch names ───────────────────────
|
|
1284
|
+
|
|
1285
|
+
console.log("\n=== getMainBranch: ignores invalid branch name ===");
|
|
1286
|
+
|
|
1287
|
+
{
|
|
1288
|
+
const repo = initBranchTestRepo();
|
|
1289
|
+
const svc = new GitServiceImpl(repo, { main_branch: "main; rm -rf /" });
|
|
1290
|
+
|
|
1291
|
+
assertEq(svc.getMainBranch(), "main", "getMainBranch ignores invalid branch name and falls back to auto-detection");
|
|
1292
|
+
|
|
1293
|
+
rmSync(repo, { recursive: true, force: true });
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
// ─── PreMergeCheckResult type export compile check ─────────────────────
|
|
1297
|
+
|
|
1298
|
+
console.log("\n=== PreMergeCheckResult type export ===");
|
|
1299
|
+
|
|
1300
|
+
{
|
|
1301
|
+
const _checkResult: PreMergeCheckResult = { passed: true, skipped: false };
|
|
1302
|
+
assert(true, "PreMergeCheckResult type exported and usable");
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
console.log(`\nResults: ${passed} passed, ${failed} failed`);
|
|
1306
|
+
if (failed > 0) process.exit(1);
|
|
1307
|
+
console.log("All tests passed ✓");
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
main().catch((error) => {
|
|
1311
|
+
console.error(error);
|
|
1312
|
+
process.exit(1);
|
|
1313
|
+
});
|