From 6058b632ba10d000657844352e1ad1a4cf4e940c Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 25 Feb 2026 01:32:06 +0000 Subject: [PATCH] test(ai): add unit tests for js/nostr/utils.js (test-coverage-agent) Added focused unit tests for `getActiveKey` in `js/nostr/utils.js` to improve test coverage. This module was identified as having 0% coverage. The new tests cover all branches: - ROOT key generation - pubkey:d key generation - LEGACY key fallback - Handling of missing/empty tags Artifacts: - tests/nostr/utils.test.mjs - docs/agents/task-logs/weekly/2026-02-25_test-coverage-agent_completed.md Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- ...026-02-25_test-coverage-agent_completed.md | 18 ++++++ tests/nostr/utils.test.mjs | 62 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 docs/agents/task-logs/weekly/2026-02-25_test-coverage-agent_completed.md create mode 100644 tests/nostr/utils.test.mjs diff --git a/docs/agents/task-logs/weekly/2026-02-25_test-coverage-agent_completed.md b/docs/agents/task-logs/weekly/2026-02-25_test-coverage-agent_completed.md new file mode 100644 index 00000000..8ebb554a --- /dev/null +++ b/docs/agents/task-logs/weekly/2026-02-25_test-coverage-agent_completed.md @@ -0,0 +1,18 @@ +# Test Coverage Agent: Completed + +**Date:** 2026-02-25 +**Agent:** test-coverage-agent +**Status:** Completed + +## Summary +- Identified `js/nostr/utils.js` as a module with 0% unit test coverage. +- Implemented `tests/nostr/utils.test.mjs` to cover `getActiveKey` logic (100% coverage for the module). +- Verified new tests pass locally. +- Verified full test suite passes. + +## Artifacts +- `tests/nostr/utils.test.mjs` (new file) +- `artifacts/tests-20260225/unit.log` (test run log) + +## Next Steps +- Continue identifying other low-coverage modules in `js/nostr/` such as `ConnectionManager.js` (requires more complex mocking). diff --git a/tests/nostr/utils.test.mjs b/tests/nostr/utils.test.mjs new file mode 100644 index 00000000..ad7fcd21 --- /dev/null +++ b/tests/nostr/utils.test.mjs @@ -0,0 +1,62 @@ +/** + * @file tests/nostr/utils.test.mjs + * @description Unit tests for js/nostr/utils.js + */ + +import { test, describe } from 'node:test'; +import assert from 'node:assert'; +import { getActiveKey } from '../../js/nostr/utils.js'; + +describe('js/nostr/utils.js', () => { + describe('getActiveKey', () => { + test('returns ROOT key when videoRootId is present', () => { + const video = { + videoRootId: 'root-123', + id: 'note-456', + pubkey: 'pk1', + tags: [['d', 'd-tag-val']] + }; + const key = getActiveKey(video); + assert.strictEqual(key, 'ROOT:root-123'); + }); + + test('returns pubkey:d key when videoRootId is missing but d-tag exists', () => { + const video = { + id: 'note-456', + pubkey: 'pk1', + tags: [['d', 'd-tag-val']] + }; + const key = getActiveKey(video); + assert.strictEqual(key, 'pk1:d-tag-val'); + }); + + test('returns LEGACY key when videoRootId and d-tag are missing', () => { + const video = { + id: 'note-456', + pubkey: 'pk1', + tags: [['t', 'hashtag']] + }; + const key = getActiveKey(video); + assert.strictEqual(key, 'LEGACY:note-456'); + }); + + test('handles missing tags array gracefully (returns LEGACY)', () => { + const video = { + id: 'note-789', + pubkey: 'pk2' + }; + const key = getActiveKey(video); + assert.strictEqual(key, 'LEGACY:note-789'); + }); + + test('handles empty tags array gracefully (returns LEGACY)', () => { + const video = { + id: 'note-789', + pubkey: 'pk2', + tags: [] + }; + const key = getActiveKey(video); + assert.strictEqual(key, 'LEGACY:note-789'); + }); + }); +});