Stop reading a passed step's result as its error - #211
Merged
Merged
Conversation
attachStepLogger bound one listener to both step.passed and step.failed and treated the second argument as an error either way. CodeceptJS emits `event.step.passed, step, val` (lib/step/record.js), where val is the promise returned by step.run(), so every passing step arrived carrying a truthy "error". The first step of a batch was therefore recorded as failed with `errorToString(promise)` — "[object Promise]" — and set batchFailed, whose `if (batchFailed) return` gate then dropped every later step. A four-command batch that fully succeeded reported one phantom failure and nothing else, and assertionsTarget kept only the first assertion, which is what feeds recordVerification and the generated test. Pass only the step for step.passed. Pass/fail is unaffected — attempt() keys off whether execute() throws — so this only corrects what gets reported. The existing tests emitted step.passed with a single argument, which is why this stayed invisible; the new one emits the result alongside it, as CodeceptJS does. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JCYmFZvUsENZBx71Yqojs6
…d-result # Conflicts: # CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while investigating a failed Tester session (Langfuse trace
078285ca5b32d556be2695c50141c5c8, sessionVariableIncreasedBrown198). Every successfulformcall in that run reported a contradiction:{ "success": true, "message": "Form completed successfully with 4 commands.", "commandsExecuted": 4, "attempts": [{"command": "I.pressKey([\"Meta\",\"a\"])", "success": false, "error": "[object Promise]"}] }The bug
attachStepLoggerbinds one listener to bothstep.passedandstep.failed, and reads argument 2 as the error either way:But CodeceptJS emits the passing step's own return value as that argument —
codeceptjs/lib/step/record.js:57:valis a promise, soerrorToStringfalls through toerror.toString()and yields"[object Promise]".The phantom entry is the visible half. The damage is the other half: it sets
batchFailed = true, andif (batchFailed) returnthen drops every later step. That is why only one attempt appears where four commands ran, and whyassertionsTargetkeeps only the first assertion of a multi-line block — the same array that feedsrecordVerificationand the generated test file.Pass/fail is unaffected:
attempt()keys off whetherexecute()throws. What changes is what gets reported — which is what the AI reads before choosing its next action.The fix
Pass only the step for
step.passed.Tests
The existing tests in
tests/unit/executed-steps.test.tsall emitstep.passedwith a single argument, which is exactly why this stayed invisible. The new test emits the result alongside the step, as CodeceptJS does, and asserts all three passing steps are recorded. Onmainit records 1 of 3.🤖 Generated with Claude Code
https://claude.ai/code/session_01JCYmFZvUsENZBx71Yqojs6