@jeancodogno/specforce-kit 0.1.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/.geminiignore +15 -0
- package/.github/workflows/ci.yml +100 -0
- package/.github/workflows/release.yml +51 -0
- package/.golangci.yml +21 -0
- package/.goreleaser.yaml +43 -0
- package/.rgignore +13 -0
- package/.specforce/config.yaml +32 -0
- package/.specforce/docs/.gitkeep +0 -0
- package/.specforce/docs/architecture.md +98 -0
- package/.specforce/docs/engineering.md +80 -0
- package/.specforce/docs/governance.md +30 -0
- package/.specforce/docs/memorial.md +44 -0
- package/.specforce/docs/principles.md +31 -0
- package/.specforce/docs/security.md +31 -0
- package/.specforce/docs/ui-ux.md +129 -0
- package/.specforce/specs/.gitkeep +0 -0
- package/AGENTS.md +36 -0
- package/CONTRIBUTING.md +81 -0
- package/LICENSE +21 -0
- package/Makefile +49 -0
- package/README.md +144 -0
- package/assets/logo-header.png +0 -0
- package/assets/logo.png +0 -0
- package/docs/artifacts.md +41 -0
- package/docs/cli.md +73 -0
- package/docs/configuration.md +50 -0
- package/docs/getting-started.md +110 -0
- package/docs/supported-tools.md +14 -0
- package/go.mod +35 -0
- package/go.sum +61 -0
- package/index.js +0 -0
- package/package.json +26 -0
- package/src/cmd/specforce/main.go +23 -0
- package/src/cmd/specforce/main_test.go +7 -0
- package/src/internal/agent/artifacts/constitution/architecture.yaml +70 -0
- package/src/internal/agent/artifacts/constitution/engineering.yaml +52 -0
- package/src/internal/agent/artifacts/constitution/governance.yaml +41 -0
- package/src/internal/agent/artifacts/constitution/memorial.yaml +55 -0
- package/src/internal/agent/artifacts/constitution/principles.yaml +54 -0
- package/src/internal/agent/artifacts/constitution/security.yaml +47 -0
- package/src/internal/agent/artifacts/constitution/ui-ux.yaml +158 -0
- package/src/internal/agent/artifacts/spec/design.yaml +50 -0
- package/src/internal/agent/artifacts/spec/requirements.yaml +48 -0
- package/src/internal/agent/artifacts/spec/tasks.yaml +55 -0
- package/src/internal/agent/compatibility_test.go +120 -0
- package/src/internal/agent/cwd_test.go +9 -0
- package/src/internal/agent/embed.go +19 -0
- package/src/internal/agent/integration_test.go +138 -0
- package/src/internal/agent/kit/agents/product-analyst.yaml +31 -0
- package/src/internal/agent/kit/agents/technical-developer.yaml +28 -0
- package/src/internal/agent/kit/agents/technical-project-planner.yaml +30 -0
- package/src/internal/agent/kit/agents/technical-qa-engineer.yaml +36 -0
- package/src/internal/agent/kit/agents/technical-solution-architect.yaml +32 -0
- package/src/internal/agent/kit/commands/archive.yaml +25 -0
- package/src/internal/agent/kit/commands/constitution.yaml +132 -0
- package/src/internal/agent/kit/commands/implement.yaml +96 -0
- package/src/internal/agent/kit/commands/spec.yaml +94 -0
- package/src/internal/agent/kit/instructions/archive.md +68 -0
- package/src/internal/agent/kit/kit.yaml +111 -0
- package/src/internal/agent/kit/skills/opportunity-framing/SKILL.yaml +56 -0
- package/src/internal/agent/kit/skills/pragmatic-product-owner/SKILL.yaml +58 -0
- package/src/internal/agent/kit/skills/pragmatic-product-owner/references/spec-artifacts.yaml +38 -0
- package/src/internal/agent/kit/skills/spec-clarification-interview/SKILL.yaml +52 -0
- package/src/internal/agent/kit/skills/task-atomic-decomposition/SKILL.yaml +137 -0
- package/src/internal/agent/kit/skills/task-atomic-decomposition/references/roadmap-patterns.yaml +103 -0
- package/src/internal/agent/kit_manifests_test.go +58 -0
- package/src/internal/agent/manifest.go +15 -0
- package/src/internal/agent/registry.go +69 -0
- package/src/internal/agent/registry_test.go +51 -0
- package/src/internal/agent/translator.go +334 -0
- package/src/internal/agent/translator_test.go +734 -0
- package/src/internal/cli/archive.go +91 -0
- package/src/internal/cli/archive_test.go +67 -0
- package/src/internal/cli/cli.go +259 -0
- package/src/internal/cli/cli_test.go +130 -0
- package/src/internal/cli/cobra/archive.go +26 -0
- package/src/internal/cli/cobra/console.go +21 -0
- package/src/internal/cli/cobra/constitution.go +44 -0
- package/src/internal/cli/cobra/dummy_test.go +7 -0
- package/src/internal/cli/cobra/implementation.go +50 -0
- package/src/internal/cli/cobra/init.go +23 -0
- package/src/internal/cli/cobra/install.go +21 -0
- package/src/internal/cli/cobra/root.go +47 -0
- package/src/internal/cli/cobra/spec.go +91 -0
- package/src/internal/cli/console.go +48 -0
- package/src/internal/cli/constitution.go +190 -0
- package/src/internal/cli/constitution_test.go +50 -0
- package/src/internal/cli/implementation.go +153 -0
- package/src/internal/cli/implementation_test.go +165 -0
- package/src/internal/cli/spec.go +369 -0
- package/src/internal/cli/spec_test.go +85 -0
- package/src/internal/constitution/registry.go +139 -0
- package/src/internal/constitution/registry_test.go +97 -0
- package/src/internal/constitution/status.go +70 -0
- package/src/internal/constitution/status_test.go +160 -0
- package/src/internal/core/blueprint.go +49 -0
- package/src/internal/core/blueprint_test.go +58 -0
- package/src/internal/core/config.go +124 -0
- package/src/internal/core/config_test.go +145 -0
- package/src/internal/core/constants.go +13 -0
- package/src/internal/core/errors.go +31 -0
- package/src/internal/core/errors_test.go +48 -0
- package/src/internal/core/hooks.go +89 -0
- package/src/internal/core/hooks_test.go +51 -0
- package/src/internal/core/kit.go +15 -0
- package/src/internal/core/kit_test.go +65 -0
- package/src/internal/core/path.go +115 -0
- package/src/internal/core/path_test.go +101 -0
- package/src/internal/core/ui.go +19 -0
- package/src/internal/installer/dependencies.go +23 -0
- package/src/internal/installer/install.go +89 -0
- package/src/internal/installer/installer.go +45 -0
- package/src/internal/installer/installer_test.go +96 -0
- package/src/internal/project/agents_md.go +108 -0
- package/src/internal/project/agents_md_test.go +101 -0
- package/src/internal/project/bootstrapper.go +64 -0
- package/src/internal/project/bootstrapper_test.go +89 -0
- package/src/internal/project/detector.go +35 -0
- package/src/internal/project/detector_test.go +96 -0
- package/src/internal/project/refresh_integration_test.go +86 -0
- package/src/internal/project/service.go +93 -0
- package/src/internal/project/service_test.go +135 -0
- package/src/internal/spec/archive.go +49 -0
- package/src/internal/spec/archive_test.go +55 -0
- package/src/internal/spec/discovery.go +53 -0
- package/src/internal/spec/discovery_test.go +60 -0
- package/src/internal/spec/implementation.go +296 -0
- package/src/internal/spec/implementation_test.go +253 -0
- package/src/internal/spec/registry.go +142 -0
- package/src/internal/spec/registry_test.go +105 -0
- package/src/internal/spec/scanner.go +219 -0
- package/src/internal/spec/scanner_test.go +243 -0
- package/src/internal/spec/service.go +157 -0
- package/src/internal/spec/service_test.go +238 -0
- package/src/internal/spec/status.go +94 -0
- package/src/internal/spec/status_test.go +146 -0
- package/src/internal/spec/tasks.go +103 -0
- package/src/internal/spec/tasks_test.go +137 -0
- package/src/internal/tui/components.go +132 -0
- package/src/internal/tui/console.go +247 -0
- package/src/internal/tui/console_test.go +19 -0
- package/src/internal/tui/constitution.go +36 -0
- package/src/internal/tui/constitution_test.go +32 -0
- package/src/internal/tui/implementation.go +151 -0
- package/src/internal/tui/logo.go +89 -0
- package/src/internal/tui/multiselect.go +199 -0
- package/src/internal/tui/progressbar.go +37 -0
- package/src/internal/tui/progressbar_test.go +30 -0
- package/src/internal/tui/spec.go +35 -0
- package/src/internal/tui/spinner.go +66 -0
- package/src/internal/tui/terminal.go +18 -0
- package/src/internal/tui/theme.go +125 -0
- package/src/internal/tui/ui.go +52 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
package spec
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"fmt"
|
|
6
|
+
"strings"
|
|
7
|
+
|
|
8
|
+
"github.com/jeancodogno/specforce-kit/src/internal/core"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
// ConfigProvider defines the contract for project configuration access.
|
|
12
|
+
type ConfigProvider interface {
|
|
13
|
+
GetConfig(ctx context.Context) (*core.ProjectConfig, error)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Service orchestrates specification management logic.
|
|
17
|
+
type Service struct {
|
|
18
|
+
registry *Registry
|
|
19
|
+
configProvider ConfigProvider
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// NewService creates a new instance of the spec service.
|
|
23
|
+
func NewService(registry *Registry, configProvider ConfigProvider) *Service {
|
|
24
|
+
return &Service{
|
|
25
|
+
registry: registry,
|
|
26
|
+
configProvider: configProvider,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// GetArtifact retrieves a specific artifact by name, injecting custom project instructions if present.
|
|
31
|
+
func (s *Service) GetArtifact(ctx context.Context, name string) (*Artifact, error) {
|
|
32
|
+
art, ok := s.registry.Get(name)
|
|
33
|
+
if !ok {
|
|
34
|
+
return nil, fmt.Errorf("artifact %q not found", name)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if s.configProvider != nil {
|
|
38
|
+
conf, err := s.configProvider.GetConfig(ctx)
|
|
39
|
+
if err == nil && conf != nil {
|
|
40
|
+
if rules, ok := conf.Instructions[name]; ok && len(rules) > 0 {
|
|
41
|
+
custom := "\n\n## Project Specific Instructions\n- " + strings.Join(rules, "\n- ")
|
|
42
|
+
art.Instruction += custom
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return &art, nil
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// GetImplementationStatus retrieves the status and details for implementing a specific feature.
|
|
51
|
+
func (s *Service) GetImplementationStatus(ctx context.Context, projectRoot, slug string) (*ImplementationReport, error) {
|
|
52
|
+
// 1. Check artifacts
|
|
53
|
+
ok, missing := CheckTriadArtifacts(projectRoot, slug)
|
|
54
|
+
|
|
55
|
+
// 2. Parse tasks
|
|
56
|
+
report, err := ParseTasks(ctx, projectRoot, slug)
|
|
57
|
+
if err != nil {
|
|
58
|
+
return nil, err
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
report.MissingArtifacts = missing
|
|
62
|
+
if !ok {
|
|
63
|
+
report.Status = "blocked"
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 3. Get context files
|
|
67
|
+
contextFiles, err := GetContextFiles(projectRoot, slug)
|
|
68
|
+
if err == nil {
|
|
69
|
+
report.ContextFiles = contextFiles
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 4. Inject instructions
|
|
73
|
+
if s.configProvider != nil {
|
|
74
|
+
conf, err := s.configProvider.GetConfig(ctx)
|
|
75
|
+
if err == nil && conf != nil {
|
|
76
|
+
if rules, ok := conf.Instructions["implementation"]; ok {
|
|
77
|
+
report.Instructions = rules
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return report, nil
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// GetStatus retrieves the status of a specific feature spec.
|
|
86
|
+
func (s *Service) GetStatus(ctx context.Context, projectRoot string, slug string) (SpecStatus, error) {
|
|
87
|
+
return GetStatus(ctx, projectRoot, slug, s.registry)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// UpdateTaskStatus handles task status updates with event hooks.
|
|
91
|
+
func (s *Service) UpdateTaskStatus(ctx context.Context, projectRoot, slug, taskID, status string) error {
|
|
92
|
+
// 1. Only run hooks if status is "finished"
|
|
93
|
+
if strings.ToLower(status) != "finished" {
|
|
94
|
+
return updateTaskStatusFile(projectRoot, slug, taskID, status)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 2. Load Config
|
|
98
|
+
var config *core.ProjectConfig
|
|
99
|
+
if s.configProvider != nil {
|
|
100
|
+
if c, err := s.configProvider.GetConfig(ctx); err == nil {
|
|
101
|
+
config = c
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// 3. Collect Hooks
|
|
106
|
+
hooks := s.collectHooksForTask(ctx, projectRoot, slug, taskID, config)
|
|
107
|
+
|
|
108
|
+
// 4. Execute Hooks
|
|
109
|
+
if len(hooks) > 0 {
|
|
110
|
+
if _, err := core.ExecuteHooks(ctx, hooks); err != nil {
|
|
111
|
+
return fmt.Errorf("hooks failed: %w", err)
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 5. Update File
|
|
116
|
+
return updateTaskStatusFile(projectRoot, slug, taskID, status)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
func (s *Service) collectHooksForTask(ctx context.Context, projectRoot, slug, taskID string, config *core.ProjectConfig) []string {
|
|
120
|
+
var hooks []string
|
|
121
|
+
if config == nil {
|
|
122
|
+
return hooks
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Always add task finished hook
|
|
126
|
+
hooks = append(hooks, config.Hooks.OnTaskFinished...)
|
|
127
|
+
|
|
128
|
+
// Use ParseTasks to determine if this is the last task in a phase or spec
|
|
129
|
+
report, err := ParseTasks(ctx, projectRoot, slug)
|
|
130
|
+
if err != nil {
|
|
131
|
+
return hooks
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
isLastInPhase, isLastInSpec := s.checkTaskPosition(report, taskID)
|
|
135
|
+
|
|
136
|
+
if isLastInPhase {
|
|
137
|
+
hooks = append(hooks, config.Hooks.OnPhaseFinished...)
|
|
138
|
+
}
|
|
139
|
+
if isLastInSpec {
|
|
140
|
+
hooks = append(hooks, config.Hooks.OnAllTasksFinished...)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return hooks
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
func (s *Service) checkTaskPosition(report *ImplementationReport, taskID string) (bool, bool) {
|
|
147
|
+
for pi, p := range report.Phases {
|
|
148
|
+
for ti, t := range p.Tasks {
|
|
149
|
+
if t.ID == taskID {
|
|
150
|
+
isLastInPhase := (ti == len(p.Tasks)-1)
|
|
151
|
+
isLastInSpec := (pi == len(report.Phases)-1 && ti == len(p.Tasks)-1)
|
|
152
|
+
return isLastInPhase, isLastInSpec
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return false, false
|
|
157
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
package spec
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"os"
|
|
6
|
+
"path/filepath"
|
|
7
|
+
"strings"
|
|
8
|
+
"testing"
|
|
9
|
+
"testing/fstest"
|
|
10
|
+
|
|
11
|
+
"github.com/jeancodogno/specforce-kit/src/internal/core"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
type mockConfigProvider struct {
|
|
15
|
+
config *core.ProjectConfig
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
func (m *mockConfigProvider) GetConfig(ctx context.Context) (*core.ProjectConfig, error) {
|
|
19
|
+
return m.config, nil
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
func TestGetArtifact(t *testing.T) {
|
|
23
|
+
artifactsFS := fstest.MapFS{
|
|
24
|
+
"requirements.yaml": &fstest.MapFile{Data: []byte(`
|
|
25
|
+
description: Requirements Template
|
|
26
|
+
instruction: Requirements Instruction
|
|
27
|
+
template: Requirements Template Content
|
|
28
|
+
`)},
|
|
29
|
+
}
|
|
30
|
+
reg, _ := NewRegistry(artifactsFS)
|
|
31
|
+
|
|
32
|
+
t.Run("success without custom instructions", func(t *testing.T) {
|
|
33
|
+
svc := NewService(reg, nil)
|
|
34
|
+
art, err := svc.GetArtifact(context.Background(), "requirements")
|
|
35
|
+
if err != nil {
|
|
36
|
+
t.Fatalf("GetArtifact failed: %v", err)
|
|
37
|
+
}
|
|
38
|
+
if art.Name != "requirements" {
|
|
39
|
+
t.Errorf("expected 'requirements', got %v", art.Name)
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
t.Run("success with custom instructions", func(t *testing.T) {
|
|
44
|
+
config := &core.ProjectConfig{
|
|
45
|
+
Instructions: map[string][]string{
|
|
46
|
+
"requirements": {"Custom 1", "Custom 2"},
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
svc := NewService(reg, &mockConfigProvider{config: config})
|
|
50
|
+
art, err := svc.GetArtifact(context.Background(), "requirements")
|
|
51
|
+
if err != nil {
|
|
52
|
+
t.Fatalf("GetArtifact failed: %v", err)
|
|
53
|
+
}
|
|
54
|
+
if !strings.Contains(art.Instruction, "Custom 1") || !strings.Contains(art.Instruction, "Custom 2") {
|
|
55
|
+
t.Errorf("custom instructions not injected")
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
t.Run("success with empty custom instructions", func(t *testing.T) {
|
|
60
|
+
config := &core.ProjectConfig{
|
|
61
|
+
Instructions: map[string][]string{
|
|
62
|
+
"requirements": {},
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
svc := NewService(reg, &mockConfigProvider{config: config})
|
|
66
|
+
art, err := svc.GetArtifact(context.Background(), "requirements")
|
|
67
|
+
if err != nil {
|
|
68
|
+
t.Fatalf("GetArtifact failed: %v", err)
|
|
69
|
+
}
|
|
70
|
+
if strings.Contains(art.Instruction, "Project Specific Instructions") {
|
|
71
|
+
t.Errorf("expected no project specific instructions, got %v", art.Instruction)
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
t.Run("not found", func(t *testing.T) {
|
|
76
|
+
svc := NewService(reg, nil)
|
|
77
|
+
_, err := svc.GetArtifact(context.Background(), "non-existent")
|
|
78
|
+
if err == nil {
|
|
79
|
+
t.Fatal("expected error for non-existent artifact")
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
func TestGetImplementationStatus(t *testing.T) {
|
|
85
|
+
tmpDir := t.TempDir()
|
|
86
|
+
slug := "test-slug"
|
|
87
|
+
specDir := filepath.Join(tmpDir, ".specforce", "specs", slug)
|
|
88
|
+
if err := os.MkdirAll(specDir, 0755); err != nil {
|
|
89
|
+
t.Fatal(err)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
content := `
|
|
93
|
+
# Implementation Tasks
|
|
94
|
+
### Phase 1: Core
|
|
95
|
+
#### T1.1: Task 1
|
|
96
|
+
**State:** [PENDING]
|
|
97
|
+
`
|
|
98
|
+
if err := os.WriteFile(filepath.Join(specDir, "tasks.md"), []byte(content), 0644); err != nil {
|
|
99
|
+
t.Fatal(err)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Create requirements.md and design.md to avoid "blocked" status
|
|
103
|
+
if err := os.WriteFile(filepath.Join(specDir, "requirements.md"), []byte("# Requirements"), 0644); err != nil {
|
|
104
|
+
t.Fatal(err)
|
|
105
|
+
}
|
|
106
|
+
if err := os.WriteFile(filepath.Join(specDir, "design.md"), []byte("# Design"), 0644); err != nil {
|
|
107
|
+
t.Fatal(err)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
t.Run("success with instructions", func(t *testing.T) {
|
|
111
|
+
config := &core.ProjectConfig{
|
|
112
|
+
Instructions: map[string][]string{
|
|
113
|
+
"implementation": {"Do it right"},
|
|
114
|
+
},
|
|
115
|
+
}
|
|
116
|
+
svc := NewService(nil, &mockConfigProvider{config: config})
|
|
117
|
+
report, err := svc.GetImplementationStatus(context.Background(), tmpDir, slug)
|
|
118
|
+
if err != nil {
|
|
119
|
+
t.Fatalf("GetImplementationStatus failed: %v", err)
|
|
120
|
+
}
|
|
121
|
+
if report.Status != "ready" {
|
|
122
|
+
t.Errorf("expected status 'ready', got %v", report.Status)
|
|
123
|
+
}
|
|
124
|
+
if len(report.Instructions) == 0 || report.Instructions[0] != "Do it right" {
|
|
125
|
+
t.Errorf("instructions not injected")
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
t.Run("success without configProvider", func(t *testing.T) {
|
|
130
|
+
svc := NewService(nil, nil)
|
|
131
|
+
report, err := svc.GetImplementationStatus(context.Background(), tmpDir, slug)
|
|
132
|
+
if err != nil {
|
|
133
|
+
t.Fatalf("GetImplementationStatus failed: %v", err)
|
|
134
|
+
}
|
|
135
|
+
if len(report.Instructions) != 0 {
|
|
136
|
+
t.Errorf("expected no instructions")
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
func TestService_GetStatus(t *testing.T) {
|
|
142
|
+
tmpDir := t.TempDir()
|
|
143
|
+
slug := "test-slug"
|
|
144
|
+
specDir := filepath.Join(tmpDir, ".specforce", "specs", slug)
|
|
145
|
+
if err := os.MkdirAll(specDir, 0755); err != nil {
|
|
146
|
+
t.Fatal(err)
|
|
147
|
+
}
|
|
148
|
+
if err := os.WriteFile(filepath.Join(specDir, "requirements.md"), []byte("# Req"), 0644); err != nil {
|
|
149
|
+
t.Fatal(err)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
reg, _ := NewRegistry(fstest.MapFS{
|
|
153
|
+
"requirements.yaml": &fstest.MapFile{Data: []byte("description: R\ninstruction: I\ntemplate: T")},
|
|
154
|
+
})
|
|
155
|
+
svc := NewService(reg, nil)
|
|
156
|
+
|
|
157
|
+
status, err := svc.GetStatus(context.Background(), tmpDir, slug)
|
|
158
|
+
if err != nil {
|
|
159
|
+
t.Fatalf("GetStatus failed: %v", err)
|
|
160
|
+
}
|
|
161
|
+
if status.Slug != slug {
|
|
162
|
+
t.Errorf("expected slug %v, got %v", slug, status.Slug)
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
func TestUpdateTaskStatus_Success(t *testing.T) {
|
|
167
|
+
tmpDir := t.TempDir()
|
|
168
|
+
slug := "test-slug"
|
|
169
|
+
tasksDir := filepath.Join(tmpDir, ".specforce", "specs", slug)
|
|
170
|
+
if err := os.MkdirAll(tasksDir, 0755); err != nil {
|
|
171
|
+
t.Fatal(err)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
content := "### Phase 1\n#### T1.1: Init\n**State:** [PENDING]\n#### T1.2: Next\n**State:** [PENDING]"
|
|
175
|
+
if err := os.WriteFile(filepath.Join(tasksDir, "tasks.md"), []byte(content), 0644); err != nil {
|
|
176
|
+
t.Fatal(err)
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
config := &core.ProjectConfig{
|
|
180
|
+
Hooks: core.HooksConfig{OnTaskFinished: []string{"echo task"}},
|
|
181
|
+
}
|
|
182
|
+
svc := NewService(nil, &mockConfigProvider{config: config})
|
|
183
|
+
|
|
184
|
+
t.Run("normal task finished", func(t *testing.T) {
|
|
185
|
+
err := svc.UpdateTaskStatus(context.Background(), tmpDir, slug, "T1.1", "finished")
|
|
186
|
+
if err != nil {
|
|
187
|
+
t.Fatalf("UpdateTaskStatus failed: %v", err)
|
|
188
|
+
}
|
|
189
|
+
updatedContent, _ := os.ReadFile(filepath.Join(tasksDir, "tasks.md"))
|
|
190
|
+
if !strings.Contains(string(updatedContent), "#### T1.1: Init\n**State:** [FINISHED]") {
|
|
191
|
+
t.Errorf("T1.1 not updated")
|
|
192
|
+
}
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
t.Run("update non-finished status", func(t *testing.T) {
|
|
196
|
+
err := svc.UpdateTaskStatus(context.Background(), tmpDir, slug, "T1.2", "in-progress")
|
|
197
|
+
if err != nil {
|
|
198
|
+
t.Fatal(err)
|
|
199
|
+
}
|
|
200
|
+
updatedContent, _ := os.ReadFile(filepath.Join(tasksDir, "tasks.md"))
|
|
201
|
+
if !strings.Contains(string(updatedContent), "#### T1.2: Next\n**State:** [IN-PROGRESS]") {
|
|
202
|
+
t.Errorf("T1.2 not updated")
|
|
203
|
+
}
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
func TestUpdateTaskStatus_Hooks(t *testing.T) {
|
|
208
|
+
tmpDir := t.TempDir()
|
|
209
|
+
slug := "hooks-slug"
|
|
210
|
+
tasksDir := filepath.Join(tmpDir, ".specforce", "specs", slug)
|
|
211
|
+
if err := os.MkdirAll(tasksDir, 0755); err != nil {
|
|
212
|
+
t.Fatal(err)
|
|
213
|
+
}
|
|
214
|
+
content := "### Phase 1\n#### T1.1: Task\n**State:** [PENDING]"
|
|
215
|
+
if err := os.WriteFile(filepath.Join(tasksDir, "tasks.md"), []byte(content), 0644); err != nil {
|
|
216
|
+
t.Fatal(err)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
config := &core.ProjectConfig{
|
|
220
|
+
Hooks: core.HooksConfig{OnTaskFinished: []string{"false"}},
|
|
221
|
+
}
|
|
222
|
+
svc := NewService(nil, &mockConfigProvider{config: config})
|
|
223
|
+
|
|
224
|
+
t.Run("failing hook blocks update", func(t *testing.T) {
|
|
225
|
+
err := svc.UpdateTaskStatus(context.Background(), tmpDir, slug, "T1.1", "finished")
|
|
226
|
+
if err == nil {
|
|
227
|
+
t.Fatal("expected error from failing hook")
|
|
228
|
+
}
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
t.Run("nil configProvider", func(t *testing.T) {
|
|
232
|
+
svcNil := NewService(nil, nil)
|
|
233
|
+
err := svcNil.UpdateTaskStatus(context.Background(), tmpDir, slug, "T1.1", "finished")
|
|
234
|
+
if err != nil {
|
|
235
|
+
t.Fatal(err)
|
|
236
|
+
}
|
|
237
|
+
})
|
|
238
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
package spec
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"fmt"
|
|
6
|
+
"os"
|
|
7
|
+
"path/filepath"
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
// ArtifactStatus represents the presence and description of a single spec document.
|
|
11
|
+
type ArtifactStatus struct {
|
|
12
|
+
Name string `json:"name"`
|
|
13
|
+
Description string `json:"description"`
|
|
14
|
+
Path string `json:"path"`
|
|
15
|
+
Exists bool `json:"exists"`
|
|
16
|
+
Blocked bool `json:"blocked"`
|
|
17
|
+
Dependency string `json:"dependency"`
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// SpecStatus represents the overall completion state of a specific feature spec.
|
|
21
|
+
type SpecStatus struct {
|
|
22
|
+
Slug string `json:"slug"`
|
|
23
|
+
Artifacts []ArtifactStatus `json:"artifacts"`
|
|
24
|
+
Progress int `json:"progress"`
|
|
25
|
+
Total int `json:"total"`
|
|
26
|
+
Found int `json:"found"`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// GetStatus checks the filesystem for the required artifacts from the registry and returns a progress summary.
|
|
30
|
+
func GetStatus(ctx context.Context, projectRoot string, slug string, registry *Registry) (SpecStatus, error) {
|
|
31
|
+
artifacts := registry.List()
|
|
32
|
+
|
|
33
|
+
status := SpecStatus{
|
|
34
|
+
Slug: slug,
|
|
35
|
+
Artifacts: make([]ArtifactStatus, 0, len(artifacts)),
|
|
36
|
+
Total: len(artifacts),
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
specDir := filepath.Join(projectRoot, ".specforce", "specs", slug)
|
|
40
|
+
if _, err := os.Stat(specDir); os.IsNotExist(err) {
|
|
41
|
+
return SpecStatus{}, fmt.Errorf("feature directory not found: %s", specDir)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Pre-scan for existing files to resolve dependencies
|
|
45
|
+
existsMap := make(map[string]bool)
|
|
46
|
+
for _, art := range artifacts {
|
|
47
|
+
if err := ctx.Err(); err != nil {
|
|
48
|
+
return SpecStatus{}, err
|
|
49
|
+
}
|
|
50
|
+
fullPath := filepath.Join(specDir, art.Name+".md")
|
|
51
|
+
if _, err := os.Stat(fullPath); err == nil {
|
|
52
|
+
existsMap[art.Name] = true
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
for _, art := range artifacts {
|
|
57
|
+
if err := ctx.Err(); err != nil {
|
|
58
|
+
return status, err
|
|
59
|
+
}
|
|
60
|
+
// Artifact paths within the spec directory
|
|
61
|
+
fileName := art.Name + ".md"
|
|
62
|
+
relPath := filepath.Join(".specforce", "specs", slug, fileName)
|
|
63
|
+
|
|
64
|
+
exists := existsMap[art.Name]
|
|
65
|
+
if exists {
|
|
66
|
+
status.Found++
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
blocked := false
|
|
70
|
+
if art.Dependency != "" {
|
|
71
|
+
// Check if dependency exists in registry first (as per REQ-1 scenario 4)
|
|
72
|
+
if _, depInRegistry := registry.Get(art.Dependency); !depInRegistry {
|
|
73
|
+
blocked = true
|
|
74
|
+
} else if !existsMap[art.Dependency] {
|
|
75
|
+
blocked = true
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
status.Artifacts = append(status.Artifacts, ArtifactStatus{
|
|
80
|
+
Name: art.Name,
|
|
81
|
+
Description: art.Description,
|
|
82
|
+
Path: relPath,
|
|
83
|
+
Exists: exists,
|
|
84
|
+
Blocked: blocked,
|
|
85
|
+
Dependency: art.Dependency,
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if status.Total > 0 {
|
|
90
|
+
status.Progress = (status.Found * 100) / status.Total
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return status, nil
|
|
94
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
package spec
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"os"
|
|
6
|
+
"path/filepath"
|
|
7
|
+
"testing"
|
|
8
|
+
"testing/fstest"
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
func TestGetStatus(t *testing.T) {
|
|
12
|
+
tmpDir, err := os.MkdirTemp("", "specforce-test-*")
|
|
13
|
+
if err != nil {
|
|
14
|
+
t.Fatal(err)
|
|
15
|
+
}
|
|
16
|
+
defer func() {
|
|
17
|
+
_ = os.RemoveAll(tmpDir)
|
|
18
|
+
}()
|
|
19
|
+
|
|
20
|
+
registry := setupMockRegistry(t)
|
|
21
|
+
slug := "test-slug"
|
|
22
|
+
specDir := setupSpecDir(t, tmpDir, slug)
|
|
23
|
+
|
|
24
|
+
t.Run("No files exist", func(t *testing.T) {
|
|
25
|
+
testGetStatus_NoFiles(t, tmpDir, slug, registry)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
t.Run("One file exists", func(t *testing.T) {
|
|
29
|
+
testGetStatus_OneFile(t, tmpDir, slug, specDir, registry)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
t.Run("Both files exist", func(t *testing.T) {
|
|
33
|
+
testGetStatus_BothFiles(t, tmpDir, slug, specDir, registry)
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
func testGetStatus_NoFiles(t *testing.T, tmpDir, slug string, registry *Registry) {
|
|
38
|
+
status, err := GetStatus(context.Background(), tmpDir, slug, registry)
|
|
39
|
+
if err != nil {
|
|
40
|
+
t.Fatalf("GetStatus failed: %v", err)
|
|
41
|
+
}
|
|
42
|
+
if status.Found != 0 {
|
|
43
|
+
t.Errorf("expected 0 found artifacts, got %d", status.Found)
|
|
44
|
+
}
|
|
45
|
+
if status.Total != 2 {
|
|
46
|
+
t.Errorf("expected 2 total artifacts, got %d", status.Total)
|
|
47
|
+
}
|
|
48
|
+
if status.Progress != 0 {
|
|
49
|
+
t.Errorf("expected 0%% progress, got %d%%", status.Progress)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Verify blocking logic
|
|
53
|
+
for _, art := range status.Artifacts {
|
|
54
|
+
if art.Name == "requirements" {
|
|
55
|
+
if art.Blocked {
|
|
56
|
+
t.Errorf("requirements should not be blocked")
|
|
57
|
+
}
|
|
58
|
+
if art.Dependency != "" {
|
|
59
|
+
t.Errorf("requirements should not have dependency")
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if art.Name == "design" {
|
|
63
|
+
if !art.Blocked {
|
|
64
|
+
t.Errorf("design should be blocked by requirements")
|
|
65
|
+
}
|
|
66
|
+
if art.Dependency != "requirements" {
|
|
67
|
+
t.Errorf("expected dependency 'requirements', got '%s'", art.Dependency)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
func testGetStatus_OneFile(t *testing.T, tmpDir, slug, specDir string, registry *Registry) {
|
|
74
|
+
if err := os.WriteFile(filepath.Join(specDir, "requirements.md"), []byte("data"), 0644); err != nil {
|
|
75
|
+
t.Fatal(err)
|
|
76
|
+
}
|
|
77
|
+
status, err := GetStatus(context.Background(), tmpDir, slug, registry)
|
|
78
|
+
if err != nil {
|
|
79
|
+
t.Fatalf("GetStatus failed: %v", err)
|
|
80
|
+
}
|
|
81
|
+
if status.Found != 1 {
|
|
82
|
+
t.Errorf("expected 1 found artifact, got %d", status.Found)
|
|
83
|
+
}
|
|
84
|
+
if status.Progress != 50 {
|
|
85
|
+
t.Errorf("expected 50%% progress, got %d%%", status.Progress)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Verify blocking logic
|
|
89
|
+
for _, art := range status.Artifacts {
|
|
90
|
+
if art.Name == "design" {
|
|
91
|
+
if art.Blocked {
|
|
92
|
+
t.Errorf("design should NOT be blocked when requirements exists")
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
func testGetStatus_BothFiles(t *testing.T, tmpDir, slug, specDir string, registry *Registry) {
|
|
99
|
+
if err := os.WriteFile(filepath.Join(specDir, "design.md"), []byte("data"), 0644); err != nil {
|
|
100
|
+
t.Fatal(err)
|
|
101
|
+
}
|
|
102
|
+
status, err := GetStatus(context.Background(), tmpDir, slug, registry)
|
|
103
|
+
if err != nil {
|
|
104
|
+
t.Fatalf("GetStatus failed: %v", err)
|
|
105
|
+
}
|
|
106
|
+
if status.Found != 2 {
|
|
107
|
+
t.Errorf("expected 2 found artifacts, got %d", status.Found)
|
|
108
|
+
}
|
|
109
|
+
if status.Progress != 100 {
|
|
110
|
+
t.Errorf("expected 100%% progress, got %d%%", status.Progress)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
func setupSpecDir(t *testing.T, tmpDir, slug string) string {
|
|
115
|
+
specDir := filepath.Join(tmpDir, ".specforce", "specs", slug)
|
|
116
|
+
if err := os.MkdirAll(specDir, 0755); err != nil {
|
|
117
|
+
t.Fatal(err)
|
|
118
|
+
}
|
|
119
|
+
return specDir
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
func setupMockRegistry(t *testing.T) *Registry {
|
|
123
|
+
mockFS := fstest.MapFS{
|
|
124
|
+
"requirements.yaml": {
|
|
125
|
+
Data: []byte(`
|
|
126
|
+
description: "Requirements"
|
|
127
|
+
instruction: "Write requirements"
|
|
128
|
+
template: "# Requirements"
|
|
129
|
+
`),
|
|
130
|
+
},
|
|
131
|
+
"design.yaml": {
|
|
132
|
+
Data: []byte(`
|
|
133
|
+
description: "Design"
|
|
134
|
+
instruction: "Write design"
|
|
135
|
+
template: "# Design"
|
|
136
|
+
dependency: "requirements"
|
|
137
|
+
`),
|
|
138
|
+
},
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
registry, err := NewRegistry(mockFS)
|
|
142
|
+
if err != nil {
|
|
143
|
+
t.Fatalf("failed to create registry: %v", err)
|
|
144
|
+
}
|
|
145
|
+
return registry
|
|
146
|
+
}
|