@commonlyai/cli 0.1.208 → 0.1.209

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.208",
3
+ "version": "0.1.209",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -0,0 +1,48 @@
1
+ /** Repository verification entry point; scenario implementations live in backend. */
2
+ import { existsSync } from 'fs';
3
+ import { resolve, join } from 'path';
4
+ import { spawnSync } from 'child_process';
5
+
6
+ export const SCENARIOS = {
7
+ wave1: '__tests__/service/verify.wave1.test.js',
8
+ 'connector-grant': '__tests__/service/verify.connectorGrant.test.js',
9
+ };
10
+ const testDatabase = (name) => /^(test|verify)([-_0-9]|$)|[-_]test$/.test(name || '');
11
+
12
+ export const verificationPlan = (scenario, repo, env = process.env) => {
13
+ const suite = SCENARIOS[scenario];
14
+ if (!suite) throw new Error(`Unknown scenario: ${scenario}. Choose ${Object.keys(SCENARIOS).join(', ')}.`);
15
+ let mongoDatabase = '';
16
+ // MongoDB authorities can contain comma-separated seed hosts, unlike WHATWG URLs.
17
+ const mongoPath = /^mongodb(?:\+srv)?:\/\/[^/?#]+\/([^?#]*)/.exec(env.MONGO_URI || '');
18
+ try { mongoDatabase = decodeURIComponent(mongoPath?.[1] || ''); } catch { /* refused below */ }
19
+ if (!env.PG_HOST || !testDatabase(env.PG_DATABASE) || !testDatabase(mongoDatabase)) {
20
+ throw new Error('Set MONGO_URI, PG_HOST and PG_DATABASE to dedicated test/verify databases. Fixture setup clears their data.');
21
+ }
22
+ const cwd = resolve(repo, 'backend');
23
+ const runner = join(cwd, 'node_modules/jest/bin/jest.js');
24
+ if (!existsSync(join(cwd, suite)) || !existsSync(runner)) {
25
+ throw new Error('Use --repo with a Commonly checkout containing the scenario and installed backend dependencies.');
26
+ }
27
+ return { command: process.execPath, args: [runner, '--runInBand', '--forceExit', '--runTestsByPath', suite,
28
+ ...(env.COMMONLY_VERIFY_CACHE_DIR ? ['--cacheDirectory', env.COMMONLY_VERIFY_CACHE_DIR] : [])],
29
+ options: { cwd, stdio: 'inherit', env: { ...env, INTEGRATION_TEST: 'true' } } };
30
+ };
31
+
32
+ export const registerVerify = (program, run = spawnSync) => {
33
+ program.command('verify <scenario>')
34
+ .description(`Run shared real-HTTP scenarios against isolated test databases (${Object.keys(SCENARIOS).join(', ')})`)
35
+ .option('--repo <path>', 'Commonly checkout with backend test dependencies', process.cwd())
36
+ .addHelpText('after', '\nUse Node 22 and explicit MONGO_URI, PG_HOST and PG_DATABASE. Fixture databases are cleared.\nRun inside the bounded test container when available; this command does not build images or contact a live instance.\n')
37
+ .action((scenario, options) => {
38
+ try {
39
+ const plan = verificationPlan(scenario, options.repo);
40
+ const result = run(plan.command, plan.args, plan.options);
41
+ if (result.error) throw result.error;
42
+ process.exitCode = result.status === null ? 1 : result.status;
43
+ } catch (error) {
44
+ console.error(error.message);
45
+ process.exitCode = 1;
46
+ }
47
+ });
48
+ };
package/src/index.js CHANGED
@@ -20,6 +20,7 @@ import { registerAgent } from './commands/agent.js';
20
20
  import { registerDaemon } from './commands/daemon.js';
21
21
  import { registerPod } from './commands/pod.js';
22
22
  import { registerDev } from './commands/dev.js';
23
+ import { registerVerify } from './commands/verify.js';
23
24
 
24
25
  const __dirname = dirname(fileURLToPath(import.meta.url));
25
26
  const pkg = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf8'));
@@ -51,6 +52,7 @@ registerPod(program);
51
52
 
52
53
  // Local dev environment
53
54
  registerDev(program);
55
+ registerVerify(program);
54
56
 
55
57
  // Each subcommand owns its own `--instance <url>` flag; a program-level
56
58
  // duplicate shadowed the subcommand value on commander v12, causing