{"record":{"id":"65dae059ff879710","repo":"paperclipai/paperclip","slug":"environment-event-order-mismatch-nexpected-jso","errorCode":null,"errorMessage":"Environment event order mismatch.\\nExpected: ${JSON.stringify(expectedOrder)}\\nActual:   ${JSON.stringify(actual)}","messagePattern":"Environment event order mismatch\\.\\\\nExpected: (.+?)\\\\nActual:   (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/plugins/sdk/src/testing.ts","lineNumber":259,"sourceCode":"  return events.filter((e) => e.type === type);\n}\n\n/** Assert that environment events occurred in the expected order. */\nexport function assertEnvironmentEventOrder(\n  events: EnvironmentEventRecord[],\n  expectedOrder: EnvironmentEventRecord[\"type\"][],\n): void {\n  const actual = events.map((e) => e.type);\n  const matched: EnvironmentEventRecord[\"type\"][] = [];\n  let cursor = 0;\n  for (const eventType of actual) {\n    if (cursor < expectedOrder.length && eventType === expectedOrder[cursor]) {\n      matched.push(eventType);\n      cursor++;\n    }\n  }\n  if (matched.length !== expectedOrder.length) {\n    throw new Error(\n      `Environment event order mismatch.\\nExpected: ${JSON.stringify(expectedOrder)}\\nActual:   ${JSON.stringify(actual)}`,\n    );\n  }\n}\n\n/** Assert that a full lease lifecycle (acquire → release) occurred for an environment. */\nexport function assertLeaseLifecycle(\n  events: EnvironmentEventRecord[],\n  environmentId: string,\n): { acquire: EnvironmentEventRecord; release: EnvironmentEventRecord } {\n  const acquire = events.find((e) => e.type === \"acquireLease\" && e.environmentId === environmentId);\n  const release = events.find((e) => (e.type === \"releaseLease\" || e.type === \"destroyLease\") && e.environmentId === environmentId);\n  if (!acquire) throw new Error(`No acquireLease event found for environment ${environmentId}`);\n  if (!release) throw new Error(`No releaseLease/destroyLease event found for environment ${environmentId}`);\n  if (acquire.timestamp > release.timestamp) {\n    throw new Error(`acquireLease occurred after release for environment ${environmentId}`);\n  }\n  return { acquire, release };","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/paperclipai/paperclip/blob/01ad8584922b5d85292b1723cae71fa0d9b07a19/packages/plugins/sdk/src/testing.ts#L241-L277","documentation":"Test-helper assertion in assertEnvironmentEventOrder: the recorded environment events, reduced to their type sequence, do not contain the expectedOrder subsequence (order-sensitive, allowing interleaved unrelated events). The error prints both the expected type list and the actual recorded order for diagnosing plugin lifecycle behavior in SDK harness tests.","triggerScenarios":"Thrown at packages/plugins/sdk/src/testing.ts:259 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix the environment lifecycle so events occur in the expected order; compare expected vs actual in the message."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ad8584922b5d85292b1723cae71fa0d9b07a19","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}