The project has a utility that accepts unknown product data, validates it, and builds a short status string for the UI. It is necessary to preserve correct behavior for a valid object and fix the behavior when reusing the result between calls. Requirements: 1) input is unknown; 2) a valid object is one with fields id: string, name: string, tags: string[], selectedTag: string | null; 3) empty strings and strings consisting of spaces in name and selectedTag are invalid; 4) tags must contain only non-empty strings; 5) the function buildProductSummary(input) must return a string of the form #id name [tag], where tag is taken from selectedTag if it is present in tags, otherwise none; 6) for invalid input, the function must return invalid; 7) when the input data changes between calls, a previously obtained result must not change its internal contents. External libraries are not allowed. Run: TypeScript 5.8, strict=true, Node.js 22, ES modules. Verification command: node --test after an npm test-equivalent run of the project without any additional build step.
TypeScript 5.8, strict=true, Node.js 22, ES modules; no extra dependencies; execution mode: direct Node.js test run with ts-node/loader not required because source is plain TypeScript compiled by the harness.
Use line comments to explain the problem, its impact, the fix and how to test it.