Closes the last genuinely-empty directory from the prior investigation pass: packages/cli/test/ had zero files despite args.ts/index.ts having real logic. Added 24 passing vitest tests (10 for parseArgs/requireFlag edge cases, 14 for index.ts's command dispatch against a mocked @qie-forge/core) and wired packages/cli into the workspace test/lint scripts. Refactored run()/main() slightly so handler errors are caught and turned into a proper exitCode in one place, making dispatch directly testable without spawning the real CLI process. Committed the previously-uncommitted TEST_LOCK serialization fix for packages/rust/tests/anvil_integration.rs (closes a real resource- contention flake between the two anvil-backed tests, confirmed passing 3x locally, 161-162s each run). Corrected docs/STATUS.md: QieForgeVault.deposit()/withdraw() lender-share accounting has existed since f55e3c6 (18 passing Foundry tests prove it), but a stale "no lender deposit/withdraw flow" claim kept getting repeated in STATUS.md and commit messages without re-reading the actual contract. Removed the false gap, updated the real test counts (41/41 Foundry tests, not 35/35), and documented the new CLI coverage. Full workspace verification: npm test (33/33 JS tests), forge test (41/41), cargo test --test anvil_integration (2/2), pytest (15/15, 8 live-gated skipped), npm run build + npm run lint (core+cli), and `next build` for apps/web — all clean. Live-verified the already-shipped demo deployment is still actually serving real data: curl against qie-forge.vercel.app/api/quote and /api/vault-position return the real on-chain quote (10 WQIE -> 1.39573 TUSD) and real vault position (500,000 WQIE collateral, 20,000 TUSD debt, 2.8x health factor) described in STATUS.md, and both /swap and /vault render the "demo network" banner live, not the empty "not deployed" state.
55 lines
2.1 KiB
TypeScript
55 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { parseArgs, requireFlag } from "../src/args.js";
|
|
|
|
describe("parseArgs", () => {
|
|
it("extracts the command and leaves flags empty when none are given", () => {
|
|
expect(parseArgs(["chain-info"])).toEqual({ command: "chain-info", flags: {} });
|
|
});
|
|
|
|
it("returns an undefined command for an empty argv", () => {
|
|
expect(parseArgs([])).toEqual({ command: undefined, flags: {} });
|
|
});
|
|
|
|
it("parses a `--flag value` pair", () => {
|
|
const parsed = parseArgs(["balance", "--network", "testnet", "--address", "0xabc"]);
|
|
expect(parsed).toEqual({
|
|
command: "balance",
|
|
flags: { network: "testnet", address: "0xabc" },
|
|
});
|
|
});
|
|
|
|
it("treats a trailing flag with no value as the boolean string \"true\"", () => {
|
|
const parsed = parseArgs(["chain-info", "--verbose"]);
|
|
expect(parsed.flags).toEqual({ verbose: "true" });
|
|
});
|
|
|
|
it("treats a flag immediately followed by another flag as boolean \"true\", not consuming the next flag's name as its value", () => {
|
|
const parsed = parseArgs(["oracle-price", "--verbose", "--asset", "BTC"]);
|
|
expect(parsed.flags).toEqual({ verbose: "true", asset: "BTC" });
|
|
});
|
|
|
|
it("ignores bare positional tokens that are not prefixed with --", () => {
|
|
const parsed = parseArgs(["chain-info", "extra-positional", "--network", "mainnet"]);
|
|
expect(parsed.flags).toEqual({ network: "mainnet" });
|
|
});
|
|
|
|
it("last occurrence of a repeated flag wins", () => {
|
|
const parsed = parseArgs(["chain-info", "--network", "testnet", "--network", "mainnet"]);
|
|
expect(parsed.flags.network).toBe("mainnet");
|
|
});
|
|
});
|
|
|
|
describe("requireFlag", () => {
|
|
it("returns the value when the flag is present", () => {
|
|
expect(requireFlag({ network: "testnet" }, "network")).toBe("testnet");
|
|
});
|
|
|
|
it("throws a descriptive error naming the missing flag", () => {
|
|
expect(() => requireFlag({}, "address")).toThrowError(/--address/);
|
|
});
|
|
|
|
it("throws on an empty-string value (falsy, same as missing)", () => {
|
|
expect(() => requireFlag({ address: "" }, "address")).toThrowError(/--address/);
|
|
});
|
|
});
|