Skip to content

Commit 82460bc

Browse files
committed
πŸ› Read every workflow option's value as a value (#818)
The review Plugin decides whether a `workflow` command line executes a document by finding the action, and the action is the first positional after `workflow` β€” the first token that is neither an option nor an option's value. The scan stepped over four options that take a separated value and missed two. `--output` and `--status` are the two, and `xmd workflow --output start export run-1` is what that costs: `--output` takes `start`, the action is `export`, and a scan that read the first recognized word installed the review graph for a command that executes no document. The list is now every non-boolean field of the command's own grammar β€” `--id`, `--at`, `--status`, `--artifact`, `--output` β€” plus the two options read out of argv before that grammar exists, `--plugin` and the aggregate and generated root properties. The boolean switches take no value and are skipped as the options they are. It is written out here because the CLI depends on this package rather than the other way round, and the comment names the grammar it mirrors. The regression walks every one of those options with an executing action's own name as its value and a management action after it, adds the assigned spelling, and keeps four executing classifications to show the same reading still finds a real action written after an option.
1 parent 0a4f45c commit 82460bc

2 files changed

Lines changed: 57 additions & 25 deletions

File tree

β€Žpackages/cli/tests/plugin-host.test.tsβ€Ž

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -436,25 +436,42 @@ describe("PH6 β€” the bundled review Plugin claims the commands that run a revie
436436
});
437437

438438
it("reads an option's value as a value, never as the action", function* () {
439-
// The command line that makes this necessary: a module named `start`, and
440-
// the management action `list`. Reading the first recognized word would
441-
// have installed the review graph for a command that executes no document.
442-
expect(yield* declaredFor("workflow", ["workflow", "--plugin", "start", "list"])).toEqual([]);
443-
expect(yield* declaredFor("workflow", ["workflow", "--plugin=./start.mjs", "list"])).toEqual(
444-
[],
445-
);
446-
expect(yield* declaredFor("workflow", ["workflow", "--id", "start", "list"])).toEqual([]);
447-
expect(yield* declaredFor("workflow", ["workflow", "--props-name", "start", "list"])).toEqual(
448-
[],
449-
);
450-
// And the same reading still finds a real action written after an option.
451-
expect(
452-
(yield* declaredFor("workflow", ["workflow", "--plugin", "list", "start", "flow.md"])).length,
453-
).toBe(35);
439+
// Every option the command defines that takes a separated value, each with
440+
// an executing action's own name as that value and a management action
441+
// after it. Reading the first recognized word would have installed the
442+
// review graph for a command that executes no document.
443+
const valued: readonly (readonly [string, string, readonly string[]])[] = [
444+
["--plugin", "start", ["workflow", "--plugin", "start", "list"]],
445+
["--output", "start", ["workflow", "--output", "start", "export", "run-1"]],
446+
["--status", "resume", ["workflow", "--status", "resume", "list"]],
447+
["--id", "fork", ["workflow", "--id", "fork", "list"]],
448+
["--at", "start", ["workflow", "--at", "start", "history", "run-1"]],
449+
["--artifact", "start", ["workflow", "--artifact", "start", "status"]],
450+
["--props", "start", ["workflow", "--props", "start", "list"]],
451+
["--props-name", "start", ["workflow", "--props-name", "start", "list"]],
452+
];
453+
for (const [option, value, args] of valued) {
454+
const declared = yield* declaredFor("workflow", args);
455+
expect(`${option}=${value}: ${declared.length}`).toBe(`${option}=${value}: 0`);
456+
}
457+
458+
// The assigned spelling is one token and was never a hazard, but a scan
459+
// that special-cased the separated form would have found this one.
454460
expect(
455-
(yield* declaredFor("workflow", ["workflow", "--id", "release-1", "start", "flow.md"]))
456-
.length,
457-
).toBe(35);
461+
yield* declaredFor("workflow", ["workflow", "--output=start.xmd", "export", "r"]),
462+
).toEqual([]);
463+
464+
// And the same reading still finds a real action written after an option.
465+
const executing: readonly (readonly string[])[] = [
466+
["workflow", "--plugin", "list", "start", "flow.md"],
467+
["workflow", "--id", "release-1", "start", "flow.md"],
468+
["workflow", "--at", "event-4", "fork", "run-1", "flow.md"],
469+
["workflow", "--verbose", "resume", "run-1"],
470+
];
471+
for (const args of executing) {
472+
const declared = yield* declaredFor("workflow", args);
473+
expect(`${args.join(" ")}: ${declared.length}`).toBe(`${args.join(" ")}: 35`);
474+
}
458475
});
459476

460477
it("registers the six reserved names where it claims the graph", function* () {

β€Žpackages/code-review-agent/src/plugin.tsβ€Ž

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,31 @@ import { reviewComponentDeclarations, useReviewComponents } from "./review-compo
3333
const EXECUTING_ACTIONS: ReadonlySet<string> = new Set(["start", "resume", "fork"]);
3434

3535
/**
36-
* The `xmd workflow` options that take a separated value.
36+
* Every `xmd workflow` option that takes a separated value.
3737
*
3838
* A value is not an action however much it reads like one, so the scan below
39-
* steps over the token after each of these. `--plugin` is the one that makes
40-
* this necessary rather than merely careful: `xmd workflow --plugin start list`
41-
* selects a module called `start` and runs the management action `list`, and a
42-
* scan that read the first recognized word would have run the review graph for
43-
* a command that executes no document.
39+
* steps over the token after each of these. The list is every non-boolean field
40+
* of the command's own grammar (`workflowConfig` in
41+
* `packages/cli/src/workflow.ts`) plus the two options read out of argv before
42+
* that grammar exists: `--plugin`, and the aggregate and generated root
43+
* properties. The boolean switches β€” `--verbose`/`-V`, `--raw`,
44+
* `--secret-detection`, `--no-secret-detection`, `--json`, `--forkable` β€” take
45+
* no value and are skipped as the options they are.
46+
*
47+
* It has to be written out here rather than read from the command, because the
48+
* CLI depends on this package and not the other way round. What makes the
49+
* omission of one visible is the rule it breaks: `xmd workflow --output start
50+
* export run-1` exports a run, and a scan that read `start` as the action would
51+
* have installed the review graph for a command that executes no document.
4452
*/
45-
const VALUED_OPTIONS: ReadonlySet<string> = new Set(["--plugin", "--id", "--at", "--artifact"]);
53+
const VALUED_OPTIONS: ReadonlySet<string> = new Set([
54+
"--plugin",
55+
"--id",
56+
"--at",
57+
"--status",
58+
"--artifact",
59+
"--output",
60+
]);
4661

4762
/** The generated root-property options, which take a separated value too. */
4863
const PROPERTY_OPTION = "--props";

0 commit comments

Comments
Β (0)