Skip to content

feat(plan-35-36): add unit tests and documentation#330

Merged
d-oit merged 2 commits into
mainfrom
feat/goap-plan-35-36-041-remaining-2026-06-19
Jun 19, 2026
Merged

feat(plan-35-36): add unit tests and documentation#330
d-oit merged 2 commits into
mainfrom
feat/goap-plan-35-36-041-remaining-2026-06-19

Conversation

@d-oit

@d-oit d-oit commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Implements remaining tasks from plans 35 (Test Coverage) and 36 (Documentation).

Plan 35: Test Coverage Expansion

New Tests

  • useFocusTrap: focus management, tab wrapping, focus restoration, inactive state, empty focusable elements
  • Markdown renderer: headings (h1-h6), ordered/unordered lists, code blocks, inline code, bold/italic/strikethrough, links, XSS sanitization, empty input, unclosed code blocks
  • DbProvider: initialization success/error states, context provision, dbReady state
  • Mind map tree (extracted to src/lib/mindmap-tree.ts): empty arrays, parent-child links, depth limits, relation filtering, null entities, circular references, ARIA attributes

Coverage Thresholds Raised

  • branches: 30 → 33
  • functions: 35 → 38
  • lines: 40 → 43
  • statements: 40 → 42

Bug Fix

  • Added <code>, <pre>, and <del> to allowed HTML tags in sanitizeHtml

Plan 36: Documentation

New Documentation

  • DEPLOYMENT.md: Static hosting (Netlify, Vercel, GitHub Pages), Nginx, Apache, Caddy, Docker, HTTPS, performance optimization
  • LLM_SETUP.md: Provider configuration (OpenRouter, Kilo, custom), API key management, rate limiting, error handling, security best practices

Files Changed

  • 4 new test files
  • 1 new utility file (mindmap-tree.ts)
  • 1 modified test file (markdown.test.tsx)
  • 1 modified security config
  • 1 modified vitest config
  • 2 new documentation files

Plan 35 (Test Coverage):
- Add useFocusTrap tests (focus management, tab wrapping, restoration)
- Add markdown renderer tests (headings, lists, code, links, XSS)
- Add DbProvider tests (initialization, error handling, context)
- Extract buildTree to src/lib/mindmap-tree.ts for isolated testing
- Add mindmap-tree tests (tree building, depth limits, circular refs, ARIA)
- Raise coverage thresholds (branches: 33, functions: 38, lines: 43, statements: 42)
- Add code and del tags to allowed HTML list in sanitizeHtml

Plan 36 (Documentation):
- Add docs/DEPLOYMENT.md (static hosting, Nginx, Apache, Caddy, Docker)
- Add docs/LLM_SETUP.md (providers, configuration, troubleshooting)
@github-actions github-actions Bot added documentation Documentation improvements config tests Related to automated/manual tests labels Jun 19, 2026
@deepsource-io

deepsource-io Bot commented Jun 19, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 5608449...bfbd5c8 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
JavaScript Jun 19, 2026 10:27a.m. Review ↗
Python Jun 19, 2026 10:27a.m. Review ↗
Shell Jun 19, 2026 10:27a.m. Review ↗
SQL Jun 19, 2026 10:27a.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

});

it('should render children when database is ready', async () => {
const { initDb } = await import('../../db/client');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Useless path segments for "../../db/client", should be "../client"


Unnecessarily complex import statements can be simplified. Complex imports usually result in confusing code. This usually happens as a result of refactoring.


it('should render children when database is ready', async () => {
const { initDb } = await import('../../db/client');
vi.mocked(initDb).mockResolvedValue(undefined);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remove redundant `undefined` from function call


When an argument is omitted from a function call, it will default to undefined. It is therefore redundant to explicitly pass an undefined literal as the last argument.

});

it('should show error state on failure', async () => {
const { initDb } = await import('../../db/client');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Useless path segments for "../../db/client", should be "../client"


Unnecessarily complex import statements can be simplified. Complex imports usually result in confusing code. This usually happens as a result of refactoring.

});

it('should provide repository in context', async () => {
const { initDb } = await import('../../db/client');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Useless path segments for "../../db/client", should be "../client"


Unnecessarily complex import statements can be simplified. Complex imports usually result in confusing code. This usually happens as a result of refactoring.


it('should provide repository in context', async () => {
const { initDb } = await import('../../db/client');
vi.mocked(initDb).mockResolvedValue(undefined);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remove redundant `undefined` from function call


When an argument is omitted from a function call, it will default to undefined. It is therefore redundant to explicitly pass an undefined literal as the last argument.

@@ -0,0 +1,125 @@
import { describe, it, expect } from 'vitest';
import { buildTree, addAriaToNodes } from '../../lib/mindmap-tree';
import type { Entity, Link } from '../../lib/validation';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Useless path segments for "../../lib/validation", should be "../validation"


Unnecessarily complex import statements can be simplified. Complex imports usually result in confusing code. This usually happens as a result of refactoring.

Comment thread src/lib/llm/__tests__/markdown.test.tsx Outdated
@@ -1,128 +1,124 @@
import { describe, it, expect } from 'vitest';
import { render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

'screen' is defined but never used


Unused variables are generally considered a code smell and should be avoided.

<MarkdownRenderer content={'Some text\n```\nconst x = 1;'} />
);
// The unclosed code block should still render as a paragraph
const p = container.querySelector('p');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Variable name is too small


Short variable names affect code readability and complicate code refactoring, because of the difficulty in searching and replacing such short characters.

Comment thread src/lib/mindmap-tree.ts
Comment on lines +20 to +43
export function buildTree(
currentId: string,
depth: number,
maxDepth: number,
entities: Entity[],
links: Link[],
relationFilter: string,
): MindMapNode | null {
const entity = entities.find(e => e.id === currentId);
if (!entity || depth > maxDepth) return null;

const childrenLinks = links.filter(l =>
l.source_id === currentId &&
(relationFilter === 'all' || l.relation === relationFilter)
);

return {
id: entity.id || `node-${Math.random()}`,
topic: entity.name,
children: childrenLinks
.map(l => buildTree(l.target_id, depth + 1, maxDepth, entities, links, relationFilter))
.filter((n): n is MindMapNode => n !== null)
};
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unexpected function declaration in the global scope, wrap in an IIFE for a local variable, assign as global property for a global variable


It is considered a best practice to avoid 'polluting' the global scope with variables that are intended to be local to the script. Global variables created from a script can produce name collisions with global variables created from another script, which will usually lead to runtime errors or unexpected behavior. It is mostly useful for browser scripts.

Comment thread src/lib/mindmap-tree.ts
Comment on lines +50 to +59
export function addAriaToNodes(container: HTMLElement): void {
const topics = container.querySelectorAll('me-tpc');
topics.forEach(tpc => {
const parent = tpc.closest('me-parent');
if (parent && !parent.hasAttribute('role')) {
parent.setAttribute('role', 'treeitem');
parent.setAttribute('aria-label', tpc.textContent?.trim() || 'Mind map node');
}
});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unexpected function declaration in the global scope, wrap in an IIFE for a local variable, assign as global property for a global variable


It is considered a best practice to avoid 'polluting' the global scope with variables that are intended to be local to the script. Global variables created from a script can produce name collisions with global variables created from another script, which will usually lead to runtime errors or unexpected behavior. It is mostly useful for browser scripts.

@codacy-production

codacy-production Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 65 complexity · 2 duplication

Metric Results
Complexity 65
Duplication 2

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@d-oit d-oit merged commit 1b19723 into main Jun 19, 2026
23 of 24 checks passed
@d-oit d-oit deleted the feat/goap-plan-35-36-041-remaining-2026-06-19 branch June 19, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config documentation Documentation improvements tests Related to automated/manual tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants