{
  "version": 3,
  "sources": ["../../src/app/ai/agents/evals2/scenarios/cms/csvImportIntoExistingCollections.eval.ts"],
  "sourcesContent": ["import { assert } from \"@framerjs/shared\"\nimport type { CollectionNode } from \"document/models/CanvasTree/index.ts\"\nimport { getContentManagementNode } from \"document/models/CanvasTree/nodes/ContentManagementNode.utils.ts\"\nimport type { NodeID } from \"document/models/CanvasTree/nodes/NodeID.ts\"\nimport { isCollectionItemNode, isCollectionNode } from \"document/models/CanvasTree/nodes/utils/nodeCheck.ts\"\nimport { isVariableDefinition } from \"document/models/CanvasTree/traits/WithVariables.ts\"\nimport { agentEvalAsset } from \"../../harness/asset.ts\"\nimport type { AgentEvalFixture } from \"../../harness/fixture.ts\"\nimport { createEvalExportZipFixture } from \"../../harness/fixture.ts\"\nimport { getCollectionItems, normalizeCmsName } from \"./cmsEvalUtils.ts\"\n\nconst csvImportRequestId = \"IRFrjMjd7\"\nconst jobsCollectionId = \"P7hvtPoNR\"\nconst departmentsCollectionId = \"N5RyECYEr\"\nconst originalDepartmentReferenceVariableId = \"ETiRgH3zR\"\nconst initialCollectionItemIds = new Set<NodeID>()\n\nfunction withInitialCollectionItemsSnapshot(fixture: AgentEvalFixture): AgentEvalFixture {\n\treturn {\n\t\t...fixture,\n\t\tload: async options => {\n\t\t\tconst runtime = await fixture.load(options)\n\n\t\t\tconst contentManagementNode = getContentManagementNode(runtime.engine.tree)\n\t\t\tassert(contentManagementNode?.isLoaded(), \"Project must have a CMS\")\n\n\t\t\tfor (const node of contentManagementNode.walk()) {\n\t\t\t\tif (isCollectionItemNode(node)) {\n\t\t\t\t\tinitialCollectionItemIds.add(node.id)\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn runtime\n\t\t},\n\t}\n}\n\nfunction countNewCollectionItems(collection: CollectionNode | null | undefined): number {\n\treturn getCollectionItems(collection ?? undefined).filter(item => !initialCollectionItemIds.has(item.id)).length\n}\n\nfunction countNewJobsWithDepartmentReference(jobs: CollectionNode, referenceVariableId: string): number {\n\treturn getCollectionItems(jobs)\n\t\t.filter(item => !initialCollectionItemIds.has(item.id))\n\t\t.filter(item => {\n\t\t\tconst value = item.getControlProp(referenceVariableId)?.value\n\t\t\tif (Array.isArray(value)) return value.length > 0\n\t\t\treturn typeof value === \"string\" && value.length > 0\n\t\t}).length\n}\n\n// During the original run, the tester asked the Agent to add data from two .csv files.\n// The agent produced buggy behavior:\n//\n// - It duplicated an existing Collection Reference variable (Departments) instead of reusing it.\n// - It deleted data while the prompt never mentioned deleting/replacing data, only adding new data.\n//   The agent's reasoning was to \"clear stale data\" and re-import from the .csv, but there was\n//   pre-existing data in the collections that wasn't present in the .csv, resulting in data loss.\nevaluation(\n\t\"CMS: Import CSV Into Existing Collections\",\n\t// Browser-only: parseCsv attachments without inlined text trip the Node CLI sandbox's fetch\n\t// hardening, same caveat as uploadCsvCollection.eval.ts.\n\twithInitialCollectionItemsSnapshot(\n\t\tcreateEvalExportZipFixture(\n\t\t\t\"cms-csv-import-into-existing-collections\",\n\t\t\tagentEvalAsset(\"./csv-import-into-existing-collections-export.zip\"),\n\t\t\t{ runtimeTarget: \"browser\" },\n\t\t),\n\t),\n\t{\n\t\tid: \"cms-csv-import-into-existing-collections\",\n\t\trequestId: csvImportRequestId,\n\t\tstepIndex: 0,\n\t\tmaxSteps: 10,\n\t},\n\t({ engine, report, tools }) => {\n\t\tconst departments = engine.tree.getNodeWithTrait(departmentsCollectionId, isCollectionNode)\n\t\tconst jobs = engine.tree.getNodeWithTrait(jobsCollectionId, isCollectionNode)\n\t\tconst originalDepartmentReference = jobs?.variables.find(\n\t\t\tvariable => variable.id === originalDepartmentReferenceVariableId,\n\t\t)\n\n\t\treport.correctness.required(\"preserves the original Departments collection\", () => {\n\t\t\texpect(departments).toBeDefined()\n\t\t})\n\n\t\treport.correctness.required(\"preserves the original Jobs.Department reference variable\", () => {\n\t\t\texpect(originalDepartmentReference).toBeDefined()\n\t\t})\n\n\t\treport.correctness.required(\"no data loss: does not delete pre-existing collection items\", () => {\n\t\t\tconst deleted = [...initialCollectionItemIds].filter(id => !engine.tree.has(id))\n\t\t\texpect(deleted).toEqual([])\n\t\t})\n\n\t\treport.correctness.required(\"does not add a new Department-named variable on Jobs\", () => {\n\t\t\tconst extraDepartmentVariables = (jobs?.variables ?? []).filter(\n\t\t\t\tvariable =>\n\t\t\t\t\tisVariableDefinition(variable) &&\n\t\t\t\t\tvariable.id !== originalDepartmentReferenceVariableId &&\n\t\t\t\t\tnormalizeCmsName(variable.name).startsWith(\"department\"),\n\t\t\t)\n\n\t\t\texpect(extraDepartmentVariables.map(variable => variable.name)).toEqual([])\n\t\t})\n\n\t\treport.correctness.scored(\"does not produce command errors\", () => {\n\t\t\texpect(tools.commandErrors()).toHaveLength(0)\n\t\t})\n\n\t\treport.correctness.scored(\"adds department values from the CSV as Departments items\", () => {\n\t\t\texpect(countNewCollectionItems(departments)).toBeGreaterThan(0)\n\t\t})\n\n\t\treport.correctness.scored(\"imports at least one job from the CSV\", () => {\n\t\t\texpect(countNewCollectionItems(jobs)).toBeGreaterThan(0)\n\t\t})\n\n\t\treport.correctness.scored(\"assigns a department reference to imported jobs\", () => {\n\t\t\texpect(jobs).toBeDefined()\n\t\t\tif (!jobs) return\n\t\t\texpect(countNewJobsWithDepartmentReference(jobs, originalDepartmentReferenceVariableId)).toBeGreaterThan(0)\n\t\t})\n\t},\n)\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAWA,IAAM,qBAAqB;AAC3B,IAAM,mBAAmB;AACzB,IAAM,0BAA0B;AAChC,IAAM,wCAAwC;AAC9C,IAAM,2BAA2B,oBAAI,IAAY;AAEjD,SAAS,mCAAmC,SAA6C;AACxF,SAAO;AAAA,IACN,GAAG;AAAA,IACH,MAAM,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