|
7 | 7 | scaleProtocolTimeoutForComposition, |
8 | 8 | shouldClampToScreenshotForConcreteGpu, |
9 | 9 | applyConcreteGpuScreenshotClamp, |
| 10 | + shouldAutoDisableStreamingEncodeOnWin32Compound, |
10 | 11 | } from "./config.js"; |
11 | 12 | import type { EngineConfig } from "./config.js"; |
12 | 13 | import { isLowMemorySystem } from "./services/systemMemory.js"; |
@@ -518,6 +519,216 @@ describe("resolveConfig", () => { |
518 | 519 | }); |
519 | 520 | }); |
520 | 521 |
|
| 522 | + describe("shouldAutoDisableStreamingEncodeOnWin32Compound (helper)", () => { |
| 523 | + // Baseline: field-signal compound — win32 + software-GPU forced + workers=1, |
| 524 | + // duration unknown, user hasn't touched the env / overrides. |
| 525 | + const compound = { |
| 526 | + platform: "win32" as NodeJS.Platform, |
| 527 | + softwareGpuForced: true, |
| 528 | + workers: 1, |
| 529 | + compositionDurationSec: undefined as number | undefined, |
| 530 | + userExplicitlySet: false, |
| 531 | + }; |
| 532 | + |
| 533 | + it("triggers on the field-signal compound (win32 + software-GPU + workers=1)", () => { |
| 534 | + expect(shouldAutoDisableStreamingEncodeOnWin32Compound(compound)).toBe(true); |
| 535 | + }); |
| 536 | + |
| 537 | + it("does NOT trigger on linux or darwin (platform gate)", () => { |
| 538 | + expect( |
| 539 | + shouldAutoDisableStreamingEncodeOnWin32Compound({ ...compound, platform: "linux" }), |
| 540 | + ).toBe(false); |
| 541 | + expect( |
| 542 | + shouldAutoDisableStreamingEncodeOnWin32Compound({ ...compound, platform: "darwin" }), |
| 543 | + ).toBe(false); |
| 544 | + }); |
| 545 | + |
| 546 | + it("does NOT trigger without software-GPU forced (bypass on hardware paths)", () => { |
| 547 | + expect( |
| 548 | + shouldAutoDisableStreamingEncodeOnWin32Compound({ ...compound, softwareGpuForced: false }), |
| 549 | + ).toBe(false); |
| 550 | + }); |
| 551 | + |
| 552 | + it("does NOT trigger with parallel workers (workers > 1 has a different failure surface)", () => { |
| 553 | + expect(shouldAutoDisableStreamingEncodeOnWin32Compound({ ...compound, workers: 2 })).toBe( |
| 554 | + false, |
| 555 | + ); |
| 556 | + expect(shouldAutoDisableStreamingEncodeOnWin32Compound({ ...compound, workers: 4 })).toBe( |
| 557 | + false, |
| 558 | + ); |
| 559 | + }); |
| 560 | + |
| 561 | + it("does NOT trigger when the user explicitly set enableStreamingEncode (escape hatch)", () => { |
| 562 | + expect( |
| 563 | + shouldAutoDisableStreamingEncodeOnWin32Compound({ ...compound, userExplicitlySet: true }), |
| 564 | + ).toBe(false); |
| 565 | + }); |
| 566 | + |
| 567 | + it("does NOT trigger for short (<=120s) compositions when duration is known", () => { |
| 568 | + // 120s boundary is off (edge) |
| 569 | + expect( |
| 570 | + shouldAutoDisableStreamingEncodeOnWin32Compound({ |
| 571 | + ...compound, |
| 572 | + compositionDurationSec: 120, |
| 573 | + }), |
| 574 | + ).toBe(false); |
| 575 | + // 60s — clearly short, off |
| 576 | + expect( |
| 577 | + shouldAutoDisableStreamingEncodeOnWin32Compound({ |
| 578 | + ...compound, |
| 579 | + compositionDurationSec: 60, |
| 580 | + }), |
| 581 | + ).toBe(false); |
| 582 | + }); |
| 583 | + |
| 584 | + it("triggers when duration is known and exceeds 120s (heavy Windows composition)", () => { |
| 585 | + // 121s — just past the boundary, on |
| 586 | + expect( |
| 587 | + shouldAutoDisableStreamingEncodeOnWin32Compound({ |
| 588 | + ...compound, |
| 589 | + compositionDurationSec: 121, |
| 590 | + }), |
| 591 | + ).toBe(true); |
| 592 | + // 156s — matches the field signal, on |
| 593 | + expect( |
| 594 | + shouldAutoDisableStreamingEncodeOnWin32Compound({ |
| 595 | + ...compound, |
| 596 | + compositionDurationSec: 156, |
| 597 | + }), |
| 598 | + ).toBe(true); |
| 599 | + }); |
| 600 | + |
| 601 | + it("triggers when duration is undefined (config-layer wire-up reduces to 3-cond)", () => { |
| 602 | + // resolveConfig can't see composition duration at config time; the |
| 603 | + // three-condition compound is conservative on its own. |
| 604 | + expect( |
| 605 | + shouldAutoDisableStreamingEncodeOnWin32Compound({ |
| 606 | + ...compound, |
| 607 | + compositionDurationSec: undefined, |
| 608 | + }), |
| 609 | + ).toBe(true); |
| 610 | + }); |
| 611 | + }); |
| 612 | + |
| 613 | + describe("enableStreamingEncode (Windows compound auto-disable wire-up)", () => { |
| 614 | + const originalPlatform = process.platform; |
| 615 | + |
| 616 | + function setPlatform(platform: NodeJS.Platform) { |
| 617 | + Object.defineProperty(process, "platform", { value: platform, configurable: true }); |
| 618 | + } |
| 619 | + |
| 620 | + afterEach(() => { |
| 621 | + Object.defineProperty(process, "platform", { value: originalPlatform, configurable: true }); |
| 622 | + }); |
| 623 | + |
| 624 | + it("auto-disables on win32 + software-GPU + workers=1 + no user opt-in", () => { |
| 625 | + setPlatform("win32"); |
| 626 | + setEnv("PRODUCER_BROWSER_GPU_MODE", "software"); |
| 627 | + setEnv("PRODUCER_MAX_WORKERS", "1"); |
| 628 | + setEnv("PRODUCER_LOW_MEMORY_MODE", "true"); |
| 629 | + unsetEnv("PRODUCER_ENABLE_STREAMING_ENCODE"); |
| 630 | + |
| 631 | + const config = resolveConfig(); |
| 632 | + expect(config.enableStreamingEncode).toBe(false); |
| 633 | + expect(config.streamingEncodeAutoDisabledOnWin32Compound).toBe(true); |
| 634 | + }); |
| 635 | + |
| 636 | + it("leaves streaming-encode on when platform is linux", () => { |
| 637 | + setPlatform("linux"); |
| 638 | + setEnv("PRODUCER_BROWSER_GPU_MODE", "software"); |
| 639 | + setEnv("PRODUCER_MAX_WORKERS", "1"); |
| 640 | + setEnv("PRODUCER_LOW_MEMORY_MODE", "true"); |
| 641 | + unsetEnv("PRODUCER_ENABLE_STREAMING_ENCODE"); |
| 642 | + |
| 643 | + const config = resolveConfig(); |
| 644 | + expect(config.enableStreamingEncode).toBe(true); |
| 645 | + expect(config.streamingEncodeAutoDisabledOnWin32Compound).toBeUndefined(); |
| 646 | + }); |
| 647 | + |
| 648 | + it("leaves streaming-encode on when workers > 1", () => { |
| 649 | + setPlatform("win32"); |
| 650 | + setEnv("PRODUCER_BROWSER_GPU_MODE", "software"); |
| 651 | + setEnv("PRODUCER_MAX_WORKERS", "4"); |
| 652 | + setEnv("PRODUCER_LOW_MEMORY_MODE", "true"); |
| 653 | + unsetEnv("PRODUCER_ENABLE_STREAMING_ENCODE"); |
| 654 | + |
| 655 | + const config = resolveConfig(); |
| 656 | + expect(config.enableStreamingEncode).toBe(true); |
| 657 | + expect(config.streamingEncodeAutoDisabledOnWin32Compound).toBeUndefined(); |
| 658 | + }); |
| 659 | + |
| 660 | + it("respects explicit env opt-in (PRODUCER_ENABLE_STREAMING_ENCODE=true) on the compound", () => { |
| 661 | + setPlatform("win32"); |
| 662 | + setEnv("PRODUCER_BROWSER_GPU_MODE", "software"); |
| 663 | + setEnv("PRODUCER_MAX_WORKERS", "1"); |
| 664 | + setEnv("PRODUCER_LOW_MEMORY_MODE", "true"); |
| 665 | + setEnv("PRODUCER_ENABLE_STREAMING_ENCODE", "true"); |
| 666 | + |
| 667 | + const config = resolveConfig(); |
| 668 | + expect(config.enableStreamingEncode).toBe(true); |
| 669 | + expect(config.streamingEncodeAutoDisabledOnWin32Compound).toBeUndefined(); |
| 670 | + }); |
| 671 | + |
| 672 | + it("respects programmatic override enableStreamingEncode=true on the compound", () => { |
| 673 | + setPlatform("win32"); |
| 674 | + setEnv("PRODUCER_BROWSER_GPU_MODE", "software"); |
| 675 | + setEnv("PRODUCER_MAX_WORKERS", "1"); |
| 676 | + setEnv("PRODUCER_LOW_MEMORY_MODE", "true"); |
| 677 | + unsetEnv("PRODUCER_ENABLE_STREAMING_ENCODE"); |
| 678 | + |
| 679 | + const config = resolveConfig({ enableStreamingEncode: true }); |
| 680 | + expect(config.enableStreamingEncode).toBe(true); |
| 681 | + expect(config.streamingEncodeAutoDisabledOnWin32Compound).toBeUndefined(); |
| 682 | + }); |
| 683 | + |
| 684 | + it("triggers via disableGpu on win32 + workers=1 (browserGpuMode may still be 'auto')", () => { |
| 685 | + // --disable-gpu path: browserGpuMode may not be literal "software" but |
| 686 | + // Chrome is still routed to CPU raster. Field-signal compound applies. |
| 687 | + setPlatform("win32"); |
| 688 | + unsetEnv("PRODUCER_BROWSER_GPU_MODE"); |
| 689 | + setEnv("PRODUCER_DISABLE_GPU", "true"); |
| 690 | + setEnv("PRODUCER_MAX_WORKERS", "1"); |
| 691 | + unsetEnv("PRODUCER_LOW_MEMORY_MODE"); |
| 692 | + unsetEnv("PRODUCER_ENABLE_STREAMING_ENCODE"); |
| 693 | + |
| 694 | + const config = resolveConfig(); |
| 695 | + expect(config.enableStreamingEncode).toBe(false); |
| 696 | + expect(config.streamingEncodeAutoDisabledOnWin32Compound).toBe(true); |
| 697 | + }); |
| 698 | + |
| 699 | + it("triggers via lowMemoryMode alone on win32 + workers=1 (screenshot capture implied)", () => { |
| 700 | + // --low-memory-mode implies screenshot capture. Compound applies even |
| 701 | + // if browserGpuMode is not literal "software" (defense-in-depth: matches |
| 702 | + // the OR semantics in `softwareGpuForced`). |
| 703 | + setPlatform("win32"); |
| 704 | + unsetEnv("PRODUCER_BROWSER_GPU_MODE"); |
| 705 | + unsetEnv("PRODUCER_DISABLE_GPU"); |
| 706 | + setEnv("PRODUCER_MAX_WORKERS", "1"); |
| 707 | + setEnv("PRODUCER_LOW_MEMORY_MODE", "true"); |
| 708 | + unsetEnv("PRODUCER_ENABLE_STREAMING_ENCODE"); |
| 709 | + |
| 710 | + const config = resolveConfig(); |
| 711 | + expect(config.enableStreamingEncode).toBe(false); |
| 712 | + expect(config.streamingEncodeAutoDisabledOnWin32Compound).toBe(true); |
| 713 | + }); |
| 714 | + |
| 715 | + it("does not trigger when concurrency is 'auto' (workers not explicitly pinned)", () => { |
| 716 | + // Config-layer sees `concurrency === "auto"`, not a number — the |
| 717 | + // helper's numeric workers check treats NaN as "unknown, don't trigger". |
| 718 | + // Downstream workers may still resolve to 1 via lowMemoryMode, but the |
| 719 | + // config-time clamp is deliberately conservative. |
| 720 | + setPlatform("win32"); |
| 721 | + setEnv("PRODUCER_BROWSER_GPU_MODE", "software"); |
| 722 | + unsetEnv("PRODUCER_MAX_WORKERS"); |
| 723 | + setEnv("PRODUCER_LOW_MEMORY_MODE", "true"); |
| 724 | + unsetEnv("PRODUCER_ENABLE_STREAMING_ENCODE"); |
| 725 | + |
| 726 | + const config = resolveConfig(); |
| 727 | + expect(config.enableStreamingEncode).toBe(true); |
| 728 | + expect(config.streamingEncodeAutoDisabledOnWin32Compound).toBeUndefined(); |
| 729 | + }); |
| 730 | + }); |
| 731 | + |
521 | 732 | describe("lowMemoryMode", () => { |
522 | 733 | it("forces on for truthy PRODUCER_LOW_MEMORY_MODE values", () => { |
523 | 734 | setEnv("PRODUCER_LOW_MEMORY_MODE", "true"); |
|
0 commit comments