Repository navigation
fix(design-v2): pre-fill a default request that matches the model - #1127
Khush7Chauhan wants to merge 1 commit into
Conversation
👷 Deploy request for ap-template-playground pending review.Visit the deploys page to approve it
|
mttrbrts-agent
left a comment
There was a problem hiding this comment.
Thanks, this is a clean way to fix #1121 and #1043. Building the request from the same LogicModel as scaffoldFromModel keeps the logic and the request in step, and the tests cover the startup, sample, import and boilerplate paths. One change before merge: a runtime Request should be replaced when the model declares its own request transaction. Otherwise "Start from boilerplate" can still leave a request that doesn't match the logic it just wrote.
Drafted by an Accord Project agent, reviewed by a maintainer.
| const className = (parsed as { $class?: unknown } | null)?.$class; | ||
| if (typeof className !== "string" || className === "") return true; | ||
| // The generic boilerplate sends the runtime Request, which no model declares. | ||
| if (className === RUNTIME_REQUEST_FQN) return false; |
There was a problem hiding this comment.
needsDefaultRequest always keeps a request whose $class is the runtime Request, even when the model declares its own request transaction. For example, open the Blank template, add transaction OrderRequest { o Integer quantity } and a response on the Data step, then click "Start from boilerplate" on Logic: the logic is scaffolded for OrderRequest, but the request stays { "$class": "org.accordproject.runtime@0.2.0.Request" }, so Simulate sends a request the logic doesn't expect, which is what #1121 is meant to prevent. Suggested fix: if (className === RUNTIME_REQUEST_FQN) return model?.request !== undefined;, and update the "keeps the runtime Request, which no model declares" test to match.
| }; | ||
|
|
||
| /** A first value for a required field; undefined when the type cannot be filled sensibly (enums, concepts). */ | ||
| const jsonPlaceholder = (field: LogicField): unknown => { |
There was a problem hiding this comment.
Nit: required enum, concept and scalar fields are left out of the default request, so for a model like transaction PaymentRequest { o MonetaryAmount amount } the pre-filled request still fails validation on Send. To close the gap: use the first enum value, build same-namespace concepts recursively, and fall back to a scalar's primitive type. Otherwise, a note in the doc comment saying the request may still need editing would set expectations.
Simulate sent an empty request after "Start from boilerplate", after importing a .cta or opening a share link without one, and samples without a request inherited the Counter sample's request, which their model does not declare. defaultRequestFromModel() sits next to scaffoldFromModel() and builds the request from the same LogicModel: the model's request transaction with first values for its required fields — primitives, the first enum value, same-namespace concepts and a scalar's base value — or the engine's runtime Request when the model declares none. needsDefaultRequest() replaces an empty, unparsable or foreign request, and the boilerplate's runtime Request once the model declares a request of its own, so one the user typed is kept. Closes accordproject#1121 Closes accordproject#1043 Signed-off-by: khush chauhan <khushchauhan2006@gmail.com>
7a1540a to
53d4cfc
Compare
|
Addressed both review points in 53d4cfc and rebased onto main. The runtime Request is now replaced whenever the model declares a request transaction, and required concepts, enums and scalars are filled; the description is updated to match. Locally tsc is clean and the request tests pass. The full suite still shows the pre-existing templateArchive, templateLibrary and ImportTemplates failures, plus one DesignV2Layout timing flake that passes on rerun. Let me know if you need any changes. |
Simulate sends an empty request after "Start from boilerplate", after importing a
.ctaor opening a share link without one, and samples without a request inherited the Counter sample's request, which their model does not declare.defaultRequestFromModel()sits next toscaffoldFromModel()and builds the request from the sameLogicModel: the model's request transaction with first values for its required fields — primitives, the first enum value, same-namespace concepts and a scalar's base value — or the engine's runtimeRequestwhen the model declares none.needsDefaultRequest()replaces only an empty, unparsable or foreign request, so one the user typed is kept.Changes
defaultRequestFromModel()andneedsDefaultRequest()tosrc/editors/logicSource.ts, both driven by the sameLogicModelasscaffoldFromModel(). Required fields are filled recursively: primitives, the first enum value, same-namespace concepts, and a scalar's base value; cyclic concepts stop at the fields already built.Requestis now replaced once the model declares a request transaction of its own, so Start from boilerplate cannot leave a request the logic it just wrote doesn't expect.Requesta model with its own request can't use.loadImportedTemplateuses the default instead of""when an import or share link carries no request, or one for another model.loadSampleuses the model's default instead of the Counter sample's request, fixing Design V2: Simulate pre-fills a CounterRequest that doesn't match the template's model #1043.Requestrather thanCounterRequest.Flags
Requestwhen the model declares its own — a request the user has edited for the current model is never overwritten.e2e/design-v2-default.spec.tscurrently fails on cleanmainlocally (the app stays on the loading splash), so this path is covered by unit tests instead.Screenshots or Video
Not applicable — the change is to the request editor's initial content.
Related Issues
Author Checklist
--signoffoption of git commit.mainfromfork:branchname