Files
multica/packages/core/issues/surface/scope.test.ts
Naiyuan Qing afc7ac4bd0 feat: space rollout — space-first navigation, per-user membership, move-to-space (MUL-4142)
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>
2026-07-08 20:57:38 +08:00

158 lines
4.7 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { issueScopeKey } from "./scope";
import { buildIssueSurfaceQueryPlan } from "./query-plan";
describe("issue surface scope", () => {
it("builds stable surface keys", () => {
expect(issueScopeKey({ type: "workspace" })).toBe("workspace:all");
expect(issueScopeKey({ type: "workspace", actorKind: "agents" })).toBe(
"workspace:agents",
);
expect(
issueScopeKey({ type: "my", relation: "assigned", userId: "u1" }),
).toBe("my:u1:assigned");
expect(issueScopeKey({ type: "project", projectId: "p1" })).toBe(
"project:p1",
);
expect(
issueScopeKey({
type: "actor",
actorType: "agent",
actorId: "a1",
relation: "created",
}),
).toBe("actor:agent:a1:created");
expect(issueScopeKey({ type: "space", spaceId: "t1" })).toBe("space:t1");
});
it("builds the workspace query plan", () => {
// The unfiltered tab shares the workspace list cache.
expect(buildIssueSurfaceQueryPlan({ type: "workspace" })).toMatchObject({
kind: "workspace",
scopeKey: "workspace:all",
queryFilter: {},
groupedScopeFilter: {},
createDefaults: {},
});
// Members/Agents tabs are server-filtered scoped lists: assignee_types
// rides the list + grouped requests, and each tab owns its cache entry
// (correct totals + load-more, no client post-filtering).
expect(
buildIssueSurfaceQueryPlan({ type: "workspace", actorKind: "agents" }),
).toMatchObject({
kind: "scoped",
scopeKey: "workspace:agents",
queryScope: "workspace:agents",
queryFilter: { assignee_types: ["agent", "squad"] },
groupedScopeFilter: { assignee_types: ["agent", "squad"] },
loadMoreScope: "workspace:agents",
loadMoreFilter: { assignee_types: ["agent", "squad"] },
createDefaults: {},
});
expect(
buildIssueSurfaceQueryPlan({ type: "workspace", actorKind: "members" }),
).toMatchObject({
kind: "scoped",
scopeKey: "workspace:members",
queryFilter: { assignee_types: ["member"] },
groupedScopeFilter: { assignee_types: ["member"] },
createDefaults: {},
});
});
it("builds personal issue query plans using the existing query contracts", () => {
expect(
buildIssueSurfaceQueryPlan({
type: "my",
relation: "assigned",
userId: "u1",
}),
).toMatchObject({
scopeKey: "my:u1:assigned",
queryScope: "assigned",
queryFilter: { assignee_id: "u1" },
groupedScopeFilter: { assignee_id: "u1" },
loadMoreScope: "assigned",
loadMoreFilter: { assignee_id: "u1" },
userId: undefined,
createDefaults: { assignee_type: "member", assignee_id: "u1" },
});
expect(
buildIssueSurfaceQueryPlan({
type: "my",
relation: "created",
userId: "u1",
}),
).toMatchObject({
queryScope: "created",
queryFilter: { creator_id: "u1" },
createDefaults: {},
});
expect(
buildIssueSurfaceQueryPlan({
type: "my",
relation: "involved",
userId: "u1",
}),
).toMatchObject({
queryScope: "agents",
queryFilter: { involves_user_id: "u1" },
createDefaults: {},
});
expect(
buildIssueSurfaceQueryPlan({
type: "my",
relation: "all",
userId: "u1",
}),
).toMatchObject({
queryScope: "all",
queryFilter: {},
groupedScopeFilter: {},
userId: "u1",
createDefaults: {},
});
});
it("builds project and actor query plans", () => {
expect(
buildIssueSurfaceQueryPlan({ type: "project", projectId: "p1" }),
).toMatchObject({
scopeKey: "project:p1",
queryScope: "project:p1",
queryFilter: { project_id: "p1" },
groupedScopeFilter: { project_id: "p1" },
createDefaults: { project_id: "p1" },
});
expect(
buildIssueSurfaceQueryPlan({
type: "actor",
actorType: "agent",
actorId: "a1",
relation: "assigned",
}),
).toMatchObject({
scopeKey: "actor:agent:a1:assigned",
queryScope: "actor:agent:a1:assigned",
queryFilter: { assignee_id: "a1" },
groupedScopeFilter: { assignee_id: "a1" },
createDefaults: { assignee_type: "agent", assignee_id: "a1" },
});
});
it("builds the space query plan mirroring the project shape", () => {
expect(
buildIssueSurfaceQueryPlan({ type: "space", spaceId: "t1" }),
).toMatchObject({
kind: "scoped",
scopeKey: "space:t1",
queryScope: "space:t1",
queryFilter: { space_id: "t1" },
groupedScopeFilter: { space_id: "t1" },
createDefaults: { space_id: "t1" },
});
});
});