netanalyzer/tests/chunkReport.test.js
Joseph McQueen b3c37bd7df feat: st command suite, Webex phone + Atlas AV integrations, dockerized remote agent
Rebrand NetAnalyzer -> StoreHealthAnalyzer and consolidate the store
reporting surface into a single `st [number]` command with focused
sub-modes.

Commands
- st [number]                - general info (SIW + brands + Meraki net link)
- st [number] network        - switches, APs, store server
- st [number] pos            - registers, payment terminals, customer display
- st [number] ios            - MDM-tracked iOS hardware
- st [number] phone          - wired 78xx + DECT basestations/handsets with
                               registration state, extensions and main DID
- st [number] av             - Atlas AMPs + MDM-tracked Apple TVs, video
                               walls, music players, LED displays
- Removed `analyze` in favor of the unified `st` surface

Integrations
- integrations/webex: Service App OAuth with rotating refresh tokens,
  seed + cleanup scripts, tokens/ storage (git-ignored)
- integrations/atlas: Xyte client + cached device discovery keyed on
  zero-padded 6-digit store numbers, cold-cache failure -> unavailable
  banner instead of a misleading empty result
- services/webexPhone, services/webexService, services/avService: shape
  raw upstream data into the report layer's contract
- utils/merakiMatcher: FQDN hostname extraction so payment terminals
  match Meraki descriptions; case-insensitive lookup
- utils/chunkReport: split long markdown replies at 7000-char boundaries

Reliability / ops
- server.js: awaited framework.stop() + 8s hard-kill timer so nodemon /
  Docker restarts don't leak WDM device registrations ("excessive device
  registrations")
- nodemon.json: SIGINT so the graceful path always runs
- scripts/cleanupWebexDevices.js: one-shot WDM cleanup utility
- Group-space routing: hears() regexes tolerate the leading @BotName
  prefix Webex prepends to mentions
- Replaced HTML-unsafe <number> placeholders with [number] in all help
  strings

Remote agent containerization
- docker/remote-agent/: multi-stage node:22-alpine image, non-root user,
  tini for signal handling, minimal deps (ws/axios/dotenv)
- docker/remote-agent/package.sh: docker buildx build defaulting to
  linux/amd64 (with override), saves image + assembles deploy/ + writes
  SHA256 + zips for offline transfer
- docker/remote-agent/deploy/: runtime docker-compose.yml, install.sh
  with platform sanity check, remote-host README
- .dockerignore + .gitignore updates for build artifacts and dist bundles
- npm run agent:package convenience script

Cleanup
- Dropped storeHealth.js / HealthReport.js and their tests/mocks in favor
  of the shared storeDetail pipeline
- Store model handles null SIW records gracefully; toSummary always
  ends with a newline so the Meraki link sits on its own line

Tests
- 144 tests across 14 suites passing; new coverage for atlasClient,
  atlasDevices, avService, avCategory classification, webexPhone,
  webexServiceAppAuth, storeDetail integration, siw, chunkReport and
  the updated meraki matcher

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-06 09:54:41 -04:00

56 lines
2.1 KiB
JavaScript

const { chunkReport } = require('../utils/chunkReport');
describe('chunkReport', () => {
it('returns [] for empty input', () => {
expect(chunkReport('')).toEqual([]);
expect(chunkReport(null)).toEqual([]);
});
it('returns a single chunk when under the limit', () => {
const report = '**🌐 Network**\n- Switch online\n- AP online';
expect(chunkReport(report, 1000)).toEqual([report]);
});
it('trims surrounding whitespace from the single-chunk case', () => {
const report = '\n\n**A**\nhello\n\n';
expect(chunkReport(report, 1000)).toEqual(['**A**\nhello']);
});
it('splits on section boundaries when over the limit', () => {
const a = '**A** ' + 'x'.repeat(60);
const b = '**B** ' + 'y'.repeat(60);
const c = '**C** ' + 'z'.repeat(60);
const report = `${a}\n\n${b}\n\n${c}`;
const chunks = chunkReport(report, 100);
// Each section is ~66 chars so two sections per chunk is just over the
// limit. Expect 3 chunks, one per section.
expect(chunks).toHaveLength(3);
expect(chunks[0]).toContain('**A**');
expect(chunks[1]).toContain('**B**');
expect(chunks[2]).toContain('**C**');
chunks.forEach(c => expect(c.length).toBeLessThanOrEqual(100));
});
it('packs multiple small sections into one chunk when they fit', () => {
const sections = ['**A** short', '**B** short', '**C** short', '**D** short'];
const report = sections.join('\n\n');
const chunks = chunkReport(report, 1000);
expect(chunks).toHaveLength(1);
expect(chunks[0]).toBe(report);
});
it('hard-splits when a single section exceeds the limit', () => {
const huge = '**Huge** ' + 'x'.repeat(500);
const chunks = chunkReport(huge, 100);
chunks.forEach(c => expect(c.length).toBeLessThanOrEqual(100));
expect(chunks.join('')).toBe(huge);
});
it('keeps each chunk under the default 7000-char limit', () => {
const section = '**Section ' + 'x'.repeat(50) + '**\n' + 'y'.repeat(3500);
const report = Array.from({ length: 5 }, () => section).join('\n\n');
const chunks = chunkReport(report);
chunks.forEach(c => expect(c.length).toBeLessThanOrEqual(7000));
});
});