Skip to content

Commit 3e5ce00

Browse files
build: run Effect rules on mobile and lock in clean suggestion rules
apps/mobile extended Expo's tsconfig and never loaded the Effect language service. Its config now extends tsconfig.effect.json, which holds the rules for every workspace, and its 94 findings are fixed. Suggestion rules with no remaining hits become errors so new violations fail the typecheck. Fixes the two errors whose `name` payload shadowed the error's own name. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 7f6f47b commit 3e5ce00

43 files changed

Lines changed: 468 additions & 292 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/preview/BrowserImport/BrowserImport.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,12 @@ export class BrowserCookieWriteError extends Schema.TaggedError<BrowserCookieWri
9696
"BrowserCookieWriteError",
9797
{
9898
url: Schema.String,
99-
name: Schema.String,
99+
cookieName: Schema.String,
100100
cause: Schema.Defect(),
101101
},
102102
) {
103103
override get message(): string {
104-
return `Could not write imported cookie ${this.name} for ${this.url}.`;
104+
return `Could not write imported cookie ${this.cookieName} for ${this.url}.`;
105105
}
106106
}
107107

@@ -167,7 +167,8 @@ export const writeCookies = Effect.fn("BrowserImport.writeCookies")(function* (
167167
sameSite: cookie.sameSite,
168168
...(cookie.expirationDate === undefined ? {} : { expirationDate: cookie.expirationDate }),
169169
}),
170-
catch: (cause) => new BrowserCookieWriteError({ url: cookie.url, name: cookie.name, cause }),
170+
catch: (cause) =>
171+
new BrowserCookieWriteError({ url: cookie.url, cookieName: cookie.name, cause }),
171172
}).pipe(
172173
Effect.as(true),
173174
Effect.tapError((error) => Effect.logDebug(error.message, { cause: error.cause })),

‎apps/mobile/src/components/PdfPreview.android.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ const preparedPdfAtom = Atom.family((uri: string) =>
3131
},
3232
catch: (cause) => (cause instanceof Error ? cause.message : "The PDF could not be loaded."),
3333
}).pipe(
34-
Effect.flatMap((file) => (file === null ? Effect.interrupt : Effect.succeed(file))),
34+
Effect.filterOrElse(
35+
(file) => file !== null,
36+
() => Effect.interrupt,
37+
),
3538
Effect.interruptible,
3639
),
3740
(file) => Effect.sync(file.dispose),

‎apps/mobile/src/connection/environment-cache-store.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ function makeDatabase() {
252252
}),
253253
clearAllCaches: Effect.sync(() => values.clear()),
254254
inspectCaches: Effect.succeed([]),
255-
loadPreferencesJson: Effect.succeed(Option.none()),
255+
loadPreferencesJson: Effect.succeedNone,
256256
savePreferencesJson: () => Effect.void,
257257
});
258258
return { database, removed, schemaVersions, values };

‎apps/mobile/src/connection/environment-cache-store.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ function mapDatabaseError(operation: CacheOperation) {
5454
return (error: MobileDatabase.MobileDatabaseError) => persistenceError(operation, error);
5555
}
5656

57-
function loadDecodedCache<A, B>(input: {
57+
function loadDecodedCache<A, B, E>(input: {
5858
readonly database: MobileDatabase.MobileDatabase["Service"];
5959
readonly environmentId: EnvironmentId;
6060
readonly kind: MobileDatabase.ClientCacheKind;
6161
readonly cacheKey: string;
6262
readonly operation: CacheOperation;
63-
readonly decode: (raw: string) => Effect.Effect<A, unknown>;
63+
readonly decode: (raw: string) => Effect.Effect<A, E>;
6464
readonly select: (value: A) => Option.Option<B>;
6565
}): Effect.Effect<Option.Option<B>, Persistence.ConnectionPersistenceError> {
6666
return input.database.loadCache(input.environmentId, input.kind, input.cacheKey).pipe(
@@ -81,7 +81,7 @@ function loadDecodedCache<A, B>(input: {
8181
Effect.andThen(
8282
input.database
8383
.removeCache(input.environmentId, input.kind, input.cacheKey)
84-
.pipe(Effect.catch(() => Effect.void)),
84+
.pipe(Effect.ignore),
8585
),
8686
Effect.as(Option.none<B>()),
8787
),

‎apps/mobile/src/connection/migration.ts‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,19 @@ function migrateConnection(
8787
);
8888
}
8989

90+
const decodeLegacyCatalogJson = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Unknown));
91+
9092
export const migrateLegacyConnectionCatalog = Effect.fn(
9193
"mobile.connectionMigration.migrateCatalog",
9294
)(function* (raw: string) {
93-
const parsed = yield* Effect.try({
94-
try: () => JSON.parse(raw) as unknown,
95-
catch: (cause) =>
96-
new LegacyConnectionMigrationError({
97-
message: `Could not parse the legacy mobile connection catalog: ${String(cause)}`,
98-
}),
99-
});
95+
const parsed = yield* decodeLegacyCatalogJson(raw).pipe(
96+
Effect.mapError(
97+
(cause) =>
98+
new LegacyConnectionMigrationError({
99+
message: `Could not parse the legacy mobile connection catalog: ${String(cause)}`,
100+
}),
101+
),
102+
);
100103
const legacy = yield* decodeLegacyConnectionDocument(parsed).pipe(
101104
Effect.mapError(
102105
(cause) =>

‎apps/mobile/src/connection/platform.ts‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Wakeups,
1111
} from "@t3tools/client-runtime/connection";
1212
import { managedRelayAccountChanges, managedRelaySessionAtom } from "@t3tools/client-runtime/relay";
13+
import * as Clock from "effect/Clock";
1314
import * as Context from "effect/Context";
1415
import * as Effect from "effect/Effect";
1516
import * as Layer from "effect/Layer";
@@ -120,8 +121,9 @@ const layerWakeups = Wakeups.layer({
120121
[
121122
Stream.callback<"application-active-probe" | "application-active-long">((queue) =>
122123
Effect.acquireRelease(
123-
Effect.sync(() => {
124-
let backgroundedAtMs = AppState.currentState === "background" ? Date.now() : null;
124+
Effect.gen(function* () {
125+
const nowMs = yield* Clock.currentTimeMillis;
126+
let backgroundedAtMs = AppState.currentState === "background" ? nowMs : null;
125127
return AppState.addEventListener("change", (state) => {
126128
if (state === "background") {
127129
backgroundedAtMs = Date.now();
@@ -187,7 +189,7 @@ const layerCapabilities = Layer.effectContext(
187189
Context.add(
188190
ClientCapabilities.PrimaryEnvironmentAuth,
189191
ClientCapabilities.PrimaryEnvironmentAuth.of({
190-
bearerToken: Effect.succeed(Option.none()),
192+
bearerToken: Effect.succeedNone,
191193
}),
192194
),
193195
// The relay device id already persists in secure storage; analytics only sends its hash.
@@ -205,7 +207,7 @@ const layerCapabilities = Layer.effectContext(
205207
detail: `Could not load the mobile device identity: ${String(cause)}`,
206208
}),
207209
),
208-
Effect.map(Option.some),
210+
Effect.asSome,
209211
),
210212
}),
211213
),
@@ -218,21 +220,25 @@ const layerCapabilities = Layer.effectContext(
218220
Context.add(
219221
ClientCapabilities.SshEnvironmentGateway,
220222
ClientCapabilities.SshEnvironmentGateway.of({
221-
provision: () =>
223+
provision: Effect.fn("ClientCapabilities.SshEnvironmentGateway.provision")(() =>
222224
Effect.fail(
223225
new ConnectionBlockedError({
224226
reason: "unsupported",
225227
detail: "SSH environments are only available in the desktop app.",
226228
}),
227229
),
228-
prepare: () =>
230+
),
231+
prepare: Effect.fn("ClientCapabilities.SshEnvironmentGateway.prepare")(() =>
229232
Effect.fail(
230233
new ConnectionBlockedError({
231234
reason: "unsupported",
232235
detail: "SSH environments are only available in the desktop app.",
233236
}),
234237
),
235-
disconnect: () => Effect.void,
238+
),
239+
disconnect: Effect.fn("ClientCapabilities.SshEnvironmentGateway.disconnect")(
240+
() => Effect.void,
241+
),
236242
}),
237243
),
238244
);
@@ -252,22 +258,16 @@ const layerProvidedCapabilities = layerCapabilities.pipe(Layer.provide(Runtime.l
252258
const layerEnvironmentOwnedDataCleanup = Layer.succeed(
253259
Persistence.EnvironmentOwnedDataCleanup,
254260
Persistence.EnvironmentOwnedDataCleanup.of({
255-
clear: (environmentId) =>
261+
clear: Effect.fn("Persistence.EnvironmentOwnedDataCleanup.clear")((environmentId) =>
256262
Effect.all(
257263
[
258264
Effect.promise(() => clearThreadOutboxEnvironment(environmentId)),
259265
Effect.promise(() => clearComposerDraftsEnvironment(environmentId)),
260266
Effect.sync(() => clearThreadComposerErrorsForEnvironment(environmentId)),
261267
],
262268
{ concurrency: "unbounded", discard: true },
263-
).pipe(
264-
Effect.catch((cause) =>
265-
Effect.logWarning("Could not clear mobile environment-owned data.", {
266-
environmentId,
267-
cause,
268-
}),
269-
),
270269
),
270+
),
271271
}),
272272
);
273273

‎apps/mobile/src/connection/storage.ts‎

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,24 +59,33 @@ export const layer = Layer.effectContext(
5959
),
6060
});
6161
const registrationStore = Persistence.ConnectionRegistrationStore.of({
62-
register: (registration, routes) =>
63-
catalog
64-
.update((document) => registerConnectionInCatalog(document, registration, routes))
65-
.pipe(Effect.mapError((error) => targetPersistenceError("register-connection", error))),
66-
setRoutes: (environmentId, routes) =>
67-
catalog
68-
.update((document) => setRoutesInCatalog(document, environmentId, routes))
69-
.pipe(Effect.mapError((error) => targetPersistenceError("set-connection-routes", error))),
70-
remove: (environmentId) =>
62+
register: Effect.fn("Persistence.ConnectionRegistrationStore.register")(
63+
(registration, routes) =>
64+
catalog
65+
.update((document) => registerConnectionInCatalog(document, registration, routes))
66+
.pipe(Effect.mapError((error) => targetPersistenceError("register-connection", error))),
67+
),
68+
setRoutes: Effect.fn("Persistence.ConnectionRegistrationStore.setRoutes")(
69+
(environmentId, routes) =>
70+
catalog
71+
.update((document) => setRoutesInCatalog(document, environmentId, routes))
72+
.pipe(
73+
Effect.mapError((error) => targetPersistenceError("set-connection-routes", error)),
74+
),
75+
),
76+
remove: Effect.fn("Persistence.ConnectionRegistrationStore.remove")((environmentId) =>
7177
catalog
7278
.update((document) => removeConnectionFromCatalog(document, environmentId))
7379
.pipe(Effect.mapError((error) => targetPersistenceError("remove-connection", error))),
74-
setEnabled: (environmentId, enabled) =>
75-
catalog
76-
.update((document) => setConnectionEnabledInCatalog(document, environmentId, enabled))
77-
.pipe(
78-
Effect.mapError((error) => targetPersistenceError("set-connection-enabled", error)),
79-
),
80+
),
81+
setEnabled: Effect.fn("Persistence.ConnectionRegistrationStore.setEnabled")(
82+
(environmentId, enabled) =>
83+
catalog
84+
.update((document) => setConnectionEnabledInCatalog(document, environmentId, enabled))
85+
.pipe(
86+
Effect.mapError((error) => targetPersistenceError("set-connection-enabled", error)),
87+
),
88+
),
8089
});
8190
const profileStore = ProfileStore.make({
8291
get: (connectionId) =>

‎apps/mobile/src/features/agent-awareness/remoteRegistration.test.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
releaseAgentAwarenessRelayTokenProvider,
3232
setAgentAwarenessRelayTokenProvider,
3333
updateAgentAwarenessRegistrationPreferences,
34+
type AgentAwarenessRegistrationError,
3435
} from "./remoteRegistration";
3536
import * as Notifications from "expo-notifications";
3637
import { Platform } from "react-native";
@@ -216,7 +217,11 @@ const runBackgroundOperations = Effect.fn("TestRemoteRegistration.runBackgroundO
216217
}
217218
idlePasses = 0;
218219
const exit = yield* Effect.exit(
219-
pending.operation as Effect.Effect<unknown, unknown, ManagedRelay.ManagedRelayClient>,
220+
pending.operation as Effect.Effect<
221+
unknown,
222+
AgentAwarenessRegistrationError,
223+
ManagedRelay.ManagedRelayClient
224+
>,
220225
);
221226
yield* Effect.sync(() => {
222227
pending.resolve(exit);
@@ -394,7 +399,11 @@ describe("makeRelayDeviceRegistrationRequest", () => {
394399
// activity lock, or, without one, at its device-id lookup.
395400
const rotatedRegistration = yield* Effect.forkChild(
396401
Effect.exit(
397-
rotated.operation as Effect.Effect<unknown, unknown, ManagedRelay.ManagedRelayClient>,
402+
rotated.operation as Effect.Effect<
403+
unknown,
404+
AgentAwarenessRegistrationError,
405+
ManagedRelay.ManagedRelayClient
406+
>,
398407
),
399408
{ startImmediately: true },
400409
);

0 commit comments

Comments
 (0)