Skip to content

Add mops generate candid#563

Open
Kamirus wants to merge 2 commits into
mainfrom
mops-generate-candid
Open

Add mops generate candid#563
Kamirus wants to merge 2 commits into
mainfrom
mops-generate-candid

Conversation

@Kamirus

@Kamirus Kamirus commented Jun 2, 2026

Copy link
Copy Markdown
Collaborator

Implements specs/mops-candid.md.

Why

The curated [canisters.<name>].candid file is a build-input contract: mops build subtype-checks the auto-generated interface against it and embeds the curated file into the wasm as candid:service metadata. Downstream tools like @icp-sdk/bindgen read 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 .did from current Motoko source.

mops generate candid                  # all canisters
mops generate candid backend          # one canister
mops generate candid backend -o <p>   # ad-hoc path; does not touch mops.toml

Destination resolution:

  1. --output <path> — single-canister only; never updates mops.toml.
  2. [canisters.<name>].candid if set — overwrites in place.
  3. Default — <dirname(main)>/<name>.did (e.g. main = "src/Backend.mo"src/backend.did); also writes the field to mops.toml so subsequent runs reuse it.

Paths inside .mops/ are rejected (it's a private cache; the .did should be committable). On moc failure, neither the destination file nor mops.toml is touched.

Implementation note

moc invocation logic (sources, [moc].args, migration flags, [build].args, per-canister args, CLI extras + managed-flag warnings) extracted from build.ts into cli/helpers/moc-args.ts. mops build now uses the same helper, guaranteeing the .did mops generate candid produces 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, -o collision warning, multi-canister + -o rejected, 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 lint clean

Out of scope (called out in spec)

  • Drift detection in mops check (separate follow-up; spec § "Interaction with mops check")
  • [candid].dir global directory config
  • --merge mode that preserves hand-edits

Made with Cursor

…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>
@Kamirus Kamirus requested a review from a team as a code owner June 2, 2026 12:51
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Cursor AI review

👍 APPROVE — looks safe to merge

Category Assessment Details
Summary Adds mops generate candid [canisters...] to regenerate curated .did files from Motoko source, and extracts shared prepareMocArgs so build and generate share the same moc invocation inputs.
Code Quality moc-args.ts cleanly deduplicates build/generate logic without speculative extras; destination resolution and failure semantics match the spec.
Consistency Mirrors mops build (canister selection, installAll, parseExtraArgs, -- passthrough, all-canisters default); changelog, skill, and CLI docs are updated.
Security Rejects writes under .mops/; no new identity/registry/secrets surface; collision warning for shared -o paths.
Tests Ten focused cases cover default/configured paths, multi-canister, -o, errors, .mops/ rejection, and moc-failure atomicity; snapshots cover primary stdout/did output.
Maintainability Shared helper keeps generate/build candid compatibility from drifting; command is isolated in generate.ts for future mops generate subcommands.

Verdict

Decision: APPROVE
Risk: Low
Reason: This is a well-scoped, user-facing CLI addition with matching docs/changelog/skill, meaningful tests, and a behavior-preserving build refactor verified by unchanged build snapshots. No new defects or production-significant changes warranting human escalation were found in the diff versus base.


Generated for commit d86303d

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant