fix: hc send text after --, history reads send args by name
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
1 parent
2fd0234831
commit
3b7b4618a3
3 files changed
+71
-3
No files matched your search
@@ -0,0 +1,35 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { sendArgs, parseSendArgs, sendNow } from "../mod/ovis-composer/delivery.js";
|
||||
|
||||
const ok = { code: 0, stdout: "{}", stderr: "" };
|
||||
|
||||
test("sendArgs puts the text after `--`, so hc cannot read it as an option", () => {
|
||||
assert.deepEqual(sendArgs("t2", "hello"), ["send", "--json", "t2", "--", "hello"]);
|
||||
});
|
||||
|
||||
test("a text that looks like an option still goes through as the text", async () => {
|
||||
for (const text of ["- fix", "--help", "--force x", "-", "--"]) {
|
||||
const calls = [];
|
||||
const result = await sendNow({ terminal: "t2", hc: async (args) => (calls.push(args), ok) }, text);
|
||||
assert.equal(result.ok, true, text);
|
||||
const args = calls[0];
|
||||
const at = args.indexOf("--");
|
||||
assert.equal(args[at + 1], text, text);
|
||||
assert.equal(args.length, at + 2, text);
|
||||
assert.deepEqual(args.slice(0, at), ["send", "--json", "t2"], text);
|
||||
}
|
||||
});
|
||||
|
||||
test("parseSendArgs reads the named fields back", () => {
|
||||
for (const text of ["hello", "- fix", "--help", "--force x", "z \"q\" ęą"]) {
|
||||
assert.deepEqual(parseSendArgs(sendArgs("t7", text)), { terminal: "t7", text, force: false });
|
||||
}
|
||||
});
|
||||
|
||||
test("parseSendArgs: not a send, or a send of another shape, is nothing", () => {
|
||||
assert.equal(parseSendArgs(["get", "t2", "--json"]), null);
|
||||
assert.equal(parseSendArgs(["send", "t2", "text", "--json"]), null);
|
||||
assert.equal(parseSendArgs(null), null);
|
||||
assert.equal(parseSendArgs([]), null);
|
||||
});
|
||||
Reference in new issue
Block a user