feat(workflows): lock/duplicate improvements for workflows (#4387)

* feat(workflows): lock/duplicate improvements

* fix duplicate var remap bug

* address comments

* remove dead vars

* fix tests

* address comments

* code cleanup

* address comments

* address comments

* minor change

* remove dead code
This commit is contained in:
Vikhyath Mondreti
2026-05-01 20:42:10 -07:00
committed by GitHub
parent 50e118a033
commit af859cd508
60 changed files with 17416 additions and 1066 deletions
@@ -1,8 +1,47 @@
import { vi } from 'vitest'
/**
* Real `WorkflowLockedError` subclass used by tests so `instanceof` checks in
* route handlers behave the same as in production. Mirrors the shape exported
* by `@sim/workflow-authz`.
*/
export class MockWorkflowLockedError extends Error {
readonly status = 423
constructor(message = 'Workflow is locked') {
super(message)
this.name = 'WorkflowLockedError'
}
}
/**
* Real `FolderLockedError` subclass used by tests so `instanceof` checks in
* route handlers behave the same as in production. Mirrors the shape exported
* by `@sim/workflow-authz`.
*/
export class MockFolderLockedError extends Error {
readonly status = 423
constructor(message = 'Folder is locked') {
super(message)
this.name = 'FolderLockedError'
}
}
const unlockedStatus = {
locked: false,
directLocked: false,
inheritedLocked: false,
lockedBy: null as 'workflow' | 'folder' | null,
lockedFolderId: null as string | null,
}
/**
* Controllable mocks for the `@sim/workflow-authz` package.
*
* Defaults assume permissive access (no lock, write allowed). Override with
* `mockResolvedValue` per test when exercising the lock/permission paths.
*
* @example
* ```ts
* import { workflowAuthzMockFns } from '@sim/testing'
@@ -20,6 +59,10 @@ export const workflowAuthzMockFns = {
mockGetActiveWorkflowContext: vi.fn(),
mockGetActiveWorkflowRecord: vi.fn(),
mockAssertActiveWorkflowContext: vi.fn(),
mockGetFolderLockStatus: vi.fn().mockResolvedValue(unlockedStatus),
mockGetWorkflowLockStatus: vi.fn().mockResolvedValue(unlockedStatus),
mockAssertWorkflowMutable: vi.fn().mockResolvedValue(undefined),
mockAssertFolderMutable: vi.fn().mockResolvedValue(undefined),
}
/**
@@ -36,4 +79,10 @@ export const workflowAuthzMock = {
getActiveWorkflowContext: workflowAuthzMockFns.mockGetActiveWorkflowContext,
getActiveWorkflowRecord: workflowAuthzMockFns.mockGetActiveWorkflowRecord,
assertActiveWorkflowContext: workflowAuthzMockFns.mockAssertActiveWorkflowContext,
getFolderLockStatus: workflowAuthzMockFns.mockGetFolderLockStatus,
getWorkflowLockStatus: workflowAuthzMockFns.mockGetWorkflowLockStatus,
assertWorkflowMutable: workflowAuthzMockFns.mockAssertWorkflowMutable,
assertFolderMutable: workflowAuthzMockFns.mockAssertFolderMutable,
WorkflowLockedError: MockWorkflowLockedError,
FolderLockedError: MockFolderLockedError,
}