Repository navigation
feat(posters): add bounded poster collections - #175
Conversation
Co-authored-by: Copilot <[email protected]> Copilot-Session: 8453c76f-a887-4fce-be42-d7997ed94292
Co-authored-by: Copilot <[email protected]> Copilot-Session: 8453c76f-a887-4fce-be42-d7997ed94292
Co-authored-by: Copilot <[email protected]> Copilot-Session: 8453c76f-a887-4fce-be42-d7997ed94292
📝 WalkthroughWalkthroughThe CLI now retrieves a remote poster catalog and exposes ChangesPoster discovery
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant Execute
participant remote.Client
participant CollectionLogic
CLI->>Execute: posters.list or posters.search
Execute->>remote.Client: GetPosterCatalog(ctx)
remote.Client-->>Execute: PosterCatalog
Execute->>CollectionLogic: filter and paginate posters
CollectionLogic-->>Execute: posters and continuation cursor
Execute-->>CLI: collection success or failure response
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (2)
internal/app/execute_test.go (1)
660-673: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd coverage for the accepted maximum limit.
This test asserts that
--limit 101is rejected. Issue#162also requires verification of maximum-limit behavior. Add a case that asserts--limit 100succeeds and reportspage.limitas100. That case pins the inclusive upper boundary and prevents an off-by-one regression inparseCollectionOptions.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/app/execute_test.go` around lines 660 - 673, Add a test alongside TestExecutePostersListRejectsLimitAboveMaximum that executes posters list with --limit 100, asserts successful execution, and verifies the response reports page.limit as 100. Use this case to cover the inclusive upper boundary handled by parseCollectionOptions while preserving the existing rejection test for 101.internal/remote/posters.go (1)
69-72: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick winBound the catalog body read.
io.ReadAllreads the whole response into memory with no upper bound. A very large or malicious response can exhaust process memory. The body is also hashed and decoded, so the cost is multiplied. Apply a maximum size and fail closed above it.♻️ Proposed refactor
- body, err := io.ReadAll(response.Body) + body, err := io.ReadAll(io.LimitReader(response.Body, maximumCatalogBytes+1)) if err != nil { return PosterCatalog{}, fmt.Errorf("%w: response read", ErrUnavailable) } + if len(body) > maximumCatalogBytes { + return PosterCatalog{}, fmt.Errorf("%w: catalog size", ErrProtocolChanged) + }Add the constant next to
posterCatalogURL:const maximumCatalogBytes = 8 << 20🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/remote/posters.go` around lines 69 - 72, Bound the response body read in the poster catalog fetch by defining maximumCatalogBytes near posterCatalogURL and using a limited reader with io.ReadAll. Return the existing ErrUnavailable-wrapped error when the limit is exceeded or the read fails, ensuring oversized bodies fail closed before hashing or decoding.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@cmd/partiful/main.go`:
- Line 24: Replace the http.DefaultClient assigned to the poster catalog fetch
HTTP field with an HTTP client configured with an explicit request timeout,
while preserving the existing fetch behavior.
In `@internal/app/posters.go`:
- Around line 106-108: Update the option validation in the function containing
the options.all handling to reject an explicit --limit combined with --all using
the existing input.invalid failure path, rather than silently assigning
options.max to options.limit. Preserve --all behavior when no explicit limit is
provided and ensure the reported page.limit reflects the accepted request.
In `@internal/remote/posters.go`:
- Line 61: Update the deferred response body cleanup in the request flow around
response.Body.Close to explicitly discard its returned error, satisfying the
lint requirement while preserving the existing cleanup behavior.
---
Nitpick comments:
In `@internal/app/execute_test.go`:
- Around line 660-673: Add a test alongside
TestExecutePostersListRejectsLimitAboveMaximum that executes posters list with
--limit 100, asserts successful execution, and verifies the response reports
page.limit as 100. Use this case to cover the inclusive upper boundary handled
by parseCollectionOptions while preserving the existing rejection test for 101.
In `@internal/remote/posters.go`:
- Around line 69-72: Bound the response body read in the poster catalog fetch by
defining maximumCatalogBytes near posterCatalogURL and using a limited reader
with io.ReadAll. Return the existing ErrUnavailable-wrapped error when the limit
is exceeded or the read fails, ensuring oversized bodies fail closed before
hashing or decoding.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 0882d592-16d0-4d31-b837-0d68bcbf8b65
📒 Files selected for processing (6)
cmd/partiful/main.godocs/CLI-PRODUCT-CONTRACT.mdinternal/app/app.gointernal/app/execute_test.gointernal/app/posters.gointernal/remote/posters.go
| CredentialsPath: credentialsPath, | ||
| CredentialsPathError: credentialsPathError, | ||
| Now: time.Now, | ||
| HTTP: http.DefaultClient, |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Set a request timeout for the poster catalog fetch.
http.DefaultClient has no Timeout. The request context is context.Background() with no deadline. If the catalog endpoint accepts the connection and never responds, the CLI blocks indefinitely. Use a client with an explicit timeout, or derive a deadline context.
🔧 Proposed fix
- HTTP: http.DefaultClient,
+ HTTP: &http.Client{Timeout: 15 * time.Second},🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@cmd/partiful/main.go` at line 24, Replace the http.DefaultClient assigned to
the poster catalog fetch HTTP field with an HTTP client configured with an
explicit request timeout, while preserving the existing fetch behavior.
| if response == nil || response.Body == nil { | ||
| return PosterCatalog{}, fmt.Errorf("%w: missing response", ErrProtocolChanged) | ||
| } | ||
| defer response.Body.Close() |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Handle the Close error return to satisfy the lint gate.
golangci-lint reports an unchecked error for response.Body.Close. Discard the value explicitly.
🔧 Proposed fix
- defer response.Body.Close()
+ defer func() { _ = response.Body.Close() }()📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| defer response.Body.Close() | |
| defer func() { _ = response.Body.Close() }() |
🧰 Tools
🪛 golangci-lint (2.12.2)
[error] 61-61: Error return value of response.Body.Close is not checked
(errcheck)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/remote/posters.go` at line 61, Update the deferred response body
cleanup in the request flow around response.Body.Close to explicitly discard its
returned error, satisfying the lint requirement while preserving the existing
cleanup behavior.
Source: Linters/SAST tools
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b0a2f4544e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| CredentialsPath: credentialsPath, | ||
| CredentialsPathError: credentialsPathError, | ||
| Now: time.Now, | ||
| HTTP: http.DefaultClient, |
There was a problem hiding this comment.
Add a timeout to poster HTTP requests
When posters list or posters search reaches a network that accepts the connection but stalls, this uses http.DefaultClient with Timeout == 0 while Execute is called with context.Background(), so the CLI can hang indefinitely instead of producing the documented remote.unavailable failure. Use a bounded client or deadline for the poster catalog request so these read-only commands reliably return.
Useful? React with 👍 / 👎.
Co-authored-by: Copilot <[email protected]> Copilot-Session: 8453c76f-a887-4fce-be42-d7997ed94292
Co-authored-by: Copilot <[email protected]> Copilot-Session: 8453c76f-a887-4fce-be42-d7997ed94292
Co-authored-by: Copilot <[email protected]> Copilot-Session: 8453c76f-a887-4fce-be42-d7997ed94292
Co-authored-by: Copilot <[email protected]> Copilot-Session: 8453c76f-a887-4fce-be42-d7997ed94292
|
Implementation review cycle 1 fixes are pushed:
Validation: targeted/full Go tests and vet passed; contract tests 15/15; typecheck passed; Pacific Node suite 336 passed/6 skipped; diff and PII/secret checks passed. |
Co-authored-by: Copilot <[email protected]> Copilot-Session: 8453c76f-a887-4fce-be42-d7997ed94292
Co-authored-by: Copilot <[email protected]> Copilot-Session: 8453c76f-a887-4fce-be42-d7997ed94292
Co-authored-by: Copilot <[email protected]> Copilot-Session: 8453c76f-a887-4fce-be42-d7997ed94292
Co-authored-by: Copilot <[email protected]> Copilot-Session: 8453c76f-a887-4fce-be42-d7997ed94292
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/app/cursor_key.go`:
- Around line 73-83: After the successful os.Link path in the cursor key
publishing flow, synchronize the parent directory before returning the key so
the directory entry is durable. Add this as a platform-specific helper and
invoke it from the relevant cursor-key function, propagating any sync error;
leave the existing os.ErrExist/read-and-validate path unchanged.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: f788a2a4-e568-4d7d-8a8c-7420e6e7eb77
📒 Files selected for processing (8)
cmd/partiful/main.godocs/CLI-PRODUCT-CONTRACT.mdinternal/app/app.gointernal/app/cursor_key.gointernal/app/execute_test.gointernal/app/posters.gointernal/remote/http.gointernal/remote/posters.go
🚧 Files skipped from review as they are similar to previous changes (4)
- internal/remote/posters.go
- docs/CLI-PRODUCT-CONTRACT.md
- internal/app/execute_test.go
- internal/app/app.go
| if err := os.Link(temporaryPath, provider.Path); err != nil { | ||
| if !errors.Is(err, os.ErrExist) { | ||
| return nil, err | ||
| } | ||
| existing, readErr := os.ReadFile(provider.Path) | ||
| if readErr != nil { | ||
| return nil, readErr | ||
| } | ||
| return validateCursorKey(existing) | ||
| } | ||
| return append([]byte(nil), key...), nil |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
ast-grep outline internal/app/cursor_key.go --items all
fd -HI -t f . | rg '(^|/)(go\.mod|.*\.(yml|yaml))$' |
while IFS= read -r file; do
rg -n -i 'GOOS|windows|darwin|ubuntu|macos|runs-on' "$file" || true
doneRepository: KalebCole/partiful-cli
Length of output: 635
🏁 Script executed:
set -euo pipefail
cat -n internal/app/cursor_key.go
printf '\n--- go.mod ---\n'
cat go.mod
printf '\n--- workflow/platform references ---\n'
fd -HI -t f . | rg '(^|/)(go\.mod|.*\.(yml|yaml))$' |
while IFS= read -r file; do
printf '\n[%s]\n' "$file"
rg -n -i 'GOOS|windows|darwin|linux|ubuntu|macos|runs-on|build' "$file" || true
done
printf '\n--- cursor key references ---\n'
rg -n 'FileCursorKeyProvider|DefaultCursorKeyPath|cursor\.key|syncCursorKeyDirectory|os\.Link|temporary\.Sync' .Repository: KalebCole/partiful-cli
Length of output: 3867
🏁 Script executed:
set -euo pipefail
printf '%s\n' '--- application startup and cursor use ---'
cat -n cmd/partiful/main.go
rg -n -C 4 'CursorKey|cursor key|cursor_key|cursor' --glob '*.go' --glob '*.md' .
printf '%s\n' '--- project metadata and documentation ---'
fd -HI -t f . | rg '(^|/)(README[^/]*|CONTRIBUTING[^/]*|Makefile|Dockerfile|.*\.(yml|yaml|md))$' |
while IFS= read -r file; do
printf '\n[%s]\n' "$file"
rg -n -i 'windows|darwin|macos|linux|supported|platform|install|build|release' "$file" || true
doneRepository: KalebCole/partiful-cli
Length of output: 50380
🌐 Web query:
Go os.File.Sync directory fsync os.Link crash durability official documentation
💡 Result:
In Go, os.File.Sync commits the current contents of a file to stable storage by flushing the file system's in-memory copy of data to disk [1][2]. However, calling Sync on a file only ensures that the file's data and metadata are persistent; it does not guarantee that the directory entry (the mapping from a filename to the file's inode) is persisted [3][4]. To ensure that operations affecting directory structure—such as file creation, renaming (os.Rename), or hard-linking (os.Link)—are crash-durable, you must also call Sync on the parent directory [3][4][5]. Without an explicit fsync on the directory, a system crash or power loss shortly after a file operation may result in a state where the file data is on disk, but the filename does not exist, or points to an incorrect or empty inode [3][5]. The Go standard library's os.File.Sync method can be used on a directory file descriptor to perform this operation [3][4]. On POSIX-compliant systems, you can achieve this by opening the directory using os.OpenFile with specific flags (e.g., os.O_RDONLY) and calling Sync on the resulting *os.File [3][4]. Because Go does not provide a specialized high-level method specifically for directory syncing, you must manage the directory file descriptor and its lifecycle manually [4]. Key durability considerations: - File Creation/Rename/Link: Always sync the parent directory after these operations to make the name-to-inode mapping persistent [3][4][5]. - Data Writes: Calling Sync on the file descriptor of the file itself is sufficient for the data contents [3][4]. - Atomicity: While os.Rename is generally atomic in terms of visibility, it is not durable without a subsequent directory sync [6][5]. - Platform differences: Note that specific file systems or operating systems may have nuances regarding how they handle metadata flushing, but the practice of syncing the parent directory is a standard requirement for crash durability on Unix-like systems [4][7].
Citations:
- 1: https://pkg.go.dev/os
- 2: https://pkg.go.dev/[email protected]
- 3: https://aalhour.com/posts/beachdb-the-syscall-i-forgot/
- 4: https://trialofcode.org/database/0104_fsync/
- 5: openshift/library-go@2b0e2f3
- 6: Question: fsync on file and/or directory google/renameio#11
- 7: https://stackoverflow.com/questions/60369291/os-link-vs-os-rename-vs-os-replace-for-writing-atomic-write-files-what
🌐 Web query:
POSIX fsync directory link persistence crash official documentation
💡 Result:
Under the POSIX standard, calling fsync on a file descriptor does not guarantee that directory entries (such as those created by rename, link, symlink, or open with O_CREAT) are synchronized to permanent storage [1][2]. The POSIX specification for fsync focuses on synchronizing data associated with a specific file descriptor [3][4]. Because directory entries are stored in directory files—which are logically separate from the files they point to—an fsync call on a file does not implicitly trigger an update of the parent directory's metadata [5][1]. If the system crashes after an fsync on a file but before the associated directory entry is persisted, the file data may be on disk, but the file may remain unreachable or "lost" because the filesystem cannot resolve the name to the inode [5]. To ensure that file system operations like creation, renaming, or linking are persisted, the application must explicitly call fsync (or fdatasync) on a file descriptor opened for the containing directory [1][2]. While POSIX is historically silent on the explicit behavior of calling fsync on a directory file descriptor, it is widely recognized as the required mechanism in practice to guarantee that directory entry modifications reach non-volatile storage [6][1][7]. Applications requiring strict crash consistency for metadata changes (e.g., ensuring a new file exists after a power failure) should perform this explicit synchronization on the parent directory [1][4][8]. Top Results: [1], [3], [4], [2]
Citations:
- 1: https://www.austingroupbugs.net/view.php?id=672
- 2: https://www.man7.org/linux/man-pages/man2/fsync.2.html
- 3: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fsync.html
- 4: https://pubs.opengroup.org/onlinepubs/9799919799/functions/fsync.html
- 5: https://unix.stackexchange.com/questions/414749/how-does-fsync-treat-directory-links
- 6: https://www.spinics.net/lists/fstests/msg09372.html
- 7: https://lkml.indiana.edu/hypermail/linux/kernel/9603.1/0682.html
- 8: https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/fdatasync.html
Synchronize the parent directory after publishing cursor.key.
temporary.Sync() does not persist the directory entry created by os.Link. A crash can remove cursor.key after Key returns successfully. The next invocation can generate a new key and invalidate previously issued cursors. Add a platform-specific parent-directory sync after a successful link.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/app/cursor_key.go` around lines 73 - 83, After the successful
os.Link path in the cursor key publishing flow, synchronize the parent directory
before returning the key so the directory entry is durable. Add this as a
platform-specific helper and invoke it from the relevant cursor-key function,
propagating any sync error; leave the existing os.ErrExist/read-and-validate
path unchanged.
Summary
posters listand case-insensitiveposters search --querybehind the existing typed application command cataloginternal/remoteHTTP adapter for the public poster catalog only; no auth, callable, Firestore, Firebase, or upload surface is introduced--limit/--cursorpagination and bounded--all --max-itemscollection output2026-08-11.1Safety and protocol behavior
application/jsonand the reviewed body shape succeedsremote.unavailable(exit 8)contract.protocol_changed(exit 9)input.invalid; changed payloads returnstate.conflictTDD
Added one
app.Executeend-to-end tracer at a time using only a scripted HTTP adapter at the true external seam. RED→GREEN cycles covered first-page mapping, limit/cursor generation, exact resume, search order, bounded--all, changed payloads, schema projection, content type, malformed cursors, filter binding, network/non-200/malformed-body failures, optional schema fields, and input bounds.Validation
go test ./...— passedgo vet ./...— passednpm test -- tests/remote-api-contract.test.js— 15 passednpm run typecheck— passedTZ=America/Los_Angeles npm test— 336 passed, 6 skippedgit diff --check 115434a176740e57047465a4e67b2a39984fee0c..HEAD— passedBase:
115434a176740e57047465a4e67b2a39984fee0c(merged contract PR #174).Closes #162
Summary by CodeRabbit
New Features
Bug Fixes
Documentation