@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,105 @@
|
|
|
1
|
+
package spec
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"strings"
|
|
5
|
+
"testing"
|
|
6
|
+
"testing/fstest"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
func TestNewRegistry(t *testing.T) {
|
|
10
|
+
fs := fstest.MapFS{
|
|
11
|
+
"requirements.yaml": {
|
|
12
|
+
Data: []byte("description: Req Desc\ninstruction: Req Inst\ntemplate: Req Temp\n"),
|
|
13
|
+
},
|
|
14
|
+
"design.yaml": {
|
|
15
|
+
Data: []byte("description: Design Desc\ninstruction: Design Inst\ntemplate: Design Temp\ndependency: requirements\n"),
|
|
16
|
+
},
|
|
17
|
+
"tasks.yaml": {
|
|
18
|
+
Data: []byte("description: Task Desc\ninstruction: Task Inst\ntemplate: Task Temp\ndependency: design\n"),
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
registry, err := NewRegistry(fs)
|
|
23
|
+
if err != nil {
|
|
24
|
+
t.Fatalf("NewRegistry failed: %v", err)
|
|
25
|
+
}
|
|
26
|
+
if registry == nil {
|
|
27
|
+
t.Fatal("NewRegistry returned nil registry")
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Check Get
|
|
31
|
+
art, ok := registry.Get("requirements")
|
|
32
|
+
if !ok {
|
|
33
|
+
t.Error("artifact 'requirements' not found")
|
|
34
|
+
}
|
|
35
|
+
if art.Name != "requirements" {
|
|
36
|
+
t.Errorf("expected name 'requirements', got '%s'", art.Name)
|
|
37
|
+
}
|
|
38
|
+
if art.Description != "Req Desc" {
|
|
39
|
+
t.Errorf("expected description 'Req Desc', got '%s'", art.Description)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
art, ok = registry.Get("design")
|
|
43
|
+
if !ok {
|
|
44
|
+
t.Error("artifact 'design' not found")
|
|
45
|
+
}
|
|
46
|
+
if art.Dependency != "requirements" {
|
|
47
|
+
t.Errorf("expected dependency 'requirements', got '%s'", art.Dependency)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Check List order
|
|
51
|
+
list := registry.List()
|
|
52
|
+
if len(list) != 3 {
|
|
53
|
+
t.Errorf("expected list length 3, got %d", len(list))
|
|
54
|
+
}
|
|
55
|
+
if list[0].Name != "requirements" {
|
|
56
|
+
t.Errorf("expected first element 'requirements', got '%s'", list[0].Name)
|
|
57
|
+
}
|
|
58
|
+
if list[1].Name != "design" {
|
|
59
|
+
t.Errorf("expected second element 'design', got '%s'", list[1].Name)
|
|
60
|
+
}
|
|
61
|
+
if list[2].Name != "tasks" {
|
|
62
|
+
t.Errorf("expected third element 'tasks', got '%s'", list[2].Name)
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
func TestNewRegistry_CircularDependency(t *testing.T) {
|
|
67
|
+
fs := fstest.MapFS{
|
|
68
|
+
"a.yaml": {
|
|
69
|
+
Data: []byte("description: A\ninstruction: A\ntemplate: A\ndependency: b\n"),
|
|
70
|
+
},
|
|
71
|
+
"b.yaml": {
|
|
72
|
+
Data: []byte("description: B\ninstruction: B\ntemplate: B\ndependency: a\n"),
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
registry, err := NewRegistry(fs)
|
|
77
|
+
if err == nil {
|
|
78
|
+
t.Fatal("expected error for circular dependency, got nil")
|
|
79
|
+
}
|
|
80
|
+
if !strings.Contains(err.Error(), "circular dependency detected") {
|
|
81
|
+
t.Errorf("expected circular dependency error message, got: %v", err)
|
|
82
|
+
}
|
|
83
|
+
if registry != nil {
|
|
84
|
+
t.Error("expected nil registry on error")
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
func TestNewRegistry_MissingFields(t *testing.T) {
|
|
89
|
+
fs := fstest.MapFS{
|
|
90
|
+
"invalid.yaml": {
|
|
91
|
+
Data: []byte("description: Only Desc\n"),
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
registry, err := NewRegistry(fs)
|
|
96
|
+
if err == nil {
|
|
97
|
+
t.Fatal("expected error for missing fields, got nil")
|
|
98
|
+
}
|
|
99
|
+
if !strings.Contains(err.Error(), "missing 'instruction'") {
|
|
100
|
+
t.Errorf("expected missing instruction error, got: %v", err)
|
|
101
|
+
}
|
|
102
|
+
if registry != nil {
|
|
103
|
+
t.Error("expected nil registry on error")
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
package spec
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"os"
|
|
6
|
+
"path/filepath"
|
|
7
|
+
"sort"
|
|
8
|
+
"strings"
|
|
9
|
+
|
|
10
|
+
"golang.org/x/text/cases"
|
|
11
|
+
"golang.org/x/text/language"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
// StateCategory defines the top-level grouping for project state items.
|
|
15
|
+
type StateCategory string
|
|
16
|
+
|
|
17
|
+
const (
|
|
18
|
+
CategoryConstitution StateCategory = "Constitution"
|
|
19
|
+
CategoryActiveSpecs StateCategory = "Active Specs"
|
|
20
|
+
CategoryImplementations StateCategory = "Active Implementations"
|
|
21
|
+
CategoryArchived StateCategory = "Archived"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
// StateItem represents a single navigatable entry in the Specforce Console.
|
|
25
|
+
type StateItem struct {
|
|
26
|
+
Slug string `json:"slug"`
|
|
27
|
+
Name string `json:"name"`
|
|
28
|
+
Path string `json:"path"`
|
|
29
|
+
Category StateCategory `json:"category"`
|
|
30
|
+
Status string `json:"status"` // PENDING | IN-PROGRESS | FINISHED
|
|
31
|
+
Progress int `json:"progress"`
|
|
32
|
+
Description string `json:"description"`
|
|
33
|
+
ArtifactCount int `json:"artifact_count"`
|
|
34
|
+
ArtifactTotal int `json:"artifact_total"`
|
|
35
|
+
TaskCount int `json:"task_count"`
|
|
36
|
+
TaskTotal int `json:"task_total"`
|
|
37
|
+
AnyTaskWorking bool `json:"any_task_working"`
|
|
38
|
+
CurrentTaskID string `json:"current_task_id"`
|
|
39
|
+
CurrentTask string `json:"current_task"`
|
|
40
|
+
ArchivedDate string `json:"archived_date"`
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// StateTree represents the full hierarchical state of a Specforce project.
|
|
44
|
+
type StateTree struct {
|
|
45
|
+
Categories map[StateCategory][]StateItem `json:"categories"`
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// NewStateTree initializes a new, empty state tree.
|
|
49
|
+
func NewStateTree() *StateTree {
|
|
50
|
+
return &StateTree{
|
|
51
|
+
Categories: make(map[StateCategory][]StateItem),
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ScanProject synchronously parses the .specforce directory to populate a StateTree.
|
|
56
|
+
func ScanProject(ctx context.Context, projectRoot string, registry *Registry) (*StateTree, error) {
|
|
57
|
+
if err := ctx.Err(); err != nil {
|
|
58
|
+
return nil, err
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
tree := NewStateTree()
|
|
62
|
+
|
|
63
|
+
// 1. Scan Constitution documents (.specforce/docs/)
|
|
64
|
+
if err := scanConstitution(ctx, projectRoot, tree); err != nil {
|
|
65
|
+
return nil, err
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 2. Scan Active Specs and Implementations (.specforce/specs/)
|
|
69
|
+
if err := scanActiveSpecs(ctx, projectRoot, tree, registry); err != nil {
|
|
70
|
+
return nil, err
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// 3. Scan Archived specs (.specforce/archive/)
|
|
74
|
+
if err := scanArchivedSpecs(ctx, projectRoot, tree); err != nil {
|
|
75
|
+
return nil, err
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return tree, nil
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
func scanConstitution(ctx context.Context, projectRoot string, tree *StateTree) error {
|
|
82
|
+
docsDir := filepath.Join(projectRoot, ".specforce", "docs")
|
|
83
|
+
entries, err := os.ReadDir(docsDir)
|
|
84
|
+
if err != nil {
|
|
85
|
+
return nil // No docs dir is fine
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
for _, entry := range entries {
|
|
89
|
+
if err := ctx.Err(); err != nil {
|
|
90
|
+
return err
|
|
91
|
+
}
|
|
92
|
+
if entry.IsDir() || !strings.HasSuffix(entry.Name(), ".md") || entry.Name() == "current-state.md" || entry.Name() == "memorial.md" {
|
|
93
|
+
continue
|
|
94
|
+
}
|
|
95
|
+
slug := strings.TrimSuffix(entry.Name(), ".md")
|
|
96
|
+
tree.Categories[CategoryConstitution] = append(tree.Categories[CategoryConstitution], StateItem{
|
|
97
|
+
Slug: slug,
|
|
98
|
+
Name: cases.Title(language.Und).String(strings.ReplaceAll(slug, "-", " ")),
|
|
99
|
+
Path: filepath.Join(".specforce", "docs", entry.Name()),
|
|
100
|
+
Category: CategoryConstitution,
|
|
101
|
+
Status: "FINISHED",
|
|
102
|
+
Progress: 100,
|
|
103
|
+
})
|
|
104
|
+
}
|
|
105
|
+
return nil
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
func scanActiveSpecs(ctx context.Context, projectRoot string, tree *StateTree, registry *Registry) error {
|
|
109
|
+
specsDir := filepath.Join(projectRoot, ".specforce", "specs")
|
|
110
|
+
entries, err := os.ReadDir(specsDir)
|
|
111
|
+
if err != nil {
|
|
112
|
+
return nil
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
for _, entry := range entries {
|
|
116
|
+
if err := ctx.Err(); err != nil {
|
|
117
|
+
return err
|
|
118
|
+
}
|
|
119
|
+
if !entry.IsDir() || strings.HasPrefix(entry.Name(), ".") {
|
|
120
|
+
continue
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
item := scanSingleActiveSpec(ctx, projectRoot, entry.Name(), registry)
|
|
124
|
+
tree.Categories[item.Category] = append(tree.Categories[item.Category], item)
|
|
125
|
+
}
|
|
126
|
+
return nil
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
func scanSingleActiveSpec(ctx context.Context, projectRoot, slug string, registry *Registry) StateItem {
|
|
130
|
+
item := StateItem{
|
|
131
|
+
Slug: slug,
|
|
132
|
+
Name: slug,
|
|
133
|
+
Path: filepath.Join(".specforce", "specs", slug),
|
|
134
|
+
Category: CategoryActiveSpecs,
|
|
135
|
+
Status: "PENDING",
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if status, err := GetStatus(ctx, projectRoot, slug, registry); err == nil {
|
|
139
|
+
item.Progress = status.Progress
|
|
140
|
+
item.ArtifactCount = status.Found
|
|
141
|
+
item.ArtifactTotal = status.Total
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
tasksPath := filepath.Join(projectRoot, ".specforce", "specs", slug, "tasks.md")
|
|
145
|
+
if _, err := os.Stat(tasksPath); err == nil {
|
|
146
|
+
item.Category = CategoryImplementations
|
|
147
|
+
if report, err := ParseTasks(ctx, projectRoot, slug); err == nil {
|
|
148
|
+
item.Status = strings.ToUpper(report.Status)
|
|
149
|
+
item.TaskTotal = len(report.Tasks())
|
|
150
|
+
foundFinished := 0
|
|
151
|
+
for _, t := range report.Tasks() {
|
|
152
|
+
state := strings.ToUpper(t.State)
|
|
153
|
+
if state == "FINISHED" || state == "X" {
|
|
154
|
+
foundFinished++
|
|
155
|
+
} else {
|
|
156
|
+
if state == "IN-PROGRESS" {
|
|
157
|
+
item.AnyTaskWorking = true
|
|
158
|
+
}
|
|
159
|
+
if item.CurrentTaskID == "" {
|
|
160
|
+
item.CurrentTaskID = t.ID
|
|
161
|
+
item.CurrentTask = t.Title
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
item.TaskCount = foundFinished
|
|
166
|
+
if item.TaskTotal > 0 {
|
|
167
|
+
item.Progress = (foundFinished * 100) / item.TaskTotal
|
|
168
|
+
}
|
|
169
|
+
if item.CurrentTask == "" && foundFinished == item.TaskTotal {
|
|
170
|
+
item.CurrentTask = "All tasks complete"
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
return item
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
func scanArchivedSpecs(ctx context.Context, projectRoot string, tree *StateTree) error {
|
|
178
|
+
archiveDir := filepath.Join(projectRoot, ".specforce", "archive")
|
|
179
|
+
entries, err := os.ReadDir(archiveDir)
|
|
180
|
+
if err != nil {
|
|
181
|
+
return nil
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
archivedItems := []StateItem{}
|
|
185
|
+
for _, entry := range entries {
|
|
186
|
+
if err := ctx.Err(); err != nil {
|
|
187
|
+
return err
|
|
188
|
+
}
|
|
189
|
+
if !entry.IsDir() || strings.HasPrefix(entry.Name(), ".") {
|
|
190
|
+
continue
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
date := "2026-04-16"
|
|
194
|
+
if info, err := entry.Info(); err == nil {
|
|
195
|
+
date = info.ModTime().Format("2006-01-02")
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
archivedItems = append(archivedItems, StateItem{
|
|
199
|
+
Slug: entry.Name(),
|
|
200
|
+
Name: entry.Name(),
|
|
201
|
+
Path: filepath.Join(".specforce", "archive", entry.Name()),
|
|
202
|
+
Category: CategoryArchived,
|
|
203
|
+
Status: "FINISHED",
|
|
204
|
+
Progress: 100,
|
|
205
|
+
ArchivedDate: date,
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
sort.Slice(archivedItems, func(i, j int) bool {
|
|
210
|
+
return archivedItems[i].ArchivedDate > archivedItems[j].ArchivedDate
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
if len(archivedItems) > 10 {
|
|
214
|
+
archivedItems = archivedItems[:10]
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
tree.Categories[CategoryArchived] = archivedItems
|
|
218
|
+
return nil
|
|
219
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
package spec
|
|
2
|
+
|
|
3
|
+
import (
|
|
4
|
+
"context"
|
|
5
|
+
"errors"
|
|
6
|
+
"os"
|
|
7
|
+
"path/filepath"
|
|
8
|
+
"strings"
|
|
9
|
+
"testing"
|
|
10
|
+
|
|
11
|
+
"github.com/jeancodogno/specforce-kit/src/internal/core"
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
func setupMockProject(t *testing.T, tempDir string) {
|
|
15
|
+
// 1. Setup mock .specforce structure
|
|
16
|
+
specforceDir := filepath.Join(tempDir, ".specforce")
|
|
17
|
+
docsDir := filepath.Join(specforceDir, "docs")
|
|
18
|
+
specsDir := filepath.Join(specforceDir, "specs")
|
|
19
|
+
archiveDir := filepath.Join(specforceDir, "archive")
|
|
20
|
+
|
|
21
|
+
dirs := []string{docsDir, specsDir, archiveDir}
|
|
22
|
+
for _, d := range dirs {
|
|
23
|
+
if err := os.MkdirAll(d, 0755); err != nil {
|
|
24
|
+
t.Fatalf("Failed to create mock dir %s: %v", d, err)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// 2. Add mock files
|
|
29
|
+
// Constitution doc
|
|
30
|
+
if err := os.WriteFile(filepath.Join(docsDir, "architecture.md"), []byte("# Architecture"), 0644); err != nil {
|
|
31
|
+
t.Fatalf("Failed to create mock doc: %v", err)
|
|
32
|
+
}
|
|
33
|
+
// Active Spec
|
|
34
|
+
activeSpecDir := filepath.Join(specsDir, "0001-test-spec")
|
|
35
|
+
if err := os.MkdirAll(activeSpecDir, 0755); err != nil {
|
|
36
|
+
t.Fatalf("Failed to create mock spec dir: %v", err)
|
|
37
|
+
}
|
|
38
|
+
if err := os.WriteFile(filepath.Join(activeSpecDir, "requirements.md"), []byte("# Requirements"), 0644); err != nil {
|
|
39
|
+
t.Fatalf("Failed to create mock requirement doc: %v", err)
|
|
40
|
+
}
|
|
41
|
+
// Active Implementation (has tasks.md)
|
|
42
|
+
implSpecDir := filepath.Join(specsDir, "0002-test-impl")
|
|
43
|
+
if err := os.MkdirAll(implSpecDir, 0755); err != nil {
|
|
44
|
+
t.Fatalf("Failed to create mock impl dir: %v", err)
|
|
45
|
+
}
|
|
46
|
+
if err := os.WriteFile(filepath.Join(implSpecDir, "tasks.md"), []byte("## 2. Tasks\n### T1.1: [SCAFFOLD] Task\n**State:** `[PENDING]`"), 0644); err != nil {
|
|
47
|
+
t.Fatalf("Failed to create mock task doc: %v", err)
|
|
48
|
+
}
|
|
49
|
+
// Archived Spec
|
|
50
|
+
archivedSpecDir := filepath.Join(archiveDir, "0003-test-archive")
|
|
51
|
+
if err := os.MkdirAll(archivedSpecDir, 0755); err != nil {
|
|
52
|
+
t.Fatalf("Failed to create mock archive dir: %v", err)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
func TestScanProject(t *testing.T) {
|
|
57
|
+
tempDir := t.TempDir()
|
|
58
|
+
setupMockProject(t, tempDir)
|
|
59
|
+
|
|
60
|
+
// 3. Mock registry
|
|
61
|
+
registry := &Registry{
|
|
62
|
+
artifacts: map[string]Artifact{
|
|
63
|
+
"requirements": {Name: "requirements"},
|
|
64
|
+
"design": {Name: "design"},
|
|
65
|
+
"tasks": {Name: "tasks"},
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// 4. Execute scan
|
|
70
|
+
tree, err := ScanProject(context.Background(), tempDir, registry)
|
|
71
|
+
if err != nil {
|
|
72
|
+
t.Fatalf("ScanProject failed: %v", err)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// 5. Assertions
|
|
76
|
+
if len(tree.Categories[CategoryConstitution]) != 1 {
|
|
77
|
+
t.Errorf("Expected 1 constitution doc, got %d", len(tree.Categories[CategoryConstitution]))
|
|
78
|
+
}
|
|
79
|
+
if len(tree.Categories[CategoryActiveSpecs]) != 1 {
|
|
80
|
+
t.Errorf("Expected 1 active spec, got %d", len(tree.Categories[CategoryActiveSpecs]))
|
|
81
|
+
}
|
|
82
|
+
if len(tree.Categories[CategoryImplementations]) != 1 {
|
|
83
|
+
t.Errorf("Expected 1 active implementation, got %d", len(tree.Categories[CategoryImplementations]))
|
|
84
|
+
}
|
|
85
|
+
if len(tree.Categories[CategoryArchived]) != 1 {
|
|
86
|
+
t.Errorf("Expected 1 archived spec, got %d", len(tree.Categories[CategoryArchived]))
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Check status
|
|
90
|
+
if tree.Categories[CategoryImplementations][0].Status != "READY" {
|
|
91
|
+
t.Errorf("Expected READY status for implementation, got %s", tree.Categories[CategoryImplementations][0].Status)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
func TestScanProject_Cancellation(t *testing.T) {
|
|
96
|
+
tempDir := t.TempDir()
|
|
97
|
+
|
|
98
|
+
// Setup many files to increase chance of catching it (though here it's synchronous)
|
|
99
|
+
docsDir := filepath.Join(tempDir, ".specforce", "docs")
|
|
100
|
+
_ = os.MkdirAll(docsDir, 0755)
|
|
101
|
+
for i := 0; i < 100; i++ {
|
|
102
|
+
_ = os.WriteFile(filepath.Join(docsDir, filepath.Join(string(rune(i)), ".md")), []byte("# Test"), 0644)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
ctx, cancel := context.WithCancel(context.Background())
|
|
106
|
+
cancel() // Cancel immediately
|
|
107
|
+
|
|
108
|
+
_, err := ScanProject(ctx, tempDir, nil)
|
|
109
|
+
if err == nil {
|
|
110
|
+
t.Fatal("expected error for cancelled context, got nil")
|
|
111
|
+
}
|
|
112
|
+
if !errors.Is(err, context.Canceled) {
|
|
113
|
+
t.Errorf("expected context.Canceled, got %v", err)
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
func TestParseTasks_InvalidFile_ReturnsErrInvalidSpecFile(t *testing.T) {
|
|
118
|
+
tmpDir := t.TempDir()
|
|
119
|
+
|
|
120
|
+
slug := "bad-spec"
|
|
121
|
+
// Create the spec directory but do NOT create tasks.md
|
|
122
|
+
specDir := filepath.Join(tmpDir, ".specforce", "specs", slug)
|
|
123
|
+
if err := os.MkdirAll(specDir, 0755); err != nil {
|
|
124
|
+
t.Fatalf("failed to create spec dir: %v", err)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
_, err := ParseTasks(context.Background(), tmpDir, slug)
|
|
128
|
+
if err == nil {
|
|
129
|
+
t.Fatal("expected an error for missing tasks.md, got nil")
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if !errors.Is(err, core.ErrInvalidSpecFile) {
|
|
133
|
+
t.Errorf("expected errors.Is(err, core.ErrInvalidSpecFile) to be true, got: %v", err)
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
func TestScanProject_AnyTaskWorking(t *testing.T) {
|
|
138
|
+
tempDir := t.TempDir()
|
|
139
|
+
|
|
140
|
+
// 1. Setup mock .specforce structure
|
|
141
|
+
specsDir := filepath.Join(tempDir, ".specforce", "specs")
|
|
142
|
+
implSpecDir := filepath.Join(specsDir, "working-impl")
|
|
143
|
+
if err := os.MkdirAll(implSpecDir, 0755); err != nil {
|
|
144
|
+
t.Fatalf("Failed to create mock impl dir: %v", err)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// 2. Add tasks.md with an in-progress task
|
|
148
|
+
content := "## 2. Tasks\n### T1.1: [SCAFFOLD] Working Task\n**State:** `[IN-PROGRESS]`"
|
|
149
|
+
if err := os.WriteFile(filepath.Join(implSpecDir, "tasks.md"), []byte(content), 0644); err != nil {
|
|
150
|
+
t.Fatalf("Failed to create mock tasks.md: %v", err)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 3. Mock registry
|
|
154
|
+
registry := &Registry{
|
|
155
|
+
artifacts: map[string]Artifact{
|
|
156
|
+
"tasks": {Name: "tasks"},
|
|
157
|
+
},
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// 4. Execute scan
|
|
161
|
+
tree, err := ScanProject(context.Background(), tempDir, registry)
|
|
162
|
+
if err != nil {
|
|
163
|
+
t.Fatalf("ScanProject failed: %v", err)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// 5. Assertions
|
|
167
|
+
found := false
|
|
168
|
+
for _, item := range tree.Categories[CategoryImplementations] {
|
|
169
|
+
if item.Slug == "working-impl" {
|
|
170
|
+
found = true
|
|
171
|
+
if !item.AnyTaskWorking {
|
|
172
|
+
t.Errorf("Expected AnyTaskWorking to be true for working-impl")
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if !found {
|
|
177
|
+
t.Errorf("Expected to find working-impl in CategoryImplementations")
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
t.Run("Task State X", func(t *testing.T) {
|
|
181
|
+
implXDir := filepath.Join(specsDir, "x-impl")
|
|
182
|
+
if err := os.MkdirAll(implXDir, 0755); err != nil {
|
|
183
|
+
t.Fatal(err)
|
|
184
|
+
}
|
|
185
|
+
contentX := "## 2. Tasks\n### T1.1: Task X\n**State:** `[X]`"
|
|
186
|
+
if err := os.WriteFile(filepath.Join(implXDir, "tasks.md"), []byte(contentX), 0644); err != nil {
|
|
187
|
+
t.Fatal(err)
|
|
188
|
+
}
|
|
189
|
+
tree, _ := ScanProject(context.Background(), tempDir, registry)
|
|
190
|
+
foundX := false
|
|
191
|
+
for _, item := range tree.Categories[CategoryImplementations] {
|
|
192
|
+
if item.Slug == "x-impl" {
|
|
193
|
+
foundX = true
|
|
194
|
+
if item.TaskCount != 1 {
|
|
195
|
+
t.Errorf("Expected TaskCount 1 for X state, got %d", item.TaskCount)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if !foundX {
|
|
200
|
+
t.Errorf("Expected to find x-impl")
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
func TestScanProject_ArchiveLimits(t *testing.T) {
|
|
206
|
+
tempDir := t.TempDir()
|
|
207
|
+
archiveDir := filepath.Join(tempDir, ".specforce", "archive")
|
|
208
|
+
if err := os.MkdirAll(archiveDir, 0755); err != nil {
|
|
209
|
+
t.Fatal(err)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Create 12 archived items
|
|
213
|
+
for i := 0; i < 12; i++ {
|
|
214
|
+
name := filepath.Join(archiveDir, filepath.Join(string(rune('a'+i)), "folder"))
|
|
215
|
+
if err := os.MkdirAll(name, 0755); err != nil {
|
|
216
|
+
t.Fatal(err)
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Hidden file and hidden dir in archive
|
|
221
|
+
if err := os.WriteFile(filepath.Join(archiveDir, ".hidden-file"), []byte("data"), 0644); err != nil {
|
|
222
|
+
t.Fatal(err)
|
|
223
|
+
}
|
|
224
|
+
if err := os.MkdirAll(filepath.Join(archiveDir, ".hidden-dir"), 0755); err != nil {
|
|
225
|
+
t.Fatal(err)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
tree, err := ScanProject(context.Background(), tempDir, nil)
|
|
229
|
+
if err != nil {
|
|
230
|
+
t.Fatal(err)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
archived := tree.Categories[CategoryArchived]
|
|
234
|
+
if len(archived) != 10 {
|
|
235
|
+
t.Errorf("Expected archive limit of 10, got %d", len(archived))
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
for _, item := range archived {
|
|
239
|
+
if strings.HasPrefix(item.Slug, ".") {
|
|
240
|
+
t.Errorf("Archive scan should ignore hidden entries: %s", item.Slug)
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|