pict-cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +109 -0
  3. package/bin/cli.js +289 -0
  4. package/package.json +62 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Takeshi Kishi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,109 @@
1
+ # pict-cli
2
+
3
+ `pict-cli` is a Node.js-friendly command-line tool for running PICT-style
4
+ combinatorial test generation from npm, CI, or ad hoc shell usage.
5
+
6
+ This is an independent project by the package author and is not affiliated with
7
+ Microsoft. It is inspired by Microsoft PICT and is intended to make similar
8
+ workflows available in a Node.js environment, but it does not claim full
9
+ command-line compatibility with the original `pict` executable.
10
+
11
+ ## Requirements
12
+
13
+ - Node.js `^22 || ^24`
14
+
15
+ ## Installation
16
+
17
+ Install `pict-cli` globally if you want a persistent local command:
18
+
19
+ ```bash
20
+ npm install --global pict-cli
21
+ ```
22
+
23
+ Run it without a global install for one-off usage or CI steps:
24
+
25
+ ```bash
26
+ npx pict-cli <model-file>
27
+ ```
28
+
29
+ Use `npx` for ad hoc runs and CI jobs. Use a global install when you expect to
30
+ run the command repeatedly on the same machine.
31
+
32
+ ## Quick Start
33
+
34
+ Create a model file such as `model.txt`:
35
+
36
+ ```txt
37
+ OS: Windows, Linux
38
+ Browser: Edge, Chrome, Firefox
39
+ ```
40
+
41
+ Generate combinations with either a global install or `npx`:
42
+
43
+ ```bash
44
+ pict-cli model.txt
45
+ npx pict-cli model.txt
46
+ ```
47
+
48
+ Example output:
49
+
50
+ ```text
51
+ OS Browser
52
+ Windows Edge
53
+ Windows Chrome
54
+ Windows Firefox
55
+ Linux Edge
56
+ Linux Chrome
57
+ Linux Firefox
58
+ ```
59
+
60
+ The generated result is written as tab-separated text. If you pass `-s`, the
61
+ command prints model statistics instead of generated cases.
62
+
63
+ ## CLI Usage
64
+
65
+ ```text
66
+ Usage: pict-cli model [options]
67
+ ```
68
+
69
+ `model` must be exactly one model file path.
70
+
71
+ | Option | Description |
72
+ | ----------- | ------------------------------------------------- |
73
+ | `-o N\|max` | Order of combinations. Default: `2`. |
74
+ | `-d C` | Separator for values. Default: `,`. |
75
+ | `-a C` | Separator for aliases. Default: `\`. |
76
+ | `-n C` | Negative value prefix. Default: `~`. |
77
+ | `-e file` | File with seeding rows. |
78
+ | `-r N` | Randomize generation with seed `N`. |
79
+ | `-c` | Enable case-sensitive model evaluation. |
80
+ | `-s` | Show model statistics instead of generated cases. |
81
+
82
+ Examples:
83
+
84
+ ```bash
85
+ pict-cli model.txt -o 3 -c
86
+ pict-cli model.txt -r 42
87
+ pict-cli model.txt -e seed.tsv
88
+ npx pict-cli model.txt -s
89
+ ```
90
+
91
+ ## Compatibility and Limitations
92
+
93
+ - Only short options are supported.
94
+ - Slash-style syntax such as `/o:3` is not supported.
95
+ - Exactly one model file path is required.
96
+
97
+ ## Relationship to Microsoft PICT
98
+
99
+ Microsoft PICT is the original combinatorial testing tool that inspired this
100
+ package. `pict-cli` brings a similar workflow to Node.js through npm
101
+ distribution and a JavaScript runtime, but it is not an official Microsoft
102
+ package and is not endorsed or supported by Microsoft.
103
+
104
+ ## Project Links
105
+
106
+ - Issues: [github.com/takeyaqa/pict-cli/issues](https://github.com/takeyaqa/pict-cli/issues)
107
+ - License: [MIT](https://github.com/takeyaqa/pict-cli/blob/main/LICENSE)
108
+
109
+ Bug reports and compatibility gaps are welcome.
package/bin/cli.js ADDED
@@ -0,0 +1,289 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { readFile } from "node:fs/promises";
4
+ import { argv, exit, stderr, stdout } from "node:process";
5
+ import { parseArgs } from "node:util";
6
+ import { PictError, PictErrorCode, PictRunner } from "@takeyaqa/pict-wasm";
7
+
8
+ const USAGE = `Pairwise Independent Combinatorial Testing
9
+
10
+ Usage: pict-cli model [options]
11
+
12
+ Options:
13
+ -o N|max Order of combinations (default: 2)
14
+ -d C Separator for values (default: ,)
15
+ -a C Separator for aliases (default: |)
16
+ -n C Negative value prefix (default: ~)
17
+ -e file File with seeding rows
18
+ -r N Randomize generation with seed N
19
+ -c Case-sensitive model evaluation
20
+ -s Show model statistics`;
21
+
22
+ const OPTIONS = {
23
+ o: { type: "string", short: "o" },
24
+ d: { type: "string", short: "d" },
25
+ a: { type: "string", short: "a" },
26
+ n: { type: "string", short: "n" },
27
+ e: { type: "string", short: "e" },
28
+ r: { type: "string", short: "r" },
29
+ c: { type: "boolean", short: "c" },
30
+ s: { type: "boolean", short: "s" },
31
+ };
32
+
33
+ class CliError extends Error {
34
+ constructor(code, message, stream = "stderr") {
35
+ super(message);
36
+ this.name = "CliError";
37
+ this.code = code;
38
+ this.stream = stream;
39
+ }
40
+ }
41
+
42
+ function writeLine(stream, text) {
43
+ if (!text) {
44
+ return;
45
+ }
46
+ stream.write(text.endsWith("\n") ? text : `${text}\n`);
47
+ }
48
+
49
+ function usageError() {
50
+ return new CliError(PictErrorCode.BadOption, USAGE, "stdout");
51
+ }
52
+
53
+ function inputError(message) {
54
+ return new CliError(PictErrorCode.BadOption, `Input Error: ${message}`);
55
+ }
56
+
57
+ function rejectUnsupportedSyntax(rawArgs) {
58
+ for (const arg of rawArgs) {
59
+ if (/^--[^-]/.test(arg)) {
60
+ throw inputError(`Unknown option: ${arg}`);
61
+ }
62
+
63
+ if (/^\/[A-Za-z](?::.*)?$/.test(arg) || arg === "/?") {
64
+ throw inputError(`Unknown option: ${arg}`);
65
+ }
66
+
67
+ if (/^-[A-Za-z]=/.test(arg)) {
68
+ throw inputError(`Unknown option: ${arg}`);
69
+ }
70
+
71
+ if (/^-[A-Za-z]:/.test(arg)) {
72
+ throw inputError(`Unknown option: ${arg}`);
73
+ }
74
+
75
+ if (/^-[A-Za-z]{2,}$/.test(arg)) {
76
+ throw inputError(`Unknown option: ${arg}`);
77
+ }
78
+ }
79
+ }
80
+
81
+ function getOptionSource(token, rawArgs) {
82
+ return rawArgs[token.index] ?? token.rawName;
83
+ }
84
+
85
+ function validateTokens(parsed, rawArgs) {
86
+ const seenOptions = new Set();
87
+ const optionSources = new Map();
88
+
89
+ for (const token of parsed.tokens) {
90
+ if (token.kind !== "option") {
91
+ continue;
92
+ }
93
+
94
+ if (!(token.name in OPTIONS)) {
95
+ throw inputError(`Unknown option: ${getOptionSource(token, rawArgs)}`);
96
+ }
97
+
98
+ if (seenOptions.has(token.name)) {
99
+ throw inputError(`Option '${token.name}' was provided more than once`);
100
+ }
101
+
102
+ seenOptions.add(token.name);
103
+ optionSources.set(token.name, getOptionSource(token, rawArgs));
104
+ }
105
+
106
+ return optionSources;
107
+ }
108
+
109
+ function getRequiredString(values, optionName, optionSources) {
110
+ const value = values[optionName];
111
+ if (value === undefined) {
112
+ return undefined;
113
+ }
114
+
115
+ if (typeof value !== "string") {
116
+ throw inputError(`Unknown option: ${optionSources.get(optionName)}`);
117
+ }
118
+
119
+ return value;
120
+ }
121
+
122
+ function getSingleCharacterValue(values, optionName, optionSources) {
123
+ const value = getRequiredString(values, optionName, optionSources);
124
+ if (value === undefined) {
125
+ return undefined;
126
+ }
127
+
128
+ if (value.length !== 1) {
129
+ throw inputError(`Unknown option: ${optionSources.get(optionName)}`);
130
+ }
131
+
132
+ return value;
133
+ }
134
+
135
+ function buildRunConfig(rawArgs) {
136
+ if (rawArgs.length === 0) {
137
+ throw usageError();
138
+ }
139
+
140
+ rejectUnsupportedSyntax(rawArgs);
141
+
142
+ const parsed = parseArgs({
143
+ args: rawArgs,
144
+ options: OPTIONS,
145
+ allowPositionals: true,
146
+ strict: false,
147
+ tokens: true,
148
+ });
149
+ const optionSources = validateTokens(parsed, rawArgs);
150
+
151
+ if (parsed.positionals.length !== 1) {
152
+ if (parsed.positionals.length === 0) {
153
+ throw usageError();
154
+ }
155
+ throw inputError("Exactly one model file path is required");
156
+ }
157
+
158
+ const orderOfCombinations = getRequiredString(
159
+ parsed.values,
160
+ "o",
161
+ optionSources,
162
+ );
163
+ if (
164
+ orderOfCombinations !== undefined &&
165
+ !(
166
+ orderOfCombinations === "max" ||
167
+ (/^\d+$/.test(orderOfCombinations) &&
168
+ Number.parseInt(orderOfCombinations, 10) > 0)
169
+ )
170
+ ) {
171
+ throw inputError(`Unknown option: ${optionSources.get("o")}`);
172
+ }
173
+
174
+ const randomizeSeed = getRequiredString(parsed.values, "r", optionSources);
175
+ if (randomizeSeed !== undefined && !/^\d+$/.test(randomizeSeed)) {
176
+ throw inputError(`Unknown option: ${optionSources.get("r")}`);
177
+ }
178
+
179
+ const valueSeparator = getSingleCharacterValue(
180
+ parsed.values,
181
+ "d",
182
+ optionSources,
183
+ );
184
+ const aliasSeparator = getSingleCharacterValue(
185
+ parsed.values,
186
+ "a",
187
+ optionSources,
188
+ );
189
+ const negativeValuePrefix = getSingleCharacterValue(
190
+ parsed.values,
191
+ "n",
192
+ optionSources,
193
+ );
194
+
195
+ return {
196
+ modelPath: parsed.positionals[0],
197
+ seedFilePath: getRequiredString(parsed.values, "e", optionSources),
198
+ options: {
199
+ ...(orderOfCombinations !== undefined
200
+ ? {
201
+ orderOfCombinations:
202
+ orderOfCombinations === "max"
203
+ ? "max"
204
+ : Number.parseInt(orderOfCombinations, 10),
205
+ }
206
+ : {}),
207
+ ...(valueSeparator !== undefined ? { valueSeparator } : {}),
208
+ ...(aliasSeparator !== undefined ? { aliasSeparator } : {}),
209
+ ...(negativeValuePrefix !== undefined ? { negativeValuePrefix } : {}),
210
+ ...(randomizeSeed !== undefined
211
+ ? {
212
+ randomizeGeneration: true,
213
+ randomizeSeed: Number.parseInt(randomizeSeed, 10),
214
+ }
215
+ : {}),
216
+ ...(parsed.values.c ? { caseSensitive: true } : {}),
217
+ ...(parsed.values.s ? { showModelStatistics: true } : {}),
218
+ },
219
+ };
220
+ }
221
+
222
+ async function readHostFile(filePath, errorCode) {
223
+ try {
224
+ return await readFile(filePath, "utf8");
225
+ } catch {
226
+ throw new CliError(
227
+ errorCode,
228
+ `Input Error: Couldn't open file: ${filePath}`,
229
+ );
230
+ }
231
+ }
232
+
233
+ function formatResult(result) {
234
+ return [result.header, ...result.body]
235
+ .map((row) => row.join("\t"))
236
+ .join("\n");
237
+ }
238
+
239
+ async function main(rawArgs) {
240
+ const config = buildRunConfig(rawArgs);
241
+ const modelText = await readHostFile(
242
+ config.modelPath,
243
+ PictErrorCode.BadModel,
244
+ );
245
+
246
+ if (config.seedFilePath !== undefined) {
247
+ config.options.seedRowsText = await readHostFile(
248
+ config.seedFilePath,
249
+ PictErrorCode.BadRowSeedFile,
250
+ );
251
+ }
252
+
253
+ const runner = await PictRunner.create();
254
+ const output = runner.runModel(modelText, { options: config.options });
255
+
256
+ if (output.message) {
257
+ writeLine(stderr, output.message);
258
+ }
259
+
260
+ if (config.options.showModelStatistics) {
261
+ writeLine(stdout, output.modelStatistics ?? "");
262
+ return PictErrorCode.Success;
263
+ }
264
+
265
+ writeLine(stdout, formatResult(output.result));
266
+ return PictErrorCode.Success;
267
+ }
268
+
269
+ try {
270
+ const exitCode = await main(argv.slice(2));
271
+ exit(exitCode);
272
+ } catch (error) {
273
+ if (error instanceof CliError) {
274
+ writeLine(error.stream === "stdout" ? stdout : stderr, error.message);
275
+ exit(error.code);
276
+ }
277
+
278
+ if (error instanceof PictError) {
279
+ writeLine(stderr, error.message);
280
+ exit(error.code);
281
+ }
282
+
283
+ if (error instanceof Error) {
284
+ writeLine(stderr, `Fatal error: ${error.message}`);
285
+ } else {
286
+ writeLine(stderr, "Fatal error: Unknown error");
287
+ }
288
+ exit(1);
289
+ }
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "pict-cli",
3
+ "version": "0.1.0",
4
+ "description": "A CLI tool for PICT, a combinatorial testing tool developed by Microsoft. This project provides a command-line interface to generate test cases using PICT's algorithms, making it easier for developers to create comprehensive test suites for their applications.",
5
+ "keywords": [
6
+ "pict",
7
+ "testing",
8
+ "testing-tools",
9
+ "test-case-generation",
10
+ "combinatorial-testing",
11
+ "pairwise",
12
+ "pairwise-testing"
13
+ ],
14
+ "homepage": "https://github.com/takeyaqa/pict-cli#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/takeyaqa/pict-cli/issues"
17
+ },
18
+ "license": "MIT",
19
+ "author": "Takeshi Kishi",
20
+ "files": [
21
+ "bin"
22
+ ],
23
+ "bin": {
24
+ "pict-cli": "bin/cli.js"
25
+ },
26
+ "type": "module",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/takeyaqa/pict-cli.git"
30
+ },
31
+ "dependencies": {
32
+ "@takeyaqa/pict-wasm": "3.7.4-wasm.17"
33
+ },
34
+ "devDependencies": {
35
+ "@eslint/js": "^10.0.1",
36
+ "eslint": "^10.0.3",
37
+ "eslint-config-prettier": "^10.1.8",
38
+ "prettier": "^3.8.1"
39
+ },
40
+ "engines": {
41
+ "node": "^22 || ^24"
42
+ },
43
+ "devEngines": {
44
+ "runtime": {
45
+ "name": "node",
46
+ "version": "^22"
47
+ },
48
+ "packageManager": [
49
+ {
50
+ "name": "pnpm",
51
+ "version": "^10"
52
+ }
53
+ ]
54
+ },
55
+ "scripts": {
56
+ "fmt": "prettier --write .",
57
+ "fmt:check": "prettier --check .",
58
+ "lint": "eslint .",
59
+ "lint:fix": "eslint --fix .",
60
+ "test": "node --test tests/e2e.spec.js"
61
+ }
62
+ }