Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/docs/content/docs/workflows/code/diagnostics.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ Workspace source reports every workflow code above for the files of `workflows/<
| `W_TABLE_COLUMN_RENAMED_IN_USE` | A table column this apply renames is still written, filtered or sorted by its old name in a stored workflow's Table block, which the run then drops. |
| `E_WORKFLOW_FILES_MISSING` | A workflow folder sent without its files whose base names no workflow of this workspace. |
| `E_WORKFLOW_FOLDER_COPIED` | A workflow folder holding the base of another declared folder's workflow: a copy. |
| `E_WORKFLOW_RENAMED_IN_USE` | A workflow folder this apply renames is still named by its old key in a deployment file or another declared workflow, which would then name no workflow. |
| `W_UNDECLARED` | A resource the server holds that the directory does not declare (kept without `--allow-delete`). |
| `W_BASE_OTHER_WORKSPACE` | The directory's base was read from another workspace: every resource is created anew. |
| `W_PROMOTE_TARGET_DELETED` | A promotion (`apply --to`) keeps deleted a resource the directory declares that the target deleted since the last promotion: the target no longer holds it. |
Expand Down
5 changes: 5 additions & 0 deletions apps/docs/openapi-v2-workflows.json
Original file line number Diff line number Diff line change
Expand Up @@ -27241,6 +27241,7 @@
"W_TABLE_COLUMN_RENAMED_IN_USE",
"E_WORKFLOW_FILES_MISSING",
"E_WORKFLOW_FOLDER_COPIED",
"E_WORKFLOW_RENAMED_IN_USE",
"W_UNDECLARED",
"W_BASE_OTHER_WORKSPACE",
"W_PROMOTE_TARGET_DELETED",
Expand Down Expand Up @@ -27833,6 +27834,7 @@
"W_TABLE_COLUMN_RENAMED_IN_USE",
"E_WORKFLOW_FILES_MISSING",
"E_WORKFLOW_FOLDER_COPIED",
"E_WORKFLOW_RENAMED_IN_USE",
"W_UNDECLARED",
"W_BASE_OTHER_WORKSPACE",
"W_PROMOTE_TARGET_DELETED",
Expand Down Expand Up @@ -28250,6 +28252,7 @@
"W_TABLE_COLUMN_RENAMED_IN_USE",
"E_WORKFLOW_FILES_MISSING",
"E_WORKFLOW_FOLDER_COPIED",
"E_WORKFLOW_RENAMED_IN_USE",
"W_UNDECLARED",
"W_BASE_OTHER_WORKSPACE",
"W_PROMOTE_TARGET_DELETED",
Expand Down Expand Up @@ -29124,6 +29127,7 @@
"W_TABLE_COLUMN_RENAMED_IN_USE",
"E_WORKFLOW_FILES_MISSING",
"E_WORKFLOW_FOLDER_COPIED",
"E_WORKFLOW_RENAMED_IN_USE",
"W_UNDECLARED",
"W_BASE_OTHER_WORKSPACE",
"W_PROMOTE_TARGET_DELETED",
Expand Down Expand Up @@ -29541,6 +29545,7 @@
"W_TABLE_COLUMN_RENAMED_IN_USE",
"E_WORKFLOW_FILES_MISSING",
"E_WORKFLOW_FOLDER_COPIED",
"E_WORKFLOW_RENAMED_IN_USE",
"W_UNDECLARED",
"W_BASE_OTHER_WORKSPACE",
"W_PROMOTE_TARGET_DELETED",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,31 @@ export function withFallback(
}
}

/** `resources`, falling back to `pending` for a key, id or name it does not resolve. */
/**
* `resources`, falling back to `pending` for a key, id or name it does not resolve; a resource the
* apply moves to a new key (`moved`) is named by that key first.
*/
function withPendingResources(
resources: ResourceKeyResolver,
pending: readonly PendingResource[]
): ResourceKeyResolver {
if (pending.length === 0) return resources
const byId = (kind: ResourceKind, id: string) =>
pending.find((entry) => entry.kind === kind && entry.id === id)
return withFallback(resources, {
const resolver = withFallback(resources, {
toKey: (kind, id) => byId(kind, id)?.key ?? null,
toId: (kind, key) =>
pending.find((entry) => entry.kind === kind && entry.key === key)?.id ?? null,
nameOf: (kind, id) => byId(kind, id)?.name ?? null,
})
const moved = pending.filter((entry) => entry.moved)
if (moved.length === 0) return resolver
return {
...resolver,
toKey: (kind, id) =>
moved.find((entry) => entry.kind === kind && entry.id === id)?.key ??
resolver.toKey(kind, id),
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ export interface PendingResource {
id: string
/** `id` stands in for a resource the apply has yet to create, not one it stores already. */
placeholder?: boolean
/**
* The apply moves the stored resource `id` to `key` (a renamed workflow folder), so source
* names and prints it by `key`, not the key it is stored under.
*/
moved?: boolean
/** The name the apply writes it under, which a workflow's stored reference repeats (a skill). */
name?: string
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,16 @@ export const applyWorkspaceSource = defineAuthorizedWorkspaceUseCase({
Object.assign(result.files, plan.reprint)
const base: WorkspaceBaseV1 = { ...plan.base, resources: { ...plan.base.resources } }
for (const change of plan.changes) {
if (change.action === 'noop' && change.base) {
base.resources[resourceAddress(change.kind, change.key)] = change.base
}
if (change.action !== 'noop' || change.renamedFrom !== undefined) continue
if (change.base) base.resources[resourceAddress(change.kind, change.key)] = change.base
}
const applyId = generateId()
result.applyId = applyId
const consumed = await withAuditCorrelation(applyId, () =>
writeAll(plan.changes, ctx, plan.staged, lease, base, result)
)
await consumeStagedBlobs(stagingScopeOf(principal, context.workspaceId), consumed)
moveUnwrittenWithRenames(base, plan.changes)
result.base = base
recordWorkspaceSourceApplied(facts, plan.changes, result)
logger.info('Applied workspace source', {
Expand Down Expand Up @@ -404,6 +404,29 @@ async function consumeStagedBlobs(target: StagingScope, consumed: StagedBlob[]):
}
}

/**
* Moves the base entry of each no-op that follows a workflow rename (an unchanged deployment) to
* the new key, once that rename was written: the base then records the workflow under the new key
* and no longer under the old one. A rename held back or stopped by a failed write moves nothing.
*/
function moveUnwrittenWithRenames(base: WorkspaceBaseV1, changes: readonly PlannedChange[]): void {
for (const change of changes) {
if (change.action !== 'noop' || change.renamedFrom === undefined) continue
const moved =
base.resources[resourceAddress('workflow', change.key)] !== undefined &&
base.resources[resourceAddress('workflow', change.renamedFrom)] === undefined
if (!moved) continue
if (change.base) base.resources[resourceAddress(change.kind, change.key)] = change.base
dropRenamedEntry(base, change)
}
}

/** Drops the base entry under the key `change` moves its resource from (a renamed folder). */
function dropRenamedEntry(base: WorkspaceBaseV1, change: PlannedChange): void {
if (change.renamedFrom === undefined) return
delete base.resources[resourceAddress(change.kind, change.renamedFrom)]
}

/**
* Writes the plan's changes in write order under `lease`, recording each into `base` and
* `result`; the first failure stops it and is reported as `result.failed`. Each write reads its
Expand Down Expand Up @@ -464,6 +487,7 @@ async function writeAll(
const address = resourceAddress(change.kind, change.key)
if (written.base) base.resources[address] = written.base
else delete base.resources[address]
dropRenamedEntry(base, change)
} catch (error) {
const failure = failureOf(error, change, result.applyId)
result.failed = failure.failed
Expand Down
Loading
Loading