Skip to content

Rebuilds update workflow state machine#1372

Open
James-Voight wants to merge 4 commits intosillsdev:developfrom
judah-sotomayor:Rebuilds-Update-WorkflowStateMachine
Open

Rebuilds update workflow state machine#1372
James-Voight wants to merge 4 commits intosillsdev:developfrom
judah-sotomayor:Rebuilds-Update-WorkflowStateMachine

Conversation

@James-Voight
Copy link

@James-Voight James-Voight commented Nov 5, 2025

Rebuilds: Update WorkflowStateMachine
#1324

Summary by CodeRabbit

  • New Features
    • Automatic product publishing on rebuild completion when a project enables the setting.
    • Project owners receive email notifications when an automatic publish completes.
    • Email translations added/updated for English, Spanish (Latin America) and French.
    • Workflow runs now indicate when a run was performed automatically.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 5, 2025

📝 Walkthrough

Walkthrough

Propagates an isAutomatic flag into product actions and workflow instances, adds autoPublishOnRebuild to workflow input/guards, introduces guarded auto-transition to publish after build, notifies project owner via queued email on automatic publish, and adds locale keys for the notification.

Changes

Cohort / File(s) Summary
Product action API
src/lib/products/server.ts
Added optional isAutomatic: boolean = false parameter to doProductAction and pass it into Workflow.create for Rebuild/Republish paths.
Workflow types & guards
src/lib/workflowTypes.ts
Added isAutomatic to WorkflowInstanceContext/WorkflowConfig, added autoPublishOnRebuild to WorkflowInput, and introduced autoPublishOnRebuild() guard (included in Guards).
State machine
src/lib/server/workflow/state-machine.ts
Added isAutomatic/autoPublishOnRebuild context fields, new guarded transition from Build_SuccessfulProduct_Publish when guard passes, and calls to notifyAutoPublishOwner() in relevant Publish_Completed transitions.
Workflow instance management
src/lib/server/workflow/index.ts
Selects AutoPublishOnRebuild from Project, parses/initializes Context with isAutomatic defaulting to false, surfaces autoPublishOnRebuild/isAutomatic in input/output, and filters autoPublishOnRebuild from persisted Context where applicable.
DB procedures / Notifications
src/lib/server/workflow/dbProcedures.ts
Added notifyAutoPublishOwner(productId: string) to load product/project, early-exit if no owner, and enqueue a BullMQ Emails job with autoPublishOnRebuildCompleted message key and projectName/productName properties.
Job executors
src/lib/server/job-executors/product.ts, src/lib/server/job-executors/system.ts
Include isAutomatic: false in Workflow.create() / instance Context payload when creating/upserting workflow instances.
Email localization
src/lib/server/email-service/locales/en-us.json, src/lib/server/email-service/locales/es-419.json, src/lib/server/email-service/locales/fr-FR.json
Added autoPublishOnRebuildCompleted keys under notifications.body and notifications.subject with localized templates referencing projectName and productName.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant API as Product API
    participant Workflow as Workflow Engine
    participant Build as Build Service
    participant Publish as Publish Service
    participant Queue as Notification Queue

    User->>API: Trigger Rebuild (isAutomatic=true)
    API->>Workflow: create instance (isAutomatic=true, autoPublishOnRebuild)
    Workflow->>Build: run build
    Build-->>Workflow: Build Successful

    rect rgb(230, 245, 230)
        note right of Workflow: Evaluate guard:\nautoPublishOnRebuild && isAutomatic && type=Rebuild
    end

    alt Guard passes
        Workflow->>Publish: transition to Publish
        Publish-->>Workflow: Publish Completed
        Workflow->>Queue: notifyAutoPublishOwner(productId)
        Queue-->>Owner: enqueue email (autoPublishOnRebuildCompleted)
    else Guard fails
        Workflow->>Workflow: await manual publish
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • chrisvire
  • 7dev7urandom

Poem

🐰 A rebuild hop, a quiet cheer,
Flags set true, the publish near,
Build succeeds, the workflow sings,
An owner’s inbox softly rings,
Rabbit claps — the auto-publish done. 🎉

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'Rebuilds update workflow state machine' clearly summarizes the main change—updating the workflow state machine in the rebuild process. The changes extensively modify src/lib/server/workflow/state-machine.ts with new auto-transitions, guard-based paths, and owner notifications after rebuild completion.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@James-Voight James-Voight force-pushed the Rebuilds-Update-WorkflowStateMachine branch from ae8eadb to 49a9ee3 Compare November 13, 2025 17:18
Copy link
Contributor

@FyreByrd FyreByrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start. Hopefully we can get testing figured out soon.

options: new Set(product.ProductDefinition[flowType].WorkflowOptions),
workflowType: product.ProductDefinition[flowType].Type
workflowType: product.ProductDefinition[flowType].Type,
isAutomatic: false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since doProductAction is likely going to be used for the software update feature, you will probably want to have isAutomatic as either an optional parameter, or a parameter with a default value. Either way you do it, you should be able to modify the function signature of doProductAction without needing to modify the callsites.

}
});
if (!product?.Project.OwnerId) return;
void getQueues().Emails.add(`Notify Owner of Auto Publish for Product #${productId}`, {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of the void keyword here? Why not await?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the same question in a few other locations.

@James-Voight James-Voight force-pushed the Rebuilds-Update-WorkflowStateMachine branch from 49a9ee3 to 65510c3 Compare November 17, 2025 14:04
@James-Voight James-Voight marked this pull request as ready for review November 17, 2025 14:11
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (4)
src/lib/server/workflow/dbProcedures.ts (1)

55-82: Consider adding error handling for robustness.

The function silently returns on missing product or owner without logging. Consider adding logging or error handling for:

  • Database read failures
  • Missing product scenarios
  • Email queueing failures

This would aid debugging if auto-publish notifications fail to send.

Example:

 export async function notifyAutoPublishOwner(productId: string) {
   const product = await DatabaseReads.products.findUnique({
     where: { Id: productId },
     select: {
       ProductDefinition: {
         select: {
           Name: true
         }
       },
       Project: {
         select: {
           Name: true,
           OwnerId: true
         }
       }
     }
   });
-  if (!product?.Project.OwnerId) return;
+  if (!product) {
+    console.warn(`notifyAutoPublishOwner: Product ${productId} not found`);
+    return;
+  }
+  if (!product.Project.OwnerId) {
+    console.warn(`notifyAutoPublishOwner: No owner for product ${productId}`);
+    return;
+  }
   await getQueues().Emails.add(`Notify Owner of Auto Publish for Product #${productId}`, {
     type: BullMQ.JobType.Email_SendNotificationToUser,
     userId: product.Project.OwnerId,
     messageKey: 'autoPublishOnRebuildCompleted',
     messageProperties: {
       projectName: product.Project.Name ?? '',
       productName: product.ProductDefinition.Name ?? ''
     }
   });
 }
src/lib/server/workflow/state-machine.ts (1)

815-846: Align notification condition more tightly with the auto-publish guard

The owner notification on Publish_Completed is currently gated by:

if (context.autoPublishOnRebuild && context.isAutomatic) {
  void notifyAutoPublishOwner(context.productId);
}

whereas the transition into auto‑publish is guarded by autoPublishOnRebuild (which also checks workflowType === WorkflowType.Rebuild).

Two suggestions:

  1. Match the guard semantics
    If the email is intended only for “auto publish on rebuild” runs (not any future workflow that might set isAutomatic), consider also checking the workflow type, e.g.:

    if (
      context.autoPublishOnRebuild &&
      context.isAutomatic &&
      context.workflowType === WorkflowType.Rebuild
    ) {
      void notifyAutoPublishOwner(context.productId);
    }

    This keeps the notification tied to the same high‑level condition as the auto‑publish path.

  2. Optional: handle notification failures explicitly
    notifyAutoPublishOwner is async and is fire‑and‑forget here. That matches the existing pattern for queueing jobs, but if you ever see unhandled rejection noise from this path, consider adding a .catch inside notifyAutoPublishOwner or here to log and swallow failures.

src/lib/server/workflow/index.ts (2)

150-205: Snapshot restore defaults isAutomatic correctly and exposes new inputs

Parsing instance.Context into a WorkflowInstanceContext, then applying:

context.isAutomatic ??= false;

before building the returned context and input:

  • Gives older snapshots (which lack isAutomatic) a safe default of false.
  • Ensures input.isAutomatic and context.isAutomatic stay in sync.
  • Adds autoPublishOnRebuild to input based on the current Project flag, so snapshot restores always reflect the latest project setting rather than whatever might have been in the stored context.

One small nit: after the nullish‑assignment, context.isAutomatic ?? false in the input construction is redundant; you can just use context.isAutomatic if you want to simplify slightly.


366-405: Consider using the filtered context for both create and update

In createSnapshot, you build a filtered context that strips non‑instance fields:

const filtered = {
  ...context,
  productId: undefined,
  hasAuthors: undefined,
  hasReviewers: undefined,
  autoPublishOnRebuild: undefined,
  productType: undefined,
  options: undefined
} as WorkflowInstanceContext;

but only use it on update, while create still persists the full context:

create: {
  State: ...,
  Context: JSON.stringify(context),
  ...
},
update: {
  State: ...,
  Context: JSON.stringify(filtered)
}

That means the very first row for a workflow instance may still serialize autoPublishOnRebuild, productId, etc., even though subsequent updates do not.

Behavior-wise this is harmless (the restore path rebuilds input from DB fields and overlays it), but for consistency and to keep workflowInstances.Context strictly to WorkflowInstanceContext, you could also use filtered in the create branch:

-      create: {
-        State: Workflow.stateName(this.currentState ?? { id: 'Start' }),
-        Context: JSON.stringify(context),
+      create: {
+        State: Workflow.stateName(this.currentState ?? { id: 'Start' }),
+        Context: JSON.stringify(filtered),
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a527d1d and 65510c3.

📒 Files selected for processing (10)
  • src/lib/products/server.ts (2 hunks)
  • src/lib/server/email-service/locales/en-us.json (2 hunks)
  • src/lib/server/email-service/locales/es-419.json (2 hunks)
  • src/lib/server/email-service/locales/fr-FR.json (2 hunks)
  • src/lib/server/job-executors/product.ts (1 hunks)
  • src/lib/server/job-executors/system.ts (1 hunks)
  • src/lib/server/workflow/dbProcedures.ts (2 hunks)
  • src/lib/server/workflow/index.ts (5 hunks)
  • src/lib/server/workflow/state-machine.ts (5 hunks)
  • src/lib/workflowTypes.ts (4 hunks)
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-09-12T14:07:02.200Z
Learnt from: FyreByrd
Repo: sillsdev/appbuilder-portal PR: 1283
File: src/routes/(authenticated)/tasks/[product_id]/+page.server.ts:285-303
Timestamp: 2025-09-12T14:07:02.200Z
Learning: In src/routes/(authenticated)/tasks/[product_id]/+page.server.ts, FyreByrd prefers to optimize filterAvailableActions by creating Sets at the caller level rather than inside the function, so the function would take Set<number> arguments instead of arrays for better performance and separation of concerns.

Applied to files:

  • src/lib/products/server.ts
📚 Learning: 2025-09-04T14:26:59.326Z
Learnt from: FyreByrd
Repo: sillsdev/appbuilder-portal PR: 1227
File: src/lib/server/job-executors/product.ts:247-250
Timestamp: 2025-09-04T14:26:59.326Z
Learning: In src/lib/server/job-executors/product.ts, the createLocal function's catch block returns false instead of rethrowing errors. This was implemented intentionally to fix another issue, so any changes to this error handling should be carefully evaluated for downstream impacts.

Applied to files:

  • src/lib/products/server.ts
  • src/lib/server/job-executors/product.ts
📚 Learning: 2025-09-04T16:23:55.891Z
Learnt from: FyreByrd
Repo: sillsdev/appbuilder-portal PR: 1227
File: src/lib/server/job-executors/product.ts:247-250
Timestamp: 2025-09-04T16:23:55.891Z
Learning: In src/lib/server/job-executors/product.ts, createLocal’s catch should log the error via job.log with relevant context (projectId/productDefinitionId/storeId) and still return false to preserve the intentional “no-retry” behavior.

Applied to files:

  • src/lib/server/job-executors/product.ts
📚 Learning: 2025-09-12T14:02:04.558Z
Learnt from: FyreByrd
Repo: sillsdev/appbuilder-portal PR: 1283
File: src/lib/server/workflow/index.ts:52-74
Timestamp: 2025-09-12T14:02:04.558Z
Learning: In the appbuilder-portal codebase, when a Product exists, it always has an associated Project relationship. The Project._count fields (Authors, Reviewers) are safe to access directly when the Product query returns a result.

Applied to files:

  • src/lib/server/workflow/index.ts
🧬 Code graph analysis (3)
src/lib/server/workflow/dbProcedures.ts (3)
src/lib/server/job-executors/build.ts (1)
  • product (11-131)
src/lib/server/job-executors/publish.ts (1)
  • product (10-158)
src/lib/server/database/prisma.ts (1)
  • DatabaseReads (22-22)
src/lib/server/workflow/state-machine.ts (2)
src/lib/workflowTypes.ts (1)
  • autoPublishOnRebuild (265-271)
src/lib/server/workflow/dbProcedures.ts (1)
  • notifyAutoPublishOwner (55-82)
src/lib/server/workflow/index.ts (1)
src/lib/workflowTypes.ts (1)
  • WorkflowInstanceContext (104-137)
🔇 Additional comments (12)
src/lib/server/job-executors/product.ts (1)

247-248: LGTM: Correct initialization for manual workflow creation.

The isAutomatic: false field is appropriately set for manually created products via createLocal.

src/lib/server/job-executors/system.ts (1)

976-976: LGTM: Appropriate default for migrated workflows.

The isAutomatic: false initialization is correct for workflow instances created during migration, as these represent pre-existing workflows rather than automatically triggered ones.

src/lib/products/server.ts (2)

7-11: LGTM: Default parameter addresses previous feedback.

The addition of the isAutomatic = false default parameter properly addresses the past review comment about making this parameter optional for backward compatibility.

Based on learnings


56-57: LGTM: Correct propagation of isAutomatic flag.

The isAutomatic parameter is properly passed to Workflow.create for rebuild/republish workflows.

src/lib/server/email-service/locales/en-us.json (1)

76-76: LGTM: English translations added correctly.

The autoPublishOnRebuildCompleted translation keys are properly added with appropriate English messages and correct placeholder variables (projectName, productName).

Also applies to: 118-118

src/lib/workflowTypes.ts (4)

2-3: LGTM: Correct import optimization.

The split between value import (WorkflowType) and type-only import (RoleId) is appropriate, as WorkflowType is used in the runtime comparison at line 269.


136-136: LGTM: Consistent field additions.

The isAutomatic: boolean field is properly added to both WorkflowInstanceContext and WorkflowConfig, ensuring type consistency across the workflow system.

Also applies to: 186-186


193-193: LGTM: Appropriate field addition.

The autoPublishOnRebuild: boolean field on WorkflowInput correctly extends the workflow configuration for the auto-publish feature.


265-272: LGTM: Guard logic is correct.

The autoPublishOnRebuild guard properly checks all three required conditions:

  1. Feature is enabled (autoPublishOnRebuild)
  2. Workflow is automatic (isAutomatic)
  3. Workflow type is Rebuild

The function is correctly added to the Guards type union.

src/lib/server/workflow/state-machine.ts (2)

17-25: Context wiring for isAutomatic / autoPublishOnRebuild looks consistent

Importing autoPublishOnRebuild and notifyAutoPublishOwner, and carrying isAutomatic, hasReviewers, and autoPublishOnRebuild through the machine context from input matches how the guards and notifications are used later. This keeps WorkflowContext and WorkflowInput aligned so both guard-based filtering and runtime guards have the data they need. I don’t see issues with this wiring.

Also applies to: 60-68


528-563: Auto-publish transition on Build_Successful is correctly guarded

The new Build_Successful transition that jumps directly to Product_Publish under autoPublishOnRebuild:

  • Is placed before the normal “verify and publish” path, so it naturally short-circuits only when the guard passes.
  • Uses includeWhen.guards: [autoPublishOnRebuild] plus guard: autoPublishOnRebuild, keeping the visualization/happy‑path filtering and runtime behavior in sync.
  • Leaves the existing Google Play startup path and the default manual path untouched.

This matches the intent of an opt‑in automatic rebuild publish without breaking existing flows.

src/lib/server/workflow/index.ts (1)

51-76: Project-level AutoPublishOnRebuild is plumbed cleanly into workflow input

Extending the initial product query to select Project.AutoPublishOnRebuild and threading it into WorkflowInput.autoPublishOnRebuild (alongside hasAuthors / hasReviewers) is straightforward and keeps all the auto‑publish inputs together. The !!check?.Project.AutoPublishOnRebuild coercion means missing or null values safely default to false. This looks good.

@James-Voight James-Voight force-pushed the Rebuilds-Update-WorkflowStateMachine branch from 4016687 to 53e957c Compare January 13, 2026 17:26
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/lib/server/workflow/index.ts (1)

189-207: Minor redundancy in isAutomatic fallback.

Line 190 already ensures context.isAutomatic is false if undefined (via ??=), so the ?? false on line 203 is redundant. However, this doesn't affect correctness.

Optional cleanup
       input: {
         workflowType: instance.WorkflowDefinition.Type,
         productType: instance.WorkflowDefinition.ProductType,
         options: new Set(instance.WorkflowDefinition.WorkflowOptions),
         hasAuthors: !!instance.Product.Project._count.Authors,
         hasReviewers: !!instance.Product.Project._count.Reviewers,
         autoPublishOnRebuild: !!instance.Product.Project.AutoPublishOnRebuild,
-        isAutomatic: context.isAutomatic ?? false,
+        isAutomatic: context.isAutomatic,
         productId,
         existingApp: !!context.environment[ENVKeys.GOOGLE_PLAY_EXISTING]
       }
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4016687 and 53e957c.

📒 Files selected for processing (10)
  • src/lib/products/server.ts
  • src/lib/server/email-service/locales/en-us.json
  • src/lib/server/email-service/locales/es-419.json
  • src/lib/server/email-service/locales/fr-FR.json
  • src/lib/server/job-executors/product.ts
  • src/lib/server/job-executors/system.ts
  • src/lib/server/workflow/dbProcedures.ts
  • src/lib/server/workflow/index.ts
  • src/lib/server/workflow/state-machine.ts
  • src/lib/workflowTypes.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • src/lib/products/server.ts
  • src/lib/server/workflow/dbProcedures.ts
  • src/lib/server/job-executors/system.ts
  • src/lib/server/email-service/locales/fr-FR.json
  • src/lib/server/email-service/locales/en-us.json
  • src/lib/server/email-service/locales/es-419.json
🧰 Additional context used
🧠 Learnings (4)
📚 Learning: 2025-12-04T23:01:23.843Z
Learnt from: FyreByrd
Repo: sillsdev/appbuilder-portal PR: 1384
File: src/lib/server/workflow/index.ts:92-103
Timestamp: 2025-12-04T23:01:23.843Z
Learning: In src/lib/server/workflow/index.ts, the Workflow.create method intentionally creates a snapshot before creating product transitions (around line 83) and another after starting the flow (around line 103). The first snapshot is required to prevent errors when the initial state is Product Build (as in Rebuild workflows). The second snapshot ensures the user tasks job has up-to-date information after transitions are created and the flow is started.

Applied to files:

  • src/lib/server/workflow/state-machine.ts
  • src/lib/server/workflow/index.ts
  • src/lib/server/job-executors/product.ts
📚 Learning: 2025-09-12T14:02:04.558Z
Learnt from: FyreByrd
Repo: sillsdev/appbuilder-portal PR: 1283
File: src/lib/server/workflow/index.ts:52-74
Timestamp: 2025-09-12T14:02:04.558Z
Learning: In the appbuilder-portal codebase, when a Product exists, it always has an associated Project relationship. The Project._count fields (Authors, Reviewers) are safe to access directly when the Product query returns a result.

Applied to files:

  • src/lib/server/workflow/index.ts
📚 Learning: 2025-09-04T14:26:59.326Z
Learnt from: FyreByrd
Repo: sillsdev/appbuilder-portal PR: 1227
File: src/lib/server/job-executors/product.ts:247-250
Timestamp: 2025-09-04T14:26:59.326Z
Learning: In src/lib/server/job-executors/product.ts, the createLocal function's catch block returns false instead of rethrowing errors. This was implemented intentionally to fix another issue, so any changes to this error handling should be carefully evaluated for downstream impacts.

Applied to files:

  • src/lib/server/job-executors/product.ts
📚 Learning: 2025-09-04T16:23:55.891Z
Learnt from: FyreByrd
Repo: sillsdev/appbuilder-portal PR: 1227
File: src/lib/server/job-executors/product.ts:247-250
Timestamp: 2025-09-04T16:23:55.891Z
Learning: In src/lib/server/job-executors/product.ts, createLocal’s catch should log the error via job.log with relevant context (projectId/productDefinitionId/storeId) and still return false to preserve the intentional “no-retry” behavior.

Applied to files:

  • src/lib/server/job-executors/product.ts
🧬 Code graph analysis (1)
src/lib/server/workflow/state-machine.ts (1)
src/lib/workflowTypes.ts (2)
  • autoPublishOnRebuild (277-283)
  • newGPApp (270-276)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: checks / build-and-test
🔇 Additional comments (14)
src/lib/workflowTypes.ts (5)

2-3: LGTM!

Good refactor to use type-only import for RoleId while keeping WorkflowType as a value import since it's used at runtime.


137-138: LGTM!

The isAutomatic field is appropriately added to WorkflowInstanceContext for persistence across workflow state transitions.


189-190: LGTM!

Consistent addition of isAutomatic to WorkflowConfig.


196-198: LGTM!

The autoPublishOnRebuild field is properly added to WorkflowInput, enabling the feature flag to flow through the workflow system.


277-288: LGTM!

The autoPublishOnRebuild guard function follows the established pattern of other guards and correctly validates all three required conditions. The Guards type union is properly extended to include it.

src/lib/server/job-executors/product.ts (1)

243-249: LGTM!

Correctly sets isAutomatic: false for local product creation. This ensures that manually created products don't trigger auto-publish behavior, reserving that for system-initiated rebuild workflows.

src/lib/server/workflow/state-machine.ts (5)

17-26: LGTM!

Imports are correctly added for the new autoPublishOnRebuild guard and notifyAutoPublishOwner procedure.


61-69: LGTM!

Context is correctly initialized with isAutomatic and autoPublishOnRebuild from the input.


550-564: LGTM!

The auto-publish transition is correctly positioned after the App Store Preview path and before the Create App Store Entry path. The guard is properly applied both for visualization (includeWhen) and runtime (guard). The console log provides useful debugging information for automatic workflows.


844-848: LGTM!

The guard logic correctly distinguishes between new Google Play apps (which go to Make_It_Live) and other products or existing Google Play apps (which go directly to Published).


829-848: Review comment is based on an incorrect assumption about isAutomatic.

The core premise—that "isAutomatic is only set to true for Rebuild workflows"—is not supported by the codebase. All observable code paths initialize isAutomatic to false:

  • Default parameter: isAutomatic = false (products/server.ts)
  • Job executor (product): isAutomatic: false
  • Job executor (system): isAutomatic: false
  • Workflow initialization: isAutomatic: context.isAutomatic ?? false

No code in the repository sets isAutomatic to true. If this is intentional (notification never sent) or if there's a missing implementation, that's a separate issue. However, the inline condition context.autoPublishOnRebuild && context.isAutomatic is not "less restrictive than the guard"—if isAutomatic is never true, adding a workflowType check is unnecessary. The proposed refactoring suggestions are therefore not actionable based on the current code state.

Likely an incorrect or invalid review comment.

src/lib/server/workflow/index.ts (3)

58-70: LGTM!

Database query correctly extended to fetch AutoPublishOnRebuild from the Project for use in workflow initialization.


71-78: LGTM!

The autoPublishOnRebuild flag is correctly initialized from the Project setting with proper null-safety using !!.


370-380: LGTM!

Correctly excludes autoPublishOnRebuild from the persisted snapshot context since it's part of the workflow input derived from Project settings, not the instance state. This is consistent with the treatment of other input-derived fields.

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.

2 participants