import test from 'node:test' import assert from 'node:assert/strict' import {normalizeSearchQuery,isSearchRequest,trimSearchText} from '../../src/utils/search-query.js' test('all search boundary whitespace is ignored, but internal spaces and punctuation survive',()=>{ for(const edge of [' ','\t\r\n','\u3000','\u00a0','\u202f','\ufeff','\u200b','\u0085'])assert.equal(trimSearchText(edge+'TP-LINK 路由器 AX 5400'+edge),'TP-LINK 路由器 AX 5400') assert.equal(trimSearchText('a b'),'a b') assert.equal(trimSearchText(' \u3000 '),'') }) test('normalization is immutable, recursive and preserves values and credentials',()=>{ const original={productName:' 路由器 ',params:{beginTime:' 2026-10-01 ',names:[' 物品 A ',null,0]},enabled:false,password:' secret ',fileName:' report.pdf ',token:' bearer '} const normalized=normalizeSearchQuery(original) assert.equal(normalized.productName,'路由器');assert.equal(original.productName,' 路由器 ') assert.deepEqual(normalized.params,{beginTime:'2026-10-01',names:['物品 A',null,0]}) for(const key of ['password','fileName','token','enabled'])assert.equal(normalized[key],original[key]) assert.equal(normalizeSearchQuery({'params[password]':' keep '})['params[password]'],' keep ') }) test('scope includes business searches and filtered exports, never collaboration or business writes',()=>{ for(const path of ['/warehouse/product/list','/production/products/options','/project/info/options','/project/loans','/system/user/list','/monitor/operlog/list','/prod-api/warehouse/stock/list'])assert.equal(isSearchRequest(path),true,path) assert.equal(isSearchRequest('/warehouse/product/export','post'),true) for(const [path,method] of [['/project/manage/projects','get'],['/warehouse/purchase','post'],['/login','post'],['/system/user/resetPwd','put'],['/common/download','get']])assert.equal(isSearchRequest(path,method),false,path) })