Repository navigation
fix(mfile,mctx): refuse a state key that is not one directory name when the file is loaded - #3520
Conversation
…en the file is loaded A task's `state_key` or a `[defaults.task]` `state_key` that is not one directory name was only refused when a task first ran, as a general error that named neither the task nor where the key is set. The project's own minimal.toml is now refused when it loads, with exit 3, by the rule the state directory already applies (`File::validate_state_component`). The message names the table that sets the key and says what a state key may be. An empty key still means "no key" and loads. An upstream layer read for the package graph is not checked, as its tasks never run. The refusal when the state directory is composed stays, for a key that arrives another way, and now names the task and where to set `state_key`. Refs gominimal/inbox#1244 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
Reviewed: 1 finding, none blocking at Address the comments on the diff. Clobber: none seen. |
| .map_err(|reason| { | ||
| // The file's load refuses such a key, so this is a key handed | ||
| // in some other way: name the task and where the key is set. | ||
| if mfile::File::validate_state_component(key).is_err() { | ||
| return Error::Other(anyhow!( | ||
| "Task `{name}` has the state key {key:?}, and {reason}. Set \ | ||
| `state_key` on the task or in `[defaults.task]` to one directory \ | ||
| name, such as \"dev\"." | ||
| )); |
There was a problem hiding this comment.
LOW · tests · confidence 0.50 · in make_env_with_network
The new branch that names the task and where to set state_key has no test. The mfile tests only cover the load-time refusal. A later change can break this message unnoticed.
What the reviewer checked
mctx/src/lib.rs: if mfile::File::validate_state_component(key).is_err() { return Error::Other(anyhow!("Task
{name}has the state key ...")) }; the diff adds no test in crates/mctx
Hand this to an agent
Act on a code-review finding.
File: crates/mctx/src/lib.rs
Lines: 1143-1151
Category: tests
Severity: low (reviewer confidence 0.50)
Finding:
The new branch that names the task and where to set `state_key` has no test. The mfile tests only cover the load-time refusal. A later change can break this message unnoticed.
First verify this against the code yourself. It is model output and
may be wrong. If it is wrong, or the tradeoff was deliberate, say so
and change nothing.
👍 useful · 👎 noise — react to tell the reviewer. Replying works too, and says more.
There was a problem hiding this comment.
Scope matches the title. The diff has three files: the load check, the new error variant and its tests, and the run-time message in mctx. Clobber none. git log on the three files shows #3342 as the last change, and this diff builds on it. Correctness the load check uses File::validate_state_component, the same rule state_dir_encoded applies. from_dir_for_graph skips the check, and a test pins that. All four production callers of make_env and make_env_with_network pass the task name as name, so the new Task ... message names the task correctly. One printed-text defect: the older run-time message now gives advice that cannot apply. Two nits follow. The new mctx branch is not reachable from a file that File::from_dir loaded, because the load refuses the key first and stack tasks carry state_key: None. The existing thread already asks for a test on that branch, and this review does not repeat it. A legacy [defaults] state_key is reported as [defaults.task]. The legacy hint prints first and names both tables, so no finding is filed. No secrets and no dependency changes are in the diff. Not checked: compile and test runs, which need a build. The CLI version is not recorded, because the harness denied the command that prints it.
| } | ||
| Error::Other(anyhow!( | ||
| "refusing to use state key {name:?}: {reason}. Choose a state key \ | ||
| "refusing to use state key {key:?}: {reason}. Choose a state key \ |
There was a problem hiding this comment.
low · After this change, this message prints only when the key passed validate_state_component. The key is then already one directory name. The remaining reasons from state_dir_encoded are about a symlink or an unresolvable path under the state base. The person who runs the task reads Choose a state key that is a single directory name and cannot act on it. Remove that sentence, or state the situation only: the task name, the key and the reason. This is the only instance of the text in the repo, and no test pins it.
| } | ||
|
|
||
| /// Whether a load refuses a task that sets `interactive = true` (BOX-054), | ||
| /// and a `state_key` that is not one directory name. |
There was a problem hiding this comment.
nit · The TaskCheck doc now names both refusals, and so do the docs on validate and check. The doc on from_dir_for_graph at crates/mfile/src/lib.rs:1294 still says it is from_dir without the interactive-task refusal only. Add the state-key refusal there, so the three docs agree.
| f, | ||
| "`{entry}` in minimal.toml sets `state_key` to {value:?}, and {reason}. A \ | ||
| state key is one directory name, such as \"dev\": not `.` or `..`, and with \ | ||
| no `/` or NUL byte." |
There was a problem hiding this comment.
nit · For the keys . and .., the reason from validate_state_component is the value again. The message prints: [tasks.build] in minimal.toml sets state_key to "..", and it is "..". The second clause adds no fact for the person who reads it. The final sentence already says the key cannot be . or ... The same reason string also goes into the new mctx message.
What
A task's
state_key, or a[defaults.task]state_key, that is not one directory name is now refused when the project'sminimal.tomlloads, with exit 3. The message names the table that sets the key and says what a state key may be.Refs gominimal/inbox#1244.
Why
Before, such a key was refused only when a task first ran, with a general error that named neither the task nor where the key is set. The check is the one the state directory already applies (
File::validate_state_component, from #3342), moved to where the author can act on it.Scope
state_key.3 files, 140 lines added and 9 removed, most of it tests.
Tested
Lint, the full pre-push run and a baseline run on ubuntu-24.04 passed at this commit.
🤖 Generated with Claude Code
🤖 Generated with Claude Code
Summary by CodeRabbit