Skip to content

Generate more unique names for new book folders (BL-15608)#7683

Open
JohnThomson wants to merge 4 commits intomasterfrom
uniqueBookNames
Open

Generate more unique names for new book folders (BL-15608)#7683
JohnThomson wants to merge 4 commits intomasterfrom
uniqueBookNames

Conversation

@JohnThomson
Copy link
Contributor

@JohnThomson JohnThomson commented Feb 11, 2026


Open with Devin

This change is Reviewable

Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

View 4 additional findings in Devin Review.

Open in Devin Review

Copy link
Contributor Author

@JohnThomson JohnThomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JohnThomson made 3 comments.
Reviewable status: 0 of 4 files reviewed, 3 unresolved discussions (waiting on @andrew-polk).

Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 4 new potential issues.

View 6 additional findings in Devin Review.

Open in Devin Review

Copy link
Contributor Author

@JohnThomson JohnThomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JohnThomson made 2 comments.
Reviewable status: 0 of 4 files reviewed, 5 unresolved discussions (waiting on @andrew-polk).

Copy link
Contributor

@andrew-polk andrew-polk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrew-polk reviewed all commit messages and resolved 1 discussion.
Reviewable status: 0 of 4 files reviewed, 3 unresolved discussions (waiting on @JohnThomson).

Copy link
Contributor Author

@JohnThomson JohnThomson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JohnThomson made 4 comments.
Reviewable status: 0 of 4 files reviewed, 5 unresolved discussions (waiting on @andrew-polk).


src/BloomTests/Book/BookStorageTests.cs line 210 at r4 (raw file):

        [Test]
        public void MoveBookToSafeName_NameNotNFC_NewNameConflicts_Moves()

This test (in addition to the one above) is not useful any more; name conflicts are vanishingly unlikely and hard to simulate.


src/BloomTests/Book/BookStorageTests.cs line 1136 at r4 (raw file):

        [Test]
        public void SetBookName_FolderWithSanitizedNameAlreadyExists_AddsANumberToName()

This seems to be doing the same thing as the previous test, at least now that a conflict is so unlikely.

Copy link

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 new potential issues.

View 9 additional findings in Devin Review.

Open in Devin Review

Comment on lines 200 to 209

var expectedFolder = bookFolder.Replace("e\x0301", "\x00e9");

Assert.That(BookStorage.MoveBookToSafeName(bookFolder), Is.EqualTo(expectedFolder));
Assert.That(Directory.Exists(expectedFolder));
var expectedBookPath = bookPath.Replace("e\x0301", "\x00e9");
Assert.That(File.ReadAllText(expectedBookPath), Is.EqualTo("this is a test"));
}

[Test]
public void MoveBookToSafeName_NameNotNFC_NewNameConflicts_Moves()
{
var oldName = "Some nice\x0301 book";
var bookFolder = Path.Combine(_fixtureFolder.Path, oldName);
Directory.CreateDirectory(bookFolder);
var bookPath = Path.Combine(bookFolder, oldName + ".htm");
File.WriteAllText(bookPath, "this is a test");

var desiredFolder = bookFolder.Replace("e\x0301", "\x00e9");
Directory.CreateDirectory(desiredFolder);
var expectedFolder = desiredFolder + " 2";

Assert.That(BookStorage.MoveBookToSafeName(bookFolder), Is.EqualTo(expectedFolder));
Assert.That(Directory.Exists(expectedFolder));
var expectedBookPath = Path.Combine(
expectedFolder,
Path.GetFileName(expectedFolder) + ".htm"
);
// Typically we added hyphen and a guid. Not sure if that's good.
var result = BookStorage.MoveBookToSafeName(bookFolder);
Assert.That(result, Does.StartWith(expectedFolder));
Assert.That(Directory.Exists(result));
var expectedBookPath = Path.Combine(result, Path.GetFileName(result) + ".htm");
Assert.That(File.ReadAllText(expectedBookPath), Is.EqualTo("this is a test"));
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 Deleted test MoveBookToSafeName_NameNotNFC_NewNameConflicts_Moves reduces coverage

The test MoveBookToSafeName_NameNotNFC_NewNameConflicts_Moves (old lines 209-228) was deleted entirely rather than updated. This test specifically validated the case where the sanitized name conflicts with an existing folder. With the new always-add-GUID behavior, conflict is extremely unlikely, but the test still provided value in verifying that the conflict-resolution loop in GetUniqueBookFolderName works. Consider adding a unit test for GetUniqueBookFolderName directly that validates collision handling (where the first proposed name already exists as a directory).

(Refers to lines 192-209)

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JohnThomson can you answer this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the code generates a new guid, there's no straightforward way to pre-arrange a conflict. We'd have to somehow reorganize the code so that the guid to use can be fed in. And then we are NOT really taking the same code path as when the 1 in 4 billion chance comes off and we get a conflict. I decided trying to test this corner was not a good use of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments