Skip to content

feat(cli): reject unknown keys in cartesi.toml + build for production - #571

Merged
brunomenezes merged 4 commits into
prerelease/v2-alphafrom
feat/cli-reject-unknown-config-keys
Oct 28, 2026
Merged

brunomenezes merged 4 commits into
prerelease/v2-alphafrom
feat/cli-reject-unknown-config-keys

Conversation

@brunomenezes

Copy link
Copy Markdown
Member

Summary

cartesi.toml silently ignored any key the CLI doesn't read: a misspelling, a key of another builder, a key written after the wrong table header, or a key of a removed feature such as [withdrawal.config]. The parser now rejects them, naming the key, the table and the keys that table accepts, as suggested in the review of #551. It also rejects a drive or nvram that isn't a table, such as [[drives.root]], which used to become the default root drive. Missing keys keep their defaults, and drive names, nvram labels and [machine.env] variables stay free.

Also, the CLI is now built for production by default, so errors print only their message, as below, instead of a minified class name and a stack trace. I tested the npm bundle version + mac-os binary

$ cartesi build
Unknown key 'sise' in [drives.root] (builder = "docker" by default), expected one of: accounts_drive, accounts_drive_size, build_args, builder, context, dockerfile, extra_size, format, image, mount, shared, tags, target, user

Closes #555.

Here is a toml file with a few test cases.

cartesi.toml with commented wrong setups
# 1. A typo, with no builder set:
# [drives.data]
# sise = "1Mi"

# 2. A key that belongs to another builder:
# [drives.data]
# builder = "empty"
# size = "1Mi"
# directory = "./data"


# 3. A top-level key written after a table header:
# [drives.data]
# builder = "empty"
# size = "1Mi"
# sdk = "cartesi/sdk:0.12.0-alpha.44"

# 4. A misspelled table name:
# [drive.data]
# builder = "empty"
# size = "1Mi"

# 5. A typo in an nvram:
# [nvrams.input]
# size = "4Ki"
# share = true


# 6. The [withdrawal.config] table from before cartesi/cli#551:
# [withdrawal.config]
# guardian = "0x0000000000000000000000000000000000000001"


# 7. Double brackets, which make an array of tables:
# [[drives.data]]
# builder = "empty"
# size = "1Mi"


# 8. A drive that isn’t a table:
# [drives]
# data = 42


# 9. Two unknown keys at once: add these lines at the very end of the file, with no header.
# ram_lenght = "256Mi"
# bootargs = ["quiet"]


# 10. A -c file that changes a drive’s builder: append to cartesi.toml:
# [drives.data]
# builder = "empty"
# size = "1Mi"

# Create override.toml next to it:

# [drives.data]
# builder = "directory"
# directory = "."
# Then build with the override:
# cartesi-dev build -c override.toml

Changes:

  • config.ts: UnknownConfigKeyError and an assertKnownKeys helper, with the accepted keys listed next to each parser: the top level, [machine], [nvrams.*], [withdrawal], and [drives.*] per builder, so a key of another builder is rejected too. The drive message names the builder in effect, marked by default when omitted. Every unknown key of a table is reported at once.
  • InvalidTableError for [drives], [nvrams], each drive and nvram, [machine] and [withdrawal] given as a non-table, e.g. Invalid [drives.root]: expected a table, got [{"builder":"empty","size":"1Mi"}].
  • [withdrawal.config] from before feat(cli): derive the accounts drive layout from the built machine #551 fails as unknown key config in [withdrawal], with no migration code.
  • base.ts: getProjectSdk no longer swallows parse errors, so hash, address-book, send, deposit, foreclose, refund and withdraw report an invalid cartesi.toml instead of hashing the snapshot with the default SDK image.
  • Integration helper: the test SDK pin is written before the caller's config. Appended after it, it landed in the last table (nvrams.output.sdk in the nvram test) and was ignored, so that test built with the default SDK.
  • Fixtures: full.toml is now a valid, commented reference that sets every accepted key to a non-default value at least once; no_boot.toml used assert_rolling_update, which never existed (the key is assert_rolling_template); the empty bootargs.toml is removed.
  • Tests: every fixture parses, and full.toml parses to the expected config with a strict comparison, so a key the parser stops reading or a new unset field fails the test; unknown keys in each table, keys of another builder, several keys at once, non-tables, -c merging and the free names; getMachineHash on an invalid config.
  • -c files are checked after merging, and merging can't unset keys, so a later file that changes a drive's builder now fails on the earlier file's builder-specific keys. Overrides within the same builder keep working.
  • build.ts: the CLI is built for production unless NODE_ENV says otherwise. The release build didn't set it, so the npm package printed the minified error class and its stack trace instead of the message shown above.
  • index.ts: the error handler also handles rejected promises. Bun, which runs the compiled binaries, doesn't turn them into uncaught exceptions, so the binaries skipped the handler and printed Bun's own error report.

@changeset-bot

changeset-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f3aade6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cartesi/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@brunomenezes brunomenezes moved this to 🧑‍💻 In Progress in Rollups Tooling Oct 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 91.1% (🎯 0%) 12350 / 13557
🔵 Statements 91.1% 12350 / 13557
🔵 Functions 81.58% 279 / 342
🔵 Branches 0% 0 / 0
📁 File Coverage (20 files)
File Lines Statements Functions Branches Uncovered Lines
apps/cli/src/base.ts 🔴 38.01% 🔴 38.01% 🟡 64.71% 🔴 0% 62, 70-74, 79, 93, 101-174,...
apps/cli/src/builder/directory.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/builder/docker.ts 🟢 87.12% 🟢 87.12% 🟡 66.67% 🔴 0% 77-79, 81, 114-116, 174-183
apps/cli/src/builder/empty.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/builder/none.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/builder/nvram.ts 🟢 96.88% 🟢 96.88% 🟢 100% 🔴 0% 27
apps/cli/src/builder/tar.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/commands/foreclose.ts 🔴 49.09% 🔴 49.09% 🔴 50% 🔴 0% 69, 91-145
apps/cli/src/commands/refund.ts 🔴 38.2% 🔴 38.2% 🟡 66.67% 🔴 0% 55-109
apps/cli/src/commands/withdraw.ts 🔴 46.58% 🔴 46.58% 🟡 73.33% 🔴 0% 95-123, 277-278, 301-356, 3...
apps/cli/src/compose/anvil.ts 🟡 79.25% 🟡 79.25% 🟢 100% 🔴 0% 19-29
apps/cli/src/compose/builder.ts 🟢 99.79% 🟢 99.79% 🟢 100% 🔴 0% 228
apps/cli/src/compose/bundler.ts 🔴 4.82% 🔴 4.82% 🔴 0% 🔴 0% 8-40, 44-75, 79-92
apps/cli/src/compose/common.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/compose/database.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/compose/explorer.ts 🔴 6.67% 🔴 6.67% 🔴 0% 🔴 0% 10-38, 43-55, 59-72
apps/cli/src/compose/node.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -
apps/cli/src/compose/passkey.ts 🔴 8.33% 🔴 8.33% 🔴 0% 🔴 0% 9-18, 23-42, 46-59
apps/cli/src/compose/paymaster.ts 🔴 7.69% 🔴 7.69% 🔴 0% 🔴 0% 8-21, 25-44, 48-61
apps/cli/src/compose/proxy.ts 🟢 100% 🟢 100% 🟢 100% 🔴 0% -

@github-project-automation github-project-automation Bot moved this from Todo to Waiting Merge in Rollups SDK Oct 28, 2026
@github-project-automation github-project-automation Bot moved this from 🧑‍💻 In Progress to 👍 Waiting Merge in Rollups Tooling Oct 28, 2026
@brunomenezes
brunomenezes merged commit 7d296fb into prerelease/v2-alpha Oct 28, 2026
4 checks passed
@brunomenezes
brunomenezes deleted the feat/cli-reject-unknown-config-keys branch October 28, 2026 19:28
@github-project-automation github-project-automation Bot moved this from Waiting Merge to Done in Rollups SDK Oct 28, 2026
@github-project-automation github-project-automation Bot moved this from 👍 Waiting Merge to 📦 Done in Rollups Tooling Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done
Status: 📦 Done

Development

Successfully merging this pull request may close these issues.

[CLI]: Reject unknown keys in cartesi.toml

2 participants