{"record":{"id":"31a435e0b60f7a57","repo":"ruvnet/ruflo","slug":"item-at-index-i-passed-predicate-but-should-not","errorCode":null,"errorMessage":"Item at index ${i} passed predicate but should not have: ${JSON.stringify(items[i])}","messagePattern":"Item at index (.+?) passed predicate but should not have: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/testing/src/helpers/assertion-helpers.ts","lineNumber":427,"sourceCode":"      );\n    }\n  }\n}\n\n/**\n * Assert that none of the items in a collection pass a predicate\n *\n * @example\n * assertNonePass(results, result => result.error);\n */\nexport function assertNonePass<T>(\n  items: T[],\n  predicate: (item: T, index: number) => boolean,\n  message?: string\n): void {\n  for (let i = 0; i < items.length; i++) {\n    if (predicate(items[i], i)) {\n      throw new Error(\n        message ?? `Item at index ${i} passed predicate but should not have: ${JSON.stringify(items[i])}`\n      );\n    }\n  }\n}\n\n/**\n * Assert that two arrays have the same elements regardless of order\n *\n * @example\n * assertSameElements([1, 2, 3], [3, 1, 2]);\n */\nexport function assertSameElements<T>(actual: T[], expected: T[]): void {\n  expect(actual).toHaveLength(expected.length);\n\n  const actualSorted = [...actual].sort((a, b) =>\n    JSON.stringify(a).localeCompare(JSON.stringify(b))\n  );","sourceCodeStart":409,"sourceCodeEnd":445,"githubUrl":"https://github.com/ruvnet/ruflo/blob/fa13ee4ad60ac2090b1480656eb233521790d640/v3/@claude-flow/testing/src/helpers/assertion-helpers.ts#L409-L445","documentation":"assertNonePass() is the inverse helper: it throws on the first item for which the predicate returns true, printing the index and the item. Use it for invariants like no result carries an error; the throw proves at least one violating item exists.","triggerScenarios":"At least one item satisfies the forbidden predicate (some result.error is truthy); a predicate that is too broad, matching on truthiness where a narrow check was intended; unexpected item shapes making the predicate accidentally true.","commonSituations":"One failed job in a batch that should be clean; warning paths setting error fields on non-errors; predicates written loosely during a rush.","solutions":["Inspect the printed item; it is the concrete violation, then trace which producer set the forbidden state","Tighten the predicate if it over-matches, for example check specific error codes instead of truthiness","If the violating case is legitimately possible, split the assertion into allowed and disallowed subsets instead"],"exampleFix":"// before\nassertNonePass(results, r => r.error); // throws at index 2\n\n// after\nassertNonePass(results, r => r.error?.fatal === true); // only fatal errors are forbidden","handlingStrategy":"validation","validationCode":"// Enumerate violations before asserting\nconst violations = items\n  .map((item, i) => ({ i, item }))\n  .filter(({ item }) => predicate(item));\nif (violations.length > 0) {\n  console.error('violations:', violations);\n}\nassertNonePass(items, predicate);","typeGuard":"function nonePass<T>(items: T[], predicate: (item: T, index: number) => boolean): boolean {\n  return !items.some((item, i) => predicate(item, i));\n}","tryCatchPattern":null,"preventionTips":["Scope forbidden predicates narrowly: specific codes or flags, not truthiness","Pre-filter known-acceptable items out of the array before asserting","Keep producer warning paths from writing to error fields for non-errors"],"tags":["testing","assertion","predicate","collections"],"backgroundTag":"predicate-assertion-failed","analyzedSha":"fa13ee4ad60ac2090b1480656eb233521790d640","analyzedAt":"2026-08-18T21:34:22.708Z","contentChangedAt":"2026-08-18T21:34:22.708Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}