Skip to content

Enhance hn: real README, full test suite, entity decoding, least-privilege docs CI - #1

Merged
tamnd merged 6 commits into
mainfrom
enhance-quality-and-tests
Jun 14, 2026
Merged

tamnd merged 6 commits into
mainfrom
enhance-quality-and-tests

Conversation

@tamnd

@tamnd tamnd commented Jun 14, 2026

Copy link
Copy Markdown
Owner

First pass of the *-cli quality review, with hackernews-cli as the pilot.

Library

  • Decode every HTML entity in text fields with html.UnescapeString. Comment and story bodies were leaking raw entities, so URLs came out as https:&#x2F;&#x2F;example.com. <p> now becomes a paragraph break instead of being dropped.
  • Add a Change record and Updates.Changes() so the updates firehose flattens into the same flat records as every other surface.
  • Make the Firebase and Algolia base URLs fields on Client so tests can point them at an httptest server. No public API change.
  • Stop echoing a story's own id back as story_id on story search hits; comment hits still carry the parent thread's id and title.

CLI

  • updates now renders structured records in any output format and honors -n.

Tests

  • httptest-backed client tests: rank order, deleted items dropped, comment-tree flatten and depth, not-found mapping, Algolia filter building and endpoint selection, retry/no-retry by status.
  • Table-driven tests for entity decoding and the record conversions.
  • Renderer across all seven formats with --fields, --no-header, --template.
  • Cobra layer for exit-code mapping and flag wiring.
  • Coverage: hackernews 91.6%, pkg/render 81%.

Docs and CI

  • Real README: full command surface, output formats with worked examples from real runs, search filters, exit-code table.
  • Least privilege for the docs workflow: read-only token by default, pages:write + id-token:write only on the Pages deploy job. The build job and the Cloudflare job (which handles the API secret) never hold a write token. The minimum Cloudflare API token scope is documented next to the secret.

Verification

  • gofmt, go vet, go test ./..., golangci-lint run all clean.
  • Ran the full command suite live on macOS (top/best/new/ask/show/jobs/item/user/search/updates/maxitem) across table/jsonl/url/csv.

Tagging v0.1.1 follows once this merges.

tamnd added 6 commits June 14, 2026 08:44
The text fields carried raw HTML entities straight from HN, so URLs in
comment and story bodies came out as https:&#x2F;&#x2F;example.com. Switch
stripTags to html.UnescapeString, which covers the numeric and hex forms HN
leans on, and turn <p> into a paragraph break instead of dropping it.

Add a Change record and Updates.Changes() so the updates firehose flattens
into the same flat records every other surface emits, and make the two API
base URLs fields on Client so tests can point them at an httptest server.
Modernize a couple of min() clamps along the way and stop echoing a story's
own id back as story_id on story search hits.
updates printed nothing reusable before. Flatten it through Updates.Changes()
so it renders in any output format like the rest of the commands, and let -n
cap the firehose the way it caps the story lists.
httptest-backed tests for the Firebase and Algolia paths (rank order, deleted
items dropped, comment-tree flatten and depth, not-found mapping, Algolia
filter building and endpoint selection), table-driven tests for the entity
decoding and record conversions, the renderer across all seven formats with
--fields/--no-header/--template, and the cobra layer for exit-code mapping and
flag wiring.
Replace the scaffold stub with the actual command surface, the output formats
with worked examples, the search filters, the exit-code table, and the layout.
The example output is from real runs.
The token was write-capable for every job. Make it read-only by default and
grant pages:write and id-token:write only to the Pages deploy job, so the
build job and the Cloudflare job (which handles the API secret) never hold a
write token. Document the minimum Cloudflare API token scope next to where the
secret is used.
One script to enable Pages in workflow mode and set the Cloudflare secrets on
a fresh repo.
@tamnd
tamnd merged commit 571c2ff into main Jun 14, 2026
7 checks passed
@tamnd
tamnd deleted the enhance-quality-and-tests branch June 14, 2026 01:46
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