Repository navigation
fix(mobile): removing an environment no longer fails when a queued message can't be read #28322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
only21mil
wants to merge
5
commits into
pingdotgg:main
Choose a base branch
from
only21mil:fix/audit-m015
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+126
−26
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0d2f876
fix(mobile): removing an environment no longer fails when a queued me…
only21mil 6789c92
fix(mobile): environment cleanup waits for every clear and logs a bou…
only21mil ee13aff
Merge remote-tracking branch 'github/main' into fix/audit-m015
maria-rcks 05e49ed
fix(mobile): environment cleanup maps clear failures to a typed error
maria-rcks 8b29305
test(mobile): drafts-clear mock builds its promise only when called
only21mil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
apps/mobile/src/connection/environment-owned-data-cleanup.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import { Persistence } from "@t3tools/client-runtime/platform"; | ||
| import { EnvironmentId } from "@t3tools/contracts"; | ||
| import { describe, expect, it } from "@effect/vitest"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Layer from "effect/Layer"; | ||
| import * as Logger from "effect/Logger"; | ||
| import { vi } from "vite-plus/test"; | ||
|
|
||
| const harness = vi.hoisted(() => ({ | ||
| clearOutbox: vi.fn<(environmentId: string) => Promise<void>>(), | ||
| clearDrafts: vi.fn<(environmentId: string) => Promise<void>>(), | ||
| clearComposerErrors: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("../state/thread-outbox-removal", () => ({ | ||
| clearThreadOutboxEnvironment: harness.clearOutbox, | ||
| })); | ||
| vi.mock("../state/use-composer-drafts", () => ({ | ||
| clearComposerDraftsEnvironment: harness.clearDrafts, | ||
| })); | ||
| vi.mock("../state/thread-composer-error", () => ({ | ||
| clearThreadComposerErrorsForEnvironment: harness.clearComposerErrors, | ||
| })); | ||
|
|
||
| import * as EnvironmentOwnedDataCleanup from "./environment-owned-data-cleanup"; | ||
|
|
||
| const ENVIRONMENT_ID = EnvironmentId.make("environment-1"); | ||
|
|
||
| describe("EnvironmentOwnedDataCleanup", () => { | ||
| it.effect("waits for the other clears and logs a bounded warning when one rejects", () => { | ||
| const warnings: Array<unknown> = []; | ||
| let releaseDrafts = () => {}; | ||
| let draftsCleared = false; | ||
| // The drafts clear finishes only after the outbox failure is logged. | ||
| const logger = Logger.make(({ message }) => { | ||
| warnings.push(message); | ||
| releaseDrafts(); | ||
| }); | ||
| return Effect.gen(function* () { | ||
| harness.clearOutbox.mockRejectedValue(new Error("Some queued messages could not be read.")); | ||
| harness.clearDrafts.mockImplementation(() => | ||
| new Promise<void>((resolve) => { | ||
| releaseDrafts = resolve; | ||
| }).then(() => { | ||
| draftsCleared = true; | ||
| }), | ||
| ); | ||
|
|
||
| const cleanup = yield* Persistence.EnvironmentOwnedDataCleanup; | ||
| yield* cleanup.clear(ENVIRONMENT_ID); | ||
|
|
||
| expect(draftsCleared).toBe(true); | ||
| expect(warnings).toEqual([ | ||
| [ | ||
| "Could not clear mobile environment-owned data.", | ||
| { | ||
| environmentId: ENVIRONMENT_ID, | ||
| operation: "outbox", | ||
| errorType: "error", | ||
| errorName: "Error", | ||
| stack: expect.any(String), | ||
| }, | ||
| ], | ||
| ]); | ||
| }).pipe( | ||
| Effect.provide( | ||
| Layer.merge( | ||
| EnvironmentOwnedDataCleanup.layer, | ||
| Logger.layer([logger], { mergeWithExisting: false }), | ||
| ), | ||
| ), | ||
| ); | ||
| }); | ||
| }); |
48 changes: 48 additions & 0 deletions
48
apps/mobile/src/connection/environment-owned-data-cleanup.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { safeErrorLogAttributes } from "@t3tools/client-runtime/errors"; | ||
| import { Persistence } from "@t3tools/client-runtime/platform"; | ||
| import type { EnvironmentId } from "@t3tools/contracts"; | ||
| import * as Effect from "effect/Effect"; | ||
| import * as Layer from "effect/Layer"; | ||
| import * as Schema from "effect/Schema"; | ||
|
|
||
| import { clearThreadComposerErrorsForEnvironment } from "../state/thread-composer-error"; | ||
| import { clearThreadOutboxEnvironment } from "../state/thread-outbox-removal"; | ||
| import { clearComposerDraftsEnvironment } from "../state/use-composer-drafts"; | ||
|
|
||
| class EnvironmentOwnedDataClearError extends Schema.TaggedError<EnvironmentOwnedDataClearError>()( | ||
| "EnvironmentOwnedDataClearError", | ||
| { cause: Schema.Defect() }, | ||
| ) {} | ||
|
|
||
| export const layer = Layer.succeed( | ||
| Persistence.EnvironmentOwnedDataCleanup, | ||
| Persistence.EnvironmentOwnedDataCleanup.of({ | ||
| clear: Effect.fn("Persistence.EnvironmentOwnedDataCleanup.clear")(function (environmentId) { | ||
| // Each clear settles on its own: a failure must not interrupt a clear that is still running. | ||
| const settle = ( | ||
| operation: "outbox" | "drafts", | ||
| clear: (environmentId: EnvironmentId) => Promise<void>, | ||
| ) => | ||
| Effect.tryPromise({ | ||
| try: () => clear(environmentId), | ||
| catch: (cause) => new EnvironmentOwnedDataClearError({ cause }), | ||
| }).pipe( | ||
| Effect.catch((error) => | ||
| Effect.logWarning("Could not clear mobile environment-owned data.", { | ||
| environmentId, | ||
| operation, | ||
| ...safeErrorLogAttributes(error.cause), | ||
| }), | ||
| ), | ||
| ); | ||
| return Effect.all( | ||
| [ | ||
| settle("outbox", clearThreadOutboxEnvironment), | ||
| settle("drafts", clearComposerDraftsEnvironment), | ||
| Effect.sync(() => clearThreadComposerErrorsForEnvironment(environmentId)), | ||
| ], | ||
| { concurrency: "unbounded", discard: true }, | ||
| ); | ||
| }), | ||
| }), | ||
| ); | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.