-
Notifications
You must be signed in to change notification settings - Fork 0
feat(kno-9713): add reusable step marshalling support to CLI #589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(kno-9713): add reusable step marshalling support to CLI #589
Conversation
9267071
to
eec0f18
Compare
eec0f18
to
08e117d
Compare
@@ -91,7 +91,8 @@ | |||
"postpack": "shx rm -f oclif.manifest.json", | |||
"prepack": "yarn build && oclif manifest && oclif readme", | |||
"test": "mocha --forbid-only \"test/**/*.test.ts\"", | |||
"version": "oclif readme && git add README.md" | |||
"version": "oclif readme && git add README.md", | |||
"check": "yarn run lint && yarn run format.check && yarn run type.check" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tests kept failing in the PR for various reasons here, I prefer them to fail locally so I can quick fix. Running the individual commands was cumbersome, added this to check everything before I submit the PR
@@ -53,7 +53,7 @@ const remoteMessageType: MessageTypeData<WithAnnotation> = { | |||
}, | |||
}; | |||
|
|||
describe("lib/marshal/message-typel/processor", () => { | |||
describe("lib/marshal/message-type/processor", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
noticed this, small fix
@@ -3,7 +3,7 @@ import type { ResourceType } from "./run-context"; | |||
// TODO Remove this once hidden option is removed from message types / guides | |||
export type NonHiddenResourceType = Exclude< | |||
ResourceType, | |||
"message_type" | "guide" | |||
"message_type" | "guide" | "reusable_step" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll hide it for now before release
// TODO: update with actual shape from mAPI | ||
export type ReusableStepData<A extends MaybeWithAnnotation = unknown> = A & { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasn't sure which keys belonged here — need to dig into this when I add the resource to mAPI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check Control.Marshal.Schemas.ReusableStep.ReusableStepSchema, in particular the dump/2
function.
@@ -0,0 +1,220 @@ | |||
import path from "node:path"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a lot of these files are copy / pasted from other resources. I'm not entirely sure about the whats & whys of what's going on, but I think I included the bare minimum, just what we needed before adding to mAPI. Please lmk if there is something here that does not belong here yet
| ReusableStepDirTarget | ||
| ReusableStepsIndexDirTarget; | ||
|
||
export const ensureValidCommandTarget = async ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not used anywhere?
export * from "./processor.isomorphic"; | ||
export * from "./reader"; | ||
export * from "./types"; | ||
export * from "./writer"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reader and writer modules are not really used anywhere? They are typically needed for the pull and push commands, and I don't think we have any commands for reusable steps.
If this PR is for dashboard to show commit diffs, you just need the buildReusableStepDirBundle
helper, and here's an example of only those changes: #498
// TODO: update with actual shape from mAPI | ||
export type ReusableStepData<A extends MaybeWithAnnotation = unknown> = A & { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check Control.Marshal.Schemas.ReusableStep.ReusableStepSchema, in particular the dump/2
function.
id: string; | ||
key: string; | ||
/** The step content for this reusable step's current version. Currently only HttpFetch is supported. */ | ||
step: HttpFetchStepData; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Continuing from above -
For example, I don't think there is a step
field, because we flatten the object in dump/2, so the data payload you get for a reusable step is:
step object
- ref
+ key, type, environment, created_at, updated_at, sha
import { prepareResourceJson } from "../shared/helpers.isomorphic"; | ||
import { ReusableStepData } from "./types"; | ||
|
||
export const REUSABLE_STEP_JSON = "reusable-step.json"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const REUSABLE_STEP_JSON = "reusable-step.json"; | |
export const REUSABLE_STEP_JSON = "reusable_step.json"; |
@@ -19,7 +20,8 @@ type ResourceData<A extends WithAnnotation> = | |||
| PartialData<A> | |||
| WorkflowData<A> | |||
| MessageTypeData<A> | |||
| GuideData<A>; | |||
| GuideData<A> | |||
| ReusableStepData<A>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we will need to specify readonly fields for the reusable step schema here: https://github.com/knocklabs/control/blob/b4c72f5a52f42ddf75265c11d21fafe2ee50b2fc/backend/lib/control/marshal/schemas/reusable_step/reusable_step_schema.ex#L9
Basically all the fields in @dump_required_fields.
* its file content. It includes the extractable fields, which are extracted out | ||
* and added to the bundle as separate files. | ||
*/ | ||
export const buildReusableStepDirBundle = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This probably works for a http fetch step which I believe is the only step type we support with reusable steps, but
one caveat to flag here is that this will likely break once you start supporting other step types.
The proper way to do this would be to refactor the buildWorkflowDirBundle
helper, and extract out the part that handles a single step. In ReusableStepSchema, the step
field is technically WorkflowStepSchema
which can be any step type. But that's more work to refactor.
I'm okay duplicating code and shipping what can work for http steps only - but it will be easy to forget this if/when we ever support additional step types for resuable steps.
Description
Added support for reusable steps in the CLI. This implementation includes:
The implementation follows the same pattern as other resource types (workflows, partials, etc.) with specialized handlers for the reusable step structure. It includes the necessary types, processors, and utilities to manage reusable steps both individually and in bulk.
Tasks
KNO-1234