Skip to content

test: cover trial-email dispatch and pre-warm maintenance commands#198

Open
dan2k3k4 wants to merge 2 commits into
devfrom
advisor/008-trial-and-prewarm-command-tests
Open

test: cover trial-email dispatch and pre-warm maintenance commands#198
dan2k3k4 wants to merge 2 commits into
devfrom
advisor/008-trial-and-prewarm-command-tests

Conversation

@dan2k3k4

@dan2k3k4 dan2k3k4 commented Jul 1, 2026

Copy link
Copy Markdown
Member

Adds test coverage for the trial-email dispatch commands and the pre-warm instance maintenance command.

Greptile Summary

This PR adds feature test coverage for three trial-email dispatch commands (dispatch-midtrial-emails, dispatch-trial-complete-emails, dispatch-trial-complete-stage-removal) and the maintain-prewarm-instances maintenance command. All four files are new test-only additions with no changes to production code.

  • Each email-dispatch test class covers the happy path, every exclusion guard (already-sent, future timestamp, non-trial, null timestamp, store-app flag), and the per-run cap.
  • The pre-warm maintenance tests cover no-excess, excess removal, at-target no-removal, --app UUID filtering, --refresh-all, confirmation-prompt abort, and the early-return no-apps path, with EnsureUnallocatedAppInstancesJob dispatch assertions on every applicable path.

Confidence Score: 5/5

Pure test additions with no production code changes; all new tests are well-scoped and correctly structured.

All four files are new feature tests with no production logic modified. Each test class correctly uses Queue::fake(), saveQuietly(), and Queue::assertPushed / assertNotPushed. The two gaps flagged in the previous review round have both been addressed. No logic errors or missing guards were found.

No files require special attention.

Important Files Changed

Filename Overview
tests/Feature/Console/Commands/DispatchMidtrialEmailJobsCommandTest.php New test covering mid-trial email dispatch: eligible dispatch, already-sent guard, future-time guard, non-trial guard, null-time guard, store-app flag guard, and per-run cap.
tests/Feature/Console/Commands/DispatchTrialCompleteEmailJobsCommandTest.php New test mirroring the mid-trial email pattern for trial-complete emails; covers the same set of guards and the per-run cap.
tests/Feature/Console/Commands/DispatchTrialCompleteStageRemovalJobsCommandTest.php New test for the stage-removal command; correctly omits the store-app flag test (command has no such filter) and adds a status-guard test unique to this command.
tests/Feature/Console/Commands/MaintainPreWarmInstancesCommandTest.php New test for the pre-warm maintenance command; covers all paths including --refresh-all flag and the two previously flagged gaps now addressed.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Test
    participant Artisan
    participant Command
    participant DB
    participant Queue

    Note over Test,Queue: Trial-email dispatch commands
    Test->>DB: createStoreApp() + createInstance()
    Test->>Artisan: "artisan('polydock:dispatch-*')"
    Artisan->>Command: handle()
    Command->>DB: query eligible instances
    DB-->>Command: collection
    Command->>Queue: "Job::dispatch(instance->id)"
    Command-->>Artisan: EXIT 0
    Test->>Queue: assertPushed / assertNotPushed

    Note over Test,Queue: MaintainPreWarmInstances command
    Test->>DB: createStoreApp(target) + createUnallocatedInstance()
    Test->>Artisan: artisan('polydock:maintain-prewarm-instances')
    Artisan->>Command: handle()
    Command->>DB: query PolydockStoreApp
    DB-->>Command: apps collection
    alt no apps found
        Command-->>Artisan: EXIT 0
    else apps found + confirmed
        loop each app
            Command->>DB: queueUnallocatedInstancesForRemoval()
        end
        Command->>Queue: EnsureUnallocatedAppInstancesJob::dispatch()
        Command-->>Artisan: EXIT 0
    end
    Test->>Queue: assertPushed(EnsureUnallocatedAppInstancesJob, 1)
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Test
    participant Artisan
    participant Command
    participant DB
    participant Queue

    Note over Test,Queue: Trial-email dispatch commands
    Test->>DB: createStoreApp() + createInstance()
    Test->>Artisan: "artisan('polydock:dispatch-*')"
    Artisan->>Command: handle()
    Command->>DB: query eligible instances
    DB-->>Command: collection
    Command->>Queue: "Job::dispatch(instance->id)"
    Command-->>Artisan: EXIT 0
    Test->>Queue: assertPushed / assertNotPushed

    Note over Test,Queue: MaintainPreWarmInstances command
    Test->>DB: createStoreApp(target) + createUnallocatedInstance()
    Test->>Artisan: artisan('polydock:maintain-prewarm-instances')
    Artisan->>Command: handle()
    Command->>DB: query PolydockStoreApp
    DB-->>Command: apps collection
    alt no apps found
        Command-->>Artisan: EXIT 0
    else apps found + confirmed
        loop each app
            Command->>DB: queueUnallocatedInstancesForRemoval()
        end
        Command->>Queue: EnsureUnallocatedAppInstancesJob::dispatch()
        Command-->>Artisan: EXIT 0
    end
    Test->>Queue: assertPushed(EnsureUnallocatedAppInstancesJob, 1)
Loading

Reviews (2): Last reviewed commit: "test: assert refill dispatch in app-filt..." | Re-trigger Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant