From 34599ec5ff58ece3a9fa38c5d050f1e4fbfb0320 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Thu, 3 Dec 2026 20:00:02 +0800 Subject: [PATCH] test(cli): share instructions completion fixtures (#16330) --- tests/boundary/cli/completions.test.ts | 65 +++++++++++--------------- 1 file changed, 26 insertions(+), 39 deletions(-) diff --git a/tests/boundary/cli/completions.test.ts b/tests/boundary/cli/completions.test.ts index a38bec2842c..21a7f3c13fc 100644 --- a/tests/boundary/cli/completions.test.ts +++ b/tests/boundary/cli/completions.test.ts @@ -56,6 +56,9 @@ const complete = (words: string[], index = words.length - 1) => { .map((value) => (value.endsWith("\x01") ? value.slice(0, -1) : value)); }; +const completeInstructions = (...words: string[]) => + complete(["rea", "instructions", ...words]); + const completeBash = ( line: string, fragment: string, @@ -79,21 +82,19 @@ it("resolves enabled builtin scopes in the same tree as registered commands", () }); it("uses canonical global flag metadata and retains command options and enum hints", () => { - expect(complete(["rea", "instructions", "--", "--he"])).toEqual([]); - expect(complete(["rea", "instructions", "--he"])).toEqual(["--help"]); - expect(complete(["rea", "instructions", "--for"])).toEqual(["--format"]); - expect(complete(["rea", "instructions", "--tok"])).toEqual( + expect(completeInstructions("--", "--he")).toEqual([]); + expect(completeInstructions("--he")).toEqual(["--help"]); + expect(completeInstructions("--for")).toEqual(["--format"]); + expect(completeInstructions("--tok")).toEqual( expect.arrayContaining([ "--token-count", "--token-limit", "--token-offset", ]), ); - expect(complete(["rea", "instructions", "--proc"])).toEqual(["--procedure"]); - expect(complete(["rea", "instructions", "--target-format", "--he"])).toEqual([ - "--help", - ]); - expect(complete(["rea", "instructions", "--target-format", ""])).toEqual([ + expect(completeInstructions("--proc")).toEqual(["--procedure"]); + expect(completeInstructions("--target-format", "--he")).toEqual(["--help"]); + expect(completeInstructions("--target-format", "")).toEqual([ "dos-com", "raw-binary", ]); @@ -111,10 +112,8 @@ it("uses canonical global flag metadata and retains command options and enum hin "mcp", "completions", ]); - expect(complete(["rea", "instructions", "--"])).not.toContain( - "--incur-update-check", - ); - expect(complete(["rea", "instructions", "--"])).not.toContain("--mcp"); + expect(completeInstructions("--")).not.toContain("--incur-update-check"); + expect(completeInstructions("--")).not.toContain("--mcp"); }); it("completes whole-word inline values with their option spelling", () => { @@ -123,36 +122,24 @@ it("completes whole-word inline values with their option spelling", () => { completionOutput("nushell", ["rea", "instructions", "--format=j"]), ), ).toEqual([{ value: "--format=json" }, { value: "--format=jsonl" }]); - expect(complete(["rea", "instructions", "--target-format="])).toEqual([ + expect(completeInstructions("--target-format=")).toEqual([ "--target-format=dos-com", "--target-format=raw-binary", ]); - expect(complete(["rea", "instructions", "--targetFormat=r"])).toEqual([]); - expect(complete(["rea", "instructions", "-f", "r"])).toEqual(["raw-binary"]); - expect(complete(["rea", "instructions", "-f=r"])).toEqual([]); + expect(completeInstructions("--targetFormat=r")).toEqual([]); + expect(completeInstructions("-f", "r")).toEqual(["raw-binary"]); + expect(completeInstructions("-f=r")).toEqual([]); + expect(completeInstructions("example.f", "--target-format=r")).toEqual([ + "--target-format=raw-binary", + ]); + expect(completeInstructions("--no-dry-run", "--target-format=r")).toEqual([ + "--target-format=raw-binary", + ]); expect( - complete(["rea", "instructions", "example.f", "--target-format=r"]), - ).toEqual(["--target-format=raw-binary"]); - expect( - complete(["rea", "instructions", "--no-dry-run", "--target-format=r"]), - ).toEqual(["--target-format=raw-binary"]); - expect( - complete([ - "rea", - "instructions", - "example.bin", - "--procedure", - "--target-format=r", - ]), + completeInstructions("example.bin", "--procedure", "--target-format=r"), ).toEqual([]); expect( - complete([ - "rea", - "instructions", - "--procedure", - "--target-format", - "--target-format=r", - ]), + completeInstructions("--procedure", "--target-format", "--target-format=r"), ).toEqual(["--target-format=raw-binary"]); for (const word of [ "--unknown=j", @@ -160,8 +147,8 @@ it("completes whole-word inline values with their option spelling", () => { "--help=t", "--format=j=", ]) - expect(complete(["rea", "instructions", word])).toEqual([]); - expect(complete(["rea", "instructions", "--", "--format=j"])).toEqual([]); + expect(completeInstructions(word)).toEqual([]); + expect(completeInstructions("--", "--format=j")).toEqual([]); expect( JSON.parse( completionOutput("nushell", [