Skip to content

Commit 40dbac1

Browse files
test(desktop): adapt auth tests to main's readiness wait and drop a duplicate case
The port-move retry case already shows ownership is rechecked before every token POST, and the foreign-responder case shows a foreign answer gets no POST, so the separate retry-recheck case is dropped. AI-assisted; verified with the tests and tools listed above.
1 parent 3266059 commit 40dbac1

1 file changed

Lines changed: 3 additions & 54 deletions

File tree

‎apps/desktop/src/backend/DesktopLocalEnvironmentAuth.test.ts‎

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ describe("DesktopLocalEnvironmentAuth", () => {
288288
Effect.flip,
289289
Effect.provide(
290290
DesktopLocalEnvironmentAuth.layer.pipe(
291-
Layer.provide(Layer.mergeAll(layerPool, layerHttpClient)),
291+
Layer.provide(Layer.mergeAll(layerPool, layerHttpClient, NodeCrypto.layerMac)),
292292
),
293293
),
294294
);
@@ -338,6 +338,7 @@ describe("DesktopLocalEnvironmentAuth", () => {
338338
id: PRIMARY_LOCAL_ENVIRONMENT_ID,
339339
label: Effect.succeed("Windows"),
340340
currentConfig: Effect.sync(() => Option.some(currentConfig)),
341+
waitForReady: () => Effect.succeed(true),
341342
},
342343
]),
343344
} as unknown as DesktopBackendPool.DesktopBackendPool["Service"]);
@@ -346,7 +347,7 @@ describe("DesktopLocalEnvironmentAuth", () => {
346347
Effect.result,
347348
Effect.provide(
348349
DesktopLocalEnvironmentAuth.layer.pipe(
349-
Layer.provide(Layer.mergeAll(movingPool, layerHttpClient)),
350+
Layer.provide(Layer.mergeAll(movingPool, layerHttpClient, NodeCrypto.layerMac)),
350351
),
351352
),
352353
Effect.forkChild,
@@ -379,56 +380,4 @@ describe("DesktopLocalEnvironmentAuth", () => {
379380
assert.deepEqual(credentials, ["desktop-bootstrap-token", "restarted-bootstrap-token"]);
380381
}).pipe(Effect.provide(TestClock.layer())),
381382
);
382-
383-
it.effect("rechecks ownership before retrying the bootstrap token exchange", () =>
384-
Effect.gen(function* () {
385-
const firstExchange = yield* Deferred.make<void>();
386-
const requests: string[] = [];
387-
let exchanged = false;
388-
const layerHttpClient = Layer.succeed(
389-
HttpClient.HttpClient,
390-
HttpClient.make((request) => {
391-
requests.push(`${request.method} ${new URL(request.url).pathname}`);
392-
if (request.url === DESCRIPTOR_URL) {
393-
return Effect.succeed(
394-
HttpClientResponse.fromWeb(
395-
request,
396-
Response.json({
397-
desktopLaunchId: exchanged ? "another-launch" : config.bootstrap.desktopLaunchId,
398-
}),
399-
),
400-
);
401-
}
402-
exchanged = true;
403-
return Deferred.succeed(firstExchange, void 0).pipe(
404-
Effect.as(HttpClientResponse.fromWeb(request, new Response("", { status: 503 }))),
405-
);
406-
}),
407-
);
408-
const result = yield* DesktopLocalEnvironmentAuth.DesktopLocalEnvironmentAuth.pipe(
409-
Effect.flatMap((auth) => auth.getBearerToken),
410-
Effect.result,
411-
Effect.provide(
412-
DesktopLocalEnvironmentAuth.layer.pipe(
413-
Layer.provide(Layer.mergeAll(layerPool, layerHttpClient)),
414-
),
415-
),
416-
Effect.forkChild,
417-
);
418-
419-
yield* Deferred.await(firstExchange);
420-
yield* TestClock.adjust(Duration.seconds(15));
421-
422-
const outcome = yield* Fiber.join(result);
423-
assert.equal(outcome._tag, "Failure");
424-
if (outcome._tag === "Failure") {
425-
assert.equal(outcome.failure._tag, "DesktopLocalEnvironmentAuthForeignServerError");
426-
}
427-
assert.deepEqual(requests, [
428-
"GET /.well-known/t3/environment",
429-
"POST /oauth/token",
430-
"GET /.well-known/t3/environment",
431-
]);
432-
}).pipe(Effect.provide(TestClock.layer())),
433-
);
434383
});

0 commit comments

Comments
 (0)