Skip to content

The open alternative to Salesforce, designed for AI.

test(cli): verify workspace and packaged installations in CI (#27424)

Weiko88f3076c95ce
diff --git a/.github/workflows/ci-cli.yaml b/.github/workflows/ci-cli.yaml
new file mode 100644
index 00000000000..37437512cd5
--- /dev/null
+++ b/.github/workflows/ci-cli.yaml
@@ -0,0 +1,58 @@
+name: CI CLI
+
+on:
+ pull_request:
+ merge_group:
+
+permissions:
+ contents: read
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
+
+jobs:
+ changed-files-check:
+ if: github.event_name != 'merge_group'
+ uses: ./.github/workflows/changed-files.yaml
+ with:
+ files: |
+ packages/twenty-cli/**
+ packages/twenty-shared/**
+ packages/twenty-sdk/**
+ packages/twenty-client-sdk/**
+ packages/twenty-ui/**
+ packages/create-twenty-app/**
+ .github/actions/yarn-install/**
+ .github/workflows/ci-cli.yaml
+ package.json
+ yarn.lock
+ nx.json
+ tsconfig.base.json
+ .yarnrc.yml
+ .yarn/**
+ cli-package-test:
+ needs: changed-files-check
+ if: >-
+ !cancelled() &&
+ (github.event_name == 'merge_group' || needs.changed-files-check.outputs.any_changed == 'true')
+ timeout-minutes: 20
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
+ with:
+ fetch-depth: 10
+ - name: Install dependencies
+ uses: ./.github/actions/yarn-install
+ - name: Build and test the CLI package
+ run: npx nx run twenty-cli:test:package
+ ci-cli-status-check:
+ if: always() && !cancelled()
+ timeout-minutes: 5
+ runs-on: ubuntu-latest
+ needs: [changed-files-check, cli-package-test]
+ steps:
+ - name: Fail job if any needs failed
+ if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
+ run: exit 1
diff --git a/packages/twenty-cli/CONTRIBUTING.md b/packages/twenty-cli/CONTRIBUTING.md
index 62c482fd7ce..9b05907e573 100644
--- a/packages/twenty-cli/CONTRIBUTING.md
+++ b/packages/twenty-cli/CONTRIBUTING.md
@@ -94,15 +94,19 @@ The archive includes the command reference, contributor guide and application
module READMEs so their relative links also work outside a repository checkout.
It does not include the CLI's TypeScript implementation or tests.
-For packaging changes, build and inspect the archive before release:
+For packaging changes, run the build and installation checks:
```bash
-yarn workspace twenty pack --dry-run
+yarn nx run twenty-cli:test:package
```
-Check both executable entry points, lazy chunks and templates in the packed
-package. Smoke-test help and app initialization from an extracted archive with
-its declared dependencies. This checks packaging without publishing anything.
+This runs the binary declared in the workspace's `package.json` directly, packs
+the CLI, and installs the archive with only its production dependencies in a
+temporary directory outside the monorepo. It checks help, offline doctor, app initialization including the
+template overlay, and a compiler diagnostic from the installed worker. npm
+registry access is required for installation; the commands do not contact a
+Twenty workspace. Temporary files are removed afterward, and nothing is
+published. CI runs the same target for CLI and dependency changes.
## App integration tests
diff --git a/packages/twenty-cli/project.json b/packages/twenty-cli/project.json
index 89337b3cb4c..aec9dab6d46 100644
--- a/packages/twenty-cli/project.json
+++ b/packages/twenty-cli/project.json
@@ -20,6 +20,14 @@
},
"typecheck": {},
"lint": {},
+ "test:package": {
+ "executor": "nx:run-commands",
+ "dependsOn": ["build"],
+ "cache": false,
+ "options": {
+ "command": "node --test packages/twenty-cli/scripts/test-package.mjs"
+ }
+ },
"test": {
"executor": "@nx/vitest:test",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
diff --git a/packages/twenty-cli/scripts/test-package.mjs b/packages/twenty-cli/scripts/test-package.mjs
new file mode 100644
index 00000000000..d4cb25b3fa5
--- /dev/null
+++ b/packages/twenty-cli/scripts/test-package.mjs
@@ -0,0 +1,197 @@
+import { strict as assert } from 'node:assert';
+import { execFileSync, fork } from 'node:child_process';
+import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { dirname, join } from 'node:path';
+import { test } from 'node:test';
+import { fileURLToPath } from 'node:url';
+
+const PACKAGE_DIRECTORY = fileURLToPath(new URL('..', import.meta.url));
+const WORKSPACE_DIRECTORY = join(PACKAGE_DIRECTORY, '../..');
+const ENVIRONMENT = {
+ ...process.env,
+ NODE_PATH: '',
+ NODE_OPTIONS: '',
+ PATH: `${dirname(process.execPath)}:${process.env.PATH}`,
+ TWENTY_API_URL: 'http://127.0.0.1:1',
+ TWENTY_API_KEY: 'package-smoke-test',
+ TWENTY_REMOTE: '',
+};
+
+const run = ({ command, commandArguments, workingDirectory }) =>
+ execFileSync(command, commandArguments, {
+ cwd: workingDirectory,
+ env: ENVIRONMENT,
+ encoding: 'utf8',
+ timeout: 120_000,
+ stdio: ['ignore', 'pipe', 'pipe'],
+ });
+
+await test('the workspace executable runs directly after a build', async () => {
+ const { bin } = JSON.parse(
+ await readFile(join(PACKAGE_DIRECTORY, 'package.json'), 'utf8'),
+ );
+ const output = run({
+ command: join(PACKAGE_DIRECTORY, bin),
+ commandArguments: ['--help'],
+ workingDirectory: WORKSPACE_DIRECTORY,
+ });
+
+ assert.match(output, /Usage: twenty/);
+});
+
+await test('the packed CLI works outside the monorepo', async (context) => {
+ const directory = await mkdtemp(join(tmpdir(), 'twenty-package-'));
+ const installDirectory = join(directory, 'installation');
+ const archive = join(directory, 'twenty.tgz');
+
+ try {
+ await mkdir(installDirectory);
+ await writeFile(
+ join(installDirectory, 'package.json'),
+ JSON.stringify({ private: true }),
+ );
+ run({
+ command: 'yarn',
+ commandArguments: ['workspace', 'twenty', 'pack', '--out', archive],
+ workingDirectory: WORKSPACE_DIRECTORY,
+ });
+ run({
+ command: 'npm',
+ commandArguments: [
+ 'install',
+ '--omit=dev',
+ '--no-audit',
+ '--no-fund',
+ archive,
+ ],
+ workingDirectory: installDirectory,
+ });
+
+ const executable = join(installDirectory, 'node_modules/.bin/twenty');
+ const installedPackage = join(installDirectory, 'node_modules/twenty');
+ const cli = (...commandArguments) =>
+ run({
+ command: executable,
+ commandArguments,
+ workingDirectory: installDirectory,
+ });
+
+ await context.test('help loads from the installed executable', () => {
+ assert.match(cli('--help'), /Usage: twenty/);
+ assert.match(cli('app', '--help'), /Usage: twenty app/);
+ });
+
+ await context.test('offline doctor loads its command chunk', () => {
+ const result = JSON.parse(cli('doctor', '--offline', '--json'));
+
+ assert.equal(result.ok, true);
+ assert.equal(result.command, 'doctor');
+ const cliCheck = result.data.checks.find((check) => check.id === 'cli');
+
+ assert.equal(cliCheck.status, 'pass');
+ assert.equal(cliCheck.details.entryPoint, executable);
+ assert.equal(
+ result.data.checks.find((check) => check.id === 'metadata-api').status,
+ 'skipped',
+ );
+ });
+
+ await context.test(
+ 'app init renders the template and its CLI overlay',
+ async () => {
+ const result = JSON.parse(
+ cli('app', 'init', 'smoke-app', '--json', '--no-input'),
+ );
+ const appDirectory = join(installDirectory, 'smoke-app');
+ const packageJson = JSON.parse(
+ await readFile(join(appDirectory, 'package.json'), 'utf8'),
+ );
+
+ assert.equal(result.ok, true);
+ assert.equal(packageJson.name, 'smoke-app');
+ assert.match(
+ await readFile(
+ join(appDirectory, 'src/application-config.ts'),
+ 'utf8',
+ ),
+ /defineApplication/,
+ );
+ assert.match(
+ await readFile(
+ join(appDirectory, 'src/__tests__/run-twenty.ts'),
+ 'utf8',
+ ),
+ /TWENTY_CLI/,
+ );
+ },
+ );
+
+ await context.test(
+ 'the installed worker reports a real compiler diagnostic',
+ async () => {
+ const appDirectory = join(installDirectory, 'typecheck-app');
+
+ await mkdir(appDirectory);
+ await writeFile(
+ join(appDirectory, 'package.json'),
+ JSON.stringify({ name: 'typecheck-app' }),
+ );
+ await writeFile(
+ join(appDirectory, 'tsconfig.json'),
+ JSON.stringify({
+ compilerOptions: { strict: true, types: [], skipLibCheck: true },
+ include: ['*.ts'],
+ }),
+ );
+ await writeFile(
+ join(appDirectory, 'application.ts'),
+ 'export const name: string = 42;',
+ );
+
+ const { code, response, stderr } = await new Promise(
+ (resolve, reject) => {
+ const worker = fork(
+ join(installedPackage, 'dist/app-worker.cjs'),
+ [],
+ {
+ cwd: appDirectory,
+ env: ENVIRONMENT,
+ execArgv: [],
+ stdio: ['ignore', 'ignore', 'pipe', 'ipc'],
+ timeout: 30_000,
+ },
+ );
+ let response;
+ let stderr = '';
+
+ worker.stderr.setEncoding('utf8');
+ worker.stderr.on('data', (chunk) => {
+ stderr += chunk;
+ });
+ worker.once('error', reject);
+ worker.once('message', (message) => {
+ response = message;
+ });
+ worker.once('exit', (code) => resolve({ code, response, stderr }));
+ worker.send({ type: 'typecheckSource', appPath: appDirectory });
+ },
+ );
+
+ assert.equal(code, 0, stderr);
+ assert.equal(response.type, 'result');
+ assert.equal(response.result.success, false);
+ assert.equal(response.result.error.code, 'TYPECHECK_FAILED');
+ assert.ok(
+ response.result.diagnostics.some(
+ (diagnostic) =>
+ diagnostic.code === 'TS2322' &&
+ diagnostic.file === 'application.ts',
+ ),
+ );
+ },
+ );
+ } finally {
+ await rm(directory, { recursive: true, force: true });
+ }
+});