CRITICAL: File Boundaries Create ONLY these 2 files. Do NOT edit, read-then-modify, or…
- User
CRITICAL: File Boundaries
Create ONLY these 2 files. Do NOT edit, read-then-modify, or touch any other file.
src/chatbot/utils/tableFormatter.tssrc/chatbot/__tests__/tableFormatter.test.ts
Task: Unicode Box-Drawing Table Formatter
Create
formatResultsTable(results: Record<string, unknown>[]): stringthat formats SQL query results as Unicode box-drawing tables, matching the hub'sformatTablestyle.Reference Pattern (hub's formatTable output)
code┌──────────────┬────────┐ │ player | points │ ├──────────────┼────────┤ │ LeBron James │ 30 │ │ S. Curry │ 28 │ └──────────────┴────────┘Key characters:
┌ ┬ ┐ ├ ┼ ┤ └ ┴ ┘ ─ │Function Signature
typescriptexport function formatResultsTable(results: Record<string, unknown>[]): stringBehavior
- Extract headers from
Object.keys(results[0]) - Convert all values to strings (null/undefined → empty string)
- Calculate column widths from max(header.length, max_value_length)
- Auto-detect numeric columns → right-align (check if value is
!isNaN(Number(val))) - Build box-drawing table lines
- If results > 20 rows, show only first 20 and prepend
Rows: N (showing first 20)\n - Empty array → return
'Query returned no results.' - Join all lines with
\nand return single string
Example Output
For input
[{ player: 'LeBron James', points: 30 }, { player: 'Stephen Curry', points: 28 }]:code┌───────────────┬────────┐ │ player │ points │ ├───────────────┼────────┤ │ LeBron James │ 30 │ │ Stephen Curry │ 28 │ └───────────────┴────────┘Note: Each cell has 1 space padding on each side (
${padded} │).TDD Workflow (MANDATORY)
For each test:
- Write ONE failing test
- Run:
bun test src/chatbot/__tests__/tableFormatter.test.ts --concurrency=1
Assistant
I'll follow TDD. Starting with test 1 - basic box-drawing table.
Assistant
Test 1 fails as expected (module not found). Now creating minimal implementation:
Assistant
Test 1 passes. Adding test 2 (empty array):
Assistant
Tests 1-2 pass. Adding remaining tests 3-11:
Assistant
10 pass, 1 fail. The implementation doesn't truncate rows. Fixing:
Assistant
All 11 tests pass. Running verification:
Assistant
Biome clean. The tsc error is pre-existing in
src/hub/tabs/timeMachine/tab.ts, not in my files. Let me verify my files specifically:Assistant
No typecheck errors in my files. Let me confirm final file contents:
Assistant
Results
11/11 tests pass | Biome clean | No typecheck errors in new files
# Test Status 1 Basic 2-column, 2-row box-drawing chars PASS 2 Empty array → no results message PASS 3 Numeric columns right-aligned PASS 4 String columns left-aligned PASS 5 Null/undefined → empty string PASS 6 Single row table PASS 7 Single column table PASS 8 21 rows → truncation message + 20 data rows PASS 9 20 rows → no truncation PASS 10 Column widths adapt to content PASS 11 Special characters preserved PASS