mirror of
https://github.com/multica-ai/multica.git
synced 2026-08-03 11:10:23 +02:00
Squashed history of PR #4892 (pr-4784-fix). Makes spaces the primary navigation and working surface, on the "associations bind at creation time only" model. Model - Issue <-> space is the only enforced ownership (per-space numbering). Parent/child and project<->space associations only seed defaults at creation; cross-space/child and project-association validations are removed. - Moving an issue renumbers it and records the old identifier in issue_identifier_alias; API/CLI lookups and GitHub branch/PR auto-linking fall back to the alias, so old identifiers resolve forever. - Membership drives only the sidebar and personal defaults — never access. Anyone can configure any space's member set wholesale (PUT /api/spaces/{id}/members); saving an empty set archives the space behind a confirm. - Per-user space order (workspace_space_member.sort_order, fractional): drag-sorted sidebar, "my first space" is the personal issue-creation default; the workspace default space backs headless creation (agents/CLI/Slack) and system placement. Surfaces - Sidebar: joined-spaces section (drag reorder, row -> space page, per-group persisted collapse), Workspace group with a More menu, Settings demoted to a footer icon. - /space/:key/{issues,projects,autopilots,settings} — space surfaces reuse shared page components; a routed /space/new create page (replacing the earlier create-space modal), reserved key "NEW" so it can never collide with a real space's /space/:key detail page. - Issue detail moves to /issue/:id (identifier-first, Linear-style; old /issues/:id redirects); create dialogs lead with a required space pill. - Agent runtime brief now carries Space context (id/key/name) through the daemon claim -> TaskContextForEnv -> prompt pipeline, with a "## Space Context" section and --space on issue create/update in both brief renderers, matching Project's existing treatment. - zh-Hans: Space translated to 空间 across locales and conventions.zh.mdx. Fixes along the way - Cache membership judgment gains the space dimension + space_changed WS flag. - Silent skip on default-space lookup during invite acceptance is now a hard failure (no space-less members). - Backfilled space_id into ~28 raw-SQL Go test fixtures across internal/handler and cmd/server that predated migration 132's NOT NULL cutover. - Fixed a resolve-loop bug in the IssueDetail identifier wrapper (mount/ unmount cycle on resolution failure) and gave it its own loading skeleton instead of a blank screen while resolving. - reserved-slugs generator's stale hardcoded doc-comment example synced back to /create-space. Verification - go build ./..., go vet ./..., go test ./... all clean. - pnpm typecheck (core/views/web/desktop) clean. - packages/views: 162 files / 1656 tests passing. - pnpm generate:reserved-slugs produces no diff. Follow-ups tracked in docs/follow-ups/space-rollout.md. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
105 lines
4.0 KiB
Go
105 lines
4.0 KiB
Go
package handler
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// Backs the Project Gantt view: only issues with at least one of
|
|
// start_date / due_date should come back when scheduled=true, regardless of
|
|
// status or assignee. The unfiltered call must keep returning everything.
|
|
func TestListIssues_ScheduledFilter(t *testing.T) {
|
|
ctx := context.Background()
|
|
suffix := time.Now().UnixNano()
|
|
|
|
// Seed three issues in a fresh project — one with start_date only, one
|
|
// with due_date only, and one with neither. Using a dedicated project so
|
|
// the assertion isn't polluted by other issues seeded by parallel tests.
|
|
var projectID string
|
|
if err := testPool.QueryRow(ctx, `
|
|
INSERT INTO project (workspace_id, title) VALUES ($1, $2) RETURNING id
|
|
`, testWorkspaceID, fmt.Sprintf("Gantt Scheduled %d", suffix)).Scan(&projectID); err != nil {
|
|
t.Fatalf("create project: %v", err)
|
|
}
|
|
t.Cleanup(func() { testPool.Exec(context.Background(), `DELETE FROM project WHERE id = $1`, projectID) })
|
|
|
|
insertIssue := func(title string, startDate, dueDate *time.Time) string {
|
|
var number int
|
|
if err := testPool.QueryRow(ctx, `
|
|
UPDATE workspace
|
|
SET issue_counter = GREATEST(issue_counter, (SELECT COALESCE(MAX(number), 0) FROM issue WHERE workspace_id = $1)) + 1
|
|
WHERE id = $1 RETURNING issue_counter
|
|
`, testWorkspaceID).Scan(&number); err != nil {
|
|
t.Fatalf("next issue number: %v", err)
|
|
}
|
|
var id string
|
|
if err := testPool.QueryRow(ctx, `
|
|
INSERT INTO issue (workspace_id, title, status, priority, creator_type, creator_id, position, number, project_id, start_date, due_date, space_id)
|
|
VALUES ($1, $2, 'todo', 'none', 'member', $3, 0, $4, $5, $6, $7, (SELECT id FROM workspace_space WHERE workspace_id = $1 LIMIT 1)) RETURNING id
|
|
`, testWorkspaceID, title, testUserID, number, projectID, startDate, dueDate).Scan(&id); err != nil {
|
|
t.Fatalf("create issue %q: %v", title, err)
|
|
}
|
|
t.Cleanup(func() { testPool.Exec(context.Background(), `DELETE FROM issue WHERE id = $1`, id) })
|
|
return id
|
|
}
|
|
|
|
start := time.Now().UTC().Truncate(24 * time.Hour)
|
|
due := start.Add(72 * time.Hour)
|
|
withStart := insertIssue(fmt.Sprintf("with-start-%d", suffix), &start, nil)
|
|
withDue := insertIssue(fmt.Sprintf("with-due-%d", suffix), nil, &due)
|
|
withBoth := insertIssue(fmt.Sprintf("with-both-%d", suffix), &start, &due)
|
|
noDates := insertIssue(fmt.Sprintf("no-dates-%d", suffix), nil, nil)
|
|
|
|
list := func(query string) (ids []string, total int64) {
|
|
path := fmt.Sprintf("/api/issues?workspace_id=%s&project_id=%s&limit=500%s",
|
|
testWorkspaceID, projectID, query)
|
|
w := httptest.NewRecorder()
|
|
testHandler.ListIssues(w, newRequest("GET", path, nil))
|
|
if w.Code != http.StatusOK {
|
|
t.Fatalf("ListIssues: expected 200, got %d: %s", w.Code, w.Body.String())
|
|
}
|
|
var resp struct {
|
|
Issues []IssueResponse `json:"issues"`
|
|
Total int64 `json:"total"`
|
|
}
|
|
if err := json.NewDecoder(w.Body).Decode(&resp); err != nil {
|
|
t.Fatalf("decode list response: %v", err)
|
|
}
|
|
for _, iss := range resp.Issues {
|
|
ids = append(ids, iss.ID)
|
|
}
|
|
return ids, resp.Total
|
|
}
|
|
|
|
// Without the filter every project issue comes back.
|
|
allIDs, allTotal := list("")
|
|
for _, want := range []string{withStart, withDue, withBoth, noDates} {
|
|
if !containsIssueID(allIDs, want) {
|
|
t.Fatalf("baseline list missing %s — all=%v", want, allIDs)
|
|
}
|
|
}
|
|
if allTotal != 4 {
|
|
t.Fatalf("baseline total: want 4, got %d", allTotal)
|
|
}
|
|
|
|
// With scheduled=true only the three dated issues should surface, and
|
|
// CountIssues must agree so the frontend pagination logic stays sane.
|
|
scheduledIDs, scheduledTotal := list("&scheduled=true")
|
|
for _, want := range []string{withStart, withDue, withBoth} {
|
|
if !containsIssueID(scheduledIDs, want) {
|
|
t.Fatalf("scheduled list missing %s — got %v", want, scheduledIDs)
|
|
}
|
|
}
|
|
if containsIssueID(scheduledIDs, noDates) {
|
|
t.Fatalf("scheduled list unexpectedly includes undated issue %s", noDates)
|
|
}
|
|
if scheduledTotal != 3 {
|
|
t.Fatalf("scheduled total: want 3, got %d", scheduledTotal)
|
|
}
|
|
}
|