Skip to content

fix(server): fetch content variants in get_content and list_content (COD-375) - #2

Merged
shivros merged 1 commit into
mainfrom
runner/cod-375-fix-variant-retrieval
Jul 24, 2026
Merged

fix(server): fetch content variants in get_content and list_content (COD-375)#2
shivros merged 1 commit into
mainfrom
runner/cod-375-fix-variant-retrieval

Conversation

@shivros

@shivros shivros commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes COD-375

SqliteStorage::get_content() was hardcoding variants: vec![], so platform variants saved via add_variant() were never read back. This PR:

  1. get_content() — Added fetch_variants_for() helper that queries the content_variants table and deserializes rows into Vec<PlatformVariant>. Variants are ordered by formatted_at ASC for deterministic retrieval.

  2. list_content() — Added a correlated subquery (COUNT(*) from content_variants) and a new variant_count: usize field on ContentSummary so list views can show how many variants each content item has.

  3. Error handling — Parse failures on metadata JSON or formatted_at timestamps now propagate as anyhow::Result errors with context, rather than being silently masked. Corrupt DB data surfaces as an error, not silently swallowed.

Test

New test test_get_content_returns_variants:

  • Saves content, adds two variants (Twitter + LinkedIn)
  • Verifies get_content() returns both variants with correct platform, text, and metadata
  • Verifies ordering matches ORDER BY formatted_at ASC
  • Verifies list_content() reports correct variant_count
  • Verifies the no-variants edge case returns an empty vec

All 6 tests pass. cargo clippy --all-targets --all-features -- -D warnings clean. cargo fmt --check clean.

Review Notes

get_content() was hardcoding variants: vec![], discarding saved
platform variants. Added fetch_variants_for() helper to query the
content_variants table and deserialize rows into Vec<PlatformVariant>.
Also added variant_count subquery to list_content() summaries.

Test: test_get_content_returns_variants verifies round-trip for two
platforms plus the no-variants edge case.

Closes COD-375

Co-authored-by: Archon <archon@purelymail.com>
@shivros

shivros commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

🤖 Automated Review Panel

Review ran against the parent session model (model override unavailable in this run). A second reviewer was not dispatched. Findings from the single review below were addressed before PR opening.

Review Findings (glm-5.1)

Verdict: Change achieves the core goal. Three issues raised:

  1. 🔴 FIXED — unwrap_or_default() / unwrap_or_else(|_| Utc::now()) in fetch_variants_for masked corrupt DB data silently. Convention violation ("no silent error masking"). Fixed: now propagates via ? with anyhow context. Parse failures on metadata JSON or formatted_at timestamps surface as real errors.

  2. ✅ Non-issue — Platform::from_db_key() signature. Reviewer suspected it returns Result/Option. Verified: returns Platform directly (infallible). Always maps any string to a known variant or Other(String). No change needed.

  3. ✅ Non-issue — ContentSummary.variant_count breaking change. Only one construction site exists (list_content), updated in this diff.

  4. ✅ Non-issue — borrow lifetime concern. rows from stmt.query() is alive when fetch_variants_for(&conn) is called. Compiled clean — rusqlite's prepare takes &self, so shared borrows coexist.

Post-review action: Error handling in fetch_variants_for rewritten to propagate all parse errors instead of silently masking them. All tests still pass.

@shivros
shivros marked this pull request as ready for review July 24, 2026 17:55
@shivros

shivros commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

Auto-Merge Gate Approval

Confidence: 0.92
Ticket: COD-375 — Fix variant retrieval in get_content storage method

Rationale

The diff directly fulfills the stated goal: SqliteStorage::get_content() was hardcoding variants: vec![], and this PR adds a fetch_variants_for() helper that queries content_variants and deserializes rows into Vec<PlatformVariant>. list_content() gains a correlated variant_count subquery. A comprehensive test (test_get_content_returns_variants) covers multi-variant retrieval, ordering, no-variant edge case, and list-count accuracy.

Acceptance Criteria (all met)

  • get_content() returns all saved variants
  • New test test_get_content_returns_variants passes
  • cargo clippy --all-targets --all-features -- -D warnings clean (Clippy check green)
  • cargo fmt --check clean (Formatting check green)
  • cargo test all green (Tests check green)

Checks Observed (5/5 SUCCESS)

Check Status
Formatting
Clippy
Tests
Build
Secret Scanning

Scope Limits

  • 1 file changed (crates/postghost-server/src/storage.rs), +130/-5
  • No secrets, no deployment, no destructive ops, no schema migration
  • Review-panel finding (silent error masking via unwrap_or_default) was addressed before PR open — errors now propagate with anyhow context

Merge Method

Squash + delete branch.


Approved by CodeFold Auto-Merge Gate (cron ceb0befd1f30)

@shivros
shivros merged commit 0f941b4 into main Jul 24, 2026
5 checks passed
@shivros
shivros deleted the runner/cod-375-fix-variant-retrieval branch July 24, 2026 17:56
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.

1 participant