|
25 | 25 | * not display it. Pinning the rule at the RENDERER and not only at the |
26 | 26 | * wire is the point — a response field is the cheapest place for ancestry |
27 | 27 | * to reappear. |
| 28 | + * 6. **the unbound reason** (objectui#9217) — a runtime row's `reason` is the |
| 29 | + * platform's sentence for why the flow is not armed. It is shown VERBATIM |
| 30 | + * and muted, never as an alert, whether it names the deployment policy or |
| 31 | + * a real binding failure; a row without one renders exactly as before. |
28 | 32 | */ |
29 | 33 |
|
30 | 34 | import '@testing-library/jest-dom/vitest'; |
@@ -78,6 +82,28 @@ const CLONE_NOTICE = |
78 | 82 | 'off-switch — a cloned record-change or schedule flow is bound to its trigger and will run alongside ' + |
79 | 83 | 'the flow it was copied from.'; |
80 | 84 |
|
| 85 | +/** |
| 86 | + * `SCHEDULED_WORK_DISABLED_REASON` (`@objectstack/types` 17.5.0), the sentence |
| 87 | + * the automation engine puts in `FlowRuntimeState.reason` for a time-triggered |
| 88 | + * flow the deployment's scheduled-work switch left unarmed. Transcribed here as |
| 89 | + * FIXTURE text only: `@object-ui/app-shell` does not depend on that package, |
| 90 | + * and the page keeps no copy of it — what is pinned is that whatever sentence |
| 91 | + * arrives is rendered unedited. |
| 92 | + */ |
| 93 | +const POLICY_REASON = |
| 94 | + 'disabled by deployment policy — package-authored scheduled work is off on this deployment ' + |
| 95 | + '(OS_AUTOMATION_SCHEDULED_WORK_ENABLED is unset or not truthy), so no time trigger arms and no ' + |
| 96 | + 'packaged `defineJob` is scheduled. This is not a binding failure and nothing about the flow ' + |
| 97 | + 'needs fixing: set OS_AUTOMATION_SCHEDULED_WORK_ENABLED=true to run package-authored scheduled ' + |
| 98 | + "work on this deployment. It is OFF by default in every posture — a clock-driven workload's " + |
| 99 | + 'cost is a fact about the deployment, not about the flow.'; |
| 100 | + |
| 101 | +/** |
| 102 | + * The automation engine's `describeUnboundReason` sentence for a trigger that |
| 103 | + * is registered but failed to bind. Fixture text, like the one above. |
| 104 | + */ |
| 105 | +const BINDING_FAILED_REASON = "trigger 'record_change' is registered but binding failed — see earlier warnings"; |
| 106 | + |
81 | 107 | /* -------------------------------------------------------------------------- */ |
82 | 108 | /* Fake server */ |
83 | 109 | /* -------------------------------------------------------------------------- */ |
@@ -430,3 +456,92 @@ describe('no ancestry or drift surface', () => { |
430 | 456 | expect(screen.queryByText(/v3/)).toBeNull(); |
431 | 457 | }); |
432 | 458 | }); |
| 459 | + |
| 460 | +/* -------------------------------------------------------------------------- */ |
| 461 | +/* 6) The unbound reason, verbatim (objectui#9217) */ |
| 462 | +/* -------------------------------------------------------------------------- */ |
| 463 | + |
| 464 | +describe('the platform reason for an unbound flow', () => { |
| 465 | + /** The flow cell of ONE named row — where the name, and any reason, render. */ |
| 466 | + function flowCell(flowName: string): HTMLElement { |
| 467 | + const cell = screen.getByTestId(`packaged-flow-${flowName}`).querySelector('td'); |
| 468 | + if (!cell) throw new Error(`no flow cell for ${flowName}`); |
| 469 | + return cell; |
| 470 | + } |
| 471 | + |
| 472 | + /** |
| 473 | + * The one assertion every reason row owes: the platform's sentence is in its |
| 474 | + * row, whole and unedited, in muted text — and nothing in the row is an alert |
| 475 | + * or destructive-styled. |
| 476 | + */ |
| 477 | + function expectMutedVerbatim(flowName: string, sentence: string) { |
| 478 | + const row = screen.getByTestId(`packaged-flow-${flowName}`); |
| 479 | + const shown = within(row).getByText(sentence); |
| 480 | + expect(shown.textContent).toBe(sentence); |
| 481 | + expect(shown).toHaveClass('text-muted-foreground'); |
| 482 | + expect(shown).not.toHaveClass('text-destructive'); |
| 483 | + expect(within(row).queryAllByRole('alert')).toHaveLength(0); |
| 484 | + expect(row.querySelectorAll('.text-destructive')).toHaveLength(0); |
| 485 | + } |
| 486 | + |
| 487 | + it('shows a deployment-policy row with the platform sentence, muted, and not as a binding failure', async () => { |
| 488 | + fixture.runtime = [ |
| 489 | + ...fixture.runtime, |
| 490 | + { name: 'pkg_digest', enabled: true, bound: false, triggerType: 'schedule', reason: POLICY_REASON }, |
| 491 | + ]; |
| 492 | + fixture.meta = [...fixture.meta, packagedItem('pkg_digest', 'Daily digest')]; |
| 493 | + await renderPage(); |
| 494 | + |
| 495 | + expectMutedVerbatim('pkg_digest', POLICY_REASON); |
| 496 | + // The page adds no failure wording of its own around the policy sentence. |
| 497 | + expect(screen.getByTestId('packaged-flow-pkg_digest').textContent).not.toMatch(/binding failed/i); |
| 498 | + // The flow's activation is still shown as the engine reports it. |
| 499 | + expect(screen.getByRole('switch', { name: 'Activation for Daily digest' })).toBeChecked(); |
| 500 | + }); |
| 501 | + |
| 502 | + it('shows a real binding failure in the platform words too, muted (acceptance ②)', async () => { |
| 503 | + fixture.runtime = [ |
| 504 | + ...fixture.runtime, |
| 505 | + { |
| 506 | + name: 'pkg_sync', |
| 507 | + enabled: true, |
| 508 | + bound: false, |
| 509 | + triggerType: 'record_change', |
| 510 | + reason: BINDING_FAILED_REASON, |
| 511 | + }, |
| 512 | + ]; |
| 513 | + fixture.meta = [...fixture.meta, packagedItem('pkg_sync', 'Sync accounts')]; |
| 514 | + await renderPage(); |
| 515 | + |
| 516 | + expectMutedVerbatim('pkg_sync', BINDING_FAILED_REASON); |
| 517 | + }); |
| 518 | + |
| 519 | + it('renders a row without a reason exactly as before, older backends included', async () => { |
| 520 | + // `pkg_notify` (bound) and `pkg_escalate` (disabled) come from the default |
| 521 | + // fixture and carry no reason; `pkg_legacy` is an older backend's bare row. |
| 522 | + fixture.runtime = [...fixture.runtime, { name: 'pkg_legacy' }]; |
| 523 | + fixture.meta = [...fixture.meta, packagedItem('pkg_legacy', 'Legacy flow')]; |
| 524 | + await renderPage(); |
| 525 | + |
| 526 | + expect(flowCell('pkg_notify').textContent).toBe('Notify ownerpkg_notify'); |
| 527 | + expect(flowCell('pkg_escalate').textContent).toBe('Escalate casepkg_escalate'); |
| 528 | + expect(flowCell('pkg_legacy').textContent).toBe('Legacy flowpkg_legacy'); |
| 529 | + }); |
| 530 | + |
| 531 | + it('ignores a reason that is not a string', async () => { |
| 532 | + fixture.runtime = [ |
| 533 | + ...fixture.runtime, |
| 534 | + { name: 'pkg_numeric', enabled: true, bound: false, reason: 42 }, |
| 535 | + { name: 'pkg_object', enabled: true, bound: false, reason: { code: 'policy' } }, |
| 536 | + ]; |
| 537 | + fixture.meta = [ |
| 538 | + ...fixture.meta, |
| 539 | + packagedItem('pkg_numeric', 'Numeric reason'), |
| 540 | + packagedItem('pkg_object', 'Object reason'), |
| 541 | + ]; |
| 542 | + await renderPage(); |
| 543 | + |
| 544 | + expect(flowCell('pkg_numeric').textContent).toBe('Numeric reasonpkg_numeric'); |
| 545 | + expect(flowCell('pkg_object').textContent).toBe('Object reasonpkg_object'); |
| 546 | + }); |
| 547 | +}); |
0 commit comments