[roads] QA F-09: a present but empty until: or ports: is key.empty, never absent
Clearing a narrowing field (until:, until: # comment, ports:) used to read as absent, which is the widest value: a permanent grant or all traffic. It is now an error, so the road grants nothing. Three fixtures, FORMATS.md updated, and the F-09 test is no longer ignored.
This commit is contained in:
@@ -16,6 +16,8 @@ pub const MAX_FILE: usize = 256 * 1024;
|
||||
|
||||
pub const REQUIRED: [&str; 4] = ["id", "subject", "verb", "created"];
|
||||
pub const OPTIONAL: [&str; 5] = ["object", "until", "ports", "via", "classic"];
|
||||
/// Optional keys whose absence is their widest value; present but empty is `key.empty`.
|
||||
pub const NARROWING: [&str; 2] = ["until", "ports"];
|
||||
/// The canonical key order.
|
||||
pub const ORDER: [&str; 9] = [
|
||||
"id", "subject", "verb", "object", "until", "ports", "via", "classic", "created",
|
||||
@@ -481,6 +483,23 @@ impl Road {
|
||||
problems.push(p(&f.key, r::KEY_UNKNOWN, "unknown key".into()));
|
||||
}
|
||||
}
|
||||
// A condition that narrows a road is widest when it is absent (no end, all traffic), so a key that is
|
||||
// present but empty is an error, never "absent": clearing a field must not widen a road (QA F-09).
|
||||
for k in NARROWING {
|
||||
if fields
|
||||
.iter()
|
||||
.any(|f| f.key == k && f.value == Value::Absent)
|
||||
{
|
||||
problems.push(p(
|
||||
k,
|
||||
r::KEY_EMPTY,
|
||||
format!(
|
||||
"`{k}:` is empty, which would widen the road to {}; give a value or remove the key",
|
||||
if k == "until" { "a permanent grant" } else { "all traffic" }
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
for k in REQUIRED {
|
||||
if get(k).is_none() {
|
||||
problems.push(
|
||||
|
||||
@@ -15,6 +15,7 @@ pub const KEY_DUPLICATE: &str = "key.duplicate";
|
||||
pub const KEY_MISSING: &str = "key.missing";
|
||||
pub const KEY_FORBIDDEN: &str = "key.forbidden";
|
||||
pub const KEY_TYPE: &str = "key.type";
|
||||
pub const KEY_EMPTY: &str = "key.empty";
|
||||
pub const ID_FORMAT: &str = "id.format";
|
||||
pub const ID_FILE_NAME: &str = "id.file-name";
|
||||
pub const ID_DUPLICATE: &str = "id.duplicate";
|
||||
@@ -78,6 +79,7 @@ pub const ALL: &[&str] = &[
|
||||
KEY_MISSING,
|
||||
KEY_FORBIDDEN,
|
||||
KEY_TYPE,
|
||||
KEY_EMPTY,
|
||||
ID_FORMAT,
|
||||
ID_FILE_NAME,
|
||||
ID_DUPLICATE,
|
||||
|
||||
@@ -43,6 +43,9 @@ road a00041-second-exit.md exit.conflict object
|
||||
road a00042-direct-public.md direct.kill-switch object
|
||||
road a00043-custom-object.md key.forbidden object
|
||||
road a00044-tab.md yaml.refused -
|
||||
road a00045-empty-until.md key.empty until
|
||||
road a00046-until-comment.md key.empty until
|
||||
road a00047-empty-ports.md key.empty ports
|
||||
directory unknown-field.directory.json snapshot.json -
|
||||
directory format-two.directory.json snapshot.format format
|
||||
directory bad-person-id.directory.json directory.id people[3].id
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: a00045
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: service:photos.home.arpa
|
||||
until:
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: a00046
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: service:photos.home.arpa
|
||||
until: # Sunday
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -0,0 +1,8 @@
|
||||
---
|
||||
id: a00047
|
||||
subject: person:jana
|
||||
verb: can-reach
|
||||
object: service:photos.home.arpa
|
||||
ports:
|
||||
created: 2026-11-25T10:00:00+01:00
|
||||
---
|
||||
@@ -239,7 +239,6 @@ fn f08_mesh_addresses_are_never_internet_addresses() {
|
||||
/// is the widest value: `until:` left empty is a permanent grant and `ports:` left empty is all traffic, with no
|
||||
/// problem reported. The same failure as QA R-35 (a misspelt `until`), reached by deleting the value instead.
|
||||
#[test]
|
||||
#[ignore = "QA F-09 (major): an emptied `until:` or `ports:` silently widens the road to its maximum"]
|
||||
fn f09_an_emptied_narrowing_condition_is_an_error() {
|
||||
for (from, to) in [
|
||||
("until: 2026-11-29T23:59:59+01:00\n", "until:\n"),
|
||||
|
||||
+4
-2
@@ -39,7 +39,7 @@ The same strict subset of YAML as Pensum's tickets (Fabrica `core/docs/FORMATS.m
|
||||
| a single-quoted string, `''` for a quote | `subject: 'person:jana'` |
|
||||
| a flow list of scalars | `ports: [tcp/443, udp/53]` |
|
||||
| a block list of scalars, indented under its key | `ports:` then ` - tcp/443` |
|
||||
| an empty value, meaning *absent* | `until:` |
|
||||
| an empty value, meaning *absent*; for `until` and `ports` it is an error (`key.empty`) | `via:` |
|
||||
| comment lines, blank lines, a trailing ` # comment` after a plain value or list | `# moved from the router` |
|
||||
|
||||
Refused, each with an error naming the file, the line and the field (`yaml.refused`): anchors (`&a`), aliases
|
||||
@@ -63,7 +63,9 @@ is not `key: value`, or a bad quoted string, is `yaml.syntax`.
|
||||
|
||||
Any other key is `key.unknown`. A key that the verb does not take is `key.forbidden`. A list where a single value
|
||||
belongs, or a single value where a list belongs, is `key.type`. A required key that is missing or empty is
|
||||
`key.missing`.
|
||||
`key.missing`. `until` and `ports` narrow a road, and absent is their widest value (no end, all traffic), so
|
||||
either key present with an empty value (`until:`, `until: # Sunday`, `ports:`) is `key.empty`: clearing a field
|
||||
never widens a road (QA F-09). `ports: []` is `ports.format`.
|
||||
|
||||
### References
|
||||
|
||||
|
||||
Reference in New Issue
Block a user