@starci/hfs 4.7.16 → 4.7.18
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/CHANGELOG.md +10 -0
- package/coverage/cli.mjs +29 -4
- package/package.json +1 -1
- package/release/gate.mjs +402 -388
- package/release/sonar-quality-gate.mjs +68 -0
- package/runtime/knowledge/hfs/canon-pins.yaml +5 -5
- package/runtime/knowledge/hfs/ci-standard.yaml +5 -3
- package/runtime/knowledge/hfs/rules.yaml +2 -1
- package/runtime/knowledge/hfs/slots.yaml +1 -1
- package/runtime/modules/kernel/failure-codes.yaml +1 -1
- package/runtime/packages/cli/src/catalog.generated.mjs +14 -7
- package/runtime/packages/jest-preset/sonar-exclusions.cjs +8 -0
- package/runtime/scripts/hfs/rules/ci-standard.mjs +5 -2
- package/runtime/scripts/hfs/rules/staged-specs.mjs +25 -5
- package/scaffold/app.mjs +21 -6
- package/src/main.mjs +5 -9
- package/sync/ci-commands.mjs +276 -275
- package/sync/hygiene.mjs +8 -2
- package/sync/index.mjs +19 -0
- package/templates/be/skeleton/src/modules/platform/database/migrate-connections.client.spec.ts +60 -0
- package/templates/fe/transport/graphql/clients/links/retry.ts +1 -1
- package/upgrade/index.mjs +2 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// sonar-quality-gate.mjs - the verdict of the release gate's sonar row after the scanner exits 0. The scanner's exit code says only
|
|
2
|
+
// that the report was uploaded; the server computes the analysis afterwards. This reads the task the scanner wrote
|
|
3
|
+
// (`.scannerwork/report-task.txt`), polls `api/ce/task` until the compute-engine task ends, then reads the quality gate of that
|
|
4
|
+
// analysis from `api/qualitygates/project_status` with the same token. OK passes; ERROR is red and names every failed condition;
|
|
5
|
+
// a task that ends FAILED or CANCELED, an unreadable answer and a deadline passed are typed refusals in the row's detail.
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
|
|
9
|
+
const SONAR_GATE_FAILED = 'RELEASE_SONAR_GATE_FAILED';
|
|
10
|
+
const SONAR_GATE_TIMEOUT = 'RELEASE_SONAR_GATE_TIMEOUT';
|
|
11
|
+
const SONAR_GATE_UNREADABLE = 'RELEASE_SONAR_GATE_UNREADABLE';
|
|
12
|
+
const REPORT_TASK = path.join('.scannerwork', 'report-task.txt');
|
|
13
|
+
const DONE = new Set(['SUCCESS', 'FAILED', 'CANCELED']);
|
|
14
|
+
/** The bound of one compute-engine wait and the pause between polls (milliseconds). */
|
|
15
|
+
const QUALITY_GATE_WAIT = Object.freeze({ deadline: 600_000, interval: 5_000 });
|
|
16
|
+
|
|
17
|
+
/** The `key=value` lines of the scanner's report-task.txt under `cwd`, or null when the scanner wrote none. */
|
|
18
|
+
function reportTask(cwd) {
|
|
19
|
+
let text;
|
|
20
|
+
try { text = fs.readFileSync(path.join(cwd, REPORT_TASK), 'utf8'); } catch { return null; }
|
|
21
|
+
return Object.fromEntries(text.split(/\r?\n/u).map((line) => line.split('=')).filter(([key, ...rest]) => key && rest.length).map(([key, ...rest]) => [key.trim(), rest.join('=').trim()]));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** One authenticated JSON GET; a failed request or a non-JSON body throws. */
|
|
25
|
+
async function getJson(ctx, url, token) {
|
|
26
|
+
const response = await ctx.fetch(url, { headers: { Authorization: `Basic ${Buffer.from(`${token}:`).toString('base64')}` }, signal: AbortSignal.timeout(30_000) });
|
|
27
|
+
if (!response.ok) throw new Error(`HTTP ${response.status} from ${url.split('?')[0]}`);
|
|
28
|
+
return response.json();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The failed conditions of a quality gate answer, as `metric comparator threshold (actual value)` lines. */
|
|
32
|
+
const failedConditions = (status) => (status?.conditions ?? []).filter((condition) => condition.status === 'ERROR')
|
|
33
|
+
.map((condition) => `${condition.metricKey} ${condition.comparator ?? ''} ${condition.errorThreshold ?? ''} (actual ${condition.actualValue ?? '?'})`.replace(/\s+/gu, ' '));
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The quality-gate verdict of the analysis the scanner just uploaded from `cwd`: `{ pass, detail, conditions? }`. `token` is the
|
|
37
|
+
* scanner's token, `host` the declared server. `ctx.fetch`, `ctx.now` and `ctx.sleep` are the seams; `wait` bounds the poll.
|
|
38
|
+
*/
|
|
39
|
+
export async function sonarQualityGate(ctx, { cwd, host, token, wait = QUALITY_GATE_WAIT }) {
|
|
40
|
+
const task = reportTask(cwd);
|
|
41
|
+
if (!task?.ceTaskId) return { pass: false, detail: `${SONAR_GATE_UNREADABLE}: the scanner wrote no ${REPORT_TASK.replaceAll('\\', '/')} with a ceTaskId` };
|
|
42
|
+
const server = String(task.serverUrl || host).replace(/\/$/u, '');
|
|
43
|
+
const sleep = ctx.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
44
|
+
const deadline = ctx.now() + wait.deadline;
|
|
45
|
+
let analysisId = null;
|
|
46
|
+
try {
|
|
47
|
+
for (;;) {
|
|
48
|
+
const state = (await getJson(ctx, `${server}/api/ce/task?id=${encodeURIComponent(task.ceTaskId)}`, token))?.task;
|
|
49
|
+
if (DONE.has(state?.status)) {
|
|
50
|
+
if (state.status !== 'SUCCESS') return { pass: false, detail: `${SONAR_GATE_FAILED}: compute-engine task ${task.ceTaskId} ended ${state.status}${state.errorMessage ? `: ${state.errorMessage}` : ''}` };
|
|
51
|
+
analysisId = state.analysisId;
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
if (ctx.now() >= deadline) return { pass: false, detail: `${SONAR_GATE_TIMEOUT}: compute-engine task ${task.ceTaskId} is still ${state?.status ?? 'unknown'} after ${Math.round(wait.deadline / 1000)}s` };
|
|
55
|
+
await sleep(wait.interval);
|
|
56
|
+
}
|
|
57
|
+
const query = analysisId ? `analysisId=${encodeURIComponent(analysisId)}` : `projectKey=${encodeURIComponent(task.projectKey ?? '')}`;
|
|
58
|
+
const status = (await getJson(ctx, `${server}/api/qualitygates/project_status?${query}`, token))?.projectStatus;
|
|
59
|
+
if (status?.status === 'OK') return { pass: true, detail: 'exit 0, quality gate OK' };
|
|
60
|
+
if (status?.status === 'ERROR') {
|
|
61
|
+
const conditions = failedConditions(status);
|
|
62
|
+
return { pass: false, detail: `${SONAR_GATE_FAILED}: quality gate ERROR (${conditions.join('; ') || 'no condition listed'})${task.dashboardUrl ? ` ${task.dashboardUrl}` : ''}`, conditions };
|
|
63
|
+
}
|
|
64
|
+
return { pass: false, detail: `${SONAR_GATE_UNREADABLE}: quality gate status ${status?.status ?? 'missing'}` };
|
|
65
|
+
} catch (error) {
|
|
66
|
+
return { pass: false, detail: `${SONAR_GATE_UNREADABLE}: ${String(error?.message ?? error)}` };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -29,14 +29,14 @@ pins:
|
|
|
29
29
|
source: packages/grammar/package.json
|
|
30
30
|
why: 'the grammar front ends read: the brand layer sets `--font-sans` and `--font-mono` and the grammar reads them; it carries the Input tel kind, the copyable and read-only Input, the IconButton disclosure props and count badge, ChatBubble, FillViewport, Textarea mentions and Enter-to-send, the leading PrimaryRailLayout rail, the plate-less Image, ListRow, the soft Alert, Progress steps, the floating primary IconButton, FlowGraph, the STATE-8 loading views and the bordered selectable TagGroup chips. The runtime source version wins for a @starci package.'
|
|
31
31
|
'@starci/eslint-canon-be':
|
|
32
|
-
version: 3.4.
|
|
32
|
+
version: 3.4.26
|
|
33
33
|
group: starci
|
|
34
34
|
install: registry
|
|
35
35
|
side: be
|
|
36
36
|
source: packages/eslint/be/package.json
|
|
37
37
|
why: 'the back-end ESLint canon: `loadHfs(import.meta.url)` of be/eslint.config.mjs finds the app-root hfs.json (kind app) and gives every linted file the view of the be side, and the project graph is built per side; its bundled runtime copies (slots, canon-pins, failure codes, the architecture machine) put .starcistacks and .sops.yaml at the app root; `starciBeConfig({ hfs: loadHfs(import.meta.url) })` is the typed factory and the BE-CONVENTION laws are its rules.'
|
|
38
38
|
'@starci/eslint-canon-fe':
|
|
39
|
-
version: 8.4.
|
|
39
|
+
version: 8.4.25
|
|
40
40
|
group: starci
|
|
41
41
|
install: registry
|
|
42
42
|
side: fe
|
|
@@ -62,7 +62,7 @@ pins:
|
|
|
62
62
|
side: both
|
|
63
63
|
source: packages/prettier-config/package.json
|
|
64
64
|
'@starci/jest-preset':
|
|
65
|
-
version: 2.3.
|
|
65
|
+
version: 2.3.4
|
|
66
66
|
group: starci
|
|
67
67
|
install: registry
|
|
68
68
|
side: be
|
|
@@ -76,14 +76,14 @@ pins:
|
|
|
76
76
|
source: packages/test-world/package.json
|
|
77
77
|
why: 'the shared e2e library of every back end (R47, R48), a devDependency of every back end: the warm stack behind toxiproxy, the network-edge fakes, the Nest boot, the typed useTestWorld handle, useSandbox for contract specs and the outage lock. Kafka is real own infra (the one digest-pinned apache/kafka KRaft image, a broker listener and proxy per slot, slot-prefixed topics, consumer groups and client ids) and Postgres is schema-per-context (a schema and a login role per context in a shared database). Each worker has its own data slot (<ns>_w<k>) with its own databases, Keycloak realm, leased Redis DB, bucket/collection/topic prefixes, fakes host, toxiproxy proxies and outage lock; a run provisions min(jest workers, workers cap, default 2) slots, and state file protocol 2 pairs exactly with @starci/jest-preset (TEST_WORLD_PAIR_MISMATCH otherwise). A modules world boots real peer apps beside its modules, world.apps.<name>.during(fn) is the outage of a peer app, w.keycloak.clientSecret(client) answers the run-generated secret of a confidential realm client, world.keycloak.events/sessions read the realm user events and live sessions, world.infra.postgresql.connection(name) takes one database connection down while the others serve, and world.resolve and scope.resolve take any Nest token. Every path a declaration names (`stack`, seeds, the realm, Dockerfiles) resolves from the app root (the directory of hfs.json); the globalSetup registers the path aliases as TypeScript resolves them. Its CLI main is exported at ./cli for starci app stack.'
|
|
78
78
|
'@starci/cli':
|
|
79
|
-
version: 1.7.
|
|
79
|
+
version: 1.7.18
|
|
80
80
|
group: starci
|
|
81
81
|
install: registry
|
|
82
82
|
side: both
|
|
83
83
|
source: packages/cli/package.json
|
|
84
84
|
why: 'the only StarCi command package; product repositories install it for starci app, while @starci/hfs remains its pinned transitive implementation.'
|
|
85
85
|
'@starci/hfs':
|
|
86
|
-
version: 4.7.
|
|
86
|
+
version: 4.7.18
|
|
87
87
|
group: starci
|
|
88
88
|
install: registry
|
|
89
89
|
side: both
|
|
@@ -19,15 +19,17 @@ jobs:
|
|
|
19
19
|
# The per-job settings the managed CI renders when .starcistacks/application-stacks.yaml ci.jobs leaves them out (ci.jobs.<job>.timeoutMinutes,
|
|
20
20
|
# ci.jobs.test.shards). Sized from a real run (NIVO v0.2.3 on the 2-vCPU GitHub runner, 2026-10-18): the be lint with the Sonar import took 11.5 minutes and the
|
|
21
21
|
# fe lint more than 8 in one 20-minute job, and ~900 unit suites ran at ~4 s each (670 of 904 in 45 minutes). One lint job per side, and 6 shards of ~150 suites
|
|
22
|
-
# (~10 minutes each plus the install) leave each job well inside its timeout.
|
|
22
|
+
# (~10 minutes each plus the install) leave each job well inside its timeout. The coverage job installs, downloads the shards, merges them and runs
|
|
23
|
+
# the coverage judgement alone (starci app coverage verify, seconds): ~5 minutes, so 15 leaves three times that. Its earlier whole app check took
|
|
24
|
+
# 18m43s on NIVO v0.3.0 and the 20-minute bound cancelled the tag run (39592175266).
|
|
23
25
|
defaults:
|
|
24
26
|
shards: 6
|
|
25
|
-
timeoutMinutes: {fast: 20, lint: 30, test: 25, coverage:
|
|
27
|
+
timeoutMinutes: {fast: 20, lint: 30, test: 25, coverage: 15, build: 30, sonar: 20, db-types: 30}
|
|
26
28
|
|
|
27
29
|
# The steps that need a raised Node heap on the GitHub runner, matched on their `run` text, and the least heap they must declare in NODE_OPTIONS.
|
|
28
30
|
heap:
|
|
29
31
|
minMiB: 6144
|
|
30
|
-
steps: ['npm run typecheck', 'npm run lint', 'app lint', 'app
|
|
32
|
+
steps: ['npm run typecheck', 'npm run lint', 'app lint', 'app coverage verify', 'npm run db:lint']
|
|
31
33
|
|
|
32
34
|
items:
|
|
33
35
|
- id: candidate-trigger
|
|
@@ -3754,7 +3754,7 @@ rules:
|
|
|
3754
3754
|
- {path: packages/eslint/be/sonar-parity-editions.spec.mjs, edition: full}
|
|
3755
3755
|
- {path: packages/eslint/fe/sonar-parity-editions.spec.mjs, edition: lite}
|
|
3756
3756
|
- {path: packages/eslint/fe/sonar-parity-editions.spec.mjs, edition: full}
|
|
3757
|
-
law: "Code carries none of the smells SonarCloud measures that a lint rule can decide: no `await` inside a loop (S9382; an endless loop is spared), no `charCodeAt`/`fromCharCode` (S7758), no string that only escapes backslashes (S7780; a Next `matcher` is spared, it is read statically), no nested conditional expression (S3358), no `void` on anything but a call (S3735), no unused import (S1128), no import that is only handed on instead of `export ... from` (S7763), no prop of a component's props type the component never reads (S6767, front end), and, through typescript-eslint with type information, no deprecated API (S1874), no object turned into text (S6551) and no `async` function that never awaits and returns no promise (S7503). The files a unit or an end-to-end spec names are outside the scan, so outside these rules."
|
|
3757
|
+
law: "Code carries none of the smells SonarCloud measures that a lint rule can decide: no `await` inside a loop (S9382; an endless loop is spared), no `charCodeAt`/`fromCharCode` (S7758), no string that only escapes backslashes (S7780; a Next `matcher` is spared, it is read statically), no nested conditional expression (S3358), no `void` on anything but a call (S3735), no unused import (S1128), no import that is only handed on instead of `export ... from` (S7763), no prop of a component's props type the component never reads (S6767, front end), no `<video>` or `<audio>` without a captions track unless muted (S4084, front end), and, through typescript-eslint with type information, no deprecated API (S1874), no object turned into text (S6551) and no `async` function that never awaits and returns no promise (S7503). Every other rule of the Sonar way TypeScript profile with an ESLint equivalent (scripts/lib/sonar-way.mjs: eslint-plugin-sonarjs' Sonar way set, the core, typescript-eslint and unicorn rules it builds on) is on at error in both canons. The files a unit or an end-to-end spec names are outside the scan, so outside these rules."
|
|
3758
3758
|
kinds: [lint, codemod]
|
|
3759
3759
|
gates: [pre-commit, settle, land, ci]
|
|
3760
3760
|
failureCodes: ["SCAN_SMELL"]
|
|
@@ -3774,6 +3774,7 @@ rules:
|
|
|
3774
3774
|
- {kind: eslint-fe, id: no-unused-import}
|
|
3775
3775
|
- {kind: eslint-fe, id: prefer-export-from}
|
|
3776
3776
|
- {kind: eslint-fe, id: no-unused-prop-types}
|
|
3777
|
+
- {kind: eslint-fe, id: media-has-caption}
|
|
3777
3778
|
- id: R236
|
|
3778
3779
|
code: "RT_GATE_LOOSENING"
|
|
3779
3780
|
editions: [lite, full]
|
|
@@ -38,7 +38,7 @@ versioning:
|
|
|
38
38
|
# or environment reads (BE_APP_OPTIONS_COMPOSITION). Secrets use EnvSource.secret(): <NAME>_FILE first, plain <NAME> only
|
|
39
39
|
# when the file key is absent; .starcistacks owns custody. Capability <capability>.config.ts roles stay unchanged.
|
|
40
40
|
# 3.3.0 is a minor (alpha.16): it ADDS the optional app.ci-stack-deploy slot, the managed workflow of the starci app stack verbs.
|
|
41
|
-
# 3.4.0 is a minor (alpha.
|
|
41
|
+
# 3.4.0 is a minor (alpha.25): it ADDS the opt-in be.contract.mcp-tools slot, the committed MCP tool-catalog snapshot of an app.
|
|
42
42
|
|
|
43
43
|
# Field meaning, per slot.
|
|
44
44
|
# id stable name, never changes meaning inside a major.
|
|
@@ -1608,7 +1608,7 @@ BE_TYPE_ESCAPE:
|
|
|
1608
1608
|
BE_UNIT_SPEC_NOT_STAGED:
|
|
1609
1609
|
title: "A new back-end logic file is committed without its unit spec"
|
|
1610
1610
|
title_vi: "Tệp logic back-end mới được commit mà không có unit spec"
|
|
1611
|
-
meaning_vi: "Commit thêm `<file>`, một tệp `<name>.<role>.ts` có vai trò logic mà unit coverage đo ở mức 100 mỗi tệp, nhưng index không có `<name>.<role>.spec.ts` bên cạnh nó: mã được viết trước, spec để sau."
|
|
1611
|
+
meaning_vi: "Commit thêm `<file>`, một tệp `<name>.<role>.ts` có vai trò logic mà unit coverage đo ở mức 100 mỗi tệp, nhưng index không có `<name>.<role>.spec.ts` bên cạnh nó: mã được viết trước, spec để sau. Tệp chỉ có hằng số và kiểu (không có hàm, phương thức nào để chạy) không cần spec riêng."
|
|
1612
1612
|
causes_vi:
|
|
1613
1613
|
- "Agent viết mã trước rồi định sửa lint và spec sau, thay vì chạy vòng op `starci gate read` → mã + spec → `starci gate run`"
|
|
1614
1614
|
- "Spec đã viết nhưng chưa được stage cùng tệp"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// GENERATED by scripts/cli/gen-catalog.mjs — do not edit
|
|
2
2
|
export const CATALOG = {
|
|
3
3
|
"schema": "starci/cli-catalog@1",
|
|
4
|
-
"hash": "
|
|
4
|
+
"hash": "2ad45b29a66fee7ac961e8546613e0455d23cc47e28a5070bd15b86154755dd8",
|
|
5
5
|
"global": [
|
|
6
6
|
{
|
|
7
7
|
"name": "json",
|
|
@@ -790,13 +790,14 @@ export const CATALOG = {
|
|
|
790
790
|
"runtimeSide": "host"
|
|
791
791
|
},
|
|
792
792
|
"coverage": {
|
|
793
|
-
"summary": "merge the
|
|
793
|
+
"summary": "merge the sharded unit coverage into one lcov report, or prove that report at 100 per file",
|
|
794
794
|
"owner": "@starci/hfs",
|
|
795
795
|
"positional": [
|
|
796
796
|
{
|
|
797
797
|
"name": "action",
|
|
798
798
|
"enum": [
|
|
799
|
-
"merge"
|
|
799
|
+
"merge",
|
|
800
|
+
"verify"
|
|
800
801
|
],
|
|
801
802
|
"required": true,
|
|
802
803
|
"variadic": false
|
|
@@ -820,12 +821,14 @@ export const CATALOG = {
|
|
|
820
821
|
}
|
|
821
822
|
],
|
|
822
823
|
"exit": {
|
|
823
|
-
"0": "merged",
|
|
824
|
+
"0": "merged or proved",
|
|
825
|
+
"1": "the coverage proof refused a measured file",
|
|
824
826
|
"2": "bad usage, no installed preset or no report found"
|
|
825
827
|
},
|
|
826
828
|
"json": "none",
|
|
827
829
|
"examples": [
|
|
828
|
-
"starci app coverage merge --out be/coverage/lcov.info be/coverage/shards"
|
|
830
|
+
"starci app coverage merge --out be/coverage/lcov.info be/coverage/shards",
|
|
831
|
+
"starci app coverage verify be/coverage/lcov.info"
|
|
829
832
|
],
|
|
830
833
|
"editions": [
|
|
831
834
|
"full",
|
|
@@ -838,7 +841,8 @@ export const CATALOG = {
|
|
|
838
841
|
"merge runs the app's installed @starci/jest-preset/merge: istanbul-lib-coverage joins the shard maps by source location",
|
|
839
842
|
"the merged lcov is written by the preset's own lcov reporter, as an unsharded run writes it",
|
|
840
843
|
"a path is a coverage-final.json or a directory searched for every one below it; no report found refuses (exit 2)",
|
|
841
|
-
"the coverage proof
|
|
844
|
+
"verify <lcov> is the coverage proof alone: every measured logic file in the report at 100 per file, a missing one refused",
|
|
845
|
+
"verify runs none of the other rules of starci app check; the managed CI coverage job runs it after the merge"
|
|
842
846
|
],
|
|
843
847
|
"runtimeSide": "host"
|
|
844
848
|
},
|
|
@@ -1234,6 +1238,9 @@ export const CATALOG = {
|
|
|
1234
1238
|
"declared release.gates gets audit appended if missing",
|
|
1235
1239
|
"--sonar appends @sonar/scan@4.3.0 against services.sonar.host (host.public for a host mapping), plus organization for sonarcloud;",
|
|
1236
1240
|
"disabled or unavailable Sonar or an unset token refuses RELEASE_SONAR_UNAVAILABLE",
|
|
1241
|
+
"a scanner exit 0 is not a pass: the row polls api/ce/task until the analysis ends, then reads api/qualitygates/project_status with the same token",
|
|
1242
|
+
"OK passes; ERROR is red as RELEASE_SONAR_GATE_FAILED naming each failed condition, as is a FAILED or CANCELED task",
|
|
1243
|
+
"a task still running after 600 s is RELEASE_SONAR_GATE_TIMEOUT; no report-task, an HTTP error or no gate is RELEASE_SONAR_GATE_UNREADABLE",
|
|
1237
1244
|
"OWNER RULING candidate-ci (2026-10-18): the gate no longer reads the default-branch CI; the verdict is the candidate run of the sha",
|
|
1238
1245
|
"push --execute sends HEAD to refs/heads/release/candidate-<version> first and waits for its ci.yml run (it triggers on release/candidate-*)",
|
|
1239
1246
|
"green moves the branch and the tag in one atomic push; red refuses RELEASE_CANDIDATE_CI_RED naming the failing jobs",
|
|
@@ -1246,7 +1253,7 @@ export const CATALOG = {
|
|
|
1246
1253
|
"runtimeSide": "host"
|
|
1247
1254
|
},
|
|
1248
1255
|
"scaffold": {
|
|
1249
|
-
"summary": "create a full or lite StarCi app
|
|
1256
|
+
"summary": "create a full or lite StarCi app in its own Git repository (unborn main)",
|
|
1250
1257
|
"owner": "@starci/hfs",
|
|
1251
1258
|
"positional": [
|
|
1252
1259
|
{
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Sonar `sonar.exclusions`: specs, e2e specs, dist and coverage output are not analysed at all. A plain list with no require, so
|
|
5
|
+
* @starci/hfs ships this file byte for byte (packages/hfs/runtime, scripts/hfs/sync-runtime.mjs) and `starci app scaffold` renders
|
|
6
|
+
* the same exclusions before any app dependency is installed.
|
|
7
|
+
*/
|
|
8
|
+
module.exports = Object.freeze(["**/*.spec.ts", "**/*.e2e-spec.ts", "**/dist/**", "**/coverage/**"])
|
|
@@ -28,6 +28,9 @@ const DIGEST_PIN = /@sha256:[0-9a-f]{64}$/;
|
|
|
28
28
|
|
|
29
29
|
let cached = null;
|
|
30
30
|
/** The standard (knowledge/hfs/ci-standard.yaml), read once. */
|
|
31
|
+
/** The coverage proof step: the coverage judgement over the merged lcov (`starci app coverage verify`), never the whole app check. */
|
|
32
|
+
const COVERAGE_PROOF = /app coverage verify\b/;
|
|
33
|
+
|
|
31
34
|
function ciStandard() {
|
|
32
35
|
if (!cached) {
|
|
33
36
|
const doc = parseYaml(fs.readFileSync(STANDARD_FILE, 'utf8'));
|
|
@@ -56,7 +59,7 @@ function jobShape(doc, edition, standard, say) {
|
|
|
56
59
|
const withStep = (match) => jobsOf(doc).filter(([, job]) => stepsOf(job).some((step) => match(step))).map(([id]) => id);
|
|
57
60
|
const unit = withStep((step) => step.name === 'unit');
|
|
58
61
|
const upload = withStep((step) => usesOf(step).startsWith('codecov/codecov-action@'));
|
|
59
|
-
const proof = withStep((step) =>
|
|
62
|
+
const proof = withStep((step) => COVERAGE_PROOF.test(runOf(step)));
|
|
60
63
|
if (unit.join() !== 'test') out.push(say('job-shape', `the unit run must be a step of the test job alone, not of ${unit.join(', ') || 'no job'}`));
|
|
61
64
|
if (proof.join() !== 'coverage') out.push(say('job-shape', `the coverage proof must be a step of the coverage job alone, not of ${proof.join(', ') || 'no job'}`));
|
|
62
65
|
if (upload.length && upload.join() !== 'coverage') out.push(say('job-shape', `the Codecov upload must be a step of the coverage job alone, not of ${upload.join(', ')}`));
|
|
@@ -79,7 +82,7 @@ function testSharding(doc, say) {
|
|
|
79
82
|
if (unit && !runOf(unit).includes('--coverageThreshold={}')) out.push(say('test-sharding', 'a shard measures without the per-file threshold (--coverageThreshold={}); the coverage job proves it on the merged report'));
|
|
80
83
|
const coverage = record(doc.jobs?.coverage) ? stepsOf(doc.jobs.coverage) : [];
|
|
81
84
|
const merge = coverage.findIndex((step) => /app coverage merge\b/.test(runOf(step)));
|
|
82
|
-
const proof = coverage.findIndex((step) =>
|
|
85
|
+
const proof = coverage.findIndex((step) => COVERAGE_PROOF.test(runOf(step)));
|
|
83
86
|
if (merge < 0 || (proof >= 0 && merge > proof)) out.push(say('test-sharding', 'the coverage job must merge the shard reports (starci app coverage merge) before the coverage proof'));
|
|
84
87
|
return out;
|
|
85
88
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
// staged-specs.mjs - BE_UNIT_SPEC_NOT_STAGED (R47): the commit that adds a back-end logic file adds its unit spec beside it. A new
|
|
2
2
|
// file `be/<path>/<name>.<role>.ts` that the coverage scope measures (scripts/hfs/coverage-scope.mjs isMeasured: a role of
|
|
3
|
-
// ruleParams.be.logicRoles below a measured root, outside its none folders)
|
|
4
|
-
//
|
|
5
|
-
//
|
|
3
|
+
// ruleParams.be.logicRoles below a measured root, outside its none folders) and that holds executable logic (a function, a method, a
|
|
4
|
+
// constructor, an accessor) needs `<name>.<role>.spec.ts` in the same index. A measured file with nothing to execute (constants and
|
|
5
|
+
// types only, such as an error-kind to HTTP-status table) has nothing a spec could call, and the spec rules refuse a spec of it
|
|
6
|
+
// (spec-infra-double-from-kit); the coverage gate still reaches it through its callers. `starci app hygiene` judges the files the
|
|
7
|
+
// index adds (packages/hfs/sync/hygiene.mjs, run by the managed pre-commit hook), so a coding agent cannot commit the code first and
|
|
8
|
+
// its spec afterwards. A file that already exists is the coverage gate's.
|
|
6
9
|
import { isMeasured } from '../coverage-scope.mjs';
|
|
7
10
|
|
|
8
11
|
const SPEC_NOT_STAGED = 'BE_UNIT_SPEC_NOT_STAGED';
|
|
@@ -11,13 +14,30 @@ const BE = 'be/';
|
|
|
11
14
|
/** The unit spec beside an app-relative `<name>.<role>.ts`: `<name>.<role>.spec.ts`. */
|
|
12
15
|
const siblingSpec = (file) => file.replace(/\.ts$/u, '.spec.ts');
|
|
13
16
|
|
|
17
|
+
/** The syntax kinds that execute: a body a spec can call. */
|
|
18
|
+
const EXECUTABLE_KINDS = ['FunctionDeclaration', 'FunctionExpression', 'ArrowFunction', 'MethodDeclaration', 'Constructor', 'GetAccessor', 'SetAccessor'];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Whether TypeScript `text` holds executable logic. Without a TypeScript parser (`ts` null) or without the text, the file counts as
|
|
22
|
+
* logic: the gate never relaxes on what it cannot read.
|
|
23
|
+
*/
|
|
24
|
+
function holdsLogic(ts, text) {
|
|
25
|
+
if (!ts || typeof text !== 'string') return true;
|
|
26
|
+
const kinds = new Set(EXECUTABLE_KINDS.map((name) => ts.SyntaxKind[name]));
|
|
27
|
+
const source = ts.createSourceFile('subject.ts', text, ts.ScriptTarget.Latest, false, ts.ScriptKind.TS);
|
|
28
|
+
const visit = (node) => kinds.has(node.kind) || ts.forEachChild(node, visit) === true;
|
|
29
|
+
return ts.forEachChild(source, visit) === true;
|
|
30
|
+
}
|
|
31
|
+
|
|
14
32
|
/**
|
|
15
33
|
* The findings `{ file, code, message }` of the app-relative files the index adds (`added`) whose sibling spec is not among the
|
|
16
|
-
* paths the index holds (`indexed`, a Set). `manifest` is the slot manifest the coverage scope reads
|
|
34
|
+
* paths the index holds (`indexed`, a Set). `manifest` is the slot manifest the coverage scope reads; `staged(file)` answers the
|
|
35
|
+
* staged text of a file and `ts` the TypeScript parser, which tell a logic file from a constants-only one.
|
|
17
36
|
*/
|
|
18
|
-
export function stagedSpecFindings(manifest, added, indexed) {
|
|
37
|
+
export function stagedSpecFindings(manifest, added, indexed, { ts = null, staged = () => null } = {}) {
|
|
19
38
|
return added
|
|
20
39
|
.filter((file) => file.startsWith(BE) && !file.endsWith('.spec.ts') && isMeasured(manifest, file.slice(BE.length)) && !indexed.has(siblingSpec(file)))
|
|
40
|
+
.filter((file) => holdsLogic(ts, staged(file)))
|
|
21
41
|
.map((file) => ({
|
|
22
42
|
file,
|
|
23
43
|
code: SPEC_NOT_STAGED,
|
package/scaffold/app.mjs
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
// is in sync by construction. The lockfile is never written by hand: once the files are written, npm resolves the real one
|
|
11
11
|
// (`npm install --package-lock-only`, no node_modules, no scripts), so `npm ci` installs the new app as it is. When npm cannot
|
|
12
12
|
// resolve it the scaffold fails (HFS_SCAFFOLD_LOCK_FAILED), names the step and unlinks its own generated entries. Replaced or
|
|
13
|
-
// occupied entries are retained with a cleanup message. The only existing root accepted is an empty unborn main Git repository
|
|
13
|
+
// occupied entries are retained with a cleanup message. The only existing root accepted is an empty unborn main Git repository; a
|
|
14
|
+
// new path is made one first (git init, branch main).
|
|
14
15
|
import fs from 'node:fs';
|
|
15
16
|
import path from 'node:path';
|
|
16
17
|
import { spawnSync } from 'node:child_process';
|
|
@@ -27,6 +28,7 @@ import { initializeAppIdentity } from '../runtime/scripts/hfs/secret-init.mjs';
|
|
|
27
28
|
import { declaredSealedMembers, materializeDeclaredPlaceholders } from '../runtime/scripts/hfs/sealed-members.mjs';
|
|
28
29
|
import { revParseQuery } from '../runtime/scripts/api/git/rev-parse-query.mjs';
|
|
29
30
|
import { lsFiles } from '../runtime/scripts/api/git/ls-files.mjs';
|
|
31
|
+
import { init as gitInit } from '../runtime/scripts/api/git/init.mjs';
|
|
30
32
|
import { insidePath, samePath } from '../runtime/scripts/lib/path-key.mjs';
|
|
31
33
|
import { byCodeUnit } from '../report/order.mjs';
|
|
32
34
|
import { sonarGateName } from '../sync/sonar-key.mjs';
|
|
@@ -629,8 +631,9 @@ function emitScaffoldDatabaseTypes(root, name, writes, emitTypes) {
|
|
|
629
631
|
|
|
630
632
|
/**
|
|
631
633
|
* `starci app scaffold <name>`: writes the new app under `into`, resolves its lockfile with npm (`lock`, npmLock), and returns
|
|
632
|
-
* `{ root, files }` (app-relative paths, sorted).
|
|
633
|
-
*
|
|
634
|
+
* `{ root, files }` (app-relative paths, sorted). A new path is first made an empty repository with unborn main (`initGit`), so the
|
|
635
|
+
* app always lives in its own Git repository. `presets` are the jest preset's Sonar exclusions; the CLI passes the copy @starci/hfs
|
|
636
|
+
* ships (bundledPresets). Failure removes only scaffold-owned entries, retaining the .git.
|
|
634
637
|
*/
|
|
635
638
|
/** Seal declared starter members to a fresh app recipient through the scaffold rollback owner. */
|
|
636
639
|
function initializeScaffoldSecrets(root, writes) {
|
|
@@ -641,13 +644,25 @@ function initializeScaffoldSecrets(root, writes) {
|
|
|
641
644
|
return [...initialized.files, ...materialized.members];
|
|
642
645
|
}
|
|
643
646
|
|
|
644
|
-
|
|
647
|
+
/**
|
|
648
|
+
* A new app path becomes the one accepted existing root first: an empty repository with unborn main (git init), so the app is always
|
|
649
|
+
* created inside its own Git repository and `starci npm ci` can install the hooks. A failed init is a refusal before any file is written.
|
|
650
|
+
*/
|
|
651
|
+
function bornRepository(root, initGit) {
|
|
652
|
+
fs.mkdirSync(root, { recursive: true });
|
|
653
|
+
const made = initGit(root, { branch: 'main' });
|
|
654
|
+
if (!made?.ok) throw new ScaffoldError('HFS_SCAFFOLD_GIT_INIT_FAILED', `git init could not create the repository of ${root} (${String(made?.stderr ?? '').trim() || 'no output'}); remove ${root}, check git, then run starci app scaffold again`);
|
|
655
|
+
return fs.lstatSync(root);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
export function scaffoldApp({ name, into, presets, edition = 'full', authCallback = false, registryVisibility = 'public', manifest = loadSlotManifest(), pins = bundledPins(), lock = npmLock, emitTypes = generateDbTypes, initGit = gitInit, now = () => new Date() }) {
|
|
645
659
|
if (!NAME.test(String(name))) throw new ScaffoldError('HFS_SCAFFOLD_NAME_INVALID', `the app name ${name} must be kebab-case (a project name: ${NAME})`);
|
|
646
660
|
const root = path.resolve(into, name);
|
|
647
|
-
const
|
|
648
|
-
if (
|
|
661
|
+
const existing = fs.lstatSync(root, { throwIfNoEntry: false });
|
|
662
|
+
if (existing && !emptyUnbornGit(root, existing)) throw new ScaffoldError('HFS_SCAFFOLD_EXISTS', `${root} already exists; only a plain directory containing solely .git with unborn main and an empty index can be scaffolded`);
|
|
649
663
|
if (!['public', 'private'].includes(registryVisibility)) throw new ScaffoldError('HFS_SCAFFOLD_REGISTRY_VISIBILITY', `--registry-visibility accepts public or private (got ${registryVisibility})`);
|
|
650
664
|
if (typeof authCallback !== 'boolean') throw new ScaffoldError('HFS_SCAFFOLD_NAME_INVALID', 'authCallback must be a boolean');
|
|
665
|
+
const original = existing ?? bornRepository(root, initGit);
|
|
651
666
|
const declaration = starterDeclaration(name, manifest, edition);
|
|
652
667
|
if (authCallback) enableAuthCallback(declaration);
|
|
653
668
|
const app = resolveRepoDeclaration(manifest, declaration);
|
package/src/main.mjs
CHANGED
|
@@ -69,7 +69,7 @@ import { formatCoverageReport } from '../runtime/scripts/hfs/coverage-from.mjs';
|
|
|
69
69
|
import { HFS_DECLARATION_FILE, HfsSlotsError, loadSlotManifest, readRepoDeclaration } from '../runtime/scripts/hfs/slots.mjs';
|
|
70
70
|
import { formatFindings } from '../sync/format.mjs';
|
|
71
71
|
import { main as syncMain } from '../sync/cli.mjs';
|
|
72
|
-
import { SyncError,
|
|
72
|
+
import { SyncError, bundledPresets } from '../sync/index.mjs';
|
|
73
73
|
import { managedFindings } from '../sync/managed.mjs';
|
|
74
74
|
import { emitContracts } from '../emit/contracts.mjs';
|
|
75
75
|
import { dbTypesEmitter } from '../emit/db-types.mjs';
|
|
@@ -282,14 +282,10 @@ async function lintMain(argv, { cwd, stdout, presets, prettier }) {
|
|
|
282
282
|
}
|
|
283
283
|
|
|
284
284
|
/**
|
|
285
|
-
* The jest preset a new app renders its Sonar exclusions from: the
|
|
286
|
-
*
|
|
285
|
+
* The jest preset a new app renders its Sonar exclusions from: the copy this @starci/hfs ships (bundledPresets), the same version the
|
|
286
|
+
* scaffold pins, so `npx @starci/cli app scaffold` works before any dependency of the app is installed.
|
|
287
287
|
*/
|
|
288
|
-
|
|
289
|
-
try { return await loadPresets(path.dirname(fileURLToPath(import.meta.url))); } catch (error) {
|
|
290
|
-
throw new SyncError('HFS_SYNC_PRESET_MISSING', `${error.message.replace(/^[A-Z_]+: /, '')}; install @starci/jest-preset beside @starci/cli, then run starci app scaffold <name>`);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
288
|
+
const scaffoldPresets = () => bundledPresets();
|
|
293
289
|
|
|
294
290
|
function globalValueArgument(arg, args) {
|
|
295
291
|
const inline = arg.startsWith('--cwd=') || arg.startsWith('--edition=');
|
|
@@ -389,7 +385,7 @@ function addMain(opts, { cwd: repoRoot, stdout: out }) {
|
|
|
389
385
|
async function scaffoldMain(opts, { cwd, edition = 'full', presets, lock, stdout: out }) {
|
|
390
386
|
const [name, ...extra] = opts.positional;
|
|
391
387
|
if (!name || extra.length) throw new Error('starci app scaffold takes `<name> [--into <dir>] [--edition full|lite] [--registry-visibility public|private]`');
|
|
392
|
-
const { root: created, files } = scaffoldApp({ name, into: path.resolve(cwd, opts.into ?? '.'), edition, presets: presets ??
|
|
388
|
+
const { root: created, files } = scaffoldApp({ name, into: path.resolve(cwd, opts.into ?? '.'), edition, presets: presets ?? scaffoldPresets(), ...(opts['registry-visibility'] === undefined ? {} : { registryVisibility: opts['registry-visibility'] }), ...(lock ? { lock } : {}) });
|
|
393
389
|
out(`starci app scaffold: created ${created} (${files.length} files); next: starci npm ci (the lockfile, then the git hooks through npm run prepare; after a raw npm ci --ignore-scripts run npm run prepare), then starci app lint\n`);
|
|
394
390
|
return 0;
|
|
395
391
|
}
|