Repository navigation
fix(explain): warn on an unknown or ambiguous command inside [ … ] (#572) #680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -307,3 +307,73 @@ test.skipIf(process.env["CENTRS_CHECK_CORPUS"] !== "1")( | |
| }, | ||
| 120_000, | ||
| ); | ||
|
|
||
| // #572: a bracketed subcommand the verb reader cannot place gets the warning | ||
| // its top-level form gets, spanned on the substitution, never an error. | ||
| test.each([ | ||
| [ | ||
| ":local varID [nosuchcmd where name=x]", | ||
| "explain/canonicalizer/unresolved-statement", | ||
| { start: 13, end: 37 }, | ||
| ], | ||
| [ | ||
| ":put [nosuchcmd]", | ||
| "explain/canonicalizer/unresolved-statement", | ||
| { start: 5, end: 16 }, | ||
| ], | ||
| [ | ||
| ":put [/ip/address/nosuchverb]", | ||
| "explain/canonicalizer/ambiguous-statement", | ||
| { start: 5, end: 29 }, | ||
| ], | ||
| [ | ||
| ":put [/ip/$menu/nosuchcmd]", | ||
| "explain/canonicalizer/unresolved-statement", | ||
| { start: 5, end: 26 }, | ||
| ], | ||
| [ | ||
| ':put "$[nosuchcmd]"', | ||
| "explain/canonicalizer/unresolved-statement", | ||
| { start: 6, end: 18 }, | ||
| ], | ||
| ])( | ||
| "a bracketed abstention warns like its statement: %s", | ||
| (input, code, span) => { | ||
| const result = explainCommand(input); | ||
| expect(result.verdict).toBe("warn"); | ||
| expect( | ||
| result.diagnostics.map((d) => ({ | ||
| code: d.code, | ||
| severity: d.severity, | ||
| span: d.span, | ||
| })), | ||
| ).toEqual([{ code, severity: "warning", span }]); | ||
| }, | ||
| ); | ||
|
|
||
| test("a bracket under a variable path warns on itself and its child (#572)", () => { | ||
| // Q3 refuses the outer bracket (variable path segment) and so loses the | ||
| // inner one's menu context; both are commands, so both abstain out loud. | ||
| const result = explainCommand(":put [/interface/$type/get [nosuchcmd]]"); | ||
| expect(result.verdict).toBe("warn"); | ||
| expect(result.diagnostics.map((d) => [d.code, d.span])).toEqual([ | ||
| ["explain/canonicalizer/unresolved-statement", { start: 5, end: 39 }], | ||
| ["explain/canonicalizer/unresolved-statement", { start: 27, end: 38 }], | ||
| ]); | ||
| }); | ||
|
|
||
| test("an escaped `\\$[` in a string is text, not a substitution (#572)", () => { | ||
| const result = explainCommand(':put "\\$[nosuchcmd]"'); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3 — Pin the even-backslash case mentioned in the earlier review reply. This test covers one literal backslash before |
||
| expect(result.structure.subcommands).toEqual([]); | ||
| expect(result.verdict).toBe("pass"); | ||
| }); | ||
|
|
||
| test("a bracket with no command head stays silent (#572)", () => { | ||
| // `[$f]` and `[(…)]` are a call and an expression, not commands, and the | ||
| // device accepts them (corrected-anchors rows `trailing-selector*`). | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cited |
||
| for (const input of [":put [$f]", ":put [$f arg=1]", ":put [($a . $b)]"]) { | ||
| const result = explainCommand(input); | ||
| expect(result.structure.subcommands[0]?.resolution).toBe("unknown"); | ||
| expect(result.verdict).toBe("pass"); | ||
| } | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2 — Preserve a distinct source span for each bracket warning.
:put ("é" . [bad1] . [bad2])emits two otherwise identicalunresolved-statementdiagnostics with[0,29)for both; the two substitutions occupy[13,19)and[22,28). A same-line BOM also widens the bracket warning. The existing fallback is documented in the matrix, but the new warnings inherit it and #572 explicitly requires a span on the subcommand. Map these warnings to the bracket offsets and test the byte slices, or explicitly carry the span work into a linked follow-up and qualify the changelog and PR claim.