Skip to content

refactor: rename "works" to "titles" across codebase#1043

Merged
fshowalter merged 1 commit intomainfrom
draft
Mar 22, 2026
Merged

refactor: rename "works" to "titles" across codebase#1043
fshowalter merged 1 commit intomainfrom
draft

Conversation

@fshowalter
Copy link
Copy Markdown
Owner

No description provided.

@claude
Copy link
Copy Markdown

claude bot commented Mar 22, 2026

Claude finished @fshowalter's task in 2m 49s —— View job


PR Review: refactor: rename "works" to "titles" across codebase

  • Gather context and analyze PR changes
  • Review key source files for code quality
  • Check for bugs, regressions, or incomplete renames
  • Assess test coverage
  • Post final review

Summary

This is a large but straightforward rename refactor — "works" → "titles" across the entire codebase (Python source, tests, reading markdown files, and JSON data files). The rename is thorough and internally consistent. Below are the findings.


Issues Found

1. Orphaned snapshot directory not cleaned up

tests/cli/__snapshots__/test_add_work/ still exists with an old test_can_create_work.json snapshot using the old schema (slug for authors, includedWorks):

{
  "authors": [{ "notes": null, "slug": "richard-laymon" }],
  "includedWorks": [],
  ...
}

The test file was renamed to test_add_title.py and its corresponding snapshot is now at tests/repository/__snapshots__/test_api/test_create_title.json, but the old test_add_work/ directory was never deleted. This is dead/orphaned test data.

Fix this →

2. reviewed field silently removed from JsonMostReadAuthor (breaking JSON output change)

In booklog/exports/stats.py, the JsonMostReadAuthor TypedDict had three fields renamed/removed:

Before After
slug: str | None authorSlug: str | None
reviewed: bool (removed)
readWorks: list[...] readTitles: list[...]

The reviewed field was dropped entirely. While reviewed was derivable from authorSlug is not None, this is still a breaking schema change for any downstream consumers of the exported stats JSON. Worth calling out explicitly if intentional.

3. Naming inconsistency: author_slug vs id in title author representation

In booklog/repository/json_titles.py, JsonTitleAuthor uses id as the field name for what is semantically an author slug:

class JsonTitleAuthor(TypedDict):
    id: str        # ← this stores an author slug
    notes: str | None

But TitleAuthor in repository/api.py uses author_slug:

@dataclass
class TitleAuthor:
    notes: str | None
    author_slug: str   # ← same value, different name

The JSON data on disk also uses "id". This works correctly, but the "id" naming is slightly surprising — it was previously "slug", which was more descriptive. A name like "authorSlug" or keeping "slug" would be more self-documenting.

4. None subtitle produces ": None" in search string

In booklog/cli/select_title.py:38, when subtitle is None:

lambda title: query.lower() in f"{title.title}: {title.subtitle}".lower()

This produces "title: none". This existed in the original select_work.py too, so it's not a regression introduced by this PR — but worth noting.


What's Done Well

  • Complete rename: All Python files, test files, snapshot files, reading markdown files, and JSON data files are consistently updated. No workSlug, work_authors, includedWorks, json_works, select_work, or add_work references remain in the codebase.
  • Data migration: The 80+ reading markdown files have been updated from workSlug: to titleId:, and the titles JSON files from "slug" to "id" for authors and "includedWorks" to "includedTitles".
  • Tests updated: All tests and their fixtures are consistently renamed, including the syrupy snapshot for the reading YAML format change.
  • No logic changes: This is purely a rename — no behavioral changes are introduced.

Minor Notes

  • The Reading.titleId field uses camelCase (matching the YAML/markdown format) while most other Reading fields also use camelCase (editionNotes, etc.) — consistent with existing style.
  • The select_title.prompt() radio list title changed from "Select work:" to "Select title:" — good UX improvement.

@fshowalter fshowalter merged commit adc4092 into main Mar 22, 2026
7 checks passed
@fshowalter fshowalter deleted the draft branch March 22, 2026 15:49
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