|
1 | 1 | import { |
| 2 | + OrchestrationProjectShell, |
2 | 3 | OrchestrationV2ThreadShell, |
3 | 4 | RepositoryIdentity, |
4 | 5 | ThreadPullRequestLink, |
5 | | - type OrchestrationProjectShell, |
6 | 6 | type OrchestrationV2ShellSnapshot, |
7 | 7 | type OrchestrationV2ShellStreamItem, |
8 | 8 | } from "@t3tools/contracts"; |
9 | 9 | import * as Schema from "effect/Schema"; |
10 | 10 |
|
11 | 11 | const sameThreadShell = Schema.toEquivalence(OrchestrationV2ThreadShell); |
| 12 | +const sameProjectShell = Schema.toEquivalence(OrchestrationProjectShell); |
12 | 13 | const sameLinks = Schema.toEquivalence(Schema.UndefinedOr(Schema.Array(ThreadPullRequestLink))); |
13 | 14 | const sameRepositoryIdentity = Schema.toEquivalence( |
14 | 15 | Schema.UndefinedOr(Schema.NullOr(RepositoryIdentity)), |
@@ -116,16 +117,16 @@ export function mergeShellSnapshotProjects( |
116 | 117 | } |
117 | 118 |
|
118 | 119 | const previousById = new Map(previous.projects.map((project) => [project.id, project] as const)); |
119 | | - return { |
120 | | - ...next, |
121 | | - projects: next.projects.map((project) => { |
122 | | - const prior = previousById.get(project.id); |
123 | | - if (resolvedRootSet?.has(project.workspaceRoot) === true) { |
124 | | - return project; |
125 | | - } |
126 | | - return retainRepositoryIdentity(prior, project); |
127 | | - }), |
128 | | - }; |
| 120 | + // Project atoms and shell persistence compare by reference, so unchanged projects keep their objects. |
| 121 | + const projects = next.projects.map((project) => { |
| 122 | + const prior = previousById.get(project.id); |
| 123 | + const merged = retainRepositoryIdentity(prior, project); |
| 124 | + return prior !== undefined && sameProjectShell(prior, merged) ? prior : merged; |
| 125 | + }); |
| 126 | + const unchanged = |
| 127 | + projects.length === previous.projects.length && |
| 128 | + projects.every((project, index) => project === previous.projects[index]); |
| 129 | + return { ...next, projects: unchanged ? previous.projects : projects }; |
129 | 130 | } |
130 | 131 |
|
131 | 132 | export function applyShellStreamEvent( |
|
0 commit comments