Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions apps/web/src/threadMove.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,21 @@ describe("describeRemoteChildrenStaying", () => {
"'Fix tests' on Mac mini becomes its thread there again.",
"2 threads it started on Windows PC stay there. It can't reach them from Mac mini.",
]);
// An older Mac mini keeps them apart: today's words.
// An older Mac mini keeps them apart, beside it rather than "there".
expect(
describeRemoteChildrenStaying(children, { label: "Mac mini", environmentId: MAC }),
).toEqual([
"1 thread it started on Mac mini stays there. It can't reach it from Mac mini.",
"'Fix tests' is already on Mac mini. It stays separate, so this thread can't reach it.",
"2 threads it started on Windows PC stay there. It can't reach them from Mac mini.",
]);
// An older server names no computer for its children: matched by name.
expect(
describeRemoteChildrenStaying(
children.map(({ label, title }) => ({ label, title })),
{ label: "Mac mini", environmentId: MAC },
),
).toEqual([
"'Fix tests' is already on Mac mini. It stays separate, so this thread can't reach it.",
"2 threads it started on Windows PC stay there. It can't reach them from Mac mini.",
]);
});
Expand Down
35 changes: 25 additions & 10 deletions apps/web/src/threadMove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1014,10 +1014,13 @@ export function describeFamilyComing(count: number): string {
/**
* "2 threads it started on Windows PC stay there. It can't reach them from
* Mac mini.", one line per computer, for the threads its agent started on
* other computers. Those on the computer it moves to, when that computer
* takes them back (`adoptsChildren`), become its threads there again
* (docs/design/fleet.md, Part 3f, (g)): "'Fix tests' on Mac mini becomes its
* thread there again."
* other computers. Those already on the computer it moves to become its
* threads there again when that computer takes them back (`adoptsChildren`,
* docs/design/fleet.md, Part 3f, (g)): "'Fix tests' on Mac mini becomes its
* thread there again." A computer that doesn't (an older one) keeps them
* apart beside it: "'Fix tests' is already on Mac mini. It stays separate, so
* this thread can't reach it." A child the server named no computer for (an
* older server) is matched to the target by its label.
*/
export function describeRemoteChildrenStaying(
remoteChildren: ReadonlyArray<{
Expand All @@ -1031,23 +1034,35 @@ export function describeRemoteChildrenStaying(
readonly adoptsChildren?: true | undefined;
},
): string[] {
const back = remoteChildren.filter(
(child) => target.adoptsChildren === true && child.environmentId === target.environmentId,
const onTarget = remoteChildren.filter((child) =>
child.environmentId !== undefined
? child.environmentId === target.environmentId
: child.label === target.label,
);
const back = target.adoptsChildren === true ? onTarget : [];
const beside = target.adoptsChildren === true ? [] : onTarget;
const byLabel = new Map<string, number>();
for (const child of remoteChildren) {
if (back.includes(child)) continue;
if (onTarget.includes(child)) continue;
byLabel.set(child.label, (byLabel.get(child.label) ?? 0) + 1);
}
const [only] = back;
const [onlyBack] = back;
const [onlyBeside] = beside;
return [
...(back.length === 0
? []
: [
back.length === 1 && only !== undefined
? `'${only.title}' on ${target.label} becomes its thread there again.`
back.length === 1 && onlyBack !== undefined
? `'${onlyBack.title}' on ${target.label} becomes its thread there again.`
: `${back.length} threads it started on ${target.label} become its threads there again.`,
]),
...(beside.length === 0
? []
: [
beside.length === 1 && onlyBeside !== undefined
? `'${onlyBeside.title}' is already on ${target.label}. It stays separate, so this thread can't reach it.`
: `${beside.length} threads it started are already on ${target.label}. They stay separate, so this thread can't reach them.`,
]),
...[...byLabel].map(([label, count]) =>
count === 1
? `1 thread it started on ${label} stays there. It can't reach it from ${target.label}.`
Expand Down
Loading