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>
143 lines
5.2 KiB
JavaScript
143 lines
5.2 KiB
JavaScript
jest.mock('../config', () => ({ logLevel: 'error' }));
|
|
|
|
jest.mock('../integrations/atlas/atlasClient', () => {
|
|
const actual = jest.requireActual('../integrations/atlas/atlasClient');
|
|
return {
|
|
...actual,
|
|
atlasGet: jest.fn(),
|
|
};
|
|
});
|
|
|
|
const { atlasGet, AtlasUnavailableError } = require('../integrations/atlas/atlasClient');
|
|
const devices = require('../integrations/atlas/atlasDevices');
|
|
|
|
function pageOf(items, nextPage = null) {
|
|
return { items, next_page: nextPage };
|
|
}
|
|
|
|
describe('atlasDevices pagination', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
devices.resetCacheForTests();
|
|
});
|
|
|
|
it('stops paginating when a short page is returned', async () => {
|
|
// 100 items + next_page=2 → keep going; 5 items on page 2 → stop.
|
|
const page1 = Array.from({ length: devices.PAGE_SIZE }, (_, i) => ({ id: `d${i}`, name: 'x' }));
|
|
const page2 = Array.from({ length: 5 }, (_, i) => ({ id: `d${100 + i}`, name: 'x' }));
|
|
atlasGet.mockResolvedValueOnce(pageOf(page1, 2)).mockResolvedValueOnce(pageOf(page2, 3));
|
|
|
|
const list = await devices.getAtlasDeviceList();
|
|
expect(list).toHaveLength(105);
|
|
expect(atlasGet).toHaveBeenCalledTimes(2);
|
|
});
|
|
|
|
it('stops paginating when next_page is missing even on a full page', async () => {
|
|
const page1 = Array.from({ length: devices.PAGE_SIZE }, (_, i) => ({ id: `d${i}`, name: 'x' }));
|
|
atlasGet.mockResolvedValueOnce(pageOf(page1, null));
|
|
|
|
const list = await devices.getAtlasDeviceList();
|
|
expect(list).toHaveLength(devices.PAGE_SIZE);
|
|
expect(atlasGet).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('preserves the previous cache when a mid-pagination call fails', async () => {
|
|
// First refresh succeeds with one device.
|
|
atlasGet.mockResolvedValueOnce(pageOf([{ id: 'd1', name: 'US000782AMP' }], null));
|
|
await devices.getAtlasDeviceList(true);
|
|
|
|
// Force a refresh that fails on page 1 → cache should not be wiped.
|
|
atlasGet.mockRejectedValueOnce(new Error('boom'));
|
|
const list = await devices.getAtlasDeviceList(true);
|
|
expect(list).toHaveLength(1);
|
|
expect(list[0].id).toBe('d1');
|
|
});
|
|
|
|
it('propagates AtlasUnavailableError so callers can render a banner', async () => {
|
|
atlasGet.mockRejectedValueOnce(new AtlasUnavailableError('ATLAS_AUTH_KEY is not set'));
|
|
await expect(devices.getAtlasDeviceList(true)).rejects.toBeInstanceOf(AtlasUnavailableError);
|
|
});
|
|
});
|
|
|
|
describe('findAtlasDevicesForStore', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
devices.resetCacheForTests();
|
|
});
|
|
|
|
it('matches the zero-padded store number against device names', async () => {
|
|
atlasGet.mockResolvedValueOnce(
|
|
pageOf(
|
|
[
|
|
{ id: '1', name: 'US000782AMP' }, // match
|
|
{ id: '2', name: 'us000782DSP' }, // match (case-insensitive)
|
|
{ id: '3', name: 'US007820AMP' }, // NOT — 782 unpadded would false-positive
|
|
{ id: '4', name: 'US000305AMP' },
|
|
],
|
|
null
|
|
)
|
|
);
|
|
|
|
const matches = await devices.findAtlasDevicesForStore('782');
|
|
expect(matches.map(m => m.id).sort()).toEqual(['1', '2']);
|
|
});
|
|
|
|
it('handles already-padded store numbers and whitespace', async () => {
|
|
atlasGet.mockResolvedValueOnce(pageOf([{ id: '1', name: 'US000305AMP' }], null));
|
|
|
|
const matches = await devices.findAtlasDevicesForStore(' 000305 ');
|
|
expect(matches).toHaveLength(1);
|
|
});
|
|
});
|
|
|
|
describe('getAtlasDevicesForStore', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
devices.resetCacheForTests();
|
|
});
|
|
|
|
it('returns { devices: [] } when no matches', async () => {
|
|
atlasGet.mockResolvedValueOnce(pageOf([{ id: '1', name: 'US000305AMP' }], null));
|
|
const result = await devices.getAtlasDevicesForStore('999');
|
|
expect(result).toEqual({ devices: [] });
|
|
});
|
|
|
|
it('fetches detail per matched device and merges over the list summary', async () => {
|
|
atlasGet
|
|
// Initial list call.
|
|
.mockResolvedValueOnce(pageOf([{ id: 'd1', name: 'US000782AMP', status: 'unknown' }], null))
|
|
// Detail call for d1 — adds richer state.
|
|
.mockResolvedValueOnce({
|
|
id: 'd1',
|
|
name: 'US000782AMP',
|
|
status: 'online',
|
|
state: { IpAddress: '10.0.0.5', MacAddress: 'aa:bb:cc:dd:ee:ff' },
|
|
});
|
|
|
|
const result = await devices.getAtlasDevicesForStore('782');
|
|
expect(result.devices).toHaveLength(1);
|
|
expect(result.devices[0]).toEqual(
|
|
expect.objectContaining({
|
|
id: 'd1',
|
|
name: 'US000782AMP',
|
|
status: 'online',
|
|
state: { IpAddress: '10.0.0.5', MacAddress: 'aa:bb:cc:dd:ee:ff' },
|
|
})
|
|
);
|
|
});
|
|
|
|
it('returns { unavailable: true } with the auth reason when the key is missing', async () => {
|
|
atlasGet.mockRejectedValueOnce(new AtlasUnavailableError('ATLAS_AUTH_KEY is not set'));
|
|
const result = await devices.getAtlasDevicesForStore('782');
|
|
expect(result.unavailable).toBe(true);
|
|
expect(result.reason).toMatch(/ATLAS_AUTH_KEY/);
|
|
expect(result.devices).toEqual([]);
|
|
});
|
|
|
|
it('returns { unavailable: true } with the transport reason on other lookup failures', async () => {
|
|
atlasGet.mockRejectedValueOnce(new Error('ECONNRESET'));
|
|
const result = await devices.getAtlasDevicesForStore('782');
|
|
expect(result.unavailable).toBe(true);
|
|
expect(result.reason).toMatch(/Atlas lookup failed/);
|
|
});
|
|
});
|