simplify layers

This commit is contained in:
Julius Marminge authored and Julius Marminge committed 2026-03-05 23:40:49 -08:00
1 parent 477b4f9d0e
commit 268bb4bfa3
5 files changed
+27 -46

No files matched your search

@@ -253,22 +253,12 @@ export const makeOrchestrationIntegrationHarness = (
? makeProviderServiceLive().pipe(
Layer.provide(providerSessionDirectoryLayer),
Layer.provide(realCodexRegistry),
Layer.provide(
Layer.succeed(AnalyticsService, {
record: () => Effect.void,
flush: Effect.void,
}),
),
Layer.provide(AnalyticsService.layerTest),
)
: makeProviderServiceLive().pipe(
Layer.provide(providerSessionDirectoryLayer),
Layer.provide(fakeRegistry!),
Layer.provide(
Layer.succeed(AnalyticsService, {
record: () => Effect.void,
flush: Effect.void,
}),
),
Layer.provide(AnalyticsService.layerTest),
);
const runtimeServicesLayer = Layer.mergeAll(
@@ -60,10 +60,7 @@ const makeIntegrationFixture = Effect.gen(function* () {
const shared = Layer.mergeAll(
directoryLayer,
Layer.succeed(ProviderAdapterRegistry, registry),
Layer.succeed(AnalyticsService, {
record: () => Effect.void,
flush: Effect.void,
}),
AnalyticsService.layerTest,
).pipe(Layer.provide(SqlitePersistenceMemory));
const layer = makeProviderServiceLive().pipe(Layer.provide(shared));
+1 -4
View File
@@ -49,10 +49,7 @@ const testLayer = Layer.mergeAll(
openBrowser: (_target: string) => Effect.void,
openInEditor: () => Effect.void,
} satisfies OpenShape),
Layer.succeed(AnalyticsService, {
record: () => Effect.void,
flush: Effect.void,
}),
AnalyticsService.layerTest,
FetchHttpClient.layer,
NodeServices.layer,
);
@@ -215,11 +215,6 @@ function makeFakeCodexAdapter(provider: ProviderKind = "codex") {
const sleep = (ms: number) =>
Effect.promise(() => new Promise<void>((resolve) => setTimeout(resolve, ms)));
const noopAnalyticsLayer = Layer.succeed(AnalyticsService, {
record: () => Effect.void,
flush: Effect.void,
});
function makeProviderServiceLayer() {
const codex = makeFakeCodexAdapter();
const registry: typeof ProviderAdapterRegistry.Service = {
@@ -241,7 +236,7 @@ function makeProviderServiceLayer() {
makeProviderServiceLive().pipe(
Layer.provide(providerAdapterLayer),
Layer.provide(directoryLayer),
Layer.provideMerge(noopAnalyticsLayer),
Layer.provideMerge(AnalyticsService.layerTest),
),
directoryLayer,
@@ -288,7 +283,7 @@ it.effect("ProviderServiceLive keeps persisted resumable sessions on startup", (
const providerLayer = makeProviderServiceLive().pipe(
Layer.provide(Layer.succeed(ProviderAdapterRegistry, registry)),
Layer.provide(directoryLayer),
Layer.provide(noopAnalyticsLayer),
Layer.provide(AnalyticsService.layerTest),
);
yield* Effect.gen(function* () {
@@ -347,7 +342,7 @@ it.effect(
const firstProviderLayer = makeProviderServiceLive().pipe(
Layer.provide(Layer.succeed(ProviderAdapterRegistry, firstRegistry)),
Layer.provide(firstDirectoryLayer),
Layer.provide(noopAnalyticsLayer),
Layer.provide(AnalyticsService.layerTest),
);
const startedSession = yield* Effect.gen(function* () {
@@ -390,7 +385,7 @@ it.effect(
const secondProviderLayer = makeProviderServiceLive().pipe(
Layer.provide(Layer.succeed(ProviderAdapterRegistry, secondRegistry)),
Layer.provide(secondDirectoryLayer),
Layer.provide(noopAnalyticsLayer),
Layer.provide(AnalyticsService.layerTest),
);
secondCodex.startSession.mockClear();
@@ -96,26 +96,28 @@ const makeAnalyticsService = Effect.gen(function* () {
});
const flush: AnalyticsServiceShape["flush"] = Effect.gen(function* () {
const batch = yield* Ref.modify(bufferRef, (current) => {
if (current.length === 0) {
return [[] as ReadonlyArray<BufferedAnalyticsEvent>, current] as const;
while (true) {
const batch = yield* Ref.modify(bufferRef, (current) => {
if (current.length === 0) {
return [[] as ReadonlyArray<BufferedAnalyticsEvent>, current] as const;
}
const nextBatch = current.slice(0, telemetryConfig.flushBatchSize);
const remaining = current.slice(nextBatch.length);
return [nextBatch, remaining] as const;
});
if (batch.length === 0) {
return;
}
const nextBatch = current.slice(0, telemetryConfig.flushBatchSize);
const remaining = current.slice(nextBatch.length);
return [nextBatch, remaining] as const;
});
if (batch.length === 0) {
return;
}
yield* sendBatch(batch).pipe(
Effect.catch((error) =>
Ref.update(bufferRef, (current) => [...batch, ...current]).pipe(
Effect.flatMap(() => Effect.fail(error)),
yield* sendBatch(batch).pipe(
Effect.catch((error) =>
Ref.update(bufferRef, (current) => [...batch, ...current]).pipe(
Effect.flatMap(() => Effect.fail(error)),
),
),
),
);
);
}
}).pipe(Effect.catch((cause) => Effect.logError("Failed to flush telemetry", { cause })));
const record: AnalyticsServiceShape["record"] = Effect.fnUntraced(function* (event, properties) {