Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 60 additions & 57 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

name: CI

on:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -49,37 +55,40 @@ 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:
include:
- 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
Expand All @@ -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
Expand All @@ -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
45 changes: 35 additions & 10 deletions src/diagnostics/bounds.ts
Original file line number Diff line number Diff line change
@@ -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. */
Expand All @@ -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}`;
}
Loading
Loading