@starci/cli 1.0.0 → 1.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.
@@ -1,83 +0,0 @@
1
- import assert from 'node:assert/strict';
2
- import { spawnSync } from 'node:child_process';
3
- import { lstatSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
4
- import os from 'node:os';
5
- import path from 'node:path';
6
- import test from 'node:test';
7
- import { fileURLToPath } from 'node:url';
8
- import { main } from './main.mjs';
9
-
10
- const bin = fileURLToPath(new URL('../bin/starci.mjs', import.meta.url));
11
- const manifest = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
12
- const run = (...args) => spawnSync(process.execPath, [bin, ...args], { encoding: 'utf8', windowsHide: true, timeout: 30_000 });
13
-
14
- test('the exact installed HFS dependency loads its real published module graph', async () => {
15
- const file = fileURLToPath(import.meta.resolve('@starci/hfs/package.json'));
16
- const installed = JSON.parse(readFileSync(file, 'utf8'));
17
- assert.equal(installed.name, '@starci/hfs');
18
- const declared = manifest.dependencies[installed.name];
19
- if (declared.startsWith('file:')) {
20
- const archive = path.resolve(fileURLToPath(new URL('../', import.meta.url)), declared.slice('file:'.length));
21
- assert.equal(path.extname(archive), '.tgz');
22
- assert.equal(lstatSync(archive).isFile(), true);
23
- // The clean-package owner verifies the original exact version and archive identity in preparePackedDependencies,
24
- // then every installed archive byte in verifyPackedDependencies, before running this spec with its scratch alias.
25
- } else assert.equal(installed.version, declared);
26
- const root = path.dirname(file);
27
- assert.equal(lstatSync(root).isDirectory(), true);
28
- assert.equal(realpathSync.native(root), path.join(realpathSync.native(fileURLToPath(new URL('../', import.meta.url))), 'node_modules', '@starci', 'hfs'));
29
- const hfs = await import('@starci/hfs');
30
- assert.equal(typeof hfs.main, 'function');
31
- });
32
-
33
- test('the real binary dispatches finite app explanations through installed HFS', (t) => {
34
- const cwd = mkdtempSync(path.join(os.tmpdir(), 'starci-app-main-'));
35
- t.after(() => rmSync(cwd, { recursive: true, force: true }));
36
- const declaration = JSON.stringify({ hfs: 2, kind: 'app', project: 'package-entry', sides: {
37
- be: { apps: [{ name: 'api', kind: 'api' }] },
38
- fe: { apps: [{ name: 'web', kind: 'next' }], reads: ['be/contracts/'] },
39
- } });
40
- writeFileSync(path.join(cwd, 'hfs.json'), declaration);
41
- const owned = run('app', 'explain', 'hfs.json', '--cwd', cwd, '--json');
42
- assert.equal(owned.status, 0, owned.stderr || String(owned.error ?? ''));
43
- const explained = JSON.parse(owned.stdout);
44
- assert.deepEqual([explained.path, explained.status, explained.slot], ['hfs.json', 'owned', 'app.declaration']);
45
- const unowned = run('app', 'explain', 'unowned.fixture', '--cwd', cwd, '--json');
46
- assert.equal(unowned.status, 1, unowned.stderr || String(unowned.error ?? ''));
47
- const refused = JSON.parse(unowned.stdout);
48
- assert.deepEqual([refused.path, refused.status, refused.code], ['unowned.fixture', 'no-slot', 'HFS_SLOT_UNDECLARED']);
49
- assert.equal(readFileSync(path.join(cwd, 'hfs.json'), 'utf8'), declaration);
50
- assert.deepEqual(readdirSync(cwd), ['hfs.json']);
51
- });
52
-
53
- test('the published binary serves its own version and catalog help', () => {
54
- const version = run('--version');
55
- assert.equal(version.status, 0, version.stderr);
56
- assert.equal(version.stdout.trim(), manifest.version);
57
- const help = run('--help');
58
- assert.equal(help.status, 0, help.stderr);
59
- assert.match(help.stdout, /Usage: starci <group> <verb>/);
60
- assert.match(help.stdout, /Groups:/);
61
- const appHelp = run('app', 'check', '--help');
62
- assert.equal(appHelp.status, 0, appHelp.stderr);
63
- assert.match(appHelp.stdout, /starci app check/);
64
- });
65
-
66
- test('the published binary refuses unknown commands and invalid flags', () => {
67
- const unknown = run('package-entry-unknown');
68
- assert.equal(unknown.status, 2);
69
- assert.match(unknown.stderr, /unknown group/);
70
- const invalid = run('app', 'check', '--package-entry-unknown');
71
- assert.equal(invalid.status, 2);
72
- assert.match(invalid.stderr, /unknown (?:flag|option)/);
73
- });
74
-
75
- test('the package dispatcher preserves app arguments, cwd and owner exit status', async () => {
76
- let called;
77
- const code = await main(['--cwd', 'selected-app', 'app', 'check', '--json'], {
78
- cwd: path.resolve('package-entry-base'), stdout: () => {}, stderr: () => {},
79
- importHfs: async () => ({ main: async (argv, io) => { called = { argv, cwd: io.cwd }; return 1; } }),
80
- });
81
- assert.equal(code, 1);
82
- assert.deepEqual(called, { argv: ['check', '--json'], cwd: path.resolve('package-entry-base', 'selected-app') });
83
- });