Harden ListBooks() against external mutation by returning a defensive copy#1
Merged
Merged
Conversation
Agent-Logs-Url: https://github.com/askrinnik/copilot-cli-for-beginners/sessions/7632c3ba-c9f3-445a-a1f6-28ef05710051 Co-authored-by: askrinnik <1359187+askrinnik@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement second to do item for BookApp
Harden May 14, 2026
ListBooks() against external mutation by returning a defensive copy
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This addresses todo github#2 from the C# BookApp review:
BookCollection.ListBooks()exposed internal mutable state by returning the backing_bookslist directly. The change isolates internal collection state while keeping the public API shape intact.Service behavior change
BookCollection.ListBooks()to return a defensive copy rather than the internal list.BookCollectionstate via operations on the returned list.Coverage for regression risk
BookCollection.Books.Original prompt
Would you implement the second to do item?
Chronological Review: 1. User asked about BookApp.csproj → explained .NET project config 2. User asked for code quality review → 8-10 issues identified across bugs/design/test gaps 3. User asked to create numbered checklist → saved to markdown, inserted into SQL todos 4. User asked to implement todo #1 (HandleRemove bool) → fixed Program.cs, committed (95d9cdb) 5. User asked about test for fix → confirmed existing tests covered the service layer 6. User reported "The Hobbit" search bug → debugged: find command only searches by author, FindByAuthor uses exact match 7. User asked to implement Test Coverage Gap todos (github#8-10) → added 12 tests, all 17 pass, committed (a292527) 8. User asked to update todo checklist → marked 4 items done in markdown 9. User asked how to run tests → provided dotnet test command 10. User asked to push to master → failed (wrong branch name) 11. Discovered branch is "main" → tried push origin main → failed (403, no write access to upstream) 12. User fixed remote URL to their fork → push succeeded to askrinnik/copilot-cli-for-beginnersIntent Mapping:
Technical Inventory:
Recent Commands:
Progress: 4/10 todos done, 6 pending. Two commits pushed to fork.
1. Conversation Overview: - Primary Objectives: Code quality review of `samples/book-app-project-cs/` C# BookApp → create numbered issue checklist → implement fixes incrementally → commit and push to remote - Session Context: Educational repo (`github/copilot-cli-for-beginners`). Full pipeline completed: review → SQL todo tracking → markdown checklist → fix implementation → tests → commits → push to fork - User Intent Evolution: Started with passive review, progressed to active bug fixing and test writing, ended with git push workflow including fork resolution-
- .NET 10 / C#: Target framework
- xUnit: Test framework in
- Git: Two commits on
- SQL todos table: 10 items total; 4 done, 6 pending; used to track issue progress
- Conventional Commits: Pattern
-
- Purpose: CLI entry point; handles
- Current State: Fixed
- Known Issue:
- Purpose: Core service: load/save
- Current State: Unmodified; several pending issues
- Key Issues:
- Purpose: xUnit tests for BookCollection service
- Current State: 12 new tests added (commit a292527); 17 total, all passing
- Coverage Added: FindByAuthor (exact, case-insensitive, multi-book, unknown), persistence round-trip via new BookCollection instance, edge cases (empty title, empty author, duplicate titles)
- Purpose: Simple POCO model
- Current State: Unmodified; mutable setters on Title/Author/Year (todo docs: improve /fleet command description and add tip in Ch07 github/copilot-cli-for-beginners#7 pending)
- Purpose: Sample data loaded at startup
- Current State: Contains "Mysterious Book" entry with empty author and year=0 (todo Add license section to README github/copilot-cli-for-beginners#3 pending)
- Purpose: Numbered 10-item checklist with severity tiers
- Current State: Items 1, 8, 9, 10 marked
-
- Issues Encountered:
- `HandleRe...
Technical Foundation:
net10.0, nullable enabled, console appTests/BookApp.Tests.csproj; 17 tests all passingmainbranch; upstream isgithub/copilot-cli-for-beginners(no write access); fork ataskrinnik/copilot-cli-for-beginners(write access confirmed)fix(book-app-cs):/test(book-app-cs):Codebase Status:
samples/book-app-project-cs/Program.cs:list,add,remove,find,helpcommandsHandleRemove(commit 95d9cdb) to store bool return fromRemoveBook()and display correct success/not-found messagesHandleFind(lines 70–77) only searches by author, not title — "The Hobbit" search returns empty because it's a titlesamples/book-app-project-cs/Services/BookCollection.cs:data.json, AddBook, RemoveBook, FindByAuthor, MarkAsReadListBooks()returns mutable internal list (todo Configure Dependabot for pip and nuget updates github/copilot-cli-for-beginners#2);FindByAuthoruses exact.Equals()not.Contains()(partial match bug);SaveBooks()has no exception handling (todo Add contributing guidelines to CONTRIBUTING.md github/copilot-cli-for-beginners#4)samples/book-app-project-cs/Tests/BookCollectionTests.cs:samples/book-app-project-cs/Models/Book.cs:samples/book-app-project-cs/data.json:bookapp-cs-issues.md(session artifact in~/.copilot/session-state/.../files/):[x]done; 6 remaining openProblem Resolution:
Created from Copilot CLI via the copilot delegate command.