|
1 | 1 | /* eslint-disable @typescript-eslint/no-non-null-assertion */ |
| 2 | +import {FeatureFlags} from "@actions/expressions/features"; |
2 | 3 | import {nullTrace} from "../test-utils/null-trace.js"; |
3 | 4 | import {parseWorkflow} from "../workflows/workflow-parser.js"; |
4 | 5 | import {convertWorkflowTemplate, ErrorPolicy} from "./convert.js"; |
@@ -578,4 +579,140 @@ jobs: |
578 | 579 | } |
579 | 580 | }); |
580 | 581 | }); |
| 582 | + |
| 583 | + describe("schedule timezone with feature flags", () => { |
| 584 | + it("allows timezone when allowCronTimezone is enabled", async () => { |
| 585 | + const result = parseWorkflow( |
| 586 | + { |
| 587 | + name: "wf.yaml", |
| 588 | + content: `on: |
| 589 | + schedule: |
| 590 | + - cron: '0 0 * * *' |
| 591 | + timezone: America/New_York |
| 592 | +jobs: |
| 593 | + build: |
| 594 | + runs-on: ubuntu-latest` |
| 595 | + }, |
| 596 | + nullTrace |
| 597 | + ); |
| 598 | + |
| 599 | + const template = await convertWorkflowTemplate(result.context, result.value!, undefined, { |
| 600 | + errorPolicy: ErrorPolicy.TryConversion, |
| 601 | + featureFlags: new FeatureFlags({allowCronTimezone: true}) |
| 602 | + }); |
| 603 | + |
| 604 | + expect(result.context.errors.getErrors()).toHaveLength(0); |
| 605 | + expect(template.events?.schedule).toHaveLength(1); |
| 606 | + expect(template.events?.schedule?.[0]).toEqual({ |
| 607 | + cron: "0 0 * * *", |
| 608 | + timezone: "America/New_York" |
| 609 | + }); |
| 610 | + }); |
| 611 | + |
| 612 | + it("reports error when timezone is present but allowCronTimezone is disabled", async () => { |
| 613 | + const result = parseWorkflow( |
| 614 | + { |
| 615 | + name: "wf.yaml", |
| 616 | + content: `on: |
| 617 | + schedule: |
| 618 | + - cron: '0 0 * * *' |
| 619 | + timezone: America/New_York |
| 620 | +jobs: |
| 621 | + build: |
| 622 | + runs-on: ubuntu-latest` |
| 623 | + }, |
| 624 | + nullTrace |
| 625 | + ); |
| 626 | + |
| 627 | + const template = await convertWorkflowTemplate(result.context, result.value!, undefined, { |
| 628 | + errorPolicy: ErrorPolicy.TryConversion, |
| 629 | + featureFlags: new FeatureFlags({allowCronTimezone: false}) |
| 630 | + }); |
| 631 | + |
| 632 | + // When timezone feature is disabled, error points at the timezone key |
| 633 | + expect(result.context.errors.getErrors()).toHaveLength(1); |
| 634 | + expect(result.context.errors.getErrors()[0].message).toContain("Key 'timezone' is not supported"); |
| 635 | + // Schedule entry is dropped due to unsupported key |
| 636 | + expect(template.events?.schedule).toHaveLength(0); |
| 637 | + }); |
| 638 | + |
| 639 | + it("reports error when timezone is present with no feature flags provided", async () => { |
| 640 | + const result = parseWorkflow( |
| 641 | + { |
| 642 | + name: "wf.yaml", |
| 643 | + content: `on: |
| 644 | + schedule: |
| 645 | + - cron: '0 0 * * *' |
| 646 | + timezone: America/New_York |
| 647 | +jobs: |
| 648 | + build: |
| 649 | + runs-on: ubuntu-latest` |
| 650 | + }, |
| 651 | + nullTrace |
| 652 | + ); |
| 653 | + |
| 654 | + await convertWorkflowTemplate(result.context, result.value!, undefined, { |
| 655 | + errorPolicy: ErrorPolicy.TryConversion |
| 656 | + }); |
| 657 | + |
| 658 | + // Default is timezone disabled, so error points at the timezone key |
| 659 | + expect(result.context.errors.getErrors()).toHaveLength(1); |
| 660 | + expect(result.context.errors.getErrors()[0].message).toContain("Key 'timezone' is not supported"); |
| 661 | + }); |
| 662 | + |
| 663 | + it("reports error when cron is missing from schedule entry", async () => { |
| 664 | + const result = parseWorkflow( |
| 665 | + { |
| 666 | + name: "wf.yaml", |
| 667 | + content: `on: |
| 668 | + schedule: |
| 669 | + - timezone: America/New_York |
| 670 | +jobs: |
| 671 | + build: |
| 672 | + runs-on: ubuntu-latest` |
| 673 | + }, |
| 674 | + nullTrace |
| 675 | + ); |
| 676 | + |
| 677 | + const template = await convertWorkflowTemplate(result.context, result.value!, undefined, { |
| 678 | + errorPolicy: ErrorPolicy.TryConversion, |
| 679 | + featureFlags: new FeatureFlags({allowCronTimezone: true}) |
| 680 | + }); |
| 681 | + |
| 682 | + // Both schema validation and converter report the missing cron |
| 683 | + expect(result.context.errors.getErrors().length).toBeGreaterThanOrEqual(1); |
| 684 | + const errorMessages = result.context.errors |
| 685 | + .getErrors() |
| 686 | + .map(e => e.message) |
| 687 | + .join(", "); |
| 688 | + expect(errorMessages).toMatch(/Required property is missing: cron|Missing required key 'cron'/); |
| 689 | + expect(template.events?.schedule).toHaveLength(0); |
| 690 | + }); |
| 691 | + |
| 692 | + it("converts schedule without timezone when allowCronTimezone is enabled", async () => { |
| 693 | + const result = parseWorkflow( |
| 694 | + { |
| 695 | + name: "wf.yaml", |
| 696 | + content: `on: |
| 697 | + schedule: |
| 698 | + - cron: '0 0 * * *' |
| 699 | +jobs: |
| 700 | + build: |
| 701 | + runs-on: ubuntu-latest` |
| 702 | + }, |
| 703 | + nullTrace |
| 704 | + ); |
| 705 | + |
| 706 | + const template = await convertWorkflowTemplate(result.context, result.value!, undefined, { |
| 707 | + errorPolicy: ErrorPolicy.TryConversion, |
| 708 | + featureFlags: new FeatureFlags({allowCronTimezone: true}) |
| 709 | + }); |
| 710 | + |
| 711 | + expect(result.context.errors.getErrors()).toHaveLength(0); |
| 712 | + expect(template.events?.schedule).toHaveLength(1); |
| 713 | + expect(template.events?.schedule?.[0]).toEqual({ |
| 714 | + cron: "0 0 * * *" |
| 715 | + }); |
| 716 | + }); |
| 717 | + }); |
581 | 718 | }); |
0 commit comments