@devries-cameron20 / composio-1 / commits / 133b4e2e7
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

refactor(cli): define the command module layout and enforce test presence (#4887)

This PR: - first of a series that restructures `ts/packages/cli/src/commands` so every command has the same file shape; this one only sets the conventions and the guard, with no runtime change - documents the per-command directory layout (`<group>/<name>/<group>.<name>.{cmd,handler,format,errors}.ts`) and its mirrored test layout in `ts/packages/cli/AGENTS.md` and the `cli-command` skill, including the rules the later PRs will apply: three-argument `Command.make` with the handler imported from `.handler.ts`, no `GetCmdParams`, one definition for commands that appear in both the root and `dev` trees - adds `pnpm run validate:command-tests` (`scripts/validate-command-tests.ts`, run by `pnpm test`): a command module without a `.cmd.test.ts` at its mirrored path fails, an orphan `.cmd.test.ts` fails, and a listed exemption that gains its test fails as stale, so `COMMAND_TEST_EXEMPTIONS` only shrinks - lists the 18 commands that have no test today as exemptions with a reason each; group entries (`<dir>/<dir>.cmd.ts` with commands below it) are exempt by construction, as `root-help-consistency.test.ts` covers them - renames `src/commands/logs-cmd/` to `logs/` and moves the four stray tests (`agent`, `generate`, `orgs.switch`, `version`) to their mirrored locations ## Context Today a `.cmd.ts` file holds flags, errors, handler, formatting, and in five cases a second registration for the `dev` tree; the largest ones are 1k to 2k lines. The follow-up PRs migrate commands one at a time into the layout documented here, provide auth and project resolution through `Command.provide` on the group, and collapse the duplicate root/`dev` registrations with `Command.withSharedFlags`. Landing the layout and the guard first lets each of those PRs be reviewed against a written rule.

Alberto Schiabel committed Oct 15, 2026 at 16:59 UTC 133b4e2e71d56904cfef159202c11df515fe6dec
22 files changed +434 -21
.agents/skills/cli-command/references/implementation.md
+41 -12
@@ -2,19 +2,33 @@
2
3 ## Command Files
4
5 -- Top-level command files use `<name>.cmd.ts`.
6 -- Nested command groups live in a directory with a group entrypoint.
5 +One directory per command under `src/commands/`, files sharing the command's dotted basename. The authoritative description, including the legacy shape and the test mirror, is "Command module layout" in `ts/packages/cli/AGENTS.md`; the short form:
6 +
7 +```
8 +src/commands/<group>/<group>.cmd.ts group entry: subcommand list only
9 +src/commands/<group>/<name>/<group>.<name>.cmd.ts flags, description, examples, Command.make
10 +src/commands/<group>/<name>/<group>.<name>.handler.ts (params) => Effect
11 +src/commands/<group>/<name>/<group>.<name>.format.ts stderr renderer + stdout renderer
12 +src/commands/<group>/<name>/<group>.<name>.errors.ts command-owned tagged errors, optional
13 +test/src/commands/<group>/<name>/<group>.<name>.cmd.test.ts argv-level, required
14 +test/src/commands/<group>/<name>/<group>.<name>.handler.test.ts handler-level, optional
15 +```
16 +
17 +- Top-level commands use the same shape without a group: `src/commands/<name>/<name>.cmd.ts`.
18 - Register new commands through `src/commands/index.ts` or the nearest group entry.
19 +- A command still in the legacy single-file shape (`<group>/commands/<group>.<name>.cmd.ts`, or top-level `<name>.cmd.ts`) is migrated in the PR that next changes it substantively, one command per PR.
20 +- `pnpm run validate:command-tests` (in `pnpm test`) fails on a command without its mirrored `.cmd.test.ts`, on an orphan `.cmd.test.ts`, and on a stale exemption. Add the test with the command; do not add exemptions.
21
22 ## Effect Patterns
23
24 The CLI is on `effect@4.0.3` (exact pin) plus `@effect/platform-bun`/`@effect/vitest` at the same version. `@effect/cli` and `@effect/platform` no longer exist as separate deps — their functionality is consolidated into `effect`'s barrel and `effect/*` submodules.
25
13 -Common shape, from `ts/packages/cli/src/commands/tools/commands/tools.list.cmd.ts`:
26 +Common shape. The command file declares the surface and passes the handler to the three-argument `Command.make`:
27
28 ```typescript
29 +// src/commands/tools/list/tools.list.cmd.ts
30 import { Argument, Command, Flag } from 'effect/cli';
17 -import { Effect, Option } from 'effect';
31 +import { runToolsList } from './tools.list.handler';
32
33 const toolkit = Argument.String('toolkit').pipe(
34 Argument.withDescription('Toolkit slug to list tools for (e.g. "gmail")')
@@ -30,14 +44,29 @@ const limit = Flag.Int('limit').pipe(
44 Flag.withDescription('Number of results per page (1-1000)')
45 );
46
33 -export const myCmd = Command.make(
34 - 'my-command',
35 - { toolkit, query, limit },
36 - ({ toolkit, query, limit }) =>
37 - Effect.gen(function* () {
38 - // resolve services with yield*
39 - })
40 -).pipe(Command.withDescription('...'));
47 +export const toolsCmd$List = Command.make('list', { toolkit, query, limit }, runToolsList).pipe(
48 + Command.withDescription('List tools in a toolkit.')
49 +);
50 +```
51 +
52 +The handler declares the params it needs as a plain type; the compiler checks that the command's flags satisfy it. No `Effect.gen` and no service access in the command file:
53 +
54 +```typescript
55 +// src/commands/tools/list/tools.list.handler.ts
56 +import { Effect, Option } from 'effect';
57 +import { TerminalUI } from 'src/services/terminal-ui';
58 +
59 +export type ToolsListParams = {
60 + readonly toolkit: string;
61 + readonly query: Option.Option<string>;
62 + readonly limit: number;
63 +};
64 +
65 +export const runToolsList = ({ toolkit, query, limit }: ToolsListParams) =>
66 + Effect.gen(function* () {
67 + const ui = yield* TerminalUI;
68 + // resolve services with yield*, render through ./tools.list.format
69 + });
70 ```
71
72 `Args`/`Options` (v3 `@effect/cli`) are gone — use `Argument` for positionals and `Flag` for named options, both from `effect/cli`. Constructors are capitalized (`Argument.String`, `Flag.String`/`.Boolean`/`.Int`/`.Literals`); `Argument.variadic()` remains lowercase and must be called rather than piped as a bare reference. Combinators remain lowercase (`.withDefault`/`.withDescription`/`.withAlias`/`.optional`). Optional flags read via `Option.getOrUndefined(...)`/`Option.isSome(...)`, matching the `query`/`tags` pattern above.
ts/packages/cli/AGENTS.md
+42 -2
@@ -29,7 +29,7 @@ Errors are captured via the custom `effect-errors/` module (source-mapped stack
29
30 ### Commands — `src/commands/`
31
32 -Each command uses `effect/cli`'s `Command.make()` pattern. Top-level command files end in `.cmd.ts`; nested command groups live in their own subdirectory with a `<group>.cmd.ts` entry. Current top-level commands:
32 +Each command uses `effect/cli`'s `Command.make()` pattern. Current top-level commands:
33
34 | Group / Command | Purpose |
35 | -------------------- | -------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
@@ -51,7 +51,7 @@ Each command uses `effect/cli`'s `Command.make()` pattern. Top-level command fil
51 | `connections` | Alias / helper for connected-account flows |
52 | `orgs` | Manage organizations |
53 | `projects` | Manage projects |
54 -| `logs` | View tool-execution logs (`logs-cmd/`) |
54 +| `logs` | View tool-execution logs |
55 | `config` | Read/write CLI config |
56 | `listen` | Listen for events |
57 | `proxy` | Proxy authenticated API requests |
@@ -61,6 +61,46 @@ Each command uses `effect/cli`'s `Command.make()` pattern. Top-level command fil
61
62 Named options use `Flag.String()`, `Flag.Boolean()`, `Flag.Int()`, `Flag.Literals()`, `Flag.Directory()` (from `effect/cli`); positionals use `Argument.String()` / `Argument.variadic()`. Both share `.withDefault`/`.withDescription`/`.withAlias`/`.optional` combinators. Feature flags live in `feature-tags.ts` and `experimental-features.ts`.
63
64 +#### Command module layout
65 +
66 +Every command is a directory named after the command, holding files that share the command's dotted basename. A group is a directory named after the group, whose entry file `<group>.cmd.ts` only lists subcommands.
67 +
68 +```
69 +src/commands/
70 + index.ts root command tree, argv contract with cli-main.ts
71 + $default.cmd.ts root command: shared flags and description
72 + <group>/<group>.cmd.ts group entry: Command.make(name) + withSubcommands, nothing else
73 + <group>/<name>/<group>.<name>.cmd.ts flags, arguments, description, examples, Command.make
74 + <group>/<name>/<group>.<name>.handler.ts (params) => Effect; imports nothing from effect/cli
75 + <group>/<name>/<group>.<name>.format.ts human renderer (stderr) and machine renderer (stdout)
76 + <group>/<name>/<group>.<name>.errors.ts command-owned Data.TaggedError classes, when any
77 + <group>/<shared-module>.ts helpers used by several commands of the group (triggers/parse.ts)
78 + <name>/<name>.cmd.ts a top-level command follows the same shape without a group
79 +```
80 +
81 +Rules:
82 +
83 +- `<group>.<name>.cmd.ts` declares the surface and nothing else: flag and argument constants, `Command.withDescription`, `Command.withExamples`, and the three-argument `Command.make(name, flags, handler)` with the handler imported from the sibling `.handler.ts`. It yields no service and contains no branching. `Command.withHandler` is reserved for `src/commands/index.ts`, where the root handler is attached at assembly time.
84 +- `<group>.<name>.handler.ts` exports the handler as a function of a plain params type it declares itself; the command proves it provides those params when it passes the handler to `Command.make`. Do not derive the params type from the `Command` value (no phantom commands, no `GetCmdParams`).
85 +- A command that exists in both the root tree and the `dev` tree is defined once. The group supplies what differs between the two surfaces through `Command.withSharedFlags` and `Command.provide`, not through a second `Command.make` with a copied description.
86 +- Logic shared across groups belongs in `src/effects/` or `src/services/`, never in another command's directory.
87 +- A group entry is recognised by its place in the tree: `<dir>/<dir>.cmd.ts` or `<dir>/root-<dir>.cmd.ts` with other `.cmd.ts` files below `<dir>/`. The same name with nothing below it (`logout/logout.cmd.ts`) is a top-level command. Every command needs a test; a group entry does not, though one with a default action (`generate`) still gets one.
88 +
89 +Legacy shape still present while commands migrate: `<group>/commands/<group>.<name>.cmd.ts` holding flags, handler, helpers, and errors in one file, and top-level `<name>.cmd.ts` doing the same. Migrate a command to the directory shape when you touch it for more than a one-line fix, one command per PR.
90 +
91 +#### Test layout
92 +
93 +Tests mirror `src/commands/` under `test/src/commands/`, with the legacy `commands/` path segment removed:
94 +
95 +```
96 +test/src/commands/<group>/<name>/<group>.<name>.cmd.test.ts argv-level: cli([...]) over TestLive
97 +test/src/commands/<group>/<name>/<group>.<name>.handler.test.ts handler-level: Service.of doubles, no argv
98 +test/src/commands/<group>/<name>/<group>.<name>.<aspect>.cmd.test.ts extra suite for one aspect (.client. for API-shape coverage)
99 +test/src/commands/<group>/<shared-module>.test.ts group helper tests (triggers/format.test.ts)
100 +```
101 +
102 +`pnpm run validate:command-tests` (part of `pnpm test`, CI-blocking, `scripts/validate-command-tests.ts`) fails when a command has no `.cmd.test.ts` at its mirrored path, when a `.cmd.test.ts` does not resolve to a command by its longest dotted basename prefix, or when a listed exemption has gained its test. Commands without a test today are listed in the script with a reason; the list only shrinks. Write the missing test in the PR that migrates the command.
103 +
104 ### Services — `src/services/`
105
106 | Service | Purpose |
ts/packages/cli/package.json
+2 -1
@@ -30,6 +30,7 @@
30 "build:skills": "tsx ./scripts/build-skills.ts",
31 "validate:skills": "tsx ./scripts/validate-skills.ts",
32 "validate:boundaries": "tsx ./scripts/validate-lint-boundaries.ts",
33 + "validate:command-tests": "tsx ./scripts/validate-command-tests.ts",
34 "install:binary": "bun run ./scripts/install-binary.ts ./dist/composio",
35 "table:metrics": "bun run ./scripts/optimize-metrics-table.ts",
36 "generate:toolkit-slugs": "bun run ./scripts/generate-toolkit-slugs.ts",
@@ -37,7 +38,7 @@
38 "prebuild": "pnpm run typecheck",
39 "build": "tsdown",
40 "bin": "./dist/composio",
40 - "test": "pnpm run validate:skills && pnpm run validate:boundaries && vitest run",
41 + "test": "pnpm run validate:skills && pnpm run validate:boundaries && pnpm run validate:command-tests && vitest run",
42 "prepublishOnly": "pnpm run build && pnpm run build:binary",
43 "typecheck:src": "tsc --noEmit -p ./tsconfig.src.json",
44 "typecheck:test": "tsc --noEmit -p ./tsconfig.test.json",
ts/packages/cli/scripts/command-tests.ts new
+158
@@ -0,0 +1,158 @@
1 +import * as fs from 'node:fs';
2 +import * as path from 'node:path';
3 +
4 +export interface CommandTestExemption {
5 + readonly command: string;
6 + readonly reason: string;
7 +}
8 +
9 +export interface CommandTestInputs {
10 + readonly commands: readonly string[];
11 + readonly tests: readonly string[];
12 + readonly exemptions: readonly CommandTestExemption[];
13 +}
14 +
15 +const COMMAND_SUFFIX = '.cmd.ts';
16 +const TEST_SUFFIX = '.cmd.test.ts';
17 +
18 +// Command paths are relative to src/commands/; tests are relative to
19 +// test/src/commands/. Both use forward slashes.
20 +export const COMMAND_TEST_EXEMPTIONS: readonly CommandTestExemption[] = [
21 + { command: 'agent/commands/agent.claim.cmd.ts', reason: 'no test yet' },
22 + { command: 'agent/commands/agent.inbox.cmd.ts', reason: 'no test yet' },
23 + { command: 'agent/commands/agent.login.cmd.ts', reason: 'no test yet' },
24 + { command: 'agent/commands/agent.signup.cmd.ts', reason: 'no test yet' },
25 + { command: 'agent/commands/agent.whoami.cmd.ts', reason: 'no test yet' },
26 + { command: 'artifacts.cmd.ts', reason: 'no test yet' },
27 + { command: 'connections/commands/connections.remove.cmd.ts', reason: 'no test yet' },
28 + { command: 'debug.cmd.ts', reason: 'no test yet' },
29 + {
30 + command: 'generate/generate.py.cmd.ts',
31 + reason: 'thin wrapper over py.generate; covered by py/py.generate.cmd.test.ts',
32 + },
33 + {
34 + command: 'generate/generate.ts.cmd.ts',
35 + reason: 'thin wrapper over ts.generate; covered by ts/ts.generate.cmd.test.ts',
36 + },
37 + {
38 + command: 'logs/commands/logs.triggers.cmd.ts',
39 + reason: 'covered by logs.triggers.client.cmd.test.ts; split pending',
40 + },
41 + { command: 'orgs/commands/orgs.list.cmd.ts', reason: 'no test yet' },
42 + { command: 'signup.cmd.ts', reason: 'no test yet' },
43 + {
44 + command: 'triggers/commands/triggers.create.cmd.ts',
45 + reason: 'covered by triggers.mutations.cmd.test.ts; split pending',
46 + },
47 + {
48 + command: 'triggers/commands/triggers.disable.cmd.ts',
49 + reason: 'covered by triggers.mutations.cmd.test.ts; split pending',
50 + },
51 + {
52 + command: 'triggers/commands/triggers.enable.cmd.ts',
53 + reason: 'covered by triggers.mutations.cmd.test.ts; split pending',
54 + },
55 + { command: 'triggers/commands/triggers.listen.cmd.ts', reason: 'no test yet' },
56 + { command: 'upgrade.cmd.ts', reason: 'no test yet' },
57 +];
58 +
59 +// A group entry is `<dir>.cmd.ts` or `root-<dir>.cmd.ts` inside `<dir>/` when
60 +// `<dir>/` holds other command modules; it only wires subcommands and is
61 +// covered by root-help-consistency.test.ts. The same name with nothing below
62 +// it is a top-level command in the per-command directory shape
63 +// (`login/login.cmd.ts`).
64 +export const isGroupEntry = (command: string, commands: readonly string[]): boolean => {
65 + const segments = command.split('/');
66 + const dir = segments.at(-2);
67 + const base = segments.at(-1);
68 + if (dir === undefined || base === undefined) return false;
69 + if (base !== `${dir}${COMMAND_SUFFIX}` && base !== `root-${dir}${COMMAND_SUFFIX}`) return false;
70 + const prefix = `${segments.slice(0, -1).join('/')}/`;
71 + return commands.some(other => other !== command && other.startsWith(prefix));
72 +};
73 +
74 +export const mirroredTestPath = (command: string): string =>
75 + command
76 + .split('/')
77 + .filter(segment => segment !== 'commands')
78 + .join('/')
79 + .replace(/\.cmd\.ts$/, TEST_SUFFIX);
80 +
81 +// Resolves a test to the command it exercises: the longest dotted prefix of
82 +// its basename that names a `<prefix>.cmd.ts` anywhere under src/commands/.
83 +// Extra segments name a test aspect (`setup.telemetry`, `tools.execute.client`).
84 +export const resolveTestCommand = (
85 + test: string,
86 + commands: readonly string[]
87 +): string | undefined => {
88 + const base = path.posix.basename(test, TEST_SUFFIX);
89 + const byBasename = new Map(commands.map(command => [path.posix.basename(command), command]));
90 + const parts = base.split('.');
91 + for (let length = parts.length; length > 0; length--) {
92 + const match = byBasename.get(`${parts.slice(0, length).join('.')}${COMMAND_SUFFIX}`);
93 + if (match !== undefined) return match;
94 + }
95 + return undefined;
96 +};
97 +
98 +export const checkCommandTests = ({
99 + commands,
100 + tests,
101 + exemptions,
102 +}: CommandTestInputs): readonly string[] => {
103 + const errors: string[] = [];
104 + const testSet = new Set(tests);
105 + const commandSet = new Set(commands);
106 + const exempted = new Map(exemptions.map(exemption => [exemption.command, exemption]));
107 +
108 + for (const exemption of exemptions) {
109 + if (!commandSet.has(exemption.command)) {
110 + errors.push(
111 + `stale exemption: ${exemption.command} is not a command under src/commands/; remove it from COMMAND_TEST_EXEMPTIONS.`
112 + );
113 + } else if (isGroupEntry(exemption.command, commands)) {
114 + errors.push(
115 + `stale exemption: ${exemption.command} is a group entry and needs no test; remove it from COMMAND_TEST_EXEMPTIONS.`
116 + );
117 + }
118 + }
119 +
120 + for (const command of [...commands].sort()) {
121 + if (isGroupEntry(command, commands)) continue;
122 + const expected = mirroredTestPath(command);
123 + const hasTest = testSet.has(expected);
124 + if (exempted.has(command)) {
125 + if (hasTest) {
126 + errors.push(
127 + `stale exemption: ${command} now has test/src/commands/${expected}; remove it from COMMAND_TEST_EXEMPTIONS.`
128 + );
129 + }
130 + } else if (!hasTest) {
131 + errors.push(`missing test: src/commands/${command} needs test/src/commands/${expected}.`);
132 + }
133 + }
134 +
135 + for (const test of [...tests].sort()) {
136 + if (resolveTestCommand(test, commands) === undefined) {
137 + errors.push(
138 + `orphan test: test/src/commands/${test} matches no <prefix>.cmd.ts under src/commands/.`
139 + );
140 + }
141 + }
142 +
143 + return errors;
144 +};
145 +
146 +const listFiles = (root: string, suffix: string): string[] =>
147 + fs
148 + .readdirSync(root, { recursive: true, encoding: 'utf8' })
149 + .filter(file => file.endsWith(suffix) && fs.statSync(path.join(root, file)).isFile())
150 + .map(file => file.split(path.sep).join('/'))
151 + .sort();
152 +
153 +export const collectCommandTests = (
154 + packageRoot: string
155 +): { readonly commands: readonly string[]; readonly tests: readonly string[] } => ({
156 + commands: listFiles(path.join(packageRoot, 'src', 'commands'), COMMAND_SUFFIX),
157 + tests: listFiles(path.join(packageRoot, 'test', 'src', 'commands'), TEST_SUFFIX),
158 +});
ts/packages/cli/scripts/validate-command-tests.ts new
+34
@@ -0,0 +1,34 @@
1 +// Guards the CLI's command test layout: every command module under
2 +// src/commands/ must have a test at its mirrored path under test/src/commands/
3 +// (drop `commands/` segments, swap `.cmd.ts` for `.cmd.test.ts`), and every
4 +// `*.cmd.test.ts` must resolve to a command. Group entries (`<dir>.cmd.ts`,
5 +// `root-<dir>.cmd.ts`) are covered by root-help-consistency.test.ts.
6 +// COMMAND_TEST_EXEMPTIONS in command-tests.ts lists untested commands; it only
7 +// shrinks, since an exemption whose test now exists fails as stale.
8 +//
9 +// Usage:
10 +// tsx ./scripts/validate-command-tests.ts
11 +import * as path from 'node:path';
12 +
13 +import {
14 + checkCommandTests,
15 + collectCommandTests,
16 + COMMAND_TEST_EXEMPTIONS,
17 + isGroupEntry,
18 +} from './command-tests';
19 +
20 +const scriptDir = import.meta.dirname ?? path.dirname(new URL(import.meta.url).pathname);
21 +const packageRoot = path.resolve(scriptDir, '..');
22 +
23 +const { commands, tests } = collectCommandTests(packageRoot);
24 +const errors = checkCommandTests({ commands, tests, exemptions: COMMAND_TEST_EXEMPTIONS });
25 +
26 +if (errors.length > 0) {
27 + console.error(errors.join('\n'));
28 + process.exit(1);
29 +}
30 +
31 +const checked = commands.filter(command => !isGroupEntry(command, commands)).length;
32 +console.log(
33 + `command tests OK: ${checked} commands checked against ${tests.length} test files, ${COMMAND_TEST_EXEMPTIONS.length} exemptions remaining.`
34 +);
ts/packages/cli/src/commands/dev.cmd.ts
+1 -1
@@ -2,7 +2,7 @@ import { Command, Flag } from 'effect/cli';
2 import { Data, Effect, Option } from 'effect';
3 import { initCmd } from './init.cmd';
4 import { triggersCmd$Listen } from './triggers/commands/triggers.listen.cmd';
5 -import { logsCmd } from './logs-cmd/logs.cmd';
5 +import { logsCmd } from './logs/logs.cmd';
6 import { devToolsCmd$Execute } from './tools/commands/tools.execute.cmd';
7 import { toolkitsCmd } from './toolkits/toolkits.cmd';
8 import { authConfigsCmd } from './auth-configs/auth-configs.cmd';
ts/packages/cli/src/commands/logs/commands/logs.tools.cmd.ts renamed
ts/packages/cli/src/commands/logs/commands/logs.triggers.cmd.ts renamed
ts/packages/cli/src/commands/logs/format.ts renamed
+1 -1
@@ -1,5 +1,5 @@
1 import type { Logs } from '@composio/client/resources/logs/logs';
2 -import type { TriggerLogRecord } from 'src/commands/logs-cmd/trigger-log-record';
2 +import type { TriggerLogRecord } from 'src/commands/logs/trigger-log-record';
3 import { bold, gray, green, red } from 'src/ui/colors';
4 import { truncate } from 'src/ui/truncate';
5
ts/packages/cli/src/commands/logs/logs.cmd.ts renamed
ts/packages/cli/src/commands/logs/trigger-log-record.ts renamed
ts/packages/cli/src/commands/logs/utils.ts renamed
ts/packages/cli/test/src/commands/agent/agent.cmd.test.ts renamed
ts/packages/cli/test/src/commands/generate/generate.cmd.test.ts renamed
ts/packages/cli/test/src/commands/logs/format.test.ts renamed
+2 -2
@@ -5,11 +5,11 @@ import {
5 formatToolLogInfo,
6 formatToolLogsTable,
7 formatTriggerLogsTable,
8 -} from 'src/commands/logs-cmd/format';
8 +} from 'src/commands/logs/format';
9 import {
10 decodeTriggerLogRecord,
11 type TriggerLogRecord,
12 -} from 'src/commands/logs-cmd/trigger-log-record';
12 +} from 'src/commands/logs/trigger-log-record';
13 import { green, red } from 'src/ui/colors';
14
15 type ToolLog = Logs.ToolListResponse.Data;
ts/packages/cli/test/src/commands/logs/logs.tools.client.cmd.test.ts renamed
ts/packages/cli/test/src/commands/logs/logs.tools.cmd.test.ts renamed
+1 -1
@@ -1,5 +1,5 @@
1 import { describe, expect, it } from 'vitest';
2 -import { buildToolLogShorthandSearchParams } from 'src/commands/logs-cmd/commands/logs.tools.cmd';
2 +import { buildToolLogShorthandSearchParams } from 'src/commands/logs/commands/logs.tools.cmd';
3
4 describe('buildToolLogShorthandSearchParams', () => {
5 it('[Given] no filters [Then] returns empty search params', () => {
ts/packages/cli/test/src/commands/logs/logs.triggers.client.cmd.test.ts renamed
ts/packages/cli/test/src/commands/logs/trigger-log-record.test.ts renamed
+1 -1
@@ -3,7 +3,7 @@ import {
3 decodeTriggerLogRecord,
4 emptyTriggerLogRecord,
5 parseMaybeJson,
6 -} from 'src/commands/logs-cmd/trigger-log-record';
6 +} from 'src/commands/logs/trigger-log-record';
7
8 describe('decodeTriggerLogRecord', () => {
9 it('[Given] camelCase-only payload [Then] resolves detail and table fields', () => {
ts/packages/cli/test/src/commands/orgs/orgs.switch.cmd.test.ts renamed
ts/packages/cli/test/src/commands/version.cmd.test.ts renamed
ts/packages/cli/test/src/scripts/command-tests.test.ts new
+151
@@ -0,0 +1,151 @@
1 +import * as path from 'node:path';
2 +
3 +import { describe, expect, it } from 'vitest';
4 +
5 +import {
6 + checkCommandTests,
7 + collectCommandTests,
8 + COMMAND_TEST_EXEMPTIONS,
9 + isGroupEntry,
10 + mirroredTestPath,
11 + resolveTestCommand,
12 +} from '../../../scripts/command-tests';
13 +
14 +const commands = [
15 + 'login.cmd.ts',
16 + 'logout/logout.cmd.ts',
17 + 'setup.cmd.ts',
18 + 'tools/tools.cmd.ts',
19 + 'tools/commands/tools.execute.cmd.ts',
20 + 'tools/list/tools.list.cmd.ts',
21 + 'triggers/root-triggers.cmd.ts',
22 + 'triggers/triggers.cmd.ts',
23 + 'triggers/commands/triggers.create.cmd.ts',
24 +];
25 +
26 +const tests = [
27 + 'login.cmd.test.ts',
28 + 'logout/logout.cmd.test.ts',
29 + 'setup.cmd.test.ts',
30 + 'setup.telemetry.cmd.test.ts',
31 + 'tools/tools.execute.cmd.test.ts',
32 + 'tools/tools.execute.client.cmd.test.ts',
33 + 'tools/list/tools.list.cmd.test.ts',
34 + 'triggers/triggers.mutations.cmd.test.ts',
35 +];
36 +
37 +const exemptions = [
38 + {
39 + command: 'triggers/commands/triggers.create.cmd.ts',
40 + reason: 'covered by triggers.mutations.cmd.test.ts; split pending',
41 + },
42 +];
43 +
44 +describe('command test layout', () => {
45 + it('detects group entries by their parent directory holding other commands', () => {
46 + expect(isGroupEntry('tools/tools.cmd.ts', commands)).toBe(true);
47 + expect(isGroupEntry('triggers/root-triggers.cmd.ts', commands)).toBe(true);
48 + expect(isGroupEntry('triggers/triggers.cmd.ts', commands)).toBe(true);
49 + expect(isGroupEntry('login.cmd.ts', commands)).toBe(false);
50 + expect(isGroupEntry('tools/commands/tools.list.cmd.ts', commands)).toBe(false);
51 + expect(isGroupEntry('tools/list/tools.list.cmd.ts', commands)).toBe(false);
52 + });
53 +
54 + it('treats <name>/<name>.cmd.ts with nothing below it as a top-level command', () => {
55 + expect(isGroupEntry('logout/logout.cmd.ts', commands)).toBe(false);
56 + expect(mirroredTestPath('logout/logout.cmd.ts')).toBe('logout/logout.cmd.test.ts');
57 + expect(
58 + checkCommandTests({
59 + commands,
60 + tests: tests.filter(test => test !== 'logout/logout.cmd.test.ts'),
61 + exemptions,
62 + })
63 + ).toEqual([
64 + 'missing test: src/commands/logout/logout.cmd.ts needs test/src/commands/logout/logout.cmd.test.ts.',
65 + ]);
66 + });
67 +
68 + it('mirrors both the legacy and the per-command directory layouts', () => {
69 + expect(mirroredTestPath('login.cmd.ts')).toBe('login.cmd.test.ts');
70 + expect(mirroredTestPath('tools/commands/tools.list.cmd.ts')).toBe(
71 + 'tools/tools.list.cmd.test.ts'
72 + );
73 + expect(mirroredTestPath('tools/list/tools.list.cmd.ts')).toBe(
74 + 'tools/list/tools.list.cmd.test.ts'
75 + );
76 + expect(mirroredTestPath('ts/commands/ts.generate.cmd.ts')).toBe('ts/ts.generate.cmd.test.ts');
77 + });
78 +
79 + it('resolves aspect-suffixed tests to the longest matching command prefix', () => {
80 + expect(resolveTestCommand('setup.telemetry.cmd.test.ts', commands)).toBe('setup.cmd.ts');
81 + expect(resolveTestCommand('tools/tools.execute.client.cmd.test.ts', commands)).toBe(
82 + 'tools/commands/tools.execute.cmd.ts'
83 + );
84 + expect(resolveTestCommand('triggers/triggers.mutations.cmd.test.ts', commands)).toBe(
85 + 'triggers/triggers.cmd.ts'
86 + );
87 + expect(resolveTestCommand('nope.cmd.test.ts', commands)).toBeUndefined();
88 + });
89 +
90 + it('passes when every command is tested or exempted', () => {
91 + expect(checkCommandTests({ commands, tests, exemptions })).toEqual([]);
92 + });
93 +
94 + it('reports a command without its mirrored test', () => {
95 + expect(
96 + checkCommandTests({
97 + commands,
98 + tests: tests.filter(test => test !== 'tools/list/tools.list.cmd.test.ts'),
99 + exemptions,
100 + })
101 + ).toEqual([
102 + 'missing test: src/commands/tools/list/tools.list.cmd.ts needs test/src/commands/tools/list/tools.list.cmd.test.ts.',
103 + ]);
104 + });
105 +
106 + it('reports a test that matches no command', () => {
107 + expect(
108 + checkCommandTests({
109 + commands,
110 + tests: [...tests, 'agent/agent.claim.cmd.test.ts'],
111 + exemptions,
112 + })
113 + ).toEqual([
114 + 'orphan test: test/src/commands/agent/agent.claim.cmd.test.ts matches no <prefix>.cmd.ts under src/commands/.',
115 + ]);
116 + });
117 +
118 + it('reports an exemption whose command now has its mirrored test', () => {
119 + expect(
120 + checkCommandTests({
121 + commands,
122 + tests: [...tests, 'triggers/triggers.create.cmd.test.ts'],
123 + exemptions,
124 + })
125 + ).toEqual([
126 + 'stale exemption: triggers/commands/triggers.create.cmd.ts now has test/src/commands/triggers/triggers.create.cmd.test.ts; remove it from COMMAND_TEST_EXEMPTIONS.',
127 + ]);
128 + });
129 +
130 + it('reports an exemption for a command that no longer exists', () => {
131 + expect(
132 + checkCommandTests({
133 + commands,
134 + tests,
135 + exemptions: [...exemptions, { command: 'gone.cmd.ts', reason: 'no test yet' }],
136 + })
137 + ).toEqual([
138 + 'stale exemption: gone.cmd.ts is not a command under src/commands/; remove it from COMMAND_TEST_EXEMPTIONS.',
139 + ]);
140 + });
141 +
142 + it('holds for the current package tree', () => {
143 + const packageRoot = path.resolve(import.meta.dirname, '../../..');
144 + expect(
145 + checkCommandTests({
146 + ...collectCommandTests(packageRoot),
147 + exemptions: COMMAND_TEST_EXEMPTIONS,
148 + })
149 + ).toEqual([]);
150 + });
151 +});