Repository navigation
feat(cli): add icontains, regex and equals text assertions (#411) - #430
Conversation
anurag629
left a comment
There was a problem hiding this comment.
Thanks, this is clean, and the bad-value tests are thorough (not- with a bad value still fails, good). Locally merged with dev: build, typecheck, 67 CLI tests, lint and docs:check pass.
One small thing from #411: a pattern that doesn't compile. Right now readRegex (packages/cli/src/test/assertions/text.ts) passes new RegExp(...) straight through, so regex: "(" fails with the engine's own text ("Invalid regular expression: /(/: Unterminated group"), which doesn't say which assertion it came from. Please wrap both new RegExp calls, catch the SyntaxError, and throw something like regex: "(" isn't a valid regular expression (Unterminated group). Then add a test for that and for invalid flags ({ pattern: 'a', flags: 'zz' }), which throws the same way.
anurag629
left a comment
There was a problem hiding this comment.
Thanks for the quick turnaround @bhushan4work. The regex fix is what I asked for: both constructors are wrapped, bad flags get their own message, and not-regex with a bad pattern still fails (test-command.test.ts:429-458). Those tests fail with the old text.ts. Merged with current dev, build, typecheck, test:coverage, lint (no new diagnostics), api:check, publint and docs:check pass.
One more thing before I merge, in equals (packages/cli/src/test/assertions/text.ts:78). Only the reply is trimmed. A long expected reply is most naturally written as a block scalar:
- equals: |
The Team plan is $19.YAML gives that value a trailing \n, so it never equals the trimmed reply. equals would always fail, which someone would notice, but not-equals would always pass, which nobody would. Please trim value too (turn.text.trim() === value.trim()) and add a test with a trailing newline for both equals and not-equals.
Two small ones while you're in there:
website/src/content/docs/core/testing.mdx:63now reads "Each assertion has one key,judgehas a model grade the reply..." sincecontainsmoved into the list. It needs a period after "one key".- The flags message repeats itself:
flags "zz" aren't valid regular expression flags (Invalid flags supplied to RegExp constructor 'zz'). I'd drop the parenthetical for flags. If you check the flags first withnew RegExp('', flags)and then compile the pattern, the nested try attext.ts:46-62goes away, and so do thethrow errorlines at 36 and 61, which can't be reached.
Heads up: #446 touches the same import block in assertions/index.ts, so whichever of the two lands second needs a small rebase there.
|
@bhushan4work #446 is merged, so this one now conflicts in the import lines of |
anurag629
left a comment
There was a problem hiding this comment.
Thanks @bhushan4work, all of it is in. equals trims both sides, with the trailing newline cases for equals and not-equals (they fail with the old line). Flags are checked first, the nested try and dead rethrows are gone, the flags message no longer repeats itself, and the docs sentence is fixed. With current dev merged in (including #446), build, typecheck, test:coverage, lint (same as dev), api:check and docs:check pass, and text.ts is at 100% of lines. Merging once CI is green.
|
Merged, thanks @bhushan4work. |
What does this change?
Adds
icontains,regex, andequalstext assertions tochatcops test, including input validation, automaticnot-support, unit tests, end-to-end coverage, and documentation.Closes #411
How I tested this
pnpm --filter @chatcops/cli exec vitest run tests/test-command.test.ts(28/28 tests passed)not-variants (1 passed)pnpm typecheckpnpm lintpnpm test:coverage(132 test files, 1,688+ tests passed)AI assistance
none
Checklist
devpnpm -r build,pnpm testandpnpm -r typecheckpass locallypnpm changeset) if this changescore,widgetorserver