Add mops generate candid#563
Open
Kamirus wants to merge 2 commits into
Open
Conversation
…urce Per `specs/mops-candid.md`. Closes the maintenance gap for `[canisters.<name>].candid` so `mops build`'s embedded Candid metadata, the subtype check, and downstream tooling (e.g. `@icp-sdk/bindgen`) stay in sync with the Motoko source. `mops build` and `mops generate candid` now share moc-invocation logic via `cli/helpers/moc-args.ts`, so the auto-generated `.did` always satisfies the build's compatibility check. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
Cursor AI review👍 APPROVE — looks safe to merge
VerdictDecision: APPROVE Generated for commit d86303d |
This was referenced Jun 9, 2026
Update icp-cli skill: replace mops build + cp pattern with mops generate candid
dfinity/icskills#214
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements
specs/mops-candid.md.Why
The curated
[canisters.<name>].candidfile is a build-input contract:mops buildsubtype-checks the auto-generated interface against it and embeds the curated file into the wasm ascandid:servicemetadata. Downstream tools like@icp-sdk/bindgenread the same file. There was no command to refresh it from source — every interface change required hand-editing the.did, with no committable file at all when the field was unset.What changes for users
mops generate candid [canisters...](re)generates the curated.didfrom current Motoko source.Destination resolution:
--output <path>— single-canister only; never updatesmops.toml.[canisters.<name>].candidif set — overwrites in place.<dirname(main)>/<name>.did(e.g.main = "src/Backend.mo"→src/backend.did); also writes the field tomops.tomlso subsequent runs reuse it.Paths inside
.mops/are rejected (it's a private cache; the.didshould be committable). Onmocfailure, neither the destination file normops.tomlis touched.Implementation note
mocinvocation logic (sources,[moc].args, migration flags,[build].args, per-canisterargs, CLI extras + managed-flag warnings) extracted frombuild.tsintocli/helpers/moc-args.ts.mops buildnow uses the same helper, guaranteeing the.didmops generate candidproduces always satisfies the build's compatibility check. The build refactor is behavior-preserving — verified by all existing build snapshots passing unchanged.Test plan
npm test -- generate.test.ts(10 cases — default path, configured path, multi-canister,--output,-ocollision warning, multi-canister +-orejected, unknown canister, moc failure leaves files/toml untouched, missing-but-configured destination,.mops/rejection)npm test -- build.test.ts(refactor regression — all snapshots unchanged)npm run check(root — TypeScript + svelte-check)npm run lintcleanOut of scope (called out in spec)
mops check(separate follow-up; spec § "Interaction withmops check")[candid].dirglobal directory config--mergemode that preserves hand-editsMade with Cursor