|
1 | | -import { EnvironmentId, ProjectId } from "@t3tools/contracts"; |
| 1 | +import { |
| 2 | + CommandId, |
| 3 | + EnvironmentId, |
| 4 | + MessageId, |
| 5 | + ProjectId, |
| 6 | + ProviderInstanceId, |
| 7 | + ThreadId, |
| 8 | +} from "@t3tools/contracts"; |
2 | 9 | import { describe, expect, it } from "vite-plus/test"; |
3 | 10 |
|
4 | 11 | import { |
| 12 | + buildPendingNewTasks, |
5 | 13 | type PendingDraftProjectDefaults, |
6 | 14 | pendingDraftBranchNeedsRefs, |
7 | 15 | resolvePendingDraftBranch, |
8 | 16 | } from "./pending-new-tasks-model"; |
| 17 | +import type { QueuedThreadMessage } from "./thread-outbox-model"; |
9 | 18 | import type { ComposerDraft, ComposerDraftWorkspaceSelection } from "./use-composer-drafts"; |
10 | 19 |
|
11 | 20 | const projectCwd = "/repo"; |
@@ -82,3 +91,55 @@ describe("resolvePendingDraftBranch", () => { |
82 | 91 | expect(resolve({ draft: chosen, branches, projectCwd })).toBe("release"); |
83 | 92 | }); |
84 | 93 | }); |
| 94 | + |
| 95 | +function queuedCreation(environmentId: string): QueuedThreadMessage { |
| 96 | + return { |
| 97 | + environmentId: EnvironmentId.make(environmentId), |
| 98 | + threadId: ThreadId.make(`thread-${environmentId}`), |
| 99 | + messageId: MessageId.make(`message-${environmentId}`), |
| 100 | + commandId: CommandId.make(`command-${environmentId}`), |
| 101 | + text: "Test", |
| 102 | + attachments: [], |
| 103 | + modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.6-sol" }, |
| 104 | + creation: { |
| 105 | + projectId: ProjectId.make("project-1"), |
| 106 | + workspaceMode: "local", |
| 107 | + branch: null, |
| 108 | + worktreePath: null, |
| 109 | + }, |
| 110 | + createdAt: "2026-11-10T01:10:00.000Z", |
| 111 | + }; |
| 112 | +} |
| 113 | + |
| 114 | +describe("buildPendingNewTasks", () => { |
| 115 | + it("lists only creations the outbox is not sending yet", () => { |
| 116 | + const sending = EnvironmentId.make("sending"); |
| 117 | + const syncing = EnvironmentId.make("syncing"); |
| 118 | + const readOnly = EnvironmentId.make("read-only"); |
| 119 | + const retrying = EnvironmentId.make("retrying"); |
| 120 | + const { modelSelection: _model, ...modelless } = queuedCreation("sending"); |
| 121 | + const tasks = buildPendingNewTasks({ |
| 122 | + queuedMessages: [ |
| 123 | + ...["sending", "syncing", "read-only", "retrying", "offline"].map(queuedCreation), |
| 124 | + { ...modelless, messageId: MessageId.make("message-modelless") }, |
| 125 | + ], |
| 126 | + drafts: {}, |
| 127 | + sendGate: { |
| 128 | + connectedEnvironmentIds: new Set([sending, syncing, readOnly, retrying]), |
| 129 | + operableEnvironmentIds: new Set([sending, syncing, retrying]), |
| 130 | + shellStatuses: new Map([ |
| 131 | + [sending, "live"], |
| 132 | + [syncing, "synchronizing"], |
| 133 | + [readOnly, "live"], |
| 134 | + [retrying, "live"], |
| 135 | + ]), |
| 136 | + retryingMessageIds: { [MessageId.make("message-retrying")]: true }, |
| 137 | + }, |
| 138 | + }); |
| 139 | + |
| 140 | + expect(tasks).toHaveLength(5); |
| 141 | + expect(new Set(tasks.map((task) => task.environmentId))).toEqual( |
| 142 | + new Set(["syncing", "read-only", "retrying", "offline", "sending"]), |
| 143 | + ); |
| 144 | + }); |
| 145 | +}); |
0 commit comments