Commit bf62322
authored
test(core): cover state typing in dowhile/dountil loop conditions (#18689)
## Description
Adds type-level regression tests for workflow `state` inference in
`dowhile`/`dountil` condition callbacks.
`createWorkflow` infers the workflow state type from `stateSchema`, so
`state` inside loop conditions is typed from the schema (the same typing
already available inside `createStep`). The existing
`workflow-schema-types.test-d.ts` covers `inputData` in
`dowhile`/`dountil` but never `state`, so this behavior could regress
silently. This PR closes that gap with three `expectTypeOf` checks:
- `state` is inferred from `stateSchema` in a `dowhile` condition
(`attempts: number`, `lastError: string | undefined`)
- same for a `dountil` condition
- with no `stateSchema`, `state` stays `unknown` (backward-compat
baseline)
```ts
const workflow = createWorkflow({
id: 'my-workflow',
inputSchema: z.object({ value: z.number() }),
outputSchema: z.object({ value: z.number() }),
stateSchema: z.object({ attempts: z.number() }),
}).dowhile(step, async ({ state }) => {
// state.attempts is typed as `number`
return state.attempts < 5;
});
```
## Related issue(s)
Closes #14627. The original report (state typed `unknown` in
`dowhile`/`dountil` conditions) no longer reproduces on `main` — it was
resolved by the `createWorkflow` schema-generic refactor in #18608. This
PR does not change runtime or types; it only adds the missing regression
coverage so the fix cannot silently regress, which is why it uses `Refs`
rather than `Closes`.
## Type of change
- [x] Test update
## Checklist
- [x] I have linked the related issue(s) in the description above
- [ ] I have made corresponding changes to the documentation (if
applicable)
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] I have addressed all Coderabbit comments on this PR1 parent 06ff9e0 commit bf62322
1 file changed
Lines changed: 68 additions & 0 deletions
Lines changed: 68 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
550 | 550 | | |
551 | 551 | | |
552 | 552 | | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
553 | 621 | | |
0 commit comments