Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/petite-buckets-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cartesi/cli": patch
---

change all toml keys to use snake_case
32 changes: 16 additions & 16 deletions apps/cli/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import bytes from "bytes";
import { extname } from "node:path";
import { type TomlPrimitive, parse as parseToml } from "smol-toml";
import { parse as parseToml, type TomlPrimitive } from "smol-toml";

/**
* Typed Errors
Expand Down Expand Up @@ -367,16 +367,16 @@ const parseMachine = (value: TomlPrimitive): MachineConfig => {

return {
assertRollingTemplate: parseOptionalBoolean(
toml["assert-rolling-template"],
toml.assert_rolling_template,
),
bootargs: parseStringArray(toml.bootargs),
bootargs: parseStringArray(toml.boot_args),
entrypoint: parseOptionalString(toml.entrypoint),
finalHash: parseBoolean(toml["final-hash"], true),
finalHash: parseBoolean(toml.final_hash, true),
interactive: undefined,
maxMCycle: parseOptionalNumber(toml["max-mcycle"]),
noRollup: parseBoolean(toml["no-rollup"], false),
ramLength: parseString(toml["ram-length"], DEFAULT_RAM),
ramImage: parseString(toml["ram-image"], DEFAULT_RAM_IMAGE),
maxMCycle: parseOptionalNumber(toml.max_mcycle),
noRollup: parseBoolean(toml.no_rollup, false),
ramLength: parseString(toml.ram_length, DEFAULT_RAM),
ramImage: parseString(toml.ram_image, DEFAULT_RAM_IMAGE),
store: "image",
user: parseOptionalString(toml.user),
};
Expand All @@ -398,11 +398,11 @@ const parseDrive = (drive: TomlPrimitive): DriveConfig => {
const builder = parseBuilder((drive as TomlTable).builder);
switch (builder) {
case "directory": {
const { extraSize, format, mount, directory, shared, user } =
const { extra_size, format, mount, directory, shared, user } =
drive as TomlTable;
return {
builder: "directory",
extraSize: parseBytes(extraSize, 0),
extraSize: parseBytes(extra_size, 0),
format: parseFormat(format),
mount: parseOptionalStringBoolean(mount),
directory: parseRequiredString(directory, "directory"),
Expand All @@ -412,10 +412,10 @@ const parseDrive = (drive: TomlPrimitive): DriveConfig => {
}
case "docker": {
const {
buildArgs,
build_args,
context,
dockerfile,
extraSize,
extra_size,
format,
image,
mount,
Expand All @@ -426,11 +426,11 @@ const parseDrive = (drive: TomlPrimitive): DriveConfig => {
} = drive as TomlTable;
return {
builder: "docker",
buildArgs: parseStringArray(buildArgs),
buildArgs: parseStringArray(build_args),
image: parseOptionalString(image),
context: parseString(context, "."),
dockerfile: parseString(dockerfile, "Dockerfile"),
extraSize: parseBytes(extraSize, 0),
extraSize: parseBytes(extra_size, 0),
format: parseFormat(format),
mount: parseOptionalStringBoolean(mount),
shared: parseOptionalBoolean(shared),
Expand All @@ -451,11 +451,11 @@ const parseDrive = (drive: TomlPrimitive): DriveConfig => {
};
}
case "tar": {
const { extraSize, filename, format, mount, shared, user } =
const { extra_size, filename, format, mount, shared, user } =
drive as TomlTable;
return {
builder: "tar",
extraSize: parseBytes(extraSize, 0),
extraSize: parseBytes(extra_size, 0),
filename: parseRequiredString(filename, "filename"),
format: parseFormat(format),
mount: parseOptionalStringBoolean(mount),
Expand Down
26 changes: 13 additions & 13 deletions apps/cli/tests/unit/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ import * as fs from "node:fs";
import * as path from "node:path";
import { describe, expect, it } from "vitest";
import {
defaultConfig,
defaultMachineConfig,
InvalidBooleanValueError,
InvalidBuilderError,
InvalidBytesValueError,
InvalidDriveFormatError,
InvalidEmptyDriveFormatError,
InvalidNumberValueError,
InvalidStringValueError,
RequiredFieldError,
defaultConfig,
defaultMachineConfig,
parse,
RequiredFieldError,
} from "../../src/config.js";

const loadDriveConfig = (driveName: string) => {
Expand Down Expand Up @@ -97,7 +97,7 @@ shared = true`);
describe("when parsing [machine]", () => {
const config = `
[machine]
no-rollup = true
no_rollup = true
`;
it("machine-config", () => {
expect(parse(config)).toEqual({
Expand All @@ -111,7 +111,7 @@ shared = true`);
it("should fail for invalid bootargs", () => {
const invalidConfig = `
${config}
bootargs = ["no4lvl", "quiet", false]
boot_args = ["no4lvl", "quiet", false]
`;
expect(() => parse(invalidConfig)).toThrowError(
new InvalidStringValueError(false),
Expand Down Expand Up @@ -203,13 +203,13 @@ shared = true`);
*/
describe("when parsing fields types", () => {
it("should fail for invalid boolean value", () => {
expect(() => parse("[machine]\nno-rollup = 42")).toThrowError(
expect(() => parse("[machine]\nno_rollup = 42")).toThrowError(
new InvalidBooleanValueError(42),
);
});

it("should fail for invalid number value", () => {
expect(() => parse("[machine]\nmax-mcycle = 'abc'")).toThrowError(
expect(() => parse("[machine]\nmax_mcycle = 'abc'")).toThrowError(
new InvalidNumberValueError("abc"),
);
});
Expand All @@ -230,7 +230,7 @@ shared = true`);
const invalidTarDrive = `
[drives.data]
builder = "tar"
extraSize = "abc"
extra_size = "abc"
filename = "data.tar"
format = "ext2"
`;
Expand All @@ -246,7 +246,7 @@ shared = true`);
`[drives.data]
builder = "directory"
directory = "/data"
extra-size = 128
extra_size = 128
`,
),
).not.toThrow();
Expand All @@ -256,7 +256,7 @@ shared = true`);
`[drives.data]
builder = "directory"
directory = "/data"
extra-size = "128MB"
extra_size = "128MB"
`,
),
).not.toThrow();
Expand All @@ -267,21 +267,21 @@ shared = true`);
`[drives.data]
builder = "directory"
directory = "/data"
extra-size = ${bigInt}
extra_size = ${bigInt}
`,
),
).not.toThrow();
});

it("should fail for invalid boolean value", () => {
expect(() => parse("[machine]\nfinal-hash = 42")).toThrowError(
expect(() => parse("[machine]\nfinal_hash = 42")).toThrowError(
new InvalidBooleanValueError(42),
);
});

it("should fail for invalid optional boolean value", () => {
expect(() =>
parse("[machine]\nassert-rolling-template = 42"),
parse("[machine]\nassert_rolling_template = 42"),
).toThrowError(new InvalidBooleanValueError(42));
});

Expand Down
2 changes: 1 addition & 1 deletion apps/cli/tests/unit/config/fixtures/drives/data.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
[drives.data]
builder = "directory"
directory = "./data" # required
extraSize = "100Mb" # optional. size is given by directory content size plus this amount
extra_size = "100Mb" # optional. size is given by directory content size plus this amount
mount = "/var/lib/app" # optional, default is /mnt/{name}
20 changes: 10 additions & 10 deletions apps/cli/tests/unit/config/fixtures/full.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# sdk = "cartesi/sdk:0.12.0"

# [machine]
# assert-rolling-update = true
# bootargs = ["no4lvl", "quiet", "earlycon=sbi", "console=hvc0", "rootfstype=ext2", "root=/dev/pmem0", "rw", "init=/usr/sbin/cartesi-init"]
# assert_rolling_update = true
# boot_args = ["no4lvl", "quiet", "earlycon=sbi", "console=hvc0", "rootfstype=ext2", "root=/dev/pmem0", "rw", "init=/usr/sbin/cartesi-init"]
# entrypoint = "/usr/local/bin/app"
# final-hash = true
# max-mcycle = 0
# no-rollup = false
# ram-image = "/usr/share/cartesi-machine/images/linux.bin" # directory inside SDK image
# ram-length = "128Mi"
# final_hash = true
# max_mcycle = 0
# no_rollup = false
# ram_image = "/usr/share/cartesi-machine/images/linux.bin" # directory inside SDK image
# ram_length = "128Mi"

# [drives.root]
# builder = "docker"
# dockerfile = "Dockerfile"
# target = "docker-multi-stage-target"
# format = "ext2"
# format = "sqfs"
# extraSize = "100Mb" # optional. size is given by directory content size plus this amount
# extra_size = "100Mb" # optional. size is given by directory content size plus this amount

# [drives.data]
# builder = "empty"
Expand All @@ -26,15 +26,15 @@
# [drives.data]
# builder = "directory"
# directory = "./data" # required
# extraSize = "100Mb" # optional. size is given by directory content size plus this amount
# extra_size = "100Mb" # optional. size is given by directory content size plus this amount
# format = "ext2"
# format = "sqfs"
# mount = "/var/lib/app" # optional, default is /mnt/{name}

# [drives.data]
# builder = "tar"
# filename = "build/files.tar"
# extraSize = "100Mb" # optional. size is given by directory content size plus this amount
# extra_size = "100Mb" # optional. size is given by directory content size plus this amount
# mount = "/var/lib/app" # optional, default is /mnt/{name}

# [drives.doom]
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/tests/unit/config/fixtures/machine/no_boot.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

[machine]
assert_rolling_update = false
max-mcycle = 0
max_mcycle = 0
Loading