ic-mops 2.2.1 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/RELEASE.md +9 -1
  3. package/cli.ts +25 -2
  4. package/commands/build.ts +2 -10
  5. package/commands/check-stable.ts +177 -0
  6. package/commands/check.ts +53 -6
  7. package/dist/bin/mops.js +1 -1
  8. package/dist/cli.js +22 -2
  9. package/dist/commands/build.js +2 -5
  10. package/dist/commands/check-stable.d.ts +14 -0
  11. package/dist/commands/check-stable.js +95 -0
  12. package/dist/commands/check.js +41 -6
  13. package/dist/fix-dist.js +5 -0
  14. package/dist/helpers/resolve-canisters.d.ts +7 -0
  15. package/dist/helpers/resolve-canisters.js +31 -0
  16. package/dist/package.json +2 -2
  17. package/dist/tests/build.test.js +18 -0
  18. package/dist/tests/check-fix.test.js +17 -0
  19. package/dist/tests/check-stable.test.d.ts +1 -0
  20. package/dist/tests/check-stable.test.js +51 -0
  21. package/dist/tests/check.test.js +54 -1
  22. package/dist/tests/moc-args.test.js +3 -3
  23. package/dist/types.d.ts +5 -1
  24. package/dist/wasm/pkg/nodejs/wasm_bg.wasm +0 -0
  25. package/dist/wasm/pkg/web/wasm_bg.wasm +0 -0
  26. package/fix-dist.ts +9 -0
  27. package/helpers/resolve-canisters.ts +52 -0
  28. package/package.json +2 -2
  29. package/tests/README.md +16 -0
  30. package/tests/__snapshots__/check-fix.test.ts.snap +16 -10
  31. package/tests/__snapshots__/check-stable.test.ts.snap +29 -0
  32. package/tests/__snapshots__/check.test.ts.snap +26 -16
  33. package/tests/build/no-dfx/mops.toml +3 -0
  34. package/tests/build/no-dfx/src/Main.mo +1 -1
  35. package/tests/build.test.ts +24 -0
  36. package/tests/check/canisters/Ok.mo +5 -0
  37. package/tests/check/canisters/mops.toml +8 -0
  38. package/tests/check/canisters-error/Error.mo +7 -0
  39. package/tests/check/canisters-error/mops.toml +8 -0
  40. package/tests/check/canisters-moc-args/Warning.mo +5 -0
  41. package/tests/check/canisters-moc-args/mops.toml +8 -0
  42. package/tests/check/deployed-compatible/main.mo +4 -0
  43. package/tests/check/deployed-compatible/mops.toml +11 -0
  44. package/tests/check/deployed-compatible/old.mo +3 -0
  45. package/tests/check/deployed-compile-error/Error.mo +7 -0
  46. package/tests/check/deployed-compile-error/mops.toml +11 -0
  47. package/tests/check/deployed-compile-error/old.mo +3 -0
  48. package/tests/check/deployed-missing-error/Ok.mo +5 -0
  49. package/tests/check/deployed-missing-error/mops.toml +11 -0
  50. package/tests/check/deployed-missing-skip/Ok.mo +5 -0
  51. package/tests/check/deployed-missing-skip/mops.toml +12 -0
  52. package/tests/check/error/Error.mo +1 -1
  53. package/tests/check/error/mops.toml +5 -2
  54. package/tests/check/fix/M0223.mo +1 -1
  55. package/tests/check/fix/M0236.mo +1 -1
  56. package/tests/check/fix/M0237.mo +1 -1
  57. package/tests/check/fix/Ok.mo +1 -1
  58. package/tests/check/fix/fix-with-error.mo +9 -0
  59. package/tests/check/fix/fix-with-warning.mo +8 -0
  60. package/tests/check/fix/mops.toml +3 -0
  61. package/tests/check/fix/transitive-main.mo +1 -1
  62. package/tests/check/moc-args/Warning.mo +1 -1
  63. package/tests/check/moc-args/mops.toml +4 -1
  64. package/tests/check/success/Ok.mo +1 -1
  65. package/tests/check/success/Warning.mo +1 -1
  66. package/tests/check/success/mops.toml +5 -2
  67. package/tests/check-fix.test.ts +25 -0
  68. package/tests/check-stable/compatible/mops.toml +8 -0
  69. package/tests/check-stable/compatible/new.mo +4 -0
  70. package/tests/check-stable/compatible/old.mo +3 -0
  71. package/tests/check-stable/incompatible/mops.toml +8 -0
  72. package/tests/check-stable/incompatible/new.mo +3 -0
  73. package/tests/check-stable/incompatible/old.mo +4 -0
  74. package/tests/check-stable/subdirectory/.old/src/main.mo +3 -0
  75. package/tests/check-stable/subdirectory/mops.toml +8 -0
  76. package/tests/check-stable/subdirectory/src/main.mo +4 -0
  77. package/tests/check-stable.test.ts +56 -0
  78. package/tests/check.test.ts +63 -1
  79. package/tests/moc-args.test.ts +3 -3
  80. package/types.ts +5 -1
  81. package/wasm/pkg/nodejs/wasm_bg.wasm +0 -0
  82. package/wasm/pkg/web/wasm_bg.wasm +0 -0
  83. package/.DS_Store +0 -0
  84. package/bundle/bench/bench-canister.mo +0 -130
  85. package/bundle/bench/user-bench.mo +0 -10
  86. package/bundle/bin/moc-wrapper.sh +0 -40
  87. package/bundle/bin/mops.js +0 -3
  88. package/bundle/cli.js +0 -1569
  89. package/bundle/cli.tgz +0 -0
  90. package/bundle/declarations/bench/bench.did +0 -30
  91. package/bundle/declarations/bench/bench.did.d.ts +0 -33
  92. package/bundle/declarations/bench/bench.did.js +0 -30
  93. package/bundle/declarations/bench/index.d.ts +0 -50
  94. package/bundle/declarations/bench/index.js +0 -40
  95. package/bundle/declarations/main/index.d.ts +0 -50
  96. package/bundle/declarations/main/index.js +0 -40
  97. package/bundle/declarations/main/main.did +0 -428
  98. package/bundle/declarations/main/main.did.d.ts +0 -348
  99. package/bundle/declarations/main/main.did.js +0 -406
  100. package/bundle/declarations/storage/index.d.ts +0 -50
  101. package/bundle/declarations/storage/index.js +0 -30
  102. package/bundle/declarations/storage/storage.did +0 -46
  103. package/bundle/declarations/storage/storage.did.d.ts +0 -40
  104. package/bundle/declarations/storage/storage.did.js +0 -38
  105. package/bundle/default-stylesheet.css +0 -415
  106. package/bundle/package.json +0 -36
  107. package/bundle/templates/README.md +0 -13
  108. package/bundle/templates/licenses/Apache-2.0 +0 -202
  109. package/bundle/templates/licenses/Apache-2.0-NOTICE +0 -13
  110. package/bundle/templates/licenses/MIT +0 -21
  111. package/bundle/templates/mops-publish.yml +0 -17
  112. package/bundle/templates/mops-test.yml +0 -24
  113. package/bundle/templates/src/lib.mo +0 -15
  114. package/bundle/templates/test/lib.test.mo +0 -4
  115. package/bundle/wasm_bg.wasm +0 -0
  116. package/bundle/xhr-sync-worker.js +0 -51
  117. package/dist/wasm/pkg/bundler/package.json +0 -20
  118. package/dist/wasm/pkg/bundler/wasm.d.ts +0 -3
  119. package/dist/wasm/pkg/bundler/wasm.js +0 -5
  120. package/dist/wasm/pkg/bundler/wasm_bg.js +0 -93
  121. package/dist/wasm/pkg/bundler/wasm_bg.wasm +0 -0
  122. package/dist/wasm/pkg/bundler/wasm_bg.wasm.d.ts +0 -8
  123. package/tests/build/success/.dfx/local/canister_ids.json +0 -17
  124. package/tests/build/success/.dfx/local/canisters/bar/bar.did +0 -3
  125. package/tests/build/success/.dfx/local/canisters/bar/bar.most +0 -4
  126. package/tests/build/success/.dfx/local/canisters/bar/bar.wasm +0 -0
  127. package/tests/build/success/.dfx/local/canisters/bar/constructor.did +0 -3
  128. package/tests/build/success/.dfx/local/canisters/bar/index.js +0 -42
  129. package/tests/build/success/.dfx/local/canisters/bar/init_args.txt +0 -1
  130. package/tests/build/success/.dfx/local/canisters/bar/service.did +0 -3
  131. package/tests/build/success/.dfx/local/canisters/bar/service.did.d.ts +0 -7
  132. package/tests/build/success/.dfx/local/canisters/bar/service.did.js +0 -4
  133. package/tests/build/success/.dfx/local/canisters/foo/constructor.did +0 -3
  134. package/tests/build/success/.dfx/local/canisters/foo/foo.did +0 -3
  135. package/tests/build/success/.dfx/local/canisters/foo/foo.most +0 -4
  136. package/tests/build/success/.dfx/local/canisters/foo/foo.wasm +0 -0
  137. package/tests/build/success/.dfx/local/canisters/foo/index.js +0 -42
  138. package/tests/build/success/.dfx/local/canisters/foo/init_args.txt +0 -1
  139. package/tests/build/success/.dfx/local/canisters/foo/service.did +0 -3
  140. package/tests/build/success/.dfx/local/canisters/foo/service.did.d.ts +0 -7
  141. package/tests/build/success/.dfx/local/canisters/foo/service.did.js +0 -4
  142. package/tests/build/success/.dfx/local/lsp/ucwa4-rx777-77774-qaada-cai.did +0 -3
  143. package/tests/build/success/.dfx/local/lsp/ulvla-h7777-77774-qaacq-cai.did +0 -3
  144. package/tests/build/success/.dfx/local/network-id +0 -4
  145. package/wasm/Cargo.lock +0 -1475
  146. package/wasm/pkg/bundler/package.json +0 -20
  147. package/wasm/pkg/bundler/wasm.d.ts +0 -3
  148. package/wasm/pkg/bundler/wasm.js +0 -5
  149. package/wasm/pkg/bundler/wasm_bg.js +0 -93
  150. package/wasm/pkg/bundler/wasm_bg.wasm +0 -0
  151. package/wasm/pkg/bundler/wasm_bg.wasm.d.ts +0 -8
@@ -0,0 +1,7 @@
1
+ actor {
2
+ public func hello() : async Text {
3
+ "Hello, World!";
4
+ };
5
+ };
6
+
7
+ thisshouldnotcompile;
@@ -0,0 +1,8 @@
1
+ [toolchain]
2
+ moc = "1.3.0"
3
+
4
+ [moc]
5
+ args = ["--default-persistent-actors"]
6
+
7
+ [canisters.backend]
8
+ main = "Error.mo"
@@ -0,0 +1,5 @@
1
+ actor {
2
+ public func example() : async () {
3
+ let unused = 123;
4
+ };
5
+ };
@@ -0,0 +1,8 @@
1
+ [toolchain]
2
+ moc = "1.3.0"
3
+
4
+ [moc]
5
+ args = ["--default-persistent-actors", "-Werror"]
6
+
7
+ [canisters.backend]
8
+ main = "Warning.mo"
@@ -0,0 +1,4 @@
1
+ actor {
2
+ var counter : Nat = 0;
3
+ var name : Text = "";
4
+ };
@@ -0,0 +1,11 @@
1
+ [toolchain]
2
+ moc = "1.3.0"
3
+
4
+ [moc]
5
+ args = ["--default-persistent-actors"]
6
+
7
+ [canisters.backend]
8
+ main = "main.mo"
9
+
10
+ [canisters.backend.check-stable]
11
+ path = "old.mo"
@@ -0,0 +1,3 @@
1
+ actor {
2
+ var counter : Nat = 0;
3
+ };
@@ -0,0 +1,7 @@
1
+ actor {
2
+ public func hello() : async Text {
3
+ "Hello, World!";
4
+ };
5
+ };
6
+
7
+ thisshouldnotcompile;
@@ -0,0 +1,11 @@
1
+ [toolchain]
2
+ moc = "1.3.0"
3
+
4
+ [moc]
5
+ args = ["--default-persistent-actors"]
6
+
7
+ [canisters.backend]
8
+ main = "Error.mo"
9
+
10
+ [canisters.backend.check-stable]
11
+ path = "old.mo"
@@ -0,0 +1,3 @@
1
+ actor {
2
+ var counter : Nat = 0;
3
+ };
@@ -0,0 +1,5 @@
1
+ actor {
2
+ public func hello() : async Text {
3
+ "Hello, World!";
4
+ };
5
+ };
@@ -0,0 +1,11 @@
1
+ [toolchain]
2
+ moc = "1.3.0"
3
+
4
+ [moc]
5
+ args = ["--default-persistent-actors"]
6
+
7
+ [canisters.backend]
8
+ main = "Ok.mo"
9
+
10
+ [canisters.backend.check-stable]
11
+ path = "nonexistent.mo"
@@ -0,0 +1,5 @@
1
+ actor {
2
+ public func hello() : async Text {
3
+ "Hello, World!";
4
+ };
5
+ };
@@ -0,0 +1,12 @@
1
+ [toolchain]
2
+ moc = "1.3.0"
3
+
4
+ [moc]
5
+ args = ["--default-persistent-actors"]
6
+
7
+ [canisters.backend]
8
+ main = "Ok.mo"
9
+
10
+ [canisters.backend.check-stable]
11
+ path = "nonexistent.mo"
12
+ skipIfMissing = true
@@ -1,4 +1,4 @@
1
- persistent actor {
1
+ actor {
2
2
  public func hello() : async Text {
3
3
  "Hello, World!";
4
4
  };
@@ -1,2 +1,5 @@
1
- [dependencies]
2
- core = "2.0.0"
1
+ [toolchain]
2
+ moc = "1.3.0"
3
+
4
+ [moc]
5
+ args = ["--default-persistent-actors"]
@@ -1,7 +1,7 @@
1
1
  // M0223: Redundant type instantiation
2
2
  // The type annotation is not needed when it can be inferred
3
3
 
4
- persistent actor {
4
+ actor {
5
5
  public func testM0223() : async () {
6
6
  func identity<T>(x : T) : T = x;
7
7
  let varArray : [var Nat] = [var 1];
@@ -3,7 +3,7 @@
3
3
  import List "mo:core/List";
4
4
  import Nat "mo:core/Nat";
5
5
 
6
- persistent actor {
6
+ actor {
7
7
  public func testM0236() : async () {
8
8
  let list = List.fromArray<Nat>([1, 2, 3]);
9
9
  List.sortInPlace(list);
@@ -3,7 +3,7 @@
3
3
  import List "mo:core/List";
4
4
  import Nat "mo:core/Nat";
5
5
 
6
- persistent actor {
6
+ actor {
7
7
  public func testM0237() : async () {
8
8
  let list = List.fromArray<Nat>([3, 2, 1]);
9
9
  list.sortInPlace(Nat.compare);
@@ -1,5 +1,5 @@
1
1
  // Clean file — no fixable warnings
2
- persistent actor {
2
+ actor {
3
3
  public func example() : async () {
4
4
  let _x : ?Text = null;
5
5
  ();
@@ -0,0 +1,9 @@
1
+ actor {
2
+ public func test() : async () {
3
+ func identity<T>(x : T) : T = x;
4
+ let nat = identity<Nat>(1);
5
+ ignore nat;
6
+ };
7
+ };
8
+
9
+ thisshouldnotcompile;
@@ -0,0 +1,8 @@
1
+ actor {
2
+ public func test() : async () {
3
+ func identity<T>(x : T) : T = x;
4
+ let unused = 123;
5
+ let nat = identity<Nat>(1);
6
+ ignore nat;
7
+ };
8
+ };
@@ -3,3 +3,6 @@ core = "2.0.0"
3
3
 
4
4
  [toolchain]
5
5
  moc = "1.3.0"
6
+
7
+ [moc]
8
+ args = ["--default-persistent-actors"]
@@ -1,6 +1,6 @@
1
1
  import Lib "./transitive-lib";
2
2
 
3
- persistent actor {
3
+ actor {
4
4
  public func run() : async () {
5
5
  func identity<T>(x : T) : T = x;
6
6
  let _ = identity<Nat>(1);
@@ -1,4 +1,4 @@
1
- persistent actor {
1
+ actor {
2
2
  public func example() : async () {
3
3
  let unused = 123;
4
4
  };
@@ -1,2 +1,5 @@
1
+ [toolchain]
2
+ moc = "1.3.0"
3
+
1
4
  [moc]
2
- args = ["-Werror"]
5
+ args = ["--default-persistent-actors", "-Werror"]
@@ -1,4 +1,4 @@
1
- persistent actor {
1
+ actor {
2
2
  public func hello() : async Text {
3
3
  "Hello, World!";
4
4
  };
@@ -1,4 +1,4 @@
1
- persistent actor {
1
+ actor {
2
2
  public func example() : async () {
3
3
  let unused = 123;
4
4
  };
@@ -1,2 +1,5 @@
1
- [dependencies]
2
- core = "2.0.0"
1
+ [toolchain]
2
+ moc = "1.3.0"
3
+
4
+ [moc]
5
+ args = ["--default-persistent-actors"]
@@ -131,4 +131,29 @@ describe("check --fix", () => {
131
131
  expect(result.stdout).toContain("Attempting to fix files");
132
132
  expect(result.stdout).toContain("No fixes were needed");
133
133
  });
134
+
135
+ test("fix with remaining warnings", async () => {
136
+ const runFilePath = copyFixture("fix-with-warning.mo");
137
+ const result = await cli(
138
+ ["check", runFilePath, "--fix", "--", warningFlags],
139
+ { cwd: fixDir },
140
+ );
141
+ expect(result.exitCode).toBe(0);
142
+ expect(result.stdout).toContain("1 fix applied");
143
+ expect(result.stdout).toMatch(/✓/);
144
+ expect(result.stderr).toMatch(/warning \[M0194\]/);
145
+ expect(result.stderr).toMatch(/unused identifier/);
146
+ });
147
+
148
+ test("fix with remaining errors", async () => {
149
+ const runFilePath = copyFixture("fix-with-error.mo");
150
+ const result = await cli(
151
+ ["check", runFilePath, "--fix", "--", warningFlags],
152
+ { cwd: fixDir },
153
+ );
154
+ expect(result.exitCode).toBe(1);
155
+ expect(result.stdout).toContain("1 fix applied");
156
+ expect(result.stderr).toMatch(/error/i);
157
+ expect(result.stdout).not.toMatch(/✓ run/);
158
+ });
134
159
  });
@@ -0,0 +1,8 @@
1
+ [toolchain]
2
+ moc = "1.3.0"
3
+
4
+ [moc]
5
+ args = ["--default-persistent-actors"]
6
+
7
+ [canisters.backend]
8
+ main = "new.mo"
@@ -0,0 +1,4 @@
1
+ actor {
2
+ var counter : Nat = 0;
3
+ var name : Text = "";
4
+ };
@@ -0,0 +1,3 @@
1
+ actor {
2
+ var counter : Nat = 0;
3
+ };
@@ -0,0 +1,8 @@
1
+ [toolchain]
2
+ moc = "1.3.0"
3
+
4
+ [moc]
5
+ args = ["--default-persistent-actors"]
6
+
7
+ [canisters.backend]
8
+ main = "new.mo"
@@ -0,0 +1,3 @@
1
+ actor {
2
+ var counter : Text = "";
3
+ };
@@ -0,0 +1,4 @@
1
+ actor {
2
+ var counter : Nat = 0;
3
+ var name : Text = "";
4
+ };
@@ -0,0 +1,3 @@
1
+ actor {
2
+ var counter : Nat = 0;
3
+ };
@@ -0,0 +1,8 @@
1
+ [toolchain]
2
+ moc = "1.3.0"
3
+
4
+ [moc]
5
+ args = ["--default-persistent-actors"]
6
+
7
+ [canisters.backend]
8
+ main = "src/main.mo"
@@ -0,0 +1,4 @@
1
+ actor {
2
+ var counter : Nat = 0;
3
+ var name : Text = "";
4
+ };
@@ -0,0 +1,56 @@
1
+ import { describe, expect, test } from "@jest/globals";
2
+ import { mkdtemp, rm, writeFile } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import path from "path";
5
+ import { cli, cliSnapshot } from "./helpers";
6
+
7
+ describe("check-stable", () => {
8
+ test("compatible upgrade from .mo file", async () => {
9
+ const cwd = path.join(import.meta.dirname, "check-stable/compatible");
10
+ await cliSnapshot(["check-stable", "old.mo"], { cwd }, 0);
11
+ });
12
+
13
+ test("incompatible upgrade from .mo file", async () => {
14
+ const cwd = path.join(import.meta.dirname, "check-stable/incompatible");
15
+ const result = await cliSnapshot(["check-stable", "old.mo"], { cwd }, 1);
16
+ expect(result.stderr).toMatch(/compatibility/i);
17
+ });
18
+
19
+ test("compatible upgrade with verbose", async () => {
20
+ const cwd = path.join(import.meta.dirname, "check-stable/compatible");
21
+ const result = await cli(["check-stable", "old.mo", "--verbose"], { cwd });
22
+ expect(result.exitCode).toBe(0);
23
+ expect(result.stdout).toMatch(/Generating stable types for old\.mo/);
24
+ expect(result.stdout).toMatch(/Generating stable types for new\.mo/);
25
+ expect(result.stdout).toMatch(/--stable-compatible/);
26
+ expect(result.stdout).toMatch(/Stable compatibility check passed/);
27
+ });
28
+
29
+ test("old file in subdirectory (.old/src/ pattern)", async () => {
30
+ const cwd = path.join(import.meta.dirname, "check-stable/subdirectory");
31
+ const result = await cli(["check-stable", ".old/src/main.mo"], { cwd });
32
+ expect(result.exitCode).toBe(0);
33
+ expect(result.stdout).toMatch(/Stable compatibility check passed/);
34
+ });
35
+
36
+ test("compatible upgrade from .most file", async () => {
37
+ const cwd = path.join(import.meta.dirname, "check-stable/compatible");
38
+ const tempDir = await mkdtemp(path.join(tmpdir(), "mops-test-most-"));
39
+ try {
40
+ const mostPath = path.join(tempDir, "old.most");
41
+ await writeFile(mostPath, "actor {\n stable var counter : Nat\n};\n");
42
+ const result = await cli(["check-stable", mostPath], { cwd });
43
+ expect(result.exitCode).toBe(0);
44
+ expect(result.stdout).toMatch(/Stable compatibility check passed/);
45
+ } finally {
46
+ await rm(tempDir, { recursive: true, force: true });
47
+ }
48
+ });
49
+
50
+ test("errors when old file does not exist", async () => {
51
+ const cwd = path.join(import.meta.dirname, "check-stable/compatible");
52
+ const result = await cli(["check-stable", "nonexistent.mo"], { cwd });
53
+ expect(result.exitCode).toBe(1);
54
+ expect(result.stderr).toMatch(/File not found/);
55
+ });
56
+ });
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, test } from "@jest/globals";
2
2
  import path from "path";
3
- import { cliSnapshot } from "./helpers";
3
+ import { cli, cliSnapshot } from "./helpers";
4
4
 
5
5
  describe("check", () => {
6
6
  test("ok", async () => {
@@ -48,4 +48,66 @@ describe("check", () => {
48
48
  const cwd = path.join(import.meta.dirname, "check/moc-args");
49
49
  await cliSnapshot(["check", "Warning.mo"], { cwd }, 1);
50
50
  });
51
+
52
+ test("no args falls back to [canisters] entrypoints", async () => {
53
+ const cwd = path.join(import.meta.dirname, "check/canisters");
54
+ await cliSnapshot(["check"], { cwd }, 0);
55
+ });
56
+
57
+ test("[moc] args applied when using canister fallback", async () => {
58
+ const cwd = path.join(import.meta.dirname, "check/canisters-moc-args");
59
+ const result = await cli(["check"], { cwd });
60
+ expect(result.exitCode).toBe(1);
61
+ expect(result.stderr).toMatch(/warning \[M0194\]/);
62
+ });
63
+
64
+ test("canister entrypoint with errors", async () => {
65
+ const cwd = path.join(import.meta.dirname, "check/canisters-error");
66
+ const result = await cli(["check"], { cwd });
67
+ expect(result.exitCode).toBe(1);
68
+ expect(result.stderr).toMatch(/error/i);
69
+ });
70
+
71
+ test("--fix with canister fallback", async () => {
72
+ const cwd = path.join(import.meta.dirname, "check/canisters");
73
+ const result = await cli(["check", "--fix"], { cwd });
74
+ expect(result.exitCode).toBe(0);
75
+ });
76
+
77
+ test("deployed: runs stable check when deployed file exists", async () => {
78
+ const cwd = path.join(import.meta.dirname, "check/deployed-compatible");
79
+ const result = await cli(["check"], { cwd });
80
+ expect(result.exitCode).toBe(0);
81
+ expect(result.stdout).toMatch(/Stable compatibility check passed/);
82
+ });
83
+
84
+ test("deployed: silently skips when file missing and skipIfMissing", async () => {
85
+ const cwd = path.join(import.meta.dirname, "check/deployed-missing-skip");
86
+ const result = await cli(["check"], { cwd });
87
+ expect(result.exitCode).toBe(0);
88
+ expect(result.stdout).not.toMatch(/stable/i);
89
+ });
90
+
91
+ test("deployed: errors when file missing without deployedSkipIfFileMissing", async () => {
92
+ const cwd = path.join(import.meta.dirname, "check/deployed-missing-error");
93
+ const result = await cli(["check"], { cwd });
94
+ expect(result.exitCode).toBe(1);
95
+ expect(result.stderr).toMatch(/Deployed file not found/);
96
+ expect(result.stderr).toMatch(/skipIfMissing/);
97
+ });
98
+
99
+ test("--fix runs stable check after fixing", async () => {
100
+ const cwd = path.join(import.meta.dirname, "check/deployed-compatible");
101
+ const result = await cli(["check", "--fix"], { cwd });
102
+ expect(result.exitCode).toBe(0);
103
+ expect(result.stdout).toMatch(/Stable compatibility check passed/);
104
+ });
105
+
106
+ test("stable check is skipped when type-checking fails", async () => {
107
+ const cwd = path.join(import.meta.dirname, "check/deployed-compile-error");
108
+ const result = await cli(["check"], { cwd });
109
+ expect(result.exitCode).toBe(1);
110
+ expect(result.stderr).toMatch(/error/i);
111
+ expect(result.stdout).not.toMatch(/Stable compatibility/);
112
+ });
51
113
  });
@@ -7,13 +7,13 @@ describe("moc-args", () => {
7
7
  const cwd = path.join(import.meta.dirname, "check/moc-args");
8
8
  const result = await cli(["moc-args"], { cwd });
9
9
  expect(result.exitCode).toBe(0);
10
- expect(result.stdout).toBe("-Werror");
10
+ expect(result.stdout).toBe("--default-persistent-actors\n-Werror");
11
11
  });
12
12
 
13
- test("prints nothing when no [moc] config", async () => {
13
+ test("prints only global args when no extra [moc] args", async () => {
14
14
  const cwd = path.join(import.meta.dirname, "check/success");
15
15
  const result = await cli(["moc-args"], { cwd });
16
16
  expect(result.exitCode).toBe(0);
17
- expect(result.stdout).toBe("");
17
+ expect(result.stdout).toBe("--default-persistent-actors");
18
18
  });
19
19
  });
package/types.ts CHANGED
@@ -33,10 +33,14 @@ export type Config = {
33
33
  };
34
34
 
35
35
  export type CanisterConfig = {
36
- main: string;
36
+ main?: string;
37
37
  args?: string[];
38
38
  candid?: string;
39
39
  initArg?: string;
40
+ "check-stable"?: {
41
+ path: string;
42
+ skipIfMissing?: boolean;
43
+ };
40
44
  };
41
45
 
42
46
  export type Dependencies = Record<string, Dependency>;
Binary file
Binary file
package/.DS_Store DELETED
Binary file
@@ -1,130 +0,0 @@
1
- import Nat64 "mo:core/Nat64";
2
- import Nat "mo:core/Nat";
3
- import Runtime "mo:core/Runtime";
4
- import InternetComputer "mo:core/InternetComputer";
5
- import Region "mo:core/Region";
6
- import Prim "mo:prim";
7
-
8
- import UserBench "./user-bench"; // file path will be replaced with the *.bench.mo file path
9
-
10
- persistent actor class () {
11
- type BenchSchema = {
12
- name : Text;
13
- description : Text;
14
- rows : [Text];
15
- cols : [Text];
16
- };
17
-
18
- type Bench = {
19
- getVersion : () -> Nat;
20
- getSchema : () -> BenchSchema;
21
- runCell : (Nat, Nat) -> ();
22
- };
23
-
24
- type BenchResult = {
25
- instructions : Int;
26
- rts_mutator_instructions : Int;
27
- stable_memory_size : Int;
28
- rts_stable_memory_size : Int;
29
- rts_logical_stable_memory_size : Int;
30
- rts_collector_instructions : Int;
31
- rts_heap_size : Int;
32
- rts_memory_size : Int;
33
- rts_total_allocation : Int;
34
- rts_reclaimed : Int;
35
- };
36
-
37
- transient var benchOpt : ?Bench = null;
38
-
39
- public func init() : async BenchSchema {
40
- let bench = UserBench.init();
41
- benchOpt := ?bench;
42
- ignore Region.grow(Region.new(), 1);
43
- bench.getSchema();
44
- };
45
-
46
- public query func getSchema() : async BenchSchema {
47
- let ?bench = benchOpt else Runtime.trap("bench not initialized");
48
- bench.getSchema();
49
- };
50
-
51
- func _getStats() : BenchResult {
52
- {
53
- instructions = 0;
54
- rts_heap_size = Prim.rts_heap_size();
55
- stable_memory_size = Prim.rts_stable_memory_size() * 65536;
56
- rts_stable_memory_size = Prim.rts_stable_memory_size();
57
- rts_logical_stable_memory_size = Prim.rts_logical_stable_memory_size();
58
- rts_memory_size = Prim.rts_memory_size();
59
- rts_total_allocation = Prim.rts_total_allocation();
60
- rts_reclaimed = Prim.rts_reclaimed();
61
- rts_mutator_instructions = Prim.rts_mutator_instructions();
62
- rts_collector_instructions = Prim.rts_collector_instructions();
63
- };
64
- };
65
-
66
- func _diffStats(before : BenchResult, after : BenchResult) : BenchResult {
67
- {
68
- instructions = after.instructions - before.instructions;
69
- rts_heap_size = after.rts_heap_size - before.rts_heap_size;
70
- stable_memory_size = after.stable_memory_size - before.stable_memory_size;
71
- rts_stable_memory_size = after.rts_stable_memory_size - before.rts_stable_memory_size;
72
- rts_logical_stable_memory_size = after.rts_logical_stable_memory_size - before.rts_logical_stable_memory_size;
73
- rts_memory_size = after.rts_memory_size - before.rts_memory_size;
74
- rts_total_allocation = after.rts_total_allocation - before.rts_total_allocation;
75
- rts_reclaimed = after.rts_reclaimed - before.rts_reclaimed;
76
- rts_mutator_instructions = after.rts_mutator_instructions - before.rts_mutator_instructions;
77
- rts_collector_instructions = after.rts_collector_instructions - before.rts_collector_instructions;
78
- };
79
- };
80
-
81
- func _runCell(rowIndex : Nat, colIndex : Nat) : BenchResult {
82
- let ?bench = benchOpt else Runtime.trap("bench not initialized");
83
- let statsBefore = _getStats();
84
-
85
- let instructions = Nat64.toNat(
86
- InternetComputer.countInstructions(
87
- func() {
88
- bench.runCell(rowIndex, colIndex);
89
- }
90
- )
91
- );
92
-
93
- let statsAfter = _getStats();
94
- _diffStats(statsBefore, { statsAfter with instructions });
95
- };
96
-
97
- func _runCellAwait(rowIndex : Nat, colIndex : Nat) : async BenchResult {
98
- let ?bench = benchOpt else Runtime.trap("bench not initialized");
99
- let statsBefore = _getStats();
100
-
101
- let instructions = Nat64.toNat(
102
- InternetComputer.countInstructions(
103
- func() {
104
- bench.runCell(rowIndex, colIndex);
105
- }
106
- )
107
- );
108
-
109
- await (func() : async () {})();
110
-
111
- let statsAfter = _getStats();
112
- _diffStats(statsBefore, { statsAfter with instructions });
113
- };
114
-
115
- public query func getStats() : async BenchResult {
116
- _getStats();
117
- };
118
-
119
- public query func runCellQuery(rowIndex : Nat, colIndex : Nat) : async BenchResult {
120
- _runCell(rowIndex, colIndex);
121
- };
122
-
123
- public func runCellUpdate(rowIndex : Nat, colIndex : Nat) : async BenchResult {
124
- _runCell(rowIndex, colIndex);
125
- };
126
-
127
- public func runCellUpdateAwait(rowIndex : Nat, colIndex : Nat) : async BenchResult {
128
- await _runCellAwait(rowIndex, colIndex);
129
- };
130
- };