{"record":{"id":"cd1535e49ad17a21","repo":"Egonex-AI/Understand-Anything","slug":"import-artifact-does-not-match-the-required-shape","errorCode":null,"errorMessage":"Import artifact does not match the required shape","messagePattern":"Import artifact does not match the required shape","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/large-repo-benchmark.mjs","lineNumber":749,"sourceCode":"  }\n}\n\nfunction validateImportArtifact(imports) {\n  if (\n    !isRecord(imports) ||\n    imports.scriptCompleted !== true ||\n    !isRecord(imports.importMap) ||\n    !isRecord(imports.stats) ||\n    !isNonNegativeInteger(imports.stats.filesScanned) ||\n    !isNonNegativeInteger(imports.stats.filesWithImports) ||\n    !isNonNegativeInteger(imports.stats.totalEdges) ||\n    Object.values(imports.importMap).some(\n      (targets) =>\n        !Array.isArray(targets) ||\n        targets.some((target) => typeof target !== 'string'),\n    )\n  ) {\n    throw new Error('Import artifact does not match the required shape');\n  }\n}\n\nfunction validateBatchArtifact(batches) {\n  if (\n    !isRecord(batches) ||\n    batches.schemaVersion !== 1 ||\n    typeof batches.algorithm !== 'string' ||\n    batches.algorithm.length === 0 ||\n    !Array.isArray(batches.batches) ||\n    !isNonNegativeInteger(batches.totalBatches) ||\n    batches.totalBatches !== batches.batches.length ||\n    batches.batches.some(\n      (batch) =>\n        !isRecord(batch) ||\n        !isNonNegativeInteger(batch.batchIndex) ||\n        !Array.isArray(batch.files) ||\n        !isRecord(batch.batchImportData) ||","sourceCodeStart":731,"sourceCodeEnd":767,"githubUrl":"https://github.com/Egonex-AI/Understand-Anything/blob/32944829e7a63a9fa9c55d811d7f98a9530c6a6a/scripts/lib/large-repo-benchmark.mjs#L731-L767","documentation":"Thrown by validateImportArtifact in the large-repo benchmark harness when the JSON written by the extract-import-map worker fails a structural schema check. The harness refuses to feed a malformed import-map into the downstream batching stage, since a partial or truncated artifact would corrupt agent input sizing. It guards schemaVersion-less output by asserting scriptCompleted, an importMap record, a stats record with three non-negative integers, and that every importMap target list is an array of strings.","triggerScenarios":"The benchmark reads artifactRoot/import-map.json after the import stage exits cleanly and calls validateImportArtifact(imports). It throws when (a) scriptCompleted !== true (worker crashed before finalizing), (b) importMap or stats is not an object, (c) stats.filesScanned/filesWithImports/totalEdges is missing or negative/non-integer, or (d) any value in importMap is not an array, or any element of that array is not a string.","commonSituations":"An older extract-import-map.mjs version that omits the scriptCompleted flag or stats block (version drift between plugin cache and benchmark script). The WASM tree-sitter loader failing partway so importMap is populated for only some files. A manually edited or hand-written import-map.json missing the stats envelope. Disk-full / interrupted write producing a truncated JSON that JSON.parse happens to accept as a partial object.","solutions":["Re-run the import stage in isolation: node understand-anything-plugin/skills/understand/extract-import-map.mjs <input.json> <output.json> and inspect stderr for filesScanned/filesWithImports/totalEdges.","Open the offending import-map.json and confirm it has top-level scriptCompleted:true, importMap:{}, and stats:{filesScanned,filesWithImports,totalEdges} all >= 0 integers.","If scriptCompleted is false/missing, the worker exited early — check the worker stage stderr captured in report.stages.imports and fix the root cause (e.g. WASM grammar load failure) before re-running.","If you edited the artifact schema, regenerate it via the shipped worker rather than hand-authoring, so all fields are populated.","Clear the artifactRoot directory and re-run the full benchmark so no stale/partial import-map.json is reused."],"exampleFix":"// before: hand-written minimal map missing stats envelope\n{ \"importMap\": { \"./a.ts\": [\"./b.ts\"] } }\n\n// after: full shape produced by extract-import-map.mjs\n{\n  \"scriptCompleted\": true,\n  \"stats\": { \"filesScanned\": 1, \"filesWithImports\": 1, \"totalEdges\": 1 },\n  \"importMap\": { \"./a.ts\": [\"./b.ts\"] }\n}","handlingStrategy":"validation","validationCode":"import { readFileSync } from 'node:fs';\nfunction isValidImportArtifact(v) {\n  if (typeof v !== 'object' || v === null) return false;\n  if (v.scriptCompleted !== true) return false;\n  if (typeof v.importMap !== 'object' || v.importMap === null) return false;\n  if (typeof v.stats !== 'object' || v.stats === null) return false;\n  const s = v.stats;\n  if (!Number.isInteger(s.filesScanned) || s.filesScanned < 0) return false;\n  if (!Number.isInteger(s.filesWithImports) || s.filesWithImports < 0) return false;\n  if (!Number.isInteger(s.totalEdges) || s.totalEdges < 0) return false;\n  for (const targets of Object.values(v.importMap)) {\n    if (!Array.isArray(targets)) return false;\n    if (targets.some((t) => typeof t !== 'string')) return false;\n  }\n  return true;\n}\n// before feeding the artifact to the benchmark:\nconst artifact = JSON.parse(readFileSync(path, 'utf-8'));\nif (!isValidImportArtifact(artifact)) throw new Error('refusing to feed malformed import artifact');","typeGuard":"function isImportArtifact(v) {\n  if (typeof v !== 'object' || v === null) return false;\n  const o = v;\n  return o.scriptCompleted === true\n    && typeof o.importMap === 'object' && o.importMap !== null\n    && typeof o.stats === 'object' && o.stats !== null\n    && Number.isInteger(o.stats.filesScanned) && o.stats.filesScanned >= 0\n    && Number.isInteger(o.stats.filesWithImports) && o.stats.filesWithImports >= 0\n    && Number.isInteger(o.stats.totalEdges) && o.stats.totalEdges >= 0\n    && Object.values(o.importMap).every(\n        (t) => Array.isArray(t) && t.every((x) => typeof x === 'string'));\n}","tryCatchPattern":"try {\n  validateImportArtifact(imports);\n} catch (e) {\n  // the message is generic; log the offending file for diagnosis\n  console.error('import-map.json shape invalid:', e.message, importPath);\n  throw e;\n}","preventionTips":["Always regenerate import-map.json via the shipped extract-import-map.mjs rather than hand-editing it.","Keep the plugin cache in sync with the benchmark script so the scriptCompleted/stats envelope is always present.","After any worker crash, delete the partial import-map.json before re-running so a stale malformed artifact is not reused."],"tags":["benchmark","validation","import-map","schema","json-artifact"],"backgroundTag":null,"analyzedSha":"32944829e7a63a9fa9c55d811d7f98a9530c6a6a","analyzedAt":"2026-08-12T10:25:44.261Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}