Repository navigation
fix(web): do not reuse archived thread ids as new drafts #7183
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
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
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
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,35 @@ | ||
| import type { ScopedThreadRef } from "@t3tools/contracts"; | ||
|
|
||
| export type StoredDraftReuseDecision = "reuse" | "mint"; | ||
|
|
||
| /** | ||
| * Decide whether a project's stored new-thread draft can keep its thread id. | ||
| * | ||
| * An id that already exists in any lifecycle (live, archived, deleted) is | ||
| * burned. Promoted/sent drafts are never reused, even when both snapshots miss | ||
| * them. An unloaded archive snapshot is unknown, not absent. | ||
| */ | ||
| export function decideStoredDraftReuse(input: { | ||
| readonly storedDraftThreadRef: ScopedThreadRef | null; | ||
| readonly liveShellExists: boolean; | ||
| readonly archivedShellExists: boolean | null; | ||
| readonly deletedShellExists?: boolean | null; | ||
| readonly promoted: boolean; | ||
| }): StoredDraftReuseDecision { | ||
| if (input.storedDraftThreadRef === null) { | ||
| return "mint"; | ||
| } | ||
| if (input.liveShellExists) { | ||
| return "mint"; | ||
| } | ||
| if (input.archivedShellExists === true) { | ||
| return "mint"; | ||
| } | ||
| if (input.deletedShellExists === true) { | ||
| return "mint"; | ||
| } | ||
| if (input.promoted) { | ||
| return "mint"; | ||
| } | ||
| return "reuse"; | ||
| } |
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,104 @@ | ||
| import { EnvironmentId, ThreadId } from "@t3tools/contracts"; | ||
| import { scopeThreadRef } from "@t3tools/client-runtime/environment"; | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import { decideStoredDraftReuse } from "./useHandleNewThread.logic"; | ||
|
|
||
| const storedDraftThreadRef = scopeThreadRef( | ||
| EnvironmentId.make("environment-1"), | ||
| ThreadId.make("thread-1"), | ||
| ); | ||
|
|
||
| describe("decideStoredDraftReuse", () => { | ||
| it("mints a new draft when the stored id is still a live shell", () => { | ||
| expect( | ||
| decideStoredDraftReuse({ | ||
| storedDraftThreadRef, | ||
| liveShellExists: true, | ||
| archivedShellExists: false, | ||
| promoted: false, | ||
| }), | ||
| ).toBe("mint"); | ||
| }); | ||
|
|
||
| it("mints a new draft when the stored id is only in archived shells", () => { | ||
| expect( | ||
| decideStoredDraftReuse({ | ||
| storedDraftThreadRef, | ||
| liveShellExists: false, | ||
| archivedShellExists: true, | ||
| promoted: false, | ||
| }), | ||
| ).toBe("mint"); | ||
| }); | ||
|
|
||
| it("reuses an empty draft when the stored id is unknown and not promoted", () => { | ||
| expect( | ||
| decideStoredDraftReuse({ | ||
| storedDraftThreadRef, | ||
| liveShellExists: false, | ||
| archivedShellExists: false, | ||
| deletedShellExists: false, | ||
| promoted: false, | ||
| }), | ||
| ).toBe("reuse"); | ||
| }); | ||
|
|
||
| it("mints a new draft when a promoted id is missing from both snapshots", () => { | ||
| expect( | ||
| decideStoredDraftReuse({ | ||
| storedDraftThreadRef, | ||
| liveShellExists: false, | ||
| archivedShellExists: null, | ||
| deletedShellExists: null, | ||
| promoted: true, | ||
| }), | ||
| ).toBe("mint"); | ||
| }); | ||
|
|
||
| it("mints a new draft when a previously promoted id later disappears after delete", () => { | ||
| expect( | ||
| decideStoredDraftReuse({ | ||
| storedDraftThreadRef, | ||
| liveShellExists: false, | ||
| archivedShellExists: false, | ||
| deletedShellExists: false, | ||
| promoted: true, | ||
| }), | ||
| ).toBe("mint"); | ||
| }); | ||
|
|
||
| it("mints a new draft when the stored id is visible as deleted", () => { | ||
| expect( | ||
| decideStoredDraftReuse({ | ||
| storedDraftThreadRef, | ||
| liveShellExists: false, | ||
| archivedShellExists: false, | ||
| deletedShellExists: true, | ||
| promoted: false, | ||
| }), | ||
| ).toBe("mint"); | ||
| }); | ||
|
|
||
| it("reuses an unpromoted draft when the archived snapshot is not loaded", () => { | ||
| expect( | ||
| decideStoredDraftReuse({ | ||
| storedDraftThreadRef, | ||
| liveShellExists: false, | ||
| archivedShellExists: null, | ||
| promoted: false, | ||
| }), | ||
| ).toBe("reuse"); | ||
| }); | ||
|
|
||
| it("mints a new draft when there is no stored draft to reuse", () => { | ||
| expect( | ||
| decideStoredDraftReuse({ | ||
| storedDraftThreadRef: null, | ||
| liveShellExists: false, | ||
| archivedShellExists: null, | ||
| promoted: false, | ||
| }), | ||
| ).toBe("mint"); | ||
| }); | ||
| }); |
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.
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.