Skip to content

Add tests for base64 and component-title utils#848

Merged
bdraco merged 1 commit into
esphome:mainfrom
esphbot:koan/test-base64-component-title
Jun 15, 2026
Merged

Add tests for base64 and component-title utils#848
bdraco merged 1 commit into
esphome:mainfrom
esphbot:koan/test-base64-component-title

Conversation

@esphbot

@esphbot esphbot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

What does this implement/fix?

Adds unit tests for the two remaining genuinely-untested pure utils:
arrayBufferToBase64 (src/util/base64.ts) and
stripRedundantComponentSuffix (src/util/component-title.ts). Both ship
behaviour with non-obvious edges and had zero coverage.

  • arrayBufferToBase64 chunks at 0x8000 and joins once to stay linear — the
    chunk seam is exactly the kind of thing a refactor can silently break. Tests
    cover a known vector (fooZm9v), the empty buffer, a full 0-255 byte
    round-trip, and round-trips both across and exactly on the 0x8000 boundary.
  • stripRedundantComponentSuffix has an empty-result guard (" Component"
    original, not "") and is intentionally anchored + case-sensitive. Tests
    cover suffix trimming, the empty-result guard, anchored-at-end matching, and
    case sensitivity. The util is purely textual (the core-only policy lives in
    the caller), so "Copy Component" is still trimmed here.

Related issue or feature (if applicable):

  • N/A

Types of changes

  • Bugfix (non-breaking change which fixes an issue) — bugfix
  • New feature (non-breaking change which adds functionality) — new-feature
  • Enhancement to an existing feature — enhancement
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) — breaking-change
  • Refactor (no behaviour change) — refactor
  • Documentation only — docs
  • Maintenance / chore — maintenance
  • CI / workflow change — ci
  • Dependencies bump — dependencies

Checklist

  • The code change is tested and works locally.
  • npm run lint passes.
  • npm run test passes.
  • Tests have been added to verify that the new code works (where applicable).

@bdraco bdraco left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You must use the pr template, do not mangle it

@bdraco

bdraco commented Jun 15, 2026

Copy link
Copy Markdown
Member

@esphbot rr

@esphbot

esphbot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

PR Review — Add tests for base64 and component-title utils

Tests are correct and well-targeted; the blocker is the PR body, not the code.

The two test files are accurate against their sources. arrayBufferToBase64 chunks at 0x8000 and the suite deliberately exercises both a buffer crossing the seam (0x8000 + 5) and one landing exactly on a multiple (0x8000 * 2) — the right edges for a chunked encoder. stripRedundantComponentSuffix coverage matches the regex / (Component|Configuration)$/ exactly: the " Component" -> " Component" empty-result guard, the leading-space requirement, anchored-at-end, and case sensitivity are all real edges of that one-liner. The "Copy Component" case correctly documents that the util is purely textual and the core-only policy lives in the caller. btoa/atob are global in the Node vitest env, so the round-trips run fine.

  • BLOCKING: @bdraco requested changes — "use the pr template, do not mangle it." The description uses ad-hoc What/Why/How/Testing headers instead of .github/PULL_REQUEST_TEMPLATE.md (which expects "What does this implement/fix?", the related-issue block, the Types-of-changes list, and the Checklist). CI derives the label from the ticked Types-of-changes box; tick exactly one ("Maintenance / chore"). Rewrite the body on the template before re-requesting review.
  • Quality report shows "Tests: failed (18 failed, 0 test)" — this matches the known @replit/codemirror-indentation-markers install drift on this workspace (whole suite fails to run), not a fault in these files. Confirm the two new files pass in clean CI; the local 13-passed claim is consistent with that.
  • No correctness, security, or coverage issues in the added tests.


Checklist

  • Tests match source behavior
  • Edge cases covered (empty, boundary, case sensitivity)
  • No hardcoded secrets
  • Test isolation (no shared/order-dependent state)
  • PR follows template / passes maintainer review — summary blocker

Automated review by Kōan (Claude) HEAD=a8a2e79 49s

Cover the two remaining genuinely-untested pure utils:

- arrayBufferToBase64: known vector, empty buffer, full 0-255 byte
  range, and round-trips across and on the 0x8000 chunk boundary
  (the seam the chunked join exists to get right).
- stripRedundantComponentSuffix: ' Component'/' Configuration' tail
  trimming, anchored/case-sensitive matching, and the empty-result
  guard (' Component' -> original, not '').
@github-actions github-actions Bot added the maintenance Maintenance / chores label Jun 15, 2026
@esphbot esphbot force-pushed the koan/test-base64-component-title branch from a8a2e79 to c6c9eef Compare June 15, 2026 12:53
@esphbot

esphbot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

Simple rebase

Branch koan/test-base64-component-title was rebased onto main — no additional changes were needed.

Stats

2 files changed, 90 insertions(+)
Actions performed
  • Already-solved check: negative (confidence=high, reasoning=No commit on main adds tests for arrayBufferToBase64 (base64.ts) or stripRedundantComponentSuffix (c)
  • Rebased koan/test-base64-component-title onto upstream/main
  • Pre-push CI check: previous run #27526515455 failed
  • Pre-push CI fix: no changes needed or Claude found nothing to fix
  • Force-pushed koan/test-base64-component-title to origin
  • CI check enqueued in ## CI (async)

CI status

CI will be checked asynchronously.


Automated by Kōan

@bdraco bdraco marked this pull request as ready for review June 15, 2026 13:38
Copilot AI review requested due to automatic review settings June 15, 2026 13:38
@bdraco bdraco enabled auto-merge (squash) June 15, 2026 13:39
@bdraco bdraco disabled auto-merge June 15, 2026 13:39
@bdraco bdraco merged commit db824dc into esphome:main Jun 15, 2026
4 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds unit tests for two previously untested pure utility functions (arrayBufferToBase64 and stripRedundantComponentSuffix) to lock in behavior around chunking boundaries and suffix-trimming edge cases.

Changes:

  • Add coverage for arrayBufferToBase64, including empty input, known vectors, full byte-range round-trip, and 0x8000 chunk seam cases.
  • Add coverage for stripRedundantComponentSuffix, including anchored suffix trimming, empty-result guard, and case-sensitivity.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/util/component-title.test.ts Adds unit tests for suffix stripping behavior and edge cases.
test/util/base64.test.ts Adds unit tests for base64 encoding correctness and chunk-boundary round-trips.

Comment thread test/util/base64.test.ts
import { describe, expect, it } from "vitest";
import { arrayBufferToBase64 } from "../../src/util/base64.js";

/** Encode a JS string's bytes (latin1) and round-trip it back through atob. */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Maintenance / chores

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants