Skip to content

fix(design-v2): pre-fill a default request that matches the model - #1127

Open
Khush7Chauhan wants to merge 1 commit into
accordproject:mainfrom
Khush7Chauhan:fix/1121-default-request
Open

Khush7Chauhan wants to merge 1 commit into
accordproject:mainfrom
Khush7Chauhan:fix/1121-default-request

Conversation

@Khush7Chauhan

@Khush7Chauhan Khush7Chauhan commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Simulate sends 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 only an empty, unparsable or foreign request, so one the user typed is kept.

Changes

  • Added defaultRequestFromModel() and needsDefaultRequest() to src/editors/logicSource.ts, both driven by the same LogicModel as scaffoldFromModel(). 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.
  • The boilerplate's runtime Request is 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.
  • Logic → Start from boilerplate fills the request when it is empty, doesn't match the model, or is the runtime Request a model with its own request can't use.
  • loadImportedTemplate uses the default instead of "" when an import or share link carries no request, or one for another model.
  • loadSample uses 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.
  • The startup request is derived from the playground model (which declares no request), so it is the runtime Request rather than CounterRequest.
  • Unit tests for the helpers (including enum, concept, scalar and cyclic-concept requests), for the startup/sample/import request paths, and for Start from boilerplate; the share-link test now expects the default request.

Flags

  • Behaviour change: only an empty, unparsable or foreign request is replaced, plus the boilerplate's runtime Request when the model declares its own — a request the user has edited for the current model is never overwritten.
  • Concept and enum values are first values, not domain-correct ones; a request with business rules may still need editing before Send.
  • No E2E test added: e2e/design-v2-default.spec.ts currently fails on clean main locally (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

  • Ensure you provide a DCO sign-off for your commits using the --signoff option of git commit.
  • Vital features and changes captured in unit and/or integration tests
  • Commits messages follow AP format
  • Extend the documentation, if necessary
  • Merging to main from fork:branchname

@Khush7Chauhan
Khush7Chauhan requested review from a team and TheCelestial25 as code owners November 16, 2026 14:41
@netlify

netlify Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

👷 Deploy request for ap-template-playground pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 53d4cfc

@mttrbrts-agent mttrbrts-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread src/editors/logicSource.ts Outdated
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;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread src/editors/logicSource.ts Outdated
};

/** A first value for a required field; undefined when the type cannot be filled sensibly (enums, concepts). */
const jsonPlaceholder = (field: LogicField): unknown => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@github-actions github-actions Bot added the maintainer-engaged A maintainer has commented or reviewed this item label Nov 19, 2026
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>
@Khush7Chauhan
Khush7Chauhan force-pushed the fix/1121-default-request branch from 7a1540a to 53d4cfc Compare November 19, 2026 14:47
@Khush7Chauhan

Khush7Chauhan commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/kind:bugfix maintainer-engaged A maintainer has commented or reviewed this item

Projects

None yet

2 participants