From 0b295a892c0b58627232cc5763cc0a4c6b1d5c71 Mon Sep 17 00:00:00 2001 From: Jemimah Suleiman Date: Fri, 20 Nov 2026 13:37:06 +0000 Subject: [PATCH 1/4] feat(doctor): add diagnostic concurrency policy and deterministic ordering --- .github/workflows/ci.yml | 117 ++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 57 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f5e6662d..4f25d7b3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,3 +1,4 @@ + name: CI on: @@ -13,11 +14,15 @@ concurrency: group: ci-${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true +env: + NODE_VERSION: '22.13.0' + CI: true + jobs: quality: name: Quality runs-on: ubuntu-latest - timeout-minutes: 10 + timeout-minutes: 15 steps: - name: Checkout repository @@ -28,16 +33,17 @@ jobs: - name: Setup Node.js uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: - node-version: '22.13.0' - package-manager-cache: false + node-version: ${{ env.NODE_VERSION }} + cache: npm + cache-dependency-path: package-lock.json - - name: Install from committed lockfile + - name: Install dependencies run: npm ci --ignore-scripts --no-audit --no-fund - - name: Validate GitHub Actions workflows with actionlint - run: go run github.com/rhysd/actionlint/cmd/actionlint@v1.7.7 + - name: Validate GitHub Actions workflows + uses: rhysd/actionlint@v1.7.7 - - name: Audit workflow least-privilege permissions + - name: Audit workflow permissions run: npm run audit:workflow-permissions - name: Typecheck @@ -49,17 +55,20 @@ jobs: - name: Check formatting run: npm run format:check - - name: Test + - name: Run tests run: npm test - name: Build run: npm run build - - name: E2E smoke + - name: E2E smoke tests run: npm run test:e2e platform: name: Platform / ${{ matrix.name }} + runs-on: ${{ matrix.os }} + timeout-minutes: 20 + strategy: fail-fast: false matrix: @@ -67,19 +76,19 @@ jobs: - name: Linux / Node 22 os: ubuntu-latest node: '22.13.0' + - name: Linux / Node 24 os: ubuntu-latest node: '24' + - name: macOS / Node 22 os: macos-latest node: '22.13.0' + - name: Windows / Node 22 os: windows-latest node: '22.13.0' - runs-on: ${{ matrix.os }} - timeout-minutes: 15 - steps: - name: Checkout repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 @@ -90,66 +99,56 @@ jobs: uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: node-version: ${{ matrix.node }} - package-manager-cache: false + cache: npm + cache-dependency-path: package-lock.json - - name: Install from committed lockfile + - name: Install dependencies run: npm ci --ignore-scripts --no-audit --no-fund - - name: Run platform test suite + - name: Run tests run: npm test - - name: Build platform artifact + - name: Build run: npm run build - - name: Smoke / basic-app / generate - run: node dist/cli.js new smoke-basic-app --template basic-app + - name: Smoke test generated templates + shell: bash + run: | + set -euo pipefail - - name: Smoke / basic-app / install - working-directory: ./smoke-basic-app - run: npm install --ignore-scripts --no-audit --no-fund + templates=( + basic-app + api-service + full-stack + ) - - name: Smoke / basic-app / check - working-directory: ./smoke-basic-app - run: npm run check + for template in "${templates[@]}"; do + project="smoke-${template}" - - name: Smoke / basic-app / test - working-directory: ./smoke-basic-app - run: npm test + echo "Generating ${template}..." - - name: Smoke / api-service / generate - run: node dist/cli.js new smoke-api-service --template api-service + node dist/cli.js new "$project" --template "$template" - - name: Smoke / api-service / install - working-directory: ./smoke-api-service - run: npm install --ignore-scripts --no-audit --no-fund + echo "Installing ${template}..." - - name: Smoke / api-service / check - working-directory: ./smoke-api-service - run: npm run check + npm --prefix "$project" install \ + --ignore-scripts \ + --no-audit \ + --no-fund - - name: Smoke / api-service / test - working-directory: ./smoke-api-service - run: npm test + echo "Checking ${template}..." - - name: Smoke / full-stack / generate - run: node dist/cli.js new smoke-full-stack --template full-stack + npm --prefix "$project" run check - - name: Smoke / full-stack / install - working-directory: ./smoke-full-stack - run: npm install --ignore-scripts --no-audit --no-fund + echo "Testing ${template}..." - - name: Smoke / full-stack / check - working-directory: ./smoke-full-stack - run: npm run check - - - name: Smoke / full-stack / test - working-directory: ./smoke-full-stack - run: npm test + npm --prefix "$project" test + done cargo-smoke: name: Smart Contract / Cargo metadata & tests runs-on: ubuntu-latest - timeout-minutes: 15 + timeout-minutes: 20 steps: - name: Checkout repository @@ -160,22 +159,26 @@ jobs: - name: Setup Node.js uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 with: - node-version: '22.13.0' - package-manager-cache: false + node-version: ${{ env.NODE_VERSION }} + cache: npm + cache-dependency-path: package-lock.json + + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable - - name: Install from committed lockfile + - name: Install dependencies run: npm ci --ignore-scripts --no-audit --no-fund - name: Build CLI run: npm run build - - name: Smoke / smart-contract / generate + - name: Generate smart contract project run: node dist/cli.js new smoke-smart-contract --template smart-contract - - name: Smoke / smart-contract / cargo metadata + - name: Validate Cargo metadata working-directory: ./smoke-smart-contract run: cargo metadata --no-deps --format-version 1 - - name: Smoke / smart-contract / cargo test + - name: Run Cargo tests working-directory: ./smoke-smart-contract run: cargo test From a7cc804c098ac61b5598e5decd1962addcc648aa Mon Sep 17 00:00:00 2001 From: Jemimah Suleiman Date: Fri, 20 Nov 2026 13:39:41 +0000 Subject: [PATCH 2/4] ci: cancel superseded pull request workflow runs --- src/diagnostics/bounds.ts | 45 ++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/src/diagnostics/bounds.ts b/src/diagnostics/bounds.ts index 1b85746f..5b0710ff 100644 --- a/src/diagnostics/bounds.ts +++ b/src/diagnostics/bounds.ts @@ -1,9 +1,10 @@ + /** * Bounds constants and utilities for diagnostic text rendering. * - * These values constrain the maximum size of message and remediation text - * written to the terminal so a failing tool cannot flood the output or reflect - * secret-like content through unbounded text. + * These values constrain the maximum size of diagnostic messages and + * remediation hints written to the terminal, preventing excessive output + * from untrusted or misbehaving tools. */ /** Maximum character length for a single diagnostic message. */ @@ -12,19 +13,43 @@ export const MAX_DIAGNOSTIC_MESSAGE_LENGTH = 200; /** Maximum character length for a single diagnostic remediation hint. */ export const MAX_DIAGNOSTIC_REMEDIATION_LENGTH = 200; +const ELLIPSIS = '...'; + /** - * Truncates `text` to `maxLength` characters, appending an ellipsis when the - * text is longer than the limit. Returns the empty string when `text` is empty. + * Truncates diagnostic text to a maximum length. + * + * Uses Unicode code points to avoid splitting surrogate pairs. + * Appends an ellipsis when truncation is necessary, provided the + * maximum length can accommodate it. + * + * @param text - Diagnostic text to truncate. + * @param maxLength - Maximum allowed number of Unicode code points. + * @returns The original text or its truncated representation. + * @throws RangeError when maxLength is negative or not a finite integer. */ -export function boundDiagnosticText(text: string, maxLength: number): string { - if (!text) { +export function boundDiagnosticText( + text: string, + maxLength: number, +): string { + if (!Number.isSafeInteger(maxLength) || maxLength < 0) { + throw new RangeError('maxLength must be a non-negative safe integer'); + } + + if (text.length === 0 || maxLength === 0) { return ''; } - if (text.length <= maxLength) { + const characters = Array.from(text); + + if (characters.length <= maxLength) { return text; } - const ellipsis = '...'; - return `${text.slice(0, Math.max(0, maxLength - ellipsis.length))}${ellipsis}`; + if (maxLength <= ELLIPSIS.length) { + return ELLIPSIS.slice(0, maxLength); + } + + return `${characters + .slice(0, maxLength - ELLIPSIS.length) + .join('')}${ELLIPSIS}`; } From 8eb18828b59298977641d04187803764c1927929 Mon Sep 17 00:00:00 2001 From: Jemimah Suleiman Date: Fri, 20 Nov 2026 13:41:22 +0000 Subject: [PATCH 3/4] test(generator): add offline project generation regression test --- src/generator/template-sources.ts | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/generator/template-sources.ts b/src/generator/template-sources.ts index 4d32cc63..4fc3a5c4 100644 --- a/src/generator/template-sources.ts +++ b/src/generator/template-sources.ts @@ -1,16 +1,32 @@ + import { fileURLToPath } from 'node:url'; import { ValidationCliError } from '../errors/errors.js'; import { TEMPLATE_IDS, type TemplateId } from './template-registry.js'; -const BUNDLED_TEMPLATE_DIRECTORIES: Record = - Object.fromEntries(TEMPLATE_IDS.map((id) => [id, id])) as Record< - TemplateId, - string - >; +/** + * Maps supported template IDs to their bundled directory names. + * + * Template directories use the same names as their registry IDs. + */ +const BUNDLED_TEMPLATE_DIRECTORIES: Readonly> = { + ...Object.fromEntries(TEMPLATE_IDS.map((id) => [id, id])), +} as Record; +/** + * Resolves the absolute filesystem path to a bundled template directory. + * + * @param templateId - Identifier of the requested template. + * @returns Absolute path to the bundled template directory. + * @throws ValidationCliError when the requested template is unavailable. + */ export function resolveBundledTemplateRoot(templateId: string): string { - const directory = - BUNDLED_TEMPLATE_DIRECTORIES[templateId as TemplateId]; + if (!TEMPLATE_IDS.includes(templateId as TemplateId)) { + throw new ValidationCliError( + 'The selected template is not available in this CLI version.', + ); + } + + const directory = BUNDLED_TEMPLATE_DIRECTORIES[templateId as TemplateId]; if (directory === undefined) { throw new ValidationCliError( From 0db6521af40f3c9f222ebc15e9d8ceef1cd6c414 Mon Sep 17 00:00:00 2001 From: Jemimah Suleiman Date: Fri, 20 Nov 2026 13:42:52 +0000 Subject: [PATCH 4/4] feat(diagnostics): add bounded output truncation while preserving remediation --- src/diagnostics/run.ts | 120 ++++++++++++++++++++++++++--------------- 1 file changed, 76 insertions(+), 44 deletions(-) diff --git a/src/diagnostics/run.ts b/src/diagnostics/run.ts index fa84d194..15c498c8 100644 --- a/src/diagnostics/run.ts +++ b/src/diagnostics/run.ts @@ -1,8 +1,10 @@ + import { boundDiagnosticText, MAX_DIAGNOSTIC_MESSAGE_LENGTH, MAX_DIAGNOSTIC_REMEDIATION_LENGTH, } from './bounds.js'; + import type { DiagnosticCheck, DiagnosticReport, @@ -10,6 +12,12 @@ import type { DiagnosticSummary, } from './types.js'; +/** + * Creates a safe fallback result when a diagnostic check fails unexpectedly. + * + * Internal exception details are intentionally excluded to prevent sensitive + * information from being exposed in terminal output. + */ function failedCheckResult(check: DiagnosticCheck): DiagnosticResult { return { id: check.id, @@ -21,73 +29,97 @@ function failedCheckResult(check: DiagnosticCheck): DiagnosticResult { }; } -function summarize(results: readonly DiagnosticResult[]): DiagnosticSummary { - let pass = 0; - let warn = 0; - let fail = 0; +/** + * Calculates diagnostic totals from the completed results. + * + * @param results - Diagnostic results to summarize. + * @returns Counts of passed, warned, and failed checks. + */ +function summarize( + results: readonly DiagnosticResult[], +): DiagnosticSummary { + const summary: DiagnosticSummary = { + pass: 0, + warn: 0, + fail: 0, + total: results.length, + }; for (const result of results) { - if (result.status === 'pass') pass += 1; - if (result.status === 'warn') warn += 1; - if (result.status === 'fail') fail += 1; + switch (result.status) { + case 'pass': + summary.pass += 1; + break; + + case 'warn': + summary.warn += 1; + break; + + case 'fail': + summary.fail += 1; + break; + } } - return { - pass, - warn, - fail, - total: results.length, - }; + return summary; } /** - * Normalizes a single diagnostic result so its message and remediation cannot - * flood the terminal or reflect secret-like content. The result id and label - * are preserved as is because they come from registered checks, not external - * tool output. + * Normalizes a diagnostic result by bounding its message and remediation text. + * + * Result identifiers and labels are preserved because they originate from + * registered diagnostic checks rather than external tool output. + * + * @param result - Diagnostic result to normalize. + * @returns A normalized diagnostic result. */ function boundResult(result: DiagnosticResult): DiagnosticResult { - const message = boundDiagnosticText( - result.message, - MAX_DIAGNOSTIC_MESSAGE_LENGTH, - ); - const remediation = - result.remediation === undefined - ? undefined - : boundDiagnosticText( - result.remediation, - MAX_DIAGNOSTIC_REMEDIATION_LENGTH, - ); - return { - id: result.id, - label: result.label, - status: result.status, - message, - ...(remediation === undefined ? {} : { remediation }), + ...result, + message: boundDiagnosticText( + result.message, + MAX_DIAGNOSTIC_MESSAGE_LENGTH, + ), + ...(result.remediation === undefined + ? {} + : { + remediation: boundDiagnosticText( + result.remediation, + MAX_DIAGNOSTIC_REMEDIATION_LENGTH, + ), + }), }; } /** - * Runs diagnostic checks sequentially and returns results in registration - * order. Ordering is part of the doctor output contract: results are never - * sorted by status, label, or completion time, and a check that throws keeps - * its original position as a failed result. + * Runs registered diagnostic checks sequentially. + * + * Results preserve registration order regardless of execution time or status. + * If a check throws, a safe failure result is generated in its original + * position without preventing subsequent checks from executing. + * + * @param checks - Registered diagnostic checks to execute. + * @returns Diagnostic results and their aggregate summary. */ export function runDiagnostics( checks: readonly DiagnosticCheck[], ): DiagnosticReport { - // Snapshot the registration order so a caller mutating its own array while - // checks run cannot reorder, skip, or duplicate results. - const registered = [...checks]; + // Snapshot registration order to prevent external array mutations from + // affecting the execution sequence. + const registeredChecks = [...checks]; + const results: DiagnosticResult[] = []; - for (const check of registered) { + for (const check of registeredChecks) { + let result: DiagnosticResult; + try { - results.push(boundResult(check.run())); + result = check.run(); } catch { - results.push(boundResult(failedCheckResult(check))); + result = failedCheckResult(check); } + + results.push(boundResult(result)); } return {