Skip to content

Commit de7040e

Browse files
test(server): cut settle device tests to the cases a regression would fail
The re-engaged case is covered by the existing re-engaged settle test's device assertion, and the plain release case by the per-device failure test's exact close inputs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 5e1bd83 commit de7040e

1 file changed

Lines changed: 61 additions & 136 deletions

File tree

‎apps/server/src/orchestration-v2/ThreadSettlementService.test.ts‎

Lines changed: 61 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ interface HarnessOptions {
590590
input: ProjectSetupScriptRunner.ProjectSetupScriptRunnerInput,
591591
) => Effect.Effect<void>;
592592
readonly onCloseIdle?: () => Effect.Effect<void>;
593-
readonly onDeviceClose?: (hostId: string | undefined) => Effect.Effect<void>;
593+
readonly onDeviceClose?: () => Effect.Effect<void>;
594594
readonly deviceCloseError?: DeviceHostUnavailableError;
595595
readonly deviceSessions?: ReadonlyArray<{ readonly hostId: string; readonly deviceId: string }>;
596596
readonly currentThreads?: ReadonlyArray<OrchestrationV2AppThread>;
@@ -745,7 +745,7 @@ const makeHarness = Effect.fn("makeThreadSettlementHarness")(function* (options:
745745
// onDeviceClose stands in for the lifecycle lock wait; `when` runs once the lock is held.
746746
close: (input, closeOptions) =>
747747
Effect.gen(function* () {
748-
yield* options.onDeviceClose?.(input.hostId) ?? Effect.void;
748+
yield* options.onDeviceClose?.() ?? Effect.void;
749749
if (closeOptions?.when && !(yield* closeOptions.when)) return;
750750
yield* Ref.update(deviceCloses, (closes) => [...closes, input]);
751751
const error = options.deviceCloseError;
@@ -1915,146 +1915,71 @@ describe("ThreadSettlementServiceV2 terminals", () => {
19151915
}),
19161916
);
19171917

1918-
it.effect("keeps the devices of a thread re-engaged while a release waits on the lock", () =>
1919-
Effect.scoped(
1920-
Effect.gen(function* () {
1921-
const firstStarted = yield* Deferred.make<void>();
1922-
const firstFinished = yield* Deferred.make<void>();
1923-
const settled = appThread("multi-device-thread", "settled");
1924-
const marker = appThread("marker-thread", "settled");
1925-
const currentThreads = [settled, marker];
1926-
const fixture = yield* makeHarness({
1927-
snapshot: makeSnapshot([]),
1928-
currentThreads,
1929-
deviceSessions: [
1930-
{ hostId: "slow-ssh", deviceId: "pixel" },
1931-
{ hostId: "local", deviceId: "emulator-5554" },
1932-
],
1933-
onDeviceClose: (hostId) =>
1934-
hostId === "slow-ssh"
1935-
? Deferred.succeed(firstStarted, undefined).pipe(
1936-
Effect.andThen(Deferred.await(firstFinished)),
1937-
)
1938-
: Effect.void,
1939-
});
1940-
1941-
yield* Effect.gen(function* () {
1942-
const service = yield* ThreadSettlementService.ThreadSettlementServiceV2;
1943-
yield* startHarness(service, fixture.activation, fixture.snapshotReads);
1944-
yield* fixture.publishEvent(settledEvent(settled));
1945-
yield* Deferred.await(firstStarted);
1946-
currentThreads[0] = { ...settled, settledOverride: "active" };
1947-
yield* Deferred.succeed(firstFinished, undefined);
1948-
yield* fixture.publishEvent(settledEvent(marker));
1949-
assert.deepStrictEqual(yield* Queue.take(fixture.closedIdle), { threadId: settled.id });
1950-
assert.deepStrictEqual(yield* Queue.take(fixture.closedIdle), { threadId: marker.id });
1951-
yield* service.drain;
1952-
assert.deepStrictEqual(
1953-
(yield* Ref.get(fixture.deviceCloses)).filter((close) => close.threadId === settled.id),
1954-
[],
1955-
);
1956-
}).pipe(Effect.provide(fixture.layer));
1957-
}),
1958-
),
1959-
);
1960-
19611918
it.effect("closes another thread's terminals while a device release waits on the lock", () =>
1962-
Effect.scoped(
1963-
Effect.gen(function* () {
1964-
const releaseStarted = yield* Deferred.make<void>();
1965-
const lockFreed = yield* Deferred.make<void>();
1966-
const waiting = appThread("waiting-device-thread", "settled");
1967-
const other = appThread("other-thread", "settled");
1968-
const fixture = yield* makeHarness({
1969-
snapshot: makeSnapshot([]),
1970-
currentThreads: [waiting, other],
1971-
deviceSessions: [{ hostId: "starting-ssh", deviceId: "pixel" }],
1972-
onDeviceClose: () =>
1973-
Deferred.succeed(releaseStarted, undefined).pipe(
1974-
Effect.andThen(Deferred.await(lockFreed)),
1975-
),
1976-
});
1977-
1978-
yield* Effect.gen(function* () {
1979-
const service = yield* ThreadSettlementService.ThreadSettlementServiceV2;
1980-
yield* startHarness(service, fixture.activation, fixture.snapshotReads);
1981-
yield* fixture.publishEvent(settledEvent(waiting));
1982-
assert.deepStrictEqual(yield* Queue.take(fixture.closedIdle), { threadId: waiting.id });
1983-
yield* Deferred.await(releaseStarted);
1984-
yield* fixture.publishEvent(settledEvent(other));
1985-
assert.deepStrictEqual(yield* Queue.take(fixture.closedIdle), { threadId: other.id });
1986-
yield* Deferred.succeed(lockFreed, undefined);
1987-
yield* service.drain;
1988-
assert.deepStrictEqual(
1989-
(yield* Ref.get(fixture.deviceCloses)).map((close) => close.threadId),
1990-
[waiting.id, other.id],
1991-
);
1992-
}).pipe(Effect.provide(fixture.layer));
1993-
}),
1994-
),
1995-
);
1996-
1997-
it.effect("releases a settled thread's devices without shutting them down", () =>
1998-
Effect.scoped(
1999-
Effect.gen(function* () {
2000-
const settled = appThread("device-thread", "settled");
2001-
const marker = appThread("marker-thread", "settled");
2002-
const fixture = yield* makeHarness({
2003-
snapshot: makeSnapshot([]),
2004-
currentThreads: [settled, marker],
2005-
});
1919+
Effect.gen(function* () {
1920+
const releaseStarted = yield* Deferred.make<void>();
1921+
const lockFreed = yield* Deferred.make<void>();
1922+
const waiting = appThread("waiting-device-thread", "settled");
1923+
const other = appThread("other-thread", "settled");
1924+
const fixture = yield* makeHarness({
1925+
snapshot: makeSnapshot([]),
1926+
currentThreads: [waiting, other],
1927+
deviceSessions: [{ hostId: "starting-ssh", deviceId: "pixel" }],
1928+
onDeviceClose: () =>
1929+
Deferred.succeed(releaseStarted, undefined).pipe(
1930+
Effect.andThen(Deferred.await(lockFreed)),
1931+
),
1932+
});
20061933

2007-
yield* Effect.gen(function* () {
2008-
const service = yield* ThreadSettlementService.ThreadSettlementServiceV2;
2009-
yield* startHarness(service, fixture.activation, fixture.snapshotReads);
2010-
yield* fixture.publishEvent(settledEvent(settled));
2011-
yield* fixture.publishEvent(settledEvent(marker));
2012-
assert.deepStrictEqual(yield* Queue.take(fixture.closedIdle), { threadId: settled.id });
2013-
assert.deepStrictEqual(yield* Queue.take(fixture.closedIdle), { threadId: marker.id });
2014-
yield* service.drain;
2015-
const closes = yield* Ref.get(fixture.deviceCloses);
2016-
assert.deepStrictEqual(
2017-
closes.filter((close) => close.threadId === settled.id),
2018-
[{ threadId: settled.id, hostId: "local", deviceId: "emulator-5554" }],
2019-
);
2020-
}).pipe(Effect.provide(fixture.layer));
2021-
}),
2022-
),
1934+
yield* Effect.gen(function* () {
1935+
const service = yield* ThreadSettlementService.ThreadSettlementServiceV2;
1936+
yield* startHarness(service, fixture.activation, fixture.snapshotReads);
1937+
yield* fixture.publishEvent(settledEvent(waiting));
1938+
assert.deepStrictEqual(yield* Queue.take(fixture.closedIdle), { threadId: waiting.id });
1939+
yield* Deferred.await(releaseStarted);
1940+
yield* fixture.publishEvent(settledEvent(other));
1941+
assert.deepStrictEqual(yield* Queue.take(fixture.closedIdle), { threadId: other.id });
1942+
yield* Deferred.succeed(lockFreed, undefined);
1943+
yield* service.drain;
1944+
assert.deepStrictEqual(
1945+
(yield* Ref.get(fixture.deviceCloses)).map((close) => close.threadId),
1946+
[waiting.id, other.id],
1947+
);
1948+
}).pipe(Effect.provide(fixture.layer));
1949+
}),
20231950
);
20241951

20251952
it.effect("releases the other devices and runs the settle script when one release fails", () =>
2026-
Effect.scoped(
2027-
Effect.gen(function* () {
2028-
const settled = appThread("reconnecting-host-thread", "settled", "/worktrees/thread");
2029-
const fixture = yield* makeHarness({
2030-
snapshot: makeSnapshot([]),
2031-
currentThreads: [settled],
2032-
existingWorktreePaths: ["/worktrees/thread"],
2033-
deviceSessions: [
2034-
{ hostId: "ssh-host", deviceId: "remote-pixel" },
2035-
{ hostId: "local", deviceId: "emulator-5554" },
2036-
],
2037-
deviceCloseError: new DeviceHostUnavailableError({
2038-
hostId: "ssh-host",
2039-
reason: "Device host is reconnecting. Retry close after it reconnects.",
2040-
}),
2041-
});
1953+
Effect.gen(function* () {
1954+
const settled = appThread("reconnecting-host-thread", "settled", "/worktrees/thread");
1955+
const fixture = yield* makeHarness({
1956+
snapshot: makeSnapshot([]),
1957+
currentThreads: [settled],
1958+
existingWorktreePaths: ["/worktrees/thread"],
1959+
deviceSessions: [
1960+
{ hostId: "ssh-host", deviceId: "remote-pixel" },
1961+
{ hostId: "local", deviceId: "emulator-5554" },
1962+
],
1963+
deviceCloseError: new DeviceHostUnavailableError({
1964+
hostId: "ssh-host",
1965+
reason: "Device host is reconnecting. Retry close after it reconnects.",
1966+
}),
1967+
});
20421968

2043-
yield* Effect.gen(function* () {
2044-
const service = yield* ThreadSettlementService.ThreadSettlementServiceV2;
2045-
yield* startHarness(service, fixture.activation, fixture.snapshotReads);
2046-
yield* fixture.publishEvent(settledEvent(settled));
2047-
assert.deepStrictEqual(yield* Queue.take(fixture.closedIdle), { threadId: settled.id });
2048-
const run = yield* Queue.take(fixture.scriptRuns);
2049-
assert.strictEqual(run.threadId, settled.id);
2050-
yield* service.drain;
2051-
assert.deepStrictEqual(yield* Ref.get(fixture.deviceCloses), [
2052-
{ threadId: settled.id, hostId: "ssh-host", deviceId: "remote-pixel" },
2053-
{ threadId: settled.id, hostId: "local", deviceId: "emulator-5554" },
2054-
]);
2055-
}).pipe(Effect.provide(fixture.layer));
2056-
}),
2057-
),
1969+
yield* Effect.gen(function* () {
1970+
const service = yield* ThreadSettlementService.ThreadSettlementServiceV2;
1971+
yield* startHarness(service, fixture.activation, fixture.snapshotReads);
1972+
yield* fixture.publishEvent(settledEvent(settled));
1973+
assert.deepStrictEqual(yield* Queue.take(fixture.closedIdle), { threadId: settled.id });
1974+
const run = yield* Queue.take(fixture.scriptRuns);
1975+
assert.strictEqual(run.threadId, settled.id);
1976+
yield* service.drain;
1977+
assert.deepStrictEqual(yield* Ref.get(fixture.deviceCloses), [
1978+
{ threadId: settled.id, hostId: "ssh-host", deviceId: "remote-pixel" },
1979+
{ threadId: settled.id, hostId: "local", deviceId: "emulator-5554" },
1980+
]);
1981+
}).pipe(Effect.provide(fixture.layer));
1982+
}),
20581983
);
20591984

20601985
it.effect("runs the settle script in the thread's own worktree", () =>

0 commit comments

Comments
 (0)